1
0

BxBaseFormView.php 50 KB

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