Ejemplo n.º 1
0
 /**
  * 递归得到模块和操作下面的子操作
  *
  * @param Int $id
  * @return Array
  */
 public static function get_actions_by_level($level = 1, $parent_id = 0)
 {
     $where['level_depth'] = $level;
     $where['parent_id'] = $parent_id;
     $actions = Myaction::instance()->get_actions($where);
     $count = count($actions) - 1;
     foreach ($actions as $key => $value) {
         if ($key == $count) {
             $actions[$key]['class_flag'] = 'last';
             $actions[$key]['last_flag'] = 'end_none';
         } else {
             $actions[$key]['class_flag'] = '';
             $actions[$key]['last_flag'] = '';
         }
     }
     return $actions;
 }
Ejemplo n.º 2
0
 /**
  * manager rule view zhu add
  */
 public function rule_view()
 {
     $id = intval($this->uri->segment('id'));
     //zhu add
     $this->_check_manager($id);
     $acl = Mymanager::instance($id)->acl();
     $current_actions_id_arr = explode(",", $acl["permissions"]);
     $actions = Myaction::instance()->actions();
     foreach ($actions as $key => $value) {
         if (!in_array($value['id'], $current_actions_id_arr)) {
             unset($actions[$key]);
         }
     }
     $this->template->content = new View("manage/manager_rule_view");
     $this->template->content->acl = $acl;
     $this->template->content->actions = $actions;
 }
Ejemplo n.º 3
0
 /**
  * set role rule
  */
 public function rule($id)
 {
     $this->template->content = new View("manage/role_rule");
     if ($_POST) {
         $resource = $this->input->post('resource');
         if (!$resource) {
             remind::set(Kohana::lang('o_manage.select_user_role'), 'manage/role/rule/' . $id);
         }
         if (Myrole::instance()->set_actions($id, $_POST)) {
             remind::set(Kohana::lang('o_global.add_success'), 'manage/role', 'success');
         } else {
             remind::set(Kohana::lang('o_global.add_error'), 'manage/role/rule/' . $id);
         }
     }
     //VIEW
     $role = Myrole::instance($id)->get();
     if (!$role['id']) {
         remind::set(Kohana::lang('o_global.access_denied'), 'manage/role');
     }
     $actions = Myaction::instance()->actions();
     if ($role['parent_id'] > 0) {
         //zhu modify  $active_actions type:string
         //$current_actions = Myrole::instance($id)->actions();
         //$active_actions = Myrole::instance($role['parent_id'])->actions();
         $parent_role = Myrole::instance($role['parent_id'])->get();
         $active_actions = $parent_role["permissions"];
     } else {
         //zhu modify  $active_actions type:array
         //$current_actions = Myrole::instance($id)->actions();
         $active_actions = $actions;
     }
     $current_actions_id_arr = array();
     $active_actions_id_arr = array();
     //zhu modify
     /*
     		foreach($current_actions as $key=>$value)
     		{
     			$current_actions_id_arr[] = $value['id'];
     		}*/
     $current_actions_id_arr = explode(",", $role["permissions"]);
     /*
     		foreach($active_actions as $key=>$value)
     		{
     			$active_actions_id_arr[] = $value['id'];
     		}*/
     if (is_array($active_actions)) {
         foreach ($active_actions as $key => $value) {
             $active_actions_id_arr[] = $value['id'];
         }
     } else {
         $active_actions_id_arr = explode(",", $active_actions);
     }
     foreach ($actions as $key => $value) {
         if (in_array($value['id'], $active_actions_id_arr)) {
             $actions[$key]['flag'] = 0;
         } else {
             $actions[$key]['flag'] = 1;
         }
         if (in_array($value['id'], $current_actions_id_arr)) {
             $actions[$key]['checked'] = "checked";
         } else {
             $actions[$key]['checked'] = "";
         }
     }
     $this->template->content->actions = $actions;
 }
