BxBaseFormView.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBaseFormView extends BxDolForm
  10. {
  11. protected static $_isToggleJsAdded = false;
  12. protected static $_isCssJsAdded = false;
  13. protected static $_isCssJsUiAdded = false;
  14. protected static $_isCssJsMinicolorsAdded = false;
  15. protected static $_isCssJsTimepickerAdded = false;
  16. protected static $_isCssJsAddedViewMode = false;
  17. /**
  18. * Enable or disable error message displaying
  19. */
  20. protected $bEnableErrorIcon = true;
  21. /**
  22. * HTML Code of this form
  23. */
  24. protected $sCode;
  25. /**
  26. * Code which will be added to the beginning of the form.
  27. * For example, hidden inputs.
  28. * For internal use only
  29. */
  30. protected $_sCodeAdd = '';
  31. /**
  32. * for internal use only
  33. */
  34. protected $_isSectionOpened = false;
  35. /**
  36. * Default divider for several inputs
  37. */
  38. protected $_sDivider = '<span class="bx-def-margin-left"></span>';
  39. /**
  40. * Alternative divider for several inputs
  41. */
  42. protected $_sDividerAlt = '<br />';
  43. /**
  44. * Form is added dynamically.
  45. */
  46. protected $_bDynamicMode = false;
  47. /**
  48. * Form is submitted dynamically (using Ajax Submit).
  49. */
  50. protected $_bAjaxMode = false;
  51. /**
  52. * Use absolute Action URL which is needed in Ajax Mode.
  53. */
  54. protected $_bAbsoluteActionUrl = false;
  55. /**
  56. * Form is displayed in view mode.
  57. */
  58. protected $_bViewMode = false;
  59. /**
  60. * Function name for generation close form section HTML.
  61. */
  62. protected $_sSectionClose = 'getCloseSection';
  63. /**
  64. * Function name for generation open form section HTML.
  65. */
  66. protected $_sSectionOpen = 'getOpenSection';
  67. /**
  68. * JS files list for form
  69. */
  70. protected $_aJs = array();
  71. /**
  72. * CSS files list for form
  73. */
  74. protected $_aCss = array();
  75. /**
  76. * Constructor
  77. *
  78. * @param array $aInfo Form contents
  79. *
  80. * $aInfo['params'] = array(
  81. * 'remove_form' => true|false,
  82. * );
  83. *
  84. * @return BxBaseFormView
  85. */
  86. function __construct($aInfo, $oTemplate)
  87. {
  88. parent::__construct($aInfo, $oTemplate);
  89. $this->_bAjaxMode = isset($this->aParams['ajax_mode']) && $this->aParams['ajax_mode'];
  90. $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode'];
  91. if($this->_bViewMode) {
  92. $this->_sSectionClose = 'getCloseSectionViewMode';
  93. $this->_sSectionOpen = 'getOpenSectionViewMode';
  94. }
  95. }
  96. function setAjaxMode($bAjaxMode)
  97. {
  98. $this->_bAjaxMode = (bool)$bAjaxMode;
  99. }
  100. function isAjaxMode()
  101. {
  102. return $this->_bAjaxMode;
  103. }
  104. function setAbsoluteActionUrl($sUrl)
  105. {
  106. if(empty($sUrl))
  107. return;
  108. $this->aFormAttrs['action'] = $sUrl;
  109. $this->_bAbsoluteActionUrl = true;
  110. }
  111. /**
  112. * Return Form code
  113. * @param $bDynamicMode - set it to true if form is added via JS/AJAX call, for example form in AJAX popup.
  114. * @return string
  115. */
  116. function getCode($bDynamicMode = false)
  117. {
  118. if(!$bDynamicMode && bx_is_dynamic_request())
  119. $bDynamicMode = true;
  120. $this->_bDynamicMode = $bDynamicMode;
  121. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  122. $sInclude = '';
  123. $this->sCode = false;
  124. bx_alert('system', 'form_output', 0, 0, array(
  125. 'dynamic' => $this->_bDynamicMode,
  126. 'object' => &$this,
  127. 'code' => &$this->sCode,
  128. 'include' => &$sInclude
  129. ));
  130. if($this->sCode === false)
  131. $this->sCode = $this->genForm();
  132. $this->addCssJs();
  133. $sDynamicCssJs = $this->_processCssJs();
  134. return $sInclude . $sDynamicCssJs . $this->sCode;
  135. }
  136. /**
  137. * Generate the whole form
  138. *
  139. * @return string
  140. */
  141. function genForm()
  142. {
  143. $this->_sCodeAdd = '';
  144. $sTable = $this->genRows();
  145. $sHtmlBefore = isset($this->aParams['html_before']) ? $this->aParams['html_before'] : '';
  146. $sHtmlAfter = isset($this->aParams['html_after']) ? $this->aParams['html_after'] : '';
  147. if (!empty($this->aParams['remove_form']) || (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])) {
  148. $sForm = <<<BLAH
  149. $sHtmlBefore
  150. {$this->_sCodeAdd}
  151. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  152. $sTable
  153. </div>
  154. $sHtmlAfter
  155. BLAH;
  156. } else {
  157. $sFormAttrs = bx_convert_array2attrs($this->aFormAttrs, 'bx-form-advanced');
  158. $sAjaxFormJs = '';
  159. if($this->_bAjaxMode)
  160. $sAjaxFormJs = <<<BLAH
  161. $("form#{$this->id}").ajaxForm({
  162. dataType: "json",
  163. beforeSubmit: function (formData, jqForm, options) {
  164. bx_loading($("form#{$this->id}"), true);
  165. },
  166. success: function (oData) {
  167. bx_loading($("form#{$this->id}"), false);
  168. processJsonData(oData);
  169. }
  170. });
  171. BLAH;
  172. $sForm = <<<BLAH
  173. $sHtmlBefore
  174. <form $sFormAttrs>
  175. {$this->_sCodeAdd}
  176. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  177. $sTable
  178. </div>
  179. </form>
  180. <script>
  181. $(document).ready(function() {
  182. $(this).addWebForms();
  183. });
  184. $sAjaxFormJs
  185. </script>
  186. $sHtmlAfter
  187. BLAH;
  188. }
  189. return $sForm;
  190. }
  191. /**
  192. * Generate Table HTML code
  193. *
  194. * @return string
  195. */
  196. function genRows()
  197. {
  198. // add CSRF token if it's needed.
  199. if (!(isset($this->aParams['view_mode']) && $this->aParams['view_mode']) && getParam('sys_security_form_token_enable') == 'on' && (!isset($this->aParams['csrf']['disable']) || (isset($this->aParams['csrf']['disable']) && $this->aParams['csrf']['disable'] !== true)) && ($mixedCsrfToken = BxDolForm::getCsrfToken()) !== false) {
  200. $this->aInputs['csrf_token'] = array(
  201. 'type' => 'hidden',
  202. 'name' => 'csrf_token',
  203. 'value' => $mixedCsrfToken,
  204. 'db' => array ('pass' => 'Xss'),
  205. 'visible_for_levels' => PHP_INT_MAX,
  206. );
  207. }
  208. // add 'Ajax Mode' flag
  209. if($this->_bAjaxMode)
  210. $this->aInputs['ajax_mode'] = array(
  211. 'type' => 'hidden',
  212. 'name' => 'ajax_mode',
  213. 'value' => 1,
  214. 'db' => array ('pass' => 'Int'),
  215. 'visible_for_levels' => PHP_INT_MAX,
  216. );
  217. // add 'Absolute Action Url' flag
  218. if($this->_bAbsoluteActionUrl)
  219. $this->aInputs['absolute_action_url'] = array(
  220. 'type' => 'hidden',
  221. 'name' => 'absolute_action_url',
  222. 'value' => 1,
  223. 'db' => array ('pass' => 'Int'),
  224. 'visible_for_levels' => PHP_INT_MAX,
  225. );
  226. // check if we need to generate open section clause
  227. $sOpenSection = '';
  228. foreach ($this->aInputs as $aInput) {
  229. if (isset($aInput['type']) && 'hidden' == $aInput['type'])
  230. continue;
  231. if (isset($aInput['type']) && 'block_header' != $aInput['type'])
  232. $sOpenSection = $this->{$this->_sSectionOpen}();
  233. break;
  234. }
  235. // generate rows contents
  236. $sCont = '';
  237. $sContHeader = '';
  238. $sContFields = '';
  239. $sFuncGenRow = isset($this->aParams['view_mode']) && $this->aParams['view_mode'] ? 'genViewRow' : 'genRow';
  240. foreach ($this->aInputs as $aInput) {
  241. if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) {
  242. if ('block_header' == $aInput['type']) {
  243. // don't show section with no fields or with empty fields
  244. if ($sContHeader) {
  245. if ($sContFields)
  246. $sCont .= $sContHeader . $sContFields;
  247. else
  248. $sContHeader = '';
  249. $sContFields = '';
  250. }
  251. else {
  252. $sCont .= $sContFields;
  253. $sContFields = '';
  254. }
  255. $sContHeader = $this->$sFuncGenRow($aInput);
  256. } else {
  257. $sContFields .= $this->$sFuncGenRow($aInput);
  258. }
  259. }
  260. }
  261. $sCont .= $sContHeader . $sContFields;
  262. $sCloseSection = $this->{$this->_sSectionClose}();
  263. return $sOpenSection . $sCont . $sCloseSection;
  264. }
  265. /**
  266. * Generate single Table Row
  267. *
  268. * @param array $aInput
  269. * @return string
  270. */
  271. function genRow(&$aInput)
  272. {
  273. if (!isset($aInput['type']))
  274. $aInput['type'] = false;
  275. if (!empty($aInput['name'])) {
  276. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  277. if (method_exists($this, $sCustomMethod))
  278. return $this->$sCustomMethod($aInput);
  279. }
  280. switch ($aInput['type']) {
  281. case 'block_header':
  282. $sRow = $this->genRowBlockHeader($aInput);
  283. break;
  284. case 'block_end':
  285. $sRow = $this->genBlockEnd($aInput);
  286. break;
  287. case 'hidden':
  288. // do not generate row for hidden inputs
  289. $sRow = '';
  290. $this->_sCodeAdd .= $this->genInput($aInput);
  291. break;
  292. case 'select_box':
  293. $sRow = $this->genRowCustom($aInput, 'genInputSelectBox');
  294. break;
  295. case 'files':
  296. $sRow = $this->genRowCustom($aInput, 'genInputFiles');
  297. break;
  298. case 'switcher':
  299. case 'checkbox':
  300. $sRow = $this->genRowStandard($aInput, true);
  301. break;
  302. default:
  303. $sRow = $this->genRowStandard($aInput);
  304. }
  305. return $sRow;
  306. }
  307. /**
  308. * Generate single Table Row for view mode
  309. *
  310. * @param array $aInput
  311. * @return string
  312. */
  313. function genViewRow(&$aInput)
  314. {
  315. if (!isset($aInput['type']))
  316. $aInput['type'] = false;
  317. if (!empty($aInput['name'])) {
  318. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  319. if (method_exists($this, $sCustomMethod))
  320. return $this->$sCustomMethod($aInput);
  321. }
  322. switch ($aInput['type']) {
  323. case 'block_header':
  324. $sRow = $this->genRowBlockHeader($aInput);
  325. break;
  326. case 'block_end':
  327. $sRow = $this->genBlockEnd($aInput);
  328. break;
  329. default:
  330. $sRow = $this->genViewRowWrapped($aInput);
  331. }
  332. return $sRow;
  333. }
  334. /**
  335. * Generate complete wrapped row for view mode form
  336. *
  337. * @param array $aInput
  338. * @return string
  339. */
  340. function genViewRowWrapped(&$aInput)
  341. {
  342. $sValue = $this->genViewRowValue($aInput);
  343. if (null === $sValue)
  344. return '';
  345. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  346. return <<<EOS
  347. <div class="bx-form-row-view-wrapper bx-form-row-view-wrapper-{$aInput['type']} bx-def-padding-sec-top">
  348. <div class="bx-form-row-view-caption">{$sCaption}:</div>
  349. <div class="bx-form-row-view-value">{$sValue}</div>
  350. </div>
  351. EOS;
  352. }
  353. /**
  354. * Generate value for view mode row
  355. *
  356. * @param array $aInput
  357. * @return string
  358. */
  359. function genViewRowValue(&$aInput)
  360. {
  361. if (!empty($aInput['name'])) {
  362. $sCustomMethod = 'genCustomViewRowValue' . $this->_genMethodName($aInput['name']);
  363. if (method_exists($this, $sCustomMethod))
  364. return $this->$sCustomMethod($aInput);
  365. }
  366. switch ($aInput['type']) {
  367. case 'hidden':
  368. $sValue = null;
  369. break;
  370. case 'select':
  371. case 'radio_set':
  372. $sValue = $this->genViewRowValueForSelect($aInput);
  373. break;
  374. case 'datepicker':
  375. $sValue = null;
  376. if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value'])
  377. break;
  378. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  379. break;
  380. case 'date_time':
  381. case 'datetime':
  382. $sValue = null;
  383. if(empty($aInput['value']) || !$aInput['value'] || '0000-00-00 00:00:00' == $aInput['value'] || '0000-00-00 00:00' == $aInput['value'])
  384. break;
  385. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  386. break;
  387. case 'checkbox_set':
  388. case 'select_multiple':
  389. $sValue = null;
  390. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  391. $sValue = '';
  392. foreach ($aInput['value'] as $sVal)
  393. $sValue .= $aInput['values'][$sVal] . ', ';
  394. $sValue = trim ($sValue, ', ');
  395. }
  396. break;
  397. case 'checkbox':
  398. case 'switcher':
  399. $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off');
  400. break;
  401. case 'textarea':
  402. if (isset($aInput['value']) && '' !== $aInput['value'])
  403. $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE);
  404. else
  405. $sValue = null;
  406. break;
  407. case 'text':
  408. if(isset($aInput['value']) && '' !== $aInput['value'])
  409. $sValue = bx_linkify(bx_process_output($aInput['value']));
  410. else
  411. $sValue = null;
  412. break;
  413. default:
  414. $sValue = isset($aInput['value']) && '' !== $aInput['value'] ? bx_process_output($aInput['value']) : null;
  415. }
  416. return $sValue;
  417. }
  418. function genViewRowValueForSelect(&$aInput)
  419. {
  420. if (!isset($aInput['value']) || !$aInput['value'])
  421. return null;
  422. $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
  423. if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])))
  424. return $oCategory->getCategoryLink($s, $aInput['value']);
  425. return $s;
  426. }
  427. protected function genCustomRowBirthday(&$aInput)
  428. {
  429. if(!$this->_bViewMode)
  430. return $this->genRowStandard($aInput);
  431. $aInput['caption_src'] = '_sys_form_input_age';
  432. $aInput['caption'] = _t($aInput['caption_src']);
  433. return $this->genViewRowWrapped($aInput);
  434. }
  435. protected function genCustomViewRowValueBirthday(&$aInput)
  436. {
  437. if(!isset($aInput['value']) || !$aInput['value'] || in_array($aInput['value'], array('0000-00-00', '0000-00-00 00:00:00')))
  438. return null;
  439. $sValue = $aInput['value'];
  440. $iPosSpace = strpos($sValue, ' ');
  441. if($iPosSpace !== false)
  442. $sValue = trim(substr($sValue, 0, $iPosSpace));
  443. $aDate = explode('-', $sValue);
  444. $iCdYear = (int)date('Y');
  445. $iCdMonth = (int)date('n');
  446. $iCdDay = (int)date('j');
  447. $iResult = $iCdYear - (int)$aDate[0];
  448. if($iCdMonth < (int)$aDate[1] || ($iCdMonth == (int)$aDate[1] && $iCdDay < (int)$aDate[2]))
  449. $iResult -= 1;
  450. return $iResult;
  451. }
  452. /**
  453. * Generate standard row
  454. *
  455. * @param array $aInput
  456. * @return string
  457. */
  458. function genRowStandard(&$aInput, $isOneLine = false)
  459. {
  460. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  461. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span> ' : '';
  462. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  463. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  464. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  465. $sClassWrapper = 'bx-form-element-wrapper';
  466. if($isOneLine)
  467. $sClassWrapper .= ' ' . $sClassWrapper . '-oneline';
  468. $sClassWrapper .= ' bx-def-margin-top';
  469. if (isset($aInput['name']))
  470. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  471. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper);
  472. $sClassOneLineCaption = '';
  473. $sClassOneLineValue = '';
  474. if ($isOneLine) {
  475. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' bx-def-margin-sec-left';
  476. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  477. $aInput['attrs']['id'] = $this->getInputId($aInput);
  478. if ($sCaption)
  479. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  480. }
  481. $sInput = $this->genInput($aInput);
  482. if(isset($aInput['error_updated']) && $aInput['error_updated'] === true)
  483. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  484. $sCaptionCode = $sCaption ? '<div class="bx-form-caption' . $sClassOneLineCaption . '">' . $sCaption . $sRequired . '</div>' : '';
  485. $sInputCode = $this->genWrapperInput($aInput, $sInput);
  486. if (empty($sInfoIcon)) $sInfoIcon = '';
  487. if (empty($sInputCode)) $sInputCode = '';
  488. if (empty($sErrorIcon)) $sErrorIcon = '';
  489. $sValueCode = '<div class="bx-form-value bx-clearfix' . $sClassAdd . $sClassOneLineValue . '">' . $sInputCode . '</div>';
  490. if ($isOneLine)
  491. $sCode = $sValueCode . $sCaptionCode;
  492. else
  493. $sCode = $sCaptionCode . $sValueCode;
  494. return '<div ' . $sTrAttrs . '><div class="bx-form-element">' . $sCode . '</div>' . $sInfoIcon . $sErrorIcon . '</div>';
  495. }
  496. function genWrapperInput($aInput, $sContent)
  497. {
  498. $sAttr = isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper']) ? bx_convert_array2attrs($aInput['attrs_wrapper']) : '';
  499. return "<div class=\"bx-form-input-wrapper bx-form-input-wrapper-{$aInput['type']}" . ((isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput)) ? ' bx-form-input-wrapper-html' : '') . "\" $sAttr>$sContent</div>";
  500. }
  501. /**
  502. * Generate custom row
  503. *
  504. * @param array $aInput
  505. * @param string $sCustomMethod custom method to generate code for input
  506. * @return string
  507. */
  508. function genRowCustom(&$aInput, $sCustomMethod)
  509. {
  510. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  511. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span> ' : '';
  512. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  513. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  514. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  515. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  516. if (isset($aInput['name']))
  517. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  518. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  519. $sCaptionCode = '';
  520. if ($sCaption)
  521. $sCaptionCode = '<div class="bx-form-caption">' . $sCaption . $sRequired . '</div>';
  522. $sCode = <<<BLAH
  523. <div $sTrAttrs>
  524. $sCaptionCode
  525. <div class="bx-form-value$sClassAdd">
  526. <div class="bx-clear"></div>
  527. $sInput
  528. <div class="bx-clear"></div>
  529. </div>
  530. </div>
  531. BLAH;
  532. return $sCode;
  533. }
  534. /**
  535. * Generate Block Headers row
  536. *
  537. * @param array $aInput
  538. * @return string
  539. */
  540. function genRowBlockHeader(&$aInput)
  541. {
  542. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  543. // if there is no caption - show divider only
  544. if (empty($aInput['caption'])) {
  545. $sCode = $this->{$this->_sSectionClose}();
  546. $sCode .= $this->{$this->_sSectionOpen}($aAttrs);
  547. return $sCode;
  548. }
  549. // if section is collapsed by default, add necessary code
  550. $sClassAddCollapsable = 'bx-form-collapsable';
  551. if (isset($aInput['collapsed']) and $aInput['collapsed'])
  552. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  553. // display section with caption
  554. $sCode = $this->{$this->_sSectionClose}();
  555. if (empty($aAttrs))
  556. $aAttrs = array('class' => 'bx-form-collapsable ' . $sClassAddCollapsable);
  557. else
  558. $aAttrs['class'] .= ' bx-form-collapsable ' . $sClassAddCollapsable;
  559. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])
  560. $sLegend = '<legend class="bx-def-padding-left bx-def-padding-sec-right bx-def-font-grayed bx-def-font-h3">' . bx_process_output($aInput['caption']) . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</legend>';
  561. else
  562. $sLegend = '<legend class="bx-def-padding-left bx-def-padding-sec-right bx-def-font-grayed bx-def-font-h3"><a href="javascript:void(0);">' . bx_process_output($aInput['caption']) . '</a>' . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</legend>';
  563. $sCode .= $this->{$this->_sSectionOpen}($aAttrs, $sLegend);
  564. return $sCode;
  565. }
  566. function genBlockEnd()
  567. {
  568. $aNextTbodyAdd = false; // need to have some default
  569. $sCode = '';
  570. $sCode .= $this->{$this->_sSectionClose}();
  571. $sCode .= $this->{$this->_sSectionOpen}($aNextTbodyAdd);
  572. return $sCode;
  573. }
  574. /**
  575. * Generate HTML Input Element
  576. *
  577. * @param array $aInput
  578. * @return string Output HTML Code
  579. */
  580. function genInput(&$aInput)
  581. {
  582. if (!empty($aInput['name'])) {
  583. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  584. if (method_exists($this, $sCustomMethod))
  585. return $this->$sCustomMethod($aInput);
  586. }
  587. switch ($aInput['type']) {
  588. // standard inputs (and non-standard, interpreted as standard)
  589. case 'text':
  590. case 'datepicker':
  591. case 'date_time':
  592. case 'datetime':
  593. case 'number':
  594. case 'time':
  595. case 'checkbox':
  596. case 'radio':
  597. case 'image':
  598. case 'password':
  599. case 'slider':
  600. case 'doublerange':
  601. case 'hidden':
  602. $sInput = $this->genInputStandard($aInput);
  603. break;
  604. case 'file':
  605. $sInput = $this->genInputFile($aInput);
  606. break;
  607. case 'rgb':
  608. case 'rgba':
  609. $sClass = 'bx-form-input-' . $aInput['type'];
  610. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  611. $aInput['type'] = 'text';
  612. $sInput = $this->genInputStandard($aInput);
  613. break;
  614. case 'switcher':
  615. $sInput = $this->genInputSwitcher($aInput);
  616. break;
  617. case 'button':
  618. case 'reset':
  619. case 'submit':
  620. $sInput = $this->genInputButton($aInput);
  621. break;
  622. case 'textarea':
  623. $sInput = $this->genInputTextarea($aInput);
  624. break;
  625. case 'select':
  626. $sInput = $this->genInputSelect($aInput);
  627. break;
  628. case 'select_multiple':
  629. $sInput = $this->genInputSelectMultiple($aInput);
  630. break;
  631. case 'checkbox_set':
  632. $sInput = $this->genInputCheckboxSet($aInput);
  633. break;
  634. case 'radio_set':
  635. $sInput = $this->genInputRadioSet($aInput);
  636. break;
  637. case 'input_set': // numeric array of inputs
  638. $sInput = '';
  639. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  640. foreach ($aInput as $iKey => $aSubInput) {
  641. if (!is_int($iKey) or !$aSubInput)
  642. continue; // parse only integer keys and existing values
  643. $sInput .= $this->genInput($aSubInput); // recursive call
  644. $sInput .= $sDivider;
  645. }
  646. $sInput .= '<div class="bx-clear"></div>';
  647. break;
  648. case 'custom':
  649. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  650. break;
  651. case 'captcha':
  652. $sInput = $this->genInputCaptcha($aInput);
  653. break;
  654. case 'location':
  655. $sInput = $this->genInputLocation($aInput);
  656. break;
  657. case 'value':
  658. $sInput = isset($aInput['value']) ? $aInput['value'] : '';
  659. break;
  660. default:
  661. //unknown control type
  662. $sInput = 'Unknown control type';
  663. }
  664. // create input label
  665. $sInput .= $this->genLabel($aInput);
  666. return $sInput;
  667. }
  668. /**
  669. * Generate new Input Element id
  670. *
  671. * @param array $aInput
  672. * @return string
  673. */
  674. function getInputId(&$aInput)
  675. {
  676. if (isset($aInput['id']))
  677. return $aInput['id'];
  678. $sName = md5($aInput['name']);
  679. $sID = $this->id . '_input_' . $sName;
  680. if ( // multiple elements cause identical id's
  681. (
  682. (
  683. $aInput['type'] == 'checkbox' and
  684. substr($aInput['name'], -2) == '[]' // it is multiple element
  685. ) or
  686. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  687. ) and
  688. isset($aInput['value']) // if we can make difference
  689. ) {
  690. $sValue = md5($aInput['value']);
  691. // add value
  692. $sID .= '_' . $sValue;
  693. }
  694. $sID = trim($sID, '_');
  695. $aInput['id'] = $sID; // just for repeated calls
  696. return $sID;
  697. }
  698. /**
  699. * Generate standard Input Element
  700. *
  701. * @param array $aInput
  702. * @return string
  703. */
  704. function genInputStandard(&$aInput)
  705. {
  706. // clone attributes for system use ;)
  707. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  708. // add default className to attributes
  709. $aAttrs['type'] = $aInput['type'];
  710. if ('datetime' == $aAttrs['type'])
  711. $aAttrs['type'] = 'date_time';
  712. switch($aAttrs['type']) {
  713. case 'date_time':
  714. $this->addCssJsUi ();
  715. $this->addCssJsTimepicker ();
  716. break;
  717. case 'slider':
  718. case 'doublerange':
  719. case 'datepicker':
  720. $this->addCssJsUi ();
  721. break;
  722. case 'text':
  723. if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
  724. $this->addCssJsMinicolors ();
  725. break;
  726. }
  727. if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) {
  728. $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max'];
  729. }
  730. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  731. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  732. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1;
  733. // for inputs with labels generate id
  734. if (isset($aInput['label']))
  735. $aAttrs['id'] = $this->getInputId($aInput);
  736. // for checkboxes
  737. if (isset($aInput['checked']) and $aInput['checked'])
  738. $aAttrs['checked'] = 'checked';
  739. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  740. return "<input $sAttrs />\n";
  741. }
  742. /**
  743. * Generate Switcher Input Element (based on checkbox)
  744. *
  745. * @param array $aInput
  746. * @return string
  747. */
  748. function genInputSwitcher(&$aInput)
  749. {
  750. $aInput['type'] = 'checkbox';
  751. $sCheckbox = $this->genInputStandard($aInput);
  752. $aInput['type'] = 'switcher';
  753. $sClass = 'off';
  754. if (isset($aInput['checked']) and $aInput['checked'])
  755. $sClass = 'on';
  756. return '
  757. <div class="bx-switcher-cont ' . $sClass . '">' . $sCheckbox . '
  758. <div class="bx-switcher-canvas">
  759. <div class="bx-switcher-on"><i class="sys-icon check"></i></div>
  760. <div class="bx-switcher-off"><i class="sys-icon times"></i></div>
  761. <div class="bx-switcher-handler">&nbsp;</div>
  762. </div>
  763. </div>';
  764. }
  765. /**
  766. * Generate Button Input Element
  767. *
  768. * @param array $aInput
  769. * @return string
  770. */
  771. function genInputButton(&$aInput)
  772. {
  773. // clone attributes for system use ;)
  774. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  775. // add default className to attributes
  776. $aAttrs['type'] = $aInput['type'];
  777. if (isset($aInput['value']))
  778. $aAttrs['value'] = $aInput['value'];
  779. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  780. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn" . ('submit' == $aInput['type'] ? ' bx-btn-primary' : ''));
  781. return "<button $sAttrs>" . $aInput['value'] . "</button>\n";
  782. }
  783. /**
  784. * Generate Textarea Element
  785. *
  786. * @param array $aInput
  787. * @return string
  788. */
  789. function genInputTextarea(&$aInput)
  790. {
  791. // clone attributes for system use ;)
  792. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  793. $aAttrs['name'] = $aInput['name'];
  794. // for inputs with labels generate id
  795. if (isset($aInput['label']))
  796. $aAttrs['id'] = $this->getInputId($aInput);
  797. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}" . ((isset($aInput['html']) and $aInput['html'] and $this->addHtmlEditor($aInput['html'], $aInput)) ? ' bx-form-input-html' : ''));
  798. $sValue = isset($aInput['value']) ? bx_process_output((isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : strip_tags($aInput['value'])) : '';
  799. return "<textarea $sAttrs>$sValue</textarea>";
  800. }
  801. function isHtmlEditor($iViewMode, &$aInput)
  802. {
  803. return BxDolEditor::getObjectInstance(false, $this->oTemplate) !== false;
  804. }
  805. function addHtmlEditor($iViewMode, &$aInput)
  806. {
  807. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  808. if (!$oEditor)
  809. return false;
  810. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name='.$aInput['name'].']', $iViewMode, $this->_bDynamicMode);
  811. return true;
  812. }
  813. /**
  814. * Generate Select Box Element
  815. *
  816. * @param array $aInput
  817. * @return string
  818. */
  819. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  820. {
  821. $aNewInput = $aInput;
  822. $aNewInput['type'] = 'select';
  823. $aNewInput['name'] .= '[]';
  824. $sInput = $this->genInput($aNewInput);
  825. return <<<BLAH
  826. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  827. $sInput
  828. </div>
  829. $sInfo
  830. $sError
  831. BLAH;
  832. }
  833. /**
  834. * Generate Browse File Element
  835. *
  836. * @param array $aInput
  837. * @return string
  838. */
  839. function genInputFile(&$aInput)
  840. {
  841. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  842. if(!empty($aInput['attrs']['onchange']))
  843. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  844. else
  845. $aInput['attrs']['onchange'] = $sOnChange;
  846. $sInput = $this->genInputStandard($aInput);
  847. return '<label class="bx-btn">' . $sInput . '<span class="bx-fif-label">' . _t('_sys_form_txt_select_file') . '</span></label><span class="bx-fif-value bx-def-margin-thd-left"></span>';
  848. }
  849. /**
  850. * Generate Select Box Element
  851. *
  852. * @param array $aInput
  853. * @return string
  854. */
  855. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  856. {
  857. $sUniqId = genRndPwd (8, false);
  858. $sUploaders = '';
  859. $oUploader = null;
  860. foreach ($aInput['uploaders'] as $sUploaderObject) {
  861. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  862. if (!$oUploader)
  863. continue;
  864. $sGhostTemplate = $this->genGhostTemplate($aInput);
  865. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  866. if (empty($aInput['attrs']['disabled']))
  867. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  868. $aParams = array(
  869. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  870. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  871. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  872. 'attrs' => bx_convert_array2attrs($aAttrs),
  873. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  874. );
  875. if (isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  876. $aParams['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  877. $sUploaders .= $oUploader->getUploaderButton($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParams, $this->_bDynamicMode);
  878. }
  879. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  880. 'uploaders_buttons' => $sUploaders,
  881. 'info' => $sInfo,
  882. 'error' => $sError,
  883. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  884. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  885. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  886. 'is_init_ghosts' => isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1,
  887. ));
  888. }
  889. protected function genGhostTemplate(&$aInput)
  890. {
  891. $sGhostTemplate = false;
  892. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  893. $oFormNested = $aInput['ghost_template'];
  894. if ($oFormNested instanceof BxDolFormNested)
  895. $sGhostTemplate = $oFormNested->genForm();
  896. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && isset($aInput['ghost_template']['inputs'])) { // form is not submitted and ghost template is form array
  897. $oFormNested = new BxDolFormNested($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  898. $sGhostTemplate = $oFormNested->getCode();
  899. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  900. $sGhostTemplate = array ();
  901. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  902. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNested)
  903. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  904. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  905. $sGhostTemplate = $aInput['ghost_template'];
  906. }
  907. return $sGhostTemplate;
  908. }
  909. protected function genCustomInputUsernamesSuggestions ($aInput)
  910. {
  911. $this->addCssJsUi();
  912. $sVals = '';
  913. if(!empty($aInput['value']) && is_array($aInput['value'])) {
  914. foreach($aInput['value'] as $sVal) {
  915. if(!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  916. continue;
  917. $sVals .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . $oProfile->getUnit(0, array('template' => 'unit_wo_info')) . $oProfile->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></b>';
  918. }
  919. $sVals = trim($sVals, ',');
  920. }
  921. $bDisabled = isset($aInput['attrs']['disabled']) && $aInput['attrs']['disabled'] == 'disabled';
  922. $sId = $aInput['name'] . time() . mt_rand(0, 100);
  923. $sClass = 'bx-form-input-autotoken bx-def-font-inputs bx-form-input-text';
  924. if($bDisabled)
  925. $sClass .= ' bx-form-input-disabled';
  926. if(!empty($aInput['attrs']['class'])) {
  927. $sClass .= ' ' . $aInput['attrs']['class'];
  928. unset($aInput['attrs']['class']);
  929. }
  930. $aAttrs = array('value' => '', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'autocorrect' => 'off');
  931. if(isset($aInput['attrs']) && is_array($aInput['attrs']))
  932. $aAttrs = array_merge($aAttrs, $aInput['attrs']);
  933. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  934. 'id' => $sId,
  935. 'name' => $aInput['name'],
  936. 'class' => $sClass,
  937. 'vals' => $sVals,
  938. 'bx_if:input' => array(
  939. 'condition' => !$bDisabled,
  940. 'content' => array(
  941. 'attrs' => bx_convert_array2attrs($aAttrs),
  942. )
  943. ),
  944. 'bx_if:init' => array(
  945. 'condition' => !$bDisabled,
  946. 'content' => array(
  947. 'id' => $sId,
  948. 'name' => $aInput['name'],
  949. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  950. 'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
  951. 'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
  952. 'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
  953. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  954. )
  955. )
  956. ));
  957. }
  958. protected function genCustomViewRowValueLabels ($aInput)
  959. {
  960. if (empty($aInput['value']) || !is_array($aInput['value']) || !($oMetatags = BxDolMetatags::getObjectInstance($aInput['meta_object'])) || !$oMetatags->keywordsIsEnabled())
  961. return null;
  962. $s = '';
  963. foreach ($aInput['value'] as $sLabel)
  964. $s .= '<a href="' . $oMetatags->keywordsGetHashTagUrl($sLabel, $aInput['content_id']) . '"><b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sLabel) . '</b></a>';
  965. return $this->oTemplate->parseHtmlByName('form_field_labels_view.html', array(
  966. 'values' => $s,
  967. ));
  968. }
  969. protected function genCustomInputLabels ($aInput)
  970. {
  971. $aValues = array();
  972. $oLabel = BxDolLabel::getInstance();
  973. $this->_getLabelOptions(0, $oLabel, $aValues);
  974. $aInput['type'] = 'select_multiple';
  975. $aInput['values'] = $aValues;
  976. return $this->genInputSelectMultiple($aInput);
  977. }
  978. protected function _getLabelOptions($iParent, &$oLabel, &$aValues)
  979. {
  980. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  981. foreach($aLabels as $aLabel) {
  982. $aValues[] = array('key' => $aLabel['value'], 'value' => str_repeat('&nbsp;&nbsp;&nbsp;', (int)$aLabel['level']) . ' ' . $aLabel['value']);
  983. $this->_getLabelOptions($aLabel['id'], $oLabel, $aValues);
  984. }
  985. }
  986. /*
  987. protected function genCustomInputLabels ($aInput)
  988. {
  989. // generate currently selected labels
  990. $sValue = '';
  991. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  992. sort($aInput['value'], SORT_LOCALE_STRING);
  993. foreach ($aInput['value'] as $sVal) {
  994. $sValue .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . trim($sVal) . '" /></b>';
  995. }
  996. $sValue = trim($sValue, ',');
  997. }
  998. // generate "following" labels
  999. $aFollowingLabels = bx_srv('bx_channels', 'get_following_channels_names', array(bx_get_logged_profile_id()));
  1000. if (!is_array($aFollowingLabels))
  1001. $aFollowingLabels = array();
  1002. $aFollowingLabels = array_intersect($aFollowingLabels, $aInput['values']);
  1003. $aFollowingLabels = array_diff($aFollowingLabels, !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array());
  1004. $aValues = array_diff($aInput['values'],
  1005. !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array(),
  1006. !empty($aFollowingLabels) && is_array($aFollowingLabels) ? $aFollowingLabels : array());
  1007. $sValues = '';
  1008. if (!empty($aFollowingLabels)) {
  1009. sort($aFollowingLabels, SORT_LOCALE_STRING);
  1010. foreach ($aFollowingLabels as $sVal) {
  1011. $sValues .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '</b>';
  1012. }
  1013. if (!empty($aValues))
  1014. $sValues .= '<a href="#" class="bx-form-input-autotoken-labels-show-more">' . _t('_sys_show_more') . '</a><i class="bx-form-input-autotoken-labels-more">';
  1015. }
  1016. // generate all possible labels
  1017. if (!empty($aValues)) {
  1018. sort($aValues, SORT_LOCALE_STRING);
  1019. foreach ($aValues as $sVal) {
  1020. $sValues .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '</b>';
  1021. }
  1022. $sValues = trim($sValues, ',');
  1023. }
  1024. if (!empty($aFollowingLabels) && !empty($aValues))
  1025. $sValues .= '</i>';
  1026. return $this->oTemplate->parseHtmlByName('form_field_labels.html', array(
  1027. 'id' => $aInput['name'] . time() . mt_rand(0, 100),
  1028. 'name' => $aInput['name'],
  1029. 'value' => $sValue,
  1030. 'values' => $sValues,
  1031. ));
  1032. }
  1033. */
  1034. /**
  1035. * Generate Select Element
  1036. *
  1037. * @param array $aInput
  1038. * @return string
  1039. */
  1040. function genInputSelect(&$aInput)
  1041. {
  1042. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1043. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1044. }
  1045. /**
  1046. * Generate Multiple Select Element
  1047. *
  1048. * @param array $aInput
  1049. * @return string
  1050. */
  1051. function genInputSelectMultiple(&$aInput)
  1052. {
  1053. $aCurValues = array();
  1054. if (isset($aInput['value']) && $aInput['value'])
  1055. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1056. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  1057. }
  1058. /**
  1059. * Generate Checkbox Set Element
  1060. *
  1061. * @param array $aInput
  1062. * @return string
  1063. */
  1064. function genInputCheckboxSet(&$aInput)
  1065. {
  1066. $aCurValues = array();
  1067. if (isset($aInput['value']) && $aInput['value'])
  1068. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1069. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  1070. }
  1071. /**
  1072. * Generate Radiobuttons Set Element
  1073. *
  1074. * @param array $aInput
  1075. * @return string
  1076. */
  1077. function genInputRadioSet(&$aInput)
  1078. {
  1079. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1080. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  1081. }
  1082. function _isSelected ($sValue, $sCurValue)
  1083. {
  1084. return ((string)$sValue === (string)$sCurValue);
  1085. }
  1086. function _isSelectedMultiple ($sValue, $aCurValues)
  1087. {
  1088. return in_array($sValue, $aCurValues);
  1089. }
  1090. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  1091. {
  1092. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1093. $aAttrs['name'] = $aInput['name'];
  1094. if ($isMultiple) {
  1095. $aAttrs['name'] .= '[]';
  1096. $aAttrs['multiple'] = 'multiple';
  1097. }
  1098. // for inputs with labels generate id
  1099. if (isset($aInput['label']))
  1100. $aAttrs['id'] = $this->getInputId($aInput);
  1101. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  1102. // generate options
  1103. $sOptions = '';
  1104. if (isset($aInput['values']) and is_array($aInput['values'])) {
  1105. foreach ($aInput['values'] as $sValue => $sTitle) {
  1106. $sAttrsOpt = "";
  1107. if(is_array($sTitle)) {
  1108. if(isset($sTitle['type'])) {
  1109. switch($sTitle['type']) {
  1110. case 'group_header':
  1111. $sTitle = bx_process_output($sTitle['value']);
  1112. $sOptions .= <<<BLAH
  1113. <optgroup label="$sTitle">
  1114. BLAH;
  1115. break;
  1116. case 'group_end':
  1117. $sOptions .= <<<BLAH
  1118. </optgroup>
  1119. BLAH;
  1120. break;
  1121. }
  1122. continue;
  1123. }
  1124. $aAttrsOpt = array();
  1125. if(!empty($sTitle['attrs']) && is_array($sTitle['attrs']))
  1126. $aAttrsOpt = $sTitle['attrs'];
  1127. if(isset($sTitle['class']))
  1128. $aAttrsOpt['class'] = !empty($aAttrsOpt['class']) ? $aAttrsOpt['class'] . ' ' . $sTitle['class'] : $sTitle['class'];
  1129. if(isset($sTitle['style']))
  1130. $aAttrsOpt['style'] = !empty($aAttrsOpt['style']) ? $aAttrsOpt['style'] . ' ' . $sTitle['style'] : $sTitle['style'];
  1131. $sAttrsOpt = !empty($aAttrsOpt) ? bx_convert_array2attrs($aAttrsOpt) : '';
  1132. $sValue = $sTitle['key'];
  1133. $sTitle = $sTitle['value'];
  1134. }
  1135. $sValueC = bx_html_attribute($sValue);
  1136. $sTitleC = bx_process_output($sTitle);
  1137. $sSelected = $this->$sIsSelectedFunc($sValue, $mixedCurrentVal) ? 'selected="selected"' : '';
  1138. $sOptions .= <<<BLAH
  1139. <option value="$sValueC" $sAttrsOpt $sSelected>$sTitleC</option>
  1140. BLAH;
  1141. }
  1142. }
  1143. // generate element
  1144. $sCode = <<<BLAH
  1145. <select $sAttrs>
  1146. $sOptions
  1147. </select>
  1148. BLAH;
  1149. if(!empty($aInput['content']))
  1150. $sCode .= $aInput['content'];
  1151. return $sCode;
  1152. }
  1153. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  1154. {
  1155. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  1156. $aAttrs['name'] = $aInput['name'];
  1157. // for inputs with labels generate id
  1158. if (isset($aInput['label']))
  1159. $aAttrs['id'] = $this->getInputId($aInput);
  1160. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1161. // generate options
  1162. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  1163. $sOptions = '';
  1164. if (isset($aInput['values']) && is_array($aInput['values'])) {
  1165. if (count($aInput['values']) > 3 && $sDivider == $this->_sDivider)
  1166. $sDivider = $this->_sDividerAlt;
  1167. // generate complex input using simple standard inputs
  1168. foreach ($aInput['values'] as $sValue => $sLabel) {
  1169. if(is_array($sLabel)) {
  1170. $sValue = $sLabel['key'];
  1171. $sLabel = $sLabel['value'];
  1172. }
  1173. // create new simple input
  1174. $aNewInput = array(
  1175. 'type' => $sType,
  1176. 'name' => $aInput['name'] . $sNameAppend,
  1177. 'value' => $sValue,
  1178. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  1179. 'label' => $sLabel,
  1180. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  1181. );
  1182. $sNewInput = $this->genInput($aNewInput);
  1183. // attach new input to complex
  1184. $sOptions .= ($sNewInput . $sDivider);
  1185. }
  1186. }
  1187. // generate element
  1188. $sCode = <<<BLAH
  1189. <div $sAttrs>
  1190. $sOptions
  1191. </div>
  1192. BLAH;
  1193. return $sCode;
  1194. }
  1195. function genInputLocation(&$aInput)
  1196. {
  1197. $isManualInput = (int)(isset($aInput['manual_input']) && $aInput['manual_input']);
  1198. $sIdStatus = $this->getInputId($aInput) . '_status';
  1199. $sIdInput = $this->getInputId($aInput) . '_location';
  1200. $sProto = (0 === strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
  1201. $aVars = array (
  1202. 'key' => trim(getParam('sys_maps_api_key')),
  1203. 'lang' => bx_lang_name(),
  1204. 'name' => $aInput['name'],
  1205. 'id_status' => $sIdStatus,
  1206. 'id_input' => $sIdInput,
  1207. 'manual_input' => $isManualInput,
  1208. 'bx_if:manual_input' => array(
  1209. 'condition' => $isManualInput,
  1210. 'content' => array(),
  1211. ),
  1212. 'bx_if:auto_input' => array(
  1213. 'condition' => !$isManualInput,
  1214. 'content' => array(
  1215. 'id_status' => $sIdStatus,
  1216. 'location_string' => _t('_sys_location_undefined'),
  1217. ),
  1218. ),
  1219. );
  1220. $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip', 'street', 'street_number');
  1221. foreach ($aLocationIndexes as $sKey)
  1222. $aVars[$sKey] = $this->getLocationVal($aInput, $sKey);
  1223. if ($aVars['country']) {
  1224. $aCountries = BxDolFormQuery::getDataItems('Country');
  1225. $s = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
  1226. $aVars['bx_if:auto_input']['content']['location_string'] = $s;
  1227. }
  1228. if ($isManualInput) {
  1229. $aInput['type'] = 'text';
  1230. $aInput['attrs']['id'] = $sIdInput;
  1231. $aVars['input'] = $this->genInputStandard($aInput);
  1232. }
  1233. else {
  1234. if ($this->getLocationVal($aInput, 'lat') && $this->getLocationVal($aInput, 'lng'))
  1235. $aInput['checked'] = true;
  1236. else
  1237. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  1238. $aVars['input'] = $this->genInputSwitcher($aInput);
  1239. }
  1240. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  1241. }
  1242. public function setLocationVal ($aInput, $sIndex, $sVal)
  1243. {
  1244. $s = $aInput['name'] . '_' . $sIndex;
  1245. $this->_aSpecificValues[$s] = $sVal;
  1246. }
  1247. protected function getLocationVal ($aInput, $sIndex)
  1248. {
  1249. $s = $aInput['name'] . '_' . $sIndex;
  1250. if (isset($this->_aSpecificValues[$s]))
  1251. return $this->_aSpecificValues[$s];
  1252. return $this->getCleanValue($s);
  1253. }
  1254. function genInputCaptcha(&$aInput)
  1255. {
  1256. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1257. // for inputs with labels generate id
  1258. if (isset($aInput['label']))
  1259. $aAttrs['id'] = $this->getInputId($aInput);
  1260. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1261. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1262. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1263. }
  1264. /**
  1265. * Generate Label Element
  1266. *
  1267. * @param string $sLabel Text of the Label
  1268. * @param string $sInputID Dependant Input Element ID
  1269. * @return string HTML code
  1270. */
  1271. function genLabel(&$aInput)
  1272. {
  1273. if (!isset($aInput['label']) or empty($aInput['label']))
  1274. return '';
  1275. $sLabel = $aInput['label'];
  1276. $sInputID = $this->getInputId($aInput);
  1277. $sRet = '<label for="' . $sInputID . '">' . bx_process_output($sLabel) . '</label>';
  1278. return $sRet;
  1279. }
  1280. function genInfoIcon($sInfo)
  1281. {
  1282. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1283. }
  1284. function genErrorIcon( $sError = '' )
  1285. {
  1286. if ($this->bEnableErrorIcon) {
  1287. $sStyle = '';
  1288. if (!$sError)
  1289. $sStyle = 'style="display:none;"';
  1290. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1291. }
  1292. }
  1293. function getOpenSection($aAttrs = array(), $sLegend = '')
  1294. {
  1295. if (!$this->_isSectionOpened) {
  1296. if (!$aAttrs || !is_array($aAttrs))
  1297. $aAttrs = array();
  1298. if ($sLegend)
  1299. $sClassesAdd = "bx-form-section-header";
  1300. else
  1301. $sClassesAdd = "bx-form-section-divider";
  1302. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1303. $this->_isSectionOpened = true;
  1304. return "<!-- form header content begins -->\n <div class=\"bx-form-section-wrapper bx-def-margin-top\"> <div $sAttrs> $sLegend <div class=\"bx-form-section-content bx-def-padding-top bx-def-padding-bottom" . ($sLegend ? ' bx-def-padding-left bx-def-padding-right' : '') . "\">\n";
  1305. } else {
  1306. return '';
  1307. }
  1308. }
  1309. function getCloseSection()
  1310. {
  1311. if ($this->_isSectionOpened) {
  1312. $this->_isSectionOpened = false;
  1313. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1314. } else {
  1315. return '';
  1316. }
  1317. }
  1318. function getOpenSectionViewMode($aAttrs = array(), $sLegend = '')
  1319. {
  1320. if (!$this->_isSectionOpened) {
  1321. if (!$aAttrs || !is_array($aAttrs))
  1322. $aAttrs = array();
  1323. if ($sLegend)
  1324. $sClassesAdd = "bx-form-section-header";
  1325. else
  1326. $sClassesAdd = "bx-form-section-divider";
  1327. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1328. $this->_isSectionOpened = true;
  1329. return "<!-- form header content begins -->\n <div class=\"bx-form-section-wrapper bx-def-margin-top\"> <div $sAttrs> $sLegend <div class=\"bx-form-section-content bx-def-padding-top\">\n";
  1330. } else {
  1331. return '';
  1332. }
  1333. }
  1334. function getCloseSectionViewMode()
  1335. {
  1336. if ($this->_isSectionOpened) {
  1337. $this->_isSectionOpened = false;
  1338. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1339. } else {
  1340. return '';
  1341. }
  1342. }
  1343. static function getJsUiLangs ()
  1344. {
  1345. return array ('af' => 1, 'ar-DZ' => 1, 'ar' => 1, 'az' => 1, 'be' => 1, 'bg' => 1, 'bs' => 1, 'ca' => 1, 'cs' => 1, 'cy-GB' => 1, 'da' => 1, 'de' => 1, 'el' => 1, 'en-AU' => 1, 'en-GB' => 1, 'en-NZ' => 1, 'en' => 1, 'eo' => 1, 'es' => 1, 'et' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1, 'fo' => 1, 'fr-CA' => 1, 'fr-CH' => 1, 'fr' => 1, 'gl' => 1, 'he' => 1, 'hi' => 1, 'hr' => 1, 'hu' => 1, 'hy' => 1, 'id' => 1, 'is' => 1, 'it' => 1, 'ja' => 1, 'ka' => 1, 'kk' => 1, 'km' => 1, 'ko' => 1, 'ky' => 1, 'lb' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'ml' => 1, 'ms' => 1, 'nb' => 1, 'nl-BE' => 1, 'nl' => 1, 'nn' => 1, 'no' => 1, 'pl' => 1, 'pt-BR' => 1, 'pt' => 1, 'rm' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sq' => 1, 'sr-SR' => 1, 'sr' => 1, 'sv' => 1, 'ta' => 1, 'th' => 1, 'tj' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-CN' => 1, 'zh-HK' => 1, 'zh-TW' => 1);
  1346. }
  1347. function addCssJsUi ()
  1348. {
  1349. if (self::$_isCssJsUiAdded)
  1350. return;
  1351. $aUiLangs = $this->getJsUiLangs ();
  1352. $sUiLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aUiLangs);
  1353. $this->_addJs(array(
  1354. 'jquery-ui/jquery-ui.custom.min.js',
  1355. 'jquery-ui/i18n/jquery.ui.datepicker-' . $sUiLang . '.min.js',
  1356. ), "'undefined' === typeof($.datepicker)");
  1357. $this->_addCss('jquery-ui/jquery-ui.css');
  1358. self::$_isCssJsUiAdded = true;
  1359. }
  1360. function addCssJsTimepicker ()
  1361. {
  1362. if (self::$_isCssJsTimepickerAdded)
  1363. return;
  1364. $aCalendarLangs = array ('af' => 1, 'am' => 1, 'bg' => 1, 'ca' => 1, 'cs' => 1, 'da' => 1, 'de' => 1, 'el' => 1, 'es' => 1, 'et' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1, 'fr' => 1, 'gl' => 1, 'he' => 1, 'hr' => 1, 'hu' => 1, 'id' => 1, 'it' => 1, 'ja' => 1, 'ko' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'nl' => 1, 'no' => 1, 'pl' => 1, 'pt-BR' => 1, 'pt' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sr-RS' => 1, 'sr-YU' => 1, 'sv' => 1, 'th' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-CN' => 1, 'zh-TW' => 1);
  1365. $sCalendarLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aCalendarLangs);
  1366. $this->_addCss('timepicker-addon/jquery-ui-timepicker-addon.css');
  1367. $this->_addJs(array(
  1368. 'timepicker-addon/jquery-ui-timepicker-addon.min.js',
  1369. 'timepicker-addon/jquery-ui-sliderAccess.js',
  1370. 'timepicker-addon/i18n/jquery-ui-timepicker-' . $sCalendarLang . '.js',
  1371. 'jquery.ui.touch-punch.min.js',
  1372. ), "'undefined' === typeof($.fn.datetimepicker)");
  1373. self::$_isCssJsTimepickerAdded = true;
  1374. }
  1375. function addCssJsMinicolors ()
  1376. {
  1377. if (self::$_isCssJsMinicolorsAdded)
  1378. return;
  1379. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  1380. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  1381. self::$_isCssJsMinicolorsAdded = true;
  1382. }
  1383. function addCssJsViewMode ()
  1384. {
  1385. if (self::$_isCssJsAddedViewMode)
  1386. return;
  1387. $this->_addCss('forms.css');
  1388. self::$_isCssJsAddedViewMode = true;
  1389. }
  1390. function addCssJsCore ()
  1391. {
  1392. if (self::$_isCssJsAdded)
  1393. return;
  1394. $this->_addCss('forms.css');
  1395. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  1396. self::$_isCssJsAdded = true;
  1397. }
  1398. function addCssJs ()
  1399. {
  1400. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  1401. $this->addCssJsViewMode ();
  1402. } else {
  1403. $this->addCssJsCore();
  1404. }
  1405. }
  1406. protected function _processCssJs()
  1407. {
  1408. $sRet = '';
  1409. if ($this->_bDynamicMode) {
  1410. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  1411. $sRet .= "\n<script>\n";
  1412. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  1413. foreach ($this->_aJs as $sCondition => $aJs) {
  1414. $sJs = $this->oTemplate->addJs($aJs, true);
  1415. if (!$sJs)
  1416. continue;
  1417. $sRet .= "if ($sCondition)\n";
  1418. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  1419. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  1420. }
  1421. $sRet .= "\n</script>\n";
  1422. }
  1423. else {
  1424. $this->oTemplate->addCss($this->_aCss);
  1425. $aJs = array();
  1426. foreach ($this->_aJs as $sCondition => $a)
  1427. $aJs = array_merge($aJs, $a);
  1428. $this->oTemplate->addJs($aJs);
  1429. }
  1430. return $sRet;
  1431. }
  1432. protected function _addJs($mixed, $sJsCondition)
  1433. {
  1434. if (!is_array($mixed))
  1435. $mixed = array($mixed);
  1436. $this->_aJs[$sJsCondition] = $mixed;
  1437. }
  1438. protected function _addCss($mixed)
  1439. {
  1440. if (!is_array($mixed))
  1441. $mixed = array($mixed);
  1442. foreach ($mixed as $s)
  1443. $this->_aCss[$s] = $s;
  1444. }
  1445. }
  1446. /** @} */