-
Notifications
You must be signed in to change notification settings - Fork 30
/
dboverview.php
509 lines (391 loc) · 12.8 KB
/
dboverview.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
<?php
/*
SQL Buddy - Web based MySQL administration
http://interruptorgeek.com/sql-buddy-ig-review/
dboverview.php
- database main page - list tables and create new table
MIT license
Original : 2008 Calvin Lough <http://calv.in>
Reviewed : 2016 Carlos Martín Arnillas <https://interruptorgeek.com>
*/
include "functions.php";
loginCheck();
if (isset($db)) {
$conn->selectDB($db);
//run delete queries
if (isset($_POST['runQuery'])) {
$runQuery = $_POST['runQuery'];
$queryList = splitQueryText($runQuery);
foreach ($queryList as $query) {
$query = trim($query);
if ($query != "") {
$conn->query($query) or ($dbError = $conn->error());
// make a list of the tables that were dropped/emptied
if (substr($query, 0, 10) == "DROP TABLE")
$droppedList[] = substr($query, 12, -1);
if (substr($query, 0, 10) == "TRUNCATE `")
$emptiedList[] = substr($query, 10, -1);
if (substr($query, 0, 13) == "DELETE FROM '")
$emptiedList[] = substr($query, 13, -1);
}
}
}
// if tables were dropped, remove them from the side menu
if (isset($droppedList) && isset($db)) {
?>
<script type="text/javascript" authkey="<?php echo $requestKey; ?>">
var targ = $(getSubMenuId('<?php echo $db . "','" . $droppedList[0]; ?>'));
while (!targ.hasClass("sublist")) {
targ = targ.parentNode;
}
var toRecalculate = targ.id;
<?php
for ($mn=0; $mn<count($droppedList); $mn++) {
?>
$(getSubMenuId('<?php echo $db . "','" . $droppedList[$mn]; ?>')).dispose();
<?php
}
?>
recalculateSubmenuHeight(toRecalculate);
</script>
<?php
}
// if tables were emptied, reset their counts in js
if (isset($emptiedList) && isset($db)) {
?>
<script type="text/javascript" authkey="<?php echo $requestKey; ?>">
<?php
for ($mn=0; $mn<count($emptiedList); $mn++) {
echo "sb.tableRowCounts[\"" . $db . "_" . $emptiedList[$mn] . "\"] = \"0\";\n";
echo "var sideA = $(getSubMenuId('" . $db . "', '" . $emptiedList[$mn] . "'));\n";
echo 'var subc = $E(".subcount", sideA);';
echo "\nsubc.set(\"text\", \"(0)\");\n";
}
?>
</script>
<?php
}
if (isset($dbError)) {
echo '<div class="errormessage" style="margin: 6px 12px 10px 7px; width: 550px"><strong>';
echo __("Error performing operation");
echo '</strong><p>' . $dbError . '</p></div>';
}
?>
<table cellpadding="0" class="dboverview" width="750" style="margin: 5px 7px 0">
<tr>
<td>
<?php
$tableSql = $conn->listTables();
if ($conn->isResultSet($tableSql)) {
echo '<div style="margin-bottom: 15px">';
echo '<table class="browsenav">';
echo '<tr>';
echo '<td class="options">';
echo __("Select") . ': <a onclick="checkAll()">' . __("All") . '</a> <a onclick="checkNone()">' . __("None") . '</a>';
echo ' ' . __("With selected") . ': <a onclick="emptySelectedTables()">' . __("Empty") . '</a> <a onclick="dropSelectedTables()">' . __("Drop") . '</a>';
echo ' <a onclick="optimizeSelectedTables()">' . __("Optimize") . '</a>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<div class="grid">';
echo '<div class="emptyvoid"> </div>';
echo '<div class="gridheader impotent">';
echo '<div class="gridheaderinner">';
echo '<table cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<td><div column="1" class="headertitle column1">' . __("Table") . '</div></td>';
echo '<td><div class="columnresizer"></div></td>';
echo '<td><div column="2" class="headertitle column2">' . __("Rows") . '</div></td>';
echo '<td><div class="columnresizer"></div></td>';
if (isset($charsetList) && isset($collationList)) {
echo '<td><div column="3" class="headertitle column3">' . __("Charset") . '</div></td>';
echo '<td><div class="columnresizer"></div></td>';
echo '<td><div column="4" class="headertitle column4">' . __("Overhead") . '</div></td>';
echo '<td><div class="columnresizer"></div></td>';
} else{
echo '<td><div column="3" class="headertitle column3">' . __("Overhead") . '</div></td>';
echo '<td><div class="columnresizer"></div></td>';
}
echo '<td><div class="emptyvoid" style="border-right: 0"> </div></td>';
echo '</tr>';
echo '</table>';
echo '</div>';
echo '</div>';
echo '<div class="leftchecks" style="max-height: 400px">';
$m = 0;
while ($tableRow = $conn->fetchArray($tableSql)) {
echo '<dl class="manip';
if ($m % 2 == 1)
echo ' alternator';
else
echo ' alternator2';
echo '"><dt><input type="checkbox" class="check' . $m . '" onclick="rowClicked(' . $m++ . ')" querybuilder="' . $tableRow[0] . '" /></dt></dl>';
}
echo '</div>';
$tableSql = $conn->listTables();
echo '<div class="gridscroll withchecks" style="overflow-x: hidden; max-height: 400px">';
$m = 0;
while ($tableRow = $conn->fetchArray($tableSql)) {
$rowCount = $conn->tableRowCount($tableRow[0]);
$infoSql = $conn->query("SHOW TABLE STATUS LIKE '" . $tableRow[0] . "'");
$infoRow = $conn->fetchAssoc($infoSql);
$overhead = $infoRow["Data_free"];
$formattedOverhead = "";
if ($overhead > 0){
$formattedOverhead = memoryFormat($overhead);
}
echo '<div class="row' . $m . ' browse';
if ($m % 2 == 1) { echo ' alternator'; }
else
{ echo ' alternator2'; }
echo '">';
echo '<table cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<td><div class="item column1"><div style="float: left; overflow: hidden; width: 185px">' . $tableRow[0] . '</div><img src="images/goto.png" class="goto" onclick="subTabLoad(\'' . $db . '\', \'' . $tableRow[0] . '\')" /></div></td>';
echo '<td><div class="item column2">' . number_format($rowCount) . '</div></td>';
if (isset($collationList) && array_key_exists("Collation", $infoRow)) {
echo '<td><div class="item column3">' . $collationList[$infoRow['Collation']] . '</div></td>';
echo '<td><div class="item column4">' . $formattedOverhead . '</div></td>';
} else{
echo '<td><div class="item column4">' . $formattedOverhead . '</div></td>';
}
echo '</tr>';
echo '</table>';
echo '</div>';
$m++;
}
echo '</div>';
echo '</div>';
echo '<br />';
}
?>
<div class="inputbox" style="width: 275px; margin-bottom: 15px">
<h4><?php echo __("Options"); ?></h4>
<a onclick="confirmDropDatabase()"><?php printf(__("Drop the '%s' database"), $db); ?></a>
</div>
<?php
if (isset($charsetList)) {
$currentChar = "";
$currentCharSql = $conn->query("SHOW VARIABLES LIKE 'character_set_database'");
if ($conn->isResultSet($currentCharSql)) {
$currentChar = $conn->result($currentCharSql, 0, "Value");
}
?>
<div class="inputbox" style="width: 325px; margin-bottom: 15px">
<h4><?php echo __("Edit database"); ?></h4>
<div id="editDatabaseMessage"></div>
<form onsubmit="editDatabase(); return false">
<table cellpadding="4">
<?php
echo "<tr>";
echo "<td class=\"secondaryheader\">";
echo __("Charset") . ":";
echo "</td>";
echo "<td class=\"inputarea\">";
echo "<select id=\"DBRECHARSET\" style=\"width: 145px\">";
echo "<option></option>";
foreach ($charsetList as $charset) {
echo "<option value=\"" . $charset . "\"";
if (isset($currentChar) && $charset == $currentChar)
echo " selected=\"selected\"";
echo ">" . $charset . "</option>";
}
echo "</select>";
echo "</td>";
echo '<td align="left" style="padding-left: 10px">';
echo '<input type="submit" class="inputbutton" value="' . __("Submit") . '" />';
echo '</td>';
echo "</tr>";
?>
</table>
</form>
</div>
<?php
}
?>
<div id="reporterror" class="errormessage" style="display: none; margin-bottom: 15px"></div>
<div class="inputbox">
<h4><?php echo __("Create a new table"); ?></h4>
<form onsubmit="createTable(); return false">
<table cellpadding="0" style="width: 300px">
<tr>
<td class="secondaryheader" style="width: 80px">
<?php echo __("Name") ?>:
</td>
<td>
<input type="text" class="text" id="TABLENAME" style="width: 150px" />
</td>
</tr>
<?php
if (isset($charsetList)) {
echo "<tr>";
echo "<td class=\"secondaryheader\" style=\"width: 60px\">";
echo __("Charset") . ":";
echo "</td>";
echo "<td>";
echo "<select id=\"TABLECHARSET\" style=\"width: 155px\">";
echo "<option></option>";
foreach ($charsetList as $charset) {
echo "<option value=\"" . $charset . "\"";
if (isset($currentChar) && $charset == $currentChar)
echo " selected=\"selected\"";
echo ">" . $charset . "</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
}
if (isset($enginesList)) {
echo "<tr>";
echo "<td class=\"secondaryheader\" style=\"width: 60px\">";
echo __("Engine") . ":";
echo "</td>";
echo "<td>";
echo "<select id=\"TABLEENGINE\" style=\"width: 155px\">";
foreach ($enginesList as $engine => $engineSupport) {
echo "<option value=\"" . $engine . "\"";
if ($engineSupport == 'DEFAULT') {
echo " selected=\"selected\"";
} else if ($engineSupport == 'NO') {
echo " disabled=\"disabled\"";
}
echo ">" . $engine . "</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
}
?>
<tr>
<td style="padding-top: 5px; color: gray" colspan="2">
<?php echo __("Setup the fields for the table below"); ?>:
</td>
</tr>
</table>
<div id="fieldlist">
<div class="fieldbox">
<table cellpadding="0" class="overview">
<tr>
<td colspan="4" class="fieldheader">
<span class="fieldheadertitle"><<?php echo __("New field"); ?>></span>
<a class="fieldclose" onclick="removeField(this)"></a>
</td>
</tr>
<tr>
<td class="secondaryheader">
<?php echo __("Name"); ?>:
</td>
<td>
<input type="text" class="text" name="NAME" onkeyup="updateFieldName(this)" />
</td>
<td class="secondaryheader" style="padding-left: 5px">
<?php echo __("Type"); ?>:
</td>
<td>
<select name="TYPE" onchange="updateFieldName(this); toggleValuesLine(this)">
<?php
foreach ($typeList as $type) {
echo '<option value="' . $type . '">' . $type . '</option>';
}
?>
</select>
</td>
</tr>
<tr class="valueline" style="display: none">
<td class="secondaryheader">
<?php echo __("Values"); ?>:
</td>
<td class="inputarea">
<input type="text" class="text" name="VALUES" onkeyup="updateFieldName(this)" />
</td>
<td colspan="2" style="color: gray">
<?php echo __("Enter in the format: ('1','2')"); ?>
</td>
</tr>
<tr>
<td class="secondaryheader">
<?php echo __("Size") ?>:
</td>
<td class="inputarea">
<input type="text" class="text" name="SIZE" onkeyup="updateFieldName(this)" />
</td>
<td class="secondaryheader" style="padding-left: 5px">
<?php echo __("Key"); ?>:
</td>
<td class="inputarea">
<select name="KEY" onchange="updateFieldName(this)">
<option value=""></option>
<option value="primary"><?php echo __("primary"); ?></option>
<option value="unique"><?php echo __("unique"); ?></option>
<option value="index"><?php echo __("index"); ?></option>
</select>
</td>
</tr>
<tr>
<td class="secondaryheader">
<?php echo __("Default") ?>:
</td>
<td class="inputarea">
<input type="text" class="text" name="DEFAULT" onkeyup="updateFieldName(this)" />
</td>
<?php
if (isset($charsetList)) {
echo "<td class=\"secondaryheader\" style=\"padding-left: 5px\">";
echo __("Charset") . ":";
echo "</td>";
echo "<td class=\"inputarea\">";
echo "<select name=\"CHARSET\" onchange=\"updateFieldName(this)\">";
echo "<option></option>";
foreach ($charsetList as $charset) {
echo "<option value=\"" . $charset . "\">" . $charset . "</option>";
}
echo "</select>";
echo "</td>";
} else {
echo "<td></td>";
echo "<td></td>";
}
?>
</tr>
<tr>
<td class="secondaryheader">
<?php echo __("Other"); ?>:
</td>
<td colspan="3">
<label><input type="checkbox" name="UNSIGN" onchange="updateFieldName(this)"><?php echo __("Unsigned"); ?></label>
<label><input type="checkbox" name="BINARY" onchange="updateFieldName(this)"><?php echo __("Binary"); ?></label>
<label><input type="checkbox" name="NOTNULL" onchange="updateFieldName(this)"><?php echo __("Not Null"); ?></label>
<label><input type="checkbox" name="AUTO" onchange="updateFieldName(this)"><?php echo __("Auto Increment"); ?></label>
</td>
</tr>
</table>
</div>
</div>
<table cellpadding="0" width="370" id="fieldcontrols">
<tr>
<td style="padding: 5px 0 4px">
<input type="submit" class="inputbutton" value="<?php echo __("Submit"); ?>" />
</td>
<td style="padding: 0px 4px 0" align="right" valign="top">
<a onclick="addTableField()" style="font-size: 11px !important"><?php echo __("Add field"); ?></a><div style="visibility: hidden; height: 0"><input type="submit" /></div>
</td>
</tr>
</table>
</form>
</div>
</td>
</table>
<script type="text/javascript" authkey="<?php echo $requestKey; ?>">
setTimeout("startGrid()", 1);
</script>
<?php
}else{
?>
<div class="errorpage">
<h4><?php echo __("Oops"); ?></h4>
<p><?php echo __("For some reason, the database parameter was not included with your request."); ?></p>
</div>
<?php
exit;
}
?>