2 class Pref_Prefs extends Protected_Handler {
4 function changepassword() {
6 $old_pw = $_POST["old_password"];
7 $new_pw = $_POST["new_password"];
8 $con_pw = $_POST["confirm_password"];
11 print "ERROR: ".__("Old password cannot be blank.");
16 print "ERROR: ".__("New password cannot be blank.");
20 if ($new_pw != $con_pw) {
21 print "ERROR: ".__("Entered passwords do not match.");
25 $old_pw_hash1 = encrypt_password($old_pw);
26 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
27 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
29 $active_uid = $_SESSION["uid"];
31 if ($old_pw && $new_pw) {
33 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
35 $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE
36 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
37 pwd_hash = '$old_pw_hash2')");
39 if (db_num_rows($result) == 1) {
40 db_query($this->link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
41 WHERE id = '$active_uid'");
43 $_SESSION["pwd_hash"] = $new_pw_hash;
45 print __("Password has been changed.");
47 print "ERROR: ".__('Old password is incorrect.');
55 function saveconfig() {
57 $_SESSION["prefs_cache"] = false;
59 $orig_theme = get_pref($this->link, "_THEME_ID");
61 foreach (array_keys($_POST) as $pref_name) {
63 $pref_name = db_escape_string($pref_name);
64 $value = db_escape_string($_POST[$pref_name]);
66 set_pref($this->link, $pref_name, $value);
70 if ($orig_theme != get_pref($this->link, "_THEME_ID")) {
71 print "PREFS_THEME_CHANGED";
73 print __("The configuration was saved.");
79 $pref_name = db_escape_string($_REQUEST["pn"]);
81 $result = db_query($this->link, "SELECT help_text FROM ttrss_prefs
82 WHERE pref_name = '$pref_name'");
84 if (db_num_rows($result) > 0) {
85 $help_text = db_fetch_result($result, 0, "help_text");
88 printf(__("Unknown option: %s"), $pref_name);
92 function changeemail() {
94 $email = db_escape_string($_POST["email"]);
95 $full_name = db_escape_string($_POST["full_name"]);
97 $active_uid = $_SESSION["uid"];
99 db_query($this->link, "UPDATE ttrss_users SET email = '$email',
100 full_name = '$full_name' WHERE id = '$active_uid'");
102 print __("Your personal data has been saved.");
107 function resetconfig() {
109 $_SESSION["prefs_op_result"] = "reset-to-defaults";
111 if ($_SESSION["profile"]) {
112 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
114 $profile_qpart = "profile IS NULL";
117 db_query($this->link, "DELETE FROM ttrss_user_prefs
118 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
120 initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
122 print "PREFS_THEME_CHANGED";
127 global $access_level_names;
129 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
130 "STRIP_UNSAFE_TAGS");
132 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
133 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
134 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
135 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
139 if (!SINGLE_USER_MODE) {
141 $_SESSION["prefs_op_result"] = "";
143 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
144 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
146 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
148 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
149 evt.preventDefault();
150 if (this.validate()) {
151 notify_progress('Saving data...', true);
153 new Ajax.Request('backend.php', {
154 parameters: dojo.objectToQuery(this.getValues()),
155 onComplete: function(transport) {
156 notify_callback2(transport);
162 print "<table width=\"100%\" class=\"prefPrefsList\">";
164 $result = db_query($this->link, "SELECT email,full_name,
165 access_level FROM ttrss_users
166 WHERE id = ".$_SESSION["uid"]);
168 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
169 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
171 print "<tr><td width=\"40%\">".__('Full name')."</td>";
172 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
173 value=\"$full_name\"></td></tr>";
175 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
176 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
178 if (!SINGLE_USER_MODE) {
179 $access_level = db_fetch_result($result, 0, "access_level");
180 print "<tr><td width=\"40%\">".__('Access level')."</td>";
181 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
186 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
187 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
189 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
190 __("Save data")."</button>";
194 print "</div>"; # pane
195 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
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>";
252 print "</div>"; #pane
255 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
257 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
259 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
260 evt.preventDefault();
261 if (this.validate()) {
262 console.log(dojo.objectToQuery(this.getValues()));
264 new Ajax.Request('backend.php', {
265 parameters: dojo.objectToQuery(this.getValues()),
266 onComplete: function(transport) {
267 var msg = transport.responseText;
268 if (msg.match('PREFS_THEME_CHANGED')) {
269 window.location.reload();
277 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
279 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
281 if ($_SESSION["profile"]) {
282 print_notice("Some preferences are only available in default profile.");
285 if ($_SESSION["profile"]) {
286 initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
287 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
289 initialize_user_prefs($this->link, $_SESSION["uid"]);
290 $profile_qpart = "profile IS NULL";
293 $result = db_query($this->link, "SELECT
294 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
295 section_name,def_value,section_id
296 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
297 WHERE type_id = ttrss_prefs_types.id AND
299 section_id = ttrss_prefs_sections.id AND
300 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
302 owner_uid = ".$_SESSION["uid"]."
303 ORDER BY section_id,short_desc");
307 $active_section = "";
309 while ($line = db_fetch_assoc($result)) {
311 if (in_array($line["pref_name"], $prefs_blacklist)) {
315 if ($_SESSION["profile"] && in_array($line["pref_name"],
316 $profile_blacklist)) {
320 if ($active_section != $line["section_name"]) {
322 if ($active_section != "") {
326 print "<table width=\"100%\" class=\"prefPrefsList\">";
328 $active_section = $line["section_name"];
330 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
332 if ($line["section_id"] == 2) {
333 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
335 $user_theme = get_pref($this->link, "_THEME_ID");
336 $themes = get_all_themes();
338 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
339 print "<option value='Default'>".__('Default')."</option>";
340 print "<option value='----------------' disabled=\"1\">--------</option>";
342 foreach ($themes as $t) {
346 if ($base == $user_theme) {
347 $selected = "selected=\"1\"";
352 print "<option $selected value='$base'>$name</option>";
356 print "</select></td></tr>";
363 $type_name = $line["type_name"];
364 $pref_name = $line["pref_name"];
365 $value = $line["value"];
366 $def_value = $line["def_value"];
367 $help_text = $line["help_text"];
369 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
371 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
375 print "<td class=\"prefValue\">";
377 if ($pref_name == "USER_TIMEZONE") {
379 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
381 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
382 } else if ($pref_name == "USER_STYLESHEET") {
384 print "<button dojoType=\"dijit.form.Button\"
385 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
387 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
389 $limits = array(15, 30, 45, 60);
391 print_select($pref_name, $value, $limits,
392 'dojoType="dijit.form.Select"');
394 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
396 global $update_intervals_nodefault;
398 print_select_hash($pref_name, $value, $update_intervals_nodefault,
399 'dojoType="dijit.form.Select"');
401 } else if ($type_name == "bool") {
403 if ($value == "true") {
409 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
410 $disabled = "disabled=\"1\"";
416 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
419 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
420 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
422 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
424 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
425 $disabled = "disabled=\"1\"";
426 $value = FORCE_ARTICLE_PURGE;
431 print "<input dojoType=\"dijit.form.ValidationTextBox\"
432 required=\"1\" $regexp $disabled
433 name=\"$pref_name\" value=\"$value\">";
435 } else if ($pref_name == "SSL_CERT_SERIAL") {
437 print "<input dojoType=\"dijit.form.ValidationTextBox\"
438 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
439 name=\"$pref_name\" value=\"$value\">";
441 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
442 $has_serial = ($cert_serial) ? "false" : "true";
444 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
445 onclick=\"insertSSLserial('$cert_serial')\">" .
446 __('Register') . "</button>";
448 print " <button dojoType=\"dijit.form.Button\"
449 onclick=\"insertSSLserial('')\">" .
450 __('Clear') . "</button>";
453 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
455 print "<input dojoType=\"dijit.form.ValidationTextBox\"
457 name=\"$pref_name\" value=\"$value\">";
469 print '</div>'; # inside pane
470 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
472 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
473 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
475 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
476 __('Save configuration')."</button> ";
478 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
479 __('Manage profiles')."</button> ";
481 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
482 __('Reset to defaults')."</button>";
484 print '</div>'; # inner pane
485 print '</div>'; # border container
489 print "</div>"; #pane
490 print "</div>"; #container