]>
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",
11 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
12 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
13 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
14 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
17 /* if (FORCE_ARTICLE_PURGE != 0) {
18 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
19 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
22 if ($subop == "change-password") {
24 $old_pw = $_POST["old_password"];
25 $new_pw = $_POST["new_password"];
26 $con_pw = $_POST["confirm_password"];
29 print "ERROR: ".__("Old password cannot be blank.");
34 print "ERROR: ".__("New password cannot be blank.");
38 if ($new_pw != $con_pw) {
39 print "ERROR: ".__("Entered passwords do not match.");
43 $old_pw_hash1 = encrypt_password($old_pw);
44 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
45 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
47 $active_uid = $_SESSION["uid"];
49 if ($old_pw && $new_pw) {
51 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
53 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
54 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
55 pwd_hash = '$old_pw_hash2')");
57 if (db_num_rows($result) == 1) {
58 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
59 WHERE id = '$active_uid'");
61 $_SESSION["pwd_hash"] = $new_pw_hash;
63 print __("Password has been changed.");
65 print "ERROR: ".__('Old password is incorrect.');
71 } else if ($subop == "save-config") {
73 # $_SESSION["prefs_op_result"] = "save-config";
75 $_SESSION["prefs_cache"] = false;
79 $orig_theme = get_pref($link, "_THEME_ID");
81 foreach (array_keys($_POST) as $pref_name) {
83 $pref_name = db_escape_string($pref_name);
84 $value = db_escape_string($_POST[$pref_name]);
86 set_pref($link, $pref_name, $value);
90 if ($orig_theme != get_pref($link, "_THEME_ID")) {
91 print "PREFS_THEME_CHANGED";
93 print __("The configuration was saved.");
98 } else if ($subop == "getHelp") {
100 $pref_name = db_escape_string($_REQUEST["pn"]);
102 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
103 WHERE pref_name = '$pref_name'");
105 if (db_num_rows($result) > 0) {
106 $help_text = db_fetch_result($result, 0, "help_text");
109 printf(__("Unknown option: %s"), $pref_name);
112 } else if ($subop == "change-email") {
114 $email = db_escape_string($_POST["email"]);
115 $full_name = db_escape_string($_POST["full_name"]);
117 $active_uid = $_SESSION["uid"];
119 db_query($link, "UPDATE ttrss_users SET email = '$email',
120 full_name = '$full_name' WHERE id = '$active_uid'");
122 print __("Your personal data has been saved.");
126 } else if ($subop == "reset-config") {
128 $_SESSION["prefs_op_result"] = "reset-to-defaults";
130 if ($_SESSION["profile"]) {
131 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
133 $profile_qpart = "profile IS NULL";
136 db_query($link, "DELETE FROM ttrss_user_prefs
137 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
139 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
141 print "PREFS_THEME_CHANGED";
143 // print __("The configuration was reset to defaults.");
149 if (!SINGLE_USER_MODE
) {
151 $_SESSION["prefs_op_result"] = "";
153 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
154 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
156 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
158 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
159 evt.preventDefault();
160 if (this.validate()) {
161 notify_progress('Saving data...', true);
163 new Ajax.Request('backend.php', {
164 parameters: dojo.objectToQuery(this.getValues()),
165 onComplete: function(transport) {
166 notify_callback2(transport);
172 print "<table width=\"100%\" class=\"prefPrefsList\">";
174 $result = db_query($link, "SELECT email,full_name,
175 access_level FROM ttrss_users
176 WHERE id = ".$_SESSION["uid"]);
178 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
179 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
181 print "<tr><td width=\"40%\">".__('Full name')."</td>";
182 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
183 value=\"$full_name\"></td></tr>";
185 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
186 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
188 if (!SINGLE_USER_MODE
) {
189 $access_level = db_fetch_result($result, 0, "access_level");
190 print "<tr><td width=\"40%\">".__('Access level')."</td>";
191 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
196 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
197 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-email\">";
199 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
200 __("Save data")."</button>";
204 print "</div>"; # pane
205 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
207 $result = db_query($link, "SELECT id FROM ttrss_users
208 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
209 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
211 if (db_num_rows($result) != 0) {
212 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
215 print "<form dojoType=\"dijit.form.Form\">";
217 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
218 evt.preventDefault();
219 if (this.validate()) {
220 notify_progress('Changing password...', true);
222 new Ajax.Request('backend.php', {
223 parameters: dojo.objectToQuery(this.getValues()),
224 onComplete: function(transport) {
226 if (transport.responseText.indexOf('ERROR: ') == 0) {
227 notify_error(transport.responseText.replace('ERROR: ', ''));
229 notify_info(transport.responseText);
230 var warn = $('default_pass_warning');
231 if (warn) Element.hide(warn);
238 print "<table width=\"100%\" class=\"prefPrefsList\">";
240 print "<tr><td width=\"40%\">".__("Old password")."</td>";
241 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
243 print "<tr><td width=\"40%\">".__("New password")."</td>";
245 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
246 name=\"new_password\"></td></tr>";
248 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
250 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
254 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
255 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-password\">";
257 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
258 __("Change password")."</button>";
262 print "</div>"; #pane
265 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
267 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
269 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
270 evt.preventDefault();
271 if (this.validate()) {
272 console.log(dojo.objectToQuery(this.getValues()));
274 new Ajax.Request('backend.php', {
275 parameters: dojo.objectToQuery(this.getValues()),
276 onComplete: function(transport) {
277 var msg = transport.responseText;
278 if (msg.match('PREFS_THEME_CHANGED')) {
279 window.location.reload();
288 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
290 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
292 if ($_SESSION["profile"]) {
293 print_notice("Some preferences are only available in default profile.");
296 if ($_SESSION["profile"]) {
297 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
298 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
300 initialize_user_prefs($link, $_SESSION["uid"]);
301 $profile_qpart = "profile IS NULL";
304 $result = db_query($link, "SELECT
305 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
306 section_name,def_value,section_id
307 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
308 WHERE type_id = ttrss_prefs_types.id AND
310 section_id = ttrss_prefs_sections.id AND
311 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
313 owner_uid = ".$_SESSION["uid"]."
314 ORDER BY section_id,short_desc");
318 $active_section = "";
320 while ($line = db_fetch_assoc($result)) {
322 if (in_array($line["pref_name"], $prefs_blacklist)) {
326 if ($_SESSION["profile"] && in_array($line["pref_name"],
327 $profile_blacklist)) {
331 if ($active_section != $line["section_name"]) {
333 if ($active_section != "") {
337 print "<table width=\"100%\" class=\"prefPrefsList\">";
339 $active_section = $line["section_name"];
341 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
343 if ($line["section_id"] == 2) {
344 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
346 $user_theme = get_pref($link, "_THEME_ID");
347 $themes = get_all_themes();
349 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
350 print "<option value='Default'>".__('Default')."</option>";
351 print "<option value='----------------' disabled=\"1\">--------</option>";
353 foreach ($themes as $t) {
357 if ($base == $user_theme) {
358 $selected = "selected=\"1\"";
363 print "<option $selected value='$base'>$name</option>";
367 print "</select></td></tr>";
370 // print "<tr class=\"title\">
371 // <td width=\"25%\">Option</td><td>Value</td></tr>";
376 // $class = ($lnum % 2) ? "even" : "odd";
380 $type_name = $line["type_name"];
381 $pref_name = $line["pref_name"];
382 $value = $line["value"];
383 $def_value = $line["def_value"];
384 $help_text = $line["help_text"];
386 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
388 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
392 print "<td class=\"prefValue\">";
394 if ($pref_name == "USER_TIMEZONE") {
396 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
398 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
399 } else if ($pref_name == "USER_STYLESHEET") {
401 print "<button dojoType=\"dijit.form.Button\"
402 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
404 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
406 $limits = array(15, 30, 45, 60);
408 print_select($pref_name, $value, $limits,
409 'dojoType="dijit.form.Select"');
411 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
413 global $update_intervals_nodefault;
415 print_select_hash($pref_name, $value, $update_intervals_nodefault,
416 'dojoType="dijit.form.Select"');
418 } else if ($type_name == "bool") {
419 // print_select($pref_name, $value, array("true", "false"));
421 if ($value == "true") {
427 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0) {
428 $disabled = "disabled=\"1\"";
434 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
437 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
438 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
440 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
442 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0) {
443 $disabled = "disabled=\"1\"";
444 $value = FORCE_ARTICLE_PURGE
;
449 print "<input dojoType=\"dijit.form.ValidationTextBox\"
450 required=\"1\" $regexp $disabled
451 name=\"$pref_name\" value=\"$value\">";
453 } else if ($pref_name == "SSL_CERT_SERIAL") {
455 print "<input dojoType=\"dijit.form.ValidationTextBox\"
456 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
457 name=\"$pref_name\" value=\"$value\">";
459 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
460 $has_serial = ($cert_serial) ?
"false" : "true";
462 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
463 onclick=\"insertSSLserial('$cert_serial')\">" .
464 __('Register') . "</button>";
466 print " <button dojoType=\"dijit.form.Button\"
467 onclick=\"insertSSLserial('')\">" .
468 __('Clear') . "</button>";
471 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
473 print "<input dojoType=\"dijit.form.ValidationTextBox\"
475 name=\"$pref_name\" value=\"$value\">";
487 print '</div>'; # inside pane
488 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
490 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
491 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save-config\">";
493 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
494 __('Save configuration')."</button> ";
496 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
497 __('Manage profiles')."</button> ";
499 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
500 __('Reset to defaults')."</button>";
502 print '</div>'; # inner pane
503 print '</div>'; # border container
507 print "</div>"; #pane
508 print "</div>"; #container