HomeHelpTrac

Changeset 15347 for trunk/administration


Ignore:
Timestamp:
07/14/11 03:07:34 (11 months ago)
Author:
Anton Lesnikov
Message:

Transfer changes from Ticket 2569(Dolphin 7.0.7)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/administration/memb_levels.php

    r15331 r15347  
    100100$_page_cont[$iNameIndex] = array( 
    101101    'page_code_settings' => PageCodeSettings($mixedResultSettings), 
    102     'page_code_create' => PageCodeCreate(), 
     102    'page_code_create' => PageCodeCreate(bx_get('action') !== false && bx_get('action') == 'edit' ? $iLevelId : 0), 
    103103    'page_code_available' => PageCodeAvailable($mixedResultAvailable), 
    104104    'page_code_actions' => bx_get('action') !== false && bx_get('action') == 'actions' && $iLevelId > 0 ? PageCodeActions($iLevelId, $mixedResultActions) : "", 
     
    115115    return DesignBoxAdmin(_t('_adm_box_cpt_mlevel_settings'), $sResult); 
    116116} 
    117 function PageCodeCreate() { 
     117function PageCodeCreate($iLevelId = 0) { 
     118    $sSubmitUrl = $GLOBALS['site']['url_admin'] . 'memb_levels.php'; 
     119 
     120    $aLevel = array(); 
     121    if(($bEdit = $iLevelId != 0) === true) 
     122        $aLevel = $GLOBALS['MySQL']->getRow("SELECT `Name` AS `Name`, `Description` AS `Description`, `Order` AS `Order` FROM `sys_acl_levels` WHERE `ID`='" . $iLevelId . "' LIMIT 1"); 
     123 
    118124    $aForm = array( 
    119125        'form_attrs' => array( 
    120126            'id' => 'adm-mlevels-create', 
    121             'action' => $GLOBALS['site']['url_admin'] . 'memb_levels.php', 
     127            'action' => $sSubmitUrl, 
    122128            'method' => 'post', 
    123129            'enctype' => 'multipart/form-data', 
     
    129135                'uri' => '', 
    130136                'uri_title' => '', 
    131                 'submit_name' => 'submit' 
     137                'submit_name' => 'Submit' 
    132138            ), 
    133139        ), 
    134         'inputs' => array ( 
     140        'inputs' => array (             
    135141            'Active' => array( 
    136142                'type' => 'hidden', 
     
    159165            'Name' => array( 
    160166                'type' => 'text', 
    161                 'name' => 'name', 
     167                'name' => 'Name', 
    162168                'caption' => _t('_adm_txt_mlevels_name'), 
    163                 'value' => '', 
     169                'value' => isset($aLevel['Name']) ? $aLevel['Name'] : '', 
    164170                'db' => array ( 
    165171                    'pass' => 'Xss', 
     
    184190            'Description' => array( 
    185191                'type' => 'textarea', 
    186                 'name' => 'description', 
     192                'name' => 'Description', 
    187193                'caption' => _t('_adm_txt_mlevels_description'), 
    188                 'value' => '', 
     194                'value' => isset($aLevel['Description']) ? $aLevel['Description'] : '', 
    189195                'db' => array ( 
    190196                    'pass' => 'XssHtml', 
    191197                ), 
    192198            ), 
    193             'submit' => array( 
     199            'Order' => array( 
     200                'type' => 'text', 
     201                'name' => 'Order', 
     202                'caption' => _t('_adm_txt_mlevels_order'), 
     203                'value' => isset($aLevel['Order']) ? $aLevel['Order'] : 0, 
     204                'db' => array ( 
     205                    'pass' => 'Int', 
     206                ), 
     207                'checker' => array ( 
     208                    'func' => 'preg', 
     209                    'params' => array('/^[1-9][0-9]*$/'), 
     210                    'error' => _t('_adm_txt_mlevels_order_err'), 
     211                ), 
     212            ), 
     213            'Submit' => array( 
    194214                'type' => 'submit', 
    195                 'name' => 'submit', 
     215                'name' => 'Submit', 
    196216                'value' => _t('_adm_btn_mlevels_add'), 
    197             ), 
     217            ),                 
    198218        ) 
    199219    ); 
     220 
     221    //--- Convert Add to Edit 
     222    if($bEdit) { 
     223        unset($aForm['inputs']['Active']); 
     224        unset($aForm['inputs']['Purchasable']); 
     225        unset($aForm['inputs']['Removable']); 
     226        unset($aForm['inputs']['Icon']); 
     227 
     228        $aForm['form_attrs']['action'] .= '?action=edit&level=' . $iLevelId; 
     229        $aForm['inputs']['Submit']['value'] = _t('_adm_btn_mlevels_save'); 
     230        $aForm['inputs']['ID'] = array( 
     231            'type' => 'hidden', 
     232            'name' => 'ID', 
     233            'value' => $iLevelId, 
     234            'db' => array ( 
     235                'pass' => 'Int', 
     236            ) 
     237        ); 
     238    } 
     239 
    200240    $oForm = new BxTemplFormView($aForm); 
    201241    $oForm->initChecker(); 
    202242 
    203     $bFile = true; 
    204     $sFilePath = BX_DIRECTORY_PATH_ROOT . 'media/images/membership/'; 
    205     $sFileName = time(); 
    206     $sFileExt = ''; 
    207     if($oForm->isSubmittedAndValid() && $bFile = (isImage($_FILES['Icon']['type'], $sFileExt) && !empty($_FILES['Icon']['tmp_name']) && move_uploaded_file($_FILES['Icon']['tmp_name'],  $sFilePath . $sFileName . '.' . $sFileExt))) { 
    208         $sPath = $sFilePath . $sFileName . '.' . $sFileExt; 
    209         imageResize($sPath, $sPath, 110, 110); 
    210  
    211         $iId = (int)$oForm->insert(array('Icon' => $sFileName . '.' . $sFileExt)); 
    212         if($iId != 0) 
    213             addStringToLanguage("_adm_txt_mp_" . strtolower(bx_get('name')), bx_get('name')); 
    214  
    215          header('Location: ' . $oForm->aFormAttrs['action']); 
    216     } else { 
    217         if(!$bFile) 
    218             $oForm->aInputs['Icon']['error'] = $oForm->aInputs['Icon']['checker']['error']; 
    219  
    220         return DesignBoxAdmin(_t('_adm_box_cpt_mlevel_create'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode()))); 
     243    if($oForm->isSubmittedAndValid()) { 
     244        //--- Add new level 
     245        if(!$bEdit) { 
     246            $sFilePath = BX_DIRECTORY_PATH_ROOT . 'media/images/membership/'; 
     247            $sFileName = time(); 
     248            $sFileExt = ''; 
     249 
     250            if(isImage($_FILES['Icon']['type'], $sFileExt) && !empty($_FILES['Icon']['tmp_name']) && move_uploaded_file($_FILES['Icon']['tmp_name'],  $sFilePath . $sFileName . '.' . $sFileExt)) { 
     251                $sPath = $sFilePath . $sFileName . '.' . $sFileExt; 
     252                imageResize($sPath, $sPath, 110, 110); 
     253 
     254                $iId = (int)$oForm->insert(array('Icon' => $sFileName . '.' . $sFileExt)); 
     255                if($iId != 0) { 
     256                    $sName = $oForm->getCleanValue('Name'); 
     257                    addStringToLanguage('_adm_txt_mp_' . strtolower($sName), $sName); 
     258                } 
     259 
     260                header('Location: ' . $sSubmitUrl); 
     261                exit; 
     262            } 
     263            else 
     264                $oForm->aInputs['Icon']['error'] = $oForm->aInputs['Icon']['checker']['error']; 
     265        } 
     266        //--- Edit existing level 
     267        else { 
     268            $bResult = $oForm->update($iLevelId); 
     269            if($bResult !== false) { 
     270                deleteStringFromLanguage('_adm_txt_mp_' . strtolower($aLevel['Name'])); 
     271 
     272                $sName = $oForm->getCleanValue('Name'); 
     273                addStringToLanguage('_adm_txt_mp_' . strtolower($sName), $sName); 
     274            } 
     275 
     276            header('Location: ' . $sSubmitUrl); 
     277            exit; 
     278        } 
    221279    } 
     280 
     281    return DesignBoxAdmin(_t(!$bEdit ? '_adm_box_cpt_mlevel_create' : '_adm_box_cpt_mlevel_edit'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode()))); 
    222282} 
    223283function PageCodeAvailable($mixedResult) { 
Note: See TracChangeset for help on using the changeset viewer.