PHP复制代码 <?php
class MY_controller extends controller {
function MY_controller (){
parent ::Controller();
$this->load->database();
if($this->uri->segment(3)==''){
return false;
}
/*$this->session->set_userdata(array('admin'=>true))*/
/*if($this->session->userdata('admin')){
redirect('admin/entry/login');
}
else{*/
$i=1;
$session_groupid=2;//$this->session->userdata('group_id');
$group_query=$this->db->query("select * from ci_access where `groupId`='$session_groupid'");
foreach($group_query->result() as $group_row){
$node_query=$this->db->query("select * from ci_node where `id`='$group_row->nodeId'");
$node_row=$node_query->row();
if($node_row->level=='3'){
$arr_access=array(array());
$parentnode_query=$this->db->query("select * from ci_node where `id`='$group_row->parentNodeId'");
$parentnode_result=$parentnode_query->row();
//echo $parentnode_result->name." ".$node_row->name."<br/>";
if($this->uri->segment(2)==$parentnode_result->name and $this->uri->segment(3)==$node_row->name){
$i=0;
return;
}
//$arr_access=array($i=>array($y=>$parentnode_result->name,$z=>$node_row->name))+$arr_access;
}
}
if($i==1){
echo "无权限";
exit;
}
}
/*}*/
}
?> 复制代码
以下是表
SQL复制代码 -- phpMyAdmin SQL Dump
-- version 3.1.3
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2009 年 03 月 19 日 05:04
-- 服务器版本: 5.0.67
-- PHP 版本: 5.2.9-1
SET SQL_MODE ="NO_AUTO_VALUE_ON_ZERO";
--
-- 数据库: `ci`
--
-- --------------------------------------------------------
--
-- 表的结构 `ci_access`
--
CREATE TABLE IF NOT EXISTS `ci_access` (
`groupId` SMALLINT(6) UNSIGNED NOT NULL,
`nodeId` SMALLINT(6) UNSIGNED NOT NULL,
`level` tinyint (1) NOT NULL,
`parentNodeId` SMALLINT(6) NOT NULL DEFAULT '0',
`status` tinyint (1) DEFAULT NULL,
KEY `groupId` (`groupId`),
KEY `nodeId` (`nodeId`),
KEY `level` (`level`),
KEY `parentNodeId` (`parentNodeId`)
) ENGINE =MyISAM DEFAULT CHARSET =utf8;
--
-- 导出表中的数据 `ci_access`
--
INSERT INTO `ci_access` (`groupId`, `nodeId`, `level`, `parentNodeId`, `status`) VALUES
(1, 1, 1, 0, NULL),
(1, 6, 2, 1, NULL),
(1, 3, 2, 1, NULL),
(1, 2, 2, 1, NULL),
(2, 1, 1, 0, NULL),
(2, 7, 2, 1, NULL),
(2, 3, 2, 1, NULL),
(2, 8, 3, 2, NULL),
(2, 9, 3, 2, NULL),
(2, 10, 3, 2, NULL),
(1, 7, 2, 1, NULL),
(1, 12, 3, 2, NULL),
(1, 11, 3, 2, NULL),
(1, 10, 3, 2, NULL),
(1, 9, 3, 2, NULL),
(1, 8, 3, 2, NULL),
(1, 13, 3, 2, NULL),
(1, 14, 3, 2, NULL),
(1, 15, 3, 2, NULL),
(1, 16, 3, 6, NULL),
(2, 2, 2, 1, NULL);
-- --------------------------------------------------------
--
-- 表的结构 `ci_group`
--
CREATE TABLE IF NOT EXISTS `ci_group` (
`id` SMALLINT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`pid` SMALLINT(6) DEFAULT NULL,
`status` tinyint (1) UNSIGNED DEFAULT NULL,
`remark` VARCHAR(255) DEFAULT NULL,
`ename` VARCHAR(5) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `parentId` (`pid`),
KEY `ename` (`ename`)
) ENGINE =MyISAM DEFAULT CHARSET =utf8 AUTO_INCREMENT=3 ;
--
-- 导出表中的数据 `ci_group`
--
INSERT INTO `ci_group` (`id`, `name`, `pid`, `status`, `remark`, `ename`) VALUES
(1, '管理员组', NULL, 1, '具有一般管理员权限', NULL),
(2, '普通用户组', NULL, 1, '一般用户权限', NULL);
-- --------------------------------------------------------
--
-- 表的结构 `ci_groupuser`
--
CREATE TABLE IF NOT EXISTS `ci_groupuser` (
`groupId` mediumint (9) UNSIGNED DEFAULT NULL,
`userId` mediumint (9) UNSIGNED DEFAULT NULL,
KEY `groupId` (`groupId`),
KEY `userId` (`userId`)
) ENGINE =MyISAM DEFAULT CHARSET =utf8;
--
-- 导出表中的数据 `ci_groupuser`
--
INSERT INTO `ci_groupuser` (`groupId`, `userId`) VALUES
(1, 3),
(2, 2);
-- --------------------------------------------------------
--
-- 表的结构 `ci_node`
--
CREATE TABLE IF NOT EXISTS `ci_node` (
`id` SMALLINT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`title` VARCHAR(50) DEFAULT NULL,
`status` tinyint (1) UNSIGNED DEFAULT NULL,
`remark` VARCHAR(255) DEFAULT NULL,
`seqNo` SMALLINT(6) UNSIGNED DEFAULT NULL,
`pid` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
`level` tinyint (1) UNSIGNED NOT NULL DEFAULT '0',
`type` tinyint (1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `parentId` (`pid`),
KEY `level` (`level`)
) ENGINE =MyISAM DEFAULT CHARSET =utf8 AUTO_INCREMENT=17 ;
--
-- 导出表中的数据 `ci_node`
--
INSERT INTO `ci_node` (`id`, `name`, `title`, `status`, `remark`, `seqNo`, `pid`, `level`, `type`) VALUES
(1, 'admin', '后台项目', 1, '后台管理项目', NULL, 0, 1, 0),
(2, 'publicmo', '公共模块', 1, '项目公共模块', NULL, 1, 2, 0),
(3, 'index', '默认模块', 1, '项目默认模块', NULL, 1, 2, 0),
(4, 'node', '节点管理', 1, '授权节点管理', NULL, 1, 2, 0),
(5, 'group', '权限管理', 1, '权限管理模块', NULL, 1, 2, 0),
(6, 'user', '用户管理', 1, '用户模块', NULL, 1, 2, 0),
(7, 'form', '数据管理', 1, '数据管理模块', NULL, 1, 2, 0),
(8, 'index', '列表', 1, '', NULL, 2, 3, 0),
(9, 'add', '增加', 1, '', NULL, 2, 3, 0),
(10, 'edit', '编辑', 1, '', NULL, 2, 3, 0),
(11, 'insert', '写入', 1, '', NULL, 2, 3, 0),
(12, 'update', '更新', 1, '', NULL, 2, 3, 0),
(13, 'delete', '删除', 1, '', NULL, 2, 3, 0),
(14, 'forbid', '禁用', 1, '', NULL, 2, 3, 0),
(15, 'resume', '恢复', 1, '', NULL, 2, 3, 0),
(16, 'resetPwd', '重置密码', 1, '', NULL, 6, 3, 0);
-- --------------------------------------------------------
--
-- 表的结构 `ci_user`
--
CREATE TABLE IF NOT EXISTS `ci_user` (
`id` mediumint (8) UNSIGNED NOT NULL AUTO_INCREMENT,
`account` VARCHAR(64) NOT NULL,
`nickname` VARCHAR(50) NOT NULL,
`password` CHAR(32) NOT NULL,
`remark` VARCHAR(255) NOT NULL,
`create_time` INT(11) UNSIGNED NOT NULL,
`update_time` INT(11) UNSIGNED NOT NULL,
`status` tinyint (1) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE =MyISAM DEFAULT CHARSET =utf8 AUTO_INCREMENT=4 ;
--
-- 导出表中的数据 `ci_user`
--
INSERT INTO `ci_user` (`id`, `account`, `nickname`, `password`, `remark`, `create_time`, `update_time`, `status`) VALUES
(1, 'admin', '管理员', '21232f297a57a5a743894a0e4a801fc3', '', 0, 0, 1),
(2, 'test', '测试用户', 'e10adc3949ba59abbe56e057f20f883e', '测试用户', 1212716492, 0, 1),
(3, 'leader', '领导', 'e10adc3949ba59abbe56e057f20f883e', '具有一般管理权限的用户', 1212716969, 0, 1); 复制代码 |