Exemple #1
0
 public function addAction()
 {
     $form = new Application_Form_User();
     $form->envoyer->setLabel('Ajouter');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $users = new Application_Model_DbTable_Users();
             /* 
              * Test supplémentaire
              */
             $erreur = false;
             /* Vérification que le username n'existe pas */
             $where = "username = '******'username') . "'";
             $sel = $users->fetchAll($where);
             if ($sel->count() > 1) {
                 /* Erreur le login existe déjà */
                 $this->_flashMessage('Login existe déjà');
                 $erreur = TRUE;
             }
             /* Vérification de la zone role */
             $role = $form->getValue('role');
             if ($role == '') {
                 $role == 'user';
             } else {
                 if (strpos('admistrator,user', $role) === FALSE) {
                     $this->_flashMessage('pb role');
                     $erreur = TRUE;
                 }
             }
             if ($erreur) {
                 $form->populate($formData);
             } else {
                 $newUser = $users->fetchNew();
                 $newUser->username = $form->getValue('username');
                 $newUser->password = $form->getValue('password');
                 $newUser->role = $form->getValue('role');
                 $newUser->token = $form->getValue('token');
                 $newUser->date_created = new Zend_Db_Expr('NOW()');
                 Zend_Debug::dump($newUser);
                 $id = $newUser->save();
                 $this->_helper->redirector('index');
             }
         } else {
             $form->populate($formData);
         }
     }
 }
 public function editAction()
 {
     $form = new Application_Form_User();
     $identity = Zend_Auth::getInstance()->getIdentity();
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         $this->_helper->flashMessenger->addMessage('access denied');
         $this->_redirect('/');
     }
     $id = $identity->id;
     $table = new Tri_Db_Table('user');
     $row = $table->find($id)->current();
     if ($row) {
         $form->populate($row->toArray());
     }
     $this->view->form = $form;
     $this->render('form');
 }
Exemple #3
0
 public function editEmployeeAction()
 {
     $id = $this->_getParam('id');
     $this->view->user_id = $id;
     $model1 = new Application_Model_User();
     $model = $model1->find($id);
     if (false === $model) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/employees'));
     }
     $options['firstName'] = $model->getFirstName();
     $options['middleName'] = $model->getMiddleName();
     $options['lastName'] = $model->getLastName();
     $options['email'] = $model->getEmail();
     $options['dob'] = $model->getDob();
     $options['doj'] = $model->getDoj();
     $options['pan'] = $model->getPan();
     $options['employeeCode'] = $model->getEmployeeCode();
     $options['contactNo'] = $model->getContactNo();
     $options['extensionNo'] = $model->getExtensionNo();
     $options['skype'] = $model->getSkype();
     $options['sex'] = $model->getSex();
     $options['mobile'] = $model->getMobile();
     $options['fatherName'] = $model->getFatherName();
     $options['marriageAnniversary'] = $model->getMarriageAnniversary();
     $options['designationId'] = $model->getDesignationId();
     $options['departmentId'] = $model->getDepartmentId();
     $options['userLevelId'] = $model->getUserLevelId();
     $options['correspondenceAddress'] = $model->getCorrespondenceAddress();
     $this->view->username = $model->getUsername();
     $request = $this->getRequest();
     $form = new Application_Form_User();
     //remove fields do not need to display in Edit
     //$form->removeElement('employeeCode');
     //$form->getElement('employeeCode')->setAttrib("readonly", "true");
     $form->removeElement('username');
     $form->removeElement('password');
     $form->removeElement('confirmPassword');
     $form->populate($options);
     $options = $request->getPost();
     if ($request->isPost()) {
         /*---- email validation ----*/
         if ($options['email'] != $model->getEmail()) {
             $form->getElement('email')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => 'Email already exists, Please choose another email address.'))));
         }
         if ($options['employeeCode'] == $model->getEmployeeCode()) {
             $form->getElement('employeeCode')->removeValidator("Db_NoRecordExists");
         }
         /*-------------------------*/
         if ($form->isValid($options)) {
             $model->setOptions($options);
             $model->save();
             /*---------  Upload image START -------------------------*/
             $model->uploadProfilePicture($id, $options);
             /*---------  Upload image END -------------------------*/
             $this->_flashMessenger->addMessage(array('success' => 'Employee information has been updated successfully!'));
             $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/edit-employee/id/' . $id));
         } else {
             $this->_flashMessenger->addMessage(array('error' => 'Unable to save the data. Please provide valid inputs and try again.'));
             $form->reset();
             $form->populate($options);
         }
     }
     $this->view->profile_image = $model->getProfileImage();
     $this->view->form = $form;
 }
Exemple #4
0
 /**
  * Método utilizado para editar Users, testando a existência de uma requisão do tipo POST.
  * Seus valores são resgatados validados e atualizados no banco de dados.
  * @param int $id
  * @method updateAction
  * @access public
  * @return resource
  */
 public function updateAction()
 {
     $form = new Application_Form_User();
     $form->setAction('/user/update');
     $users = new Application_Model_User();
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $values = $form->getValues();
             $users->update($values, 'id = ' . $values['id']);
             $this->_redirect('/user/retrieve');
         }
     } else {
         $id = $this->_getParam('id');
         $user = $users->fetchRow("id ={$id}")->toArray();
         $form->populate($user);
     }
     $this->view->form = $form;
 }
Exemple #5
0
 public function editAction()
 {
     $id = $this->_request->getParam("id");
     $form = new Application_Form_User();
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     if ($userInfo->type == "regular") {
         $form->getElement("password")->setAttrib('disabled', 'disabled');
         $form->getElement("userName")->setAttrib('disabled', 'disabled');
         $form->getElement("email")->setAttrib('disabled', 'disabled');
         $form->getElement("email")->setRequired(false);
         $form->getElement("userName")->setRequired(false);
     }
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     if ($userInfo->type == "admin") {
         $form->getElement("password")->setAttrib('disabled', 'disabled');
     }
     $form->getElement("password")->setRequired(false);
     $form->getElement("email")->removeValidator('Db_NoRecordExists');
     $form->getElement("profilePicture")->setRequired(false);
     $form->getElement("signature")->setRequired(false);
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getParams())) {
             $user_info = $form->getValues();
             $user_model = new Application_Model_User();
             $user_model->editUser($user_info);
             $userInfo = Zend_Auth::getInstance()->getStorage()->read();
             if ($userInfo->type == "admin") {
                 $this->redirect("user/list");
             } else {
                 $this->redirect("user/display");
             }
         }
     }
     if (!empty($id)) {
         $user_model = new Application_Model_User();
         $user = $user_model->getUserById($id);
         $form->populate($user[0]);
     }
     $this->view->form = $form;
     $this->render('add');
 }