| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- <?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 TridentModules
- *
- * @{
- */
- /**
- * Entry forms helper functions
- */
- class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
- {
- protected $_oModule;
- public function __construct($oModule)
- {
- parent::__construct();
- $this->_oModule = $oModule;
- }
- public function getObjectStorage()
- {
- return BxDolStorage::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_STORAGE']);
- }
- public function getObjectFormAdd ()
- {
- return BxDolForm::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_FORM_ENTRY'], $this->_oModule->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oModule->_oTemplate);
- }
- public function getObjectFormEdit ($sDisplay = false)
- {
- if (false === $sDisplay)
- $sDisplay = $this->_oModule->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
- return BxDolForm::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
- }
- public function getObjectFormDelete ()
- {
- return BxDolForm::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_FORM_ENTRY'], $this->_oModule->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'], $this->_oModule->_oTemplate);
- }
- 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 = $this->getObjectFormAdd();
- 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 (getLoggedId(), $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, $this->_oModule->_oTemplate);
- if (!$oForm)
- return MsgBox(_t('_sys_txt_error_occured'));
- $aSpecificValues = array();
- if (!empty($CNF['OBJECT_METATAGS'])) {
- $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
- if ($oMetatags->locationsIsEnabled())
- $aSpecificValues = $oMetatags->locationGet($iContentId, empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
- }
- $oForm->initChecker($aContentInfo, $aSpecificValues);
- 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, $this->_oModule->_oTemplate);
- if (!$oForm)
- return MsgBox(_t('_sys_txt_error_occured'));
- $oForm->initChecker($aContentInfo);
- if (!$oForm->isSubmittedAndValid())
- return $oForm->getCode();
- if ($sError = $this->deleteData($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile, $oForm))
- return MsgBox($sError);
- // perform action
- $this->_oModule->checkAllowedDelete($aContentInfo, true);
- // redirect
- $this->_redirectAndExit($CNF['URL_HOME'], true, array(
- 'account_id' => getLoggedId(),
- 'profile_id' => bx_get_logged_profile_id(),
- ));
- }
- /**
- * Delete data entry
- * @param $iContentId entry id
- * @param $oForm optional content info array
- * @param $aContentInfo optional content info array
- * @param $oProfile optional content author profile
- * @return error string on error or empty string on success
- */
- public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (!$aContentInfo || !$oProfile)
- list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
- if (!$aContentInfo)
- return _t('_sys_txt_error_entry_is_not_defined');
- if (!$oForm)
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'], $this->_oModule->_oTemplate);
- if (!$oForm->delete ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo))
- return _t('_sys_txt_error_entry_delete');
- if ($sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile))
- return $sResult;
- // create an alert
- bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']]);
- return '';
- }
- 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 ($sMsg = $this->_processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile))
- return MsgBox($sMsg);
- // get form
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
- if (!$oForm)
- return MsgBox(_t('_sys_txt_error_occured'));
- // process metatags
- if (!empty($CNF['OBJECT_METATAGS'])) {
- $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
- if ($oMetatags->keywordsIsEnabled()) {
- $aFields = $oMetatags->keywordsFields($aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']);
- $oForm->setMetatagsKeywordsData($iContentId, $aFields, $oMetatags);
- }
- }
- // display profile
- $oForm->initChecker($aContentInfo);
- return $oForm->getCode();
- }
- protected function _processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile)
- {
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
- return $sMsg;
- return '';
- }
- public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
- {
- return '';
- }
- public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
- {
- }
- public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (!empty($CNF['OBJECT_METATAGS'])) { // && isset($aTrackTextFieldsChanges['changed_fields'][$CNF['FIELD_TEXT']])) { // TODO: check if aTrackTextFieldsChanges works
- list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
- $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
- if ($oMetatags->keywordsIsEnabled())
- $oMetatags->keywordsAddAuto($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']);
- if ($oMetatags->locationsIsEnabled())
- $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
- }
- return '';
- }
- public function onDataAddAfter ($iAccountId, $iContentId)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (!empty($CNF['OBJECT_METATAGS'])) {
- list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
- $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
- if ($oMetatags->keywordsIsEnabled())
- $oMetatags->keywordsAddAuto($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
- if ($oMetatags->locationsIsEnabled())
- $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], $CNF['FIELD_LOCATION_PREFIX']);
- }
- return '';
- }
- }
- /** @} */
|