]>
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",
12 "HEADLINES_SMART_DATE");
14 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
15 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
16 "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS",
17 "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL",
18 "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE");
20 if (FORCE_ARTICLE_PURGE
!= 0) {
21 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
22 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
25 if ($subop == "change-password") {
27 $old_pw = $_POST["old_password"];
28 $new_pw = $_POST["new_password"];
29 $con_pw = $_POST["confirm_password"];
32 print "ERROR: ".__("Old password cannot be blank.");
37 print "ERROR: ".__("New password cannot be blank.");
41 if ($new_pw != $con_pw) {
42 print "ERROR: ".__("Entered passwords do not match.");
46 $old_pw_hash1 = encrypt_password($old_pw);
47 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
48 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
50 $active_uid = $_SESSION["uid"];
52 if ($old_pw && $new_pw) {
54 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
56 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
57 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
58 pwd_hash = '$old_pw_hash2')");
60 if (db_num_rows($result) == 1) {
61 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
62 WHERE id = '$active_uid'");
64 $_SESSION["pwd_hash"] = $new_pw_hash;
66 print __("Password has been changed.");
68 print "ERROR: ".__('Old password is incorrect.');
74 } else if ($subop == "save-config") {
76 # $_SESSION["prefs_op_result"] = "save-config";
78 $_SESSION["prefs_cache"] = false;
82 $orig_theme = get_pref($link, "_THEME_ID");
84 foreach (array_keys($_POST) as $pref_name) {
86 $pref_name = db_escape_string($pref_name);
87 $value = db_escape_string($_POST[$pref_name]);
89 set_pref($link, $pref_name, $value);
93 if ($orig_theme != get_pref($link, "_THEME_ID")) {
94 print "PREFS_THEME_CHANGED";
96 print __("The configuration was saved.");
101 } else if ($subop == "getHelp") {
103 $pref_name = db_escape_string($_REQUEST["pn"]);
105 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
106 WHERE pref_name = '$pref_name'");
108 if (db_num_rows($result) > 0) {
109 $help_text = db_fetch_result($result, 0, "help_text");
112 printf(__("Unknown option: %s"), $pref_name);
115 } else if ($subop == "change-email") {
117 $email = db_escape_string($_POST["email"]);
118 $full_name = db_escape_string($_POST["full_name"]);
120 $active_uid = $_SESSION["uid"];
122 db_query($link, "UPDATE ttrss_users SET email = '$email',
123 full_name = '$full_name' WHERE id = '$active_uid'");
125 print __("Your personal data has been saved.");
129 } else if ($subop == "reset-config") {
131 $_SESSION["prefs_op_result"] = "reset-to-defaults";
133 if ($_SESSION["profile"]) {
134 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
136 $profile_qpart = "profile IS NULL";
139 db_query($link, "DELETE FROM ttrss_user_prefs
140 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
142 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
144 print "PREFS_THEME_CHANGED";
146 // print __("The configuration was reset to defaults.");
152 if (!SINGLE_USER_MODE
) {
154 $_SESSION["prefs_op_result"] = "";
156 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
157 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
159 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
161 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
162 evt.preventDefault();
163 if (this.validate()) {
164 notify_progress('Saving data...', true);
166 new Ajax.Request('backend.php', {
167 parameters: dojo.objectToQuery(this.getValues()),
168 onComplete: function(transport) {
169 notify_callback2(transport);
175 print "<table width=\"100%\" class=\"prefPrefsList\">";
177 $result = db_query($link, "SELECT email,full_name,
178 access_level FROM ttrss_users
179 WHERE id = ".$_SESSION["uid"]);
181 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
182 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
184 print "<tr><td width=\"40%\">".__('Full name')."</td>";
185 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
186 value=\"$full_name\"></td></tr>";
188 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
189 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
191 if (!SINGLE_USER_MODE
) {
192 $access_level = db_fetch_result($result, 0, "access_level");
193 print "<tr><td width=\"40%\">".__('Access level')."</td>";
194 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
199 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
200 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-email\">";
202 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
203 __("Save data")."</button>";
207 print "</div>"; # pane
208 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
210 $result = db_query($link, "SELECT id FROM ttrss_users
211 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
212 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
214 if (db_num_rows($result) != 0) {
215 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
218 print "<form dojoType=\"dijit.form.Form\">";
220 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
221 evt.preventDefault();
222 if (this.validate()) {
223 notify_progress('Changing password...', true);
225 new Ajax.Request('backend.php', {
226 parameters: dojo.objectToQuery(this.getValues()),
227 onComplete: function(transport) {
229 if (transport.responseText.indexOf('ERROR: ') == 0) {
230 notify_error(transport.responseText.replace('ERROR: ', ''));
232 notify_info(transport.responseText);
233 var warn = $('default_pass_warning');
234 if (warn) Element.hide(warn);
241 print "<table width=\"100%\" class=\"prefPrefsList\">";
243 print "<tr><td width=\"40%\">".__("Old password")."</td>";
244 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
246 print "<tr><td width=\"40%\">".__("New password")."</td>";
248 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
249 name=\"new_password\"></td></tr>";
251 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
253 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
257 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
258 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-password\">";
260 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
261 __("Change password")."</button>";
265 print "</div>"; #pane
268 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
270 if ($_SESSION["profile"]) {
271 print_notice("Some preferences are only available in default profile.");
274 if ($_SESSION["profile"]) {
275 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
276 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
278 initialize_user_prefs($link, $_SESSION["uid"]);
279 $profile_qpart = "profile IS NULL";
282 $result = db_query($link, "SELECT
283 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
284 section_name,def_value,section_id
285 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
286 WHERE type_id = ttrss_prefs_types.id AND
288 section_id = ttrss_prefs_sections.id AND
289 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
291 owner_uid = ".$_SESSION["uid"]."
292 ORDER BY section_id,short_desc");
294 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
296 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
297 evt.preventDefault();
298 if (this.validate()) {
299 console.log(dojo.objectToQuery(this.getValues()));
301 new Ajax.Request('backend.php', {
302 parameters: dojo.objectToQuery(this.getValues()),
303 onComplete: function(transport) {
304 var msg = transport.responseText;
305 if (msg.match('PREFS_THEME_CHANGED')) {
306 window.location.reload();
316 $active_section = "";
318 while ($line = db_fetch_assoc($result)) {
320 if (in_array($line["pref_name"], $prefs_blacklist)) {
324 if ($_SESSION["profile"] && in_array($line["pref_name"],
325 $profile_blacklist)) {
329 if ($active_section != $line["section_name"]) {
331 if ($active_section != "") {
335 print "<table width=\"100%\" class=\"prefPrefsList\">";
337 $active_section = $line["section_name"];
339 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
341 if ($line["section_id"] == 2) {
342 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
344 $user_theme = get_pref($link, "_THEME_ID");
345 $themes = get_all_themes();
347 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
348 print "<option value='Default'>".__('Default')."</option>";
349 print "<option value='----------------' disabled=\"1\">--------</option>";
351 foreach ($themes as $t) {
355 if ($base == $user_theme) {
356 $selected = "selected=\"1\"";
361 print "<option $selected value='$base'>$name</option>";
365 print "</select></td></tr>";
368 // print "<tr class=\"title\">
369 // <td width=\"25%\">Option</td><td>Value</td></tr>";
374 // $class = ($lnum % 2) ? "even" : "odd";
378 $type_name = $line["type_name"];
379 $pref_name = $line["pref_name"];
380 $value = $line["value"];
381 $def_value = $line["def_value"];
382 $help_text = $line["help_text"];
384 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
386 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
390 print "<td class=\"prefValue\">";
392 if ($pref_name == "USER_TIMEZONE") {
394 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
396 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
397 } else if ($pref_name == "USER_STYLESHEET") {
399 print "<button dojoType=\"dijit.form.Button\"
400 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
402 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
404 $limits = array(15, 30, 45, 60);
406 print_select($pref_name, $value, $limits,
407 'dojoType="dijit.form.Select"');
409 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
411 global $update_intervals_nodefault;
413 print_select_hash($pref_name, $value, $update_intervals_nodefault,
414 'dojoType="dijit.form.Select"');
416 } else if ($type_name == "bool") {
417 // print_select($pref_name, $value, array("true", "false"));
419 if ($value == "true") {
425 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
427 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
428 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
430 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
432 print "<input dojoType=\"dijit.form.ValidationTextBox\"
433 required=\"1\" $regexp
434 name=\"$pref_name\" value=\"$value\">";
436 } else if ($pref_name == "SSL_CERT_SERIAL") {
438 print "<input dojoType=\"dijit.form.ValidationTextBox\"
439 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
440 name=\"$pref_name\" value=\"$value\">";
442 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
443 $has_serial = ($cert_serial) ?
"false" : "true";
445 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
446 onclick=\"insertSSLserial('$cert_serial')\">" .
447 __('Register') . "</button>";
449 print " <button dojoType=\"dijit.form.Button\"
450 onclick=\"insertSSLserial('')\">" .
451 __('Clear') . "</button>";
454 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
456 print "<input dojoType=\"dijit.form.ValidationTextBox\"
458 name=\"$pref_name\" value=\"$value\">";
470 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
471 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save-config\">";
473 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
474 __('Save configuration')."</button> ";
476 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
477 __('Manage profiles')."</button> ";
479 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
480 __('Reset to defaults')."</button></p>";
484 print "</div>"; #pane
485 print "</div>"; #container