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->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; }
/** * * 获取子级菜单 * @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 .= " "; } } $pfix .= "┠ "; $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); }