/**
  * 角色主页面
  */
 public function cRoleIndex()
 {
     $this->_modelRole = $this->getGlobal('model/Role', 'Model_Role');
     $dataList = $this->_modelRole->getAll();
     $this->assign('dataList', $dataList);
     $this->display(VIEW_PAGE);
 }
 /**
  * 编辑用户
  */
 public function cEdit()
 {
     $this->_modelUser = $this->getGlobal('model/User', 'Model_User');
     if ($this->isPost()) {
         $postArr = array('id' => intval($this->getR('id')), 'vuser' => $this->getR('vuser'), 'pwd' => $this->getR('pwd'), 'pwd1' => $this->getR('pwd1'), 'role' => $this->getR('role'), 'login_count' => RegistryRequest::getInstance()->absInt('login_count'));
         $info = $this->_modelUser->edit($postArr);
         if ($info['status'] == 1) {
             $this->success($info['info'], $info['url']);
         } else {
             $this->error($info['info'], $info['url']);
         }
     } else {
         $this->_modelRole = $this->getGlobal('model/Role', 'Model_Role');
         $roles = $this->_modelRole->getAll();
         $this->assign('roleList', $roles);
         $dataList = $this->_modelUser->findById($this->getR('id'));
         $dataList['role'] = $dataList['role'] ? explode(',', $dataList['role']) : array();
         $this->assign('dataList', $dataList);
         $this->display(VIEW_PAGE);
     }
 }
