1
0

BxBaseFormView.php 50 KB

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