]> git.wh0rd.org - tt-rss.git/blame - modules/pref-prefs.php
remove google gears
[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 10 function module_pref_prefs($link) {
a88d37e5
AD
11
12 global $access_level_names;
13
ef8be8ea
AD
14 $subop = $_REQUEST["subop"];
15
3b0a65ad 16 $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS",
75c51032
AD
17 "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS", "ENABLE_FEED_ICONS",
18 "ENABLE_OFFLINE_READING");
4bb2b579 19
d9084cf2
AD
20 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
21 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
22 "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS",
23 "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL",
b3990c92 24 "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE");
d9084cf2 25
3907ef71
AD
26 if (FORCE_ARTICLE_PURGE != 0) {
27 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
28 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
29 }
30
d95bd220
AD
31 if ($subop == "change-password") {
32
33 $old_pw = $_POST["OLD_PASSWORD"];
34 $new_pw = $_POST["NEW_PASSWORD"];
35 $con_pw = $_POST["CONFIRM_PASSWORD"];
36
37 if ($old_pw == "") {
7990ac73 38 print "ERROR: ".__("Old password cannot be blank.");
d95bd220
AD
39 return;
40 }
41
42 if ($new_pw == "") {
7990ac73 43 print "ERROR: ".__("New password cannot be blank.");
d95bd220
AD
44 return;
45 }
46
47 if ($new_pw != $con_pw) {
7990ac73 48 print "ERROR: ".__("Entered passwords do not match.");
d95bd220
AD
49 return;
50 }
51
1a9f4d3c
AD
52 $old_pw_hash1 = encrypt_password($_POST["OLD_PASSWORD"]);
53 $old_pw_hash2 = encrypt_password($_POST["OLD_PASSWORD"],
54 $_SESSION["name"]);
55
56 $new_pw_hash = encrypt_password($_POST["NEW_PASSWORD"],
57 $_SESSION["name"]);
d95bd220
AD
58
59 $active_uid = $_SESSION["uid"];
60
61 if ($old_pw && $new_pw) {
62
63 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
64
65 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1a9f4d3c
AD
66 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
67 pwd_hash = '$old_pw_hash2')");
d95bd220
AD
68
69 if (db_num_rows($result) == 1) {
70 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
71 WHERE id = '$active_uid'");
72
d43f7837
AD
73 $_SESSION["pwd_hash"] = $new_pw_hash;
74
7990ac73 75 print __("Password has been changed.");
d95bd220 76 } else {
7990ac73 77 print "ERROR: ".__('Old password is incorrect.');
d95bd220
AD
78 }
79 }
80
81 return;
d95bd220 82
b652c1b7 83 } else if ($subop == "save-config") {
ef8be8ea 84
b652c1b7 85# $_SESSION["prefs_op_result"] = "save-config";
ef8be8ea
AD
86
87 $_SESSION["prefs_cache"] = false;
88
f541eb78
AD
89// print_r($_POST);
90
dce46cad 91 $orig_theme = get_pref($link, "_THEME_ID");
d9084cf2 92
ef8be8ea
AD
93 foreach (array_keys($_POST) as $pref_name) {
94
95 $pref_name = db_escape_string($pref_name);
96 $value = db_escape_string($_POST[$pref_name]);
97
e9105eb5 98 set_pref($link, $pref_name, $value);
ef8be8ea 99
ef8be8ea
AD
100 }
101
dce46cad 102 if ($orig_theme != get_pref($link, "_THEME_ID")) {
d9084cf2
AD
103 print "PREFS_THEME_CHANGED";
104 } else {
105 print __("The configuration was saved.");
106 }
b652c1b7
AD
107
108 return;
f27d955a 109
ef8be8ea
AD
110 } else if ($subop == "getHelp") {
111
b4e75b2a 112 $pref_name = db_escape_string($_REQUEST["pn"]);
ef8be8ea
AD
113
114 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
115 WHERE pref_name = '$pref_name'");
116
117 if (db_num_rows($result) > 0) {
118 $help_text = db_fetch_result($result, 0, "help_text");
119 print $help_text;
120 } else {
2a52d96f 121 printf(__("Unknown option: %s"), $pref_name);
ef8be8ea
AD
122 }
123
42395d28 124 } else if ($subop == "change-email") {
ef8be8ea 125
42395d28 126 $email = db_escape_string($_POST["email"]);
73fe13af
AD
127 $full_name = db_escape_string($_POST["full_name"]);
128
ef8be8ea
AD
129 $active_uid = $_SESSION["uid"];
130
73fe13af
AD
131 db_query($link, "UPDATE ttrss_users SET email = '$email',
132 full_name = '$full_name' WHERE id = '$active_uid'");
42395d28 133
73fe13af 134 print __("Your personal data has been saved.");
42395d28
AD
135
136 return;
ef8be8ea 137
b652c1b7 138 } else if ($subop == "reset-config") {
ef8be8ea 139
ef8be8ea
AD
140 $_SESSION["prefs_op_result"] = "reset-to-defaults";
141
1a697fa3
AD
142 if ($_SESSION["profile"]) {
143 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
144 } else {
145 $profile_qpart = "profile IS NULL";
146 }
147
eb7ab952 148 db_query($link, "DELETE FROM ttrss_user_prefs
1a697fa3
AD
149 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
150
151 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
ef8be8ea 152
1a697fa3
AD
153 print "PREFS_THEME_CHANGED";
154
155// print __("The configuration was reset to defaults.");
b652c1b7
AD
156
157 return;
ef8be8ea 158
ef8be8ea
AD
159 } else {
160
fe8d2059
AD
161 set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig");
162
d9084cf2
AD
163 if ($_SESSION["profile"]) {
164 print_notice("Some preferences are only available in default profile.");
165 }
166
ef8be8ea
AD
167 if (!SINGLE_USER_MODE) {
168
d84f9523
AD
169 $result = db_query($link, "SELECT id FROM ttrss_users
170 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
171 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
ef8be8ea
AD
172
173 if (db_num_rows($result) != 0) {
7990ac73
AD
174 print format_warning(__("Your password is at default value,
175 please change it."), "default_pass_warning");
ef8be8ea
AD
176 }
177
d95bd220 178/* if ($_SESSION["pwd_change_result"] == "failed") {
0d32b41e 179 print format_warning("Could not change the password.");
ef8be8ea
AD
180 }
181
182 if ($_SESSION["pwd_change_result"] == "ok") {
0d32b41e 183 print format_notice("Password was changed.");
ef8be8ea
AD
184 }
185
d95bd220 186 $_SESSION["pwd_change_result"] = ""; */
ef8be8ea 187
1a697fa3 188/* if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
7990ac73 189 print format_notice(__("The configuration was reset to defaults."));
1a697fa3 190} */
ef8be8ea 191
b652c1b7
AD
192# if ($_SESSION["prefs_op_result"] == "save-config") {
193# print format_notice(__("The configuration was saved."));
194# }
ef8be8ea
AD
195
196 $_SESSION["prefs_op_result"] = "";
197
42395d28 198 print "<form onsubmit='return false' id='change_email_form'>";
ef8be8ea
AD
199
200 print "<table width=\"100%\" class=\"prefPrefsList\">";
7990ac73 201 print "<tr><td colspan='3'><h3>".__("Personal data")."</h3></tr></td>";
ef8be8ea 202
73fe13af
AD
203 $result = db_query($link, "SELECT email,full_name,
204 access_level FROM ttrss_users
ef8be8ea
AD
205 WHERE id = ".$_SESSION["uid"]);
206
73fe13af
AD
207 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
208 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
209
210 print "<tr><td width=\"40%\">".__('Full name')."</td>";
211 print "<td class=\"prefValue\"><input class=\"editbox\" name=\"full_name\"
212 onfocus=\"javascript:disableHotkeys();\"
213 onblur=\"javascript:enableHotkeys();\"
214 onkeypress=\"return filterCR(event, changeUserEmail)\"
215 value=\"$full_name\"></td></tr>";
216
e400230e 217 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
e351c494 218 print "<td class=\"prefValue\"><input class=\"editbox\" name=\"email\"
6068d33b
AD
219 onfocus=\"javascript:disableHotkeys();\"
220 onblur=\"javascript:enableHotkeys();\"
42395d28 221 onkeypress=\"return filterCR(event, changeUserEmail)\"
ef8be8ea 222 value=\"$email\"></td></tr>";
a88d37e5
AD
223
224 if (!SINGLE_USER_MODE) {
225
226 $access_level = db_fetch_result($result, 0, "access_level");
227
228 print "<tr><td width=\"40%\">".__('Access level')."</td>";
229 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
230
231 }
ef8be8ea
AD
232
233 print "</table>";
234
235 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
42395d28 236 print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">";
ef8be8ea
AD
237
238 print "</form>";
239
577399e8 240 print "<p><button onclick=\"return changeUserEmail()\">".
73fe13af 241 __("Save data")."</button>";
42395d28 242
e6312f6c 243 print "<form onsubmit=\"return false\"
d95bd220 244 name=\"change_pass_form\" id=\"change_pass_form\">";
ef8be8ea
AD
245
246 print "<table width=\"100%\" class=\"prefPrefsList\">";
7990ac73 247 print "<tr><td colspan='3'><h3>".__("Authentication")."</h3></tr></td>";
ef8be8ea 248
7990ac73 249 print "<tr><td width=\"40%\">".__("Old password")."</td>";
e351c494 250 print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"
6068d33b
AD
251 onfocus=\"javascript:disableHotkeys();\"
252 onblur=\"javascript:enableHotkeys();\"
d95bd220 253 onkeypress=\"return filterCR(event, changeUserPassword)\"
ef8be8ea
AD
254 name=\"OLD_PASSWORD\"></td></tr>";
255
7990ac73 256 print "<tr><td width=\"40%\">".__("New password")."</td>";
ef8be8ea 257
e351c494 258 print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"
6068d33b
AD
259 onfocus=\"javascript:disableHotkeys();\"
260 onblur=\"javascript:enableHotkeys();\"
d95bd220 261 onkeypress=\"return filterCR(event, changeUserPassword)\"
ef8be8ea 262 name=\"NEW_PASSWORD\"></td></tr>";
d95bd220 263
7990ac73 264 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
d95bd220 265
e351c494 266 print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"
6068d33b
AD
267 onfocus=\"javascript:disableHotkeys();\"
268 onblur=\"javascript:enableHotkeys();\"
d95bd220
AD
269 onkeypress=\"return filterCR(event, changeUserPassword)\"
270 name=\"CONFIRM_PASSWORD\"></td></tr>";
271
ef8be8ea
AD
272 print "</table>";
273
274 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
d95bd220
AD
275 print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">";
276
ef8be8ea
AD
277 print "</form>";
278
577399e8
AD
279 print "<p><button onclick=\"return changeUserPassword()\">".
280 __("Change password")."</button>";
d95bd220 281
ef8be8ea
AD
282 }
283
d9084cf2
AD
284 if ($_SESSION["profile"]) {
285 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
286 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
287 } else {
288 initialize_user_prefs($link, $_SESSION["uid"]);
289 $profile_qpart = "profile IS NULL";
ef8be8ea
AD
290 }
291
ef8be8ea
AD
292 $result = db_query($link, "SELECT
293 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
d9084cf2 294 section_name,def_value,section_id
ef8be8ea
AD
295 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
296 WHERE type_id = ttrss_prefs_types.id AND
d9084cf2 297 $profile_qpart AND
ef8be8ea
AD
298 section_id = ttrss_prefs_sections.id AND
299 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
40496720 300 short_desc != '' AND
ef8be8ea
AD
301 owner_uid = ".$_SESSION["uid"]."
302 ORDER BY section_id,short_desc");
303
ae661a8c
AD
304 print "<form onsubmit='return false' action=\"backend.php\"
305 method=\"POST\" id=\"pref_prefs_form\">";
ef8be8ea
AD
306
307 $lnum = 0;
308
309 $active_section = "";
310
311 while ($line = db_fetch_assoc($result)) {
312
4bb2b579
AD
313 if (in_array($line["pref_name"], $prefs_blacklist)) {
314 continue;
315 }
316
d9084cf2
AD
317 if ($_SESSION["profile"] && in_array($line["pref_name"],
318 $profile_blacklist)) {
319 continue;
320 }
321
ef8be8ea
AD
322 if ($active_section != $line["section_name"]) {
323
324 if ($active_section != "") {
325 print "</table>";
326 }
327
328 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
d9084cf2 329
ef8be8ea
AD
330 $active_section = $line["section_name"];
331
89cb787e 332 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
d9084cf2
AD
333
334 if ($line["section_id"] == 2) {
335 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
dce46cad
AD
336
337 $user_theme = get_pref($link, "_THEME_ID");
338 $themes = get_all_themes();
339
d9084cf2 340 print "<td><select name=\"_THEME_ID\">";
dce46cad 341 print "<option value=''>".__('Default')."</option>";
d9084cf2 342 print "<option disabled>--------</option>";
dce46cad
AD
343
344 foreach ($themes as $t) {
345 $base = $t['base'];
346 $name = $t['name'];
347
348 if ($base == $user_theme) {
349 $selected = "selected=\"1\"";
d9084cf2
AD
350 } else {
351 $selected = "";
352 }
dce46cad
AD
353
354 print "<option $selected value='$base'>$name</option>";
355
d9084cf2 356 }
dce46cad 357
d9084cf2
AD
358 print "</select></td></tr>";
359 }
360
ef8be8ea
AD
361// print "<tr class=\"title\">
362// <td width=\"25%\">Option</td><td>Value</td></tr>";
363
364 $lnum = 0;
365 }
366
367// $class = ($lnum % 2) ? "even" : "odd";
368
369 print "<tr>";
370
371 $type_name = $line["type_name"];
372 $pref_name = $line["pref_name"];
373 $value = $line["value"];
374 $def_value = $line["def_value"];
375 $help_text = $line["help_text"];
376
e351c494 377 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
ef8be8ea 378
89cb787e 379 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
ef8be8ea
AD
380
381 print "</td>";
382
e351c494 383 print "<td class=\"prefValue\">";
ef8be8ea 384
324944f3
AD
385 if ($pref_name == "USER_TIMEZONE") {
386
387 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
388
389 print_select($pref_name, $value, $timezones);
390
391 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
505f2f0e
AD
392
393 global $update_intervals_nodefault;
394
395 print_select_hash($pref_name, $value, $update_intervals_nodefault);
396
397 } else if ($type_name == "bool") {
ef8be8ea
AD
398// print_select($pref_name, $value, array("true", "false"));
399
400 if ($value == "true") {
836537f7 401 $value = __("Yes");
ef8be8ea 402 } else {
836537f7 403 $value = __("No");
ef8be8ea
AD
404 }
405
f541eb78 406 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
ef8be8ea
AD
407
408 } else {
6068d33b
AD
409 print "<input class=\"editbox\"
410 onfocus=\"javascript:disableHotkeys();\"
411 onblur=\"javascript:enableHotkeys();\"
412 name=\"$pref_name\" value=\"$value\">";
ef8be8ea
AD
413 }
414
415 print "</td>";
416
417 print "</tr>";
418
419 $lnum++;
420 }
421
422 print "</table>";
423
424 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
425
577399e8
AD
426 print "<p><button onclick=\"return validatePrefsSave()\">".
427 __('Save configuration')."</button> ";
d9084cf2
AD
428
429 print "<button onclick=\"return editProfiles()\">".
430 __('Manage profiles')."</button> ";
431
577399e8
AD
432 print "<button onclick=\"return validatePrefsReset()\">".
433 __('Reset to defaults')."</button></p>";
ef8be8ea
AD
434
435 print "</form>";
436
437 }
438 }
439?>