BxBaseModGeneralFormsEntryHelper.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Entry forms helper functions
  13. */
  14. class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
  15. {
  16. protected $_oModule;
  17. /**
  18. * 'Ajax Mode' determines the format of response. If it's TRUE the response
  19. * (a form or an error appeared during form creation) should be returned
  20. * as text during initial loading, while all other responses appeared after
  21. * form submit should be arrays, which are ready to path to echoJson.
  22. */
  23. protected $_bAjaxMode;
  24. /**
  25. * Use absolute Action URL in generated form object.
  26. * It's needed in Ajax Mode.
  27. */
  28. protected $_bAbsoluteActionUrl;
  29. protected $_bDynamicMode;
  30. public function __construct($oModule)
  31. {
  32. parent::__construct();
  33. $this->_oModule = $oModule;
  34. $this->_bDynamicMode = false;
  35. $this->_bAjaxMode = false;
  36. $mixedAjaxMode = bx_get('ajax_mode');
  37. if($mixedAjaxMode !== false)
  38. $this->setAjaxMode($mixedAjaxMode);
  39. $this->_bAbsoluteActionUrl = false;
  40. $mixedAbsoluteActionUrl = bx_get('absolute_action_url');
  41. if($mixedAbsoluteActionUrl !== false)
  42. $this->setAbsoluteActionUrl($mixedAbsoluteActionUrl);
  43. }
  44. public function setAjaxMode($bAjaxMode)
  45. {
  46. $this->_bAjaxMode = (bool)$bAjaxMode;
  47. if($this->_bAjaxMode)
  48. $this->setDynamicMode(true);
  49. }
  50. public function setAbsoluteActionUrl($bAbsoluteActionUrl)
  51. {
  52. $this->_bAbsoluteActionUrl = (bool)$bAbsoluteActionUrl;
  53. }
  54. public function setDynamicMode($bDynamicMode)
  55. {
  56. $this->_bDynamicMode = (bool)$bDynamicMode;
  57. }
  58. public function getObjectStorage()
  59. {
  60. return BxDolStorage::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_STORAGE']);
  61. }
  62. public function getObjectFormAdd ($sDisplay = false)
  63. {
  64. $CNF = &$this->_oModule->_oConfig->CNF;
  65. if(false === $sDisplay)
  66. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
  67. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
  68. if($this->_bAjaxMode)
  69. $oForm->setAjaxMode($this->_bAjaxMode);
  70. if($this->_bAbsoluteActionUrl)
  71. $this->_setAbsoluteActionUrl('add', $oForm);
  72. return $oForm;
  73. }
  74. public function getObjectFormEdit ($sDisplay = false)
  75. {
  76. $CNF = &$this->_oModule->_oConfig->CNF;
  77. if(false === $sDisplay)
  78. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
  79. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
  80. if($this->_bAjaxMode)
  81. $oForm->setAjaxMode($this->_bAjaxMode);
  82. if($this->_bAbsoluteActionUrl)
  83. $this->_setAbsoluteActionUrl('edit', $oForm);
  84. return $oForm;
  85. }
  86. public function getObjectFormView ($sDisplay = false)
  87. {
  88. $CNF = &$this->_oModule->_oConfig->CNF;
  89. if (false === $sDisplay)
  90. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW'];
  91. return BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
  92. }
  93. public function getObjectFormDelete ($sDisplay = false)
  94. {
  95. $CNF = &$this->_oModule->_oConfig->CNF;
  96. if (false === $sDisplay)
  97. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'];
  98. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
  99. if($this->_bAjaxMode)
  100. $oForm->setAjaxMode($this->_bAjaxMode);
  101. if($this->_bAbsoluteActionUrl)
  102. $this->_setAbsoluteActionUrl('delete', $oForm);
  103. return $oForm;
  104. }
  105. public function viewDataEntry ($iContentId)
  106. {
  107. $CNF = &$this->_oModule->_oConfig->CNF;
  108. $sMsgCnt = '';
  109. // get content data and profile info
  110. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  111. if (!$aContentInfo)
  112. $sMsgCnt = _t('_sys_txt_error_entry_is_not_defined');
  113. // check access
  114. if (empty($sMsgCnt) && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  115. $sMsgCnt = $sMsg;
  116. if ($sMsgCnt)
  117. return bx_is_api() ? [['id' => 1, 'type' => 'msg', 'data' => $sMsgCnt]] : MsgBox($sMsgCnt);
  118. $oForm = $this->getObjectFormView();
  119. if (!$oForm)
  120. return '';
  121. $oForm->initChecker($aContentInfo);
  122. if(!empty($CNF['FIELD_TEXT']) && !$oForm->isInputVisible($CNF['FIELD_TEXT']))
  123. $s = '';
  124. else
  125. $s = $this->_oModule->_oTemplate->entryText($aContentInfo);
  126. return bx_is_api() ? [['id' => 1, 'type' => 'entry', 'data' => $s]] : $s;
  127. }
  128. public function addData ($iProfile, $aValues, $sDisplay = false)
  129. {
  130. $CNF = &$this->_oModule->_oConfig->CNF;
  131. // check and display form
  132. $oForm = $this->getObjectFormAdd($sDisplay);
  133. if (!$oForm)
  134. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  135. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  136. $oForm->aParams['csrf']['disable'] = true;
  137. if(!empty($oForm->aParams['db']['submit_name'])) {
  138. $sSubmitName = false;
  139. if (is_array($oForm->aParams['db']['submit_name'])) {
  140. foreach ($oForm->aParams['db']['submit_name'] as $sVal) {
  141. if (isset($oForm->aInputs[$sVal])) {
  142. $sSubmitName = $sVal;
  143. break;
  144. }
  145. }
  146. }
  147. else {
  148. $sSubmitName = $oForm->aParams['db']['submit_name'];
  149. }
  150. if ($sSubmitName && isset($oForm->aInputs[$sSubmitName]))
  151. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  152. }
  153. $oForm->initChecker(array(), $aValues);
  154. if (!$oForm->isSubmittedAndValid()) {
  155. $aErrors = array();
  156. array_walk($oForm->aInputs, function($aInput, $sKey) use (&$aErrors) {
  157. if(!empty($aInput['error']))
  158. $aErrors[$sKey] = $aInput['error'];
  159. });
  160. return array('code' => 2, 'message' => '_sys_txt_error_occured', 'errors' => $aErrors);
  161. }
  162. // insert data into database
  163. $aValsToAdd = array ();
  164. if(isset($CNF['FIELD_AUTHOR']))
  165. $aValsToAdd[$CNF['FIELD_AUTHOR']] = $iProfile;
  166. $iContentId = $oForm->insert($aValsToAdd);
  167. if (!$iContentId) {
  168. if (!$oForm->isValid())
  169. return array('code' => 2, 'message' => '_sys_txt_error_occured');
  170. else
  171. return array('code' => 3, 'message' => '_sys_txt_error_entry_creation');
  172. }
  173. $sResult = $this->onDataAddAfter(BxDolProfile::getInstance($iProfile)->getAccountId(), $iContentId);
  174. if($sResult)
  175. return array('code' => 4, 'message' => $sResult);
  176. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  177. /*
  178. * Process metas.
  179. * Note. It's essential to process metas a the very end,
  180. * because all data related to an entry should be already
  181. * processed and are ready to be passed to alert.
  182. */
  183. $this->_oModule->processMetasAdd($iContentId);
  184. /*
  185. * Create alert about the completed action.
  186. */
  187. $this->_oModule->alertAfterAdd($aContentInfo);
  188. return array('code' => 0, 'message' => '', 'content' => $aContentInfo);
  189. }
  190. public function addDataForm ($sDisplay = false, $sCheckFunction = false)
  191. {
  192. if (!$sCheckFunction)
  193. $sCheckFunction = 'checkAllowedAdd';
  194. $CNF = &$this->_oModule->_oConfig->CNF;
  195. $bAsJson = false;
  196. // get form object
  197. $oForm = $this->getObjectFormAdd($sDisplay);
  198. if (!$oForm)
  199. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_occured')), $bAsJson, 'msg');
  200. $bAsJson = $this->_bAjaxMode && $oForm->isSubmitted();
  201. // check access
  202. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction())) {
  203. $oProfile = BxDolProfile::getInstance();
  204. if ($oProfile && ($aProfileInfo = $oProfile->getInfo()) && $aProfileInfo['type'] == 'system' && is_subclass_of($this->_oModule, 'BxBaseModProfileModule') && $this->_oModule->serviceActAsProfile()) // special check for system profile is needed, because of incorrect error message
  205. return $this->prepareResponse(MsgBox(_t('_sys_txt_access_denied')), $bAsJson, 'msg');
  206. else
  207. return $this->prepareResponse(MsgBox($sMsg), $bAsJson, 'msg');
  208. }
  209. // check and display form
  210. $oForm->initChecker();
  211. if (!$oForm->isSubmittedAndValid())
  212. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  213. 'form_id' => $oForm->getId()
  214. ));
  215. // insert data into database
  216. $aValsToAdd = array ();
  217. $iContentId = $oForm->insert ($aValsToAdd);
  218. if (!$iContentId) {
  219. if (!$oForm->isValid())
  220. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  221. 'form_id' => $oForm->getId()
  222. ));
  223. else
  224. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_entry_creation')), $bAsJson, 'msg');
  225. }
  226. $sResult = $this->onDataAddAfter (getLoggedId(), $iContentId);
  227. if ($sResult)
  228. return $this->prepareResponse($sResult, $bAsJson, 'msg');
  229. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  230. /*
  231. * Process metas.
  232. * Note. It's essential to process metas a the very end,
  233. * because all data related to an entry should be already
  234. * processed and are ready to be passed to alert.
  235. */
  236. $this->_oModule->processMetasAdd($iContentId);
  237. // Perform ACL action
  238. $this->_oModule->$sCheckFunction(true);
  239. // Create alert about the completed action.
  240. $this->_oModule->alertAfterAdd($aContentInfo);
  241. // Redirect
  242. $this->redirectAfterAdd($aContentInfo);
  243. }
  244. public function redirectAfterAdd($aContentInfo, $sUrl = '')
  245. {
  246. $CNF = &$this->_oModule->_oConfig->CNF;
  247. if ($sUrl == '')
  248. $sUrl = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']];
  249. bx_alert($this->_oModule->getName(), 'redirect_after_add', 0, false, array(
  250. 'ajax_mode' => $this->_bAjaxMode,
  251. 'content' => $aContentInfo,
  252. 'override_result' => &$sUrl,
  253. ));
  254. if($this->_bAjaxMode) {
  255. echoJson($this->prepareResponse($sUrl, $this->_bAjaxMode, 'redirect'));
  256. exit;
  257. }
  258. else
  259. $this->_redirectAndExit($sUrl);
  260. }
  261. public function editDataForm ($iContentId, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  262. {
  263. if (!$sCheckFunction)
  264. $sCheckFunction = 'checkAllowedEdit';
  265. $CNF = &$this->_oModule->_oConfig->CNF;
  266. // get content data and profile info
  267. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  268. if (!$aContentInfo)
  269. return $bErrorMsg ? MsgBox(_t('_sys_txt_error_entry_is_not_defined')) : '';
  270. // check access
  271. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)))
  272. return $bErrorMsg ? MsgBox($sMsg) : '';
  273. // check and display form
  274. $oForm = $this->getObjectFormEdit($sDisplay);
  275. if (!$oForm)
  276. return $bErrorMsg ? MsgBox(_t('_sys_txt_error_occured')) : '';
  277. $aSpecificValues = array();
  278. if (!empty($CNF['OBJECT_METATAGS'])) {
  279. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  280. if ($oMetatags->locationsIsEnabled())
  281. $aSpecificValues = $oMetatags->locationGet($iContentId, empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
  282. }
  283. $oForm->initChecker($aContentInfo, $aSpecificValues);
  284. if (!$oForm->isSubmittedAndValid())
  285. return $oForm->getCode();
  286. // update data in the DB
  287. $aTrackTextFieldsChanges = null;
  288. $this->onDataEditBefore ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  289. if (!$oForm->update ($aContentInfo[$CNF['FIELD_ID']], array(), $aTrackTextFieldsChanges)) {
  290. if (!$oForm->isValid())
  291. return $oForm->getCode();
  292. else
  293. return MsgBox(_t('_sys_txt_error_entry_update'));
  294. }
  295. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  296. $sResult = $this->onDataEditAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  297. if ($sResult)
  298. return $sResult;
  299. /*
  300. * Process metas.
  301. * Note. It's essential to process metas a the very end,
  302. * because all data related to an entry should be already
  303. * processed and are ready to be passed to alert.
  304. */
  305. $this->_oModule->processMetasEdit($iContentId, $oForm);
  306. // Perform ACL action
  307. $this->_oModule->$sCheckFunction($aContentInfo, true);
  308. // Create alert about the completed action.
  309. $this->_oModule->alertAfterEdit($aContentInfo);
  310. // Redirect
  311. $this->redirectAfterEdit($aContentInfo);
  312. }
  313. protected function redirectAfterEdit($aContentInfo)
  314. {
  315. $CNF = &$this->_oModule->_oConfig->CNF;
  316. $sUrl = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']];
  317. bx_alert($this->_oModule->getName(), 'redirect_after_edit', 0, false, array(
  318. 'content' => $aContentInfo,
  319. 'override_result' => &$sUrl,
  320. ));
  321. $this->_redirectAndExit($sUrl);
  322. }
  323. public function deleteDataForm ($iContentId, $sDisplay = false, $sCheckFunction = false)
  324. {
  325. if (!$sCheckFunction)
  326. $sCheckFunction = 'checkAllowedDelete';
  327. $CNF = &$this->_oModule->_oConfig->CNF;
  328. // get content data and profile info
  329. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  330. if (!$aContentInfo)
  331. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  332. // check access
  333. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)))
  334. return MsgBox($sMsg);
  335. // check and display form
  336. $oForm = $this->getObjectFormDelete($sDisplay);
  337. if (!$oForm)
  338. return MsgBox(_t('_sys_txt_error_occured'));
  339. $oForm->initChecker($aContentInfo);
  340. if (!$oForm->isSubmittedAndValid())
  341. return $oForm->getCode();
  342. if ($sError = $this->deleteData($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile, $oForm))
  343. return MsgBox($sError);
  344. // perform action
  345. $this->_oModule->$sCheckFunction($aContentInfo, true);
  346. // redirect
  347. $this->redirectAfterDelete($aContentInfo);
  348. }
  349. protected function redirectAfterDelete($aContentInfo)
  350. {
  351. $CNF = &$this->_oModule->_oConfig->CNF;
  352. $sUrl = $CNF['URL_HOME'];
  353. $aMarkers = array(
  354. 'account_id' => getLoggedId(),
  355. 'profile_id' => bx_get_logged_profile_id(),
  356. );
  357. bx_alert($this->_oModule->getName(), 'redirect_after_delete', 0, false, array(
  358. 'content' => $aContentInfo,
  359. 'markers' => &$aMarkers,
  360. 'override_result' => &$sUrl,
  361. ));
  362. $this->_redirectAndExit($sUrl, true, $aMarkers);
  363. }
  364. /**
  365. * Delete data entry
  366. * @param $iContentId entry id
  367. * @param $oForm optional content info array
  368. * @param $aContentInfo optional content info array
  369. * @param $oProfile optional content author profile
  370. * @return error string on error or empty string on success
  371. */
  372. public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
  373. {
  374. $CNF = &$this->_oModule->_oConfig->CNF;
  375. if (!$aContentInfo || !$oProfile)
  376. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  377. if (!$aContentInfo)
  378. return _t('_sys_txt_error_entry_is_not_defined');
  379. if (!$oForm)
  380. $oForm = $this->getObjectFormDelete();
  381. if (!$oForm->delete ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo))
  382. return _t('_sys_txt_error_entry_delete');
  383. // remove data from nested forms
  384. $aNestedForms = BxDolFormQuery::getNestedFormObjects($oForm->aParams['object']);
  385. foreach ($aNestedForms as $aNestedForm) {
  386. BxDolFormQuery::deleteDataFromNestedForm($aNestedForm['table'], $iContentId);
  387. }
  388. if ($sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile))
  389. return $sResult;
  390. // create an alert
  391. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']], false, array(
  392. 'content' => &$aContentInfo
  393. ));
  394. return '';
  395. }
  396. public function viewDataForm ($iContentId, $sDisplay = false)
  397. {
  398. $CNF = &$this->_oModule->_oConfig->CNF;
  399. // get content data and profile info
  400. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  401. if (!$aContentInfo)
  402. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  403. // check access
  404. if ($sMsg = $this->_processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile))
  405. return MsgBox($sMsg);
  406. // get form
  407. $oForm = $this->getObjectFormView($sDisplay);
  408. if (!$oForm)
  409. return MsgBox(_t('_sys_txt_error_occured'));
  410. // process metatags
  411. if (!empty($CNF['OBJECT_METATAGS'])) {
  412. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  413. if ($oMetatags->keywordsIsEnabled()) {
  414. $aFields = $oMetatags->metaFields($aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']);
  415. $oForm->setMetatagsKeywordsData($iContentId, $aFields, $oMetatags);
  416. }
  417. }
  418. // display profile
  419. $oForm->initChecker($aContentInfo);
  420. return $oForm->getCode();
  421. }
  422. protected function _processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile)
  423. {
  424. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  425. return $sMsg;
  426. return '';
  427. }
  428. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  429. {
  430. $CNF = &$this->_oModule->_oConfig->CNF;
  431. if(($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  432. $oPrivacy->deleteGroupCustomByContentId($iContentId);
  433. bx_audit(
  434. $iContentId,
  435. $this->_oModule->getName(),
  436. '_sys_audit_action_detete_content',
  437. $this->_oModule->_prepareAuditParams($aContentInfo)
  438. );
  439. return '';
  440. }
  441. public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges, &$oProfile, &$oForm)
  442. {
  443. $CNF = &$this->_oModule->_oConfig->CNF;
  444. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
  445. $oForm->addTrackFields($CNF['FIELD_STATUS'], $aContentInfo);
  446. }
  447. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  448. {
  449. $CNF = &$this->_oModule->_oConfig->CNF;
  450. /*
  451. * Load update data.
  452. */
  453. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  454. if(isset($CNF['FIELD_PHOTO']))
  455. $oForm->processFiles ($CNF['FIELD_PHOTO'], $iContentId, false);
  456. if(isset($CNF['FIELD_STATUS']) && ($aTrackResult = $oForm->isTrackFieldChanged($CNF['FIELD_STATUS'], true)) !== false)
  457. if($aTrackResult['old'] == 'failed' && $aTrackResult['new'] == 'active')
  458. $this->_oModule->alertAfterAdd($aContentInfo);
  459. if(isset($CNF['FIELD_ALLOW_VIEW_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  460. $oPrivacy->reassociateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  461. bx_audit(
  462. $iContentId,
  463. $this->_oModule->getName(),
  464. '_sys_audit_action_edit_content',
  465. $this->_oModule->_prepareAuditParams($aContentInfo)
  466. );
  467. return '';
  468. }
  469. public function onDataAddAfter ($iAccountId, $iContentId)
  470. {
  471. $CNF = &$this->_oModule->_oConfig->CNF;
  472. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  473. if(($oForm = $this->getObjectFormAdd()) !== false) {
  474. if(isset($CNF['FIELD_PHOTO']))
  475. $oForm->processFiles($CNF['FIELD_PHOTO'], $iContentId, true);
  476. }
  477. if(isset($CNF['FIELD_ALLOW_VIEW_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  478. $oPrivacy->associateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  479. bx_audit(
  480. $iContentId,
  481. $this->_oModule->getName(),
  482. '_sys_audit_action_add_content',
  483. $this->_oModule->_prepareAuditParams($aContentInfo)
  484. );
  485. return '';
  486. }
  487. protected function prepareCustomRedirectUrl($s, $aContentInfo)
  488. {
  489. $CNF = &$this->_oModule->_oConfig->CNF;
  490. $oProfile = BxDolProfile::getInstanceByContentAndType($aContentInfo[$CNF['FIELD_ID']], $this->_oModule->getName());
  491. $aMarkers = array(
  492. '{profile_id}',
  493. '{content_id}',
  494. '{module}',
  495. );
  496. $aReplacements = array(
  497. $oProfile ? $oProfile->id() : 0,
  498. $aContentInfo[$CNF['FIELD_ID']],
  499. $this->_oModule->getName(),
  500. );
  501. $s = str_replace($aMarkers, $aReplacements, $s);
  502. $s = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($s));
  503. return $s;
  504. }
  505. protected function prepareResponse($mixedResponse, $bAsJson = false, $sKey = 'msg', $aAdditional = array())
  506. {
  507. if(!$bAsJson)
  508. return $mixedResponse;
  509. $aResponse = array(
  510. $sKey => $mixedResponse,
  511. '_dt' => 'json'
  512. );
  513. if(!empty($aAdditional) && is_array($aAdditional))
  514. $aResponse = array_merge($aResponse, $aAdditional);
  515. return $aResponse;
  516. }
  517. protected function _setAbsoluteActionUrl($sType, &$oForm)
  518. {
  519. $CNF = &$this->_oModule->_oConfig->CNF;
  520. $sKeyUri = 'URI_' . strtoupper($sType) . '_ENTRY';
  521. if(empty($CNF[$sKeyUri]))
  522. return;
  523. $oForm->setAbsoluteActionUrl(bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF[$sKeyUri])));
  524. }
  525. }
  526. /** @} */