forked from sandboxgangster/Part-DB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_database.php
executable file
·219 lines (188 loc) · 10.5 KB
/
system_database.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
<?php
/*
part-db version 0.1
Copyright (C) 2005 Christoph Lechner
http://www.cl-projects.de/
part-db version 0.2+
Copyright (C) 2009 K. Jacobs and others (see authors.php)
http://code.google.com/p/part-db/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
$Id$
Changelog (sorted by date):
[DATE] [NICKNAME] [CHANGES]
2012-??-?? weinbauer73 - changed to templates
2012-09-14 kami89 - changed to OOP
*/
include_once('start_session.php');
$messages = array();
$fatal_error = false; // if a fatal error occurs, only the $messages will be printed, but not the site content
/********************************************************************************
*
* Evaluate $_REQUEST
*
*********************************************************************************/
$db_type = isset($_REQUEST['db_type']) ? (string)$_REQUEST['db_type'] : 'mysql';
$db_charset = isset($_REQUEST['db_charset']) ? (string)$_REQUEST['db_charset'] : 'utf8';
$db_host = isset($_REQUEST['db_host']) ? (string)$_REQUEST['db_host'] : 'localhost';
$db_name = isset($_REQUEST['db_name']) ? (string)$_REQUEST['db_name'] : '';
$db_user = isset($_REQUEST['db_user']) ? (string)$_REQUEST['db_user'] : '';
$db_password = isset($_REQUEST['db_password']) ? trim((string)$_REQUEST['db_password']) : '';
$admin_password = isset($_REQUEST['admin_password']) ? trim((string)$_REQUEST['admin_password']) : '';
$automatic_updates_enabled = isset($_REQUEST['automatic_updates_enabled']);
$action = 'default';
if (isset($_REQUEST["apply_connection_settings"])) {$action = 'apply_connection_settings';}
if (isset($_REQUEST["apply_auto_updates"])) {$action = 'apply_auto_updates';}
if (isset($_REQUEST["make_update"])) {$action = 'make_update';}
if (isset($_REQUEST["make_new_update"])) {$action = 'make_new_update';}
/********************************************************************************
*
* Initialize Objects
*
*********************************************************************************/
$html = new HTML($config['html']['theme'], $config['html']['custom_css'], 'Datenbank');
try
{
$database = new Database();
}
catch (Exception $e)
{
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
$fatal_error = true;
}
/********************************************************************************
*
* Execute actions
*
*********************************************************************************/
switch ($action)
{
case 'apply_connection_settings':
$config_old = $config;
try
{
if ($config['is_online_demo'])
break;
if ( ! is_admin_password($admin_password))
throw new Exception('Das Administratorpasswort ist falsch!');
$config['db']['type'] = $db_type;
//$config['db']['charset'] = $db_charset; // temporarly deactivated
$config['db']['host'] = $db_host;
$config['db']['name'] = $db_name;
$config['db']['user'] = $db_user;
$config['db']['password'] = $db_password;
save_config();
header('Location: system_database.php'); // Reload the page that we can see if the new settings are stored successfully
}
catch (Exception $e)
{
$config = $config_old; // reload the old config
$messages[] = array('text' => 'Die neuen Werte konnten nicht gespeichert werden!', 'strong' => true, 'color' => 'red');
$messages[] = array('text' => 'Fehlermeldung: '.nl2br($e->getMessage()), 'color' => 'red');
}
break;
case 'apply_auto_updates':
$config_old = $config;
try
{
$config['db']['auto_update'] = $automatic_updates_enabled;
save_config();
header('Location: system_database.php'); // Reload the page that we can see if the new settings are stored successfully
}
catch (Exception $e)
{
$config = $config_old; // reload the old config
$messages[] = array('text' => 'Die neuen Werte konnten nicht gespeichert werden!', 'strong' => true, 'color' => 'red');
$messages[] = array('text' => 'Fehlermeldung: '.nl2br($e->getMessage()), 'color' => 'red');
}
break;
case 'make_new_update':
// start the next update attempt from the beginning, not from the step of the last error
$config['db']['update_error']['version'] = -1;
$config['db']['update_error']['next_step'] = 0;
case 'make_update':
try
{
if ( ! is_object($database))
throw new Exception('Es konnte keine Verbindung mit der Datenbank hergestellt werden!');
$database_update_executed = true;
$update_log = $database->update();
$messages[] = array('text' => nl2br($update_log), 'color' => 'red');
}
catch (Exception $e)
{
$messages[] = array('text' => 'Es trat ein Fehler auf!', 'strong' => true, 'color' => 'red');
$messages[] = array('text' => 'Fehlermeldung: '.nl2br($e->getMessage()), 'color' => 'red');
}
break;
}
/********************************************************************************
*
* Set all HTML variables
*
*********************************************************************************/
$html->set_variable('is_online_demo', $config['is_online_demo'], 'boolean');
$html->set_loop('db_type_loop', array_to_template_loop($config['db_types'], $config['db']['type']));
$html->set_loop('db_charset_loop', array_to_template_loop($config['db_charsets'], $config['db']['charset']));
$html->set_variable('db_host', $config['db']['host'], 'string');
$html->set_variable('db_name', $config['db']['name'], 'string');
$html->set_variable('db_user', $config['db']['user'], 'string');
$html->set_variable('automatic_updates_enabled', $config['db']['auto_update'], 'boolean');
$html->set_variable('refresh_navigation_frame', (isset($database_update_executed) && $database_update_executed), 'boolean');
if (! $fatal_error)
{
try
{
$current = $database->get_current_version();
$latest = $database->get_latest_version();
$html->set_variable('current_version', $current, 'integer');
$html->set_variable('latest_version', $latest, 'integer');
$html->set_variable('update_required', ($latest > $current), 'boolean');
$html->set_variable('last_update_failed', ($config['db']['update_error']['version'] == $current), 'boolean');
if (($current > 0) && ($current < 13) && ($latest >= 13)) // v12 to v13 was a huge update! show warning!
{
$messages[] = array('text' => 'Achtung!<br><br>'.
'Das Datenbankupdate auf Version 13 ist sehr umfangreich, es finden sehr viele Veränderungen statt.<br>'.
'Es wird dringend empfohlen, vor dem Update eine Sicherung der Datenbank anzulegen, '.
'damit diese im Fehlerfall wiederhergestellt, und so ein Datenverlust verhindert werden kann.<br>'.
'Die Entwickler von Part-DB übernehmen keinerlei Haftung für Schäden, die durch fehlgeschlagene Updates, '.
'Fehler in der Software oder durch andere Ursachen hervorgerufen werden.',
'strong' => true, 'color' => 'red', );
}
elseif (($current > 0) && ($latest > $current)) // normal update...we will show a hint
{
$messages[] = array('text' => 'Hinweis:<br><br>'.
'Es wird dringend empfohlen, vor jedem Datenbankupdate eine Sicherung der Datenbank anzulegen.<br>'.
'Die Entwickler von Part-DB übernehmen keinerlei Haftung für Schäden, die durch fehlgeschlagene Updates, '.
'Fehler in der Software oder durch andere Ursachen hervorgerufen werden.',
'strong' => true, 'color' => 'red', );
}
}
catch (Exception $e)
{
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red', );
$fatal_error = true;
}
}
$html->set_variable('hide_status', $fatal_error, 'boolean');
/********************************************************************************
*
* Generate HTML Output
*
*********************************************************************************/
// an empty $reload_link means that the reload-button won't be visible
$reload_link = ($fatal_error || isset($database_update_executed)) ? 'system_database.php' : '';
$html->print_header($messages, $reload_link);
//if (! $fatal_error) // we don't hide the site content if there is an error, because this way we can set the database connection data
$html->print_template('system_database');
$html->print_footer();
?>