BxBaseFormView.php 85 KB

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