Example #1
0
 /** Edit a user's account
  * @access public
  * @return void
  * @throws Pas_Exception_Param
  */
 public function editAction()
 {
     if ($this->getParam('id', false)) {
         $form = new EditAccountForm();
         $form->submit->setLabel('Save details');
         $form->removeElement('password');
         $this->view->form = $form;
         if ($this->_request->isPost()) {
             if ($form->isValid($this->_request->getPost())) {
                 $updateData = $form->getValues();
                 $where = array();
                 $where[] = $this->getUsers()->getAdapter()->quoteInto('id = ?', $this->getParam('id'));
                 $oldData = $this->getUsers()->fetchRow('id=' . $this->getParam('id'))->toArray();
                 unset($updateData['person']);
                 $this->getUsers()->update($updateData, $where);
                 $this->_helper->audit($updateData, $oldData, 'UsersAudit', $this->getParam('id'), $this->getParam('id'));
                 $this->getFlash()->addMessage('You updated the account successfully.');
                 $this->redirect('/admin/users/account/username/' . $form->getValue('username'));
             } else {
                 $form->populate($this->_request->getPost());
             }
         } else {
             $id = (int) $this->_request->getParam('id', 0);
             if ($id > 0) {
                 $user = $this->getUsers()->fetchRow('id =' . $this->getParam('id'));
                 if (!empty($user)) {
                     $data = $user->toArray();
                     if (isset($data['peopleID'])) {
                         $people = new People();
                         $person = $people->fetchRow($people->select()->where('secuid = ?', $data['peopleID']));
                         if ($person) {
                             $person = $person->toArray();
                             $form->peopleID->setValue($person['secuid']);
                             $form->person->setValue($person['fullname']);
                         }
                     }
                     $form->populate($user->toArray());
                 } else {
                     throw new Pas_Exception_Param('No user account found with that id');
                 }
             }
         }
     } else {
         throw new Pas_Exception_Param('No parameter found on url string');
     }
 }