source: minimanager/repair.php@ 19

Last change on this file since 19 was 19, checked in by george, 18 years ago

Aktualizace MaNGOS Minimanageru na verzi 0.1.4a.

File size: 5.8 KB
Line 
1<?php
2/*
3 * Project Name: MiniManager for Mangos Server
4 * Date: 17.10.2006 inital version (0.0.1a)
5 * Author: Q.SA
6 * Copyright: Q.SA
7 * Email: *****
8 * License: GNU General Public License v2(GPL)
9 */
10
11require_once("header.php");
12valid_login(3);
13
14//##############################################################################################
15// PRINT REPAIR/OPTIMIZE FORM
16//##############################################################################################
17function repair_form(){
18 global $lang_global, $lang_repair, $output, $realm_db, $realm_id, $mangos_db;
19
20 $output .= "<center>
21 <fieldset style=\"width: 700px;\">
22 <legend>{$lang_repair['repair_optimize']}</legend>
23 <form action=\"repair.php?action=do_repair\" method=\"post\" name=\"form\">
24 <table class=\"hidden\">";
25 $output .= "<tr><td>
26 <select name=\"repair_action\">
27 <option value=\"REPAIR\">{$lang_repair['repair']}</option>
28 <option value=\"OPTIMIZE\">{$lang_repair['optimize']}</option>
29 </select>
30 </td><td>";
31 makebutton($lang_repair['start'], "javascript:do_submit()",100);
32 makebutton($lang_global['back'], "javascript:window.history.back()",100);
33 $output .= "</td></tr>
34 </table><p>{$lang_repair['select_tables']}</p>";
35 $output .="<script type=\"text/javascript\" src=\"js/check.js\"></script>";
36
37 $sql = new SQL;
38 $sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
39
40 $result = $sql->query("SHOW TABLES FROM {$realm_db['name']}");
41
42 $output .= "<table class=\"lined\" style=\"width: 550px;\">
43 <tr>
44 <th width=\"5%\"><input name=\"allbox\" type=\"checkbox\" value=\"Check All\" onclick=\"CheckAll(document.form);\" /></th>
45 <th width=\"25%\">{$lang_repair['table_name']}</th>
46 <th width=\"35%\">{$lang_repair['status']}</th>
47 <th width=\"15%\">{$lang_repair['num_records']}</th>
48 </tr>
49 <tr class=\"large_bold\"><td colspan=\"3\" class=\"hidden\" align=\"left\">{$realm_db['name']} {$lang_repair['tables']} :</td></tr>";
50
51 while ($table = $sql->fetch_row($result)){
52 $result1 = $sql->query("SELECT count(*) FROM `$table[0]`");
53 $result2 = $sql->query("CHECK TABLE `$table[0]` CHANGED");
54
55 $output .= "<tr>
56 <td><input type=\"checkbox\" name=\"check[]\" value=\"realm~0~{$realm_db['name']}~$table[0]\" onclick=\"CheckCheckAll(document.form);\" /></td>
57 <td>$table[0]</td>
58 <td>".$sql->result($result2, 0, 'Msg_type')." : ".$sql->result($result2, 0, 'Msg_text')."</td>
59 <td>".$sql->result($result1, 0)."</td>
60 </tr>";
61}
62
63 foreach ($mangos_db as $db){
64 $output .= "<tr class=\"large_bold\"><td colspan=\"3\" class=\"hidden\" align=\"left\">{$db['name']} Tables :</td></tr>";
65
66 $sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
67 $result = $sql->query("SHOW TABLES FROM {$db['name']}");
68
69 while ($table = $sql->fetch_row($result)){
70 $result1 = $sql->query("SELECT count(*) FROM `$table[0]`");
71 $result2 = $sql->query("CHECK TABLE `$table[0]` CHANGED");
72
73 $output .= "<tr>
74 <td><input type=\"checkbox\" name=\"check[]\" value=\"world~{$db['id']}~{$db['name']}~$table[0]\" onclick=\"CheckCheckAll(document.form);\" /></td>
75 <td>$table[0]</td>
76 <td>".$sql->result($result2, 0, 'Msg_type')." : ".$sql->result($result2, 0, 'Msg_text')."</td>
77 <td>".$sql->result($result1, 0)."</td>
78 </tr>";
79 }
80 }
81
82 $output .= "</table></form></fieldset><br /><br /></center>";
83}
84
85
86//##############################################################################################
87// EXECUTE TABLE REPAIR OR OPTIMIZATION
88//##############################################################################################
89function do_repair(){
90 global $lang_global, $output, $realm_db, $mangos_db;
91
92 if ((!isset($_POST['repair_action']) && $_POST['repair_action'] === '') || (!isset($_POST['check'])) ) {
93 redirect("repair.php?error=1");
94 } else {
95 $table_list = $_POST['check'];
96 $table_action = addslashes($_POST['repair_action']);
97 }
98
99 $sql = new SQL;
100 $counter = 0;
101
102 foreach($table_list as $table){
103
104 $table_data = explode("~", $table);
105 if ($table_data[0] == "realm"){
106 $sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
107 } else {
108 $sql->connect($mangos_db[$table_data[1]]['addr'], $mangos_db[$table_data[1]]['user'], $mangos_db[$table_data[1]]['pass']);
109 }
110
111 $result = $sql->query("$table_action TABLE {$table_data[2]}.`{$table_data[3]}`");
112 $action_result = $sql->fetch_row($result);
113
114 if ($action_result[3] === "OK") $counter++;
115 else $err = $action_result[3];
116 }
117
118 if ($counter) redirect("repair.php?error=2&num=$counter");
119 else redirect("repair.php?error=4&rep_err=$err");
120}
121
122
123//########################################################################################################################
124// MAIN
125//########################################################################################################################
126$err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
127$num = (isset($_GET['num'])) ? $_GET['num'] : NULL;
128$rep_err = (isset($_GET['rep_err'])) ? $_GET['rep_err'] : NULL;
129
130$output .= "<div class=\"top\">";
131switch ($err) {
132case 1:
133 $output .= "<h1><font class=\"error\">{$lang_global['empty_fields']}</font></h1>";
134 break;
135case 2:
136 $output .= "<h1><font class=\"error\">{$lang_repair['repair_finished']} : $num {$lang_repair['tables']}</font></h1>";
137 break;
138case 3:
139 $output .= "<h1><font class=\"error\">{$lang_repair['no_table_selected']}</font></h1>";
140 break;
141case 4:
142 $output .= "<h1><font class=\"error\">{$lang_repair['repair_error']} : $rep_err</font></h1>";
143 break;
144default: //no error
145 $output .= "<h1>{$lang_repair['repair_optimize']}</h1>";
146}
147$output .= "</div>";
148
149$action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
150
151switch ($action) {
152case "repair_form":
153 repair_form();
154 break;
155case "do_repair":
156 do_repair();
157 break;
158default:
159 repair_form();
160}
161
162include_once("footer.php");
163?>
Note: See TracBrowser for help on using the repository browser.