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