Ejemplo n.º 4
0
 /**
  * edit 
  */
 public function edit($id)
 {
     $action = Myaction::instance($id)->get();
     if (!$action['id']) {
         remind::set(Kohana::lang('o_manage.resources_not_exist'), 'manage/action');
     }
     if ($_POST) {
         //标签过滤
         tool::filter_strip_tags($_POST);
         $name = $this->input->post('name');
         $resource = $this->input->post('resource');
         $parent_id = $this->input->post('parent_id');
         if ($name != $action['name']) {
             $data = Myaction::instance()->get_by_name($name);
             if ($data['id']) {
                 remind::set(Kohana::lang('o_manage.resources_name_exist'), 'manage/action/add');
             }
         }
         if ($resource != $action['resource']) {
             $data = Myaction::instance()->get_by_resource($resource);
             if ($data['id']) {
                 remind::set(Kohana::lang('o_manage.resources_mark_exist'), 'manage/action/add');
             }
         }
         //zhu add 上级资源不能选择自身,子项
         if ($parent_id > 0) {
             if ($action['id'] == $parent_id) {
                 remind::set(Kohana::lang('o_manage.parent_action_is_self'), 'manage/action/edit/' . $id);
             }
             $sub_ac = Myaction::instance()->actions($id);
             if (is_array($sub_ac) && count($sub_ac)) {
                 foreach ($sub_ac as $ac) {
                     if ($ac['id'] == $parent_id) {
                         remind::set(Kohana::lang('o_manage.parent_action_is_child'), 'manage/action/edit/' . $id);
                     }
                 }
             }
         }
         //zhu add end
         if (Myaction::instance($id)->edit($_POST)) {
             remind::set(Kohana::lang('o_global.update_success'), 'manage/action', 'success');
         } else {
             remind::set(Kohana::lang('o_global.update_error'), 'manage/action/edit/' . $id);
         }
     }
     $actions = Myaction::instance()->actions();
     foreach ($actions as $key => $value) {
         $actions[$key]['selected'] = '';
         if ($actions['id'] = $action['parent_id']) {
             $actions[$key]['selected'] = 'selected';
         }
     }
     $this->template->content = new View("manage/action_edit");
     $this->template->content->actions = $actions;
     $this->template->content->data = $action;
 }
Ejemplo n.º 5
0
 /**
  * 得到用户所有权限资源
  * @param Int $manager_id manager id
  * @param Boolean $type 读取缓存数据还是更新缓存数据
  * @return Array
  */
 public static function manager_actions($manager_id = NULL, $type = false)
 {
     if (is_null($manager_id)) {
         $manager = self::get_manager();
     } else {
         $manager = Mymanager::instance($manager_id)->get();
     }
     $manager_id = $manager['id'];
     $cache = Mycache::instance();
     $tag = "admin/actions/" . $manager_id;
     $data = $cache->get($tag);
     if ($type) {
         $data = false;
     }
     if ($data) {
         if (!is_array($data)) {
             return unserialize($data);
         } else {
             return $data;
         }
     } else {
         //帐号名称为超级管理员root,获得全部的资源和权限 zhu modify
         if (self::is_root($manager['username'])) {
             $actions = Myaction::instance()->get_actions();
         } else {
             //zhu modify get acl
             //$manager = Mymanager::instance($manager_id)->get();
             //$role = Mymanager::instance($manager_id)->role();
             //$actions = Myrole::instance($role['id'])->actions();
             $acl = Mymanager::instance($manager_id)->acl();
             $actions = Myacl::instance($acl['id'])->actions();
             //d($actions);
         }
         $cache->set($tag, $actions, self::$expire);
         return $actions;
     }
 }
Ejemplo n.º 6
0
 /**
  * edit menu
  */
 public function edit($id)
 {
     $menu = Mymenu::instance($id)->get();
     if (!$menu['id']) {
         remind::set(Kohana::lang('o_global.bad_request'), 'manage/menu');
     }
     if ($_POST) {
         //标签过滤
         tool::filter_strip_tags($_POST);
         $target = $this->input->post('target');
         $parent_id = $this->input->post('parent_id');
         if ($menu['target'] != $target) {
             $data = Mymenu::instance($id)->get_by_target($target);
             if ($data['id']) {
                 remind::set(Kohana::lang('o_manage.mark_has_exist'), 'manage/menu/edit/' . $id);
             }
         }
         /* 最多只能添加三级菜单 */
         if ($parent_id > 0) {
             $parent_menu = Mymenu::instance($parent_id)->get();
             if ($parent_menu['level_depth'] >= 3) {
                 remind::set(Kohana::lang('o_manage.menu_can_not_add_level'), 'manage/menu/add');
             }
         }
         /* 添加 */
         if (Mymenu::instance($id)->edit($_POST)) {
             remind::set(Kohana::lang('o_global.update_success'), 'manage/menu', 'success');
         } else {
             remind::set(Kohana::lang('o_global.update_error'), 'manage/menu/edit/' . $id);
         }
     }
     $menus = Mymenu::instance()->menus();
     foreach ($menus as $key => $value) {
         if ($value['id'] == $menu['parent_id']) {
             $menus[$key]['selected'] = 'selected';
         } else {
             $menus[$key]['selected'] = '';
         }
     }
     $actions = Myaction::instance()->actions();
     foreach ($actions as $key => $value) {
         if ($value['id'] == $menu['action_id']) {
             $actions[$key]['selected'] = 'selected';
         } else {
             $actions[$key]['selected'] = '';
         }
     }
     $this->template->content = new View("manage/menu_edit");
     $this->template->content->data = $menu;
     $this->template->content->menus = $menus;
     $this->template->content->actions = $actions;
 }