BxBaseFormView.php 86 KB

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