BxBaseFormView.php 91 KB

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