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