| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaView UNA Studio Representation classes
- * @ingroup UnaStudio
- * @{
- */
- bx_import('BxTemplStudioFormsField');
- define('BX_DOL_STUDIO_FORMS_FIELDS_JS_OBJECT', 'oBxDolStudioFormsFields');
- class BxBaseStudioFormsFields extends BxDolStudioFormsFields
- {
- protected $sClass;
- protected $sUrlPage;
- function __construct($aOptions, $oTemplate = false)
- {
- parent::__construct($aOptions, $oTemplate);
- $this->_aConfirmMessages['delete'] = _t('_adm_form_txt_confirm_delete');
- $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_field_edit');
- $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_form_btn_field_delete');
- $this->sClass = 'BxTemplStudioFormsField';
- $this->sUrlPage = BX_DOL_URL_STUDIO . 'builder_forms.php?page=fields';
- }
- public function performActionAdd()
- {
- $sAction = 'add';
- $sType = '';
- if(($mixedType = bx_get('type')) !== false)
- $sType = bx_process_input($mixedType);
- $oClass = $this->_getFieldObject($sType, array('module' => $this->sModule, 'object' => $this->sObject, 'display' => $this->sDisplay));
- if($oClass === false || !$oClass->canAdd()) {
- echoJson(array('msg' => _t('_adm_form_err_field_add_not_allowed')));
- exit;
- }
- $mixedResult = $oClass->getCode($sAction, $this->_sObject);
- if(is_array($mixedResult))
- echoJson($mixedResult);
- else if(is_string($mixedResult))
- echoJson(array('popup' => array('html' => $mixedResult, 'options' => array('closeOnOuterClick' => false))));
- else if(is_int($mixedResult) || is_bool($mixedResult)) {
- $aResult = $mixedResult !== false ? array('grid' => $this->getCode(false), 'blink' => (int)$mixedResult) : array('msg' => _t('_adm_form_err_field_add'));
- echoJson($aResult);
- }
- }
- public function performActionEdit()
- {
- $sAction = 'edit';
- $aIds = bx_get('ids');
- if(!$aIds || !is_array($aIds)) {
- $iId = (int)bx_get('di_id');
- if(!$iId) {
- echoJson(array());
- exit;
- }
- $aIds = array($iId);
- }
- $iId = $aIds[0];
- $aField = array();
- $this->oDb->getInputs(array('type' => 'by_object_id', 'object' => $this->sObject, 'id' => (int)$iId), $aField, false);
- if(empty($aField) || !is_array($aField)) {
- echoJson(array());
- exit;
- }
- $sType = '';
- if(($mixedType = bx_get('type')) !== false)
- $aField['type'] = bx_process_input($mixedType);
-
- $oClass = $this->_getFieldObject($aField['type'], array('module' => $this->sModule, 'object' => $this->sObject, 'display' => $this->sDisplay), $aField);
- if($oClass === false) {
- echoJson(array());
- exit;
- }
- $mixedResult = $oClass->getCode($sAction, $this->_sObject);
- if(is_string($mixedResult))
- echoJson(array('popup' => array('html' => $mixedResult, 'options' => array('closeOnOuterClick' => false))));
- else if(is_bool($mixedResult)) {
- $aResult = $mixedResult ? array('grid' => $this->getCode(false), 'blink' => $iId) : array('msg' => _t('_adm_form_err_field_edit'));
- echoJson($aResult);
- }
- }
- public function performActionDelete()
- {
- $sAction = 'delete';
- $iAffected = 0;
- $aIds = bx_get('ids');
- if(!$aIds || !is_array($aIds)) {
- echoJson(array());
- exit;
- }
- $aIdsAffected = array ();
- foreach($aIds as $iId) {
- $aField = array();
- $this->oDb->getInputs(array('type' => 'by_object_id', 'object' => $this->sObject, 'id' => (int)$iId), $aField, false);
- if(empty($aField) || !is_array($aField))
- continue;
- if((int)$aField['deletable'] != 1)
- continue;
- $oClass = $this->_getFieldObject($aField['type'], array('module' => $this->sModule, 'object' => $this->sObject, 'display' => $this->sDisplay));
- if($oClass === false || (int)$this->_delete($iId) <= 0 || !$this->oDb->deleteInputs(array('type' => 'by_id', 'value' => $aField['id'], 'object' => $aField['object'], 'name' => $aField['name'])))
- continue;
- $oClass->alterRemove($aField['name']);
- $oLanguage = BxDolStudioLanguagesUtils::getInstance();
- if(!empty($aField['caption']))
- $oLanguage->deleteLanguageString($aField['caption']);
- if(!empty($aField['info']))
- $oLanguage->deleteLanguageString($aField['info']);
- if(!empty($aField['checker_error']))
- $oLanguage->deleteLanguageString($aField['checker_error']);
- $aIdsAffected[] = $iId;
- $iAffected++;
- }
- echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_from_err_field_delete')));
- }
- public function performActionShowTo()
- {
- $sAction = 'show_to';
- $aIds = bx_get('ids');
- if(!$aIds || !is_array($aIds)) {
- $iId = (int)bx_get('id');
- if(!$iId) {
- echoJson(array());
- exit;
- }
- $aIds = array($iId);
- }
- $iId = $aIds[0];
- $aField = array();
- $this->oDb->getInputs(array('type' => 'by_object_id', 'object' => $this->sObject, 'id' => (int)$iId), $aField, false);
- if(empty($aField) || !is_array($aField)) {
- echoJson(array());
- exit;
- }
- bx_import('BxDolStudioUtils');
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-form-field-visibility',
- 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&object=' . $this->sObject . '&display=' . $this->sDisplay,
- 'method' => 'post'
- ),
- 'params' => array (
- 'db' => array(
- 'table' => 'sys_form_display_inputs',
- 'key' => 'id',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ),
- ),
- 'inputs' => array (
- 'id' => array(
- 'type' => 'hidden',
- 'name' => 'id',
- 'value' => $iId,
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- 'visible_for' => array(
- 'type' => 'select',
- 'name' => 'visible_for',
- 'caption' => _t('_adm_form_txt_field_visible_for'),
- 'info' => '',
- 'value' => $aField['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
- 'values' => array(
- array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_form_txt_field_visible_for_all')),
- array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_form_txt_field_visible_for_selected')),
- ),
- 'required' => '0',
- 'attrs' => array(
- 'onchange' => $this->getJsObject() . '.onChangeVisibleFor(this)'
- ),
- 'db' => array (
- 'pass' => 'Xss',
- )
- ),
- 'visible_for_levels' => array(
- 'type' => 'checkbox_set',
- 'name' => 'visible_for_levels',
- 'caption' => _t('_adm_form_txt_field_visible_for_levels'),
- 'info' => _t('_adm_form_dsc_field_visible_for_levels'),
- 'value' => '',
- 'values' => array(),
- 'tr_attrs' => array(
- 'style' => $aField['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
- ),
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- 'controls' => array(
- 'name' => 'controls',
- 'type' => 'input_set',
- array(
- 'type' => 'submit',
- 'name' => 'do_submit',
- 'value' => _t('_adm_form_btn_field_save'),
- ),
- array (
- 'type' => 'reset',
- 'name' => 'close',
- 'value' => _t('_adm_form_btn_field_cancel'),
- 'attrs' => array(
- 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
- 'class' => 'bx-def-margin-sec-left',
- ),
- )
- )
- )
- );
- BxDolStudioUtils::getVisibilityValues($aField['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
- $oForm = new BxTemplStudioFormView($aForm);
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- if($oForm->updateWithVisibility($iId) !== false)
- $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
- else
- $aRes = array('msg' => _t('_adm_form_err_field_show_to'));
- echoJson($aRes);
- }
- else {
- $sCaption = _t($aField['caption_system']);
- if(empty($sCaption))
- $sCaption = _t($aField['caption']);
- $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-form-field-show-to-popup', _t('_adm_form_txt_field_show_to_popup', $sCaption), $this->_oTemplate->parseHtmlByName('form_add_field.html', array(
- 'form_id' => $aForm['form_attrs']['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- )));
- echoJson(array('popup' => $sContent));
- }
- }
- function getJsObject()
- {
- return BX_DOL_STUDIO_FORMS_FIELDS_JS_OBJECT;
- }
- function getDisplaysSelector($sModule = '')
- {
- $oForm = new BxTemplStudioFormView(array());
- $aInputDisplays = array(
- 'type' => 'select',
- 'name' => 'display',
- 'attrs' => array(
- 'id' => 'bx-grid-display-' . $this->_sObject,
- 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeDisplay()'
- ),
- 'value' => $this->sObject . $this->sParamsDivider . $this->sDisplay,
- 'values' => array(
- '' => _t('_adm_form_txt_select_display'),
- )
- );
- $aDisplays = array();
- if(!empty($sModule))
- $this->oDb->getDisplays(array('type' => 'by_module_with_forms', 'value' => $sModule), $aDisplays, false);
- else
- $aInputDisplays['attrs']['disabled'] = 'disabled';
- if(!empty($aDisplays)) {
- $aDisplaysGrouped = $aCounter = array();
- $this->oDb->getInputs(array('type' => 'counter_by_displays'), $aCounter, false);
- foreach($aDisplays as $aDisplay)
- $aDisplaysGrouped[_t($aDisplay['form_title'])][] = $aDisplay;
- ksort($aDisplaysGrouped);
- foreach($aDisplaysGrouped as $sForm => $aDisplays) {
- if(!empty($aDisplays))
- $aInputDisplays['values'][] = array('type' => 'group_header', 'value' => _t($aDisplays[0]['form_title']) . " (" . (isset($aCounter[$aDisplays[0]['name']]) ? $aCounter[$aDisplays[0]['name']] : "0") . ")");
- $aDisplaysSubgroup = array();
- foreach($aDisplays as $aDisplay)
- $aDisplaysSubgroup[$aDisplay['object'] . $this->sParamsDivider . $aDisplay['name']] = _t($aDisplay['title']);
- asort($aDisplaysSubgroup);
- $aInputDisplays['values'] = array_merge($aInputDisplays['values'], $aDisplaysSubgroup);
- if(!empty($aDisplays))
- $aInputDisplays['values'][] = array('type' => 'group_end');
- }
- }
- return $oForm->genRow($aInputDisplays);
- }
- function getCode($isDisplayHeader = true)
- {
- return $this->_oTemplate->parseHtmlByName('forms_fields.html', array(
- 'content' => parent::getCode($isDisplayHeader),
- 'js_object' => $this->getJsObject(),
- 'page_url' => $this->sUrlPage,
- 'grid_object' => $this->_sObject,
- 'params_divider' => $this->sParamsDivider
- ));
- }
- protected function _addJsCss()
- {
- parent::_addJsCss();
- $this->_oTemplate->addCss(array('menu.css'));
- $this->_oTemplate->addJs(array('jquery.form.min.js', 'forms_fields.js'));
- $oForm = new BxTemplStudioFormView(array());
- $oForm->addCssJs();
- }
- protected function _getFieldObject ($sType, $aParams = array(), $aField = array())
- {
- $sClass = $this->sClass . $this->getClassName($sType);
- if(!class_exists($sClass))
- return false;
- $oClass = new $sClass($aParams, $aField);
- $oClass->init();
- return $oClass;
- }
- protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
- {
- if(!$this->_isEditable($aRow))
- return parent::_getCellDefault('', $sKey, $aField, $aRow);
- return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellType ($mixedValue, $sKey, $aField, $aRow)
- {
- $mixedValue = $this->_oTemplate->getIcon('ui-' . $aRow['type'] . '.png', array('alt' => _t('_adm_form_txt_field_type_' . $aRow['type'])));
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellCaptionSystem ($mixedValue, $sKey, $aField, $aRow)
- {
- if(empty($mixedValue))
- $mixedValue = _t($aRow['caption']);
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
- {
- $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellVisibleForLevels ($mixedValue, $sKey, $aField, $aRow)
- {
- if(!$this->_isEditable($aRow))
- return parent::_getCellDefault('', $sKey, $aField, $aRow);
- $mixedValue = $this->_oTemplate->parseLink('javascript:void(0)', BxDolStudioUtils::getVisibilityTitle($aRow['visible_for_levels']), array(
- 'title' => _t('_adm_form_txt_fields_manage_visibility'),
- 'bx_grid_action_single' => 'show_to',
- 'bx_grid_action_data' => $aRow['id']
- ));
- return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getActionAdd ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- if($this->sDisplay == '')
- $isDisabled = true;
- return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
- }
- protected function _getActionEdit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- if($sType == 'single' && !$this->_isEditable($aRow))
- return '';
- return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
- }
- protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- if($sType == 'single' && !$this->_isDeletable($aRow))
- return '';
- return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
- }
- protected function _getActionShowTo ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- return '';
- }
- protected function _getActionsDisabledBehavior($aRow)
- {
- return false;
- }
- protected function _getFilterControls ()
- {
- parent::_getFilterControls();
- $sContent = $this->getModulesSelectOne('getInputs') . $this->getDisplaysSelector($this->sModule);
- $oForm = new BxTemplStudioFormView(array());
- $aInputSearch = array(
- 'type' => 'text',
- 'name' => 'keyword',
- 'attrs' => array(
- 'id' => 'bx-grid-search-' . $this->_sObject,
- ),
- 'tr_attrs' => array(
- 'style' => 'display:none;'
- )
- );
- $sContent .= $oForm->genRow($aInputSearch);
- return $sContent;
- }
- protected function _isEditable(&$aRow)
- {
- return (int)$aRow['editable'] != 0;
- }
- protected function _isDeletable(&$aRow)
- {
- return (int)$aRow['deletable'] != 0;
- }
- }
- /** @} */
|