forked from Amit86/minimanager
-
Notifications
You must be signed in to change notification settings - Fork 38
/
repair.php
255 lines (227 loc) · 10.3 KB
/
repair.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
require_once 'header.php';
valid_login($action_permission['read']);
//##############################################################################################
// PRINT REPAIR/OPTIMIZE FORM
//##############################################################################################
function repair_form()
{
global $output, $lang_global, $lang_repair, $realm_db, $world_db, $characters_db, $mmfpm_db, $action_permission, $user_lvl;
$output .= '
<center>
<fieldset class="tquarter_frame">
<legend>'.$lang_repair['repair_optimize'].'</legend>
<form action="repair.php?action=do_repair" method="post" name="form">';
if($user_lvl >= $action_permission['update'])
{
$output .= '
<table class="hidden">
<tr>
<td>
<select name="repair_action">
<option value="REPAIR">'.$lang_repair['repair'].'</option>
<option value="OPTIMIZE">'.$lang_repair['optimize'].'</option>
</select>
</td>
<td>';
makebutton($lang_repair['start'], 'javascript:do_submit()" type="wrn', 130);
$output .= '
</td>
<td>';
makebutton($lang_global['back'], 'javascript:window.history.back()" type="def', 130);
$output .= '
</td>
</tr>
</table>
<p>'.$lang_repair['select_tables'].'</p>';
}
$output .= '
<script type="text/javascript" src="libs/js/check.js"></script>
<table style="width: 550px;" class="lined">
<tr>';
if($user_lvl >= $action_permission['update'])
$output .= '
<th width="5%"><input name="allbox" type="checkbox" value="Check All" onclick="CheckAll(document.form);" /></th>';
$output .= '
<th width="25%">'.$lang_repair['table_name'].'</th>
<th width="35%">'.$lang_repair['status'].'</th>
<th width="15%">'.$lang_repair['num_records'].'</th>
</tr>
</table>';
$sql = new SQL;
$mm_dbs= [$realm_db, $mmfpm_db];
foreach ($mm_dbs as $db)
{
$output.= '
<table style="width: 550px;" class="lined">
<tr class="large_bold">
<td colspan="3" class="hidden" align="left">
<div id="div'.$db['name'].'" onclick="expand(\''.$db['name'].'\', this, \''.$db['name'].' '.$lang_repair['tables'].' :\');">[+] '.$db['name'].' '.$lang_repair['tables'].' :</div>
</td>
</tr>
</table>
<table id="'.$db['name'].'" style="width: 550px; display: none;" class="lined">';
$sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
$result = $sql->query('SHOW TABLES FROM '.$db['name'].'');
while ($table = $sql->fetch_row($result))
{
$result1 = $sql->query('SELECT count(*) FROM '.$table[0].'');
$result2 = $sql->query('CHECK TABLE '.$table[0].' CHANGED');
$output .= '
<tr>';
if($user_lvl >= $action_permission['update'])
$output .= '
<td>
<input type="checkbox" name="check[]" value="db~0~'.$db['name'].'~'.$table[0].'" onclick="CheckCheckAll(document.form);" />
</td>';
$output .= '
<td>'.$table[0].'</td>
<td>'.$sql->result($result2, 0, 'Msg_type').' : '.$sql->result($result2, 0, 'Msg_text').'</td>
<td>'.$sql->result($result1, 0).'</td>
</tr>';
}
$output .= '
</table>';
}
$mm_dbs= [$world_db, $characters_db];
foreach ($mm_dbs as $dbs)
{
foreach ($dbs as $dbr => $db)
{
$output .= '
<table style="width: 550px;" class="lined">
<tr class="large_bold">
<td colspan="3" class="hidden" align="left">
<div id="div'.$db['name'].$dbr.'" onclick="expand(\''.$db['name'].$dbr.'\', this, \''.$db['name'].' Realm '.$dbr.' Tables :\');">[+] '.$db['name'].' Realm '.$dbr.' Tables :</div>
</td>
</tr>
</table>
<table id="'.$db['name'].$dbr.'" style="width: 550px; display: none;" class="lined">';
$sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
$result = $sql->query('SHOW TABLES FROM '.$db['name'].'');
while ($table = $sql->fetch_row($result))
{
$result1 = $sql->query('SELECT count(*) FROM '.$table[0].'');
$result2 = $sql->query('CHECK TABLE '.$table[0].' CHANGED');
$output .= '
<tr>';
if($user_lvl >= $action_permission['update'])
$output .= '
<td>
<input type="checkbox" name="check[]" value="db~'.$dbr.'~'.$db['name'].'~'.$table[0].'" onclick="CheckCheckAll(document.form);" />
</td>';
$output .= '
<td>'.$table[0].'</td>
<td>'.$sql->result($result2, 0, 'Msg_type').' : '.$sql->result($result2, 0, 'Msg_text').'</td>
<td>'.$sql->result($result1, 0).'</td>
</tr>';
}
$output .= '
</table>';
}
}
unset($dbs);
unset($db);
unset($result);
unset($result2);
unset($result1);
unset($table);
unset($mm_dbs);
$output .= '
</form>
</fieldset>
<br /><br />
</center>';
}
//##############################################################################################
// EXECUTE TABLE REPAIR OR OPTIMIZATION
//##############################################################################################
function do_repair()
{
global $output, $realm_db, $mmfpm_db, $world_db, $characters_db, $action_permission;
valid_login($action_permission['update']);
if ((empty($_POST['repair_action']) && '' === $_POST['repair_action']) || (empty($_POST['check'])) )
redirect('repair.php?error=1');
else
{
$table_list = $_POST['check'];
$table_action = addslashes($_POST['repair_action']);
}
$sql = new SQL;
$counter = 0;
foreach($table_list as $table)
{
$table_data = explode('~', $table);
if ($table_data[2] == $realm_db['name'])
$sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
elseif ($table_data[2] == $mmfpm_db['name'])
$sql->connect($mmfpm_db['addr'], $mmfpm_db['user'], $mmfpm_db['pass'], $mmfpm_db['name']);
elseif ($table_data[2] == $world_db[$table_data[1]]['name'])
$sql->connect($world_db[$table_data[1]]['addr'], $world_db[$table_data[1]]['user'], $world_db[$table_data[1]]['pass']);
elseif ($table_data[2] == $characters_db[$table_data[1]]['name'])
$sql->connect($characters_db[$table_data[1]]['addr'], $characters_db[$table_data[1]]['user'], $characters_db[$table_data[1]]['pass']);
$action_result = $sql->fetch_row($sql->query(''.$table_action.' TABLE '.$table_data[2].'.'.$table_data[3].''));
if ($action_result[3] === 'OK')
++$counter;
else
$err = $action_result[3];
}
unset($action_result);
unset($table_data);
unset($table);
unset($table_action);
unset($table_list);
if ($counter)
redirect('repair.php?error=2&num='.$counter.'');
else
redirect('repair.php?error=4&rep_err='.$err.'');
}
//########################################################################################################################
// MAIN
//########################################################################################################################
$err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
$num = (isset($_GET['num'])) ? $_GET['num'] : NULL;
$rep_err = (isset($_GET['rep_err'])) ? $_GET['rep_err'] : NULL;
$output .= '
<div class="top">';
$lang_repair = lang_repair();
if (1 == $err)
$output .= '
<h1>
<font class="error">'.$lang_global['empty_fields'].'</font>
</h1>';
elseif (2 == $err)
$output .= '
<h1>
<font class="error">'.$lang_repair['repair_finished'].' : '.$num.' '.$lang_repair['tables'].'</font>
</h1>';
elseif (3 == $err)
$output .= '
<h1>
<font class="error">'.$lang_repair['no_table_selected'].'</font>
</h1>';
elseif (4 == $err)
$output .= '
<h1>
<font class="error">'.$lang_repair['repair_error'].' : '.$rep_err.'</font>
</h1>';
else
$output .= '
<h1>'.$lang_repair['repair_optimize'].'</h1>';
$output .= '
</div>';
unset($err);
unset($num);
unset($rep_err);
$action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
if ('repair_form' == $action)
repair_form();
elseif ('do_repair' == $action)
do_repair();
else
repair_form();
unset($action);
unset($action_permission);
unset($lang_repair);
include_once 'footer.php';
?>