source: trunk/test_server/command.php@ 649

Last change on this file since 649 was 649, checked in by barny, 15 years ago

*Přidán minimanager pro test server

File size: 6.6 KB
Line 
1<?php
2
3
4// page header, and any additional required libraries
5include 'header.php';
6// minimum permission to view page
7valid_login($action_permission['read']);
8
9//#############################################################################
10// PRINT COMMAND FORM
11//#############################################################################
12function print_commands_form()
13{
14 global $output, $lang_command,
15 $realm_id, $world_db,
16 $action_permission, $user_lvl, $gm_level_arr;
17
18 $levels = $gm_level_arr;
19
20 $sqlw = new SQL;
21 $sqlw->connect($world_db[$realm_id]['addr'], $world_db[$realm_id]['user'], $world_db[$realm_id]['pass'], $world_db[$realm_id]['name']);
22
23 $query = $sqlw->query('SELECT name, help, security FROM command WHERE security <= '.$user_lvl.'');
24
25 while ($data = $sqlw->fetch_assoc($query))
26 {
27 $comm = explode("\r\n", $data['help'], 2);
28 $levels[$data['security']][3] .= '
29 <tr>
30 '.(($user_lvl >= $action_permission['update']) ? '<td><input type="checkbox" name="check['.$data['name'].']" value="'.$data['security'].'" /></td>' : '<td></td>').'
31 <td align="left">'.$data['name'].'</td>
32 <td>'.htmlentities(ereg_replace("[a-zA-Z ]+:* *\.", ".", $comm[0])).'</td>
33 <td>'.(isset($comm[1]) ? str_replace("\r\n", "<br />", str_replace("\r\n\r\n", "<br />", htmlentities($comm[1]))): '').'</td>
34 </tr>';
35 }
36 unset($comm);
37 unset($data);
38 unset($query);
39
40 $output .= '
41 <center>
42 <form method="get" action="command.php" name="form">
43 <input type="hidden" name="action" value="update" />';
44 for ($i=0; $i<=$user_lvl; ++$i)
45 {
46 $output .= '
47 <table style="width: 720px; text-align: left;" class="lined">
48 <tr>
49 <th>
50 <div id="div'.$levels[$i][1].'" onclick="expand(\''.$levels[$i][1].'\', this, \''.$levels[$i][1].'\');">[+] '.$levels[$i][1].' :</div>
51 </th>
52 </tr>
53 </table>
54 <table id="'.$levels[$i][1].'" class="lined" style="width: 720px; text-align: left; display: none">
55 <tr style="text-align: center;">
56 <th width="2%"></th>
57 <th width="13%">'.$lang_command['command'].'</th>
58 <th width="20%">'.$lang_command['syntax'].'</th>
59 <th width="65%">'.$lang_command['description'].'</th>
60 </tr>'.$levels[$i][3];
61 if($user_lvl >= $action_permission['update'])
62 {
63 $output .= '
64 </table>
65 <br />
66 <table class="hidden" style="width: 720px;">
67 <tr>
68 <td>';
69 makebutton($lang_command['change_level'], 'javascript:do_submit()',280);
70 $output .= '
71 </td>
72 </tr>';
73 }
74 $output .= '
75 </table>
76 <br />';
77 }
78 $output .= '
79 </form>
80 </center>';
81
82}
83
84
85//#############################################################################
86// UPDATE COMMAND LEVEL
87//#############################################################################
88function update_commands()
89{
90 global $output, $lang_global, $lang_command,
91 $action_permission, $user_lvl, $gm_level_arr;
92 valid_login($action_permission['update']);
93
94 if(isset($_GET['check'])) $check = $_GET['check'];
95 else redirect('command.php?error=1');
96
97 $output .= '
98 <center>
99 <form method="get" action="command.php" name="form">
100 <input type="hidden" name="action" value="doupdate" />
101 <table class="lined" style="width: 700px;">
102 <tr>
103 <th width="1%"></th>';
104 for ($i=0; $i<=$user_lvl; ++$i)
105 {
106 $output .= '
107 <th width="1%">'.$gm_level_arr[$i][1].'</th>';
108 }
109
110 $output .= '
111 </tr>';
112
113 $commands = array_keys($check);
114 $n_commands = count($check);
115 for ($i=0; $i<$n_commands; ++$i)
116 {
117 $output .= '
118 <tr>
119 <td>'.$commands[$i].'</td>';
120 for ($j=0; $j<=$user_lvl; ++$j)
121 {
122 $output .= '
123 <td><input type="radio" name="change['.$commands[$i].']" value="'.$j.'"';
124 if ($j==$check[$commands[$i]])
125 $output .= ' checked="checked"';
126 $output .= ' /></td>';
127 }
128 $output .= '
129 </tr>';
130 }
131 unset($n_commands);
132 unset($commands);
133 unset($check);
134 $output .= '
135 </table>
136 </form>
137 <table width="300" class="hidden">
138 <tr>
139 <td>';
140 makebutton($lang_command['save'], 'javascript:do_submit()" type="wrn', 130);
141 makebutton($lang_global['back'], 'command.php" type="def', 130);
142 $output .= '
143 </td>
144 </tr>
145 </table>
146 </center';
147}
148
149
150//#############################################################################
151// DO UPDATE COMMAND LEVEL
152//#############################################################################
153function doupdate_commands()
154{
155 global $output,
156 $realm_id, $world_db,
157 $action_permission;
158 valid_login($action_permission['update']);
159
160 $sqlw = new SQL;
161 $sqlw->connect($world_db[$realm_id]['addr'], $world_db[$realm_id]['user'], $world_db[$realm_id]['pass'], $world_db[$realm_id]['name']);
162
163 if(isset($_GET['change']))
164 $change = $sqlw->quote_smart($_GET['change']);
165 else
166 redirect('command.php?error=1');
167
168 $commands = array_keys($change);
169 $n_commands = count($change);
170 for ($i=0; $i<$n_commands; ++$i)
171 {
172 $query = $sqlw->query('UPDATE command SET security = '.$change[$commands[$i]].' WHERE name= \''.$commands[$i].'\'');
173 }
174 unset($n_commands);
175 unset($commands);
176 unset($change);
177 redirect('command.php');
178}
179
180
181//#############################################################################
182// MAIN
183//#############################################################################
184$err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
185
186$output .= '
187 <div class="top">';
188
189$lang_command = lang_command();
190
191if(1 == $err)
192 $output .= '
193 <h1><font class="error">'.$lang_global['empty_fields'].'</font></h1>';
194else
195 $output .= '
196 <h1>'.$lang_command['command_list'].'</h1>';
197
198unset($err);
199
200$output .= '
201 </div>';
202
203$action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
204
205if ('update' == $action)
206 update_commands();
207elseif ('doupdate' == $action)
208 doupdate_commands();
209else
210 print_commands_form();
211
212unset($action);
213unset($action_permission);
214unset($lang_command);
215
216include 'footer.php';
217
218
219?>
Note: See TracBrowser for help on using the repository browser.