BxBaseFormView.php 84 KB

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