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