Example #1
0
 public function getTopPermissionByGroup($group_id, $top_menu_id)
 {
     $permission_list = $this->getPermissionByGruop($group_id);
     $top_permission = array();
     $permission_to_process = array();
     foreach ($permission_list as $key => $value) {
         //待归档的权限列表
         $permission_to_process[$value['menu_id']] = 1;
     }
     $Menu = new Widget_Menu();
     while (count($permission_to_process)) {
         foreach ($permission_to_process as $menu_id => $value) {
             $menu = $Menu->get($menu_id);
             //如果是当前顶层目录
             if ($menu['parent'] == $top_menu_id) {
                 $top_permission[$menu_id] = $menu;
             } else {
                 $permission_to_process[$menu['parent']] = 1;
             }
             //从待处理队列中移除
             unset($permission_to_process[$menu_id]);
         }
     }
     return $top_permission;
 }
 /**
  * 
  * 递归获取菜单
  * @author 张骥
  */
 public function getChildMenu($parentId)
 {
     $Menu = new Widget_Menu();
     $ChildMenu = $Menu->getChildMenu($parentId);
     if (count($ChildMenu)) {
         foreach ($ChildMenu as $key => $val) {
             $rescurTree = $this->getChildMenu($val['menu_id']);
             if (count($rescurTree)) {
                 $ChildMenu[$key]['tree'] = $rescurTree;
             }
         }
     }
     return $ChildMenu;
 }
 /**
  * 
  * 递归获取菜单
  * @author 张骥
  */
 public function getChildMenu($parentId)
 {
     $Menu = new Widget_Menu();
     $ChildMenu = $Menu->getPermissionChildMenu($parentId);
     if (isset($ChildMenu['menu_list']) && count($ChildMenu['menu_list'])) {
         foreach ($ChildMenu['menu_list'] as $key => $val) {
             $rescurTree = $this->getChildMenu($val['menu_id']);
             if (count($rescurTree)) {
                 $ChildMenu['menu_list'][$key]['tree'] = $rescurTree;
             }
         }
     } else {
         $menu_info = $Menu->get($parentId);
         $permission_list = array();
         $M = explode('|', $menu_info['permission_list']);
         if (is_array($M)) {
             foreach ($M as $key => $value) {
                 $P = explode(':', $value);
                 if (is_array($P)) {
                     $permission_list['permission_list'][$P[1]] = array('permission_name' => $P[0], 'selected' => 0);
                 }
             }
         }
         ksort($permission_list);
         $ChildMenu = $permission_list;
     }
     return $ChildMenu;
 }
