BxBaseFormView.php 82 KB

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