public function editAction() { $layoutPath = APPLICATION_PATH . '/templates/' . TEMPLATE_USED; $option = array('layout' => 'hethong/layout', 'layoutPath' => $layoutPath); Zend_Layout::startMvc($option); $translate = Zend_Registry::get('Zend_Translate'); $this->view->title = 'Quản lý tài khoản - ' . $translate->_('TEXT_DEFAULT_TITLE'); $this->view->headTitle($this->view->title); $id = $this->_getParam('id', 0); $userModel = new Front_Model_Users(); $employeesModel = new Front_Model_Employees(); $groupsModel = new Front_Model_Groups(); $list_employees = $employeesModel->fetchAll(); $list_groups = $groupsModel->fetchAll(); $error_message = array(); $success_message = ''; $user_info = $userModel->fetchRow('user_id=' . $id); if (!$user_info) { $error_message[] = 'Không tìm thấy thông tin của tài khoản.'; } if ($this->_request->isPost()) { $username = trim($this->_arrParam['username']); $password = trim($this->_arrParam['password']); $employee = $this->_arrParam['employee']; $group = $this->_arrParam['group']; $status = $this->_arrParam['status']; $validator_length = new Zend_Validate_StringLength(array('min' => 4, 'max' => 12)); $validator_username = new Zend_Validate_Alnum(array('allowWhiteSpace' => false)); //kiem tra dữ liệu if (!$validator_length->isValid($username)) { $error_message[] = 'Tên tài khoản phải bằng hoặc hơn 4 ký tự và nhỏ hơn hoặc bằng 12 ký tự.'; } if (!$validator_username->isValid($username)) { $error_message[] = 'Tên tài khoản không không được chứa khoảng trắng.'; } if ($password) { if (!$validator_length->isValid($password)) { $error_message[] = 'Mật khẩu phải bằng hoặc hơn 4 ký tự và nhỏ hơn hoặc bằng 12 ký tự.'; } } //check username đã tồn tại $check_username = $userModel->fetchRow('username="******" and username !="' . $user_info->username . '"'); if ($check_username) { $error_message[] = 'Tên đăng nhập <strong>' . $username . '</strong> đã tồn tại.'; } //check employee $check_employee = $userModel->fetchRow('em_id=' . $employee . ' and em_id !=' . $user_info->em_id); if ($check_employee) { $error_message[] = 'Nhân viên <strong>' . $this->view->viewGetName($employee) . '</strong> đã có tài khoản rồi.'; } if (!sizeof($error_message)) { $current_time = new Zend_Db_Expr('NOW()'); $userModel->update(array('em_id' => $employee, 'group_id' => $group, 'username' => $username, 'status' => $status, 'date_modified' => $current_time), 'user_id=' . $id); if ($password) { $userModel->update(array('password' => md5($password)), 'user_id=' . $id); } $user_info->em_id = $employee; $user_info->group_id = $group; $user_info->username = $username; $user_info->status = $status; $success_message = 'Đã cập nhật thông tin tài khoản thành công.'; } } $this->view->user_info = $user_info; $this->view->success_message = $success_message; $this->view->error_message = $error_message; $this->view->list_groups = $list_groups; $this->view->list_employees = $list_employees; }