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