]>
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 $_SESSION["prefs_op_result"] = "";
165 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
166 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
168 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
170 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
171 evt.preventDefault();
172 if (this.validate()) {
173 notify_progress('Saving data...', true);
175 new Ajax.Request('backend.php', {
176 parameters: dojo.objectToQuery(this.getValues()),
177 onComplete: function(transport) {
178 notify_callback2(transport);
184 print "<table width=\"100%\" class=\"prefPrefsList\">";
186 $result = db_query($this->link
, "SELECT email,full_name,
187 access_level FROM ttrss_users
188 WHERE id = ".$_SESSION["uid"]);
190 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
191 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
193 print "<tr><td width=\"40%\">".__('Full name')."</td>";
194 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
195 value=\"$full_name\"></td></tr>";
197 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
198 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
200 if (!SINGLE_USER_MODE
&& !(ALLOW_REMOTE_USER_AUTH
&& AUTO_LOGIN
)) {
202 $access_level = db_fetch_result($result, 0, "access_level");
203 print "<tr><td width=\"40%\">".__('Access level')."</td>";
204 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
209 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
210 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
212 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
213 __("Save data")."</button>";
217 if (!SINGLE_USER_MODE
&& !(ALLOW_REMOTE_USER_AUTH
&& AUTO_LOGIN
)) {
219 $result = db_query($this->link
, "SELECT id FROM ttrss_users
220 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
221 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
223 if (db_num_rows($result) != 0) {
224 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
227 print "<form dojoType=\"dijit.form.Form\">";
229 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
230 evt.preventDefault();
231 if (this.validate()) {
232 notify_progress('Changing password...', true);
234 new Ajax.Request('backend.php', {
235 parameters: dojo.objectToQuery(this.getValues()),
236 onComplete: function(transport) {
238 if (transport.responseText.indexOf('ERROR: ') == 0) {
239 notify_error(transport.responseText.replace('ERROR: ', ''));
241 notify_info(transport.responseText);
242 var warn = $('default_pass_warning');
243 if (warn) Element.hide(warn);
250 print "<table width=\"100%\" class=\"prefPrefsList\">";
252 print "<tr><td width=\"40%\">".__("Old password")."</td>";
253 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
255 print "<tr><td width=\"40%\">".__("New password")."</td>";
257 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
258 name=\"new_password\"></td></tr>";
260 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
262 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
266 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
267 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
269 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
270 __("Change password")."</button>";
276 print "</div>"; #pane
278 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
280 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
282 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
283 evt.preventDefault();
284 if (this.validate()) {
285 console.log(dojo.objectToQuery(this.getValues()));
287 new Ajax.Request('backend.php', {
288 parameters: dojo.objectToQuery(this.getValues()),
289 onComplete: function(transport) {
290 var msg = transport.responseText;
291 if (msg.match('PREFS_THEME_CHANGED')) {
292 window.location.reload();
300 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
302 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
304 if ($_SESSION["profile"]) {
305 print_notice("Some preferences are only available in default profile.");
308 if ($_SESSION["profile"]) {
309 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
310 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
312 initialize_user_prefs($this->link
, $_SESSION["uid"]);
313 $profile_qpart = "profile IS NULL";
316 $result = db_query($this->link
, "SELECT DISTINCT
317 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
318 section_name,def_value,section_id
319 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
320 WHERE type_id = ttrss_prefs_types.id AND
322 section_id = ttrss_prefs_sections.id AND
323 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
325 owner_uid = ".$_SESSION["uid"]."
326 ORDER BY section_id,short_desc");
330 $active_section = "";
332 while ($line = db_fetch_assoc($result)) {
334 if (in_array($line["pref_name"], $prefs_blacklist)) {
338 if ($_SESSION["profile"] && in_array($line["pref_name"],
339 $profile_blacklist)) {
343 if ($active_section != $line["section_name"]) {
345 if ($active_section != "") {
349 print "<table width=\"100%\" class=\"prefPrefsList\">";
351 $active_section = $line["section_name"];
353 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
355 if ($line["section_id"] == 2) {
356 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
358 $user_theme = get_pref($this->link
, "_THEME_ID");
359 $themes = get_all_themes();
361 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
362 print "<option value='Default'>".__('Default')."</option>";
363 print "<option value='----------------' disabled=\"1\">--------</option>";
365 foreach ($themes as $t) {
369 if ($base == $user_theme) {
370 $selected = "selected=\"1\"";
375 print "<option $selected value='$base'>$name</option>";
379 print "</select></td></tr>";
386 $type_name = $line["type_name"];
387 $pref_name = $line["pref_name"];
388 $value = $line["value"];
389 $def_value = $line["def_value"];
390 $help_text = $line["help_text"];
392 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
394 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
398 print "<td class=\"prefValue\">";
400 if ($pref_name == "USER_TIMEZONE") {
402 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
404 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
405 } else if ($pref_name == "USER_STYLESHEET") {
407 print "<button dojoType=\"dijit.form.Button\"
408 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
410 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
412 $limits = array(15, 30, 45, 60);
414 print_select($pref_name, $value, $limits,
415 'dojoType="dijit.form.Select"');
417 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
419 global $update_intervals_nodefault;
421 print_select_hash($pref_name, $value, $update_intervals_nodefault,
422 'dojoType="dijit.form.Select"');
424 } else if ($type_name == "bool") {
426 if ($value == "true") {
432 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0) {
433 $disabled = "disabled=\"1\"";
439 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
442 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
443 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
445 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
447 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0) {
448 $disabled = "disabled=\"1\"";
449 $value = FORCE_ARTICLE_PURGE
;
454 print "<input dojoType=\"dijit.form.ValidationTextBox\"
455 required=\"1\" $regexp $disabled
456 name=\"$pref_name\" value=\"$value\">";
458 } else if ($pref_name == "SSL_CERT_SERIAL") {
460 print "<input dojoType=\"dijit.form.ValidationTextBox\"
461 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
462 name=\"$pref_name\" value=\"$value\">";
464 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
465 $has_serial = ($cert_serial) ?
"false" : "true";
467 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
468 onclick=\"insertSSLserial('$cert_serial')\">" .
469 __('Register') . "</button>";
471 print " <button dojoType=\"dijit.form.Button\"
472 onclick=\"insertSSLserial('')\">" .
473 __('Clear') . "</button>";
475 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
476 print "<input dojoType=\"dijit.form.ValidationTextBox\"
477 id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
478 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
479 T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
481 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
483 print "<input dojoType=\"dijit.form.ValidationTextBox\"
485 name=\"$pref_name\" value=\"$value\">";
497 print '</div>'; # inside pane
498 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
500 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
501 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
503 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
504 __('Save configuration')."</button> ";
506 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
507 __('Manage profiles')."</button> ";
509 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
510 __('Reset to defaults')."</button>";
512 print '</div>'; # inner pane
513 print '</div>'; # border container
517 print "</div>"; #pane
518 print "</div>"; #container