1
0

BxBaseFormView.php 102 KB

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