-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccountmanage.php
180 lines (176 loc) · 6.28 KB
/
accountmanage.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
172
173
174
175
176
177
178
179
180
<?php
/*
* ybot.php - a plurk bot use php-plurk-api
*
* Copyright (C) 2012 Wei-Chen Lai <abev66@gmail.com>
* 2012 Zheng-Yen Hong
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
session_start();
if($_SESSION['_ybot_uid']!=1 || !isset($_SESSION['_ybot_uid'])){
header('Location: login.php');
}
else{
require('db_port.php');
$dblink = db_init($_SESSION[_ybot_uid]);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ybot - Account manage</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<style type='text/css'>
<!--
.add input[type='text'],.add input[type='password'] {
width: 100%;
margin-left: auto;
display:block;
margin-bottom: 10px;
border: 1px solid #999;
border-radius: 3px;
}
.add input[type='submit']{
display: block;
margin: 0.8em auto 0;
}
/* Login Window */
.add {
background: #FFF;
opacity: 0.7;
border-radius: 5px;
display: block;
margin: 2em auto;
padding: 2em 2.5em;
max-width: 460px;
text-align: left;
vertical-align: middle;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
-moz-transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
-o-transition: opacity 0.3s;
}
h3 {
margin: 12px auto;
font-weight: bold;
font-size: 133%;
display:block;
font-weight: normal;
text-align: center;
}
.add:hover{
opacity: 1;
}
-->
</style>
</head>
<body>
<div class='container'>
<?php include('header.inc'); ?>
<?php include('navbar.inc'); ?>
<form class='search' action='' method='GET'>
<input type='text' name='searchw'>
<input id='search-btn' type='submit' value='search'>
</form>
<h3>Account List</h3>
<?php
if(isset($_GET['searchw']) && !empty($_GET['searchw'])) {
$result=get_user_data($dblink);
$tmp=array();
foreach($result as $i)
if (strpos(strtoupper($i['account']), strtoupper(trim($_GET['searchw']))) !== false){
$tmp[]=$i;
}
$result=$tmp;
echo "<div class='notice-green'>Search result of ".$_GET['searchw']." . <a href='accountmanage.php'>Display All</a></div>";
}
?>
<table><th>Account</th><th>Type</th><th colspan='2'>Action</th>
<?php //view all manager
if(!isset($_GET['searchw']) || empty($_GET['searchw'])){
$result=get_user_data($dblink);
foreach($result as $record){
if ($record['uid']==1)
continue;
$record['type']=='a'? $record['type']='A' : $record['type']='B';
echo "<tr><td>".$record['account']."</td><td>".$record['type'],"</td>";
echo "<td><form action='' method='POST'><input type='hidden' name='delete' value='".$record['account']."'><input type='button' value='Delete' onclick='javascript: if(confirm(\"Are you sure?\")) this.form.submit();' title='Destroy this account!!'></form></td>";
echo "<td><form action='' method='POST'><input type='hidden' name='update' value='".$record['account']."'><input type='hidden' name='updatet' value='".$record['type']."'><input type='submit' value='Switch' title='Switch Account Type'></form></td></tr>";
}
}else {
foreach($result as $record){
if ($record['uid']==1)
continue;
$record['type']=='a'? $record['type']='A' : $record['type']='B';
echo "<tr><td>".$record['account']."</td><td>".$record['type'],"</td>";
echo "<td><form action='' method='POST'><input type='hidden' name='delete' value='".$record['account']."'><input type='submit' value='Delete' title='Destroy this account!!'></form></td>";
echo "<td><form action='' method='POST'><input type='hidden' name='update' value='".$record['account']."'><input type='hidden' name='updatet' value='".$record['type']."'><input type='submit' value='Switch' title='Switch Account Type'></form></td></tr>";
}
}
?>
</table>
<?php
if (isset($_POST['delete'])){
remove_user($dblink,$_POST['delete']);
db_close($dblink);
header('location: accountmanage.php');
}
if (isset($_POST['updatet'])){
$type = ($_POST['updatet']=='A' ? 'b' : 'a');
if (!update_user_type($dblink,$_POST['update'],$type)){
db_close($dblink);
header('Location: accountmanage.php');
}
}
?>
<div style='font-size: 90%; text-align: center;'>a:can control robot and edit keywords and responses, b:can only edit keywords and responses</div>
<div class='add'>
<h3>Create new user</h3>
<form action='' method='post'><input type='hidden' name='account_create'>
Account name<input type='text' name='name'><br />
Password<input type='password' name='pass'><br />
Confirm password<input type='password' name='repass'><br />
<div style='text-align: center'>Type
<input type="radio" name="auth" value="a" />A<input type="radio" name="auth" value="b" CHECKED/>B</div>
<br /><input type='submit' value='Create'>
</form>
</div>
<?php //add manager
if(isset($_POST['account_create'])){
$pass=$_POST['pass'];
$account=$_POST['name'];
$type=$_POST['auth'];
if(strlen($account) < 3){
echo "<div class='notice-red'>please make account name longer</div>";
} else if($pass==$_POST['repass'] && strlen($pass)>6){
if (!get_user_data($dblink,$account)){
add_user($dblink,$account,$pass,$type);
db_close($dblink);
header('Location: accountmanage.php');
}
else
echo "<div class='notice-red'>user already exists!!</div>";
}
else
echo "<div class='notice-red'>please recheck password.</div>";
}
?>
</div>
</body>
</html>
<?php
db_close($dblink);
}?>