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