]>
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 | ||
b4e75b2a | 123 | $pref_name = db_escape_string($_REQUEST["pn"]); |
ef8be8ea AD |
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 { | |
2a52d96f | 132 | printf(__("Unknown option: %s"), $pref_name); |
ef8be8ea AD |
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 | ||
fe8d2059 AD |
189 | set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig"); |
190 | ||
ef8be8ea AD |
191 | if (!SINGLE_USER_MODE) { |
192 | ||
d84f9523 AD |
193 | $result = db_query($link, "SELECT id FROM ttrss_users |
194 | WHERE id = ".$_SESSION["uid"]." AND pwd_hash | |
195 | = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); | |
ef8be8ea AD |
196 | |
197 | if (db_num_rows($result) != 0) { | |
7990ac73 AD |
198 | print format_warning(__("Your password is at default value, |
199 | please change it."), "default_pass_warning"); | |
ef8be8ea AD |
200 | } |
201 | ||
d95bd220 | 202 | /* if ($_SESSION["pwd_change_result"] == "failed") { |
0d32b41e | 203 | print format_warning("Could not change the password."); |
ef8be8ea AD |
204 | } |
205 | ||
206 | if ($_SESSION["pwd_change_result"] == "ok") { | |
0d32b41e | 207 | print format_notice("Password was changed."); |
ef8be8ea AD |
208 | } |
209 | ||
d95bd220 | 210 | $_SESSION["pwd_change_result"] = ""; */ |
ef8be8ea AD |
211 | |
212 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { | |
7990ac73 | 213 | print format_notice(__("The configuration was reset to defaults.")); |
ef8be8ea AD |
214 | } |
215 | ||
b652c1b7 AD |
216 | # if ($_SESSION["prefs_op_result"] == "save-config") { |
217 | # print format_notice(__("The configuration was saved.")); | |
218 | # } | |
ef8be8ea AD |
219 | |
220 | $_SESSION["prefs_op_result"] = ""; | |
221 | ||
42395d28 | 222 | print "<form onsubmit='return false' id='change_email_form'>"; |
ef8be8ea AD |
223 | |
224 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
7990ac73 | 225 | print "<tr><td colspan='3'><h3>".__("Personal data")."</h3></tr></td>"; |
ef8be8ea | 226 | |
a88d37e5 | 227 | $result = db_query($link, "SELECT email,access_level FROM ttrss_users |
ef8be8ea AD |
228 | WHERE id = ".$_SESSION["uid"]); |
229 | ||
230 | $email = db_fetch_result($result, 0, "email"); | |
231 | ||
e400230e | 232 | print "<tr><td width=\"40%\">".__('E-mail')."</td>"; |
e351c494 | 233 | print "<td class=\"prefValue\"><input class=\"editbox\" name=\"email\" |
6068d33b AD |
234 | onfocus=\"javascript:disableHotkeys();\" |
235 | onblur=\"javascript:enableHotkeys();\" | |
42395d28 | 236 | onkeypress=\"return filterCR(event, changeUserEmail)\" |
ef8be8ea | 237 | value=\"$email\"></td></tr>"; |
a88d37e5 AD |
238 | |
239 | if (!SINGLE_USER_MODE) { | |
240 | ||
241 | $access_level = db_fetch_result($result, 0, "access_level"); | |
242 | ||
243 | print "<tr><td width=\"40%\">".__('Access level')."</td>"; | |
244 | print "<td>" . $access_level_names[$access_level] . "</td></tr>"; | |
245 | ||
246 | } | |
ef8be8ea AD |
247 | |
248 | print "</table>"; | |
249 | ||
250 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
42395d28 | 251 | print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">"; |
ef8be8ea AD |
252 | |
253 | print "</form>"; | |
254 | ||
42395d28 | 255 | print "<p><input class=\"button\" type=\"submit\" |
7990ac73 | 256 | onclick=\"return changeUserEmail()\" value=\"".__("Change e-mail")."\">"; |
42395d28 | 257 | |
e6312f6c | 258 | print "<form onsubmit=\"return false\" |
d95bd220 | 259 | name=\"change_pass_form\" id=\"change_pass_form\">"; |
ef8be8ea AD |
260 | |
261 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
7990ac73 | 262 | print "<tr><td colspan='3'><h3>".__("Authentication")."</h3></tr></td>"; |
ef8be8ea | 263 | |
7990ac73 | 264 | print "<tr><td width=\"40%\">".__("Old password")."</td>"; |
e351c494 | 265 | print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\" |
6068d33b AD |
266 | onfocus=\"javascript:disableHotkeys();\" |
267 | onblur=\"javascript:enableHotkeys();\" | |
d95bd220 | 268 | onkeypress=\"return filterCR(event, changeUserPassword)\" |
ef8be8ea AD |
269 | name=\"OLD_PASSWORD\"></td></tr>"; |
270 | ||
7990ac73 | 271 | print "<tr><td width=\"40%\">".__("New password")."</td>"; |
ef8be8ea | 272 | |
e351c494 | 273 | print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\" |
6068d33b AD |
274 | onfocus=\"javascript:disableHotkeys();\" |
275 | onblur=\"javascript:enableHotkeys();\" | |
d95bd220 | 276 | onkeypress=\"return filterCR(event, changeUserPassword)\" |
ef8be8ea | 277 | name=\"NEW_PASSWORD\"></td></tr>"; |
d95bd220 | 278 | |
7990ac73 | 279 | print "<tr><td width=\"40%\">".__("Confirm password")."</td>"; |
d95bd220 | 280 | |
e351c494 | 281 | print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\" |
6068d33b AD |
282 | onfocus=\"javascript:disableHotkeys();\" |
283 | onblur=\"javascript:enableHotkeys();\" | |
d95bd220 AD |
284 | onkeypress=\"return filterCR(event, changeUserPassword)\" |
285 | name=\"CONFIRM_PASSWORD\"></td></tr>"; | |
286 | ||
ef8be8ea AD |
287 | print "</table>"; |
288 | ||
289 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
d95bd220 AD |
290 | print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">"; |
291 | ||
ef8be8ea AD |
292 | print "</form>"; |
293 | ||
d95bd220 AD |
294 | print "<p><input class=\"button\" type=\"submit\" |
295 | onclick=\"return changeUserPassword()\" | |
7990ac73 | 296 | value=\"".__("Change password")."\">"; |
d95bd220 | 297 | |
ef8be8ea AD |
298 | } |
299 | ||
300 | $result = db_query($link, "SELECT | |
301 | theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]); | |
302 | ||
303 | $user_theme_id = db_fetch_result($result, 0, "theme_id"); | |
304 | ||
305 | $result = db_query($link, "SELECT | |
306 | id,theme_name FROM ttrss_themes ORDER BY theme_name"); | |
307 | ||
308 | if (db_num_rows($result) > 0) { | |
309 | ||
310 | print "<form action=\"backend.php\" method=\"POST\">"; | |
311 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
7990ac73 AD |
312 | print "<tr><td colspan='3'><h3>".__("Themes")."</h3></tr></td>"; |
313 | print "<tr><td width=\"40%\">".__("Select theme")."</td>"; | |
ef8be8ea | 314 | print "<td><select name=\"theme\">"; |
89cb787e | 315 | print "<option value='Default'>".__('Default')."</option>"; |
ef8be8ea AD |
316 | print "<option disabled>--------</option>"; |
317 | ||
318 | while ($line = db_fetch_assoc($result)) { | |
319 | if ($line["id"] == $user_theme_id) { | |
320 | $selected = "selected"; | |
321 | } else { | |
322 | $selected = ""; | |
323 | } | |
324 | print "<option $selected>" . $line["theme_name"] . "</option>"; | |
325 | } | |
326 | print "</select></td></tr>"; | |
327 | print "</table>"; | |
328 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
1a66dd9f | 329 | print "<input type=\"hidden\" name=\"subop\" value=\"change-theme\">"; |
ef8be8ea | 330 | print "<p><input class=\"button\" type=\"submit\" |
89cb787e | 331 | value=\"".__('Change theme')."\">"; |
ef8be8ea AD |
332 | print "</form>"; |
333 | } | |
334 | ||
335 | initialize_user_prefs($link, $_SESSION["uid"]); | |
336 | ||
337 | $result = db_query($link, "SELECT | |
338 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, | |
339 | section_name,def_value | |
340 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs | |
341 | WHERE type_id = ttrss_prefs_types.id AND | |
342 | section_id = ttrss_prefs_sections.id AND | |
343 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND | |
40496720 | 344 | short_desc != '' AND |
ef8be8ea AD |
345 | owner_uid = ".$_SESSION["uid"]." |
346 | ORDER BY section_id,short_desc"); | |
347 | ||
ae661a8c AD |
348 | print "<form onsubmit='return false' action=\"backend.php\" |
349 | method=\"POST\" id=\"pref_prefs_form\">"; | |
ef8be8ea AD |
350 | |
351 | $lnum = 0; | |
352 | ||
353 | $active_section = ""; | |
354 | ||
355 | while ($line = db_fetch_assoc($result)) { | |
356 | ||
4bb2b579 AD |
357 | if (in_array($line["pref_name"], $prefs_blacklist)) { |
358 | continue; | |
359 | } | |
360 | ||
ef8be8ea AD |
361 | if ($active_section != $line["section_name"]) { |
362 | ||
363 | if ($active_section != "") { | |
364 | print "</table>"; | |
365 | } | |
366 | ||
367 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
368 | ||
369 | $active_section = $line["section_name"]; | |
370 | ||
89cb787e | 371 | print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>"; |
ef8be8ea AD |
372 | // print "<tr class=\"title\"> |
373 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
374 | ||
375 | $lnum = 0; | |
376 | } | |
377 | ||
378 | // $class = ($lnum % 2) ? "even" : "odd"; | |
379 | ||
380 | print "<tr>"; | |
381 | ||
382 | $type_name = $line["type_name"]; | |
383 | $pref_name = $line["pref_name"]; | |
384 | $value = $line["value"]; | |
385 | $def_value = $line["def_value"]; | |
386 | $help_text = $line["help_text"]; | |
387 | ||
e351c494 | 388 | print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]); |
ef8be8ea | 389 | |
89cb787e | 390 | if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>"; |
ef8be8ea AD |
391 | |
392 | print "</td>"; | |
393 | ||
e351c494 | 394 | print "<td class=\"prefValue\">"; |
ef8be8ea AD |
395 | |
396 | if ($type_name == "bool") { | |
397 | // print_select($pref_name, $value, array("true", "false")); | |
398 | ||
399 | if ($value == "true") { | |
836537f7 | 400 | $value = __("Yes"); |
ef8be8ea | 401 | } else { |
836537f7 | 402 | $value = __("No"); |
ef8be8ea AD |
403 | } |
404 | ||
f541eb78 | 405 | print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No"))); |
ef8be8ea AD |
406 | |
407 | } else { | |
6068d33b AD |
408 | print "<input class=\"editbox\" |
409 | onfocus=\"javascript:disableHotkeys();\" | |
410 | onblur=\"javascript:enableHotkeys();\" | |
411 | name=\"$pref_name\" value=\"$value\">"; | |
ef8be8ea AD |
412 | } |
413 | ||
414 | print "</td>"; | |
415 | ||
416 | print "</tr>"; | |
417 | ||
418 | $lnum++; | |
419 | } | |
420 | ||
421 | print "</table>"; | |
422 | ||
423 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
424 | ||
425 | print "<p><input class=\"button\" type=\"submit\" | |
b652c1b7 AD |
426 | onclick=\"return validatePrefsSave()\" |
427 | value=\"".__('Save configuration')."\">"; | |
ef8be8ea AD |
428 | |
429 | print " <input class=\"button\" type=\"submit\" | |
b652c1b7 | 430 | onclick=\"return validatePrefsReset()\" |
89cb787e | 431 | value=\"".__('Reset to defaults')."\"></p>"; |
ef8be8ea AD |
432 | |
433 | print "</form>"; | |
434 | ||
435 | } | |
436 | } | |
437 | ?> |