BxNotesNoteForms.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Notes Notes
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolProfileForms');
  12. bx_import('BxDolProfile');
  13. bx_import('BxDolForm');
  14. /**
  15. * Note forms functions
  16. */
  17. class BxNotesNoteForms extends BxDolProfileForms {
  18. protected $_oModule;
  19. public function __construct($oModule) {
  20. parent::__construct();
  21. $this->_oModule = $oModule;
  22. }
  23. /**
  24. * @return add data html
  25. */
  26. public function addDataForm () {
  27. // check access
  28. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedAdd()))
  29. return MsgBox($sMsg);
  30. // check and display form
  31. $oForm = BxDolForm::getObjectInstance('bx_notes', 'bx_notes_note_add');
  32. if (!$oForm)
  33. return MsgBox(_t('_sys_txt_error_occured'));
  34. $oForm->initChecker();
  35. if (!$oForm->isSubmittedAndValid())
  36. return $oForm->getCode();
  37. // insert data into database
  38. $aValsToAdd = array ();
  39. $iContentId = $oForm->insert ($aValsToAdd);
  40. if (!$iContentId) {
  41. if (!$oForm->isValid())
  42. return $oForm->getCode();
  43. else
  44. return MsgBox(_t('_bx_notes_txt_error_note_creation'));
  45. }
  46. /* TODO: status
  47. // approve note if auto-approval is enabled and profile status is 'pending'
  48. $sStatus = $oProfile->getStatus();
  49. $isAutoApprove = getParam('bx_notes_autoapproval') ? true : false;
  50. if ($sStatus == BX_PROFILE_STATUS_PENDING && $isAutoApprove)
  51. $oProfile->approve(BX_PROFILE_ACTION_AUTO);
  52. */
  53. // perform action
  54. $this->_oModule->isAllowedAdd(true);
  55. // alert
  56. //TODO: Pass a valid Note's privacy view group.
  57. bx_import('BxDolPrivacy');
  58. bx_alert($this->_oModule->getName(), 'added', $iContentId, false, array('privacy_view' => BX_DOL_PG_ALL));
  59. // redirect
  60. $this->_redirectAndExit('page.php?i=view-note&id=' . $iContentId);
  61. }
  62. /**
  63. * @return edit data html
  64. */
  65. public function editDataForm ($iContentId, $sDisplay = 'bx_notes_note_edit') {
  66. // get content data and profile info
  67. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  68. if (!$aContentInfo)
  69. return MsgBox(_t('_bx_notes_txt_error_note_is_not_defined'));
  70. // check access
  71. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedEdit($aContentInfo)))
  72. return MsgBox($sMsg);
  73. // check and display form
  74. $oForm = BxDolForm::getObjectInstance('bx_notes', $sDisplay);
  75. if (!$oForm)
  76. return MsgBox(_t('_sys_txt_error_occured'));
  77. $oForm->initChecker($aContentInfo);
  78. if (!$oForm->isSubmittedAndValid())
  79. return $oForm->getCode();
  80. // update data in the DB
  81. $aTrackTextFieldsChanges = null;
  82. /* TODO: status
  83. $isAutoApprove = getParam('bx_notes_autoapproval') ? true : false;
  84. if (!$isAutoApprove && $oProfile->isActive()))
  85. $aTrackTextFieldsChanges = array ();
  86. */
  87. if (!$oForm->update ($aContentInfo['id'], array(), $aTrackTextFieldsChanges)) {
  88. if (!$oForm->isValid())
  89. return $oForm->getCode();
  90. else
  91. return MsgBox(_t('_bx_notes_txt_error_note_update'));
  92. }
  93. // change profile to 'pending' only if profile is 'active'
  94. if (/*!$isAutoApprove &&*/ $oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  95. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  96. // perform action
  97. $this->_oModule->isAllowedEdit($aContentInfo, true);
  98. // create an alert
  99. //TODO: Pass a valid Note's privacy view group.
  100. bx_import('BxDolPrivacy');
  101. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo['id'], false, array('privacy_view' => BX_DOL_PG_MEMBERS));
  102. // redirect
  103. $this->_redirectAndExit('page.php?i=view-note&id=' . $aContentInfo['id']);
  104. }
  105. /**
  106. * @return delete data html
  107. */
  108. public function deleteDataForm ($iContentId, $sDisplay = 'bx_notes_note_delete') {
  109. // get content data and profile info
  110. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  111. if (!$aContentInfo)
  112. return MsgBox(_t('_bx_notes_txt_error_note_is_not_defined'));
  113. // check access
  114. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedDelete($aContentInfo)))
  115. return MsgBox($sMsg);
  116. // check and display form
  117. $oForm = BxDolForm::getObjectInstance('bx_notes', $sDisplay);
  118. if (!$oForm)
  119. return MsgBox(_t('_sys_txt_error_occured'));
  120. $oForm->initChecker($aContentInfo);
  121. if (!$oForm->isSubmittedAndValid())
  122. return $oForm->getCode();
  123. if (!$oForm->delete ($aContentInfo['id'])) {
  124. if (!$oForm->isValid())
  125. return $oForm->getCode();
  126. else
  127. return MsgBox(_t('_bx_notes_txt_error_note_delete'));
  128. }
  129. // perform action
  130. $this->_oModule->isAllowedDelete($aContentInfo, true);
  131. // create an alert
  132. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo['id']);
  133. // redirect
  134. $this->_redirectAndExit('page.php?i=notes-home');
  135. }
  136. /**
  137. * @return view data html
  138. */
  139. public function viewDataForm ($iContentId) {
  140. // get content data and profile info
  141. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  142. if (!$aContentInfo)
  143. return MsgBox(_t('_bx_notes_txt_error_note_is_not_defined'));
  144. // check access
  145. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo)))
  146. return MsgBox($sMsg);
  147. // get form
  148. $oForm = BxDolForm::getObjectInstance('bx_notes', 'bx_notes_note_view');
  149. if (!$oForm)
  150. return MsgBox(_t('_sys_txt_error_occured'));
  151. // perform action
  152. $this->_oModule->isAllowedView($aContentInfo);
  153. // display profile
  154. $oForm->initChecker($aContentInfo);
  155. return $oForm->getCode();
  156. }
  157. /**
  158. * @return main content text
  159. */
  160. public function viewDataText ($iContentId) {
  161. // get content data and profile info
  162. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  163. if (!$aContentInfo)
  164. return MsgBox(_t('_bx_notes_txt_error_note_is_not_defined'));
  165. // check access
  166. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo)))
  167. return MsgBox($sMsg);
  168. return $aContentInfo[BxNotesConfig::$FIELD_TEXT];
  169. }
  170. /**
  171. * @return main content text
  172. */
  173. public function viewDataEntry ($iContentId) {
  174. // get content data and profile info
  175. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  176. if (!$aContentInfo)
  177. return MsgBox(_t('_bx_notes_txt_error_note_is_not_defined'));
  178. // check access
  179. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo)))
  180. return MsgBox($sMsg);
  181. return $this->_oModule->_oTemplate->entryText($aContentInfo);
  182. }
  183. /**
  184. * @return array of profile object, profile info and content info
  185. */
  186. protected function _getProfileAndContentData ($iContentId) {
  187. $aContentInfo = array();
  188. $oProfile = false;
  189. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  190. if (!$aContentInfo)
  191. return array (false, false, false);
  192. $oProfile = BxDolProfile::getInstance($aContentInfo['author']);
  193. if (!$oProfile) {
  194. bx_import('BxDolProfileUndefined');
  195. $oProfile = BxDolProfileUndefined::getInstance();
  196. }
  197. return array ($oProfile, $aContentInfo);
  198. }
  199. }
  200. /** @} */