| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- <?php
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup DolphinView Dolphin Studio Representation classes
- * @ingroup DolphinStudio
- * @{
- */
- defined('BX_DOL') or die('hack attempt');
- bx_import('BxDolStudioPermissionsLevels');
- bx_import('BxTemplStudioFormView');
- class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels {
- public static $iBinMB = 1048576;
- function __construct($aOptions, $oTemplate = false) {
- parent::__construct($aOptions, $oTemplate);
- $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_prm_btn_level_edit');
- $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_prm_btn_level_delete');
- }
- public function performActionAdd() {
- $sAction = 'add';
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-prm-level-create',
- 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
- 'method' => BX_DOL_STUDIO_METHOD_DEFAULT,
- 'enctype' => 'multipart/form-data',
- ),
- 'params' => array (
- 'db' => array(
- 'table' => 'sys_acl_levels',
- 'key' => 'ID',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ),
- ),
- 'inputs' => array (
- 'Active' => array(
- 'type' => 'hidden',
- 'name' => 'Active',
- 'value' => 'yes',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'Purchasable' => array(
- 'type' => 'hidden',
- 'name' => 'Purchasable',
- 'value' => 'no',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'Removable' => array(
- 'type' => 'hidden',
- 'name' => 'Removable',
- 'value' => 'yes',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'Name' => array(
- 'type' => 'text_translatable',
- 'name' => 'Name',
- 'caption' => _t('_adm_prm_txt_level_name'),
- 'info' => _t('_adm_prm_dsc_level_name'),
- 'value' => '_adm_prm_txt_level',
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- 'checker' => array (
- 'func' => 'LengthTranslatable',
- 'params' => array(3, 100, 'Name'),
- 'error' => _t('_adm_prm_err_level_name'),
- ),
- ),
- 'Description' => array(
- 'type' => 'textarea_translatable',
- 'name' => 'Description',
- 'caption' => _t('_adm_prm_txt_level_description'),
- 'info' => _t('_adm_prm_dsc_level_description'),
- 'value' => '_adm_prm_txt_level',
- 'db' => array (
- 'pass' => 'XssHtml',
- )
- ),
- 'QuotaSize' => array(
- 'type' => 'text',
- 'name' => 'QuotaSize',
- 'caption' => _t('_adm_prm_txt_level_quota_size'),
- 'info' => _t('_adm_prm_dsc_level_quota_size'),
- 'value' => '0',
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Float',
- ),
- 'checker' => array (
- 'func' => 'preg',
- 'params' => array('/^[0-9\.]+$/'),
- 'error' => _t('_adm_prm_err_level_quota_size'),
- ),
- ),
- 'QuotaMaxFileSize' => array(
- 'type' => 'text',
- 'name' => 'QuotaMaxFileSize',
- 'caption' => _t('_adm_prm_txt_level_quota_max_file_size'),
- 'info' => _t('_adm_prm_dsc_level_quota_max_file_size'),
- 'value' => '',
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Float',
- ),
- 'checker' => array (
- 'func' => 'preg',
- 'params' => array('/^[0-9\.]+$/'),
- 'error' => _t('_adm_prm_err_level_quota_max_file_size'),
- ),
- ),
- 'QuotaNumber' => array(
- 'type' => 'text',
- 'name' => 'QuotaNumber',
- 'caption' => _t('_adm_prm_txt_level_quota_number'),
- 'info' => _t('_adm_prm_dsc_level_quota_number'),
- 'value' => '0',
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Int',
- ),
- 'checker' => array (
- 'func' => 'preg',
- 'params' => array('/^[0-9]+$/'),
- 'error' => _t('_adm_prm_err_level_quota_number'),
- ),
- ),
- 'Icon' => array(
- 'type' => 'file',
- 'name' => 'Icon',
- 'caption' => _t('_adm_prm_txt_level_icon'),
- 'value' => '',
- 'checker' => array (
- 'func' => '',
- 'params' => '',
- 'error' => _t('_adm_prm_err_level_icon'),
- ),
- ),
- 'controls' => array(
- 'name' => 'controls',
- 'type' => 'input_set',
- array(
- 'type' => 'submit',
- 'name' => 'do_submit',
- 'value' => _t('_adm_prm_btn_level_add'),
- ),
- array (
- 'type' => 'reset',
- 'name' => 'close',
- 'value' => _t('_adm_prm_btn_level_cancel'),
- 'attrs' => array(
- 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
- 'class' => 'bx-def-margin-sec-left',
- ),
- )
- )
- )
- );
- $oForm = new BxTemplStudioFormView($aForm);
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- if(($iId = $this->getAvailableId()) === false) {
- $this->_echoResultJson(array('msg' => _t('_adm_prm_err_level_id')), true);
- return;
- }
- $mixedIcon = 'acl-unconfirmed.png';
- if(!empty($_FILES['Icon']['tmp_name'])) {
- bx_import('BxDolStorage');
- $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
-
- $mixedIcon = $oStorage->storeFileFromForm($_FILES['Icon'], false, 0);
- if($mixedIcon === false) {
- $this->_echoResultJson(array('msg' => _t('_adm_prm_err_level_icon') . $oStorage->getErrorString()), true);
- return;
- }
- $oStorage->afterUploadCleanup($mixedIcon, 0);
- }
- $fQuotaSize = round($oForm->getCleanValue('QuotaSize'), 1);
- BxDolForm::setSubmittedValue('QuotaSize', self::$iBinMB * $fQuotaSize, $aForm['form_attrs']['method']);
- $fQuotaMaxFileSize = round($oForm->getCleanValue('QuotaMaxFileSize'), 1);
- BxDolForm::setSubmittedValue('QuotaMaxFileSize', self::$iBinMB * $fQuotaMaxFileSize, $aForm['form_attrs']['method']);
- $iId = (int)$oForm->insert(array('ID' => $iId, 'Icon' => $mixedIcon, 'Order' => $this->oDb->getLevelOrderMax() + 1));
- if($iId != 0)
- $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
- else
- $aRes = array('msg' => _t('_adm_prm_err_level_create'));
- $this->_echoResultJson($aRes, true);
- }
- else {
- bx_import('BxTemplStudioFunctions');
- $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-prm-level-create-popup', _t('_adm_prm_txt_level_create_popup'), $this->_oTemplate->parseHtmlByName('prm_add_level.html', array(
- 'form_id' => $aForm['form_attrs']['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- )));
- $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
- }
- }
- public function performActionEdit() {
- $sAction = 'edit';
- $aIds = bx_get('ids');
- if(!$aIds || !is_array($aIds)) {
- $iId = (int)bx_get('id');
- if(!$iId) {
- $this->_echoResultJson(array());
- exit;
- }
- $aIds = array($iId);
- }
- $iId = $aIds[0];
- $aLevel = array();
- $iLevel = $this->oDb->getLevels(array('type' => 'by_id', 'value' => $iId), $aLevel);
- if($iLevel != 1 || empty($aLevel)){
- $this->_echoResultJson(array());
- exit;
- }
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-prm-level-edit',
- 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
- 'method' => 'post',
- 'enctype' => 'multipart/form-data',
- ),
- 'params' => array (
- 'db' => array(
- 'table' => 'sys_acl_levels',
- 'key' => 'ID',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ),
- ),
- 'inputs' => array (
- 'id' => array(
- 'type' => 'hidden',
- 'name' => 'id',
- 'value' => $iId,
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- 'Description' => array(
- 'type' => 'textarea_translatable',
- 'name' => 'Description',
- 'caption' => _t('_adm_prm_txt_level_description'),
- 'info' => _t('_adm_prm_dsc_level_description'),
- 'value' => $aLevel['description'],
- 'db' => array (
- 'pass' => 'XssHtml',
- ),
- ),
- 'QuotaSize' => array(
- 'type' => 'text',
- 'name' => 'QuotaSize',
- 'caption' => _t('_adm_prm_txt_level_quota_size'),
- 'info' => _t('_adm_prm_dsc_level_quota_size'),
- 'value' => round($aLevel['quota_size'] / self::$iBinMB, 1),
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Float',
- ),
- 'checker' => array (
- 'func' => 'preg',
- 'params' => array('/^[0-9\.]+$/'),
- 'error' => _t('_adm_prm_err_level_quota_size'),
- ),
- ),
- 'QuotaMaxFileSize' => array(
- 'type' => 'text',
- 'name' => 'QuotaMaxFileSize',
- 'caption' => _t('_adm_prm_txt_level_quota_max_file_size'),
- 'info' => _t('_adm_prm_dsc_level_quota_max_file_size'),
- 'value' => round($aLevel['quota_max_file_size'] / self::$iBinMB, 1),
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Float',
- ),
- 'checker' => array (
- 'func' => 'preg',
- 'params' => array('/^[0-9\.]+$/'),
- 'error' => _t('_adm_prm_err_level_quota_max_file_size'),
- ),
- ),
- 'QuotaNumber' => array(
- 'type' => 'text',
- 'name' => 'QuotaNumber',
- 'caption' => _t('_adm_prm_txt_level_quota_number'),
- 'info' => _t('_adm_prm_dsc_level_quota_number'),
- 'value' => $aLevel['quota_number'],
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Int',
- ),
- 'checker' => array (
- 'func' => 'preg',
- 'params' => array('/^[0-9]+$/'),
- 'error' => _t('_adm_prm_err_level_quota_number'),
- ),
- ),
- 'Icon' => array(
- 'type' => 'file',
- 'name' => 'Icon',
- 'caption' => _t('_adm_prm_txt_level_icon'),
- 'value' => '',
- 'checker' => array (
- 'func' => '',
- 'params' => '',
- 'error' => _t('_adm_prm_err_level_icon'),
- ),
- ),
- 'controls' => array(
- 'name' => 'controls',
- 'type' => 'input_set',
- array(
- 'type' => 'submit',
- 'name' => 'do_submit',
- 'value' => _t('_adm_prm_btn_level_save'),
- ),
- array (
- 'type' => 'reset',
- 'name' => 'close',
- 'value' => _t('_adm_prm_btn_level_cancel'),
- 'attrs' => array(
- 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
- 'class' => 'bx-def-margin-sec-left',
- ),
- )
- )
- )
- );
- bx_import('BxTemplStudioFormView');
- $oForm = new BxTemplStudioFormView($aForm);
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- $mixedIcon = 0;
- if(!empty($_FILES['Icon']['tmp_name'])) {
- bx_import('BxDolStorage');
- $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
-
- if(is_numeric($aLevel['icon']) && (int)$aLevel['icon'] != 0 && !$oStorage->deleteFile((int)$aLevel['icon'], 0)) {
- $this->_echoResultJson(array('msg' => _t('_adm_prm_err_level_icon_remove')), true);
- return;
- }
- $mixedIcon = $oStorage->storeFileFromForm($_FILES['Icon'], false, 0);
- if($mixedIcon === false) {
- $this->_echoResultJson(array('msg' => _t('_adm_prm_err_level_icon') . $oStorage->getErrorString()), true);
- return;
- }
- $oStorage->afterUploadCleanup($mixedIcon, 0);
- }
- $fQuotaSize = round($oForm->getCleanValue('QuotaSize'), 1);
- BxDolForm::setSubmittedValue('QuotaSize', self::$iBinMB * $fQuotaSize, $aForm['form_attrs']['method']);
- $fQuotaMaxFileSize = round($oForm->getCleanValue('QuotaMaxFileSize'), 1);
- BxDolForm::setSubmittedValue('QuotaMaxFileSize', self::$iBinMB * $fQuotaMaxFileSize, $aForm['form_attrs']['method']);
- if($oForm->update($iId, (int)$mixedIcon != 0 ? array('Icon' => $mixedIcon) : array()) !== false)
- $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
- else
- $aRes = array('msg' => _t('_adm_prm_err_level_edit'));
- $this->_echoResultJson($aRes, true);
- }
- else {
- bx_import('BxTemplStudioFunctions');
- $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-prm-level-edit-popup', _t('_adm_prm_txt_level_edit_popup', _t($aLevel['name'])), $this->_oTemplate->parseHtmlByName('prm_add_level.html', array(
- 'form_id' => $aForm['form_attrs']['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- )));
- $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
- }
- }
- public function performActionDelete() {
- $iAffected = 0;
- $aIds = bx_get('ids');
- if(!$aIds || !is_array($aIds)) {
- $this->_echoResultJson(array());
- exit;
- }
- $aIdsAffected = array ();
- foreach($aIds as $iId) {
- if(!$this->delete($iId))
- continue;
- $aIdsAffected[] = $iId;
- $iAffected++;
- }
- $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_prm_err_level_delete')));
- }
- protected function _addJsCss() {
- parent::_addJsCss();
- $this->_oTemplate->addJs(array('jquery.form.js'));
- bx_import('BxTemplStudioFormView');
- $oForm = new BxTemplStudioFormView(array());
- $oForm->addCssJs();
- }
- protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow) {
- bx_import('BxDolAcl');
- if(in_array($aRow['ID'], array(MEMBERSHIP_ID_NON_MEMBER, MEMBERSHIP_ID_STANDARD, MEMBERSHIP_ID_UNCONFIRMED, MEMBERSHIP_ID_PENDING, MEMBERSHIP_ID_SUSPENDED)))
- return parent::_getCellDefault('', $sKey, $aField, $aRow);;
- return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow) {
- $mixedValue = $this->_oTemplate->getImage($mixedValue, array('class' => 'bx-prm-level-icon bx-def-border'));
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellActionsList ($mixedValue, $sKey, $aField, $aRow) {
- $aActions = array();
- $iActions = $this->oDb->getActions(array('type' => 'by_level_id', 'value' => $aRow['ID']), $aActions);
- $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
- 'href' => BX_DOL_URL_STUDIO . 'builder_permissions.php?page=actions&level=' . $aRow['ID'],
- 'title' => _t('_adm_prm_txt_manage_actions'),
- 'bx_repeat:attrs' => array(),
- 'content' => _t('_adm_prm_txt_n_actions', $iActions)
- ));
- return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellQuotaSize ($mixedValue, $sKey, $aField, $aRow) {
- return parent::_getCellDefault ($mixedValue > 0 ? _t_format_size($mixedValue) : '∞', $sKey, $aField, $aRow);
- }
- protected function _getCellQuotaNumber ($mixedValue, $sKey, $aField, $aRow) {
- return parent::_getCellDefault ($mixedValue > 0 ? $mixedValue : '∞', $sKey, $aField, $aRow);
- }
- protected function _getCellQuotaMaxFileSize ($mixedValue, $sKey, $aField, $aRow) {
- return parent::_getCellDefault ($mixedValue > 0 ? _t_format_size($mixedValue) : '∞', $sKey, $aField, $aRow);
- }
- protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
- if ($sType == 'single' && $aRow['Removable'] != 'yes')
- return '';
- return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
- }
- protected function getAvailableId() {
- $aLevels = array();
- $this->oDb->getLevels(array('type' =>'all_order_id'), $aLevels, false);
- $iId = 1;
- foreach($aLevels as $aLevel) {
- if($iId != (int)$aLevel['id'])
- break;
- $iId++;
- }
- return $iId <= BX_DOL_STUDIO_PERMISSIONS_LEVEL_ID_INT_MAX ? $iId : false;
- }
- }
- /** @} */
|