]> git.wh0rd.org - tt-rss.git/blob - modules/pref-prefs.php
359359733315095245b6cf540316f4782ee20ace
[tt-rss.git] / modules / pref-prefs.php
1 <?php
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
10 function module_pref_prefs($link) {
11
12 global $access_level_names;
13
14 $subop = $_REQUEST["subop"];
15
16 $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS",
17 "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS", "ENABLE_FEED_ICONS",
18 "ENABLE_OFFLINE_READING", "EXTENDED_FEEDLIST", "FEEDS_SORT_BY_UNREAD",
19 "OPEN_LINKS_IN_NEW_WINDOW", "USER_STYLESHEET_URL");
20
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",
25 "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE");
26
27 if (FORCE_ARTICLE_PURGE != 0) {
28 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
29 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
30 }
31
32 if ($subop == "change-password") {
33
34 $old_pw = $_POST["old_password"];
35 $new_pw = $_POST["new_password"];
36 $con_pw = $_POST["confirm_password"];
37
38 if ($old_pw == "") {
39 print "ERROR: ".__("Old password cannot be blank.");
40 return;
41 }
42
43 if ($new_pw == "") {
44 print "ERROR: ".__("New password cannot be blank.");
45 return;
46 }
47
48 if ($new_pw != $con_pw) {
49 print "ERROR: ".__("Entered passwords do not match.");
50 return;
51 }
52
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"]);
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
64 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
65 pwd_hash = '$old_pw_hash2')");
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
71 $_SESSION["pwd_hash"] = $new_pw_hash;
72
73 print __("Password has been changed.");
74 } else {
75 print "ERROR: ".__('Old password is incorrect.');
76 }
77 }
78
79 return;
80
81 } else if ($subop == "save-config") {
82
83 # $_SESSION["prefs_op_result"] = "save-config";
84
85 $_SESSION["prefs_cache"] = false;
86
87 // print_r($_POST);
88
89 $orig_theme = get_pref($link, "_THEME_ID");
90
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
96 set_pref($link, $pref_name, $value);
97
98 }
99
100 if ($orig_theme != get_pref($link, "_THEME_ID")) {
101 print "PREFS_THEME_CHANGED";
102 } else {
103 print __("The configuration was saved.");
104 }
105
106 return;
107
108 } else if ($subop == "getHelp") {
109
110 $pref_name = db_escape_string($_REQUEST["pn"]);
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 {
119 printf(__("Unknown option: %s"), $pref_name);
120 }
121
122 } else if ($subop == "change-email") {
123
124 $email = db_escape_string($_POST["email"]);
125 $full_name = db_escape_string($_POST["full_name"]);
126
127 $active_uid = $_SESSION["uid"];
128
129 db_query($link, "UPDATE ttrss_users SET email = '$email',
130 full_name = '$full_name' WHERE id = '$active_uid'");
131
132 print __("Your personal data has been saved.");
133
134 return;
135
136 } else if ($subop == "reset-config") {
137
138 $_SESSION["prefs_op_result"] = "reset-to-defaults";
139
140 if ($_SESSION["profile"]) {
141 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
142 } else {
143 $profile_qpart = "profile IS NULL";
144 }
145
146 db_query($link, "DELETE FROM ttrss_user_prefs
147 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
148
149 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
150
151 print "PREFS_THEME_CHANGED";
152
153 // print __("The configuration was reset to defaults.");
154
155 return;
156
157 } else {
158
159 if (!SINGLE_USER_MODE) {
160
161 /* if ($_SESSION["pwd_change_result"] == "failed") {
162 print format_warning("Could not change the password.");
163 }
164
165 if ($_SESSION["pwd_change_result"] == "ok") {
166 print format_notice("Password was changed.");
167 }
168
169 $_SESSION["pwd_change_result"] = ""; */
170
171 /* if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
172 print format_notice(__("The configuration was reset to defaults."));
173 } */
174
175 # if ($_SESSION["prefs_op_result"] == "save-config") {
176 # print format_notice(__("The configuration was saved."));
177 # }
178
179 $_SESSION["prefs_op_result"] = "";
180
181 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
182 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
183
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
200 print "<table width=\"100%\" class=\"prefPrefsList\">";
201
202 $result = db_query($link, "SELECT email,full_name,
203 access_level FROM ttrss_users
204 WHERE id = ".$_SESSION["uid"]);
205
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>";
210 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
211 value=\"$full_name\"></td></tr>";
212
213 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
214 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
215
216 if (!SINGLE_USER_MODE) {
217 $access_level = db_fetch_result($result, 0, "access_level");
218 print "<tr><td width=\"40%\">".__('Access level')."</td>";
219 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
220 }
221
222 print "</table>";
223
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\">";
226
227 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
228 __("Save data")."</button>";
229
230 print "</form>";
231
232 print "</div>"; # pane
233 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
234
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
266 print "<table width=\"100%\" class=\"prefPrefsList\">";
267
268 print "<tr><td width=\"40%\">".__("Old password")."</td>";
269 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
270
271 print "<tr><td width=\"40%\">".__("New password")."</td>";
272
273 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
274 name=\"new_password\"></td></tr>";
275
276 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
277
278 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
279
280 print "</table>";
281
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\">";
284
285 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
286 __("Change password")."</button>";
287
288 print "</form>";
289
290 print "</div>"; #pane
291 }
292
293 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
294
295 if ($_SESSION["profile"]) {
296 print_notice("Some preferences are only available in default profile.");
297 }
298
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";
305 }
306
307 $result = db_query($link, "SELECT
308 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
309 section_name,def_value,section_id
310 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
311 WHERE type_id = ttrss_prefs_types.id AND
312 $profile_qpart AND
313 section_id = ttrss_prefs_sections.id AND
314 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
315 short_desc != '' AND
316 owner_uid = ".$_SESSION["uid"]."
317 ORDER BY section_id,short_desc");
318
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>";
338
339 $lnum = 0;
340
341 $active_section = "";
342
343 while ($line = db_fetch_assoc($result)) {
344
345 if (in_array($line["pref_name"], $prefs_blacklist)) {
346 continue;
347 }
348
349 if ($_SESSION["profile"] && in_array($line["pref_name"],
350 $profile_blacklist)) {
351 continue;
352 }
353
354 if ($active_section != $line["section_name"]) {
355
356 if ($active_section != "") {
357 print "</table>";
358 }
359
360 print "<table width=\"100%\" class=\"prefPrefsList\">";
361
362 $active_section = $line["section_name"];
363
364 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
365
366 if ($line["section_id"] == 2) {
367 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
368
369 $user_theme = get_pref($link, "_THEME_ID");
370 $themes = get_all_themes();
371
372 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
373 print "<option value='Default'>".__('Default')."</option>";
374 print "<option value='----------------' disabled=\"1\">--------</option>";
375
376 foreach ($themes as $t) {
377 $base = $t['base'];
378 $name = $t['name'];
379
380 if ($base == $user_theme) {
381 $selected = "selected=\"1\"";
382 } else {
383 $selected = "";
384 }
385
386 print "<option $selected value='$base'>$name</option>";
387
388 }
389
390 print "</select></td></tr>";
391 }
392
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
409 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
410
411 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
412
413 print "</td>";
414
415 print "<td class=\"prefValue\">";
416
417 if ($pref_name == "USER_TIMEZONE") {
418
419 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
420
421 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
422 } else if ($pref_name == "USER_STYLESHEET") {
423
424 print "<button dojoType=\"dijit.form.Button\"
425 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
426
427 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
428
429 global $update_intervals_nodefault;
430
431 print_select_hash($pref_name, $value, $update_intervals_nodefault,
432 'dojoType="dijit.form.Select"');
433
434 } else if ($type_name == "bool") {
435 // print_select($pref_name, $value, array("true", "false"));
436
437 if ($value == "true") {
438 $value = __("Yes");
439 } else {
440 $value = __("No");
441 }
442
443 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
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
452 name=\"$pref_name\" value=\"$value\">";
453
454 } else {
455 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
456
457 print "<input dojoType=\"dijit.form.ValidationTextBox\"
458 $regexp
459 name=\"$pref_name\" value=\"$value\">";
460 }
461
462 print "</td>";
463
464 print "</tr>";
465
466 $lnum++;
467 }
468
469 print "</table>";
470
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\">";
473
474 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
475 __('Save configuration')."</button> ";
476
477 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
478 __('Manage profiles')."</button> ";
479
480 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
481 __('Reset to defaults')."</button></p>";
482
483 print "</form>";
484
485 print "</div>"; #pane
486 print "</div>"; #container
487
488 }
489 }
490 ?>