BxBaseFormView.php 102 KB

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