1
0

BxBaseFormView.php 48 KB

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