public function viewGetGroupName($id = 0) { if ($id) { $groupModel = new Front_Model_Groups(); $group = $groupModel->fetchRow('group_id=' . $id); if ($group) { return $group->group_name; } return ''; } return ''; }
function checkPermission($group_id, $permission_id) { if ($permission_id == '' || $permission_id == null) { $permission_id = 0; } $groupModel = new Front_Model_Groups(); $check_group = $groupModel->checkPermission($group_id, $permission_id); if ($check_group->group_id) { return true; } return false; }
public function checkToChucUsers($permission = 0) { $users = $groups = array(); $groupsModel = new Front_Model_Groups(); $employeeModel = new Front_Model_Employees(); $list_groups = $groupsModel->getGroupByPermission($permission); if ($list_groups) { foreach ($list_groups as $group) { $groups[] = $group->group_id; } $users = $employeeModel->getUsersByGroups($groups); } return $users; }
function permissionsAction() { $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ý Nhóm, Quyền - ' . $translate->_('TEXT_DEFAULT_TITLE'); $this->view->headTitle($this->view->title); $id = $this->_getParam('id', 0); $groupsModel = new Front_Model_Groups(); $group_info = $groupsModel->fetchRow('group_id=' . $id); if (!$group_info) { $error_message[] = 'Không tìm thấy thông tin của nhóm.'; } if ($this->_request->isPost()) { $item = $this->getRequest()->getPost('cid'); $permissions = ''; foreach ($item as $permission_id) { $permissions .= $permission_id . ','; } $current_time = new Zend_Db_Expr('NOW()'); $groupsModel->update(array('group_permissions' => $permissions, 'group_date_modified' => $current_time), 'group_id=' . $id); $group_info->group_permissions = $permissions; } $this->view->group_info = $group_info; $this->view->success_message = $success_message; $this->view->error_message = $error_message; }
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; }