BxBaseFormView.php 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853
  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 $_isCssJsCodeMirrorAdded = false;
  17. protected static $_isCssJsLabelsAdded = false;
  18. protected static $_isCssJsTimepickerAdded = false;
  19. protected static $_isCssJsAddedViewMode = false;
  20. /**
  21. * Enable or disable error message displaying
  22. */
  23. protected $bEnableErrorIcon = true;
  24. /**
  25. * HTML Code of this form
  26. */
  27. protected $sCode;
  28. /**
  29. * Code which will be added to the beginning of the form.
  30. * For example, hidden inputs.
  31. * For internal use only
  32. */
  33. protected $_sCodeAdd = '';
  34. /**
  35. * for internal use only
  36. */
  37. protected $_isSectionOpened = false;
  38. /**
  39. * Default divider for several inputs
  40. */
  41. protected $_sDivider = '<span class="bx-def-margin-left"></span>';
  42. /**
  43. * Alternative divider for several inputs
  44. */
  45. protected $_sDividerAlt = '<div class="bx-form-input-dv-nl"></div>';
  46. /**
  47. * Form is added dynamically.
  48. */
  49. protected $_bDynamicMode = false;
  50. /**
  51. * Form is submitted dynamically (using Ajax Submit).
  52. */
  53. protected $_bAjaxMode = false;
  54. /**
  55. * Use absolute Action URL which is needed in Ajax Mode.
  56. */
  57. protected $_bAbsoluteActionUrl = false;
  58. /**
  59. * Form is displayed in view mode.
  60. */
  61. protected $_bViewMode = false;
  62. /**
  63. * Show or not sections which have no fileds
  64. */
  65. protected $_bShowEmptySections = false;
  66. /**
  67. * Function name for generation close form section HTML.
  68. */
  69. protected $_sSectionClose = 'getCloseSection';
  70. /**
  71. * Function name for generation open form section HTML.
  72. */
  73. protected $_sSectionOpen = 'getOpenSection';
  74. /**
  75. * JS files list for form
  76. */
  77. protected $_aJs = array();
  78. /**
  79. * CSS files list for form
  80. */
  81. protected $_aCss = array();
  82. protected $_sJsClassName;
  83. protected $_sJsObjectName;
  84. protected $_aHtmlIds;
  85. protected $_aAgentsFormObject;
  86. protected $_sAgentFormObject;
  87. /**
  88. * Constructor
  89. *
  90. * @param array $aInfo Form contents
  91. *
  92. * $aInfo['params'] = array(
  93. * 'remove_form' => true|false,
  94. * );
  95. *
  96. * @return BxBaseFormView
  97. */
  98. function __construct($aInfo, $oTemplate)
  99. {
  100. parent::__construct($aInfo, $oTemplate);
  101. $this->_bAjaxMode = isset($this->aParams['ajax_mode']) && $this->aParams['ajax_mode'];
  102. $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode'];
  103. if($this->_bViewMode) {
  104. $this->_sSectionClose = 'getCloseSectionViewMode';
  105. $this->_sSectionOpen = 'getOpenSectionViewMode';
  106. }
  107. $this->_sJsClassName = 'BxDolForm';
  108. $sName = !empty($aInfo['params']['display']) ? $aInfo['params']['display'] : '';
  109. if(empty($sName) && !empty($aInfo['params']['object']))
  110. $sName = $aInfo['params']['object'];
  111. if(empty($sName) && !empty($aInfo['form_attrs']['id']))
  112. $sName = $aInfo['form_attrs']['id'];
  113. if(empty($sName) && !empty($aInfo['form_attrs']['name']))
  114. $sName = $aInfo['form_attrs']['name'];
  115. $this->_sJsObjectName = 'oForm' . bx_gen_method_name($sName, array('_' , '-'));
  116. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sName);
  117. $this->_aHtmlIds = array(
  118. 'help_popup' => $sHtmlId . '-help-popup-',
  119. 'pgc' => $sHtmlId . '-pgc-',
  120. 'pgc_popup' => $sHtmlId . '-pgc-popup-',
  121. 'pgc_form' => $sHtmlId . '-pgc-form-',
  122. );
  123. $this->_sAgentFormObject = $aInfo['params']['object'] ?? $this->id;
  124. $this->_aAgentsFormObject = BxDolAI::getInstance()->getAgentsByFormObject($this->_sAgentFormObject);
  125. }
  126. public function performActionGetHelp()
  127. {
  128. $sInput = bx_process_input(bx_get('input'));
  129. if(empty($sInput) || empty($this->aInputs[$sInput]['help']))
  130. return;
  131. echo $this->oTemplate->parseHtmlByName('form_field_help_popup.html', array(
  132. 'content' => _t($this->aInputs[$sInput]['help']),
  133. 'bx_if:show_edit' => array(
  134. 'condition' => isAdmin(),
  135. 'content' => array(
  136. 'link' => BX_DOL_URL_STUDIO . bx_append_url_params('builder_forms.php', array(
  137. 'page' => 'fields',
  138. 'module' => $this->aParams['module'],
  139. 'object' => $this->aParams['object'],
  140. 'display' => $this->aParams['display']
  141. ))
  142. )
  143. )
  144. ));
  145. }
  146. public function performActionChangePrivacyGroup()
  147. {
  148. $iAuthorId = (int)bx_get_logged_profile_id();
  149. if(empty($iAuthorId))
  150. return echoJson(array());
  151. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  152. if(empty($iInputId))
  153. return echoJson(array());
  154. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  155. $sPrivacyField = BxDolPrivacy::getFieldName($sPrivacyObject);
  156. if(empty($sPrivacyField))
  157. return echoJson(array());
  158. $sPrivacyGroup = bx_process_input(bx_get($sPrivacyField));
  159. if(empty($sPrivacyField))
  160. return echoJson(array());
  161. if(!BxDolFormQuery::setInputPrivacy($iInputId, $iAuthorId, $sPrivacyField, $sPrivacyGroup))
  162. return echoJson(array());
  163. return echoJson(array(
  164. 'code' => 0,
  165. 'form_id' => $this->getId(),
  166. 'chooser_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  167. 'icon' => $this->_getPrivacyIcon($sPrivacyGroup),
  168. 'eval' => $this->getJsObjectName() . '.pgcOnSelectGroup(oData);'
  169. ));
  170. }
  171. public function performActionGetPrivacyGroupChooser()
  172. {
  173. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  174. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  175. if(empty($iInputId) || empty($sPrivacyObject))
  176. return '';
  177. $sFormId = $this->_aHtmlIds['pgc_form'] . $iInputId;
  178. $aFormActionParams = array();
  179. if(!empty($this->aParams['object']) && !empty($this->aParams['display']))
  180. $aFormActionParams = array(
  181. 'o' => $this->aParams['object'],
  182. 'd' => $this->aParams['display']
  183. );
  184. $aFormActionParams['a'] = 'change_privacy_group';
  185. $iAuthorId = bx_get_logged_profile_id();
  186. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  187. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  188. $aInputPgc = $oPrivacy->getGroupChooser($sPrivacyObject, $iAuthorId);
  189. $aInputPgc['value'] = $mixedPrivacyGroup;
  190. if(!isset($aInputPgc['content']))
  191. $aInputPgc['content'] = '';
  192. $aInputPgc['content'] .= $oPrivacy->addCssJs(true);
  193. $aInputPgc['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iAuthorId, array(
  194. 'content_id' => $iInputId,
  195. 'group_id' => $mixedPrivacyGroup,
  196. 'html_ids' => array(
  197. 'form' => $sFormId
  198. )
  199. ));
  200. $aFormInfo = array(
  201. 'form_attrs' => array(
  202. 'id' => $sFormId,
  203. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('form.php', $aFormActionParams),
  204. 'method' => 'post'
  205. ),
  206. 'inputs' => array (
  207. 'input_id' => array(
  208. 'type' => 'hidden',
  209. 'name' => 'input_id',
  210. 'value' => $iInputId,
  211. 'db' => array (
  212. 'pass' => 'Int',
  213. ),
  214. ),
  215. 'privacy_object' => array(
  216. 'type' => 'hidden',
  217. 'name' => 'privacy_object',
  218. 'value' => $sPrivacyObject,
  219. 'db' => array (
  220. 'pass' => 'Xss',
  221. ),
  222. ),
  223. 'privacy_group_chooser' => $aInputPgc,
  224. 'controls' => array(
  225. 'name' => 'controls',
  226. 'type' => 'input_set',
  227. array(
  228. 'type' => 'button',
  229. 'name' => 'do_submit',
  230. 'value' => _t('_sys_submit'),
  231. 'attrs' => array(
  232. 'onclick' => "$('#" . $sFormId . "').submit()",
  233. ),
  234. ),
  235. array (
  236. 'type' => 'reset',
  237. 'name' => 'do_cancel',
  238. 'value' => _t('_Cancel'),
  239. 'attrs' => array(
  240. 'onclick' => "$(this).parents('.bx-popup-applied:visible:first').dolPopupHide()",
  241. 'class' => 'bx-def-margin-sec-left',
  242. ),
  243. )
  244. )
  245. )
  246. );
  247. $oForm = new BxTemplFormView($aFormInfo);
  248. echo $this->oTemplate->parseHtmlByName('form_field_privacy_popup.html', array(
  249. 'form_id' => $oForm->getId(),
  250. 'form' => $oForm->getCode(true),
  251. ));
  252. }
  253. function setShowEmptySections($b)
  254. {
  255. $this->_bShowEmptySections = $b;
  256. }
  257. function setAjaxMode($bAjaxMode)
  258. {
  259. $this->_bAjaxMode = (bool)$bAjaxMode;
  260. }
  261. function isAjaxMode()
  262. {
  263. return $this->_bAjaxMode;
  264. }
  265. function isViewMode()
  266. {
  267. return (bool)($this->aParams['view_mode'] ?? 0);
  268. }
  269. function setAbsoluteActionUrl($sUrl)
  270. {
  271. if(empty($sUrl))
  272. return;
  273. $this->aFormAttrs['action'] = $sUrl;
  274. $this->_bAbsoluteActionUrl = true;
  275. }
  276. /**
  277. * Return Form code
  278. * @param $bDynamicMode - set it to true if form is added via JS/AJAX call, for example form in AJAX popup.
  279. * @return string
  280. */
  281. function getCode($bDynamicMode = false)
  282. {
  283. if(!$bDynamicMode && bx_is_dynamic_request())
  284. $bDynamicMode = true;
  285. $this->_bDynamicMode = $bDynamicMode;
  286. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  287. $sInclude = '';
  288. $this->sCode = false;
  289. /**
  290. * @hooks
  291. * @hookdef hook-system-form_output 'system', 'form_output' - hook to override form object and/or code to be output
  292. * - $unit_name - equals `system`
  293. * - $action - equals `form_output`
  294. * - $object_id - not used
  295. * - $sender_id - not used
  296. * - $extra_params - array of additional params with the following array keys:
  297. * - `dynamic` - [boolean] is dynamic mode
  298. * - `object` - [object] by ref, an instance of form class, @see BxDolForm, can be overridden in hook processing
  299. * - `code` - [boolean] or [string] by ref, when false the default generation mechanism will be used, can be overridden in hook processing
  300. * - `include` - [string] by ref, additional data to be attached to output, can be overridden in hook processing
  301. * @hook @ref hook-system-form_output
  302. */
  303. bx_alert('system', 'form_output', 0, 0, [
  304. 'dynamic' => $this->_bDynamicMode,
  305. 'object' => &$this,
  306. 'code' => &$this->sCode,
  307. 'include' => &$sInclude,
  308. 'code_ref' => &$this->sCode,
  309. 'include_ref' => &$sInclude,
  310. 'form_inputs_ref' => &$this->aInputs,
  311. ]);
  312. if($this->sCode === false)
  313. $this->sCode = $this->genForm();
  314. $this->addCssJs();
  315. $sDynamicCssJs = $this->_processCssJs();
  316. return $sInclude . $sDynamicCssJs . $this->sCode;
  317. }
  318. function getCodeAPI()
  319. {
  320. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  321. $this->sCode = false;
  322. /**
  323. * @hooks
  324. * @hookdef hook-system-form_output_api 'system', 'form_output_api' - hook to override form object and/or code to be output. Is used in API calls.
  325. * - $unit_name - equals `system`
  326. * - $action - equals `form_output_api`
  327. * - $object_id - not used
  328. * - $sender_id - not used
  329. * - $extra_params - array of additional params with the following array keys:
  330. * - `dynamic` - [boolean] is dynamic mode
  331. * - `object` - [object] by ref, an instance of form class, @see BxDolForm, can be overridden in hook processing
  332. * - `code` - [boolean] by ref, when false the default generation mechanism will be used, can be overridden in hook processing
  333. * @hook @ref hook-system-form_output_api
  334. */
  335. bx_alert('system', 'form_output_api', 0, 0, [
  336. 'dynamic' => $this->_bDynamicMode,
  337. 'object' => &$this,
  338. 'code' => &$this->sCode,
  339. 'code_ref' => &$this->sCode,
  340. 'form_inputs_ref' => &$this->aInputs,
  341. ]);
  342. if($this->sCode === false) {
  343. if(!$this->genForm() && (bool)($this->aParams['view_mode'] ?? 0))
  344. return [];
  345. }
  346. $oIconset = BxDolIconset::getObjectInstance();
  347. $oFunctions = BxTemplFunctions::getInstanceWithTemplate($this->oTemplate);
  348. // TODO: process inputs to translate titles, alerts, etc
  349. $aInputs = [];
  350. foreach($this->aInputs as $sKey => $aInput) {
  351. if(isset($aInput['visible_for_levels']) && !self::isVisible($aInput))
  352. continue;
  353. if(isset($aInput['type']) && in_array($aInput['name'], ['captcha']))
  354. continue;
  355. list($sIcon, $sIconUrl, $sIconA, $sIconHtml) = $oFunctions->getIcon($aInput['icon'] ?? '');
  356. $aInput['icon'] = $sIcon ? $oIconset->getIcon($sIcon) : ($sIconHtml ? $sIconHtml : '');
  357. if(!empty($aInput['info']))
  358. $aInput['info'] = strip_tags($aInput['info']);
  359. if(!empty($aInput['help']))
  360. $aInput['help'] = strip_tags($aInput['help']);
  361. if(!empty($aInput['error']))
  362. $aInput['error'] = strip_tags($aInput['error']);
  363. $bType = isset($aInput['type']);
  364. if ($bType && 'files' == $aInput['type']) {
  365. $oStorage = BxDolStorage::getObjectInstance($aInput['storage_object']);
  366. $aInput['ext_allow'] = $oStorage->getObjectData()['ext_allow'];
  367. $aInput['ext_deny'] = $oStorage->getObjectData()['ext_deny'];
  368. $aInput['ghost_template'] = '';
  369. $aInput['value'] = '';
  370. $aInput['values'] = '';
  371. $aInput['values_src'] = '';
  372. if(!empty($aInput['content_id']) && ($sUpr = reset($aInput['uploaders'])) && ($sStg = $aInput['storage_object'] ?? '') && ($oUploader = BxDolUploader::getObjectInstance($sUpr, $sStg, genRndPwd(8))) !== false) {
  373. $oUploader->setMultiple($aInput['multiple'] ?? true);
  374. if(($sMethod = 'setSubmitted') && method_exists($oUploader, $sMethod))
  375. $oUploader->$sMethod($this->isSubmitted());
  376. $sData = $oUploader->getGhostsWithOrder((int)bx_get_logged_profile_id(), 'json', $aInput['images_transcoder'], $aInput['content_id']);
  377. if($sData && ($aData = json_decode($sData, true)) && !empty($aData['g']) && is_array($aData['g'])) {
  378. $aInput['values_src'] = array_values($aData['g']);
  379. $aGhostIds = [];
  380. array_walk($aData['g'], function($aGhost) use (&$aGhostIds) {
  381. $aGhostIds[] = $aGhost['file_id'];
  382. });
  383. $aInput['value'] = implode(',', $aGhostIds);
  384. }
  385. }
  386. }
  387. if ($bType && 'custom' == $aInput['type']){
  388. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  389. if (method_exists($this, $sCustomMethod))
  390. $aInput = $this->$sCustomMethod($aInput);
  391. }
  392. if ($bType && 'block_header' == $aInput['type']){
  393. $aInput['name'] = $sKey;
  394. }
  395. if ($bType && 'block_header' == $aInput['type']){
  396. $aInput['name'] = $sKey;
  397. }
  398. if ($bType && 'location' == $aInput['type']){
  399. $oLocation = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  400. $aVars = [];
  401. foreach(BxDolForm::$LOCATION_INDEXES as $sKey)
  402. $aVars[$sKey] = $oLocation->getLocationVal($aInput, $sKey, $this);
  403. if(($sLocationString = bx_api_get_location_string($aVars)))
  404. $aVars['location_string'] = $sLocationString;
  405. $aInput['value'] = $aVars;
  406. }
  407. if ($bType && 'textarea' == $aInput['type']){
  408. if (isset($aInput['value'], $aInput['html']) && (int)$aInput['html'] == 0)
  409. $aInput['value'] = strip_tags($aInput['value']);
  410. }
  411. if ($bType && 'price' == $aInput['type']) {
  412. $aInput['value'] = [
  413. 'value' => $aInput['value'],
  414. 'currency' => BxDolPayments::getInstance()->getOption('default_currency_sign') ?: getParam('currency_sign')
  415. ];
  416. }
  417. /**
  418. * Everytime when [key => value] is used it should be converted to [key => ..., value => ...]
  419. */
  420. if (($sVt = $aInput['type'] ?? false) && in_array($sVt, ['select', 'select_multiple', 'checkbox_set', 'radio_set']) && is_array(($aVv = $aInput[($sKv = 'values')] ?? false)) && !(is_array(($aVv1 = reset($aVv))) && isset($aVv1['key'], $aVv1['value']))) {
  421. $aInput[$sKv] = array_map(function($sKey) use($aInput, $sKv) {
  422. return ['key' => $sKey, 'value' => $aInput[$sKv][$sKey]];
  423. }, array_keys($aInput[$sKv]));
  424. }
  425. if(isset($aInput['name']) && in_array($aInput['name'], ['allow_view_to', 'object_privacy_view'])) {
  426. $aParams = bx_get('params');
  427. if(empty($aParams) || !is_array($aParams))
  428. $aParams = [];
  429. if(!isset($aParams['context_id']) || ($iContextId = (int)$aParams['context_id']) >= 0) {
  430. $oProfile = BxDolProfile::getInstance();
  431. foreach($aInput['values'] as $aValue) {
  432. //--- Selected friends
  433. if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_FRIENDS_SELECTED) {
  434. $aIds = BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContent($oProfile->id(), true, 0, 20);
  435. if(!empty($aIds) && is_array($aIds)) {
  436. $aInput['values_friends'] = [];
  437. foreach($aIds as $iId)
  438. $aInput['values_friends'][] = ['key' => $iId, 'value' => BxDolProfile::getData($iId)];
  439. }
  440. }
  441. //--- Selected relations
  442. if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_RELATIONS_SELECTED) {
  443. $aIds = BxDolConnection::getObjectInstance('sys_profiles_relations')->getConnectedContent($oProfile->id(), true, 0, 20);
  444. if(!empty($aIds) && is_array($aIds)) {
  445. $aInput['values_relations'] = [];
  446. foreach($aIds as $iId)
  447. $aInput['values_relations'][] = ['key' => $iId, 'value' => BxDolProfile::getData($iId)];
  448. }
  449. }
  450. //--- Selected memberships
  451. if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_MEMBERSHIPS_SELECTED) {
  452. $aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
  453. if(!empty($aLevels) && is_array($aLevels)) {
  454. $aInput['values_memberships'] = [];
  455. foreach($aLevels as $iId => $sTitle)
  456. $aInput['values_memberships'][] = ['key' => $iId, 'value' => $sTitle];
  457. }
  458. }
  459. }
  460. }
  461. else
  462. $aInput = array_merge($aInput, [
  463. 'type' => 'hidden',
  464. 'value' => $iContextId,
  465. 'owner_info' => BxDolProfile::getData(abs($iContextId))
  466. ]);
  467. }
  468. $aInputs[$sKey] = $aInput;
  469. }
  470. return [
  471. 'inputs' => $aInputs,
  472. 'attrs' => $this->aFormAttrs,
  473. 'params' => $this->aParams
  474. ];
  475. }
  476. public function getJsClassName()
  477. {
  478. return $this->_sJsClassName;
  479. }
  480. public function getJsObjectName()
  481. {
  482. return $this->_sJsObjectName;
  483. }
  484. public function getJsScript($bWrap = false)
  485. {
  486. $sJsObjName = $this->getJsObjectName();
  487. $sJsObjClass = $this->getJsClassName();
  488. $sCode = "if(window['" . $sJsObjName . "'] == undefined) window['" . $sJsObjName . "'] = new " . $sJsObjClass . "(" . json_encode(array(
  489. 'sObjName' => $sJsObjName,
  490. 'sId' => $this->getId(),
  491. 'sName' => $this->getName(),
  492. 'sObject' => isset($this->aParams['object']) ? $this->aParams['object'] : '',
  493. 'sDisplay' => isset($this->aParams['display']) ? $this->aParams['display'] : '',
  494. 'sRootUrl' => BX_DOL_URL_ROOT,
  495. 'aHtmlIds' => $this->_aHtmlIds,
  496. 'bInitCodeMirror' => self::$_isCssJsCodeMirrorAdded === true,
  497. 'bLeavePageConfirmation' => getParam('sys_form_lpc_enable') == 'on',
  498. 'sTxtLeavePageConfirmation' => _t('_sys_leave_page_confirmation')
  499. )) . "); window['" . $sJsObjName . "'].init();";
  500. return $bWrap ? $this->oTemplate->_wrapInTagJsCode($sCode) : $sCode;
  501. }
  502. /**
  503. * Generate the whole form
  504. *
  505. * @return string
  506. */
  507. function genForm()
  508. {
  509. $this->_sCodeAdd = '';
  510. $bViewMode = $this->isViewMode();
  511. $sTable = $this->genRows();
  512. if($bViewMode && !$sTable)
  513. return '';
  514. $sHtmlBefore = isset($this->aParams['html_before']) ? $this->aParams['html_before'] : '';
  515. $sHtmlAfter = isset($this->aParams['html_after']) ? $this->aParams['html_after'] : '';
  516. if (!empty($this->aParams['remove_form']) || $bViewMode) {
  517. $sForm = <<<BLAH
  518. $sHtmlBefore
  519. {$this->_sCodeAdd}
  520. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  521. $sTable
  522. </div>
  523. $sHtmlAfter
  524. BLAH;
  525. } else {
  526. $sFormAttrs = bx_convert_array2attrs($this->aFormAttrs, 'bx-form-advanced');
  527. $sAjaxFormJs = '';
  528. if($this->_bAjaxMode)
  529. $sAjaxFormJs = <<<BLAH
  530. $("form#{$this->id}").ajaxForm({
  531. dataType: "json",
  532. beforeSubmit: function (formData, jqForm, options) {
  533. bx_loading($("form#{$this->id}"), true);
  534. },
  535. success: function (oData) {
  536. bx_loading($("form#{$this->id}"), false);
  537. processJsonData(oData);
  538. }
  539. });
  540. BLAH;
  541. $sJsCodeDynamic = '';
  542. if($this->_bDynamicMode)
  543. $sJsCodeDynamic = 'function() {' . $this->getJsScript() . '}';
  544. $sForm = <<<BLAH
  545. $sHtmlBefore
  546. <form $sFormAttrs>
  547. {$this->_sCodeAdd}
  548. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  549. $sTable
  550. </div>
  551. </form>
  552. <script>
  553. $(document).ready(function() {
  554. $(this).addWebForms($sJsCodeDynamic);
  555. });
  556. $sAjaxFormJs
  557. </script>
  558. $sHtmlAfter
  559. BLAH;
  560. }
  561. if(!$this->_bDynamicMode)
  562. $sForm = $sForm . $this->getJsScript(true);
  563. return $sForm;
  564. }
  565. /**
  566. * Generate Table HTML code
  567. *
  568. * @return string
  569. */
  570. function genRows()
  571. {
  572. // add CSRF token if it's needed.
  573. 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) {
  574. $this->aInputs['csrf_token'] = array(
  575. 'type' => 'hidden',
  576. 'name' => 'csrf_token',
  577. 'value' => $mixedCsrfToken,
  578. 'db' => array ('pass' => 'Xss'),
  579. 'visible_for_levels' => PHP_INT_MAX,
  580. );
  581. }
  582. // add 'Ajax Mode' flag
  583. if($this->_bAjaxMode)
  584. $this->aInputs['ajax_mode'] = array(
  585. 'type' => 'hidden',
  586. 'name' => 'ajax_mode',
  587. 'value' => 1,
  588. 'db' => array ('pass' => 'Int'),
  589. 'visible_for_levels' => PHP_INT_MAX,
  590. );
  591. // add 'Absolute Action Url' flag
  592. if($this->_bAbsoluteActionUrl)
  593. $this->aInputs['absolute_action_url'] = array(
  594. 'type' => 'hidden',
  595. 'name' => 'absolute_action_url',
  596. 'value' => 1,
  597. 'db' => array ('pass' => 'Int'),
  598. 'visible_for_levels' => PHP_INT_MAX,
  599. );
  600. // check if we need to generate open section clause
  601. $sOpenSection = '';
  602. foreach ($this->aInputs as $aInput) {
  603. if (isset($aInput['type']) && 'hidden' == $aInput['type'])
  604. continue;
  605. if (isset($aInput['type']) && 'block_header' != $aInput['type'])
  606. $sOpenSection = $this->{$this->_sSectionOpen}();
  607. break;
  608. }
  609. // generate rows contents
  610. $sCont = '';
  611. $sContHeader = '';
  612. $sContFields = '';
  613. $sFuncGenRow = isset($this->aParams['view_mode']) && $this->aParams['view_mode'] ? 'genViewRow' : 'genRow';
  614. foreach ($this->aInputs as &$aInput) {
  615. if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) {
  616. if ((isset($aInput['type']) && 'block_header' == $aInput['type']) && !$this->_bShowEmptySections) {
  617. // don't show section with no fields or with empty fields
  618. if ($sContHeader) {
  619. if ($sContFields)
  620. $sCont .= $sContHeader . $sContFields;
  621. else
  622. $sContHeader = '';
  623. $sContFields = '';
  624. }
  625. else {
  626. $sCont .= $sContFields;
  627. $sContFields = '';
  628. }
  629. $sContHeader = $this->$sFuncGenRow($aInput);
  630. } else {
  631. $sContFields .= $this->$sFuncGenRow($aInput);
  632. }
  633. }
  634. }
  635. $sCont .= $sContHeader . $sContFields;
  636. $sCloseSection = $this->{$this->_sSectionClose}();
  637. return $this->isViewMode() && !$sCont ? '' : $sOpenSection . $sCont . $sCloseSection;
  638. }
  639. /**
  640. * Generate single Table Row
  641. *
  642. * @param array $aInput
  643. * @return string
  644. */
  645. function genRow(&$aInput)
  646. {
  647. if (!isset($aInput['type']))
  648. $aInput['type'] = false;
  649. if (!empty($aInput['name'])) {
  650. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  651. if (method_exists($this, $sCustomMethod))
  652. return $this->$sCustomMethod($aInput);
  653. }
  654. switch ($aInput['type']) {
  655. case 'block_header':
  656. $sRow = $this->genRowBlockHeader($aInput);
  657. break;
  658. case 'block_end':
  659. $sRow = $this->genBlockEnd($aInput);
  660. break;
  661. case 'hidden':
  662. // do not generate row for hidden inputs
  663. $sRow = '';
  664. $this->_sCodeAdd .= $this->genInput($aInput);
  665. break;
  666. case 'select_box':
  667. $sRow = $this->genRowCustom($aInput, 'genInputSelectBox');
  668. break;
  669. case 'files':
  670. $sRow = $this->genRowCustom($aInput, 'genInputFiles');
  671. break;
  672. case 'switcher':
  673. case 'checkbox':
  674. $sRow = $this->genRowStandard($aInput, true);
  675. break;
  676. default:
  677. $sRow = $this->genRowStandard($aInput);
  678. }
  679. return $sRow;
  680. }
  681. public function isInputVisible($mixedInput)
  682. {
  683. if(!is_array($mixedInput) && isset($this->aInputs[$mixedInput]))
  684. $mixedInput = $this->aInputs[$mixedInput];
  685. if(empty($mixedInput) || !is_array($mixedInput))
  686. $mixedInput = BxDolFormQuery::getInputByName($this->aParams['object'], $mixedInput);
  687. if(empty($mixedInput) || !is_array($mixedInput))
  688. return false;
  689. if(!empty($mixedInput['privacy']) && !empty($this->_iAuthorId) && !$this->_isInputVisibleByPrivacy($mixedInput))
  690. return false;
  691. return true;
  692. }
  693. protected function _isInputVisibleByPrivacy($aInput)
  694. {
  695. $mixedResult = checkActionModule($this->_iAuthorId, 'set form fields privacy', 'system');
  696. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  697. return true;
  698. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  699. if(empty($aInputPrivacy) || !is_array($aInputPrivacy))
  700. if(BxDolFormQuery::setInputPrivacy($aInput['id'], $this->_iAuthorId, BxDolPrivacy::getFieldName($this->_sPrivacyObjectView), $this->_sPrivacyGroupDefault))
  701. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  702. if((empty($aInputPrivacy) || !is_array($aInputPrivacy)) && $this->_sPrivacyGroupDefault != BX_DOL_PG_ALL)
  703. return false;
  704. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_sPrivacyObjectView);
  705. if($oPrivacy && !$oPrivacy->check($aInputPrivacy['id']))
  706. return false;
  707. return true;
  708. }
  709. /**
  710. * Generate single Table Row for view mode
  711. *
  712. * @param array $aInput
  713. * @return string
  714. */
  715. function genViewRow(&$aInput)
  716. {
  717. if (!isset($aInput['type']))
  718. $aInput['type'] = false;
  719. if(!$this->isInputVisible($aInput))
  720. return '';
  721. if (!empty($aInput['name'])) {
  722. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  723. if (method_exists($this, $sCustomMethod))
  724. return $this->$sCustomMethod($aInput);
  725. }
  726. switch ($aInput['type']) {
  727. case 'block_header':
  728. $sRow = $this->genRowBlockHeader($aInput);
  729. break;
  730. case 'block_end':
  731. $sRow = $this->genBlockEnd($aInput);
  732. break;
  733. case 'nested_form':
  734. $sRow = $this->genNestedForm($aInput);
  735. break;
  736. case 'textarea':
  737. $sRow = $this->{'genViewRowWrapped' . ($aInput['html'] != 0 ? 'Html' : '')}($aInput);
  738. break;
  739. default:
  740. $sRow = $this->genViewRowWrapped($aInput);
  741. }
  742. return $sRow;
  743. }
  744. /**
  745. * Generate complete wrapped row for view mode form
  746. *
  747. * @param array $aInput
  748. * @return string
  749. */
  750. function genViewRowWrapped(&$aInput)
  751. {
  752. return $this->_genViewRowWrapped($aInput);
  753. }
  754. function genViewRowWrappedHtml(&$aInput)
  755. {
  756. return $this->_genViewRowWrapped($aInput, [
  757. 'class_value' => 'bx-def-vanilla-html max-w-none'
  758. ]);
  759. }
  760. protected function _genViewRowWrapped(&$aInput, $aParams = [])
  761. {
  762. $sValue = $this->genViewRowValue($aInput);
  763. if (null === $sValue)
  764. return '';
  765. $sClass = !empty($aParams['class']) ? $aParams['class'] : '';
  766. $sClassValue = !empty($aParams['class_value']) ? $aParams['class_value'] : '';
  767. $aTmplVarsIcon = [];
  768. if(!empty($aInput['icon']))
  769. $aTmplVarsIcon = [
  770. 'icon' => $this->genIcon($aInput['icon'])
  771. ];
  772. return $this->oTemplate->parseHtmlByName('form_view_row.html', [
  773. 'type' => $aInput['type'],
  774. 'class' => $sClass,
  775. 'bx_if:show_icon' => [
  776. 'condition' => !empty($aTmplVarsIcon),
  777. 'content' => $aTmplVarsIcon
  778. ],
  779. 'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '',
  780. 'class_value' => $sClassValue,
  781. 'value' => $sValue
  782. ]);
  783. }
  784. /**
  785. * Generate value for view mode row
  786. *
  787. * @param array $aInput
  788. * @return string
  789. */
  790. function genViewRowValue(&$aInput)
  791. {
  792. if (!empty($aInput['name'])) {
  793. $sCustomMethod = 'genCustomViewRowValue' . $this->_genMethodName($aInput['name']);
  794. if (method_exists($this, $sCustomMethod))
  795. return $this->$sCustomMethod($aInput);
  796. }
  797. switch ($aInput['type']) {
  798. case 'hidden':
  799. $sValue = null;
  800. break;
  801. case 'select':
  802. case 'radio_set':
  803. $sValue = $this->genViewRowValueForSelect($aInput);
  804. break;
  805. case 'dateselect':
  806. case 'datepicker':
  807. $sValue = null;
  808. if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value'])
  809. break;
  810. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  811. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format']: BX_FORMAT_DATE, true, true);
  812. else
  813. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  814. break;
  815. case 'date_time':
  816. case 'datetime':
  817. $sValue = null;
  818. if(empty($aInput['value']) || !$aInput['value'] || '0000-00-00 00:00:00' == $aInput['value'] || '0000-00-00 00:00' == $aInput['value'])
  819. break;
  820. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  821. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true, true);
  822. else
  823. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  824. break;
  825. case 'checkbox_set':
  826. case 'select_multiple':
  827. $sValue = null;
  828. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  829. $sValue = '';
  830. foreach ($aInput['value'] as $sVal)
  831. $sValue .= $aInput['values'][$sVal] . ', ';
  832. $sValue = trim ($sValue, ', ');
  833. }
  834. break;
  835. case 'checkbox':
  836. case 'switcher':
  837. $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off');
  838. break;
  839. case 'textarea':
  840. if (isset($aInput['value']) && '' !== $aInput['value'])
  841. $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE);
  842. else
  843. $sValue = null;
  844. break;
  845. case 'text':
  846. if(isset($aInput['value']) && '' !== $aInput['value'])
  847. $sValue = bx_linkify(bx_process_output($aInput['value']));
  848. else
  849. $sValue = null;
  850. break;
  851. case 'price':
  852. if(isset($aInput['value']) && $aInput['value'] !== '')
  853. $sValue = _t_format_currency(bx_process_output($aInput['value']));
  854. else
  855. $sValue = null;
  856. break;
  857. default:
  858. if(isset($aInput['value']) && '' !== $aInput['value']) {
  859. $sValue = $aInput['value'];
  860. if(get_mb_substr($sValue, 0, 1) == '_')
  861. $sValue = _t($sValue);
  862. $sValue = bx_process_output($sValue);
  863. }
  864. else
  865. $sValue = null;
  866. }
  867. return $sValue;
  868. }
  869. function genViewRowValueForSelect(&$aInput)
  870. {
  871. if (!isset($aInput['value']) || !$aInput['value'])
  872. return null;
  873. $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
  874. if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])) !== false)
  875. return $oCategory->getCategoryLink($s, $aInput['value']);
  876. return $s;
  877. }
  878. protected function genCustomRowBirthday(&$aInput)
  879. {
  880. if(!$this->_bViewMode)
  881. return $this->genRowStandard($aInput);
  882. $sTxtAge = '_sys_form_input_age';
  883. $aInput = array_merge($aInput, [
  884. 'caption_src' => $sTxtAge,
  885. 'caption' => _t($sTxtAge),
  886. ]);
  887. if(bx_is_api())
  888. $aInput = array_merge($aInput, [
  889. 'type' => 'text',
  890. 'value' => bx_birthday2age($aInput['value'])
  891. ]);
  892. return $this->genViewRowWrapped($aInput);
  893. }
  894. protected function genCustomRowCf(&$aInput)
  895. {
  896. $aInput = BxDolContentFilter::getInstance()->getInput($aInput);
  897. if($aInput['type'] == 'hidden') {
  898. $this->_sCodeAdd .= $this->genInput($aInput);
  899. return '';
  900. }
  901. return $this->genRowStandard($aInput);
  902. }
  903. protected function genCustomViewRowValueBirthday(&$aInput)
  904. {
  905. 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')))
  906. return null;
  907. return bx_birthday2age($aInput['value']);
  908. }
  909. /**
  910. * Generate standard row
  911. *
  912. * @param array $aInput
  913. * @return string
  914. */
  915. function genRowStandard(&$aInput, $isOneLine = false)
  916. {
  917. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  918. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  919. $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> ' : '';
  920. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  921. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  922. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  923. $sClassWrapper = 'bx-form-element-wrapper';
  924. if($isOneLine)
  925. $sClassWrapper .= ' ' . $sClassWrapper . '-oneline';
  926. $sClassWrapper .= ' bx-def-margin-top-auto';
  927. if (isset($aInput['name'])) {
  928. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  929. $aInput['tr_attrs'] = [];
  930. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  931. }
  932. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper);
  933. $sClassOneLineCaption = '';
  934. $sClassOneLineValue = '';
  935. if ($isOneLine) {
  936. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' ltr:ml-4 rtl:mr-4';
  937. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  938. if (!isset($aInput['attrs']) || !is_array($aInput['attrs']))
  939. $aInput['attrs'] = [];
  940. $aInput['attrs']['id'] = $this->getInputId($aInput);
  941. if ($sCaption)
  942. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  943. }
  944. $sInput = $this->genInput($aInput);
  945. if(isset($aInput['error_updated']) && $aInput['error_updated'] === true)
  946. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  947. if(empty($sErrorIcon))
  948. $sErrorIcon = '';
  949. $aTmplVarsRow = array(
  950. 'bx_if:show_caption' => array(
  951. 'condition' => !empty($sCaption),
  952. 'content' => array(
  953. 'class_caption' => $sClassOneLineCaption,
  954. 'caption' => $sCaption,
  955. 'required' => $sRequired,
  956. 'help' => $sHelp,
  957. )
  958. ),
  959. 'class_value' => $sClassAdd . $sClassOneLineValue,
  960. 'value' => $this->genWrapperInput($aInput, $sInput),
  961. 'info' => $sInfoIcon,
  962. 'error' => $sErrorIcon,
  963. );
  964. return $this->oTemplate->parseHtmlByName('form_row_standard.html', array(
  965. 'tr_attrs' => $sTrAttrs,
  966. 'bx_if:show_one_line' => array(
  967. 'condition' => $isOneLine,
  968. 'content' => $aTmplVarsRow
  969. ),
  970. 'bx_if:show_lined' => array(
  971. 'condition' => !$isOneLine,
  972. 'content' => $aTmplVarsRow
  973. ),
  974. 'info' => $sInfoIcon,
  975. 'error' => $sErrorIcon
  976. ));
  977. }
  978. function genWrapperInput($aInput, $sContent)
  979. {
  980. $aAttrs = $this->_genWrapperInputAttrs($aInput);
  981. $sClass = "bx-form-input-wrapper bx-form-input-wrapper-{$aInput['type']}";
  982. if(isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput))
  983. $sClass .= ' bx-form-input-wrapper-html';
  984. return $this->oTemplate->parseHtmlByName('form_input_wrapper.html', array(
  985. 'attrs' => bx_convert_array2attrs($aAttrs, $sClass),
  986. 'content' => $sContent
  987. ));
  988. }
  989. protected function _genWrapperInputAttrs(&$aInput)
  990. {
  991. return isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper']) ? $aInput['attrs_wrapper'] : [];
  992. }
  993. /**
  994. * Generate custom row
  995. *
  996. * @param array $aInput
  997. * @param string $sCustomMethod custom method to generate code for input
  998. * @return string
  999. */
  1000. function genRowCustom(&$aInput, $sCustomMethod)
  1001. {
  1002. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  1003. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  1004. $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> ' : '';
  1005. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  1006. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  1007. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  1008. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  1009. if (isset($aInput['name'])) {
  1010. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  1011. $aInput['tr_attrs'] = [];
  1012. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  1013. }
  1014. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  1015. return $this->oTemplate->parseHtmlByName('form_row_custom.html', array(
  1016. 'tr_attrs' => $sTrAttrs,
  1017. 'bx_if:show_caption' => array(
  1018. 'condition' => !empty($sCaption),
  1019. 'content' => array(
  1020. 'class_caption' => '',
  1021. 'caption' => $sCaption,
  1022. 'required' => $sRequired,
  1023. 'help' => $sHelp
  1024. )
  1025. ),
  1026. 'class_value' => $sClassAdd,
  1027. 'value' => $sInput,
  1028. ));
  1029. }
  1030. /**
  1031. * Generate Block Headers row
  1032. *
  1033. * @param array $aInput
  1034. * @return string
  1035. */
  1036. function genRowBlockHeader(&$aInput)
  1037. {
  1038. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  1039. // if there is no caption - show divider only
  1040. if (empty($aInput['caption']))
  1041. return $this->{$this->_sSectionOpen}($aAttrs);
  1042. // if section is collapsed by default, add necessary code
  1043. $sClassAddCollapsable = 'bx-form-collapsable';
  1044. if(isset($aInput['collapsed']) && $aInput['collapsed'])
  1045. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  1046. // display section with caption
  1047. if(empty($aAttrs))
  1048. $aAttrs = ['class' => $sClassAddCollapsable];
  1049. else
  1050. $aAttrs['class'] .= ' ' . $sClassAddCollapsable;
  1051. $bViewMode = !empty($this->aParams['view_mode']);
  1052. $sCaption = bx_process_output($aInput['caption'], BX_DATA_HTML);
  1053. $sInfo = !empty($aInput['info']) ? bx_process_output($aInput['info']) : '';
  1054. $bInfo = !empty($sInfo);
  1055. $sTitle = $this->oTemplate->parseHtmlByName('form_field_section_title.html', [
  1056. 'bx_if:show_view' => [
  1057. 'condition' => $bViewMode,
  1058. 'content' => [
  1059. 'caption' => $sCaption,
  1060. 'bx_if:show_view_info' => [
  1061. 'condition' => $bInfo,
  1062. 'content' => [
  1063. 'info' => $sInfo
  1064. ]
  1065. ]
  1066. ]
  1067. ],
  1068. 'bx_if:show_default' => [
  1069. 'condition' => !$bViewMode,
  1070. 'content' => [
  1071. 'caption' => $sCaption,
  1072. 'bx_if:show_default_info' => [
  1073. 'condition' => $bInfo,
  1074. 'content' => [
  1075. 'info' => $sInfo
  1076. ]
  1077. ]
  1078. ]
  1079. ]
  1080. ]);
  1081. if (isset($aInput['name'])) {
  1082. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  1083. $aInput['tr_attrs'] = [];
  1084. $aInput['tr_attrs']['id'] = "bx-form-section-" . $aInput['name'];
  1085. }
  1086. return $this->{$this->_sSectionOpen}($aAttrs, $sTitle, !empty($aInput['tr_attrs']) ? $aInput['tr_attrs'] : []);
  1087. }
  1088. function genBlockEnd()
  1089. {
  1090. return $this->{$this->_sSectionClose}();
  1091. }
  1092. /**
  1093. * Generate HTML Input Element
  1094. *
  1095. * @param array $aInput
  1096. * @return string Output HTML Code
  1097. */
  1098. function genInput(&$aInput)
  1099. {
  1100. if (!empty($aInput['name'])) {
  1101. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  1102. if (method_exists($this, $sCustomMethod))
  1103. return $this->$sCustomMethod($aInput);
  1104. }
  1105. switch ($aInput['type']) {
  1106. case 'datepicker':
  1107. if (!isset($aInput['attrs']))
  1108. $aInput['attrs'] = array();
  1109. $aInput['attrs']['autosuggestion'] = 'off';
  1110. $sInput = $this->genInputStandard($aInput);
  1111. break;
  1112. // standard inputs (and non-standard, interpreted as standard)
  1113. case 'text':
  1114. case 'datepicker':
  1115. case 'dateselect':
  1116. case 'date_time':
  1117. case 'datetime':
  1118. case 'number':
  1119. case 'time':
  1120. case 'checkbox':
  1121. case 'radio':
  1122. case 'image':
  1123. case 'slider':
  1124. case 'doublerange':
  1125. case 'hidden':
  1126. $sInput = $this->genInputStandard($aInput);
  1127. break;
  1128. case 'phone':
  1129. $aInput['type'] = 'text';
  1130. $sInput = $this->genInputStandard($aInput);
  1131. break;
  1132. case 'password':
  1133. $sInput = $this->genInputPassword($aInput);
  1134. break;
  1135. case 'price':
  1136. $sInput = $this->genInputPrice($aInput);
  1137. break;
  1138. case 'file':
  1139. $sInput = $this->genInputFile($aInput);
  1140. break;
  1141. case 'rgb':
  1142. case 'rgba':
  1143. $sClass = 'bx-form-input-' . $aInput['type'];
  1144. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  1145. $aInput['type'] = 'text';
  1146. $sInput = $this->genInputStandard($aInput);
  1147. break;
  1148. case 'rgb-list':
  1149. $sInput = $this->genInputSelectRgb($aInput);
  1150. break;
  1151. case 'switcher':
  1152. $sInput = $this->genInputSwitcher($aInput);
  1153. break;
  1154. case 'button':
  1155. case 'reset':
  1156. case 'submit':
  1157. $sInput = $this->genInputButton($aInput);
  1158. break;
  1159. case 'textarea':
  1160. $sInput = $this->genInputTextarea($aInput);
  1161. break;
  1162. case 'select':
  1163. $sInput = $this->genInputSelect($aInput);
  1164. break;
  1165. case 'select_multiple':
  1166. $sInput = $this->genInputSelectMultiple($aInput);
  1167. break;
  1168. case 'checkbox_set':
  1169. $sInput = $this->genInputCheckboxSet($aInput);
  1170. break;
  1171. case 'radio_set':
  1172. $sInput = $this->genInputRadioSet($aInput);
  1173. break;
  1174. case 'input_set': // numeric array of inputs
  1175. $sInput = '';
  1176. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  1177. foreach ($aInput as $iKey => $aSubInput) {
  1178. if (!is_int($iKey) or !$aSubInput)
  1179. continue; // parse only integer keys and existing values
  1180. $sInput .= $this->genInput($aSubInput); // recursive call
  1181. $sInput .= $sDivider;
  1182. }
  1183. $sInput .= '<div class="bx-clear"></div>';
  1184. break;
  1185. case 'custom':
  1186. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  1187. break;
  1188. case 'captcha':
  1189. $sInput = $this->genInputCaptcha($aInput);
  1190. break;
  1191. case 'location':
  1192. $sInput = $this->genInputLocation($aInput);
  1193. break;
  1194. case 'nested_form':
  1195. $sInput = $this->genInputNestedForm($aInput);
  1196. break;
  1197. case 'value':
  1198. $sInput = '';
  1199. if(!isset($aInput['value']))
  1200. break;
  1201. $sInput = $aInput['value'];
  1202. if(get_mb_substr($sInput, 0, 1) == '_')
  1203. $sInput = _t($sInput);
  1204. break;
  1205. default:
  1206. //unknown control type
  1207. $sInput = 'Unknown control type';
  1208. }
  1209. // create input label
  1210. $sInput .= $this->genLabel($aInput);
  1211. // create input privacy group chooser
  1212. $sInput .= $this->genPrivacyGroupChooser($aInput);
  1213. return $sInput;
  1214. }
  1215. /**
  1216. * Generate new Input Element id
  1217. *
  1218. * @param array $aInput
  1219. * @return string
  1220. */
  1221. function getInputId(&$aInput)
  1222. {
  1223. if (isset($aInput['id']))
  1224. return $aInput['id'];
  1225. $sName = md5($aInput['name']);
  1226. $sID = $this->id . '_input_' . $sName;
  1227. if ( // multiple elements cause identical id's
  1228. (
  1229. (
  1230. $aInput['type'] == 'checkbox' and
  1231. substr($aInput['name'], -2) == '[]' // it is multiple element
  1232. ) or
  1233. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  1234. ) and
  1235. isset($aInput['value']) // if we can make difference
  1236. ) {
  1237. $sValue = md5($aInput['value']);
  1238. // add value
  1239. $sID .= '_' . $sValue;
  1240. }
  1241. $sID = trim($sID, '_');
  1242. $aInput['id'] = $sID; // just for repeated calls
  1243. return $sID;
  1244. }
  1245. /**
  1246. * Generate standard Input Element
  1247. *
  1248. * @param array $aInput
  1249. * @return string
  1250. */
  1251. function genInputStandard(&$aInput)
  1252. {
  1253. $aAttrs = $this->_genInputStandardAttrs($aInput);
  1254. $aAgent = [];
  1255. if(!empty($this->_aAgentsFormObject) && isset($aInput['name'])) {
  1256. foreach($this->_aAgentsFormObject as $a) {
  1257. if($a['form_object'] == $this->_sAgentFormObject && $a['form_input'] == $aInput['name']) {
  1258. $aAgent = $a;
  1259. break;
  1260. }
  1261. }
  1262. }
  1263. $sAgentButton = '';
  1264. if($aInput['type'] == 'text' && !empty($aAgent)) {
  1265. $sAgentButton = $this->oTemplate->parseHtmlByName('form_field_agent_button.html', [
  1266. 'input' => 'input',
  1267. 'name' => $aInput['name'],
  1268. 'agent_id' => $aAgent['id'] ?? 0,
  1269. 'form_id' => $this->getId(),
  1270. 'html' => $aInput['html'] ?? 0,
  1271. 'popup_text' => $aInput['agent_popup_text'] ?? _t('_sys_agents_agent_form_input_popup_text'),
  1272. ]);
  1273. }
  1274. return $this->oTemplate->parseHtmlByName('form_field_standard.html', [
  1275. 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}"),
  1276. 'agent_button' => $sAgentButton,
  1277. ]);
  1278. }
  1279. protected function _genInputStandardAttrs(&$aInput)
  1280. {
  1281. // clone attributes for system use ;)
  1282. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1283. // add default className to attributes
  1284. $aAttrs['type'] = $aInput['type'];
  1285. if ('datetime' == $aAttrs['type'])
  1286. $aAttrs['type'] = 'date_time';
  1287. switch($aAttrs['type']) {
  1288. case 'datepicker':
  1289. case 'date_time':
  1290. $this->addCssJsTimepicker ();
  1291. break;
  1292. case 'slider':
  1293. case 'doublerange':
  1294. $this->addCssJsUi ();
  1295. break;
  1296. case 'dateselect':
  1297. if(!empty($aInput['value']) && strpos($aInput['value'], ' ') !== false)
  1298. list($aInput['value']) = explode(' ', $aInput['value']);
  1299. $this->_addJs(array(
  1300. 'combodate/combodate.js',
  1301. ), "'undefined' === typeof($.combodate)");
  1302. break;
  1303. case 'text':
  1304. if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
  1305. $this->addCssJsMinicolors ();
  1306. break;
  1307. }
  1308. if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) {
  1309. $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max'];
  1310. }
  1311. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  1312. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  1313. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1;
  1314. if (!isset($aAttrs['data-format-24h']))
  1315. $aAttrs['data-frmt-24h'] = getParam('sys_format_input_24h');
  1316. if (!isset($aAttrs['data-format-date']))
  1317. $aAttrs['data-frmt-date'] = getParam('sys_format_date');
  1318. if (!isset($aAttrs['data-format-datetime']))
  1319. $aAttrs['data-frmt-datetime'] = getParam('sys_format_datetime');
  1320. if(($sAreaLabel = $this->_genInputAreaLabel($aInput) ?: bx_html_attribute($this->_genInputCaption($aInput))))
  1321. $aAttrs['area-label'] = $sAreaLabel;
  1322. // for inputs with labels generate id
  1323. if (isset($aInput['label']))
  1324. $aAttrs['id'] = $this->getInputId($aInput);
  1325. // for checkboxes
  1326. if (isset($aInput['checked']) and $aInput['checked'])
  1327. $aAttrs['checked'] = 'checked';
  1328. return $aAttrs;
  1329. }
  1330. /**
  1331. * Generate Switcher Input Element (based on checkbox)
  1332. *
  1333. * @param array $aInput
  1334. * @return string
  1335. */
  1336. function genInputSwitcher(&$aInput)
  1337. {
  1338. $aInput['type'] = 'checkbox';
  1339. $sCheckbox = $this->genInputStandard($aInput);
  1340. $aInput['type'] = 'switcher';
  1341. $sClass = 'off';
  1342. if(isset($aInput['checked']) && $aInput['checked'])
  1343. $sClass = 'on';
  1344. return $this->oTemplate->parseHtmlByName('form_field_switcher.html', [
  1345. 'class' => $sClass,
  1346. 'checkbox' => $sCheckbox
  1347. ]);
  1348. }
  1349. function genInputCheckbox(&$aInput, $bWrapped = false)
  1350. {
  1351. $sInput = $this->genInputStandard($aInput);
  1352. return $bWrapped ? $this->genWrapperInput($aInput, $sInput) : $sInput;
  1353. }
  1354. /**
  1355. * Generate Button Input Element
  1356. *
  1357. * @param array $aInput
  1358. * @return string
  1359. */
  1360. function genInputButton(&$aInput)
  1361. {
  1362. $aAttrs = $this->_genInputButtonAttrs($aInput);
  1363. $sClassAdd = "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn";
  1364. if($aInput['type'] == 'submit')
  1365. $sClassAdd .= ' bx-btn-primary';
  1366. $aTmplVarsIcon = [];
  1367. if(isset($aInput['icon']) && ($sIcon = $this->genIcon($aInput['icon'])))
  1368. $aTmplVarsIcon = ['icon' => $sIcon];
  1369. return $this->oTemplate->parseHtmlByName('form_field_button.html', [
  1370. 'attrs' => bx_convert_array2attrs($aAttrs, $sClassAdd),
  1371. 'bx_if:show_icon' => [
  1372. 'condition' => !empty($aTmplVarsIcon),
  1373. 'content' => $aTmplVarsIcon
  1374. ],
  1375. 'value' => $aInput['value']
  1376. ]);
  1377. }
  1378. protected function _genInputButtonAttrs(&$aInput)
  1379. {
  1380. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : [];
  1381. // add default className to attributes
  1382. $aAttrs['type'] = $aInput['type'];
  1383. if(isset($aInput['value']))
  1384. $aAttrs['value'] = $aInput['value'];
  1385. if(isset($aInput['name']))
  1386. $aAttrs['name'] = $aInput['name'];
  1387. if(($sAreaLabel = $this->_genInputAreaLabel($aInput) ?: bx_html_attribute($aInput['value'])))
  1388. $aAttrs['area-label'] = $sAreaLabel;
  1389. return $aAttrs;
  1390. }
  1391. /**
  1392. * Generate Textarea Element
  1393. *
  1394. * @param array $aInput
  1395. * @return string
  1396. */
  1397. function genInputTextarea(&$aInput)
  1398. {
  1399. $aAttrs = $this->_genInputTextareaAttrs($aInput);
  1400. $sUniq = genRndPwd(10, false);
  1401. $sClassAdd = "bx-def-font-inputs bx-form-input-{$aInput['type']}";
  1402. $bHtml = $bHtmlEditor = false;
  1403. if(($bHtmlEditor = ($bHtml = (bool)($aInput['html'] ?? false)) && $this->addHtmlEditor($aInput['html'], $aInput, $sUniq))) {
  1404. $sClassAdd .= ' bx-form-input-html ' . $sUniq;
  1405. }
  1406. $bCode = $bCodeEditor = false;
  1407. if(($bCodeEditor = ($bCode = (bool)($aInput['code'] ?? false)) && $this->addCodeEditor($aInput['code'], $aInput, $sUniq))) {
  1408. $sClassAdd .= ' bx-form-input-code ' . $sUniq;
  1409. }
  1410. $aTmplVarsSwitcher = [];
  1411. if(($aInput['html_toggle'] ?? false) && $bHtmlEditor && ($aHtmlEditor = $this->getHtmlEditorInfo($aInput['html'], $aInput, $sUniq))) {
  1412. if(($sJsInit = ($aHtmlEditor['js_call_init'] ?? false)) && ($sJsDestroy = ($aHtmlEditor['js_call_destroy'] ?? false))) {
  1413. $aInputSwitcher = [
  1414. 'type' => 'switcher',
  1415. 'name' => $aInput['name'] . '_switcher',
  1416. 'checked' => true,
  1417. 'attrs' => [
  1418. 'onchange' => "if($(this).prop('checked')) " . $sJsInit . "; else " . $sJsDestroy . ";",
  1419. ],
  1420. ];
  1421. $aTmplVarsSwitcher = [
  1422. 'class' => 'bx-form-input-' . $aInput['type'] . '-switcher',
  1423. 'title' => _t('_sys_form_input_textarea_editor'),
  1424. 'switcher' => $this->genInputSwitcher($aInputSwitcher)
  1425. ];
  1426. }
  1427. }
  1428. $bTagsAllowed = $bHtml || $bCode || ($aInput['html_tags'] ?? false);
  1429. $sValue = isset($aInput['value']) ? bx_process_output($bTagsAllowed ? $aInput['value'] : strip_tags($aInput['value']), BX_DATA_TEXT, ['no_process_macros']) : '';
  1430. $aAgent = [];
  1431. if(!empty($this->_aAgentsFormObject)) {
  1432. foreach($this->_aAgentsFormObject as $a) {
  1433. if($a['form_object'] == $this->_sAgentFormObject && $a['form_input'] == $aInput['name']) {
  1434. $aAgent = $a;
  1435. break;
  1436. }
  1437. }
  1438. }
  1439. $sAgentButton = '';
  1440. if(!empty($aAgent)) {
  1441. $sAgentButton = $this->oTemplate->parseHtmlByName('form_field_agent_button.html', [
  1442. 'input' => 'textarea',
  1443. 'name' => $aInput['name'],
  1444. 'agent_id' => $aAgent['id'] ?? 0,
  1445. 'form_id' => $this->getId(),
  1446. 'html' => $aInput['html'] ?? 0,
  1447. 'popup_text' => $aInput['agent_popup_text'] ?? _t('_sys_agents_agent_form_input_popup_text'),
  1448. ]);
  1449. }
  1450. return $this->oTemplate->parseHtmlByName('form_field_textarea.html', [
  1451. 'attrs' => bx_convert_array2attrs($aAttrs, $sClassAdd),
  1452. 'value' => $sValue,
  1453. 'bx_if:show_switcher' => [
  1454. 'condition' => !empty($aTmplVarsSwitcher),
  1455. 'content' => $aTmplVarsSwitcher
  1456. ],
  1457. 'agent_button' => $sAgentButton,
  1458. ]);
  1459. }
  1460. protected function _genInputTextareaAttrs(&$aInput)
  1461. {
  1462. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1463. $aAttrs['name'] = $aInput['name'];
  1464. if(($sAreaLabel = $this->_genInputAreaLabel($aInput) ?: bx_html_attribute($this->_genInputCaption($aInput))))
  1465. $aAttrs['area-label'] = $sAreaLabel;
  1466. // for inputs with labels generate id
  1467. if (isset($aInput['label']))
  1468. $aAttrs['id'] = $this->getInputId($aInput);
  1469. return $aAttrs;
  1470. }
  1471. function isHtmlEditor($iViewMode, &$aInput)
  1472. {
  1473. return BxDolEditor::getObjectInstance(false, $this->oTemplate) !== false;
  1474. }
  1475. function addHtmlEditor($iViewMode, &$aInput, $sUniq)
  1476. {
  1477. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  1478. if(!$oEditor)
  1479. return false;
  1480. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name=' . $aInput['name'] . ']', $iViewMode, $this->_bDynamicMode, [
  1481. 'form_id' => $this->aFormAttrs['id'],
  1482. 'element_name' => $aInput['name'],
  1483. 'query_params' => $this->getHtmlEditorQueryParams($aInput),
  1484. 'uniq' => $sUniq
  1485. ]);
  1486. return true;
  1487. }
  1488. function getHtmlEditorInfo($iViewMode, &$aInput, $sUniq)
  1489. {
  1490. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  1491. if(!$oEditor)
  1492. return false;
  1493. return $oEditor->getEditorInfo('#' . $this->aFormAttrs['id'] . ' [name=' . $aInput['name'] . ']', $iViewMode, $this->_bDynamicMode, [
  1494. 'form_id' => $this->aFormAttrs['id'],
  1495. 'element_name' => $aInput['name'],
  1496. 'uniq' => $sUniq
  1497. ]);
  1498. }
  1499. function addCodeEditor($iViewMode, &$aInput, $sUniq)
  1500. {
  1501. $this->addCssJsCodeMirror();
  1502. return true;
  1503. }
  1504. function getHtmlEditorQueryParams($aInput)
  1505. {
  1506. $aQueryParams = ['i' => $aInput['name'], 'f' => $this->aFormAttrs['id'], 'fi' => ''];
  1507. /**
  1508. * @hooks
  1509. * @hookdef hook-system-editor_query_params 'system', 'editor_query_params' - hook to override http(s) request's query params, which is used in HTML editor
  1510. * - $unit_name - equals `system`
  1511. * - $action - equals `editor_query_params`
  1512. * - $object_id - not used
  1513. * - $sender_id - not used
  1514. * - $extra_params - array of additional params with the following array keys:
  1515. * - `form` - [object] an instance of form, @see BxDolForm
  1516. * - `override_result` - [array] by ref, query string params, can be overridden in hook processing
  1517. * @hook @ref hook-system-editor_query_params
  1518. */
  1519. bx_alert('system', 'editor_query_params', 0, 0, [
  1520. 'form' => $this,
  1521. 'override_result' => &$aQueryParams
  1522. ]);
  1523. return $aQueryParams;
  1524. }
  1525. /**
  1526. * Generate Select Box Element
  1527. *
  1528. * @param array $aInput
  1529. * @return string
  1530. */
  1531. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  1532. {
  1533. $aNewInput = $aInput;
  1534. $aNewInput['type'] = 'select';
  1535. $aNewInput['name'] .= '[]';
  1536. $sInput = $this->genInput($aNewInput);
  1537. return <<<BLAH
  1538. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  1539. $sInput
  1540. </div>
  1541. $sInfo
  1542. $sError
  1543. BLAH;
  1544. }
  1545. /**
  1546. * Generate Browse File Element
  1547. *
  1548. * @param array $aInput
  1549. * @return string
  1550. */
  1551. function genInputFile(&$aInput)
  1552. {
  1553. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  1554. if(!empty($aInput['attrs']['onchange']))
  1555. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  1556. else
  1557. $aInput['attrs']['onchange'] = $sOnChange;
  1558. $sInput = $this->genInputStandard($aInput);
  1559. 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>';
  1560. }
  1561. /**
  1562. * Generate Select Box Element
  1563. *
  1564. * @param array $aInput
  1565. * @return string
  1566. */
  1567. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  1568. {
  1569. if(empty($aInput['uploaders']) || !is_array($aInput['uploaders']))
  1570. return '';
  1571. $sUniqId = !empty($aInput['uploaders_id']) ? $aInput['uploaders_id'] : genRndPwd (8, false);
  1572. $bMultiple = $aInput['multiple'] ?? true;
  1573. $bInitGhosts = isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1;
  1574. $bInitReordering = empty($aInput['init_reordering']) ? 0 : 1;
  1575. $oUploader = null;
  1576. $sUploadersButtons = $sUploadersJs = '';
  1577. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1578. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  1579. if(!$oUploader)
  1580. continue;
  1581. $oUploader->setMultiple($bMultiple);
  1582. //--- Get Button code.
  1583. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1584. if(empty($aInput['attrs']['disabled']))
  1585. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  1586. $aParamsButtons = [
  1587. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1588. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1589. 'attrs' => bx_convert_array2attrs($aAttrs),
  1590. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  1591. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  1592. ];
  1593. $sUploadersButtons .= $oUploader->getUploaderButton($aParamsButtons);
  1594. //--- Get JS code.
  1595. $sGhostTemplate = $this->genGhostTemplate($aInput);
  1596. $aParamsJs = array_merge($oUploader->getUploaderJsParams(),
  1597. [
  1598. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1599. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1600. 'is_init_ghosts' => $bInitGhosts,
  1601. 'is_init_reordering' => $bInitReordering
  1602. ]
  1603. );
  1604. if(isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  1605. $aParamsJs['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  1606. $sUploadersJs .= $oUploader->getUploaderJs($sGhostTemplate, $bMultiple, $aParamsJs, $this->_bDynamicMode);
  1607. }
  1608. if(!$oUploader)
  1609. return '';
  1610. if($bInitReordering) {
  1611. $this->addCssJsUi();
  1612. $this->addCssJsUiSortable();
  1613. }
  1614. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  1615. 'uploaders_buttons' => $sUploadersButtons,
  1616. 'info' => $sInfo,
  1617. 'error' => $sError,
  1618. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  1619. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  1620. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  1621. 'uploaders_js' => $sUploadersJs,
  1622. ));
  1623. }
  1624. protected function genGhostTemplate(&$aInput)
  1625. {
  1626. $sGhostTemplate = false;
  1627. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  1628. $oFormNested = $aInput['ghost_template'];
  1629. if ($oFormNested instanceof BxDolFormNestedGhost)
  1630. $sGhostTemplate = $oFormNested->genForm();
  1631. } 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
  1632. $oFormNested = new BxDolFormNestedGhost($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  1633. $sGhostTemplate = $oFormNested->getCode();
  1634. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  1635. $sGhostTemplate = array ();
  1636. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  1637. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNestedGhost)
  1638. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  1639. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  1640. $sGhostTemplate = $aInput['ghost_template'];
  1641. }
  1642. return $sGhostTemplate;
  1643. }
  1644. protected function genCustomInputUsernamesSuggestions ($aInput)
  1645. {
  1646. $bDisabled = isset($aInput['attrs']['disabled']) && $aInput['attrs']['disabled'] == 'disabled';
  1647. $aAttrs = $this->_genCustomInputUsernamesSuggestionsAttrs($aInput, $bDisabled);
  1648. $aTmplVarsVals = [];
  1649. $sValue = '';
  1650. if(!empty($aInput['value'])) {
  1651. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']) . 'Value';
  1652. if(method_exists($this, $sCustomMethod))
  1653. $aTmplVarsVals = $this->$sCustomMethod($aInput);
  1654. else if(is_array($aInput['value']) || (is_numeric($aInput['value']))) {
  1655. if (!is_array($aInput['value']))
  1656. $aInput['value'] = [$aInput['value']];
  1657. foreach($aInput['value'] as $sVal) {
  1658. if(!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  1659. continue;
  1660. $aTmplVarsVals[] = [
  1661. 'item_unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']]),
  1662. 'item_name' => $oProfile->getDisplayName(),
  1663. 'name' => $aInput['name'] . (isset($aInput['custom']['only_once']) && $aInput['custom']['only_once'] == 1 ? '' : '[]'),
  1664. 'value' => $sVal
  1665. ];
  1666. }
  1667. }
  1668. else if(is_string($aInput['value']))
  1669. $sValue = $aInput['value'];
  1670. }
  1671. $aTmplVarsInputText = [];
  1672. if(!$bDisabled) {
  1673. $aInputText = $aInput;
  1674. $aInputText['type'] = 'text';
  1675. $aInputText['value'] = '';
  1676. $aInputText['attrs'] = $this->_genCustomInputUsernamesSuggestionsTextAttrs($aInputText, $bDisabled);
  1677. unset($aInputText['name']);
  1678. $aTmplVarsInputText['input'] = $this->genInputStandard($aInputText);
  1679. }
  1680. if (bx_is_api()){
  1681. $aInput['type'] = 'initial_members';
  1682. return $aInput;
  1683. }
  1684. $this->addCssJsUi();
  1685. $sJsCode = '';
  1686. if(!$bDisabled) {
  1687. $sJsCode = $this->oTemplate->parseHtmlByName('form_field_custom_suggestions_js.html', [
  1688. 'id' => $aAttrs['id'],
  1689. 'name' => $aInput['name'],
  1690. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  1691. 'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
  1692. 'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
  1693. 'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
  1694. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  1695. ]);
  1696. if($this->_bDynamicMode)
  1697. $sJsCode = $this->oTemplate->addJsPreloadedWrapped([
  1698. 'jquery-ui/jquery-ui.min.js'
  1699. ], $sJsCode);
  1700. else
  1701. $sJsCode = $this->oTemplate->addJsCodeOnLoadWrapped($sJsCode);
  1702. }
  1703. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  1704. 'name' => $aInput['name'],
  1705. 'attrs' => bx_convert_array2attrs($aAttrs),
  1706. 'bx_repeat:vals' => $aTmplVarsVals,
  1707. 'value' => $sValue,
  1708. 'bx_if:input' => array(
  1709. 'condition' => !$bDisabled,
  1710. 'content' => $aTmplVarsInputText
  1711. ),
  1712. 'js_code' => $sJsCode
  1713. ));
  1714. }
  1715. protected function _genCustomInputUsernamesSuggestionsAttrs (&$aInput, $bDisabled = false)
  1716. {
  1717. $aAttrs = ['id' => $aInput['name'] . time() . mt_rand(0, 100)];
  1718. $aAttrs['class'] = 'bx-form-input-autotoken bx-form-input-text bx-def-font-inputs';
  1719. if($bDisabled)
  1720. $aAttrs['class'] .= ' bx-form-input-disabled';
  1721. if(!empty($aInput['attrs']['class']))
  1722. $aAttrs['class'] .= ' ' . $aInput['attrs']['class'];
  1723. return $aAttrs;
  1724. }
  1725. protected function _genCustomInputUsernamesSuggestionsTextAttrs (&$aInput, $bDisabled = false)
  1726. {
  1727. $aAttrs = ['value' => '', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'autocorrect' => 'off'];
  1728. if(!empty($aInput['attrs']) && is_array($aInput['attrs'])) {
  1729. if(isset($aInput['attrs']['class']))
  1730. unset($aInput['attrs']['class']);
  1731. $aAttrs = array_merge($aAttrs, $aInput['attrs']);
  1732. }
  1733. return $aAttrs;
  1734. }
  1735. protected function genCustomViewRowValueLabels ($aInput)
  1736. {
  1737. if (empty($aInput['value']) || !($oMetatags = BxDolMetatags::getObjectInstance($aInput['meta_object'])) || !$oMetatags->keywordsIsEnabled())
  1738. return null;
  1739. if (!empty($aInput['value']) && !is_array($aInput['value']))
  1740. $aInput['value'] = unserialize($aInput['value']);
  1741. $s = '';
  1742. foreach ($aInput['value'] as $sLabel)
  1743. $s .= '<a href="' . $oMetatags->keywordsGetHashTagUrl($sLabel, $aInput['content_id']) . '"><b class="bx-def-label val">' . trim($sLabel) . '</b></a>';
  1744. return $this->oTemplate->parseHtmlByName('form_field_labels_view.html', array(
  1745. 'values' => $s,
  1746. ));
  1747. }
  1748. protected function genCustomInputLabels (&$aInput)
  1749. {
  1750. $oLabel = BxDolLabel::getInstance();
  1751. $sName = !empty($aInput['name']) ? $aInput['name'] : 'labels';
  1752. $sValue = '';
  1753. if(!empty($aInput['value'])) {
  1754. if(!is_array($aInput['value']))
  1755. $aInput['value'] = unserialize($aInput['value']);
  1756. if(is_array($aInput['value']))
  1757. foreach($aInput['value'] as $sLabel)
  1758. $sValue .= $oLabel->getLabel($sName, $sLabel);
  1759. }
  1760. $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
  1761. if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
  1762. $sValue .= $oLabel->getLabelPlaceholder($sKeyPlaceholder);
  1763. $aInputLabels = array(
  1764. 'type' => 'custom',
  1765. 'name' => $sName,
  1766. 'caption' => '',
  1767. 'value' => $sValue,
  1768. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('label.php', array(
  1769. 'action' => 'labels_list',
  1770. )),
  1771. 'attrs' => array(
  1772. 'class' => 'bx-form-input-labels',
  1773. 'disabled' => 'disabled'
  1774. )
  1775. );
  1776. if (bx_is_api()) {
  1777. return array_merge($aInput, [
  1778. 'type' => 'labels',
  1779. 'values' => bx_srv('system', 'get_labels', [], 'TemplLabelsServices')
  1780. ]);
  1781. }
  1782. return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
  1783. 'js_object' => $oLabel->getJsObjectName(),
  1784. 'js_code' => $oLabel->getJsCodeForm(),
  1785. 'html_id' => $oLabel->getFormFieldId($aInput),
  1786. 'name' => $sName,
  1787. 'input_labels' => $this->genCustomInputUsernamesSuggestions($aInputLabels)
  1788. ));
  1789. }
  1790. /**
  1791. * Generate Select Element
  1792. *
  1793. * @param array $aInput
  1794. * @return string
  1795. */
  1796. function genInputSelect(&$aInput)
  1797. {
  1798. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1799. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1800. }
  1801. /**
  1802. * Generate Select RGB Element
  1803. *
  1804. * @param array $aInput
  1805. * @return string
  1806. */
  1807. function genInputSelectRgb(&$aInput)
  1808. {
  1809. $aInput['type'] = 'select';
  1810. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1811. $aInput['values_list_name'] = 'sys_colors';
  1812. $aInput['values'] = self::getDataItems('sys_colors', isset(self::$TYPES_SET[$aInput['type']]));
  1813. $aInput['attrs'] = ['class' => 'bx-form-input-rgb-list'];
  1814. foreach ($aInput['values'] as $sOptValue => $sOptTitle) {
  1815. $aInput['values'][$sOptValue] = ['key' => $sOptValue, 'value' => $sOptTitle, 'class' => 'bg-' . $sOptValue, 'style' => 'color:#fff'];
  1816. }
  1817. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1818. }
  1819. /**
  1820. * Generate Multiple Select Element
  1821. *
  1822. * @param array $aInput
  1823. * @return string
  1824. */
  1825. function genInputSelectMultiple(&$aInput)
  1826. {
  1827. $aCurValues = array();
  1828. if (isset($aInput['value']) && $aInput['value'])
  1829. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1830. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  1831. }
  1832. /**
  1833. * Generate Checkbox Set Element
  1834. *
  1835. * @param array $aInput
  1836. * @return string
  1837. */
  1838. function genInputCheckboxSet(&$aInput)
  1839. {
  1840. $aCurValues = array();
  1841. if (isset($aInput['value']) && $aInput['value'])
  1842. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1843. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  1844. }
  1845. /**
  1846. * Generate Radiobuttons Set Element
  1847. *
  1848. * @param array $aInput
  1849. * @return string
  1850. */
  1851. function genInputRadioSet(&$aInput)
  1852. {
  1853. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1854. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  1855. }
  1856. function _isSelected ($sValue, $sCurValue)
  1857. {
  1858. return ((string)$sValue === (string)$sCurValue);
  1859. }
  1860. function _isSelectedMultiple ($sValue, $aCurValues)
  1861. {
  1862. return in_array($sValue, $aCurValues);
  1863. }
  1864. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  1865. {
  1866. $aOptions = [];
  1867. if(isset($aInput['values']) && is_array($aInput['values'])) {
  1868. foreach ($aInput['values'] as $sOptValue => $sOptTitle) {
  1869. $aOption = array(
  1870. 'bx_if:show_option_group_begin' => [
  1871. 'condition' => false,
  1872. 'content' => []
  1873. ],
  1874. 'bx_if:show_option_group_end' => [
  1875. 'condition' => false,
  1876. 'content' => []
  1877. ],
  1878. 'bx_if:show_option' => [
  1879. 'condition' => false,
  1880. 'content' => []
  1881. ]
  1882. );
  1883. $sOptAttrs = "";
  1884. if(is_array($sOptTitle)) {
  1885. if(isset($sOptTitle['type'])) {
  1886. switch($sOptTitle['type']) {
  1887. case 'group_header':
  1888. $aOption = array_merge($aOption, [
  1889. 'bx_if:show_option_group_begin' => [
  1890. 'condition' => true,
  1891. 'content' => [
  1892. 'opt_label' => bx_process_output($sOptTitle['value'])
  1893. ]
  1894. ]
  1895. ]);
  1896. $aOptions[] = $aOption;
  1897. break;
  1898. case 'group_end':
  1899. $aOption = array_merge($aOption, [
  1900. 'bx_if:show_option_group_end' => [
  1901. 'condition' => true,
  1902. 'content' => []
  1903. ]
  1904. ]);
  1905. $aOptions[] = $aOption;
  1906. break;
  1907. }
  1908. continue;
  1909. }
  1910. $aOptAttrs = $this->_genInputSelectOptionAttrs($sOptTitle);
  1911. if(!empty($aOptAttrs))
  1912. $sOptAttrs = bx_convert_array2attrs($aOptAttrs);
  1913. $sOptValue = $sOptTitle['key'];
  1914. $sOptTitle = $sOptTitle['value'];
  1915. }
  1916. $aOption = array_merge($aOption, [
  1917. 'bx_if:show_option' => [
  1918. 'condition' => true,
  1919. 'content' => [
  1920. 'opt_title' => bx_process_output($sOptTitle),
  1921. 'opt_value' => !empty($sOptValue) ? bx_html_attribute($sOptValue) : '',
  1922. 'opt_attrs' => $sOptAttrs,
  1923. 'bx_if:show_selected' => [
  1924. 'condition' => $this->$sIsSelectedFunc($sOptValue, $mixedCurrentVal),
  1925. 'content' => []
  1926. ]
  1927. ]
  1928. ]
  1929. ]);
  1930. $aOptions[] = $aOption;
  1931. }
  1932. }
  1933. $aAttrs = $this->_genInputSelectAttrs($aInput, $isMultiple);
  1934. return $this->_parseInputSelect('form_field_select.html', [
  1935. 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}"),
  1936. 'bx_repeat:options' => $aOptions,
  1937. 'content' => !empty($aInput['content']) ? $aInput['content'] : ''
  1938. ]);
  1939. }
  1940. protected function _genInputSelectAttrs(&$aInput, $isMultiple)
  1941. {
  1942. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : [];
  1943. $aAttrs['name'] = $aInput['name'];
  1944. if ($isMultiple) {
  1945. $aAttrs['name'] .= '[]';
  1946. $aAttrs['multiple'] = 'multiple';
  1947. }
  1948. if(($sAreaLabel = $this->_genInputAreaLabel($aInput) ?: bx_html_attribute($this->_genInputCaption($aInput))))
  1949. $aAttrs['area-label'] = $sAreaLabel;
  1950. // for inputs with labels generate id
  1951. if (isset($aInput['label']))
  1952. $aAttrs['id'] = $this->getInputId($aInput);
  1953. return $aAttrs;
  1954. }
  1955. protected function _genInputSelectOptionAttrs(&$aOption)
  1956. {
  1957. $aAttrs = [];
  1958. if(!empty($aOption['attrs']) && is_array($aOption['attrs']))
  1959. $aAttrs = $aOption['attrs'];
  1960. if(isset($aOption['class']))
  1961. $aAttrs['class'] = !empty($aAttrs['class']) ? $aAttrs['class'] . ' ' . $aOption['class'] : $aOption['class'];
  1962. if(isset($aOption['style']))
  1963. $aAttrs['style'] = !empty($aAttrs['style']) ? $aAttrs['style'] . ' ' . $aOption['style'] : $aOption['style'];
  1964. return $aAttrs;
  1965. }
  1966. protected function _parseInputSelect($sTmplName, $aTmplVars)
  1967. {
  1968. return $this->oTemplate->parseHtmlByName($sTmplName, $aTmplVars);
  1969. }
  1970. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  1971. {
  1972. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  1973. $aAttrs['name'] = $aInput['name'];
  1974. if(($sAreaLabel = $this->_genInputAreaLabel($aInput) ?: bx_html_attribute($this->_genInputCaption($aInput))))
  1975. $aAttrs['area-label'] = $sAreaLabel;
  1976. // for inputs with labels generate id
  1977. if (isset($aInput['label']))
  1978. $aAttrs['id'] = $this->getInputId($aInput);
  1979. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1980. // generate options
  1981. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  1982. $iDividerThreshold = !empty($aInput['dv_thd']) ? (int)$aInput['dv_thd'] : 3;
  1983. $sOptions = '';
  1984. $aAdditionalFieldInfo = [];
  1985. if (in_array($aInput['type'], ['radio_set', 'checkbox_set']) && !empty($aInput['values_list_name']))
  1986. $aAdditionalFieldInfo = BxDolFormQuery::getDataItems($aInput['values_list_name'], false, BX_DATA_VALUES_ALL);
  1987. if (isset($aInput['values']) && is_array($aInput['values'])) {
  1988. if (count($aInput['values']) > $iDividerThreshold && $sDivider == $this->_sDivider)
  1989. $sDivider = $this->_sDividerAlt;
  1990. // generate complex input using simple standard inputs
  1991. foreach ($aInput['values'] as $sValue => $sLabel) {
  1992. if(is_array($sLabel)) {
  1993. $sValue = $sLabel['key'];
  1994. $sLabel = $sLabel['value'];
  1995. }
  1996. // create new simple input
  1997. $aNewInput = array(
  1998. 'type' => $sType,
  1999. 'name' => $aInput['name'] . $sNameAppend,
  2000. 'value' => $sValue,
  2001. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  2002. 'label' => $sLabel,
  2003. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  2004. );
  2005. if (isset($aInput['label_as_html']))
  2006. $aNewInput['label_as_html'] = $aInput['label_as_html'];
  2007. $sNewInput = $this->genInputCheckbox($aNewInput, true) . $this->genLabel($aNewInput);
  2008. // add additional info for the field
  2009. if (isset($aAdditionalFieldInfo[$sValue]) && !empty($aAdditionalFieldInfo[$sValue]['LKey2']))
  2010. $sNewInput = $this->genFiledItemInfoWrapper($sNewInput, _t($aAdditionalFieldInfo[$sValue]['LKey2']));
  2011. // attach new input to complex
  2012. $sOptions .= ($sNewInput . $sDivider);
  2013. }
  2014. }
  2015. // generate element
  2016. $sCode = <<<BLAH
  2017. <div $sAttrs>
  2018. $sOptions
  2019. </div>
  2020. BLAH;
  2021. return $sCode;
  2022. }
  2023. function genInputLocation(&$aInput)
  2024. {
  2025. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  2026. if (!$o)
  2027. return _t('_sys_txt_error_occured');
  2028. return $o->genInputLocation($aInput, $this);
  2029. }
  2030. public function setLocationVals ($aInput, $aVals)
  2031. {
  2032. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  2033. if (!$o)
  2034. return false;
  2035. return $o->setLocationVals ($aInput, $aVals, $this);
  2036. }
  2037. public function setLocationVal ($aInput, $sIndex, $sVal)
  2038. {
  2039. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  2040. if (!$o)
  2041. return false;
  2042. return $o->setLocationVal ($aInput, $sIndex, $sVal, $this);
  2043. }
  2044. protected function getLocationVal ($aInput, $sIndex)
  2045. {
  2046. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  2047. if (!$o)
  2048. return false;
  2049. return $o->getLocationVal ($aInput, $sIndex, $this);
  2050. }
  2051. function genInputPassword(&$aInput)
  2052. {
  2053. return $this->oTemplate->parseHtmlByName('form_field_password.html', array('input' => $this->genInputStandard($aInput)));
  2054. }
  2055. function genInputPrice(&$aInput)
  2056. {
  2057. $sCurrency = '';
  2058. if(!isset($aInput['value_currency'])) {
  2059. $sCurrency = BxDolPayments::getInstance()->getOption('default_currency_code');
  2060. if(empty($sCurrency))
  2061. $sCurrency = getParam('currency_code');
  2062. }
  2063. else
  2064. $sCurrency = $aInput['value_currency'];
  2065. return $this->oTemplate->parseHtmlByName('form_field_price.html', array(
  2066. 'bx_if:show_currency' => [
  2067. 'condition' => !empty($sCurrency),
  2068. 'content' => [
  2069. 'currency' => $sCurrency,
  2070. ]
  2071. ],
  2072. 'input' => $this->genInputStandard($aInput)
  2073. ));
  2074. }
  2075. function genInputNestedForm(&$aInput)
  2076. {
  2077. return '';
  2078. }
  2079. function genNestedForm(&$aInput)
  2080. {
  2081. return '';
  2082. }
  2083. function genInputCaptcha(&$aInput)
  2084. {
  2085. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  2086. // for inputs with labels generate id
  2087. if (isset($aInput['label']))
  2088. $aAttrs['id'] = $this->getInputId($aInput);
  2089. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  2090. $oCaptcha = BxDolCaptcha::getObjectInstance();
  2091. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  2092. }
  2093. /**
  2094. * Generate Label Element
  2095. *
  2096. * @param string $aInput input array
  2097. * @return string HTML code
  2098. */
  2099. function genLabel(&$aInput)
  2100. {
  2101. if (!isset($aInput['label']) || empty($aInput['label']))
  2102. return '';
  2103. $sInputID = $this->getInputId($aInput);
  2104. $sLabel = bx_process_output($aInput['label']);
  2105. if (isset($aInput['label_as_html']) && $aInput['label_as_html'] == true)
  2106. $sLabel = $aInput['label'];
  2107. return '<label for="' . $sInputID . '">' . $sLabel . '</label>';
  2108. }
  2109. function genPrivacyGroupChooser(&$aInput, $sPrivacyObject = '')
  2110. {
  2111. if(!isset($aInput['privacy']) || empty($aInput['privacy']))
  2112. return '';
  2113. $iAuthorId = bx_get_logged_profile_id();
  2114. $mixedResult = checkActionModule($iAuthorId, 'set form fields privacy', 'system');
  2115. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2116. return '';
  2117. if(empty($sPrivacyObject))
  2118. $sPrivacyObject = $this->_sPrivacyObjectView;
  2119. $iInputId = (int)$aInput['id'];
  2120. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  2121. if(!isset($aInput['attrs_wrapper']['class']))
  2122. $aInput['attrs_wrapper']['class'] = '';
  2123. $aInput['attrs_wrapper']['class'] .= ' bx-form-input-wrapper-pgc';
  2124. return $this->oTemplate->parseHtmlByName('form_field_privacy.html', array(
  2125. 'js_object' => $this->getJsObjectName(),
  2126. 'html_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  2127. 'id' => $iInputId,
  2128. 'privacy_object' => $sPrivacyObject,
  2129. 'icon' => $this->_getPrivacyIcon($mixedPrivacyGroup)
  2130. ));
  2131. }
  2132. function genFiledItemInfoWrapper($sInput, $sInfoValue)
  2133. {
  2134. $sInfo = $this->genInfoIcon($sInfoValue) ;
  2135. return $this->oTemplate->parseHtmlByName('form_field_option_info.html', [
  2136. 'input' => $sInput,
  2137. 'info' => $sInfo
  2138. ]);
  2139. }
  2140. function genIcon($sIcon)
  2141. {
  2142. if(!$sIcon)
  2143. return '';
  2144. list ($sIcon, $sIconUrl, $sIconA, $sIconHtml) = BxTemplFunctions::getInstanceWithTemplate($this->oTemplate)->getIcon($sIcon);
  2145. return $this->oTemplate->parseHtmlByName('form_input_icon.html', [
  2146. 'bx_if:icon' => [
  2147. 'condition' => (bool)$sIcon,
  2148. 'content' => ['icon' => $sIcon],
  2149. ],
  2150. 'bx_if:icon-html' => [
  2151. 'condition' => (bool)$sIconHtml,
  2152. 'content' => ['icon' => $sIconHtml],
  2153. ],
  2154. 'bx_if:image_inline' => [
  2155. 'condition' => false,
  2156. 'content' => ['image' => ''],
  2157. ]
  2158. ]);
  2159. }
  2160. function genInfoIcon($sInfo)
  2161. {
  2162. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small mt-1">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  2163. }
  2164. function genErrorIcon( $sError = '' )
  2165. {
  2166. if ($this->bEnableErrorIcon) {
  2167. $sStyle = '';
  2168. if (!$sError)
  2169. $sStyle = 'style="display:none;"';
  2170. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  2171. }
  2172. }
  2173. function getOpenSection($aAttrs = [], $sTitle = '', $aWrapperAttrs = [])
  2174. {
  2175. $sClose = '';
  2176. if($this->_isSectionOpened)
  2177. $sClose = $this->{$this->_sSectionClose}();
  2178. $sWrapperAttrs = bx_convert_array2attrs($aWrapperAttrs, "bx-form-section-wrapper my-4");
  2179. if(!$aAttrs || !is_array($aAttrs))
  2180. $aAttrs = [];
  2181. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-section-" . ($sTitle ? "header" : "divider"));
  2182. $this->_isSectionOpened = true;
  2183. return $sClose . "<!-- form header content begins -->\n <div $sWrapperAttrs> <div $sAttrs> $sTitle <div class=\"bx-form-section-content pt-4 pb-6" . ($sTitle ? ' px-6' : '') . "\">\n";
  2184. }
  2185. function getCloseSection()
  2186. {
  2187. if(!$this->_isSectionOpened)
  2188. return '';
  2189. $this->_isSectionOpened = false;
  2190. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  2191. }
  2192. function getOpenSectionViewMode($aAttrs = array(), $sTitle = '', $aWrapperAttrs = [])
  2193. {
  2194. if (!$this->_isSectionOpened) {
  2195. if (!$aAttrs || !is_array($aAttrs))
  2196. $aAttrs = array();
  2197. if ($sTitle)
  2198. $sClassesAdd = "bx-form-section-header";
  2199. else
  2200. $sClassesAdd = "bx-form-section-divider";
  2201. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  2202. $sWrapperAttrs = bx_convert_array2attrs($aWrapperAttrs, "bx-form-section-wrapper bx-def-margin-top");
  2203. $this->_isSectionOpened = true;
  2204. return "<!-- form header content begins -->\n <div $sWrapperAttrs> <div $sAttrs> $sTitle <div class=\"bx-form-section-content bx-def-padding-top\">\n";
  2205. } else {
  2206. return '';
  2207. }
  2208. }
  2209. function getCloseSectionViewMode()
  2210. {
  2211. if ($this->_isSectionOpened) {
  2212. $this->_isSectionOpened = false;
  2213. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  2214. } else {
  2215. return '';
  2216. }
  2217. }
  2218. protected function _genInputCaption($aInput)
  2219. {
  2220. return ($sCaption = $aInput['caption'] ?? '') ? bx_process_output($sCaption, BX_DATA_HTML) : '';
  2221. }
  2222. protected function _genInputAreaLabel($aInput)
  2223. {
  2224. return ($sAreaLabel = $aInput['area_label'] ?? '') && ($sAreaLabel = strip_tags(_t($sAreaLabel))) ? bx_html_attribute($sAreaLabel) : '';
  2225. }
  2226. public static function getJsCalendarLangs ()
  2227. {
  2228. 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);
  2229. }
  2230. public static function getCssJsCalendar()
  2231. {
  2232. $aLangs = self::getJsCalendarLangs();
  2233. $sLang = BxDolLanguages::getInstance()->detectLanguageFromArray($aLangs);
  2234. return [[
  2235. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flatpickr/dist/|flatpickr.min.css'
  2236. ], [
  2237. 'flatpickr/dist/flatpickr.min.js',
  2238. 'flatpickr/dist/l10n/' . $sLang . '.js',
  2239. ]
  2240. ];
  2241. }
  2242. function addCssJsUi ()
  2243. {
  2244. if (self::$_isCssJsUiAdded)
  2245. return;
  2246. $this->_addJs(array(
  2247. 'jquery-ui/jquery-ui.min.js',
  2248. ), "'undefined' === typeof(jQuery.ui.position)");
  2249. $this->_addCss('jquery-ui/jquery-ui.min.css');
  2250. self::$_isCssJsUiAdded = true;
  2251. }
  2252. function addCssJsUiSortable ()
  2253. {
  2254. if (self::$_isCssJsUiSortableAdded)
  2255. return;
  2256. $this->_addJs(array(
  2257. 'jquery-ui/jquery-ui.min.js'
  2258. ), "'undefined' === typeof(jQuery.ui.position)");
  2259. self::$_isCssJsUiSortableAdded = true;
  2260. }
  2261. function addCssJsTimepicker ()
  2262. {
  2263. if (self::$_isCssJsTimepickerAdded)
  2264. return;
  2265. list($aCss, $aJs) = self::getCssJsCalendar();
  2266. $this->_addCss($aCss);
  2267. $this->_addJs($aJs, "'undefined' === typeof(flatpickr)");
  2268. self::$_isCssJsTimepickerAdded = true;
  2269. }
  2270. function addCssJsMinicolors ()
  2271. {
  2272. if (self::$_isCssJsMinicolorsAdded)
  2273. return;
  2274. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  2275. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  2276. self::$_isCssJsMinicolorsAdded = true;
  2277. }
  2278. function addCssJsCodeMirror ()
  2279. {
  2280. if (self::$_isCssJsCodeMirrorAdded)
  2281. return;
  2282. $this->_addCss([BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css']);
  2283. $this->_addJs(['codemirror/codemirror-ext.min.js'], "'undefined' === typeof(CodeMirror)");
  2284. self::$_isCssJsCodeMirrorAdded = true;
  2285. }
  2286. function addCssJsViewMode ()
  2287. {
  2288. if (self::$_isCssJsAddedViewMode)
  2289. return;
  2290. $this->_addCss('forms.css');
  2291. self::$_isCssJsAddedViewMode = true;
  2292. }
  2293. function addCssJsCore ()
  2294. {
  2295. if (self::$_isCssJsAdded)
  2296. return;
  2297. $this->_addCss('forms.css');
  2298. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  2299. $this->_addJs(array('BxDolForm.js', 'BxDolNestedForm.js'), "true");
  2300. self::$_isCssJsAdded = true;
  2301. }
  2302. function addCssJs ()
  2303. {
  2304. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  2305. $this->addCssJsViewMode ();
  2306. } else {
  2307. $this->addCssJsCore();
  2308. }
  2309. }
  2310. protected function _processCssJs()
  2311. {
  2312. $sRet = '';
  2313. if ($this->_bDynamicMode) {
  2314. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  2315. $sRet .= "\n<script>\n";
  2316. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  2317. foreach ($this->_aJs as $sCondition => $aJs) {
  2318. $sJs = $this->oTemplate->addJs($aJs, true);
  2319. if (!$sJs)
  2320. continue;
  2321. $sRet .= "if ($sCondition)\n";
  2322. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  2323. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  2324. }
  2325. $sRet .= "\n</script>\n";
  2326. }
  2327. else {
  2328. $this->oTemplate->addCss($this->_aCss);
  2329. $aJs = array();
  2330. foreach ($this->_aJs as $sCondition => $a)
  2331. $aJs = array_merge($aJs, $a);
  2332. $this->oTemplate->addJs($aJs);
  2333. }
  2334. return $sRet;
  2335. }
  2336. protected function _addJs($mixed, $sJsCondition)
  2337. {
  2338. if (!is_array($mixed))
  2339. $mixed = array($mixed);
  2340. $this->_aJs[$sJsCondition] = $mixed;
  2341. }
  2342. protected function _addCss($mixed)
  2343. {
  2344. if (!is_array($mixed))
  2345. $mixed = array($mixed);
  2346. foreach ($mixed as $s)
  2347. $this->_aCss[$s] = $s;
  2348. }
  2349. }
  2350. /** @} */