BxBaseFormView.php 51 KB

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