BxBaseFormView.php 86 KB

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