BxBaseModGeneralFormEntry.php 41 KB

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