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