BxBaseModGeneralFormsEntryHelper.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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. // get content data and profile info
  109. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  110. if (!$aContentInfo)
  111. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  112. // check access
  113. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  114. return MsgBox($sMsg);
  115. $oForm = $this->getObjectFormView();
  116. if (!$oForm)
  117. return '';
  118. $oForm->initChecker($aContentInfo);
  119. if(!empty($CNF['FIELD_TEXT']) && !$oForm->isInputVisible($CNF['FIELD_TEXT']))
  120. return '';
  121. return $this->_oModule->_oTemplate->entryText($aContentInfo);
  122. }
  123. public function addData ($iProfile, $aValues, $sDisplay = false)
  124. {
  125. $CNF = &$this->_oModule->_oConfig->CNF;
  126. // check and display form
  127. $oForm = $this->getObjectFormAdd($sDisplay);
  128. if (!$oForm)
  129. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  130. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  131. $oForm->aParams['csrf']['disable'] = true;
  132. if(!empty($oForm->aParams['db']['submit_name'])) {
  133. $sSubmitName = false;
  134. if (is_array($oForm->aParams['db']['submit_name'])) {
  135. foreach ($oForm->aParams['db']['submit_name'] as $sVal) {
  136. if (isset($oForm->aInputs[$sVal])) {
  137. $sSubmitName = $sVal;
  138. break;
  139. }
  140. }
  141. }
  142. else {
  143. $sSubmitName = $oForm->aParams['db']['submit_name'];
  144. }
  145. if ($sSubmitName && isset($oForm->aInputs[$sSubmitName]))
  146. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  147. }
  148. $oForm->initChecker(array(), $aValues);
  149. if (!$oForm->isSubmittedAndValid()) {
  150. $aErrors = array();
  151. array_walk($oForm->aInputs, function($aInput, $sKey) use (&$aErrors) {
  152. if(!empty($aInput['error']))
  153. $aErrors[$sKey] = $aInput['error'];
  154. });
  155. return array('code' => 2, 'message' => '_sys_txt_error_occured', 'errors' => $aErrors);
  156. }
  157. // insert data into database
  158. $aValsToAdd = array ();
  159. if(isset($CNF['FIELD_AUTHOR']))
  160. $aValsToAdd[$CNF['FIELD_AUTHOR']] = $iProfile;
  161. $iContentId = $oForm->insert($aValsToAdd);
  162. if (!$iContentId) {
  163. if (!$oForm->isValid())
  164. return array('code' => 2, 'message' => '_sys_txt_error_occured');
  165. else
  166. return array('code' => 3, 'message' => '_sys_txt_error_entry_creation');
  167. }
  168. $sResult = $this->onDataAddAfter(BxDolProfile::getInstance($iProfile)->getAccountId(), $iContentId);
  169. if($sResult)
  170. return array('code' => 4, 'message' => $sResult);
  171. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  172. /*
  173. * Process metas.
  174. * Note. It's essential to process metas a the very end,
  175. * because all data related to an entry should be already
  176. * processed and are ready to be passed to alert.
  177. */
  178. $this->_oModule->processMetasAdd($iContentId);
  179. /*
  180. * Create alert about the completed action.
  181. */
  182. $this->_oModule->alertAfterAdd($aContentInfo);
  183. return array('code' => 0, 'message' => '', 'content' => $aContentInfo);
  184. }
  185. public function addDataForm ($sDisplay = false, $sCheckFunction = false)
  186. {
  187. if (!$sCheckFunction)
  188. $sCheckFunction = 'checkAllowedAdd';
  189. $CNF = &$this->_oModule->_oConfig->CNF;
  190. $bAsJson = false;
  191. // get form object
  192. $oForm = $this->getObjectFormAdd($sDisplay);
  193. if (!$oForm)
  194. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_occured')), $bAsJson, 'msg');
  195. $bAsJson = $this->_bAjaxMode && $oForm->isSubmitted();
  196. // check access
  197. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction())) {
  198. $oProfile = BxDolProfile::getInstance();
  199. 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
  200. return $this->prepareResponse(MsgBox(_t('_sys_txt_access_denied')), $bAsJson, 'msg');
  201. else
  202. return $this->prepareResponse(MsgBox($sMsg), $bAsJson, 'msg');
  203. }
  204. // check and display form
  205. $oForm->initChecker();
  206. if (!$oForm->isSubmittedAndValid())
  207. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  208. 'form_id' => $oForm->getId()
  209. ));
  210. // insert data into database
  211. $aValsToAdd = array ();
  212. $iContentId = $oForm->insert ($aValsToAdd);
  213. if (!$iContentId) {
  214. if (!$oForm->isValid())
  215. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  216. 'form_id' => $oForm->getId()
  217. ));
  218. else
  219. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_entry_creation')), $bAsJson, 'msg');
  220. }
  221. $sResult = $this->onDataAddAfter (getLoggedId(), $iContentId);
  222. if ($sResult)
  223. return $this->prepareResponse($sResult, $bAsJson, 'msg');
  224. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  225. /*
  226. * Process metas.
  227. * Note. It's essential to process metas a the very end,
  228. * because all data related to an entry should be already
  229. * processed and are ready to be passed to alert.
  230. */
  231. $this->_oModule->processMetasAdd($iContentId);
  232. // Perform ACL action
  233. $this->_oModule->$sCheckFunction(true);
  234. // Create alert about the completed action.
  235. $this->_oModule->alertAfterAdd($aContentInfo);
  236. // Redirect
  237. $this->redirectAfterAdd($aContentInfo);
  238. }
  239. public function redirectAfterAdd($aContentInfo, $sUrl = '')
  240. {
  241. $CNF = &$this->_oModule->_oConfig->CNF;
  242. if ($sUrl == '')
  243. $sUrl = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']];
  244. bx_alert($this->_oModule->getName(), 'redirect_after_add', 0, false, array(
  245. 'ajax_mode' => $this->_bAjaxMode,
  246. 'content' => $aContentInfo,
  247. 'override_result' => &$sUrl,
  248. ));
  249. if($this->_bAjaxMode) {
  250. echoJson($this->prepareResponse($sUrl, $this->_bAjaxMode, 'redirect'));
  251. exit;
  252. }
  253. else
  254. $this->_redirectAndExit($sUrl);
  255. }
  256. public function editDataForm ($iContentId, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  257. {
  258. if (!$sCheckFunction)
  259. $sCheckFunction = 'checkAllowedEdit';
  260. $CNF = &$this->_oModule->_oConfig->CNF;
  261. // get content data and profile info
  262. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  263. if (!$aContentInfo)
  264. return $bErrorMsg ? MsgBox(_t('_sys_txt_error_entry_is_not_defined')) : '';
  265. // check access
  266. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)))
  267. return $bErrorMsg ? MsgBox($sMsg) : '';
  268. // check and display form
  269. $oForm = $this->getObjectFormEdit($sDisplay);
  270. if (!$oForm)
  271. return $bErrorMsg ? MsgBox(_t('_sys_txt_error_occured')) : '';
  272. $aSpecificValues = array();
  273. if (!empty($CNF['OBJECT_METATAGS'])) {
  274. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  275. if ($oMetatags->locationsIsEnabled())
  276. $aSpecificValues = $oMetatags->locationGet($iContentId, empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
  277. }
  278. $oForm->initChecker($aContentInfo, $aSpecificValues);
  279. if (!$oForm->isSubmittedAndValid())
  280. return $oForm->getCode();
  281. // update data in the DB
  282. $aTrackTextFieldsChanges = null;
  283. $this->onDataEditBefore ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  284. if (!$oForm->update ($aContentInfo[$CNF['FIELD_ID']], array(), $aTrackTextFieldsChanges)) {
  285. if (!$oForm->isValid())
  286. return $oForm->getCode();
  287. else
  288. return MsgBox(_t('_sys_txt_error_entry_update'));
  289. }
  290. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  291. $sResult = $this->onDataEditAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  292. if ($sResult)
  293. return $sResult;
  294. /*
  295. * Process metas.
  296. * Note. It's essential to process metas a the very end,
  297. * because all data related to an entry should be already
  298. * processed and are ready to be passed to alert.
  299. */
  300. $this->_oModule->processMetasEdit($iContentId, $oForm);
  301. // Perform ACL action
  302. $this->_oModule->$sCheckFunction($aContentInfo, true);
  303. // Create alert about the completed action.
  304. $this->_oModule->alertAfterEdit($aContentInfo);
  305. // Redirect
  306. $this->redirectAfterEdit($aContentInfo);
  307. }
  308. protected function redirectAfterEdit($aContentInfo)
  309. {
  310. $CNF = &$this->_oModule->_oConfig->CNF;
  311. $sUrl = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']];
  312. bx_alert($this->_oModule->getName(), 'redirect_after_edit', 0, false, array(
  313. 'content' => $aContentInfo,
  314. 'override_result' => &$sUrl,
  315. ));
  316. $this->_redirectAndExit($sUrl);
  317. }
  318. public function deleteDataForm ($iContentId, $sDisplay = false, $sCheckFunction = false)
  319. {
  320. if (!$sCheckFunction)
  321. $sCheckFunction = 'checkAllowedDelete';
  322. $CNF = &$this->_oModule->_oConfig->CNF;
  323. // get content data and profile info
  324. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  325. if (!$aContentInfo)
  326. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  327. // check access
  328. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)))
  329. return MsgBox($sMsg);
  330. // check and display form
  331. $oForm = $this->getObjectFormDelete($sDisplay);
  332. if (!$oForm)
  333. return MsgBox(_t('_sys_txt_error_occured'));
  334. $oForm->initChecker($aContentInfo);
  335. if (!$oForm->isSubmittedAndValid())
  336. return $oForm->getCode();
  337. if ($sError = $this->deleteData($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile, $oForm))
  338. return MsgBox($sError);
  339. // perform action
  340. $this->_oModule->$sCheckFunction($aContentInfo, true);
  341. // redirect
  342. $this->redirectAfterDelete($aContentInfo);
  343. }
  344. protected function redirectAfterDelete($aContentInfo)
  345. {
  346. $CNF = &$this->_oModule->_oConfig->CNF;
  347. $sUrl = $CNF['URL_HOME'];
  348. $aMarkers = array(
  349. 'account_id' => getLoggedId(),
  350. 'profile_id' => bx_get_logged_profile_id(),
  351. );
  352. bx_alert($this->_oModule->getName(), 'redirect_after_delete', 0, false, array(
  353. 'content' => $aContentInfo,
  354. 'markers' => &$aMarkers,
  355. 'override_result' => &$sUrl,
  356. ));
  357. $this->_redirectAndExit($sUrl, true, $aMarkers);
  358. }
  359. /**
  360. * Delete data entry
  361. * @param $iContentId entry id
  362. * @param $oForm optional content info array
  363. * @param $aContentInfo optional content info array
  364. * @param $oProfile optional content author profile
  365. * @return error string on error or empty string on success
  366. */
  367. public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
  368. {
  369. $CNF = &$this->_oModule->_oConfig->CNF;
  370. if (!$aContentInfo || !$oProfile)
  371. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  372. if (!$aContentInfo)
  373. return _t('_sys_txt_error_entry_is_not_defined');
  374. if (!$oForm)
  375. $oForm = $this->getObjectFormDelete();
  376. if (!$oForm->delete ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo))
  377. return _t('_sys_txt_error_entry_delete');
  378. // remove data from nested forms
  379. $aNestedForms = BxDolFormQuery::getNestedFormObjects($oForm->aParams['object']);
  380. foreach ($aNestedForms as $aNestedForm) {
  381. BxDolFormQuery::deleteDataFromNestedForm($aNestedForm['table'], $iContentId);
  382. }
  383. if ($sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile))
  384. return $sResult;
  385. // create an alert
  386. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']], false, array(
  387. 'content' => &$aContentInfo
  388. ));
  389. return '';
  390. }
  391. public function viewDataForm ($iContentId, $sDisplay = false)
  392. {
  393. $CNF = &$this->_oModule->_oConfig->CNF;
  394. // get content data and profile info
  395. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  396. if (!$aContentInfo)
  397. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  398. // check access
  399. if ($sMsg = $this->_processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile))
  400. return MsgBox($sMsg);
  401. // get form
  402. $oForm = $this->getObjectFormView($sDisplay);
  403. if (!$oForm)
  404. return MsgBox(_t('_sys_txt_error_occured'));
  405. // process metatags
  406. if (!empty($CNF['OBJECT_METATAGS'])) {
  407. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  408. if ($oMetatags->keywordsIsEnabled()) {
  409. $aFields = $oMetatags->metaFields($aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']);
  410. $oForm->setMetatagsKeywordsData($iContentId, $aFields, $oMetatags);
  411. }
  412. }
  413. // display profile
  414. $oForm->initChecker($aContentInfo);
  415. return $oForm->getCode();
  416. }
  417. protected function _processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile)
  418. {
  419. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  420. return $sMsg;
  421. return '';
  422. }
  423. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  424. {
  425. $CNF = &$this->_oModule->_oConfig->CNF;
  426. if(($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  427. $oPrivacy->deleteGroupCustomByContentId($iContentId);
  428. bx_audit(
  429. $iContentId,
  430. $this->_oModule->getName(),
  431. '_sys_audit_action_detete_content',
  432. $this->_oModule->_prepareAuditParams($aContentInfo)
  433. );
  434. return '';
  435. }
  436. public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges, &$oProfile, &$oForm)
  437. {
  438. $CNF = &$this->_oModule->_oConfig->CNF;
  439. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
  440. $oForm->addTrackFields($CNF['FIELD_STATUS'], $aContentInfo);
  441. }
  442. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  443. {
  444. $CNF = &$this->_oModule->_oConfig->CNF;
  445. /*
  446. * Load update data.
  447. */
  448. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  449. if(isset($CNF['FIELD_PHOTO']))
  450. $oForm->processFiles ($CNF['FIELD_PHOTO'], $iContentId, false);
  451. if(isset($CNF['FIELD_STATUS']) && ($aTrackResult = $oForm->isTrackFieldChanged($CNF['FIELD_STATUS'], true)) !== false)
  452. if($aTrackResult['old'] == 'failed' && $aTrackResult['new'] == 'active')
  453. $this->_oModule->alertAfterAdd($aContentInfo);
  454. if(isset($CNF['FIELD_ALLOW_VIEW_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  455. $oPrivacy->reassociateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  456. bx_audit(
  457. $iContentId,
  458. $this->_oModule->getName(),
  459. '_sys_audit_action_edit_content',
  460. $this->_oModule->_prepareAuditParams($aContentInfo)
  461. );
  462. return '';
  463. }
  464. public function onDataAddAfter ($iAccountId, $iContentId)
  465. {
  466. $CNF = &$this->_oModule->_oConfig->CNF;
  467. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  468. if(($oForm = $this->getObjectFormAdd()) !== false) {
  469. if(isset($CNF['FIELD_PHOTO']))
  470. $oForm->processFiles($CNF['FIELD_PHOTO'], $iContentId, true);
  471. }
  472. if(isset($CNF['FIELD_ALLOW_VIEW_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  473. $oPrivacy->associateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  474. bx_audit(
  475. $iContentId,
  476. $this->_oModule->getName(),
  477. '_sys_audit_action_add_content',
  478. $this->_oModule->_prepareAuditParams($aContentInfo)
  479. );
  480. return '';
  481. }
  482. protected function prepareCustomRedirectUrl($s, $aContentInfo)
  483. {
  484. $CNF = &$this->_oModule->_oConfig->CNF;
  485. $oProfile = BxDolProfile::getInstanceByContentAndType($aContentInfo[$CNF['FIELD_ID']], $this->_oModule->getName());
  486. $aMarkers = array(
  487. '{profile_id}',
  488. '{content_id}',
  489. '{module}',
  490. );
  491. $aReplacements = array(
  492. $oProfile ? $oProfile->id() : 0,
  493. $aContentInfo[$CNF['FIELD_ID']],
  494. $this->_oModule->getName(),
  495. );
  496. $s = str_replace($aMarkers, $aReplacements, $s);
  497. $s = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($s));
  498. return $s;
  499. }
  500. protected function prepareResponse($mixedResponse, $bAsJson = false, $sKey = 'msg', $aAdditional = array())
  501. {
  502. if(!$bAsJson)
  503. return $mixedResponse;
  504. $aResponse = array(
  505. $sKey => $mixedResponse,
  506. '_dt' => 'json'
  507. );
  508. if(!empty($aAdditional) && is_array($aAdditional))
  509. $aResponse = array_merge($aResponse, $aAdditional);
  510. return $aResponse;
  511. }
  512. protected function _setAbsoluteActionUrl($sType, &$oForm)
  513. {
  514. $CNF = &$this->_oModule->_oConfig->CNF;
  515. $sKeyUri = 'URI_' . strtoupper($sType) . '_ENTRY';
  516. if(empty($CNF[$sKeyUri]))
  517. return;
  518. $oForm->setAbsoluteActionUrl(bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF[$sKeyUri])));
  519. }
  520. }
  521. /** @} */