BxBaseFormView.php 49 KB

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