]> git.wh0rd.org - tt-rss.git/blame - modules/pref-prefs.php
move messages.* to fr_FR/LC_MESSAGES
[tt-rss.git] / modules / pref-prefs.php
CommitLineData
ef8be8ea 1<?php
f27d955a
AD
2 function prefs_js_redirect() {
3 print "<html><body>
4 <script type=\"text/javascript\">
5 window.location = 'prefs.php';
6 </script>
7 </body></html>";
8 }
9
ef8be8ea
AD
10 function module_pref_prefs($link) {
11 $subop = $_REQUEST["subop"];
12
d95bd220
AD
13 if ($subop == "change-password") {
14
15 $old_pw = $_POST["OLD_PASSWORD"];
16 $new_pw = $_POST["NEW_PASSWORD"];
17 $con_pw = $_POST["CONFIRM_PASSWORD"];
18
19 if ($old_pw == "") {
7990ac73 20 print "ERROR: ".__("Old password cannot be blank.");
d95bd220
AD
21 return;
22 }
23
24 if ($new_pw == "") {
7990ac73 25 print "ERROR: ".__("New password cannot be blank.");
d95bd220
AD
26 return;
27 }
28
29 if ($new_pw != $con_pw) {
7990ac73 30 print "ERROR: ".__("Entered passwords do not match.");
d95bd220
AD
31 return;
32 }
33
34 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
35 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
36
37 $active_uid = $_SESSION["uid"];
38
39 if ($old_pw && $new_pw) {
40
41 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
42
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')");
46
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'");
50
7990ac73 51 print __("Password has been changed.");
d95bd220 52 } else {
7990ac73 53 print "ERROR: ".__('Old password is incorrect.');
d95bd220
AD
54 }
55 }
56
57 return;
d95bd220 58
42395d28 59 } else if ($subop == "Save configuration") {
ef8be8ea 60
ef8be8ea
AD
61 $_SESSION["prefs_op_result"] = "save-config";
62
63 $_SESSION["prefs_cache"] = false;
64
65 foreach (array_keys($_POST) as $pref_name) {
66
67 $pref_name = db_escape_string($pref_name);
68 $value = db_escape_string($_POST[$pref_name]);
69
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");
73
74 if (db_num_rows($result) > 0) {
75
76 $type_name = db_fetch_result($result, 0, "type_name");
77
78// print "$pref_name : $type_name : $value<br>";
79
80 if ($type_name == "bool") {
81 if ($value == "1") {
82 $value = "true";
83 } else {
84 $value = "false";
85 }
86 } else if ($type_name == "integer") {
87 $value = sprintf("%d", $value);
88 }
89
90// print "$pref_name : $type_name : $value<br>";
91
92 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
93 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
94
95 }
96
ef8be8ea
AD
97 }
98
f27d955a
AD
99 return prefs_js_redirect();
100
ef8be8ea
AD
101 } else if ($subop == "getHelp") {
102
103 $pref_name = db_escape_string($_GET["pn"]);
104
105 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
106 WHERE pref_name = '$pref_name'");
107
108 if (db_num_rows($result) > 0) {
109 $help_text = db_fetch_result($result, 0, "help_text");
110 print $help_text;
111 } else {
112 print "Unknown option: $pref_name";
113 }
114
42395d28 115 } else if ($subop == "change-email") {
ef8be8ea 116
42395d28 117 $email = db_escape_string($_POST["email"]);
ef8be8ea
AD
118 $active_uid = $_SESSION["uid"];
119
42395d28
AD
120 db_query($link, "UPDATE ttrss_users SET email = '$email'
121 WHERE id = '$active_uid'");
122
123 print "E-mail has been changed.";
124
125 return;
ef8be8ea 126
ef8be8ea
AD
127 } else if ($subop == "Reset to defaults") {
128
ef8be8ea
AD
129 $_SESSION["prefs_op_result"] = "reset-to-defaults";
130
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");
136 } else {
137 db_query($link, "DELETE FROM ttrss_user_prefs
138 WHERE owner_uid = ".$_SESSION["uid"]);
139 initialize_user_prefs($link, $_SESSION["uid"]);
140 }
141
f27d955a 142 return prefs_js_redirect();
ef8be8ea
AD
143
144 } else if ($subop == "Change theme") {
145
146 $theme = db_escape_string($_POST["theme"]);
147
148 if ($theme == "Default") {
149 $theme_qpart = 'NULL';
150 } else {
151 $theme_qpart = "'$theme'";
152 }
153
154 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
155 WHERE theme_name = '$theme'");
156
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");
160 } else {
161 $theme_id = "NULL";
162 $theme_path = "";
163 }
164
165 db_query($link, "UPDATE ttrss_users SET
166 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
167
168 $_SESSION["theme"] = $theme_path;
169
f27d955a 170 return prefs_js_redirect();
ef8be8ea
AD
171
172 } else {
173
2b2044bc 174// print check_for_update($link);
ef8be8ea 175
fe8d2059
AD
176 set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig");
177
ef8be8ea
AD
178 if (!SINGLE_USER_MODE) {
179
d84f9523
AD
180 $result = db_query($link, "SELECT id FROM ttrss_users
181 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
182 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
ef8be8ea
AD
183
184 if (db_num_rows($result) != 0) {
7990ac73
AD
185 print format_warning(__("Your password is at default value,
186 please change it."), "default_pass_warning");
ef8be8ea
AD
187 }
188
d95bd220 189/* if ($_SESSION["pwd_change_result"] == "failed") {
0d32b41e 190 print format_warning("Could not change the password.");
ef8be8ea
AD
191 }
192
193 if ($_SESSION["pwd_change_result"] == "ok") {
0d32b41e 194 print format_notice("Password was changed.");
ef8be8ea
AD
195 }
196
d95bd220 197 $_SESSION["pwd_change_result"] = ""; */
ef8be8ea
AD
198
199 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
7990ac73 200 print format_notice(__("The configuration was reset to defaults."));
ef8be8ea
AD
201 }
202
203 if ($_SESSION["prefs_op_result"] == "save-config") {
7990ac73 204 print format_notice(__("The configuration was saved."));
ef8be8ea
AD
205 }
206
207 $_SESSION["prefs_op_result"] = "";
208
42395d28 209 print "<form onsubmit='return false' id='change_email_form'>";
ef8be8ea
AD
210
211 print "<table width=\"100%\" class=\"prefPrefsList\">";
7990ac73 212 print "<tr><td colspan='3'><h3>".__("Personal data")."</h3></tr></td>";
ef8be8ea
AD
213
214 $result = db_query($link, "SELECT email FROM ttrss_users
215 WHERE id = ".$_SESSION["uid"]);
216
217 $email = db_fetch_result($result, 0, "email");
218
219 print "<tr><td width=\"40%\">E-mail</td>";
220 print "<td><input class=\"editbox\" name=\"email\"
42395d28 221 onkeypress=\"return filterCR(event, changeUserEmail)\"
ef8be8ea
AD
222 value=\"$email\"></td></tr>";
223
224 print "</table>";
225
226 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
42395d28 227 print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">";
ef8be8ea
AD
228
229 print "</form>";
230
42395d28 231 print "<p><input class=\"button\" type=\"submit\"
7990ac73 232 onclick=\"return changeUserEmail()\" value=\"".__("Change e-mail")."\">";
42395d28 233
e6312f6c 234 print "<form onsubmit=\"return false\"
d95bd220 235 name=\"change_pass_form\" id=\"change_pass_form\">";
ef8be8ea
AD
236
237 print "<table width=\"100%\" class=\"prefPrefsList\">";
7990ac73 238 print "<tr><td colspan='3'><h3>".__("Authentication")."</h3></tr></td>";
ef8be8ea 239
7990ac73 240 print "<tr><td width=\"40%\">".__("Old password")."</td>";
ef8be8ea 241 print "<td><input class=\"editbox\" type=\"password\"
d95bd220 242 onkeypress=\"return filterCR(event, changeUserPassword)\"
ef8be8ea
AD
243 name=\"OLD_PASSWORD\"></td></tr>";
244
7990ac73 245 print "<tr><td width=\"40%\">".__("New password")."</td>";
ef8be8ea
AD
246
247 print "<td><input class=\"editbox\" type=\"password\"
d95bd220 248 onkeypress=\"return filterCR(event, changeUserPassword)\"
ef8be8ea 249 name=\"NEW_PASSWORD\"></td></tr>";
d95bd220 250
7990ac73 251 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
d95bd220
AD
252
253 print "<td><input class=\"editbox\" type=\"password\"
254 onkeypress=\"return filterCR(event, changeUserPassword)\"
255 name=\"CONFIRM_PASSWORD\"></td></tr>";
256
ef8be8ea
AD
257 print "</table>";
258
259 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
d95bd220
AD
260 print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">";
261
ef8be8ea
AD
262 print "</form>";
263
d95bd220
AD
264 print "<p><input class=\"button\" type=\"submit\"
265 onclick=\"return changeUserPassword()\"
7990ac73 266 value=\"".__("Change password")."\">";
d95bd220 267
ef8be8ea
AD
268 }
269
270 $result = db_query($link, "SELECT
271 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
272
273 $user_theme_id = db_fetch_result($result, 0, "theme_id");
274
275 $result = db_query($link, "SELECT
276 id,theme_name FROM ttrss_themes ORDER BY theme_name");
277
278 if (db_num_rows($result) > 0) {
279
280 print "<form action=\"backend.php\" method=\"POST\">";
281 print "<table width=\"100%\" class=\"prefPrefsList\">";
7990ac73
AD
282 print "<tr><td colspan='3'><h3>".__("Themes")."</h3></tr></td>";
283 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
ef8be8ea
AD
284 print "<td><select name=\"theme\">";
285 print "<option>Default</option>";
286 print "<option disabled>--------</option>";
287
288 while ($line = db_fetch_assoc($result)) {
289 if ($line["id"] == $user_theme_id) {
290 $selected = "selected";
291 } else {
292 $selected = "";
293 }
294 print "<option $selected>" . $line["theme_name"] . "</option>";
295 }
296 print "</select></td></tr>";
297 print "</table>";
298 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
299 print "<p><input class=\"button\" type=\"submit\"
300 value=\"Change theme\" name=\"subop\">";
301 print "</form>";
302 }
303
304 initialize_user_prefs($link, $_SESSION["uid"]);
305
306 $result = db_query($link, "SELECT
307 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
308 section_name,def_value
309 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
310 WHERE type_id = ttrss_prefs_types.id AND
311 section_id = ttrss_prefs_sections.id AND
312 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
40496720 313 short_desc != '' AND
ef8be8ea
AD
314 owner_uid = ".$_SESSION["uid"]."
315 ORDER BY section_id,short_desc");
316
317 print "<form action=\"backend.php\" method=\"POST\">";
318
319 $lnum = 0;
320
321 $active_section = "";
322
323 while ($line = db_fetch_assoc($result)) {
324
325 if ($active_section != $line["section_name"]) {
326
327 if ($active_section != "") {
328 print "</table>";
329 }
330
331 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
332
333 $active_section = $line["section_name"];
334
335 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
336// print "<tr class=\"title\">
337// <td width=\"25%\">Option</td><td>Value</td></tr>";
338
339 $lnum = 0;
340 }
341
342// $class = ($lnum % 2) ? "even" : "odd";
343
344 print "<tr>";
345
346 $type_name = $line["type_name"];
347 $pref_name = $line["pref_name"];
348 $value = $line["value"];
349 $def_value = $line["def_value"];
350 $help_text = $line["help_text"];
351
352 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
353
354 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
355
356 print "</td>";
357
358 print "<td>";
359
360 if ($type_name == "bool") {
361// print_select($pref_name, $value, array("true", "false"));
362
363 if ($value == "true") {
364 $value = "Yes";
365 } else {
366 $value = "No";
367 }
368
369 print_radio($pref_name, $value, array("Yes", "No"));
370
371 } else {
372 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
373 }
374
375 print "</td>";
376
377 print "</tr>";
378
379 $lnum++;
380 }
381
382 print "</table>";
383
384 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
385
386 print "<p><input class=\"button\" type=\"submit\"
387 name=\"subop\" value=\"Save configuration\">";
388
389 print "&nbsp;<input class=\"button\" type=\"submit\"
390 name=\"subop\" onclick=\"return validatePrefsReset()\"
391 value=\"Reset to defaults\"></p>";
392
393 print "</form>";
394
395 }
396 }
397?>