1
0

BxBaseFormView.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  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. $aVars = array (
  978. 'key' => trim(getParam('sys_maps_api_key')),
  979. 'lang' => bx_lang_name(),
  980. 'name' => $aInput['name'],
  981. 'id_status' => $sIdStatus,
  982. 'id_input' => $sIdInput,
  983. 'manual_input' => $isManualInput,
  984. 'bx_if:manual_input' => array(
  985. 'condition' => $isManualInput,
  986. 'content' => array(),
  987. ),
  988. 'bx_if:auto_input' => array(
  989. 'condition' => !$isManualInput,
  990. 'content' => array(
  991. 'id_status' => $sIdStatus,
  992. 'location_string' => _t('_sys_location_undefined'),
  993. ),
  994. ),
  995. );
  996. $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip', 'street', 'street_number');
  997. foreach ($aLocationIndexes as $sKey)
  998. $aVars[$sKey] = $this->getLocationVal($aInput, $sKey);
  999. if ($aVars['country']) {
  1000. $aCountries = BxDolFormQuery::getDataItems('Country');
  1001. $s = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
  1002. $aVars['bx_if:auto_input']['content']['location_string'] = $s;
  1003. }
  1004. if ($isManualInput) {
  1005. $aInput['type'] = 'text';
  1006. $aInput['attrs']['id'] = $sIdInput;
  1007. $aVars['input'] = $this->genInputStandard($aInput);
  1008. }
  1009. else {
  1010. if ($this->getLocationVal($aInput, 'lat') && $this->getLocationVal($aInput, 'lng'))
  1011. $aInput['checked'] = true;
  1012. else
  1013. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  1014. $aVars['input'] = $this->genInputSwitcher($aInput);
  1015. }
  1016. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  1017. }
  1018. public function setLocationVal ($aInput, $sIndex, $sVal)
  1019. {
  1020. $s = $aInput['name'] . '_' . $sIndex;
  1021. $this->_aSpecificValues[$s] = $sVal;
  1022. }
  1023. protected function getLocationVal ($aInput, $sIndex)
  1024. {
  1025. $s = $aInput['name'] . '_' . $sIndex;
  1026. if (isset($this->_aSpecificValues[$s]))
  1027. return $this->_aSpecificValues[$s];
  1028. return $this->getCleanValue($s);
  1029. }
  1030. function genInputCaptcha(&$aInput)
  1031. {
  1032. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1033. // for inputs with labels generate id
  1034. if (isset($aInput['label']))
  1035. $aAttrs['id'] = $this->getInputId($aInput);
  1036. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1037. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1038. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1039. }
  1040. /**
  1041. * Generate Label Element
  1042. *
  1043. * @param string $sLabel Text of the Label
  1044. * @param string $sInputID Dependant Input Element ID
  1045. * @return string HTML code
  1046. */
  1047. function genLabel(&$aInput)
  1048. {
  1049. if (!isset($aInput['label']) or empty($aInput['label']))
  1050. return '';
  1051. $sLabel = $aInput['label'];
  1052. $sInputID = $this->getInputId($aInput);
  1053. $sRet = '<label for="' . $sInputID . '">' . bx_process_output($sLabel) . '</label>';
  1054. return $sRet;
  1055. }
  1056. function genInfoIcon($sInfo)
  1057. {
  1058. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1059. }
  1060. function genErrorIcon( $sError = '' )
  1061. {
  1062. if ($this->bEnableErrorIcon) {
  1063. $sStyle = '';
  1064. if (!$sError)
  1065. $sStyle = 'style="display:none;"';
  1066. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1067. }
  1068. }
  1069. function getOpenSection($aAttrs = array(), $sLegend = '')
  1070. {
  1071. if (!$this->_isSectionOpened) {
  1072. if (!$aAttrs || !is_array($aAttrs))
  1073. $aAttrs = array();
  1074. if ($sLegend)
  1075. $sClassesAdd = "bx-form-section-header";
  1076. else
  1077. $sClassesAdd = "bx-form-section-divider";
  1078. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1079. $this->_isSectionOpened = true;
  1080. 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";
  1081. } else {
  1082. return '';
  1083. }
  1084. }
  1085. function getCloseSection()
  1086. {
  1087. if ($this->_isSectionOpened) {
  1088. $this->_isSectionOpened = false;
  1089. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1090. } else {
  1091. return '';
  1092. }
  1093. }
  1094. function getOpenSectionViewMode($aAttrs = array(), $sLegend = '')
  1095. {
  1096. if (!$this->_isSectionOpened) {
  1097. if (!$aAttrs || !is_array($aAttrs))
  1098. $aAttrs = array();
  1099. if ($sLegend)
  1100. $sClassesAdd = "bx-form-section-header";
  1101. else
  1102. $sClassesAdd = "bx-form-section-divider";
  1103. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1104. $this->_isSectionOpened = true;
  1105. 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";
  1106. } else {
  1107. return '';
  1108. }
  1109. }
  1110. function getCloseSectionViewMode()
  1111. {
  1112. if ($this->_isSectionOpened) {
  1113. $this->_isSectionOpened = false;
  1114. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1115. } else {
  1116. return '';
  1117. }
  1118. }
  1119. function addCssJs ()
  1120. {
  1121. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  1122. if (self::$_isCssJsAddedViewMode)
  1123. return;
  1124. $this->_addCss('forms.css');
  1125. self::$_isCssJsAddedViewMode = true;
  1126. } else {
  1127. if (self::$_isCssJsAdded)
  1128. return;
  1129. $aCss = array(
  1130. 'forms.css',
  1131. 'jquery-ui/jquery-ui.css',
  1132. 'timepicker-addon/jquery-ui-timepicker-addon.css',
  1133. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css',
  1134. );
  1135. $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);
  1136. $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);
  1137. $sCalendarLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aCalendarLangs);
  1138. $sUiLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aUiLangs);
  1139. $aJs = array(
  1140. 'jquery-ui/jquery-ui.custom.min.js',
  1141. 'jquery.webForms.js',
  1142. 'jquery-ui/i18n/jquery.ui.datepicker-' . $sUiLang . '.js',
  1143. 'jquery-minicolors/jquery.minicolors.min.js',
  1144. 'timepicker-addon/jquery-ui-timepicker-addon.min.js',
  1145. 'timepicker-addon/jquery-ui-sliderAccess.js',
  1146. 'timepicker-addon/i18n/jquery-ui-timepicker-' . $sCalendarLang . '.js',
  1147. );
  1148. foreach ($this->aInputs as $aInput) {
  1149. if (!isset($aInput['type']) || 'files' != $aInput['type'] || !isset($aInput['uploaders']))
  1150. continue;
  1151. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1152. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], '', $this->oTemplate);
  1153. if ($oUploader)
  1154. $oUploader->addCssJs();
  1155. }
  1156. }
  1157. $this->_addJs($aJs);
  1158. $this->_addCss($aCss);
  1159. self::$_isCssJsAdded = true;
  1160. }
  1161. }
  1162. protected function _processCssJs()
  1163. {
  1164. $sRet = '';
  1165. if ($this->_bDynamicMode) {
  1166. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  1167. $sJs = $this->oTemplate->addJs($this->_aJs, true);
  1168. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  1169. $sRet .= "<script>
  1170. bx_get_scripts(" . json_encode($aMatches[1]) . ");
  1171. </script>";
  1172. }
  1173. else {
  1174. $this->oTemplate->addCss($this->_aCss);
  1175. $this->oTemplate->addJs($this->_aJs);
  1176. }
  1177. return $sRet;
  1178. }
  1179. protected function _addJs($mixed)
  1180. {
  1181. if (!is_array($mixed))
  1182. $mixed = array($mixed);
  1183. foreach ($mixed as $s)
  1184. $this->_aJs[$s] = $s;
  1185. }
  1186. protected function _addCss($mixed)
  1187. {
  1188. if (!is_array($mixed))
  1189. $mixed = array($mixed);
  1190. foreach ($mixed as $s)
  1191. $this->_aCss[$s] = $s;
  1192. }
  1193. }
  1194. /** @} */