1
0

BxBaseFormView.php 64 KB

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