_oModule = $oModule; } /** * @return add data html */ public function addDataForm () { $CNF = &$this->_oModule->_oConfig->CNF; // check access if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedAdd())) 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('_bx_notes_txt_error_entry_creation')); } // perform action $this->_oModule->isAllowedAdd(true); // alert //TODO: Pass a valid entry privacy view group. bx_import('BxDolPrivacy'); bx_alert($this->_oModule->getName(), 'added', $iContentId, false, array('privacy_view' => BX_DOL_PG_ALL)); // redirect $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId); } /** * @return edit data html */ 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('_bx_notes_txt_error_entry_is_not_defined')); // check access if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedEdit($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; if (!$oForm->update ($aContentInfo['id'], array(), $aTrackTextFieldsChanges)) { if (!$oForm->isValid()) return $oForm->getCode(); else return MsgBox(_t('_bx_notes_txt_error_entry_update')); } // change profile to 'pending' only if profile is 'active' if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields'])) $oProfile->disapprove(BX_PROFILE_ACTION_AUTO); // perform action $this->_oModule->isAllowedEdit($aContentInfo, true); // create an alert //TODO: Pass a valid entry privacy view group. bx_import('BxDolPrivacy'); bx_alert($this->_oModule->getName(), 'edited', $aContentInfo['id'], false, array('privacy_view' => BX_DOL_PG_MEMBERS)); // redirect $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo['id']); } /** * @return delete data html */ 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('_bx_notes_txt_error_entry_is_not_defined')); // check access if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedDelete($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['id'])) { if (!$oForm->isValid()) return $oForm->getCode(); else return MsgBox(_t('_bx_notes_txt_error_entry_delete')); } // perform action $this->_oModule->isAllowedDelete($aContentInfo, true); // create an alert bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo['id']); // redirect $this->_redirectAndExit('page.php?i=' . $CNF['URI_HOME']); } /** * @return view data html */ public function viewDataForm ($iContentId) { $CNF = &$this->_oModule->_oConfig->CNF; // get content data and profile info list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId); if (!$aContentInfo) return MsgBox(_t('_bx_notes_txt_error_entry_is_not_defined')); // check access if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo))) return MsgBox($sMsg); // get form $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']); if (!$oForm) return MsgBox(_t('_sys_txt_error_occured')); // perform action $this->_oModule->isAllowedView($aContentInfo); // display profile $oForm->initChecker($aContentInfo); return $oForm->getCode(); } /** * @return main content text */ public function viewDataText ($iContentId) { $CNF = &$this->_oModule->_oConfig->CNF; // get content data and profile info list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId); if (!$aContentInfo) return MsgBox(_t('_bx_notes_txt_error_entry_is_not_defined')); // check access if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo))) return MsgBox($sMsg); return $aContentInfo[$CNF['FIELD_TEXT']]; } /** * @return main content text */ public function viewDataEntry ($iContentId) { // get content data and profile info list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId); if (!$aContentInfo) return MsgBox(_t('_bx_notes_txt_error_entry_is_not_defined')); // check access if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo))) return MsgBox($sMsg); return $this->_oModule->_oTemplate->entryText($aContentInfo); } /** * @return array of profile object, profile info and content info */ protected function _getProfileAndContentData ($iContentId) { $CNF = &$this->_oModule->_oConfig->CNF; $aContentInfo = array(); $oProfile = false; $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId); if (!$aContentInfo) return array (false, false, false); $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]); if (!$oProfile) { bx_import('BxDolProfileUndefined'); $oProfile = BxDolProfileUndefined::getInstance(); } return array ($oProfile, $aContentInfo); } } /** @} */