'; /** * Alternative divider for several inputs */ protected $_sDividerAlt = '
'; /** * Form is added dynamically. */ protected $_bDynamicMode = false; /** * Form is submitted dynamically (using Ajax Submit). */ protected $_bAjaxMode = false; /** * Use absolute Action URL which is needed in Ajax Mode. */ protected $_bAbsoluteActionUrl = false; /** * Form is displayed in view mode. */ protected $_bViewMode = false; /** * Cached CSRF check for revealing a secret field in the current request. */ protected $_bSecretRevealCsrfValid = null; /** * Show or not sections which have no fileds */ protected $_bShowEmptySections = false; /** * Function name for generation close form section HTML. */ protected $_sSectionClose = 'getCloseSection'; /** * Function name for generation open form section HTML. */ protected $_sSectionOpen = 'getOpenSection'; /** * JS files list for form */ protected $_aJs = array(); /** * CSS files list for form */ protected $_aCss = array(); protected $_sJsClassName; protected $_sJsObjectName; protected $_aHtmlIds; protected $_aAgentsFormObject; protected $_sAgentFormObject; /** * Constructor * * @param array $aInfo Form contents * * $aInfo['params'] = array( * 'remove_form' => true|false, * ); * * @return BxBaseFormView */ function __construct($aInfo, $oTemplate) { parent::__construct($aInfo, $oTemplate); $this->_bAjaxMode = isset($this->aParams['ajax_mode']) && $this->aParams['ajax_mode']; $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode']; if($this->_bViewMode) { $this->_sSectionClose = 'getCloseSectionViewMode'; $this->_sSectionOpen = 'getOpenSectionViewMode'; } $this->_sJsClassName = 'BxDolForm'; $sName = !empty($aInfo['params']['display']) ? $aInfo['params']['display'] : ''; if(empty($sName) && !empty($aInfo['params']['object'])) $sName = $aInfo['params']['object']; if(empty($sName) && !empty($aInfo['form_attrs']['id'])) $sName = $aInfo['form_attrs']['id']; if(empty($sName) && !empty($aInfo['form_attrs']['name'])) $sName = $aInfo['form_attrs']['name']; $this->_sJsObjectName = 'oForm' . bx_gen_method_name($sName, array('_' , '-')); $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sName); $this->_aHtmlIds = array( 'help_popup' => $sHtmlId . '-help-popup-', 'pgc' => $sHtmlId . '-pgc-', 'pgc_popup' => $sHtmlId . '-pgc-popup-', 'pgc_form' => $sHtmlId . '-pgc-form-', ); $this->_sAgentFormObject = $aInfo['params']['object'] ?? $this->id; $oAi = BxDolAI::getInstance(); $this->_aAgentsFormObject = $oAi ? $oAi->getAgentsByFormObject($this->_sAgentFormObject) : []; if ($this->_aAgentsFormObject && is_array($this->_aAgentsFormObject)) { $this->_aAgentsFormObject = array_filter($this->_aAgentsFormObject, function ($a) use ($oAi) { return $oAi->canInteract($a); }); } } public function performActionGetHelp() { $sInput = bx_process_input(bx_get('input')); if(empty($sInput) || empty($this->aInputs[$sInput]['help'])) return; echo $this->oTemplate->parseHtmlByName('form_field_help_popup.html', array( 'content' => _t($this->aInputs[$sInput]['help']), 'bx_if:show_edit' => array( 'condition' => isAdmin(), 'content' => array( 'link' => BX_DOL_URL_STUDIO . bx_append_url_params('builder_forms.php', array( 'page' => 'fields', 'module' => $this->aParams['module'], 'object' => $this->aParams['object'], 'display' => $this->aParams['display'] )) ) ) )); } public function performActionChangePrivacyGroup() { $iAuthorId = (int)bx_get_logged_profile_id(); if(empty($iAuthorId)) return echoJson(array()); $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT); if(empty($iInputId)) return echoJson(array()); $sPrivacyObject = bx_process_input(bx_get('privacy_object')); $sPrivacyField = BxDolPrivacy::getFieldName($sPrivacyObject); if(empty($sPrivacyField)) return echoJson(array()); $sPrivacyGroup = bx_process_input(bx_get($sPrivacyField)); if(empty($sPrivacyField)) return echoJson(array()); if(!BxDolFormQuery::setInputPrivacy($iInputId, $iAuthorId, $sPrivacyField, $sPrivacyGroup)) return echoJson(array()); return echoJson(array( 'code' => 0, 'form_id' => $this->getId(), 'chooser_id' => $this->_aHtmlIds['pgc'] . $iInputId, 'icon' => $this->_getPrivacyIcon($sPrivacyGroup), 'eval' => $this->getJsObjectName() . '.pgcOnSelectGroup(oData);' )); } public function performActionGetPrivacyGroupChooser() { $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT); $sPrivacyObject = bx_process_input(bx_get('privacy_object')); if(empty($iInputId) || empty($sPrivacyObject)) return ''; $sFormId = $this->_aHtmlIds['pgc_form'] . $iInputId; $aFormActionParams = array(); if(!empty($this->aParams['object']) && !empty($this->aParams['display'])) $aFormActionParams = array( 'o' => $this->aParams['object'], 'd' => $this->aParams['display'] ); $aFormActionParams['a'] = 'change_privacy_group'; $iAuthorId = bx_get_logged_profile_id(); $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId); $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject); $aInputPgc = $oPrivacy->getGroupChooser($sPrivacyObject, $iAuthorId); $aInputPgc['value'] = $mixedPrivacyGroup; if(!isset($aInputPgc['content'])) $aInputPgc['content'] = ''; $aInputPgc['content'] .= $oPrivacy->addCssJs(true); $aInputPgc['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iAuthorId, array( 'content_id' => $iInputId, 'group_id' => $mixedPrivacyGroup, 'html_ids' => array( 'form' => $sFormId ) )); $aFormInfo = array( 'form_attrs' => array( 'id' => $sFormId, 'action' => BX_DOL_URL_ROOT . bx_append_url_params('form.php', $aFormActionParams), 'method' => 'post' ), 'inputs' => array ( 'input_id' => array( 'type' => 'hidden', 'name' => 'input_id', 'value' => $iInputId, 'db' => array ( 'pass' => 'Int', ), ), 'privacy_object' => array( 'type' => 'hidden', 'name' => 'privacy_object', 'value' => $sPrivacyObject, 'db' => array ( 'pass' => 'Xss', ), ), 'privacy_group_chooser' => $aInputPgc, 'controls' => array( 'name' => 'controls', 'type' => 'input_set', array( 'type' => 'button', 'name' => 'do_submit', 'value' => _t('_sys_submit'), 'attrs' => array( 'onclick' => "$('#" . $sFormId . "').submit()", ), ), array ( 'type' => 'reset', 'name' => 'do_cancel', 'value' => _t('_Cancel'), 'attrs' => array( 'onclick' => "$(this).parents('.bx-popup-applied:visible:first').dolPopupHide()", 'class' => 'bx-def-margin-sec-left', ), ) ) ) ); $oForm = new BxTemplFormView($aFormInfo); echo $this->oTemplate->parseHtmlByName('form_field_privacy_popup.html', array( 'form_id' => $oForm->getId(), 'form' => $oForm->getCode(true), )); } function setShowEmptySections($b) { $this->_bShowEmptySections = $b; } function setAjaxMode($bAjaxMode) { $this->_bAjaxMode = (bool)$bAjaxMode; } function isAjaxMode() { return $this->_bAjaxMode; } function isViewMode() { return (bool)($this->aParams['view_mode'] ?? 0); } function setAbsoluteActionUrl($sUrl) { if(empty($sUrl)) return; $this->aFormAttrs['action'] = $sUrl; $this->_bAbsoluteActionUrl = true; } /** * Return Form code * @param $bDynamicMode - set it to true if form is added via JS/AJAX call, for example form in AJAX popup. * @return string */ function getCode($bDynamicMode = false) { if(!$bDynamicMode && bx_is_dynamic_request()) $bDynamicMode = true; $this->_bDynamicMode = $bDynamicMode; $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs); $sInclude = ''; $this->sCode = false; /** * @hooks * @hookdef hook-system-form_output 'system', 'form_output' - hook to override form object and/or code to be output * - $unit_name - equals `system` * - $action - equals `form_output` * - $object_id - not used * - $sender_id - not used * - $extra_params - array of additional params with the following array keys: * - `dynamic` - [boolean] is dynamic mode * - `object` - [object] by ref, an instance of form class, @see BxDolForm, can be overridden in hook processing * - `code` - [boolean] or [string] by ref, when false the default generation mechanism will be used, can be overridden in hook processing * - `include` - [string] by ref, additional data to be attached to output, can be overridden in hook processing * @hook @ref hook-system-form_output */ bx_alert('system', 'form_output', 0, 0, [ 'dynamic' => $this->_bDynamicMode, 'object' => &$this, 'code' => &$this->sCode, 'include' => &$sInclude, 'code_ref' => &$this->sCode, 'include_ref' => &$sInclude, 'form_inputs_ref' => &$this->aInputs, ]); if($this->sCode === false) $this->sCode = $this->genForm(); $this->addCssJs(); $sDynamicCssJs = $this->_processCssJs(); return $sInclude . $sDynamicCssJs . $this->sCode; } function getCodeAPI() { $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs); $this->sCode = false; /** * @hooks * @hookdef hook-system-form_output_api 'system', 'form_output_api' - hook to override form object and/or code to be output. Is used in API calls. * - $unit_name - equals `system` * - $action - equals `form_output_api` * - $object_id - not used * - $sender_id - not used * - $extra_params - array of additional params with the following array keys: * - `dynamic` - [boolean] is dynamic mode * - `object` - [object] by ref, an instance of form class, @see BxDolForm, can be overridden in hook processing * - `code` - [boolean] by ref, when false the default generation mechanism will be used, can be overridden in hook processing * @hook @ref hook-system-form_output_api */ bx_alert('system', 'form_output_api', 0, 0, [ 'dynamic' => $this->_bDynamicMode, 'object' => &$this, 'code' => &$this->sCode, 'code_ref' => &$this->sCode, 'form_inputs_ref' => &$this->aInputs, ]); if($this->sCode === false) { if(!$this->genForm() && (bool)($this->aParams['view_mode'] ?? 0)) return []; } $oIconset = BxDolIconset::getObjectInstance(); $oFunctions = BxTemplFunctions::getInstanceWithTemplate($this->oTemplate); // TODO: process inputs to translate titles, alerts, etc $aInputs = []; foreach($this->aInputs as $sKey => $aInput) { if(isset($aInput['visible_for_levels']) && !self::isVisible($aInput)) continue; if(isset($aInput['type']) && in_array($aInput['name'], ['captcha'])) continue; list($sIcon, $sIconUrl, $sIconA, $sIconHtml) = $oFunctions->getIcon($aInput['icon'] ?? ''); $aInput['icon'] = $sIcon ? $oIconset->getIcon($sIcon) : ($sIconHtml ? $sIconHtml : ''); if(!empty($aInput['info'])) $aInput['info'] = strip_tags($aInput['info']); if(!empty($aInput['help'])) $aInput['help'] = strip_tags($aInput['help']); if(!empty($aInput['error'])) $aInput['error'] = strip_tags($aInput['error']); $bType = isset($aInput['type']); if ($bType && 'select' == $aInput['type']) { if(($sK1 = 'value') && empty($aInput[$sK1]) && ($aValues = $aInput['values'] ?? false) && is_array($aValues)) $aInput[$sK1] = reset($aValues)['key'] ?? key($aValues); } if ($bType && 'files' == $aInput['type']) { $oStorage = BxDolStorage::getObjectInstance($aInput['storage_object']); $aInput['ext_allow'] = $oStorage->getObjectData()['ext_allow']; $aInput['ext_deny'] = $oStorage->getObjectData()['ext_deny']; $aInput['ghost_template'] = ''; $aInput['value'] = ''; $aInput['values'] = ''; $aInput['values_src'] = ''; if(!empty($aInput['content_id']) && ($sUpr = reset($aInput['uploaders'])) && ($sStg = $aInput['storage_object'] ?? '') && ($oUploader = BxDolUploader::getObjectInstance($sUpr, $sStg, genRndPwd(8))) !== false) { $oUploader->setMultiple($aInput['multiple'] ?? true); if(($sMethod = 'setSubmitted') && method_exists($oUploader, $sMethod)) $oUploader->$sMethod($this->isSubmitted()); $sData = $oUploader->getGhostsWithOrder((int)bx_get_logged_profile_id(), 'json', $aInput['images_transcoder'], $aInput['content_id']); if($sData && ($aData = json_decode($sData, true)) && !empty($aData['g']) && is_array($aData['g'])) { $aInput['values_src'] = array_values($aData['g']); $aGhostIds = []; array_walk($aData['g'], function($aGhost) use (&$aGhostIds) { $aGhostIds[] = $aGhost['file_id']; }); $aInput['value'] = implode(',', $aGhostIds); } } } if ($bType && 'custom' == $aInput['type']){ $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']); if (method_exists($this, $sCustomMethod)) { $mixed = $this->$sCustomMethod($aInput); $aInput = is_array($mixed) ? $mixed : ['type' => 'custom', 'content' => $mixed]; } } if ($bType && 'block_header' == $aInput['type']){ $aInput['name'] = $sKey; } if ($bType && 'block_header' == $aInput['type']){ $aInput['name'] = $sKey; } if ($bType && 'location' == $aInput['type']){ $oLocation = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default')); $aVars = []; foreach(BxDolForm::$LOCATION_INDEXES as $sKey) $aVars[$sKey] = $oLocation->getLocationVal($aInput, $sKey, $this); if(($sLocationString = bx_api_get_location_string($aVars))) $aVars['location_string'] = $sLocationString; $aInput['value'] = $aVars; } if ($bType && 'textarea' == $aInput['type']) { $iTaHtml = (int)($aInput['html'] ?? 0); if(($sTaValue = $aInput['value'] ?? false) && $iTaHtml == 0) $aInput['value'] = strip_tags($sTaValue); if($iTaHtml != 0) $aInput['mentions'] = $this->getMentionsQueryParams($aInput); } if ($bType && 'price' == $aInput['type']) { $aInput['value'] = [ 'value' => $aInput['value'], 'currency' => BxDolPayments::getInstance()->getOption('default_currency_sign') ?: getParam('currency_sign') ]; } if ($this->_isSecretInput($aInput) && isset($aInput['value']) && $aInput['value'] !== '' && $aInput['value'] !== null && !is_array($aInput['value'])) { if (!$this->isViewMode() || !$this->_isSecretRevealed($aInput['name'])) $aInput['value'] = bx_gen_secret((string)$aInput['value']); } /** * Everytime when [key => value] is used it should be converted to [key => ..., value => ...] */ if (($sVt = $aInput['type'] ?? false) && in_array($sVt, ['select', 'select_multiple', 'checkbox_set', 'radio_set']) && is_array(($aVv = $aInput[($sKv = 'values')] ?? false)) && !(is_array(($aVv1 = reset($aVv))) && isset($aVv1['key'], $aVv1['value']))) { $aInput[$sKv] = array_map(function($sKey) use($aInput, $sKv) { return ['key' => $sKey, 'value' => $aInput[$sKv][$sKey]]; }, array_keys($aInput[$sKv])); } if(isset($aInput['name']) && in_array($aInput['name'], ['allow_view_to', 'object_privacy_view'])) { $aParams = bx_get('params'); if(empty($aParams) || !is_array($aParams)) $aParams = []; if(!isset($aParams['context_id']) || ($iContextId = (int)$aParams['context_id']) >= 0) { $oProfile = BxDolProfile::getInstance(); foreach($aInput['values'] as $aValue) { //--- Selected friends if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_FRIENDS_SELECTED) { $aIds = BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContent($oProfile->id(), true, 0, 20); if(!empty($aIds) && is_array($aIds)) { $aInput['values_friends'] = []; foreach($aIds as $iId) $aInput['values_friends'][] = ['key' => $iId, 'value' => BxDolProfile::getData($iId)]; } } //--- Selected relations if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_RELATIONS_SELECTED) { $aIds = BxDolConnection::getObjectInstance('sys_profiles_relations')->getConnectedContent($oProfile->id(), true, 0, 20); if(!empty($aIds) && is_array($aIds)) { $aInput['values_relations'] = []; foreach($aIds as $iId) $aInput['values_relations'][] = ['key' => $iId, 'value' => BxDolProfile::getData($iId)]; } } //--- Selected memberships if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_MEMBERSHIPS_SELECTED) { $aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true); if(!empty($aLevels) && is_array($aLevels)) { $aInput['values_memberships'] = []; foreach($aLevels as $iId => $sTitle) $aInput['values_memberships'][] = ['key' => $iId, 'value' => $sTitle]; } } } } else $aInput = array_merge($aInput, [ 'type' => 'hidden', 'value' => $iContextId, 'owner_info' => BxDolProfile::getData(abs($iContextId)) ]); } $aInputs[$sKey] = $aInput; } return [ 'inputs' => $aInputs, 'attrs' => $this->aFormAttrs, 'params' => $this->aParams ]; } public function getJsClassName() { return $this->_sJsClassName; } public function getJsObjectName() { return $this->_sJsObjectName; } public function getJsScript($bWrap = false) { $sJsObjName = $this->getJsObjectName(); $sJsObjClass = $this->getJsClassName(); $sCode = "if(window['" . $sJsObjName . "'] == undefined) window['" . $sJsObjName . "'] = new " . $sJsObjClass . "(" . json_encode(array( 'sObjName' => $sJsObjName, 'sId' => $this->getId(), 'sName' => $this->getName(), 'sObject' => isset($this->aParams['object']) ? $this->aParams['object'] : '', 'sDisplay' => isset($this->aParams['display']) ? $this->aParams['display'] : '', 'sRootUrl' => BX_DOL_URL_ROOT, 'aHtmlIds' => $this->_aHtmlIds, 'bInitCodeMirror' => self::$_isCssJsCodeMirrorAdded === true, 'bLeavePageConfirmation' => getParam('sys_form_lpc_enable') == 'on', 'sTxtLeavePageConfirmation' => _t('_sys_leave_page_confirmation') )) . "); window['" . $sJsObjName . "'].init();"; return $bWrap ? $this->oTemplate->_wrapInTagJsCode($sCode) : $sCode; } /** * Generate the whole form * * @return string */ function genForm() { $this->_sCodeAdd = ''; $bViewMode = $this->isViewMode(); $sTable = $this->genRows(); if($bViewMode && !$sTable) return ''; $sHtmlBefore = isset($this->aParams['html_before']) ? $this->aParams['html_before'] : ''; $sHtmlAfter = isset($this->aParams['html_after']) ? $this->aParams['html_after'] : ''; if (!empty($this->aParams['remove_form']) || $bViewMode) { $sForm = <<_sCodeAdd}
$sTable
$sHtmlAfter BLAH; } else { $sFormAttrs = bx_convert_array2attrs($this->aFormAttrs, 'bx-form-advanced'); $sAjaxFormJs = ''; if($this->_bAjaxMode) $sAjaxFormJs = <<id}").ajaxForm({ dataType: "json", beforeSubmit: function (formData, jqForm, options) { bx_loading($("form#{$this->id}"), true); }, success: function (oData) { bx_loading($("form#{$this->id}"), false); processJsonData(oData); } }); BLAH; $sJsCodeDynamic = ''; if($this->_bDynamicMode) $sJsCodeDynamic = 'function() {' . $this->getJsScript() . '}'; $sForm = << {$this->_sCodeAdd}
$sTable
$sHtmlAfter BLAH; } if(!$this->_bDynamicMode) $sForm = $sForm . $this->getJsScript(true); return $sForm; } /** * Generate Table HTML code * * @return string */ function genRows() { // add CSRF token if it's needed. 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) { $this->aInputs['csrf_token'] = array( 'type' => 'hidden', 'name' => 'csrf_token', 'value' => $mixedCsrfToken, 'db' => array ('pass' => 'Xss'), 'visible_for_levels' => PHP_INT_MAX, ); } // add 'Ajax Mode' flag if($this->_bAjaxMode) $this->aInputs['ajax_mode'] = array( 'type' => 'hidden', 'name' => 'ajax_mode', 'value' => 1, 'db' => array ('pass' => 'Int'), 'visible_for_levels' => PHP_INT_MAX, ); // add 'Absolute Action Url' flag if($this->_bAbsoluteActionUrl) $this->aInputs['absolute_action_url'] = array( 'type' => 'hidden', 'name' => 'absolute_action_url', 'value' => 1, 'db' => array ('pass' => 'Int'), 'visible_for_levels' => PHP_INT_MAX, ); // check if we need to generate open section clause $sOpenSection = ''; foreach ($this->aInputs as $aInput) { if (isset($aInput['type']) && 'hidden' == $aInput['type']) continue; if (isset($aInput['type']) && 'block_header' != $aInput['type']) $sOpenSection = $this->{$this->_sSectionOpen}(); break; } // generate rows contents $sCont = ''; $sContHeader = ''; $sContFields = ''; $sFuncGenRow = isset($this->aParams['view_mode']) && $this->aParams['view_mode'] ? 'genViewRow' : 'genRow'; foreach ($this->aInputs as &$aInput) { if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) { if ((isset($aInput['type']) && 'block_header' == $aInput['type']) && !$this->_bShowEmptySections) { // don't show section with no fields or with empty fields if ($sContHeader) { if ($sContFields) $sCont .= $sContHeader . $sContFields; else $sContHeader = ''; $sContFields = ''; } else { $sCont .= $sContFields; $sContFields = ''; } $sContHeader = $this->$sFuncGenRow($aInput); } else { $sContFields .= $this->$sFuncGenRow($aInput); } } } $sCont .= $sContHeader . $sContFields; $sCloseSection = $this->{$this->_sSectionClose}(); return $this->isViewMode() && !$sCont ? '' : $sOpenSection . $sCont . $sCloseSection; } /** * Generate single Table Row * * @param array $aInput * @return string */ function genRow(&$aInput) { if (!isset($aInput['type'])) $aInput['type'] = false; if (!empty($aInput['name'])) { $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']); if (method_exists($this, $sCustomMethod)) return $this->$sCustomMethod($aInput); } switch ($aInput['type']) { case 'block_header': $sRow = $this->genRowBlockHeader($aInput); break; case 'block_end': $sRow = $this->genBlockEnd($aInput); break; case 'hidden': // do not generate row for hidden inputs $sRow = ''; $this->_sCodeAdd .= $this->genInput($aInput); break; case 'select_box': $sRow = $this->genRowCustom($aInput, 'genInputSelectBox'); break; case 'files': $sRow = $this->genRowCustom($aInput, 'genInputFiles'); break; case 'switcher': case 'checkbox': $sRow = $this->genRowStandard($aInput, true); break; default: $sRow = $this->genRowStandard($aInput); } return $sRow; } public function isInputVisible($mixedInput) { if(!is_array($mixedInput) && isset($this->aInputs[$mixedInput])) $mixedInput = $this->aInputs[$mixedInput]; if(empty($mixedInput) || !is_array($mixedInput)) $mixedInput = BxDolFormQuery::getInputByName($this->aParams['object'], $mixedInput); if(empty($mixedInput) || !is_array($mixedInput)) return false; if(!empty($mixedInput['privacy']) && !empty($this->_iAuthorId) && !$this->_isInputVisibleByPrivacy($mixedInput)) return false; return true; } protected function _isInputVisibleByPrivacy($aInput) { $mixedResult = checkActionModule($this->_iAuthorId, 'set form fields privacy', 'system'); if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED) return true; $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId); if(empty($aInputPrivacy) || !is_array($aInputPrivacy)) if(BxDolFormQuery::setInputPrivacy($aInput['id'], $this->_iAuthorId, BxDolPrivacy::getFieldName($this->_sPrivacyObjectView), $this->_sPrivacyGroupDefault)) $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId); if((empty($aInputPrivacy) || !is_array($aInputPrivacy)) && $this->_sPrivacyGroupDefault != BX_DOL_PG_ALL) return false; $oPrivacy = BxDolPrivacy::getObjectInstance($this->_sPrivacyObjectView); if($oPrivacy && !$oPrivacy->check($aInputPrivacy['id'])) return false; return true; } /** * Generate single Table Row for view mode * * @param array $aInput * @return string */ function genViewRow(&$aInput) { if (!isset($aInput['type'])) $aInput['type'] = false; if(!$this->isInputVisible($aInput)) return ''; if (!empty($aInput['name'])) { $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']); if (method_exists($this, $sCustomMethod)) return $this->$sCustomMethod($aInput); } switch ($aInput['type']) { case 'block_header': $sRow = $this->genRowBlockHeader($aInput); break; case 'block_end': $sRow = $this->genBlockEnd($aInput); break; case 'nested_form': $sRow = $this->genNestedForm($aInput); break; case 'textarea': $sRow = $this->{'genViewRowWrapped' . ($aInput['html'] != 0 ? 'Html' : '')}($aInput); break; default: $sRow = $this->genViewRowWrapped($aInput); } return $sRow; } /** * Generate complete wrapped row for view mode form * * @param array $aInput * @return string */ function genViewRowWrapped(&$aInput) { return $this->_genViewRowWrapped($aInput); } function genViewRowWrappedHtml(&$aInput) { return $this->_genViewRowWrapped($aInput, [ 'class_value' => 'bx-def-vanilla-html max-w-none' ]); } protected function _genViewRowWrapped(&$aInput, $aParams = []) { $sValue = $this->genViewRowValue($aInput); if (null === $sValue) return ''; $sClass = !empty($aParams['class']) ? $aParams['class'] : ''; $sClassValue = !empty($aParams['class_value']) ? $aParams['class_value'] : ''; if ($this->_isSecretInput($aInput)) { $sValue = $this->_wrapSecretViewRowValue($aInput, $sValue, $this->_isSecretRevealed($aInput['name'])); $sClassValue .= ($sClassValue ? ' ' : '') . 'bx-form-row-view-value-secret'; } $aTmplVarsIcon = []; if(!empty($aInput['icon'])) $aTmplVarsIcon = [ 'icon' => $this->genIcon($aInput['icon']) ]; return $this->oTemplate->parseHtmlByName('form_view_row.html', [ 'type' => $aInput['type'], 'class' => $sClass, 'bx_if:show_icon' => [ 'condition' => !empty($aTmplVarsIcon), 'content' => $aTmplVarsIcon ], 'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '', 'class_value' => $sClassValue, 'value' => $sValue ]); } /** * Generate value for view mode row * * @param array $aInput * @return string */ function genViewRowValue(&$aInput) { if ($this->_isSecretInput($aInput) && !$this->_isSecretRevealed($aInput['name'])) { $sRaw = $this->_getSecretRawValue($aInput); return $sRaw !== '' ? bx_process_output(bx_gen_secret($sRaw)) : null; } if (!empty($aInput['name'])) { $sCustomMethod = 'genCustomViewRowValue' . $this->_genMethodName($aInput['name']); if (method_exists($this, $sCustomMethod)) return $this->$sCustomMethod($aInput); } switch ($aInput['type']) { case 'hidden': $sValue = null; break; case 'select': case 'radio_set': $sValue = $this->genViewRowValueForSelect($aInput); break; case 'dateselect': case 'datepicker': $sValue = null; if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value']) break; if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value'])) $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format']: BX_FORMAT_DATE, true, true); else $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true); break; case 'date_time': case 'datetime': $sValue = null; if(empty($aInput['value']) || !$aInput['value'] || '0000-00-00 00:00:00' == $aInput['value'] || '0000-00-00 00:00' == $aInput['value']) break; if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value'])) $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true, true); else $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true); break; case 'checkbox_set': case 'select_multiple': $sValue = null; if (!empty($aInput['value']) && is_array($aInput['value'])) { $sValue = ''; foreach ($aInput['value'] as $sVal) $sValue .= $aInput['values'][$sVal] . ', '; $sValue = trim ($sValue, ', '); } break; case 'checkbox': case 'switcher': $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off'); break; case 'textarea': if (isset($aInput['value']) && '' !== $aInput['value']) $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE); else $sValue = null; break; case 'text': if(isset($aInput['value']) && '' !== $aInput['value']) $sValue = bx_linkify(bx_process_output($aInput['value'])); else $sValue = null; break; case 'price': if(isset($aInput['value']) && $aInput['value'] !== '') $sValue = _t_format_currency(bx_process_output($aInput['value'])); else $sValue = null; break; default: if(isset($aInput['value']) && '' !== $aInput['value']) { $sValue = $aInput['value']; if(get_mb_substr($sValue, 0, 1) == '_') $sValue = _t($sValue); $sValue = bx_process_output($sValue); } else $sValue = null; } return $sValue; } function genViewRowValueForSelect(&$aInput) { if (!isset($aInput['value']) || !$aInput['value']) return null; $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null; if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])) !== false) return $oCategory->getCategoryLink($s, $aInput['value']); return $s; } protected function _isSecretInput($aInput) { return !empty($aInput['secret']) && !empty($aInput['name']); } protected function _isSecretRevealed($sName) { $mixed = bx_get('form_secret_reveal'); if ($mixed === false || $sName === '' || $sName === null) return false; if (is_array($mixed)) { if (!in_array((string)$sName, array_map('strval', $mixed), true)) return false; } else if ((string)$mixed !== (string)$sName) { return false; } if ($this->_bSecretRevealCsrfValid === null) { $mixedToken = bx_get('csrf_token'); $this->_bSecretRevealCsrfValid = BxDolForm::isCsrfTokenValid($mixedToken === false ? '' : $mixedToken); } return $this->_bSecretRevealCsrfValid; } protected function _getSecretRawValue(&$aInput) { if (!isset($aInput['value']) || $aInput['value'] === '' || $aInput['value'] === null || is_array($aInput['value'])) return ''; return (string)$aInput['value']; } protected function _wrapSecretViewRowValue(&$aInput, $sValue, $bRevealed = false) { $mixedToken = !$bRevealed ? BxDolForm::getCsrfToken() : false; return $this->oTemplate->parseHtmlByName('form_view_secret.html', [ 'class' => $bRevealed ? 'bx-form-secret-shown' : '', 'value' => $sValue, 'title' => bx_html_attribute(_t($bRevealed ? '_sys_form_secret_hide' : '_sys_form_secret_reveal')), 'name' => bx_html_attribute($aInput['name']), 'csrf' => $mixedToken ? bx_html_attribute($mixedToken) : '', 'icon' => $bRevealed ? 'eye-slash' : 'eye', ]); } protected function genCustomRowBirthday(&$aInput) { if(!$this->_bViewMode) return $this->genRowStandard($aInput); $sTxtAge = '_sys_form_input_age'; $aInput = array_merge($aInput, [ 'caption_src' => $sTxtAge, 'caption' => _t($sTxtAge), ]); if(bx_is_api()) $aInput = array_merge($aInput, [ 'type' => 'text', 'value' => bx_birthday2age($aInput['value']) ]); return $this->genViewRowWrapped($aInput); } protected function genCustomRowCf(&$aInput) { $aInput = BxDolContentFilter::getInstance()->getInput($aInput); if($aInput['type'] == 'hidden') { $this->_sCodeAdd .= $this->genInput($aInput); return ''; } return $this->genRowStandard($aInput); } protected function genCustomViewRowValueBirthday(&$aInput) { 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'))) return null; return bx_birthday2age($aInput['value']); } /** * Generate standard row * * @param array $aInput * @return string */ function genRowStandard(&$aInput, $isOneLine = false) { $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : ''; $sRequired = !empty($aInput['required']) ? '*' : ''; $sHelp = !empty($aInput['help']) ? ' ' : ''; $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : ''; $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : ''; $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']); $sClassWrapper = 'bx-form-element-wrapper'; if($isOneLine) $sClassWrapper .= ' ' . $sClassWrapper . '-oneline'; $sClassWrapper .= ' bx-def-margin-top-auto'; if (isset($aInput['name'])) { if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs'])) $aInput['tr_attrs'] = []; $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name']; } $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper); $sClassOneLineCaption = ''; $sClassOneLineValue = ''; if ($isOneLine) { $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' ltr:ml-4 rtl:mr-4'; $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type']; if (!isset($aInput['attrs']) || !is_array($aInput['attrs'])) $aInput['attrs'] = []; $aInput['attrs']['id'] = $this->getInputId($aInput); if ($sCaption) $sCaption = ''; } $sInput = $this->genInput($aInput); if(isset($aInput['error_updated']) && $aInput['error_updated'] === true) $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']); if(empty($sErrorIcon)) $sErrorIcon = ''; $aTmplVarsRow = array( 'bx_if:show_caption' => array( 'condition' => !empty($sCaption), 'content' => array( 'class_caption' => $sClassOneLineCaption, 'caption' => $sCaption, 'required' => $sRequired, 'help' => $sHelp, ) ), 'class_value' => $sClassAdd . $sClassOneLineValue, 'value' => $this->genWrapperInput($aInput, $sInput), 'info' => $sInfoIcon, 'error' => $sErrorIcon, ); return $this->oTemplate->parseHtmlByName('form_row_standard.html', array( 'tr_attrs' => $sTrAttrs, 'bx_if:show_one_line' => array( 'condition' => $isOneLine, 'content' => $aTmplVarsRow ), 'bx_if:show_lined' => array( 'condition' => !$isOneLine, 'content' => $aTmplVarsRow ), 'info' => $sInfoIcon, 'error' => $sErrorIcon )); } function genWrapperInput($aInput, $sContent) { $aAttrs = $this->_genWrapperInputAttrs($aInput); $sClass = "bx-form-input-wrapper bx-form-input-wrapper-{$aInput['type']}"; if(isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput)) $sClass .= ' bx-form-input-wrapper-html'; return $this->oTemplate->parseHtmlByName('form_input_wrapper.html', array( 'attrs' => bx_convert_array2attrs($aAttrs, $sClass), 'content' => $sContent )); } protected function _genWrapperInputAttrs(&$aInput) { return isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper']) ? $aInput['attrs_wrapper'] : []; } /** * Generate custom row * * @param array $aInput * @param string $sCustomMethod custom method to generate code for input * @return string */ function genRowCustom(&$aInput, $sCustomMethod) { $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : ''; $sRequired = !empty($aInput['required']) ? '*' : ''; $sHelp = !empty($aInput['help']) ? ' ' : ''; $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : ''; $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : ''; $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']); $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon); if (isset($aInput['name'])) { if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs'])) $aInput['tr_attrs'] = []; $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name']; } $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top"); return $this->oTemplate->parseHtmlByName('form_row_custom.html', array( 'tr_attrs' => $sTrAttrs, 'bx_if:show_caption' => array( 'condition' => !empty($sCaption), 'content' => array( 'class_caption' => '', 'caption' => $sCaption, 'required' => $sRequired, 'help' => $sHelp ) ), 'class_value' => $sClassAdd, 'value' => $sInput, )); } /** * Generate Block Headers row * * @param array $aInput * @return string */ function genRowBlockHeader(&$aInput) { $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs']; // if there is no caption - show divider only if (empty($aInput['caption'])) return $this->{$this->_sSectionOpen}($aAttrs); // if section is collapsed by default, add necessary code $sClassAddCollapsable = 'bx-form-collapsable'; if(isset($aInput['collapsed']) && $aInput['collapsed']) $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden'; // display section with caption if(empty($aAttrs)) $aAttrs = ['class' => $sClassAddCollapsable]; else $aAttrs['class'] .= ' ' . $sClassAddCollapsable; $bViewMode = !empty($this->aParams['view_mode']); $sCaption = bx_process_output($aInput['caption'], BX_DATA_HTML); $sInfo = !empty($aInput['info']) ? bx_process_output($aInput['info']) : ''; $bInfo = !empty($sInfo); $sTitle = $this->oTemplate->parseHtmlByName('form_field_section_title.html', [ 'bx_if:show_view' => [ 'condition' => $bViewMode, 'content' => [ 'caption' => $sCaption, 'bx_if:show_view_info' => [ 'condition' => $bInfo, 'content' => [ 'info' => $sInfo ] ] ] ], 'bx_if:show_default' => [ 'condition' => !$bViewMode, 'content' => [ 'caption' => $sCaption, 'bx_if:show_default_info' => [ 'condition' => $bInfo, 'content' => [ 'info' => $sInfo ] ] ] ] ]); if (isset($aInput['name'])) { if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs'])) $aInput['tr_attrs'] = []; $aInput['tr_attrs']['id'] = "bx-form-section-" . $aInput['name']; } return $this->{$this->_sSectionOpen}($aAttrs, $sTitle, !empty($aInput['tr_attrs']) ? $aInput['tr_attrs'] : []); } function genBlockEnd() { return $this->{$this->_sSectionClose}(); } /** * Generate HTML Input Element * * @param array $aInput * @return string Output HTML Code */ function genInput(&$aInput) { if (!empty($aInput['name'])) { $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']); if (method_exists($this, $sCustomMethod)) return $this->$sCustomMethod($aInput); } switch ($aInput['type']) { case 'datepicker': if (!isset($aInput['attrs'])) $aInput['attrs'] = array(); $aInput['attrs']['autosuggestion'] = 'off'; $sInput = $this->genInputStandard($aInput); break; // standard inputs (and non-standard, interpreted as standard) case 'text': case 'datepicker': case 'dateselect': case 'date_time': case 'datetime': case 'number': case 'time': case 'checkbox': case 'radio': case 'image': case 'slider': case 'doublerange': case 'hidden': $sInput = $this->genInputStandard($aInput); break; case 'phone': $aInput['type'] = 'text'; $sInput = $this->genInputStandard($aInput); break; case 'password': $sInput = $this->genInputPassword($aInput); break; case 'price': $sInput = $this->genInputPrice($aInput); break; case 'file': $sInput = $this->genInputFile($aInput); break; case 'rgb': case 'rgba': $sClass = 'bx-form-input-' . $aInput['type']; $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass; $aInput['type'] = 'text'; $sInput = $this->genInputStandard($aInput); break; case 'rgb-list': $sInput = $this->genInputSelectRgb($aInput); break; case 'switcher': $sInput = $this->genInputSwitcher($aInput); break; case 'button': case 'reset': case 'submit': $sInput = $this->genInputButton($aInput); break; case 'textarea': $sInput = $this->genInputTextarea($aInput); break; case 'select': $sInput = $this->genInputSelect($aInput); break; case 'select_multiple': $sInput = $this->genInputSelectMultiple($aInput); break; case 'checkbox_set': $sInput = $this->genInputCheckboxSet($aInput); break; case 'radio_set': $sInput = $this->genInputRadioSet($aInput); break; case 'input_set': // numeric array of inputs $sInput = ''; $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' '; foreach ($aInput as $iKey => $aSubInput) { if (!is_int($iKey) or !$aSubInput) continue; // parse only integer keys and existing values $sInput .= $this->genInput($aSubInput); // recursive call $sInput .= $sDivider; } $sInput .= '
'; break; case 'custom': $sInput = isset($aInput['content']) ? $aInput['content'] : ''; break; case 'captcha': $sInput = $this->genInputCaptcha($aInput); break; case 'location': $sInput = $this->genInputLocation($aInput); break; case 'nested_form': $sInput = $this->genInputNestedForm($aInput); break; case 'value': $sInput = ''; if(!isset($aInput['value'])) break; $sInput = $aInput['value']; if(get_mb_substr($sInput, 0, 1) == '_') $sInput = _t($sInput); break; default: //unknown control type $sInput = 'Unknown control type'; } // create input label $sInput .= $this->genLabel($aInput); // create input privacy group chooser $sInput .= $this->genPrivacyGroupChooser($aInput); return $sInput; } /** * Generate new Input Element id * * @param array $aInput * @return string */ function getInputId(&$aInput) { if (isset($aInput['id'])) return $aInput['id']; $sName = md5($aInput['name']); $sID = $this->id . '_input_' . $sName; if ( // multiple elements cause identical id's ( ( $aInput['type'] == 'checkbox' and substr($aInput['name'], -2) == '[]' // it is multiple element ) or $aInput['type'] == 'radio' // it is always multiple (i think so... hm) ) and isset($aInput['value']) // if we can make difference ) { $sValue = md5($aInput['value']); // add value $sID .= '_' . $sValue; } $sID = trim($sID, '_'); $aInput['id'] = $sID; // just for repeated calls return $sID; } /** * Generate standard Input Element * * @param array $aInput * @return string */ function genInputStandard(&$aInput) { $aAttrs = $this->_genInputStandardAttrs($aInput); $aAgent = []; if(!empty($this->_aAgentsFormObject) && isset($aInput['name'])) { foreach($this->_aAgentsFormObject as $a) { if($a['form_object'] == $this->_sAgentFormObject && $a['form_input'] == $aInput['name']) { $aAgent = $a; break; } } } $sAgentButton = ''; if($aInput['type'] == 'text' && !empty($aAgent)) { $sAgentButton = $this->oTemplate->parseHtmlByName('form_field_agent_button.html', [ 'input' => 'input', 'name' => $aInput['name'], 'agent_id' => $aAgent['id'] ?? 0, 'form_id' => $this->getId(), 'html' => $aInput['html'] ?? 0, 'popup_text' => $aInput['agent_popup_text'] ?? _t('_sys_agents_agent_form_input_popup_text'), ]); } return $this->oTemplate->parseHtmlByName('form_field_standard.html', [ 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}"), 'agent_button' => $sAgentButton, ]); } protected function _genInputStandardAttrs(&$aInput) { // clone attributes for system use ;) $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs']; // add default className to attributes $aAttrs['type'] = $aInput['type']; if ('datetime' == $aAttrs['type']) $aAttrs['type'] = 'date_time'; switch($aAttrs['type']) { case 'datepicker': case 'date_time': $this->addCssJsTimepicker (); break; case 'slider': case 'doublerange': $this->addCssJsUi (); break; case 'dateselect': if(!empty($aInput['value']) && strpos($aInput['value'], ' ') !== false) list($aInput['value']) = explode(' ', $aInput['value']); $this->_addJs(array( 'combodate/combodate.js', ), "'undefined' === typeof($.combodate)"); break; case 'text': if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb')) $this->addCssJsMinicolors (); break; } if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) { $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max']; } if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name']; if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value']; if ($aInput['type'] == 'text' && ($aInput['secret'] ?? false) && ($sValue = $aAttrs['value'] ?? false)) $aAttrs['value'] = bx_gen_secret($sValue); if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1; if (!isset($aAttrs['data-format-24h'])) $aAttrs['data-frmt-24h'] = getParam('sys_format_input_24h'); if (!isset($aAttrs['data-format-date'])) $aAttrs['data-frmt-date'] = getParam('sys_format_date'); if (!isset($aAttrs['data-format-datetime'])) $aAttrs['data-frmt-datetime'] = getParam('sys_format_datetime'); if(($sAreaLabel = $this->_genInputAreaLabel($aInput) ?: bx_html_attribute($this->_genInputCaption($aInput)))) $aAttrs['aria-label'] = $sAreaLabel; // for inputs with labels generate id if (isset($aInput['label'])) $aAttrs['id'] = $this->getInputId($aInput); // for checkboxes if (isset($aInput['checked']) and $aInput['checked']) $aAttrs['checked'] = 'checked'; return $aAttrs; } /** * Generate Switcher Input Element (based on checkbox) * * @param array $aInput * @return string */ function genInputSwitcher(&$aInput) { $aInput['type'] = 'checkbox'; $sCheckbox = $this->genInputStandard($aInput); $aInput['type'] = 'switcher'; $sClass = 'off'; if(isset($aInput['checked']) && $aInput['checked']) $sClass = 'on'; return $this->oTemplate->parseHtmlByName('form_field_switcher.html', [ 'class' => $sClass, 'checked' => $sClass == 'on' ? 'true' : 'false', // the button's initial aria-checked; jquery.webForms.js keeps it in step 'checkbox' => $sCheckbox, 'bx_if:show_label' => $this->genInputSwitcherLabel($aInput) ]); } /** * The switch's visible control is a button, not the checkbox the field's