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