BxBaseFormView.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. class BxBaseFormView extends BxDolForm
  10. {
  11. protected static $_isToggleJsAdded = false;
  12. protected static $_isCssJsAdded = false;
  13. protected static $_isCssJsAddedViewMode = false;
  14. /**
  15. * Enable or disable error message displaying
  16. */
  17. protected $bEnableErrorIcon = true;
  18. /**
  19. * HTML Code of this form
  20. */
  21. protected $sCode;
  22. /**
  23. * Code which will be added to the beginning of the form.
  24. * For example, hidden inputs.
  25. * For internal use only
  26. */
  27. protected $_sCodeAdd = '';
  28. /**
  29. * for internal use only
  30. */
  31. protected $_isSectionOpened = false;
  32. /**
  33. * Default divider for several inputs
  34. */
  35. protected $_sDivider = '<span class="bx-def-margin-left"></span>';
  36. /**
  37. * Alternative divider for several inputs
  38. */
  39. protected $_sDividerAlt = '<br />';
  40. /**
  41. * Form is added dynamically.
  42. */
  43. protected $_bDynamicMode = false;
  44. /**
  45. * Function name for generation close form section HTML.
  46. */
  47. protected $_sSectionClose = 'getCloseSection';
  48. /**
  49. * Function name for generation open form section HTML.
  50. */
  51. protected $_sSectionOpen = 'getOpenSection';
  52. /**
  53. * Constructor
  54. *
  55. * @param array $aInfo Form contents
  56. *
  57. * $aInfo['params'] = array(
  58. * 'remove_form' => true|false,
  59. * );
  60. *
  61. * @return BxBaseFormView
  62. */
  63. function __construct($aInfo, $oTemplate)
  64. {
  65. parent::__construct($aInfo, $oTemplate);
  66. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  67. $this->_sSectionClose = 'getCloseSectionViewMode';
  68. $this->_sSectionOpen = 'getOpenSectionViewMode';
  69. }
  70. }
  71. /**
  72. * Return Form code
  73. * @param $bDynamicMode - set it to true if form is added via JS/AJAX call, for example form in AJAX popup.
  74. * @return string
  75. */
  76. function getCode($bDynamicMode = false)
  77. {
  78. $this->_bDynamicMode = $bDynamicMode;
  79. $this->addCssJs ();
  80. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  81. return ($this->sCode = $this->genForm());
  82. }
  83. /**
  84. * Generate the whole form
  85. *
  86. * @return string
  87. */
  88. function genForm()
  89. {
  90. $this->_sCodeAdd = '';
  91. $sTable = $this->genRows();
  92. $sHtmlBefore = isset($this->aParams['html_before']) ? $this->aParams['html_before'] : '';
  93. $sHtmlAfter = isset($this->aParams['html_after']) ? $this->aParams['html_after'] : '';
  94. if (!empty($this->aParams['remove_form']) || (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])) {
  95. $sForm = <<<BLAH
  96. $sHtmlBefore
  97. {$this->_sCodeAdd}
  98. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  99. $sTable
  100. </div>
  101. $sHtmlAfter
  102. BLAH;
  103. } else {
  104. $sFormAttrs = bx_convert_array2attrs($this->aFormAttrs, 'bx-form-advanced');
  105. $sForm = <<<BLAH
  106. $sHtmlBefore
  107. <form $sFormAttrs>
  108. {$this->_sCodeAdd}
  109. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  110. $sTable
  111. </div>
  112. </form>
  113. <script>
  114. $(document).ready(function() {
  115. $(this).addWebForms();
  116. });
  117. </script>
  118. $sHtmlAfter
  119. BLAH;
  120. }
  121. return $sForm;
  122. }
  123. /**
  124. * Generate Table HTML code
  125. *
  126. * @return string
  127. */
  128. function genRows()
  129. {
  130. // add CSRF token if it's needed.
  131. 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) {
  132. $this->aInputs['csrf_token'] = array(
  133. 'type' => 'hidden',
  134. 'name' => 'csrf_token',
  135. 'value' => $mixedCsrfToken,
  136. 'db' => array ('pass' => 'Xss'),
  137. 'visible_for_levels' => PHP_INT_MAX,
  138. );
  139. }
  140. // check if we need to generate open section clause
  141. $sOpenSection = '';
  142. foreach ($this->aInputs as $aInput) {
  143. if (isset($aInput['type']) && 'hidden' == $aInput['type'])
  144. continue;
  145. if (isset($aInput['type']) && 'block_header' != $aInput['type'])
  146. $sOpenSection = $this->{$this->_sSectionOpen}();
  147. break;
  148. }
  149. // generate rows contents
  150. $sCont = '';
  151. $sFuncGenRow = isset($this->aParams['view_mode']) && $this->aParams['view_mode'] ? 'genViewRow' : 'genRow';
  152. foreach ($this->aInputs as $aInput)
  153. if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput))
  154. $sCont .= $this->$sFuncGenRow($aInput);
  155. $sCloseSection = $this->{$this->_sSectionClose}();
  156. return $sOpenSection . $sCont . $sCloseSection;
  157. }
  158. /**
  159. * Generate single Table Row
  160. *
  161. * @param array $aInput
  162. * @return string
  163. */
  164. function genRow(&$aInput)
  165. {
  166. if (!isset($aInput['type']))
  167. $aInput['type'] = false;
  168. if (!empty($aInput['name'])) {
  169. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  170. if (method_exists($this, $sCustomMethod))
  171. return $this->$sCustomMethod($aInput);
  172. }
  173. switch ($aInput['type']) {
  174. case 'block_header':
  175. $sRow = $this->genRowBlockHeader($aInput);
  176. break;
  177. case 'block_end':
  178. $sRow = $this->genBlockEnd($aInput);
  179. break;
  180. case 'hidden':
  181. // do not generate row for hidden inputs
  182. $sRow = '';
  183. $this->_sCodeAdd .= $this->genInput($aInput);
  184. break;
  185. case 'select_box':
  186. $sRow = $this->genRowCustom($aInput, 'genInputSelectBox');
  187. break;
  188. case 'files':
  189. $sRow = $this->genRowCustom($aInput, 'genInputFiles');
  190. break;
  191. case 'switcher':
  192. case 'checkbox':
  193. $sRow = $this->genRowStandard($aInput, true);
  194. break;
  195. default:
  196. $sRow = $this->genRowStandard($aInput);
  197. }
  198. return $sRow;
  199. }
  200. /**
  201. * Generate single Table Row for view mode
  202. *
  203. * @param array $aInput
  204. * @return string
  205. */
  206. function genViewRow(&$aInput)
  207. {
  208. if (!isset($aInput['type']))
  209. $aInput['type'] = false;
  210. if (!empty($aInput['name'])) {
  211. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  212. if (method_exists($this, $sCustomMethod))
  213. return $this->$sCustomMethod($aInput);
  214. }
  215. switch ($aInput['type']) {
  216. case 'block_header':
  217. $sRow = $this->genRowBlockHeader($aInput);
  218. break;
  219. case 'block_end':
  220. $sRow = $this->genBlockEnd($aInput);
  221. break;
  222. default:
  223. $sRow = $this->genViewRowWrapped($aInput);
  224. }
  225. return $sRow;
  226. }
  227. /**
  228. * Generate complete wrapped row for view mode form
  229. *
  230. * @param array $aInput
  231. * @return string
  232. */
  233. function genViewRowWrapped(&$aInput)
  234. {
  235. $sValue = $this->genViewRowValue($aInput);
  236. if (null === $sValue)
  237. return '';
  238. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  239. return <<<EOS
  240. <div class="bx-form-row-view-wrapper bx-form-row-view-wrapper-{$aInput['type']} bx-def-padding-sec-top">
  241. <div class="bx-form-row-view-caption">{$sCaption}:</div>
  242. <div class="bx-form-row-view-value">{$sValue}</div>
  243. </div>
  244. EOS;
  245. }
  246. /**
  247. * Generate value for view mode row
  248. *
  249. * @param array $aInput
  250. * @return string
  251. */
  252. function genViewRowValue(&$aInput)
  253. {
  254. switch ($aInput['type']) {
  255. case 'hidden':
  256. $sValue = null;
  257. break;
  258. case 'select':
  259. case 'radio_set':
  260. $sValue = $this->genViewRowValueForSelect($aInput);
  261. break;
  262. case 'datepicker':
  263. $iTime = bx_process_input ($aInput['value'], isset($aInput['date_filter']) ? $aInput['date_filter'] : BX_DATA_DATE_TS, false, false);
  264. $sValue = bx_time_js ($iTime, isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE);
  265. break;
  266. case 'date_time':
  267. case 'datetime':
  268. $iTime = bx_process_input ($aInput['value'], isset($aInput['date_filter']) ? $aInput['date_filter'] : BX_DATA_DATETIME_TS, false, false);
  269. $sValue = bx_time_js ($iTime, isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME);
  270. break;
  271. case 'checkbox_set':
  272. case 'select_multiple':
  273. $sValue = null;
  274. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  275. $sValue = '';
  276. foreach ($aInput['value'] as $sVal)
  277. $sValue .= $aInput['values'][$sVal] . ', ';
  278. $sValue = trim ($sValue, ', ');
  279. }
  280. break;
  281. case 'checkbox':
  282. case 'switcher':
  283. $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off');
  284. break;
  285. case 'textarea':
  286. if (isset($aInput['value']) && '' !== $aInput['value'])
  287. $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE);
  288. else
  289. $sValue = null;
  290. break;
  291. default:
  292. $sValue = isset($aInput['value']) && '' !== $aInput['value'] ? bx_process_output($aInput['value']) : null;
  293. }
  294. return $sValue;
  295. }
  296. function genViewRowValueForSelect(&$aInput)
  297. {
  298. $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
  299. if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])))
  300. return $oCategory->getCategoryLink($s, $aInput['value']);
  301. return $s;
  302. }
  303. /**
  304. * Generate standard row
  305. *
  306. * @param array $aInput
  307. * @return string
  308. */
  309. function genRowStandard(&$aInput, $isOneLine = false)
  310. {
  311. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  312. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span> ' : '';
  313. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  314. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  315. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  316. if (isset($aInput['name']))
  317. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  318. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), "bx-form-element-wrapper bx-def-margin-top");
  319. $sClassOneLineCaption = '';
  320. $sClassOneLineValue = '';
  321. if ($isOneLine) {
  322. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' bx-def-margin-sec-left';
  323. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  324. $aInput['attrs']['id'] = $this->getInputId($aInput);
  325. if ($sCaption)
  326. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  327. }
  328. $sInput = $this->genInput($aInput);
  329. $sCaptionCode = '';
  330. if ($sCaption)
  331. $sCaptionCode = '<div class="bx-form-caption' . $sClassOneLineCaption . '">' . $sCaption . $sRequired . '</div>';
  332. else
  333. $sInput .= $sRequired;
  334. $sInputCode = $this->genWrapperInput($aInput, $sInput);
  335. if (empty($sInputCodeExtra)) $sInputCodeExtra = '';
  336. if (empty($sInfoIcon)) $sInfoIcon = '';
  337. if (empty($sInputCode)) $sInputCode = '';
  338. if (empty($sErrorIcon)) $sErrorIcon = '';
  339. $sValueCode = '
  340. <div class="bx-form-value bx-clearfix' . $sClassAdd . $sClassOneLineValue . '">
  341. ' . $sInputCode . '
  342. ' . ($isOneLine ? '' : $sInfoIcon . $sErrorIcon) . '
  343. ' . $sInputCodeExtra . '
  344. </div>';
  345. if ($isOneLine)
  346. $sCode = $sValueCode . $sCaptionCode . '<div class="bx-clear"></div>' . $sInfoIcon . $sErrorIcon;
  347. else
  348. $sCode = $sCaptionCode . $sValueCode;
  349. return "<div $sTrAttrs>" . $sCode . "</div>";
  350. }
  351. function genWrapperInput($aInput, $sContent)
  352. {
  353. $sAttr = isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper']) ? bx_convert_array2attrs($aInput['attrs_wrapper']) : '';
  354. return "<div class=\"bx-form-input-wrapper bx-form-input-wrapper-{$aInput['type']}\" $sAttr>$sContent</div>";
  355. }
  356. /**
  357. * Generate custom row
  358. *
  359. * @param array $aInput
  360. * @param string $sCustomMethod custom method to generate code for input
  361. * @return string
  362. */
  363. function genRowCustom(&$aInput, $sCustomMethod)
  364. {
  365. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  366. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span> ' : '';
  367. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  368. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  369. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  370. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  371. if (isset($aInput['name']))
  372. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  373. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  374. $sCaptionCode = '';
  375. if ($sCaption)
  376. $sCaptionCode = '<div class="bx-form-caption">' . $sCaption . $sRequired . '</div>';
  377. $sCode = <<<BLAH
  378. <div $sTrAttrs>
  379. $sCaptionCode
  380. <div class="bx-form-value$sClassAdd">
  381. <div class="bx-clear"></div>
  382. $sInput
  383. <div class="bx-clear"></div>
  384. </div>
  385. </div>
  386. BLAH;
  387. return $sCode;
  388. }
  389. /**
  390. * Generate Block Headers row
  391. *
  392. * @param array $aInput
  393. * @return string
  394. */
  395. function genRowBlockHeader(&$aInput)
  396. {
  397. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  398. // if there is no caption - show divider only
  399. if (empty($aInput['caption'])) {
  400. $sCode = $this->{$this->_sSectionClose}();
  401. $sCode .= $this->{$this->_sSectionOpen}($aAttrs);
  402. return $sCode;
  403. }
  404. // if section is collapsed by default, add necessary code
  405. $sClassAddCollapsable = 'bx-form-collapsable';
  406. if (isset($aInput['collapsed']) and $aInput['collapsed'])
  407. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  408. // display section with caption
  409. $sCode = $this->{$this->_sSectionClose}();
  410. if (empty($aAttrs))
  411. $aAttrs['class'] = 'bx-form-collapsable ' . $sClassAddCollapsable;
  412. else
  413. $aAttrs['class'] .= ' bx-form-collapsable ' . $sClassAddCollapsable;
  414. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])
  415. $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']) . '</legend>';
  416. else
  417. $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></legend>';
  418. $sCode .= $this->{$this->_sSectionOpen}($aAttrs, $sLegend);
  419. return $sCode;
  420. }
  421. function genBlockEnd()
  422. {
  423. $aNextTbodyAdd = false; // need to have some default
  424. $sCode = '';
  425. $sCode .= $this->{$this->_sSectionClose}();
  426. $sCode .= $this->{$this->_sSectionOpen}($aNextTbodyAdd);
  427. return $sCode;
  428. }
  429. /**
  430. * Generate HTML Input Element
  431. *
  432. * @param array $aInput
  433. * @return string Output HTML Code
  434. */
  435. function genInput(&$aInput)
  436. {
  437. if (!empty($aInput['name'])) {
  438. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  439. if (method_exists($this, $sCustomMethod))
  440. return $this->$sCustomMethod($aInput);
  441. }
  442. switch ($aInput['type']) {
  443. // standard inputs (and non-standard, interpreted as standard)
  444. case 'text':
  445. case 'datepicker':
  446. case 'date_time':
  447. case 'datetime':
  448. case 'number':
  449. case 'checkbox':
  450. case 'radio':
  451. case 'image':
  452. case 'password':
  453. case 'slider':
  454. case 'doublerange':
  455. case 'hidden':
  456. $sInput = $this->genInputStandard($aInput);
  457. break;
  458. case 'file':
  459. $sInput = $this->genInputFile($aInput);
  460. break;
  461. case 'rgb':
  462. case 'rgba':
  463. $sClass = 'bx-form-input-' . $aInput['type'];
  464. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  465. $aInput['type'] = 'text';
  466. $sInput = $this->genInputStandard($aInput);
  467. break;
  468. case 'switcher':
  469. $sInput = $this->genInputSwitcher($aInput);
  470. break;
  471. case 'button':
  472. case 'reset':
  473. case 'submit':
  474. $sInput = $this->genInputButton($aInput);
  475. break;
  476. case 'textarea':
  477. $sInput = $this->genInputTextarea($aInput);
  478. break;
  479. case 'select':
  480. $sInput = $this->genInputSelect($aInput);
  481. break;
  482. case 'select_multiple':
  483. $sInput = $this->genInputSelectMultiple($aInput);
  484. break;
  485. case 'checkbox_set':
  486. $sInput = $this->genInputCheckboxSet($aInput);
  487. break;
  488. case 'radio_set':
  489. $sInput = $this->genInputRadioSet($aInput);
  490. break;
  491. case 'input_set': // numeric array of inputs
  492. $sInput = '';
  493. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  494. foreach ($aInput as $iKey => $aSubInput) {
  495. if (!is_int($iKey) or !$aSubInput)
  496. continue; // parse only integer keys and existing values
  497. $sInput .= $this->genInput($aSubInput); // recursive call
  498. $sInput .= $sDivider;
  499. }
  500. $sInput .= '<div class="bx-clear"></div>';
  501. break;
  502. case 'custom':
  503. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  504. break;
  505. case 'captcha':
  506. $sInput = $this->genInputCaptcha($aInput);
  507. break;
  508. case 'location':
  509. $sInput = $this->genInputLocation($aInput);
  510. break;
  511. case 'value':
  512. $sInput = isset($aInput['value']) ? $aInput['value'] : '';
  513. break;
  514. default:
  515. //unknown control type
  516. $sInput = 'Unknown control type';
  517. }
  518. // create input label
  519. $sInput .= $this->genLabel($aInput);
  520. return $sInput;
  521. }
  522. /**
  523. * Generate new Input Element id
  524. *
  525. * @param array $aInput
  526. * @return string
  527. */
  528. function getInputId(&$aInput)
  529. {
  530. if (isset($aInput['id']))
  531. return $aInput['id'];
  532. $sName = md5($aInput['name']);
  533. $sID = $this->id . '_input_' . $sName;
  534. if ( // multiple elements cause identical id's
  535. (
  536. (
  537. $aInput['type'] == 'checkbox' and
  538. substr($aInput['name'], -2) == '[]' // it is multiple element
  539. ) or
  540. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  541. ) and
  542. isset($aInput['value']) // if we can make difference
  543. ) {
  544. $sValue = md5($aInput['value']);
  545. // add value
  546. $sID .= '_' . $sValue;
  547. }
  548. $sID = trim($sID, '_');
  549. $aInput['id'] = $sID; // just for repeated calls
  550. return $sID;
  551. }
  552. /**
  553. * Generate standard Input Element
  554. *
  555. * @param array $aInput
  556. * @return string
  557. */
  558. function genInputStandard(&$aInput)
  559. {
  560. // clone attributes for system use ;)
  561. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  562. // add default className to attributes
  563. $aAttrs['type'] = $aInput['type'];
  564. if ('datetime' == $aAttrs['type'])
  565. $aAttrs['type'] = 'date_time';
  566. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  567. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  568. // for inputs with labels generate id
  569. if (isset($aInput['label']))
  570. $aAttrs['id'] = $this->getInputId($aInput);
  571. // for checkboxes
  572. if (isset($aInput['checked']) and $aInput['checked'])
  573. $aAttrs['checked'] = 'checked';
  574. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  575. return "<input $sAttrs />\n";
  576. }
  577. /**
  578. * Generate Switcher Input Element (based on checkbox)
  579. *
  580. * @param array $aInput
  581. * @return string
  582. */
  583. function genInputSwitcher(&$aInput)
  584. {
  585. $aInput['type'] = 'checkbox';
  586. $sCheckbox = $this->genInputStandard($aInput);
  587. $aInput['type'] = 'switcher';
  588. $sClass = 'off';
  589. if (isset($aInput['checked']) and $aInput['checked'])
  590. $sClass = 'on';
  591. return '
  592. <div class="bx-switcher-cont ' . $sClass . '">' . $sCheckbox . '
  593. <div class="bx-switcher-canvas">
  594. <div class="bx-switcher-on"><i class="sys-icon check"></i></div>
  595. <div class="bx-switcher-off"><i class="sys-icon times"></i></div>
  596. <div class="bx-switcher-handler">&nbsp;</div>
  597. </div>
  598. </div>';
  599. }
  600. /**
  601. * Generate Button Input Element
  602. *
  603. * @param array $aInput
  604. * @return string
  605. */
  606. function genInputButton(&$aInput)
  607. {
  608. // clone attributes for system use ;)
  609. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  610. // add default className to attributes
  611. $aAttrs['type'] = $aInput['type'];
  612. if (isset($aInput['value']))
  613. $aAttrs['value'] = $aInput['value'];
  614. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  615. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn" . ('submit' == $aInput['type'] ? ' bx-btn-primary' : ''));
  616. return "<button $sAttrs>" . $aInput['value'] . "</button>\n";
  617. }
  618. /**
  619. * Generate Textarea Element
  620. *
  621. * @param array $aInput
  622. * @return string
  623. */
  624. function genInputTextarea(&$aInput)
  625. {
  626. // clone attributes for system use ;)
  627. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  628. $aAttrs['name'] = $aInput['name'];
  629. // for inputs with labels generate id
  630. if (isset($aInput['label']))
  631. $aAttrs['id'] = $this->getInputId($aInput);
  632. $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' : ''));
  633. $sValue = isset($aInput['value']) ? bx_process_output((isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : strip_tags($aInput['value'])) : '';
  634. return "<textarea $sAttrs>$sValue</textarea>";
  635. }
  636. function addHtmlEditor($iViewMode, &$aInput)
  637. {
  638. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  639. if (!$oEditor)
  640. return false;
  641. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name='.$aInput['name'].']', $iViewMode, $this->_bDynamicMode);
  642. return true;
  643. }
  644. /**
  645. * Generate Select Box Element
  646. *
  647. * @param array $aInput
  648. * @return string
  649. */
  650. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  651. {
  652. $aNewInput = $aInput;
  653. $aNewInput['type'] = 'select';
  654. $aNewInput['name'] .= '[]';
  655. $sInput = $this->genInput($aNewInput);
  656. return <<<BLAH
  657. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  658. $sInput
  659. </div>
  660. $sInfo
  661. $sError
  662. BLAH;
  663. }
  664. /**
  665. * Generate Browse File Element
  666. *
  667. * @param array $aInput
  668. * @return string
  669. */
  670. function genInputFile(&$aInput)
  671. {
  672. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  673. if(!empty($aInput['attrs']['onchange']))
  674. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  675. else
  676. $aInput['attrs']['onchange'] = $sOnChange;
  677. $sInput = $this->genInputStandard($aInput);
  678. 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>';
  679. }
  680. /**
  681. * Generate Select Box Element
  682. *
  683. * @param array $aInput
  684. * @return string
  685. */
  686. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  687. {
  688. $sUniqId = genRndPwd (8, false);
  689. $sUploaders = '';
  690. $oUploader = null;
  691. foreach ($aInput['uploaders'] as $sUploaderObject) {
  692. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  693. if (!$oUploader)
  694. continue;
  695. $sGhostTemplate = $this->genGhostTemplate($aInput);
  696. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  697. if (empty($aInput['attrs']['disabled']))
  698. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  699. $aParams = array(
  700. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  701. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  702. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  703. 'attrs' => bx_convert_array2attrs($aAttrs),
  704. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  705. );
  706. if (isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  707. $aParams['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  708. $sUploaders .= $oUploader->getUploaderButton($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParams);
  709. }
  710. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  711. 'uploaders_buttons' => $sUploaders,
  712. 'info' => $sInfo,
  713. 'error' => $sError,
  714. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  715. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  716. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  717. 'is_init_ghosts' => isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1,
  718. ));
  719. }
  720. protected function genGhostTemplate(&$aInput)
  721. {
  722. $sGhostTemplate = false;
  723. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  724. $oFormNested = $aInput['ghost_template'];
  725. if ($oFormNested instanceof BxDolFormNested)
  726. $sGhostTemplate = $oFormNested->genForm();
  727. } 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
  728. $oFormNested = new BxDolFormNested($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  729. $sGhostTemplate = $oFormNested->getCode();
  730. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  731. $sGhostTemplate = array ();
  732. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  733. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNested)
  734. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  735. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  736. $sGhostTemplate = $aInput['ghost_template'];
  737. }
  738. return $sGhostTemplate;
  739. }
  740. protected function genCustomInputUsernamesSuggestions ($aInput)
  741. {
  742. $this->oTemplate->addJs(array(
  743. 'jquery-ui/jquery-ui.custom.min.js',
  744. 'jquery.form.min.js',
  745. ));
  746. $sVals = '';
  747. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  748. foreach ($aInput['value'] as $sVal) {
  749. if (!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  750. continue;
  751. $sVals .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . $oProfile->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></b>';
  752. }
  753. $sVals = trim($sVals, ',');
  754. }
  755. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  756. 'id' => $aInput['name'] . time(),
  757. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  758. 'name' => $aInput['name'],
  759. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  760. 'vals' => $sVals,
  761. ));
  762. }
  763. /**
  764. * Generate Select Element
  765. *
  766. * @param array $aInput
  767. * @return string
  768. */
  769. function genInputSelect(&$aInput)
  770. {
  771. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  772. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  773. }
  774. /**
  775. * Generate Multiple Select Element
  776. *
  777. * @param array $aInput
  778. * @return string
  779. */
  780. function genInputSelectMultiple(&$aInput)
  781. {
  782. $aCurValues = array();
  783. if (isset($aInput['value']) && $aInput['value'])
  784. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  785. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  786. }
  787. /**
  788. * Generate Checkbox Set Element
  789. *
  790. * @param array $aInput
  791. * @return string
  792. */
  793. function genInputCheckboxSet(&$aInput)
  794. {
  795. $aCurValues = array();
  796. if (isset($aInput['value']) && $aInput['value'])
  797. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  798. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  799. }
  800. /**
  801. * Generate Radiobuttons Set Element
  802. *
  803. * @param array $aInput
  804. * @return string
  805. */
  806. function genInputRadioSet(&$aInput)
  807. {
  808. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  809. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  810. }
  811. function _isSelected ($sValue, $sCurValue)
  812. {
  813. return ((string)$sValue === (string)$sCurValue);
  814. }
  815. function _isSelectedMultiple ($sValue, $aCurValues)
  816. {
  817. return in_array($sValue, $aCurValues);
  818. }
  819. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  820. {
  821. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  822. $aAttrs['name'] = $aInput['name'];
  823. if ($isMultiple) {
  824. $aAttrs['name'] .= '[]';
  825. $aAttrs['multiple'] = 'multiple';
  826. }
  827. // for inputs with labels generate id
  828. if (isset($aInput['label']))
  829. $aAttrs['id'] = $this->getInputId($aInput);
  830. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  831. // generate options
  832. $sOptions = '';
  833. if (isset($aInput['values']) and is_array($aInput['values'])) {
  834. foreach ($aInput['values'] as $sValue => $sTitle) {
  835. $sClassC = $sStyleC = "";
  836. if(is_array($sTitle)) {
  837. if(isset($sTitle['type'])) {
  838. switch($sTitle['type']) {
  839. case 'group_header':
  840. $sTitle = bx_process_output($sTitle['value']);
  841. $sOptions .= <<<BLAH
  842. <optgroup label="$sTitle">
  843. BLAH;
  844. break;
  845. case 'group_end':
  846. $sOptions .= <<<BLAH
  847. </optgroup>
  848. BLAH;
  849. break;
  850. }
  851. continue;
  852. }
  853. $sClassC = isset($sTitle['class']) ? " class=\"" . $sTitle['class'] . "\"" : "";
  854. $sStyleC = isset($sTitle['style']) ? " style=\"" . $sTitle['style'] . "\"" : "";
  855. $sValue = $sTitle['key'];
  856. $sTitle = $sTitle['value'];
  857. }
  858. $sValueC = bx_html_attribute($sValue);
  859. $sTitleC = bx_process_output($sTitle);
  860. $sSelected = $this->$sIsSelectedFunc($sValue, $mixedCurrentVal) ? 'selected="selected"' : '';
  861. $sOptions .= <<<BLAH
  862. <option value="$sValueC"$sClassC$sStyleC $sSelected>$sTitleC</option>
  863. BLAH;
  864. }
  865. }
  866. // generate element
  867. $sCode = <<<BLAH
  868. <select $sAttrs>
  869. $sOptions
  870. </select>
  871. BLAH;
  872. return $sCode;
  873. }
  874. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  875. {
  876. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  877. $aAttrs['name'] = $aInput['name'];
  878. // for inputs with labels generate id
  879. if (isset($aInput['label']))
  880. $aAttrs['id'] = $this->getInputId($aInput);
  881. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  882. // generate options
  883. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  884. $sOptions = '';
  885. if (isset($aInput['values']) and is_array($aInput['values'])) {
  886. if (count($aInput['values']) > 3 && $sDivider == $this->_sDivider)
  887. $sDivider = $this->_sDividerAlt;
  888. // generate complex input using simple standard inputs
  889. foreach ($aInput['values'] as $sValue => $sLabel) {
  890. // create new simple input
  891. $aNewInput = array(
  892. 'type' => $sType,
  893. 'name' => $aInput['name'] . $sNameAppend,
  894. 'value' => $sValue,
  895. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  896. 'label' => $sLabel,
  897. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  898. );
  899. $sNewInput = $this->genInput($aNewInput);
  900. // attach new input to complex
  901. $sOptions .= ($sNewInput . $sDivider);
  902. }
  903. }
  904. // generate element
  905. $sCode = <<<BLAH
  906. <div $sAttrs>
  907. $sOptions
  908. </div>
  909. BLAH;
  910. return $sCode;
  911. }
  912. function genInputLocation(&$aInput)
  913. {
  914. $isManualInput = (int)(isset($aInput['manual_input']) && $aInput['manual_input']);
  915. $sIdStatus = $this->getInputId($aInput) . '_status';
  916. $sIdInput = $this->getInputId($aInput) . '_location';
  917. $sProto = (0 == strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
  918. $this->oTemplate->addJs($sProto . '://maps.google.com/maps/api/js?libraries=places&language=' . bx_lang_name() . '&key=' . trim(getParam('sys_maps_api_key')));
  919. $aVars = array (
  920. 'name' => $aInput['name'],
  921. 'id_status' => $sIdStatus,
  922. 'id_input' => $sIdInput,
  923. 'manual_input' => $isManualInput,
  924. 'bx_if:manual_input' => array(
  925. 'condition' => $isManualInput,
  926. 'content' => array(),
  927. ),
  928. 'bx_if:auto_input' => array(
  929. 'condition' => !$isManualInput,
  930. 'content' => array(
  931. 'id_status' => $sIdStatus,
  932. 'location_string' => _t('_sys_location_undefined'),
  933. ),
  934. ),
  935. );
  936. $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip', 'street', 'street_number');
  937. foreach ($aLocationIndexes as $sKey)
  938. $aVars[$sKey] = $this->getLocationVal($aInput, $sKey);
  939. if ($aVars['country']) {
  940. $aCountries = BxDolFormQuery::getDataItems('Country');
  941. $s = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
  942. $aVars['bx_if:auto_input']['content']['location_string'] = $s;
  943. }
  944. if ($isManualInput) {
  945. $aInput['type'] = 'text';
  946. $aInput['attrs']['id'] = $sIdInput;
  947. $aVars['input'] = $this->genInputStandard($aInput);
  948. }
  949. else {
  950. if ($this->getLocationVal($aInput, 'lat') && $this->getLocationVal($aInput, 'lng'))
  951. $aInput['checked'] = true;
  952. else
  953. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  954. $aVars['input'] = $isManualInput ? $this->genInputStandard($aInput) : $this->genInputSwitcher($aInput);
  955. }
  956. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  957. }
  958. protected function getLocationVal ($aInput, $sIndex)
  959. {
  960. $s = $aInput['name'] . '_' . $sIndex;
  961. if (isset($this->_aSpecificValues[$s]))
  962. return $this->_aSpecificValues[$s];
  963. return $this->getCleanValue($s);
  964. }
  965. function genInputCaptcha(&$aInput)
  966. {
  967. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  968. // for inputs with labels generate id
  969. if (isset($aInput['label']))
  970. $aAttrs['id'] = $this->getInputId($aInput);
  971. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  972. $oCaptcha = BxDolCaptcha::getObjectInstance();
  973. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  974. }
  975. /**
  976. * Generate Label Element
  977. *
  978. * @param string $sLabel Text of the Label
  979. * @param string $sInputID Dependant Input Element ID
  980. * @return string HTML code
  981. */
  982. function genLabel(&$aInput)
  983. {
  984. if (!isset($aInput['label']) or empty($aInput['label']))
  985. return '';
  986. $sLabel = $aInput['label'];
  987. $sInputID = $this->getInputId($aInput);
  988. $sRet = '<label for="' . $sInputID . '">' . bx_process_output($sLabel) . '</label>';
  989. return $sRet;
  990. }
  991. function genInfoIcon($sInfo)
  992. {
  993. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo) . '</div>';
  994. }
  995. function genErrorIcon( $sError = '' )
  996. {
  997. if ($this->bEnableErrorIcon) {
  998. $sStyle = '';
  999. if (!$sError)
  1000. $sStyle = 'style="display:none;"';
  1001. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1002. }
  1003. }
  1004. function getOpenSection($aAttrs = array(), $sLegend = '')
  1005. {
  1006. if (!$this->_isSectionOpened) {
  1007. if (!$aAttrs || !is_array($aAttrs))
  1008. $aAttrs = array();
  1009. if ($sLegend)
  1010. $sClassesAdd = "bx-form-section-header";
  1011. else
  1012. $sClassesAdd = "bx-form-section-divider";
  1013. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1014. $this->_isSectionOpened = true;
  1015. 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";
  1016. } else {
  1017. return '';
  1018. }
  1019. }
  1020. function getCloseSection()
  1021. {
  1022. if ($this->_isSectionOpened) {
  1023. $this->_isSectionOpened = false;
  1024. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1025. } else {
  1026. return '';
  1027. }
  1028. }
  1029. function getOpenSectionViewMode($aAttrs = array(), $sLegend = '')
  1030. {
  1031. if (!$this->_isSectionOpened) {
  1032. if (!$aAttrs || !is_array($aAttrs))
  1033. $aAttrs = array();
  1034. if ($sLegend)
  1035. $sClassesAdd = "bx-form-section-header";
  1036. else
  1037. $sClassesAdd = "bx-form-section-divider";
  1038. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1039. $this->_isSectionOpened = true;
  1040. 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";
  1041. } else {
  1042. return '';
  1043. }
  1044. }
  1045. function getCloseSectionViewMode()
  1046. {
  1047. if ($this->_isSectionOpened) {
  1048. $this->_isSectionOpened = false;
  1049. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1050. } else {
  1051. return '';
  1052. }
  1053. }
  1054. function addCssJs ()
  1055. {
  1056. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  1057. if (self::$_isCssJsAddedViewMode)
  1058. return;
  1059. $this->oTemplate->addCss('forms.css');
  1060. self::$_isCssJsAddedViewMode = true;
  1061. } else {
  1062. if (self::$_isCssJsAdded)
  1063. return;
  1064. $aCss = array(
  1065. 'forms.css',
  1066. 'jquery-ui/jquery-ui.css',
  1067. 'timepicker-addon/jquery-ui-timepicker-addon.css',
  1068. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css',
  1069. );
  1070. $aUiLangs = 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);
  1071. $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);
  1072. $sCalendarLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aCalendarLangs);
  1073. $sUiLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aUiLangs);
  1074. $aJs = array(
  1075. 'jquery.webForms.js',
  1076. 'jquery-ui/jquery.ui.core.min.js',
  1077. 'jquery-ui/jquery.ui.widget.min.js',
  1078. 'jquery-ui/jquery.ui.mouse.min.js',
  1079. 'jquery-ui/jquery.ui.position.min.js',
  1080. 'jquery-ui/jquery.ui.slider.min.js',
  1081. 'jquery-ui/jquery.ui.datepicker.min.js',
  1082. 'jquery-ui/i18n/jquery.ui.datepicker-' . $sUiLang . '.js',
  1083. 'jquery-minicolors/jquery.minicolors.min.js',
  1084. 'timepicker-addon/jquery-ui-timepicker-addon.min.js',
  1085. 'timepicker-addon/jquery-ui-sliderAccess.js',
  1086. 'timepicker-addon/i18n/jquery-ui-timepicker-' . $sCalendarLang . '.js',
  1087. );
  1088. foreach ($this->aInputs as $aInput) {
  1089. if (!isset($aInput['type']) || 'files' != $aInput['type'] || !isset($aInput['uploaders']))
  1090. continue;
  1091. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1092. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], '', $this->oTemplate);
  1093. if ($oUploader)
  1094. $oUploader->addCssJs();
  1095. }
  1096. }
  1097. $this->oTemplate->addJs($aJs);
  1098. $this->oTemplate->addCss($aCss);
  1099. self::$_isCssJsAdded = true;
  1100. }
  1101. }
  1102. }
  1103. /** @} */