BxBaseFormView.php 83 KB

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