BxBaseFormView.php 85 KB

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