public function indexAction()
 {
     // get user session
     $session = new Zend_Session_Namespace('user');
     // check for non guest users
     if (!$session->valid) {
         $this->_redirect('');
     }
     // get user
     $user = new Knowledgeroot_User($session->id);
     // check for post
     if ($this->getRequest()->getMethod() == 'POST') {
         $user->setFirstName($this->_getParam('first_name'));
         $user->setLastName($this->_getParam('last_name'));
         $user->setEmail($this->_getParam('email'));
         $user->setLanguage($this->_getParam('language'));
         $user->setTimezone($this->_getParam('timezone'));
         // check for password change
         if ($this->_getParam('password') != '') {
             if ($this->_getParam('password') == $this->_getParam('password1')) {
                 //  save password
                 $user->setPassword($this->_getParam('password'));
                 // display success message
                 Knowledgeroot_Message::success("Password changed", "Your password was changed!");
             } else {
                 Knowledgeroot_Message::error("Password", "Your password could not changed!");
             }
         }
         // save user
         $user->save();
         // save settings also to session
         $session->language = $this->_getParam('language');
         $session->timezone = $this->_getParam('timezone');
         // display message
         // TODO: translate text to new language here!
         Knowledgeroot_Message::success("Settings", "Your settings were saved");
         // redirect to this page again
         $this->_redirect('settings');
     }
     // prepare view vars
     $this->view->id = $user->getId();
     $this->view->login = $user->getLogin();
     $this->view->first_name = $user->getFirstName();
     $this->view->last_name = $user->getLastName();
     $this->view->email = $user->getEmail();
     $this->view->language = $user->getLanguage();
     $this->view->timezone = $user->getTimezone();
     // get translations
     $translation = Knowledgeroot_Registry::get('translate');
     $this->view->translations = $translation->getTranslations();
     // get timezones
     $this->view->timezones = Knowledgeroot_Timezone::getTimezones();
 }
Esempio n. 2
0
 public function editAction()
 {
     if ($this->getRequest()->getMethod() == 'POST') {
         if ($this->_getParam('button') == 'close') {
             $this->_redirect('user/');
         }
         $user = new Knowledgeroot_User($this->_getParam('id'));
         $user->setLogin($this->_getParam('login'));
         // check if password is changed
         if ($this->_getParam('password') != '' && $this->_getParam('password2') != '' && $this->_getParam('password') == $this->_getParam('password2')) {
             $user->setPassword($this->_getParam('password'));
         }
         $user->setFirstName($this->_getParam('firstname'));
         $user->setLastName($this->_getParam('lastname'));
         $user->setEmail($this->_getParam('email'));
         $user->setLanguage($this->_getParam('language'));
         $user->setTimezone($this->_getParam('timezone'));
         $user->setActive($this->_getParam('active'));
         $user->save();
         // remove existing group memberships
         Knowledgeroot_Group::deleteMemberFromGroups($user);
         // save group membership
         foreach (Knowledgeroot_Util::objectToArray(json_decode($this->_getParam('memberpanel_user'))) as $memberId => $value) {
             // we only can be a member of a group
             if ($memberId[0] == 'G') {
                 $id = substr($memberId, 2);
                 $group = new Knowledgeroot_Group($id);
                 $group->addMember($user);
             }
         }
         if ($this->_getParam('button') == 'save') {
             $this->_redirect('user/edit/' . $user->getId());
         } else {
             $this->_redirect('user/');
         }
     } else {
         $id = $this->_getParam('id');
         $user = new Knowledgeroot_User($id);
         $this->view->action = 'edit';
         $this->view->id = $user->getId();
         $this->view->login = $user->getLogin();
         $this->view->firstname = $user->getFirstName();
         $this->view->lastname = $user->getLastName();
         $this->view->email = $user->getEmail();
         $this->view->timezone = $user->getTimezone();
         $this->view->language = $user->getLanguage();
         $this->view->active = $user->getActive();
         $this->renderScript("user/user.phtml");
     }
 }