]> git.wh0rd.org - tt-rss.git/blame - modules/pref-prefs.php
add persistent storage for toolbar view options, bump schema
[tt-rss.git] / modules / pref-prefs.php
CommitLineData
ef8be8ea 1<?php
f27d955a
AD
2 function prefs_js_redirect() {
3 print "<html><body>
4 <script type=\"text/javascript\">
5 window.location = 'prefs.php';
6 </script>
7 </body></html>";
8 }
9
ef8be8ea
AD
10 function module_pref_prefs($link) {
11 $subop = $_REQUEST["subop"];
12
d95bd220
AD
13 if ($subop == "change-password") {
14
15 $old_pw = $_POST["OLD_PASSWORD"];
16 $new_pw = $_POST["NEW_PASSWORD"];
17 $con_pw = $_POST["CONFIRM_PASSWORD"];
18
19 if ($old_pw == "") {
7990ac73 20 print "ERROR: ".__("Old password cannot be blank.");
d95bd220
AD
21 return;
22 }
23
24 if ($new_pw == "") {
7990ac73 25 print "ERROR: ".__("New password cannot be blank.");
d95bd220
AD
26 return;
27 }
28
29 if ($new_pw != $con_pw) {
7990ac73 30 print "ERROR: ".__("Entered passwords do not match.");
d95bd220
AD
31 return;
32 }
33
34 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
35 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
36
37 $active_uid = $_SESSION["uid"];
38
39 if ($old_pw && $new_pw) {
40
41 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
42
43 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
44 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
45 pwd_hash = '$old_pw_hash')");
46
47 if (db_num_rows($result) == 1) {
48 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
49 WHERE id = '$active_uid'");
50
7990ac73 51 print __("Password has been changed.");
d95bd220 52 } else {
7990ac73 53 print "ERROR: ".__('Old password is incorrect.');
d95bd220
AD
54 }
55 }
56
57 return;
d95bd220 58
42395d28 59 } else if ($subop == "Save configuration") {
ef8be8ea 60
ef8be8ea
AD
61 $_SESSION["prefs_op_result"] = "save-config";
62
63 $_SESSION["prefs_cache"] = false;
64
65 foreach (array_keys($_POST) as $pref_name) {
66
67 $pref_name = db_escape_string($pref_name);
68 $value = db_escape_string($_POST[$pref_name]);
69
70 $result = db_query($link, "SELECT type_name
71 FROM ttrss_prefs,ttrss_prefs_types
72 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
73
74 if (db_num_rows($result) > 0) {
75
76 $type_name = db_fetch_result($result, 0, "type_name");
77
78// print "$pref_name : $type_name : $value<br>";
79
80 if ($type_name == "bool") {
81 if ($value == "1") {
82 $value = "true";
83 } else {
84 $value = "false";
85 }
86 } else if ($type_name == "integer") {
87 $value = sprintf("%d", $value);
88 }
89
90// print "$pref_name : $type_name : $value<br>";
91
92 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
93 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
94
95 }
96
ef8be8ea
AD
97 }
98
f27d955a
AD
99 return prefs_js_redirect();
100
ef8be8ea
AD
101 } else if ($subop == "getHelp") {
102
103 $pref_name = db_escape_string($_GET["pn"]);
104
105 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
106 WHERE pref_name = '$pref_name'");
107
108 if (db_num_rows($result) > 0) {
109 $help_text = db_fetch_result($result, 0, "help_text");
110 print $help_text;
111 } else {
112 print "Unknown option: $pref_name";
113 }
114
42395d28 115 } else if ($subop == "change-email") {
ef8be8ea 116
42395d28 117 $email = db_escape_string($_POST["email"]);
ef8be8ea
AD
118 $active_uid = $_SESSION["uid"];
119
42395d28
AD
120 db_query($link, "UPDATE ttrss_users SET email = '$email'
121 WHERE id = '$active_uid'");
122
123 print "E-mail has been changed.";
124
125 return;
ef8be8ea 126
ef8be8ea
AD
127 } else if ($subop == "Reset to defaults") {
128
ef8be8ea
AD
129 $_SESSION["prefs_op_result"] = "reset-to-defaults";
130
131 if (DB_TYPE == "pgsql") {
132 db_query($link,"UPDATE ttrss_user_prefs
133 SET value = ttrss_prefs.def_value
134 WHERE owner_uid = '".$_SESSION["uid"]."' AND
135 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
136 } else {
137 db_query($link, "DELETE FROM ttrss_user_prefs
138 WHERE owner_uid = ".$_SESSION["uid"]);
139 initialize_user_prefs($link, $_SESSION["uid"]);
140 }
141
f27d955a 142 return prefs_js_redirect();
ef8be8ea
AD
143
144 } else if ($subop == "Change theme") {
145
146 $theme = db_escape_string($_POST["theme"]);
147
148 if ($theme == "Default") {
149 $theme_qpart = 'NULL';
150 } else {
151 $theme_qpart = "'$theme'";
152 }
153
154 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
155 WHERE theme_name = '$theme'");
156
157 if (db_num_rows($result) == 1) {
158 $theme_id = db_fetch_result($result, 0, "id");
159 $theme_path = db_fetch_result($result, 0, "theme_path");
160 } else {
161 $theme_id = "NULL";
162 $theme_path = "";
163 }
164
165 db_query($link, "UPDATE ttrss_users SET
166 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
167
168 $_SESSION["theme"] = $theme_path;
169
f27d955a 170 return prefs_js_redirect();
ef8be8ea
AD
171
172 } else {
173
2b2044bc 174// print check_for_update($link);
ef8be8ea
AD
175
176 if (!SINGLE_USER_MODE) {
177
178 $result = db_query($link, "SELECT id,email FROM ttrss_users
179 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
180 pwd_hash = 'SHA1:".sha1("password")."')");
181
182 if (db_num_rows($result) != 0) {
7990ac73
AD
183 print format_warning(__("Your password is at default value,
184 please change it."), "default_pass_warning");
ef8be8ea
AD
185 }
186
d95bd220 187/* if ($_SESSION["pwd_change_result"] == "failed") {
0d32b41e 188 print format_warning("Could not change the password.");
ef8be8ea
AD
189 }
190
191 if ($_SESSION["pwd_change_result"] == "ok") {
0d32b41e 192 print format_notice("Password was changed.");
ef8be8ea
AD
193 }
194
d95bd220 195 $_SESSION["pwd_change_result"] = ""; */
ef8be8ea
AD
196
197 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
7990ac73 198 print format_notice(__("The configuration was reset to defaults."));
ef8be8ea
AD
199 }
200
201 if ($_SESSION["prefs_op_result"] == "save-config") {
7990ac73 202 print format_notice(__("The configuration was saved."));
ef8be8ea
AD
203 }
204
205 $_SESSION["prefs_op_result"] = "";
206
42395d28 207 print "<form onsubmit='return false' id='change_email_form'>";
ef8be8ea
AD
208
209 print "<table width=\"100%\" class=\"prefPrefsList\">";
7990ac73 210 print "<tr><td colspan='3'><h3>".__("Personal data")."</h3></tr></td>";
ef8be8ea
AD
211
212 $result = db_query($link, "SELECT email FROM ttrss_users
213 WHERE id = ".$_SESSION["uid"]);
214
215 $email = db_fetch_result($result, 0, "email");
216
217 print "<tr><td width=\"40%\">E-mail</td>";
218 print "<td><input class=\"editbox\" name=\"email\"
42395d28 219 onkeypress=\"return filterCR(event, changeUserEmail)\"
ef8be8ea
AD
220 value=\"$email\"></td></tr>";
221
222 print "</table>";
223
224 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
42395d28 225 print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">";
ef8be8ea
AD
226
227 print "</form>";
228
42395d28 229 print "<p><input class=\"button\" type=\"submit\"
7990ac73 230 onclick=\"return changeUserEmail()\" value=\"".__("Change e-mail")."\">";
42395d28 231
e6312f6c 232 print "<form onsubmit=\"return false\"
d95bd220 233 name=\"change_pass_form\" id=\"change_pass_form\">";
ef8be8ea
AD
234
235 print "<table width=\"100%\" class=\"prefPrefsList\">";
7990ac73 236 print "<tr><td colspan='3'><h3>".__("Authentication")."</h3></tr></td>";
ef8be8ea 237
7990ac73 238 print "<tr><td width=\"40%\">".__("Old password")."</td>";
ef8be8ea 239 print "<td><input class=\"editbox\" type=\"password\"
d95bd220 240 onkeypress=\"return filterCR(event, changeUserPassword)\"
ef8be8ea
AD
241 name=\"OLD_PASSWORD\"></td></tr>";
242
7990ac73 243 print "<tr><td width=\"40%\">".__("New password")."</td>";
ef8be8ea
AD
244
245 print "<td><input class=\"editbox\" type=\"password\"
d95bd220 246 onkeypress=\"return filterCR(event, changeUserPassword)\"
ef8be8ea 247 name=\"NEW_PASSWORD\"></td></tr>";
d95bd220 248
7990ac73 249 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
d95bd220
AD
250
251 print "<td><input class=\"editbox\" type=\"password\"
252 onkeypress=\"return filterCR(event, changeUserPassword)\"
253 name=\"CONFIRM_PASSWORD\"></td></tr>";
254
ef8be8ea
AD
255 print "</table>";
256
257 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
d95bd220
AD
258 print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">";
259
ef8be8ea
AD
260 print "</form>";
261
d95bd220
AD
262 print "<p><input class=\"button\" type=\"submit\"
263 onclick=\"return changeUserPassword()\"
7990ac73 264 value=\"".__("Change password")."\">";
d95bd220 265
ef8be8ea
AD
266 }
267
268 $result = db_query($link, "SELECT
269 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
270
271 $user_theme_id = db_fetch_result($result, 0, "theme_id");
272
273 $result = db_query($link, "SELECT
274 id,theme_name FROM ttrss_themes ORDER BY theme_name");
275
276 if (db_num_rows($result) > 0) {
277
278 print "<form action=\"backend.php\" method=\"POST\">";
279 print "<table width=\"100%\" class=\"prefPrefsList\">";
7990ac73
AD
280 print "<tr><td colspan='3'><h3>".__("Themes")."</h3></tr></td>";
281 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
ef8be8ea
AD
282 print "<td><select name=\"theme\">";
283 print "<option>Default</option>";
284 print "<option disabled>--------</option>";
285
286 while ($line = db_fetch_assoc($result)) {
287 if ($line["id"] == $user_theme_id) {
288 $selected = "selected";
289 } else {
290 $selected = "";
291 }
292 print "<option $selected>" . $line["theme_name"] . "</option>";
293 }
294 print "</select></td></tr>";
295 print "</table>";
296 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
297 print "<p><input class=\"button\" type=\"submit\"
298 value=\"Change theme\" name=\"subop\">";
299 print "</form>";
300 }
301
302 initialize_user_prefs($link, $_SESSION["uid"]);
303
304 $result = db_query($link, "SELECT
305 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
306 section_name,def_value
307 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
308 WHERE type_id = ttrss_prefs_types.id AND
309 section_id = ttrss_prefs_sections.id AND
310 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
40496720 311 short_desc != '' AND
ef8be8ea
AD
312 owner_uid = ".$_SESSION["uid"]."
313 ORDER BY section_id,short_desc");
314
315 print "<form action=\"backend.php\" method=\"POST\">";
316
317 $lnum = 0;
318
319 $active_section = "";
320
321 while ($line = db_fetch_assoc($result)) {
322
323 if ($active_section != $line["section_name"]) {
324
325 if ($active_section != "") {
326 print "</table>";
327 }
328
329 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
330
331 $active_section = $line["section_name"];
332
333 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
334// print "<tr class=\"title\">
335// <td width=\"25%\">Option</td><td>Value</td></tr>";
336
337 $lnum = 0;
338 }
339
340// $class = ($lnum % 2) ? "even" : "odd";
341
342 print "<tr>";
343
344 $type_name = $line["type_name"];
345 $pref_name = $line["pref_name"];
346 $value = $line["value"];
347 $def_value = $line["def_value"];
348 $help_text = $line["help_text"];
349
350 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
351
352 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
353
354 print "</td>";
355
356 print "<td>";
357
358 if ($type_name == "bool") {
359// print_select($pref_name, $value, array("true", "false"));
360
361 if ($value == "true") {
362 $value = "Yes";
363 } else {
364 $value = "No";
365 }
366
367 print_radio($pref_name, $value, array("Yes", "No"));
368
369 } else {
370 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
371 }
372
373 print "</td>";
374
375 print "</tr>";
376
377 $lnum++;
378 }
379
380 print "</table>";
381
382 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
383
384 print "<p><input class=\"button\" type=\"submit\"
385 name=\"subop\" value=\"Save configuration\">";
386
387 print "&nbsp;<input class=\"button\" type=\"submit\"
388 name=\"subop\" onclick=\"return validatePrefsReset()\"
389 value=\"Reset to defaults\"></p>";
390
391 print "</form>";
392
393 }
394 }
395?>