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