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