]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | function module_pref_prefs($link) { | |
3 | ||
4 | global $access_level_names; | |
5 | ||
6 | $subop = $_REQUEST["subop"]; | |
7 | ||
8 | $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS", | |
9 | "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS", "ENABLE_FEED_ICONS", | |
10 | "ENABLE_OFFLINE_READING", "EXTENDED_FEEDLIST", "FEEDS_SORT_BY_UNREAD", | |
11 | "OPEN_LINKS_IN_NEW_WINDOW", "USER_STYLESHEET_URL", "ENABLE_FLASH_PLAYER"); | |
12 | ||
13 | $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", | |
14 | "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", | |
15 | "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS", | |
16 | "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL", | |
17 | "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE"); | |
18 | ||
19 | if (FORCE_ARTICLE_PURGE != 0) { | |
20 | array_push($prefs_blacklist, "PURGE_OLD_DAYS"); | |
21 | array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES"); | |
22 | } | |
23 | ||
24 | if ($subop == "change-password") { | |
25 | ||
26 | $old_pw = $_POST["old_password"]; | |
27 | $new_pw = $_POST["new_password"]; | |
28 | $con_pw = $_POST["confirm_password"]; | |
29 | ||
30 | if ($old_pw == "") { | |
31 | print "ERROR: ".__("Old password cannot be blank."); | |
32 | return; | |
33 | } | |
34 | ||
35 | if ($new_pw == "") { | |
36 | print "ERROR: ".__("New password cannot be blank."); | |
37 | return; | |
38 | } | |
39 | ||
40 | if ($new_pw != $con_pw) { | |
41 | print "ERROR: ".__("Entered passwords do not match."); | |
42 | return; | |
43 | } | |
44 | ||
45 | $old_pw_hash1 = encrypt_password($old_pw); | |
46 | $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]); | |
47 | $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]); | |
48 | ||
49 | $active_uid = $_SESSION["uid"]; | |
50 | ||
51 | if ($old_pw && $new_pw) { | |
52 | ||
53 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
54 | ||
55 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
56 | id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR | |
57 | pwd_hash = '$old_pw_hash2')"); | |
58 | ||
59 | if (db_num_rows($result) == 1) { | |
60 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
61 | WHERE id = '$active_uid'"); | |
62 | ||
63 | $_SESSION["pwd_hash"] = $new_pw_hash; | |
64 | ||
65 | print __("Password has been changed."); | |
66 | } else { | |
67 | print "ERROR: ".__('Old password is incorrect.'); | |
68 | } | |
69 | } | |
70 | ||
71 | return; | |
72 | ||
73 | } else if ($subop == "save-config") { | |
74 | ||
75 | # $_SESSION["prefs_op_result"] = "save-config"; | |
76 | ||
77 | $_SESSION["prefs_cache"] = false; | |
78 | ||
79 | // print_r($_POST); | |
80 | ||
81 | $orig_theme = get_pref($link, "_THEME_ID"); | |
82 | ||
83 | foreach (array_keys($_POST) as $pref_name) { | |
84 | ||
85 | $pref_name = db_escape_string($pref_name); | |
86 | $value = db_escape_string($_POST[$pref_name]); | |
87 | ||
88 | set_pref($link, $pref_name, $value); | |
89 | ||
90 | } | |
91 | ||
92 | if ($orig_theme != get_pref($link, "_THEME_ID")) { | |
93 | print "PREFS_THEME_CHANGED"; | |
94 | } else { | |
95 | print __("The configuration was saved."); | |
96 | } | |
97 | ||
98 | return; | |
99 | ||
100 | } else if ($subop == "getHelp") { | |
101 | ||
102 | $pref_name = db_escape_string($_REQUEST["pn"]); | |
103 | ||
104 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
105 | WHERE pref_name = '$pref_name'"); | |
106 | ||
107 | if (db_num_rows($result) > 0) { | |
108 | $help_text = db_fetch_result($result, 0, "help_text"); | |
109 | print $help_text; | |
110 | } else { | |
111 | printf(__("Unknown option: %s"), $pref_name); | |
112 | } | |
113 | ||
114 | } else if ($subop == "change-email") { | |
115 | ||
116 | $email = db_escape_string($_POST["email"]); | |
117 | $full_name = db_escape_string($_POST["full_name"]); | |
118 | ||
119 | $active_uid = $_SESSION["uid"]; | |
120 | ||
121 | db_query($link, "UPDATE ttrss_users SET email = '$email', | |
122 | full_name = '$full_name' WHERE id = '$active_uid'"); | |
123 | ||
124 | print __("Your personal data has been saved."); | |
125 | ||
126 | return; | |
127 | ||
128 | } else if ($subop == "reset-config") { | |
129 | ||
130 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; | |
131 | ||
132 | if ($_SESSION["profile"]) { | |
133 | $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; | |
134 | } else { | |
135 | $profile_qpart = "profile IS NULL"; | |
136 | } | |
137 | ||
138 | db_query($link, "DELETE FROM ttrss_user_prefs | |
139 | WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]); | |
140 | ||
141 | initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]); | |
142 | ||
143 | print "PREFS_THEME_CHANGED"; | |
144 | ||
145 | // print __("The configuration was reset to defaults."); | |
146 | ||
147 | return; | |
148 | ||
149 | } else { | |
150 | ||
151 | if (!SINGLE_USER_MODE) { | |
152 | ||
153 | $_SESSION["prefs_op_result"] = ""; | |
154 | ||
155 | print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; | |
156 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">"; | |
157 | ||
158 | print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">"; | |
159 | ||
160 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
161 | evt.preventDefault(); | |
162 | if (this.validate()) { | |
163 | notify_progress('Saving data...', true); | |
164 | ||
165 | new Ajax.Request('backend.php', { | |
166 | parameters: dojo.objectToQuery(this.getValues()), | |
167 | onComplete: function(transport) { | |
168 | notify_callback2(transport); | |
169 | } }); | |
170 | ||
171 | } | |
172 | </script>"; | |
173 | ||
174 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
175 | ||
176 | $result = db_query($link, "SELECT email,full_name, | |
177 | access_level FROM ttrss_users | |
178 | WHERE id = ".$_SESSION["uid"]); | |
179 | ||
180 | $email = htmlspecialchars(db_fetch_result($result, 0, "email")); | |
181 | $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); | |
182 | ||
183 | print "<tr><td width=\"40%\">".__('Full name')."</td>"; | |
184 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\" | |
185 | value=\"$full_name\"></td></tr>"; | |
186 | ||
187 | print "<tr><td width=\"40%\">".__('E-mail')."</td>"; | |
188 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>"; | |
189 | ||
190 | if (!SINGLE_USER_MODE) { | |
191 | $access_level = db_fetch_result($result, 0, "access_level"); | |
192 | print "<tr><td width=\"40%\">".__('Access level')."</td>"; | |
193 | print "<td>" . $access_level_names[$access_level] . "</td></tr>"; | |
194 | } | |
195 | ||
196 | print "</table>"; | |
197 | ||
198 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
199 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-email\">"; | |
200 | ||
201 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
202 | __("Save data")."</button>"; | |
203 | ||
204 | print "</form>"; | |
205 | ||
206 | print "</div>"; # pane | |
207 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">"; | |
208 | ||
209 | $result = db_query($link, "SELECT id FROM ttrss_users | |
210 | WHERE id = ".$_SESSION["uid"]." AND pwd_hash | |
211 | = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); | |
212 | ||
213 | if (db_num_rows($result) != 0) { | |
214 | print format_warning(__("Your password is at default value, please change it."), "default_pass_warning"); | |
215 | } | |
216 | ||
217 | print "<form dojoType=\"dijit.form.Form\">"; | |
218 | ||
219 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
220 | evt.preventDefault(); | |
221 | if (this.validate()) { | |
222 | notify_progress('Changing password...', true); | |
223 | ||
224 | new Ajax.Request('backend.php', { | |
225 | parameters: dojo.objectToQuery(this.getValues()), | |
226 | onComplete: function(transport) { | |
227 | notify(''); | |
228 | if (transport.responseText.indexOf('ERROR: ') == 0) { | |
229 | notify_error(transport.responseText.replace('ERROR: ', '')); | |
230 | } else { | |
231 | notify_info(transport.responseText); | |
232 | var warn = $('default_pass_warning'); | |
233 | if (warn) Element.hide(warn); | |
234 | } | |
235 | }}); | |
236 | this.reset(); | |
237 | } | |
238 | </script>"; | |
239 | ||
240 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
241 | ||
242 | print "<tr><td width=\"40%\">".__("Old password")."</td>"; | |
243 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>"; | |
244 | ||
245 | print "<tr><td width=\"40%\">".__("New password")."</td>"; | |
246 | ||
247 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" | |
248 | name=\"new_password\"></td></tr>"; | |
249 | ||
250 | print "<tr><td width=\"40%\">".__("Confirm password")."</td>"; | |
251 | ||
252 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>"; | |
253 | ||
254 | print "</table>"; | |
255 | ||
256 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
257 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-password\">"; | |
258 | ||
259 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
260 | __("Change password")."</button>"; | |
261 | ||
262 | print "</form>"; | |
263 | ||
264 | print "</div>"; #pane | |
265 | } | |
266 | ||
267 | print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">"; | |
268 | ||
269 | if ($_SESSION["profile"]) { | |
270 | print_notice("Some preferences are only available in default profile."); | |
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 dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">"; | |
294 | ||
295 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
296 | evt.preventDefault(); | |
297 | if (this.validate()) { | |
298 | console.log(dojo.objectToQuery(this.getValues())); | |
299 | ||
300 | new Ajax.Request('backend.php', { | |
301 | parameters: dojo.objectToQuery(this.getValues()), | |
302 | onComplete: function(transport) { | |
303 | var msg = transport.responseText; | |
304 | if (msg.match('PREFS_THEME_CHANGED')) { | |
305 | window.location.reload(); | |
306 | } else { | |
307 | notify_info(msg); | |
308 | } | |
309 | } }); | |
310 | } | |
311 | </script>"; | |
312 | ||
313 | $lnum = 0; | |
314 | ||
315 | $active_section = ""; | |
316 | ||
317 | while ($line = db_fetch_assoc($result)) { | |
318 | ||
319 | if (in_array($line["pref_name"], $prefs_blacklist)) { | |
320 | continue; | |
321 | } | |
322 | ||
323 | if ($_SESSION["profile"] && in_array($line["pref_name"], | |
324 | $profile_blacklist)) { | |
325 | continue; | |
326 | } | |
327 | ||
328 | if ($active_section != $line["section_name"]) { | |
329 | ||
330 | if ($active_section != "") { | |
331 | print "</table>"; | |
332 | } | |
333 | ||
334 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
335 | ||
336 | $active_section = $line["section_name"]; | |
337 | ||
338 | print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>"; | |
339 | ||
340 | if ($line["section_id"] == 2) { | |
341 | print "<tr><td width=\"40%\">".__("Select theme")."</td>"; | |
342 | ||
343 | $user_theme = get_pref($link, "_THEME_ID"); | |
344 | $themes = get_all_themes(); | |
345 | ||
346 | print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">"; | |
347 | print "<option value='Default'>".__('Default')."</option>"; | |
348 | print "<option value='----------------' disabled=\"1\">--------</option>"; | |
349 | ||
350 | foreach ($themes as $t) { | |
351 | $base = $t['base']; | |
352 | $name = $t['name']; | |
353 | ||
354 | if ($base == $user_theme) { | |
355 | $selected = "selected=\"1\""; | |
356 | } else { | |
357 | $selected = ""; | |
358 | } | |
359 | ||
360 | print "<option $selected value='$base'>$name</option>"; | |
361 | ||
362 | } | |
363 | ||
364 | print "</select></td></tr>"; | |
365 | } | |
366 | ||
367 | // print "<tr class=\"title\"> | |
368 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
369 | ||
370 | $lnum = 0; | |
371 | } | |
372 | ||
373 | // $class = ($lnum % 2) ? "even" : "odd"; | |
374 | ||
375 | print "<tr>"; | |
376 | ||
377 | $type_name = $line["type_name"]; | |
378 | $pref_name = $line["pref_name"]; | |
379 | $value = $line["value"]; | |
380 | $def_value = $line["def_value"]; | |
381 | $help_text = $line["help_text"]; | |
382 | ||
383 | print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]); | |
384 | ||
385 | if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>"; | |
386 | ||
387 | print "</td>"; | |
388 | ||
389 | print "<td class=\"prefValue\">"; | |
390 | ||
391 | if ($pref_name == "USER_TIMEZONE") { | |
392 | ||
393 | $timezones = explode("\n", file_get_contents("lib/timezones.txt")); | |
394 | ||
395 | print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); | |
396 | } else if ($pref_name == "USER_STYLESHEET") { | |
397 | ||
398 | print "<button dojoType=\"dijit.form.Button\" | |
399 | onclick=\"customizeCSS()\">" . __('Customize') . "</button>"; | |
400 | ||
401 | } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") { | |
402 | ||
403 | $limits = array(15, 30, 45, 60); | |
404 | ||
405 | print_select($pref_name, $value, $limits, | |
406 | 'dojoType="dijit.form.Select"'); | |
407 | ||
408 | } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { | |
409 | ||
410 | global $update_intervals_nodefault; | |
411 | ||
412 | print_select_hash($pref_name, $value, $update_intervals_nodefault, | |
413 | 'dojoType="dijit.form.Select"'); | |
414 | ||
415 | } else if ($type_name == "bool") { | |
416 | // print_select($pref_name, $value, array("true", "false")); | |
417 | ||
418 | if ($value == "true") { | |
419 | $value = __("Yes"); | |
420 | } else { | |
421 | $value = __("No"); | |
422 | } | |
423 | ||
424 | print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No"))); | |
425 | ||
426 | } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT', | |
427 | 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { | |
428 | ||
429 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
430 | ||
431 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
432 | required=\"1\" $regexp | |
433 | name=\"$pref_name\" value=\"$value\">"; | |
434 | ||
435 | } else { | |
436 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
437 | ||
438 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
439 | $regexp | |
440 | name=\"$pref_name\" value=\"$value\">"; | |
441 | } | |
442 | ||
443 | print "</td>"; | |
444 | ||
445 | print "</tr>"; | |
446 | ||
447 | $lnum++; | |
448 | } | |
449 | ||
450 | print "</table>"; | |
451 | ||
452 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
453 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save-config\">"; | |
454 | ||
455 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
456 | __('Save configuration')."</button> "; | |
457 | ||
458 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">". | |
459 | __('Manage profiles')."</button> "; | |
460 | ||
461 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">". | |
462 | __('Reset to defaults')."</button></p>"; | |
463 | ||
464 | print "</form>"; | |
465 | ||
466 | print "</div>"; #pane | |
467 | print "</div>"; #container | |
468 | ||
469 | } | |
470 | } | |
471 | ?> |