BxBaseFormView.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  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']), BX_DATA_TEXT, array('no_process_macros')) : '';
  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. $this->oTemplate->addJs(array(
  976. 'select2/js/select2.min.js',
  977. 'select2/select2-to-tree/select2totree.js',
  978. ));
  979. $this->oTemplate->addCss(array(
  980. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'select2/css/|select2.min.css',
  981. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'select2/select2-to-tree/|select2totree.css'
  982. ));
  983. $aValues = array();
  984. $oLabel = BxDolLabel::getInstance();
  985. $this->_getLabelOptions(0, $oLabel, $aValues, 1, '');
  986. $aInput['type'] = 'select_multiple bx-form-select-labels';
  987. $aInput['values'] = $aValues;
  988. return $this->genInputSelectMultiple($aInput);
  989. }
  990. protected function _getLabelOptions($iParent, &$oLabel, &$aValues, $iLevel = 1, $sParentValue = '')
  991. {
  992. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  993. foreach($aLabels as $aLabel) {
  994. $aAttrs = array();
  995. if ($aLabel['parent'] != 0)
  996. $aAttrs = array('data-pup' => $sParentValue);
  997. $sClass = 'l' . $iLevel;
  998. $aLabels2 = $oLabel->getLabels(array('type' => 'parent', 'parent' => $aLabel['id']));
  999. if (count($aLabels2) > 0)
  1000. $sClass .= ' non-leaf';
  1001. $aValues[] = array('attrs' => $aAttrs, 'class' => $sClass, 'key' => $aLabel['value'], 'value' => $aLabel['value']);
  1002. $iLevel2 = $iLevel + 1;
  1003. $this->_getLabelOptions($aLabel['id'], $oLabel, $aValues, $iLevel2, $aLabel['value']);
  1004. }
  1005. }
  1006. /*
  1007. protected function genCustomInputLabels ($aInput)
  1008. {
  1009. // generate currently selected labels
  1010. $sValue = '';
  1011. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  1012. sort($aInput['value'], SORT_LOCALE_STRING);
  1013. foreach ($aInput['value'] as $sVal) {
  1014. $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>';
  1015. }
  1016. $sValue = trim($sValue, ',');
  1017. }
  1018. // generate "following" labels
  1019. $aFollowingLabels = bx_srv('bx_channels', 'get_following_channels_names', array(bx_get_logged_profile_id()));
  1020. if (!is_array($aFollowingLabels))
  1021. $aFollowingLabels = array();
  1022. $aFollowingLabels = array_intersect($aFollowingLabels, $aInput['values']);
  1023. $aFollowingLabels = array_diff($aFollowingLabels, !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array());
  1024. $aValues = array_diff($aInput['values'],
  1025. !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array(),
  1026. !empty($aFollowingLabels) && is_array($aFollowingLabels) ? $aFollowingLabels : array());
  1027. $sValues = '';
  1028. if (!empty($aFollowingLabels)) {
  1029. sort($aFollowingLabels, SORT_LOCALE_STRING);
  1030. foreach ($aFollowingLabels as $sVal) {
  1031. $sValues .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '</b>';
  1032. }
  1033. if (!empty($aValues))
  1034. $sValues .= '<a href="#" class="bx-form-input-autotoken-labels-show-more">' . _t('_sys_show_more') . '</a><i class="bx-form-input-autotoken-labels-more">';
  1035. }
  1036. // generate all possible labels
  1037. if (!empty($aValues)) {
  1038. sort($aValues, SORT_LOCALE_STRING);
  1039. foreach ($aValues as $sVal) {
  1040. $sValues .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '</b>';
  1041. }
  1042. $sValues = trim($sValues, ',');
  1043. }
  1044. if (!empty($aFollowingLabels) && !empty($aValues))
  1045. $sValues .= '</i>';
  1046. return $this->oTemplate->parseHtmlByName('form_field_labels.html', array(
  1047. 'id' => $aInput['name'] . time() . mt_rand(0, 100),
  1048. 'name' => $aInput['name'],
  1049. 'value' => $sValue,
  1050. 'values' => $sValues,
  1051. ));
  1052. }
  1053. */
  1054. /**
  1055. * Generate Select Element
  1056. *
  1057. * @param array $aInput
  1058. * @return string
  1059. */
  1060. function genInputSelect(&$aInput)
  1061. {
  1062. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1063. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1064. }
  1065. /**
  1066. * Generate Multiple Select Element
  1067. *
  1068. * @param array $aInput
  1069. * @return string
  1070. */
  1071. function genInputSelectMultiple(&$aInput)
  1072. {
  1073. $aCurValues = array();
  1074. if (isset($aInput['value']) && $aInput['value'])
  1075. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1076. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  1077. }
  1078. /**
  1079. * Generate Checkbox Set Element
  1080. *
  1081. * @param array $aInput
  1082. * @return string
  1083. */
  1084. function genInputCheckboxSet(&$aInput)
  1085. {
  1086. $aCurValues = array();
  1087. if (isset($aInput['value']) && $aInput['value'])
  1088. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1089. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  1090. }
  1091. /**
  1092. * Generate Radiobuttons Set Element
  1093. *
  1094. * @param array $aInput
  1095. * @return string
  1096. */
  1097. function genInputRadioSet(&$aInput)
  1098. {
  1099. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1100. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  1101. }
  1102. function _isSelected ($sValue, $sCurValue)
  1103. {
  1104. return ((string)$sValue === (string)$sCurValue);
  1105. }
  1106. function _isSelectedMultiple ($sValue, $aCurValues)
  1107. {
  1108. return in_array($sValue, $aCurValues);
  1109. }
  1110. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  1111. {
  1112. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1113. $aAttrs['name'] = $aInput['name'];
  1114. if ($isMultiple) {
  1115. $aAttrs['name'] .= '[]';
  1116. $aAttrs['multiple'] = 'multiple';
  1117. }
  1118. // for inputs with labels generate id
  1119. if (isset($aInput['label']))
  1120. $aAttrs['id'] = $this->getInputId($aInput);
  1121. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  1122. // generate options
  1123. $sOptions = '';
  1124. if (isset($aInput['values']) and is_array($aInput['values'])) {
  1125. foreach ($aInput['values'] as $sValue => $sTitle) {
  1126. $sAttrsOpt = "";
  1127. if(is_array($sTitle)) {
  1128. if(isset($sTitle['type'])) {
  1129. switch($sTitle['type']) {
  1130. case 'group_header':
  1131. $sTitle = bx_process_output($sTitle['value']);
  1132. $sOptions .= <<<BLAH
  1133. <optgroup label="$sTitle">
  1134. BLAH;
  1135. break;
  1136. case 'group_end':
  1137. $sOptions .= <<<BLAH
  1138. </optgroup>
  1139. BLAH;
  1140. break;
  1141. }
  1142. continue;
  1143. }
  1144. $aAttrsOpt = array();
  1145. if(!empty($sTitle['attrs']) && is_array($sTitle['attrs']))
  1146. $aAttrsOpt = $sTitle['attrs'];
  1147. if(isset($sTitle['class']))
  1148. $aAttrsOpt['class'] = !empty($aAttrsOpt['class']) ? $aAttrsOpt['class'] . ' ' . $sTitle['class'] : $sTitle['class'];
  1149. if(isset($sTitle['style']))
  1150. $aAttrsOpt['style'] = !empty($aAttrsOpt['style']) ? $aAttrsOpt['style'] . ' ' . $sTitle['style'] : $sTitle['style'];
  1151. $sAttrsOpt = !empty($aAttrsOpt) ? bx_convert_array2attrs($aAttrsOpt) : '';
  1152. $sValue = $sTitle['key'];
  1153. $sTitle = $sTitle['value'];
  1154. }
  1155. $sValueC = bx_html_attribute($sValue);
  1156. $sTitleC = bx_process_output($sTitle);
  1157. $sSelected = $this->$sIsSelectedFunc($sValue, $mixedCurrentVal) ? 'selected="selected"' : '';
  1158. $sOptions .= <<<BLAH
  1159. <option value="$sValueC" $sAttrsOpt $sSelected>$sTitleC</option>
  1160. BLAH;
  1161. }
  1162. }
  1163. // generate element
  1164. $sCode = <<<BLAH
  1165. <select $sAttrs>
  1166. $sOptions
  1167. </select>
  1168. BLAH;
  1169. if(!empty($aInput['content']))
  1170. $sCode .= $aInput['content'];
  1171. return $sCode;
  1172. }
  1173. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  1174. {
  1175. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  1176. $aAttrs['name'] = $aInput['name'];
  1177. // for inputs with labels generate id
  1178. if (isset($aInput['label']))
  1179. $aAttrs['id'] = $this->getInputId($aInput);
  1180. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1181. // generate options
  1182. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  1183. $sOptions = '';
  1184. if (isset($aInput['values']) && is_array($aInput['values'])) {
  1185. if (count($aInput['values']) > 3 && $sDivider == $this->_sDivider)
  1186. $sDivider = $this->_sDividerAlt;
  1187. // generate complex input using simple standard inputs
  1188. foreach ($aInput['values'] as $sValue => $sLabel) {
  1189. if(is_array($sLabel)) {
  1190. $sValue = $sLabel['key'];
  1191. $sLabel = $sLabel['value'];
  1192. }
  1193. // create new simple input
  1194. $aNewInput = array(
  1195. 'type' => $sType,
  1196. 'name' => $aInput['name'] . $sNameAppend,
  1197. 'value' => $sValue,
  1198. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  1199. 'label' => $sLabel,
  1200. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  1201. );
  1202. $sNewInput = $this->genInput($aNewInput);
  1203. // attach new input to complex
  1204. $sOptions .= ($sNewInput . $sDivider);
  1205. }
  1206. }
  1207. // generate element
  1208. $sCode = <<<BLAH
  1209. <div $sAttrs>
  1210. $sOptions
  1211. </div>
  1212. BLAH;
  1213. return $sCode;
  1214. }
  1215. function genInputLocation(&$aInput)
  1216. {
  1217. $isManualInput = (int)(isset($aInput['manual_input']) && $aInput['manual_input']);
  1218. $sIdStatus = $this->getInputId($aInput) . '_status';
  1219. $sIdInput = $this->getInputId($aInput) . '_location';
  1220. $sProto = (0 === strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
  1221. $aVars = array (
  1222. 'key' => trim(getParam('sys_maps_api_key')),
  1223. 'lang' => bx_lang_name(),
  1224. 'name' => $aInput['name'],
  1225. 'id_status' => $sIdStatus,
  1226. 'id_input' => $sIdInput,
  1227. 'manual_input' => $isManualInput,
  1228. 'bx_if:manual_input' => array(
  1229. 'condition' => $isManualInput,
  1230. 'content' => array(),
  1231. ),
  1232. 'bx_if:auto_input' => array(
  1233. 'condition' => !$isManualInput,
  1234. 'content' => array(
  1235. 'id_status' => $sIdStatus,
  1236. 'location_string' => _t('_sys_location_undefined'),
  1237. ),
  1238. ),
  1239. );
  1240. $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip', 'street', 'street_number');
  1241. foreach ($aLocationIndexes as $sKey)
  1242. $aVars[$sKey] = $this->getLocationVal($aInput, $sKey);
  1243. if ($aVars['country']) {
  1244. $aCountries = BxDolFormQuery::getDataItems('Country');
  1245. $s = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
  1246. $aVars['bx_if:auto_input']['content']['location_string'] = $s;
  1247. }
  1248. if ($isManualInput) {
  1249. $aInput['type'] = 'text';
  1250. $aInput['attrs']['id'] = $sIdInput;
  1251. $aVars['input'] = $this->genInputStandard($aInput);
  1252. }
  1253. else {
  1254. if ($this->getLocationVal($aInput, 'lat') && $this->getLocationVal($aInput, 'lng'))
  1255. $aInput['checked'] = true;
  1256. else
  1257. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  1258. $aVars['input'] = $this->genInputSwitcher($aInput);
  1259. }
  1260. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  1261. }
  1262. public function setLocationVal ($aInput, $sIndex, $sVal)
  1263. {
  1264. $s = $aInput['name'] . '_' . $sIndex;
  1265. $this->_aSpecificValues[$s] = $sVal;
  1266. }
  1267. protected function getLocationVal ($aInput, $sIndex)
  1268. {
  1269. $s = $aInput['name'] . '_' . $sIndex;
  1270. if (isset($this->_aSpecificValues[$s]))
  1271. return $this->_aSpecificValues[$s];
  1272. return $this->getCleanValue($s);
  1273. }
  1274. function genInputCaptcha(&$aInput)
  1275. {
  1276. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1277. // for inputs with labels generate id
  1278. if (isset($aInput['label']))
  1279. $aAttrs['id'] = $this->getInputId($aInput);
  1280. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1281. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1282. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1283. }
  1284. /**
  1285. * Generate Label Element
  1286. *
  1287. * @param string $sLabel Text of the Label
  1288. * @param string $sInputID Dependant Input Element ID
  1289. * @return string HTML code
  1290. */
  1291. function genLabel(&$aInput)
  1292. {
  1293. if (!isset($aInput['label']) or empty($aInput['label']))
  1294. return '';
  1295. $sLabel = $aInput['label'];
  1296. $sInputID = $this->getInputId($aInput);
  1297. $sRet = '<label for="' . $sInputID . '">' . bx_process_output($sLabel) . '</label>';
  1298. return $sRet;
  1299. }
  1300. function genInfoIcon($sInfo)
  1301. {
  1302. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1303. }
  1304. function genErrorIcon( $sError = '' )
  1305. {
  1306. if ($this->bEnableErrorIcon) {
  1307. $sStyle = '';
  1308. if (!$sError)
  1309. $sStyle = 'style="display:none;"';
  1310. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1311. }
  1312. }
  1313. function getOpenSection($aAttrs = array(), $sLegend = '')
  1314. {
  1315. if (!$this->_isSectionOpened) {
  1316. if (!$aAttrs || !is_array($aAttrs))
  1317. $aAttrs = array();
  1318. if ($sLegend)
  1319. $sClassesAdd = "bx-form-section-header";
  1320. else
  1321. $sClassesAdd = "bx-form-section-divider";
  1322. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1323. $this->_isSectionOpened = true;
  1324. 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";
  1325. } else {
  1326. return '';
  1327. }
  1328. }
  1329. function getCloseSection()
  1330. {
  1331. if ($this->_isSectionOpened) {
  1332. $this->_isSectionOpened = false;
  1333. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1334. } else {
  1335. return '';
  1336. }
  1337. }
  1338. function getOpenSectionViewMode($aAttrs = array(), $sLegend = '')
  1339. {
  1340. if (!$this->_isSectionOpened) {
  1341. if (!$aAttrs || !is_array($aAttrs))
  1342. $aAttrs = array();
  1343. if ($sLegend)
  1344. $sClassesAdd = "bx-form-section-header";
  1345. else
  1346. $sClassesAdd = "bx-form-section-divider";
  1347. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1348. $this->_isSectionOpened = true;
  1349. 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";
  1350. } else {
  1351. return '';
  1352. }
  1353. }
  1354. function getCloseSectionViewMode()
  1355. {
  1356. if ($this->_isSectionOpened) {
  1357. $this->_isSectionOpened = false;
  1358. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1359. } else {
  1360. return '';
  1361. }
  1362. }
  1363. static function getJsUiLangs ()
  1364. {
  1365. 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);
  1366. }
  1367. function addCssJsUi ()
  1368. {
  1369. if (self::$_isCssJsUiAdded)
  1370. return;
  1371. $aUiLangs = $this->getJsUiLangs ();
  1372. $sUiLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aUiLangs);
  1373. $this->_addJs(array(
  1374. 'jquery-ui/jquery-ui.custom.min.js',
  1375. 'jquery-ui/i18n/jquery.ui.datepicker-' . $sUiLang . '.min.js',
  1376. ), "'undefined' === typeof($.datepicker)");
  1377. $this->_addCss('jquery-ui/jquery-ui.css');
  1378. self::$_isCssJsUiAdded = true;
  1379. }
  1380. function addCssJsTimepicker ()
  1381. {
  1382. if (self::$_isCssJsTimepickerAdded)
  1383. return;
  1384. $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);
  1385. $sCalendarLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aCalendarLangs);
  1386. $this->_addCss('timepicker-addon/jquery-ui-timepicker-addon.css');
  1387. $this->_addJs(array(
  1388. 'timepicker-addon/jquery-ui-timepicker-addon.min.js',
  1389. 'timepicker-addon/jquery-ui-sliderAccess.js',
  1390. 'timepicker-addon/i18n/jquery-ui-timepicker-' . $sCalendarLang . '.js',
  1391. 'jquery.ui.touch-punch.min.js',
  1392. ), "'undefined' === typeof($.fn.datetimepicker)");
  1393. self::$_isCssJsTimepickerAdded = true;
  1394. }
  1395. function addCssJsMinicolors ()
  1396. {
  1397. if (self::$_isCssJsMinicolorsAdded)
  1398. return;
  1399. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  1400. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  1401. self::$_isCssJsMinicolorsAdded = true;
  1402. }
  1403. function addCssJsViewMode ()
  1404. {
  1405. if (self::$_isCssJsAddedViewMode)
  1406. return;
  1407. $this->_addCss('forms.css');
  1408. self::$_isCssJsAddedViewMode = true;
  1409. }
  1410. function addCssJsCore ()
  1411. {
  1412. if (self::$_isCssJsAdded)
  1413. return;
  1414. $this->_addCss('forms.css');
  1415. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  1416. self::$_isCssJsAdded = true;
  1417. }
  1418. function addCssJs ()
  1419. {
  1420. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  1421. $this->addCssJsViewMode ();
  1422. } else {
  1423. $this->addCssJsCore();
  1424. }
  1425. }
  1426. protected function _processCssJs()
  1427. {
  1428. $sRet = '';
  1429. if ($this->_bDynamicMode) {
  1430. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  1431. $sRet .= "\n<script>\n";
  1432. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  1433. foreach ($this->_aJs as $sCondition => $aJs) {
  1434. $sJs = $this->oTemplate->addJs($aJs, true);
  1435. if (!$sJs)
  1436. continue;
  1437. $sRet .= "if ($sCondition)\n";
  1438. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  1439. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  1440. }
  1441. $sRet .= "\n</script>\n";
  1442. }
  1443. else {
  1444. $this->oTemplate->addCss($this->_aCss);
  1445. $aJs = array();
  1446. foreach ($this->_aJs as $sCondition => $a)
  1447. $aJs = array_merge($aJs, $a);
  1448. $this->oTemplate->addJs($aJs);
  1449. }
  1450. return $sRet;
  1451. }
  1452. protected function _addJs($mixed, $sJsCondition)
  1453. {
  1454. if (!is_array($mixed))
  1455. $mixed = array($mixed);
  1456. $this->_aJs[$sJsCondition] = $mixed;
  1457. }
  1458. protected function _addCss($mixed)
  1459. {
  1460. if (!is_array($mixed))
  1461. $mixed = array($mixed);
  1462. foreach ($mixed as $s)
  1463. $this->_aCss[$s] = $s;
  1464. }
  1465. }
  1466. /** @} */