BxBaseFormView.php 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062
  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 $_isCssJsMinicolorsAdded = false;
  15. protected static $_isCssJsLabelsAdded = false;
  16. protected static $_isCssJsTimepickerAdded = false;
  17. protected static $_isCssJsAddedViewMode = false;
  18. /**
  19. * Enable or disable error message displaying
  20. */
  21. protected $bEnableErrorIcon = true;
  22. /**
  23. * HTML Code of this form
  24. */
  25. protected $sCode;
  26. /**
  27. * Code which will be added to the beginning of the form.
  28. * For example, hidden inputs.
  29. * For internal use only
  30. */
  31. protected $_sCodeAdd = '';
  32. /**
  33. * for internal use only
  34. */
  35. protected $_isSectionOpened = false;
  36. /**
  37. * Default divider for several inputs
  38. */
  39. protected $_sDivider = '<span class="bx-def-margin-left"></span>';
  40. /**
  41. * Alternative divider for several inputs
  42. */
  43. protected $_sDividerAlt = '<br />';
  44. /**
  45. * Form is added dynamically.
  46. */
  47. protected $_bDynamicMode = false;
  48. /**
  49. * Form is submitted dynamically (using Ajax Submit).
  50. */
  51. protected $_bAjaxMode = false;
  52. /**
  53. * Use absolute Action URL which is needed in Ajax Mode.
  54. */
  55. protected $_bAbsoluteActionUrl = false;
  56. /**
  57. * Form is displayed in view mode.
  58. */
  59. protected $_bViewMode = false;
  60. /**
  61. * Show or not sections which have no fileds
  62. */
  63. protected $_bShowEmptySections = false;
  64. /**
  65. * Function name for generation close form section HTML.
  66. */
  67. protected $_sSectionClose = 'getCloseSection';
  68. /**
  69. * Function name for generation open form section HTML.
  70. */
  71. protected $_sSectionOpen = 'getOpenSection';
  72. /**
  73. * JS files list for form
  74. */
  75. protected $_aJs = array();
  76. /**
  77. * CSS files list for form
  78. */
  79. protected $_aCss = array();
  80. protected $_sJsClassName;
  81. protected $_sJsObjectName;
  82. protected $_aHtmlIds;
  83. /**
  84. * Constructor
  85. *
  86. * @param array $aInfo Form contents
  87. *
  88. * $aInfo['params'] = array(
  89. * 'remove_form' => true|false,
  90. * );
  91. *
  92. * @return BxBaseFormView
  93. */
  94. function __construct($aInfo, $oTemplate)
  95. {
  96. parent::__construct($aInfo, $oTemplate);
  97. $this->_bAjaxMode = isset($this->aParams['ajax_mode']) && $this->aParams['ajax_mode'];
  98. $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode'];
  99. if($this->_bViewMode) {
  100. $this->_sSectionClose = 'getCloseSectionViewMode';
  101. $this->_sSectionOpen = 'getOpenSectionViewMode';
  102. }
  103. $this->_sJsClassName = 'BxDolForm';
  104. $sName = !empty($aInfo['params']['display']) ? $aInfo['params']['display'] : '';
  105. if(empty($sName) && !empty($aInfo['params']['object']))
  106. $sName = $aInfo['params']['object'];
  107. $this->_sJsObjectName = 'oForm' . bx_gen_method_name($sName, array('_' , '-'));
  108. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sName);
  109. $this->_aHtmlIds = array(
  110. 'pgc' => $sHtmlId . '-pgc-',
  111. 'pgc_popup' => $sHtmlId . '-pgc-popup-',
  112. 'pgc_form' => $sHtmlId . '-pgc-form-',
  113. );
  114. }
  115. public function performActionChangePrivacyGroup()
  116. {
  117. $iAuthorId = (int)bx_get_logged_profile_id();
  118. if(empty($iAuthorId))
  119. return echoJson(array());
  120. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  121. if(empty($iInputId))
  122. return echoJson(array());
  123. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  124. $sPrivacyField = BxDolPrivacy::getFieldName($sPrivacyObject);
  125. if(empty($sPrivacyField))
  126. return echoJson(array());
  127. $sPrivacyGroup = bx_process_input(bx_get($sPrivacyField));
  128. if(empty($sPrivacyField))
  129. return echoJson(array());
  130. if(!BxDolFormQuery::setInputPrivacy($iInputId, $iAuthorId, $sPrivacyField, $sPrivacyGroup))
  131. return echoJson(array());
  132. return echoJson(array(
  133. 'code' => 0,
  134. 'form_id' => $this->getId(),
  135. 'chooser_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  136. 'icon' => $this->_getPrivacyIcon($sPrivacyGroup),
  137. 'eval' => $this->getJsObjectName() . '.pgcOnSelectGroup(oData);'
  138. ));
  139. }
  140. public function performActionGetPrivacyGroupChooser()
  141. {
  142. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  143. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  144. if(empty($iInputId) || empty($sPrivacyObject))
  145. return '';
  146. $sFormId = $this->_aHtmlIds['pgc_form'] . $iInputId;
  147. $aFormActionParams = array();
  148. if(!empty($this->aParams['object']) && !empty($this->aParams['display']))
  149. $aFormActionParams = array(
  150. 'o' => $this->aParams['object'],
  151. 'd' => $this->aParams['display']
  152. );
  153. $aFormActionParams['a'] = 'change_privacy_group';
  154. $iAuthorId = bx_get_logged_profile_id();
  155. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  156. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  157. $aInputPgc = $oPrivacy->getGroupChooser($sPrivacyObject, $iAuthorId);
  158. $aInputPgc['value'] = $mixedPrivacyGroup;
  159. if(!isset($aInputPgc['content']))
  160. $aInputPgc['content'] = '';
  161. $aInputPgc['content'] .= $oPrivacy->addCssJs(true);
  162. $aInputPgc['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iAuthorId, array(
  163. 'content_id' => $iInputId,
  164. 'group_id' => $mixedPrivacyGroup,
  165. 'html_ids' => array(
  166. 'form' => $sFormId
  167. )
  168. ));
  169. $aFormInfo = array(
  170. 'form_attrs' => array(
  171. 'id' => $sFormId,
  172. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('form.php', $aFormActionParams),
  173. 'method' => 'post'
  174. ),
  175. 'inputs' => array (
  176. 'input_id' => array(
  177. 'type' => 'hidden',
  178. 'name' => 'input_id',
  179. 'value' => $iInputId,
  180. 'db' => array (
  181. 'pass' => 'Int',
  182. ),
  183. ),
  184. 'privacy_object' => array(
  185. 'type' => 'hidden',
  186. 'name' => 'privacy_object',
  187. 'value' => $sPrivacyObject,
  188. 'db' => array (
  189. 'pass' => 'Xss',
  190. ),
  191. ),
  192. 'privacy_group_chooser' => $aInputPgc,
  193. 'controls' => array(
  194. 'name' => 'controls',
  195. 'type' => 'input_set',
  196. array(
  197. 'type' => 'button',
  198. 'name' => 'do_submit',
  199. 'value' => _t('_sys_submit'),
  200. 'attrs' => array(
  201. 'onclick' => "$('#" . $sFormId . "').submit()",
  202. ),
  203. ),
  204. array (
  205. 'type' => 'reset',
  206. 'name' => 'do_cancel',
  207. 'value' => _t('_Cancel'),
  208. 'attrs' => array(
  209. 'onclick' => "$(this).parents('.bx-popup-applied:visible:first').dolPopupHide()",
  210. 'class' => 'bx-def-margin-sec-left',
  211. ),
  212. )
  213. )
  214. )
  215. );
  216. $oForm = new BxTemplFormView($aFormInfo);
  217. echo $this->oTemplate->parseHtmlByName('form_field_privacy_popup.html', array(
  218. 'form_id' => $oForm->getId(),
  219. 'form' => $oForm->getCode(true),
  220. ));
  221. }
  222. function setShowEmptySections($b)
  223. {
  224. $this->_bShowEmptySections = $b;
  225. }
  226. function setAjaxMode($bAjaxMode)
  227. {
  228. $this->_bAjaxMode = (bool)$bAjaxMode;
  229. }
  230. function isAjaxMode()
  231. {
  232. return $this->_bAjaxMode;
  233. }
  234. function setAbsoluteActionUrl($sUrl)
  235. {
  236. if(empty($sUrl))
  237. return;
  238. $this->aFormAttrs['action'] = $sUrl;
  239. $this->_bAbsoluteActionUrl = true;
  240. }
  241. /**
  242. * Return Form code
  243. * @param $bDynamicMode - set it to true if form is added via JS/AJAX call, for example form in AJAX popup.
  244. * @return string
  245. */
  246. function getCode($bDynamicMode = false)
  247. {
  248. if(!$bDynamicMode && bx_is_dynamic_request())
  249. $bDynamicMode = true;
  250. $this->_bDynamicMode = $bDynamicMode;
  251. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  252. $sInclude = '';
  253. $this->sCode = false;
  254. bx_alert('system', 'form_output', 0, 0, array(
  255. 'dynamic' => $this->_bDynamicMode,
  256. 'object' => &$this,
  257. 'code' => &$this->sCode,
  258. 'include' => &$sInclude
  259. ));
  260. if($this->sCode === false)
  261. $this->sCode = $this->genForm();
  262. $this->addCssJs();
  263. $sDynamicCssJs = $this->_processCssJs();
  264. return $sInclude . $sDynamicCssJs . $this->sCode;
  265. }
  266. public function getJsClassName()
  267. {
  268. return $this->_sJsClassName;
  269. }
  270. public function getJsObjectName()
  271. {
  272. return $this->_sJsObjectName;
  273. }
  274. public function getJsScript($bWrap = false)
  275. {
  276. $sJsObjName = $this->getJsObjectName();
  277. $sJsObjClass = $this->getJsClassName();
  278. $sCode = "if(window['" . $sJsObjName . "'] == undefined) var " . $sJsObjName . " = new " . $sJsObjClass . "(" . json_encode(array(
  279. 'sObjName' => $sJsObjName,
  280. 'sObject' => isset($this->aParams['object']) ? $this->aParams['object'] : '',
  281. 'sDisplay' => isset($this->aParams['display']) ? $this->aParams['display'] : '',
  282. 'sRootUrl' => BX_DOL_URL_ROOT,
  283. 'aHtmlIds' => array(
  284. 'pgc_popup' => 'bx-form-input-pgc-popup'
  285. ),
  286. )) . ");";
  287. return $bWrap ? $this->oTemplate->_wrapInTagJsCode($sCode) : $sCode;
  288. }
  289. /**
  290. * Generate the whole form
  291. *
  292. * @return string
  293. */
  294. function genForm()
  295. {
  296. $this->_sCodeAdd = '';
  297. $sTable = $this->genRows();
  298. $sHtmlBefore = isset($this->aParams['html_before']) ? $this->aParams['html_before'] : '';
  299. $sHtmlAfter = isset($this->aParams['html_after']) ? $this->aParams['html_after'] : '';
  300. if (!empty($this->aParams['remove_form']) || (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])) {
  301. $sForm = <<<BLAH
  302. $sHtmlBefore
  303. {$this->_sCodeAdd}
  304. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  305. $sTable
  306. </div>
  307. $sHtmlAfter
  308. BLAH;
  309. } else {
  310. $sFormAttrs = bx_convert_array2attrs($this->aFormAttrs, 'bx-form-advanced');
  311. $sAjaxFormJs = '';
  312. if($this->_bAjaxMode)
  313. $sAjaxFormJs = <<<BLAH
  314. $("form#{$this->id}").ajaxForm({
  315. dataType: "json",
  316. beforeSubmit: function (formData, jqForm, options) {
  317. bx_loading($("form#{$this->id}"), true);
  318. },
  319. success: function (oData) {
  320. bx_loading($("form#{$this->id}"), false);
  321. processJsonData(oData);
  322. }
  323. });
  324. BLAH;
  325. $sJsCodeDynamic = '';
  326. if($this->_bDynamicMode)
  327. $sJsCodeDynamic = 'function() {' . $this->getJsScript() . '}';
  328. $sForm = <<<BLAH
  329. $sHtmlBefore
  330. <form $sFormAttrs>
  331. {$this->_sCodeAdd}
  332. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  333. $sTable
  334. </div>
  335. </form>
  336. <script>
  337. $(document).ready(function() {
  338. $(this).addWebForms($sJsCodeDynamic);
  339. });
  340. $sAjaxFormJs
  341. </script>
  342. $sHtmlAfter
  343. BLAH;
  344. }
  345. if(!$this->_bDynamicMode)
  346. $sForm = $this->getJsScript(true) . $sForm;
  347. return $sForm;
  348. }
  349. /**
  350. * Generate Table HTML code
  351. *
  352. * @return string
  353. */
  354. function genRows()
  355. {
  356. // add CSRF token if it's needed.
  357. 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) {
  358. $this->aInputs['csrf_token'] = array(
  359. 'type' => 'hidden',
  360. 'name' => 'csrf_token',
  361. 'value' => $mixedCsrfToken,
  362. 'db' => array ('pass' => 'Xss'),
  363. 'visible_for_levels' => PHP_INT_MAX,
  364. );
  365. }
  366. // add 'Ajax Mode' flag
  367. if($this->_bAjaxMode)
  368. $this->aInputs['ajax_mode'] = array(
  369. 'type' => 'hidden',
  370. 'name' => 'ajax_mode',
  371. 'value' => 1,
  372. 'db' => array ('pass' => 'Int'),
  373. 'visible_for_levels' => PHP_INT_MAX,
  374. );
  375. // add 'Absolute Action Url' flag
  376. if($this->_bAbsoluteActionUrl)
  377. $this->aInputs['absolute_action_url'] = array(
  378. 'type' => 'hidden',
  379. 'name' => 'absolute_action_url',
  380. 'value' => 1,
  381. 'db' => array ('pass' => 'Int'),
  382. 'visible_for_levels' => PHP_INT_MAX,
  383. );
  384. // check if we need to generate open section clause
  385. $sOpenSection = '';
  386. foreach ($this->aInputs as $aInput) {
  387. if (isset($aInput['type']) && 'hidden' == $aInput['type'])
  388. continue;
  389. if (isset($aInput['type']) && 'block_header' != $aInput['type'])
  390. $sOpenSection = $this->{$this->_sSectionOpen}();
  391. break;
  392. }
  393. // generate rows contents
  394. $sCont = '';
  395. $sContHeader = '';
  396. $sContFields = '';
  397. $sFuncGenRow = isset($this->aParams['view_mode']) && $this->aParams['view_mode'] ? 'genViewRow' : 'genRow';
  398. foreach ($this->aInputs as $aInput) {
  399. if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) {
  400. if ('block_header' == $aInput['type'] && !$this->_bShowEmptySections) {
  401. // don't show section with no fields or with empty fields
  402. if ($sContHeader) {
  403. if ($sContFields)
  404. $sCont .= $sContHeader . $sContFields;
  405. else
  406. $sContHeader = '';
  407. $sContFields = '';
  408. }
  409. else {
  410. $sCont .= $sContFields;
  411. $sContFields = '';
  412. }
  413. $sContHeader = $this->$sFuncGenRow($aInput);
  414. } else {
  415. $sContFields .= $this->$sFuncGenRow($aInput);
  416. }
  417. }
  418. }
  419. $sCont .= $sContHeader . $sContFields;
  420. $sCloseSection = $this->{$this->_sSectionClose}();
  421. return $sOpenSection . $sCont . $sCloseSection;
  422. }
  423. /**
  424. * Generate single Table Row
  425. *
  426. * @param array $aInput
  427. * @return string
  428. */
  429. function genRow(&$aInput)
  430. {
  431. if (!isset($aInput['type']))
  432. $aInput['type'] = false;
  433. if (!empty($aInput['name'])) {
  434. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  435. if (method_exists($this, $sCustomMethod))
  436. return $this->$sCustomMethod($aInput);
  437. }
  438. switch ($aInput['type']) {
  439. case 'block_header':
  440. $sRow = $this->genRowBlockHeader($aInput);
  441. break;
  442. case 'block_end':
  443. $sRow = $this->genBlockEnd($aInput);
  444. break;
  445. case 'hidden':
  446. // do not generate row for hidden inputs
  447. $sRow = '';
  448. $this->_sCodeAdd .= $this->genInput($aInput);
  449. break;
  450. case 'select_box':
  451. $sRow = $this->genRowCustom($aInput, 'genInputSelectBox');
  452. break;
  453. case 'files':
  454. $sRow = $this->genRowCustom($aInput, 'genInputFiles');
  455. break;
  456. case 'switcher':
  457. case 'checkbox':
  458. $sRow = $this->genRowStandard($aInput, true);
  459. break;
  460. default:
  461. $sRow = $this->genRowStandard($aInput);
  462. }
  463. return $sRow;
  464. }
  465. public function isInputVisible($mixedInput)
  466. {
  467. if(!is_array($mixedInput) && isset($this->aInputs[$mixedInput]))
  468. $mixedInput = $this->aInputs[$mixedInput];
  469. if(empty($mixedInput) || !is_array($mixedInput))
  470. $mixedInput = BxDolFormQuery::getInputByName($this->aParams['object'], $mixedInput);
  471. if(empty($mixedInput) || !is_array($mixedInput))
  472. return false;
  473. if(!empty($mixedInput['privacy']) && !empty($this->_iAuthorId) && !$this->_isInputVisibleByPrivacy($mixedInput))
  474. return false;
  475. return true;
  476. }
  477. protected function _isInputVisibleByPrivacy($aInput)
  478. {
  479. $mixedResult = checkActionModule($this->_iAuthorId, 'set form fields privacy', 'system');
  480. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  481. return true;
  482. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  483. if(empty($aInputPrivacy) || !is_array($aInputPrivacy))
  484. if(BxDolFormQuery::setInputPrivacy($aInput['id'], $this->_iAuthorId, BxDolPrivacy::getFieldName($this->_sPrivacyObjectView), $this->_sPrivacyGroupDefault))
  485. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  486. if((empty($aInputPrivacy) || !is_array($aInputPrivacy)) && $this->_sPrivacyGroupDefault != BX_DOL_PG_ALL)
  487. return false;
  488. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_sPrivacyObjectView);
  489. if($oPrivacy && !$oPrivacy->check($aInputPrivacy['id']))
  490. return false;
  491. return true;
  492. }
  493. /**
  494. * Generate single Table Row for view mode
  495. *
  496. * @param array $aInput
  497. * @return string
  498. */
  499. function genViewRow(&$aInput)
  500. {
  501. if (!isset($aInput['type']))
  502. $aInput['type'] = false;
  503. if(!$this->isInputVisible($aInput))
  504. return '';
  505. if (!empty($aInput['name'])) {
  506. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  507. if (method_exists($this, $sCustomMethod))
  508. return $this->$sCustomMethod($aInput);
  509. }
  510. switch ($aInput['type']) {
  511. case 'block_header':
  512. $sRow = $this->genRowBlockHeader($aInput);
  513. break;
  514. case 'block_end':
  515. $sRow = $this->genBlockEnd($aInput);
  516. break;
  517. case 'nested_form':
  518. $sRow = $this->genNestedForm($aInput);
  519. break;
  520. default:
  521. $sRow = $this->genViewRowWrapped($aInput);
  522. }
  523. return $sRow;
  524. }
  525. /**
  526. * Generate complete wrapped row for view mode form
  527. *
  528. * @param array $aInput
  529. * @return string
  530. */
  531. function genViewRowWrapped(&$aInput)
  532. {
  533. $sValue = $this->genViewRowValue($aInput);
  534. if (null === $sValue)
  535. return '';
  536. return $this->oTemplate->parseHtmlByName('form_view_row.html', array(
  537. 'type' => $aInput['type'],
  538. 'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '',
  539. 'value' => $sValue
  540. ));
  541. }
  542. /**
  543. * Generate value for view mode row
  544. *
  545. * @param array $aInput
  546. * @return string
  547. */
  548. function genViewRowValue(&$aInput)
  549. {
  550. if (!empty($aInput['name'])) {
  551. $sCustomMethod = 'genCustomViewRowValue' . $this->_genMethodName($aInput['name']);
  552. if (method_exists($this, $sCustomMethod))
  553. return $this->$sCustomMethod($aInput);
  554. }
  555. switch ($aInput['type']) {
  556. case 'hidden':
  557. $sValue = null;
  558. break;
  559. case 'select':
  560. case 'radio_set':
  561. $sValue = $this->genViewRowValueForSelect($aInput);
  562. break;
  563. case 'datepicker':
  564. $sValue = null;
  565. if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value'])
  566. break;
  567. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  568. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'] . " Z", isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  569. else
  570. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  571. break;
  572. case 'date_time':
  573. case 'datetime':
  574. $sValue = null;
  575. if(empty($aInput['value']) || !$aInput['value'] || '0000-00-00 00:00:00' == $aInput['value'] || '0000-00-00 00:00' == $aInput['value'])
  576. break;
  577. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  578. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'] . " Z", isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  579. else
  580. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  581. break;
  582. case 'checkbox_set':
  583. case 'select_multiple':
  584. $sValue = null;
  585. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  586. $sValue = '';
  587. foreach ($aInput['value'] as $sVal)
  588. $sValue .= $aInput['values'][$sVal] . ', ';
  589. $sValue = trim ($sValue, ', ');
  590. }
  591. break;
  592. case 'checkbox':
  593. case 'switcher':
  594. $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off');
  595. break;
  596. case 'textarea':
  597. if (isset($aInput['value']) && '' !== $aInput['value'])
  598. $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE);
  599. else
  600. $sValue = null;
  601. break;
  602. case 'text':
  603. if(isset($aInput['value']) && '' !== $aInput['value'])
  604. $sValue = bx_linkify(bx_process_output($aInput['value']));
  605. else
  606. $sValue = null;
  607. break;
  608. default:
  609. if(isset($aInput['value']) && '' !== $aInput['value']) {
  610. $sValue = $aInput['value'];
  611. if(get_mb_substr($sValue, 0, 1) == '_')
  612. $sValue = _t($sValue);
  613. $sValue = bx_process_output($sValue);
  614. }
  615. else
  616. $sValue = null;
  617. }
  618. return $sValue;
  619. }
  620. function genViewRowValueForSelect(&$aInput)
  621. {
  622. if (!isset($aInput['value']) || !$aInput['value'])
  623. return null;
  624. $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
  625. if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])) !== false)
  626. return $oCategory->getCategoryLink($s, $aInput['value']);
  627. return $s;
  628. }
  629. protected function genCustomRowBirthday(&$aInput)
  630. {
  631. if(!$this->_bViewMode)
  632. return $this->genRowStandard($aInput);
  633. $aInput['caption_src'] = '_sys_form_input_age';
  634. $aInput['caption'] = _t($aInput['caption_src']);
  635. return $this->genViewRowWrapped($aInput);
  636. }
  637. protected function genCustomViewRowValueBirthday(&$aInput)
  638. {
  639. if(!isset($aInput['value']) || !$aInput['value'] || in_array($aInput['value'], array('0000-00-00', '0000-00-00 00:00:00')))
  640. return null;
  641. $sValue = $aInput['value'];
  642. $iPosSpace = strpos($sValue, ' ');
  643. if($iPosSpace !== false)
  644. $sValue = trim(substr($sValue, 0, $iPosSpace));
  645. $aDate = explode('-', $sValue);
  646. $iCdYear = (int)date('Y');
  647. $iCdMonth = (int)date('n');
  648. $iCdDay = (int)date('j');
  649. $iResult = $iCdYear - (int)$aDate[0];
  650. if($iCdMonth < (int)$aDate[1] || ($iCdMonth == (int)$aDate[1] && $iCdDay < (int)$aDate[2]))
  651. $iResult -= 1;
  652. return $iResult;
  653. }
  654. /**
  655. * Generate standard row
  656. *
  657. * @param array $aInput
  658. * @return string
  659. */
  660. function genRowStandard(&$aInput, $isOneLine = false)
  661. {
  662. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  663. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span> ' : '';
  664. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  665. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  666. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  667. $sClassWrapper = 'bx-form-element-wrapper';
  668. if($isOneLine)
  669. $sClassWrapper .= ' ' . $sClassWrapper . '-oneline';
  670. $sClassWrapper .= ' bx-def-margin-top';
  671. if (isset($aInput['name']))
  672. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  673. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper);
  674. $sClassOneLineCaption = '';
  675. $sClassOneLineValue = '';
  676. if ($isOneLine) {
  677. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' bx-def-margin-sec-left';
  678. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  679. $aInput['attrs']['id'] = $this->getInputId($aInput);
  680. if ($sCaption)
  681. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  682. }
  683. $sInput = $this->genInput($aInput);
  684. if(isset($aInput['error_updated']) && $aInput['error_updated'] === true)
  685. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  686. if(empty($sErrorIcon))
  687. $sErrorIcon = '';
  688. $aTmplVarsRow = array(
  689. 'bx_if:show_caption' => array(
  690. 'condition' => !empty($sCaption),
  691. 'content' => array(
  692. 'class_caption' => $sClassOneLineCaption,
  693. 'caption' => $sCaption,
  694. 'required' => $sRequired
  695. )
  696. ),
  697. 'class_value' => $sClassAdd . $sClassOneLineValue,
  698. 'value' => $this->genWrapperInput($aInput, $sInput),
  699. 'info' => $sInfoIcon,
  700. 'error' => $sErrorIcon,
  701. );
  702. return $this->oTemplate->parseHtmlByName('form_row_standard.html', array(
  703. 'tr_attrs' => $sTrAttrs,
  704. 'bx_if:show_one_line' => array(
  705. 'condition' => $isOneLine,
  706. 'content' => $aTmplVarsRow
  707. ),
  708. 'bx_if:show_lined' => array(
  709. 'condition' => !$isOneLine,
  710. 'content' => $aTmplVarsRow
  711. ),
  712. 'info' => $sInfoIcon,
  713. 'error' => $sErrorIcon
  714. ));
  715. }
  716. function genWrapperInput($aInput, $sContent)
  717. {
  718. $sClass = "";
  719. if(isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput))
  720. $sClass .= ' bx-form-input-wrapper-html';
  721. $sAttrs = "";
  722. if(isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper'])) {
  723. if(!empty($aInput['attrs_wrapper']['class'])) {
  724. $sClass .= ' ' . trim($aInput['attrs_wrapper']['class']);
  725. unset($aInput['attrs_wrapper']['class']);
  726. }
  727. $sAttrs = bx_convert_array2attrs($aInput['attrs_wrapper']);
  728. }
  729. return $this->oTemplate->parseHtmlByName('form_input_wrapper.html', array(
  730. 'type' => $aInput['type'],
  731. 'class' => $sClass,
  732. 'attrs' => $sAttrs,
  733. 'content' => $sContent
  734. ));
  735. }
  736. /**
  737. * Generate custom row
  738. *
  739. * @param array $aInput
  740. * @param string $sCustomMethod custom method to generate code for input
  741. * @return string
  742. */
  743. function genRowCustom(&$aInput, $sCustomMethod)
  744. {
  745. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  746. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span> ' : '';
  747. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  748. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  749. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  750. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  751. if (isset($aInput['name']))
  752. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  753. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  754. return $this->oTemplate->parseHtmlByName('form_row_custom.html', array(
  755. 'tr_attrs' => $sTrAttrs,
  756. 'bx_if:show_caption' => array(
  757. 'condition' => !empty($sCaption),
  758. 'content' => array(
  759. 'caption' => $sCaption,
  760. 'required' => $sRequired
  761. )
  762. ),
  763. 'class_value' => $sClassAdd,
  764. 'value' => $sInput,
  765. ));
  766. }
  767. /**
  768. * Generate Block Headers row
  769. *
  770. * @param array $aInput
  771. * @return string
  772. */
  773. function genRowBlockHeader(&$aInput)
  774. {
  775. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  776. // if there is no caption - show divider only
  777. if (empty($aInput['caption'])) {
  778. $sCode = $this->{$this->_sSectionClose}();
  779. $sCode .= $this->{$this->_sSectionOpen}($aAttrs);
  780. return $sCode;
  781. }
  782. // if section is collapsed by default, add necessary code
  783. $sClassAddCollapsable = 'bx-form-collapsable';
  784. if (isset($aInput['collapsed']) and $aInput['collapsed'])
  785. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  786. // display section with caption
  787. $sCode = $this->{$this->_sSectionClose}();
  788. if (empty($aAttrs))
  789. $aAttrs = array('class' => 'bx-form-collapsable ' . $sClassAddCollapsable);
  790. else
  791. $aAttrs['class'] .= ' bx-form-collapsable ' . $sClassAddCollapsable;
  792. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])
  793. $sLegend = '<legend class="bx-def-padding-left bx-def-padding-sec-right bx-def-font-grayed bx-def-font-large">' . bx_process_output($aInput['caption']) . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</legend>';
  794. else
  795. $sLegend = '<legend class="bx-def-padding-left bx-def-padding-sec-right bx-def-font-grayed bx-def-font-large"><a href="javascript:void(0);">' . bx_process_output($aInput['caption']) . '</a>' . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</legend>';
  796. $sCode .= $this->{$this->_sSectionOpen}($aAttrs, $sLegend);
  797. return $sCode;
  798. }
  799. function genBlockEnd()
  800. {
  801. $aNextTbodyAdd = false; // need to have some default
  802. $sCode = '';
  803. $sCode .= $this->{$this->_sSectionClose}();
  804. $sCode .= $this->{$this->_sSectionOpen}($aNextTbodyAdd);
  805. return $sCode;
  806. }
  807. /**
  808. * Generate HTML Input Element
  809. *
  810. * @param array $aInput
  811. * @return string Output HTML Code
  812. */
  813. function genInput(&$aInput)
  814. {
  815. if (!empty($aInput['name'])) {
  816. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  817. if (method_exists($this, $sCustomMethod))
  818. return $this->$sCustomMethod($aInput);
  819. }
  820. switch ($aInput['type']) {
  821. // standard inputs (and non-standard, interpreted as standard)
  822. case 'text':
  823. case 'datepicker':
  824. case 'date_time':
  825. case 'datetime':
  826. case 'number':
  827. case 'time':
  828. case 'checkbox':
  829. case 'radio':
  830. case 'image':
  831. case 'slider':
  832. case 'doublerange':
  833. case 'hidden':
  834. $sInput = $this->genInputStandard($aInput);
  835. break;
  836. case 'password':
  837. $sInput = $this->genInputPassword($aInput);
  838. break;
  839. case 'file':
  840. $sInput = $this->genInputFile($aInput);
  841. break;
  842. case 'rgb':
  843. case 'rgba':
  844. $sClass = 'bx-form-input-' . $aInput['type'];
  845. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  846. $aInput['type'] = 'text';
  847. $sInput = $this->genInputStandard($aInput);
  848. break;
  849. case 'switcher':
  850. $sInput = $this->genInputSwitcher($aInput);
  851. break;
  852. case 'button':
  853. case 'reset':
  854. case 'submit':
  855. $sInput = $this->genInputButton($aInput);
  856. break;
  857. case 'textarea':
  858. $sInput = $this->genInputTextarea($aInput);
  859. break;
  860. case 'select':
  861. $sInput = $this->genInputSelect($aInput);
  862. break;
  863. case 'select_multiple':
  864. $sInput = $this->genInputSelectMultiple($aInput);
  865. break;
  866. case 'checkbox_set':
  867. $sInput = $this->genInputCheckboxSet($aInput);
  868. break;
  869. case 'radio_set':
  870. $sInput = $this->genInputRadioSet($aInput);
  871. break;
  872. case 'input_set': // numeric array of inputs
  873. $sInput = '';
  874. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  875. foreach ($aInput as $iKey => $aSubInput) {
  876. if (!is_int($iKey) or !$aSubInput)
  877. continue; // parse only integer keys and existing values
  878. $sInput .= $this->genInput($aSubInput); // recursive call
  879. $sInput .= $sDivider;
  880. }
  881. $sInput .= '<div class="bx-clear"></div>';
  882. break;
  883. case 'custom':
  884. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  885. break;
  886. case 'captcha':
  887. $sInput = $this->genInputCaptcha($aInput);
  888. break;
  889. case 'location':
  890. $sInput = $this->genInputLocation($aInput);
  891. break;
  892. case 'nested_form':
  893. $sInput = $this->genInputNestedForm($aInput);
  894. break;
  895. case 'value':
  896. $sInput = '';
  897. if(!isset($aInput['value']))
  898. break;
  899. $sInput = $aInput['value'];
  900. if(get_mb_substr($sInput, 0, 1) == '_')
  901. $sInput = _t($sInput);
  902. break;
  903. default:
  904. //unknown control type
  905. $sInput = 'Unknown control type';
  906. }
  907. // create input label
  908. $sInput .= $this->genLabel($aInput);
  909. // create input privacy group chooser
  910. $sInput .= $this->genPrivacyGroupChooser($aInput);
  911. return $sInput;
  912. }
  913. /**
  914. * Generate new Input Element id
  915. *
  916. * @param array $aInput
  917. * @return string
  918. */
  919. function getInputId(&$aInput)
  920. {
  921. if (isset($aInput['id']))
  922. return $aInput['id'];
  923. $sName = md5($aInput['name']);
  924. $sID = $this->id . '_input_' . $sName;
  925. if ( // multiple elements cause identical id's
  926. (
  927. (
  928. $aInput['type'] == 'checkbox' and
  929. substr($aInput['name'], -2) == '[]' // it is multiple element
  930. ) or
  931. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  932. ) and
  933. isset($aInput['value']) // if we can make difference
  934. ) {
  935. $sValue = md5($aInput['value']);
  936. // add value
  937. $sID .= '_' . $sValue;
  938. }
  939. $sID = trim($sID, '_');
  940. $aInput['id'] = $sID; // just for repeated calls
  941. return $sID;
  942. }
  943. /**
  944. * Generate standard Input Element
  945. *
  946. * @param array $aInput
  947. * @return string
  948. */
  949. function genInputStandard(&$aInput)
  950. {
  951. // clone attributes for system use ;)
  952. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  953. // add default className to attributes
  954. $aAttrs['type'] = $aInput['type'];
  955. if ('datetime' == $aAttrs['type'])
  956. $aAttrs['type'] = 'date_time';
  957. switch($aAttrs['type']) {
  958. case 'date_time':
  959. $this->addCssJsUi ();
  960. $this->addCssJsTimepicker ();
  961. break;
  962. case 'slider':
  963. case 'doublerange':
  964. case 'datepicker':
  965. $this->addCssJsUi ();
  966. break;
  967. case 'text':
  968. if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
  969. $this->addCssJsMinicolors ();
  970. break;
  971. }
  972. if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) {
  973. $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max'];
  974. }
  975. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  976. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  977. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1;
  978. // for inputs with labels generate id
  979. if (isset($aInput['label']))
  980. $aAttrs['id'] = $this->getInputId($aInput);
  981. // for checkboxes
  982. if (isset($aInput['checked']) and $aInput['checked'])
  983. $aAttrs['checked'] = 'checked';
  984. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  985. return "<input $sAttrs />\n";
  986. }
  987. /**
  988. * Generate Switcher Input Element (based on checkbox)
  989. *
  990. * @param array $aInput
  991. * @return string
  992. */
  993. function genInputSwitcher(&$aInput)
  994. {
  995. $aInput['type'] = 'checkbox';
  996. $sCheckbox = $this->genInputStandard($aInput);
  997. $aInput['type'] = 'switcher';
  998. $sClass = 'off';
  999. if (isset($aInput['checked']) and $aInput['checked'])
  1000. $sClass = 'on';
  1001. return '
  1002. <div class="bx-switcher-cont ' . $sClass . '">' . $sCheckbox . '
  1003. <div class="bx-switcher-canvas">
  1004. <div class="bx-switcher-on"><i class="sys-icon check"></i></div>
  1005. <div class="bx-switcher-off"><i class="sys-icon times"></i></div>
  1006. <div class="bx-switcher-handler">&nbsp;</div>
  1007. </div>
  1008. </div>';
  1009. }
  1010. /**
  1011. * Generate Button Input Element
  1012. *
  1013. * @param array $aInput
  1014. * @return string
  1015. */
  1016. function genInputButton(&$aInput)
  1017. {
  1018. // clone attributes for system use ;)
  1019. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1020. // add default className to attributes
  1021. $aAttrs['type'] = $aInput['type'];
  1022. if (isset($aInput['value']))
  1023. $aAttrs['value'] = $aInput['value'];
  1024. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  1025. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn" . ('submit' == $aInput['type'] ? ' bx-btn-primary' : ''));
  1026. return "<button $sAttrs>" . $aInput['value'] . "</button>\n";
  1027. }
  1028. /**
  1029. * Generate Textarea Element
  1030. *
  1031. * @param array $aInput
  1032. * @return string
  1033. */
  1034. function genInputTextarea(&$aInput)
  1035. {
  1036. // clone attributes for system use ;)
  1037. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1038. $aAttrs['name'] = $aInput['name'];
  1039. // for inputs with labels generate id
  1040. if (isset($aInput['label']))
  1041. $aAttrs['id'] = $this->getInputId($aInput);
  1042. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}" . ((isset($aInput['html']) and $aInput['html'] and $this->addHtmlEditor($aInput['html'], $aInput)) ? ' bx-form-input-html' : ''));
  1043. $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')) : '';
  1044. return "<textarea $sAttrs>$sValue</textarea>";
  1045. }
  1046. function isHtmlEditor($iViewMode, &$aInput)
  1047. {
  1048. return BxDolEditor::getObjectInstance(false, $this->oTemplate) !== false;
  1049. }
  1050. function addHtmlEditor($iViewMode, &$aInput)
  1051. {
  1052. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  1053. if (!$oEditor)
  1054. return false;
  1055. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name='.$aInput['name'].']', $iViewMode, $this->_bDynamicMode);
  1056. return true;
  1057. }
  1058. /**
  1059. * Generate Select Box Element
  1060. *
  1061. * @param array $aInput
  1062. * @return string
  1063. */
  1064. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  1065. {
  1066. $aNewInput = $aInput;
  1067. $aNewInput['type'] = 'select';
  1068. $aNewInput['name'] .= '[]';
  1069. $sInput = $this->genInput($aNewInput);
  1070. return <<<BLAH
  1071. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  1072. $sInput
  1073. </div>
  1074. $sInfo
  1075. $sError
  1076. BLAH;
  1077. }
  1078. /**
  1079. * Generate Browse File Element
  1080. *
  1081. * @param array $aInput
  1082. * @return string
  1083. */
  1084. function genInputFile(&$aInput)
  1085. {
  1086. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  1087. if(!empty($aInput['attrs']['onchange']))
  1088. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  1089. else
  1090. $aInput['attrs']['onchange'] = $sOnChange;
  1091. $sInput = $this->genInputStandard($aInput);
  1092. 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>';
  1093. }
  1094. /**
  1095. * Generate Select Box Element
  1096. *
  1097. * @param array $aInput
  1098. * @return string
  1099. */
  1100. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  1101. {
  1102. $sUniqId = !empty($aInput['uploaders_id']) ? $aInput['uploaders_id'] : genRndPwd (8, false);
  1103. $sUploaders = '';
  1104. $oUploader = null;
  1105. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1106. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  1107. if (!$oUploader)
  1108. continue;
  1109. $sGhostTemplate = $this->genGhostTemplate($aInput);
  1110. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1111. if (empty($aInput['attrs']['disabled']))
  1112. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  1113. $aParams = array(
  1114. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  1115. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1116. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1117. 'attrs' => bx_convert_array2attrs($aAttrs),
  1118. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  1119. );
  1120. if (isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  1121. $aParams['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  1122. $sUploaders .= $oUploader->getUploaderButton($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParams, $this->_bDynamicMode);
  1123. }
  1124. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  1125. 'uploaders_buttons' => $sUploaders,
  1126. 'info' => $sInfo,
  1127. 'error' => $sError,
  1128. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  1129. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  1130. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  1131. 'is_init_ghosts' => isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1,
  1132. ));
  1133. }
  1134. protected function genGhostTemplate(&$aInput)
  1135. {
  1136. $sGhostTemplate = false;
  1137. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  1138. $oFormNested = $aInput['ghost_template'];
  1139. if ($oFormNested instanceof BxDolFormNestedGhost)
  1140. $sGhostTemplate = $oFormNested->genForm();
  1141. } 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
  1142. $oFormNested = new BxDolFormNestedGhost($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  1143. $sGhostTemplate = $oFormNested->getCode();
  1144. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  1145. $sGhostTemplate = array ();
  1146. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  1147. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNestedGhost)
  1148. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  1149. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  1150. $sGhostTemplate = $aInput['ghost_template'];
  1151. }
  1152. return $sGhostTemplate;
  1153. }
  1154. protected function genCustomInputUsernamesSuggestions ($aInput)
  1155. {
  1156. $this->addCssJsUi();
  1157. $sVals = '';
  1158. if(!empty($aInput['value'])) {
  1159. if(is_array($aInput['value'])) {
  1160. foreach($aInput['value'] as $sVal) {
  1161. if(!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  1162. continue;
  1163. $sVals .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . $oProfile->getUnit(0, array('template' => 'unit_wo_info')) . $oProfile->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></b>';
  1164. }
  1165. $sVals = trim($sVals, ',');
  1166. }
  1167. else if(is_string($aInput['value']))
  1168. $sVals = $aInput['value'];
  1169. }
  1170. $bDisabled = isset($aInput['attrs']['disabled']) && $aInput['attrs']['disabled'] == 'disabled';
  1171. $sId = $aInput['name'] . time() . mt_rand(0, 100);
  1172. $sClass = 'bx-form-input-autotoken bx-def-font-inputs bx-form-input-text';
  1173. if($bDisabled)
  1174. $sClass .= ' bx-form-input-disabled';
  1175. if(!empty($aInput['attrs']['class'])) {
  1176. $sClass .= ' ' . $aInput['attrs']['class'];
  1177. unset($aInput['attrs']['class']);
  1178. }
  1179. $aAttrs = array('value' => '', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'autocorrect' => 'off');
  1180. if(isset($aInput['attrs']) && is_array($aInput['attrs']))
  1181. $aAttrs = array_merge($aAttrs, $aInput['attrs']);
  1182. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  1183. 'id' => $sId,
  1184. 'name' => $aInput['name'],
  1185. 'class' => $sClass,
  1186. 'vals' => $sVals,
  1187. 'bx_if:input' => array(
  1188. 'condition' => !$bDisabled,
  1189. 'content' => array(
  1190. 'attrs' => bx_convert_array2attrs($aAttrs),
  1191. )
  1192. ),
  1193. 'bx_if:init' => array(
  1194. 'condition' => !$bDisabled,
  1195. 'content' => array(
  1196. 'id' => $sId,
  1197. 'name' => $aInput['name'],
  1198. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  1199. 'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
  1200. 'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
  1201. 'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
  1202. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  1203. )
  1204. )
  1205. ));
  1206. }
  1207. protected function genCustomViewRowValueLabels ($aInput)
  1208. {
  1209. if (empty($aInput['value']) || !($oMetatags = BxDolMetatags::getObjectInstance($aInput['meta_object'])) || !$oMetatags->keywordsIsEnabled())
  1210. return null;
  1211. if (!empty($aInput['value']) && !is_array($aInput['value']))
  1212. $aInput['value'] = unserialize($aInput['value']);
  1213. $s = '';
  1214. foreach ($aInput['value'] as $sLabel)
  1215. $s .= '<a href="' . $oMetatags->keywordsGetHashTagUrl($sLabel, $aInput['content_id']) . '"><b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sLabel) . '</b></a>';
  1216. return $this->oTemplate->parseHtmlByName('form_field_labels_view.html', array(
  1217. 'values' => $s,
  1218. ));
  1219. }
  1220. protected function genCustomInputLabels ($aInput)
  1221. {
  1222. $oLabel = BxDolLabel::getInstance();
  1223. $sName = !empty($aInput['name']) ? $aInput['name'] : 'labels';
  1224. $sValue = '';
  1225. if(!empty($aInput['value'])) {
  1226. if(!is_array($aInput['value']))
  1227. $aInput['value'] = unserialize($aInput['value']);
  1228. if(is_array($aInput['value']))
  1229. foreach($aInput['value'] as $sLabel)
  1230. $sValue .= $oLabel->getLabel($sName, $sLabel);
  1231. }
  1232. $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
  1233. if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
  1234. $sValue .= $oLabel->getLabelPlaceholder($sKeyPlaceholder);
  1235. $aInputLabels = array(
  1236. 'type' => 'custom',
  1237. 'name' => $sName,
  1238. 'caption' => '',
  1239. 'value' => $sValue,
  1240. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('label.php', array(
  1241. 'action' => 'labels_list',
  1242. )),
  1243. 'attrs' => array(
  1244. 'class' => 'bx-form-input-labels',
  1245. 'disabled' => 'disabled'
  1246. )
  1247. );
  1248. return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
  1249. 'js_object' => $oLabel->getJsObjectName(),
  1250. 'js_code' => $oLabel->getJsCodeForm(),
  1251. 'html_id' => $oLabel->getFormFieldId($aInput),
  1252. 'name' => $sName,
  1253. 'input_labels' => $this->genCustomInputUsernamesSuggestions($aInputLabels)
  1254. ));
  1255. }
  1256. /**
  1257. * Generate Select Element
  1258. *
  1259. * @param array $aInput
  1260. * @return string
  1261. */
  1262. function genInputSelect(&$aInput)
  1263. {
  1264. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1265. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1266. }
  1267. /**
  1268. * Generate Multiple Select Element
  1269. *
  1270. * @param array $aInput
  1271. * @return string
  1272. */
  1273. function genInputSelectMultiple(&$aInput)
  1274. {
  1275. $aCurValues = array();
  1276. if (isset($aInput['value']) && $aInput['value'])
  1277. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1278. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  1279. }
  1280. /**
  1281. * Generate Checkbox Set Element
  1282. *
  1283. * @param array $aInput
  1284. * @return string
  1285. */
  1286. function genInputCheckboxSet(&$aInput)
  1287. {
  1288. $aCurValues = array();
  1289. if (isset($aInput['value']) && $aInput['value'])
  1290. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1291. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  1292. }
  1293. /**
  1294. * Generate Radiobuttons Set Element
  1295. *
  1296. * @param array $aInput
  1297. * @return string
  1298. */
  1299. function genInputRadioSet(&$aInput)
  1300. {
  1301. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1302. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  1303. }
  1304. function _isSelected ($sValue, $sCurValue)
  1305. {
  1306. return ((string)$sValue === (string)$sCurValue);
  1307. }
  1308. function _isSelectedMultiple ($sValue, $aCurValues)
  1309. {
  1310. return in_array($sValue, $aCurValues);
  1311. }
  1312. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  1313. {
  1314. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1315. $aAttrs['name'] = $aInput['name'];
  1316. if ($isMultiple) {
  1317. $aAttrs['name'] .= '[]';
  1318. $aAttrs['multiple'] = 'multiple';
  1319. }
  1320. // for inputs with labels generate id
  1321. if (isset($aInput['label']))
  1322. $aAttrs['id'] = $this->getInputId($aInput);
  1323. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  1324. // generate options
  1325. $sOptions = '';
  1326. if (isset($aInput['values']) and is_array($aInput['values'])) {
  1327. foreach ($aInput['values'] as $sValue => $sTitle) {
  1328. $sAttrsOpt = "";
  1329. if(is_array($sTitle)) {
  1330. if(isset($sTitle['type'])) {
  1331. switch($sTitle['type']) {
  1332. case 'group_header':
  1333. $sTitle = bx_process_output($sTitle['value']);
  1334. $sOptions .= <<<BLAH
  1335. <optgroup label="$sTitle">
  1336. BLAH;
  1337. break;
  1338. case 'group_end':
  1339. $sOptions .= <<<BLAH
  1340. </optgroup>
  1341. BLAH;
  1342. break;
  1343. }
  1344. continue;
  1345. }
  1346. $aAttrsOpt = array();
  1347. if(!empty($sTitle['attrs']) && is_array($sTitle['attrs']))
  1348. $aAttrsOpt = $sTitle['attrs'];
  1349. if(isset($sTitle['class']))
  1350. $aAttrsOpt['class'] = !empty($aAttrsOpt['class']) ? $aAttrsOpt['class'] . ' ' . $sTitle['class'] : $sTitle['class'];
  1351. if(isset($sTitle['style']))
  1352. $aAttrsOpt['style'] = !empty($aAttrsOpt['style']) ? $aAttrsOpt['style'] . ' ' . $sTitle['style'] : $sTitle['style'];
  1353. $sAttrsOpt = !empty($aAttrsOpt) ? bx_convert_array2attrs($aAttrsOpt) : '';
  1354. $sValue = $sTitle['key'];
  1355. $sTitle = $sTitle['value'];
  1356. }
  1357. $sValueC = bx_html_attribute($sValue);
  1358. $sTitleC = bx_process_output($sTitle);
  1359. $sSelected = $this->$sIsSelectedFunc($sValue, $mixedCurrentVal) ? 'selected="selected"' : '';
  1360. $sOptions .= <<<BLAH
  1361. <option value="$sValueC" $sAttrsOpt $sSelected>$sTitleC</option>
  1362. BLAH;
  1363. }
  1364. }
  1365. // generate element
  1366. $sCode = <<<BLAH
  1367. <select $sAttrs>
  1368. $sOptions
  1369. </select>
  1370. BLAH;
  1371. if(!empty($aInput['content']))
  1372. $sCode .= $aInput['content'];
  1373. return $sCode;
  1374. }
  1375. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  1376. {
  1377. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  1378. $aAttrs['name'] = $aInput['name'];
  1379. // for inputs with labels generate id
  1380. if (isset($aInput['label']))
  1381. $aAttrs['id'] = $this->getInputId($aInput);
  1382. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1383. // generate options
  1384. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  1385. $sOptions = '';
  1386. if (isset($aInput['values']) && is_array($aInput['values'])) {
  1387. if (count($aInput['values']) > 3 && $sDivider == $this->_sDivider)
  1388. $sDivider = $this->_sDividerAlt;
  1389. // generate complex input using simple standard inputs
  1390. foreach ($aInput['values'] as $sValue => $sLabel) {
  1391. if(is_array($sLabel)) {
  1392. $sValue = $sLabel['key'];
  1393. $sLabel = $sLabel['value'];
  1394. }
  1395. // create new simple input
  1396. $aNewInput = array(
  1397. 'type' => $sType,
  1398. 'name' => $aInput['name'] . $sNameAppend,
  1399. 'value' => $sValue,
  1400. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  1401. 'label' => $sLabel,
  1402. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  1403. );
  1404. if (isset($aInput['label_as_html']))
  1405. $aNewInput['label_as_html'] = $aInput['label_as_html'];
  1406. $sNewInput = $this->genInput($aNewInput);
  1407. // attach new input to complex
  1408. $sOptions .= ($sNewInput . $sDivider);
  1409. }
  1410. }
  1411. // generate element
  1412. $sCode = <<<BLAH
  1413. <div $sAttrs>
  1414. $sOptions
  1415. </div>
  1416. BLAH;
  1417. return $sCode;
  1418. }
  1419. function genInputLocation(&$aInput)
  1420. {
  1421. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1422. if (!$o)
  1423. return _t('_sys_txt_error_occured');
  1424. return $o->genInputLocation($aInput, $this);
  1425. }
  1426. public function setLocationVals ($aInput, $aVals)
  1427. {
  1428. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1429. if (!$o)
  1430. return false;
  1431. return $o->setLocationVals ($aInput, $aVals, $this);
  1432. }
  1433. public function setLocationVal ($aInput, $sIndex, $sVal)
  1434. {
  1435. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1436. if (!$o)
  1437. return false;
  1438. return $o->setLocationVal ($aInput, $sIndex, $sVal, $this);
  1439. }
  1440. protected function getLocationVal ($aInput, $sIndex)
  1441. {
  1442. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1443. if (!$o)
  1444. return false;
  1445. return $o->getLocationVal ($aInput, $sIndex, $this);
  1446. }
  1447. function genInputPassword(&$aInput)
  1448. {
  1449. return $this->oTemplate->parseHtmlByName('form_field_password.html', array('input' => $this->genInputStandard($aInput)));
  1450. }
  1451. function genInputNestedForm(&$aInput)
  1452. {
  1453. return '';
  1454. }
  1455. function genNestedForm(&$aInput)
  1456. {
  1457. return '';
  1458. }
  1459. function genInputCaptcha(&$aInput)
  1460. {
  1461. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1462. // for inputs with labels generate id
  1463. if (isset($aInput['label']))
  1464. $aAttrs['id'] = $this->getInputId($aInput);
  1465. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1466. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1467. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1468. }
  1469. /**
  1470. * Generate Label Element
  1471. *
  1472. * @param string $aInput input array
  1473. * @return string HTML code
  1474. */
  1475. function genLabel(&$aInput)
  1476. {
  1477. if (!isset($aInput['label']) || empty($aInput['label']))
  1478. return '';
  1479. $sInputID = $this->getInputId($aInput);
  1480. $sLabel = bx_process_output($aInput['label']);
  1481. if (isset($aInput['label_as_html']) && $aInput['label_as_html'] == true)
  1482. $sLabel = $aInput['label'];
  1483. return '<label for="' . $sInputID . '">' . $sLabel . '</label>';
  1484. }
  1485. function genPrivacyGroupChooser(&$aInput, $sPrivacyObject = '')
  1486. {
  1487. if(!isset($aInput['privacy']) || empty($aInput['privacy']))
  1488. return '';
  1489. $iAuthorId = bx_get_logged_profile_id();
  1490. $mixedResult = checkActionModule($iAuthorId, 'set form fields privacy', 'system');
  1491. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1492. return '';
  1493. if(empty($sPrivacyObject))
  1494. $sPrivacyObject = $this->_sPrivacyObjectView;
  1495. $iInputId = (int)$aInput['id'];
  1496. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  1497. if(!isset($aInput['attrs_wrapper']['class']))
  1498. $aInput['attrs_wrapper']['class'] = '';
  1499. $aInput['attrs_wrapper']['class'] .= ' bx-form-input-wrapper-pgc';
  1500. return $this->oTemplate->parseHtmlByName('form_field_privacy.html', array(
  1501. 'js_object' => $this->getJsObjectName(),
  1502. 'html_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  1503. 'html_id_popup' => $this->_aHtmlIds['pgc_popup'] . $iInputId,
  1504. 'id' => $iInputId,
  1505. 'privacy_object' => $sPrivacyObject,
  1506. 'icon' => $this->_getPrivacyIcon($mixedPrivacyGroup)
  1507. ));
  1508. }
  1509. function genInfoIcon($sInfo)
  1510. {
  1511. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1512. }
  1513. function genErrorIcon( $sError = '' )
  1514. {
  1515. if ($this->bEnableErrorIcon) {
  1516. $sStyle = '';
  1517. if (!$sError)
  1518. $sStyle = 'style="display:none;"';
  1519. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1520. }
  1521. }
  1522. function getOpenSection($aAttrs = array(), $sLegend = '')
  1523. {
  1524. if (!$this->_isSectionOpened) {
  1525. if (!$aAttrs || !is_array($aAttrs))
  1526. $aAttrs = array();
  1527. if ($sLegend)
  1528. $sClassesAdd = "bx-form-section-header";
  1529. else
  1530. $sClassesAdd = "bx-form-section-divider";
  1531. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1532. $this->_isSectionOpened = true;
  1533. return "<!-- form header content begins -->\n <div class=\"bx-form-section-wrapper bx-def-margin-top\"> <div $sAttrs> $sLegend <div class=\"bx-form-section-content bx-def-padding-top bx-def-padding-bottom" . ($sLegend ? ' bx-def-padding-left bx-def-padding-right' : '') . "\">\n";
  1534. } else {
  1535. return '';
  1536. }
  1537. }
  1538. function getCloseSection()
  1539. {
  1540. if ($this->_isSectionOpened) {
  1541. $this->_isSectionOpened = false;
  1542. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1543. } else {
  1544. return '';
  1545. }
  1546. }
  1547. function getOpenSectionViewMode($aAttrs = array(), $sLegend = '')
  1548. {
  1549. if (!$this->_isSectionOpened) {
  1550. if (!$aAttrs || !is_array($aAttrs))
  1551. $aAttrs = array();
  1552. if ($sLegend)
  1553. $sClassesAdd = "bx-form-section-header";
  1554. else
  1555. $sClassesAdd = "bx-form-section-divider";
  1556. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1557. $this->_isSectionOpened = true;
  1558. return "<!-- form header content begins -->\n <div class=\"bx-form-section-wrapper bx-def-margin-top\"> <div $sAttrs> $sLegend <div class=\"bx-form-section-content bx-def-padding-top\">\n";
  1559. } else {
  1560. return '';
  1561. }
  1562. }
  1563. function getCloseSectionViewMode()
  1564. {
  1565. if ($this->_isSectionOpened) {
  1566. $this->_isSectionOpened = false;
  1567. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1568. } else {
  1569. return '';
  1570. }
  1571. }
  1572. static function getJsUiLangs ()
  1573. {
  1574. return array ('af' => 1, 'ar-DZ' => 1, 'ar' => 1, 'az' => 1, 'be' => 1, 'bg' => 1, 'bs' => 1, 'ca' => 1, 'cs' => 1, 'cy-GB' => 1, 'da' => 1, 'de' => 1, 'el' => 1, 'en-AU' => 1, 'en-GB' => 1, 'en-NZ' => 1, 'en' => 1, 'eo' => 1, 'es' => 1, 'et' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1, 'fo' => 1, 'fr-CA' => 1, 'fr-CH' => 1, 'fr' => 1, 'gl' => 1, 'he' => 1, 'hi' => 1, 'hr' => 1, 'hu' => 1, 'hy' => 1, 'id' => 1, 'is' => 1, 'it' => 1, 'ja' => 1, 'ka' => 1, 'kk' => 1, 'km' => 1, 'ko' => 1, 'ky' => 1, 'lb' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'ml' => 1, 'ms' => 1, 'nb' => 1, 'nl-BE' => 1, 'nl' => 1, 'nn' => 1, 'no' => 1, 'pl' => 1, 'pt-BR' => 1, 'pt' => 1, 'rm' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sq' => 1, 'sr-SR' => 1, 'sr' => 1, 'sv' => 1, 'ta' => 1, 'th' => 1, 'tj' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-CN' => 1, 'zh-HK' => 1, 'zh-TW' => 1);
  1575. }
  1576. function addCssJsUi ()
  1577. {
  1578. if (self::$_isCssJsUiAdded)
  1579. return;
  1580. $aUiLangs = $this->getJsUiLangs ();
  1581. $sUiLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aUiLangs);
  1582. $this->_addJs(array(
  1583. 'jquery-ui/jquery-ui.custom.min.js',
  1584. 'jquery-ui/i18n/jquery.ui.datepicker-' . $sUiLang . '.min.js',
  1585. ), "'undefined' === typeof($.datepicker)");
  1586. $this->_addCss('jquery-ui/jquery-ui.css');
  1587. self::$_isCssJsUiAdded = true;
  1588. }
  1589. function addCssJsTimepicker ()
  1590. {
  1591. if (self::$_isCssJsTimepickerAdded)
  1592. return;
  1593. $aCalendarLangs = array ('af' => 1, 'am' => 1, 'bg' => 1, 'ca' => 1, 'cs' => 1, 'da' => 1, 'de' => 1, 'el' => 1, 'es' => 1, 'et' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1, 'fr' => 1, 'gl' => 1, 'he' => 1, 'hr' => 1, 'hu' => 1, 'id' => 1, 'it' => 1, 'ja' => 1, 'ko' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'nl' => 1, 'no' => 1, 'pl' => 1, 'pt-BR' => 1, 'pt' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sr-RS' => 1, 'sr-YU' => 1, 'sv' => 1, 'th' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-CN' => 1, 'zh-TW' => 1);
  1594. $sCalendarLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aCalendarLangs);
  1595. $this->_addCss('timepicker-addon/jquery-ui-timepicker-addon.css');
  1596. $this->_addJs(array(
  1597. 'timepicker-addon/jquery-ui-timepicker-addon.min.js',
  1598. 'timepicker-addon/jquery-ui-sliderAccess.js',
  1599. 'timepicker-addon/i18n/jquery-ui-timepicker-' . $sCalendarLang . '.js',
  1600. 'jquery.ui.touch-punch.min.js',
  1601. ), "'undefined' === typeof($.fn.datetimepicker)");
  1602. self::$_isCssJsTimepickerAdded = true;
  1603. }
  1604. function addCssJsMinicolors ()
  1605. {
  1606. if (self::$_isCssJsMinicolorsAdded)
  1607. return;
  1608. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  1609. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  1610. self::$_isCssJsMinicolorsAdded = true;
  1611. }
  1612. function addCssJsViewMode ()
  1613. {
  1614. if (self::$_isCssJsAddedViewMode)
  1615. return;
  1616. $this->_addCss('forms.css');
  1617. self::$_isCssJsAddedViewMode = true;
  1618. }
  1619. function addCssJsCore ()
  1620. {
  1621. if (self::$_isCssJsAdded)
  1622. return;
  1623. $this->_addCss('forms.css');
  1624. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  1625. $this->_addJs(array('BxDolForm.js', 'BxDolNestedForm.js'), "true");
  1626. self::$_isCssJsAdded = true;
  1627. }
  1628. function addCssJs ()
  1629. {
  1630. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  1631. $this->addCssJsViewMode ();
  1632. } else {
  1633. $this->addCssJsCore();
  1634. }
  1635. }
  1636. protected function _processCssJs()
  1637. {
  1638. $sRet = '';
  1639. if ($this->_bDynamicMode) {
  1640. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  1641. $sRet .= "\n<script>\n";
  1642. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  1643. foreach ($this->_aJs as $sCondition => $aJs) {
  1644. $sJs = $this->oTemplate->addJs($aJs, true);
  1645. if (!$sJs)
  1646. continue;
  1647. $sRet .= "if ($sCondition)\n";
  1648. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  1649. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  1650. }
  1651. $sRet .= "\n</script>\n";
  1652. }
  1653. else {
  1654. $this->oTemplate->addCss($this->_aCss);
  1655. $aJs = array();
  1656. foreach ($this->_aJs as $sCondition => $a)
  1657. $aJs = array_merge($aJs, $a);
  1658. $this->oTemplate->addJs($aJs);
  1659. }
  1660. return $sRet;
  1661. }
  1662. protected function _addJs($mixed, $sJsCondition)
  1663. {
  1664. if (!is_array($mixed))
  1665. $mixed = array($mixed);
  1666. $this->_aJs[$sJsCondition] = $mixed;
  1667. }
  1668. protected function _addCss($mixed)
  1669. {
  1670. if (!is_array($mixed))
  1671. $mixed = array($mixed);
  1672. foreach ($mixed as $s)
  1673. $this->_aCss[$s] = $s;
  1674. }
  1675. }
  1676. /** @} */