BxBaseModGeneralFormEntry.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  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. * Create/edit entry form
  13. */
  14. class BxBaseModGeneralFormEntry extends BxTemplFormView
  15. {
  16. protected static $_isCssJsGeneralModuleAdded = false;
  17. protected $MODULE;
  18. protected $_oModule;
  19. protected $_aMetatagsFieldsWithKeywords = array();
  20. protected $_oMetatagsObject = null;
  21. protected $_oMetatagsContentId = 0;
  22. protected $_sGhostTemplate = 'form_ghost_template.html';
  23. protected $_aTrackFieldsChanges;
  24. protected $_iContentId;
  25. protected $_bAllowChangeUserForAdmins;
  26. public function __construct($aInfo, $oTemplate = false)
  27. {
  28. if (!isset($this->_bAllowChangeUserForAdmins))
  29. $this->_bAllowChangeUserForAdmins = true;
  30. parent::__construct($aInfo, $oTemplate);
  31. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  32. $this->_aTrackFieldsChanges = array();
  33. $CNF = &$this->_oModule->_oConfig->CNF;
  34. if (isset($CNF['FIELD_ADDED']) && isset($this->aInputs[$CNF['FIELD_ADDED']])) {
  35. $this->aInputs[$CNF['FIELD_ADDED']]['date_filter'] = BX_DATA_INT;
  36. $this->aInputs[$CNF['FIELD_ADDED']]['date_format'] = BX_FORMAT_DATE;
  37. }
  38. if (isset($CNF['FIELD_CHANGED']) && isset($this->aInputs[$CNF['FIELD_CHANGED']])) {
  39. $this->aInputs[$CNF['FIELD_CHANGED']]['date_filter'] = BX_DATA_INT;
  40. $this->aInputs[$CNF['FIELD_CHANGED']]['date_format'] = BX_FORMAT_DATE;
  41. }
  42. if (isset($CNF['FIELD_TEXT']) && isset($this->aInputs[$CNF['FIELD_TEXT']]) && isset($CNF['FIELD_TEXT_ID'])) {
  43. $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] = array_merge (
  44. array ('id' => $CNF['FIELD_TEXT_ID']),
  45. is_array($this->aInputs[$CNF['FIELD_TEXT']]['attrs']) ? $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] : array ()
  46. );
  47. }
  48. if (isset($CNF['FIELD_LABELS']) && isset($this->aInputs[$CNF['FIELD_LABELS']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->keywordsIsEnabled()) {
  49. $this->aInputs[$CNF['FIELD_LABELS']]['meta_object'] = $CNF['OBJECT_METATAGS'];
  50. }
  51. if (isset($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']])) {
  52. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = true;
  53. }
  54. // add ability to change author by admins in some apps
  55. if (
  56. $this->_oModule->checkAllowedEditAnyEntry(false) === CHECK_ACTION_RESULT_ALLOWED &&
  57. isset($CNF['FIELD_AUTHOR']) &&
  58. (
  59. (isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']) && $this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']) ||
  60. (isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']) && $this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])
  61. ) &&
  62. $this->_bAllowChangeUserForAdmins){
  63. $this->aInputs = array_merge([
  64. $CNF['FIELD_AUTHOR'] => [
  65. 'type' => 'custom',
  66. 'name' => $CNF['FIELD_AUTHOR'],
  67. 'db' => ['pass' => 'Xss'],
  68. 'caption' => '_sys_form_input_caption_author'
  69. ],
  70. ], $this->aInputs);
  71. }
  72. if (isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  73. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  74. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  75. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  76. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  77. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  78. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  79. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  80. }
  81. $aPrivacyFields = $this->_getPrivacyFields();
  82. foreach($aPrivacyFields as $sField => $sObject)
  83. $this->_preparePrivacyField($sField, $sObject);
  84. foreach($this->aInputs as $sKey => $aInput) {
  85. if ($aInput['type'] == 'nested_form'){
  86. $this->genGhostTemplateForInputNestedForm ($this->aInputs[$sKey]);
  87. }
  88. }
  89. }
  90. function getCode($bDynamicMode = false)
  91. {
  92. $CNF = &$this->_oModule->_oConfig->CNF;
  93. if(!$bDynamicMode && bx_is_dynamic_request())
  94. $bDynamicMode = true;
  95. $sResult = parent::getCode($bDynamicMode);
  96. $aPrivacyFields = $this->_getPrivacyFields();
  97. foreach($aPrivacyFields as $sField => $sObject)
  98. $this->_addCssJsPrivacyField($sField, $sObject, $bDynamicMode);
  99. if(isset($CNF['PARAM_MULTICAT_ENABLED']) && $CNF['PARAM_MULTICAT_ENABLED'] === true) {
  100. $sInclude2 = '';
  101. $sInclude2 .= $this->_oModule->_oTemplate->addJs(array('BxDolCategories.js'), $bDynamicMode);
  102. $sInclude2 .= $this->_oModule->_oTemplate->addCss(array('categories.css'), $bDynamicMode);
  103. $sResult .= ($bDynamicMode ? $sInclude2 : '') . $this->_oModule->_oTemplate->getJsCode('categories');
  104. }
  105. return $sResult;
  106. }
  107. /**
  108. * Nested forms processing
  109. */
  110. function genInputNestedForm (&$aInput, $sInfo = '', $sError = '')
  111. {
  112. $sUniqId = genRndPwd (8, false);
  113. $aNestedForms = array();
  114. if (!$this->isSubmitted()){
  115. $aNestedValues = $this->_oModule->_oDb->getNestedBy(array('type' => 'content_id', 'id' => $this->_iContentId, 'key_name' => $aInput['ghost_template']['params']['db']['key']), $aInput['ghost_template']['params']['db']['table']);
  116. foreach($aNestedValues as $aNestedValue) {
  117. $aNestedValuesRv = array();
  118. $oForm = $this->getNestedFormObject($aInput);
  119. foreach($aNestedValue as $aNestedKey => $aNestedItem) {
  120. if ($oForm->aParams['db']['key'] == $aNestedKey)
  121. $aNestedValuesRv[$aNestedKey . '[]'] = $aNestedItem;
  122. else
  123. $aNestedValuesRv[$aNestedKey] = $aNestedItem;
  124. }
  125. $oForm->initChecker($aNestedValuesRv);
  126. array_push(
  127. $aNestedForms,
  128. array(
  129. 'key_value' => $aNestedValuesRv[$oForm->aParams['db']['key'] . '[]'],
  130. 'key_name' => $aInput['name'],
  131. 'form_code' => $oForm->genRows(),
  132. 'js_instance_name' => 'oBxNestedForm_' . $sUniqId,
  133. 'nested_type' => $aInput['name'],
  134. )
  135. );
  136. }
  137. }
  138. else{
  139. $aInput['ghost_templates'] = $aInput['ghost_template'];
  140. $this->genGhostTemplateForInputNestedForm ($aInput);
  141. foreach($aInput['ghost_templates'] as $oForm) {
  142. if (isset($oForm->aInputs)){
  143. array_push(
  144. $aNestedForms,
  145. array(
  146. 'key_value' => $oForm->aInputs[$aInput['name']]['value'],
  147. 'key_name' => $aInput['name'],
  148. 'form_code' => $oForm->genRows(),
  149. 'js_instance_name' => 'oBxNestedForm_' . $sUniqId,
  150. 'nested_type' => $aInput['name'],
  151. )
  152. );
  153. }
  154. }
  155. }
  156. return $this->oTemplate->parseHtmlByName('form_field_nested_form.html', array(
  157. 'bx_repeat:items' => $aNestedForms,
  158. 'info' => $sInfo,
  159. 'error' => $sError,
  160. 'uniq_id' => $sUniqId,
  161. 'js_instance_name' => 'oBxNestedForm_' . $sUniqId,
  162. 'options' => json_encode(array(
  163. 'uniq_id' => $sUniqId,
  164. 'js_instance_name' => 'oBxNestedForm_' . $sUniqId,
  165. 'template_ghost' => $this->genGhostTemplate($aInput),
  166. 'form_name' => $aInput['value'],
  167. 'action_uri' => $this->_oModule->_oConfig->getBaseUri(),
  168. 'nested_type' => $aInput['name'],
  169. )),
  170. ));
  171. }
  172. function genNestedForm (&$aInput)
  173. {
  174. $sResult = '';
  175. $aNestedValues = $this->_oModule->_oDb->getNestedBy(array('type' => 'content_id', 'id' => $this->_iContentId, 'key_name' => $aInput['ghost_template']['params']['db']['key']), $aInput['ghost_template']['params']['db']['table']);
  176. foreach($aNestedValues as $aNestedValue) {
  177. $sValue = '';
  178. $aNestedValuesRv = array();
  179. $oForm = $this->getNestedFormObject($aInput, true);
  180. foreach($aNestedValue as $aNestedKey => $aNestedItem) {
  181. if ($oForm->aParams['db']['key'] == $aNestedKey)
  182. $aNestedValuesRv[$aNestedKey . '[]'] = $aNestedItem;
  183. else
  184. $aNestedValuesRv[$aNestedKey] = $aNestedItem;
  185. }
  186. $oForm->initChecker($aNestedValuesRv);
  187. if ($aInput['rateable']){
  188. $sVote = '';
  189. $sVoteBtn = '';
  190. $iId = BxDolFormQuery::getFormField($this->id, $aInput['name'], $this->_iContentId, $aNestedValuesRv[$oForm->aParams['db']['key'] . '[]']);
  191. $oVote = BxDolVote::getObjectInstance($aInput['rateable'], $iId, true, BxDolTemplate::getInstance());
  192. if ($oVote){
  193. $sVote = $oVote->getCounter(array('show_counter_empty' => true, 'show_counter' => true, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode));
  194. $sVoteBtn = $oVote->getElementInline(array('show_counter_empty' => true, 'show_counter' => false, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode));
  195. }
  196. $sValue = $this->oTemplate->parseHtmlByName('form_view_rateable_row.html', array(
  197. 'value' => $oForm->getCode(),
  198. 'rate' => $sVote,
  199. 'rate_btn' => $sVoteBtn
  200. ));
  201. }
  202. else{
  203. $sValue = $oForm->getCode();
  204. }
  205. $sResult .= $this->oTemplate->parseHtmlByName('form_view_nested_row.html', array(
  206. 'value' => $sValue
  207. ));
  208. }
  209. if ($sResult != ''){
  210. return $this->oTemplate->parseHtmlByName('form_view_row.html', array(
  211. 'type' => $aInput['type'],
  212. 'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '',
  213. 'value' => $sResult
  214. ));
  215. }
  216. }
  217. protected function genGhostTemplateForInputNestedForm (&$aInput)
  218. {
  219. $oForm = $this->getNestedFormObject($aInput);
  220. $aInput['ghost_template'] = array (
  221. 'params' => array(
  222. 'nested_form_template' => 'form_field_nested_form_wrapper.html',
  223. 'db' => array(
  224. 'table' => $oForm->aParams['db']['table'],
  225. 'key' => $oForm->aParams['db']['key'],
  226. 'submit_name' => $oForm->aParams['db']['key'],
  227. ),
  228. ),
  229. 'inputs' => $oForm->aInputs
  230. );
  231. }
  232. function getNestedFormObject (&$aInput, $bViewMode = false)
  233. {
  234. $oForm = BxDolForm::getObjectInstance($aInput['value'], $aInput['value'] . ($bViewMode ? '_view' : ''));
  235. foreach($oForm->aInputs as $sKey => $aInput2) {
  236. $sName = $oForm->aInputs[$sKey]['name'];
  237. if (strpos($sName,'[]') === false)
  238. $oForm->aInputs[$sKey]['name'] = $sName . '[]';
  239. }
  240. return $oForm;
  241. }
  242. /**
  243. * Add field(s) which will be tracked during content update.
  244. */
  245. public function addTrackFields($mixedFields, $mixedContent)
  246. {
  247. if(empty($mixedContent) || empty($mixedFields))
  248. return;
  249. if(!is_array($mixedContent)) {
  250. $mixedContent = $this->_oModule->_oDb->getContentInfoById((int)$mixedContent);
  251. if(empty($mixedContent) || !is_array($mixedContent))
  252. return;
  253. }
  254. if(!is_array($mixedFields))
  255. $mixedFields = array($mixedFields);
  256. foreach($mixedFields as $sField) {
  257. if(!isset($mixedContent[$sField]))
  258. continue;
  259. $this->_aTrackFieldsChanges[$sField] = array(
  260. 'old' => $mixedContent[$sField],
  261. );
  262. }
  263. }
  264. /**
  265. * Checks if the field was changed.
  266. */
  267. public function isTrackFieldChanged($sField, $bReturnValues = false)
  268. {
  269. if(!isset($this->_aTrackFieldsChanges[$sField]) || $this->_aTrackFieldsChanges[$sField] === false)
  270. return false;
  271. return $bReturnValues ? $this->_aTrackFieldsChanges[$sField] : true;
  272. }
  273. function initChecker ($aValues = array (), $aSpecificValues = array())
  274. {
  275. $CNF = &$this->_oModule->_oConfig->CNF;
  276. $bValues = $aValues && !empty($aValues['id']);
  277. $this->_iContentId = isset($aValues['id']) ? $aValues['id'] : false;
  278. if (!empty($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && isset($aValues[$CNF['FIELD_ID']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->locationsIsEnabled())
  279. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['value'] = $oMetatags->locationsString($aValues[$CNF['FIELD_ID']], false);
  280. if (isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  281. $aContentInfo = false;
  282. if ($aValues && !empty($aValues['id'])) {
  283. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
  284. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = $aValues['id'];
  285. }
  286. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplate, $this->_getPhotoGhostTmplVars($aContentInfo));
  287. }
  288. if (isset($CNF['FIELD_LABELS']) && isset($this->aInputs[$CNF['FIELD_LABELS']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->keywordsIsEnabled() && !empty($aValues['id'])) {
  289. $this->aInputs[$CNF['FIELD_LABELS']]['content_id'] = $aValues['id'];
  290. if(($aLabels = $oMetatags->keywordsGet($aValues['id'])))
  291. $this->aInputs[$CNF['FIELD_LABELS']]['value'] = array_intersect($aLabels, BxDolLabel::getInstance()->getLabels(array('type' => 'values')));
  292. }
  293. if (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && isset($CNF['FIELD_AUTHOR']) && isset($aValues[$CNF['FIELD_AUTHOR']])) {
  294. $this->aInputs[$CNF['FIELD_ANONYMOUS']]['checked'] = $aValues[$CNF['FIELD_AUTHOR']] < 0;
  295. }
  296. if (isset($CNF['FIELD_MULTICAT']) && isset($this->aInputs[$CNF['FIELD_MULTICAT']]) && $CNF['PARAM_MULTICAT_ENABLED']) {
  297. if ($bValues)
  298. $this->aInputs[$CNF['FIELD_MULTICAT']]['content_id'] = $aValues['id'];
  299. }
  300. $aPrivacyFields = $this->_getPrivacyFields();
  301. foreach($aPrivacyFields as $sField => $sObject)
  302. $this->_preloadPrivacyField($sField, $sObject, $aValues);
  303. if (isset($CNF['FIELD_AUTHOR']) && isset($this->aInputs[$CNF['FIELD_AUTHOR']])){
  304. if (isset($aValues[$CNF['FIELD_AUTHOR']]))
  305. $aValues[$CNF['FIELD_AUTHOR']] = [$aValues[$CNF['FIELD_AUTHOR']]];
  306. else
  307. $aValues[$CNF['FIELD_AUTHOR']] = [bx_get_logged_profile_id()];
  308. }
  309. parent::initChecker ($aValues, $aSpecificValues);
  310. foreach($aPrivacyFields as $sField => $sObject)
  311. $this->_validatePrivacyField($sField, $sObject, $aValues);
  312. }
  313. public function insert ($aValsToAdd = array(), $isIgnore = false)
  314. {
  315. $CNF = &$this->_oModule->_oConfig->CNF;
  316. if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]) && (!isset($this->aInputs[$CNF['FIELD_AUTHOR']]) || empty($this->getCleanValue($CNF['FIELD_AUTHOR']))))
  317. $aValsToAdd[$CNF['FIELD_AUTHOR']] = (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * bx_get_logged_profile_id ();
  318. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]) && empty($this->getCleanValue($CNF['FIELD_ADDED'])))
  319. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  320. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
  321. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  322. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb() && isset($CNF['FIELD_THUMB'])) {
  323. $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
  324. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  325. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  326. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  327. }
  328. if(!empty($CNF['OBJECT_METATAGS']))
  329. $this->_processMetas($aValsToAdd);
  330. if(isset($CNF['FIELD_STATUS']) && !empty($CNF['FIELDS_DELAYED_PROCESSING']) && !empty($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4'])) {
  331. $oTranscoder = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  332. $aFields = $CNF['FIELDS_DELAYED_PROCESSING'];
  333. if(is_string($aFields))
  334. $aFields = explode(',', $aFields);
  335. foreach($aFields as $sField) {
  336. $mixedFieldValues = $this->getCleanValue($sField);
  337. if(empty($mixedFieldValues))
  338. continue;
  339. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sField]['storage_object']);
  340. if(!$oStorage)
  341. continue;
  342. if(!is_array($mixedFieldValues))
  343. $mixedFieldValues = array($mixedFieldValues);
  344. foreach($mixedFieldValues as $mixedFieldValue) {
  345. $aInfo = $oStorage->getFile((int)$mixedFieldValue);
  346. if(empty($aInfo) || !is_array($aInfo))
  347. continue;
  348. if(strncmp($aInfo['mime_type'], 'video/', 6) != 0)
  349. continue;
  350. if($oTranscoder->isFileReady((int)$mixedFieldValue))
  351. continue;
  352. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  353. break 2;
  354. }
  355. }
  356. }
  357. $bMulticatEnabled = $this->_isMulticatEnabled();
  358. if ($bMulticatEnabled)
  359. $this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);
  360. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  361. if(!empty($iContentId)){
  362. foreach($this->aInputs as $aInput) {
  363. if ($aInput['type'] == 'nested_form'){
  364. if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
  365. foreach ($aInput['ghost_template'] as $oFormNested) {
  366. $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
  367. if ($aInput['rateable']){
  368. BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $aValsToAdd[$CNF['FIELD_AUTHOR']], $this->_oModule->getName(), $iNestedContentId);
  369. }
  370. }
  371. }
  372. }
  373. }
  374. if ($bMulticatEnabled)
  375. $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
  376. }
  377. foreach($this->aInputs as $aInput) {
  378. if (isset($aInput['rateable']) && $aInput['rateable'] && $aInput['type'] != 'nested_form'){
  379. BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $aValsToAdd[$CNF['FIELD_AUTHOR']], $this->_oModule->getName());
  380. }
  381. }
  382. return $iContentId;
  383. }
  384. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  385. {
  386. $CNF = &$this->_oModule->_oConfig->CNF;
  387. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  388. if(isset($CNF['FIELD_AUTHOR']) && isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]))
  389. $aValsToAdd[$CNF['FIELD_AUTHOR']] = ($this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * abs($aContentInfo[$CNF['FIELD_AUTHOR']]);
  390. if(isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
  391. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  392. if(CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb($iContentId) && isset($CNF['FIELD_THUMB'])) {
  393. $aThumb = bx_process_input (bx_get($CNF['FIELD_THUMB']), BX_DATA_INT);
  394. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  395. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  396. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  397. }
  398. if(!empty($CNF['OBJECT_METATAGS']))
  399. $this->_processMetas($aValsToAdd);
  400. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
  401. $aValsToAdd[$CNF['FIELD_STATUS']] = 'active';
  402. $bMulticatEnabled = $this->_isMulticatEnabled();
  403. if ($bMulticatEnabled)
  404. $this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);
  405. $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  406. foreach($this->aInputs as $aInput) {
  407. if ($aInput['type'] == 'nested_form'){
  408. if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
  409. foreach ($aInput['ghost_template'] as $oFormNested) {
  410. $iNestedContentId = $oFormNested->aInputs[$aInput['name']]['value'];
  411. if (empty($iNestedContentId)){
  412. $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
  413. if ($aInput['rateable']){
  414. BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $this->_oModule->getName(), $iNestedContentId);
  415. }
  416. }
  417. else{
  418. $oFormNested->update($iNestedContentId, array('content_id' => $iContentId));
  419. }
  420. }
  421. }
  422. }
  423. }
  424. if ($bMulticatEnabled)
  425. $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
  426. foreach($this->aInputs as $aInput) {
  427. if (isset($aInput['rateable']) && $aInput['rateable'] && $aInput['type'] != 'nested_form'){
  428. BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $this->_oModule->getName());
  429. }
  430. }
  431. if($mixedResult !== false)
  432. $this->_processTrackFields($iContentId);
  433. return $mixedResult;
  434. }
  435. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
  436. {
  437. $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId, $this->_isAdmin($iContentId));
  438. }
  439. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  440. {
  441. $CNF = &$this->_oModule->_oConfig->CNF;
  442. return array (
  443. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  444. 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  445. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  446. 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  447. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
  448. 'bx_if:set_thumb' => array (
  449. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb($this->aInputs[$CNF['FIELD_PHOTO']]['content_id']),
  450. 'content' => array (
  451. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
  452. 'txt_pict_use_as_thumb' => _t(!empty($CNF['T']['txt_pict_use_as_thumb']) ? $CNF['T']['txt_pict_use_as_thumb'] : '_sys_txt_form_entry_input_picture_use_as_thumb')
  453. ),
  454. ),
  455. );
  456. }
  457. function delete ($iContentId, $aContentInfo = array())
  458. {
  459. $CNF = &$this->_oModule->_oConfig->CNF;
  460. // delete associated files
  461. $a = array('OBJECT_STORAGE', 'OBJECT_STORAGE_FILES', 'OBJECT_STORAGE_PHOTOS', 'OBJECT_STORAGE_VIDEOS', 'OBJECT_STORAGE_SOUNDS');
  462. foreach ($a as $k) {
  463. if (!empty($CNF[$k])) {
  464. $oStorage = BxDolStorage::getObjectInstance($CNF[$k]);
  465. if ($oStorage)
  466. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  467. }
  468. }
  469. // delete associated objects data
  470. if (!empty($CNF['OBJECT_VIEWS'])) {
  471. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  472. if ($o) $o->onObjectDelete();
  473. }
  474. if (!empty($CNF['OBJECT_VOTES'])) {
  475. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  476. if ($o) $o->onObjectDelete();
  477. }
  478. if (!empty($CNF['OBJECT_SCORES'])) {
  479. $o = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  480. if ($o) $o->onObjectDelete();
  481. }
  482. if (!empty($CNF['OBJECT_COMMENTS'])) {
  483. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  484. if ($o) $o->onObjectDelete();
  485. }
  486. if (!empty($CNF['OBJECT_METATAGS'])) {
  487. $o = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  488. if ($o) $o->onDeleteContent($iContentId);
  489. }
  490. // delete SEO links
  491. BxDolPage::deleteSeoLink ($this->_oModule->getName(), $this->_oModule->getName(), $iContentId);
  492. // delete db record
  493. BxDolFormQuery::removeFormField($this->id, $iContentId);
  494. return parent::delete($iContentId);
  495. }
  496. protected function _isAdmin ($iContentId = 0)
  497. {
  498. return $this->_oModule->_isModerator();
  499. }
  500. public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
  501. {
  502. $CNF = &$this->_oModule->_oConfig->CNF;
  503. if (!isset($this->aInputs[$sFieldFile]))
  504. return true;
  505. $mixedFileIds = $this->getCleanValue($sFieldFile);
  506. if(!$mixedFileIds)
  507. return true;
  508. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
  509. if (!$oStorage)
  510. return false;
  511. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  512. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true, $this->_isAdmin($iContentId));
  513. if (!$aGhostFiles)
  514. return true;
  515. foreach ($aGhostFiles as $aFile) {
  516. if (is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
  517. continue;
  518. if ($aFile['private'])
  519. $oStorage->setFilePrivate ($aFile['id'], 1);
  520. if ($iContentId)
  521. $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
  522. }
  523. return true;
  524. }
  525. function _deleteFile ($iFileId, $sStorage = '')
  526. {
  527. $CNF = &$this->_oModule->_oConfig->CNF;
  528. if (!$iFileId)
  529. return true;
  530. $sStorage = !empty($sStorage) ? $sStorage : $CNF['OBJECT_STORAGE'];
  531. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  532. if (!$oStorage)
  533. return false;
  534. if (!$oStorage->getFile($iFileId))
  535. return true;
  536. $iProfileId = bx_get_logged_profile_id();
  537. return $oStorage->deleteFile($iFileId, $iProfileId);
  538. }
  539. function addCssJs ()
  540. {
  541. if ((!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) && !self::$_isCssJsGeneralModuleAdded) {
  542. $this->_oModule->_oTemplate->addCss('forms.css');
  543. $this->_oModule->_oTemplate->addJs('modules/base/general/js/|forms.js');
  544. self::$_isCssJsGeneralModuleAdded = true;
  545. }
  546. return parent::addCssJs ();
  547. }
  548. function genViewRowValue(&$aInput)
  549. {
  550. $s = parent::genViewRowValue($aInput);
  551. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
  552. $s = $this->_oMetatagsObject->metaParse($this->_oMetatagsContentId, $s);
  553. return $s;
  554. }
  555. function genViewRowWrapped(&$aInput)
  556. {
  557. $sResult = parent::genViewRowWrapped($aInput);
  558. if (!$aInput['rateable']){
  559. return $sResult;
  560. }
  561. $sValue = $this->genViewRowValue($aInput);
  562. if (null === $sValue)
  563. return '';
  564. // process rateable fields
  565. $iId = BxDolFormQuery::getFormField($this->id, $aInput['name'], $this->_iContentId);
  566. $sVote = '';
  567. $oVote = BxDolVote::getObjectInstance($aInput['rateable'], $iId, true, BxDolTemplate::getInstance());
  568. if ($oVote){
  569. $sVote = $oVote->getCounter(array('show_counter_empty' => true, 'show_counter' => true, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode));
  570. $sVoteBtn = $oVote->getElementInline(array('show_counter_empty' => true, 'show_counter' => false, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode));
  571. return $this->oTemplate->parseHtmlByName('form_view_rateable_row.html', array(
  572. 'value' => $sResult,
  573. 'rate' => $sVote,
  574. 'rate_btn' => $sVoteBtn
  575. ));
  576. }
  577. return $sResult;
  578. }
  579. function setMetatagsKeywordsData($iId, $a, $o)
  580. {
  581. $this->_oMetatagsContentId = $iId;
  582. $this->_aMetatagsFieldsWithKeywords = $a;
  583. $this->_oMetatagsObject = $o;
  584. }
  585. function getContentOwnerProfileId ($iContentId)
  586. {
  587. return $this->_oModule->serviceGetContentOwnerProfileId($iContentId);
  588. }
  589. protected function _processTrackFields($mixedContent)
  590. {
  591. if(empty($mixedContent) || empty($this->_aTrackFieldsChanges))
  592. return;
  593. if(!is_array($mixedContent)) {
  594. $mixedContent = $this->_oModule->_oDb->getContentInfoById((int)$mixedContent);
  595. if(empty($mixedContent) || !is_array($mixedContent))
  596. return;
  597. }
  598. foreach($this->_aTrackFieldsChanges as $sField => $aValues)
  599. if($mixedContent[$sField] == $aValues['old'])
  600. $this->_aTrackFieldsChanges[$sField] = false;
  601. else
  602. $this->_aTrackFieldsChanges[$sField]['new'] = $mixedContent[$sField];
  603. }
  604. protected function _processMetas(&$aValsToAdd)
  605. {
  606. $CNF = &$this->_oModule->_oConfig->CNF;
  607. $sKey = 'FIELD_LABELS';
  608. if(isset($CNF[$sKey]) && isset($this->aInputs[$CNF[$sKey]]) && empty($aValsToAdd[$CNF[$sKey]])) {
  609. $aLabels = $this->getCleanValue($CNF[$sKey]);
  610. if(!empty($aLabels) && is_array($aLabels))
  611. $aValsToAdd[$CNF[$sKey]] = serialize($aLabels);
  612. else
  613. $aValsToAdd[$CNF[$sKey]] = '';
  614. }
  615. $sKey1 = 'FIELD_LOCATION';
  616. $sKey2 = 'FIELD_LOCATION_PREFIX';
  617. if(isset($CNF[$sKey1]) && isset($CNF[$sKey2]) && isset($this->aInputs[$CNF[$sKey1]]) && empty($aValsToAdd[$CNF[$sKey1]])) {
  618. $aLocation = BxDolMetatags::locationsRetrieveFromForm($CNF[$sKey2], $this);
  619. if(!empty($aLocation) && is_array($aLocation))
  620. $aValsToAdd[$CNF[$sKey1]] = serialize(BxDolMetatags::locationsParseComponents($aLocation));
  621. }
  622. }
  623. protected function _getPrivacyFields($aKeysF2O = array())
  624. {
  625. $CNF = &$this->_oModule->_oConfig->CNF;
  626. if(isset($CNF['PRIVACY_FIELD_TO_OBJECT']) && is_array($CNF['PRIVACY_FIELD_TO_OBJECT']))
  627. return $CNF['PRIVACY_FIELD_TO_OBJECT'];
  628. if(empty($aKeysF2O))
  629. $aKeysF2O = array('FIELD_ALLOW_VIEW_TO' => 'OBJECT_PRIVACY_VIEW');
  630. $aResult = array();
  631. foreach($aKeysF2O as $sKeyField => $sKeyObject) {
  632. if(!isset($CNF[$sKeyField]) || !isset($this->aInputs[$CNF[$sKeyField]]) || !isset($CNF[$sKeyObject]))
  633. continue;
  634. $aResult[$CNF[$sKeyField]] = $CNF[$sKeyObject];
  635. }
  636. return $aResult;
  637. }
  638. function _addCssJsPrivacyField($sField, $sPrivacyObject, $bDynamicMode = false)
  639. {
  640. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  641. if(!$oPrivacy)
  642. return;
  643. $this->aInputs[$sField]['content'] = $oPrivacy->addCssJs($bDynamicMode) . $this->aInputs[$sField]['content'];
  644. }
  645. protected function _preparePrivacyField($sField, $sPrivacyObject)
  646. {
  647. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  648. if(!$oPrivacy)
  649. return;
  650. $aSave = array('db' => array('pass' => 'Xss'));
  651. array_walk($this->aInputs[$sField], function ($a, $k, $aSave) {
  652. if (in_array($k, array('info', 'caption', 'value')))
  653. $aSave[0][$k] = $a;
  654. }, array(&$aSave));
  655. $aGroupChooser = $oPrivacy->getGroupChooser($sPrivacyObject, 0, array(
  656. 'object' => $this->aParams['object'],
  657. 'display' => $this->aParams['display']
  658. ));
  659. $this->aInputs[$sField] = array_merge($this->aInputs[$sField], $aGroupChooser, $aSave);
  660. }
  661. protected function _preloadPrivacyField($sField, $sPrivacyObject, $aValues)
  662. {
  663. $CNF = &$this->_oModule->_oConfig->CNF;
  664. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  665. if(!$oPrivacy)
  666. return;
  667. $iContentId = !empty($aValues[$CNF['FIELD_ID']]) ? (int)$aValues[$CNF['FIELD_ID']] : 0;
  668. $iProfileId = !empty($iContentId) ? (int)$this->getContentOwnerProfileId($iContentId) : bx_get_logged_profile_id();
  669. $iGroupId = !empty($aValues[$sField]) ? $aValues[$sField] : 0;
  670. if(!isset($this->aInputs[$sField]['content']))
  671. $this->aInputs[$sField]['content'] = '';
  672. $this->aInputs[$sField]['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iProfileId, array(
  673. 'content_id' => $iContentId,
  674. 'group_id' => $iGroupId,
  675. 'html_ids' => array(
  676. 'form' => $this->getId()
  677. )
  678. ));
  679. }
  680. protected function _validatePrivacyField($sField, $sPrivacyObject, $aValues)
  681. {
  682. $mixedValue = $this->aInputs[$sField]['value'];
  683. $bValue = false;
  684. foreach($this->aInputs[$sField]['values'] as $aValue)
  685. if(isset($aValue['key']) && $aValue['key'] == $mixedValue) {
  686. $bValue = true;
  687. break;
  688. }
  689. if(!$bValue) {
  690. $sTitle = '';
  691. if(is_numeric($mixedValue) && (int)$mixedValue < 0 && ($oContext = BxDolProfile::getInstance(abs((int)$mixedValue))) !== false)
  692. $sTitle = $oContext->getDisplayName();
  693. else
  694. $sTitle = _t('_sys_ps_group_title_unknown');
  695. $this->aInputs[$sField]['values'] = array_merge(array(
  696. array('key' => $mixedValue, 'value' => $sTitle),
  697. array('key' => '', 'value' => '----', 'attrs' => array('disabled' => 'disabled'))
  698. ), $this->aInputs[$sField]['values']);
  699. }
  700. }
  701. /**
  702. *
  703. * MultiCategories related methods.
  704. *
  705. */
  706. protected function processMulticatBefore($sFieldName, &$aValsToAdd){
  707. if (isset($this->aInputs[$sFieldName])){
  708. $this->aInputs[$sFieldName]['value'] = array_unique(array_filter($this->aInputs[$sFieldName]['value'], function($sTmp){
  709. return trim($sTmp);
  710. }));
  711. $aValsToAdd[$sFieldName] = implode(',', $this->aInputs[$sFieldName]['value']);
  712. }
  713. }
  714. protected function processMulticatAfter($sFieldName, $iContentId){
  715. $CNF = &$this->_oModule->_oConfig->CNF;
  716. $bAutoActivation = (isset($CNF['PARAM_MULTICAT_AUTO_ACTIVATION_FOR_CATEGORIES']) && getParam($CNF['PARAM_MULTICAT_AUTO_ACTIVATION_FOR_CATEGORIES']) == 'on') ? true : false;
  717. $oCategories = BxDolCategories::getInstance();
  718. if (isset($this->aInputs[$sFieldName])){
  719. $oCategories->delete($this->_oModule->getName(), $iContentId);
  720. foreach($this->aInputs[$sFieldName]['value'] as $sValue) {
  721. $oCategories->add($this->_oModule->getName(), bx_get_logged_profile_id(), $sValue, $iContentId, $bAutoActivation);
  722. }
  723. }
  724. }
  725. protected function genCustomViewRowValueMulticat(&$aInput)
  726. {
  727. $oCategories = BxDolCategories::getInstance();
  728. $aValues = $oCategories->getData(array('type' => 'by_module_and_object', 'module' => $this->_oModule->getName(), 'object_id' => (!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0 )));
  729. if (count($aValues) > 0){
  730. $aVars = array('bx_repeat:cats' => array());
  731. foreach ($aValues as $sValue) {
  732. $aVars['bx_repeat:cats'][] = array(
  733. 'url' => $oCategories->getUrl($this->_oModule->getName(), $sValue),
  734. 'name' => _t($sValue),
  735. 'bx_if:more' => array(
  736. 'condition' => $sValue === end($aValues) ? false : true,
  737. 'content' => array('1')
  738. ),
  739. );
  740. }
  741. if (!$aVars['bx_repeat:cats'])
  742. return '';
  743. return $this->_oModule->_oTemplate->parseHtmlByName('category_list_inline.html', $aVars);
  744. }
  745. return '';
  746. }
  747. protected function genCustomInputMulticat(&$aInput)
  748. {
  749. $sJsObject = $this->_oModule->_oConfig->getJsObject('categories');
  750. $aValuesForSelect = BxDolCategories::getInstance()->getData(array('type' => 'by_module_and_author', 'module' => $this->_oModule->getName(), 'author' => bx_get_logged_profile_id()));
  751. $aSelectedItems = array();
  752. if (isset($aInput['value']) && is_array($aInput['value']))
  753. $aInput['value'] = array_filter($aInput['value']);
  754. if(!empty($aInput['value'])) {
  755. if (!is_array($aInput['value']))
  756. $aValues = BxDolCategories::getInstance()->getData(array('type' => 'by_module_and_object', 'module' => $this->_oModule->getName(), 'object_id' => (!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0 )));
  757. else
  758. $aValues = $aInput['value'];
  759. $aValues = array_filter($aValues);
  760. foreach($aValues as $sValue) {
  761. if (!array_key_exists($sValue, $aValuesForSelect)){
  762. $aValuesForSelect[$sValue] = array('key' => $sValue, 'value' => $sValue);
  763. }
  764. }
  765. foreach($aValues as $sValue) {
  766. $sInput = $this->genCustomInputMulticatSelect($aInput, $aValuesForSelect, $sValue);
  767. $aSelectedItems[] = array('js_object' => $sJsObject, 'select_cat' => $sInput);
  768. }
  769. }
  770. else{
  771. $aSelectedItems = array(
  772. array('js_object' => $sJsObject, 'select_cat' => $this->genCustomInputMulticatSelect($aInput, $aValuesForSelect))
  773. );
  774. }
  775. return $this->_oModule->_oTemplate->parseHtmlByName('form_categories.html', array(
  776. 'bx_repeat:items' => $aSelectedItems,
  777. 'js_object' => $sJsObject,
  778. 'select_cat' => $this->genCustomInputMulticatSelect($aInput, $aValuesForSelect, -1),
  779. 'input_cat' => $this->genCustomInputMulticatInput($aInput),
  780. 'js_object' => $sJsObject,
  781. 'btn_add' => $this->genCustomInputMulticatButton($aInput),
  782. 'btn_add_new' => $this->genCustomInputMulticatButtonNew($aInput)
  783. ));
  784. }
  785. protected function genCustomInputMulticatSelect($aInput, $aValues, $mixedValue = '')
  786. {
  787. foreach($aValues as $sKey => $aValue) {
  788. $aValues[$sKey]['value'] = _t($aValue['key']);
  789. }
  790. $aValues = array_merge(array('1' => array('key' => false, 'value' => _t('_sys_please_select'))), $aValues);
  791. $aInput['type'] = 'select';
  792. $aInput['name'] .= '[]';
  793. $aInput['value'] = $mixedValue;
  794. $aInput['values'] = $aValues;
  795. return $this->genInput($aInput);
  796. }
  797. protected function genCustomInputMulticatInput($aInput)
  798. {
  799. $aInput['type'] = 'text';
  800. $aInput['name'] .= '[]';
  801. $aInput['value'] = '';
  802. return $this->genInput($aInput);
  803. }
  804. protected function genCustomInputMulticatButton($aInput)
  805. {
  806. $sName = $aInput['name'];
  807. $aInput['type'] = 'button';
  808. $aInput['name'] .= '_add';
  809. $aInput['value'] = _t('_sys_txt_categories_button_caption_add');
  810. $aInput['attrs']['class'] = 'bx-def-margin-right bx-def-margin-sec-top';
  811. $aInput['attrs']['onclick'] = $this->_oModule->_oConfig->getJsObject('categories') . ".categoryAdd(this, '" . $sName . "');";
  812. return $this->genInputButton($aInput);
  813. }
  814. protected function genCustomInputMulticatButtonNew($aInput)
  815. {
  816. $sName = $aInput['name'];
  817. $aInput['type'] = 'button';
  818. $aInput['name'] .= '_add';
  819. $aInput['value'] = _t('_sys_txt_categories_button_caption_addnew');
  820. $aInput['attrs']['class'] = 'bx-def-margin-sec-top';
  821. $aInput['attrs']['onclick'] = $this->_oModule->_oConfig->getJsObject('categories') . ".categoryAddNew(this, '" . $sName . "');";
  822. return $this->genInputButton($aInput);
  823. }
  824. protected function genCustomInputAuthor ($aInput)
  825. {
  826. if(empty($aInput['custom']) || !is_array($aInput['custom']))
  827. $aInput['custom'] = array();
  828. $aInput['custom']['only_once'] = 1;
  829. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_profiles";
  830. return $this->genCustomInputUsernamesSuggestions($aInput);
  831. }
  832. protected function _isMulticatEnabled(){
  833. $CNF = $this->_oModule->_oConfig->CNF;
  834. return isset($CNF['PARAM_MULTICAT_ENABLED']) && $CNF['PARAM_MULTICAT_ENABLED'] === true && isset($CNF['FIELD_MULTICAT']);
  835. }
  836. }
  837. /** @} */