BxBaseFormView.php 48 KB

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