BxBaseFormView.php 47 KB

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