BxBaseFormView.php 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524
  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. $sTxtAge = '_sys_form_input_age';
  771. $aInput = array_merge($aInput, [
  772. 'caption_src' => $sTxtAge,
  773. 'caption' => _t($sTxtAge),
  774. ]);
  775. if(bx_is_api())
  776. $aInput = array_merge($aInput, [
  777. 'type' => 'text',
  778. 'value' => bx_birthday2age($aInput['value'])
  779. ]);
  780. return $this->genViewRowWrapped($aInput);
  781. }
  782. protected function genCustomRowCf(&$aInput)
  783. {
  784. $aInput = BxDolContentFilter::getInstance()->getInput($aInput);
  785. if($aInput['type'] == 'hidden') {
  786. $this->_sCodeAdd .= $this->genInput($aInput);
  787. return '';
  788. }
  789. return $this->genRowStandard($aInput);
  790. }
  791. protected function genCustomViewRowValueBirthday(&$aInput)
  792. {
  793. 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')))
  794. return null;
  795. return bx_birthday2age($aInput['value']);
  796. }
  797. /**
  798. * Generate standard row
  799. *
  800. * @param array $aInput
  801. * @return string
  802. */
  803. function genRowStandard(&$aInput, $isOneLine = false)
  804. {
  805. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  806. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  807. $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> ' : '';
  808. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  809. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  810. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  811. $sClassWrapper = 'bx-form-element-wrapper';
  812. if($isOneLine)
  813. $sClassWrapper .= ' ' . $sClassWrapper . '-oneline';
  814. $sClassWrapper .= ' bx-def-margin-top-auto';
  815. if (isset($aInput['name'])) {
  816. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  817. $aInput['tr_attrs'] = [];
  818. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  819. }
  820. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper);
  821. $sClassOneLineCaption = '';
  822. $sClassOneLineValue = '';
  823. if ($isOneLine) {
  824. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' bx-def-margin-sec-left';
  825. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  826. if (!isset($aInput['attrs']) || !is_array($aInput['attrs']))
  827. $aInput['attrs'] = [];
  828. $aInput['attrs']['id'] = $this->getInputId($aInput);
  829. if ($sCaption)
  830. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  831. }
  832. $sInput = $this->genInput($aInput);
  833. if(isset($aInput['error_updated']) && $aInput['error_updated'] === true)
  834. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  835. if(empty($sErrorIcon))
  836. $sErrorIcon = '';
  837. $aTmplVarsRow = array(
  838. 'bx_if:show_caption' => array(
  839. 'condition' => !empty($sCaption),
  840. 'content' => array(
  841. 'class_caption' => $sClassOneLineCaption,
  842. 'caption' => $sCaption,
  843. 'required' => $sRequired,
  844. 'help' => $sHelp,
  845. )
  846. ),
  847. 'class_value' => $sClassAdd . $sClassOneLineValue,
  848. 'value' => $this->genWrapperInput($aInput, $sInput),
  849. 'info' => $sInfoIcon,
  850. 'error' => $sErrorIcon,
  851. );
  852. return $this->oTemplate->parseHtmlByName('form_row_standard.html', array(
  853. 'tr_attrs' => $sTrAttrs,
  854. 'bx_if:show_one_line' => array(
  855. 'condition' => $isOneLine,
  856. 'content' => $aTmplVarsRow
  857. ),
  858. 'bx_if:show_lined' => array(
  859. 'condition' => !$isOneLine,
  860. 'content' => $aTmplVarsRow
  861. ),
  862. 'info' => $sInfoIcon,
  863. 'error' => $sErrorIcon
  864. ));
  865. }
  866. function genWrapperInput($aInput, $sContent)
  867. {
  868. $aAttrs = $this->_genWrapperInputAttrs($aInput);
  869. $sClass = "bx-form-input-wrapper bx-form-input-wrapper-{$aInput['type']}";
  870. if(isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput))
  871. $sClass .= ' bx-form-input-wrapper-html';
  872. return $this->oTemplate->parseHtmlByName('form_input_wrapper.html', array(
  873. 'attrs' => bx_convert_array2attrs($aAttrs, $sClass),
  874. 'content' => $sContent
  875. ));
  876. }
  877. protected function _genWrapperInputAttrs(&$aInput)
  878. {
  879. return isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper']) ? $aInput['attrs_wrapper'] : [];
  880. }
  881. /**
  882. * Generate custom row
  883. *
  884. * @param array $aInput
  885. * @param string $sCustomMethod custom method to generate code for input
  886. * @return string
  887. */
  888. function genRowCustom(&$aInput, $sCustomMethod)
  889. {
  890. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  891. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  892. $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> ' : '';
  893. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  894. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  895. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  896. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  897. if (isset($aInput['name'])) {
  898. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  899. $aInput['tr_attrs'] = [];
  900. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  901. }
  902. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  903. return $this->oTemplate->parseHtmlByName('form_row_custom.html', array(
  904. 'tr_attrs' => $sTrAttrs,
  905. 'bx_if:show_caption' => array(
  906. 'condition' => !empty($sCaption),
  907. 'content' => array(
  908. 'class_caption' => '',
  909. 'caption' => $sCaption,
  910. 'required' => $sRequired,
  911. 'help' => $sHelp
  912. )
  913. ),
  914. 'class_value' => $sClassAdd,
  915. 'value' => $sInput,
  916. ));
  917. }
  918. /**
  919. * Generate Block Headers row
  920. *
  921. * @param array $aInput
  922. * @return string
  923. */
  924. function genRowBlockHeader(&$aInput)
  925. {
  926. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  927. // if there is no caption - show divider only
  928. if (empty($aInput['caption']))
  929. return $this->{$this->_sSectionOpen}($aAttrs);
  930. // if section is collapsed by default, add necessary code
  931. $sClassAddCollapsable = 'bx-form-collapsable';
  932. if (isset($aInput['collapsed']) and $aInput['collapsed'])
  933. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  934. // display section with caption
  935. if (empty($aAttrs))
  936. $aAttrs = array('class' => 'bx-form-collapsable ' . $sClassAddCollapsable);
  937. else
  938. $aAttrs['class'] .= ' bx-form-collapsable ' . $sClassAddCollapsable;
  939. $bViewMode = !empty($this->aParams['view_mode']);
  940. $sCaption = bx_process_output($aInput['caption'], BX_DATA_HTML);
  941. $sInfo = !empty($aInput['info']) ? bx_process_output($aInput['info']) : '';
  942. $bInfo = !empty($sInfo);
  943. $sTitle = $this->oTemplate->parseHtmlByName('form_field_section_title.html', [
  944. 'bx_if:show_view' => [
  945. 'condition' => $bViewMode,
  946. 'content' => [
  947. 'caption' => $sCaption,
  948. 'bx_if:show_view_info' => [
  949. 'condition' => $bInfo,
  950. 'content' => [
  951. 'info' => $sInfo
  952. ]
  953. ]
  954. ]
  955. ],
  956. 'bx_if:show_default' => [
  957. 'condition' => !$bViewMode,
  958. 'content' => [
  959. 'caption' => $sCaption,
  960. 'bx_if:show_default_info' => [
  961. 'condition' => $bInfo,
  962. 'content' => [
  963. 'info' => $sInfo
  964. ]
  965. ]
  966. ]
  967. ]
  968. ]);
  969. if (isset($aInput['name'])) {
  970. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  971. $aInput['tr_attrs'] = [];
  972. $aInput['tr_attrs']['id'] = "bx-form-section-" . $aInput['name'];
  973. }
  974. return $this->{$this->_sSectionOpen}($aAttrs, $sTitle, !empty($aInput['tr_attrs']) ? $aInput['tr_attrs'] : []);
  975. }
  976. function genBlockEnd()
  977. {
  978. return $this->{$this->_sSectionClose}();
  979. }
  980. /**
  981. * Generate HTML Input Element
  982. *
  983. * @param array $aInput
  984. * @return string Output HTML Code
  985. */
  986. function genInput(&$aInput)
  987. {
  988. if (!empty($aInput['name'])) {
  989. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  990. if (method_exists($this, $sCustomMethod))
  991. return $this->$sCustomMethod($aInput);
  992. }
  993. switch ($aInput['type']) {
  994. case 'datepicker':
  995. if (!isset($aInput['attrs']))
  996. $aInput['attrs'] = array();
  997. $aInput['attrs']['autosuggestion'] = 'off';
  998. $sInput = $this->genInputStandard($aInput);
  999. break;
  1000. // standard inputs (and non-standard, interpreted as standard)
  1001. case 'text':
  1002. case 'datepicker':
  1003. case 'dateselect':
  1004. case 'date_time':
  1005. case 'datetime':
  1006. case 'number':
  1007. case 'time':
  1008. case 'checkbox':
  1009. case 'radio':
  1010. case 'image':
  1011. case 'slider':
  1012. case 'doublerange':
  1013. case 'hidden':
  1014. $sInput = $this->genInputStandard($aInput);
  1015. break;
  1016. case 'password':
  1017. $sInput = $this->genInputPassword($aInput);
  1018. break;
  1019. case 'price':
  1020. $sInput = $this->genInputPrice($aInput);
  1021. break;
  1022. case 'file':
  1023. $sInput = $this->genInputFile($aInput);
  1024. break;
  1025. case 'rgb':
  1026. case 'rgba':
  1027. $sClass = 'bx-form-input-' . $aInput['type'];
  1028. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  1029. $aInput['type'] = 'text';
  1030. $sInput = $this->genInputStandard($aInput);
  1031. break;
  1032. case 'rgb-list':
  1033. $sInput = $this->genInputSelectRgb($aInput);
  1034. break;
  1035. case 'switcher':
  1036. $sInput = $this->genInputSwitcher($aInput);
  1037. break;
  1038. case 'button':
  1039. case 'reset':
  1040. case 'submit':
  1041. $sInput = $this->genInputButton($aInput);
  1042. break;
  1043. case 'textarea':
  1044. $sInput = $this->genInputTextarea($aInput);
  1045. break;
  1046. case 'select':
  1047. $sInput = $this->genInputSelect($aInput);
  1048. break;
  1049. case 'select_multiple':
  1050. $sInput = $this->genInputSelectMultiple($aInput);
  1051. break;
  1052. case 'checkbox_set':
  1053. $sInput = $this->genInputCheckboxSet($aInput);
  1054. break;
  1055. case 'radio_set':
  1056. $sInput = $this->genInputRadioSet($aInput);
  1057. break;
  1058. case 'input_set': // numeric array of inputs
  1059. $sInput = '';
  1060. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  1061. foreach ($aInput as $iKey => $aSubInput) {
  1062. if (!is_int($iKey) or !$aSubInput)
  1063. continue; // parse only integer keys and existing values
  1064. $sInput .= $this->genInput($aSubInput); // recursive call
  1065. $sInput .= $sDivider;
  1066. }
  1067. $sInput .= '<div class="bx-clear"></div>';
  1068. break;
  1069. case 'custom':
  1070. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  1071. break;
  1072. case 'captcha':
  1073. $sInput = $this->genInputCaptcha($aInput);
  1074. break;
  1075. case 'location':
  1076. $sInput = $this->genInputLocation($aInput);
  1077. break;
  1078. case 'nested_form':
  1079. $sInput = $this->genInputNestedForm($aInput);
  1080. break;
  1081. case 'value':
  1082. $sInput = '';
  1083. if(!isset($aInput['value']))
  1084. break;
  1085. $sInput = $aInput['value'];
  1086. if(get_mb_substr($sInput, 0, 1) == '_')
  1087. $sInput = _t($sInput);
  1088. break;
  1089. default:
  1090. //unknown control type
  1091. $sInput = 'Unknown control type';
  1092. }
  1093. // create input label
  1094. $sInput .= $this->genLabel($aInput);
  1095. // create input privacy group chooser
  1096. $sInput .= $this->genPrivacyGroupChooser($aInput);
  1097. return $sInput;
  1098. }
  1099. /**
  1100. * Generate new Input Element id
  1101. *
  1102. * @param array $aInput
  1103. * @return string
  1104. */
  1105. function getInputId(&$aInput)
  1106. {
  1107. if (isset($aInput['id']))
  1108. return $aInput['id'];
  1109. $sName = md5($aInput['name']);
  1110. $sID = $this->id . '_input_' . $sName;
  1111. if ( // multiple elements cause identical id's
  1112. (
  1113. (
  1114. $aInput['type'] == 'checkbox' and
  1115. substr($aInput['name'], -2) == '[]' // it is multiple element
  1116. ) or
  1117. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  1118. ) and
  1119. isset($aInput['value']) // if we can make difference
  1120. ) {
  1121. $sValue = md5($aInput['value']);
  1122. // add value
  1123. $sID .= '_' . $sValue;
  1124. }
  1125. $sID = trim($sID, '_');
  1126. $aInput['id'] = $sID; // just for repeated calls
  1127. return $sID;
  1128. }
  1129. /**
  1130. * Generate standard Input Element
  1131. *
  1132. * @param array $aInput
  1133. * @return string
  1134. */
  1135. function genInputStandard(&$aInput)
  1136. {
  1137. $aAttrs = $this->_genInputStandardAttrs($aInput);
  1138. return $this->oTemplate->parseHtmlByName('form_field_standard.html', [
  1139. 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}")
  1140. ]);
  1141. }
  1142. protected function _genInputStandardAttrs(&$aInput)
  1143. {
  1144. // clone attributes for system use ;)
  1145. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1146. // add default className to attributes
  1147. $aAttrs['type'] = $aInput['type'];
  1148. if ('datetime' == $aAttrs['type'])
  1149. $aAttrs['type'] = 'date_time';
  1150. switch($aAttrs['type']) {
  1151. case 'datepicker':
  1152. case 'date_time':
  1153. $this->addCssJsTimepicker ();
  1154. break;
  1155. case 'slider':
  1156. case 'doublerange':
  1157. $this->addCssJsUi ();
  1158. break;
  1159. case 'dateselect':
  1160. if(strpos($aInput['value'], ' ') !== false)
  1161. list($aInput['value']) = explode(' ', $aInput['value']);
  1162. $this->_addJs(array(
  1163. 'combodate/combodate.js',
  1164. ), "'undefined' === typeof($.combodate)");
  1165. break;
  1166. case 'text':
  1167. if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
  1168. $this->addCssJsMinicolors ();
  1169. break;
  1170. }
  1171. if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) {
  1172. $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max'];
  1173. }
  1174. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  1175. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  1176. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1;
  1177. if (!isset($aAttrs['data-format-24h']))
  1178. $aAttrs['data-frmt-24h'] = getParam('sys_format_input_24h');
  1179. if (!isset($aAttrs['data-format-date']))
  1180. $aAttrs['data-frmt-date'] = getParam('sys_format_date');
  1181. if (!isset($aAttrs['data-format-datetime']))
  1182. $aAttrs['data-frmt-datetime'] = getParam('sys_format_datetime');
  1183. // for inputs with labels generate id
  1184. if (isset($aInput['label']))
  1185. $aAttrs['id'] = $this->getInputId($aInput);
  1186. // for checkboxes
  1187. if (isset($aInput['checked']) and $aInput['checked'])
  1188. $aAttrs['checked'] = 'checked';
  1189. return $aAttrs;
  1190. }
  1191. /**
  1192. * Generate Switcher Input Element (based on checkbox)
  1193. *
  1194. * @param array $aInput
  1195. * @return string
  1196. */
  1197. function genInputSwitcher(&$aInput)
  1198. {
  1199. $aInput['type'] = 'checkbox';
  1200. $sCheckbox = $this->genInputStandard($aInput);
  1201. $aInput['type'] = 'switcher';
  1202. $sClass = 'off';
  1203. if(isset($aInput['checked']) && $aInput['checked'])
  1204. $sClass = 'on';
  1205. return $this->oTemplate->parseHtmlByName('form_field_switcher.html', [
  1206. 'class' => $sClass,
  1207. 'checkbox' => $sCheckbox
  1208. ]);
  1209. }
  1210. /**
  1211. * Generate Button Input Element
  1212. *
  1213. * @param array $aInput
  1214. * @return string
  1215. */
  1216. function genInputButton(&$aInput)
  1217. {
  1218. $aAttrs = $this->_genInputButtonAttrs($aInput);
  1219. $sClassAdd = "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn";
  1220. if($aInput['type'] == 'submit')
  1221. $sClassAdd .= ' bx-btn-primary';
  1222. return $this->oTemplate->parseHtmlByName('form_field_button.html', [
  1223. 'attrs' => bx_convert_array2attrs($aAttrs, $sClassAdd),
  1224. 'value' => $aInput['value']
  1225. ]);
  1226. }
  1227. protected function _genInputButtonAttrs(&$aInput)
  1228. {
  1229. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : [];
  1230. // add default className to attributes
  1231. $aAttrs['type'] = $aInput['type'];
  1232. if(isset($aInput['value']))
  1233. $aAttrs['value'] = $aInput['value'];
  1234. if(isset($aInput['name']))
  1235. $aAttrs['name'] = $aInput['name'];
  1236. return $aAttrs;
  1237. }
  1238. /**
  1239. * Generate Textarea Element
  1240. *
  1241. * @param array $aInput
  1242. * @return string
  1243. */
  1244. function genInputTextarea(&$aInput)
  1245. {
  1246. $aAttrs = $this->_genInputTextareaAttrs($aInput);
  1247. $sUniq = genRndPwd(10, false);
  1248. $sClassAdd = "bx-def-font-inputs bx-form-input-{$aInput['type']}";
  1249. if(isset($aInput['html']) && $aInput['html'] && $this->addHtmlEditor($aInput['html'], $aInput, $sUniq)){
  1250. $sClassAdd .= ' bx-form-input-html ' . $sUniq;
  1251. }
  1252. $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')) : '';
  1253. return $this->oTemplate->parseHtmlByName('form_field_textarea.html', [
  1254. 'attrs' => bx_convert_array2attrs($aAttrs, $sClassAdd),
  1255. 'value' => $sValue
  1256. ]);
  1257. }
  1258. protected function _genInputTextareaAttrs(&$aInput)
  1259. {
  1260. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1261. $aAttrs['name'] = $aInput['name'];
  1262. // for inputs with labels generate id
  1263. if (isset($aInput['label']))
  1264. $aAttrs['id'] = $this->getInputId($aInput);
  1265. return $aAttrs;
  1266. }
  1267. function isHtmlEditor($iViewMode, &$aInput)
  1268. {
  1269. return BxDolEditor::getObjectInstance(false, $this->oTemplate) !== false;
  1270. }
  1271. function addHtmlEditor($iViewMode, &$aInput, $sUniq)
  1272. {
  1273. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  1274. if (!$oEditor)
  1275. return false;
  1276. $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]);
  1277. return true;
  1278. }
  1279. function getHtmlEditorQueryParams($aInput)
  1280. {
  1281. $aQueryParams = ['i' => $aInput['name'], 'f' => $this->aFormAttrs['id'], 'fi' => ''];
  1282. bx_alert('system', 'editor_query_params', 0, 0, array(
  1283. 'form' => $this,
  1284. 'override_result' => &$aQueryParams
  1285. ));
  1286. return $aQueryParams;
  1287. }
  1288. /**
  1289. * Generate Select Box Element
  1290. *
  1291. * @param array $aInput
  1292. * @return string
  1293. */
  1294. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  1295. {
  1296. $aNewInput = $aInput;
  1297. $aNewInput['type'] = 'select';
  1298. $aNewInput['name'] .= '[]';
  1299. $sInput = $this->genInput($aNewInput);
  1300. return <<<BLAH
  1301. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  1302. $sInput
  1303. </div>
  1304. $sInfo
  1305. $sError
  1306. BLAH;
  1307. }
  1308. /**
  1309. * Generate Browse File Element
  1310. *
  1311. * @param array $aInput
  1312. * @return string
  1313. */
  1314. function genInputFile(&$aInput)
  1315. {
  1316. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  1317. if(!empty($aInput['attrs']['onchange']))
  1318. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  1319. else
  1320. $aInput['attrs']['onchange'] = $sOnChange;
  1321. $sInput = $this->genInputStandard($aInput);
  1322. 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>';
  1323. }
  1324. /**
  1325. * Generate Select Box Element
  1326. *
  1327. * @param array $aInput
  1328. * @return string
  1329. */
  1330. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  1331. {
  1332. if(empty($aInput['uploaders']) || !is_array($aInput['uploaders']))
  1333. return '';
  1334. $sUniqId = !empty($aInput['uploaders_id']) ? $aInput['uploaders_id'] : genRndPwd (8, false);
  1335. $bInitGhosts = isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1;
  1336. $bInitReordering = empty($aInput['init_reordering']) ? 0 : 1;
  1337. $oUploader = null;
  1338. $sUploadersButtons = $sUploadersJs = '';
  1339. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1340. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  1341. if(!$oUploader)
  1342. continue;
  1343. //--- Get Button code.
  1344. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1345. if(empty($aInput['attrs']['disabled']))
  1346. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  1347. $aParamsButtons = [
  1348. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1349. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1350. 'attrs' => bx_convert_array2attrs($aAttrs),
  1351. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  1352. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  1353. ];
  1354. $sUploadersButtons .= $oUploader->getUploaderButton($aParamsButtons);
  1355. //--- Get JS code.
  1356. $sGhostTemplate = $this->genGhostTemplate($aInput);
  1357. $aParamsJs = array_merge($oUploader->getUploaderJsParams(),
  1358. [
  1359. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1360. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1361. 'is_init_ghosts' => $bInitGhosts,
  1362. 'is_init_reordering' => $bInitReordering
  1363. ]
  1364. );
  1365. if(isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  1366. $aParamsJs['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  1367. $sUploadersJs .= $oUploader->getUploaderJs($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParamsJs, $this->_bDynamicMode);
  1368. }
  1369. if(!$oUploader)
  1370. return '';
  1371. if($bInitReordering) {
  1372. $this->addCssJsUi();
  1373. $this->addCssJsUiSortable();
  1374. }
  1375. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  1376. 'uploaders_buttons' => $sUploadersButtons,
  1377. 'info' => $sInfo,
  1378. 'error' => $sError,
  1379. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  1380. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  1381. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  1382. 'uploaders_js' => $sUploadersJs,
  1383. ));
  1384. }
  1385. protected function genGhostTemplate(&$aInput)
  1386. {
  1387. $sGhostTemplate = false;
  1388. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  1389. $oFormNested = $aInput['ghost_template'];
  1390. if ($oFormNested instanceof BxDolFormNestedGhost)
  1391. $sGhostTemplate = $oFormNested->genForm();
  1392. } 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
  1393. $oFormNested = new BxDolFormNestedGhost($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  1394. $sGhostTemplate = $oFormNested->getCode();
  1395. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  1396. $sGhostTemplate = array ();
  1397. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  1398. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNestedGhost)
  1399. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  1400. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  1401. $sGhostTemplate = $aInput['ghost_template'];
  1402. }
  1403. return $sGhostTemplate;
  1404. }
  1405. protected function genCustomInputUsernamesSuggestions ($aInput)
  1406. {
  1407. $bDisabled = isset($aInput['attrs']['disabled']) && $aInput['attrs']['disabled'] == 'disabled';
  1408. $aAttrs = $this->_genCustomInputUsernamesSuggestionsAttrs($aInput, $bDisabled);
  1409. $aTmplVarsVals = [];
  1410. $sValue = '';
  1411. if(!empty($aInput['value'])) {
  1412. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']) . 'Value';
  1413. if(method_exists($this, $sCustomMethod))
  1414. $aTmplVarsVals = $this->$sCustomMethod($aInput);
  1415. else if(is_array($aInput['value']) || (is_numeric($aInput['value']))) {
  1416. if (!is_array($aInput['value']))
  1417. $aInput['value'] = [$aInput['value']];
  1418. foreach($aInput['value'] as $sVal) {
  1419. if(!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  1420. continue;
  1421. $aTmplVarsVals[] = [
  1422. 'item_unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']]),
  1423. 'item_name' => $oProfile->getDisplayName(),
  1424. 'name' => $aInput['name'] . (isset($aInput['custom']['only_once']) && $aInput['custom']['only_once'] == 1 ? '' : '[]'),
  1425. 'value' => $sVal
  1426. ];
  1427. }
  1428. }
  1429. else if(is_string($aInput['value']))
  1430. $sValue = $aInput['value'];
  1431. }
  1432. $aTmplVarsInputText = [];
  1433. if(!$bDisabled) {
  1434. $aInputText = $aInput;
  1435. $aInputText['type'] = 'text';
  1436. $aInputText['value'] = '';
  1437. $aInputText['attrs'] = $this->_genCustomInputUsernamesSuggestionsTextAttrs($aInputText, $bDisabled);
  1438. unset($aInputText['name']);
  1439. $aTmplVarsInputText['input'] = $this->genInputStandard($aInputText);
  1440. }
  1441. if (bx_is_api()){
  1442. $aInput['type'] = 'initial_members';
  1443. return $aInput;
  1444. }
  1445. $this->addCssJsUi();
  1446. $sJsCode = '';
  1447. if(!$bDisabled) {
  1448. $sJsCode = $this->oTemplate->parseHtmlByName('form_field_custom_suggestions_js.html', [
  1449. 'id' => $aAttrs['id'],
  1450. 'name' => $aInput['name'],
  1451. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  1452. 'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
  1453. 'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
  1454. 'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
  1455. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  1456. ]);
  1457. if($this->_bDynamicMode)
  1458. $sJsCode = $this->oTemplate->addJsPreloadedWrapped([
  1459. 'jquery-ui/jquery-ui.min.js'
  1460. ], $sJsCode);
  1461. else
  1462. $sJsCode = $this->oTemplate->addJsCodeOnLoadWrapped($sJsCode);
  1463. }
  1464. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  1465. 'name' => $aInput['name'],
  1466. 'attrs' => bx_convert_array2attrs($aAttrs),
  1467. 'bx_repeat:vals' => $aTmplVarsVals,
  1468. 'value' => $sValue,
  1469. 'bx_if:input' => array(
  1470. 'condition' => !$bDisabled,
  1471. 'content' => $aTmplVarsInputText
  1472. ),
  1473. 'js_code' => $sJsCode
  1474. ));
  1475. }
  1476. protected function _genCustomInputUsernamesSuggestionsAttrs (&$aInput, $bDisabled = false)
  1477. {
  1478. $aAttrs = ['id' => $aInput['name'] . time() . mt_rand(0, 100)];
  1479. $aAttrs['class'] = 'bx-form-input-autotoken bx-form-input-text bx-def-font-inputs';
  1480. if($bDisabled)
  1481. $aAttrs['class'] .= ' bx-form-input-disabled';
  1482. if(!empty($aInput['attrs']['class']))
  1483. $aAttrs['class'] .= ' ' . $aInput['attrs']['class'];
  1484. return $aAttrs;
  1485. }
  1486. protected function _genCustomInputUsernamesSuggestionsTextAttrs (&$aInput, $bDisabled = false)
  1487. {
  1488. $aAttrs = ['value' => '', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'autocorrect' => 'off'];
  1489. if(!empty($aInput['attrs']) && is_array($aInput['attrs'])) {
  1490. if(isset($aInput['attrs']['class']))
  1491. unset($aInput['attrs']['class']);
  1492. $aAttrs = array_merge($aAttrs, $aInput['attrs']);
  1493. }
  1494. return $aAttrs;
  1495. }
  1496. protected function genCustomViewRowValueLabels ($aInput)
  1497. {
  1498. if (empty($aInput['value']) || !($oMetatags = BxDolMetatags::getObjectInstance($aInput['meta_object'])) || !$oMetatags->keywordsIsEnabled())
  1499. return null;
  1500. if (!empty($aInput['value']) && !is_array($aInput['value']))
  1501. $aInput['value'] = unserialize($aInput['value']);
  1502. $s = '';
  1503. foreach ($aInput['value'] as $sLabel)
  1504. $s .= '<a href="' . $oMetatags->keywordsGetHashTagUrl($sLabel, $aInput['content_id']) . '"><b class="bx-def-label val">' . trim($sLabel) . '</b></a>';
  1505. return $this->oTemplate->parseHtmlByName('form_field_labels_view.html', array(
  1506. 'values' => $s,
  1507. ));
  1508. }
  1509. protected function genCustomInputLabels (&$aInput)
  1510. {
  1511. $oLabel = BxDolLabel::getInstance();
  1512. $sName = !empty($aInput['name']) ? $aInput['name'] : 'labels';
  1513. $sValue = '';
  1514. if(!empty($aInput['value'])) {
  1515. if(!is_array($aInput['value']))
  1516. $aInput['value'] = unserialize($aInput['value']);
  1517. if(is_array($aInput['value']))
  1518. foreach($aInput['value'] as $sLabel)
  1519. $sValue .= $oLabel->getLabel($sName, $sLabel);
  1520. }
  1521. $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
  1522. if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
  1523. $sValue .= $oLabel->getLabelPlaceholder($sKeyPlaceholder);
  1524. $aInputLabels = array(
  1525. 'type' => 'custom',
  1526. 'name' => $sName,
  1527. 'caption' => '',
  1528. 'value' => $sValue,
  1529. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('label.php', array(
  1530. 'action' => 'labels_list',
  1531. )),
  1532. 'attrs' => array(
  1533. 'class' => 'bx-form-input-labels',
  1534. 'disabled' => 'disabled'
  1535. )
  1536. );
  1537. if (bx_is_api()){
  1538. $aInput['type'] = 'labels';
  1539. //$aInput['ajax_get_suggestions'] = 'system/select_labels/TemplLabelsServices&params[]=';
  1540. $aInput['values'] = bx_srv('system', 'get_labels', [], 'TemplLabelsServices');
  1541. }
  1542. return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
  1543. 'js_object' => $oLabel->getJsObjectName(),
  1544. 'js_code' => $oLabel->getJsCodeForm(),
  1545. 'html_id' => $oLabel->getFormFieldId($aInput),
  1546. 'name' => $sName,
  1547. 'input_labels' => $this->genCustomInputUsernamesSuggestions($aInputLabels)
  1548. ));
  1549. }
  1550. /**
  1551. * Generate Select Element
  1552. *
  1553. * @param array $aInput
  1554. * @return string
  1555. */
  1556. function genInputSelect(&$aInput)
  1557. {
  1558. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1559. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1560. }
  1561. /**
  1562. * Generate Select RGB Element
  1563. *
  1564. * @param array $aInput
  1565. * @return string
  1566. */
  1567. function genInputSelectRgb(&$aInput)
  1568. {
  1569. $aInput['type'] = 'select';
  1570. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1571. $aInput['values_list_name'] = 'sys_colors';
  1572. $aInput['values'] = self::getDataItems('sys_colors', isset(self::$TYPES_SET[$aInput['type']]));
  1573. $aInput['attrs'] = ['class' => 'bx-form-input-rgb-list'];
  1574. foreach ($aInput['values'] as $sOptValue => $sOptTitle) {
  1575. $aInput['values'][$sOptValue] = ['key' => $sOptValue, 'value' => $sOptTitle, 'class' => 'bg-' . $sOptValue, 'style' => 'color:#fff'];
  1576. }
  1577. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1578. }
  1579. /**
  1580. * Generate Multiple Select Element
  1581. *
  1582. * @param array $aInput
  1583. * @return string
  1584. */
  1585. function genInputSelectMultiple(&$aInput)
  1586. {
  1587. $aCurValues = array();
  1588. if (isset($aInput['value']) && $aInput['value'])
  1589. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1590. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  1591. }
  1592. /**
  1593. * Generate Checkbox Set Element
  1594. *
  1595. * @param array $aInput
  1596. * @return string
  1597. */
  1598. function genInputCheckboxSet(&$aInput)
  1599. {
  1600. $aCurValues = array();
  1601. if (isset($aInput['value']) && $aInput['value'])
  1602. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1603. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  1604. }
  1605. /**
  1606. * Generate Radiobuttons Set Element
  1607. *
  1608. * @param array $aInput
  1609. * @return string
  1610. */
  1611. function genInputRadioSet(&$aInput)
  1612. {
  1613. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1614. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  1615. }
  1616. function _isSelected ($sValue, $sCurValue)
  1617. {
  1618. return ((string)$sValue === (string)$sCurValue);
  1619. }
  1620. function _isSelectedMultiple ($sValue, $aCurValues)
  1621. {
  1622. return in_array($sValue, $aCurValues);
  1623. }
  1624. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  1625. {
  1626. $aOptions = [];
  1627. if(isset($aInput['values']) && is_array($aInput['values'])) {
  1628. foreach ($aInput['values'] as $sOptValue => $sOptTitle) {
  1629. $aOption = array(
  1630. 'bx_if:show_option_group_begin' => [
  1631. 'condition' => false,
  1632. 'content' => []
  1633. ],
  1634. 'bx_if:show_option_group_end' => [
  1635. 'condition' => false,
  1636. 'content' => []
  1637. ],
  1638. 'bx_if:show_option' => [
  1639. 'condition' => false,
  1640. 'content' => []
  1641. ]
  1642. );
  1643. $sOptAttrs = "";
  1644. if(is_array($sOptTitle)) {
  1645. if(isset($sOptTitle['type'])) {
  1646. switch($sOptTitle['type']) {
  1647. case 'group_header':
  1648. $aOption = array_merge($aOption, [
  1649. 'bx_if:show_option_group_begin' => [
  1650. 'condition' => true,
  1651. 'content' => [
  1652. 'opt_label' => bx_process_output($sOptTitle['value'])
  1653. ]
  1654. ]
  1655. ]);
  1656. $aOptions[] = $aOption;
  1657. break;
  1658. case 'group_end':
  1659. $aOption = array_merge($aOption, [
  1660. 'bx_if:show_option_group_end' => [
  1661. 'condition' => true,
  1662. 'content' => []
  1663. ]
  1664. ]);
  1665. $aOptions[] = $aOption;
  1666. break;
  1667. }
  1668. continue;
  1669. }
  1670. $aOptAttrs = $this->_genInputSelectOptionAttrs($sOptTitle);
  1671. if(!empty($aOptAttrs))
  1672. $sOptAttrs = bx_convert_array2attrs($aOptAttrs);
  1673. $sOptValue = $sOptTitle['key'];
  1674. $sOptTitle = $sOptTitle['value'];
  1675. }
  1676. $aOption = array_merge($aOption, [
  1677. 'bx_if:show_option' => [
  1678. 'condition' => true,
  1679. 'content' => [
  1680. 'opt_title' => bx_process_output($sOptTitle),
  1681. 'opt_value' => !empty($sOptValue) ? bx_html_attribute($sOptValue) : '',
  1682. 'opt_attrs' => $sOptAttrs,
  1683. 'bx_if:show_selected' => [
  1684. 'condition' => $this->$sIsSelectedFunc($sOptValue, $mixedCurrentVal),
  1685. 'content' => []
  1686. ]
  1687. ]
  1688. ]
  1689. ]);
  1690. $aOptions[] = $aOption;
  1691. }
  1692. }
  1693. $aAttrs = $this->_genInputSelectAttrs($aInput, $isMultiple);
  1694. return $this->_parseInputSelect('form_field_select.html', [
  1695. 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}"),
  1696. 'bx_repeat:options' => $aOptions,
  1697. 'content' => !empty($aInput['content']) ? $aInput['content'] : ''
  1698. ]);
  1699. }
  1700. protected function _genInputSelectAttrs(&$aInput, $isMultiple)
  1701. {
  1702. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : [];
  1703. $aAttrs['name'] = $aInput['name'];
  1704. if ($isMultiple) {
  1705. $aAttrs['name'] .= '[]';
  1706. $aAttrs['multiple'] = 'multiple';
  1707. }
  1708. // for inputs with labels generate id
  1709. if (isset($aInput['label']))
  1710. $aAttrs['id'] = $this->getInputId($aInput);
  1711. return $aAttrs;
  1712. }
  1713. protected function _genInputSelectOptionAttrs(&$aOption)
  1714. {
  1715. $aAttrs = [];
  1716. if(!empty($aOption['attrs']) && is_array($aOption['attrs']))
  1717. $aAttrs = $aOption['attrs'];
  1718. if(isset($aOption['class']))
  1719. $aAttrs['class'] = !empty($aAttrs['class']) ? $aAttrs['class'] . ' ' . $aOption['class'] : $aOption['class'];
  1720. if(isset($aOption['style']))
  1721. $aAttrs['style'] = !empty($aAttrs['style']) ? $aAttrs['style'] . ' ' . $aOption['style'] : $aOption['style'];
  1722. return $aAttrs;
  1723. }
  1724. protected function _parseInputSelect($sTmplName, $aTmplVars)
  1725. {
  1726. return $this->oTemplate->parseHtmlByName($sTmplName, $aTmplVars);
  1727. }
  1728. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  1729. {
  1730. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  1731. $aAttrs['name'] = $aInput['name'];
  1732. // for inputs with labels generate id
  1733. if (isset($aInput['label']))
  1734. $aAttrs['id'] = $this->getInputId($aInput);
  1735. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1736. // generate options
  1737. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  1738. $iDividerThreshold = !empty($aInput['dv_thd']) ? (int)$aInput['dv_thd'] : 3;
  1739. $sOptions = '';
  1740. $aAdditionalFieldInfo = [];
  1741. if (in_array($aInput['type'], ['radio_set', 'checkbox_set']) && !empty($aInput['values_list_name']))
  1742. $aAdditionalFieldInfo = BxDolFormQuery::getDataItems($aInput['values_list_name'], false, BX_DATA_VALUES_ALL);
  1743. if (isset($aInput['values']) && is_array($aInput['values'])) {
  1744. if (count($aInput['values']) > $iDividerThreshold && $sDivider == $this->_sDivider)
  1745. $sDivider = $this->_sDividerAlt;
  1746. // generate complex input using simple standard inputs
  1747. foreach ($aInput['values'] as $sValue => $sLabel) {
  1748. if(is_array($sLabel)) {
  1749. $sValue = $sLabel['key'];
  1750. $sLabel = $sLabel['value'];
  1751. }
  1752. // create new simple input
  1753. $aNewInput = array(
  1754. 'type' => $sType,
  1755. 'name' => $aInput['name'] . $sNameAppend,
  1756. 'value' => $sValue,
  1757. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  1758. 'label' => $sLabel,
  1759. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  1760. );
  1761. if (isset($aInput['label_as_html']))
  1762. $aNewInput['label_as_html'] = $aInput['label_as_html'];
  1763. $sNewInput = $this->genInput($aNewInput);
  1764. // add additional info for the field
  1765. if (isset($aAdditionalFieldInfo[$sValue]) && !empty($aAdditionalFieldInfo[$sValue]['LKey2']))
  1766. $sNewInput = $this->genFiledItemInfoWrapper($sNewInput, _t($aAdditionalFieldInfo[$sValue]['LKey2']));
  1767. // attach new input to complex
  1768. $sOptions .= ($sNewInput . $sDivider);
  1769. }
  1770. }
  1771. // generate element
  1772. $sCode = <<<BLAH
  1773. <div $sAttrs>
  1774. $sOptions
  1775. </div>
  1776. BLAH;
  1777. return $sCode;
  1778. }
  1779. function genInputLocation(&$aInput)
  1780. {
  1781. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1782. if (!$o)
  1783. return _t('_sys_txt_error_occured');
  1784. return $o->genInputLocation($aInput, $this);
  1785. }
  1786. public function setLocationVals ($aInput, $aVals)
  1787. {
  1788. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1789. if (!$o)
  1790. return false;
  1791. return $o->setLocationVals ($aInput, $aVals, $this);
  1792. }
  1793. public function setLocationVal ($aInput, $sIndex, $sVal)
  1794. {
  1795. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1796. if (!$o)
  1797. return false;
  1798. return $o->setLocationVal ($aInput, $sIndex, $sVal, $this);
  1799. }
  1800. protected function getLocationVal ($aInput, $sIndex)
  1801. {
  1802. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1803. if (!$o)
  1804. return false;
  1805. return $o->getLocationVal ($aInput, $sIndex, $this);
  1806. }
  1807. function genInputPassword(&$aInput)
  1808. {
  1809. return $this->oTemplate->parseHtmlByName('form_field_password.html', array('input' => $this->genInputStandard($aInput)));
  1810. }
  1811. function genInputPrice(&$aInput)
  1812. {
  1813. $sCurrency = '';
  1814. if(!isset($aInput['value_currency'])) {
  1815. $sCurrency = BxDolPayments::getInstance()->getOption('default_currency_code');
  1816. if(empty($sCurrency))
  1817. $sCurrency = getParam('currency_code');
  1818. }
  1819. else
  1820. $sCurrency = $aInput['value_currency'];
  1821. return $this->oTemplate->parseHtmlByName('form_field_price.html', array(
  1822. 'bx_if:show_currency' => [
  1823. 'condition' => !empty($sCurrency),
  1824. 'content' => [
  1825. 'currency' => $sCurrency,
  1826. ]
  1827. ],
  1828. 'input' => $this->genInputStandard($aInput)
  1829. ));
  1830. }
  1831. function genInputNestedForm(&$aInput)
  1832. {
  1833. return '';
  1834. }
  1835. function genNestedForm(&$aInput)
  1836. {
  1837. return '';
  1838. }
  1839. function genInputCaptcha(&$aInput)
  1840. {
  1841. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1842. // for inputs with labels generate id
  1843. if (isset($aInput['label']))
  1844. $aAttrs['id'] = $this->getInputId($aInput);
  1845. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1846. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1847. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1848. }
  1849. /**
  1850. * Generate Label Element
  1851. *
  1852. * @param string $aInput input array
  1853. * @return string HTML code
  1854. */
  1855. function genLabel(&$aInput)
  1856. {
  1857. if (!isset($aInput['label']) || empty($aInput['label']))
  1858. return '';
  1859. $sInputID = $this->getInputId($aInput);
  1860. $sLabel = bx_process_output($aInput['label']);
  1861. if (isset($aInput['label_as_html']) && $aInput['label_as_html'] == true)
  1862. $sLabel = $aInput['label'];
  1863. return '<label for="' . $sInputID . '">' . $sLabel . '</label>';
  1864. }
  1865. function genPrivacyGroupChooser(&$aInput, $sPrivacyObject = '')
  1866. {
  1867. if(!isset($aInput['privacy']) || empty($aInput['privacy']))
  1868. return '';
  1869. $iAuthorId = bx_get_logged_profile_id();
  1870. $mixedResult = checkActionModule($iAuthorId, 'set form fields privacy', 'system');
  1871. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1872. return '';
  1873. if(empty($sPrivacyObject))
  1874. $sPrivacyObject = $this->_sPrivacyObjectView;
  1875. $iInputId = (int)$aInput['id'];
  1876. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  1877. if(!isset($aInput['attrs_wrapper']['class']))
  1878. $aInput['attrs_wrapper']['class'] = '';
  1879. $aInput['attrs_wrapper']['class'] .= ' bx-form-input-wrapper-pgc';
  1880. return $this->oTemplate->parseHtmlByName('form_field_privacy.html', array(
  1881. 'js_object' => $this->getJsObjectName(),
  1882. 'html_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  1883. 'id' => $iInputId,
  1884. 'privacy_object' => $sPrivacyObject,
  1885. 'icon' => $this->_getPrivacyIcon($mixedPrivacyGroup)
  1886. ));
  1887. }
  1888. function genFiledItemInfoWrapper($sInput, $sInfoValue)
  1889. {
  1890. $sInfo = $this->genInfoIcon($sInfoValue) ;
  1891. return $this->oTemplate->parseHtmlByName('form_field_option_info.html', [
  1892. 'input' => $sInput,
  1893. 'info' => $sInfo
  1894. ]);
  1895. }
  1896. function genInfoIcon($sInfo)
  1897. {
  1898. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1899. }
  1900. function genErrorIcon( $sError = '' )
  1901. {
  1902. if ($this->bEnableErrorIcon) {
  1903. $sStyle = '';
  1904. if (!$sError)
  1905. $sStyle = 'style="display:none;"';
  1906. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1907. }
  1908. }
  1909. function getOpenSection($aAttrs = [], $sTitle = '', $aWrapperAttrs = [])
  1910. {
  1911. $sClose = '';
  1912. if($this->_isSectionOpened)
  1913. $sClose = $this->{$this->_sSectionClose}();
  1914. $sWrapperAttrs = bx_convert_array2attrs($aWrapperAttrs, "bx-form-section-wrapper my-4");
  1915. if(!$aAttrs || !is_array($aAttrs))
  1916. $aAttrs = [];
  1917. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-section-" . ($sTitle ? "header" : "divider") . " p-4 border rounded-lg");
  1918. $this->_isSectionOpened = true;
  1919. return $sClose . "<!-- form header content begins -->\n <div $sWrapperAttrs> <div $sAttrs> $sTitle <div class=\"bx-form-section-content py-4" . ($sTitle ? ' px-4' : '') . "\">\n";
  1920. }
  1921. function getCloseSection()
  1922. {
  1923. if(!$this->_isSectionOpened)
  1924. return '';
  1925. $this->_isSectionOpened = false;
  1926. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1927. }
  1928. function getOpenSectionViewMode($aAttrs = array(), $sTitle = '', $aWrapperAttrs = [])
  1929. {
  1930. if (!$this->_isSectionOpened) {
  1931. if (!$aAttrs || !is_array($aAttrs))
  1932. $aAttrs = array();
  1933. if ($sTitle)
  1934. $sClassesAdd = "bx-form-section-header";
  1935. else
  1936. $sClassesAdd = "bx-form-section-divider";
  1937. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1938. $sWrapperAttrs = bx_convert_array2attrs($aWrapperAttrs, "bx-form-section-wrapper bx-def-margin-top");
  1939. $this->_isSectionOpened = true;
  1940. return "<!-- form header content begins -->\n <div $sWrapperAttrs> <div $sAttrs> $sTitle <div class=\"bx-form-section-content bx-def-padding-top\">\n";
  1941. } else {
  1942. return '';
  1943. }
  1944. }
  1945. function getCloseSectionViewMode()
  1946. {
  1947. if ($this->_isSectionOpened) {
  1948. $this->_isSectionOpened = false;
  1949. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1950. } else {
  1951. return '';
  1952. }
  1953. }
  1954. public static function getJsCalendarLangs ()
  1955. {
  1956. 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);
  1957. }
  1958. public static function getCssJsCalendar()
  1959. {
  1960. $aLangs = self::getJsCalendarLangs();
  1961. $sLang = BxDolLanguages::getInstance()->detectLanguageFromArray($aLangs);
  1962. return [[
  1963. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flatpickr/dist/|flatpickr.min.css'
  1964. ], [
  1965. 'flatpickr/dist/flatpickr.min.js',
  1966. 'flatpickr/dist/l10n/' . $sLang . '.js',
  1967. ]
  1968. ];
  1969. }
  1970. function addCssJsUi ()
  1971. {
  1972. if (self::$_isCssJsUiAdded)
  1973. return;
  1974. $this->_addJs(array(
  1975. 'jquery-ui/jquery-ui.min.js',
  1976. ), "'undefined' === typeof(jQuery.ui.position)");
  1977. $this->_addCss('jquery-ui/jquery-ui.min.css');
  1978. self::$_isCssJsUiAdded = true;
  1979. }
  1980. function addCssJsUiSortable ()
  1981. {
  1982. if (self::$_isCssJsUiSortableAdded)
  1983. return;
  1984. $this->_addJs(array(
  1985. 'jquery-ui/jquery-ui.min.js'
  1986. ), "'undefined' === typeof(jQuery.ui.position)");
  1987. self::$_isCssJsUiSortableAdded = true;
  1988. }
  1989. function addCssJsTimepicker ()
  1990. {
  1991. if (self::$_isCssJsTimepickerAdded)
  1992. return;
  1993. list($aCss, $aJs) = self::getCssJsCalendar();
  1994. $this->_addCss($aCss);
  1995. $this->_addJs($aJs, "'undefined' === typeof(flatpickr)");
  1996. self::$_isCssJsTimepickerAdded = true;
  1997. }
  1998. function addCssJsMinicolors ()
  1999. {
  2000. if (self::$_isCssJsMinicolorsAdded)
  2001. return;
  2002. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  2003. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  2004. self::$_isCssJsMinicolorsAdded = true;
  2005. }
  2006. function addCssJsViewMode ()
  2007. {
  2008. if (self::$_isCssJsAddedViewMode)
  2009. return;
  2010. $this->_addCss('forms.css');
  2011. self::$_isCssJsAddedViewMode = true;
  2012. }
  2013. function addCssJsCore ()
  2014. {
  2015. if (self::$_isCssJsAdded)
  2016. return;
  2017. $this->_addCss('forms.css');
  2018. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  2019. $this->_addJs(array('BxDolForm.js', 'BxDolNestedForm.js'), "true");
  2020. self::$_isCssJsAdded = true;
  2021. }
  2022. function addCssJs ()
  2023. {
  2024. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  2025. $this->addCssJsViewMode ();
  2026. } else {
  2027. $this->addCssJsCore();
  2028. }
  2029. }
  2030. protected function _processCssJs()
  2031. {
  2032. $sRet = '';
  2033. if ($this->_bDynamicMode) {
  2034. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  2035. $sRet .= "\n<script>\n";
  2036. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  2037. foreach ($this->_aJs as $sCondition => $aJs) {
  2038. $sJs = $this->oTemplate->addJs($aJs, true);
  2039. if (!$sJs)
  2040. continue;
  2041. $sRet .= "if ($sCondition)\n";
  2042. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  2043. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  2044. }
  2045. $sRet .= "\n</script>\n";
  2046. }
  2047. else {
  2048. $this->oTemplate->addCss($this->_aCss);
  2049. $aJs = array();
  2050. foreach ($this->_aJs as $sCondition => $a)
  2051. $aJs = array_merge($aJs, $a);
  2052. $this->oTemplate->addJs($aJs);
  2053. }
  2054. return $sRet;
  2055. }
  2056. protected function _addJs($mixed, $sJsCondition)
  2057. {
  2058. if (!is_array($mixed))
  2059. $mixed = array($mixed);
  2060. $this->_aJs[$sJsCondition] = $mixed;
  2061. }
  2062. protected function _addCss($mixed)
  2063. {
  2064. if (!is_array($mixed))
  2065. $mixed = array($mixed);
  2066. foreach ($mixed as $s)
  2067. $this->_aCss[$s] = $s;
  2068. }
  2069. }
  2070. /** @} */