BxBaseFormView.php 64 KB

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