BxBaseFormView.php 47 KB

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