forked from Amit86/minimanager
-
Notifications
You must be signed in to change notification settings - Fork 38
/
command.php
214 lines (185 loc) · 7.49 KB
/
command.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
// page header, and any additional required libraries
include 'header.php';
// minimum permission to view page
valid_login($action_permission['read']);
//#############################################################################
// PRINT COMMAND FORM
//#############################################################################
function print_commands_form()
{
global $output, $lang_command, $realm_id, $world_db, $action_permission, $user_lvl, $gm_level_arr;
$levels = $gm_level_arr;
$sqlw = new SQL;
$sqlw->connect($world_db[$realm_id]['addr'], $world_db[$realm_id]['user'], $world_db[$realm_id]['pass'], $world_db[$realm_id]['name']);
$query = $sqlw->query('SELECT name, help FROM command WHERE security <= '.$user_lvl.'');
while ($data = $sqlw->fetch_assoc($query))
{
$comm = explode("\r\n", $data['help'], 2);
$levels[$data['security']][3] .= '
<tr>
'.(($user_lvl >= $action_permission['update']) ? '<td><input type="checkbox" name="check['.$data['name'].']" value="'.$data['security'].'" /></td>' : '<td></td>').'
<td align="left">'.$data['name'].'</td>
<td>'.htmlentities(preg_replace("/[a-zA-Z ]+:* *\./", ".", $comm[0])).'</td>
<td>'.(isset($comm[1]) ? str_replace("\r\n", "<br />", str_replace("\r\n\r\n", "<br />", htmlentities($comm[1]))): '').'</td>
</tr>';
}
unset($comm);
unset($data);
unset($query);
$output .= '
<center>
<form method="get" action="command.php" name="form">
<input type="hidden" name="action" value="update" />';
for ($i=0; $i<=$user_lvl; ++$i)
{
$output .= '
<table style="width: 720px; text-align: left;" class="lined">
<tr>
<th>
<div id="div'.$levels[$i][1].'" onclick="expand(\''.$levels[$i][1].'\', this, \''.$levels[$i][1].'\');">[+] '.$levels[$i][1].' :</div>
</th>
</tr>
</table>
<table id="'.$levels[$i][1].'" class="lined" style="width: 720px; text-align: left; display: none">
<tr style="text-align: center;">
<th width="2%"></th>
<th width="13%">'.$lang_command['command'].'</th>
<th width="20%">'.$lang_command['syntax'].'</th>
<th width="65%">'.$lang_command['description'].'</th>
</tr>'.$levels[$i][3];
if($user_lvl >= $action_permission['update'])
{
$output .= '
</table>
<br />
<table class="hidden" style="width: 720px;">
<tr>
<td>';
makebutton($lang_command['change_level'], 'javascript:do_submit()',280);
$output .= '
</td>
</tr>';
}
$output .= '
</table>
<br />';
}
$output .= '
</form>
</center>';
}
//#############################################################################
// UPDATE COMMAND LEVEL
//#############################################################################
function update_commands()
{
global $output, $lang_global, $lang_command, $action_permission, $user_lvl, $gm_level_arr;
valid_login($action_permission['update']);
if(isset($_GET['check']))
$check = $_GET['check'];
else
redirect('command.php?error=1');
$output .= '
<center>
<form method="get" action="command.php" name="form">
<input type="hidden" name="action" value="doupdate" />
<table class="lined" style="width: 700px;">
<tr>
<th width="1%"></th>';
for ($i=0; $i<=$user_lvl; ++$i)
$output .= '
<th width="1%">'.$gm_level_arr[$i][1].'</th>';
$output .= '
</tr>';
$commands = array_keys($check);
$n_commands = count($check);
for ($i=0; $i<$n_commands; ++$i)
{
$output .= '
<tr>
<td>'.$commands[$i].'</td>';
for ($j=0; $j<=$user_lvl; ++$j)
{
$output .= '
<td>
<input type="radio" name="change['.$commands[$i].']" value="'.$j.'"';
if ($j==$check[$commands[$i]])
$output .= ' checked="checked"';
$output .= ' />
</td>';
}
$output .= '
</tr>';
}
unset($n_commands);
unset($commands);
unset($check);
$output .= '
</table>
</form>
<table width="300" class="hidden">
<tr>
<td>';
makebutton($lang_command['save'], 'javascript:do_submit()" type="wrn', 130);
makebutton($lang_global['back'], 'command.php" type="def', 130);
$output .= '
</td>
</tr>
</table>
</center>';
}
//#############################################################################
// DO UPDATE COMMAND LEVEL
//#############################################################################
function doupdate_commands()
{
global $output, $realm_id, $world_db, $action_permission;
valid_login($action_permission['update']);
$sqlw = new SQL;
$sqlw->connect($world_db[$realm_id]['addr'], $world_db[$realm_id]['user'], $world_db[$realm_id]['pass'], $world_db[$realm_id]['name']);
if(isset($_GET['change']))
$change = $sqlw->quote_smart($_GET['change']);
else
redirect('command.php?error=1');
$commands = array_keys($change);
$n_commands = count($change);
for ($i=0; $i<$n_commands; ++$i)
{
$query = $sqlw->query('UPDATE command SET security = '.$change[$commands[$i]].' WHERE name= \''.$commands[$i].'\'');
}
unset($n_commands);
unset($commands);
unset($change);
redirect('command.php');
}
//#############################################################################
// MAIN
//#############################################################################
$err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
$output .= '
<div class="top">';
$lang_command = lang_command();
if(1 == $err)
$output .= '
<h1>
<font class="error">'.$lang_global['empty_fields'].'</font>
</h1>';
else
$output .= '
<h1>'.$lang_command['command_list'].'</h1>';
unset($err);
$output .= '
</div>';
$action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
if ('update' == $action)
update_commands();
elseif ('doupdate' == $action)
doupdate_commands();
else
print_commands_form();
unset($action);
unset($action_permission);
unset($lang_command);
include 'footer.php';
?>