-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
171 lines (157 loc) · 4.67 KB
/
ajax.php
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
165
166
167
168
169
170
171
<?php
/* 包含全局配置文件 */
include('include/init.php');
/* 禁止直接访问
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest'){
header("Location: index.php"); exit();
}*/
/*
* statusCode 值说明
* 200 执行正确
* 300 程序出错
* 301 SESSION过期
*/
//用户登录返回的sessionID 就是用户表的ID
$sessionID = Session::get('sessionID');
$statusCode = "200";
if( $sessionID === NULL ){
$statusCode = "301";
}
$arr = array();
$ac = isset($_REQUEST['ac']) ? $_REQUEST['ac'] : NULL;
switch ($ac) {
//得到用户配置
case 'getUserSetting' :
$sql = "SELECT
a.wptype,
a.wpmode,
a.dtsort,
a.appsize,
a.wplink,
b.sort
FROM setting AS a, appsort AS b
WHERE a.uid = b.uid AND b.uid = '".$sessionID."' AND b.aid = '0' ";
$arr = $db->fetch_once_array($sql);
break;
//得到开始菜单信息
case 'getStartMenu' :
$sql = "SELECT
a.rname,
a.status,
b.sing,
b.head FROM user AS a, userinfo as b
WHERE b.uid=a.id AND b.uid='".$sessionID."'";
$arr = $db->fetch_once_array($sql);
break;
//设置图标排序方式
case 'setUserDtsort' :
if(isset($_REQUEST['dtsort'])){
$sql = "UPDATE setting SET dtsort='".$_REQUEST['dtsort']."' WHERE uid=".$sessionID;
if($db->iudquery($sql) > 0){
$arr['dtsort'] = $_REQUEST['dtsort'];
}else{
$statusCode = '300';
};
}else{
$statusCode = '300';
};
break;
//设置用户APP尺寸
case 'setUserAppSize' :
if(isset($_REQUEST['appsize'])){
$sql = "UPDATE setting SET appsize='".$_REQUEST['appsize']."' WHERE uid=".$sessionID;
if($db->iudquery($sql) > 0){
$arr['appsize'] = $_REQUEST['appsize'];
}else{
$statusCode = '300';
};
}else{
$statusCode = '300';
};
break;
//得到应用数组
case 'getAppJson' :
$sort = $_REQUEST['sort'];
$sort = $sort{strlen($sort)-1} == ',' ? substr($sort,0,-1) : $sort;
$sql = "SELECT * FROM app WHERE id in (".$sort.") ORDER BY INSTR('".$sort."',id)";
$arr['sc'] = $db->fetch_array($sql);
break;
//更新图标序数组
case 'setAppSort' :
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : NULL;
$aid = isset($_REQUEST['aid']) ? $_REQUEST['aid'] : NULL;
$sort = $sort{strlen($sort)-1} == ',' ? substr($sort,0,-1) : $sort;
$sql = "UPDATE appsort SET sort='".$sort."' WHERE uid='".$sessionID."' AND aid='".$aid."' ";
$num = $db->iudquery($sql);
$arr['sort'] = $sort;
break;
//获取app内容
case 'getAppContent' :
$appid = $_REQUEST['appid'];
$sql = "SELECT * FROM app WHERE id='".$appid."'";
$arr = $db->fetch_once_array($sql);
break;
//设置锁屏密码
case 'setLockscreenPassword' :
$pwd = $_REQUEST['pwd'];
$sql = "UPDATE setting SET password='".$pwd."' WHERE uid='".$sessionID."'";
$num = $db->iudquery($sql);
break;
//获取锁屏密码
case 'getLockscreenPassword' :
$sql = "SELECT password FROM setting WHERE uid='".$sessionID."'";
$arr = $db->fetch_once_array($sql);
break;
//用户登陆
case 'login':
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$sql = "SELECT id,pass FROM user WHERE name='".$username."' LIMIT 0,1";
$array = $db->fetch_once_array($sql);
if ( $array['pass'] == $password ){
$t = time();
$sql2 = "UPDATE user SET logintime=". $t ." WHERE id=".$array['id'];
$num = $db->iudquery($sql2);
if($num != 0){
Session::set('sessionID', $array['id']);
}
$arr['code'] = 0;
}else{
$arr['code'] = 1;
}
break;
case 'register' :
$username = $_REQUEST['username'];
$relname = $_REQUEST['relname'];
$password = $_REQUEST['password'];
$email = $_REQUEST['email'];
$t = time();
$sql = "SELECT id FROM user WHERE name='".$username."' LIMIT 0,1";
$array = $db->fetch_once_array($sql);
if($array['id']){
//用户名已存在
$arr['code'] = 2;
}else{
$sql2 = "INSERT INTO user
(name,pass,rname,email,addtime)
VALUES
('".$username."','".$password."','".$relname."','".$email."','".$t."') ";
$db->query($sql2);
$num = $db->get_insert_id();
$sql3 = "INSERT INTO setting (uid) VALUES ('".$num."')";
$sql4 = "INSERT INTO appsort (uid,sort) VALUES ('".$num."','1,2,3,4,5,6,7,8,9,10,11,12,13,14,15')";
$sql5 = "INSERT INTO userinfo (uid) VALUES ('".$num."')";
$db->query($sql3);
$db->query($sql4);
$db->query($sql5);
//注册成功
$arr['code'] = 6;
}
break;
default :
//AJAX执行失败返回参数
$statusCode = '300';
}
$arr['statusCode'] = $statusCode;
echo json_encode($arr);
?>