Exemple #1
0
 public function editAction()
 {
     $id = $this->_request->getParam("id");
     $data = User::findById($id);
     $userAircrafts = App_Utils::toList($data['Aircraft'], "id", "id");
     $form = new Form_UserEdit();
     $form->role_id->addMultiOptions(App_Utils::toList(AclRole::findAll(), 'id', 'name'));
     $form->aircraft->setMultiOptions(App_Utils::toList($data['Aircraft'], 'id', 'name'));
     $form->aircraft_available->setMultiOptions(App_Utils::toList(Aircraft::findAll(array('exclude' => $userAircrafts)), 'id', 'name'));
     $form->role_id->setValue($data['role_id']);
     $form->user_id->setValue($id);
     $form->populate($data);
     $options = array('title' => "Edit User", 'url' => "/user/edit/format/json/subaction/submit", 'button' => "Edit", 'success' => array("button" => array("title" => "Close", "action" => "close"), "redirect" => "/user/list", "message" => "User {$form->first_name->getValue()} {$form->last_name->getValue()} modified correctly"), 'model' => array("class" => "User", "method" => "edit"));
     $this->ajaxFormProcessor($form, $options);
 }
 public function editAction()
 {
     $this->view->headTitle()->append($this->view->translate('Edit your profile'));
     $id = $this->view->id = (int) $this->getRequest()->getParam('id');
     $auth = Zend_Auth::getInstance();
     if (!$auth->getIdentity()->id) {
         $this->_helper->_flashMessenger->addMessage($this->view->translate('You are not allowed to view this page'));
         $this->_redirect('/' . $this->view->lang . '/woeid/' . $this->location . '/give');
         return;
     }
     $model = new Model_User();
     $user = $model->fetchUser($id)->id;
     if ($auth->getIdentity()->id == $user) {
         //if is the user profile owner lets edit
         require_once APPLICATION_PATH . '/forms/UserEdit.php';
         $form = new Form_UserEdit();
         $form->submit->setLabel('Save profile');
         $this->view->form = $form;
         if ($this->getRequest()->isPost()) {
             $formData = $this->getRequest()->getPost();
             if ($form->isValid($formData)) {
                 //chekusername if exists, dont let change it
                 $checkuser = $model->checkUsername($form->getValue('username'));
                 if (!is_null($checkuser) and $checkuser['username'] != $auth->getIdentity()->username) {
                     $this->view = $this->initView();
                     $this->view->error = $this->view->translate('This username is taken. Please choose another one.');
                     return;
                 }
                 $data['id'] = $id;
                 $data['username'] = $form->getValue('username');
                 if ($form->getValue('password')) {
                     $data['password'] = md5(trim($form->getValue('password')));
                 }
                 $model->update($data);
                 //update the auth data stored
                 $auth = Zend_Auth::getInstance();
                 $auth->getStorage()->write((object) $data);
                 $this->_helper->_flashMessenger->addMessage($this->view->translate('Your profile was edited succesfully!'));
                 $this->_redirect('/' . $this->view->lang . '/woeid/' . $this->location . '/give');
                 return;
             } else {
                 $form->populate($formData);
             }
         } else {
             $id = $this->_getParam('id', 0);
             if ($id > 0) {
                 $user = new Model_User();
                 $form->populate($user->fetchUser($id)->toArray());
             }
         }
     } else {
         $this->_helper->_flashMessenger->addMessage($this->view->translate('You are not allowed to view this page'));
         $this->_redirect('/' . $this->view->lang . '/woeid/' . $this->location . '/give');
         return;
     }
 }