示例#1
0
文件: User.php 项目: maxwroc/PHP
 public function settingsAction()
 {
     // sprawdzamy czy zalogowany
     if (!$this->oAuth->isLoggedIn()) {
         $this->redirect('/');
         echo ' ';
         return;
     }
     $this->mTemplate->sSectionTitle = 'Ustawienia';
     $oLayout = new Model_Layout();
     $aLayouts = $oLayout->getAll();
     if (isset($_POST['submit'])) {
         $sResult = $this->saveSettings($aLayouts);
         if ($sResult === true) {
             $aData['sInfo'] = 'Ustawienia zapisane pomyslenie.';
         } else {
             $aData['sInfo'] = $sResult;
         }
     }
     $aOption = array();
     foreach ($aLayouts as $aLayout) {
         $aOption[] = array('value' => $aLayout['layout_id'], 'text' => $aLayout['name']);
     }
     $aData['aChangePassForm'] = array('sTitle' => 'Zmiana hasla', 'sOldPass' => 'Stare haslo', 'sNewPass' => 'Nowe haslo', 'sNewPassConfirm' => 'Powtorz nowe haslo', 'sSubmit' => 'Zmien');
     $aData['aLayoutForm'] = array('sTitle' => 'Wybor layout\'u', 'sNull' => '', 'value' => (int) $this->oCurrentUser->layout_id, 'sSubmit' => 'Zapisz', 'aOptions' => $aOption);
     $this->mTemplate->content = View::factory('user/settings', $aData)->render();
 }
示例#2
0
文件: Account.php 项目: maxwroc/PHP
 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();
 }