]> git.wh0rd.org - tt-rss.git/blame - classes/pref/prefs.php
require version information in all additional themes
[tt-rss.git] / classes / pref / prefs.php
CommitLineData
1395083e 1<?php
dfad9d7a 2
369dbc19 3class Pref_Prefs extends Handler_Protected {
1395083e 4
dfad9d7a
AD
5 private $pref_help = array();
6 private $pref_sections = array();
7
8484ce22 8 function csrf_ignore($method) {
9d76e754 9 $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles");
8484ce22
AD
10
11 return array_search($method, $csrf_ignored) !== false;
12 }
13
48ed517e
AD
14 function __construct($args) {
15 parent::__construct($args);
dfad9d7a
AD
16
17 $this->pref_sections = array(
18 1 => __('General'),
19 2 => __('Interface'),
20 3 => __('Advanced'),
21 4 => __('Digest')
22 );
23
24 $this->pref_help = array(
9db8e607 25 "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""),
5f462963 26 "AUTO_ASSIGN_LABELS" => array(__("Assign articles to labels automatically"), ""),
9db8e607
AD
27 "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("When auto-detecting tags in articles these tags will not be applied (comma-separated list).")),
28 "CDM_AUTO_CATCHUP" => array(__("Automatically mark articles as read"), __("This option enables marking articles as read automatically while you scroll article list.")),
5f462963 29 "CDM_EXPANDED" => array(__("Automatically expand articles in combined mode"), ""),
dfad9d7a 30 "COMBINED_DISPLAY_MODE" => array(__("Combined feed display"), __("Display expanded list of feed articles, instead of separate displays for headlines and article content")),
5f462963
AD
31 "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feed as read"), ""),
32 "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once"), ""),
723bcdb2 33 "DEFAULT_UPDATE_INTERVAL" => array(__("Default feed update interval"), __("Shortest interval at which a feed will be checked for updates regardless of update method")),
5f462963 34 "DIGEST_CATCHUP" => array(__("Mark articles in e-mail digest as read"), ""),
9db8e607 35 "DIGEST_ENABLE" => array(__("Enable e-mail digest"), __("This option enables sending daily digest of new (and unread) headlines on your configured e-mail address")),
dfad9d7a 36 "DIGEST_PREFERRED_TIME" => array(__("Try to send digests around specified time"), __("Uses UTC timezone")),
9db8e607 37 "ENABLE_API_ACCESS" => array(__("Enable API access"), __("Allows external clients to access this account through the API")),
5f462963
AD
38 "ENABLE_FEED_CATS" => array(__("Enable feed categories"), ""),
39 "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""),
40 "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles (in hours)"), ""),
41 "HIDE_READ_FEEDS" => array(__("Hide feeds with no unread articles"), ""),
9db8e607 42 "HIDE_READ_SHOWS_SPECIAL" => array(__("Show special feeds when hiding read feeds"), ""),
8429af52 43 "LONG_DATE_FORMAT" => array(__("Long date format"), __("The syntax used is identical to the PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")),
dfad9d7a 44 "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("On catchup show next feed"), __("Automatically open next feed with unread articles after marking one as read")),
5f462963
AD
45 "PURGE_OLD_DAYS" => array(__("Purge articles after this number of days (0 - disables)"), ""),
46 "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles"), ""),
47 "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)"), ""),
48 "SHORT_DATE_FORMAT" => array(__("Short date format"), ""),
49 "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines list"), ""),
dfad9d7a
AD
50 "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")),
51 "SSL_CERT_SERIAL" => array(__("Login with an SSL certificate"), __("Click to register your SSL client certificate with tt-rss")),
5f462963 52 "STRIP_IMAGES" => array(__("Do not embed images in articles"), ""),
dfad9d7a 53 "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")),
dfad9d7a 54 "USER_STYLESHEET" => array(__("Customize stylesheet"), __("Customize CSS stylesheet to your liking")),
bd02d29e 55 "USER_TIMEZONE" => array(__("Time zone"), ""),
8ef9645d 56 "VFEED_GROUP_BY_FEED" => array(__("Group headlines in virtual feeds"), __("Special feeds, labels, and categories are grouped by originating feeds")),
7b149552 57 "USER_LANGUAGE" => array(__("Language")),
bd02d29e 58 "USER_CSS_THEME" => array(__("Theme"), __("Select one of the available CSS themes"))
dfad9d7a
AD
59 );
60 }
61
1395083e
AD
62 function changepassword() {
63
64 $old_pw = $_POST["old_password"];
65 $new_pw = $_POST["new_password"];
66 $con_pw = $_POST["confirm_password"];
67
68 if ($old_pw == "") {
69 print "ERROR: ".__("Old password cannot be blank.");
70 return;
71 }
72
73 if ($new_pw == "") {
74 print "ERROR: ".__("New password cannot be blank.");
75 return;
76 }
77
78 if ($new_pw != $con_pw) {
79 print "ERROR: ".__("Entered passwords do not match.");
80 return;
81 }
82
1ffe3391 83 $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
1395083e 84
d5fd183d
AD
85 if (method_exists($authenticator, "change_password")) {
86 print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
098df83b 87 } else {
d5fd183d 88 print "ERROR: ".__("Function not supported by authentication module.");
098df83b 89 }
1395083e
AD
90 }
91
92 function saveconfig() {
451ff722
AD
93 $boolean_prefs = explode(",", $_POST["boolean_prefs"]);
94
95 foreach ($boolean_prefs as $pref) {
96 if (!isset($_POST[$pref])) $_POST[$pref] = 'false';
97 }
98
29c8fa08
AD
99 $need_reload = false;
100
1395083e
AD
101 foreach (array_keys($_POST) as $pref_name) {
102
d9c85e0f
AD
103 $pref_name = $this->dbh->escape_string($pref_name);
104 $value = $this->dbh->escape_string($_POST[$pref_name]);
1395083e 105
1b9b19af 106 if ($pref_name == 'DIGEST_PREFERRED_TIME') {
a42c55f0 107 if (get_pref('DIGEST_PREFERRED_TIME') != $value) {
1b9b19af 108
d9c85e0f 109 $this->dbh->query("UPDATE ttrss_users SET
1b9b19af
AD
110 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
111
112 }
113 }
114
7b149552 115 if ($pref_name == "USER_LANGUAGE") {
29c8fa08 116 if ($_SESSION["language"] != $value) {
29c8fa08
AD
117 $need_reload = true;
118 }
29c8fa08 119 }
1395083e 120
7b149552 121 set_pref($pref_name, $value);
1395083e
AD
122 }
123
29c8fa08
AD
124 if ($need_reload) {
125 print "PREFS_NEED_RELOAD";
126 } else {
127 print __("The configuration was saved.");
128 }
1395083e
AD
129 }
130
131 function getHelp() {
132
d9c85e0f 133 $pref_name = $this->dbh->escape_string($_REQUEST["pn"]);
1395083e 134
d9c85e0f 135 $result = $this->dbh->query("SELECT help_text FROM ttrss_prefs
1395083e
AD
136 WHERE pref_name = '$pref_name'");
137
d9c85e0f
AD
138 if ($this->dbh->num_rows($result) > 0) {
139 $help_text = $this->dbh->fetch_result($result, 0, "help_text");
1395083e
AD
140 print $help_text;
141 } else {
142 printf(__("Unknown option: %s"), $pref_name);
143 }
144 }
145
146 function changeemail() {
147
d9c85e0f
AD
148 $email = $this->dbh->escape_string($_POST["email"]);
149 $full_name = $this->dbh->escape_string($_POST["full_name"]);
1395083e
AD
150
151 $active_uid = $_SESSION["uid"];
152
d9c85e0f 153 $this->dbh->query("UPDATE ttrss_users SET email = '$email',
1395083e
AD
154 full_name = '$full_name' WHERE id = '$active_uid'");
155
156 print __("Your personal data has been saved.");
157
158 return;
159 }
160
161 function resetconfig() {
162
163 $_SESSION["prefs_op_result"] = "reset-to-defaults";
164
165 if ($_SESSION["profile"]) {
166 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
167 } else {
168 $profile_qpart = "profile IS NULL";
169 }
170
d9c85e0f 171 $this->dbh->query("DELETE FROM ttrss_user_prefs
1395083e
AD
172 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
173
a42c55f0 174 initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
bf878338
AD
175
176 echo __("Your preferences are now set to default values.");
1395083e
AD
177 }
178
179 function index() {
180
181 global $access_level_names;
182
8aa01d79 183 $prefs_blacklist = array("STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES",
78744d48
AD
184 "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT",
185 "FEEDS_SORT_BY_UNREAD");
33b3db33
AD
186
187 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
1395083e
AD
188
189 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
190 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
191 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
192 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
6d9455e9 193 "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
1395083e
AD
194
195
d4c64ecc 196 $_SESSION["prefs_op_result"] = "";
1395083e 197
d4c64ecc
AD
198 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
199 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
1395083e 200
d4c64ecc 201 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
1395083e 202
d4c64ecc
AD
203 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
204 evt.preventDefault();
205 if (this.validate()) {
206 notify_progress('Saving data...', true);
1395083e 207
d4c64ecc
AD
208 new Ajax.Request('backend.php', {
209 parameters: dojo.objectToQuery(this.getValues()),
210 onComplete: function(transport) {
211 notify_callback2(transport);
212 } });
1395083e 213
d4c64ecc
AD
214 }
215 </script>";
1395083e 216
d4c64ecc 217 print "<table width=\"100%\" class=\"prefPrefsList\">";
1395083e 218
fb70f26e
AD
219 print "<h2>" . __("Personal data") . "</h2>";
220
d9c85e0f 221 $result = $this->dbh->query("SELECT email,full_name,otp_enabled,
d4c64ecc
AD
222 access_level FROM ttrss_users
223 WHERE id = ".$_SESSION["uid"]);
1395083e 224
d9c85e0f
AD
225 $email = htmlspecialchars($this->dbh->fetch_result($result, 0, "email"));
226 $full_name = htmlspecialchars($this->dbh->fetch_result($result, 0, "full_name"));
227 $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled"));
1395083e 228
d4c64ecc
AD
229 print "<tr><td width=\"40%\">".__('Full name')."</td>";
230 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
231 value=\"$full_name\"></td></tr>";
1395083e 232
d4c64ecc
AD
233 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
234 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
1395083e 235
0d421af8 236 if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
949b1a94 237
d9c85e0f 238 $access_level = $this->dbh->fetch_result($result, 0, "access_level");
d4c64ecc
AD
239 print "<tr><td width=\"40%\">".__('Access level')."</td>";
240 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
241 }
1395083e 242
d4c64ecc 243 print "</table>";
1395083e 244
d4c64ecc
AD
245 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
246 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
1395083e 247
d4c64ecc
AD
248 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
249 __("Save data")."</button>";
1395083e 250
d4c64ecc 251 print "</form>";
1395083e 252
0f28f81f 253 if ($_SESSION["auth_module"]) {
1ffe3391 254 $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
d5fd183d
AD
255 } else {
256 $authenticator = false;
257 }
258
259 if ($authenticator && method_exists($authenticator, "change_password")) {
1395083e 260
fb70f26e
AD
261 print "<h2>" . __("Password") . "</h2>";
262
d9c85e0f 263 $result = $this->dbh->query("SELECT id FROM ttrss_users
1395083e
AD
264 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
265 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
266
d9c85e0f 267 if ($this->dbh->num_rows($result) != 0) {
1395083e
AD
268 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
269 }
270
271 print "<form dojoType=\"dijit.form.Form\">";
272
273 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
274 evt.preventDefault();
275 if (this.validate()) {
276 notify_progress('Changing password...', true);
277
278 new Ajax.Request('backend.php', {
279 parameters: dojo.objectToQuery(this.getValues()),
280 onComplete: function(transport) {
281 notify('');
282 if (transport.responseText.indexOf('ERROR: ') == 0) {
283 notify_error(transport.responseText.replace('ERROR: ', ''));
284 } else {
285 notify_info(transport.responseText);
286 var warn = $('default_pass_warning');
287 if (warn) Element.hide(warn);
288 }
289 }});
290 this.reset();
291 }
292 </script>";
293
3ca8af7f 294 if ($otp_enabled) {
9a73994c 295 print_notice(__("Changing your current password will disable OTP."));
3ca8af7f
AD
296 }
297
1395083e
AD
298 print "<table width=\"100%\" class=\"prefPrefsList\">";
299
300 print "<tr><td width=\"40%\">".__("Old password")."</td>";
301 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
302
303 print "<tr><td width=\"40%\">".__("New password")."</td>";
304
305 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
306 name=\"new_password\"></td></tr>";
307
308 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
309
310 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
311
312 print "</table>";
313
314 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
315 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
316
317 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
318 __("Change password")."</button>";
319
320 print "</form>";
321
0f28f81f 322 if ($_SESSION["auth_module"] == "auth_internal") {
fb70f26e
AD
323
324 print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
325
326 if ($otp_enabled) {
327
9a73994c 328 print_notice(__("One time passwords are currently enabled. Enter your current password below to disable."));
3ca8af7f
AD
329
330 print "<form dojoType=\"dijit.form.Form\">";
331
332 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
333 evt.preventDefault();
334 if (this.validate()) {
335 notify_progress('Disabling OTP', true);
336
337 new Ajax.Request('backend.php', {
338 parameters: dojo.objectToQuery(this.getValues()),
339 onComplete: function(transport) {
340 notify('');
341 if (transport.responseText.indexOf('ERROR: ') == 0) {
342 notify_error(transport.responseText.replace('ERROR: ', ''));
343 } else {
344 window.location.reload();
345 }
346 }});
347 this.reset();
348 }
349 </script>";
350
351 print "<table width=\"100%\" class=\"prefPrefsList\">";
352
353 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
354
355 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
356 name=\"password\"></td></tr>";
357
358 print "</table>";
359
360 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
361 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">";
362
363 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
364 __("Disable OTP")."</button>";
365
366 print "</form>";
fb70f26e 367
a845a3d5 368 } else if (function_exists("imagecreatefromstring")) {
fb70f26e 369
11334fdf 370 print_warning(__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."));
fb70f26e
AD
371
372 print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
373
374 $csrf_token = $_SESSION["csrf_token"];
375
376 print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
377
378 print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
379
380 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
3ca8af7f 381 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">";
fb70f26e
AD
382
383 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
384 evt.preventDefault();
385 if (this.validate()) {
386 notify_progress('Saving data...', true);
387
388 new Ajax.Request('backend.php', {
389 parameters: dojo.objectToQuery(this.getValues()),
390 onComplete: function(transport) {
3ca8af7f 391 notify('');
9deca86d
AD
392 if (transport.responseText.indexOf('ERROR:') == 0) {
393 notify_error(transport.responseText.replace('ERROR:', ''));
3ca8af7f
AD
394 } else {
395 window.location.reload();
396 }
fb70f26e
AD
397 } });
398
399 }
400 </script>";
401
3ca8af7f
AD
402 print "<table width=\"100%\" class=\"prefPrefsList\">";
403
404 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
405
406 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
407 name=\"password\"></td></tr>";
408
9deca86d
AD
409 print "<tr><td width=\"40%\">".__("Enter the generated one time password")."</td>";
410
411 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" autocomplete=\"off\"
412 required=\"1\"
413 name=\"otp\"></td></tr>";
3ca8af7f 414
9deca86d 415 print "<tr><td colspan=\"2\">";
fb70f26e 416
3ca8af7f
AD
417 print "</td></tr><tr><td colspan=\"2\">";
418
419 print "</td></tr>";
420 print "</table>";
421
fb70f26e 422 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
3ca8af7f 423 __("Enable OTP")."</button>";
fb70f26e
AD
424
425 print "</form>";
426
a845a3d5
AD
427 } else {
428
429 print_notice(__("PHP GD functions are required for OTP support."));
430
fb70f26e
AD
431 }
432
433 }
1395083e
AD
434 }
435
1ffe3391 436 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
699daf58
AD
437 "hook_prefs_tab_section", "prefPrefsAuth");
438
d4c64ecc
AD
439 print "</div>"; #pane
440
1395083e
AD
441 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
442
443 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
444
122e9d78
AD
445 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt, quit\">
446 if (evt) evt.preventDefault();
1395083e
AD
447 if (this.validate()) {
448 console.log(dojo.objectToQuery(this.getValues()));
449
450 new Ajax.Request('backend.php', {
451 parameters: dojo.objectToQuery(this.getValues()),
452 onComplete: function(transport) {
453 var msg = transport.responseText;
29c8fa08
AD
454 if (quit) {
455 gotoMain();
456 } else {
457 if (msg == 'PREFS_NEED_RELOAD') {
458 window.location.reload();
459 } else {
460 notify_info(msg);
461 }
462 }
1395083e
AD
463 } });
464 }
465 </script>";
466
467 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
468
469 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
470
471 if ($_SESSION["profile"]) {
9a73994c 472 print_notice(__("Some preferences are only available in default profile."));
1395083e
AD
473 }
474
475 if ($_SESSION["profile"]) {
a42c55f0 476 initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
1395083e
AD
477 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
478 } else {
a42c55f0 479 initialize_user_prefs($_SESSION["uid"]);
1395083e
AD
480 $profile_qpart = "profile IS NULL";
481 }
482
744a1b00 483 /* if ($_SESSION["prefs_show_advanced"])
f9ebb32c
AD
484 $access_query = "true";
485 else
744a1b00
AD
486 $access_query = "(access_level = 0 AND section_id != 3)"; */
487
488 $access_query = 'true';
f9ebb32c 489
d9c85e0f 490 $result = $this->dbh->query("SELECT DISTINCT
dfad9d7a 491 ttrss_user_prefs.pref_name,value,type_name,
f9ebb32c 492 ttrss_prefs_sections.order_id,
dfad9d7a 493 def_value,section_id
1395083e
AD
494 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
495 WHERE type_id = ttrss_prefs_types.id AND
496 $profile_qpart AND
497 section_id = ttrss_prefs_sections.id AND
498 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
f9ebb32c 499 $access_query AND
1395083e 500 owner_uid = ".$_SESSION["uid"]."
dfad9d7a 501 ORDER BY ttrss_prefs_sections.order_id,pref_name");
1395083e
AD
502
503 $lnum = 0;
504
505 $active_section = "";
506
451ff722
AD
507 $listed_boolean_prefs = array();
508
d9c85e0f 509 while ($line = $this->dbh->fetch_assoc($result)) {
1395083e
AD
510
511 if (in_array($line["pref_name"], $prefs_blacklist)) {
512 continue;
513 }
514
dfad9d7a
AD
515 $type_name = $line["type_name"];
516 $pref_name = $line["pref_name"];
517 $section_name = $this->getSectionName($line["section_id"]);
518 $value = $line["value"];
519
520 $short_desc = $this->getShortDesc($pref_name);
521 $help_text = $this->getHelpText($pref_name);
522
523 if (!$short_desc) continue;
524
1395083e
AD
525 if ($_SESSION["profile"] && in_array($line["pref_name"],
526 $profile_blacklist)) {
527 continue;
528 }
529
dfad9d7a 530 if ($active_section != $line["section_id"]) {
1395083e
AD
531
532 if ($active_section != "") {
533 print "</table>";
534 }
535
536 print "<table width=\"100%\" class=\"prefPrefsList\">";
537
dfad9d7a 538 $active_section = $line["section_id"];
1395083e 539
dfad9d7a 540 print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>";
1395083e 541
1395083e
AD
542 $lnum = 0;
543 }
544
545 print "<tr>";
546
451ff722
AD
547 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">";
548 print "<label for='CB_$pref_name'>";
dfad9d7a 549 print $short_desc;
451ff722 550 print "</label>";
1395083e
AD
551
552 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
553
554 print "</td>";
555
556 print "<td class=\"prefValue\">";
557
7b149552
AD
558 if ($pref_name == "USER_LANGUAGE") {
559 print_select_hash($pref_name, $value, get_translations(),
560 "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
561
562 } else if ($pref_name == "USER_TIMEZONE") {
1395083e
AD
563
564 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
565
566 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
567 } else if ($pref_name == "USER_STYLESHEET") {
568
569 print "<button dojoType=\"dijit.form.Button\"
570 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
571
5d40efc9
AD
572 } else if ($pref_name == "USER_CSS_THEME") {
573
f6cbe9a5
AD
574 $themes = array_filter(array_map("basename", glob("themes/*.css")),
575 "theme_valid");
5d40efc9
AD
576
577 print_select($pref_name, $value, $themes,
578 'dojoType="dijit.form.Select"');
579
580
1395083e
AD
581 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
582
583 global $update_intervals_nodefault;
584
585 print_select_hash($pref_name, $value, $update_intervals_nodefault,
586 'dojoType="dijit.form.Select"');
587
588 } else if ($type_name == "bool") {
589
451ff722
AD
590 array_push($listed_boolean_prefs, $pref_name);
591
592 $checked = ($value == "true") ? "checked=\"checked\"" : "";
1395083e
AD
593
594 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
595 $disabled = "disabled=\"1\"";
451ff722 596 $checked = "checked=\"checked\"";
1395083e
AD
597 } else {
598 $disabled = "";
599 }
600
451ff722
AD
601 print "<input type='checkbox' name='$pref_name' $checked $disabled
602 dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
1395083e 603
f17cac6b 604 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE',
1395083e
AD
605 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
606
607 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
608
609 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
610 $disabled = "disabled=\"1\"";
611 $value = FORCE_ARTICLE_PURGE;
612 } else {
613 $disabled = "";
614 }
615
616 print "<input dojoType=\"dijit.form.ValidationTextBox\"
617 required=\"1\" $regexp $disabled
618 name=\"$pref_name\" value=\"$value\">";
619
620 } else if ($pref_name == "SSL_CERT_SERIAL") {
621
622 print "<input dojoType=\"dijit.form.ValidationTextBox\"
623 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
624 name=\"$pref_name\" value=\"$value\">";
625
626 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
627 $has_serial = ($cert_serial) ? "false" : "true";
628
629 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
630 onclick=\"insertSSLserial('$cert_serial')\">" .
631 __('Register') . "</button>";
632
633 print " <button dojoType=\"dijit.form.Button\"
634 onclick=\"insertSSLserial('')\">" .
635 __('Clear') . "</button>";
636
76c843a9 637 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
61c1812f 638 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1b92f543 639 id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
61c1812f 640 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
8eba830f 641 T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
1395083e
AD
642 } else {
643 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
644
645 print "<input dojoType=\"dijit.form.ValidationTextBox\"
646 $regexp
647 name=\"$pref_name\" value=\"$value\">";
648 }
649
650 print "</td>";
651
652 print "</tr>";
653
654 $lnum++;
655 }
656
657 print "</table>";
658
451ff722
AD
659 $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
660
661 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">";
662
1ffe3391 663 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
699daf58
AD
664 "hook_prefs_tab_section", "prefPrefsPrefsInside");
665
1395083e
AD
666 print '</div>'; # inside pane
667 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
668
669 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
670 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
671
122e9d78
AD
672 print "<div dojoType=\"dijit.form.ComboButton\" type=\"submit\">
673 <span>".__('Save configuration')."</span>
674 <div dojoType=\"dijit.DropDownMenu\">
675 <div dojoType=\"dijit.MenuItem\"
676 onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">".
677 __("Save and exit preferences")."</div>
678 </div>
679 </div>";
1395083e
AD
680
681 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
682 __('Manage profiles')."</button> ";
683
684 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
685 __('Reset to defaults')."</button>";
686
f9ebb32c
AD
687 print "&nbsp;";
688
744a1b00 689 /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
f9ebb32c
AD
690
691 print "<input onclick='toggleAdvancedPrefs()'
692 id='prefs_show_advanced'
693 dojoType=\"dijit.form.CheckBox\"
694 $checked
695 type=\"checkbox\"></input>
696 <label for='prefs_show_advanced'>" .
744a1b00 697 __("Show additional preferences") . "</label>"; */
f9ebb32c 698
1ffe3391 699 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
699daf58
AD
700 "hook_prefs_tab_section", "prefPrefsPrefsOutside");
701
de612e7a 702 print "</form>";
1395083e
AD
703 print '</div>'; # inner pane
704 print '</div>'; # border container
de612e7a
AD
705
706 print "</div>"; #pane
707
708 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
709
6deafe90 710 print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
65f85248 711
6deafe90 712 print_notice(__("Download more plugins at tt-rss.org <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/forum/viewforum.php?f=22\">forums</a> or <a target=\"_blank\" class=\"visibleLink\" href=\"http://tt-rss.org/wiki/Plugins\">wiki</a>."));
de612e7a
AD
713
714 print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
715
716 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
717 evt.preventDefault();
718 if (this.validate()) {
719 notify_progress('Saving data...', true);
720
721 new Ajax.Request('backend.php', {
722 parameters: dojo.objectToQuery(this.getValues()),
723 onComplete: function(transport) {
724 notify('');
725 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
726 window.location.reload();
727 }
728 } });
729
730 }
731 </script>";
732
733 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
734 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
735
65d1e250 736 print "<table width='100%' class='prefPluginsList'>";
de612e7a
AD
737
738 print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
739
740 print "<tr class=\"title\">
741 <td width=\"5%\">&nbsp;</td>
742 <td width='10%'>".__('Plugin')."</td>
743 <td width=''>".__('Description')."</td>
744 <td width='5%'>".__('Version')."</td>
745 <td width='10%'>".__('Author')."</td></tr>";
746
747 $system_enabled = array_map("trim", explode(",", PLUGINS));
a42c55f0 748 $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
de612e7a 749
6f7798b6 750 $tmppluginhost = new PluginHost();
5d9abb1e
AD
751 $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]);
752 $tmppluginhost->load_data(true);
de612e7a
AD
753
754 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
d2a421e3 755 $about = $plugin->about();
de612e7a 756
23be0bd3 757 if ($about[3] && strpos($name, "example") === FALSE) {
de612e7a
AD
758 if (in_array($name, $system_enabled)) {
759 $checked = "checked='1'";
760 } else {
761 $checked = "";
762 }
763
764 print "<tr>";
765
766 print "<td align='center'><input disabled='1'
767 dojoType=\"dijit.form.CheckBox\" $checked
768 type=\"checkbox\"></td>";
769
2f20dd58
AD
770 $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
771
06a39024 772 print "<td><label><img src='images/$plugin_icon' alt=''> $name</label></td>";
bb5e1a32
AD
773 print "<td>" . htmlspecialchars($about[1]);
774 if (@$about[4]) {
775 print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
776 href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
777 }
778 print "</td>";
de612e7a
AD
779 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
780 print "<td>" . htmlspecialchars($about[2]) . "</td>";
781
5d9abb1e 782 if (count($tmppluginhost->get_all($plugin)) > 0) {
81c54e3d
AD
783 if (in_array($name, $system_enabled)) {
784 print "<td><a href='#' onclick=\"clearPluginData('$name')\"
785 class='visibleLink'>".__("Clear data")."</a></td>";
786 }
5d9abb1e
AD
787 }
788
de612e7a
AD
789 print "</tr>";
790
791 }
792 }
793
794 print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
795
796 print "<tr class=\"title\">
797 <td width=\"5%\">&nbsp;</td>
798 <td width='10%'>".__('Plugin')."</td>
799 <td width=''>".__('Description')."</td>
800 <td width='5%'>".__('Version')."</td>
801 <td width='10%'>".__('Author')."</td></tr>";
802
803
804 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
d2a421e3 805 $about = $plugin->about();
de612e7a 806
23be0bd3 807 if (!$about[3] && strpos($name, "example") === FALSE) {
de612e7a
AD
808
809 if (in_array($name, $system_enabled)) {
810 $checked = "checked='1'";
811 $disabled = "disabled='1'";
65d1e250 812 $rowclass = '';
de612e7a
AD
813 } else if (in_array($name, $user_enabled)) {
814 $checked = "checked='1'";
815 $disabled = "";
65d1e250 816 $rowclass = "Selected";
de612e7a
AD
817 } else {
818 $checked = "";
819 $disabled = "";
65d1e250 820 $rowclass = '';
de612e7a
AD
821 }
822
65d1e250 823 print "<tr class='$rowclass'>";
de612e7a 824
2f20dd58
AD
825 $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
826
de612e7a
AD
827 print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
828 dojoType=\"dijit.form.CheckBox\" $checked $disabled
829 type=\"checkbox\"></td>";
830
2f20dd58 831 print "<td><label for='FPCHK-$name'><img src='images/$plugin_icon' alt=''> $name</label></td>";
bb5e1a32
AD
832 print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
833 if (@$about[4]) {
834 print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
835 href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
836 }
837 print "</td>";
838
de612e7a
AD
839 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
840 print "<td>" . htmlspecialchars($about[2]) . "</td>";
841
5d9abb1e 842 if (count($tmppluginhost->get_all($plugin)) > 0) {
81c54e3d
AD
843 if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
844 print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
845 }
5d9abb1e
AD
846 }
847
de612e7a
AD
848 print "</tr>";
849
850
851
852 }
853
854 }
855
856 print "</table>";
857
858 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
859 __("Enable selected plugins")."</button></p>";
860
1395083e
AD
861 print "</form>";
862
863 print "</div>"; #pane
27211afe 864
1ffe3391 865 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
6065f3ad
AD
866 "hook_prefs_tab", "prefPrefs");
867
1395083e
AD
868 print "</div>"; #container
869 }
27211afe 870
f9ebb32c
AD
871 function toggleAdvanced() {
872 $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
873 }
fb70f26e
AD
874
875 function otpqrcode() {
876 require_once "lib/otphp/vendor/base32.php";
877 require_once "lib/otphp/lib/otp.php";
878 require_once "lib/otphp/lib/totp.php";
879 require_once "lib/phpqrcode/phpqrcode.php";
880
d9c85e0f 881 $result = $this->dbh->query("SELECT login,salt,otp_enabled
fb70f26e
AD
882 FROM ttrss_users
883 WHERE id = ".$_SESSION["uid"]);
884
885 $base32 = new Base32();
886
d9c85e0f
AD
887 $login = $this->dbh->fetch_result($result, 0, "login");
888 $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled"));
fb70f26e 889
973392b9 890 if (!$otp_enabled) {
d9c85e0f 891 $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
ab85ad89
AD
892 print QRcode::png("otpauth://totp/".urlencode($login).
893 "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS"));
894
973392b9 895 }
fb70f26e
AD
896 }
897
3ca8af7f 898 function otpenable() {
9deca86d
AD
899 require_once "lib/otphp/vendor/base32.php";
900 require_once "lib/otphp/lib/otp.php";
901 require_once "lib/otphp/lib/totp.php";
902
903 $password = $_REQUEST["password"];
904 $otp = $_REQUEST["otp"];
3ca8af7f 905
1ffe3391 906 $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
0f28f81f 907
3ca8af7f
AD
908 if ($authenticator->check_password($_SESSION["uid"], $password)) {
909
d9c85e0f 910 $result = $this->dbh->query("SELECT salt
9deca86d
AD
911 FROM ttrss_users
912 WHERE id = ".$_SESSION["uid"]);
913
914 $base32 = new Base32();
915
d9c85e0f 916 $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
9deca86d
AD
917 $topt = new \OTPHP\TOTP($secret);
918
919 $otp_check = $topt->now();
920
921 if ($otp == $otp_check) {
d9c85e0f 922 $this->dbh->query("UPDATE ttrss_users SET otp_enabled = true WHERE
3ca8af7f
AD
923 id = " . $_SESSION["uid"]);
924
925 print "OK";
9deca86d
AD
926 } else {
927 print "ERROR:".__("Incorrect one time password");
3ca8af7f
AD
928 }
929 } else {
9deca86d 930 print "ERROR:".__("Incorrect password");
3ca8af7f 931 }
fb70f26e 932
3ca8af7f
AD
933 }
934
935 function otpdisable() {
d9c85e0f 936 $password = $this->dbh->escape_string($_REQUEST["password"]);
3ca8af7f 937
1ffe3391 938 $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
3ca8af7f
AD
939
940 if ($authenticator->check_password($_SESSION["uid"], $password)) {
941
d9c85e0f 942 $this->dbh->query("UPDATE ttrss_users SET otp_enabled = false WHERE
fb70f26e 943 id = " . $_SESSION["uid"]);
3ca8af7f
AD
944
945 print "OK";
946 } else {
947 print "ERROR: ".__("Incorrect password");
fb70f26e 948 }
3ca8af7f 949
fb70f26e 950 }
de612e7a
AD
951
952 function setplugins() {
f4c02a15
AD
953 if (is_array($_REQUEST["plugins"]))
954 $plugins = join(",", $_REQUEST["plugins"]);
955 else
956 $plugins = "";
de612e7a 957
a42c55f0 958 set_pref("_ENABLED_PLUGINS", $plugins);
de612e7a 959 }
5d9abb1e
AD
960
961 function clearplugindata() {
d9c85e0f 962 $name = $this->dbh->escape_string($_REQUEST["name"]);
5d9abb1e 963
1ffe3391 964 PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name));
5d9abb1e 965 }
00e34741
AD
966
967 function customizeCSS() {
a42c55f0 968 $value = get_pref("USER_STYLESHEET");
00e34741
AD
969
970 $value = str_replace("<br/>", "\n", $value);
971
5bbc4bb4 972 print_notice(T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target=\"_blank\" class=\"visibleLink\" href=\"%s\">This file</a> can be used as a baseline.", "css/tt-rss.css"));
00e34741
AD
973
974 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
975 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setpref\">";
976 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"key\" value=\"USER_STYLESHEET\">";
977
978 print "<table width='100%'><tr><td>";
979 print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
980 style='font-size : 12px; width : 100%; height: 200px;'
981 placeHolder='body#ttrssMain { font-size : 14px; };'
982 name='value'>$value</textarea>";
983 print "</td></tr></table>";
984
985 print "<div class='dlgButtons'>";
986 print "<button dojoType=\"dijit.form.Button\"
987 onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> ";
988 print "<button dojoType=\"dijit.form.Button\"
989 onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>";
990 print "</div>";
991
992 }
993
9d76e754
AD
994 function editPrefProfiles() {
995 print "<div dojoType=\"dijit.Toolbar\">";
996
997 print "<div dojoType=\"dijit.form.DropDownButton\">".
998 "<span>" . __('Select')."</span>";
999 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1000 print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\"
1001 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1002 print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\"
1003 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1004 print "</div></div>";
1005
1006 print "<div style=\"float : right\">";
1007
1008 print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
1009 required=\"1\">
1010 <button dojoType=\"dijit.form.Button\"
1011 onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
1012 __('Create profile')."</button></div>";
1013
1014 print "</div>";
1015
d9c85e0f 1016 $result = $this->dbh->query("SELECT title,id FROM ttrss_settings_profiles
9d76e754
AD
1017 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1018
1019 print "<div class=\"prefProfileHolder\">";
1020
1021 print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
1022
1023 print "<table width=\"100%\" class=\"prefFeedProfileList\"
1024 cellspacing=\"0\" id=\"prefFeedProfileList\">";
1025
1026 print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd
1027
1028 print "<td width='5%' align='center'><input
1029 id='FCATC-0'
1030 onclick='toggleSelectRow2(this);'
1031 dojoType=\"dijit.form.CheckBox\"
1032 type=\"checkbox\"></td>";
1033
1034 if (!$_SESSION["profile"]) {
1035 $is_active = __("(active)");
1036 } else {
1037 $is_active = "";
1038 }
1039
1040 print "<td><span>" .
1041 __("Default profile") . " $is_active</span></td>";
1042
1043 print "</tr>";
1044
1045 $lnum = 1;
1046
d9c85e0f 1047 while ($line = $this->dbh->fetch_assoc($result)) {
9d76e754 1048
9d76e754
AD
1049 $profile_id = $line["id"];
1050 $this_row_id = "id=\"FCATR-$profile_id\"";
1051
1052 print "<tr class=\"placeholder\" $this_row_id>";
1053
1054 $edit_title = htmlspecialchars($line["title"]);
1055
1056 print "<td width='5%' align='center'><input
1057 onclick='toggleSelectRow2(this);'
1058 id='FCATC-$profile_id'
1059 dojoType=\"dijit.form.CheckBox\"
1060 type=\"checkbox\"></td>";
1061
1062 if ($_SESSION["profile"] == $line["id"]) {
1063 $is_active = __("(active)");
1064 } else {
1065 $is_active = "";
1066 }
1067
1068 print "<td><span dojoType=\"dijit.InlineEditBox\"
1069 width=\"300px\" autoSave=\"false\"
1070 profile-id=\"$profile_id\">" . $edit_title .
1071 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
1072 var elem = this;
1073 dojo.xhrPost({
1074 url: 'backend.php',
1075 content: {op: 'rpc', method: 'saveprofile',
1076 value: this.value,
1077 id: this.srcNodeRef.getAttribute('profile-id')},
1078 load: function(response) {
1079 elem.attr('value', response);
1080 }
1081 });
1082 </script>
1083 </span> $is_active</td>";
1084
1085 print "</tr>";
1086
1087 ++$lnum;
1088 }
1089
1090 print "</table>";
1091 print "</form>";
1092 print "</div>";
1093
1094 print "<div class='dlgButtons'>
1095 <div style='float : left'>
1096 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
1097 __('Remove selected profiles')."</button>
1098 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
1099 __('Activate profile')."</button>
1100 </div>";
1101
1102 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
1103 __('Close this window')."</button>";
1104 print "</div>";
1105
1106 }
1107
dfad9d7a
AD
1108 private function getShortDesc($pref_name) {
1109 if (isset($this->pref_help[$pref_name])) {
1110 return $this->pref_help[$pref_name][0];
1111 }
1112 return "";
1113 }
9d76e754 1114
dfad9d7a
AD
1115 private function getHelpText($pref_name) {
1116 if (isset($this->pref_help[$pref_name])) {
1117 return $this->pref_help[$pref_name][1];
1118 }
1119 return "";
1120 }
1121
1122 private function getSectionName($id) {
1123 if (isset($this->pref_sections[$id])) {
1124 return $this->pref_sections[$id];
1125 }
1126
1127 return "";
1128 }
1395083e
AD
1129}
1130?>