forked from sandboxgangster/Part-DB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_config.php
executable file
·315 lines (268 loc) · 16.6 KB
/
system_config.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
<?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-13 kami89 - renamed to system_config.php
- changed to OOP
*/
include_once('start_session.php');
// this file enables write permissions in the DokuWiki
define('DOKUWIKI_PERMS_FILENAME', BASE.'/data/ENABLE-DOKUWIKI-WRITE-PERMS.txt');
$messages = array();
$fatal_error = false; // if a fatal error occurs, only the $messages will be printed, but not the site content
/********************************************************************************
*
* Some special functions for this site
*
*********************************************************************************/
function build_theme_loop()
{
global $config;
$loop = array();
$directories = find_all_directories(BASE.'/templates/');
foreach ($directories as $directory)
{
$name = str_ireplace(BASE.'/templates/', '', $directory);
if ($name != 'custom_css')
$loop[] = array('value' => $name, 'text' => $name, 'selected' => ($name == $config['html']['theme']));
}
return $loop;
}
function build_custom_css_loop()
{
global $config;
$loop = array();
$files = find_all_files(BASE.'/templates/custom_css/', true, '.css');
foreach ($files as $file)
{
$name = str_ireplace(BASE.'/templates/custom_css/', '', $file);
$loop[] = array('value' => $name, 'text' => $name, 'selected' => ($name == $config['html']['custom_css']));
}
return $loop;
}
/********************************************************************************
*
* Evaluate $_REQUEST
*
*********************************************************************************/
// section "system settings"
$http_charset = isset($_REQUEST['http_charset']) ? (string)$_REQUEST['http_charset'] : 'utf-8';
$theme = isset($_REQUEST['theme']) ? (string)$_REQUEST['theme'] : $config['html']['theme'];
$custom_css = isset($_REQUEST['custom_css']) ? (string)$_REQUEST['custom_css'] : $config['html']['custom_css'];
$timezone = isset($_REQUEST['timezone']) ? (string)$_REQUEST['timezone'] : $config['timezone'];
$language = isset($_REQUEST['language']) ? (string)$_REQUEST['language'] : $config['language'];
$disable_updatelist = isset($_REQUEST['disable_updatelist']);
$disable_help = isset($_REQUEST['disable_help']);
$disable_config = isset($_REQUEST['disable_config']);
$enable_debug_link = isset($_REQUEST['enable_debug_link']);
$disable_devices = isset($_REQUEST['disable_devices']);
$disable_footprints = isset($_REQUEST['disable_footprints']);
$disable_manufacturers = isset($_REQUEST['disable_manufacturers']);
$disable_labels = isset($_REQUEST['disable_labels']);
$disable_calculator = isset($_REQUEST['disable_calculator']);
$disable_iclogos = isset($_REQUEST['disable_iclogos']);
$disable_auto_datasheets = isset($_REQUEST['disable_auto_datasheets']);
$disable_tools_footprints = isset($_REQUEST['disable_tools_footprints']);
$tools_footprints_autoload = isset($_REQUEST['tools_footprints_autoload']);
$enable_developer_mode = isset($_REQUEST['enable_developer_mode']);
$enable_dokuwiki_write_perms= isset($_REQUEST['enable_dokuwiki_write_perms']);
$use_modal_popup = isset($_REQUEST['use_modal_popup']);
$popup_width = isset($_REQUEST['popup_width']) ? (integer)$_REQUEST['popup_width'] : $config['popup']['width'];
$popup_height = isset($_REQUEST['popup_height']) ? (integer)$_REQUEST['popup_height'] : $config['popup']['height'];
$page_title = isset($_REQUEST['page_title']) ? (string)$_REQUEST['page_title'] : $config['page_title'];
$startup_banner = isset($_REQUEST['startup_banner']) ? (string)$_REQUEST['startup_banner'] : $config['startup']['custom_banner'];
// section "change administrator password"
$current_admin_password = isset($_REQUEST['current_admin_password']) ? (string)$_REQUEST['current_admin_password'] : '';
$new_admin_password_1 = isset($_REQUEST['new_admin_password_1']) ? (string)$_REQUEST['new_admin_password_1'] : '';
$new_admin_password_2 = isset($_REQUEST['new_admin_password_2']) ? (string)$_REQUEST['new_admin_password_2'] : '';
$action = 'default';
if (isset($_REQUEST["apply"])) {$action = 'apply';}
if (isset($_REQUEST["change_admin_password"])) {$action = 'change_admin_password';}
/********************************************************************************
*
* Initialize Objects
*
*********************************************************************************/
$html = new HTML($config['html']['theme'], /*$config['html']['custom_css']*/ $custom_css, 'Konfiguration');
try
{
//$database = new Database();
//$log = new Log($database);
//$system = new System($database, $log);
//$current_user = new User($database, $current_user, $log, 1); // admin
}
catch (Exception $e)
{
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
$fatal_error = true;
}
/********************************************************************************
*
* Execute actions
*
*********************************************************************************/
if ( ! $fatal_error)
{
switch ($action)
{
case 'apply':
$config_old = $config;
//$config['html']['http_charset'] = $http_charset;
$config['html']['theme'] = $theme;
$config['html']['custom_css'] = $custom_css;
$config['timezone'] = $timezone;
$config['language'] = $language;
$config['startup']['disable_update_list'] = $disable_updatelist;
$config['menu']['disable_help'] = $disable_help;
$config['menu']['disable_labels'] = $disable_labels;
$config['menu']['disable_calculator'] = $disable_calculator;
$config['menu']['disable_iclogos'] = $disable_iclogos;
$config['menu']['enable_debug'] = $enable_debug_link;
$config['devices']['disable'] = $disable_devices;
$config['footprints']['disable'] = $disable_footprints;
$config['manufacturers']['disable'] = $disable_manufacturers;
$config['auto_datasheets']['disable'] = $disable_auto_datasheets;
$config['menu']['disable_footprints'] = $disable_tools_footprints;
$config['tools']['footprints']['autoload'] = $tools_footprints_autoload;
$config['developer_mode'] = ($enable_developer_mode && file_exists(BASE.'/development'));
$config['popup']['modal'] = $use_modal_popup;
$config['popup']['width'] = $popup_width;
$config['popup']['height'] = $popup_height;
if ( ! $config['is_online_demo'])
{
// settings which should not be able to change in the online demo
$config['menu']['disable_config'] = $disable_config;
$config['page_title'] = $page_title;
$config['startup']['custom_banner'] = $startup_banner;
}
else
{
// this is an online demo!
$enable_dokuwiki_write_perms = false; // the DokuWiki must be in read-only mode in the online demo!!
}
// change DokuWiki write permissions
if (($enable_dokuwiki_write_perms) && ( ! file_exists(DOKUWIKI_PERMS_FILENAME)))
{
// enable write permissions
$filehandle = fopen(DOKUWIKI_PERMS_FILENAME, 'w');
if ( ! $filehandle)
$messages[] = array('text' => 'Die Datei "'.DOKUWIKI_PERMS_FILENAME.'" kann nicht gelöscht werden! '.
'Überprüfen Sie, ob Sie die nötigen Schreibrechte besitzen.', 'strong' => true, 'color' => 'red');
else
fclose($filehandle);
}
elseif (( ! $enable_dokuwiki_write_perms) && (file_exists(DOKUWIKI_PERMS_FILENAME)))
{
// disable write permissions
if ( ! unlink(DOKUWIKI_PERMS_FILENAME))
$messages[] = array('text' => 'Die Datei "'.DOKUWIKI_PERMS_FILENAME.'" kann nicht gelöscht werden! '.
'Überprüfen Sie, ob Sie die nötigen Schreibrechte besitzen.', 'strong' => true, 'color' => 'red');
}
try
{
save_config();
$html->set_variable('refresh_navigation_frame', true, 'boolean');
//header('Location: system_config.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 'change_admin_password':
try
{
if ($config['is_online_demo'])
throw new Exception('Diese Funktion steht in der Online-Demo nicht zur Verfügung!');
// set_admin_password() throws an exception if the old or the new passwords are not valid
set_admin_password($current_admin_password, $new_admin_password_1, $new_admin_password_2, false);
save_config();
$messages[] = array('text' => 'Das neue Administratorpasswort wurde erfolgreich gespeichert.', 'strong' => true, 'color' => 'darkgreen');
}
catch (Exception $e)
{
$messages[] = array('text' => 'Die neuen Werte konnten nicht gespeichert werden!', 'strong' => true, 'color' => 'red');
$messages[] = array('text' => 'Fehlermeldung: '.nl2br($e->getMessage()), 'color' => 'red');
}
break;
}
}
/********************************************************************************
*
* Set all HTML variables
*
*********************************************************************************/
$html->use_javascript(array('validatenumber', 'popup'));
// http charset / theme
$html->set_loop('http_charset_loop', array_to_template_loop($config['http_charsets'], $config['html']['http_charset']));
$html->set_loop('theme_loop', build_theme_loop(), $config['html']['theme']);
$html->set_loop('custom_css_loop', build_custom_css_loop(), $config['html']['custom_css']);
// locale settings
$html->set_loop('timezone_loop', array_to_template_loop($config['timezones'], $config['timezone']));
$html->set_loop('language_loop', array_to_template_loop($config['languages'], $config['language']));
// checkboxes
$html->set_variable('disable_updatelist', $config['startup']['disable_update_list'], 'boolean');
$html->set_variable('disable_help', $config['menu']['disable_help'], 'boolean');
$html->set_variable('disable_config', $config['menu']['disable_config'], 'boolean');
$html->set_variable('enable_debug_link', $config['menu']['enable_debug'], 'boolean');
$html->set_variable('disable_devices', $config['devices']['disable'], 'boolean');
$html->set_variable('disable_footprints', $config['footprints']['disable'], 'boolean');
$html->set_variable('disable_manufacturers', $config['manufacturers']['disable'], 'boolean');
$html->set_variable('disable_labels', $config['menu']['disable_labels'], 'boolean');
$html->set_variable('disable_calculator', $config['menu']['disable_calculator'], 'boolean');
$html->set_variable('disable_iclogos', $config['menu']['disable_iclogos'], 'boolean');
$html->set_variable('disable_auto_datasheets', $config['auto_datasheets']['disable'], 'boolean');
$html->set_variable('disable_tools_footprints', $config['menu']['disable_footprints'], 'boolean');
$html->set_variable('tools_footprints_autoload', $config['tools']['footprints']['autoload'], 'boolean');
$html->set_variable('developer_mode_available', file_exists(BASE.'/development'), 'boolean');
$html->set_variable('enable_developer_mode', $config['developer_mode'], 'boolean');
$html->set_variable('enable_dokuwiki_write_perms', file_exists(DOKUWIKI_PERMS_FILENAME), 'boolean');
// popup settings
$html->set_variable('use_modal_popup', $config['popup']['modal'], 'boolean');
$html->set_variable('popup_width', $config['popup']['width'], 'integer');
$html->set_variable('popup_height', $config['popup']['height'], 'integer');
// site properties
$html->set_variable('page_title', $config['page_title'], 'string');
$html->set_variable('startup_banner', $config['startup']['custom_banner'], 'string');
// server
$html->set_variable('php_version', phpversion(), 'string');
$html->set_variable('htaccess_works', (getenv('htaccessWorking')=='true'), 'boolean');
$html->set_variable('is_online_demo', $config['is_online_demo'], 'boolean');
// check if the server supports the selected language and print a warning if not
if ( ! own_setlocale(LC_ALL, $config['language']))
{
$messages[] = array('text' => 'Achtung:', 'strong' => true, 'color' => 'red');
$messages[] = array('text' => 'Die gewählte Sprache "'.$config['language'].'" wird vom Server nicht unterstützt!', 'color' => 'red', );
$messages[] = array('text' => 'Bitte installieren Sie diese Sprache oder wählen Sie eine andere.', 'color' => 'red', );
}
/********************************************************************************
*
* Generate HTML Output
*
*********************************************************************************/
$html->print_header($messages);
if ( ! $fatal_error)
$html->print_template('system_config');
$html->print_footer();
?>