BxBaseFormView.php 48 KB

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