This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.php
142 lines (122 loc) · 4.28 KB
/
setup.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
<?php
// vim: expandtab sw=4 ts=4 sts=4:
// This is setup file for Ukolovnik
// Copyright © 2005 - 2016 Michal Čihař
// Published under GNU GPL version 3 or later
// Grab needed libaries
require_once('./lib/version.php');
require_once('./lib/http.php');
require_once('./lib/html.php');
require_once('./lib/config.php');
require_once('./lib/string.php');
require_once('./lib/sql.php');
require_once('./lib/category.php');
require_once('./lib/priority.php');
require_once('./lib/extensions.php');
// Strip possible slashes in REQUEST
HTTP_clean_request();
// Include correct language file
LOCALE_init();
// Grab some parameters
if (empty($_REQUEST['cmd'])) {
$cmd = '';
} else {
$cmd = $_REQUEST['cmd'];
}
$langs = LOCALE_list();
$styles = HTML_list_styles();
function N_($text) {
return $text;
}
$settings = array(
/* l10n: please keep also English text "Language" in translated text */
array('name' => 'language', 'text' => N_('Language'), 'type' => 'select', 'values' => $langs),
array('name' => 'style', 'text' => N_('Style'), 'type' => 'select', 'values' => $styles),
array('name' => 'add_stay', 'text' => N_('Stay on add page after adding new entry'), 'type' => 'bool'),
array('name' => 'add_list', 'text' => N_('Show entries list on add page'), 'type' => 'bool'),
array('name' => 'main_style', 'text' => N_('Show category name in main page output'), 'type' => 'bool'),
);
// Process settings
if ($cmd == 'save') {
foreach($settings as $val) {
if (isset($_REQUEST['s_' . $val['name']])) {
$data = $_REQUEST['s_' . $val['name']];
unset($set);
switch($val['type']) {
case 'text':
$set = $data;
break;
case 'select':
if (in_array($data, $val['values'])) {
$set = $data;
}
break;
case 'bool':
if ($data == '1') {
$set = '1';
} elseif ($data == '0') {
$set = '0';
}
break;
}
CONFIG_set($val['name'], $set);
}
}
LOCALE_init();
}
HTTP_nocache_headers();
HTML_header();
// Check for extensions
$check = EXTENSIONS_check();
if (count($check) > 0) {
foreach($check as $name) {
HTML_message('error', sprintf(_('Can not find needed PHP extension "%s". Please install and enable it.'), $name));
}
HTML_footer();
}
// Connect to database
if (!SQL_init()) {
HTML_die_error(_('Can not connect to MySQL database. Please check your configuration.'));
}
require('./lib/toolbar.php');
if ($cmd == 'update') {
// Check with possible upgrade
SQL_check(true);
// We're done for now
HTML_message('notice', str_replace('index.php', '<a href="index.php">index.php</a>', _('Tables are in correct state (see above messages about needed changes, if any), you can go back to index.php.')));
} elseif ($cmd == 'save') {
HTML_message('notice', _('Settings has been updated'));
}
echo '<form class="settings" method="post">';
foreach($settings as $val) {
$name = $val['name'];
$message = $val['text'];
echo '<div class="opts">' . "\n";
echo '<label for="set_' . $name . '">' . gettext($message) . '</label>' . "\n";
if ($val['type'] == 'text') {
echo '<input type="text" name="s_' . $name . '" id="set_' . $name . '" value="' . htmlspecialchars(CONFIG_get($name)) . '" />' . "\n";
} else {
if ($val['type'] == 'select') {
$opts = $val['values'];
} else {
$opts = array('1' => _('Yes'), '0' => _('No'));
}
echo '<select name="s_' . $name . '" id="set_' . $name . '" />' . "\n";
foreach ($opts as $key => $val) {
echo '<option value="' . $key . '"';
if ($key == CONFIG_get($name)) {
echo ' selected="selected"';
}
echo '>' . $val . '</option>' . "\n";
}
echo '</select>' . "\n";
}
echo '</div>' . "\n";
}
echo '<div class="opts">' . "\n";
echo '<input type="hidden" name="cmd" value="save" />' . "\n";
echo '<input type="submit" value="' . _('Save') . '" />' . "\n";
echo '</div>' . "\n";
echo '</form>' . "\n";
// End
HTML_footer();