]>
git.wh0rd.org - tt-rss.git/blob - classes/pref_prefs.php
2 class Pref_Prefs
extends Protected_Handler
{
4 function csrf_ignore($method) {
5 $csrf_ignored = array("index");
7 return array_search($method, $csrf_ignored) !== false;
10 function changepassword() {
12 $old_pw = $_POST["old_password"];
13 $new_pw = $_POST["new_password"];
14 $con_pw = $_POST["confirm_password"];
17 print "ERROR: ".__("Old password cannot be blank.");
22 print "ERROR: ".__("New password cannot be blank.");
26 if ($new_pw != $con_pw) {
27 print "ERROR: ".__("Entered passwords do not match.");
31 $result = db_query($this->link
, "SELECT salt FROM ttrss_users WHERE
32 id = " . $_SESSION['uid']);
34 $salt = db_fetch_result($result, 0, "salt");
37 $old_pw_hash1 = encrypt_password($old_pw);
38 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
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')";
45 $old_pw_hash = encrypt_password($old_pw, $salt, true);
47 $query = "SELECT id FROM ttrss_users WHERE
48 id = ".$_SESSION['uid']." AND pwd_hash = '$old_pw_hash'";
51 $result = db_query($this->link
, $query);
53 if (db_num_rows($result) == 1) {
55 $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
56 $new_pw_hash = encrypt_password($new_pw, $new_salt, true);
58 db_query($this->link
, "UPDATE ttrss_users SET
59 pwd_hash = '$new_pw_hash', salt = '$new_salt'
60 WHERE id = ".$_SESSION['uid']);
62 $_SESSION["pwd_hash"] = $new_pw_hash;
64 print __("Password has been changed.");
66 print "ERROR: ".__('Old password is incorrect.');
70 function saveconfig() {
72 $_SESSION["prefs_cache"] = false;
74 $orig_theme = get_pref($this->link
, "_THEME_ID");
76 foreach (array_keys($_POST) as $pref_name) {
78 $pref_name = db_escape_string($pref_name);
79 $value = db_escape_string($_POST[$pref_name]);
81 if ($pref_name == 'DIGEST_PREFERRED_TIME') {
82 if (get_pref($this->link
, 'DIGEST_PREFERRED_TIME') != $value) {
84 db_query($this->link
, "UPDATE ttrss_users SET
85 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
90 set_pref($this->link
, $pref_name, $value);
94 if ($orig_theme != get_pref($this->link
, "_THEME_ID")) {
95 print "PREFS_THEME_CHANGED";
97 print __("The configuration was saved.");
103 $pref_name = db_escape_string($_REQUEST["pn"]);
105 $result = db_query($this->link
, "SELECT help_text FROM ttrss_prefs
106 WHERE pref_name = '$pref_name'");
108 if (db_num_rows($result) > 0) {
109 $help_text = db_fetch_result($result, 0, "help_text");
112 printf(__("Unknown option: %s"), $pref_name);
116 function changeemail() {
118 $email = db_escape_string($_POST["email"]);
119 $full_name = db_escape_string($_POST["full_name"]);
121 $active_uid = $_SESSION["uid"];
123 db_query($this->link
, "UPDATE ttrss_users SET email = '$email',
124 full_name = '$full_name' WHERE id = '$active_uid'");
126 print __("Your personal data has been saved.");
131 function resetconfig() {
133 $_SESSION["prefs_op_result"] = "reset-to-defaults";
135 if ($_SESSION["profile"]) {
136 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
138 $profile_qpart = "profile IS NULL";
141 db_query($this->link
, "DELETE FROM ttrss_user_prefs
142 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
144 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
146 print "PREFS_THEME_CHANGED";
151 global $access_level_names;
153 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
154 "STRIP_UNSAFE_TAGS");
156 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
157 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
158 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
159 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
160 "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
163 if (!SINGLE_USER_MODE
) {
165 $_SESSION["prefs_op_result"] = "";
167 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
168 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
170 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
172 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
173 evt.preventDefault();
174 if (this.validate()) {
175 notify_progress('Saving data...', true);
177 new Ajax.Request('backend.php', {
178 parameters: dojo.objectToQuery(this.getValues()),
179 onComplete: function(transport) {
180 notify_callback2(transport);
186 print "<table width=\"100%\" class=\"prefPrefsList\">";
188 $result = db_query($this->link
, "SELECT email,full_name,
189 access_level FROM ttrss_users
190 WHERE id = ".$_SESSION["uid"]);
192 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
193 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
195 print "<tr><td width=\"40%\">".__('Full name')."</td>";
196 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
197 value=\"$full_name\"></td></tr>";
199 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
200 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
202 if (!SINGLE_USER_MODE
) {
203 $access_level = db_fetch_result($result, 0, "access_level");
204 print "<tr><td width=\"40%\">".__('Access level')."</td>";
205 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
210 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
211 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
213 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
214 __("Save data")."</button>";
218 $result = db_query($this->link
, "SELECT id FROM ttrss_users
219 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
220 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
222 if (db_num_rows($result) != 0) {
223 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
226 print "<form dojoType=\"dijit.form.Form\">";
228 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
229 evt.preventDefault();
230 if (this.validate()) {
231 notify_progress('Changing password...', true);
233 new Ajax.Request('backend.php', {
234 parameters: dojo.objectToQuery(this.getValues()),
235 onComplete: function(transport) {
237 if (transport.responseText.indexOf('ERROR: ') == 0) {
238 notify_error(transport.responseText.replace('ERROR: ', ''));
240 notify_info(transport.responseText);
241 var warn = $('default_pass_warning');
242 if (warn) Element.hide(warn);
249 print "<table width=\"100%\" class=\"prefPrefsList\">";
251 print "<tr><td width=\"40%\">".__("Old password")."</td>";
252 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
254 print "<tr><td width=\"40%\">".__("New password")."</td>";
256 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
257 name=\"new_password\"></td></tr>";
259 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
261 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
265 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
266 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
268 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
269 __("Change password")."</button>";
273 print "</div>"; #pane
276 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
278 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
280 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
281 evt.preventDefault();
282 if (this.validate()) {
283 console.log(dojo.objectToQuery(this.getValues()));
285 new Ajax.Request('backend.php', {
286 parameters: dojo.objectToQuery(this.getValues()),
287 onComplete: function(transport) {
288 var msg = transport.responseText;
289 if (msg.match('PREFS_THEME_CHANGED')) {
290 window.location.reload();
298 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
300 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
302 if ($_SESSION["profile"]) {
303 print_notice("Some preferences are only available in default profile.");
306 if ($_SESSION["profile"]) {
307 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
308 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
310 initialize_user_prefs($this->link
, $_SESSION["uid"]);
311 $profile_qpart = "profile IS NULL";
314 $result = db_query($this->link
, "SELECT
315 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
316 section_name,def_value,section_id
317 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
318 WHERE type_id = ttrss_prefs_types.id AND
320 section_id = ttrss_prefs_sections.id AND
321 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
323 owner_uid = ".$_SESSION["uid"]."
324 ORDER BY section_id,short_desc");
328 $active_section = "";
330 while ($line = db_fetch_assoc($result)) {
332 if (in_array($line["pref_name"], $prefs_blacklist)) {
336 if ($_SESSION["profile"] && in_array($line["pref_name"],
337 $profile_blacklist)) {
341 if ($active_section != $line["section_name"]) {
343 if ($active_section != "") {
347 print "<table width=\"100%\" class=\"prefPrefsList\">";
349 $active_section = $line["section_name"];
351 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
353 if ($line["section_id"] == 2) {
354 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
356 $user_theme = get_pref($this->link
, "_THEME_ID");
357 $themes = get_all_themes();
359 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
360 print "<option value='Default'>".__('Default')."</option>";
361 print "<option value='----------------' disabled=\"1\">--------</option>";
363 foreach ($themes as $t) {
367 if ($base == $user_theme) {
368 $selected = "selected=\"1\"";
373 print "<option $selected value='$base'>$name</option>";
377 print "</select></td></tr>";
384 $type_name = $line["type_name"];
385 $pref_name = $line["pref_name"];
386 $value = $line["value"];
387 $def_value = $line["def_value"];
388 $help_text = $line["help_text"];
390 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
392 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
396 print "<td class=\"prefValue\">";
398 if ($pref_name == "USER_TIMEZONE") {
400 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
402 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
403 } else if ($pref_name == "USER_STYLESHEET") {
405 print "<button dojoType=\"dijit.form.Button\"
406 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
408 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
410 $limits = array(15, 30, 45, 60);
412 print_select($pref_name, $value, $limits,
413 'dojoType="dijit.form.Select"');
415 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
417 global $update_intervals_nodefault;
419 print_select_hash($pref_name, $value, $update_intervals_nodefault,
420 'dojoType="dijit.form.Select"');
422 } else if ($type_name == "bool") {
424 if ($value == "true") {
430 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0) {
431 $disabled = "disabled=\"1\"";
437 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
440 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
441 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
443 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
445 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0) {
446 $disabled = "disabled=\"1\"";
447 $value = FORCE_ARTICLE_PURGE
;
452 print "<input dojoType=\"dijit.form.ValidationTextBox\"
453 required=\"1\" $regexp $disabled
454 name=\"$pref_name\" value=\"$value\">";
456 } else if ($pref_name == "SSL_CERT_SERIAL") {
458 print "<input dojoType=\"dijit.form.ValidationTextBox\"
459 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
460 name=\"$pref_name\" value=\"$value\">";
462 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
463 $has_serial = ($cert_serial) ?
"false" : "true";
465 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
466 onclick=\"insertSSLserial('$cert_serial')\">" .
467 __('Register') . "</button>";
469 print " <button dojoType=\"dijit.form.Button\"
470 onclick=\"insertSSLserial('')\">" .
471 __('Clear') . "</button>";
473 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
474 print "<input dojoType=\"dijit.form.ValidationTextBox\"
475 id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
476 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
477 T_sprintf("Current server time: %s", date("H:i")) . "</div>";
479 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
481 print "<input dojoType=\"dijit.form.ValidationTextBox\"
483 name=\"$pref_name\" value=\"$value\">";
495 print '</div>'; # inside pane
496 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
498 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
499 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
501 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
502 __('Save configuration')."</button> ";
504 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
505 __('Manage profiles')."</button> ";
507 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
508 __('Reset to defaults')."</button>";
510 print '</div>'; # inner pane
511 print '</div>'; # border container
515 print "</div>"; #pane
516 print "</div>"; #container