]>
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) {
11 $subop = $_REQUEST["subop"];
13 if ($subop == "change-password") {
15 $old_pw = $_POST["OLD_PASSWORD"];
16 $new_pw = $_POST["NEW_PASSWORD"];
17 $con_pw = $_POST["CONFIRM_PASSWORD"];
20 print "ERROR: ".__("Old password cannot be blank.");
25 print "ERROR: ".__("New password cannot be blank.");
29 if ($new_pw != $con_pw) {
30 print "ERROR: ".__("Entered passwords do not match.");
34 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
35 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
37 $active_uid = $_SESSION["uid"];
39 if ($old_pw && $new_pw) {
41 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
43 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
44 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
45 pwd_hash = '$old_pw_hash')");
47 if (db_num_rows($result) == 1) {
48 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
49 WHERE id = '$active_uid'");
51 print __("Password has been changed.");
53 print "ERROR: ".__('Old password is incorrect.');
59 } else if ($subop == __("Save configuration")) {
61 $_SESSION["prefs_op_result"] = "save-config";
63 $_SESSION["prefs_cache"] = false;
65 foreach (array_keys($_POST) as $pref_name) {
67 $pref_name = db_escape_string($pref_name);
68 $value = db_escape_string($_POST[$pref_name]);
70 $result = db_query($link, "SELECT type_name
71 FROM ttrss_prefs,ttrss_prefs_types
72 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
74 if (db_num_rows($result) > 0) {
76 $type_name = db_fetch_result($result, 0, "type_name");
78 // print "$pref_name : $type_name : $value<br>";
80 if ($type_name == "bool") {
86 } else if ($type_name == "integer") {
87 $value = sprintf("%d", $value);
90 // print "$pref_name : $type_name : $value<br>";
92 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
93 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
99 return prefs_js_redirect();
101 } else if ($subop == "getHelp") {
103 $pref_name = db_escape_string($_GET["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 print "Unknown option: $pref_name";
115 } else if ($subop == "change-email") {
117 $email = db_escape_string($_POST["email"]);
118 $active_uid = $_SESSION["uid"];
120 db_query($link, "UPDATE ttrss_users SET email = '$email'
121 WHERE id = '$active_uid'");
123 print "E-mail has been changed.";
127 } else if ($subop == __("Reset to defaults")) {
129 $_SESSION["prefs_op_result"] = "reset-to-defaults";
131 if (DB_TYPE
== "pgsql") {
132 db_query($link,"UPDATE ttrss_user_prefs
133 SET value = ttrss_prefs.def_value
134 WHERE owner_uid = '".$_SESSION["uid"]."' AND
135 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
137 db_query($link, "DELETE FROM ttrss_user_prefs
138 WHERE owner_uid = ".$_SESSION["uid"]);
139 initialize_user_prefs($link, $_SESSION["uid"]);
142 return prefs_js_redirect();
144 } else if ($subop == "Change theme") {
146 $theme = db_escape_string($_POST["theme"]);
148 if ($theme == "Default") {
149 $theme_qpart = 'NULL';
151 $theme_qpart = "'$theme'";
154 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
155 WHERE theme_name = '$theme'");
157 if (db_num_rows($result) == 1) {
158 $theme_id = db_fetch_result($result, 0, "id");
159 $theme_path = db_fetch_result($result, 0, "theme_path");
165 db_query($link, "UPDATE ttrss_users SET
166 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
168 $_SESSION["theme"] = $theme_path;
170 return prefs_js_redirect();
174 // print check_for_update($link);
176 set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig");
178 if (!SINGLE_USER_MODE
) {
180 $result = db_query($link, "SELECT id FROM ttrss_users
181 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
182 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
184 if (db_num_rows($result) != 0) {
185 print format_warning(__("Your password is at default value,
186 please change it."), "default_pass_warning");
189 /* if ($_SESSION["pwd_change_result"] == "failed") {
190 print format_warning("Could not change the password.");
193 if ($_SESSION["pwd_change_result"] == "ok") {
194 print format_notice("Password was changed.");
197 $_SESSION["pwd_change_result"] = ""; */
199 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
200 print format_notice(__("The configuration was reset to defaults."));
203 if ($_SESSION["prefs_op_result"] == "save-config") {
204 print format_notice(__("The configuration was saved."));
207 $_SESSION["prefs_op_result"] = "";
209 print "<form onsubmit='return false' id='change_email_form'>";
211 print "<table width=\"100%\" class=\"prefPrefsList\">";
212 print "<tr><td colspan='3'><h3>".__("Personal data")."</h3></tr></td>";
214 $result = db_query($link, "SELECT email FROM ttrss_users
215 WHERE id = ".$_SESSION["uid"]);
217 $email = db_fetch_result($result, 0, "email");
219 print "<tr><td width=\"40%\">E-mail</td>";
220 print "<td><input class=\"editbox\" name=\"email\"
221 onkeypress=\"return filterCR(event, changeUserEmail)\"
222 value=\"$email\"></td></tr>";
226 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
227 print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">";
231 print "<p><input class=\"button\" type=\"submit\"
232 onclick=\"return changeUserEmail()\" value=\"".__("Change e-mail")."\">";
234 print "<form onsubmit=\"return false\"
235 name=\"change_pass_form\" id=\"change_pass_form\">";
237 print "<table width=\"100%\" class=\"prefPrefsList\">";
238 print "<tr><td colspan='3'><h3>".__("Authentication")."</h3></tr></td>";
240 print "<tr><td width=\"40%\">".__("Old password")."</td>";
241 print "<td><input class=\"editbox\" type=\"password\"
242 onkeypress=\"return filterCR(event, changeUserPassword)\"
243 name=\"OLD_PASSWORD\"></td></tr>";
245 print "<tr><td width=\"40%\">".__("New password")."</td>";
247 print "<td><input class=\"editbox\" type=\"password\"
248 onkeypress=\"return filterCR(event, changeUserPassword)\"
249 name=\"NEW_PASSWORD\"></td></tr>";
251 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
253 print "<td><input class=\"editbox\" type=\"password\"
254 onkeypress=\"return filterCR(event, changeUserPassword)\"
255 name=\"CONFIRM_PASSWORD\"></td></tr>";
259 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
260 print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">";
264 print "<p><input class=\"button\" type=\"submit\"
265 onclick=\"return changeUserPassword()\"
266 value=\"".__("Change password")."\">";
270 $result = db_query($link, "SELECT
271 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
273 $user_theme_id = db_fetch_result($result, 0, "theme_id");
275 $result = db_query($link, "SELECT
276 id,theme_name FROM ttrss_themes ORDER BY theme_name");
278 if (db_num_rows($result) > 0) {
280 print "<form action=\"backend.php\" method=\"POST\">";
281 print "<table width=\"100%\" class=\"prefPrefsList\">";
282 print "<tr><td colspan='3'><h3>".__("Themes")."</h3></tr></td>";
283 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
284 print "<td><select name=\"theme\">";
285 print "<option value='Default'>".__('Default')."</option>";
286 print "<option disabled>--------</option>";
288 while ($line = db_fetch_assoc($result)) {
289 if ($line["id"] == $user_theme_id) {
290 $selected = "selected";
294 print "<option $selected>" . $line["theme_name"] . "</option>";
296 print "</select></td></tr>";
298 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
299 print "<input type=\"hidden\" name=\"subop\" value=\"Change theme\">";
300 print "<p><input class=\"button\" type=\"submit\"
301 value=\"".__('Change theme')."\">";
305 initialize_user_prefs($link, $_SESSION["uid"]);
307 $result = db_query($link, "SELECT
308 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
309 section_name,def_value
310 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
311 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 action=\"backend.php\" method=\"POST\">";
322 $active_section = "";
324 while ($line = db_fetch_assoc($result)) {
326 if ($active_section != $line["section_name"]) {
328 if ($active_section != "") {
332 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
334 $active_section = $line["section_name"];
336 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
337 // print "<tr class=\"title\">
338 // <td width=\"25%\">Option</td><td>Value</td></tr>";
343 // $class = ($lnum % 2) ? "even" : "odd";
347 $type_name = $line["type_name"];
348 $pref_name = $line["pref_name"];
349 $value = $line["value"];
350 $def_value = $line["def_value"];
351 $help_text = $line["help_text"];
353 print "<td width=\"40%\" id=\"$pref_name\">" . __($line["short_desc"]);
355 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
361 if ($type_name == "bool") {
362 // print_select($pref_name, $value, array("true", "false"));
364 if ($value == "true") {
370 print_radio($pref_name, $value, array(__("Yes"), __("No")));
373 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
385 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
387 print "<p><input class=\"button\" type=\"submit\"
388 name=\"subop\" value=\"".__('Save configuration')."\">";
390 print " <input class=\"button\" type=\"submit\"
391 name=\"subop\" onclick=\"return validatePrefsReset()\"
392 value=\"".__('Reset to defaults')."\"></p>";