CommonAction.class.php
4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
class CommonAction extends BaseAction {
public $ADMIN_KEY='';
public $LOGIN_TIME='';
public $ADMIN_SCHOOL='';
public function __construct() {
parent::__construct();
$this->ADMIN_KEY=cookie('ADMIN_KEY');
$this->ADMIN_SCHOOL=cookie('ADMIN_SCHOOL');
$this->LOGIN_TIME=cookie('LOGIN_TIME');
header('Content-Type:text/html; charset=utf-8');
$this->ppFirewall();
$this->checkAdminSession();
//去除反斜梗
if (get_magic_quotes_gpc())
{
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
}
public function _initialize()
{
parent::_initialize();
if((MODULE_NAME !="Index" || (MODULE_NAME =="Index" && !in_array(ACTION_NAME,array('index','main','menu','delcache','outlogin')))) && (MODULE_NAME !="Public" || (MODULE_NAME == 'Public' && !in_array(ACTION_NAME,array('login','index','verify')))))
{
import('ORG.Util.Auth');//加载类库
$auth=new Auth();
// var_dump($auth->check(strtolower(MODULE_NAME).'-'.strtolower(ACTION_NAME),session('ADMIN_KEY')));
// exit;
if(!$auth->check(strtolower(MODULE_NAME).'-'.strtolower(ACTION_NAME),cookie('ADMIN_KEY'))){
$this->error('你没有权限');
}
}
}
/**
* 判断用户并返回查询条件 超级管理员与学院管理员
*/
protected function getWhere(){
if($this->ADMIN_KEY == 1)
return NULL;
else
return array('eq',$this->ADMIN_SCHOOL);
}
public function checkAdminSession() {
$ADMIN_KEY=$this->ADMIN_KEY;
if (!isset($ADMIN_KEY) || !isset($this->LOGIN_TIME)) {
$this->outclear();
exit('<script>alert("当前用户未登录或登录超时,请重新登录");top.location.href="'.U('Public/login').'";</script>');
}
}
//防火墙验证
protected function ppFirewall(){
if(!$_COOKIE['pro_ppfirewall']){
header('Content-Type:text/html; charset=utf-8');
exit('您无权限操作');
}
}
//清除//防火墙验证
protected function dFirewall(){
setcookie('pro_ppfirewall',null,time()-1000);
}
public function outlogin(){
$this->outclear();
$this->success('退出成功!',U('Public/index'));
}
protected function outclear(){
cookie('ADMIN_KEY',null);
cookie('ADMIN_NAME',null);
cookie('LOGIN_TIME',null);
cookie('pp_authlist',null);
// $this->dFirewall();
}
public function IsAuth($action) {
import('ORG.Util.Auth');//加载类库
$auth=new Auth();
/*if(!$auth->check(strtolower($action),$_SESSION['ADMIN_KEY']['id'])){
$this->error('你没有权限');
}*/
}
public function AllCatid($id,$type='1',$tab='Category',$upid='upid'){
$table=M($tab);
if($type==1){
$return[]=$id;
}else{
$return =$id;
}
$map[$upid]=array('eq',$id);
$lists=$table->where($map)->select();
foreach($lists as $k=>$v){
$listarr=$this->AllCatid($v['id'],$type,$tab);
if($type==1){
$return=array_merge($return,$listarr);
}else{
$return .=','.$listarr;
}
}
return $return;
}
public function topId($id){
$table=M('Category');
$da=$table->where('id='.$id)->find();
if(!$da){
return false;
}
if($da['topid']==0){
return $da['id'];
}else{
return $da['topid'];
}
}
/**
* 导入excel
**/
function impExcel()
{
if(isset($_FILES["import"]) && ($_FILES["import"]["error"] == 0))
{
$result = $this->importExecl($_FILES["import"]["tmp_name"]);
if($result["error"] == 1)
{
$execl_data = $result["data"][0]["Content"];
foreach($execl_data as $k=>$v)
{
// 这里写你的业务代码
}
}
}
}
/**
* 导出Excel
**/
function expExcel()
{
$xlsName = "Authrule";
$xlsCell = array(
array('id','序列'),
array('name','规则'),
array('title','规则说明')
);
$xlsModel = M('Authrule');
$xlsData = $xlsModel->Field('id,name,title')->select();
$this->exportExcel($xlsName,$xlsCell,$xlsData);
}
/**
* 获取用户权限
* 防止 authlist 走出cookie限制
* @return array
*/
protected function getPower(){
//获取用户权限
import('ORG.Util.Auth');//加载类库
$auth=new Auth();
$authlist=$auth->getAuthList(cookie('ADMIN_KEY'));
return $authlist;
}
}