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