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