/** * get data * * @param Array $query_struct * @param Array $orderby * @param Int $limit * @param Int $offset * @return Array */ private function _data($query_struct = array(), $orderby = NULL, $limit = 1000, $offset = 0) { $list = array(); $where = array(); $like = array(); $in = array(); $manager = ORM::factory('manager'); //WHERE if (count($query_struct) > 0) { if (isset($query_struct['where'])) { foreach ($query_struct['where'] as $key => $value) { $where[$key] = $value; } } } //LIKE if (count($query_struct) > 0) { if (isset($query_struct['like'])) { foreach ($query_struct['like'] as $key => $value) { $like[$key] = $value; } } } //IN if (count($query_struct) > 0) { if (isset($query_struct['in'])) { foreach ($query_struct['in'] as $key => $value) { $in[$key] = $value; } } } //WHERE if (count($where) > 0) { $manager->where($where); } //LIKE if (count($like) > 0) { $manager->like($like); } //IN if (count($in) > 0) { foreach ($in as $key => $value) { $manager->in($key, $value); } } if (!empty($orderby)) { $manager->orderby($orderby); } $orm_list = $manager->find_all($limit, $offset); foreach ($orm_list as $item) { $merge_arr = array('role_name' => Myrole::instance($item->role_id)->get('name')); $list[] = array_merge($item->as_array(), $merge_arr); } return $list; }
/** * 编辑商户信息 */ public function edit() { $id = intval($this->uri->segment('id')); $manager = Mymanager::instance($id)->get(); //zhu add $this->_check_manager($manager['id']); if ($_POST) { tool::filter_strip_tags($_POST); $password1 = $this->input->post('password1'); $password2 = $this->input->post('password2'); $email = $this->input->post('email'); $username = $this->input->post('username'); $role_id = intval($this->input->post('role_id')); $submit_target = intval($this->input->post('submit_target')); //zhu add if ($manager['email'] != $email) { $data = Mymanager::instance()->get_by_email($email); if ($data['id']) { remind::set(Kohana::lang('o_manage.email_has_exist'), 'manage/manager/add'); } } /* 判断用户名是否重复 */ if (Mymanager::instance()->username_exist($username, $id)) { remind::set(Kohana::lang('o_manage.username_can_not_repeat'), 'manage/manager/edit/id/' . $id); } //验证两次密码是否相同 if ($password1 != $password2) { remind::set(Kohana::lang('o_manage.two_pwd_not_valid'), 'manage/manager/add'); } else { //不填写密码表示不修改密码 if (empty($password1)) { $_POST['password'] = $manager['password']; } else { $_POST['password'] = md5($password1); } } if (Mymanager::instance($id)->edit($_POST)) { //zhu modify to acl page if ($role_id == 0 || $submit_target > 0) { remind::set(Kohana::lang('o_global.update_success'), 'manage/manager/rule/' . $id, 'success'); } else { remind::set(Kohana::lang('o_global.update_success'), 'manage/manager', 'success'); } } else { $error = Mysite::instance()->error(); remind::set(Kohana::lang('o_global.update_error') . $error, 'manage/manager'); } } //zhu modify $role_id = $manager['role_id']; if ($role_id > 0) { $role = Myrole::instance($role_id)->get(); if ($manager['is_admin'] != $role['type']) { remind::set(Kohana::lang('o_manage.manager_edit_load_error'), 'manage/manager'); } } if ($manager['is_admin'] == 1) { /* 管理员 */ $where = array(); $where['type'] = $manager['is_admin']; $where['active'] = 1; //zhu add /* 管理员的用户组 */ $roles = Myrole::instance()->roles($where); $this->template->content = new View("manage/manager_adminedit"); } else { $parent_id = $manager['parent_id']; $parent = Mymanager::instance($parent_id)->get(); if ($parent['is_admin']) { /* 商户 */ $where = array(); $where['type'] = 0; $where['active'] = 1; //zhu add $roles = Myrole::instance()->roles($where); $this->template->content = new View("manage/manager_edit"); } else { /* 商户子账号 zhu modify */ //$roles = Myrole::instance()->childrens($parent['role_id']); $roles = array(); if ($parent['role_id'] > 0) { $roles = Myrole::instance()->childrens($parent['role_id']); } $this->template->content = new View("manage/manager_child_edit"); } } foreach ($roles as $key => $value) { if ($manager['role_id'] == $value['id']) { $roles[$key]['selected'] = 'selected'; } else { $roles[$key]['selected'] = ''; } } $this->template->content->roles = $roles; $this->template->content->data = $manager; }
public function delete($id) { if (Myrole::instance($id)->delete()) { remind::set(Kohana::lang('o_global.delete_success'), 'manage/role', 'success'); } else { $error = Myrole::instance($id)->error(); remind::set(Kohana::lang('o_global.delete_error') . $error, 'manage/role'); } }