1
0

BxBaseFormView.php 48 KB

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