BxBaseFormView.php 87 KB

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