]>
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 $old_pw_hash1 = encrypt_password($old_pw);
32 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
33 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
35 $active_uid = $_SESSION["uid"];
37 if ($old_pw && $new_pw) {
39 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
41 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE
42 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
43 pwd_hash = '$old_pw_hash2')");
45 if (db_num_rows($result) == 1) {
46 db_query($this->link
, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
47 WHERE id = '$active_uid'");
49 $_SESSION["pwd_hash"] = $new_pw_hash;
51 print __("Password has been changed.");
53 print "ERROR: ".__('Old password is incorrect.');
61 function saveconfig() {
63 $_SESSION["prefs_cache"] = false;
65 $orig_theme = get_pref($this->link
, "_THEME_ID");
67 foreach (array_keys($_POST) as $pref_name) {
69 $pref_name = db_escape_string($pref_name);
70 $value = db_escape_string($_POST[$pref_name]);
72 set_pref($this->link
, $pref_name, $value);
76 if ($orig_theme != get_pref($this->link
, "_THEME_ID")) {
77 print "PREFS_THEME_CHANGED";
79 print __("The configuration was saved.");
85 $pref_name = db_escape_string($_REQUEST["pn"]);
87 $result = db_query($this->link
, "SELECT help_text FROM ttrss_prefs
88 WHERE pref_name = '$pref_name'");
90 if (db_num_rows($result) > 0) {
91 $help_text = db_fetch_result($result, 0, "help_text");
94 printf(__("Unknown option: %s"), $pref_name);
98 function changeemail() {
100 $email = db_escape_string($_POST["email"]);
101 $full_name = db_escape_string($_POST["full_name"]);
103 $active_uid = $_SESSION["uid"];
105 db_query($this->link
, "UPDATE ttrss_users SET email = '$email',
106 full_name = '$full_name' WHERE id = '$active_uid'");
108 print __("Your personal data has been saved.");
113 function resetconfig() {
115 $_SESSION["prefs_op_result"] = "reset-to-defaults";
117 if ($_SESSION["profile"]) {
118 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
120 $profile_qpart = "profile IS NULL";
123 db_query($this->link
, "DELETE FROM ttrss_user_prefs
124 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
126 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
128 print "PREFS_THEME_CHANGED";
133 global $access_level_names;
135 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
136 "STRIP_UNSAFE_TAGS");
138 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
139 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
140 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
141 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
145 if (!SINGLE_USER_MODE
) {
147 $_SESSION["prefs_op_result"] = "";
149 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
150 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
152 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
154 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
155 evt.preventDefault();
156 if (this.validate()) {
157 notify_progress('Saving data...', true);
159 new Ajax.Request('backend.php', {
160 parameters: dojo.objectToQuery(this.getValues()),
161 onComplete: function(transport) {
162 notify_callback2(transport);
168 print "<table width=\"100%\" class=\"prefPrefsList\">";
170 $result = db_query($this->link
, "SELECT email,full_name,
171 access_level FROM ttrss_users
172 WHERE id = ".$_SESSION["uid"]);
174 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
175 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
177 print "<tr><td width=\"40%\">".__('Full name')."</td>";
178 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
179 value=\"$full_name\"></td></tr>";
181 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
182 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
184 if (!SINGLE_USER_MODE
) {
185 $access_level = db_fetch_result($result, 0, "access_level");
186 print "<tr><td width=\"40%\">".__('Access level')."</td>";
187 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
192 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
193 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
195 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
196 __("Save data")."</button>";
200 print "</div>"; # pane
201 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
203 $result = db_query($this->link
, "SELECT id FROM ttrss_users
204 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
205 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
207 if (db_num_rows($result) != 0) {
208 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
211 print "<form dojoType=\"dijit.form.Form\">";
213 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
214 evt.preventDefault();
215 if (this.validate()) {
216 notify_progress('Changing password...', true);
218 new Ajax.Request('backend.php', {
219 parameters: dojo.objectToQuery(this.getValues()),
220 onComplete: function(transport) {
222 if (transport.responseText.indexOf('ERROR: ') == 0) {
223 notify_error(transport.responseText.replace('ERROR: ', ''));
225 notify_info(transport.responseText);
226 var warn = $('default_pass_warning');
227 if (warn) Element.hide(warn);
234 print "<table width=\"100%\" class=\"prefPrefsList\">";
236 print "<tr><td width=\"40%\">".__("Old password")."</td>";
237 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
239 print "<tr><td width=\"40%\">".__("New password")."</td>";
241 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
242 name=\"new_password\"></td></tr>";
244 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
246 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
250 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
251 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
253 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
254 __("Change password")."</button>";
258 print "</div>"; #pane
261 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
263 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
265 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
266 evt.preventDefault();
267 if (this.validate()) {
268 console.log(dojo.objectToQuery(this.getValues()));
270 new Ajax.Request('backend.php', {
271 parameters: dojo.objectToQuery(this.getValues()),
272 onComplete: function(transport) {
273 var msg = transport.responseText;
274 if (msg.match('PREFS_THEME_CHANGED')) {
275 window.location.reload();
283 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
285 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
287 if ($_SESSION["profile"]) {
288 print_notice("Some preferences are only available in default profile.");
291 if ($_SESSION["profile"]) {
292 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
293 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
295 initialize_user_prefs($this->link
, $_SESSION["uid"]);
296 $profile_qpart = "profile IS NULL";
299 $result = db_query($this->link
, "SELECT
300 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
301 section_name,def_value,section_id
302 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
303 WHERE type_id = ttrss_prefs_types.id AND
305 section_id = ttrss_prefs_sections.id AND
306 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
308 owner_uid = ".$_SESSION["uid"]."
309 ORDER BY section_id,short_desc");
313 $active_section = "";
315 while ($line = db_fetch_assoc($result)) {
317 if (in_array($line["pref_name"], $prefs_blacklist)) {
321 if ($_SESSION["profile"] && in_array($line["pref_name"],
322 $profile_blacklist)) {
326 if ($active_section != $line["section_name"]) {
328 if ($active_section != "") {
332 print "<table width=\"100%\" class=\"prefPrefsList\">";
334 $active_section = $line["section_name"];
336 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
338 if ($line["section_id"] == 2) {
339 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
341 $user_theme = get_pref($this->link
, "_THEME_ID");
342 $themes = get_all_themes();
344 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
345 print "<option value='Default'>".__('Default')."</option>";
346 print "<option value='----------------' disabled=\"1\">--------</option>";
348 foreach ($themes as $t) {
352 if ($base == $user_theme) {
353 $selected = "selected=\"1\"";
358 print "<option $selected value='$base'>$name</option>";
362 print "</select></td></tr>";
369 $type_name = $line["type_name"];
370 $pref_name = $line["pref_name"];
371 $value = $line["value"];
372 $def_value = $line["def_value"];
373 $help_text = $line["help_text"];
375 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
377 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
381 print "<td class=\"prefValue\">";
383 if ($pref_name == "USER_TIMEZONE") {
385 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
387 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
388 } else if ($pref_name == "USER_STYLESHEET") {
390 print "<button dojoType=\"dijit.form.Button\"
391 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
393 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
395 $limits = array(15, 30, 45, 60);
397 print_select($pref_name, $value, $limits,
398 'dojoType="dijit.form.Select"');
400 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
402 global $update_intervals_nodefault;
404 print_select_hash($pref_name, $value, $update_intervals_nodefault,
405 'dojoType="dijit.form.Select"');
407 } else if ($type_name == "bool") {
409 if ($value == "true") {
415 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0) {
416 $disabled = "disabled=\"1\"";
422 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
425 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
426 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
428 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
430 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0) {
431 $disabled = "disabled=\"1\"";
432 $value = FORCE_ARTICLE_PURGE
;
437 print "<input dojoType=\"dijit.form.ValidationTextBox\"
438 required=\"1\" $regexp $disabled
439 name=\"$pref_name\" value=\"$value\">";
441 } else if ($pref_name == "SSL_CERT_SERIAL") {
443 print "<input dojoType=\"dijit.form.ValidationTextBox\"
444 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
445 name=\"$pref_name\" value=\"$value\">";
447 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
448 $has_serial = ($cert_serial) ?
"false" : "true";
450 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
451 onclick=\"insertSSLserial('$cert_serial')\">" .
452 __('Register') . "</button>";
454 print " <button dojoType=\"dijit.form.Button\"
455 onclick=\"insertSSLserial('')\">" .
456 __('Clear') . "</button>";
459 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
461 print "<input dojoType=\"dijit.form.ValidationTextBox\"
463 name=\"$pref_name\" value=\"$value\">";
475 print '</div>'; # inside pane
476 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
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\">";
481 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
482 __('Save configuration')."</button> ";
484 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
485 __('Manage profiles')."</button> ";
487 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
488 __('Reset to defaults')."</button>";
490 print '</div>'; # inner pane
491 print '</div>'; # border container
495 print "</div>"; #pane
496 print "</div>"; #container