| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup BaseGeneral Base classes for modules
- * @ingroup DolphinModules
- *
- * @{
- */
- bx_import('BxDolProfileForms');
- bx_import('BxDolForm');
- /**
- * Entry forms helper functions
- */
- class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
- {
- protected $_oModule;
- public function __construct($oModule)
- {
- parent::__construct();
- $this->_oModule = $oModule;
- }
- public function addDataForm ()
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- // check access
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedAdd()))
- return MsgBox($sMsg);
- // check and display form
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
- if (!$oForm)
- return MsgBox(_t('_sys_txt_error_occured'));
- $oForm->initChecker();
- if (!$oForm->isSubmittedAndValid())
- return $oForm->getCode();
- // insert data into database
- $aValsToAdd = array ();
- $iContentId = $oForm->insert ($aValsToAdd);
- if (!$iContentId) {
- if (!$oForm->isValid())
- return $oForm->getCode();
- else
- return MsgBox(_t('_sys_txt_error_entry_creation'));
- }
- $sResult = $this->onDataAddAfter ($iContentId);
- if ($sResult)
- return $sResult;
- // perform action
- $this->_oModule->checkAllowedAdd(true);
- // redirect
- $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
- }
- public function editDataForm ($iContentId, $sDisplay = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (false === $sDisplay)
- $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
- // get content data and profile info
- list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
- if (!$aContentInfo)
- return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
- // check access
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedEdit($aContentInfo)))
- return MsgBox($sMsg);
-
- // check and display form
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
- if (!$oForm)
- return MsgBox(_t('_sys_txt_error_occured'));
- $oForm->initChecker($aContentInfo);
- if (!$oForm->isSubmittedAndValid())
- return $oForm->getCode();
- // update data in the DB
- $aTrackTextFieldsChanges = null;
- $this->onDataEditBefore ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges);
- if (!$oForm->update ($aContentInfo[$CNF['FIELD_ID']], array(), $aTrackTextFieldsChanges)) {
- if (!$oForm->isValid())
- return $oForm->getCode();
- else
- return MsgBox(_t('_sys_txt_error_entry_update'));
- }
- $sResult = $this->onDataEditAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile);
- if ($sResult)
- return $sResult;
- // perform action
- $this->_oModule->checkAllowedEdit($aContentInfo, true);
- // redirect
- $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
- }
- public function deleteDataForm ($iContentId, $sDisplay = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (false === $sDisplay)
- $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'];
- // get content data and profile info
- list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
- if (!$aContentInfo)
- return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
- // check access
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedDelete($aContentInfo)))
- return MsgBox($sMsg);
-
- // check and display form
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
- if (!$oForm)
- return MsgBox(_t('_sys_txt_error_occured'));
- $oForm->initChecker($aContentInfo);
- if (!$oForm->isSubmittedAndValid())
- return $oForm->getCode();
- if (!$oForm->delete ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo))
- return MsgBox(_t('_sys_txt_error_entry_delete'));
- $sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile);
- if ($sResult)
- return $sResult;
- // perform action
- $this->_oModule->checkAllowedDelete($aContentInfo, true);
- // create an alert
- bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']]);
- // redirect
- bx_import('BxDolPermalinks');
- $this->_redirectAndExit(BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']));
- }
- public function viewDataForm ($iContentId, $sDisplay = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (false === $sDisplay)
- $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW'];
- // get content data and profile info
- list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
- if (!$aContentInfo)
- return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
- // check access
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
- return MsgBox($sMsg);
-
- // get form
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
- if (!$oForm)
- return MsgBox(_t('_sys_txt_error_occured'));
- // display profile
- $oForm->initChecker($aContentInfo);
- return $oForm->getCode();
- }
- }
- /** @} */
|