BxBaseFormView.php 51 KB

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