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