]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-prefs.php
2 function prefs_js_redirect() {
4 <script type=\"text/javascript\">
5 window.location = 'prefs.php';
10 function module_pref_prefs($link) {
12 global $access_level_names;
14 $subop = $_REQUEST["subop"];
16 $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS",
17 "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS", "ENABLE_FEED_ICONS",
18 "ENABLE_OFFLINE_READING", "EXTENDED_FEEDLIST", "FEEDS_SORT_BY_UNREAD",
19 "OPEN_LINKS_IN_NEW_WINDOW");
21 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
22 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
23 "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS",
24 "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL",
25 "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE");
27 if (FORCE_ARTICLE_PURGE
!= 0) {
28 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
29 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
32 if ($subop == "change-password") {
34 $old_pw = $_POST["old_password"];
35 $new_pw = $_POST["new_password"];
36 $con_pw = $_POST["confirm_password"];
39 print "ERROR: ".__("Old password cannot be blank.");
44 print "ERROR: ".__("New password cannot be blank.");
48 if ($new_pw != $con_pw) {
49 print "ERROR: ".__("Entered passwords do not match.");
53 $old_pw_hash1 = encrypt_password($old_pw);
54 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
55 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
57 $active_uid = $_SESSION["uid"];
59 if ($old_pw && $new_pw) {
61 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
63 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
64 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
65 pwd_hash = '$old_pw_hash2')");
67 if (db_num_rows($result) == 1) {
68 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
69 WHERE id = '$active_uid'");
71 $_SESSION["pwd_hash"] = $new_pw_hash;
73 print __("Password has been changed.");
75 print "ERROR: ".__('Old password is incorrect.');
81 } else if ($subop == "save-config") {
83 # $_SESSION["prefs_op_result"] = "save-config";
85 $_SESSION["prefs_cache"] = false;
89 $orig_theme = get_pref($link, "_THEME_ID");
91 foreach (array_keys($_POST) as $pref_name) {
93 $pref_name = db_escape_string($pref_name);
94 $value = db_escape_string($_POST[$pref_name]);
96 set_pref($link, $pref_name, $value);
100 if ($orig_theme != get_pref($link, "_THEME_ID")) {
101 print "PREFS_THEME_CHANGED";
103 print __("The configuration was saved.");
108 } else if ($subop == "getHelp") {
110 $pref_name = db_escape_string($_REQUEST["pn"]);
112 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
113 WHERE pref_name = '$pref_name'");
115 if (db_num_rows($result) > 0) {
116 $help_text = db_fetch_result($result, 0, "help_text");
119 printf(__("Unknown option: %s"), $pref_name);
122 } else if ($subop == "change-email") {
124 $email = db_escape_string($_POST["email"]);
125 $full_name = db_escape_string($_POST["full_name"]);
127 $active_uid = $_SESSION["uid"];
129 db_query($link, "UPDATE ttrss_users SET email = '$email',
130 full_name = '$full_name' WHERE id = '$active_uid'");
132 print __("Your personal data has been saved.");
136 } else if ($subop == "reset-config") {
138 $_SESSION["prefs_op_result"] = "reset-to-defaults";
140 if ($_SESSION["profile"]) {
141 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
143 $profile_qpart = "profile IS NULL";
146 db_query($link, "DELETE FROM ttrss_user_prefs
147 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
149 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
151 print "PREFS_THEME_CHANGED";
153 // print __("The configuration was reset to defaults.");
159 if (!SINGLE_USER_MODE
) {
161 /* if ($_SESSION["pwd_change_result"] == "failed") {
162 print format_warning("Could not change the password.");
165 if ($_SESSION["pwd_change_result"] == "ok") {
166 print format_notice("Password was changed.");
169 $_SESSION["pwd_change_result"] = ""; */
171 /* if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
172 print format_notice(__("The configuration was reset to defaults."));
175 # if ($_SESSION["prefs_op_result"] == "save-config") {
176 # print format_notice(__("The configuration was saved."));
179 $_SESSION["prefs_op_result"] = "";
181 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
182 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
184 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
186 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
187 evt.preventDefault();
188 if (this.validate()) {
189 notify_progress('Saving data...', true);
191 new Ajax.Request('backend.php', {
192 parameters: dojo.objectToQuery(this.getValues()),
193 onComplete: function(transport) {
194 notify_callback2(transport);
200 print "<table width=\"100%\" class=\"prefPrefsList\">";
202 $result = db_query($link, "SELECT email,full_name,
203 access_level FROM ttrss_users
204 WHERE id = ".$_SESSION["uid"]);
206 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
207 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
209 print "<tr><td width=\"40%\">".__('Full name')."</td>";
210 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
211 value=\"$full_name\"></td></tr>";
213 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
214 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
216 if (!SINGLE_USER_MODE
) {
217 $access_level = db_fetch_result($result, 0, "access_level");
218 print "<tr><td width=\"40%\">".__('Access level')."</td>";
219 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
224 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
225 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-email\">";
227 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
228 __("Save data")."</button>";
232 print "</div>"; # pane
233 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
235 $result = db_query($link, "SELECT id FROM ttrss_users
236 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
237 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
239 if (db_num_rows($result) != 0) {
240 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
243 print "<form dojoType=\"dijit.form.Form\">";
245 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
246 evt.preventDefault();
247 if (this.validate()) {
248 notify_progress('Changing password...', true);
250 new Ajax.Request('backend.php', {
251 parameters: dojo.objectToQuery(this.getValues()),
252 onComplete: function(transport) {
254 if (transport.responseText.indexOf('ERROR: ') == 0) {
255 notify_error(transport.responseText.replace('ERROR: ', ''));
257 notify_info(transport.responseText);
258 var warn = $('default_pass_warning');
259 if (warn) Element.hide(warn);
266 print "<table width=\"100%\" class=\"prefPrefsList\">";
268 print "<tr><td width=\"40%\">".__("Old password")."</td>";
269 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
271 print "<tr><td width=\"40%\">".__("New password")."</td>";
273 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
274 name=\"new_password\"></td></tr>";
276 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
278 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
282 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
283 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-password\">";
285 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
286 __("Change password")."</button>";
290 print "</div>"; #pane
293 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
295 if ($_SESSION["profile"]) {
296 print_notice("Some preferences are only available in default profile.");
299 if ($_SESSION["profile"]) {
300 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
301 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
303 initialize_user_prefs($link, $_SESSION["uid"]);
304 $profile_qpart = "profile IS NULL";
307 $result = db_query($link, "SELECT
308 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
309 section_name,def_value,section_id
310 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
311 WHERE type_id = ttrss_prefs_types.id AND
313 section_id = ttrss_prefs_sections.id AND
314 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
316 owner_uid = ".$_SESSION["uid"]."
317 ORDER BY section_id,short_desc");
319 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
321 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
322 evt.preventDefault();
323 if (this.validate()) {
324 console.log(dojo.objectToQuery(this.getValues()));
326 new Ajax.Request('backend.php', {
327 parameters: dojo.objectToQuery(this.getValues()),
328 onComplete: function(transport) {
329 var msg = transport.responseText;
330 if (msg.match('PREFS_THEME_CHANGED')) {
331 window.location.reload();
341 $active_section = "";
343 while ($line = db_fetch_assoc($result)) {
345 if (in_array($line["pref_name"], $prefs_blacklist)) {
349 if ($_SESSION["profile"] && in_array($line["pref_name"],
350 $profile_blacklist)) {
354 if ($active_section != $line["section_name"]) {
356 if ($active_section != "") {
360 print "<table width=\"100%\" class=\"prefPrefsList\">";
362 $active_section = $line["section_name"];
364 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
366 if ($line["section_id"] == 2) {
367 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
369 $user_theme = get_pref($link, "_THEME_ID");
370 $themes = get_all_themes();
372 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
373 print "<option value='Default'>".__('Default')."</option>";
374 print "<option value='----------------' disabled=\"1\">--------</option>";
376 foreach ($themes as $t) {
380 if ($base == $user_theme) {
381 $selected = "selected=\"1\"";
386 print "<option $selected value='$base'>$name</option>";
390 print "</select></td></tr>";
393 // print "<tr class=\"title\">
394 // <td width=\"25%\">Option</td><td>Value</td></tr>";
399 // $class = ($lnum % 2) ? "even" : "odd";
403 $type_name = $line["type_name"];
404 $pref_name = $line["pref_name"];
405 $value = $line["value"];
406 $def_value = $line["def_value"];
407 $help_text = $line["help_text"];
409 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
411 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
415 print "<td class=\"prefValue\">";
417 if ($pref_name == "USER_TIMEZONE") {
419 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
421 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
423 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
425 global $update_intervals_nodefault;
427 print_select_hash($pref_name, $value, $update_intervals_nodefault,
428 'dojoType="dijit.form.Select"');
430 } else if ($type_name == "bool") {
431 // print_select($pref_name, $value, array("true", "false"));
433 if ($value == "true") {
439 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
441 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
442 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
444 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
446 print "<input dojoType=\"dijit.form.ValidationTextBox\"
447 required=\"1\" $regexp
448 name=\"$pref_name\" value=\"$value\">";
451 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
453 print "<input dojoType=\"dijit.form.ValidationTextBox\"
455 name=\"$pref_name\" value=\"$value\">";
467 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
468 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save-config\">";
470 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
471 __('Save configuration')."</button> ";
473 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
474 __('Manage profiles')."</button> ";
476 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
477 __('Reset to defaults')."</button></p>";
481 print "</div>"; #pane
482 print "</div>"; #container