]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-prefs.php
2 function module_pref_prefs($link) {
4 global $access_level_names;
6 $subop = $_REQUEST["subop"];
8 $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS",
9 "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS", "ENABLE_FEED_ICONS",
10 "ENABLE_OFFLINE_READING", "EXTENDED_FEEDLIST", "FEEDS_SORT_BY_UNREAD",
11 "OPEN_LINKS_IN_NEW_WINDOW", "USER_STYLESHEET_URL", "ENABLE_FLASH_PLAYER");
13 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
14 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
15 "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS",
16 "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL",
17 "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE");
19 if (FORCE_ARTICLE_PURGE
!= 0) {
20 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
21 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
24 if ($subop == "change-password") {
26 $old_pw = $_POST["old_password"];
27 $new_pw = $_POST["new_password"];
28 $con_pw = $_POST["confirm_password"];
31 print "ERROR: ".__("Old password cannot be blank.");
36 print "ERROR: ".__("New password cannot be blank.");
40 if ($new_pw != $con_pw) {
41 print "ERROR: ".__("Entered passwords do not match.");
45 $old_pw_hash1 = encrypt_password($old_pw);
46 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
47 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
49 $active_uid = $_SESSION["uid"];
51 if ($old_pw && $new_pw) {
53 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
55 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
56 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
57 pwd_hash = '$old_pw_hash2')");
59 if (db_num_rows($result) == 1) {
60 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
61 WHERE id = '$active_uid'");
63 $_SESSION["pwd_hash"] = $new_pw_hash;
65 print __("Password has been changed.");
67 print "ERROR: ".__('Old password is incorrect.');
73 } else if ($subop == "save-config") {
75 # $_SESSION["prefs_op_result"] = "save-config";
77 $_SESSION["prefs_cache"] = false;
81 $orig_theme = get_pref($link, "_THEME_ID");
83 foreach (array_keys($_POST) as $pref_name) {
85 $pref_name = db_escape_string($pref_name);
86 $value = db_escape_string($_POST[$pref_name]);
88 set_pref($link, $pref_name, $value);
92 if ($orig_theme != get_pref($link, "_THEME_ID")) {
93 print "PREFS_THEME_CHANGED";
95 print __("The configuration was saved.");
100 } else if ($subop == "getHelp") {
102 $pref_name = db_escape_string($_REQUEST["pn"]);
104 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
105 WHERE pref_name = '$pref_name'");
107 if (db_num_rows($result) > 0) {
108 $help_text = db_fetch_result($result, 0, "help_text");
111 printf(__("Unknown option: %s"), $pref_name);
114 } else if ($subop == "change-email") {
116 $email = db_escape_string($_POST["email"]);
117 $full_name = db_escape_string($_POST["full_name"]);
119 $active_uid = $_SESSION["uid"];
121 db_query($link, "UPDATE ttrss_users SET email = '$email',
122 full_name = '$full_name' WHERE id = '$active_uid'");
124 print __("Your personal data has been saved.");
128 } else if ($subop == "reset-config") {
130 $_SESSION["prefs_op_result"] = "reset-to-defaults";
132 if ($_SESSION["profile"]) {
133 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
135 $profile_qpart = "profile IS NULL";
138 db_query($link, "DELETE FROM ttrss_user_prefs
139 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
141 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
143 print "PREFS_THEME_CHANGED";
145 // print __("The configuration was reset to defaults.");
151 if (!SINGLE_USER_MODE
) {
153 $_SESSION["prefs_op_result"] = "";
155 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
156 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
158 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
160 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
161 evt.preventDefault();
162 if (this.validate()) {
163 notify_progress('Saving data...', true);
165 new Ajax.Request('backend.php', {
166 parameters: dojo.objectToQuery(this.getValues()),
167 onComplete: function(transport) {
168 notify_callback2(transport);
174 print "<table width=\"100%\" class=\"prefPrefsList\">";
176 $result = db_query($link, "SELECT email,full_name,
177 access_level FROM ttrss_users
178 WHERE id = ".$_SESSION["uid"]);
180 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
181 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
183 print "<tr><td width=\"40%\">".__('Full name')."</td>";
184 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
185 value=\"$full_name\"></td></tr>";
187 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
188 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
190 if (!SINGLE_USER_MODE
) {
191 $access_level = db_fetch_result($result, 0, "access_level");
192 print "<tr><td width=\"40%\">".__('Access level')."</td>";
193 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
198 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
199 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-email\">";
201 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
202 __("Save data")."</button>";
206 print "</div>"; # pane
207 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
209 $result = db_query($link, "SELECT id FROM ttrss_users
210 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
211 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
213 if (db_num_rows($result) != 0) {
214 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
217 print "<form dojoType=\"dijit.form.Form\">";
219 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
220 evt.preventDefault();
221 if (this.validate()) {
222 notify_progress('Changing password...', true);
224 new Ajax.Request('backend.php', {
225 parameters: dojo.objectToQuery(this.getValues()),
226 onComplete: function(transport) {
228 if (transport.responseText.indexOf('ERROR: ') == 0) {
229 notify_error(transport.responseText.replace('ERROR: ', ''));
231 notify_info(transport.responseText);
232 var warn = $('default_pass_warning');
233 if (warn) Element.hide(warn);
240 print "<table width=\"100%\" class=\"prefPrefsList\">";
242 print "<tr><td width=\"40%\">".__("Old password")."</td>";
243 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
245 print "<tr><td width=\"40%\">".__("New password")."</td>";
247 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
248 name=\"new_password\"></td></tr>";
250 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
252 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
256 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
257 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-password\">";
259 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
260 __("Change password")."</button>";
264 print "</div>"; #pane
267 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
269 if ($_SESSION["profile"]) {
270 print_notice("Some preferences are only available in default profile.");
273 if ($_SESSION["profile"]) {
274 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
275 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
277 initialize_user_prefs($link, $_SESSION["uid"]);
278 $profile_qpart = "profile IS NULL";
281 $result = db_query($link, "SELECT
282 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
283 section_name,def_value,section_id
284 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
285 WHERE type_id = ttrss_prefs_types.id AND
287 section_id = ttrss_prefs_sections.id AND
288 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
290 owner_uid = ".$_SESSION["uid"]."
291 ORDER BY section_id,short_desc");
293 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
295 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
296 evt.preventDefault();
297 if (this.validate()) {
298 console.log(dojo.objectToQuery(this.getValues()));
300 new Ajax.Request('backend.php', {
301 parameters: dojo.objectToQuery(this.getValues()),
302 onComplete: function(transport) {
303 var msg = transport.responseText;
304 if (msg.match('PREFS_THEME_CHANGED')) {
305 window.location.reload();
315 $active_section = "";
317 while ($line = db_fetch_assoc($result)) {
319 if (in_array($line["pref_name"], $prefs_blacklist)) {
323 if ($_SESSION["profile"] && in_array($line["pref_name"],
324 $profile_blacklist)) {
328 if ($active_section != $line["section_name"]) {
330 if ($active_section != "") {
334 print "<table width=\"100%\" class=\"prefPrefsList\">";
336 $active_section = $line["section_name"];
338 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
340 if ($line["section_id"] == 2) {
341 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
343 $user_theme = get_pref($link, "_THEME_ID");
344 $themes = get_all_themes();
346 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
347 print "<option value='Default'>".__('Default')."</option>";
348 print "<option value='----------------' disabled=\"1\">--------</option>";
350 foreach ($themes as $t) {
354 if ($base == $user_theme) {
355 $selected = "selected=\"1\"";
360 print "<option $selected value='$base'>$name</option>";
364 print "</select></td></tr>";
367 // print "<tr class=\"title\">
368 // <td width=\"25%\">Option</td><td>Value</td></tr>";
373 // $class = ($lnum % 2) ? "even" : "odd";
377 $type_name = $line["type_name"];
378 $pref_name = $line["pref_name"];
379 $value = $line["value"];
380 $def_value = $line["def_value"];
381 $help_text = $line["help_text"];
383 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
385 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
389 print "<td class=\"prefValue\">";
391 if ($pref_name == "USER_TIMEZONE") {
393 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
395 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
396 } else if ($pref_name == "USER_STYLESHEET") {
398 print "<button dojoType=\"dijit.form.Button\"
399 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
401 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
403 $limits = array(15, 30, 45, 60);
405 print_select($pref_name, $value, $limits,
406 'dojoType="dijit.form.Select"');
408 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
410 global $update_intervals_nodefault;
412 print_select_hash($pref_name, $value, $update_intervals_nodefault,
413 'dojoType="dijit.form.Select"');
415 } else if ($type_name == "bool") {
416 // print_select($pref_name, $value, array("true", "false"));
418 if ($value == "true") {
424 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
426 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
427 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
429 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
431 print "<input dojoType=\"dijit.form.ValidationTextBox\"
432 required=\"1\" $regexp
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\"
439 name=\"$pref_name\" value=\"$value\">";
441 $cert_serial = htmlspecialchars($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"]);
444 print " <button dojoType=\"dijit.form.Button\"
445 onclick=\"insertSSLserial('$cert_serial')\">" .
446 __('Fill automatically') . "</button>";
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