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