1 | <?php
|
---|
2 |
|
---|
3 |
|
---|
4 | require_once 'header.php';
|
---|
5 | valid_login($action_permission['read']);
|
---|
6 |
|
---|
7 | //##############################################################################################
|
---|
8 | // PRINT REPAIR/OPTIMIZE FORM
|
---|
9 | //##############################################################################################
|
---|
10 | function repair_form()
|
---|
11 | {
|
---|
12 | global $output, $lang_global, $lang_repair,
|
---|
13 | $realm_db, $world_db, $characters_db, $mmfpm_db,
|
---|
14 | $action_permission, $user_lvl;
|
---|
15 |
|
---|
16 | $output .= '
|
---|
17 | <center>
|
---|
18 | <fieldset class="tquarter_frame">
|
---|
19 | <legend>'.$lang_repair['repair_optimize'].'</legend>
|
---|
20 | <form action="repair.php?action=do_repair" method="post" name="form">';
|
---|
21 | if($user_lvl >= $action_permission['update'])
|
---|
22 | {
|
---|
23 | $output .= '
|
---|
24 | <table class="hidden">
|
---|
25 | <tr>
|
---|
26 | <td>
|
---|
27 | <select name="repair_action">
|
---|
28 | <option value="REPAIR">'.$lang_repair['repair'].'</option>
|
---|
29 | <option value="OPTIMIZE">'.$lang_repair['optimize'].'</option>
|
---|
30 | </select>
|
---|
31 | </td>
|
---|
32 | <td>';
|
---|
33 | makebutton($lang_repair['start'], 'javascript:do_submit()" type="wrn', 130);
|
---|
34 | $output .= '
|
---|
35 | </td>
|
---|
36 | <td>';
|
---|
37 | makebutton($lang_global['back'], 'javascript:window.history.back()" type="def', 130);
|
---|
38 | $output .= '
|
---|
39 | </td>
|
---|
40 | </tr>
|
---|
41 | </table>
|
---|
42 | <p>'.$lang_repair['select_tables'].'</p>';
|
---|
43 | }
|
---|
44 | $output .= '
|
---|
45 | <script type="text/javascript" src="libs/js/check.js"></script>
|
---|
46 | <table style="width: 550px;" class="lined">
|
---|
47 | <tr>';
|
---|
48 | if($user_lvl >= $action_permission['update'])
|
---|
49 | $output .= '
|
---|
50 | <th width="5%"><input name="allbox" type="checkbox" value="Check All" onclick="CheckAll(document.form);" /></th>';
|
---|
51 | $output .= '
|
---|
52 | <th width="25%">'.$lang_repair['table_name'].'</th>
|
---|
53 | <th width="35%">'.$lang_repair['status'].'</th>
|
---|
54 | <th width="15%">'.$lang_repair['num_records'].'</th>
|
---|
55 | </tr>
|
---|
56 | </table>';
|
---|
57 | $sql = new SQL;
|
---|
58 | $mm_dbs=array($realm_db, $mmfpm_db);
|
---|
59 | foreach ($mm_dbs as $db)
|
---|
60 | {
|
---|
61 | $output.= '
|
---|
62 | <table style="width: 550px;" class="lined">
|
---|
63 | <tr class="large_bold">
|
---|
64 | <td colspan="3" class="hidden" align="left">
|
---|
65 | <div id="div'.$db['name'].'" onclick="expand(\''.$db['name'].'\', this, \''.$db['name'].' '.$lang_repair['tables'].' :\');">[+] '.$db['name'].' '.$lang_repair['tables'].' :</div>
|
---|
66 | </td>
|
---|
67 | </tr>
|
---|
68 | </table>
|
---|
69 | <table id="'.$db['name'].'" style="width: 550px; display: none;" class="lined">';
|
---|
70 | $sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
|
---|
71 | $result = $sql->query('SHOW TABLES FROM '.$db['name'].'');
|
---|
72 |
|
---|
73 | while ($table = $sql->fetch_row($result))
|
---|
74 | {
|
---|
75 | $result1 = $sql->query('SELECT count(*) FROM '.$table[0].'');
|
---|
76 | $result2 = $sql->query('CHECK TABLE '.$table[0].' CHANGED');
|
---|
77 | $output .= '
|
---|
78 | <tr>';
|
---|
79 | if($user_lvl >= $action_permission['update'])
|
---|
80 | $output .= '
|
---|
81 | <td>
|
---|
82 | <input type="checkbox" name="check[]" value="db~0~'.$db['name'].'~'.$table[0].'" onclick="CheckCheckAll(document.form);" />
|
---|
83 | </td>';
|
---|
84 | $output .= '
|
---|
85 | <td>'.$table[0].'</td>
|
---|
86 | <td>'.$sql->result($result2, 0, 'Msg_type').' : '.$sql->result($result2, 0, 'Msg_text').'</td>
|
---|
87 | <td>'.$sql->result($result1, 0).'</td>
|
---|
88 | </tr>';
|
---|
89 | }
|
---|
90 | $output .= '
|
---|
91 | </table>';
|
---|
92 | }
|
---|
93 | $mm_dbs=array($world_db, $characters_db);
|
---|
94 | foreach ($mm_dbs as $dbs)
|
---|
95 | {
|
---|
96 | foreach ($dbs as $dbr => $db)
|
---|
97 | {
|
---|
98 | $output .= '
|
---|
99 | <table style="width: 550px;" class="lined">
|
---|
100 | <tr class="large_bold">
|
---|
101 | <td colspan="3" class="hidden" align="left">
|
---|
102 | <div id="div'.$db['name'].$dbr.'" onclick="expand(\''.$db['name'].$dbr.'\', this, \''.$db['name'].' Realm '.$dbr.' Tables :\');">[+] '.$db['name'].' Realm '.$dbr.' Tables :</div>
|
---|
103 | </td>
|
---|
104 | </tr>
|
---|
105 | </table>
|
---|
106 | <table id="'.$db['name'].$dbr.'" style="width: 550px; display: none;" class="lined">';
|
---|
107 | $sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
|
---|
108 | $result = $sql->query('SHOW TABLES FROM '.$db['name'].'');
|
---|
109 |
|
---|
110 | while ($table = $sql->fetch_row($result))
|
---|
111 | {
|
---|
112 | $result1 = $sql->query('SELECT count(*) FROM '.$table[0].'');
|
---|
113 | $result2 = $sql->query('CHECK TABLE '.$table[0].' CHANGED');
|
---|
114 | $output .= '
|
---|
115 | <tr>';
|
---|
116 | if($user_lvl >= $action_permission['update'])
|
---|
117 | $output .= '
|
---|
118 | <td>
|
---|
119 | <input type="checkbox" name="check[]" value="db~'.$dbr.'~'.$db['name'].'~'.$table[0].'" onclick="CheckCheckAll(document.form);" />
|
---|
120 | </td>';
|
---|
121 | $output .= '
|
---|
122 | <td>'.$table[0].'</td>
|
---|
123 | <td>'.$sql->result($result2, 0, 'Msg_type').' : '.$sql->result($result2, 0, 'Msg_text').'</td>
|
---|
124 | <td>'.$sql->result($result1, 0).'</td>
|
---|
125 | </tr>';
|
---|
126 | }
|
---|
127 | $output .= '
|
---|
128 | </table>';
|
---|
129 | }
|
---|
130 | }
|
---|
131 | unset($dbs);
|
---|
132 | unset($db);
|
---|
133 | unset($result);
|
---|
134 | unset($result2);
|
---|
135 | unset($result1);
|
---|
136 | unset($table);
|
---|
137 | unset($mm_dbs);
|
---|
138 | $output .= '
|
---|
139 | </form>
|
---|
140 | </fieldset>
|
---|
141 | <br /><br />
|
---|
142 | </center>';
|
---|
143 |
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | //##############################################################################################
|
---|
148 | // EXECUTE TABLE REPAIR OR OPTIMIZATION
|
---|
149 | //##############################################################################################
|
---|
150 | function do_repair()
|
---|
151 | {
|
---|
152 | global $output,
|
---|
153 | $realm_db, $mmfpm_db, $world_db, $characters_db,
|
---|
154 | $action_permission;
|
---|
155 | valid_login($action_permission['update']);
|
---|
156 |
|
---|
157 | if ((empty($_POST['repair_action']) && '' === $_POST['repair_action']) || (empty($_POST['check'])) )
|
---|
158 | redirect('repair.php?error=1');
|
---|
159 | else
|
---|
160 | {
|
---|
161 | $table_list = $_POST['check'];
|
---|
162 | $table_action = addslashes($_POST['repair_action']);
|
---|
163 | }
|
---|
164 |
|
---|
165 | $sql = new SQL;
|
---|
166 | $counter = 0;
|
---|
167 |
|
---|
168 | foreach($table_list as $table)
|
---|
169 | {
|
---|
170 | $table_data = explode('~', $table);
|
---|
171 | if ($table_data[2] == $realm_db['name'])
|
---|
172 | $sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
|
---|
173 | elseif ($table_data[2] == $mmfpm_db['name'])
|
---|
174 | $sql->connect($mmfpm_db['addr'], $mmfpm_db['user'], $mmfpm_db['pass'], $mmfpm_db['name']);
|
---|
175 | elseif ($table_data[2] == $world_db[$table_data[1]]['name'])
|
---|
176 | $sql->connect($world_db[$table_data[1]]['addr'], $world_db[$table_data[1]]['user'], $world_db[$table_data[1]]['pass']);
|
---|
177 | elseif ($table_data[2] == $characters_db[$table_data[1]]['name'])
|
---|
178 | $sql->connect($characters_db[$table_data[1]]['addr'], $characters_db[$table_data[1]]['user'], $characters_db[$table_data[1]]['pass']);
|
---|
179 |
|
---|
180 | $action_result = $sql->fetch_row($sql->query(''.$table_action.' TABLE '.$table_data[2].'.'.$table_data[3].''));
|
---|
181 |
|
---|
182 | if ($action_result[3] === 'OK') ++$counter;
|
---|
183 | else $err = $action_result[3];
|
---|
184 | }
|
---|
185 | unset($action_result);
|
---|
186 | unset($table_data);
|
---|
187 | unset($table);
|
---|
188 | unset($table_action);
|
---|
189 | unset($table_list);
|
---|
190 |
|
---|
191 | if ($counter)
|
---|
192 | redirect('repair.php?error=2&num='.$counter.'');
|
---|
193 | else
|
---|
194 | redirect('repair.php?error=4&rep_err='.$err.'');
|
---|
195 |
|
---|
196 | }
|
---|
197 |
|
---|
198 |
|
---|
199 | //########################################################################################################################
|
---|
200 | // MAIN
|
---|
201 | //########################################################################################################################
|
---|
202 | $err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
|
---|
203 | $num = (isset($_GET['num'])) ? $_GET['num'] : NULL;
|
---|
204 | $rep_err = (isset($_GET['rep_err'])) ? $_GET['rep_err'] : NULL;
|
---|
205 |
|
---|
206 | $output .= '
|
---|
207 | <div class="top">';
|
---|
208 |
|
---|
209 | $lang_repair = lang_repair();
|
---|
210 |
|
---|
211 | if (1 == $err)
|
---|
212 | $output .= '
|
---|
213 | <h1><font class="error">'.$lang_global['empty_fields'].'</font></h1>';
|
---|
214 | elseif (2 == $err)
|
---|
215 | $output .= '
|
---|
216 | <h1><font class="error">'.$lang_repair['repair_finished'].' : '.$num.' '.$lang_repair['tables'].'</font></h1>';
|
---|
217 | elseif (3 == $err)
|
---|
218 | $output .= '
|
---|
219 | <h1><font class="error">'.$lang_repair['no_table_selected'].'</font></h1>';
|
---|
220 | elseif (4 == $err)
|
---|
221 | $output .= '
|
---|
222 | <h1><font class="error">'.$lang_repair['repair_error'].' : '.$rep_err.'</font></h1>';
|
---|
223 | else
|
---|
224 | $output .= '
|
---|
225 | <h1>'.$lang_repair['repair_optimize'].'</h1>';
|
---|
226 |
|
---|
227 | $output .= '
|
---|
228 | </div>';
|
---|
229 |
|
---|
230 | unset($err);
|
---|
231 | unset($num);
|
---|
232 | unset($rep_err);
|
---|
233 |
|
---|
234 | $action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
|
---|
235 |
|
---|
236 | if ('repair_form' == $action)
|
---|
237 | repair_form();
|
---|
238 | elseif ('do_repair' == $action)
|
---|
239 | do_repair();
|
---|
240 | else
|
---|
241 | repair_form();
|
---|
242 |
|
---|
243 | unset($action);
|
---|
244 | unset($action_permission);
|
---|
245 | unset($lang_repair);
|
---|
246 |
|
---|
247 | include_once 'footer.php';
|
---|
248 |
|
---|
249 |
|
---|
250 | ?>
|
---|