BxBaseFormView.php 51 KB

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