1
0

BxBaseFormView.php 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361
  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 $_isCssJsUiSortableAdded = false;
  15. protected static $_isCssJsMinicolorsAdded = false;
  16. protected static $_isCssJsLabelsAdded = false;
  17. protected static $_isCssJsTimepickerAdded = false;
  18. protected static $_isCssJsAddedViewMode = false;
  19. /**
  20. * Enable or disable error message displaying
  21. */
  22. protected $bEnableErrorIcon = true;
  23. /**
  24. * HTML Code of this form
  25. */
  26. protected $sCode;
  27. /**
  28. * Code which will be added to the beginning of the form.
  29. * For example, hidden inputs.
  30. * For internal use only
  31. */
  32. protected $_sCodeAdd = '';
  33. /**
  34. * for internal use only
  35. */
  36. protected $_isSectionOpened = false;
  37. /**
  38. * Default divider for several inputs
  39. */
  40. protected $_sDivider = '<span class="bx-def-margin-left"></span>';
  41. /**
  42. * Alternative divider for several inputs
  43. */
  44. protected $_sDividerAlt = '<br />';
  45. /**
  46. * Form is added dynamically.
  47. */
  48. protected $_bDynamicMode = false;
  49. /**
  50. * Form is submitted dynamically (using Ajax Submit).
  51. */
  52. protected $_bAjaxMode = false;
  53. /**
  54. * Use absolute Action URL which is needed in Ajax Mode.
  55. */
  56. protected $_bAbsoluteActionUrl = false;
  57. /**
  58. * Form is displayed in view mode.
  59. */
  60. protected $_bViewMode = false;
  61. /**
  62. * Show or not sections which have no fileds
  63. */
  64. protected $_bShowEmptySections = false;
  65. /**
  66. * Function name for generation close form section HTML.
  67. */
  68. protected $_sSectionClose = 'getCloseSection';
  69. /**
  70. * Function name for generation open form section HTML.
  71. */
  72. protected $_sSectionOpen = 'getOpenSection';
  73. /**
  74. * JS files list for form
  75. */
  76. protected $_aJs = array();
  77. /**
  78. * CSS files list for form
  79. */
  80. protected $_aCss = array();
  81. protected $_sJsClassName;
  82. protected $_sJsObjectName;
  83. protected $_aHtmlIds;
  84. /**
  85. * Constructor
  86. *
  87. * @param array $aInfo Form contents
  88. *
  89. * $aInfo['params'] = array(
  90. * 'remove_form' => true|false,
  91. * );
  92. *
  93. * @return BxBaseFormView
  94. */
  95. function __construct($aInfo, $oTemplate)
  96. {
  97. parent::__construct($aInfo, $oTemplate);
  98. $this->_bAjaxMode = isset($this->aParams['ajax_mode']) && $this->aParams['ajax_mode'];
  99. $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode'];
  100. if($this->_bViewMode) {
  101. $this->_sSectionClose = 'getCloseSectionViewMode';
  102. $this->_sSectionOpen = 'getOpenSectionViewMode';
  103. }
  104. $this->_sJsClassName = 'BxDolForm';
  105. $sName = !empty($aInfo['params']['display']) ? $aInfo['params']['display'] : '';
  106. if(empty($sName) && !empty($aInfo['params']['object']))
  107. $sName = $aInfo['params']['object'];
  108. $this->_sJsObjectName = 'oForm' . bx_gen_method_name($sName, array('_' , '-'));
  109. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sName);
  110. $this->_aHtmlIds = array(
  111. 'help_popup' => $sHtmlId . '-help-popup-',
  112. 'pgc' => $sHtmlId . '-pgc-',
  113. 'pgc_popup' => $sHtmlId . '-pgc-popup-',
  114. 'pgc_form' => $sHtmlId . '-pgc-form-',
  115. );
  116. }
  117. public function performActionGetHelp()
  118. {
  119. $sInput = bx_process_input(bx_get('input'));
  120. if(empty($sInput) || empty($this->aInputs[$sInput]['help']))
  121. return;
  122. echo $this->oTemplate->parseHtmlByName('form_field_help_popup.html', array(
  123. 'content' => _t($this->aInputs[$sInput]['help']),
  124. 'bx_if:show_edit' => array(
  125. 'condition' => isAdmin(),
  126. 'content' => array(
  127. 'link' => BX_DOL_URL_STUDIO . bx_append_url_params('builder_forms.php', array(
  128. 'page' => 'fields',
  129. 'module' => $this->aParams['module'],
  130. 'object' => $this->aParams['object'],
  131. 'display' => $this->aParams['display']
  132. ))
  133. )
  134. )
  135. ));
  136. }
  137. public function performActionChangePrivacyGroup()
  138. {
  139. $iAuthorId = (int)bx_get_logged_profile_id();
  140. if(empty($iAuthorId))
  141. return echoJson(array());
  142. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  143. if(empty($iInputId))
  144. return echoJson(array());
  145. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  146. $sPrivacyField = BxDolPrivacy::getFieldName($sPrivacyObject);
  147. if(empty($sPrivacyField))
  148. return echoJson(array());
  149. $sPrivacyGroup = bx_process_input(bx_get($sPrivacyField));
  150. if(empty($sPrivacyField))
  151. return echoJson(array());
  152. if(!BxDolFormQuery::setInputPrivacy($iInputId, $iAuthorId, $sPrivacyField, $sPrivacyGroup))
  153. return echoJson(array());
  154. return echoJson(array(
  155. 'code' => 0,
  156. 'form_id' => $this->getId(),
  157. 'chooser_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  158. 'icon' => $this->_getPrivacyIcon($sPrivacyGroup),
  159. 'eval' => $this->getJsObjectName() . '.pgcOnSelectGroup(oData);'
  160. ));
  161. }
  162. public function performActionGetPrivacyGroupChooser()
  163. {
  164. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  165. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  166. if(empty($iInputId) || empty($sPrivacyObject))
  167. return '';
  168. $sFormId = $this->_aHtmlIds['pgc_form'] . $iInputId;
  169. $aFormActionParams = array();
  170. if(!empty($this->aParams['object']) && !empty($this->aParams['display']))
  171. $aFormActionParams = array(
  172. 'o' => $this->aParams['object'],
  173. 'd' => $this->aParams['display']
  174. );
  175. $aFormActionParams['a'] = 'change_privacy_group';
  176. $iAuthorId = bx_get_logged_profile_id();
  177. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  178. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  179. $aInputPgc = $oPrivacy->getGroupChooser($sPrivacyObject, $iAuthorId);
  180. $aInputPgc['value'] = $mixedPrivacyGroup;
  181. if(!isset($aInputPgc['content']))
  182. $aInputPgc['content'] = '';
  183. $aInputPgc['content'] .= $oPrivacy->addCssJs(true);
  184. $aInputPgc['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iAuthorId, array(
  185. 'content_id' => $iInputId,
  186. 'group_id' => $mixedPrivacyGroup,
  187. 'html_ids' => array(
  188. 'form' => $sFormId
  189. )
  190. ));
  191. $aFormInfo = array(
  192. 'form_attrs' => array(
  193. 'id' => $sFormId,
  194. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('form.php', $aFormActionParams),
  195. 'method' => 'post'
  196. ),
  197. 'inputs' => array (
  198. 'input_id' => array(
  199. 'type' => 'hidden',
  200. 'name' => 'input_id',
  201. 'value' => $iInputId,
  202. 'db' => array (
  203. 'pass' => 'Int',
  204. ),
  205. ),
  206. 'privacy_object' => array(
  207. 'type' => 'hidden',
  208. 'name' => 'privacy_object',
  209. 'value' => $sPrivacyObject,
  210. 'db' => array (
  211. 'pass' => 'Xss',
  212. ),
  213. ),
  214. 'privacy_group_chooser' => $aInputPgc,
  215. 'controls' => array(
  216. 'name' => 'controls',
  217. 'type' => 'input_set',
  218. array(
  219. 'type' => 'button',
  220. 'name' => 'do_submit',
  221. 'value' => _t('_sys_submit'),
  222. 'attrs' => array(
  223. 'onclick' => "$('#" . $sFormId . "').submit()",
  224. ),
  225. ),
  226. array (
  227. 'type' => 'reset',
  228. 'name' => 'do_cancel',
  229. 'value' => _t('_Cancel'),
  230. 'attrs' => array(
  231. 'onclick' => "$(this).parents('.bx-popup-applied:visible:first').dolPopupHide()",
  232. 'class' => 'bx-def-margin-sec-left',
  233. ),
  234. )
  235. )
  236. )
  237. );
  238. $oForm = new BxTemplFormView($aFormInfo);
  239. echo $this->oTemplate->parseHtmlByName('form_field_privacy_popup.html', array(
  240. 'form_id' => $oForm->getId(),
  241. 'form' => $oForm->getCode(true),
  242. ));
  243. }
  244. function setShowEmptySections($b)
  245. {
  246. $this->_bShowEmptySections = $b;
  247. }
  248. function setAjaxMode($bAjaxMode)
  249. {
  250. $this->_bAjaxMode = (bool)$bAjaxMode;
  251. }
  252. function isAjaxMode()
  253. {
  254. return $this->_bAjaxMode;
  255. }
  256. function setAbsoluteActionUrl($sUrl)
  257. {
  258. if(empty($sUrl))
  259. return;
  260. $this->aFormAttrs['action'] = $sUrl;
  261. $this->_bAbsoluteActionUrl = true;
  262. }
  263. /**
  264. * Return Form code
  265. * @param $bDynamicMode - set it to true if form is added via JS/AJAX call, for example form in AJAX popup.
  266. * @return string
  267. */
  268. function getCode($bDynamicMode = false)
  269. {
  270. if(!$bDynamicMode && bx_is_dynamic_request())
  271. $bDynamicMode = true;
  272. $this->_bDynamicMode = $bDynamicMode;
  273. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  274. $sInclude = '';
  275. $this->sCode = false;
  276. bx_alert('system', 'form_output', 0, 0, array(
  277. 'dynamic' => $this->_bDynamicMode,
  278. 'object' => &$this,
  279. 'code' => &$this->sCode,
  280. 'include' => &$sInclude
  281. ));
  282. if($this->sCode === false)
  283. $this->sCode = $this->genForm();
  284. $this->addCssJs();
  285. $sDynamicCssJs = $this->_processCssJs();
  286. return $sInclude . $sDynamicCssJs . $this->sCode;
  287. }
  288. function getCodeAPI()
  289. {
  290. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  291. $this->sCode = false;
  292. bx_alert('system', 'form_output', 0, 0, array(
  293. 'dynamic' => $this->_bDynamicMode,
  294. 'object' => &$this,
  295. 'code' => &$this->sCode,
  296. 'include' => &$sInclude
  297. ));
  298. if($this->sCode === false)
  299. $this->genForm();
  300. // TODO: process inputs to translate titles, alerts, etc
  301. return ['inputs' => $this->aInputs, 'attrs' => $this->aFormAttrs, 'params' => $this->aParams];
  302. }
  303. public function getJsClassName()
  304. {
  305. return $this->_sJsClassName;
  306. }
  307. public function getJsObjectName()
  308. {
  309. return $this->_sJsObjectName;
  310. }
  311. public function getJsScript($bWrap = false)
  312. {
  313. $sJsObjName = $this->getJsObjectName();
  314. $sJsObjClass = $this->getJsClassName();
  315. $sCode = "if(window['" . $sJsObjName . "'] == undefined) window['" . $sJsObjName . "'] = new " . $sJsObjClass . "(" . json_encode(array(
  316. 'sObjName' => $sJsObjName,
  317. 'sObject' => isset($this->aParams['object']) ? $this->aParams['object'] : '',
  318. 'sDisplay' => isset($this->aParams['display']) ? $this->aParams['display'] : '',
  319. 'sRootUrl' => BX_DOL_URL_ROOT,
  320. 'aHtmlIds' => $this->_aHtmlIds,
  321. )) . ");";
  322. return $bWrap ? $this->oTemplate->_wrapInTagJsCode($sCode) : $sCode;
  323. }
  324. /**
  325. * Generate the whole form
  326. *
  327. * @return string
  328. */
  329. function genForm()
  330. {
  331. $this->_sCodeAdd = '';
  332. $sTable = $this->genRows();
  333. $sHtmlBefore = isset($this->aParams['html_before']) ? $this->aParams['html_before'] : '';
  334. $sHtmlAfter = isset($this->aParams['html_after']) ? $this->aParams['html_after'] : '';
  335. if (!empty($this->aParams['remove_form']) || (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])) {
  336. $sForm = <<<BLAH
  337. $sHtmlBefore
  338. {$this->_sCodeAdd}
  339. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  340. $sTable
  341. </div>
  342. $sHtmlAfter
  343. BLAH;
  344. } else {
  345. $sFormAttrs = bx_convert_array2attrs($this->aFormAttrs, 'bx-form-advanced');
  346. $sAjaxFormJs = '';
  347. if($this->_bAjaxMode)
  348. $sAjaxFormJs = <<<BLAH
  349. $("form#{$this->id}").ajaxForm({
  350. dataType: "json",
  351. beforeSubmit: function (formData, jqForm, options) {
  352. bx_loading($("form#{$this->id}"), true);
  353. },
  354. success: function (oData) {
  355. bx_loading($("form#{$this->id}"), false);
  356. processJsonData(oData);
  357. }
  358. });
  359. BLAH;
  360. $sJsCodeDynamic = '';
  361. if($this->_bDynamicMode)
  362. $sJsCodeDynamic = 'function() {' . $this->getJsScript() . '}';
  363. $sForm = <<<BLAH
  364. $sHtmlBefore
  365. <form $sFormAttrs>
  366. {$this->_sCodeAdd}
  367. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  368. $sTable
  369. </div>
  370. </form>
  371. <script>
  372. $(document).ready(function() {
  373. $(this).addWebForms($sJsCodeDynamic);
  374. });
  375. $sAjaxFormJs
  376. </script>
  377. $sHtmlAfter
  378. BLAH;
  379. }
  380. if(!$this->_bDynamicMode)
  381. $sForm = $this->getJsScript(true) . $sForm;
  382. return $sForm;
  383. }
  384. /**
  385. * Generate Table HTML code
  386. *
  387. * @return string
  388. */
  389. function genRows()
  390. {
  391. // add CSRF token if it's needed.
  392. 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) {
  393. $this->aInputs['csrf_token'] = array(
  394. 'type' => 'hidden',
  395. 'name' => 'csrf_token',
  396. 'value' => $mixedCsrfToken,
  397. 'db' => array ('pass' => 'Xss'),
  398. 'visible_for_levels' => PHP_INT_MAX,
  399. );
  400. }
  401. // add 'Ajax Mode' flag
  402. if($this->_bAjaxMode)
  403. $this->aInputs['ajax_mode'] = array(
  404. 'type' => 'hidden',
  405. 'name' => 'ajax_mode',
  406. 'value' => 1,
  407. 'db' => array ('pass' => 'Int'),
  408. 'visible_for_levels' => PHP_INT_MAX,
  409. );
  410. // add 'Absolute Action Url' flag
  411. if($this->_bAbsoluteActionUrl)
  412. $this->aInputs['absolute_action_url'] = array(
  413. 'type' => 'hidden',
  414. 'name' => 'absolute_action_url',
  415. 'value' => 1,
  416. 'db' => array ('pass' => 'Int'),
  417. 'visible_for_levels' => PHP_INT_MAX,
  418. );
  419. // check if we need to generate open section clause
  420. $sOpenSection = '';
  421. foreach ($this->aInputs as $aInput) {
  422. if (isset($aInput['type']) && 'hidden' == $aInput['type'])
  423. continue;
  424. if (isset($aInput['type']) && 'block_header' != $aInput['type'])
  425. $sOpenSection = $this->{$this->_sSectionOpen}();
  426. break;
  427. }
  428. // generate rows contents
  429. $sCont = '';
  430. $sContHeader = '';
  431. $sContFields = '';
  432. $sFuncGenRow = isset($this->aParams['view_mode']) && $this->aParams['view_mode'] ? 'genViewRow' : 'genRow';
  433. foreach ($this->aInputs as &$aInput) {
  434. if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) {
  435. if ('block_header' == $aInput['type'] && !$this->_bShowEmptySections) {
  436. // don't show section with no fields or with empty fields
  437. if ($sContHeader) {
  438. if ($sContFields)
  439. $sCont .= $sContHeader . $sContFields;
  440. else
  441. $sContHeader = '';
  442. $sContFields = '';
  443. }
  444. else {
  445. $sCont .= $sContFields;
  446. $sContFields = '';
  447. }
  448. $sContHeader = $this->$sFuncGenRow($aInput);
  449. } else {
  450. $sContFields .= $this->$sFuncGenRow($aInput);
  451. }
  452. }
  453. }
  454. $sCont .= $sContHeader . $sContFields;
  455. $sCloseSection = $this->{$this->_sSectionClose}();
  456. return $sOpenSection . $sCont . $sCloseSection;
  457. }
  458. /**
  459. * Generate single Table Row
  460. *
  461. * @param array $aInput
  462. * @return string
  463. */
  464. function genRow(&$aInput)
  465. {
  466. if (!isset($aInput['type']))
  467. $aInput['type'] = false;
  468. if (!empty($aInput['name'])) {
  469. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  470. if (method_exists($this, $sCustomMethod))
  471. return $this->$sCustomMethod($aInput);
  472. }
  473. switch ($aInput['type']) {
  474. case 'block_header':
  475. $sRow = $this->genRowBlockHeader($aInput);
  476. break;
  477. case 'block_end':
  478. $sRow = $this->genBlockEnd($aInput);
  479. break;
  480. case 'hidden':
  481. // do not generate row for hidden inputs
  482. $sRow = '';
  483. $this->_sCodeAdd .= $this->genInput($aInput);
  484. break;
  485. case 'select_box':
  486. $sRow = $this->genRowCustom($aInput, 'genInputSelectBox');
  487. break;
  488. case 'files':
  489. $sRow = $this->genRowCustom($aInput, 'genInputFiles');
  490. break;
  491. case 'switcher':
  492. case 'checkbox':
  493. $sRow = $this->genRowStandard($aInput, true);
  494. break;
  495. default:
  496. $sRow = $this->genRowStandard($aInput);
  497. }
  498. return $sRow;
  499. }
  500. public function isInputVisible($mixedInput)
  501. {
  502. if(!is_array($mixedInput) && isset($this->aInputs[$mixedInput]))
  503. $mixedInput = $this->aInputs[$mixedInput];
  504. if(empty($mixedInput) || !is_array($mixedInput))
  505. $mixedInput = BxDolFormQuery::getInputByName($this->aParams['object'], $mixedInput);
  506. if(empty($mixedInput) || !is_array($mixedInput))
  507. return false;
  508. if(!empty($mixedInput['privacy']) && !empty($this->_iAuthorId) && !$this->_isInputVisibleByPrivacy($mixedInput))
  509. return false;
  510. return true;
  511. }
  512. protected function _isInputVisibleByPrivacy($aInput)
  513. {
  514. $mixedResult = checkActionModule($this->_iAuthorId, 'set form fields privacy', 'system');
  515. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  516. return true;
  517. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  518. if(empty($aInputPrivacy) || !is_array($aInputPrivacy))
  519. if(BxDolFormQuery::setInputPrivacy($aInput['id'], $this->_iAuthorId, BxDolPrivacy::getFieldName($this->_sPrivacyObjectView), $this->_sPrivacyGroupDefault))
  520. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  521. if((empty($aInputPrivacy) || !is_array($aInputPrivacy)) && $this->_sPrivacyGroupDefault != BX_DOL_PG_ALL)
  522. return false;
  523. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_sPrivacyObjectView);
  524. if($oPrivacy && !$oPrivacy->check($aInputPrivacy['id']))
  525. return false;
  526. return true;
  527. }
  528. /**
  529. * Generate single Table Row for view mode
  530. *
  531. * @param array $aInput
  532. * @return string
  533. */
  534. function genViewRow(&$aInput)
  535. {
  536. if (!isset($aInput['type']))
  537. $aInput['type'] = false;
  538. if(!$this->isInputVisible($aInput))
  539. return '';
  540. if (!empty($aInput['name'])) {
  541. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  542. if (method_exists($this, $sCustomMethod))
  543. return $this->$sCustomMethod($aInput);
  544. }
  545. switch ($aInput['type']) {
  546. case 'block_header':
  547. $sRow = $this->genRowBlockHeader($aInput);
  548. break;
  549. case 'block_end':
  550. $sRow = $this->genBlockEnd($aInput);
  551. break;
  552. case 'nested_form':
  553. $sRow = $this->genNestedForm($aInput);
  554. break;
  555. default:
  556. $sRow = $this->genViewRowWrapped($aInput);
  557. }
  558. return $sRow;
  559. }
  560. /**
  561. * Generate complete wrapped row for view mode form
  562. *
  563. * @param array $aInput
  564. * @return string
  565. */
  566. function genViewRowWrapped(&$aInput)
  567. {
  568. $sValue = $this->genViewRowValue($aInput);
  569. if (null === $sValue)
  570. return '';
  571. return $this->oTemplate->parseHtmlByName('form_view_row.html', array(
  572. 'type' => $aInput['type'],
  573. 'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '',
  574. 'value' => $sValue
  575. ));
  576. }
  577. /**
  578. * Generate value for view mode row
  579. *
  580. * @param array $aInput
  581. * @return string
  582. */
  583. function genViewRowValue(&$aInput)
  584. {
  585. if (!empty($aInput['name'])) {
  586. $sCustomMethod = 'genCustomViewRowValue' . $this->_genMethodName($aInput['name']);
  587. if (method_exists($this, $sCustomMethod))
  588. return $this->$sCustomMethod($aInput);
  589. }
  590. switch ($aInput['type']) {
  591. case 'hidden':
  592. $sValue = null;
  593. break;
  594. case 'select':
  595. case 'radio_set':
  596. $sValue = $this->genViewRowValueForSelect($aInput);
  597. break;
  598. case 'dateselect':
  599. case 'datepicker':
  600. $sValue = null;
  601. if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value'])
  602. break;
  603. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  604. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format']: BX_FORMAT_DATE, true, true);
  605. else
  606. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  607. break;
  608. case 'date_time':
  609. case 'datetime':
  610. $sValue = null;
  611. if(empty($aInput['value']) || !$aInput['value'] || '0000-00-00 00:00:00' == $aInput['value'] || '0000-00-00 00:00' == $aInput['value'])
  612. break;
  613. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  614. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true, true);
  615. else
  616. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  617. break;
  618. case 'checkbox_set':
  619. case 'select_multiple':
  620. $sValue = null;
  621. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  622. $sValue = '';
  623. foreach ($aInput['value'] as $sVal)
  624. $sValue .= $aInput['values'][$sVal] . ', ';
  625. $sValue = trim ($sValue, ', ');
  626. }
  627. break;
  628. case 'checkbox':
  629. case 'switcher':
  630. $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off');
  631. break;
  632. case 'textarea':
  633. if (isset($aInput['value']) && '' !== $aInput['value'])
  634. $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE);
  635. else
  636. $sValue = null;
  637. break;
  638. case 'text':
  639. if(isset($aInput['value']) && '' !== $aInput['value'])
  640. $sValue = bx_linkify(bx_process_output($aInput['value']));
  641. else
  642. $sValue = null;
  643. break;
  644. case 'price':
  645. if(isset($aInput['value']) && $aInput['value'] !== '')
  646. $sValue = _t_format_currency(bx_process_output($aInput['value']));
  647. else
  648. $sValue = null;
  649. break;
  650. default:
  651. if(isset($aInput['value']) && '' !== $aInput['value']) {
  652. $sValue = $aInput['value'];
  653. if(get_mb_substr($sValue, 0, 1) == '_')
  654. $sValue = _t($sValue);
  655. $sValue = bx_process_output($sValue);
  656. }
  657. else
  658. $sValue = null;
  659. }
  660. return $sValue;
  661. }
  662. function genViewRowValueForSelect(&$aInput)
  663. {
  664. if (!isset($aInput['value']) || !$aInput['value'])
  665. return null;
  666. $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
  667. if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])) !== false)
  668. return $oCategory->getCategoryLink($s, $aInput['value']);
  669. return $s;
  670. }
  671. protected function genCustomRowBirthday(&$aInput)
  672. {
  673. if(!$this->_bViewMode)
  674. return $this->genRowStandard($aInput);
  675. $aInput['caption_src'] = '_sys_form_input_age';
  676. $aInput['caption'] = _t($aInput['caption_src']);
  677. return $this->genViewRowWrapped($aInput);
  678. }
  679. protected function genCustomRowCf(&$aInput)
  680. {
  681. $aInput = BxDolContentFilter::getInstance()->getInput($aInput);
  682. if($aInput['type'] == 'hidden') {
  683. $this->_sCodeAdd .= $this->genInput($aInput);
  684. return '';
  685. }
  686. return $this->genRowStandard($aInput);
  687. }
  688. protected function genCustomViewRowValueBirthday(&$aInput)
  689. {
  690. if(!isset($aInput['value']) || !$aInput['value'] || in_array($aInput['value'], array('0000-00-00', '0000-00-00 00:00:00', '0000-00-00Z', '0000-00-00 00:00:00Z')))
  691. return null;
  692. return bx_birthday2age($aInput['value']);
  693. }
  694. /**
  695. * Generate standard row
  696. *
  697. * @param array $aInput
  698. * @return string
  699. */
  700. function genRowStandard(&$aInput, $isOneLine = false)
  701. {
  702. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  703. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  704. $sHelp = !empty($aInput['help']) ? ' <a href="javascript:void(0)" onclick="javascript:' . $this->getJsObjectName() . '.showHelp(this, \'' . $aInput['name'] . '\')"><i class="sys-icon question-circle"></i></a> ' : '';
  705. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  706. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  707. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  708. $sClassWrapper = 'bx-form-element-wrapper';
  709. if($isOneLine)
  710. $sClassWrapper .= ' ' . $sClassWrapper . '-oneline';
  711. $sClassWrapper .= ' bx-def-margin-top-auto';
  712. if (isset($aInput['name'])) {
  713. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  714. $aInput['tr_attrs'] = [];
  715. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  716. }
  717. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper);
  718. $sClassOneLineCaption = '';
  719. $sClassOneLineValue = '';
  720. if ($isOneLine) {
  721. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' bx-def-margin-sec-left';
  722. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  723. if (!isset($aInput['attrs']) || !is_array($aInput['attrs']))
  724. $aInput['attrs'] = [];
  725. $aInput['attrs']['id'] = $this->getInputId($aInput);
  726. if ($sCaption)
  727. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  728. }
  729. $sInput = $this->genInput($aInput);
  730. if(isset($aInput['error_updated']) && $aInput['error_updated'] === true)
  731. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  732. if(empty($sErrorIcon))
  733. $sErrorIcon = '';
  734. $aTmplVarsRow = array(
  735. 'bx_if:show_caption' => array(
  736. 'condition' => !empty($sCaption),
  737. 'content' => array(
  738. 'class_caption' => $sClassOneLineCaption,
  739. 'caption' => $sCaption,
  740. 'required' => $sRequired,
  741. 'help' => $sHelp,
  742. )
  743. ),
  744. 'class_value' => $sClassAdd . $sClassOneLineValue,
  745. 'value' => $this->genWrapperInput($aInput, $sInput),
  746. 'info' => $sInfoIcon,
  747. 'error' => $sErrorIcon,
  748. );
  749. return $this->oTemplate->parseHtmlByName('form_row_standard.html', array(
  750. 'tr_attrs' => $sTrAttrs,
  751. 'bx_if:show_one_line' => array(
  752. 'condition' => $isOneLine,
  753. 'content' => $aTmplVarsRow
  754. ),
  755. 'bx_if:show_lined' => array(
  756. 'condition' => !$isOneLine,
  757. 'content' => $aTmplVarsRow
  758. ),
  759. 'info' => $sInfoIcon,
  760. 'error' => $sErrorIcon
  761. ));
  762. }
  763. function genWrapperInput($aInput, $sContent)
  764. {
  765. $aAttrs = $this->_genWrapperInputAttrs($aInput);
  766. $sClass = "bx-form-input-wrapper bx-form-input-wrapper-{$aInput['type']}";
  767. if(isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput))
  768. $sClass .= ' bx-form-input-wrapper-html';
  769. return $this->oTemplate->parseHtmlByName('form_input_wrapper.html', array(
  770. 'attrs' => bx_convert_array2attrs($aAttrs, $sClass),
  771. 'content' => $sContent
  772. ));
  773. }
  774. protected function _genWrapperInputAttrs(&$aInput)
  775. {
  776. return isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper']) ? $aInput['attrs_wrapper'] : [];
  777. }
  778. /**
  779. * Generate custom row
  780. *
  781. * @param array $aInput
  782. * @param string $sCustomMethod custom method to generate code for input
  783. * @return string
  784. */
  785. function genRowCustom(&$aInput, $sCustomMethod)
  786. {
  787. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  788. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  789. $sHelp = !empty($aInput['help']) ? ' <a href="javascript:void(0)" onclick="javascript:' . $this->getJsObjectName() . '.showHelp(this, \'' . $aInput['name'] . '\')"><i class="sys-icon question-circle"></i></a> ' : '';
  790. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  791. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  792. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  793. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  794. if (isset($aInput['name'])) {
  795. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  796. $aInput['tr_attrs'] = [];
  797. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  798. }
  799. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  800. return $this->oTemplate->parseHtmlByName('form_row_custom.html', array(
  801. 'tr_attrs' => $sTrAttrs,
  802. 'bx_if:show_caption' => array(
  803. 'condition' => !empty($sCaption),
  804. 'content' => array(
  805. 'class_caption' => '',
  806. 'caption' => $sCaption,
  807. 'required' => $sRequired,
  808. 'help' => $sHelp
  809. )
  810. ),
  811. 'class_value' => $sClassAdd,
  812. 'value' => $sInput,
  813. ));
  814. }
  815. /**
  816. * Generate Block Headers row
  817. *
  818. * @param array $aInput
  819. * @return string
  820. */
  821. function genRowBlockHeader(&$aInput)
  822. {
  823. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  824. // if there is no caption - show divider only
  825. if (empty($aInput['caption'])) {
  826. $sCode = $this->{$this->_sSectionClose}();
  827. $sCode .= $this->{$this->_sSectionOpen}($aAttrs);
  828. return $sCode;
  829. }
  830. // if section is collapsed by default, add necessary code
  831. $sClassAddCollapsable = 'bx-form-collapsable';
  832. if (isset($aInput['collapsed']) and $aInput['collapsed'])
  833. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  834. // display section with caption
  835. $sCode = $this->{$this->_sSectionClose}();
  836. if (empty($aAttrs))
  837. $aAttrs = array('class' => 'bx-form-collapsable ' . $sClassAddCollapsable);
  838. else
  839. $aAttrs['class'] .= ' bx-form-collapsable ' . $sClassAddCollapsable;
  840. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])
  841. $sTitle = '<div class="bx-form-section-title bx-def-font-grayed bx-def-font-large">' . bx_process_output($aInput['caption'], BX_DATA_HTML) . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</div>';
  842. else
  843. $sTitle = '<div class="bx-form-section-title bx-def-font-grayed bx-def-font-large"><a href="javascript:void(0);">' . bx_process_output($aInput['caption'], BX_DATA_HTML) . '</a>' . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</div>';
  844. $sCode .= $this->{$this->_sSectionOpen}($aAttrs, $sTitle);
  845. return $sCode;
  846. }
  847. function genBlockEnd()
  848. {
  849. $aNextTbodyAdd = false; // need to have some default
  850. $sCode = '';
  851. $sCode .= $this->{$this->_sSectionClose}();
  852. $sCode .= $this->{$this->_sSectionOpen}($aNextTbodyAdd);
  853. return $sCode;
  854. }
  855. /**
  856. * Generate HTML Input Element
  857. *
  858. * @param array $aInput
  859. * @return string Output HTML Code
  860. */
  861. function genInput(&$aInput)
  862. {
  863. if (!empty($aInput['name'])) {
  864. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  865. if (method_exists($this, $sCustomMethod))
  866. return $this->$sCustomMethod($aInput);
  867. }
  868. switch ($aInput['type']) {
  869. case 'datepicker':
  870. if (!isset($aInput['attrs']))
  871. $aInput['attrs'] = array();
  872. $aInput['attrs']['autosuggestion'] = 'off';
  873. $sInput = $this->genInputStandard($aInput);
  874. break;
  875. // standard inputs (and non-standard, interpreted as standard)
  876. case 'text':
  877. case 'datepicker':
  878. case 'dateselect':
  879. case 'date_time':
  880. case 'datetime':
  881. case 'number':
  882. case 'time':
  883. case 'checkbox':
  884. case 'radio':
  885. case 'image':
  886. case 'slider':
  887. case 'doublerange':
  888. case 'hidden':
  889. $sInput = $this->genInputStandard($aInput);
  890. break;
  891. case 'password':
  892. $sInput = $this->genInputPassword($aInput);
  893. break;
  894. case 'price':
  895. $sInput = $this->genInputPrice($aInput);
  896. break;
  897. case 'file':
  898. $sInput = $this->genInputFile($aInput);
  899. break;
  900. case 'rgb':
  901. case 'rgba':
  902. $sClass = 'bx-form-input-' . $aInput['type'];
  903. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  904. $aInput['type'] = 'text';
  905. $sInput = $this->genInputStandard($aInput);
  906. break;
  907. case 'rgb-list':
  908. $sInput = $this->genInputSelectRgb($aInput);
  909. break;
  910. case 'switcher':
  911. $sInput = $this->genInputSwitcher($aInput);
  912. break;
  913. case 'button':
  914. case 'reset':
  915. case 'submit':
  916. $sInput = $this->genInputButton($aInput);
  917. break;
  918. case 'textarea':
  919. $sInput = $this->genInputTextarea($aInput);
  920. break;
  921. case 'select':
  922. $sInput = $this->genInputSelect($aInput);
  923. break;
  924. case 'select_multiple':
  925. $sInput = $this->genInputSelectMultiple($aInput);
  926. break;
  927. case 'checkbox_set':
  928. $sInput = $this->genInputCheckboxSet($aInput);
  929. break;
  930. case 'radio_set':
  931. $sInput = $this->genInputRadioSet($aInput);
  932. break;
  933. case 'input_set': // numeric array of inputs
  934. $sInput = '';
  935. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  936. foreach ($aInput as $iKey => $aSubInput) {
  937. if (!is_int($iKey) or !$aSubInput)
  938. continue; // parse only integer keys and existing values
  939. $sInput .= $this->genInput($aSubInput); // recursive call
  940. $sInput .= $sDivider;
  941. }
  942. $sInput .= '<div class="bx-clear"></div>';
  943. break;
  944. case 'custom':
  945. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  946. break;
  947. case 'captcha':
  948. $sInput = $this->genInputCaptcha($aInput);
  949. break;
  950. case 'location':
  951. $sInput = $this->genInputLocation($aInput);
  952. break;
  953. case 'nested_form':
  954. $sInput = $this->genInputNestedForm($aInput);
  955. break;
  956. case 'value':
  957. $sInput = '';
  958. if(!isset($aInput['value']))
  959. break;
  960. $sInput = $aInput['value'];
  961. if(get_mb_substr($sInput, 0, 1) == '_')
  962. $sInput = _t($sInput);
  963. break;
  964. default:
  965. //unknown control type
  966. $sInput = 'Unknown control type';
  967. }
  968. // create input label
  969. $sInput .= $this->genLabel($aInput);
  970. // create input privacy group chooser
  971. $sInput .= $this->genPrivacyGroupChooser($aInput);
  972. return $sInput;
  973. }
  974. /**
  975. * Generate new Input Element id
  976. *
  977. * @param array $aInput
  978. * @return string
  979. */
  980. function getInputId(&$aInput)
  981. {
  982. if (isset($aInput['id']))
  983. return $aInput['id'];
  984. $sName = md5($aInput['name']);
  985. $sID = $this->id . '_input_' . $sName;
  986. if ( // multiple elements cause identical id's
  987. (
  988. (
  989. $aInput['type'] == 'checkbox' and
  990. substr($aInput['name'], -2) == '[]' // it is multiple element
  991. ) or
  992. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  993. ) and
  994. isset($aInput['value']) // if we can make difference
  995. ) {
  996. $sValue = md5($aInput['value']);
  997. // add value
  998. $sID .= '_' . $sValue;
  999. }
  1000. $sID = trim($sID, '_');
  1001. $aInput['id'] = $sID; // just for repeated calls
  1002. return $sID;
  1003. }
  1004. /**
  1005. * Generate standard Input Element
  1006. *
  1007. * @param array $aInput
  1008. * @return string
  1009. */
  1010. function genInputStandard(&$aInput)
  1011. {
  1012. $aAttrs = $this->_genInputStandardAttrs($aInput);
  1013. return $this->oTemplate->parseHtmlByName('form_field_standard.html', [
  1014. 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}")
  1015. ]);
  1016. }
  1017. protected function _genInputStandardAttrs(&$aInput)
  1018. {
  1019. // clone attributes for system use ;)
  1020. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1021. // add default className to attributes
  1022. $aAttrs['type'] = $aInput['type'];
  1023. if ('datetime' == $aAttrs['type'])
  1024. $aAttrs['type'] = 'date_time';
  1025. switch($aAttrs['type']) {
  1026. case 'datepicker':
  1027. case 'date_time':
  1028. $this->addCssJsTimepicker ();
  1029. break;
  1030. case 'slider':
  1031. case 'doublerange':
  1032. $this->addCssJsUi ();
  1033. break;
  1034. case 'dateselect':
  1035. $this->_addJs(array(
  1036. 'combodate/combodate.js',
  1037. ), "'undefined' === typeof($.combodate)");
  1038. break;
  1039. case 'text':
  1040. if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
  1041. $this->addCssJsMinicolors ();
  1042. break;
  1043. }
  1044. if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) {
  1045. $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max'];
  1046. }
  1047. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  1048. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  1049. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1;
  1050. if (!isset($aAttrs['data-format-24h']))
  1051. $aAttrs['data-frmt-24h'] = getParam('sys_format_input_24h');
  1052. if (!isset($aAttrs['data-format-date']))
  1053. $aAttrs['data-frmt-date'] = getParam('sys_format_date');
  1054. if (!isset($aAttrs['data-format-datetime']))
  1055. $aAttrs['data-frmt-datetime'] = getParam('sys_format_datetime');
  1056. // for inputs with labels generate id
  1057. if (isset($aInput['label']))
  1058. $aAttrs['id'] = $this->getInputId($aInput);
  1059. // for checkboxes
  1060. if (isset($aInput['checked']) and $aInput['checked'])
  1061. $aAttrs['checked'] = 'checked';
  1062. return $aAttrs;
  1063. }
  1064. /**
  1065. * Generate Switcher Input Element (based on checkbox)
  1066. *
  1067. * @param array $aInput
  1068. * @return string
  1069. */
  1070. function genInputSwitcher(&$aInput)
  1071. {
  1072. $aInput['type'] = 'checkbox';
  1073. $sCheckbox = $this->genInputStandard($aInput);
  1074. $aInput['type'] = 'switcher';
  1075. $sClass = 'off';
  1076. if(isset($aInput['checked']) && $aInput['checked'])
  1077. $sClass = 'on';
  1078. return $this->oTemplate->parseHtmlByName('form_field_switcher.html', [
  1079. 'class' => $sClass,
  1080. 'checkbox' => $sCheckbox
  1081. ]);
  1082. }
  1083. /**
  1084. * Generate Button Input Element
  1085. *
  1086. * @param array $aInput
  1087. * @return string
  1088. */
  1089. function genInputButton(&$aInput)
  1090. {
  1091. $aAttrs = $this->_genInputButtonAttrs($aInput);
  1092. $sClassAdd = "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn";
  1093. if($aInput['type'] == 'submit')
  1094. $sClassAdd .= ' bx-btn-primary';
  1095. return $this->oTemplate->parseHtmlByName('form_field_button.html', [
  1096. 'attrs' => bx_convert_array2attrs($aAttrs, $sClassAdd),
  1097. 'value' => $aInput['value']
  1098. ]);
  1099. }
  1100. protected function _genInputButtonAttrs(&$aInput)
  1101. {
  1102. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : [];
  1103. // add default className to attributes
  1104. $aAttrs['type'] = $aInput['type'];
  1105. if(isset($aInput['value']))
  1106. $aAttrs['value'] = $aInput['value'];
  1107. if(isset($aInput['name']))
  1108. $aAttrs['name'] = $aInput['name'];
  1109. return $aAttrs;
  1110. }
  1111. /**
  1112. * Generate Textarea Element
  1113. *
  1114. * @param array $aInput
  1115. * @return string
  1116. */
  1117. function genInputTextarea(&$aInput)
  1118. {
  1119. $aAttrs = $this->_genInputTextareaAttrs($aInput);
  1120. $sUniq = genRndPwd(10, false);
  1121. $sClassAdd = "bx-def-font-inputs bx-form-input-{$aInput['type']}";
  1122. if(isset($aInput['html']) && $aInput['html'] && $this->addHtmlEditor($aInput['html'], $aInput, $sUniq)){
  1123. $sClassAdd .= ' bx-form-input-html ' . $sUniq;
  1124. }
  1125. $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')) : '';
  1126. return $this->oTemplate->parseHtmlByName('form_field_textarea.html', [
  1127. 'attrs' => bx_convert_array2attrs($aAttrs, $sClassAdd),
  1128. 'value' => $sValue
  1129. ]);
  1130. }
  1131. protected function _genInputTextareaAttrs(&$aInput)
  1132. {
  1133. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1134. $aAttrs['name'] = $aInput['name'];
  1135. // for inputs with labels generate id
  1136. if (isset($aInput['label']))
  1137. $aAttrs['id'] = $this->getInputId($aInput);
  1138. return $aAttrs;
  1139. }
  1140. function isHtmlEditor($iViewMode, &$aInput)
  1141. {
  1142. return BxDolEditor::getObjectInstance(false, $this->oTemplate) !== false;
  1143. }
  1144. function addHtmlEditor($iViewMode, &$aInput, $sUniq)
  1145. {
  1146. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  1147. if (!$oEditor)
  1148. return false;
  1149. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name=' . $aInput['name'] . ']', $iViewMode, $this->_bDynamicMode, ['form_id' => $this->aFormAttrs['id'], 'element_name' => $aInput['name'], 'query_params' => $this->getHtmlEditorQueryParams($aInput), 'uniq' => $sUniq]);
  1150. return true;
  1151. }
  1152. function getHtmlEditorQueryParams($aInput)
  1153. {
  1154. $aQueryParams = ['i' => $aInput['name'], 'f' => $this->aFormAttrs['id'], 'fi' => ''];
  1155. bx_alert('system', 'editor_query_params', 0, 0, array(
  1156. 'form' => $this,
  1157. 'override_result' => &$aQueryParams
  1158. ));
  1159. return $aQueryParams;
  1160. }
  1161. /**
  1162. * Generate Select Box Element
  1163. *
  1164. * @param array $aInput
  1165. * @return string
  1166. */
  1167. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  1168. {
  1169. $aNewInput = $aInput;
  1170. $aNewInput['type'] = 'select';
  1171. $aNewInput['name'] .= '[]';
  1172. $sInput = $this->genInput($aNewInput);
  1173. return <<<BLAH
  1174. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  1175. $sInput
  1176. </div>
  1177. $sInfo
  1178. $sError
  1179. BLAH;
  1180. }
  1181. /**
  1182. * Generate Browse File Element
  1183. *
  1184. * @param array $aInput
  1185. * @return string
  1186. */
  1187. function genInputFile(&$aInput)
  1188. {
  1189. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  1190. if(!empty($aInput['attrs']['onchange']))
  1191. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  1192. else
  1193. $aInput['attrs']['onchange'] = $sOnChange;
  1194. $sInput = $this->genInputStandard($aInput);
  1195. 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>';
  1196. }
  1197. /**
  1198. * Generate Select Box Element
  1199. *
  1200. * @param array $aInput
  1201. * @return string
  1202. */
  1203. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  1204. {
  1205. if(empty($aInput['uploaders']) || !is_array($aInput['uploaders']))
  1206. return '';
  1207. $sUniqId = !empty($aInput['uploaders_id']) ? $aInput['uploaders_id'] : genRndPwd (8, false);
  1208. $bInitGhosts = isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1;
  1209. $bInitReordering = empty($aInput['init_reordering']) ? 0 : 1;
  1210. $oUploader = null;
  1211. $sUploadersButtons = $sUploadersJs = '';
  1212. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1213. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  1214. if(!$oUploader)
  1215. continue;
  1216. //--- Get Button code.
  1217. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1218. if(empty($aInput['attrs']['disabled']))
  1219. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  1220. $aParamsButtons = [
  1221. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1222. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1223. 'attrs' => bx_convert_array2attrs($aAttrs),
  1224. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  1225. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  1226. ];
  1227. $sUploadersButtons .= $oUploader->getUploaderButton($aParamsButtons);
  1228. //--- Get JS code.
  1229. $sGhostTemplate = $this->genGhostTemplate($aInput);
  1230. $aParamsJs = array_merge($oUploader->getUploaderJsParams(),
  1231. [
  1232. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1233. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1234. 'is_init_ghosts' => $bInitGhosts,
  1235. 'is_init_reordering' => $bInitReordering
  1236. ]
  1237. );
  1238. if(isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  1239. $aParamsJs['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  1240. $sUploadersJs .= $oUploader->getUploaderJs($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParamsJs, $this->_bDynamicMode);
  1241. }
  1242. if(!$oUploader)
  1243. return '';
  1244. if($bInitReordering) {
  1245. $this->addCssJsUi();
  1246. $this->addCssJsUiSortable();
  1247. }
  1248. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  1249. 'uploaders_buttons' => $sUploadersButtons,
  1250. 'info' => $sInfo,
  1251. 'error' => $sError,
  1252. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  1253. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  1254. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  1255. 'uploaders_js' => $sUploadersJs,
  1256. ));
  1257. }
  1258. protected function genGhostTemplate(&$aInput)
  1259. {
  1260. $sGhostTemplate = false;
  1261. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  1262. $oFormNested = $aInput['ghost_template'];
  1263. if ($oFormNested instanceof BxDolFormNestedGhost)
  1264. $sGhostTemplate = $oFormNested->genForm();
  1265. } 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
  1266. $oFormNested = new BxDolFormNestedGhost($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  1267. $sGhostTemplate = $oFormNested->getCode();
  1268. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  1269. $sGhostTemplate = array ();
  1270. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  1271. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNestedGhost)
  1272. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  1273. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  1274. $sGhostTemplate = $aInput['ghost_template'];
  1275. }
  1276. return $sGhostTemplate;
  1277. }
  1278. protected function genCustomInputUsernamesSuggestions ($aInput)
  1279. {
  1280. $bDisabled = isset($aInput['attrs']['disabled']) && $aInput['attrs']['disabled'] == 'disabled';
  1281. $aAttrs = $this->_genCustomInputUsernamesSuggestionsAttrs($aInput, $bDisabled);
  1282. $aTmplVarsVals = [];
  1283. $sValue = '';
  1284. if(!empty($aInput['value'])) {
  1285. if(is_array($aInput['value']) || (is_numeric($aInput['value']))) {
  1286. if (!is_array($aInput['value']))
  1287. $aInput['value'] = [$aInput['value']];
  1288. foreach($aInput['value'] as $sVal) {
  1289. if(!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  1290. continue;
  1291. $aTmplVarsVals[] = [
  1292. 'item_unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']]),
  1293. 'item_name' => $oProfile->getDisplayName(),
  1294. 'name' => $aInput['name'] . (isset($aInput['custom']['only_once']) && $aInput['custom']['only_once'] == 1 ? '' : '[]'),
  1295. 'value' => $sVal
  1296. ];
  1297. }
  1298. }
  1299. else if(is_string($aInput['value']))
  1300. $sValue = $aInput['value'];
  1301. }
  1302. $aTmplVarsInputText = [];
  1303. if(!$bDisabled) {
  1304. $aInputText = $aInput;
  1305. $aInputText['type'] = 'text';
  1306. $aInputText['value'] = '';
  1307. $aInputText['attrs'] = $this->_genCustomInputUsernamesSuggestionsTextAttrs($aInputText, $bDisabled);
  1308. unset($aInputText['name']);
  1309. $aTmplVarsInputText['input'] = $this->genInputStandard($aInputText);
  1310. }
  1311. $this->addCssJsUi();
  1312. $sJsCode = '';
  1313. if(!$bDisabled) {
  1314. $sJsCode = $this->oTemplate->parseHtmlByName('form_field_custom_suggestions_js.html', [
  1315. 'id' => $aAttrs['id'],
  1316. 'name' => $aInput['name'],
  1317. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  1318. 'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
  1319. 'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
  1320. 'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
  1321. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  1322. ]);
  1323. if($this->_bDynamicMode)
  1324. $sJsCode = $this->oTemplate->addJsPreloadedWrapped([
  1325. 'jquery-ui/jquery-ui.min.js'
  1326. ], $sJsCode);
  1327. else
  1328. $sJsCode = $this->oTemplate->addJsCodeOnLoadWrapped($sJsCode);
  1329. }
  1330. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  1331. 'name' => $aInput['name'],
  1332. 'attrs' => bx_convert_array2attrs($aAttrs),
  1333. 'bx_repeat:vals' => $aTmplVarsVals,
  1334. 'value' => $sValue,
  1335. 'bx_if:input' => array(
  1336. 'condition' => !$bDisabled,
  1337. 'content' => $aTmplVarsInputText
  1338. ),
  1339. 'js_code' => $sJsCode
  1340. ));
  1341. }
  1342. protected function _genCustomInputUsernamesSuggestionsAttrs (&$aInput, $bDisabled = false)
  1343. {
  1344. $aAttrs = ['id' => $aInput['name'] . time() . mt_rand(0, 100)];
  1345. $aAttrs['class'] = 'bx-form-input-autotoken bx-form-input-text bx-def-font-inputs';
  1346. if($bDisabled)
  1347. $aAttrs['class'] .= ' bx-form-input-disabled';
  1348. if(!empty($aInput['attrs']['class']))
  1349. $aAttrs['class'] .= ' ' . $aInput['attrs']['class'];
  1350. return $aAttrs;
  1351. }
  1352. protected function _genCustomInputUsernamesSuggestionsTextAttrs (&$aInput, $bDisabled = false)
  1353. {
  1354. $aAttrs = ['value' => '', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'autocorrect' => 'off'];
  1355. if(!empty($aInput['attrs']) && is_array($aInput['attrs'])) {
  1356. if(isset($aInput['attrs']['class']))
  1357. unset($aInput['attrs']['class']);
  1358. $aAttrs = array_merge($aAttrs, $aInput['attrs']);
  1359. }
  1360. return $aAttrs;
  1361. }
  1362. protected function genCustomViewRowValueLabels ($aInput)
  1363. {
  1364. if (empty($aInput['value']) || !($oMetatags = BxDolMetatags::getObjectInstance($aInput['meta_object'])) || !$oMetatags->keywordsIsEnabled())
  1365. return null;
  1366. if (!empty($aInput['value']) && !is_array($aInput['value']))
  1367. $aInput['value'] = unserialize($aInput['value']);
  1368. $s = '';
  1369. foreach ($aInput['value'] as $sLabel)
  1370. $s .= '<a href="' . $oMetatags->keywordsGetHashTagUrl($sLabel, $aInput['content_id']) . '"><b class="bx-def-label val">' . trim($sLabel) . '</b></a>';
  1371. return $this->oTemplate->parseHtmlByName('form_field_labels_view.html', array(
  1372. 'values' => $s,
  1373. ));
  1374. }
  1375. protected function genCustomInputLabels ($aInput)
  1376. {
  1377. $oLabel = BxDolLabel::getInstance();
  1378. $sName = !empty($aInput['name']) ? $aInput['name'] : 'labels';
  1379. $sValue = '';
  1380. if(!empty($aInput['value'])) {
  1381. if(!is_array($aInput['value']))
  1382. $aInput['value'] = unserialize($aInput['value']);
  1383. if(is_array($aInput['value']))
  1384. foreach($aInput['value'] as $sLabel)
  1385. $sValue .= $oLabel->getLabel($sName, $sLabel);
  1386. }
  1387. $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
  1388. if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
  1389. $sValue .= $oLabel->getLabelPlaceholder($sKeyPlaceholder);
  1390. // print_r($aInput);
  1391. $aInputLabels = array(
  1392. 'type' => 'custom',
  1393. 'name' => $sName,
  1394. 'caption' => '',
  1395. 'value' => $sValue,
  1396. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('label.php', array(
  1397. 'action' => 'labels_list',
  1398. )),
  1399. 'attrs' => array(
  1400. 'class' => 'bx-form-input-labels',
  1401. 'disabled' => 'disabled'
  1402. )
  1403. );
  1404. return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
  1405. 'js_object' => $oLabel->getJsObjectName(),
  1406. 'js_code' => $oLabel->getJsCodeForm(),
  1407. 'html_id' => $oLabel->getFormFieldId($aInput),
  1408. 'name' => $sName,
  1409. 'input_labels' => $this->genCustomInputUsernamesSuggestions($aInputLabels)
  1410. ));
  1411. }
  1412. /**
  1413. * Generate Select Element
  1414. *
  1415. * @param array $aInput
  1416. * @return string
  1417. */
  1418. function genInputSelect(&$aInput)
  1419. {
  1420. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1421. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1422. }
  1423. /**
  1424. * Generate Select RGB Element
  1425. *
  1426. * @param array $aInput
  1427. * @return string
  1428. */
  1429. function genInputSelectRgb(&$aInput)
  1430. {
  1431. $aInput['type'] = 'select';
  1432. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1433. $aInput['values_list_name'] = 'sys_colors';
  1434. $aInput['values'] = self::getDataItems('sys_colors', isset(self::$TYPES_SET[$aInput['type']]));
  1435. $aInput['attrs'] = ['class' => 'bx-form-input-rgb-list'];
  1436. foreach ($aInput['values'] as $sOptValue => $sOptTitle) {
  1437. $aInput['values'][$sOptValue] = ['key' => $sOptValue, 'value' => $sOptTitle, 'class' => 'bg-' . $sOptValue, 'style' => 'color:#fff'];
  1438. }
  1439. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1440. }
  1441. /**
  1442. * Generate Multiple Select Element
  1443. *
  1444. * @param array $aInput
  1445. * @return string
  1446. */
  1447. function genInputSelectMultiple(&$aInput)
  1448. {
  1449. $aCurValues = array();
  1450. if (isset($aInput['value']) && $aInput['value'])
  1451. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1452. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  1453. }
  1454. /**
  1455. * Generate Checkbox Set Element
  1456. *
  1457. * @param array $aInput
  1458. * @return string
  1459. */
  1460. function genInputCheckboxSet(&$aInput)
  1461. {
  1462. $aCurValues = array();
  1463. if (isset($aInput['value']) && $aInput['value'])
  1464. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1465. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  1466. }
  1467. /**
  1468. * Generate Radiobuttons Set Element
  1469. *
  1470. * @param array $aInput
  1471. * @return string
  1472. */
  1473. function genInputRadioSet(&$aInput)
  1474. {
  1475. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1476. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  1477. }
  1478. function _isSelected ($sValue, $sCurValue)
  1479. {
  1480. return ((string)$sValue === (string)$sCurValue);
  1481. }
  1482. function _isSelectedMultiple ($sValue, $aCurValues)
  1483. {
  1484. return in_array($sValue, $aCurValues);
  1485. }
  1486. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  1487. {
  1488. $aOptions = [];
  1489. if(isset($aInput['values']) && is_array($aInput['values'])) {
  1490. foreach ($aInput['values'] as $sOptValue => $sOptTitle) {
  1491. $aOption = array(
  1492. 'bx_if:show_option_group_begin' => [
  1493. 'condition' => false,
  1494. 'content' => []
  1495. ],
  1496. 'bx_if:show_option_group_end' => [
  1497. 'condition' => false,
  1498. 'content' => []
  1499. ],
  1500. 'bx_if:show_option' => [
  1501. 'condition' => false,
  1502. 'content' => []
  1503. ]
  1504. );
  1505. $sOptAttrs = "";
  1506. if(is_array($sOptTitle)) {
  1507. if(isset($sOptTitle['type'])) {
  1508. switch($sOptTitle['type']) {
  1509. case 'group_header':
  1510. $aOption = array_merge($aOption, [
  1511. 'bx_if:show_option_group_begin' => [
  1512. 'condition' => true,
  1513. 'content' => [
  1514. 'opt_label' => bx_process_output($sOptTitle['value'])
  1515. ]
  1516. ]
  1517. ]);
  1518. $aOptions[] = $aOption;
  1519. break;
  1520. case 'group_end':
  1521. $aOption = array_merge($aOption, [
  1522. 'bx_if:show_option_group_end' => [
  1523. 'condition' => true,
  1524. 'content' => []
  1525. ]
  1526. ]);
  1527. $aOptions[] = $aOption;
  1528. break;
  1529. }
  1530. continue;
  1531. }
  1532. $aOptAttrs = $this->_genInputSelectOptionAttrs($sOptTitle);
  1533. if(!empty($aOptAttrs))
  1534. $sOptAttrs = bx_convert_array2attrs($aOptAttrs);
  1535. $sOptValue = $sOptTitle['key'];
  1536. $sOptTitle = $sOptTitle['value'];
  1537. }
  1538. $aOption = array_merge($aOption, [
  1539. 'bx_if:show_option' => [
  1540. 'condition' => true,
  1541. 'content' => [
  1542. 'opt_title' => bx_process_output($sOptTitle),
  1543. 'opt_value' => bx_html_attribute($sOptValue),
  1544. 'opt_attrs' => $sOptAttrs,
  1545. 'bx_if:show_selected' => [
  1546. 'condition' => $this->$sIsSelectedFunc($sOptValue, $mixedCurrentVal),
  1547. 'content' => []
  1548. ]
  1549. ]
  1550. ]
  1551. ]);
  1552. $aOptions[] = $aOption;
  1553. }
  1554. }
  1555. $aAttrs = $this->_genInputSelectAttrs($aInput, $isMultiple);
  1556. return $this->_parseInputSelect('form_field_select.html', [
  1557. 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}"),
  1558. 'bx_repeat:options' => $aOptions,
  1559. 'content' => !empty($aInput['content']) ? $aInput['content'] : ''
  1560. ]);
  1561. }
  1562. protected function _genInputSelectAttrs(&$aInput, $isMultiple)
  1563. {
  1564. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : [];
  1565. $aAttrs['name'] = $aInput['name'];
  1566. if ($isMultiple) {
  1567. $aAttrs['name'] .= '[]';
  1568. $aAttrs['multiple'] = 'multiple';
  1569. }
  1570. // for inputs with labels generate id
  1571. if (isset($aInput['label']))
  1572. $aAttrs['id'] = $this->getInputId($aInput);
  1573. return $aAttrs;
  1574. }
  1575. protected function _genInputSelectOptionAttrs(&$aOption)
  1576. {
  1577. $aAttrs = [];
  1578. if(!empty($aOption['attrs']) && is_array($aOption['attrs']))
  1579. $aAttrs = $aOption['attrs'];
  1580. if(isset($aOption['class']))
  1581. $aAttrs['class'] = !empty($aAttrs['class']) ? $aAttrs['class'] . ' ' . $aOption['class'] : $aOption['class'];
  1582. if(isset($aOption['style']))
  1583. $aAttrs['style'] = !empty($aAttrs['style']) ? $aAttrs['style'] . ' ' . $aOption['style'] : $aOption['style'];
  1584. return $aAttrs;
  1585. }
  1586. protected function _parseInputSelect($sTmplName, $aTmplVars)
  1587. {
  1588. return $this->oTemplate->parseHtmlByName($sTmplName, $aTmplVars);
  1589. }
  1590. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  1591. {
  1592. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  1593. $aAttrs['name'] = $aInput['name'];
  1594. // for inputs with labels generate id
  1595. if (isset($aInput['label']))
  1596. $aAttrs['id'] = $this->getInputId($aInput);
  1597. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1598. // generate options
  1599. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  1600. $iDividerThreshold = !empty($aInput['dv_thd']) ? (int)$aInput['dv_thd'] : 3;
  1601. $sOptions = '';
  1602. if (isset($aInput['values']) && is_array($aInput['values'])) {
  1603. if (count($aInput['values']) > $iDividerThreshold && $sDivider == $this->_sDivider)
  1604. $sDivider = $this->_sDividerAlt;
  1605. // generate complex input using simple standard inputs
  1606. foreach ($aInput['values'] as $sValue => $sLabel) {
  1607. if(is_array($sLabel)) {
  1608. $sValue = $sLabel['key'];
  1609. $sLabel = $sLabel['value'];
  1610. }
  1611. // create new simple input
  1612. $aNewInput = array(
  1613. 'type' => $sType,
  1614. 'name' => $aInput['name'] . $sNameAppend,
  1615. 'value' => $sValue,
  1616. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  1617. 'label' => $sLabel,
  1618. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  1619. );
  1620. if (isset($aInput['label_as_html']))
  1621. $aNewInput['label_as_html'] = $aInput['label_as_html'];
  1622. $sNewInput = $this->genInput($aNewInput);
  1623. // attach new input to complex
  1624. $sOptions .= ($sNewInput . $sDivider);
  1625. }
  1626. }
  1627. // generate element
  1628. $sCode = <<<BLAH
  1629. <div $sAttrs>
  1630. $sOptions
  1631. </div>
  1632. BLAH;
  1633. return $sCode;
  1634. }
  1635. function genInputLocation(&$aInput)
  1636. {
  1637. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1638. if (!$o)
  1639. return _t('_sys_txt_error_occured');
  1640. return $o->genInputLocation($aInput, $this);
  1641. }
  1642. public function setLocationVals ($aInput, $aVals)
  1643. {
  1644. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1645. if (!$o)
  1646. return false;
  1647. return $o->setLocationVals ($aInput, $aVals, $this);
  1648. }
  1649. public function setLocationVal ($aInput, $sIndex, $sVal)
  1650. {
  1651. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1652. if (!$o)
  1653. return false;
  1654. return $o->setLocationVal ($aInput, $sIndex, $sVal, $this);
  1655. }
  1656. protected function getLocationVal ($aInput, $sIndex)
  1657. {
  1658. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1659. if (!$o)
  1660. return false;
  1661. return $o->getLocationVal ($aInput, $sIndex, $this);
  1662. }
  1663. function genInputPassword(&$aInput)
  1664. {
  1665. return $this->oTemplate->parseHtmlByName('form_field_password.html', array('input' => $this->genInputStandard($aInput)));
  1666. }
  1667. function genInputPrice(&$aInput)
  1668. {
  1669. $sCurrency = '';
  1670. if(!isset($aInput['value_currency'])) {
  1671. $sCurrency = BxDolPayments::getInstance()->getOption('default_currency_code');
  1672. if(empty($sCurrency))
  1673. $sCurrency = getParam('currency_code');
  1674. }
  1675. else
  1676. $sCurrency = $aInput['value_currency'];
  1677. return $this->oTemplate->parseHtmlByName('form_field_price.html', array(
  1678. 'bx_if:show_currency' => [
  1679. 'condition' => !empty($sCurrency),
  1680. 'content' => [
  1681. 'currency' => $sCurrency,
  1682. ]
  1683. ],
  1684. 'input' => $this->genInputStandard($aInput)
  1685. ));
  1686. }
  1687. function genInputNestedForm(&$aInput)
  1688. {
  1689. return '';
  1690. }
  1691. function genNestedForm(&$aInput)
  1692. {
  1693. return '';
  1694. }
  1695. function genInputCaptcha(&$aInput)
  1696. {
  1697. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1698. // for inputs with labels generate id
  1699. if (isset($aInput['label']))
  1700. $aAttrs['id'] = $this->getInputId($aInput);
  1701. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1702. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1703. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1704. }
  1705. /**
  1706. * Generate Label Element
  1707. *
  1708. * @param string $aInput input array
  1709. * @return string HTML code
  1710. */
  1711. function genLabel(&$aInput)
  1712. {
  1713. if (!isset($aInput['label']) || empty($aInput['label']))
  1714. return '';
  1715. $sInputID = $this->getInputId($aInput);
  1716. $sLabel = bx_process_output($aInput['label']);
  1717. if (isset($aInput['label_as_html']) && $aInput['label_as_html'] == true)
  1718. $sLabel = $aInput['label'];
  1719. return '<label for="' . $sInputID . '">' . $sLabel . '</label>';
  1720. }
  1721. function genPrivacyGroupChooser(&$aInput, $sPrivacyObject = '')
  1722. {
  1723. if(!isset($aInput['privacy']) || empty($aInput['privacy']))
  1724. return '';
  1725. $iAuthorId = bx_get_logged_profile_id();
  1726. $mixedResult = checkActionModule($iAuthorId, 'set form fields privacy', 'system');
  1727. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1728. return '';
  1729. if(empty($sPrivacyObject))
  1730. $sPrivacyObject = $this->_sPrivacyObjectView;
  1731. $iInputId = (int)$aInput['id'];
  1732. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  1733. if(!isset($aInput['attrs_wrapper']['class']))
  1734. $aInput['attrs_wrapper']['class'] = '';
  1735. $aInput['attrs_wrapper']['class'] .= ' bx-form-input-wrapper-pgc';
  1736. return $this->oTemplate->parseHtmlByName('form_field_privacy.html', array(
  1737. 'js_object' => $this->getJsObjectName(),
  1738. 'html_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  1739. 'id' => $iInputId,
  1740. 'privacy_object' => $sPrivacyObject,
  1741. 'icon' => $this->_getPrivacyIcon($mixedPrivacyGroup)
  1742. ));
  1743. }
  1744. function genInfoIcon($sInfo)
  1745. {
  1746. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1747. }
  1748. function genErrorIcon( $sError = '' )
  1749. {
  1750. if ($this->bEnableErrorIcon) {
  1751. $sStyle = '';
  1752. if (!$sError)
  1753. $sStyle = 'style="display:none;"';
  1754. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1755. }
  1756. }
  1757. function getOpenSection($aAttrs = array(), $sTitle = '')
  1758. {
  1759. if (!$this->_isSectionOpened) {
  1760. if (!$aAttrs || !is_array($aAttrs))
  1761. $aAttrs = array();
  1762. if ($sTitle)
  1763. $sClassesAdd = "bx-form-section-header";
  1764. else
  1765. $sClassesAdd = "bx-form-section-divider";
  1766. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1767. $this->_isSectionOpened = true;
  1768. return "<!-- form header content begins -->\n <div class=\"bx-form-section-wrapper bx-def-margin-top\"> <div $sAttrs> $sTitle <div class=\"bx-form-section-content bx-def-padding-top bx-def-padding-bottom" . ($sTitle ? ' bx-def-padding-left bx-def-padding-right' : '') . "\">\n";
  1769. } else {
  1770. return '';
  1771. }
  1772. }
  1773. function getCloseSection()
  1774. {
  1775. if ($this->_isSectionOpened) {
  1776. $this->_isSectionOpened = false;
  1777. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1778. } else {
  1779. return '';
  1780. }
  1781. }
  1782. function getOpenSectionViewMode($aAttrs = array(), $sTitle = '')
  1783. {
  1784. if (!$this->_isSectionOpened) {
  1785. if (!$aAttrs || !is_array($aAttrs))
  1786. $aAttrs = array();
  1787. if ($sTitle)
  1788. $sClassesAdd = "bx-form-section-header";
  1789. else
  1790. $sClassesAdd = "bx-form-section-divider";
  1791. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1792. $this->_isSectionOpened = true;
  1793. return "<!-- form header content begins -->\n <div class=\"bx-form-section-wrapper bx-def-margin-top\"> <div $sAttrs> $sTitle <div class=\"bx-form-section-content bx-def-padding-top\">\n";
  1794. } else {
  1795. return '';
  1796. }
  1797. }
  1798. function getCloseSectionViewMode()
  1799. {
  1800. if ($this->_isSectionOpened) {
  1801. $this->_isSectionOpened = false;
  1802. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1803. } else {
  1804. return '';
  1805. }
  1806. }
  1807. public static function getJsCalendarLangs ()
  1808. {
  1809. return array ('ar-dz' => 1, 'ar' => 1, 'at' => 1, 'az' => 1, 'be' => 1, 'bg' => 1, 'bn' => 1, 'bs' => 1, 'cat' => 1, 'ckb' => 1, 'cs' => 1, 'cy' => 1, 'da' => 1, 'de' => 1, 'default' => 1, 'eo' => 1, 'es' => 1, 'et' => 1, 'fa' => 1, 'fi' => 1, 'fo' => 1, 'fr' => 1, 'ga' => 1, 'gr' => 1, 'he' => 1, 'hi' => 1, 'hr' => 1, 'hu' => 1, 'hy' => 1, 'id' => 1, 'index' => 1, 'is' => 1, 'it' => 1, 'ja' => 1, 'ka' => 1, 'km' => 1, 'ko' => 1, 'kz' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'mn' => 1, 'ms' => 1, 'my' => 1, 'nl' => 1, 'nn' => 1, 'no' => 1, 'pa' => 1, 'pl' => 1, 'pt' => 1, 'ro' => 1, 'ru' => 1, 'si' => 1, 'sk' => 1, 'sl' => 1, 'sq' => 1, 'sr-cyr' => 1, 'sr' => 1, 'sv' => 1, 'th' => 1, 'tr' => 1, 'uk' => 1, 'uz' => 1, 'uz_latn' => 1, 'vn' => 1, 'zh-tw' => 1, 'zh' => 1);
  1810. }
  1811. public static function getCssJsCalendar()
  1812. {
  1813. $aLangs = self::getJsCalendarLangs();
  1814. $sLang = BxDolLanguages::getInstance()->detectLanguageFromArray($aLangs);
  1815. return [[
  1816. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flatpickr/dist/|flatpickr.min.css'
  1817. ], [
  1818. 'flatpickr/dist/flatpickr.min.js',
  1819. 'flatpickr/dist/l10n/' . $sLang . '.js',
  1820. ]
  1821. ];
  1822. }
  1823. function addCssJsUi ()
  1824. {
  1825. if (self::$_isCssJsUiAdded)
  1826. return;
  1827. $this->_addJs(array(
  1828. 'jquery-ui/jquery-ui.min.js',
  1829. ), "'undefined' === typeof(jQuery.ui.position)");
  1830. $this->_addCss('jquery-ui/jquery-ui.min.css');
  1831. self::$_isCssJsUiAdded = true;
  1832. }
  1833. function addCssJsUiSortable ()
  1834. {
  1835. if (self::$_isCssJsUiSortableAdded)
  1836. return;
  1837. $this->_addJs(array(
  1838. 'jquery-ui/jquery-ui.min.js'
  1839. ), "'undefined' === typeof(jQuery.ui.position)");
  1840. self::$_isCssJsUiSortableAdded = true;
  1841. }
  1842. function addCssJsTimepicker ()
  1843. {
  1844. if (self::$_isCssJsTimepickerAdded)
  1845. return;
  1846. list($aCss, $aJs) = self::getCssJsCalendar();
  1847. $this->_addCss($aCss);
  1848. $this->_addJs($aJs, "'undefined' === typeof(flatpickr)");
  1849. self::$_isCssJsTimepickerAdded = true;
  1850. }
  1851. function addCssJsMinicolors ()
  1852. {
  1853. if (self::$_isCssJsMinicolorsAdded)
  1854. return;
  1855. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  1856. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  1857. self::$_isCssJsMinicolorsAdded = true;
  1858. }
  1859. function addCssJsViewMode ()
  1860. {
  1861. if (self::$_isCssJsAddedViewMode)
  1862. return;
  1863. $this->_addCss('forms.css');
  1864. self::$_isCssJsAddedViewMode = true;
  1865. }
  1866. function addCssJsCore ()
  1867. {
  1868. if (self::$_isCssJsAdded)
  1869. return;
  1870. $this->_addCss('forms.css');
  1871. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  1872. $this->_addJs(array('BxDolForm.js', 'BxDolNestedForm.js'), "true");
  1873. self::$_isCssJsAdded = true;
  1874. }
  1875. function addCssJs ()
  1876. {
  1877. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  1878. $this->addCssJsViewMode ();
  1879. } else {
  1880. $this->addCssJsCore();
  1881. }
  1882. }
  1883. protected function _processCssJs()
  1884. {
  1885. $sRet = '';
  1886. if ($this->_bDynamicMode) {
  1887. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  1888. $sRet .= "\n<script>\n";
  1889. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  1890. foreach ($this->_aJs as $sCondition => $aJs) {
  1891. $sJs = $this->oTemplate->addJs($aJs, true);
  1892. if (!$sJs)
  1893. continue;
  1894. $sRet .= "if ($sCondition)\n";
  1895. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  1896. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  1897. }
  1898. $sRet .= "\n</script>\n";
  1899. }
  1900. else {
  1901. $this->oTemplate->addCss($this->_aCss);
  1902. $aJs = array();
  1903. foreach ($this->_aJs as $sCondition => $a)
  1904. $aJs = array_merge($aJs, $a);
  1905. $this->oTemplate->addJs($aJs);
  1906. }
  1907. return $sRet;
  1908. }
  1909. protected function _addJs($mixed, $sJsCondition)
  1910. {
  1911. if (!is_array($mixed))
  1912. $mixed = array($mixed);
  1913. $this->_aJs[$sJsCondition] = $mixed;
  1914. }
  1915. protected function _addCss($mixed)
  1916. {
  1917. if (!is_array($mixed))
  1918. $mixed = array($mixed);
  1919. foreach ($mixed as $s)
  1920. $this->_aCss[$s] = $s;
  1921. }
  1922. }
  1923. /** @} */