BxBaseFormView.php 103 KB

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