BxBaseFormView.php 62 KB

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