BxBaseFormView.php 88 KB

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