]> git.wh0rd.org - tt-rss.git/blame - backend.php
more debugging in feedlist init
[tt-rss.git] / backend.php
CommitLineData
1cd17194 1<?
36bfab86 2 require_once "sessions.php";
01b3e191 3 require_once "backend-rpc.php";
36bfab86 4
59b8192f 5 header("Cache-Control: no-cache, must-revalidate");
ce0619bb
AD
6 header("Pragma: no-cache");
7 header("Expires: -1");
de696427 8
894ebcf5 9/* if ($_GET["debug"]) {
cce28758
AD
10 define('DEFAULT_ERROR_LEVEL', E_ALL);
11 } else {
12 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
13 }
894ebcf5
AD
14
15 error_reporting(DEFAULT_ERROR_LEVEL); */
cce28758 16
262bd8ea
AD
17 $op = $_REQUEST["op"];
18
657770a0
AD
19 define('SCHEMA_VERSION', 7);
20
21 require_once "sanity_check.php";
22 require_once "config.php";
23
24 $err_msg = check_configuration_variables();
25
26 if ($err_msg) {
27 print "Fatal error: $err_msg";
28 exit;
29 }
30
a2770077 31 if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
262bd8ea
AD
32 header("Content-Type: application/xml");
33 }
34
a2770077 35 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
262bd8ea 36
a2770077 37 if ($op == "rpc") {
262bd8ea 38 print "<error error-code=\"6\"/>";
04269460
AD
39 } else {
40 print "
41 <html><body>
42 <p>Error: Not logged in.</p>
43 <script type=\"text/javascript\">
44 if (parent.window != 'undefined') {
45 parent.window.location = \"login.php\";
46 } else {
47 window.location = \"login.php\";
48 }
49 </script>
50 </body></html>
51 ";
262bd8ea
AD
52 }
53 exit;
54 }
1c7f75ed 55
a2770077
AD
56 if (!$op) {
57 print "<error error-code=\"7\"/>";
58 exit;
59 }
60
648472a7 61 require_once "db.php";
3bac89ad 62 require_once "db-prefs.php";
82baad4a
AD
63 require_once "functions.php";
64 require_once "magpierss/rss_fetch.inc";
1cd17194 65
ad815c71
AD
66 $purge_intervals = array(
67 0 => "Default",
68 -1 => "Never purge",
69 5 => "1 week",
70 14 => "2 weeks",
71 31 => "1 month",
72 60 => "2 months",
73 90 => "3 months");
74
75 $update_intervals = array(
76 0 => "Default",
77 -1 => "Disable updates",
78 30 => "30 minutes",
79 60 => "1 hour",
80 240 => "4 hours",
81 720 => "12 hours",
82 1440 => "Daily",
83 10080 => "Weekly");
84
406d9489
AD
85 $script_started = getmicrotime();
86
648472a7 87 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
d76a3b03 88
5136011e
AD
89 if (!$link) {
90 if (DB_TYPE == "mysql") {
91 print mysql_error();
92 }
93 // PG seems to display its own errors just fine by default.
94 return;
95 }
96
648472a7
AD
97 if (DB_TYPE == "pgsql") {
98 pg_query("set client_encoding = 'utf-8'");
99 }
7ec2a838 100
4053b540
AD
101 if ($_SESSION["uid"]) {
102 if (get_pref($link, "HIDE_READ_FEEDS") == "true") {
103 setcookie("ttrss_vf_hreadf", 1);
104 } else {
105 setcookie("ttrss_vf_hreadf", 0);
106 }
f5de0d8d
AD
107
108 setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH);
c6784aea 109 setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON);
4053b540 110 }
7f123cda 111
331900c6 112 $fetch = $_GET["fetch"];
175847de 113
76b4eae1 114// setcookie("ttrss_icons_url", ICONS_URL);
b2804af7
AD
115
116 if (!sanity_check($link)) { return; }
023fe037 117
8143ae1f 118 function outputFeedList($link, $tags = false) {
175847de 119
1a66d16e
AD
120 print "<html><head>
121 <title>Tiny Tiny RSS : Feedlist</title>
430bf183
AD
122 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
123
503eb349
AD
124 $user_theme = $_SESSION["theme"];
125 if ($user_theme) {
126 print "<link rel=\"stylesheet\" type=\"text/css\"
127 href=\"themes/$user_theme/theme.css\">";
128 }
129
4769ddaf 130 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
131 print "<link rel=\"stylesheet\" type=\"text/css\"
132 href=\"tt-rss_compact.css\"/>";
133 } else {
134 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
135 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
136 }
137
138 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
1a66d16e
AD
139 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
140 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
beac550b
AD
141 <!--[if gte IE 5.5000]>
142 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
2f52ca1b 143 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
beac550b 144 <![endif]-->
97dcd654
AD
145 </head><body>
146 <script type=\"text/javascript\">
147 if (document.addEventListener) {
148 document.addEventListener(\"DOMContentLoaded\", init, null);
149 }
150 window.onload = init;
151 </script>";
254e0e4b 152
140ff9db 153 print "<ul class=\"feedList\" id=\"feedList\">\n";
254e0e4b 154
4356293a
AD
155 $owner_uid = $_SESSION["uid"];
156
8143ae1f 157 if (!$tags) {
254e0e4b 158
8143ae1f 159 /* virtual feeds */
254e0e4b 160
91ff844a 161 if (get_pref($link, 'ENABLE_FEED_CATS')) {
937881b5
AD
162 print "<li class=\"feedCat\">Special</li>";
163 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a
AD
164 }
165
8143ae1f 166 $result = db_query($link, "SELECT count(id) as num_starred
4c193675
AD
167 FROM ttrss_entries,ttrss_user_entries
168 WHERE marked = true AND
169 ttrss_user_entries.ref_id = ttrss_entries.id AND
170 unread = true AND owner_uid = '$owner_uid'");
8143ae1f 171 $num_starred = db_fetch_result($result, 0, "num_starred");
254e0e4b 172
3745788e 173 $class = "virt";
8add756a
AD
174
175 if ($num_starred > 0) $class .= "Unread";
176
177 printFeedEntry(-1, $class, "Starred articles", $num_starred,
4668523d 178 "images/mark_set.png", $link);
48f0adb0 179
91ff844a 180 if (get_pref($link, 'ENABLE_FEED_CATS')) {
140ff9db 181 print "</ul>\n";
91ff844a
AD
182 }
183
cfaba6df 184 if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
8143ae1f
AD
185
186 $result = db_query($link, "SELECT id,sql_exp,description FROM
4356293a 187 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
8143ae1f
AD
188
189 if (db_num_rows($result) > 0) {
91ff844a 190 if (get_pref($link, 'ENABLE_FEED_CATS')) {
937881b5
AD
191 print "<li class=\"feedCat\">Labels</li>";
192 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a 193 } else {
937881b5 194 print "<li><hr></li>";
91ff844a 195 }
8143ae1f
AD
196 }
197
198 while ($line = db_fetch_assoc($result)) {
48f0adb0 199
8143ae1f
AD
200 error_reporting (0);
201
280ee9a3
AD
202 $tmp_result = db_query($link, "SELECT count(id) as count
203 FROM ttrss_entries,ttrss_user_entries
4c193675
AD
204 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
205 ttrss_user_entries.ref_id = ttrss_entries.id
655be073 206 AND owner_uid = '$owner_uid'");
8143ae1f
AD
207
208 $count = db_fetch_result($tmp_result, 0, "count");
209
3745788e 210 $class = "label";
8143ae1f
AD
211
212 if ($count > 0) {
213 $class .= "Unread";
214 }
215
cce28758 216 error_reporting (DEFAULT_ERROR_LEVEL);
8143ae1f
AD
217
218 printFeedEntry(-$line["id"]-11,
4668523d 219 $class, $line["description"], $count, "images/label.png", $link);
8143ae1f
AD
220
221 }
91ff844a
AD
222
223 if (db_num_rows($result) > 0) {
224 if (get_pref($link, 'ENABLE_FEED_CATS')) {
140ff9db 225 print "</ul>";
91ff844a
AD
226 }
227 }
228
229 }
230
231// if (!get_pref($link, 'ENABLE_FEED_CATS')) {
232 print "<li><hr></li>";
233// }
234
235 if (get_pref($link, 'ENABLE_FEED_CATS')) {
236 $order_by_qpart = "category,title";
237 } else {
238 $order_by_qpart = "title";
48f0adb0 239 }
8143ae1f 240
db42b934 241 $result = db_query($link, "SELECT ttrss_feeds.*,
fb1fb4ab 242 SUBSTRING(last_updated,1,19) AS last_updated_noms,
db42b934 243 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
4c193675
AD
244 WHERE feed_id = ttrss_feeds.id AND
245 ttrss_user_entries.ref_id = ttrss_entries.id AND
246 owner_uid = '$owner_uid') AS total,
db42b934 247 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
b88917af 248 WHERE feed_id = ttrss_feeds.id AND unread = true
4c193675 249 AND ttrss_user_entries.ref_id = ttrss_entries.id
91ff844a 250 AND owner_uid = '$owner_uid') as unread,
023fe037 251 cat_id,last_error,
db42b934
AD
252 ttrss_feed_categories.title AS category,
253 ttrss_feed_categories.collapsed
254 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
255 ON (ttrss_feed_categories.id = cat_id)
256 WHERE
257 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
258 ORDER BY $order_by_qpart");
259
8143ae1f
AD
260 $actid = $_GET["actid"];
261
262 /* real feeds */
263
264 $lnum = 0;
265
266 $total_unread = 0;
91ff844a
AD
267
268 $category = "";
fb1fb4ab
AD
269
270 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
8143ae1f 271
48f0adb0 272 while ($line = db_fetch_assoc($result)) {
8143ae1f 273
69668465 274 $feed = db_unescape_string($line["title"]);
8143ae1f
AD
275 $feed_id = $line["id"];
276
277 $subop = $_GET["subop"];
278
279 $total = $line["total"];
280 $unread = $line["unread"];
91ff844a 281
fb1fb4ab
AD
282 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
283 $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
284 } else {
285 $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
286 }
287
9323147e
AD
288 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
289
290 if ($rtl_content) {
291 $rtl_tag = "dir=\"RTL\"";
292 } else {
293 $rtl_tag = "";
294 }
295
db42b934
AD
296 $tmp_result = db_query($link,
297 "SELECT id,COUNT(unread) AS unread
298 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
299 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
300 WHERE parent_feed = '$feed_id' AND unread = true
301 GROUP BY ttrss_feeds.id");
302
303 if (db_num_rows($tmp_result) > 0) {
304 while ($l = db_fetch_assoc($tmp_result)) {
305 $unread += $l["unread"];
306 }
307 }
308
fe14aeb8
AD
309 $cat_id = $line["cat_id"];
310
91ff844a
AD
311 $tmp_category = $line["category"];
312
313 if (!$tmp_category) {
314 $tmp_category = "Uncategorized";
315 }
8143ae1f
AD
316
317 // $class = ($lnum % 2) ? "even" : "odd";
023fe037
AD
318
319 if ($line["last_error"]) {
320 $class = "error";
321 } else {
322 $class = "feed";
323 }
8143ae1f
AD
324
325 if ($unread > 0) $class .= "Unread";
326
327 if ($actid == $feed_id) {
328 $class .= "Selected";
392d4563 329 }
48f0adb0 330
8143ae1f 331 $total_unread += $unread;
91ff844a
AD
332
333 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
334
335 if ($category) {
140ff9db 336 print "</ul></li>";
91ff844a
AD
337 }
338
339 $category = $tmp_category;
fe14aeb8
AD
340
341 $collapsed = $line["collapsed"];
342
65f85814
AD
343 // workaround for NULL category
344 if ($category == "Uncategorized") {
345 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
346 $collapsed = "t";
347 }
348 }
349
fe14aeb8
AD
350 if ($collapsed == "t" || $collapsed == "1") {
351 $holder_class = "invisible";
65f85814 352 $ellipsis = "...";
fe14aeb8
AD
353 } else {
354 $holder_class = "";
65f85814 355 $ellipsis = "";
280ee9a3
AD
356 }
357
358 if ($cat_id) {
359 $cat_id_qpart = "cat_id = '$cat_id'";
360 } else {
361 $cat_id_qpart = "cat_id IS NULL";
362 }
363
364 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
365 FROM ttrss_user_entries,ttrss_feeds WHERE
366 unread = true AND
367 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
368 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
369
370 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
371
372 $cat_id = sprintf("%d", $cat_id);
91ff844a 373
fe14aeb8 374 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
ff2c6e6a 375 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
99ff73f4 376 <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
280ee9a3 377 <span id=\"FCATCTR-$cat_id\"
fb1fb4ab
AD
378 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span>
379 </a></li>";
c3f348c2
AD
380
381 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
382 // -> keyboard navigation, etc.
96737ce9 383 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
91ff844a 384 }
8143ae1f 385
91ff844a 386 printFeedEntry($feed_id, $class, $feed, $unread,
fb1fb4ab
AD
387 "icons/$feed_id.ico", $link, $rtl_content,
388 $last_updated, $line["last_error"]);
8143ae1f
AD
389
390 ++$lnum;
48f0adb0 391 }
91ff844a 392
8143ae1f 393 } else {
a1a8a2be 394
8143ae1f 395 // tags
a1a8a2be 396
987170e6 397/* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
05732aa0
AD
398 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
399 post_int_id = ttrss_user_entries.int_id AND
400 unread = true AND ref_id = ttrss_entries.id
3b0948c4 401 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
8143ae1f 402 UNION
3b0948c4 403 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
987170e6
AD
404 ORDER BY tag_name"); */
405
406 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
407 FROM ttrss_user_entries WHERE int_id = post_int_id
408 AND unread = true)) AS count FROM ttrss_tags
409 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
410
8143ae1f
AD
411 $tags = array();
412
413 while ($line = db_fetch_assoc($result)) {
414 $tags[$line["tag_name"]] += $line["count"];
1a66d16e 415 }
8143ae1f
AD
416
417 foreach (array_keys($tags) as $tag) {
418
419 $unread = $tags[$tag];
420
83957936 421 $class = "tag";
8143ae1f
AD
422
423 if ($unread > 0) {
424 $class .= "Unread";
425 }
426
4668523d 427 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
8143ae1f
AD
428
429 }
1a66d16e 430
e828e31e 431 }
82baad4a 432
dc33ec95 433 if (db_num_rows($result) == 0) {
8037c618
AD
434 if ($tags) {
435 $what = "tags";
436 } else {
437 $what = "feeds";
438 }
439 print "<li>No $what to display.</li>";
dc33ec95
AD
440 }
441
8143ae1f 442 print "</ul>";
1cd17194 443
97dcd654
AD
444 print '
445 <script type="text/javascript">
446 /* for IE */
447 function statechange() {
448 if (document.readyState == "interactive") init();
449 }
450
451 if (document.readyState) {
452 if (document.readyState == "interactive" || document.readyState == "complete") {
453 init();
454 } else {
455 document.onreadystatechange = statechange;
456 }
457 }
458 </script></body></html>';
c3b81db0
AD
459 }
460
461
462 if ($op == "rpc") {
01b3e191 463 handle_rpc_request($link);
c3b81db0
AD
464 }
465
466 if ($op == "feeds") {
467
8143ae1f
AD
468 $tags = $_GET["tags"];
469
c3b81db0
AD
470 $subop = $_GET["subop"];
471
472 if ($subop == "catchupAll") {
b018b49b 473 db_query($link, "UPDATE ttrss_user_entries SET
6d15e1ef 474 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
c3b81db0
AD
475 }
476
fe14aeb8
AD
477 if ($subop == "collapse") {
478 $cat_id = db_escape_string($_GET["cid"]);
280ee9a3 479
fe14aeb8
AD
480 db_query($link, "UPDATE ttrss_feed_categories SET
481 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
482 $_SESSION["uid"]);
483 return;
484 }
485
8143ae1f 486 outputFeedList($link, $tags);
c3b81db0 487
1cd17194
AD
488 }
489
490 if ($op == "view") {
491
70f6dbb1
AD
492 $id = db_escape_string($_GET["id"]);
493 $feed_id = db_escape_string($_GET["feed"]);
494
495 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
496 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
497
498 if (db_num_rows($result) == 1) {
499 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
500 } else {
501 $rtl_content = false;
502 }
503
504 if ($rtl_content) {
505 $rtl_tag = "dir=\"RTL\"";
ed51e128 506 $rtl_class = "RTL";
70f6dbb1
AD
507 } else {
508 $rtl_tag = "";
ed51e128 509 $rtl_class = "";
70f6dbb1 510 }
d76a3b03 511
4c193675
AD
512 $result = db_query($link, "UPDATE ttrss_user_entries
513 SET unread = false,last_read = NOW()
514 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
a1a8a2be 515
21703604 516 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
9167e250 517 SUBSTRING(updated,1,16) as updated,
11b0dce2 518 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
a545b564
AD
519 num_comments,
520 author
4c193675
AD
521 FROM ttrss_entries,ttrss_user_entries
522 WHERE id = '$id' AND ref_id = id");
1cd17194 523
59b8192f
AD
524 print "<html><head>
525 <title>Tiny Tiny RSS : Article $id</title>
526 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
503eb349 527
59b8192f
AD
528 $user_theme = $_SESSION["theme"];
529 if ($user_theme) {
530 print "<link rel=\"stylesheet\" type=\"text/css\"
531 href=\"themes/$user_theme/theme.css\">";
532 }
503eb349 533
59b8192f
AD
534 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
535 print "<link rel=\"stylesheet\" type=\"text/css\"
536 href=\"tt-rss_compact.css\"/>";
537 } else {
538 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
539 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
70830c87
AD
540 }
541
59b8192f
AD
542 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
543 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
70f6dbb1 544 </head><body $rtl_tag>";
59b8192f 545
d76a3b03 546 if ($result) {
1cd17194 547
648472a7 548 $line = db_fetch_assoc($result);
1cd17194 549
b7f4bda2
AD
550 if ($line["icon_url"]) {
551 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
552 } else {
553 $feed_icon = "&nbsp;";
554 }
d76a3b03 555
11b0dce2 556/* if ($line["comments"] && $line["link"] != $line["comments"]) {
f7181e9b
AD
557 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
558 } else {
559 $entry_comments = "";
11b0dce2
AD
560 } */
561
562 $num_comments = $line["num_comments"];
563 $entry_comments = "";
564
565 if ($num_comments > 0) {
566 if ($line["comments"]) {
567 $comments_url = $line["comments"];
568 } else {
569 $comments_url = $line["link"];
570 }
6a1ad084 571 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
11b0dce2
AD
572 } else {
573 if ($line["comments"] && $line["link"] != $line["comments"]) {
672366bd 574 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
11b0dce2 575 }
f7181e9b
AD
576 }
577
e828e31e
AD
578 print "<div class=\"postReply\">";
579
21703604
AD
580 print "<div class=\"postHeader\"><table width=\"100%\">";
581
a545b564
AD
582 $entry_author = $line["author"];
583
584 if ($entry_author) {
585 $entry_author = " - by $entry_author";
586 }
587
588 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] .
589 "</a>$entry_author</td>";
9167e250
AD
590
591 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
592 strtotime($line["updated"]));
593
ed51e128 594 print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
9167e250
AD
595
596 print "</tr>";
21703604
AD
597
598 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
599 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
600 ORDER BY tag_name");
601
602 $tags_str = "";
42918a07
AD
603 $f_tags_str = "";
604
605 $num_tags = 0;
21703604
AD
606
607 while ($tmp_line = db_fetch_assoc($tmp_result)) {
42918a07
AD
608 $num_tags++;
609 $tag = $tmp_line["tag_name"];
610 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
611
612 if ($num_tags == 5) {
613 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
614 } else if ($num_tags < 5) {
615 $tags_str .= $tag_str;
616 }
617 $f_tags_str .= $tag_str;
618 }
21703604 619
42918a07
AD
620 $tags_str = preg_replace("/, $/", "", $tags_str);
621 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
e828e31e 622
6a1ad084 623// $truncated_link = truncate_string($line["link"], 60);
21703604 624
6a1ad084
AD
625 if ($tags_str || $entry_comments) {
626 print "<tr><td width='50%'>
627 $entry_comments</td>
628 <td align=\"right\">$tags_str</td></tr>";
629 }
21703604 630
e828e31e
AD
631 print "</table></div>";
632
633 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
42918a07
AD
634 print "<div class=\"postContent\">";
635
636 if (db_num_rows($tmp_result) > 5) {
637 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
638 }
639
68511f86
AD
640 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
641 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
642 }
643
42918a07 644 print $line["content"] . "</div>";
e828e31e
AD
645
646 print "</div>";
647
090e250b 648 print "<script type=\"text/javascript\">
4f3a84f4 649 update_all_counters('$feed_id');
090e250b 650 </script>";
d76a3b03 651 }
70830c87 652
59b8192f 653 print "</body></html>";
1cd17194
AD
654 }
655
656 if ($op == "viewfeed") {
657
3c81ae1a
AD
658 $feed = db_escape_string($_GET["feed"]);
659 $skip = db_escape_string($_GET["skip"]);
660 $subop = db_escape_string($_GET["subop"]);
661 $view_mode = db_escape_string($_GET["view"]);
662 $limit = db_escape_string($_GET["limit"]);
663 $cat_view = db_escape_string($_GET["cat"]);
a1a8a2be 664
ac53063a
AD
665 if (!$skip) $skip = 0;
666
476cac42 667 if ($subop == "undefined") $subop = "";
1cd17194 668
59b8192f
AD
669 print "<html><head>
670 <title>Tiny Tiny RSS : Feed $feed</title>
671 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
503eb349 672
59b8192f
AD
673 $user_theme = $_SESSION["theme"];
674 if ($user_theme) {
675 print "<link rel=\"stylesheet\" type=\"text/css\"
676 href=\"themes/$user_theme/theme.css\">";
677 }
430bf183 678
59b8192f
AD
679 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
680 print "<link rel=\"stylesheet\"
681 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
503eb349 682
59b8192f
AD
683 } else {
684 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
685 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
f0601b87
AD
686 }
687
2e915ba9
AD
688 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
689
690 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
691 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
70f6dbb1 692
2e915ba9
AD
693 if (db_num_rows($result) == 1) {
694 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
695 } else {
696 $rtl_content = false;
697 }
698
699 if ($rtl_content) {
700 $rtl_tag = "dir=\"RTL\"";
701 } else {
702 $rtl_tag = "";
703 }
70f6dbb1
AD
704 } else {
705 $rtl_tag = "";
2e915ba9 706 $rtl_content = false;
70f6dbb1
AD
707 }
708
59b8192f
AD
709 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
710 <script type=\"text/javascript\" src=\"functions.js\"></script>
711 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
712 <!--[if gte IE 5.5000]>
713 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
714 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
715 <![endif]-->
10031c3b 716 </head><body $rtl_tag>
59b8192f
AD
717 <script type=\"text/javascript\">
718 if (document.addEventListener) {
719 document.addEventListener(\"DOMContentLoaded\", init, null);
720 }
721 window.onload = init;
722 </script>";
723
7a232fc6 724 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
23aa0d16 725 update_generic_feed($link, $feed, $cat_view);
dcee8f61
AD
726 }
727
0e32076b 728 if ($subop == "MarkAllRead") {
23aa0d16 729 catchup_feed($link, $feed, $cat_view);
a1a8a2be 730 }
d76a3b03 731
f932bc9f
AD
732 $search = db_escape_string($_GET["search"]);
733 $search_mode = db_escape_string($_GET["smode"]);
52b51244 734
f175937c 735 if ($search) {
8e84993b
AD
736 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
737 OR ttrss_entries.content LIKE '%$search%') AND";
f175937c
AD
738 } else {
739 $search_query_part = "";
740 }
741
742 $view_query_part = "";
743
0ee2d12f 744 if ($view_mode == "Adaptive") {
f18d0d94
AD
745 if ($search) {
746 $view_query_part = " ";
747 } else if ($feed != -1) {
0ee2d12f
AD
748 $unread = getFeedUnread($link, $feed);
749 if ($unread > 0) {
750 $view_query_part = " unread = true AND ";
751 }
752 }
753 }
754
f175937c
AD
755 if ($view_mode == "Starred") {
756 $view_query_part = " marked = true AND ";
ac53063a
AD
757 }
758
ac43eba1
AD
759 if ($view_mode == "Unread") {
760 $view_query_part = " unread = true AND ";
761 }
762
8d7008c7 763 if ($limit && $limit != "All") {
82c9223c 764 $limit_query_part = "LIMIT " . $limit;
ad3cb710 765 }
f0601b87 766
254e0e4b
AD
767 $vfeed_query_part = "";
768
52b51244 769 // override query strategy and enable feed display when searching globally
d3416913 770 if ($search && $search_mode == "All feeds") {
8e84993b 771 $query_strategy_part = "ttrss_entries.id > 0";
b0005823 772 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
d0bb308e 773 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
8143ae1f
AD
774 $query_strategy_part = "ttrss_entries.id > 0";
775 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
776 id = feed_id) as feed_title,";
b0005823
AD
777 } else if ($feed >= 0 && $search && $search_mode == "This category") {
778
779 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
780
781 $tmp_result = db_query($link, "SELECT id
782 FROM ttrss_feeds WHERE cat_id =
783 (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'");
784
785 $cat_siblings = array();
786
787 if (db_num_rows($tmp_result) > 0) {
788 while ($p = db_fetch_assoc($tmp_result)) {
789 array_push($cat_siblings, "feed_id = " . $p["id"]);
790 }
791
792 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
793 $feed, implode(" OR ", $cat_siblings));
794
795 } else {
796 $query_strategy_part = "ttrss_entries.id > 0";
797 }
ff2c6e6a 798
8143ae1f 799 } else if ($feed >= 0) {
60103089 800
ff2c6e6a 801 if ($cat_view) {
b0005823 802
99ff73f4
AD
803 if ($feed > 0) {
804 $query_strategy_part = "cat_id = '$feed'";
805 } else {
806 $query_strategy_part = "cat_id IS NULL";
807 }
808
60103089 809 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
ff2c6e6a
AD
810
811 } else {
812 $tmp_result = db_query($link, "SELECT id
813 FROM ttrss_feeds WHERE parent_feed = '$feed'
814 ORDER BY cat_id,title");
815
816 $parent_ids = array();
817
818 if (db_num_rows($tmp_result) > 0) {
819 while ($p = db_fetch_assoc($tmp_result)) {
820 array_push($parent_ids, "feed_id = " . $p["id"]);
821 }
822
823 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
824 $feed, implode(" OR ", $parent_ids));
825
826 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
827 } else {
828 $query_strategy_part = "feed_id = '$feed'";
829 }
60103089 830 }
48f0adb0 831 } else if ($feed == -1) { // starred virtual feed
254e0e4b 832 $query_strategy_part = "marked = true";
60103089 833 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
48f0adb0
AD
834 } else if ($feed <= -10) { // labels
835 $label_id = -$feed - 11;
836
837 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
838 WHERE id = '$label_id'");
839
840 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
841
60103089 842 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
254e0e4b 843 } else {
48f0adb0 844 $query_strategy_part = "id > 0"; // dumb
254e0e4b
AD
845 }
846
f99321a3
AD
847 $order_by = "updated DESC";
848
849// if ($feed < -10) {
850// $order_by = "feed_id,updated DESC";
851// }
852
1572afe5
AD
853 $feed_title = "";
854
855 if ($search && $search_mode == "All feeds") {
49b7cbd3 856 $feed_title = "Global search results ($search)";
d0bb308e 857 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
49b7cbd3 858 $feed_title = "Feed search results ($search, $feed)";
d0bb308e
AD
859 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
860 $feed_title = $feed;
861 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
1572afe5 862
ff2c6e6a 863 if ($cat_view) {
ff2c6e6a 864
019ce9f3
AD
865 if ($feed != 0) {
866 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
867 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
868 $feed_title = db_fetch_result($result, 0, "title");
869 } else {
870 $feed_title = "Uncategorized";
871 }
ff2c6e6a
AD
872 } else {
873
874 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
875 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
876
877 $feed_title = db_fetch_result($result, 0, "title");
878 $feed_site_url = db_fetch_result($result, 0, "site_url");
879 $last_error = db_fetch_result($result, 0, "last_error");
880
881 }
1572afe5
AD
882
883 } else if ($feed == -1) {
884 $feed_title = "Starred articles";
885 } else if ($feed < -10) {
886 $label_id = -$feed - 11;
887 $result = db_query($link, "SELECT description FROM ttrss_labels
888 WHERE id = '$label_id'");
889 $feed_title = db_fetch_result($result, 0, "description");
890 } else {
891 $feed_title = "?";
892 }
893
48f0adb0
AD
894 if ($feed < -10) error_reporting (0);
895
386cbf27
AD
896 print "<div id=\"headlinesContainer\">";
897
d0bb308e 898 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
8143ae1f 899
99ff73f4 900 if ($feed >= 0) {
21703604
AD
901 $feed_kind = "Feeds";
902 } else {
903 $feed_kind = "Labels";
904 }
905
386cbf27
AD
906// if (!$vfeed_query_part) {
907 $content_query_part = "content as content_preview,";
908// } else {
909// $content_query_part = "";
910// }
bd34c528 911
894ebcf5 912 $query = "SELECT
60103089 913 ttrss_entries.id,ttrss_entries.title,
1572afe5
AD
914 SUBSTRING(updated,1,16) as updated,
915 unread,feed_id,marked,link,last_read,
8143ae1f
AD
916 SUBSTRING(last_read,1,19) as last_read_noms,
917 $vfeed_query_part
bd34c528
AD
918 $content_query_part
919 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 920 FROM
60103089 921 ttrss_entries,ttrss_user_entries,ttrss_feeds
8143ae1f 922 WHERE
60103089 923 ttrss_user_entries.feed_id = ttrss_feeds.id AND
4c193675 924 ttrss_user_entries.ref_id = ttrss_entries.id AND
60103089 925 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
926 $search_query_part
927 $view_query_part
928 $query_strategy_part ORDER BY $order_by
894ebcf5
AD
929 $limit_query_part";
930
931 $result = db_query($link, $query);
932
933 if ($_GET["debug"]) print $query;
8143ae1f
AD
934
935 } else {
936 // browsing by tag
937
21703604
AD
938 $feed_kind = "Tags";
939
8143ae1f 940 $result = db_query($link, "SELECT
1572afe5
AD
941 ttrss_entries.id as id,title,
942 SUBSTRING(updated,1,16) as updated,
943 unread,feed_id,
1e471f3b 944 marked,link,last_read,
c05a19f3 945 SUBSTRING(last_read,1,19) as last_read_noms,
254e0e4b 946 $vfeed_query_part
bd34c528
AD
947 $content_query_part
948 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 949 FROM
05732aa0 950 ttrss_entries,ttrss_user_entries,ttrss_tags
8143ae1f 951 WHERE
05732aa0
AD
952 ref_id = ttrss_entries.id AND
953 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
954 post_int_id = int_id AND tag_name = '$feed' AND
8143ae1f
AD
955 $view_query_part
956 $search_query_part
957 $query_strategy_part ORDER BY $order_by
958 $limit_query_part");
959 }
d76a3b03 960
48f0adb0 961 if (!$result) {
386cbf27
AD
962 print "<div align='center'>
963 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
964 return;
adccd201 965 }
98bea1b1 966
e0a7121b 967 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
c1c9df00 968 $bottom = false, $rtl_content = false) {
f56ec297 969
e0a7121b
AD
970 if (!$bottom) {
971 $class = "headlinesSubToolbar";
972 $tid = "headlineActionsTop";
973 } else {
974 $class = "invisible";
975 $tid = "headlineActionsBottom";
976 }
977
978 print "<table class=\"$class\" id=\"$tid\"
386cbf27
AD
979 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
980
c1c9df00
AD
981 if ($rtl_content) {
982 $rtl_cpart = "RTL";
983 } else {
984 $rtl_cpart = "";
985 }
986
386cbf27 987 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201 988
c1c9df00 989 print "<td class=\"headlineActions$rtl_cpart\">
adccd201 990 Select:
e7811ea5
AD
991 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
992 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
993 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
386cbf27 994 &nbsp;&nbsp;
e7811ea5
AD
995 Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
996 <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
adccd201 997 print "</td>";
386cbf27
AD
998
999 } else {
1000
c1c9df00 1001 print "<td class=\"headlineActions$rtl_cpart\">
386cbf27 1002 Select:
e7811ea5
AD
1003 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>,
1004 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1005 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a>
386cbf27 1006 &nbsp;&nbsp;
e7811ea5
AD
1007 Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1008 <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>";
386cbf27 1009
adccd201 1010 print "</td>";
386cbf27 1011
386cbf27
AD
1012 }
1013
c1c9df00 1014 print "<td class=\"headlineTitle$rtl_cpart\">";
adccd201 1015
386cbf27 1016 if ($feed_site_url) {
c7a8abe6
AD
1017 if (!$bottom) {
1018 $target = "target=\"_blank\"";
1019 }
1020 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
386cbf27
AD
1021 } else {
1022 print $feed_title;
1023 }
1024
1025 print "</td>";
1026 print "</tr></table>";
1027
98bea1b1
AD
1028 }
1029
1030 if (db_num_rows($result) > 0) {
1031
c1c9df00
AD
1032 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
1033 $rtl_content);
98bea1b1 1034
386cbf27 1035 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201 1036 print "<table class=\"headlinesList\" id=\"headlinesList\"
10031c3b 1037 cellspacing=\"0\" width=\"100%\">";
f4c10d44 1038 }
386cbf27 1039
e5a99b88
AD
1040 $lnum = 0;
1041
1042 error_reporting (DEFAULT_ERROR_LEVEL);
1043
1044 $num_unread = 0;
1045
1046 while ($line = db_fetch_assoc($result)) {
adccd201 1047
e5a99b88
AD
1048 $class = ($lnum % 2) ? "even" : "odd";
1049
1050 $id = $line["id"];
1051 $feed_id = $line["feed_id"];
1052
1053 if ($line["last_read"] == "" &&
1054 ($line["unread"] != "t" && $line["unread"] != "1")) {
1055
1056 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1057 alt=\"Updated\">";
1058 } else {
1059 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1060 alt=\"Updated\">";
1061 }
1062
1063 if ($line["unread"] == "t" || $line["unread"] == "1") {
1064 $class .= "Unread";
1065 ++$num_unread;
386cbf27 1066 $is_unread = true;
adccd201 1067 } else {
386cbf27 1068 $is_unread = false;
e5a99b88
AD
1069 }
1070
1071 if ($line["marked"] == "t" || $line["marked"] == "1") {
1072 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
9932fb06 1073 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
e5a99b88
AD
1074 } else {
1075 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
9932fb06 1076 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
e5a99b88
AD
1077 }
1078
e454a889 1079 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
e5a99b88 1080 $line["title"] . "</a>";
adccd201 1081
e5a99b88
AD
1082 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1083 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1084 } else {
1085 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1086 $updated_fmt = date($short_date, strtotime($line["updated"]));
1087 }
adccd201
AD
1088
1089 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
8fd0c717 1090 $content_preview = truncate_string(strip_tags($line["content_preview"]),
070d0d2a 1091 100);
adccd201
AD
1092 }
1093
386cbf27 1094 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201
AD
1095
1096 print "<tr class='$class' id='RROW-$id'>";
adccd201
AD
1097
1098 print "<td class='hlUpdatePic'>$update_pic</td>";
1099
1100 print "<td class='hlSelectRow'>
1101 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1102 class=\"feedCheckBox\" id=\"RCHK-$id\">
1103 </td>";
1104
1105 print "<td class='hlMarkedPic'>$marked_pic</td>";
1106
1107 if ($line["feed_title"]) {
1108 print "<td class='hlContent'>$content_link</td>";
1109 print "<td class='hlFeed'>
9b1424fe
AD
1110 <a href='javascript:viewfeed($feed_id)'>".
1111 $line["feed_title"]."</a>&nbsp;</td>";
adccd201 1112 } else {
de244d27 1113 print "<td class='hlContent' valign='middle'>";
adccd201 1114
e454a889 1115 print "<a href=\"javascript:view($id,$feed_id);\">" .
adccd201
AD
1116 $line["title"];
1117
70f6dbb1 1118 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
adccd201
AD
1119 if ($content_preview) {
1120 print "<span class=\"contentPreview\"> - $content_preview</span>";
1121 }
1122 }
1123
1124 print "</a>";
1125 print "</td>";
1126 }
1127
1128 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1129
1130 print "</tr>";
1131
1132 } else {
386cbf27
AD
1133
1134 if ($is_unread) {
1135 $add_class = "Unread";
1136 } else {
1137 $add_class = "";
1138 }
1139
1140 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1141
1142 print "<div class=\"cdmHeader\">";
adccd201 1143
386cbf27
AD
1144 print "<div style=\"float : right\">$updated_fmt</div>";
1145
86383df6 1146 print "<a target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
adccd201 1147
386cbf27
AD
1148 if ($line["feed_title"]) {
1149 print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
adccd201 1150 }
adccd201 1151
386cbf27
AD
1152 print "</div>";
1153
1154 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1155
1156 print "<div style=\"float : right\">$marked_pic</div>
1157 <div class=\"cdmFooter\">
1158 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1159 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1160
1161 print "</div>";
1162
1163 }
e5a99b88
AD
1164
1165 ++$lnum;
254e0e4b 1166 }
adccd201 1167
386cbf27 1168 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201 1169 print "</table>";
adccd201 1170 }
d76a3b03 1171
e0a7121b 1172 print_headline_subtoolbar($link,
f90372c4 1173 "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
98bea1b1
AD
1174
1175
e5a99b88
AD
1176 } else {
1177 print "<div width='100%' align='center'>No articles found.</div>";
a1a8a2be 1178 }
d76a3b03 1179
386cbf27 1180 print "</div>";
d76a3b03 1181
386cbf27
AD
1182 print "<script type=\"text/javascript\">
1183 document.onkeydown = hotkey_handler;
5a494a0b 1184 // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
386cbf27
AD
1185 update_all_counters('$feed');
1186 </script>";
adccd201 1187
97dcd654
AD
1188 print '
1189 <script type="text/javascript">
1190 /* for IE */
1191 function statechange() {
1192 if (document.readyState == "interactive") init();
1193 }
1194
1195 if (document.readyState) {
1196 if (document.readyState == "interactive" || document.readyState == "complete") {
1197 init();
1198 } else {
1199 document.onreadystatechange = statechange;
1200 }
1201 }
1202 </script>';
1203
59b8192f 1204 print "</body></html>";
1cd17194
AD
1205 }
1206
0e091d38 1207 if ($op == "pref-rpc") {
331900c6 1208
0e091d38 1209 $subop = $_GET["subop"];
331900c6 1210
83fe4d6d 1211 if ($subop == "unread") {
f932bc9f 1212 $ids = split(",", db_escape_string($_GET["ids"]));
83fe4d6d 1213 foreach ($ids as $id) {
a5873b2e
AD
1214 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1215 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1216 }
0e091d38 1217
a5873b2e 1218 print "Marked selected feeds as unread.";
83fe4d6d
AD
1219 }
1220
1221 if ($subop == "read") {
f932bc9f 1222 $ids = split(",", db_escape_string($_GET["ids"]));
83fe4d6d 1223 foreach ($ids as $id) {
a5873b2e
AD
1224 db_query($link, "UPDATE ttrss_user_entries
1225 SET unread = false,last_read = NOW() WHERE
1226 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1227 }
0e091d38 1228
a5873b2e 1229 print "Marked selected feeds as read.";
0e091d38
AD
1230
1231 }
1232
1233 }
1234
1235 if ($op == "pref-feeds") {
1236
47c6c988
AD
1237 $subop = $_REQUEST["subop"];
1238 $quiet = $_REQUEST["quiet"];
0e091d38 1239
a0476535
AD
1240 if ($subop == "massSubscribe") {
1241 $ids = split(",", db_escape_string($_GET["ids"]));
1242
a7f22b70
AD
1243 $subscribed = array();
1244
a0476535
AD
1245 foreach ($ids as $id) {
1246 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1247 WHERE id = '$id'");
1248
1249 $feed_url = db_fetch_result($result, 0, "feed_url");
1250 $title = db_fetch_result($result, 0, "title");
1251
1252 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1253 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1254
1255 if (db_num_rows($result) == 0) {
1256 $result = db_query($link,
1257 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1258 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
a7f22b70
AD
1259
1260 array_push($subscribed, $title);
1261 }
1262 }
1263
1264 if (count($subscribed) > 0) {
1265 print "<div class=\"notice\">";
1266 print "<b>Subscribed to feeds:</b>";
1267 print "<ul class=\"nomarks\">";
1268 foreach ($subscribed as $title) {
1269 print "<li>$title</li>";
a0476535 1270 }
a7f22b70
AD
1271 print "</ul>";
1272 print "</div>";
a0476535
AD
1273 }
1274 }
1275
f9cb39ac 1276 if ($subop == "browse") {
e2f728be
AD
1277
1278 if (!ENABLE_FEED_BROWSER) {
1279 print "Feed browser is administratively disabled.";
1280 return;
1281 }
f9cb39ac
AD
1282
1283 print "<div class=\"infoBoxContents\">";
1284
1285 print "<h1>Feed browser</h1>";
1286
1287 print "<p>Showing top 50 registered feeds, sorted by popularity:</p>";
1288
1289 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
e3c99f3b
AD
1290 FROM ttrss_feeds
1291 WHERE auth_login = '' AND auth_pass = '' AND private = false
24b18114 1292 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50");
f9cb39ac
AD
1293
1294 print "<ul class='browseFeedList' id='browseFeedList'>";
dc932d0a
AD
1295
1296 $feedctr = 0;
f9cb39ac
AD
1297
1298 while ($line = db_fetch_assoc($result)) {
1299 $feed_url = $line["feed_url"];
1300 $subscribers = $line["subscribers"];
dc932d0a
AD
1301
1302 $sub_result = db_query($link, "SELECT id
1303 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
1304 $_SESSION["uid"]);
1305
1306 if (db_num_rows($sub_result) > 0) {
1307 continue; // already subscribed
1308 }
f9cb39ac
AD
1309
1310 $det_result = db_query($link, "SELECT site_url,title,id
1311 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1312
1313 $details = db_fetch_assoc($det_result);
1314
1315 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1316
1317 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1318 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1319 "/".$details["id"].".ico\">";
1320 } else {
1321 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1322 }
1323
b92e6209
AD
1324 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1325 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
f9cb39ac 1326
b92e6209
AD
1327 $class = ($feedctr % 2) ? "even" : "odd";
1328
1329 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1330 "$feed_icon " . db_unescape_string($details["title"]) .
f9cb39ac 1331 "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
dc932d0a
AD
1332
1333 ++$feedctr;
1334 }
1335
1336 if ($feedctr == 0) {
1337 print "<li>No feeds found to subscribe.</li>";
1338 }
f9cb39ac
AD
1339
1340 print "</ul>";
1341
1342 print "<div align='center'>
f9cb39ac 1343 <input type=\"submit\" class=\"button\"
d10fabe4
AD
1344 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1345 <input type='submit' class='button'
1346 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
f9cb39ac
AD
1347
1348 print "</div>";
1349 return;
1350 }
1351
0ea4fb50
AD
1352 if ($subop == "editfeed") {
1353 $feed_id = db_escape_string($_GET["id"]);
1354
1355 $result = db_query($link,
1356 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1357 owner_uid = " . $_SESSION["uid"]);
1358
1359 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1360 0, "title")));
1361
1362 print "<div class=\"infoBoxContents\">";
1363
1364 $icon_file = ICONS_DIR . "/$feed_id.ico";
1365
1366 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1367 $feed_icon = "<img width=\"16\" height=\"16\"
1368 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1369 } else {
1370 $feed_icon = "";
1371 }
1372
1373 print "<h1>$feed_icon $title</h1>";
1374
1375 print "<table width='100%'>";
1376
1377 $row_class = "odd";
1378
1379 print "<tr class='$row_class'><td>Title:</td>";
1380 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1381
1382 $feed_url = db_fetch_result($result, 0, "feed_url");
1383 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1384 0, "feed_url")));
1385 $row_class = toggleEvenOdd($row_class);
1386
1387 print "<tr class='$row_class'><td>Feed URL:</td>";
1388 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
ad815c71 1389
0ea4fb50
AD
1390 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1391
1392 $cat_id = db_fetch_result($result, 0, "cat_id");
1393
1394 $row_class = toggleEvenOdd($row_class);
1395
1396 print "<tr class='$row_class'><td>Category:</td>";
1397 print "<td>";
1398 print "<select id=\"iedit_fcat\">";
1399 print "<option id=\"0\">Uncategorized</option>";
1400
1401 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1402 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1403
1404 if (db_num_rows($tmp_result) > 0) {
1405 print "<option disabled>--------</option>";
1406 }
1407
1408 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1409 if ($tmp_line["id"] == $cat_id) {
1410 $is_selected = "selected";
1411 } else {
1412 $is_selected = "";
1413 }
1414 printf("<option $is_selected id='%d'>%s</option>",
1415 $tmp_line["id"], $tmp_line["title"]);
1416 }
1417
1418 print "</select></td>";
1419 print "</td></tr>";
1420
1421 }
1422
1423 $update_interval = db_fetch_result($result, 0, "update_interval");
1424 $row_class = toggleEvenOdd($row_class);
1425
1426 print "<tr class='$row_class'><td>Update Interval:</td>";
ad815c71
AD
1427// print "<td><input id=\"iedit_updintl\"
1428// value=\"$update_interval\"></td></tr>";
1429
1430 print "<td>";
1431
1432 print "<select id=\"iedit_updintl\">";
1433
1434 foreach (array_keys($update_intervals) as $i) {
1435
1436 if ($i == $update_interval) {
1437 $selected = "selected";
1438 } else {
1439 $selected = "";
1440 }
1441 print "<option $selected id=\"$i\">" . $update_intervals[$i] . "</option>";
1442 }
1443
1444 print "</select>";
1445
1446 print "</td>";
0ea4fb50 1447
1da7e457
AD
1448 $row_class = toggleEvenOdd($row_class);
1449 print "<tr class='$row_class'><td>Link to:</td>";
1450
3b0027a4
AD
1451 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1452 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1453
1454 $linked_count = db_fetch_result($tmp_result, 0, "count");
1455
1da7e457 1456 $parent_feed = db_fetch_result($result, 0, "parent_feed");
3b0027a4
AD
1457
1458 if ($linked_count > 0) {
1459 $disabled = "disabled";
1460 }
1461
1462 print "<select $disabled id=\"iedit_parent_feed\">";
1463
eac46afb 1464 print "<option id=\"0\">Not linked</option>";
1da7e457 1465
8a53e029
AD
1466 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1467 if ($cat_id) {
1468 $cat_qpart = "AND cat_id = '$cat_id'";
1469 } else {
1470 $cat_qpart = "AND cat_id IS NULL";
1471 }
1472 }
1473
1da7e457 1474 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
262c2426
AD
1475 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1476 $cat_qpart ORDER BY title");
1da7e457
AD
1477
1478 if (db_num_rows($tmp_result) > 0) {
1479 print "<option disabled>--------</option>";
1480 }
1481
1482 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1483 if ($tmp_line["id"] == $parent_feed) {
1484 $is_selected = "selected";
1485 } else {
1486 $is_selected = "";
1487 }
1488 printf("<option $is_selected id='%d'>%s</option>",
1489 $tmp_line["id"], $tmp_line["title"]);
1490 }
1491
1492 print "</select></td>";
1493 print "</td></tr>";
1494
0ea4fb50
AD
1495 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1496 $row_class = toggleEvenOdd($row_class);
1497
1498 print "<tr class='$row_class'><td>Purge Days:</td>";
ad815c71
AD
1499// print "<td><input id=\"iedit_purgintl\"
1500// value=\"$purge_interval\"></td></tr>";
1501
1502 print "<td>";
1503
1504 print "<select id=\"iedit_purgintl\">";
1505
1506 foreach (array_keys($purge_intervals) as $i) {
1507
1508 if ($i == $purge_interval) {
1509 $selected = "selected";
1510 } else {
1511 $selected = "";
1512 }
1513 print "<option $selected id=\"$i\">" . $purge_intervals[$i] . "</option>";
1514 }
1515
1516 print "</select>";
1517
1518 print "</td>";
0ea4fb50 1519
47c6c988
AD
1520// print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1521
1522 $row_class = toggleEvenOdd($row_class);
1523 $auth_login = db_fetch_result($result, 0, "auth_login");
1524
1525 print "<tr class='$row_class'><td>Login:</td>";
1526 print "<td><input id=\"iedit_login\"
1527 value=\"$auth_login\"></td></tr>";
1528
1529 $row_class = toggleEvenOdd($row_class);
1530 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1531
1532 print "<tr class='$row_class'><td>Password:</td>";
1533 print "<td><input type=\"password\" id=\"iedit_pass\"
1534 value=\"$auth_pass\"></td></tr>";
1535
e3c99f3b
AD
1536 $row_class = toggleEvenOdd($row_class);
1537 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1538
1539 if ($private) {
1540 $checked = "checked";
1541 } else {
1542 $checked = "";
1543 }
1544
991ee9e2 1545 print "<tr class='$row_class'><td valign='top'>Options:</td>";
e3c99f3b 1546 print "<td><input type=\"checkbox\" id=\"iedit_private\"
70f6dbb1
AD
1547 $checked><label for=\"iedit_private\">Hide from feed browser</label>";
1548
1549 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1550
1551 if ($rtl_content) {
1552 $checked = "checked";
1553 } else {
1554 $checked = "";
1555 }
1556
1557 print "<br><input type=\"checkbox\" id=\"iedit_rtl\"
1558 $checked><label for=\"iedit_rtl\">Right-to-left content</label>";
1559
1560 print "</td></tr>";
e3c99f3b 1561
0ea4fb50
AD
1562 print "</table>";
1563 print "</div>";
1564
1565 print "<div align='center'>
0ea4fb50 1566 <input type=\"submit\" class=\"button\"
d10fabe4
AD
1567 onclick=\"feedEditSave()\" value=\"Save\">
1568 <input type='submit' class='button'
1569 onclick=\"feedEditCancel()\" value=\"Cancel\"></div>";
0ea4fb50
AD
1570 return;
1571 }
1572
508a81e1 1573 if ($subop == "editSave") {
47c6c988
AD
1574 $feed_title = db_escape_string($_POST["t"]);
1575 $feed_link = db_escape_string($_POST["l"]);
1576 $upd_intl = db_escape_string($_POST["ui"]);
1577 $purge_intl = db_escape_string($_POST["pi"]);
1578 $feed_id = db_escape_string($_POST["id"]);
1579 $cat_id = db_escape_string($_POST["catid"]);
1580 $auth_login = db_escape_string($_POST["login"]);
1581 $auth_pass = db_escape_string($_POST["pass"]);
1da7e457 1582 $parent_feed = db_escape_string($_POST["pfeed"]);
19ded366 1583 $private = db_escape_string($_POST["is_pvt"]);
70f6dbb1 1584 $rtl_content = db_escape_string($_POST["is_rtl"]);
508a81e1 1585
d148926e
AD
1586 if (strtoupper($upd_intl) == "DEFAULT")
1587 $upd_intl = 0;
1588
a88c1f36
AD
1589 if (strtoupper($upd_intl) == "DISABLED")
1590 $upd_intl = -1;
1591
5d73494a
AD
1592 if (strtoupper($purge_intl) == "DEFAULT")
1593 $purge_intl = 0;
1594
140aae81
AD
1595 if (strtoupper($purge_intl) == "DISABLED")
1596 $purge_intl = -1;
1597
91ff844a
AD
1598 if ($cat_id != 0) {
1599 $category_qpart = "cat_id = '$cat_id'";
1600 } else {
1601 $category_qpart = 'cat_id = NULL';
1602 }
1603
1da7e457
AD
1604 if ($parent_feed != 0) {
1605 $parent_qpart = "parent_feed = '$parent_feed'";
1606 } else {
1607 $parent_qpart = 'parent_feed = NULL';
1608 }
1609
648472a7 1610 $result = db_query($link, "UPDATE ttrss_feeds SET
91ff844a 1611 $category_qpart,
1da7e457 1612 $parent_qpart,
d148926e 1613 title = '$feed_title', feed_url = '$feed_link',
5d73494a 1614 update_interval = '$upd_intl',
47c6c988
AD
1615 purge_interval = '$purge_intl',
1616 auth_login = '$auth_login',
e3c99f3b 1617 auth_pass = '$auth_pass',
ac92cb46
AD
1618 private = $private,
1619 rtl_content = $rtl_content
1620 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
5ddadb4c
AD
1621 }
1622
1623 if ($subop == "saveCat") {
1624 $cat_title = db_escape_string($_GET["title"]);
1625 $cat_id = db_escape_string($_GET["id"]);
1626
1627 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1628 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
508a81e1 1629
83fe4d6d
AD
1630 }
1631
331900c6 1632 if ($subop == "remove") {
331900c6 1633
b0b4abcf 1634 if (!WEB_DEMO_MODE) {
331900c6 1635
f932bc9f 1636 $ids = split(",", db_escape_string($_GET["ids"]));
b0b4abcf
AD
1637
1638 foreach ($ids as $id) {
f72dbbde
AD
1639 db_query($link, "DELETE FROM ttrss_feeds
1640 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
4769ddaf 1641
273a2f6b 1642 $icons_dir = ICONS_DIR;
d5caaae5 1643
4769ddaf
AD
1644 if (file_exists($icons_dir . "/$id.ico")) {
1645 unlink($icons_dir . "/$id.ico");
d5caaae5 1646 }
b0b4abcf 1647 }
331900c6
AD
1648 }
1649 }
1650
1651 if ($subop == "add") {
b0b4abcf
AD
1652
1653 if (!WEB_DEMO_MODE) {
331900c6 1654
b6b535ca 1655 $feed_link = db_escape_string(trim($_GET["link"]));
15da5cc1
AD
1656 $cat_id = db_escape_string($_GET["cid"]);
1657
5edfe303 1658 if ($cat_id == "0" || !$cat_id) {
15da5cc1
AD
1659 $cat_qpart = "NULL";
1660 } else {
1661 $cat_qpart = "'$cat_id'";
1662 }
331900c6 1663
648472a7 1664 $result = db_query($link,
7e9a3986
AD
1665 "SELECT id FROM ttrss_feeds
1666 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1667
1668 if (db_num_rows($result) == 0) {
1669
1670 $result = db_query($link,
15da5cc1 1671 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
746b249f
AD
1672 VALUES ('".$_SESSION["uid"]."', '$feed_link',
1673 '[Unknown]', $cat_qpart)");
331900c6 1674
7e9a3986 1675 $result = db_query($link,
746b249f 1676 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
7e9a3986
AD
1677 AND owner_uid = " . $_SESSION["uid"]);
1678
1679 $feed_id = db_fetch_result($result, 0, "id");
1680
1681 if ($feed_id) {
ddb68b81 1682 update_rss_feed($link, $feed_link, $feed_id, true);
7e9a3986
AD
1683 }
1684 } else {
331900c6 1685
7e9a3986
AD
1686 print "<div class=\"warning\">
1687 Feed <b>$feed_link</b> already exists in the database.
1688 </div>";
b0b4abcf
AD
1689 }
1690 }
331900c6 1691 }
a0d53889 1692
91ff844a
AD
1693 if ($subop == "addCat") {
1694
1695 if (!WEB_DEMO_MODE) {
1696
1697 $feed_cat = db_escape_string(trim($_GET["cat"]));
1698
1699 $result = db_query($link,
1700 "SELECT id FROM ttrss_feed_categories
1701 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1702
1703 if (db_num_rows($result) == 0) {
1704
1705 $result = db_query($link,
1706 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1707 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1708
1709 } else {
1710
1711 print "<div class=\"warning\">
1712 Category <b>$feed_cat</b> already exists in the database.
1713 </div>";
1714 }
1715
1716
1717 }
1718 }
1719
1720 if ($subop == "removeCats") {
1721
1722 if (!WEB_DEMO_MODE) {
1723
f932bc9f 1724 $ids = split(",", db_escape_string($_GET["ids"]));
91ff844a
AD
1725
1726 foreach ($ids as $id) {
1727
1728 db_query($link, "BEGIN");
1729
1730 $result = db_query($link,
1731 "SELECT count(id) as num_feeds FROM ttrss_feeds
1732 WHERE cat_id = '$id'");
1733
1734 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1735
1736 if ($num_feeds == 0) {
1737 db_query($link, "DELETE FROM ttrss_feed_categories
1738 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1739 } else {
1740
1741 print "<div class=\"warning\">
1742 Unable to delete non empty feed categories.</div>";
1743
1744 }
1745
1746 db_query($link, "COMMIT");
1747 }
1748 }
1749 }
1750
f932bc9f
AD
1751 if ($subop == "categorize") {
1752
1753 if (!WEB_DEMO_MODE) {
1754
1755 $ids = split(",", db_escape_string($_GET["ids"]));
1756
1757 $cat_id = db_escape_string($_GET["cat_id"]);
1758
1759 if ($cat_id == 0) {
1760 $cat_id_qpart = 'NULL';
1761 } else {
1762 $cat_id_qpart = "'$cat_id'";
1763 }
1764
1765 db_query($link, "BEGIN");
1766
1767 foreach ($ids as $id) {
1768
1769 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1770 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1771 }
1772
1773 db_query($link, "COMMIT");
1774 }
1775
1776 }
1777
a24f525c
AD
1778 if ($quiet) return;
1779
c64d5b03 1780// print "<h3>Edit Feeds</h3>";
91ff844a 1781
4904f845
AD
1782 $result = db_query($link, "SELECT id,title,feed_url,last_error
1783 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1784
1785 if (db_num_rows($result) > 0) {
1786
1787 print "<div class=\"warning\">";
a9b0bfd5
AD
1788
1789// print"<img class=\"closeButton\"
1790// onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1791
36aab70f
AD
1792 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1793 <b>Feeds with update errors</b> (click to expand)</a>";
4904f845 1794
36aab70f 1795 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
4904f845
AD
1796
1797 while ($line = db_fetch_assoc($result)) {
1798 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1799 $line["last_error"];
1800 }
1801
1802 print "</ul>";
1803 print "</div>";
1804
1805 }
1806
f932bc9f
AD
1807 $feed_search = db_escape_string($_GET["search"]);
1808
1809 if (array_key_exists("search", $_GET)) {
1810 $_SESSION["prefs_feed_search"] = $feed_search;
1811 } else {
1812 $feed_search = $_SESSION["prefs_feed_search"];
1813 }
1814
1815 print "<table width='100%' class=\"prefGenericAddBox\"
1816 cellspacing='0' cellpadding='0'><tr>
1817 <td>
1818 <input id=\"fadd_link\"
1819 onchange=\"javascript:addFeed()\"
1820 size=\"40\">
1821 <input type=\"submit\" class=\"button\"
e2f728be
AD
1822 onclick=\"javascript:addFeed()\" value=\"Add feed\">";
1823
1824 if (ENABLE_FEED_BROWSER) {
1825 print "&nbsp;(<a href='javascript:browseFeeds()'>Top 50</a>)";
1826 }
1827
1828 print "</td><td align='right'>
f932bc9f
AD
1829 <input id=\"feed_search\" size=\"20\"
1830 onchange=\"javascript:updateFeedList()\"
1831 value=\"$feed_search\">
1832 <input type=\"submit\" class=\"button\"
1833 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1834 </td>
1835 </tr></table>";
a0d53889 1836
b83c7545
AD
1837 $feeds_sort = db_escape_string($_GET["sort"]);
1838
1839 if (!$feeds_sort || $feeds_sort == "undefined") {
1840 $feeds_sort = $_SESSION["pref_sort_feeds"];
1841 if (!$feeds_sort) $feeds_sort = "title";
1842 }
1843
1844 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1845
f932bc9f 1846 if ($feed_search) {
11de82c3
AD
1847 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1848 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
f932bc9f
AD
1849 } else {
1850 $search_qpart = "";
1851 }
1852
648472a7 1853 $result = db_query($link, "SELECT
db42b934
AD
1854 F1.id,
1855 F1.title,
1856 F1.feed_url,
1857 substring(F1.last_updated,1,16) AS last_updated,
1858 F1.parent_feed,
1859 F1.update_interval,
1860 F1.purge_interval,
1861 F1.cat_id,
1862 F2.title AS parent_title,
1863 C1.title AS category
c0e5a40e 1864 FROM
db42b934
AD
1865 ttrss_feeds AS F1
1866 LEFT JOIN ttrss_feeds AS F2
1867 ON (F1.parent_feed = F2.id)
1868 LEFT JOIN ttrss_feed_categories AS C1
1869 ON (F1.cat_id = C1.id)
f932bc9f 1870 WHERE
db42b934 1871 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
0ea4fb50 1872 ORDER by category,$feeds_sort,title");
1cd17194 1873
3b0feb9b 1874 if (db_num_rows($result) != 0) {
91ff844a 1875
3b0feb9b 1876 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
35f3c923 1877
f4fe2cde
AD
1878 print "<p><table width=\"100%\" cellspacing=\"0\"
1879 class=\"prefFeedList\" id=\"prefFeedList\">";
35f3c923
AD
1880 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1881 Select:
1882 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 1883 'FEEDR-', 'FRCHK-', true)\">All</a>,
35f3c923 1884 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 1885 'FEEDR-', 'FRCHK-', false)\">None</a>
35f3c923
AD
1886 </td</tr>";
1887
0ea4fb50
AD
1888 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1889 print "<tr class=\"title\">
e325c6e7 1890 <td width='5%' align='center'>&nbsp;</td>
01b3e191
AD
1891 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1892 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1893 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
603c27f8 1894 }
603c27f8 1895
c64d5b03 1896 $lnum = 0;
0ea4fb50
AD
1897
1898 $cur_cat_id = -1;
c64d5b03
AD
1899
1900 while ($line = db_fetch_assoc($result)) {
1901
3b0feb9b 1902 $feed_id = $line["id"];
0ea4fb50
AD
1903 $cat_id = $line["cat_id"];
1904
1905 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1906 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1907 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
0ea4fb50
AD
1908
1909 if (!$edit_cat) $edit_cat = "Uncategorized";
1910
01b3e191
AD
1911 $last_updated = $line["last_updated"];
1912
1913 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1914 $last_updated = smart_date_time(strtotime($last_updated));
1915 } else {
1916 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1917 $last_updated = date($short_date, strtotime($last_updated));
1918 }
1919
0ea4fb50 1920 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
cb58d0df
AD
1921 $lnum = 0;
1922
0ea4fb50
AD
1923 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1924
1925 print "<tr class=\"title\">
e325c6e7 1926 <td width='5%' align='center'>&nbsp;</td>
01b3e191
AD
1927 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1928 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1929 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
0ea4fb50
AD
1930
1931 $cur_cat_id = $cat_id;
c64d5b03 1932 }
0ea4fb50 1933
cb58d0df 1934 $class = ($lnum % 2) ? "even" : "odd";
0ea4fb50
AD
1935 $this_row_id = "id=\"FEEDR-$feed_id\"";
1936
53226edc 1937 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1938
1939 $icon_file = ICONS_DIR . "/$feed_id.ico";
1940
1941 if (file_exists($icon_file) && filesize($icon_file) > 0) {
327a3bbe 1942 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
3b0feb9b 1943 } else {
327a3bbe 1944 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3b0feb9b 1945 }
327a3bbe 1946// print "<td class='feedIcon'>$feed_icon</td>";
c64d5b03 1947
62ac0cc8 1948 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
0ea4fb50 1949 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
3547842a 1950
0ea4fb50
AD
1951 $edit_title = truncate_string($edit_title, 40);
1952 $edit_link = truncate_string($edit_link, 60);
a88c1f36 1953
1da7e457
AD
1954 $parent_title = $line["parent_title"];
1955 if ($parent_title) {
1956 $parent_title = "<span class='groupPrompt'>(linked to
1957 $parent_title)</span>";
1958 }
1959
0ea4fb50 1960 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1da7e457 1961 "$feed_icon $edit_title $parent_title" . "</a></td>";
0ea4fb50
AD
1962
1963 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1964 $edit_link . "</a></td>";
3547842a 1965
0ea4fb50
AD
1966/* if (get_pref($link, 'ENABLE_FEED_CATS')) {
1967 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1968 $edit_cat . "</a></td>";
1969 } */
3547842a 1970
01b3e191 1971/* print "<td><a href=\"javascript:editFeed($feed_id);\">" .
ad815c71 1972 $update_intervals[$line["update_interval"]] . "</a></td>";
3b0feb9b 1973
0ea4fb50 1974 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
01b3e191
AD
1975 $purge_intervals[$line["purge_interval"]] . "</a></td>"; */
1976
1977 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1978 "$last_updated</a></td>";
1979
c64d5b03
AD
1980 print "</tr>";
1981
1982 ++$lnum;
1983 }
1984
c64d5b03 1985 print "</table>";
3b0feb9b 1986
c64d5b03
AD
1987 print "<p>";
1988
3b0feb9b
AD
1989 if ($subop == "edit") {
1990 print "Edit feed:&nbsp;
c64d5b03 1991 <input type=\"submit\" class=\"button\"
3b0feb9b 1992 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
c64d5b03 1993 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1994 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1995 } else {
c64d5b03
AD
1996
1997 print "
1998 Selection:&nbsp;
1999 <input type=\"submit\" class=\"button\"
3b0feb9b 2000 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
c64d5b03 2001 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2002 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2003 <input type=\"submit\" class=\"button\"
2004 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
f932bc9f
AD
2005
2006 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2007
2008 print "&nbsp;&nbsp;";
2009
2010 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2011 WHERE owner_uid = ".$_SESSION["uid"]."
2012 ORDER BY title");
2013
2014 print "<select id=\"sfeed_set_fcat\">";
2015 print "<option id=\"0\">Uncategorized</option>";
2016
2017 if (db_num_rows($result) != 0) {
2018
2019 print "<option disabled>--------</option>";
2020
2021 while ($line = db_fetch_assoc($result)) {
2022 printf("<option id='%d'>%s</option>",
2023 $line["id"], $line["title"]);
2024 }
2025 }
2026
2027 print "</select>";
2028
2029 print " <input type=\"submit\" class=\"button\"
2030 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2031
2032 }
3b0feb9b
AD
2033
2034 print "
f932bc9f 2035 &nbsp;All feeds: <input type=\"submit\"
3b0feb9b
AD
2036 class=\"button\" onclick=\"gotoExportOpml()\"
2037 value=\"Export OPML\">";
2038 }
2039 } else {
2040
2041 print "<p>No feeds defined.</p>";
2042
2043 }
2044
2045 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2046
2047 print "<h3>Edit Categories</h3>";
2048
2049 // print "<h3>Categories</h3>";
2050
2051 print "<div class=\"prefGenericAddBox\">
f932bc9f
AD
2052 <input id=\"fadd_cat\"
2053 onchange=\"javascript:addFeedCat()\"
2054 size=\"40\">&nbsp;
2055 <input
3b0feb9b
AD
2056 type=\"submit\" class=\"button\"
2057 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2058
2059 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2060 WHERE owner_uid = ".$_SESSION["uid"]."
2061 ORDER BY title");
2062
2063 if (db_num_rows($result) != 0) {
2064
35f3c923 2065 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
f4fe2cde 2066 cellspacing=\"0\" id=\"prefFeedCatList\">";
35f3c923
AD
2067
2068 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2069 Select:
2070 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 2071 'FCATR-', 'FCCHK-', true)\">All</a>,
35f3c923 2072 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 2073 'FCATR-', 'FCCHK-', false)\">None</a>
35f3c923
AD
2074 </td</tr>";
2075
3b0feb9b 2076 print "<tr class=\"title\">
a426e532 2077 <td width=\"5%\"></td><td width=\"80%\">Title</td>
3b0feb9b
AD
2078 </tr>";
2079
2080 $lnum = 0;
2081
2082 while ($line = db_fetch_assoc($result)) {
2083
2084 $class = ($lnum % 2) ? "even" : "odd";
2085
2086 $cat_id = $line["id"];
2087
2088 $edit_cat_id = $_GET["id"];
2089
2090 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2091 $class .= "Grayed";
53226edc
AD
2092 $this_row_id = "";
2093 } else {
2094 $this_row_id = "id=\"FCATR-$cat_id\"";
3b0feb9b
AD
2095 }
2096
53226edc 2097 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2098
2099 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2100
2101 if (!$edit_cat_id || $subop != "editCat") {
2102
a426e532 2103 print "<td align='center'><input onclick='toggleSelectRow(this);'
3b0feb9b
AD
2104 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2105
2106 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2107 $edit_title . "</a></td>";
2108
2109 } else if ($cat_id != $edit_cat_id) {
2110
2111 print "<td><input disabled=\"true\" type=\"checkbox\"
2112 id=\"FRCHK-".$line["id"]."\"></td>";
2113
2114 print "<td>$edit_title</td>";
2115
2116 } else {
2117
2118 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2119
2120 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2121
2122 }
2123
2124 print "</tr>";
2125
2126 ++$lnum;
2127 }
2128
2129 print "</table>";
2130
2131 print "<p>";
2132
2133 if ($subop == "editCat") {
2134 print "Edit category:&nbsp;
2135 <input type=\"submit\" class=\"button\"
2136 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2137 <input type=\"submit\" class=\"button\"
2138 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2139 } else {
2140
2141 print "
2142 Selection:&nbsp;
2143 <input type=\"submit\" class=\"button\"
2144 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2145 <input type=\"submit\" class=\"button\"
2146 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2147
2148 }
2149
2150 } else {
2151 print "<p>No feed categories defined.</p>";
2152 }
c64d5b03
AD
2153 }
2154
2155 print "<h3>Import OPML</h3>
f5a50b25
AD
2156 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2157 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
2158 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2159 type=\"submit\" value=\"Import\">
2160 </form>";
2161
007bda35
AD
2162 }
2163
a0d53889
AD
2164 if ($op == "pref-filters") {
2165
2166 $subop = $_GET["subop"];
a24f525c 2167 $quiet = $_GET["quiet"];
a0d53889
AD
2168
2169 if ($subop == "editSave") {
a0d53889 2170
648472a7 2171 $regexp = db_escape_string($_GET["r"]);
648472a7
AD
2172 $match = db_escape_string($_GET["m"]);
2173 $filter_id = db_escape_string($_GET["id"]);
ead60402 2174 $feed_id = db_escape_string($_GET["fid"]);
19c9cb11 2175 $action_id = db_escape_string($_GET["aid"]);
ead60402
AD
2176
2177 if (!$feed_id) {
2178 $feed_id = 'NULL';
2179 } else {
2180 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2181 }
0afbd851 2182
648472a7 2183 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 2184 reg_exp = '$regexp',
ead60402 2185 feed_id = $feed_id,
19c9cb11 2186 action_id = '$action_id',
0afbd851
AD
2187 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2188 description = '$match')
2189 WHERE id = '$filter_id'");
a0d53889
AD
2190 }
2191
2192 if ($subop == "remove") {
2193
2194 if (!WEB_DEMO_MODE) {
2195
f932bc9f 2196 $ids = split(",", db_escape_string($_GET["ids"]));
a0d53889
AD
2197
2198 foreach ($ids as $id) {
648472a7 2199 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
2200
2201 }
2202 }
2203 }
2204
2205 if ($subop == "add") {
2206
de435974 2207 if (!WEB_DEMO_MODE) {
a0d53889 2208
b6b535ca
AD
2209 $regexp = db_escape_string(trim($_GET["regexp"]));
2210 $match = db_escape_string(trim($_GET["match"]));
ead60402 2211 $feed_id = db_escape_string($_GET["fid"]);
19c9cb11 2212 $action_id = db_escape_string($_GET["aid"]);
ead60402
AD
2213
2214 if (!$feed_id) {
2215 $feed_id = 'NULL';
2216 } else {
2217 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2218 }
4401bf04 2219
648472a7 2220 $result = db_query($link,
19c9cb11
AD
2221 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2222 action_id)
2223 VALUES
de435974 2224 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
19c9cb11
AD
2225 description = '$match'),'".$_SESSION["uid"]."',
2226 $feed_id, '$action_id')");
de435974 2227 }
a0d53889
AD
2228 }
2229
a24f525c
AD
2230 if ($quiet) return;
2231
648472a7 2232 $result = db_query($link, "SELECT description
a0d53889
AD
2233 FROM ttrss_filter_types ORDER BY description");
2234
2235 $filter_types = array();
2236
648472a7 2237 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
2238 array_push($filter_types, $line["description"]);
2239 }
2240
2c7070b5 2241 print "<div class=\"prefGenericAddBox\">
7cc1e5d6 2242 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2c7070b5 2243
ead60402
AD
2244 print_select("fadd_match", "Title", $filter_types);
2245
2246 print "&nbsp;<select id=\"fadd_feed\">";
2247
2248 print "<option selected id=\"0\">All feeds</option>";
2249
2250 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2251 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2252
2253 if (db_num_rows($result) > 0) {
2254 print "<option disabled>--------</option>";
2255 }
2256
2257 while ($line = db_fetch_assoc($result)) {
2258 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2259 }
2260
2c7070b5 2261 print "</select>&nbsp;";
19c9cb11
AD
2262
2263 print "&nbsp;Action: ";
2264
2265 print "<select id=\"fadd_action\">";
2266
2267 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2268 ORDER BY name");
2269
2270 while ($line = db_fetch_assoc($result)) {
2271 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2272 }
2273
2274 print "</select>&nbsp;";
2275
9323147e
AD
2276/* print "<input type=\"submit\"
2277 class=\"button\" onclick=\"javascript:testFilter()\"
2278 value=\"Test filter\"> "; */
2279
2c7070b5
AD
2280 print "<input type=\"submit\"
2281 class=\"button\" onclick=\"javascript:addFilter()\"
2282 value=\"Add filter\">";
a0d53889 2283
19c9cb11
AD
2284 print "</div>";
2285
648472a7 2286 $result = db_query($link, "SELECT
ead60402 2287 ttrss_filters.id AS id,reg_exp,
ead60402
AD
2288 ttrss_filter_types.name AS filter_type_name,
2289 ttrss_filter_types.description AS filter_type_descr,
2290 feed_id,
19c9cb11 2291 ttrss_filter_actions.description AS action_description,
11de82c3 2292 ttrss_feeds.title AS feed_title
a0d53889 2293 FROM
5890c3f4
AD
2294 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2295 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
4356293a 2296 WHERE
ead60402 2297 filter_type = ttrss_filter_types.id AND
19c9cb11 2298 ttrss_filter_actions.id = action_id AND
ead60402 2299 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
4356293a 2300 ORDER by reg_exp");
a0d53889 2301
3b0feb9b 2302 if (db_num_rows($result) != 0) {
a0d53889 2303
f4fe2cde
AD
2304 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2305 id=\"prefFilterList\">";
35f3c923
AD
2306
2307 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2308 Select:
2309 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 2310 'FILRR-', 'FICHK-', true)\">All</a>,
35f3c923 2311 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 2312 'FILRR-', 'FICHK-', false)\">None</a>
35f3c923
AD
2313 </td</tr>";
2314
3b0feb9b 2315 print "<tr class=\"title\">
e325c6e7 2316 <td align='center' width=\"5%\">&nbsp;</td>
19c9cb11
AD
2317 <td width=\"20%\">Filter expression</td>
2318 <td width=\"20%\">Feed</td>
2319 <td width=\"15%\">Match</td>
01b3e191
AD
2320 <td width=\"15%\">Action</td>";
2321
3b0feb9b
AD
2322 $lnum = 0;
2323
2324 while ($line = db_fetch_assoc($result)) {
2325
2326 $class = ($lnum % 2) ? "even" : "odd";
2327
2328 $filter_id = $line["id"];
2329 $edit_filter_id = $_GET["id"];
2330
2331 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2332 $class .= "Grayed";
53226edc
AD
2333 $this_row_id = "";
2334 } else {
2335 $this_row_id = "id=\"FILRR-$filter_id\"";
ead60402 2336 }
3b0feb9b 2337
53226edc 2338 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2339
2340 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
3b0feb9b
AD
2341
2342 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2343
2344 if (!$edit_filter_id || $subop != "edit") {
2345
a426e532 2346 print "<td align='center'><input onclick='toggleSelectRow(this);'
3b0feb9b
AD
2347 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2348
2349 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2350 $line["reg_exp"] . "</td>";
2351
2352 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2353 $line["feed_title"] . "</td>";
2354
2355 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2356 $line["filter_type_descr"] . "</td>";
19c9cb11
AD
2357
2358 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2359 $line["action_description"] . "</td>";
3b0feb9b
AD
2360
2361 } else if ($filter_id != $edit_filter_id) {
2362
2363 if (!$line["description"]) $line["description"] = "[No description]";
2364
2365 print "<td><input disabled=\"true\" type=\"checkbox\"
2366 id=\"FICHK-".$line["id"]."\"></td>";
2367
2368 print "<td>".$line["reg_exp"]."</td>";
2369 print "<td>".$line["feed_title"]."</td>";
2370 print "<td>".$line["filter_type_descr"]."</td>";
19c9cb11 2371 print "<td>".$line["action_description"]."</td>";
19c9cb11 2372
3b0feb9b
AD
2373 } else {
2374
2375 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2376
2377 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2378 "\"></td>";
2379
2380 print "<td>";
3b0feb9b 2381 print "<select id=\"iedit_feed\">";
3b0feb9b
AD
2382 print "<option id=\"0\">All feeds</option>";
2383
3b0feb9b
AD
2384 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2385 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
19c9cb11
AD
2386
2387 if (db_num_rows($tmp_result) > 0) {
2388 print "<option disabled>--------</option>";
2389 }
2390
3b0feb9b
AD
2391 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2392 if ($tmp_line["id"] == $line["feed_id"]) {
2393 $is_selected = "selected";
2394 } else {
2395 $is_selected = "";
2396 }
2397 printf("<option $is_selected id='%d'>%s</option>",
2398 $tmp_line["id"], $tmp_line["title"]);
ead60402 2399 }
3b0feb9b
AD
2400
2401 print "</select></td>";
2402
2403 print "<td>";
2404 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2405 print "</td>";
19c9cb11
AD
2406
2407 print "<td>";
2408 print "<select id=\"iedit_filter_action\">";
2409
2410 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2411 ORDER BY description");
2412
2413 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2414 if ($tmp_line["description"] == $line["action_description"]) {
2415 $is_selected = "selected";
2416 } else {
2417 $is_selected = "";
2418 }
2419 printf("<option $is_selected id='%d'>%s</option>",
2420 $tmp_line["id"], $tmp_line["description"]);
2421 }
3b0feb9b 2422
19c9cb11
AD
2423 print "</select></td>";
2424
3b0feb9b 2425 print "</td>";
ead60402 2426 }
3b0feb9b
AD
2427
2428 print "</tr>";
2429
2430 ++$lnum;
a0d53889 2431 }
3b0feb9b
AD
2432
2433 if ($lnum == 0) {
2434 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2435 }
2436
2437 print "</table>";
2438
2439 print "<p>";
2440
2441 if ($subop == "edit") {
d10fabe4 2442 print "Edit filter:
3b0feb9b 2443 <input type=\"submit\" class=\"button\"
d10fabe4 2444 onclick=\"javascript:filterEditSave()\" value=\"Save\">
3b0feb9b 2445 <input type=\"submit\" class=\"button\"
d10fabe4 2446 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
3b0feb9b
AD
2447
2448 } else {
2449
2450 print "
2451 Selection:
e828e31e 2452 <input type=\"submit\" class=\"button\"
3b0feb9b 2453 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
e828e31e 2454 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2455 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2456 }
2457
a0d53889
AD
2458 } else {
2459
3b0feb9b
AD
2460 print "<p>No filters defined.</p>";
2461
a0d53889
AD
2462 }
2463 }
2464
80dce858
AD
2465 // We need to accept raw SQL data in label queries, so not everything is escaped
2466 // here, this is by design. If you don't like the whole idea, disable labels
2467 // altogether with GLOBAL_ENABLE_LABELS = false
2468
48f0adb0
AD
2469 if ($op == "pref-labels") {
2470
cfaba6df
AD
2471 if (!GLOBAL_ENABLE_LABELS) {
2472 return;
2473 }
2474
48f0adb0
AD
2475 $subop = $_GET["subop"];
2476
d9dde1d6
AD
2477 if ($subop == "test") {
2478
2479 $expr = $_GET["expr"];
2480 $descr = $_GET["descr"];
2481
2482 print "<div class='infoBoxContents'>";
2483
2484 print "<h1>Label &laquo;$descr&raquo;</h1>";
2485
2486// print "<p><b>Expression</b>: $expr</p>";
2487
2488 $result = db_query($link,
2489 "SELECT count(id) AS num_matches
2490 FROM ttrss_entries,ttrss_user_entries
2491 WHERE ($expr) AND
2492 ttrss_user_entries.ref_id = ttrss_entries.id AND
2493 owner_uid = " . $_SESSION["uid"]);
2494
2495 $num_matches = db_fetch_result($result, 0, "num_matches");;
2496
2497 if ($num_matches > 0) {
2498
a31a7b39 2499 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
d9dde1d6
AD
2500
2501 $result = db_query($link,
2502 "SELECT title,
2503 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2504 FROM ttrss_entries,ttrss_user_entries
2505 WHERE ($expr) AND
2506 ttrss_user_entries.ref_id = ttrss_entries.id
2507 AND owner_uid = " . $_SESSION["uid"] . "
2508 ORDER BY date_entered DESC LIMIT 5");
2509
2510 print "<ul class=\"nomarks\">";
2511 while ($line = db_fetch_assoc($result)) {
2512 print "<li>".$line["title"].
2513 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2514 }
2515 print "</ul>";
2516
2517 } else {
2518 print "<p>Query didn't return any matches.</p>";
2519 }
2520
2521 print "</div>";
2522
2523 print "<div align='center'>
2524 <input type='submit' class='button'
2525 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2526 return;
2527 }
2528
48f0adb0
AD
2529 if ($subop == "editSave") {
2530
2531 $sql_exp = $_GET["s"];
2532 $descr = $_GET["d"];
2533 $label_id = db_escape_string($_GET["id"]);
2534
2535// print "$sql_exp : $descr : $label_id";
2536
2537 $result = db_query($link, "UPDATE ttrss_labels SET
2538 sql_exp = '$sql_exp',
2539 description = '$descr'
2540 WHERE id = '$label_id'");
2541 }
2542
2543 if ($subop == "remove") {
2544
2545 if (!WEB_DEMO_MODE) {
2546
f932bc9f 2547 $ids = split(",", db_escape_string($_GET["ids"]));
48f0adb0
AD
2548
2549 foreach ($ids as $id) {
2550 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2551
2552 }
2553 }
2554 }
2555
2556 if ($subop == "add") {
2557
2558 if (!WEB_DEMO_MODE) {
2559
4401bf04
AD
2560 // no escaping is done here on purpose
2561 $exp = trim($_GET["exp"]);
48f0adb0
AD
2562
2563 $result = db_query($link,
4356293a
AD
2564 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2565 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
2566 }
2567 }
2568
2c7070b5
AD
2569 print "<div class=\"prefGenericAddBox\">
2570 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
48f0adb0 2571
2c7070b5
AD
2572 print"<input type=\"submit\" class=\"button\"
2573 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
48f0adb0
AD
2574
2575 $result = db_query($link, "SELECT
2576 id,sql_exp,description
2577 FROM
4356293a
AD
2578 ttrss_labels
2579 WHERE
2580 owner_uid = ".$_SESSION["uid"]."
2581 ORDER by description");
48f0adb0 2582
d9dde1d6
AD
2583 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2584
3b0feb9b 2585 if (db_num_rows($result) != 0) {
48f0adb0 2586
f4fe2cde
AD
2587 print "<p><table width=\"100%\" cellspacing=\"0\"
2588 class=\"prefLabelList\" id=\"prefLabelList\">";
35f3c923
AD
2589
2590 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2591 Select:
2592 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 2593 'LILRR-', 'LICHK-', true)\">All</a>,
35f3c923 2594 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 2595 'LILRR-', 'LICHK-', false)\">None</a>
35f3c923
AD
2596 </td</tr>";
2597
3b0feb9b 2598 print "<tr class=\"title\">
e325c6e7
AD
2599 <td align='center' width=\"5%\">&nbsp;</td>
2600 <td width=\"40%\">SQL expression
01c9c74a 2601 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
3b0feb9b
AD
2602 </td>
2603 <td width=\"40%\">Caption</td></tr>";
2604
2605 $lnum = 0;
2606
2607 while ($line = db_fetch_assoc($result)) {
2608
2609 $class = ($lnum % 2) ? "even" : "odd";
2610
2611 $label_id = $line["id"];
2612 $edit_label_id = $_GET["id"];
2613
2614 if ($subop == "edit" && $label_id != $edit_label_id) {
2615 $class .= "Grayed";
53226edc
AD
2616 $this_row_id = "";
2617 } else {
2618 $this_row_id = "id=\"LILRR-$label_id\"";
3b0feb9b
AD
2619 }
2620
53226edc 2621 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2622
2623 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2624 $line["description"] = htmlspecialchars($line["description"]);
2625
2626 if (!$edit_label_id || $subop != "edit") {
2627
2628 if (!$line["description"]) $line["description"] = "[No caption]";
2629
a426e532 2630 print "<td align='center'><input onclick='toggleSelectRow(this);'
3b0feb9b
AD
2631 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2632
2633 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2634 $line["sql_exp"] . "</td>";
48f0adb0 2635
3b0feb9b
AD
2636 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2637 $line["description"] . "</td>";
2638
2639 } else if ($label_id != $edit_label_id) {
2640
2641 if (!$line["description"]) $line["description"] = "[No description]";
2642
2643 print "<td><input disabled=\"true\" type=\"checkbox\"
2644 id=\"LICHK-".$line["id"]."\"></td>";
2645
2646 print "<td>".$line["sql_exp"]."</td>";
2647 print "<td>".$line["description"]."</td>";
2648
2649 } else {
2650
2651 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2652
2653 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2654 "\"></td>";
2655
2656 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2657 "\"></td>";
2658
2659 }
2660
48f0adb0 2661
3b0feb9b
AD
2662 print "</tr>";
2663
2664 ++$lnum;
2665 }
2666
2667 if ($lnum == 0) {
2668 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2669 }
2670
2671 print "</table>";
2672
2673 print "<p>";
2674
2675 if ($subop == "edit") {
2676 print "Edit label:
d9dde1d6
AD
2677 <input type=\"submit\" class=\"button\"
2678 onclick=\"javascript:labelTest()\" value=\"Test\">
3b0feb9b 2679 <input type=\"submit\" class=\"button\"
d10fabe4 2680 onclick=\"javascript:labelEditSave()\" value=\"Save\">
3b0feb9b 2681 <input type=\"submit\" class=\"button\"
d10fabe4 2682 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
3b0feb9b
AD
2683
2684 } else {
2685
2686 print "
2687 Selection:
48f0adb0 2688 <input type=\"submit\" class=\"button\"
3b0feb9b 2689 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
48f0adb0 2690 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2691 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2692 }
48f0adb0 2693 } else {
3b0feb9b 2694 print "<p>No labels defined.</p>";
48f0adb0
AD
2695 }
2696 }
2697
e828e31e
AD
2698 if ($op == "error") {
2699 print "<div width=\"100%\" align='center'>";
2700 $msg = $_GET["msg"];
2701 print $msg;
2702 print "</div>";
2703 }
2704
7dc66a61 2705 if ($op == "help") {
01c9c74a
AD
2706 if (!$_GET["noheaders"]) {
2707 print "<html><head>
2708 <title>Tiny Tiny RSS : Help</title>
2709 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2710 <script type=\"text/javascript\" src=\"functions.js\"></script>
2711 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2712 </head><body>";
2713 }
7dc66a61
AD
2714
2715 $tid = sprintf("%d", $_GET["tid"]);
2716
01c9c74a 2717 print "<div class='infoBoxContents'>";
7dc66a61 2718
01c9c74a
AD
2719 if (file_exists("help/$tid.php")) {
2720 include("help/$tid.php");
2721 } else {
2722 print "<p>Help topic not found.</p>";
2723 }
7dc66a61 2724
01c9c74a 2725 print "</div>";
7dc66a61
AD
2726
2727 print "<div align='center'>
01c9c74a
AD
2728 <input type='submit' class='button'
2729 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
7dc66a61 2730
01c9c74a
AD
2731 if (!$_GET["noheaders"]) {
2732 print "</body></html>";
2733 }
7dc66a61
AD
2734
2735 }
2736
f84a97a3
AD
2737 if ($op == "dlg") {
2738 $id = $_GET["id"];
6de5d056 2739 $param = $_GET["param"];
f84a97a3
AD
2740
2741 if ($id == "quickAddFeed") {
76332f3c
AD
2742 print "
2743 Feed URL: <input
033e47e0 2744 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
15da5cc1
AD
2745 id=\"qafInput\">";
2746
2747 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2748 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2749 WHERE owner_uid = ".$_SESSION["uid"]."
2750 ORDER BY title");
2751
2752 print " <select id=\"qafCat\">";
2753 print "<option id=\"0\">Uncategorized</option>";
2754
2755 if (db_num_rows($result) != 0) {
2756
2757 print "<option disabled>--------</option>";
2758
2759 while ($line = db_fetch_assoc($result)) {
2760 printf("<option id='%d'>%s</option>",
2761 $line["id"], $line["title"]);
2762 }
2763 }
2764
2765 print "</select>";
2766 }
2767
2768 print "&nbsp;<input class=\"button\"
f84a97a3
AD
2769 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2770 <input class=\"button\"
2771 type=\"submit\" onclick=\"javascript:closeDlg()\"
2772 value=\"Cancel\">";
2773 }
6de5d056
AD
2774
2775 if ($id == "quickDelFeed") {
2776
2777 $param = db_escape_string($param);
2778
2779 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2780
2781 if ($result) {
2782
2783 $f_title = db_fetch_result($result, 0, "title");
2784
76332f3c 2785 print "Remove current feed (<b>$f_title</b>)?&nbsp;
6de5d056
AD
2786 <input class=\"button\"
2787 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2788 <input class=\"button\"
2789 type=\"submit\" onclick=\"javascript:closeDlg()\"
2790 value=\"Cancel\">";
2791 } else {
2792 print "Error: Feed $param not found.&nbsp;
2793 <input class=\"button\"
2794 type=\"submit\" onclick=\"javascript:closeDlg()\"
2795 value=\"Cancel\">";
2796 }
2797 }
2798
033e47e0
AD
2799 if ($id == "search") {
2800
49b7cbd3
AD
2801 $active_feed_id = db_escape_string($_GET["param"]);
2802
033e47e0
AD
2803 print "<input id=\"searchbox\" class=\"extSearch\"
2804 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2805 onchange=\"javascript:search()\">
2806 <select id=\"searchmodebox\">
49b7cbd3
AD
2807 <option selected>All feeds</option>";
2808
2809 if ($active_feed_id) {
2810 print "<option>This feed</option>";
2811 } else {
2812 print "<option disabled>This feed</option>";
2813 }
b0005823
AD
2814
2815 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2816 print "<option>This category</option>";
2817 }
2818
49b7cbd3 2819 print "</select>
033e47e0
AD
2820 <input type=\"submit\"
2821 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2822 <input class=\"button\"
2823 type=\"submit\" onclick=\"javascript:closeDlg()\"
2824 value=\"Close\">";
2825
2826 }
2827
a24f525c
AD
2828 if ($id == "quickAddFilter") {
2829
2830 $result = db_query($link, "SELECT description
2831 FROM ttrss_filter_types ORDER BY description");
2832
2833 $filter_types = array();
2834
2835 while ($line = db_fetch_assoc($result)) {
2836 array_push($filter_types, $line["description"]);
2837 }
2838
2839 print "<table>";
2840
2841 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2842
2843 print_select("fadd_match", "Title", $filter_types);
2844
2845 print "</td></tr>";
2846 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2847
2848 print "<option selected id=\"0\">All feeds</option>";
2849
2850 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2851 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2852
2853 if (db_num_rows($result) > 0) {
2854 print "<option disabled>--------</option>";
2855 }
2856
2857 while ($line = db_fetch_assoc($result)) {
2858 if ($param == $line["id"]) {
2859 $selected = "selected";
2860 } else {
2861 $selected = "";
2862 }
2863 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2864 }
2865
2866 print "</select></td></tr>";
2867
2868 print "<tr><td>Action:</td>";
2869
2870 print "<td><select id=\"fadd_action\">";
2871
2872 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2873 ORDER BY name");
2874
2875 while ($line = db_fetch_assoc($result)) {
2876 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2877 }
2878
2879 print "</select>";
2880
2881 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2882
2883 print "<input type=\"submit\"
2884 class=\"button\" onclick=\"javascript:qaddFilter()\"
2885 value=\"Add filter\"> ";
2886
2887 print "<input class=\"button\"
2888 type=\"submit\" onclick=\"javascript:closeDlg()\"
2889 value=\"Close\">";
2890
2891 print "</td></tr></table>";
2892 }
f84a97a3
AD
2893 }
2894
a2770077
AD
2895 // update feeds of all users, may be used anonymously
2896 if ($op == "globalUpdateFeeds") {
2897
2898 $result = db_query($link, "SELECT id FROM ttrss_users");
2899
2900 while ($line = db_fetch_assoc($result)) {
2901 $user_id = $line["id"];
2902// print "<!-- updating feeds of uid $user_id -->";
2903 update_all_feeds($link, false, $user_id);
2904 }
e65af9c1 2905
a2770077
AD
2906 print "<rpc-reply>
2907 <message msg=\"All feeds updated\"/>
2908 </rpc-reply>";
e65af9c1
AD
2909
2910 }
2911
77e96719
AD
2912 if ($op == "pref-prefs") {
2913
b1895692 2914 $subop = $_REQUEST["subop"];
77e96719
AD
2915
2916 if ($subop == "Save configuration") {
2917
d2892032
AD
2918 if (WEB_DEMO_MODE) {
2919 header("Location: prefs.php");
2920 return;
2921 }
01d68cf9 2922
93cb4442
AD
2923 $_SESSION["prefs_op_result"] = "save-config";
2924
11de82c3
AD
2925 $_SESSION["prefs_cache"] = false;
2926
77e96719
AD
2927 foreach (array_keys($_POST) as $pref_name) {
2928
2929 $pref_name = db_escape_string($pref_name);
2930 $value = db_escape_string($_POST[$pref_name]);
2931
2932 $result = db_query($link, "SELECT type_name
2933 FROM ttrss_prefs,ttrss_prefs_types
2934 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2935
2936 if (db_num_rows($result) > 0) {
2937
2938 $type_name = db_fetch_result($result, 0, "type_name");
2939
5da169d9
AD
2940// print "$pref_name : $type_name : $value<br>";
2941
77e96719 2942 if ($type_name == "bool") {
5da169d9 2943 if ($value == "1") {
77e96719
AD
2944 $value = "true";
2945 } else {
2946 $value = "false";
2947 }
2948 } else if ($type_name == "integer") {
2949 $value = sprintf("%d", $value);
2950 }
2951
2952// print "$pref_name : $type_name : $value<br>";
2953
ff485f1d
AD
2954 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2955 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
2956
2957 }
2958
2959 header("Location: prefs.php");
2960
2961 }
2962
b1895692
AD
2963 } else if ($subop == "getHelp") {
2964
2965 $pref_name = db_escape_string($_GET["pn"]);
2966
2967 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2968 WHERE pref_name = '$pref_name'");
2969
2970 if (db_num_rows($result) > 0) {
2971 $help_text = db_fetch_result($result, 0, "help_text");
2972 print $help_text;
2973 } else {
2974 print "Unknown option: $pref_name";
2975 }
2976
cbb01696
AD
2977 } else if ($subop == "Change e-mail") {
2978
2979 if (WEB_DEMO_MODE) {
2980 header("Location: prefs.php");
2981 return;
2982 }
2983
2984 $email = db_escape_string($_GET["email"]);
2985 $active_uid = $_SESSION["uid"];
2986
2987 if ($email) {
2988 db_query($link, "UPDATE ttrss_users SET email = '$email'
2989 WHERE id = '$active_uid'");
2990 }
2991
2992 header("Location: prefs.php");
2993
1c7f75ed
AD
2994 } else if ($subop == "Change password") {
2995
d2892032
AD
2996 if (WEB_DEMO_MODE) {
2997 header("Location: prefs.php");
2998 return;
2999 }
1c7f75ed
AD
3000
3001 $old_pw = $_POST["OLD_PASSWORD"];
3002 $new_pw = $_POST["OLD_PASSWORD"];
3003
3004 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3005 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3006
3007 $active_uid = $_SESSION["uid"];
3008
3009 if ($old_pw && $new_pw) {
3010
3011 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3012
3013 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3014 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3015 pwd_hash = '$old_pw_hash')");
3016
3017 if (db_num_rows($result) == 1) {
3018 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3019 WHERE id = '$active_uid'");
b791095d
AD
3020
3021 $_SESSION["pwd_change_result"] = "ok";
3022 } else {
3023 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
3024 }
3025 }
3026
3027 header("Location: prefs.php");
b791095d 3028
77e96719
AD
3029 } else if ($subop == "Reset to defaults") {
3030
d2892032
AD
3031 if (WEB_DEMO_MODE) {
3032 header("Location: prefs.php");
3033 return;
3034 }
01d68cf9 3035
93cb4442
AD
3036 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3037
e1aa0559
AD
3038 if (DB_TYPE == "pgsql") {
3039 db_query($link,"UPDATE ttrss_user_prefs
3040 SET value = ttrss_prefs.def_value
3041 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3042 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3043 } else {
3044 db_query($link, "DELETE FROM ttrss_user_prefs
3045 WHERE owner_uid = ".$_SESSION["uid"]);
3046 initialize_user_prefs($link, $_SESSION["uid"]);
3047 }
5da169d9 3048
77e96719
AD
3049 header("Location: prefs.php");
3050
58f8ad54
AD
3051 } else if ($subop == "Change theme") {
3052
3053 $theme = db_escape_string($_POST["theme"]);
3054
3055 if ($theme == "Default") {
3056 $theme_qpart = 'NULL';
3057 } else {
3058 $theme_qpart = "'$theme'";
3059 }
3060
6752e330
AD
3061 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3062 WHERE theme_name = '$theme'");
3063
3064 if (db_num_rows($result) == 1) {
3065 $theme_id = db_fetch_result($result, 0, "id");
3066 $theme_path = db_fetch_result($result, 0, "theme_path");
3067 } else {
3068 $theme_id = "NULL";
3069 $theme_path = "";
3070 }
3071
58f8ad54 3072 db_query($link, "UPDATE ttrss_users SET
6752e330 3073 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 3074
6752e330 3075 $_SESSION["theme"] = $theme_path;
503eb349 3076
58f8ad54
AD
3077 header("Location: prefs.php");
3078
77e96719
AD
3079 } else {
3080
7d4c898a 3081 if (!SINGLE_USER_MODE) {
1c7f75ed 3082
cbb01696 3083 $result = db_query($link, "SELECT id,email FROM ttrss_users
a029d530
AD
3084 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3085 pwd_hash = 'SHA1:".sha1("password")."')");
3086
3087 if (db_num_rows($result) != 0) {
b791095d 3088 print "<div class=\"warning\">
a029d530
AD
3089 Your password is at default value, please change it.
3090 </div>";
3091 }
3092
b791095d
AD
3093 if ($_SESSION["pwd_change_result"] == "failed") {
3094 print "<div class=\"warning\">
3095 There was an error while changing your password.
3096 </div>";
3097 }
3098
3099 if ($_SESSION["pwd_change_result"] == "ok") {
3100 print "<div class=\"notice\">
3101 Password changed successfully.
3102 </div>";
3103 }
3104
3105 $_SESSION["pwd_change_result"] = "";
3106
93cb4442
AD
3107 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3108 print "<div class=\"notice\">
3109 Your configuration was reset to defaults.
3110 </div>";
3111 }
3112
3113 if ($_SESSION["prefs_op_result"] == "save-config") {
3114 print "<div class=\"notice\">
3115 Your configuration was saved successfully.
3116 </div>";
3117 }
3118
3119 $_SESSION["prefs_op_result"] = "";
3120
cbb01696
AD
3121 print "<form action=\"backend.php\" method=\"GET\">";
3122
3123 print "<table width=\"100%\" class=\"prefPrefsList\">";
3124 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3125
3126 $result = db_query($link, "SELECT email FROM ttrss_users
3127 WHERE id = ".$_SESSION["uid"]);
3128
3129 $email = db_fetch_result($result, 0, "email");
3130
3131 print "<tr><td width=\"40%\">E-mail</td>";
3132 print "<td><input class=\"editbox\" name=\"email\"
3133 value=\"$email\"></td></tr>";
3134
3135 print "</table>";
3136
3137 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3138
3139 print "<p><input class=\"button\" type=\"submit\"
3140 value=\"Change e-mail\" name=\"subop\">";
3141
a132b8b1
AD
3142 print "</form>";
3143
7d4c898a
AD
3144 print "<form action=\"backend.php\" method=\"POST\">";
3145
3146 print "<table width=\"100%\" class=\"prefPrefsList\">";
3147 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3148
3149 print "<tr><td width=\"40%\">Old password</td>";
3150 print "<td><input class=\"editbox\" type=\"password\"
3151 name=\"OLD_PASSWORD\"></td></tr>";
3152
3153 print "<tr><td width=\"40%\">New password</td>";
3154
3155 print "<td><input class=\"editbox\" type=\"password\"
3156 name=\"NEW_PASSWORD\"></td></tr>";
3157
3158 print "</table>";
3159
3160 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3161
3162 print "<p><input class=\"button\" type=\"submit\"
3163 value=\"Change password\" name=\"subop\">";
3164
3165 print "</form>";
1c7f75ed 3166
7d4c898a 3167 }
1c7f75ed 3168
58f8ad54
AD
3169 $result = db_query($link, "SELECT
3170 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3171
3172 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3173
3174 $result = db_query($link, "SELECT
3175 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3176
3177 if (db_num_rows($result) > 0) {
6752e330
AD
3178
3179 print "<form action=\"backend.php\" method=\"POST\">";
3180 print "<table width=\"100%\" class=\"prefPrefsList\">";
3181 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3182 print "<tr><td width=\"40%\">Select theme</td>";
3183 print "<td><select name=\"theme\">";
3184 print "<option>Default</option>";
58f8ad54 3185 print "<option disabled>--------</option>";
6752e330 3186
58f8ad54
AD
3187 while ($line = db_fetch_assoc($result)) {
3188 if ($line["id"] == $user_theme_id) {
3189 $selected = "selected";
3190 } else {
3191 $selected = "";
3192 }
3193 print "<option $selected>" . $line["theme_name"] . "</option>";
3194 }
6752e330
AD
3195 print "</select></td></tr>";
3196 print "</table>";
3197 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3198 print "<p><input class=\"button\" type=\"submit\"
3199 value=\"Change theme\" name=\"subop\">";
3200 print "</form>";
58f8ad54
AD
3201 }
3202
77e96719 3203 $result = db_query($link, "SELECT
ff485f1d 3204 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 3205 section_name,def_value
ff485f1d 3206 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 3207 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 3208 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
3209 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3210 owner_uid = ".$_SESSION["uid"]."
650bc435 3211 ORDER BY section_id,short_desc");
77e96719
AD
3212
3213 print "<form action=\"backend.php\" method=\"POST\">";
3214
77e96719
AD
3215 $lnum = 0;
3216
3217 $active_section = "";
3218
3219 while ($line = db_fetch_assoc($result)) {
3220
3221 if ($active_section != $line["section_name"]) {
59a654ba
AD
3222
3223 if ($active_section != "") {
1c7f75ed 3224 print "</table>";
59a654ba 3225 }
1c7f75ed
AD
3226
3227 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
3228
3229 $active_section = $line["section_name"];
3230
77e96719 3231 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
3232// print "<tr class=\"title\">
3233// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
3234
3235 $lnum = 0;
77e96719
AD
3236 }
3237
650bc435 3238// $class = ($lnum % 2) ? "even" : "odd";
77e96719 3239
650bc435 3240 print "<tr>";
77e96719 3241
77e96719
AD
3242 $type_name = $line["type_name"];
3243 $pref_name = $line["pref_name"];
3244 $value = $line["value"];
3245 $def_value = $line["def_value"];
b1895692
AD
3246 $help_text = $line["help_text"];
3247
3248 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3249
3250 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3251
3252 print "</td>";
77e96719
AD
3253
3254 print "<td>";
3255
3256 if ($type_name == "bool") {
3257// print_select($pref_name, $value, array("true", "false"));
3258
3259 if ($value == "true") {
3260 $value = "Yes";
3261 } else {
3262 $value = "No";
3263 }
3264
3265 print_radio($pref_name, $value, array("Yes", "No"));
3266
3267 } else {
3268 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3269 }
3270
3271 print "</td>";
3272
3273 print "</tr>";
3274
3275 $lnum++;
3276 }
3277
3278 print "</table>";
3279
3280 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3281
3282 print "<p><input class=\"button\" type=\"submit\"
3283 name=\"subop\" value=\"Save configuration\">";
3284
3285 print "&nbsp;<input class=\"button\" type=\"submit\"
69668465
AD
3286 name=\"subop\" onclick=\"return validatePrefsReset()\"
3287 value=\"Reset to defaults\"></p>";
77e96719
AD
3288
3289 print "</form>";
3290
3291 }
3292
3293 }
3294
e6cb77a0
AD
3295 if ($op == "pref-users") {
3296
3297 $subop = $_GET["subop"];
3298
3299 if ($subop == "editSave") {
3300
3301 if (!WEB_DEMO_MODE) {
3302
3303 $login = db_escape_string($_GET["l"]);
3304 $uid = db_escape_string($_GET["id"]);
3305 $access_level = sprintf("%d", $_GET["al"]);
72932a75 3306 $email = db_escape_string($_GET["e"]);
e6cb77a0 3307
72932a75
AD
3308 db_query($link, "UPDATE ttrss_users SET login = '$login',
3309 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
e6cb77a0
AD
3310
3311 }
3312 } else if ($subop == "remove") {
3313
3314 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3315
f932bc9f 3316 $ids = split(",", db_escape_string($_GET["ids"]));
e6cb77a0
AD
3317
3318 foreach ($ids as $id) {
3319 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3320
3321 }
3322 }
3323 } else if ($subop == "add") {
3324
3325 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3326
b6b535ca 3327 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0
AD
3328 $tmp_user_pwd = make_password(8);
3329 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3330
69c0d759
AD
3331 db_query($link, "INSERT INTO ttrss_users
3332 (login,pwd_hash,access_level,last_login)
3333 VALUES ('$login', '$pwd_hash', 0, NOW())");
e6cb77a0
AD
3334
3335
3336 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3337 login = '$login' AND pwd_hash = '$pwd_hash'");
3338
3339 if (db_num_rows($result) == 1) {
3340
3341 $new_uid = db_fetch_result($result, 0, "id");
3342
3343 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3344 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3345
3346 initialize_user($link, $new_uid);
3347
3348 } else {
3349
3350 print "<div class=\"warning\">Error while adding user <b>".
3351 $_GET["login"].".</b></div>";
3352
3353 }
3354 }
3355 } else if ($subop == "resetPass") {
3356
3357 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3358
3359 $uid = db_escape_string($_GET["id"]);
3360
72932a75
AD
3361 $result = db_query($link, "SELECT login,email
3362 FROM ttrss_users WHERE id = '$uid'");
e6cb77a0
AD
3363
3364 $login = db_fetch_result($result, 0, "login");
72932a75 3365 $email = db_fetch_result($result, 0, "email");
e6cb77a0
AD
3366 $tmp_user_pwd = make_password(8);
3367 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3368
3369 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3370 WHERE id = '$uid'");
3371
3372 print "<div class=\"notice\">Changed password of
72932a75
AD
3373 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3374
3375 if (MAIL_RESET_PASS && $email) {
3376 print " Notifying <b>$email</b>.";
3377
3378 mail("$login <$email>", "Password reset notification",
3379 "Hi, $login.\n".
3380 "\n".
3381 "Your password for this TT-RSS installation was reset by".
3382 " an administrator.\n".
3383 "\n".
3384 "Your new password is $tmp_user_pwd, please remember".
3385 " it for later reference.\n".
3386 "\n".
3387 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3388 }
3389
3390 print "</div>";
e6cb77a0
AD
3391
3392 }
3393 }
3394
2c7070b5 3395 print "<div class=\"prefGenericAddBox\">
f932bc9f 3396 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\">&nbsp;";
e6cb77a0 3397
2c7070b5
AD
3398 print"<input type=\"submit\" class=\"button\"
3399 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
e6cb77a0
AD
3400
3401 $result = db_query($link, "SELECT
72932a75 3402 id,login,access_level,email,
fe99ab12 3403 SUBSTRING(last_login,1,16) as last_login
e6cb77a0
AD
3404 FROM
3405 ttrss_users
3406 ORDER by login");
3407
2317ffaa 3408 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1a7572cb 3409
f4fe2cde
AD
3410 print "<p><table width=\"100%\" cellspacing=\"0\"
3411 class=\"prefUserList\" id=\"prefUserList\">";
e6cb77a0 3412
35f3c923
AD
3413 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3414 Select:
3415 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 3416 'UMRR-', 'UMCHK-', true)\">All</a>,
35f3c923 3417 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 3418 'UMRR-', 'UMCHK-', false)\">None</a>
35f3c923
AD
3419 </td</tr>";
3420
e6cb77a0 3421 print "<tr class=\"title\">
e325c6e7 3422 <td align='center' width=\"5%\">&nbsp;</td>
72932a75
AD
3423 <td width='20%'>Username</td>
3424 <td width='20%'>E-mail</td>
3425 <td width='20%'>Access Level</td>
3426 <td width='20%'>Last login</td></tr>";
e6cb77a0
AD
3427
3428 $lnum = 0;
3429
3430 while ($line = db_fetch_assoc($result)) {
3431
3432 $class = ($lnum % 2) ? "even" : "odd";
3433
3434 $uid = $line["id"];
3435 $edit_uid = $_GET["id"];
3436
4154a415 3437 if ($subop == "edit" && $uid != $edit_uid) {
e6cb77a0 3438 $class .= "Grayed";
53226edc
AD
3439 $this_row_id = "";
3440 } else {
3441 $this_row_id = "id=\"UMRR-$uid\"";
3442 }
3443
3444 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
3445
3446 $line["login"] = htmlspecialchars($line["login"]);
3447
6be6bc03
AD
3448 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3449 strtotime($line["last_login"]));
3450
5917a8e4
AD
3451 $access_level_names = array(0 => "User", 10 => "Administrator");
3452
72932a75 3453/* if ($uid == $_SESSION["uid"]) {
e6cb77a0 3454
a426e532 3455 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
e6cb77a0
AD
3456 id=\"UMCHK-".$line["id"]."\"></td>";
3457
72932a75
AD
3458 print "<td>".$line["login"]."</td>";
3459 print "<td>".$line["email"]."</td>";
3460 print "<td>".$line["access_level"]."</td>";
e6cb77a0 3461
72932a75 3462 } else */ if (!$edit_uid || $subop != "edit") {
e6cb77a0 3463
a426e532 3464 print "<td align='center'><input onclick='toggleSelectRow(this);'
1a7572cb 3465 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
3466
3467 print "<td><a href=\"javascript:editUser($uid);\">" .
3468 $line["login"] . "</td>";
72932a75
AD
3469
3470 print "<td><a href=\"javascript:editUser($uid);\">" .
3471 $line["email"] . "</td>";
3472
e6cb77a0 3473 print "<td><a href=\"javascript:editUser($uid);\">" .
5917a8e4 3474 $access_level_names[$line["access_level"]] . "</td>";
e6cb77a0
AD
3475
3476 } else if ($uid != $edit_uid) {
3477
72932a75 3478 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
e6cb77a0
AD
3479 id=\"UMCHK-".$line["id"]."\"></td>";
3480
3481 print "<td>".$line["login"]."</td>";
72932a75 3482 print "<td>".$line["email"]."</td>";
5917a8e4 3483 print "<td>".$access_level_names[$line["access_level"]]."</td>";
e6cb77a0
AD
3484
3485 } else {
3486
72932a75
AD
3487 print "<td align='center'>
3488 <input disabled=\"true\" type=\"checkbox\" checked></td>";
e6cb77a0
AD
3489
3490 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3491 "\"></td>";
3492
72932a75
AD
3493 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3494 "\"></td>";
3495
5917a8e4
AD
3496// print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3497// "\"></td>";
3498
3499 print "<td>";
3500 print "<select id=\"iedit_ulevel\">";
3501 foreach (array_keys($access_level_names) as $al) {
3502 if ($al == $line["access_level"]) {
3503 $selected = "selected";
3504 } else {
3505 $selected = "";
3506 }
3507 print "<option $selected id=\"$al\">" .
3508 $access_level_names[$al] . "</option>";
3509 }
3510 print "</select>";
3511 print "</td>";
3512
e6cb77a0
AD
3513 }
3514
f6f32198
AD
3515 print "<td>".$line["last_login"]."</td>";
3516
e6cb77a0
AD
3517 print "</tr>";
3518
3519 ++$lnum;
3520 }
3521
3522 print "</table>";
3523
3524 print "<p>";
3525
3526 if ($subop == "edit") {
d10fabe4 3527 print "Edit user:
e6cb77a0 3528 <input type=\"submit\" class=\"button\"
d10fabe4 3529 onclick=\"javascript:userEditSave()\" value=\"Save\">
e6cb77a0 3530 <input type=\"submit\" class=\"button\"
d10fabe4 3531 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
e6cb77a0
AD
3532
3533 } else {
3534
3535 print "
3536 Selection:
3537 <input type=\"submit\" class=\"button\"
717f5e64 3538 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
e6cb77a0
AD
3539 <input type=\"submit\" class=\"button\"
3540 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3541 <input type=\"submit\" class=\"button\"
717f5e64
AD
3542 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3543 <input type=\"submit\" class=\"button\"
3544 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3545
3546 }
3547 }
3548
3549 if ($op == "user-details") {
3550
3551 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3552 return;
3553 }
3554
1a7572cb 3555/* print "<html><head>
717f5e64
AD
3556 <title>Tiny Tiny RSS : User Details</title>
3557 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3558 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 3559 </head><body>"; */
717f5e64
AD
3560
3561 $uid = sprintf("%d", $_GET["id"]);
3562
c6c3a07f 3563 print "<div class='infoBoxContents'>";
717f5e64 3564
fe99ab12
AD
3565 $result = db_query($link, "SELECT login,
3566 SUBSTRING(last_login,1,16) AS last_login,
3567 access_level,
c6c3a07f
AD
3568 (SELECT COUNT(int_id) FROM ttrss_user_entries
3569 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
3570 FROM ttrss_users
3571 WHERE id = '$uid'");
3572
3573 if (db_num_rows($result) == 0) {
3574 print "<h1>User not found</h1>";
3575 return;
3576 }
3577
3578 print "<h1>User Details</h1>";
3579
3580 print "<table width='100%'>";
3581
3582 $login = db_fetch_result($result, 0, "login");
6be6bc03
AD
3583 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3584 strtotime(db_fetch_result($result, 0, "last_login")));
717f5e64 3585 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 3586 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64
AD
3587
3588 print "<tr><td>Username</td><td>$login</td></tr>";
3589 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3590 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 3591 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
3592
3593 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3594 WHERE owner_uid = '$uid'");
3595
3596 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3597
3598 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3599
5d15d3ea 3600/* $result = db_query($link, "SELECT
717f5e64 3601 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
3602 FROM ttrss_user_entries,ttrss_entries
3603 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 3604
d9f115c3 3605 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 3606
c6c3a07f 3607 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
3608
3609 print "</table>";
3610
3611 print "<h1>Subscribed feeds</h1>";
3612
e94645ca 3613 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
9b3e2cc7 3614 WHERE owner_uid = '$uid' ORDER BY title");
717f5e64 3615
9b3e2cc7 3616 print "<ul class=\"userFeedList\">";
717f5e64
AD
3617
3618 while ($line = db_fetch_assoc($result)) {
3619
3620 $icon_file = ICONS_URL."/".$line["id"].".ico";
3621
3622 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 3623 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 3624 } else {
5951ded1 3625 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
3626 }
3627
e94645ca 3628 print "<li>$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
e6cb77a0 3629 }
717f5e64 3630
a88c1f36
AD
3631 if (db_num_rows($result) < $num_feeds) {
3632 // FIXME - add link to show ALL subscribed feeds here somewhere
3633 print "<li><img
3634 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3635 }
3636
717f5e64
AD
3637 print "</ul>";
3638
717f5e64
AD
3639 print "</div>";
3640
1a7572cb
AD
3641 print "<div align='center'>
3642 <input type='submit' class='button'
c6c3a07f 3643 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
3644
3645// print "</body></html>";
717f5e64 3646
e6cb77a0
AD
3647 }
3648
c6c3a07f
AD
3649 if ($op == "feed-details") {
3650
df268d47 3651// $feed_id = $_GET["id"];
4fec9fd7 3652
df268d47 3653 $feed_ids = split(",", db_escape_string($_GET["id"]));
c6c3a07f 3654
df268d47 3655 print "<div class=\"infoBoxContents\">";
bca02305 3656
df268d47 3657 foreach ($feed_ids as $feed_id) {
c6c3a07f 3658
df268d47
AD
3659 $result = db_query($link,
3660 "SELECT
3661 title,feed_url,
3662 SUBSTRING(last_updated,1,16) as last_updated,
3663 icon_url,site_url,
3664 (SELECT COUNT(int_id) FROM ttrss_user_entries
3665 WHERE feed_id = id) AS total,
3666 (SELECT COUNT(int_id) FROM ttrss_user_entries
3667 WHERE feed_id = id AND unread = true) AS unread,
3668 (SELECT COUNT(int_id) FROM ttrss_user_entries
3669 WHERE feed_id = id AND marked = true) AS marked
3670 FROM ttrss_feeds
3671 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3672
3673 if (db_num_rows($result) == 0) return;
3674
3675 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3676 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3677 strtotime(db_fetch_result($result, 0, "last_updated")));
3678 $feed_url = db_fetch_result($result, 0, "feed_url");
3679 $icon_url = db_fetch_result($result, 0, "icon_url");
3680 $total = db_fetch_result($result, 0, "total");
3681 $unread = db_fetch_result($result, 0, "unread");
3682 $marked = db_fetch_result($result, 0, "marked");
3683 $site_url = db_fetch_result($result, 0, "site_url");
bca02305 3684
df268d47 3685 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3803fa6a 3686 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false");
df268d47
AD
3687
3688 $subscribed = db_fetch_result($result, 0, "subscribed");
3689
3690 $icon_file = ICONS_DIR . "/$feed_id.ico";
3691
3692 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3693 $feed_icon = "<img width=\"16\" height=\"16\"
3694 src=\"" . ICONS_URL . "/$feed_id.ico\">";
3695 } else {
3696 $feed_icon = "";
bca02305
AD
3697 }
3698
df268d47 3699 print "<h1>$feed_icon $title</h1>";
bca02305 3700
df268d47 3701 print "<table width='100%'>";
bca02305 3702
df268d47
AD
3703 if ($site_url) {
3704 print "<tr><td width='30%'>Link</td>
3705 <td><a href=\"$site_url\">$site_url</a>
3706 <a href=\"$feed_url\">(feed)</a></td>
3707 </td></tr>";
3708 } else {
3709 print "<tr><td width='30%'>Feed URL</td>
3710 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3711 }
3712 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3713 print "<tr><td>Total articles</td><td>$total</td></tr>";
3714 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3715 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3716 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3717
3718 print "</table>";
3719
3720/* $result = db_query($link, "SELECT title,
3721 SUBSTRING(updated,1,16) AS updated,unread
3722 FROM ttrss_entries,ttrss_user_entries
3723 WHERE ref_id = id AND feed_id = '$feed_id'
3724 ORDER BY date_entered DESC LIMIT 5");
3725
3726 if (db_num_rows($result) > 0) {
3727
3728 print "<h1>Latest headlines</h1>";
3729
3730 print "<ul class=\"nomarks\">";
3731
3732 while ($line = db_fetch_assoc($result)) {
3733 if ($line["unread"] == "t" || $line["unread"] == "1") {
3734 $line["title"] = "<b>" . $line["title"] . "</b>";
3735 }
3736 print "<li>" . $line["title"].
3737 "&nbsp;<span class=\"insensitive\">(" .
3738 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3739 strtotime($line["updated"])).
3740 ")</span></li>";
3741 }
3742
3743 print "</ul>";
3744
3745 } */
bca02305 3746 }
df268d47
AD
3747
3748 print "</div>";
3749
3750 print "<div align='center'>
3751 <input type='submit' class='button'
3752 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3753 }
c6c3a07f 3754
c6232e43
AD
3755 if ($op == "pref-feed-browser") {
3756
e2f728be
AD
3757 if (!ENABLE_FEED_BROWSER) {
3758 print "Feed browser is administratively disabled.";
3759 return;
3760 }
3761
c6232e43
AD
3762 $subop = $_REQUEST["subop"];
3763
3764 if ($subop == "details") {
3765 $id = db_escape_string($_GET["id"]);
c2b2aee0 3766
072f1ee2
AD
3767 print "<div class=\"browserFeedInfo\">";
3768 print "<b>Feed information:</b>";
3769 print "<div class=\"detailsPart\">";
3770
3771 $result = db_query($link, "SELECT
3772 feed_url,site_url,
3773 SUBSTRING(last_updated,1,19) AS last_updated
3774 FROM ttrss_feeds WHERE id = '$id'");
3775
3776 $feed_url = db_fetch_result($result, 0, "feed_url");
3777 $site_url = db_fetch_result($result, 0, "site_url");
3778 $last_updated = db_fetch_result($result, 0, "last_updated");
3779
3780 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3781 $last_updated = smart_date_time(strtotime($last_updated));
3782 } else {
3783 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3784 $last_updated = date($short_date, strtotime($last_updated));
3785 }
3786
3787 print "Site: <a href='$site_url'>$site_url</a> ".
3788 "(<a href='$feed_url'>feed</a>), ".
3789 "Last updated: $last_updated";
3790
3791 print "</div>";
3792
3793 $result = db_query($link, "SELECT
3794 ttrss_entries.title,
3795 content,
c2b2aee0
AD
3796 substring(date_entered,1,19) as date_entered,
3797 substring(updated,1,19) as updated
072f1ee2
AD
3798 FROM ttrss_entries,ttrss_user_entries
3799 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
c2b2aee0
AD
3800 ORDER BY updated DESC LIMIT 5");
3801
3802 if (db_num_rows($result) > 0) {
c2b2aee0
AD
3803
3804 print "<b>Last headlines:</b><br>";
3805
3806 print "<div class=\"detailsPart\">";
3807 print "<ul class=\"compact\">";
3808 while ($line = db_fetch_assoc($result)) {
3809
3810 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3811 $entry_dt = smart_date_time(strtotime($line["updated"]));
3812 } else {
3813 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3814 $entry_dt = date($short_date, strtotime($line["updated"]));
3815 }
3816
3817 print "<li>" . $line["title"] .
3818 "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";
3819 }
3820 print "</ul></div>";
3821 }
072f1ee2
AD
3822
3823 print "</div>";
c2b2aee0 3824
c6232e43
AD
3825 return;
3826 }
65f28a40 3827
c6232e43
AD
3828 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
3829 FROM ttrss_feeds
3830 WHERE auth_login = '' AND auth_pass = '' AND private = false
65f28a40 3831 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100");
c6232e43 3832
0fefdacc 3833 print "<ul class='nomarks' id='browseBigFeedList'>";
c6232e43
AD
3834
3835 $feedctr = 0;
3836
3837 while ($line = db_fetch_assoc($result)) {
3838 $feed_url = $line["feed_url"];
3839 $subscribers = $line["subscribers"];
3840
3841 $sub_result = db_query($link, "SELECT id
3842 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
3843 $_SESSION["uid"]);
3844
3845 if (db_num_rows($sub_result) > 0) {
3846 continue; // already subscribed
3847 }
3848
3849 $det_result = db_query($link, "SELECT site_url,title,id
3850 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3851
3852 $details = db_fetch_assoc($det_result);
3853
3854 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
3855
3856 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3857 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
3858 "/".$details["id"].".ico\">";
3859 } else {
3860 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3861 }
3862
3863 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
3864 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3865
3866 $class = ($feedctr % 2) ? "even" : "odd";
3867
3868 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3869 "$feed_icon ";
3870
c2b2aee0 3871 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
c6232e43
AD
3872 $details["title"] ."</a>&nbsp;" .
3873 "<span class='subscribers'>($subscribers)</span>";
3874
3875 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3876 print "</div>";
3877
3878 print "</li>";
3879
3880 ++$feedctr;
3881 }
3882
3883 if ($feedctr == 0) {
3884 print "<li>No feeds found to subscribe.</li>";
3885 }
3886
3887 print "</ul>";
3888
0010d872
AD
3889 print "<p>Selection:
3890 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
3891 value=\"Subscribe\"></p>";
c6232e43
AD
3892
3893 print "</div>";
3894
3895 }
3896
657770a0
AD
3897 function check_configuration_variables() {
3898 if (!defined('SESSION_EXPIRE_TIME')) {
adf702d6 3899 return "config: SESSION_EXPIRE_TIME is undefined";
657770a0
AD
3900 }
3901
3902 if (SESSION_EXPIRE_TIME < 60) {
adf702d6
AD
3903 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3904 }
3905
3906 if (SESSION_EXPIRE_TIME < SESSION_COOKIE_LIFETIME_REMEMBER) {
3907 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3908 "SESSION_COOKIE_LIFETIME_REMEMBER";
3909 }
3910
3911 if (defined('DISABLE_SESSIONS') && DISABLE_SESSIONS) {
3912 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
657770a0
AD
3913 }
3914
8a414837
AD
3915 if (DATABASE_BACKED_SESSIONS && SINGLE_USER_MODE) {
3916 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3917 }
3918
657770a0
AD
3919 return false;
3920 }
3921
4b3dff6e 3922 db_close($link);
1cd17194 3923?>
406d9489
AD
3924
3925<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3926