]>
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_READ_FEEDS", "FEEDS_SORT_BY_UNREAD");
10 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
11 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
12 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
13 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
16 if (FORCE_ARTICLE_PURGE
!= 0) {
17 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
18 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
21 if ($subop == "change-password") {
23 $old_pw = $_POST["old_password"];
24 $new_pw = $_POST["new_password"];
25 $con_pw = $_POST["confirm_password"];
28 print "ERROR: ".__("Old password cannot be blank.");
33 print "ERROR: ".__("New password cannot be blank.");
37 if ($new_pw != $con_pw) {
38 print "ERROR: ".__("Entered passwords do not match.");
42 $old_pw_hash1 = encrypt_password($old_pw);
43 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
44 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
46 $active_uid = $_SESSION["uid"];
48 if ($old_pw && $new_pw) {
50 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
52 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
53 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
54 pwd_hash = '$old_pw_hash2')");
56 if (db_num_rows($result) == 1) {
57 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
58 WHERE id = '$active_uid'");
60 $_SESSION["pwd_hash"] = $new_pw_hash;
62 print __("Password has been changed.");
64 print "ERROR: ".__('Old password is incorrect.');
70 } else if ($subop == "save-config") {
72 # $_SESSION["prefs_op_result"] = "save-config";
74 $_SESSION["prefs_cache"] = false;
78 $orig_theme = get_pref($link, "_THEME_ID");
80 foreach (array_keys($_POST) as $pref_name) {
82 $pref_name = db_escape_string($pref_name);
83 $value = db_escape_string($_POST[$pref_name]);
85 set_pref($link, $pref_name, $value);
89 if ($orig_theme != get_pref($link, "_THEME_ID")) {
90 print "PREFS_THEME_CHANGED";
92 print __("The configuration was saved.");
97 } else if ($subop == "getHelp") {
99 $pref_name = db_escape_string($_REQUEST["pn"]);
101 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
102 WHERE pref_name = '$pref_name'");
104 if (db_num_rows($result) > 0) {
105 $help_text = db_fetch_result($result, 0, "help_text");
108 printf(__("Unknown option: %s"), $pref_name);
111 } else if ($subop == "change-email") {
113 $email = db_escape_string($_POST["email"]);
114 $full_name = db_escape_string($_POST["full_name"]);
116 $active_uid = $_SESSION["uid"];
118 db_query($link, "UPDATE ttrss_users SET email = '$email',
119 full_name = '$full_name' WHERE id = '$active_uid'");
121 print __("Your personal data has been saved.");
125 } else if ($subop == "reset-config") {
127 $_SESSION["prefs_op_result"] = "reset-to-defaults";
129 if ($_SESSION["profile"]) {
130 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
132 $profile_qpart = "profile IS NULL";
135 db_query($link, "DELETE FROM ttrss_user_prefs
136 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
138 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
140 print "PREFS_THEME_CHANGED";
142 // print __("The configuration was reset to defaults.");
148 if (!SINGLE_USER_MODE
) {
150 $_SESSION["prefs_op_result"] = "";
152 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
153 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
155 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
157 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
158 evt.preventDefault();
159 if (this.validate()) {
160 notify_progress('Saving data...', true);
162 new Ajax.Request('backend.php', {
163 parameters: dojo.objectToQuery(this.getValues()),
164 onComplete: function(transport) {
165 notify_callback2(transport);
171 print "<table width=\"100%\" class=\"prefPrefsList\">";
173 $result = db_query($link, "SELECT email,full_name,
174 access_level FROM ttrss_users
175 WHERE id = ".$_SESSION["uid"]);
177 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
178 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
180 print "<tr><td width=\"40%\">".__('Full name')."</td>";
181 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
182 value=\"$full_name\"></td></tr>";
184 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
185 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
187 if (!SINGLE_USER_MODE
) {
188 $access_level = db_fetch_result($result, 0, "access_level");
189 print "<tr><td width=\"40%\">".__('Access level')."</td>";
190 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
195 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
196 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-email\">";
198 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
199 __("Save data")."</button>";
203 print "</div>"; # pane
204 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
206 $result = db_query($link, "SELECT id FROM ttrss_users
207 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
208 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
210 if (db_num_rows($result) != 0) {
211 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
214 print "<form dojoType=\"dijit.form.Form\">";
216 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
217 evt.preventDefault();
218 if (this.validate()) {
219 notify_progress('Changing password...', true);
221 new Ajax.Request('backend.php', {
222 parameters: dojo.objectToQuery(this.getValues()),
223 onComplete: function(transport) {
225 if (transport.responseText.indexOf('ERROR: ') == 0) {
226 notify_error(transport.responseText.replace('ERROR: ', ''));
228 notify_info(transport.responseText);
229 var warn = $('default_pass_warning');
230 if (warn) Element.hide(warn);
237 print "<table width=\"100%\" class=\"prefPrefsList\">";
239 print "<tr><td width=\"40%\">".__("Old password")."</td>";
240 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
242 print "<tr><td width=\"40%\">".__("New password")."</td>";
244 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
245 name=\"new_password\"></td></tr>";
247 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
249 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
253 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
254 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-password\">";
256 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
257 __("Change password")."</button>";
261 print "</div>"; #pane
264 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
266 if ($_SESSION["profile"]) {
267 print_notice("Some preferences are only available in default profile.");
270 if ($_SESSION["profile"]) {
271 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
272 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
274 initialize_user_prefs($link, $_SESSION["uid"]);
275 $profile_qpart = "profile IS NULL";
278 $result = db_query($link, "SELECT
279 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
280 section_name,def_value,section_id
281 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
282 WHERE type_id = ttrss_prefs_types.id AND
284 section_id = ttrss_prefs_sections.id AND
285 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
287 owner_uid = ".$_SESSION["uid"]."
288 ORDER BY section_id,short_desc");
290 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
292 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
293 evt.preventDefault();
294 if (this.validate()) {
295 console.log(dojo.objectToQuery(this.getValues()));
297 new Ajax.Request('backend.php', {
298 parameters: dojo.objectToQuery(this.getValues()),
299 onComplete: function(transport) {
300 var msg = transport.responseText;
301 if (msg.match('PREFS_THEME_CHANGED')) {
302 window.location.reload();
312 $active_section = "";
314 while ($line = db_fetch_assoc($result)) {
316 if (in_array($line["pref_name"], $prefs_blacklist)) {
320 if ($_SESSION["profile"] && in_array($line["pref_name"],
321 $profile_blacklist)) {
325 if ($active_section != $line["section_name"]) {
327 if ($active_section != "") {
331 print "<table width=\"100%\" class=\"prefPrefsList\">";
333 $active_section = $line["section_name"];
335 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
337 if ($line["section_id"] == 2) {
338 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
340 $user_theme = get_pref($link, "_THEME_ID");
341 $themes = get_all_themes();
343 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
344 print "<option value='Default'>".__('Default')."</option>";
345 print "<option value='----------------' disabled=\"1\">--------</option>";
347 foreach ($themes as $t) {
351 if ($base == $user_theme) {
352 $selected = "selected=\"1\"";
357 print "<option $selected value='$base'>$name</option>";
361 print "</select></td></tr>";
364 // print "<tr class=\"title\">
365 // <td width=\"25%\">Option</td><td>Value</td></tr>";
370 // $class = ($lnum % 2) ? "even" : "odd";
374 $type_name = $line["type_name"];
375 $pref_name = $line["pref_name"];
376 $value = $line["value"];
377 $def_value = $line["def_value"];
378 $help_text = $line["help_text"];
380 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
382 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
386 print "<td class=\"prefValue\">";
388 if ($pref_name == "USER_TIMEZONE") {
390 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
392 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
393 } else if ($pref_name == "USER_STYLESHEET") {
395 print "<button dojoType=\"dijit.form.Button\"
396 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
398 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
400 $limits = array(15, 30, 45, 60);
402 print_select($pref_name, $value, $limits,
403 'dojoType="dijit.form.Select"');
405 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
407 global $update_intervals_nodefault;
409 print_select_hash($pref_name, $value, $update_intervals_nodefault,
410 'dojoType="dijit.form.Select"');
412 } else if ($type_name == "bool") {
413 // print_select($pref_name, $value, array("true", "false"));
415 if ($value == "true") {
421 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
423 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
424 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
426 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
428 print "<input dojoType=\"dijit.form.ValidationTextBox\"
429 required=\"1\" $regexp
430 name=\"$pref_name\" value=\"$value\">";
432 } else if ($pref_name == "SSL_CERT_SERIAL") {
434 print "<input dojoType=\"dijit.form.ValidationTextBox\"
435 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
436 name=\"$pref_name\" value=\"$value\">";
438 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
439 $has_serial = ($cert_serial) ?
"false" : "true";
441 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
442 onclick=\"insertSSLserial('$cert_serial')\">" .
443 __('Register') . "</button>";
445 print " <button dojoType=\"dijit.form.Button\"
446 onclick=\"insertSSLserial('')\">" .
447 __('Clear') . "</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