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