BxBaseModGeneralFormEntry.php 42 KB

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