/** * Action save. * * @return void */ public function saveAction() { $messages = array(); $isValidEmail = true; $session = new Zend_Session_Namespace('data'); $form = new Application_Form_User(); $table = new Tri_Db_Table('user'); $data = $this->_getAllParams(); if ($data['email'] && (!isset($data['id']) || !$data['id'])) { $row = $table->fetchRow(array('email = ?' => $data['email'])); if ($row) { $isValidEmail = false; $messages[] = 'Email existing'; } } if (!isset($data['id']) || !$data['id']) { $form->getElement('password')->setAllowEmpty(false); } if ($form->isValid($data) && $isValidEmail) { if (!$form->image->receive()) { $messages[] = 'Image fail'; } $data = $form->getValues(); if (!$form->image->getValue()) { unset($data['image']); } if (!$data['password']) { unset($data['password']); } if (isset($data['id']) && $data['id'] && Zend_Auth::getInstance()->hasIdentity()) { $row = $table->find($data['id'])->current(); $row->setFromArray($data); $id = $row->save(); } else { unset($data['id']); $row = $table->createRow($data); $id = $row->save(); $session->attempt = 0; $data['password'] = $this->_getParam('password'); $this->view->data = $data; $mail = new Zend_Mail(APP_CHARSET); $mail->setBodyHtml($this->view->render('user/welcome.phtml')); $mail->setSubject($this->view->translate('Welcome')); $mail->addTo($data['email'], $data['name']); $mail->send(); $result = $this->login($data['email'], $data['password']); if ($result->isValid()) { if ($session->url) { $this->_helper->_flashMessenger->addMessage('Success'); $url = $session->url; $session->url = null; $this->_redirect($url); } } } $this->_helper->_flashMessenger->addMessage('Success'); $identity = Zend_Auth::getInstance()->getIdentity(); if ($identity->id == $id) { $this->_redirect('user/edit'); } if ($identity->role == 'institution') { $this->_redirect('user'); } $this->_redirect('dashboard'); } $messages[] = 'Error'; $this->view->messages = $messages; $this->view->form = $form; $this->render('form'); }
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; }
public function manageAction() { $userForm = new Application_Form_User(); $userForm->getElement('password')->setRequired(false); if ($this->getRequest()->isPost()) { //if we are updating $userId = $this->getRequest()->getParam('id'); if ($userId) { $userForm->setId($userId); } if ($userForm->isValid($this->getRequest()->getParams())) { $data = $userForm->getValues(); $user = new Application_Model_Models_User($data); Application_Model_Mappers_UserMapper::getInstance()->save($user); $this->_helper->response->success($this->_helper->language->translate('Saved')); exit; } else { $this->_helper->response->fail(Tools_Content_Tools::proccessFormMessages($userForm->getMessages())); exit; } } $pnum = (int) filter_var($this->getParam('pnum'), FILTER_SANITIZE_NUMBER_INT); $offset = 0; if ($pnum) { $offset = 10 * ($pnum - 1); } $select = $this->_zendDbTable->getAdapter()->select()->from('user'); $by = filter_var($this->getParam('by', 'last_login'), FILTER_SANITIZE_STRING); $order = filter_var($this->getParam('order', 'desc'), FILTER_SANITIZE_STRING); $searchKey = filter_var($this->getParam('key'), FILTER_SANITIZE_STRING); if (!in_array($order, array('asc', 'desc'))) { $order = 'desc'; } $select = $select->order($by . ' ' . $order); $paginatorOrderLink = '/by/' . $by . '/order/' . $order; if (!empty($searchKey)) { $select->where('email LIKE ?', '%' . $searchKey . '%')->orWhere('full_name LIKE ?', '%' . $searchKey . '%')->orWhere('role_id LIKE ?', '%' . $searchKey . '%')->orWhere('last_login LIKE ?', '%' . date("Y-m-d", strtotime($searchKey)) . '%')->orWhere('ipaddress LIKE ?', '%' . $searchKey . '%'); $paginatorOrderLink .= '/key/' . $searchKey; } $adapter = new Zend_Paginator_Adapter_DbSelect($select); $users = $adapter->getItems($offset, 10); $userPaginator = new Zend_Paginator($adapter); $userPaginator->setCurrentPageNumber($pnum); $userPaginator->setItemCountPerPage(10); $pager = $this->view->paginationControl($userPaginator, 'Sliding', 'backend/user/pager.phtml', array('urlData' => $this->_websiteUrl . 'backend/backend_user/manage', 'order' => $paginatorOrderLink)); if ($order === 'desc') { $order = 'asc'; } else { $order = 'desc'; } if (!empty($searchKey)) { $this->view->orderParam = $order . '/key/' . $searchKey; } else { $this->view->orderParam = $order; } $this->view->by = $by; $this->view->order = $order; $this->view->key = $searchKey; $this->view->pager = $pager; $this->view->users = $users; $this->view->helpSection = 'users'; $this->view->userForm = $userForm; }
public function loginAction() { $user_form = new Application_Form_User(); $user_form->removeElement("userName"); $user_form->removeElement("gender"); $user_form->removeElement("country"); $user_form->removeElement("profilePicture"); $user_form->removeElement("signature"); $user_form->getElement("email")->removeValidator("Zend_Validate_Db_NoRecordExists"); $this->view->form = $user_form; if ($this->_request->isPost()) { if ($user_form->isValid($this->getRequest()->getParams())) { $email = $user_form->getValue("email"); $password = $user_form->getValue("password"); $db = Zend_Db_Table::getDefaultAdapter(); $auth = new Zend_Auth_Adapter_DbTable($db, 'user', 'email', 'password', 'ban'); $auth->setIdentity($email); $auth->setCredential(md5($password)); $row = $auth->authenticate(); if ($row->isValid()) { $autho = Zend_Auth::getInstance(); $storage = $autho->getStorage(); //info=$autho ->getidentity $storage->write($auth->getResultRowObject(array("id", "userName", "type", "profilePicture", "signature", "ban"))); //info-arrow id if ($storage->read()->ban == "off") { $this->view->message = "valid user"; $info = $autho->getIdentity(); $this->redirect("user/home"); } else { $this->view->message = "You are banned"; } } else { $this->view->message = "not valid user"; } } } }