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