]>
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");
20 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
21 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
22 "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS",
23 "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL",
24 "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE");
26 if (FORCE_ARTICLE_PURGE
!= 0) {
27 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
28 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
31 if ($subop == "change-password") {
33 $old_pw = $_POST["old_password"];
34 $new_pw = $_POST["new_password"];
35 $con_pw = $_POST["confirm_password"];
38 print "ERROR: ".__("Old password cannot be blank.");
43 print "ERROR: ".__("New password cannot be blank.");
47 if ($new_pw != $con_pw) {
48 print "ERROR: ".__("Entered passwords do not match.");
52 $old_pw_hash1 = encrypt_password($old_pw);
53 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
54 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
56 $active_uid = $_SESSION["uid"];
58 if ($old_pw && $new_pw) {
60 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
62 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
63 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
64 pwd_hash = '$old_pw_hash2')");
66 if (db_num_rows($result) == 1) {
67 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
68 WHERE id = '$active_uid'");
70 $_SESSION["pwd_hash"] = $new_pw_hash;
72 print __("Password has been changed.");
74 print "ERROR: ".__('Old password is incorrect.');
80 } else if ($subop == "save-config") {
82 # $_SESSION["prefs_op_result"] = "save-config";
84 $_SESSION["prefs_cache"] = false;
88 $orig_theme = get_pref($link, "_THEME_ID");
90 foreach (array_keys($_POST) as $pref_name) {
92 $pref_name = db_escape_string($pref_name);
93 $value = db_escape_string($_POST[$pref_name]);
95 set_pref($link, $pref_name, $value);
99 if ($orig_theme != get_pref($link, "_THEME_ID")) {
100 print "PREFS_THEME_CHANGED";
102 print __("The configuration was saved.");
107 } else if ($subop == "getHelp") {
109 $pref_name = db_escape_string($_REQUEST["pn"]);
111 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
112 WHERE pref_name = '$pref_name'");
114 if (db_num_rows($result) > 0) {
115 $help_text = db_fetch_result($result, 0, "help_text");
118 printf(__("Unknown option: %s"), $pref_name);
121 } else if ($subop == "change-email") {
123 $email = db_escape_string($_POST["email"]);
124 $full_name = db_escape_string($_POST["full_name"]);
126 $active_uid = $_SESSION["uid"];
128 db_query($link, "UPDATE ttrss_users SET email = '$email',
129 full_name = '$full_name' WHERE id = '$active_uid'");
131 print __("Your personal data has been saved.");
135 } else if ($subop == "reset-config") {
137 $_SESSION["prefs_op_result"] = "reset-to-defaults";
139 if ($_SESSION["profile"]) {
140 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
142 $profile_qpart = "profile IS NULL";
145 db_query($link, "DELETE FROM ttrss_user_prefs
146 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
148 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
150 print "PREFS_THEME_CHANGED";
152 // print __("The configuration was reset to defaults.");
158 if (!SINGLE_USER_MODE
) {
160 /* if ($_SESSION["pwd_change_result"] == "failed") {
161 print format_warning("Could not change the password.");
164 if ($_SESSION["pwd_change_result"] == "ok") {
165 print format_notice("Password was changed.");
168 $_SESSION["pwd_change_result"] = ""; */
170 /* if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
171 print format_notice(__("The configuration was reset to defaults."));
174 # if ($_SESSION["prefs_op_result"] == "save-config") {
175 # print format_notice(__("The configuration was saved."));
178 $_SESSION["prefs_op_result"] = "";
180 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
181 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
183 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
185 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
186 evt.preventDefault();
187 if (this.validate()) {
188 notify_progress('Saving data...', true);
190 new Ajax.Request('backend.php', {
191 parameters: dojo.objectToQuery(this.getValues()),
192 onComplete: function(transport) {
193 notify_callback2(transport);
199 print "<table width=\"100%\" class=\"prefPrefsList\">";
201 $result = db_query($link, "SELECT email,full_name,
202 access_level FROM ttrss_users
203 WHERE id = ".$_SESSION["uid"]);
205 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
206 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
208 print "<tr><td width=\"40%\">".__('Full name')."</td>";
209 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
210 value=\"$full_name\"></td></tr>";
212 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
213 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
215 if (!SINGLE_USER_MODE
) {
216 $access_level = db_fetch_result($result, 0, "access_level");
217 print "<tr><td width=\"40%\">".__('Access level')."</td>";
218 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
223 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
224 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-email\">";
226 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
227 __("Save data")."</button>";
231 print "</div>"; # pane
232 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
234 $result = db_query($link, "SELECT id FROM ttrss_users
235 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
236 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
238 if (db_num_rows($result) != 0) {
239 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
242 print "<form dojoType=\"dijit.form.Form\">";
244 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
245 evt.preventDefault();
246 if (this.validate()) {
247 notify_progress('Changing password...', true);
249 new Ajax.Request('backend.php', {
250 parameters: dojo.objectToQuery(this.getValues()),
251 onComplete: function(transport) {
253 if (transport.responseText.indexOf('ERROR: ') == 0) {
254 notify_error(transport.responseText.replace('ERROR: ', ''));
256 notify_info(transport.responseText);
257 var warn = $('default_pass_warning');
258 if (warn) Element.hide(warn);
265 print "<table width=\"100%\" class=\"prefPrefsList\">";
267 print "<tr><td width=\"40%\">".__("Old password")."</td>";
268 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
270 print "<tr><td width=\"40%\">".__("New password")."</td>";
272 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
273 name=\"new_password\"></td></tr>";
275 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
277 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
281 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
282 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-password\">";
284 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
285 __("Change password")."</button>";
289 print "</div>"; #pane
292 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
294 if ($_SESSION["profile"]) {
295 print_notice("Some preferences are only available in default profile.");
298 if ($_SESSION["profile"]) {
299 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
300 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
302 initialize_user_prefs($link, $_SESSION["uid"]);
303 $profile_qpart = "profile IS NULL";
306 $result = db_query($link, "SELECT
307 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
308 section_name,def_value,section_id
309 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
310 WHERE type_id = ttrss_prefs_types.id AND
312 section_id = ttrss_prefs_sections.id AND
313 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
315 owner_uid = ".$_SESSION["uid"]."
316 ORDER BY section_id,short_desc");
318 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
320 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
321 evt.preventDefault();
322 if (this.validate()) {
323 console.log(dojo.objectToQuery(this.getValues()));
325 new Ajax.Request('backend.php', {
326 parameters: dojo.objectToQuery(this.getValues()),
327 onComplete: function(transport) {
328 var msg = transport.responseText;
329 if (msg.match('PREFS_THEME_CHANGED')) {
330 window.location.reload();
340 $active_section = "";
342 while ($line = db_fetch_assoc($result)) {
344 if (in_array($line["pref_name"], $prefs_blacklist)) {
348 if ($_SESSION["profile"] && in_array($line["pref_name"],
349 $profile_blacklist)) {
353 if ($active_section != $line["section_name"]) {
355 if ($active_section != "") {
359 print "<table width=\"100%\" class=\"prefPrefsList\">";
361 $active_section = $line["section_name"];
363 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
365 if ($line["section_id"] == 2) {
366 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
368 $user_theme = get_pref($link, "_THEME_ID");
369 $themes = get_all_themes();
371 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
372 print "<option value='Default'>".__('Default')."</option>";
373 print "<option value='----------------' disabled=\"1\">--------</option>";
375 foreach ($themes as $t) {
379 if ($base == $user_theme) {
380 $selected = "selected=\"1\"";
385 print "<option $selected value='$base'>$name</option>";
389 print "</select></td></tr>";
392 // print "<tr class=\"title\">
393 // <td width=\"25%\">Option</td><td>Value</td></tr>";
398 // $class = ($lnum % 2) ? "even" : "odd";
402 $type_name = $line["type_name"];
403 $pref_name = $line["pref_name"];
404 $value = $line["value"];
405 $def_value = $line["def_value"];
406 $help_text = $line["help_text"];
408 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
410 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
414 print "<td class=\"prefValue\">";
416 if ($pref_name == "USER_TIMEZONE") {
418 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
420 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
422 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
424 global $update_intervals_nodefault;
426 print_select_hash($pref_name, $value, $update_intervals_nodefault,
427 'dojoType="dijit.form.Select"');
429 } else if ($type_name == "bool") {
430 // print_select($pref_name, $value, array("true", "false"));
432 if ($value == "true") {
438 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
440 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
441 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
443 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
445 print "<input dojoType=\"dijit.form.ValidationTextBox\"
446 required=\"1\" $regexp
447 name=\"$pref_name\" value=\"$value\">";
450 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
452 print "<input dojoType=\"dijit.form.ValidationTextBox\"
454 name=\"$pref_name\" value=\"$value\">";
466 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
467 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save-config\">";
469 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
470 __('Save configuration')."</button> ";
472 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
473 __('Manage profiles')."</button> ";
475 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
476 __('Reset to defaults')."</button></p>";
480 print "</div>"; #pane
481 print "</div>"; #container