Example #4
0
 /**
  * 检查菜单权限
  * @param integer $menu_id
  * @param string $operation
  * @param boolean $return
  * @return boolean
  * @throws Base_Exception
  */
 public function checkMenuPermission($operation, $return = false)
 {
     $oMenu = new Widget_Menu();
     $oMenuPurview = new Widget_Menu_Permission();
     $t = explode("&", $_SERVER['QUERY_STRING']);
     foreach ($t as $key => $value) {
         $t2 = explode("=", $value);
         if (trim($t2[0]) == "ctl") {
             $ctl = $value;
             break;
         }
     }
     $link = $ctl;
     //获取页面ID
     $MenuInfo = $oMenu->getOneBylink("?" . $link, "name,menu_id,parent,permission_list");
     //获取当前用户组在当前页面的所有权限
     $purview = $oMenuPurview->getPermission($MenuInfo['menu_id'], $this->menu_group_id);
     //如果只是进入页面,不执行操作
     if ($operation == "0") {
         //当前页面有任何权限
         if (count($purview) > 0) {
             $return = array('return' => 1);
         } else {
             $return = array('return' => 0, 'message' => "对不起,您没有进入 " . $MenuInfo['name'] . " 的权限!");
         }
     } else {
         if (strpos($MenuInfo['permission_list'], $operation)) {
             foreach ($purview as $key => $value) {
                 if ($value['permission'] == $operation) {
                     $return = array('return' => 1);
                     return $return;
                 }
             }
             $t = explode("|", $MenuInfo['permission_list']);
             foreach ($t as $k => $v) {
                 $t2 = explode(":", $v);
                 if ($t2[1] == $operation) {
                     $action = $t2[0];
                     break;
                 }
             }
             $return = array('return' => 0, 'message' => "对不起,您没有执行 " . $action . " 的权限!");
         } else {
             $return = array('return' => 0, 'message' => "无此权限!");
         }
     }
     return $return;
 }
 /**
  * 
  * 获取子级菜单
  * @author 张骥
  */
 public function getChildMenuAction()
 {
     $partnerId = $this->request->partnerId;
     $menu_id = $this->request->menu;
     $level = $this->request->level;
     $is_table = $this->request->is_table;
     $Menu = new Widget_Menu();
     $childmenu = $Menu->getChildMenu($partnerId);
     $menuCount = count($childmenu);
     if ($is_table) {
         $pfix = "";
         for ($i = 1; $i <= $level; $i++) {
             for ($j = 1; $j <= $level; $j++) {
                 $pfix .= "&nbsp;&nbsp;";
             }
         }
         $pfix .= "┠&nbsp;&nbsp;";
         $return = array("count" => $menuCount, "tr" => '<tr class="' . $partnerId . '_' . $level . '" level="' . $level . '"><td colspan="6" style="padding:0px;border-top:none;border-bottom:none;"><table border="0" cellpadding="0" cellspacing="0">');
         if ($menuCount) {
             foreach ($childmenu as $key => $arr) {
                 $Child = $Menu->getChildMenu($arr['menu_id']);
                 if (count($Child) > 0) {
                     $arr['permission_list'] = "双击打开下级菜单";
                     $arr['update_permission'] = '';
                 } else {
                     $arr['update_permission'] = '| <a href="?ctl=menu/permission&ac=modify.by.menu&menu_id=' . $arr['menu_id'] . '">权限</a>';
                 }
                 $return['tr'] .= '<tr class="hover" id="' . $arr['menu_id'] . '" level="' . $level . '" ondblclick="getChildMenu(this.id,' . ($level + 1) . ')" style="cursor: pointer;">';
                 $return['tr'] .= '<td width="100"><input type="text" name="sort[' . $arr['menu_id'] . ']" value="' . $arr['sort'] . '" size="3"/></td>
                                   <td width="100">' . $arr['menu_id'] . '</td>
                                   <td style="text-align:left" width="500">' . $pfix . $arr['name'] . '</td>
                                   <td width="400">' . $arr['link'] . '</td>
                                   <td width="400">' . $arr['permission_list'] . '</td>
                                   <td width="200">
                                     <a href="javascript:;" onclick="divBox.showBox(\'?ctl=menu&ac=modify&menu_id=' . $arr['menu_id'] . '\', {title:\'修改菜单\',height:450,width:620});">修改</a>
                                   | <a href="javascript:;" onclick="divBox.confirmBox({content:\'是否确认删除 ' . $arr['name'] . ' ?\',ok:function(){location.href=\'?ctl=menu&ac=delete&menu_id=' . $arr['menu_id'] . '\';}});">删除</a>' . $arr['update_permission'] . '
                                   </td>
                                   </tr>';
             }
         }
         $return['tr'] .= '</table></td></tr>';
     } else {
         $menu = $Menu->get($menu_id);
         $return = array("count" => $menuCount, "select" => '<select id="parent_' . $level . '" level="' . $level . '" onchange="getChildMenu(this.id,' . ($level + 1) . ');" name="parent_' . $level . '">');
         if ($menu['parent'] == $partnerId) {
             $return['select'] .= '<option value="0" selected="selected">无</option>';
             if ($menuCount) {
                 foreach ($childmenu as $key => $arr) {
                     if ($arr['menu_id'] != $menu_id) {
                         $return['select'] .= '<option value="' . $arr['menu_id'] . '">' . $arr['name'] . '</option>';
                     }
                 }
             }
         } else {
             $return['select'] .= '<option value="0">无</option>';
             if ($menuCount) {
                 foreach ($childmenu as $key => $arr) {
                     if ($arr['menu_id'] != $menu_id) {
                         if ($arr['menu_id'] == $menu['parent']) {
                             $return['select'] .= '<option value="' . $arr['menu_id'] . '" selected>' . $arr['name'] . '</option>';
                         } else {
                             $return['select'] .= '<option value="' . $arr['menu_id'] . '">' . $arr['name'] . '</option>';
                         }
                     }
                 }
             }
         }
         $return['select'] .= '</select>';
         $return['myid'] = "parent_{$level}";
     }
     echo json_encode($return);
 }