BxBaseFormView.php 88 KB

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