/
all_db.php
166 lines (144 loc) · 5.25 KB
/
all_db.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
<?php
/**
* Manage databases within a server
*
* $Id: all_db.php,v 1.15 2003/06/04 13:31:16 xzilla Exp $
*/
// Include application functions
include_once('libraries/lib.inc.php');
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
if (!isset($msg)) $msg = '';
$PHP_SELF = $_SERVER['PHP_SELF'];
/**
* Show confirmation of drop and perform actual drop
*/
function doDrop($confirm) {
global $data, $localData, $misc;
global $PHP_SELF, $lang, $_reload_drop_database;
if ($confirm) {
echo "<h2>{$lang['strdatabases']}: ", $misc->printVal($_REQUEST['database']), ": {$lang['strdrop']}</h2>\n";
echo "<p>", sprintf($lang['strconfdropdatabase'], $misc->printVal($_REQUEST['database'])), "</p>\n";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
echo "<input type=\"hidden\" name=\"database\" value=\"",
htmlspecialchars($_REQUEST['database']), "\" />\n";
echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n";
echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n";
echo "</form>\n";
}
else {
$localData->close();
$status = $data->dropDatabase($_POST['database']);
if ($status == 0) {
$_reload_drop_database = true;
doDefault($lang['strdatabasedropped']);
}
else
doDefault($lang['strdatabasedroppedbad']);
}
}
/**
* Displays a screen where they can enter a new database
*/
function doCreate($msg = '') {
global $data, $misc;
global $PHP_SELF, $lang;
if (!isset($_POST['formName'])) $_POST['formName'] = '';
if (!isset($_POST['formEncoding'])) $_POST['formEncoding'] = '';
echo "<h2>{$lang['strdatabases']}: {$lang['strcreatedatabase']}</h2>\n";
$misc->printMsg($msg);
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strencoding']}</th></tr>\n";
echo "<tr><td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['formName']), "\" /></td>";
echo "<td class=\"data1\">";
echo "<select name=\"formEncoding\">";
echo "<option value=\"\"></option>\n";
while (list ($key) = each ($data->codemap)) {
echo "<option value=\"", htmlspecialchars($key), "\"",
($key == $_POST['formEncoding']) ? ' selected="selected"' : '', ">",
$misc->printVal($key), "</option>\n";
}
echo "</select>\n";
echo "</td></tr>\n";
echo "</table>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
echo "<input type=\"reset\" value=\"{$lang['strreset']}\" />\n";
echo "</form>\n";
echo "<p><a class=\"navlink\" href=\"$PHP_SELF\">{$lang['strshowalldatabases']}</a></p>\n";
}
/**
* Actually creates the new view in the database
*/
function doSaveCreate() {
global $data, $lang, $_reload_browser;
// Check that they've given a name and a definition
if ($_POST['formName'] == '') doCreate($lang['strdatabaseneedsname']);
else {
$status = $data->createDatabase($_POST['formName'], $_POST['formEncoding']);
if ($status == 0) {
$_reload_browser = true;
doDefault($lang['strdatabasecreated']);
}
else
doCreate($lang['strdatabasecreatedbad']);
}
}
/**
* Show default list of databases in the server
*/
function doDefault($msg = '') {
global $data, $misc;
global $PHP_SELF, $lang;
echo "<h2>{$lang['strdatabases']}</h2>\n";
$misc->printMsg($msg);
$databases = &$data->getDatabases();
if ($databases->recordCount() > 0) {
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strdatabase']}</th><th class=\"data\">{$lang['strowner']}</th>";
echo "<th class=\"data\">{$lang['strencoding']}</th><th class=\"data\">{$lang['strcomment']}</th>";
echo "<th class=\"data\">{$lang['stractions']}</th></tr>\n";
$i = 0;
while (!$databases->EOF) {
$id = (($i % 2) == 0 ? '1' : '2');
echo "<tr><td class=\"data{$id}\">", $misc->printVal($databases->f[$data->dbFields['dbname']]), "</td>\n";
echo "<td class=\"data{$id}\">", $misc->printVal($databases->f[$data->dbFields['owner']]), "</td>\n";
echo "<td class=\"data{$id}\">", $misc->printVal($databases->f[$data->dbFields['encoding']]), "</td>\n";
echo "<td class=\"data{$id}\">", htmlspecialchars($databases->f[$data->dbFields['dbcomment']]), "</td>\n";
echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&database=",
urlencode($databases->f[$data->dbFields['dbname']]), "\">{$lang['strdrop']}</a></td>\n";
echo "</tr>\n";
$databases->moveNext();
$i++;
}
echo "</table>\n";
}
else {
echo "<p>{$lang['strnodatabases']}</p>\n";
}
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create\">{$lang['strcreatedatabase']}</a></p>\n";
}
$misc->printHeader($lang['strdatabases']);
$misc->printBody();
switch ($action) {
case 'save_create':
doSaveCreate();
break;
case 'create':
doCreate();
break;
case 'drop':
if (isset($_REQUEST['yes'])) doDrop(false);
else doDefault();
break;
case 'confirm_drop':
doDrop(true);
break;
default:
doDefault();
break;
}
$misc->printFooter();
?>