BxBaseFormView.php 48 KB

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