Пример #3
0
 public function userAction($iId = null)
 {
     $this->mTemplate->sSectionTitle = $this->getLang('section_title_useredit');
     // sprawdzamy czy user jest adminem
     if ($this->sRole !== 'admin') {
         $aData['info'] = $this->getLang('access_denied');
         $this->mTemplate->content = View::factory('account/item_edit', $aData)->render();
         return;
     }
     if (isset($iId) and $iId !== 0 and !isset($_POST['submit'])) {
         // edycja usera
         $bDelete = func_get_arg(0) == 'delete';
         if ($bDelete) {
             $iId = func_get_arg(1);
         }
         $iId = (int) $iId;
         $oUser = new Model_User($iId);
         $aUser = $oUser->getRow();
         if ($iId and !empty($aUser) and $aUser['account_id'] == $this->oCurrentUser->account_id) {
             if ($bDelete) {
                 // usuwanie uzytkownika
                 if (func_num_args() == 4 and $this->oAuth->isValidToken(func_get_arg(2))) {
                     if ($oUser->delete()) {
                         $aMeta = $this->mTemplate->aMeta;
                         $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />';
                         $this->mTemplate->aMeta = $aMeta;
                         $aData['info'] = $this->getLang('delele_user_successfull');
                     } else {
                         $aData['info'] = $this->getLang('delele_user_failed');
                     }
                 } else {
                     // potwierdzenie usuniecia
                     $aData = array('sQuestion' => $this->getLang('delele_user_question', $aUser['name']), 'sTextYes' => $this->getLang('Catering.ok'), 'sLinkYes' => '/account/user/delete/' . $iId . '/' . $this->oAuth->getSecurityToken() . '/', 'sTextNo' => $this->getLang('Catering.cancel'), 'sLinkNo' => '/account/user/' . $iId . '/');
                 }
                 $this->mTemplate->sSectionTitle = $this->getLang('section_title_userdelete');
             } else {
                 // edycja danych
                 $aOptions = array();
                 $aLayoutList = array();
                 $oRole = new Model_Role();
                 $aRoles = $oRole->getAll();
                 foreach ($aRoles as $aRole) {
                     $aOptions[] = array('value' => $aRole['role_id'], 'name' => $aRole['name']);
                 }
                 // pobieramy dostepne layouty
                 $oLayout = new Model_Layout();
                 $aLayouts = $oLayout->getAll();
                 foreach ($aLayouts as $aLayout) {
                     $aLayoutList[] = array('value' => $aLayout['layout_id'], 'name' => $aLayout['name']);
                 }
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('first_name'), 'name' => 'fname', 'value' => $aUser['fname']);
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('sure_name'), 'name' => 'name', 'value' => $aUser['name']);
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('email'), 'name' => 'email', 'value' => $aUser['email']);
                 $aInputs[] = array('type' => 'password', 'label' => $this->getLang('password'), 'name' => 'pass', 'value' => '');
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('registered'), 'name' => 'since', 'value' => $aUser['since'], 'disabled' => true);
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('last_login'), 'name' => 'last_login', 'value' => $aUser['last_login'], 'disabled' => true);
                 $aInputs[] = array('type' => 'select', 'label' => $this->getLang('layout'), 'name' => 'layout', 'value' => $aUser['layout_id'], 'items' => $aLayoutList);
                 $aInputs[] = array('type' => 'select', 'label' => $this->getLang('role'), 'name' => 'role', 'value' => $aUser['role_id'], 'items' => $aOptions);
                 $aInputs[] = array('type' => 'hidden', 'name' => 'user_id', 'value' => $aUser['user_id']);
                 $aData = array('bPrintForm' => true, 'aInputs' => $aInputs, 'sTextDelete' => $this->getLang('delete'), 'sLinkDelete' => '/account/user/delete/' . $aUser['user_id'] . '/');
                 $this->mTemplate->sSectionTitle = $this->getLang('section_title_useredit');
             }
         } else {
             $aData['info'] = $this->getLang('user_not_found');
         }
     } elseif (isset($_POST['submit'])) {
         // zapis usera
         $sFName = $this->post('fname');
         $sName = $this->post('name');
         $sPass = $this->post('pass');
         $sEmail = $this->post('email');
         $iRole = $this->post('role');
         $iLayout = $this->post('layout');
         $user_id = $this->post('user_id');
         $oValidator = new Module_Validator();
         $oValidator->field('first_name', $sFName)->rules('required');
         $oValidator->field('sure_name', $sName)->rules('required');
         $oValidator->field('email', $sEmail)->rules('required|email');
         $oValidator->field('layout', $iLayout)->rules('required|toint');
         $oValidator->field('role', $iRole)->rules('required|toint');
         $oValidator->field('user_id', $user_id)->rules('toint');
         if ($user_id == 0) {
             $oValidator->field($this->getLang('password'), $sPass)->rules('required|md5');
         } elseif (strlen($sPass)) {
             $oValidator->field($this->getLang('password'), $sPass)->rules('md5');
         }
         if ($oValidator->validate()) {
             if ($user_id == 0) {
                 //zapis nowego usera
                 $oUser = new Model_User();
                 $oUser->fname = $sFName;
                 $oUser->name = $sName;
                 $oUser->email = $sEmail;
                 $oUser->password = $sPass;
                 $oUser->layout_id = $iLayout;
                 $oUser->role_id = $iRole;
                 $oUser->account_id = $this->oCurrentUser->account_id;
                 if ($oUser->save()) {
                     $aMeta = $this->mTemplate->aMeta;
                     $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />';
                     $this->mTemplate->aMeta = $aMeta;
                     $aData['info'] = $this->getLang('save_user_successfull');
                 } else {
                     $aData['info'] = $this->getLang('save_user_failed');
                 }
             } else {
                 // zapis edytowanego usera
                 $oUser = new Model_User($user_id);
                 $aUser = $oUser->getRow();
                 if (!empty($aUser) and $aUser['account_id'] == $this->oCurrentUser->account_id) {
                     $oUser->fname = $sFName;
                     $oUser->name = $sName;
                     $oUser->email = $sEmail;
                     $oUser->layout_id = $iLayout;
                     $oUser->role_id = $iRole;
                     if (!empty($sPass)) {
                         $oUser->password = $sPass;
                     }
                     if ($oUser->save()) {
                         $aMeta = $this->mTemplate->aMeta;
                         $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />';
                         $this->mTemplate->aMeta = $aMeta;
                         $aData['info'] = $this->getLang('save_user_successfull');
                     } else {
                         $aData['info'] = $this->getLang('save_user_failed');
                     }
                 }
             }
         } else {
             $aErrors = $oValidator->getError();
             foreach ($aErrors as $sField => $aError) {
                 $sMsg .= '<br />' . $this->getLang($aError['msg'], $this->getLang($sField));
             }
             $aData['info'] = $sMsg;
         }
         $this->mTemplate->sSectionTitle = $this->getLang('section_title_user_save');
     } else {
         // akcja domyślna czyli dodawanie usera
         $aOptions = array();
         $aLayoutList = array();
         // pobieramy dostepne role
         $oRole = new Model_Role();
         $aRoles = $oRole->getAll();
         foreach ($aRoles as $aRole) {
             $aOptions[] = array('value' => $aRole['role_id'], 'name' => $aRole['name']);
         }
         // pobieramy dostepne layouty
         $oLayout = new Model_Layout();
         $aLayouts = $oLayout->getAll();
         foreach ($aLayouts as $aLayout) {
             $aLayoutList[] = array('value' => $aLayout['layout_id'], 'name' => $aLayout['name']);
         }
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('first_name'), 'name' => 'fname', 'value' => '');
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('sure_name'), 'name' => 'name', 'value' => '');
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('email'), 'name' => 'email', 'value' => '');
         $aInputs[] = array('type' => 'password', 'label' => $this->getLang('password'), 'name' => 'pass', 'value' => '');
         $aInputs[] = array('type' => 'select', 'label' => $this->getLang('layout'), 'name' => 'layout', 'value' => 2, 'items' => $aLayoutList);
         $aInputs[] = array('type' => 'select', 'label' => $this->getLang('role'), 'name' => 'role', 'value' => 3, 'items' => $aOptions);
         $aData = array('bPrintForm' => true, 'aInputs' => $aInputs);
         $this->mTemplate->sSectionTitle = $this->getLang('section_title_user_add');
     }
     $aData['submit'] = $this->getLang('Catering.save');
     $this->mTemplate->content = View::factory('/account/item_edit', $aData)->render();
 }