]> git.wh0rd.org - tt-rss.git/blob - backend.php
userDetails -> infoBox, feed infobox, user details improvements
[tt-rss.git] / backend.php
1 <?
2 session_start();
3
4 $op = $_REQUEST["op"];
5
6 if (($op == "rpc" || $op == "updateAllFeeds" ||
7 $op == "forceUpdateAllFeeds") && !$_REQUEST["noxml"]) {
8 header("Content-Type: application/xml");
9 }
10
11 if (!$_SESSION["uid"]) {
12
13 if (($op == "rpc" || $op == "updateAllFeeds" ||
14 $op == "forceUpdateAllFeeds")) {
15 print "<error error-code=\"6\"/>";
16 }
17 exit;
18 }
19
20 define(SCHEMA_VERSION, 2);
21
22 require_once "config.php";
23 require_once "db.php";
24 require_once "db-prefs.php";
25 require_once "functions.php";
26 require_once "magpierss/rss_fetch.inc";
27
28 $script_started = getmicrotime();
29
30 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
31
32 if (!$link) {
33 if (DB_TYPE == "mysql") {
34 print mysql_error();
35 }
36 // PG seems to display its own errors just fine by default.
37 return;
38 }
39
40 if (DB_TYPE == "pgsql") {
41 pg_query("set client_encoding = 'utf-8'");
42 }
43
44 /*
45 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
46
47 $schema_version = db_fetch_result($result, 0, "schema_version");
48
49 if ($schema_version != SCHEMA_VERSION) {
50 print "Error: database schema is invalid
51 (got version $schema_version; expected ".SCHEMA_VERSION.")";
52 return;
53 }
54 */
55
56 $fetch = $_GET["fetch"];
57
58 /* FIXME this needs reworking */
59
60 function getGlobalCounters($link) {
61 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
62 WHERE unread = true AND
63 ttrss_user_entries.ref_id = ttrss_entries.id AND
64 owner_uid = " . $_SESSION["uid"]);
65 $c_id = db_fetch_result($result, 0, "c_id");
66 print "<counter id='global-unread' counter='$c_id'/>";
67 }
68
69 function getTagCounters($link) {
70
71 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
72 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
73 ttrss_user_entries.ref_id = ttrss_entries.id AND
74 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
75 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
76 UNION
77 select tag_name,0 as count FROM ttrss_tags
78 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
79
80 $tags = array();
81
82 while ($line = db_fetch_assoc($result)) {
83 $tags[$line["tag_name"]] += $line["count"];
84 }
85
86 foreach (array_keys($tags) as $tag) {
87 $unread = $tags[$tag];
88
89 $tag = htmlspecialchars($tag);
90 print "<tag id=\"$tag\" counter=\"$unread\"/>";
91 }
92 }
93
94 function getLabelCounters($link) {
95
96 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
97 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
98 unread = true AND owner_uid = ".$_SESSION["uid"]);
99
100 $count = db_fetch_result($result, 0, "count");
101
102 print "<label id=\"-1\" counter=\"$count\"/>";
103
104 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
105 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
106
107 while ($line = db_fetch_assoc($result)) {
108
109 $id = -$line["id"] - 11;
110
111 error_reporting (0);
112
113 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
114 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
115 ttrss_user_entries.ref_id = ttrss_entries.id AND
116 owner_uid = ".$_SESSION["uid"]);
117
118 $count = db_fetch_result($tmp_result, 0, "count");
119
120 print "<label id=\"$id\" counter=\"$count\"/>";
121
122 error_reporting (E_ERROR | E_WARNING | E_PARSE);
123
124 }
125 }
126
127 function getFeedCounter($link, $id) {
128
129 $result = db_query($link, "SELECT
130 count(id) as count FROM ttrss_entries,ttrss_user_entries
131 WHERE feed_id = '$id' AND unread = true
132 AND ttrss_user_entries.ref_id = ttrss_entries.id");
133
134 $count = db_fetch_result($result, 0, "count");
135
136 print "<feed id=\"$id\" counter=\"$count\"/>";
137 }
138
139 function getFeedCounters($link) {
140
141 $result = db_query($link, "SELECT id,
142 (SELECT count(id)
143 FROM ttrss_entries,ttrss_user_entries
144 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
145 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
146 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
147
148 while ($line = db_fetch_assoc($result)) {
149
150 $id = $line["id"];
151 $count = $line["count"];
152
153 print "<feed id=\"$id\" counter=\"$count\"/>";
154 }
155 }
156
157 function outputFeedList($link, $tags = false) {
158
159 print "<html><head>
160 <title>Tiny Tiny RSS : Feedlist</title>
161 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
162
163 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
164 print "<link rel=\"stylesheet\" type=\"text/css\"
165 href=\"tt-rss_compact.css\"/>";
166 } else {
167 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
168 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
169 }
170
171 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
172 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
173 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
174 </head><body onload=\"init()\">";
175
176 print "<ul class=\"feedList\" id=\"feedList\">";
177
178 $owner_uid = $_SESSION["uid"];
179
180 if (!$tags) {
181
182 /* virtual feeds */
183
184 $result = db_query($link, "SELECT count(id) as num_starred
185 FROM ttrss_entries,ttrss_user_entries
186 WHERE marked = true AND
187 ttrss_user_entries.ref_id = ttrss_entries.id AND
188 unread = true AND owner_uid = '$owner_uid'");
189 $num_starred = db_fetch_result($result, 0, "num_starred");
190
191 $class = "virt";
192
193 if ($num_starred > 0) $class .= "Unread";
194
195 printFeedEntry(-1, $class, "Starred articles", $num_starred,
196 "images/mark_set.png", $link);
197
198 if (get_pref($link, 'ENABLE_LABELS')) {
199
200 $result = db_query($link, "SELECT id,sql_exp,description FROM
201 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
202
203 if (db_num_rows($result) > 0) {
204 print "<li><hr></li>";
205 }
206
207 while ($line = db_fetch_assoc($result)) {
208
209 error_reporting (0);
210
211 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
212 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
213 ttrss_user_entries.ref_id = ttrss_entries.id
214 AND owner_uid = '$owner_uid'");
215
216 $count = db_fetch_result($tmp_result, 0, "count");
217
218 $class = "label";
219
220 if ($count > 0) {
221 $class .= "Unread";
222 }
223
224 error_reporting (E_ERROR | E_WARNING | E_PARSE);
225
226 printFeedEntry(-$line["id"]-11,
227 $class, $line["description"], $count, "images/label.png", $link);
228
229 }
230 }
231
232 print "<li><hr></li>";
233
234 $result = db_query($link, "SELECT *,
235 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
236 WHERE feed_id = ttrss_feeds.id AND
237 ttrss_user_entries.ref_id = ttrss_entries.id AND
238 owner_uid = '$owner_uid') AS total,
239 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
240 WHERE feed_id = ttrss_feeds.id AND unread = true
241 AND ttrss_user_entries.ref_id = ttrss_entries.id
242 AND owner_uid = '$owner_uid') as unread
243 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");
244
245 $actid = $_GET["actid"];
246
247 /* real feeds */
248
249 $lnum = 0;
250
251 $total_unread = 0;
252
253 while ($line = db_fetch_assoc($result)) {
254
255 $feed = $line["title"];
256 $feed_id = $line["id"];
257
258 $subop = $_GET["subop"];
259
260 $total = $line["total"];
261 $unread = $line["unread"];
262
263 // $class = ($lnum % 2) ? "even" : "odd";
264
265 $class = "feed";
266
267 if ($unread > 0) $class .= "Unread";
268
269 if ($actid == $feed_id) {
270 $class .= "Selected";
271 }
272
273 $total_unread += $unread;
274
275 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
276
277 ++$lnum;
278 }
279 } else {
280
281 // tags
282
283 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
284 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
285 post_int_id = ttrss_user_entries.int_id AND
286 unread = true AND ref_id = ttrss_entries.id
287 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
288 UNION
289 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
290 ORDER BY tag_name");
291
292 $tags = array();
293
294 while ($line = db_fetch_assoc($result)) {
295 $tags[$line["tag_name"]] += $line["count"];
296 }
297
298 foreach (array_keys($tags) as $tag) {
299
300 $unread = $tags[$tag];
301
302 $class = "odd";
303
304 if ($unread > 0) {
305 $class .= "Unread";
306 }
307
308 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
309
310 }
311
312 }
313
314 if (db_num_rows($result) == 0) {
315 print "<li>No tags/feeds to display.</li>";
316 }
317
318 print "</ul>";
319
320 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
321
322 }
323
324
325 if ($op == "rpc") {
326
327 $subop = $_GET["subop"];
328
329 if ($subop == "getLabelCounters") {
330 $aid = $_GET["aid"];
331 print "<rpc-reply>";
332 getLabelCounters($link);
333 if ($aid) {
334 getFeedCounter($link, $aid);
335 }
336 print "</rpc-reply>";
337 }
338
339 if ($subop == "getFeedCounters") {
340 print "<rpc-reply>";
341 getFeedCounters($link);
342 print "</rpc-reply>";
343 }
344
345 if ($subop == "getAllCounters") {
346 print "<rpc-reply>";
347 getLabelCounters($link);
348 getFeedCounters($link);
349 getTagCounters($link);
350 getGlobalCounters($link);
351 print "</rpc-reply>";
352 }
353
354 if ($subop == "mark") {
355 $mark = $_GET["mark"];
356 $id = db_escape_string($_GET["id"]);
357
358 if ($mark == "1") {
359 $mark = "true";
360 } else {
361 $mark = "false";
362 }
363
364 // FIXME this needs collision testing
365
366 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
367 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
368 }
369
370 if ($subop == "updateFeed") {
371 $feed_id = db_escape_string($_GET["feed"]);
372
373 $result = db_query($link,
374 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
375 AND owner_uid = " . $_SESSION["uid"]);
376
377 if (db_num_rows($result) > 0) {
378 $feed_url = db_fetch_result($result, 0, "feed_url");
379 update_rss_feed($link, $feed_url, $feed_id);
380 }
381
382 print "<rpc-reply>";
383 getFeedCounter($link, $feed_id);
384 print "</rpc-reply>";
385
386 return;
387 }
388
389 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
390
391 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
392
393 $omode = $_GET["omode"];
394
395 if (!$omode) $omode = "tfl";
396
397 print "<rpc-reply>";
398 if (strchr($omode, "l")) getLabelCounters($link);
399 if (strchr($omode, "f")) getFeedCounters($link);
400 if (strchr($omode, "t")) getTagCounters($link);
401 getGlobalCounters($link);
402 print "</rpc-reply>";
403 }
404
405 if ($subop == "catchupSelected") {
406
407 $ids = split(",", $_GET["ids"]);
408
409 foreach ($ids as $id) {
410
411 db_query($link, "UPDATE ttrss_user_entries SET unread=false,last_read = NOW()
412 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
413
414 }
415
416 print "Marked active page as read.";
417 }
418
419 if ($subop == "sanityCheck") {
420
421 $error_code = 0;
422
423 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
424
425 $schema_version = db_fetch_result($result, 0, "schema_version");
426
427 if ($schema_version != SCHEMA_VERSION) {
428 $error_code = 5;
429 }
430
431 print "<error error-code='$error_code'/>";
432 }
433
434 if ($subop == "globalPurge") {
435
436 print "<rpc-reply>";
437 global_purge_old_posts($link, true);
438 print "</rpc-reply>";
439
440 }
441
442 }
443
444 if ($op == "feeds") {
445
446 $tags = $_GET["tags"];
447
448 $subop = $_GET["subop"];
449
450 if ($subop == "catchupAll") {
451 db_query($link, "UPDATE ttrss_user_entries SET
452 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
453 }
454
455 outputFeedList($link, $tags);
456
457 }
458
459 if ($op == "view") {
460
461 $id = $_GET["id"];
462 $feed_id = $_GET["feed"];
463
464 $result = db_query($link, "UPDATE ttrss_user_entries
465 SET unread = false,last_read = NOW()
466 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
467
468 $addheader = $_GET["addheader"];
469
470 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
471 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
472 FROM ttrss_entries,ttrss_user_entries
473 WHERE id = '$id' AND ref_id = id");
474
475 if ($addheader) {
476 print "<html><head>
477 <title>Tiny Tiny RSS : Article $id</title>
478 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
479 <script type=\"text/javascript\" src=\"functions.js\"></script>
480 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
481 </head><body>";
482 }
483
484 if ($result) {
485
486 $line = db_fetch_assoc($result);
487
488 if ($line["icon_url"]) {
489 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
490 } else {
491 $feed_icon = "&nbsp;";
492 }
493
494 if ($line["comments"] && $line["link"] != $line["comments"]) {
495 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
496 } else {
497 $entry_comments = "";
498 }
499
500 print "<div class=\"postReply\">";
501
502 print "<div class=\"postHeader\"><table>";
503
504 print "<tr><td><b>Title:</b></td>
505 <td width='100%'>" . $line["title"] . "</td></tr>";
506
507 print "<tr><td><b>Link:</b></td>
508 <td width='100%'>
509 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
510 $entry_comments</td></tr>";
511
512 print "</table></div>";
513
514 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
515 print "<div class=\"postContent\">" . $line["content"] . "</div>";
516
517 print "</div>";
518
519 print "<script type=\"text/javascript\">
520 update_label_counters('$feed_id');
521 </script>";
522 }
523
524 if ($addheader) {
525 print "</body></html>";
526 }
527 }
528
529 if ($op == "viewfeed") {
530
531 $feed = $_GET["feed"];
532 $skip = $_GET["skip"];
533 $subop = $_GET["subop"];
534 $view_mode = $_GET["view"];
535 $addheader = $_GET["addheader"];
536 $limit = $_GET["limit"];
537
538 if (!$feed) {
539 print "Error: no feed to display.";
540 return;
541 }
542
543 if (!$skip) $skip = 0;
544
545 if ($subop == "undefined") $subop = "";
546
547 if ($addheader) {
548 print "<html><head>
549 <title>Tiny Tiny RSS : Feed $feed</title>
550 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
551
552 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
553 print "<link rel=\"stylesheet\"
554 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
555
556 } else {
557 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
558 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
559 }
560 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
561 <script type=\"text/javascript\" src=\"functions.js\"></script>
562 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
563 </head><body onload='init()'>";
564 }
565
566 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
567
568 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
569 WHERE id = '$feed'");
570
571 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
572
573 update_rss_feed($link, $feed_url, $feed);
574
575 }
576
577 if ($subop == "MarkAllRead") {
578
579 if (sprintf("%d", $feed) != 0) {
580
581 if ($feed > 0) {
582 db_query($link, "UPDATE ttrss_user_entries
583 SET unread = false,last_read = NOW()
584 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
585
586 } else if ($feed < 0 && $feed > -10) { // special, like starred
587
588 if ($feed == -1) {
589 db_query($link, "UPDATE ttrss_user_entries
590 SET unread = false,last_read = NOW()
591 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
592 }
593
594 } else if ($feed < -10) { // label
595
596 // TODO make this more efficient
597
598 $label_id = -$feed - 11;
599
600 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
601 WHERE id = '$label_id'");
602
603 if ($tmp_result) {
604 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
605
606 db_query($link, "BEGIN");
607
608 $tmp2_result = db_query($link,
609 "SELECT
610 int_id
611 FROM
612 ttrss_user_entries,ttrss_entries
613 WHERE
614 ref_id = id AND
615 $sql_exp AND
616 owner_uid = " . $_SESSION["uid"]);
617
618 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
619 db_query($link, "UPDATE
620 ttrss_user_entries
621 SET
622 unread = false, last_read = NOW()
623 WHERE
624 int_id = " . $tmp_line["int_id"]);
625 }
626
627 db_query($link, "COMMIT");
628
629 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
630 SET unread = false,last_read = NOW()
631 WHERE $sql_exp
632 AND ref_id = id
633 AND owner_uid = ".$_SESSION["uid"]); */
634 }
635 }
636 } else { // tag
637 // FIXME, implement catchup for tags
638 }
639
640 }
641
642 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
643
644 $search = $_GET["search"];
645
646 $search_mode = $_GET["smode"];
647
648 if ($search) {
649 $search_query_part = "(upper(title) LIKE upper('%$search%')
650 OR content LIKE '%$search%') AND";
651 } else {
652 $search_query_part = "";
653 }
654
655 $view_query_part = "";
656
657 if ($view_mode == "Starred") {
658 $view_query_part = " marked = true AND ";
659 }
660
661 if ($view_mode == "Unread") {
662 $view_query_part = " unread = true AND ";
663 }
664
665 if ($view_mode == "Unread or Starred") {
666 $view_query_part = " (unread = true OR marked = true) AND ";
667 }
668
669 if ($view_mode == "Unread or Updated") {
670 $view_query_part = " (unread = true OR last_read is NULL) AND ";
671 }
672
673 /* $result = db_query($link, "SELECT count(id) AS total_entries
674 FROM ttrss_entries WHERE
675 $search_query_part
676 feed_id = '$feed'");
677
678 $total_entries = db_fetch_result($result, 0, "total_entries"); */
679
680 /* $result = db_query("SELECT count(id) AS unread_entries
681 FROM ttrss_entries WHERE
682 $search_query_part
683 unread = true AND
684 feed_id = '$feed'");
685
686 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
687
688 if ($limit && $limit != "All") {
689 $limit_query_part = "LIMIT " . $limit;
690 }
691
692 $vfeed_query_part = "";
693
694 // override query strategy and enable feed display when searching globally
695 if ($search && $search_mode == "All feeds") {
696 $query_strategy_part = "id > 0";
697 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
698 id = feed_id) as feed_title,";
699 } else if (sprintf("%d", $feed) == 0) {
700 $query_strategy_part = "ttrss_entries.id > 0";
701 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
702 id = feed_id) as feed_title,";
703 } else if ($feed >= 0) {
704 $query_strategy_part = "feed_id = '$feed'";
705 } else if ($feed == -1) { // starred virtual feed
706 $query_strategy_part = "marked = true";
707 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
708 id = feed_id) as feed_title,";
709 } else if ($feed <= -10) { // labels
710 $label_id = -$feed - 11;
711
712 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
713 WHERE id = '$label_id'");
714
715 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
716
717 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
718 id = feed_id) as feed_title,";
719 } else {
720 $query_strategy_part = "id > 0"; // dumb
721 }
722
723
724 $order_by = "updated DESC";
725
726 // if ($feed < -10) {
727 // $order_by = "feed_id,updated DESC";
728 // }
729
730 if ($feed < -10) error_reporting (0);
731
732 if (sprintf("%d", $feed) != 0) {
733
734 $result = db_query($link, "SELECT
735 id,title,updated,unread,feed_id,marked,link,last_read,
736 SUBSTRING(last_read,1,19) as last_read_noms,
737 $vfeed_query_part
738 SUBSTRING(updated,1,19) as updated_noms
739 FROM
740 ttrss_entries,ttrss_user_entries
741 WHERE
742 ttrss_user_entries.ref_id = ttrss_entries.id AND
743 owner_uid = '".$_SESSION["uid"]."' AND
744 $search_query_part
745 $view_query_part
746 $query_strategy_part ORDER BY $order_by
747 $limit_query_part");
748
749 } else {
750 // browsing by tag
751
752 $result = db_query($link, "SELECT
753 ttrss_entries.id as id,title,updated,unread,feed_id,
754 marked,link,last_read,
755 SUBSTRING(last_read,1,19) as last_read_noms,
756 $vfeed_query_part
757 SUBSTRING(updated,1,19) as updated_noms
758 FROM
759 ttrss_entries,ttrss_user_entries,ttrss_tags
760 WHERE
761 ref_id = ttrss_entries.id AND
762 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
763 post_int_id = int_id AND tag_name = '$feed' AND
764 $view_query_part
765 $search_query_part
766 $query_strategy_part ORDER BY $order_by
767 $limit_query_part");
768 }
769
770 if (!$result) {
771 print "<tr><td colspan='4' align='center'>
772 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
773 return;
774 }
775
776 $lnum = 0;
777
778 error_reporting (E_ERROR | E_WARNING | E_PARSE);
779
780 $num_unread = 0;
781
782 while ($line = db_fetch_assoc($result)) {
783
784 $class = ($lnum % 2) ? "even" : "odd";
785
786 $id = $line["id"];
787 $feed_id = $line["feed_id"];
788
789 // printf("L %d (%s) &gt; U %d (%s) = %d<br>",
790 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
791 // strtotime($line["updated"]), $line["updated"],
792 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
793
794 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
795 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
796
797 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
798 alt=\"Updated\">";
799
800 } else {
801
802 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
803 alt=\"Updated\">";
804
805 } */
806
807 if ($line["last_read"] == "" &&
808 ($line["unread"] != "t" && $line["unread"] != "1")) {
809
810 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
811 alt=\"Updated\">";
812 } else {
813 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
814 alt=\"Updated\">";
815 }
816
817 if ($line["unread"] == "t" || $line["unread"] == "1") {
818 $class .= "Unread";
819 ++$num_unread;
820 }
821
822 if ($line["marked"] == "t" || $line["marked"] == "1") {
823 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
824 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
825 } else {
826 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
827 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
828 }
829
830 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
831 $line["title"] . "</a>";
832
833 print "<tr class='$class' id='RROW-$id'>";
834 // onclick=\"javascript:view($id,$feed_id)\">
835
836 print "<td valign='center' align='center'>$update_pic</td>";
837 print "<td valign='center' align='center'>$marked_pic</td>";
838
839 print "<td width='25%'>
840 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
841
842 if ($line["feed_title"]) {
843 print "<td width='50%'>$content_link</td>";
844 print "<td width='20%'>
845 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
846 } else {
847 print "<td width='70%'>$content_link</td>";
848 }
849
850 print "</tr>";
851
852 ++$lnum;
853 }
854
855 if ($lnum == 0) {
856 print "<tr><td align='center'>No articles found.</td></tr>";
857 }
858
859 print "</table>";
860
861 print "<script type=\"text/javascript\">
862 document.onkeydown = hotkey_handler;
863 update_label_counters('$feed');
864 </script>";
865
866 if ($addheader) {
867 print "</body></html>";
868 }
869
870 }
871
872 if ($op == "pref-rpc") {
873
874 $subop = $_GET["subop"];
875
876 if ($subop == "unread") {
877 $ids = split(",", $_GET["ids"]);
878 foreach ($ids as $id) {
879 db_query($link, "UPDATE ttrss_user_entries SET unread = true
880 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
881 }
882
883 print "Marked selected feeds as unread.";
884 }
885
886 if ($subop == "read") {
887 $ids = split(",", $_GET["ids"]);
888 foreach ($ids as $id) {
889 db_query($link, "UPDATE ttrss_user_entries
890 SET unread = false,last_read = NOW() WHERE
891 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
892 }
893
894 print "Marked selected feeds as read.";
895
896 }
897
898 }
899
900 if ($op == "pref-feeds") {
901
902 $subop = $_GET["subop"];
903
904 if ($subop == "editSave") {
905 $feed_title = db_escape_string($_GET["t"]);
906 $feed_link = db_escape_string($_GET["l"]);
907 $upd_intl = db_escape_string($_GET["ui"]);
908 $purge_intl = db_escape_string($_GET["pi"]);
909 $feed_id = $_GET["id"];
910
911 if (strtoupper($upd_intl) == "DEFAULT")
912 $upd_intl = 0;
913
914 if (strtoupper($purge_intl) == "DEFAULT")
915 $purge_intl = 0;
916
917 if (strtoupper($purge_intl) == "DISABLED")
918 $purge_intl = -1;
919
920 $result = db_query($link, "UPDATE ttrss_feeds SET
921 title = '$feed_title', feed_url = '$feed_link',
922 update_interval = '$upd_intl',
923 purge_interval = '$purge_intl'
924 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
925
926 }
927
928 if ($subop == "remove") {
929
930 if (!WEB_DEMO_MODE) {
931
932 $ids = split(",", $_GET["ids"]);
933
934 foreach ($ids as $id) {
935 db_query($link, "DELETE FROM ttrss_feeds
936 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
937
938 $icons_dir = ICONS_DIR;
939
940 if (file_exists($icons_dir . "/$id.ico")) {
941 unlink($icons_dir . "/$id.ico");
942 }
943 }
944 }
945 }
946
947 if ($subop == "add") {
948
949 if (!WEB_DEMO_MODE) {
950
951 $feed_link = db_escape_string($_GET["link"]);
952
953 $result = db_query($link,
954 "SELECT id FROM ttrss_feeds
955 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
956
957 if (db_num_rows($result) == 0) {
958
959 $result = db_query($link,
960 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
961 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
962
963 $result = db_query($link,
964 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
965 AND owner_uid = " . $_SESSION["uid"]);
966
967 $feed_id = db_fetch_result($result, 0, "id");
968
969 if ($feed_id) {
970 update_rss_feed($link, $feed_link, $feed_id);
971 }
972 } else {
973
974 print "<div class=\"warning\">
975 Feed <b>$feed_link</b> already exists in the database.
976 </div>";
977 }
978 }
979 }
980
981 $result = db_query($link, "SELECT id,title,feed_url,last_error
982 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
983
984 if (db_num_rows($result) > 0) {
985
986 print "<div class=\"warning\">";
987
988 print "<b>Feeds with update errors:</b>";
989
990 print "<ul class=\"nomarks\">";
991
992 while ($line = db_fetch_assoc($result)) {
993 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
994 $line["last_error"];
995 }
996
997 print "</ul>";
998 print "</div>";
999
1000 }
1001
1002 print "<table class=\"prefAddFeed\"><tr>
1003 <td><input id=\"fadd_link\"></td>
1004 <td colspan=\"4\" align=\"right\">
1005 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
1006 </table>";
1007
1008 $result = db_query($link, "SELECT
1009 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1010 update_interval,purge_interval
1011 FROM
1012 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
1013
1014 print "<div id=\"infoBox\">PLACEHOLDER</div>";
1015
1016 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
1017 print "<tr class=\"title\">
1018 <td>&nbsp;</td><td>Select</td><td width=\"30%\">Title</td>
1019 <td width=\"30%\">Link</td>
1020 <td width=\"10%\">Update Interval</td>
1021 <td width=\"10%\">Purge Days</td>
1022 <td>Last updated</td></tr>";
1023
1024 $lnum = 0;
1025
1026 while ($line = db_fetch_assoc($result)) {
1027
1028 $class = ($lnum % 2) ? "even" : "odd";
1029
1030 $feed_id = $line["id"];
1031
1032 $edit_feed_id = $_GET["id"];
1033
1034 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1035 $class .= "Grayed";
1036 }
1037
1038 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
1039
1040 $icon_file = ICONS_DIR . "/$feed_id.ico";
1041
1042 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1043 $feed_icon = "<img width=\"16\" height=\"16\"
1044 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1045 } else {
1046 $feed_icon = "&nbsp;";
1047 }
1048 print "<td align='center'>$feed_icon</td>";
1049
1050 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1051 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1052
1053 if (!$edit_feed_id || $subop != "edit") {
1054
1055 print "<td><input onclick='toggleSelectRow(this);'
1056 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1057
1058 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1059 $edit_title . "</a></td>";
1060 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1061 $edit_link . "</a></td>";
1062
1063 if ($line["update_interval"] == "0")
1064 $line["update_interval"] = "Default";
1065
1066 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1067 $line["update_interval"] . "</a></td>";
1068
1069 if ($line["purge_interval"] == "0")
1070 $line["purge_interval"] = "Default";
1071
1072 if ($line["purge_interval"] < 0)
1073 $line["purge_interval"] = "Disabled";
1074
1075 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1076 $line["purge_interval"] . "</a></td>";
1077
1078 } else if ($feed_id != $edit_feed_id) {
1079
1080 print "<td><input disabled=\"true\" type=\"checkbox\"
1081 id=\"FRCHK-".$line["id"]."\"></td>";
1082
1083 print "<td>$edit_title</td>";
1084 print "<td>$edit_link</td>";
1085
1086 if ($line["update_interval"] == "0")
1087 $line["update_interval"] = "Default";
1088
1089 print "<td>" . $line["update_interval"] . "</td>";
1090
1091 if ($line["purge_interval"] == "0")
1092 $line["purge_interval"] = "Default";
1093
1094 if ($line["purge_interval"] < 0)
1095 $line["purge_interval"] = "Disabled";
1096
1097 print "<td>" . $line["purge_interval"] . "</td>";
1098
1099 } else {
1100
1101 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1102
1103 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1104 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1105 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
1106 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
1107
1108 }
1109
1110 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1111
1112 print "<td>" . $line["last_updated"] . "</td>";
1113
1114 print "</tr>";
1115
1116 ++$lnum;
1117 }
1118
1119 if ($lnum == 0) {
1120 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1121 }
1122
1123 print "</table>";
1124
1125 print "<p>";
1126
1127 if ($subop == "edit") {
1128 print "Edit feed:&nbsp;
1129 <input type=\"submit\" class=\"button\"
1130 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1131 <input type=\"submit\" class=\"button\"
1132 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1133 } else {
1134
1135 print "
1136 Selection:&nbsp;
1137 <input type=\"submit\" class=\"button\"
1138 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1139 <input type=\"submit\" class=\"button\"
1140 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1141 <input type=\"submit\" class=\"button\"
1142 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1143
1144 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1145 print "
1146 <input type=\"submit\" class=\"button\"
1147 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1148 <input type=\"submit\" class=\"button\"
1149 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
1150 }
1151 print "
1152 All feeds:
1153 <input type=\"submit\"
1154 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1155
1156 }
1157
1158 print "<h3>OPML Import</h3>
1159 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1160 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1161 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1162 type=\"submit\" value=\"Import\">
1163 </form>";
1164
1165 }
1166
1167 if ($op == "pref-filters") {
1168
1169 $subop = $_GET["subop"];
1170
1171 if ($subop == "editSave") {
1172
1173 $regexp = db_escape_string($_GET["r"]);
1174 $descr = db_escape_string($_GET["d"]);
1175 $match = db_escape_string($_GET["m"]);
1176 $filter_id = db_escape_string($_GET["id"]);
1177
1178 $result = db_query($link, "UPDATE ttrss_filters SET
1179 reg_exp = '$regexp',
1180 description = '$descr',
1181 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1182 description = '$match')
1183 WHERE id = '$filter_id'");
1184 }
1185
1186 if ($subop == "remove") {
1187
1188 if (!WEB_DEMO_MODE) {
1189
1190 $ids = split(",", $_GET["ids"]);
1191
1192 foreach ($ids as $id) {
1193 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1194
1195 }
1196 }
1197 }
1198
1199 if ($subop == "add") {
1200
1201 if (!WEB_DEMO_MODE) {
1202
1203 $regexp = db_escape_string($_GET["regexp"]);
1204 $match = db_escape_string($_GET["match"]);
1205
1206 $result = db_query($link,
1207 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES
1208 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1209 description = '$match'),'".$_SESSION["uid"]."')");
1210 }
1211 }
1212
1213 $result = db_query($link, "SELECT description
1214 FROM ttrss_filter_types ORDER BY description");
1215
1216 $filter_types = array();
1217
1218 while ($line = db_fetch_assoc($result)) {
1219 array_push($filter_types, $line["description"]);
1220 }
1221
1222 print "<table class=\"prefAddFeed\"><tr>
1223 <td><input id=\"fadd_regexp\"></td>
1224 <td>";
1225 print_select("fadd_match", "Title", $filter_types);
1226
1227 print"</td><td colspan=\"4\" align=\"right\">
1228 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1229 </table>";
1230
1231 $result = db_query($link, "SELECT
1232 id,reg_exp,description,
1233 (SELECT name FROM ttrss_filter_types WHERE
1234 id = filter_type) as filter_type_name,
1235 (SELECT description FROM ttrss_filter_types
1236 WHERE id = filter_type) as filter_type_descr
1237 FROM
1238 ttrss_filters
1239 WHERE
1240 owner_uid = ".$_SESSION["uid"]."
1241 ORDER by reg_exp");
1242
1243 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1244
1245 print "<tr class=\"title\">
1246 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1247 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1248
1249 $lnum = 0;
1250
1251 while ($line = db_fetch_assoc($result)) {
1252
1253 $class = ($lnum % 2) ? "even" : "odd";
1254
1255 $filter_id = $line["id"];
1256 $edit_filter_id = $_GET["id"];
1257
1258 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1259 $class .= "Grayed";
1260 }
1261
1262 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1263
1264 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1265 $line["description"] = htmlspecialchars($line["description"]);
1266
1267 if (!$edit_filter_id || $subop != "edit") {
1268
1269 if (!$line["description"]) $line["description"] = "[No description]";
1270
1271 print "<td><input onclick='toggleSelectRow(this);'
1272 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1273
1274 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1275 $line["reg_exp"] . "</td>";
1276
1277 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1278 $line["description"] . "</td>";
1279
1280 print "<td>".$line["filter_type_descr"]."</td>";
1281
1282 } else if ($filter_id != $edit_filter_id) {
1283
1284 if (!$line["description"]) $line["description"] = "[No description]";
1285
1286 print "<td><input disabled=\"true\" type=\"checkbox\"
1287 id=\"FICHK-".$line["id"]."\"></td>";
1288
1289 print "<td>".$line["reg_exp"]."</td>";
1290 print "<td>".$line["description"]."</td>";
1291 print "<td>".$line["filter_type_descr"]."</td>";
1292
1293 } else {
1294
1295 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1296
1297 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1298 "\"></td>";
1299
1300 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1301 "\"></td>";
1302
1303 print "<td>";
1304 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1305 print "</td>";
1306
1307 }
1308
1309
1310 print "</tr>";
1311
1312 ++$lnum;
1313 }
1314
1315 if ($lnum == 0) {
1316 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1317 }
1318
1319 print "</table>";
1320
1321 print "<p>";
1322
1323 if ($subop == "edit") {
1324 print "Edit feed:
1325 <input type=\"submit\" class=\"button\"
1326 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1327 <input type=\"submit\" class=\"button\"
1328 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1329
1330 } else {
1331
1332 print "
1333 Selection:
1334 <input type=\"submit\" class=\"button\"
1335 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1336 <input type=\"submit\" class=\"button\"
1337 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1338 }
1339 }
1340
1341 if ($op == "pref-labels") {
1342
1343 $subop = $_GET["subop"];
1344
1345 if ($subop == "editSave") {
1346
1347 $sql_exp = $_GET["s"];
1348 $descr = $_GET["d"];
1349 $label_id = db_escape_string($_GET["id"]);
1350
1351 // print "$sql_exp : $descr : $label_id";
1352
1353 $result = db_query($link, "UPDATE ttrss_labels SET
1354 sql_exp = '$sql_exp',
1355 description = '$descr'
1356 WHERE id = '$label_id'");
1357 }
1358
1359 if ($subop == "remove") {
1360
1361 if (!WEB_DEMO_MODE) {
1362
1363 $ids = split(",", $_GET["ids"]);
1364
1365 foreach ($ids as $id) {
1366 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1367
1368 }
1369 }
1370 }
1371
1372 if ($subop == "add") {
1373
1374 if (!WEB_DEMO_MODE) {
1375
1376 $exp = $_GET["exp"];
1377
1378 $result = db_query($link,
1379 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1380 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
1381 }
1382 }
1383
1384 print "<table class=\"prefAddFeed\"><tr>
1385 <td><input id=\"ladd_expr\"></td>";
1386
1387 print"<td colspan=\"4\" align=\"right\">
1388 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1389 </table>";
1390
1391 $result = db_query($link, "SELECT
1392 id,sql_exp,description
1393 FROM
1394 ttrss_labels
1395 WHERE
1396 owner_uid = ".$_SESSION["uid"]."
1397 ORDER by description");
1398
1399 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1400
1401 print "<tr class=\"title\">
1402 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1403 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1404 </td>
1405 <td width=\"40%\">Caption</td></tr>";
1406
1407 $lnum = 0;
1408
1409 while ($line = db_fetch_assoc($result)) {
1410
1411 $class = ($lnum % 2) ? "even" : "odd";
1412
1413 $label_id = $line["id"];
1414 $edit_label_id = $_GET["id"];
1415
1416 if ($subop == "edit" && $label_id != $edit_label_id) {
1417 $class .= "Grayed";
1418 }
1419
1420 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1421
1422 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1423 $line["description"] = htmlspecialchars($line["description"]);
1424
1425 if (!$edit_label_id || $subop != "edit") {
1426
1427 if (!$line["description"]) $line["description"] = "[No caption]";
1428
1429 print "<td><input onclick='toggleSelectRow(this);'
1430 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1431
1432 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1433 $line["sql_exp"] . "</td>";
1434
1435 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1436 $line["description"] . "</td>";
1437
1438 } else if ($label_id != $edit_label_id) {
1439
1440 if (!$line["description"]) $line["description"] = "[No description]";
1441
1442 print "<td><input disabled=\"true\" type=\"checkbox\"
1443 id=\"LICHK-".$line["id"]."\"></td>";
1444
1445 print "<td>".$line["sql_exp"]."</td>";
1446 print "<td>".$line["description"]."</td>";
1447
1448 } else {
1449
1450 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1451
1452 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1453 "\"></td>";
1454
1455 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1456 "\"></td>";
1457
1458 }
1459
1460
1461 print "</tr>";
1462
1463 ++$lnum;
1464 }
1465
1466 if ($lnum == 0) {
1467 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1468 }
1469
1470 print "</table>";
1471
1472 print "<p>";
1473
1474 if ($subop == "edit") {
1475 print "Edit label:
1476 <input type=\"submit\" class=\"button\"
1477 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1478 <input type=\"submit\" class=\"button\"
1479 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1480
1481 } else {
1482
1483 print "
1484 Selection:
1485 <input type=\"submit\" class=\"button\"
1486 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1487 <input type=\"submit\" class=\"button\"
1488 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1489 }
1490 }
1491
1492 if ($op == "error") {
1493 print "<div width=\"100%\" align='center'>";
1494 $msg = $_GET["msg"];
1495 print $msg;
1496 print "</div>";
1497 }
1498
1499 if ($op == "help") {
1500 print "<html><head>
1501 <title>Tiny Tiny RSS : Help</title>
1502 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1503 <script type=\"text/javascript\" src=\"functions.js\"></script>
1504 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1505 </head><body>";
1506
1507 $tid = sprintf("%d", $_GET["tid"]);
1508
1509 /* FIXME this badly needs real implementation */
1510
1511 print "<div class='helpResponse'>";
1512
1513 ?>
1514
1515 <h1>Help for SQL expressions</h1>
1516
1517 <h2>Description</h2>
1518
1519 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
1520 view feed query. You can match on ttrss_entries table fields
1521 and even use subselect to query additional information. This
1522 functionality is considered to be advanced and requires basic
1523 understanding of SQL.</p>
1524
1525 <h2>Examples</h2>
1526
1527 <pre>unread = true</pre>
1528
1529 Matches all unread articles
1530
1531 <pre>title like '%Linux%'</pre>
1532
1533 Matches all articles which mention Linux in the title. You get the idea.
1534
1535 <p>See the database schema included in the distribution package for gruesome
1536 details.</p>
1537
1538 <?
1539
1540 print "<div align='center'>
1541 <a class=\"helpLink\"
1542 href=\"javascript:window.close()\">(Close this window)</a></div>";
1543
1544 print "</div>";
1545
1546 print "</body></html>";
1547
1548 }
1549
1550 if ($op == "dlg") {
1551 $id = $_GET["id"];
1552 $param = $_GET["param"];
1553
1554 if ($id == "quickAddFeed") {
1555 print "Feed URL: <input
1556 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1557 id=\"qafInput\">
1558 <input class=\"button\"
1559 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1560 <input class=\"button\"
1561 type=\"submit\" onclick=\"javascript:closeDlg()\"
1562 value=\"Cancel\">";
1563 }
1564
1565 if ($id == "quickDelFeed") {
1566
1567 $param = db_escape_string($param);
1568
1569 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1570
1571 if ($result) {
1572
1573 $f_title = db_fetch_result($result, 0, "title");
1574
1575 print "Remove current feed ($f_title)?&nbsp;
1576 <input class=\"button\"
1577 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1578 <input class=\"button\"
1579 type=\"submit\" onclick=\"javascript:closeDlg()\"
1580 value=\"Cancel\">";
1581 } else {
1582 print "Error: Feed $param not found.&nbsp;
1583 <input class=\"button\"
1584 type=\"submit\" onclick=\"javascript:closeDlg()\"
1585 value=\"Cancel\">";
1586 }
1587 }
1588
1589 if ($id == "search") {
1590
1591 print "<input id=\"searchbox\" class=\"extSearch\"
1592 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1593 onchange=\"javascript:search()\">
1594 <select id=\"searchmodebox\">
1595 <option selected>All feeds</option>
1596 <option>This feed</option>
1597 </select>
1598 <input type=\"submit\"
1599 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1600 <input class=\"button\"
1601 type=\"submit\" onclick=\"javascript:closeDlg()\"
1602 value=\"Close\">";
1603
1604 }
1605
1606 }
1607
1608 if ($op == "updateAllFeeds") {
1609 update_all_feeds($link, true);
1610
1611 print "<rpc-reply>";
1612 getLabelCounters($link);
1613 getFeedCounters($link);
1614 getTagCounters($link);
1615 getGlobalCounters($link);
1616 print "</rpc-reply>";
1617
1618 }
1619
1620 if ($op == "pref-prefs") {
1621
1622 $subop = $_REQUEST["subop"];
1623
1624 if ($subop == "Save configuration") {
1625
1626 if (WEB_DEMO_MODE) return;
1627
1628 foreach (array_keys($_POST) as $pref_name) {
1629
1630 $pref_name = db_escape_string($pref_name);
1631 $value = db_escape_string($_POST[$pref_name]);
1632
1633 $result = db_query($link, "SELECT type_name
1634 FROM ttrss_prefs,ttrss_prefs_types
1635 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
1636
1637 if (db_num_rows($result) > 0) {
1638
1639 $type_name = db_fetch_result($result, 0, "type_name");
1640
1641 // print "$pref_name : $type_name : $value<br>";
1642
1643 if ($type_name == "bool") {
1644 if ($value == "1") {
1645 $value = "true";
1646 } else {
1647 $value = "false";
1648 }
1649 } else if ($type_name == "integer") {
1650 $value = sprintf("%d", $value);
1651 }
1652
1653 // print "$pref_name : $type_name : $value<br>";
1654
1655 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
1656 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
1657
1658 }
1659
1660 header("Location: prefs.php");
1661
1662 }
1663
1664 } else if ($subop == "getHelp") {
1665
1666 $pref_name = db_escape_string($_GET["pn"]);
1667
1668 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
1669 WHERE pref_name = '$pref_name'");
1670
1671 if (db_num_rows($result) > 0) {
1672 $help_text = db_fetch_result($result, 0, "help_text");
1673 print $help_text;
1674 } else {
1675 print "Unknown option: $pref_name";
1676 }
1677
1678 } else if ($subop == "Change password") {
1679
1680 if (WEB_DEMO_MODE) return;
1681
1682 $old_pw = $_POST["OLD_PASSWORD"];
1683 $new_pw = $_POST["OLD_PASSWORD"];
1684
1685 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
1686 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
1687
1688 $active_uid = $_SESSION["uid"];
1689
1690 if ($old_pw && $new_pw) {
1691
1692 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
1693
1694 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1695 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
1696 pwd_hash = '$old_pw_hash')");
1697
1698 if (db_num_rows($result) == 1) {
1699 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
1700 WHERE id = '$active_uid'");
1701 }
1702 }
1703
1704 header("Location: prefs.php");
1705
1706 } else if ($subop == "Reset to defaults") {
1707
1708 if (WEB_DEMO_MODE) return;
1709
1710 if (DB_TYPE == "pgsql") {
1711 db_query($link,"UPDATE ttrss_user_prefs
1712 SET value = ttrss_prefs.def_value
1713 WHERE owner_uid = '".$_SESSION["uid"]."' AND
1714 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
1715 } else {
1716 db_query($link, "DELETE FROM ttrss_user_prefs
1717 WHERE owner_uid = ".$_SESSION["uid"]);
1718 initialize_user_prefs($link, $_SESSION["uid"]);
1719 }
1720
1721 header("Location: prefs.php");
1722
1723 } else {
1724
1725 if (!SINGLE_USER_MODE) {
1726
1727 print "<form action=\"backend.php\" method=\"POST\">";
1728
1729 print "<table width=\"100%\" class=\"prefPrefsList\">";
1730 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
1731
1732 print "<tr><td width=\"40%\">Old password</td>";
1733 print "<td><input class=\"editbox\" type=\"password\"
1734 name=\"OLD_PASSWORD\"></td></tr>";
1735
1736 print "<tr><td width=\"40%\">New password</td>";
1737
1738 print "<td><input class=\"editbox\" type=\"password\"
1739 name=\"NEW_PASSWORD\"></td></tr>";
1740
1741 print "</table>";
1742
1743 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1744
1745 print "<p><input class=\"button\" type=\"submit\"
1746 value=\"Change password\" name=\"subop\">";
1747
1748 print "</form>";
1749
1750 }
1751
1752 $result = db_query($link, "SELECT
1753 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
1754 section_name,def_value
1755 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
1756 WHERE type_id = ttrss_prefs_types.id AND
1757 section_id = ttrss_prefs_sections.id AND
1758 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
1759 owner_uid = ".$_SESSION["uid"]."
1760 ORDER BY section_id,short_desc");
1761
1762 print "<form action=\"backend.php\" method=\"POST\">";
1763
1764 $lnum = 0;
1765
1766 $active_section = "";
1767
1768 while ($line = db_fetch_assoc($result)) {
1769
1770 if ($active_section != $line["section_name"]) {
1771
1772 if ($active_section != "") {
1773 print "</table>";
1774 }
1775
1776 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
1777
1778 $active_section = $line["section_name"];
1779
1780 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
1781 // print "<tr class=\"title\">
1782 // <td width=\"25%\">Option</td><td>Value</td></tr>";
1783
1784 $lnum = 0;
1785 }
1786
1787 // $class = ($lnum % 2) ? "even" : "odd";
1788
1789 print "<tr>";
1790
1791 $type_name = $line["type_name"];
1792 $pref_name = $line["pref_name"];
1793 $value = $line["value"];
1794 $def_value = $line["def_value"];
1795 $help_text = $line["help_text"];
1796
1797 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
1798
1799 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
1800
1801 print "</td>";
1802
1803 print "<td>";
1804
1805 if ($type_name == "bool") {
1806 // print_select($pref_name, $value, array("true", "false"));
1807
1808 if ($value == "true") {
1809 $value = "Yes";
1810 } else {
1811 $value = "No";
1812 }
1813
1814 print_radio($pref_name, $value, array("Yes", "No"));
1815
1816 } else {
1817 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
1818 }
1819
1820 print "</td>";
1821
1822 print "</tr>";
1823
1824 $lnum++;
1825 }
1826
1827 print "</table>";
1828
1829 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1830
1831 print "<p><input class=\"button\" type=\"submit\"
1832 name=\"subop\" value=\"Save configuration\">";
1833
1834 print "&nbsp;<input class=\"button\" type=\"submit\"
1835 name=\"subop\" value=\"Reset to defaults\"></p>";
1836
1837 print "</form>";
1838
1839 }
1840
1841 }
1842
1843 if ($op == "pref-users") {
1844
1845 $subop = $_GET["subop"];
1846
1847 if ($subop == "editSave") {
1848
1849 if (!WEB_DEMO_MODE) {
1850
1851 $login = db_escape_string($_GET["l"]);
1852 $uid = db_escape_string($_GET["id"]);
1853 $access_level = sprintf("%d", $_GET["al"]);
1854
1855 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
1856
1857 }
1858 } else if ($subop == "remove") {
1859
1860 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1861
1862 $ids = split(",", $_GET["ids"]);
1863
1864 foreach ($ids as $id) {
1865 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
1866
1867 }
1868 }
1869 } else if ($subop == "add") {
1870
1871 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1872
1873 $login = db_escape_string($_GET["login"]);
1874 $tmp_user_pwd = make_password(8);
1875 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1876
1877 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
1878 VALUES ('$login', '$pwd_hash', 0)");
1879
1880
1881 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1882 login = '$login' AND pwd_hash = '$pwd_hash'");
1883
1884 if (db_num_rows($result) == 1) {
1885
1886 $new_uid = db_fetch_result($result, 0, "id");
1887
1888 print "<div class=\"notice\">Added user <b>".$_GET["login"].
1889 "</b> with password <b>$tmp_user_pwd</b>.</div>";
1890
1891 initialize_user($link, $new_uid);
1892
1893 } else {
1894
1895 print "<div class=\"warning\">Error while adding user <b>".
1896 $_GET["login"].".</b></div>";
1897
1898 }
1899 }
1900 } else if ($subop == "resetPass") {
1901
1902 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1903
1904 $uid = db_escape_string($_GET["id"]);
1905
1906 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
1907
1908 $login = db_fetch_result($result, 0, "login");
1909 $tmp_user_pwd = make_password(8);
1910 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1911
1912 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
1913 WHERE id = '$uid'");
1914
1915 print "<div class=\"notice\">Changed password of
1916 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
1917
1918 }
1919 }
1920
1921 print "<table class=\"prefAddFeed\"><tr>
1922 <td><input id=\"uadd_box\"></td>";
1923
1924 print"<td colspan=\"4\" align=\"right\">
1925 <a class=\"button\" href=\"javascript:addUser()\">Add user</a></td></tr>
1926 </table>";
1927
1928 $result = db_query($link, "SELECT
1929 id,login,access_level,last_login
1930 FROM
1931 ttrss_users
1932 ORDER by login");
1933
1934 print "<div id=\"infoBox\">PLACEHOLDER</div>";
1935
1936 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
1937
1938 print "<tr class=\"title\">
1939 <td width=\"5%\">Select</td>
1940 <td width='30%'>Username</td>
1941 <td width='30%'>Access Level</td>
1942 <td width='30%'>Last login</td></tr>";
1943
1944 $lnum = 0;
1945
1946 while ($line = db_fetch_assoc($result)) {
1947
1948 $class = ($lnum % 2) ? "even" : "odd";
1949
1950 $uid = $line["id"];
1951 $edit_uid = $_GET["id"];
1952
1953 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
1954 $class .= "Grayed";
1955 }
1956
1957 print "<tr class=\"$class\" id=\"UMRR-$uid\">";
1958
1959 $line["login"] = htmlspecialchars($line["login"]);
1960
1961 if ($uid == $_SESSION["uid"]) {
1962
1963 print "<td><input disabled=\"true\" type=\"checkbox\"
1964 id=\"UMCHK-".$line["id"]."\"></td>";
1965
1966 print "<td>".$line["login"]."</td>";
1967 print "<td>".$line["access_level"]."</td>";
1968
1969 } else if (!$edit_uid || $subop != "edit") {
1970
1971 print "<td><input onclick='toggleSelectRow(this);'
1972 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
1973
1974 print "<td><a href=\"javascript:editUser($uid);\">" .
1975 $line["login"] . "</td>";
1976
1977 print "<td><a href=\"javascript:editUser($uid);\">" .
1978 $line["access_level"] . "</td>";
1979
1980 } else if ($uid != $edit_uid) {
1981
1982 print "<td><input disabled=\"true\" type=\"checkbox\"
1983 id=\"UMCHK-".$line["id"]."\"></td>";
1984
1985 print "<td>".$line["login"]."</td>";
1986 print "<td>".$line["access_level"]."</td>";
1987
1988 } else {
1989
1990 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1991
1992 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
1993 "\"></td>";
1994
1995 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
1996 "\"></td>";
1997
1998 }
1999
2000 print "<td>".$line["last_login"]."</td>";
2001
2002 print "</tr>";
2003
2004 ++$lnum;
2005 }
2006
2007 print "</table>";
2008
2009 print "<p>";
2010
2011 if ($subop == "edit") {
2012 print "Edit label:
2013 <input type=\"submit\" class=\"button\"
2014 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2015 <input type=\"submit\" class=\"button\"
2016 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2017
2018 } else {
2019
2020 print "
2021 Selection:
2022 <input type=\"submit\" class=\"button\"
2023 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
2024 <input type=\"submit\" class=\"button\"
2025 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2026 <input type=\"submit\" class=\"button\"
2027 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2028 <input type=\"submit\" class=\"button\"
2029 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2030
2031 }
2032 }
2033
2034 if ($op == "user-details") {
2035
2036 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2037 return;
2038 }
2039
2040 /* print "<html><head>
2041 <title>Tiny Tiny RSS : User Details</title>
2042 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2043 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2044 </head><body>"; */
2045
2046 $uid = sprintf("%d", $_GET["id"]);
2047
2048 print "<div class='infoBoxContents'>";
2049
2050 $result = db_query($link, "SELECT login,last_login,access_level,
2051 (SELECT COUNT(int_id) FROM ttrss_user_entries
2052 WHERE owner_uid = id) AS stored_articles
2053 FROM ttrss_users
2054 WHERE id = '$uid'");
2055
2056 if (db_num_rows($result) == 0) {
2057 print "<h1>User not found</h1>";
2058 return;
2059 }
2060
2061 print "<h1>User Details</h1>";
2062
2063 print "<table width='100%'>";
2064
2065 $login = db_fetch_result($result, 0, "login");
2066 $last_login = db_fetch_result($result, 0, "last_login");
2067 $access_level = db_fetch_result($result, 0, "access_level");
2068 $stored_articles = db_fetch_result($result, 0, "stored_articles");
2069
2070 print "<tr><td>Username</td><td>$login</td></tr>";
2071 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2072 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
2073 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
2074
2075 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2076 WHERE owner_uid = '$uid'");
2077
2078 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2079
2080 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2081
2082 /* $result = db_query($link, "SELECT
2083 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
2084 FROM ttrss_user_entries,ttrss_entries
2085 WHERE owner_uid = '$uid' AND ref_id = id");
2086
2087 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
2088
2089 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
2090
2091 print "</table>";
2092
2093 print "<h1>Subscribed feeds</h1>";
2094
2095 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2096 WHERE owner_uid = '$uid' ORDER BY title");
2097
2098 print "<ul class=\"nomarks\">";
2099
2100 while ($line = db_fetch_assoc($result)) {
2101
2102 $icon_file = ICONS_URL."/".$line["id"].".ico";
2103
2104 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2105 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
2106 } else {
2107 $feed_icon = "<img class=\"feedIcon\" src=\"images/blank_icon.gif\">";
2108 }
2109
2110 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2111 }
2112
2113 print "</ul>";
2114
2115 print "</div>";
2116
2117 print "<div align='center'>
2118 <input type='submit' class='button'
2119 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2120
2121 // print "</body></html>";
2122
2123 }
2124
2125 if ($op == "feed-details") {
2126
2127 $feed_id = $_GET["id"];
2128
2129 $result = db_query($link,
2130 "SELECT
2131 title,feed_url,last_updated,
2132 (SELECT COUNT(int_id) FROM ttrss_user_entries
2133 WHERE feed_id = id) AS total,
2134 (SELECT COUNT(int_id) FROM ttrss_user_entries
2135 WHERE feed_id = id AND unread = true) AS unread,
2136 (SELECT COUNT(int_id) FROM ttrss_user_entries
2137 WHERE feed_id = id AND marked = true) AS marked
2138 FROM ttrss_feeds
2139 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2140
2141 if (db_num_rows($result) == 0) return;
2142
2143 $title = db_fetch_result($result, 0, "title");
2144 $last_updated = db_fetch_result($result, 0, "last_updated");
2145 $feed_url = db_fetch_result($result, 0, "feed_url");
2146 $total = db_fetch_result($result, 0, "total");
2147 $unread = db_fetch_result($result, 0, "unread");
2148 $marked = db_fetch_result($result, 0, "marked");
2149
2150 print "<div class=\"infoBoxContents\"><h1>$title</h1>";
2151
2152 print "<table width='100%'>";
2153
2154 print "<tr><td>Feed URL</td><td><a href=\"$feed_url\">$feed_url</a></td></tr>";
2155 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
2156 print "<tr><td>Total articles</td><td>$total</td></tr>";
2157 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
2158 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
2159
2160 print "</table>";
2161
2162 print "</div>";
2163
2164 print "<div align='center'>
2165 <input type='submit' class='button'
2166 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2167
2168 }
2169
2170 db_close($link);
2171 ?>
2172
2173 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
2174