]>
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 $module_class = "auth_" . $_SESSION["auth_module"];
32 $authenticator = new $module_class($this->link
);
34 if (method_exists($authenticator, "change_password")) {
35 print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
37 print "ERROR: ".__("Function not supported by authentication module.");
41 function saveconfig() {
43 $_SESSION["prefs_cache"] = false;
45 $orig_theme = get_pref($this->link
, "_THEME_ID");
47 foreach (array_keys($_POST) as $pref_name) {
49 $pref_name = db_escape_string($pref_name);
50 $value = db_escape_string($_POST[$pref_name]);
52 if ($pref_name == 'DIGEST_PREFERRED_TIME') {
53 if (get_pref($this->link
, 'DIGEST_PREFERRED_TIME') != $value) {
55 db_query($this->link
, "UPDATE ttrss_users SET
56 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
61 set_pref($this->link
, $pref_name, $value);
65 if ($orig_theme != get_pref($this->link
, "_THEME_ID")) {
66 print "PREFS_THEME_CHANGED";
68 print __("The configuration was saved.");
74 $pref_name = db_escape_string($_REQUEST["pn"]);
76 $result = db_query($this->link
, "SELECT help_text FROM ttrss_prefs
77 WHERE pref_name = '$pref_name'");
79 if (db_num_rows($result) > 0) {
80 $help_text = db_fetch_result($result, 0, "help_text");
83 printf(__("Unknown option: %s"), $pref_name);
87 function changeemail() {
89 $email = db_escape_string($_POST["email"]);
90 $full_name = db_escape_string($_POST["full_name"]);
92 $active_uid = $_SESSION["uid"];
94 db_query($this->link
, "UPDATE ttrss_users SET email = '$email',
95 full_name = '$full_name' WHERE id = '$active_uid'");
97 print __("Your personal data has been saved.");
102 function resetconfig() {
104 $_SESSION["prefs_op_result"] = "reset-to-defaults";
106 if ($_SESSION["profile"]) {
107 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
109 $profile_qpart = "profile IS NULL";
112 db_query($this->link
, "DELETE FROM ttrss_user_prefs
113 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
115 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
117 print "PREFS_THEME_CHANGED";
122 global $access_level_names;
124 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
125 "STRIP_UNSAFE_TAGS");
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",
131 "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
134 $_SESSION["prefs_op_result"] = "";
136 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
137 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
139 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
141 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
142 evt.preventDefault();
143 if (this.validate()) {
144 notify_progress('Saving data...', true);
146 new Ajax.Request('backend.php', {
147 parameters: dojo.objectToQuery(this.getValues()),
148 onComplete: function(transport) {
149 notify_callback2(transport);
155 print "<table width=\"100%\" class=\"prefPrefsList\">";
157 $result = db_query($this->link
, "SELECT email,full_name,
158 access_level FROM ttrss_users
159 WHERE id = ".$_SESSION["uid"]);
161 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
162 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
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>";
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>";
171 if (!SINGLE_USER_MODE
&& !$_SESSION["hide_hello"]) {
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>";
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\">";
183 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
184 __("Save data")."</button>";
188 if ($_SESSION["auth_module"]) {
189 $module_class = "auth_" . $_SESSION["auth_module"];
190 $authenticator = new $module_class($this->link
);
192 $authenticator = false;
195 if ($authenticator && method_exists($authenticator, "change_password")) {
197 $result = db_query($this->link
, "SELECT id FROM ttrss_users
198 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
199 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
201 if (db_num_rows($result) != 0) {
202 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
205 print "<form dojoType=\"dijit.form.Form\">";
207 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
208 evt.preventDefault();
209 if (this.validate()) {
210 notify_progress('Changing password...', true);
212 new Ajax.Request('backend.php', {
213 parameters: dojo.objectToQuery(this.getValues()),
214 onComplete: function(transport) {
216 if (transport.responseText.indexOf('ERROR: ') == 0) {
217 notify_error(transport.responseText.replace('ERROR: ', ''));
219 notify_info(transport.responseText);
220 var warn = $('default_pass_warning');
221 if (warn) Element.hide(warn);
228 print "<table width=\"100%\" class=\"prefPrefsList\">";
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>";
233 print "<tr><td width=\"40%\">".__("New password")."</td>";
235 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
236 name=\"new_password\"></td></tr>";
238 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
240 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
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\">";
247 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
248 __("Change password")."</button>";
254 print "</div>"; #pane
256 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
258 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
260 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
261 evt.preventDefault();
262 if (this.validate()) {
263 console.log(dojo.objectToQuery(this.getValues()));
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();
278 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
280 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
282 if ($_SESSION["profile"]) {
283 print_notice("Some preferences are only available in default profile.");
286 if ($_SESSION["profile"]) {
287 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
288 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
290 initialize_user_prefs($this->link
, $_SESSION["uid"]);
291 $profile_qpart = "profile IS NULL";
294 $result = db_query($this->link
, "SELECT DISTINCT
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
300 section_id = ttrss_prefs_sections.id AND
301 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
303 owner_uid = ".$_SESSION["uid"]."
304 ORDER BY section_id,short_desc");
308 $active_section = "";
310 while ($line = db_fetch_assoc($result)) {
312 if (in_array($line["pref_name"], $prefs_blacklist)) {
316 if ($_SESSION["profile"] && in_array($line["pref_name"],
317 $profile_blacklist)) {
321 if ($active_section != $line["section_name"]) {
323 if ($active_section != "") {
327 print "<table width=\"100%\" class=\"prefPrefsList\">";
329 $active_section = $line["section_name"];
331 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
333 if ($line["section_id"] == 2) {
334 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
336 $user_theme = get_pref($this->link
, "_THEME_ID");
337 $themes = get_all_themes();
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>";
343 foreach ($themes as $t) {
347 if ($base == $user_theme) {
348 $selected = "selected=\"1\"";
353 print "<option $selected value='$base'>$name</option>";
357 print "</select></td></tr>";
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"];
370 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
372 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
376 print "<td class=\"prefValue\">";
378 if ($pref_name == "USER_TIMEZONE") {
380 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
382 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
383 } else if ($pref_name == "USER_STYLESHEET") {
385 print "<button dojoType=\"dijit.form.Button\"
386 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
388 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
390 $limits = array(15, 30, 45, 60);
392 print_select($pref_name, $value, $limits,
393 'dojoType="dijit.form.Select"');
395 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
397 global $update_intervals_nodefault;
399 print_select_hash($pref_name, $value, $update_intervals_nodefault,
400 'dojoType="dijit.form.Select"');
402 } else if ($type_name == "bool") {
404 if ($value == "true") {
410 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0) {
411 $disabled = "disabled=\"1\"";
417 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
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) {
423 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
425 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0) {
426 $disabled = "disabled=\"1\"";
427 $value = FORCE_ARTICLE_PURGE
;
432 print "<input dojoType=\"dijit.form.ValidationTextBox\"
433 required=\"1\" $regexp $disabled
434 name=\"$pref_name\" value=\"$value\">";
436 } else if ($pref_name == "SSL_CERT_SERIAL") {
438 print "<input dojoType=\"dijit.form.ValidationTextBox\"
439 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
440 name=\"$pref_name\" value=\"$value\">";
442 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
443 $has_serial = ($cert_serial) ?
"false" : "true";
445 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
446 onclick=\"insertSSLserial('$cert_serial')\">" .
447 __('Register') . "</button>";
449 print " <button dojoType=\"dijit.form.Button\"
450 onclick=\"insertSSLserial('')\">" .
451 __('Clear') . "</button>";
453 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
454 print "<input dojoType=\"dijit.form.ValidationTextBox\"
455 id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
456 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
457 T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
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