]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
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 | ||
10 | function module_pref_prefs($link) { | |
11 | ||
12 | global $access_level_names; | |
13 | ||
14 | $subop = $_REQUEST["subop"]; | |
15 | ||
16 | $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS"); | |
17 | ||
18 | if (FORCE_ARTICLE_PURGE != 0) { | |
19 | array_push($prefs_blacklist, "PURGE_OLD_DAYS"); | |
20 | array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES"); | |
21 | } | |
22 | ||
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 == "") { | |
30 | print "ERROR: ".__("Old password cannot be blank."); | |
31 | return; | |
32 | } | |
33 | ||
34 | if ($new_pw == "") { | |
35 | print "ERROR: ".__("New password cannot be blank."); | |
36 | return; | |
37 | } | |
38 | ||
39 | if ($new_pw != $con_pw) { | |
40 | print "ERROR: ".__("Entered passwords do not match."); | |
41 | return; | |
42 | } | |
43 | ||
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"]); | |
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 | |
58 | id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR | |
59 | pwd_hash = '$old_pw_hash2')"); | |
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 | ||
65 | print __("Password has been changed."); | |
66 | } else { | |
67 | print "ERROR: ".__('Old password is incorrect.'); | |
68 | } | |
69 | } | |
70 | ||
71 | return; | |
72 | ||
73 | } else if ($subop == "save-config") { | |
74 | ||
75 | # $_SESSION["prefs_op_result"] = "save-config"; | |
76 | ||
77 | $_SESSION["prefs_cache"] = false; | |
78 | ||
79 | // print_r($_POST); | |
80 | ||
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 | ||
113 | } | |
114 | ||
115 | #return prefs_js_redirect(); | |
116 | ||
117 | print __("The configuration was saved."); | |
118 | ||
119 | return; | |
120 | ||
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 | ||
135 | } else if ($subop == "change-email") { | |
136 | ||
137 | $email = db_escape_string($_POST["email"]); | |
138 | $active_uid = $_SESSION["uid"]; | |
139 | ||
140 | db_query($link, "UPDATE ttrss_users SET email = '$email' | |
141 | WHERE id = '$active_uid'"); | |
142 | ||
143 | print __("E-mail has been changed."); | |
144 | ||
145 | return; | |
146 | ||
147 | } else if ($subop == "reset-config") { | |
148 | ||
149 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; | |
150 | ||
151 | db_query($link, "DELETE FROM ttrss_user_prefs | |
152 | WHERE owner_uid = ".$_SESSION["uid"]); | |
153 | initialize_user_prefs($link, $_SESSION["uid"]); | |
154 | ||
155 | print __("The configuration was reset to defaults."); | |
156 | ||
157 | return; | |
158 | ||
159 | } else if ($subop == "change-theme") { | |
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 | ||
185 | return prefs_js_redirect(); | |
186 | ||
187 | } else { | |
188 | ||
189 | // print check_for_update($link); | |
190 | ||
191 | set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig"); | |
192 | ||
193 | if (!SINGLE_USER_MODE) { | |
194 | ||
195 | $result = db_query($link, "SELECT id FROM ttrss_users | |
196 | WHERE id = ".$_SESSION["uid"]." AND pwd_hash | |
197 | = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); | |
198 | ||
199 | if (db_num_rows($result) != 0) { | |
200 | print format_warning(__("Your password is at default value, | |
201 | please change it."), "default_pass_warning"); | |
202 | } | |
203 | ||
204 | /* if ($_SESSION["pwd_change_result"] == "failed") { | |
205 | print format_warning("Could not change the password."); | |
206 | } | |
207 | ||
208 | if ($_SESSION["pwd_change_result"] == "ok") { | |
209 | print format_notice("Password was changed."); | |
210 | } | |
211 | ||
212 | $_SESSION["pwd_change_result"] = ""; */ | |
213 | ||
214 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { | |
215 | print format_notice(__("The configuration was reset to defaults.")); | |
216 | } | |
217 | ||
218 | # if ($_SESSION["prefs_op_result"] == "save-config") { | |
219 | # print format_notice(__("The configuration was saved.")); | |
220 | # } | |
221 | ||
222 | $_SESSION["prefs_op_result"] = ""; | |
223 | ||
224 | print "<form onsubmit='return false' id='change_email_form'>"; | |
225 | ||
226 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
227 | print "<tr><td colspan='3'><h3>".__("Personal data")."</h3></tr></td>"; | |
228 | ||
229 | $result = db_query($link, "SELECT email,access_level FROM ttrss_users | |
230 | WHERE id = ".$_SESSION["uid"]); | |
231 | ||
232 | $email = db_fetch_result($result, 0, "email"); | |
233 | ||
234 | print "<tr><td width=\"40%\">".__('E-mail')."</td>"; | |
235 | print "<td class=\"prefValue\"><input class=\"editbox\" name=\"email\" | |
236 | onfocus=\"javascript:disableHotkeys();\" | |
237 | onblur=\"javascript:enableHotkeys();\" | |
238 | onkeypress=\"return filterCR(event, changeUserEmail)\" | |
239 | value=\"$email\"></td></tr>"; | |
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 | } | |
249 | ||
250 | print "</table>"; | |
251 | ||
252 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
253 | print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">"; | |
254 | ||
255 | print "</form>"; | |
256 | ||
257 | print "<p><input class=\"button\" type=\"submit\" | |
258 | onclick=\"return changeUserEmail()\" value=\"".__("Change e-mail")."\">"; | |
259 | ||
260 | print "<form onsubmit=\"return false\" | |
261 | name=\"change_pass_form\" id=\"change_pass_form\">"; | |
262 | ||
263 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
264 | print "<tr><td colspan='3'><h3>".__("Authentication")."</h3></tr></td>"; | |
265 | ||
266 | print "<tr><td width=\"40%\">".__("Old password")."</td>"; | |
267 | print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\" | |
268 | onfocus=\"javascript:disableHotkeys();\" | |
269 | onblur=\"javascript:enableHotkeys();\" | |
270 | onkeypress=\"return filterCR(event, changeUserPassword)\" | |
271 | name=\"OLD_PASSWORD\"></td></tr>"; | |
272 | ||
273 | print "<tr><td width=\"40%\">".__("New password")."</td>"; | |
274 | ||
275 | print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\" | |
276 | onfocus=\"javascript:disableHotkeys();\" | |
277 | onblur=\"javascript:enableHotkeys();\" | |
278 | onkeypress=\"return filterCR(event, changeUserPassword)\" | |
279 | name=\"NEW_PASSWORD\"></td></tr>"; | |
280 | ||
281 | print "<tr><td width=\"40%\">".__("Confirm password")."</td>"; | |
282 | ||
283 | print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\" | |
284 | onfocus=\"javascript:disableHotkeys();\" | |
285 | onblur=\"javascript:enableHotkeys();\" | |
286 | onkeypress=\"return filterCR(event, changeUserPassword)\" | |
287 | name=\"CONFIRM_PASSWORD\"></td></tr>"; | |
288 | ||
289 | print "</table>"; | |
290 | ||
291 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
292 | print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">"; | |
293 | ||
294 | print "</form>"; | |
295 | ||
296 | print "<p><input class=\"button\" type=\"submit\" | |
297 | onclick=\"return changeUserPassword()\" | |
298 | value=\"".__("Change password")."\">"; | |
299 | ||
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\">"; | |
314 | print "<tr><td colspan='3'><h3>".__("Themes")."</h3></tr></td>"; | |
315 | print "<tr><td width=\"40%\">".__("Select theme")."</td>"; | |
316 | print "<td><select name=\"theme\">"; | |
317 | print "<option value='Default'>".__('Default')."</option>"; | |
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\">"; | |
331 | print "<input type=\"hidden\" name=\"subop\" value=\"change-theme\">"; | |
332 | print "<p><input class=\"button\" type=\"submit\" | |
333 | value=\"".__('Change theme')."\">"; | |
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 | |
346 | short_desc != '' AND | |
347 | owner_uid = ".$_SESSION["uid"]." | |
348 | ORDER BY section_id,short_desc"); | |
349 | ||
350 | print "<form onsubmit='return false' action=\"backend.php\" | |
351 | method=\"POST\" id=\"pref_prefs_form\">"; | |
352 | ||
353 | $lnum = 0; | |
354 | ||
355 | $active_section = ""; | |
356 | ||
357 | while ($line = db_fetch_assoc($result)) { | |
358 | ||
359 | if (in_array($line["pref_name"], $prefs_blacklist)) { | |
360 | continue; | |
361 | } | |
362 | ||
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 | ||
373 | print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>"; | |
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 | ||
390 | print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]); | |
391 | ||
392 | if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>"; | |
393 | ||
394 | print "</td>"; | |
395 | ||
396 | print "<td class=\"prefValue\">"; | |
397 | ||
398 | if ($type_name == "bool") { | |
399 | // print_select($pref_name, $value, array("true", "false")); | |
400 | ||
401 | if ($value == "true") { | |
402 | $value = __("Yes"); | |
403 | } else { | |
404 | $value = __("No"); | |
405 | } | |
406 | ||
407 | print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No"))); | |
408 | ||
409 | } else { | |
410 | print "<input class=\"editbox\" | |
411 | onfocus=\"javascript:disableHotkeys();\" | |
412 | onblur=\"javascript:enableHotkeys();\" | |
413 | name=\"$pref_name\" value=\"$value\">"; | |
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\" | |
428 | onclick=\"return validatePrefsSave()\" | |
429 | value=\"".__('Save configuration')."\">"; | |
430 | ||
431 | print " <input class=\"button\" type=\"submit\" | |
432 | onclick=\"return validatePrefsReset()\" | |
433 | value=\"".__('Reset to defaults')."\"></p>"; | |
434 | ||
435 | print "</form>"; | |
436 | ||
437 | } | |
438 | } | |
439 | ?> |