]> git.wh0rd.org - tt-rss.git/blob - backend.php
headlines: hide subtoolbar when there are no articles to display
[tt-rss.git] / backend.php
1 <?
2 session_start();
3
4 if ($_GET["debug"]) {
5 define('DEFAULT_ERROR_LEVEL', E_ALL);
6 } else {
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
8 }
9
10 error_reporting(DEFAULT_ERROR_LEVEL);
11
12 $op = $_REQUEST["op"];
13
14 if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
15 header("Content-Type: application/xml");
16 }
17
18 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
19
20 if ($op == "rpc") {
21 print "<error error-code=\"6\"/>";
22 }
23 exit;
24 }
25
26 if (!$op) {
27 print "<error error-code=\"7\"/>";
28 exit;
29 }
30
31 define('SCHEMA_VERSION', 2);
32
33 require_once "sanity_check.php";
34 require_once "config.php";
35 require_once "db.php";
36 require_once "db-prefs.php";
37 require_once "functions.php";
38 require_once "magpierss/rss_fetch.inc";
39
40 $script_started = getmicrotime();
41
42 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
43
44 if (!$link) {
45 if (DB_TYPE == "mysql") {
46 print mysql_error();
47 }
48 // PG seems to display its own errors just fine by default.
49 return;
50 }
51
52 if (DB_TYPE == "pgsql") {
53 pg_query("set client_encoding = 'utf-8'");
54 }
55
56 $fetch = $_GET["fetch"];
57
58 function getAllCounters($link) {
59 getLabelCounters($link);
60 getFeedCounters($link);
61 getTagCounters($link);
62 getGlobalCounters($link);
63 }
64
65 /* FIXME this needs reworking */
66
67 function getGlobalCounters($link) {
68 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
69 WHERE unread = true AND
70 ttrss_user_entries.ref_id = ttrss_entries.id AND
71 owner_uid = " . $_SESSION["uid"]);
72 $c_id = db_fetch_result($result, 0, "c_id");
73 print "<counter id='global-unread' counter='$c_id'/>";
74 }
75
76 function getTagCounters($link) {
77
78 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
79 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
80 ttrss_user_entries.ref_id = ttrss_entries.id AND
81 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
82 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
83 UNION
84 select tag_name,0 as count FROM ttrss_tags
85 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
86
87 $tags = array();
88
89 while ($line = db_fetch_assoc($result)) {
90 $tags[$line["tag_name"]] += $line["count"];
91 }
92
93 foreach (array_keys($tags) as $tag) {
94 $unread = $tags[$tag];
95
96 $tag = htmlspecialchars($tag);
97 print "<tag id=\"$tag\" counter=\"$unread\"/>";
98 }
99 }
100
101 function getLabelCounters($link) {
102
103 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
104 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
105 unread = true AND owner_uid = ".$_SESSION["uid"]);
106
107 $count = db_fetch_result($result, 0, "count");
108
109 print "<label id=\"-1\" counter=\"$count\"/>";
110
111 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
112 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
113
114 while ($line = db_fetch_assoc($result)) {
115
116 $id = -$line["id"] - 11;
117
118 error_reporting (0);
119
120 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
121 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
122 ttrss_user_entries.ref_id = ttrss_entries.id AND
123 owner_uid = ".$_SESSION["uid"]);
124
125 $count = db_fetch_result($tmp_result, 0, "count");
126
127 print "<label id=\"$id\" counter=\"$count\"/>";
128
129 error_reporting (DEFAULT_ERROR_LEVEL);
130
131 }
132 }
133
134 function getFeedCounter($link, $id) {
135
136 $result = db_query($link, "SELECT
137 count(id) as count FROM ttrss_entries,ttrss_user_entries
138 WHERE feed_id = '$id' AND unread = true
139 AND ttrss_user_entries.ref_id = ttrss_entries.id");
140
141 $count = db_fetch_result($result, 0, "count");
142
143 print "<feed id=\"$id\" counter=\"$count\"/>";
144 }
145
146 function getFeedCounters($link) {
147
148 $result = db_query($link, "SELECT id,
149 (SELECT count(id)
150 FROM ttrss_entries,ttrss_user_entries
151 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
152 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
153 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
154
155 while ($line = db_fetch_assoc($result)) {
156
157 $id = $line["id"];
158 $count = $line["count"];
159
160 print "<feed id=\"$id\" counter=\"$count\"/>";
161 }
162 }
163
164 function outputFeedList($link, $tags = false) {
165
166 print "<html><head>
167 <title>Tiny Tiny RSS : Feedlist</title>
168 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
169
170 $user_theme = $_SESSION["theme"];
171 if ($user_theme) {
172 print "<link rel=\"stylesheet\" type=\"text/css\"
173 href=\"themes/$user_theme/theme.css\">";
174 }
175
176 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
177 print "<link rel=\"stylesheet\" type=\"text/css\"
178 href=\"tt-rss_compact.css\"/>";
179 } else {
180 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
181 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
182 }
183
184 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
185 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
186 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
187 </head><body onload=\"init()\">";
188
189 print "<ul class=\"feedList\" id=\"feedList\">";
190
191 $owner_uid = $_SESSION["uid"];
192
193 if (!$tags) {
194
195 /* virtual feeds */
196
197 if (get_pref($link, 'ENABLE_FEED_CATS')) {
198 print "<li class=\"feedCat\">Special</li>";
199 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
200 }
201
202 $result = db_query($link, "SELECT count(id) as num_starred
203 FROM ttrss_entries,ttrss_user_entries
204 WHERE marked = true AND
205 ttrss_user_entries.ref_id = ttrss_entries.id AND
206 unread = true AND owner_uid = '$owner_uid'");
207 $num_starred = db_fetch_result($result, 0, "num_starred");
208
209 $class = "virt";
210
211 if ($num_starred > 0) $class .= "Unread";
212
213 printFeedEntry(-1, $class, "Starred articles", $num_starred,
214 "images/mark_set.png", $link);
215
216 if (get_pref($link, 'ENABLE_FEED_CATS')) {
217 print "</li></ul>";
218 }
219
220 if (get_pref($link, 'ENABLE_LABELS')) {
221
222 $result = db_query($link, "SELECT id,sql_exp,description FROM
223 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
224
225 if (db_num_rows($result) > 0) {
226 if (get_pref($link, 'ENABLE_FEED_CATS')) {
227 print "<li class=\"feedCat\">Labels</li>";
228 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
229 } else {
230 print "<li><hr></li>";
231 }
232 }
233
234 while ($line = db_fetch_assoc($result)) {
235
236 error_reporting (0);
237
238 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
239 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
240 ttrss_user_entries.ref_id = ttrss_entries.id
241 AND owner_uid = '$owner_uid'");
242
243 $count = db_fetch_result($tmp_result, 0, "count");
244
245 $class = "label";
246
247 if ($count > 0) {
248 $class .= "Unread";
249 }
250
251 error_reporting (DEFAULT_ERROR_LEVEL);
252
253 printFeedEntry(-$line["id"]-11,
254 $class, $line["description"], $count, "images/label.png", $link);
255
256 }
257
258 if (db_num_rows($result) > 0) {
259 if (get_pref($link, 'ENABLE_FEED_CATS')) {
260 print "</li></ul>";
261 }
262 }
263
264 }
265
266 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
267 print "<li><hr></li>";
268 // }
269
270 if (get_pref($link, 'ENABLE_FEED_CATS')) {
271 $order_by_qpart = "category,title";
272 } else {
273 $order_by_qpart = "title";
274 }
275
276 $result = db_query($link, "SELECT *,
277 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
278 WHERE feed_id = ttrss_feeds.id AND
279 ttrss_user_entries.ref_id = ttrss_entries.id AND
280 owner_uid = '$owner_uid') AS total,
281 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
282 WHERE feed_id = ttrss_feeds.id AND unread = true
283 AND ttrss_user_entries.ref_id = ttrss_entries.id
284 AND owner_uid = '$owner_uid') as unread,
285 (SELECT title FROM ttrss_feed_categories
286 WHERE id = cat_id) AS category
287 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart");
288
289 $actid = $_GET["actid"];
290
291 /* real feeds */
292
293 $lnum = 0;
294
295 $total_unread = 0;
296
297 $category = "";
298
299 while ($line = db_fetch_assoc($result)) {
300
301 $feed = $line["title"];
302 $feed_id = $line["id"];
303
304 $subop = $_GET["subop"];
305
306 $total = $line["total"];
307 $unread = $line["unread"];
308
309 $tmp_category = $line["category"];
310
311 if (!$tmp_category) {
312 $tmp_category = "Uncategorized";
313 }
314
315 // $class = ($lnum % 2) ? "even" : "odd";
316
317 $class = "feed";
318
319 if ($unread > 0) $class .= "Unread";
320
321 if ($actid == $feed_id) {
322 $class .= "Selected";
323 }
324
325 $total_unread += $unread;
326
327 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
328
329 if ($category) {
330 print "</li></ul></li>";
331 }
332
333 $category = $tmp_category;
334
335 print "<li class=\"feedCat\">$category</li>";
336 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
337 }
338
339 printFeedEntry($feed_id, $class, $feed, $unread,
340 "icons/$feed_id.ico", $link);
341
342 ++$lnum;
343 }
344
345 } else {
346
347 // tags
348
349 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
350 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
351 post_int_id = ttrss_user_entries.int_id AND
352 unread = true AND ref_id = ttrss_entries.id
353 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
354 UNION
355 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
356 ORDER BY tag_name");
357
358 $tags = array();
359
360 while ($line = db_fetch_assoc($result)) {
361 $tags[$line["tag_name"]] += $line["count"];
362 }
363
364 foreach (array_keys($tags) as $tag) {
365
366 $unread = $tags[$tag];
367
368 $class = "tag";
369
370 if ($unread > 0) {
371 $class .= "Unread";
372 }
373
374 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
375
376 }
377
378 }
379
380 if (db_num_rows($result) == 0) {
381 if ($tags) {
382 $what = "tags";
383 } else {
384 $what = "feeds";
385 }
386 print "<li>No $what to display.</li>";
387 }
388
389 print "</ul>";
390
391 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
392
393 }
394
395
396 if ($op == "rpc") {
397
398 $subop = $_GET["subop"];
399
400 if ($subop == "getLabelCounters") {
401 $aid = $_GET["aid"];
402 print "<rpc-reply>";
403 getLabelCounters($link);
404 if ($aid) {
405 getFeedCounter($link, $aid);
406 }
407 print "</rpc-reply>";
408 }
409
410 if ($subop == "getFeedCounters") {
411 print "<rpc-reply>";
412 getFeedCounters($link);
413 print "</rpc-reply>";
414 }
415
416 if ($subop == "getAllCounters") {
417 print "<rpc-reply>";
418 getAllCounters($link);
419 print "</rpc-reply>";
420 }
421
422 if ($subop == "mark") {
423 $mark = $_GET["mark"];
424 $id = db_escape_string($_GET["id"]);
425
426 if ($mark == "1") {
427 $mark = "true";
428 } else {
429 $mark = "false";
430 }
431
432 // FIXME this needs collision testing
433
434 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
435 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
436 }
437
438 if ($subop == "updateFeed") {
439 $feed_id = db_escape_string($_GET["feed"]);
440
441 $result = db_query($link,
442 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
443 AND owner_uid = " . $_SESSION["uid"]);
444
445 if (db_num_rows($result) > 0) {
446 $feed_url = db_fetch_result($result, 0, "feed_url");
447 update_rss_feed($link, $feed_url, $feed_id);
448 }
449
450 print "<rpc-reply>";
451 getFeedCounter($link, $feed_id);
452 print "</rpc-reply>";
453
454 return;
455 }
456
457 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
458
459 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
460
461 $omode = $_GET["omode"];
462
463 if (!$omode) $omode = "tfl";
464
465 print "<rpc-reply>";
466 if (strchr($omode, "l")) getLabelCounters($link);
467 if (strchr($omode, "f")) getFeedCounters($link);
468 if (strchr($omode, "t")) getTagCounters($link);
469 getGlobalCounters($link);
470 print "</rpc-reply>";
471 }
472
473 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
474 if ($subop == "catchupSelected") {
475
476 $ids = split(",", $_GET["ids"]);
477
478 $cmode = sprintf("%d", $_GET["cmode"]);
479
480 foreach ($ids as $id) {
481
482 if ($cmode == 0) {
483 db_query($link, "UPDATE ttrss_user_entries SET
484 unread = false,last_read = NOW()
485 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
486 } else if ($cmode == 1) {
487 db_query($link, "UPDATE ttrss_user_entries SET
488 unread = true
489 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
490 } else {
491 db_query($link, "UPDATE ttrss_user_entries SET
492 unread = NOT unread,last_read = NOW()
493 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
494 }
495 }
496 print "<rpc-reply>";
497 getAllCounters($link);
498 print "</rpc-reply>";
499 }
500
501 if ($subop == "markSelected") {
502
503 $ids = split(",", $_GET["ids"]);
504
505 $cmode = sprintf("%d", $_GET["cmode"]);
506
507 foreach ($ids as $id) {
508
509 if ($cmode == 0) {
510 db_query($link, "UPDATE ttrss_user_entries SET
511 marked = false
512 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
513 } else if ($cmode == 1) {
514 db_query($link, "UPDATE ttrss_user_entries SET
515 marked = true
516 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
517 } else {
518 db_query($link, "UPDATE ttrss_user_entries SET
519 marked = NOT marked
520 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
521 }
522 }
523 print "<rpc-reply>";
524 getAllCounters($link);
525 print "</rpc-reply>";
526 }
527
528 if ($subop == "sanityCheck") {
529
530 $error_code = 0;
531
532 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
533
534 $schema_version = db_fetch_result($result, 0, "schema_version");
535
536 if ($schema_version != SCHEMA_VERSION) {
537 $error_code = 5;
538 }
539
540 print "<error error-code='$error_code'/>";
541 }
542
543 if ($subop == "globalPurge") {
544
545 print "<rpc-reply>";
546 global_purge_old_posts($link, true);
547 print "</rpc-reply>";
548
549 }
550
551 }
552
553 if ($op == "feeds") {
554
555 $tags = $_GET["tags"];
556
557 $subop = $_GET["subop"];
558
559 if ($subop == "catchupAll") {
560 db_query($link, "UPDATE ttrss_user_entries SET
561 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
562 }
563
564 outputFeedList($link, $tags);
565
566 }
567
568 if ($op == "view") {
569
570 $id = $_GET["id"];
571 $feed_id = $_GET["feed"];
572
573 $result = db_query($link, "UPDATE ttrss_user_entries
574 SET unread = false,last_read = NOW()
575 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
576
577 $addheader = $_GET["addheader"];
578
579 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
580 SUBSTRING(updated,1,16) as updated,
581 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
582 FROM ttrss_entries,ttrss_user_entries
583 WHERE id = '$id' AND ref_id = id");
584
585 if ($addheader) {
586 print "<html><head>
587 <title>Tiny Tiny RSS : Article $id</title>
588 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
589
590 $user_theme = $_SESSION["theme"];
591 if ($user_theme) {
592 print "<link rel=\"stylesheet\" type=\"text/css\"
593 href=\"themes/$user_theme/theme.css\">";
594 }
595
596 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
597 print "<link rel=\"stylesheet\" type=\"text/css\"
598 href=\"tt-rss_compact.css\"/>";
599 } else {
600 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
601 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
602 }
603
604 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
605 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
606 </head><body>";
607 }
608
609 if ($result) {
610
611 $line = db_fetch_assoc($result);
612
613 if ($line["icon_url"]) {
614 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
615 } else {
616 $feed_icon = "&nbsp;";
617 }
618
619 if ($line["comments"] && $line["link"] != $line["comments"]) {
620 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
621 } else {
622 $entry_comments = "";
623 }
624
625 print "<div class=\"postReply\">";
626
627 print "<div class=\"postHeader\"><table width=\"100%\">";
628
629 print "<tr><td>" . $line["title"] . "</td>";
630
631 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
632 strtotime($line["updated"]));
633
634 print "<td class=\"postDate\">$parsed_updated</td>";
635
636 print "</tr>";
637
638 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
639 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
640 ORDER BY tag_name");
641
642 $tags_str = "";
643
644 while ($tmp_line = db_fetch_assoc($tmp_result)) {
645 $tag = $tmp_line["tag_name"];
646 $tags_str .= "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
647 }
648
649 $tags_str = preg_replace("/, $/", "", $tags_str);
650
651 print "<tr><td width='50%'>
652 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
653 $entry_comments</td>
654 <td align=\"right\">$tags_str</td></tr>";
655
656 /* if ($tags_str) {
657 print "<tr><td><b>Tags:</b></td>
658 <td width='100%'>$tags_str</td></tr>";
659 } */
660
661 print "</table></div>";
662
663 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
664 print "<div class=\"postContent\">" . $line["content"] . "</div>";
665
666 print "</div>";
667
668 print "<script type=\"text/javascript\">
669 update_all_counters('$feed_id');
670 </script>";
671 }
672
673 if ($addheader) {
674 print "</body></html>";
675 }
676 }
677
678 if ($op == "viewfeed") {
679
680 $feed = $_GET["feed"];
681 $skip = $_GET["skip"];
682 $subop = $_GET["subop"];
683 $view_mode = $_GET["view"];
684 $addheader = $_GET["addheader"];
685 $limit = $_GET["limit"];
686
687 if (!$feed) {
688 return;
689 }
690
691 if (!$skip) $skip = 0;
692
693 if ($subop == "undefined") $subop = "";
694
695 if ($addheader) {
696 print "<html><head>
697 <title>Tiny Tiny RSS : Feed $feed</title>
698 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
699
700 $user_theme = $_SESSION["theme"];
701 if ($user_theme) {
702 print "<link rel=\"stylesheet\" type=\"text/css\"
703 href=\"themes/$user_theme/theme.css\">";
704 }
705
706 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
707 print "<link rel=\"stylesheet\"
708 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
709
710 } else {
711 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
712 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
713 }
714
715 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
716 <script type=\"text/javascript\" src=\"functions.js\"></script>
717 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
718 </head><body onload='init()'>";
719 }
720
721 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
722
723 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
724 WHERE id = '$feed'");
725
726 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
727
728 update_rss_feed($link, $feed_url, $feed);
729
730 }
731
732 if ($subop == "MarkAllRead") {
733
734 if (sprintf("%d", $feed) != 0) {
735
736 if ($feed > 0) {
737 db_query($link, "UPDATE ttrss_user_entries
738 SET unread = false,last_read = NOW()
739 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
740
741 } else if ($feed < 0 && $feed > -10) { // special, like starred
742
743 if ($feed == -1) {
744 db_query($link, "UPDATE ttrss_user_entries
745 SET unread = false,last_read = NOW()
746 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
747 }
748
749 } else if ($feed < -10) { // label
750
751 // TODO make this more efficient
752
753 $label_id = -$feed - 11;
754
755 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
756 WHERE id = '$label_id'");
757
758 if ($tmp_result) {
759 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
760
761 db_query($link, "BEGIN");
762
763 $tmp2_result = db_query($link,
764 "SELECT
765 int_id
766 FROM
767 ttrss_user_entries,ttrss_entries
768 WHERE
769 ref_id = id AND
770 $sql_exp AND
771 owner_uid = " . $_SESSION["uid"]);
772
773 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
774 db_query($link, "UPDATE
775 ttrss_user_entries
776 SET
777 unread = false, last_read = NOW()
778 WHERE
779 int_id = " . $tmp_line["int_id"]);
780 }
781
782 db_query($link, "COMMIT");
783
784 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
785 SET unread = false,last_read = NOW()
786 WHERE $sql_exp
787 AND ref_id = id
788 AND owner_uid = ".$_SESSION["uid"]); */
789 }
790 }
791 } else { // tag
792 db_query($link, "BEGIN");
793
794 $tag_name = db_escape_string($feed);
795
796 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
797 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
798
799 while ($line = db_fetch_assoc($result)) {
800 db_query($link, "UPDATE ttrss_user_entries SET
801 unread = false, last_read = NOW()
802 WHERE int_id = " . $line["post_int_id"]);
803 }
804 db_query($link, "COMMIT");
805 }
806
807 }
808
809 $search = $_GET["search"];
810
811 $search_mode = $_GET["smode"];
812
813 if ($search) {
814 $search_query_part = "(upper(title) LIKE upper('%$search%')
815 OR content LIKE '%$search%') AND";
816 } else {
817 $search_query_part = "";
818 }
819
820 $view_query_part = "";
821
822 if ($view_mode == "Starred") {
823 $view_query_part = " marked = true AND ";
824 }
825
826 if ($view_mode == "Unread") {
827 $view_query_part = " unread = true AND ";
828 }
829
830 if ($view_mode == "Unread or Starred") {
831 $view_query_part = " (unread = true OR marked = true) AND ";
832 }
833
834 if ($view_mode == "Unread or Updated") {
835 $view_query_part = " (unread = true OR last_read is NULL) AND ";
836 }
837
838 /* $result = db_query($link, "SELECT count(id) AS total_entries
839 FROM ttrss_entries WHERE
840 $search_query_part
841 feed_id = '$feed'");
842
843 $total_entries = db_fetch_result($result, 0, "total_entries"); */
844
845 /* $result = db_query("SELECT count(id) AS unread_entries
846 FROM ttrss_entries WHERE
847 $search_query_part
848 unread = true AND
849 feed_id = '$feed'");
850
851 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
852
853 if ($limit && $limit != "All") {
854 $limit_query_part = "LIMIT " . $limit;
855 }
856
857 $vfeed_query_part = "";
858
859 // override query strategy and enable feed display when searching globally
860 if ($search && $search_mode == "All feeds") {
861 $query_strategy_part = "id > 0";
862 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
863 id = feed_id) as feed_title,";
864 } else if (sprintf("%d", $feed) == 0) {
865 $query_strategy_part = "ttrss_entries.id > 0";
866 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
867 id = feed_id) as feed_title,";
868 } else if ($feed >= 0) {
869 $query_strategy_part = "feed_id = '$feed'";
870 } else if ($feed == -1) { // starred virtual feed
871 $query_strategy_part = "marked = true";
872 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
873 id = feed_id) as feed_title,";
874 } else if ($feed <= -10) { // labels
875 $label_id = -$feed - 11;
876
877 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
878 WHERE id = '$label_id'");
879
880 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
881
882 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
883 id = feed_id) as feed_title,";
884 } else {
885 $query_strategy_part = "id > 0"; // dumb
886 }
887
888 $order_by = "updated DESC";
889
890 // if ($feed < -10) {
891 // $order_by = "feed_id,updated DESC";
892 // }
893
894 $feed_title = "";
895
896 if ($search && $search_mode == "All feeds") {
897 $feed_title = "Search results";
898 } else if (sprintf("%d", $feed) == 0) {
899 $feed_title = $feed;
900 } else if ($feed > 0) {
901 $result = db_query($link, "SELECT title,site_url FROM ttrss_feeds
902 WHERE id = '$feed'");
903
904 $feed_title = db_fetch_result($result, 0, "title");
905 $feed_site_url = db_fetch_result($result, 0, "site_url");
906
907 } else if ($feed == -1) {
908 $feed_title = "Starred articles";
909 } else if ($feed < -10) {
910 $label_id = -$feed - 11;
911 $result = db_query($link, "SELECT description FROM ttrss_labels
912 WHERE id = '$label_id'");
913 $feed_title = db_fetch_result($result, 0, "description");
914 } else {
915 $feed_title = "?";
916 }
917
918 if ($feed < -10) error_reporting (0);
919
920 if (sprintf("%d", $feed) != 0) {
921
922 if ($feed > 0) {
923 $feed_kind = "Feeds";
924 } else {
925 $feed_kind = "Labels";
926 }
927
928 if (!$vfeed_query_part) {
929 $content_query_part = "content as content_preview,";
930 } else {
931 $content_query_part = "";
932 }
933
934 $result = db_query($link, "SELECT
935 id,title,
936 SUBSTRING(updated,1,16) as updated,
937 unread,feed_id,marked,link,last_read,
938 SUBSTRING(last_read,1,19) as last_read_noms,
939 $vfeed_query_part
940 $content_query_part
941 SUBSTRING(updated,1,19) as updated_noms
942 FROM
943 ttrss_entries,ttrss_user_entries
944 WHERE
945 ttrss_user_entries.ref_id = ttrss_entries.id AND
946 owner_uid = '".$_SESSION["uid"]."' AND
947 $search_query_part
948 $view_query_part
949 $query_strategy_part ORDER BY $order_by
950 $limit_query_part");
951
952 } else {
953 // browsing by tag
954
955 $feed_kind = "Tags";
956
957 $result = db_query($link, "SELECT
958 ttrss_entries.id as id,title,
959 SUBSTRING(updated,1,16) as updated,
960 unread,feed_id,
961 marked,link,last_read,
962 SUBSTRING(last_read,1,19) as last_read_noms,
963 $vfeed_query_part
964 $content_query_part
965 SUBSTRING(updated,1,19) as updated_noms
966 FROM
967 ttrss_entries,ttrss_user_entries,ttrss_tags
968 WHERE
969 ref_id = ttrss_entries.id AND
970 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
971 post_int_id = int_id AND tag_name = '$feed' AND
972 $view_query_part
973 $search_query_part
974 $query_strategy_part ORDER BY $order_by
975 $limit_query_part");
976 }
977
978 if (!$result) {
979 print "<div align='center'>
980 Could not display feed (query failed). Please check match syntax or local configuration.</div>";
981 return;
982 }
983
984 if (db_num_rows($result) > 0) {
985
986 print "<table class=\"headlinesSubToolbar\"
987 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
988
989 print "<td class=\"headlineActions\">
990 Select:
991 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
992 'RROW-', 'RCHK-', true)\">All</a>,
993 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
994 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
995 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
996 'RROW-', 'RCHK-', false)\">None</a>
997 &nbsp;&nbsp;
998 Toggle: <a href=\"javascript:toggleUnread()\">Unread</a>,
999 <a href=\"javascript:toggleStarred()\">Starred</a>";
1000
1001 print "</td>";
1002
1003 print "<td class=\"headlineTitle\">";
1004
1005 if ($feed_site_url) {
1006 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
1007 } else {
1008 print $feed_title;
1009 }
1010
1011 print "</td>";
1012 print "</tr></table>";
1013
1014 }
1015
1016 print "<table class=\"headlinesList\" id=\"headlinesList\"
1017 cellspacing=\"0\" width=\"100%\">";
1018
1019
1020
1021 $lnum = 0;
1022
1023 error_reporting (DEFAULT_ERROR_LEVEL);
1024
1025 $num_unread = 0;
1026
1027 while ($line = db_fetch_assoc($result)) {
1028
1029 $class = ($lnum % 2) ? "even" : "odd";
1030
1031 $id = $line["id"];
1032 $feed_id = $line["feed_id"];
1033
1034 if ($line["last_read"] == "" &&
1035 ($line["unread"] != "t" && $line["unread"] != "1")) {
1036
1037 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1038 alt=\"Updated\">";
1039 } else {
1040 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1041 alt=\"Updated\">";
1042 }
1043
1044 if ($line["unread"] == "t" || $line["unread"] == "1") {
1045 $class .= "Unread";
1046 ++$num_unread;
1047 }
1048
1049 if ($line["marked"] == "t" || $line["marked"] == "1") {
1050 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1051 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
1052 } else {
1053 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1054 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
1055 }
1056
1057 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
1058 $line["title"] . "</a>";
1059
1060 print "<tr class='$class' id='RROW-$id'>";
1061 // onclick=\"javascript:view($id,$feed_id)\">
1062
1063 print "<td valign='center' class='hlUpdatePic'>$update_pic</td>";
1064
1065 print "<td valign='center' class='hlSelectRow'>
1066 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1067 class=\"feedCheckBox\" id=\"RCHK-$id\">
1068 </td>";
1069
1070 print "<td valign='center' class='hlMarkedPic'>$marked_pic</td>";
1071
1072 if ($line["feed_title"]) {
1073 print "<td class='hlContent'>$content_link</td>";
1074 print "<td class='hlFeed'>
1075 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
1076 } else {
1077 print "<td class='hlContent'>";
1078
1079 print "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
1080 $line["title"];
1081
1082 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1083
1084 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1085 101);
1086
1087 if ($content_preview) {
1088 print "<span class=\"contentPreview\"> - $content_preview</span>";
1089 }
1090 }
1091
1092 print "</a>";
1093 print "</td>";
1094 }
1095
1096 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1097 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1098 } else {
1099 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1100 $updated_fmt = date($short_date, strtotime($line["updated"]));
1101 }
1102
1103 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1104
1105 print "</tr>";
1106
1107 ++$lnum;
1108 }
1109
1110 if ($lnum == 0) {
1111 print "<tr><td align='center'>No articles found.</td></tr>";
1112 }
1113
1114 print "</table>";
1115
1116 print "<script type=\"text/javascript\">
1117 document.onkeydown = hotkey_handler;
1118 update_all_counters('$feed');
1119 </script>";
1120
1121 if ($addheader) {
1122 print "</body></html>";
1123 }
1124
1125 }
1126
1127 if ($op == "pref-rpc") {
1128
1129 $subop = $_GET["subop"];
1130
1131 if ($subop == "unread") {
1132 $ids = split(",", $_GET["ids"]);
1133 foreach ($ids as $id) {
1134 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1135 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1136 }
1137
1138 print "Marked selected feeds as unread.";
1139 }
1140
1141 if ($subop == "read") {
1142 $ids = split(",", $_GET["ids"]);
1143 foreach ($ids as $id) {
1144 db_query($link, "UPDATE ttrss_user_entries
1145 SET unread = false,last_read = NOW() WHERE
1146 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1147 }
1148
1149 print "Marked selected feeds as read.";
1150
1151 }
1152
1153 }
1154
1155 if ($op == "pref-feeds") {
1156
1157 $subop = $_GET["subop"];
1158
1159 if ($subop == "editSave") {
1160 $feed_title = db_escape_string($_GET["t"]);
1161 $feed_link = db_escape_string($_GET["l"]);
1162 $upd_intl = db_escape_string($_GET["ui"]);
1163 $purge_intl = db_escape_string($_GET["pi"]);
1164 $feed_id = db_escape_string($_GET["id"]);
1165 $cat_id = db_escape_string($_GET["catid"]);
1166
1167 if (strtoupper($upd_intl) == "DEFAULT")
1168 $upd_intl = 0;
1169
1170 if (strtoupper($purge_intl) == "DEFAULT")
1171 $purge_intl = 0;
1172
1173 if (strtoupper($purge_intl) == "DISABLED")
1174 $purge_intl = -1;
1175
1176 if ($cat_id != 0) {
1177 $category_qpart = "cat_id = '$cat_id'";
1178 } else {
1179 $category_qpart = 'cat_id = NULL';
1180 }
1181
1182 $result = db_query($link, "UPDATE ttrss_feeds SET
1183 $category_qpart,
1184 title = '$feed_title', feed_url = '$feed_link',
1185 update_interval = '$upd_intl',
1186 purge_interval = '$purge_intl'
1187 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1188
1189 }
1190
1191 if ($subop == "remove") {
1192
1193 if (!WEB_DEMO_MODE) {
1194
1195 $ids = split(",", $_GET["ids"]);
1196
1197 foreach ($ids as $id) {
1198 db_query($link, "DELETE FROM ttrss_feeds
1199 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1200
1201 $icons_dir = ICONS_DIR;
1202
1203 if (file_exists($icons_dir . "/$id.ico")) {
1204 unlink($icons_dir . "/$id.ico");
1205 }
1206 }
1207 }
1208 }
1209
1210 if ($subop == "add") {
1211
1212 if (!WEB_DEMO_MODE) {
1213
1214 $feed_link = db_escape_string(trim($_GET["link"]));
1215
1216 $result = db_query($link,
1217 "SELECT id FROM ttrss_feeds
1218 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1219
1220 if (db_num_rows($result) == 0) {
1221
1222 $result = db_query($link,
1223 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1224 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
1225
1226 $result = db_query($link,
1227 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1228 AND owner_uid = " . $_SESSION["uid"]);
1229
1230 $feed_id = db_fetch_result($result, 0, "id");
1231
1232 if ($feed_id) {
1233 update_rss_feed($link, $feed_link, $feed_id, true);
1234 }
1235 } else {
1236
1237 print "<div class=\"warning\">
1238 Feed <b>$feed_link</b> already exists in the database.
1239 </div>";
1240 }
1241 }
1242 }
1243
1244 if ($subop == "addCat") {
1245
1246 if (!WEB_DEMO_MODE) {
1247
1248 $feed_cat = db_escape_string(trim($_GET["cat"]));
1249
1250 $result = db_query($link,
1251 "SELECT id FROM ttrss_feed_categories
1252 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1253
1254 if (db_num_rows($result) == 0) {
1255
1256 $result = db_query($link,
1257 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1258 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1259
1260 } else {
1261
1262 print "<div class=\"warning\">
1263 Category <b>$feed_cat</b> already exists in the database.
1264 </div>";
1265 }
1266
1267
1268 }
1269 }
1270
1271 if ($subop == "removeCats") {
1272
1273 if (!WEB_DEMO_MODE) {
1274
1275 $ids = split(",", $_GET["ids"]);
1276
1277 foreach ($ids as $id) {
1278
1279 db_query($link, "BEGIN");
1280
1281 $result = db_query($link,
1282 "SELECT count(id) as num_feeds FROM ttrss_feeds
1283 WHERE cat_id = '$id'");
1284
1285 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1286
1287 if ($num_feeds == 0) {
1288 db_query($link, "DELETE FROM ttrss_feed_categories
1289 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1290 } else {
1291
1292 print "<div class=\"warning\">
1293 Unable to delete non empty feed categories.</div>";
1294
1295 }
1296
1297 db_query($link, "COMMIT");
1298 }
1299 }
1300 }
1301
1302 // print "<h3>Edit Feeds</h3>";
1303
1304 $result = db_query($link, "SELECT id,title,feed_url,last_error
1305 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1306
1307 if (db_num_rows($result) > 0) {
1308
1309 print "<div class=\"warning\">";
1310
1311 print "<b>Feeds with update errors:</b>";
1312
1313 print "<ul class=\"nomarks\">";
1314
1315 while ($line = db_fetch_assoc($result)) {
1316 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1317 $line["last_error"];
1318 }
1319
1320 print "</ul>";
1321 print "</div>";
1322
1323 }
1324
1325 print "<p><div class=\"prefGenericAddBox\">
1326 <input id=\"fadd_link\" size=\"40\">&nbsp;<input
1327 type=\"submit\" class=\"button\"
1328 onclick=\"javascript:addFeed()\" value=\"Add feed\"></div>";
1329
1330 $feeds_sort = db_escape_string($_GET["sort"]);
1331
1332 if (!$feeds_sort || $feeds_sort == "undefined") {
1333 $feeds_sort = $_SESSION["pref_sort_feeds"];
1334 if (!$feeds_sort) $feeds_sort = "title";
1335 }
1336
1337 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1338
1339 $result = db_query($link, "SELECT
1340 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1341 update_interval,purge_interval,
1342 (SELECT title FROM ttrss_feed_categories
1343 WHERE id = cat_id) AS category
1344 FROM
1345 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."'
1346 ORDER by $feeds_sort,title");
1347
1348 if (db_num_rows($result) != 0) {
1349
1350 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1351
1352 print "<p><table width=\"100%\" cellspacing=\"0\"
1353 class=\"prefFeedList\" id=\"prefFeedList\">";
1354 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1355 Select:
1356 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1357 'FEEDR-', 'FRCHK-', true)\">All</a>,
1358 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1359 'FEEDR-', 'FRCHK-', false)\">None</a>
1360 </td</tr>";
1361
1362 print "<tr class=\"title\">
1363 <td width=\"3%\">&nbsp;</td>
1364 <td width=\"3%\">Select</td>
1365 <td width=\"20%\">
1366 <a href=\"javascript:updateFeedList('title')\">Title</a></td>
1367 <td width=\"20%\">
1368 <a href=\"javascript:updateFeedList('feed_url')\">Link</a>
1369 </td>";
1370
1371 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1372 print "<td width=\"10%\">
1373 <a href=\"javascript:updateFeedList('category')\">Category</a></td>";
1374 }
1375
1376 print "
1377 <td width=\"10%\">
1378 <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a>
1379 </td>
1380 <td width=\"10%\">
1381 <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a>
1382 </td>
1383 </tr>";
1384
1385 $lnum = 0;
1386
1387 while ($line = db_fetch_assoc($result)) {
1388
1389 $class = ($lnum % 2) ? "even" : "odd";
1390
1391 $feed_id = $line["id"];
1392
1393 $edit_feed_id = $_GET["id"];
1394
1395 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1396 $class .= "Grayed";
1397 $this_row_id = "";
1398 } else {
1399 $this_row_id = "id=\"FEEDR-$feed_id\"";
1400 }
1401
1402 print "<tr class=\"$class\" $this_row_id>";
1403
1404 $icon_file = ICONS_DIR . "/$feed_id.ico";
1405
1406 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1407 $feed_icon = "<img width=\"16\" height=\"16\"
1408 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1409 } else {
1410 $feed_icon = "&nbsp;";
1411 }
1412 print "<td align='center'>$feed_icon</td>";
1413
1414 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1415 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1416 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1417
1418 if (!$edit_cat) $edit_cat = "Uncategorized";
1419
1420 if (!$edit_feed_id || $subop != "edit") {
1421
1422 print "<td><input onclick='toggleSelectRow(this);'
1423 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1424
1425 $edit_title = truncate_string($edit_title, 40);
1426 $edit_link = truncate_string($edit_link, 60);
1427
1428 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1429 $edit_title . "</a></td>";
1430
1431 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1432 $edit_link . "</a></td>";
1433
1434 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1435 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1436 $edit_cat . "</a></td>";
1437 }
1438
1439 if ($line["update_interval"] == "0")
1440 $line["update_interval"] = "Default";
1441
1442 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1443 $line["update_interval"] . "</a></td>";
1444
1445 if ($line["purge_interval"] == "0")
1446 $line["purge_interval"] = "Default";
1447
1448 if ($line["purge_interval"] < 0)
1449 $line["purge_interval"] = "Disabled";
1450
1451 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1452 $line["purge_interval"] . "</a></td>";
1453
1454 } else if ($feed_id != $edit_feed_id) {
1455
1456 print "<td><input disabled=\"true\" type=\"checkbox\"
1457 id=\"FRCHK-".$line["id"]."\"></td>";
1458
1459 $edit_title = truncate_string($edit_title, 40);
1460 $edit_link = truncate_string($edit_link, 60);
1461
1462 print "<td>$edit_title</td>";
1463 print "<td>$edit_link</td>";
1464
1465 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1466 print "<td>$edit_cat</td>";
1467 }
1468
1469 if ($line["update_interval"] == "0")
1470 $line["update_interval"] = "Default";
1471
1472 print "<td>" . $line["update_interval"] . "</td>";
1473
1474 if ($line["purge_interval"] == "0")
1475 $line["purge_interval"] = "Default";
1476
1477 if ($line["purge_interval"] < 0)
1478 $line["purge_interval"] = "Disabled";
1479
1480 print "<td>" . $line["purge_interval"] . "</td>";
1481
1482 } else {
1483
1484 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1485
1486 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1487 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1488
1489 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1490
1491 print "<td>";
1492 print "<select id=\"iedit_fcat\">";
1493 print "<option id=\"0\">Uncategorized</option>";
1494
1495 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1496 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1497
1498 if (db_num_rows($tmp_result) > 0) {
1499 print "<option disabled>--------</option>";
1500 }
1501
1502 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1503 if ($tmp_line["id"] == $line["cat_id"]) {
1504 $is_selected = "selected";
1505 } else {
1506 $is_selected = "";
1507 }
1508 printf("<option $is_selected id='%d'>%s</option>",
1509 $tmp_line["id"], $tmp_line["title"]);
1510 }
1511
1512 print "</select></td>";
1513 print "</td>";
1514
1515 }
1516
1517 print "<td><input id=\"iedit_updintl\"
1518 value=\"".$line["update_interval"]."\"></td>";
1519 print "<td><input id=\"iedit_purgintl\"
1520 value=\"".$line["purge_interval"]."\"></td>";
1521
1522 }
1523
1524 /* if (!$line["last_updated"]) $line["last_updated"] = "Never";
1525
1526 print "<td>" . $line["last_updated"] . "</td>"; */
1527
1528 print "</tr>";
1529
1530 ++$lnum;
1531 }
1532
1533 print "</table>";
1534
1535 print "<p>";
1536
1537 if ($subop == "edit") {
1538 print "Edit feed:&nbsp;
1539 <input type=\"submit\" class=\"button\"
1540 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1541 <input type=\"submit\" class=\"button\"
1542 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1543 } else {
1544
1545 print "
1546 Selection:&nbsp;
1547 <input type=\"submit\" class=\"button\"
1548 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1549 <input type=\"submit\" class=\"button\"
1550 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1551 <input type=\"submit\" class=\"button\"
1552 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1553
1554 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1555 print "
1556 <input type=\"submit\" class=\"button\"
1557 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
1558 <input type=\"submit\" class=\"button\"
1559 onclick=\"javascript:readSelectedFeeds(false)\"
1560 value=\"Mark as unread\">&nbsp;";
1561 }
1562
1563 print "
1564 All feeds: <input type=\"submit\"
1565 class=\"button\" onclick=\"gotoExportOpml()\"
1566 value=\"Export OPML\">";
1567 }
1568 } else {
1569
1570 print "<p>No feeds defined.</p>";
1571
1572 }
1573
1574 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1575
1576 print "<h3>Edit Categories</h3>";
1577
1578 // print "<h3>Categories</h3>";
1579
1580 print "<div class=\"prefGenericAddBox\">
1581 <input id=\"fadd_cat\" size=\"40\">&nbsp;<input
1582 type=\"submit\" class=\"button\"
1583 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1584
1585 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1586 WHERE owner_uid = ".$_SESSION["uid"]."
1587 ORDER BY title");
1588
1589 if (db_num_rows($result) != 0) {
1590
1591 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1592 cellspacing=\"0\" id=\"prefFeedCatList\">";
1593
1594 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1595 Select:
1596 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1597 'FCATR-', 'FCCHK-', true)\">All</a>,
1598 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1599 'FCATR-', 'FCCHK-', false)\">None</a>
1600 </td</tr>";
1601
1602 print "<tr class=\"title\">
1603 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1604 </tr>";
1605
1606 $lnum = 0;
1607
1608 while ($line = db_fetch_assoc($result)) {
1609
1610 $class = ($lnum % 2) ? "even" : "odd";
1611
1612 $cat_id = $line["id"];
1613
1614 $edit_cat_id = $_GET["id"];
1615
1616 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1617 $class .= "Grayed";
1618 $this_row_id = "";
1619 } else {
1620 $this_row_id = "id=\"FCATR-$cat_id\"";
1621 }
1622
1623 print "<tr class=\"$class\" $this_row_id>";
1624
1625 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1626
1627 if (!$edit_cat_id || $subop != "editCat") {
1628
1629 print "<td><input onclick='toggleSelectRow(this);'
1630 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1631
1632 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1633 $edit_title . "</a></td>";
1634
1635 } else if ($cat_id != $edit_cat_id) {
1636
1637 print "<td><input disabled=\"true\" type=\"checkbox\"
1638 id=\"FRCHK-".$line["id"]."\"></td>";
1639
1640 print "<td>$edit_title</td>";
1641
1642 } else {
1643
1644 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1645
1646 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1647
1648 }
1649
1650 print "</tr>";
1651
1652 ++$lnum;
1653 }
1654
1655 print "</table>";
1656
1657 print "<p>";
1658
1659 if ($subop == "editCat") {
1660 print "Edit category:&nbsp;
1661 <input type=\"submit\" class=\"button\"
1662 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1663 <input type=\"submit\" class=\"button\"
1664 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1665 } else {
1666
1667 print "
1668 Selection:&nbsp;
1669 <input type=\"submit\" class=\"button\"
1670 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1671 <input type=\"submit\" class=\"button\"
1672 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1673
1674 }
1675
1676 } else {
1677 print "<p>No feed categories defined.</p>";
1678 }
1679 }
1680
1681 print "<h3>Import OPML</h3>
1682 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1683 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1684 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1685 type=\"submit\" value=\"Import\">
1686 </form>";
1687
1688 }
1689
1690 if ($op == "pref-filters") {
1691
1692 $subop = $_GET["subop"];
1693
1694 if ($subop == "editSave") {
1695
1696 $regexp = db_escape_string($_GET["r"]);
1697 $descr = db_escape_string($_GET["d"]);
1698 $match = db_escape_string($_GET["m"]);
1699 $filter_id = db_escape_string($_GET["id"]);
1700 $feed_id = db_escape_string($_GET["fid"]);
1701
1702 if (!$feed_id) {
1703 $feed_id = 'NULL';
1704 } else {
1705 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1706 }
1707
1708 $result = db_query($link, "UPDATE ttrss_filters SET
1709 reg_exp = '$regexp',
1710 description = '$descr',
1711 feed_id = $feed_id,
1712 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1713 description = '$match')
1714 WHERE id = '$filter_id'");
1715 }
1716
1717 if ($subop == "remove") {
1718
1719 if (!WEB_DEMO_MODE) {
1720
1721 $ids = split(",", $_GET["ids"]);
1722
1723 foreach ($ids as $id) {
1724 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1725
1726 }
1727 }
1728 }
1729
1730 if ($subop == "add") {
1731
1732 if (!WEB_DEMO_MODE) {
1733
1734 $regexp = db_escape_string(trim($_GET["regexp"]));
1735 $match = db_escape_string(trim($_GET["match"]));
1736 $feed_id = db_escape_string($_GET["fid"]);
1737
1738 if (!$feed_id) {
1739 $feed_id = 'NULL';
1740 } else {
1741 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1742 }
1743
1744 $result = db_query($link,
1745 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
1746 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1747 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
1748 }
1749 }
1750
1751 $result = db_query($link, "SELECT description
1752 FROM ttrss_filter_types ORDER BY description");
1753
1754 $filter_types = array();
1755
1756 while ($line = db_fetch_assoc($result)) {
1757 array_push($filter_types, $line["description"]);
1758 }
1759
1760 print "<div class=\"prefGenericAddBox\">
1761 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
1762
1763 print_select("fadd_match", "Title", $filter_types);
1764
1765 print "&nbsp;<select id=\"fadd_feed\">";
1766
1767 print "<option selected id=\"0\">All feeds</option>";
1768
1769 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1770 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1771
1772 if (db_num_rows($result) > 0) {
1773 print "<option disabled>--------</option>";
1774 }
1775
1776 while ($line = db_fetch_assoc($result)) {
1777 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1778 }
1779
1780 print "</select>&nbsp;";
1781
1782 print "<input type=\"submit\"
1783 class=\"button\" onclick=\"javascript:addFilter()\"
1784 value=\"Add filter\">";
1785
1786 $result = db_query($link, "SELECT
1787 ttrss_filters.id AS id,reg_exp,
1788 ttrss_filters.description AS description,
1789 ttrss_filter_types.name AS filter_type_name,
1790 ttrss_filter_types.description AS filter_type_descr,
1791 feed_id,
1792 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1793 FROM
1794 ttrss_filters,ttrss_filter_types
1795 WHERE
1796 filter_type = ttrss_filter_types.id AND
1797 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
1798 ORDER by reg_exp");
1799
1800 if (db_num_rows($result) != 0) {
1801
1802 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
1803 id=\"prefFilterList\">";
1804
1805 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1806 Select:
1807 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1808 'FILRR-', 'FICHK-', true)\">All</a>,
1809 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1810 'FILRR-', 'FICHK-', false)\">None</a>
1811 </td</tr>";
1812
1813 print "<tr class=\"title\">
1814 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1815 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1816 <td width=\"30%\">Description</td></tr>";
1817
1818 $lnum = 0;
1819
1820 while ($line = db_fetch_assoc($result)) {
1821
1822 $class = ($lnum % 2) ? "even" : "odd";
1823
1824 $filter_id = $line["id"];
1825 $edit_filter_id = $_GET["id"];
1826
1827 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1828 $class .= "Grayed";
1829 $this_row_id = "";
1830 } else {
1831 $this_row_id = "id=\"FILRR-$filter_id\"";
1832 }
1833
1834 print "<tr class=\"$class\" $this_row_id>";
1835
1836 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1837 $line["description"] = htmlspecialchars($line["description"]);
1838
1839 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1840
1841 if (!$edit_filter_id || $subop != "edit") {
1842
1843 if (!$line["description"]) $line["description"] = "[No description]";
1844
1845 print "<td><input onclick='toggleSelectRow(this);'
1846 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1847
1848 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1849 $line["reg_exp"] . "</td>";
1850
1851 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1852 $line["feed_title"] . "</td>";
1853
1854 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1855 $line["filter_type_descr"] . "</td>";
1856
1857 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1858 $line["description"] . "</td>";
1859
1860 } else if ($filter_id != $edit_filter_id) {
1861
1862 if (!$line["description"]) $line["description"] = "[No description]";
1863
1864 print "<td><input disabled=\"true\" type=\"checkbox\"
1865 id=\"FICHK-".$line["id"]."\"></td>";
1866
1867 print "<td>".$line["reg_exp"]."</td>";
1868 print "<td>".$line["feed_title"]."</td>";
1869 print "<td>".$line["filter_type_descr"]."</td>";
1870 print "<td>".$line["description"]."</td>";
1871
1872 } else {
1873
1874 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1875
1876 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1877 "\"></td>";
1878
1879 print "<td>";
1880
1881 print "<select id=\"iedit_feed\">";
1882
1883 print "<option id=\"0\">All feeds</option>";
1884
1885 if (db_num_rows($result) > 0) {
1886 print "<option disabled>--------</option>";
1887 }
1888
1889 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1890 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1891
1892 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1893 if ($tmp_line["id"] == $line["feed_id"]) {
1894 $is_selected = "selected";
1895 } else {
1896 $is_selected = "";
1897 }
1898 printf("<option $is_selected id='%d'>%s</option>",
1899 $tmp_line["id"], $tmp_line["title"]);
1900 }
1901
1902 print "</select></td>";
1903
1904 print "<td>";
1905 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1906 print "</td>";
1907
1908 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1909 "\"></td>";
1910
1911 print "</td>";
1912 }
1913
1914 print "</tr>";
1915
1916 ++$lnum;
1917 }
1918
1919 if ($lnum == 0) {
1920 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1921 }
1922
1923 print "</table>";
1924
1925 print "<p>";
1926
1927 if ($subop == "edit") {
1928 print "Edit feed:
1929 <input type=\"submit\" class=\"button\"
1930 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1931 <input type=\"submit\" class=\"button\"
1932 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1933
1934 } else {
1935
1936 print "
1937 Selection:
1938 <input type=\"submit\" class=\"button\"
1939 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1940 <input type=\"submit\" class=\"button\"
1941 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1942 }
1943
1944 } else {
1945
1946 print "<p>No filters defined.</p>";
1947
1948 }
1949 }
1950
1951 if ($op == "pref-labels") {
1952
1953 $subop = $_GET["subop"];
1954
1955 if ($subop == "test") {
1956
1957 $expr = $_GET["expr"];
1958 $descr = $_GET["descr"];
1959
1960 print "<div class='infoBoxContents'>";
1961
1962 print "<h1>Label &laquo;$descr&raquo;</h1>";
1963
1964 // print "<p><b>Expression</b>: $expr</p>";
1965
1966 $result = db_query($link,
1967 "SELECT count(id) AS num_matches
1968 FROM ttrss_entries,ttrss_user_entries
1969 WHERE ($expr) AND
1970 ttrss_user_entries.ref_id = ttrss_entries.id AND
1971 owner_uid = " . $_SESSION["uid"]);
1972
1973 $num_matches = db_fetch_result($result, 0, "num_matches");;
1974
1975 if ($num_matches > 0) {
1976
1977 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
1978
1979 $result = db_query($link,
1980 "SELECT title,
1981 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1982 FROM ttrss_entries,ttrss_user_entries
1983 WHERE ($expr) AND
1984 ttrss_user_entries.ref_id = ttrss_entries.id
1985 AND owner_uid = " . $_SESSION["uid"] . "
1986 ORDER BY date_entered DESC LIMIT 5");
1987
1988 print "<ul class=\"nomarks\">";
1989 while ($line = db_fetch_assoc($result)) {
1990 print "<li>".$line["title"].
1991 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
1992 }
1993 print "</ul>";
1994
1995 } else {
1996 print "<p>Query didn't return any matches.</p>";
1997 }
1998
1999 print "</div>";
2000
2001 print "<div align='center'>
2002 <input type='submit' class='button'
2003 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2004 return;
2005 }
2006
2007 if ($subop == "editSave") {
2008
2009 $sql_exp = $_GET["s"];
2010 $descr = $_GET["d"];
2011 $label_id = db_escape_string($_GET["id"]);
2012
2013 // print "$sql_exp : $descr : $label_id";
2014
2015 $result = db_query($link, "UPDATE ttrss_labels SET
2016 sql_exp = '$sql_exp',
2017 description = '$descr'
2018 WHERE id = '$label_id'");
2019 }
2020
2021 if ($subop == "remove") {
2022
2023 if (!WEB_DEMO_MODE) {
2024
2025 $ids = split(",", $_GET["ids"]);
2026
2027 foreach ($ids as $id) {
2028 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2029
2030 }
2031 }
2032 }
2033
2034 if ($subop == "add") {
2035
2036 if (!WEB_DEMO_MODE) {
2037
2038 // no escaping is done here on purpose
2039 $exp = trim($_GET["exp"]);
2040
2041 $result = db_query($link,
2042 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2043 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2044 }
2045 }
2046
2047 print "<div class=\"prefGenericAddBox\">
2048 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
2049
2050 print"<input type=\"submit\" class=\"button\"
2051 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2052
2053 $result = db_query($link, "SELECT
2054 id,sql_exp,description
2055 FROM
2056 ttrss_labels
2057 WHERE
2058 owner_uid = ".$_SESSION["uid"]."
2059 ORDER by description");
2060
2061 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2062
2063 if (db_num_rows($result) != 0) {
2064
2065 print "<p><table width=\"100%\" cellspacing=\"0\"
2066 class=\"prefLabelList\" id=\"prefLabelList\">";
2067
2068 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2069 Select:
2070 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2071 'LILRR-', 'LICHK-', true)\">All</a>,
2072 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2073 'LILRR-', 'LICHK-', false)\">None</a>
2074 </td</tr>";
2075
2076 print "<tr class=\"title\">
2077 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
2078 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2079 </td>
2080 <td width=\"40%\">Caption</td></tr>";
2081
2082 $lnum = 0;
2083
2084 while ($line = db_fetch_assoc($result)) {
2085
2086 $class = ($lnum % 2) ? "even" : "odd";
2087
2088 $label_id = $line["id"];
2089 $edit_label_id = $_GET["id"];
2090
2091 if ($subop == "edit" && $label_id != $edit_label_id) {
2092 $class .= "Grayed";
2093 $this_row_id = "";
2094 } else {
2095 $this_row_id = "id=\"LILRR-$label_id\"";
2096 }
2097
2098 print "<tr class=\"$class\" $this_row_id>";
2099
2100 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2101 $line["description"] = htmlspecialchars($line["description"]);
2102
2103 if (!$edit_label_id || $subop != "edit") {
2104
2105 if (!$line["description"]) $line["description"] = "[No caption]";
2106
2107 print "<td><input onclick='toggleSelectRow(this);'
2108 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2109
2110 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2111 $line["sql_exp"] . "</td>";
2112
2113 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2114 $line["description"] . "</td>";
2115
2116 } else if ($label_id != $edit_label_id) {
2117
2118 if (!$line["description"]) $line["description"] = "[No description]";
2119
2120 print "<td><input disabled=\"true\" type=\"checkbox\"
2121 id=\"LICHK-".$line["id"]."\"></td>";
2122
2123 print "<td>".$line["sql_exp"]."</td>";
2124 print "<td>".$line["description"]."</td>";
2125
2126 } else {
2127
2128 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2129
2130 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2131 "\"></td>";
2132
2133 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2134 "\"></td>";
2135
2136 }
2137
2138
2139 print "</tr>";
2140
2141 ++$lnum;
2142 }
2143
2144 if ($lnum == 0) {
2145 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2146 }
2147
2148 print "</table>";
2149
2150 print "<p>";
2151
2152 if ($subop == "edit") {
2153 print "Edit label:
2154 <input type=\"submit\" class=\"button\"
2155 onclick=\"javascript:labelTest()\" value=\"Test\">
2156 <input type=\"submit\" class=\"button\"
2157 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2158 <input type=\"submit\" class=\"button\"
2159 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2160
2161 } else {
2162
2163 print "
2164 Selection:
2165 <input type=\"submit\" class=\"button\"
2166 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2167 <input type=\"submit\" class=\"button\"
2168 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2169 }
2170 } else {
2171 print "<p>No labels defined.</p>";
2172 }
2173 }
2174
2175 if ($op == "error") {
2176 print "<div width=\"100%\" align='center'>";
2177 $msg = $_GET["msg"];
2178 print $msg;
2179 print "</div>";
2180 }
2181
2182 if ($op == "help") {
2183 if (!$_GET["noheaders"]) {
2184 print "<html><head>
2185 <title>Tiny Tiny RSS : Help</title>
2186 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2187 <script type=\"text/javascript\" src=\"functions.js\"></script>
2188 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2189 </head><body>";
2190 }
2191
2192 $tid = sprintf("%d", $_GET["tid"]);
2193
2194 print "<div class='infoBoxContents'>";
2195
2196 if (file_exists("help/$tid.php")) {
2197 include("help/$tid.php");
2198 } else {
2199 print "<p>Help topic not found.</p>";
2200 }
2201
2202 print "</div>";
2203
2204 print "<div align='center'>
2205 <input type='submit' class='button'
2206 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2207
2208 if (!$_GET["noheaders"]) {
2209 print "</body></html>";
2210 }
2211
2212 }
2213
2214 if ($op == "dlg") {
2215 $id = $_GET["id"];
2216 $param = $_GET["param"];
2217
2218 if ($id == "quickAddFeed") {
2219 print "
2220 Feed URL: <input
2221 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2222 id=\"qafInput\">
2223 <input class=\"button\"
2224 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2225 <input class=\"button\"
2226 type=\"submit\" onclick=\"javascript:closeDlg()\"
2227 value=\"Cancel\">";
2228 }
2229
2230 if ($id == "quickDelFeed") {
2231
2232 $param = db_escape_string($param);
2233
2234 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2235
2236 if ($result) {
2237
2238 $f_title = db_fetch_result($result, 0, "title");
2239
2240 print "Remove current feed (<b>$f_title</b>)?&nbsp;
2241 <input class=\"button\"
2242 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2243 <input class=\"button\"
2244 type=\"submit\" onclick=\"javascript:closeDlg()\"
2245 value=\"Cancel\">";
2246 } else {
2247 print "Error: Feed $param not found.&nbsp;
2248 <input class=\"button\"
2249 type=\"submit\" onclick=\"javascript:closeDlg()\"
2250 value=\"Cancel\">";
2251 }
2252 }
2253
2254 if ($id == "search") {
2255
2256 print "<input id=\"searchbox\" class=\"extSearch\"
2257 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2258 onchange=\"javascript:search()\">
2259 <select id=\"searchmodebox\">
2260 <option selected>All feeds</option>
2261 <option>This feed</option>
2262 </select>
2263 <input type=\"submit\"
2264 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2265 <input class=\"button\"
2266 type=\"submit\" onclick=\"javascript:closeDlg()\"
2267 value=\"Close\">";
2268
2269 }
2270
2271 }
2272
2273 // update feeds of all users, may be used anonymously
2274 if ($op == "globalUpdateFeeds") {
2275
2276 $result = db_query($link, "SELECT id FROM ttrss_users");
2277
2278 while ($line = db_fetch_assoc($result)) {
2279 $user_id = $line["id"];
2280 // print "<!-- updating feeds of uid $user_id -->";
2281 update_all_feeds($link, false, $user_id);
2282 }
2283
2284 print "<rpc-reply>
2285 <message msg=\"All feeds updated\"/>
2286 </rpc-reply>";
2287
2288 }
2289
2290 if ($op == "pref-prefs") {
2291
2292 $subop = $_REQUEST["subop"];
2293
2294 if ($subop == "Save configuration") {
2295
2296 if (WEB_DEMO_MODE) {
2297 header("Location: prefs.php");
2298 return;
2299 }
2300
2301 $_SESSION["prefs_op_result"] = "save-config";
2302
2303 foreach (array_keys($_POST) as $pref_name) {
2304
2305 $pref_name = db_escape_string($pref_name);
2306 $value = db_escape_string($_POST[$pref_name]);
2307
2308 $result = db_query($link, "SELECT type_name
2309 FROM ttrss_prefs,ttrss_prefs_types
2310 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2311
2312 if (db_num_rows($result) > 0) {
2313
2314 $type_name = db_fetch_result($result, 0, "type_name");
2315
2316 // print "$pref_name : $type_name : $value<br>";
2317
2318 if ($type_name == "bool") {
2319 if ($value == "1") {
2320 $value = "true";
2321 } else {
2322 $value = "false";
2323 }
2324 } else if ($type_name == "integer") {
2325 $value = sprintf("%d", $value);
2326 }
2327
2328 // print "$pref_name : $type_name : $value<br>";
2329
2330 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2331 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2332
2333 }
2334
2335 header("Location: prefs.php");
2336
2337 }
2338
2339 } else if ($subop == "getHelp") {
2340
2341 $pref_name = db_escape_string($_GET["pn"]);
2342
2343 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2344 WHERE pref_name = '$pref_name'");
2345
2346 if (db_num_rows($result) > 0) {
2347 $help_text = db_fetch_result($result, 0, "help_text");
2348 print $help_text;
2349 } else {
2350 print "Unknown option: $pref_name";
2351 }
2352
2353 } else if ($subop == "Change password") {
2354
2355 if (WEB_DEMO_MODE) {
2356 header("Location: prefs.php");
2357 return;
2358 }
2359
2360 $old_pw = $_POST["OLD_PASSWORD"];
2361 $new_pw = $_POST["OLD_PASSWORD"];
2362
2363 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2364 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2365
2366 $active_uid = $_SESSION["uid"];
2367
2368 if ($old_pw && $new_pw) {
2369
2370 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2371
2372 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2373 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2374 pwd_hash = '$old_pw_hash')");
2375
2376 if (db_num_rows($result) == 1) {
2377 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2378 WHERE id = '$active_uid'");
2379
2380 $_SESSION["pwd_change_result"] = "ok";
2381 } else {
2382 $_SESSION["pwd_change_result"] = "failed";
2383 }
2384 }
2385
2386 header("Location: prefs.php");
2387
2388 } else if ($subop == "Reset to defaults") {
2389
2390 if (WEB_DEMO_MODE) {
2391 header("Location: prefs.php");
2392 return;
2393 }
2394
2395 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2396
2397 if (DB_TYPE == "pgsql") {
2398 db_query($link,"UPDATE ttrss_user_prefs
2399 SET value = ttrss_prefs.def_value
2400 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2401 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2402 } else {
2403 db_query($link, "DELETE FROM ttrss_user_prefs
2404 WHERE owner_uid = ".$_SESSION["uid"]);
2405 initialize_user_prefs($link, $_SESSION["uid"]);
2406 }
2407
2408 header("Location: prefs.php");
2409
2410 } else if ($subop == "Change theme") {
2411
2412 $theme = db_escape_string($_POST["theme"]);
2413
2414 if ($theme == "Default") {
2415 $theme_qpart = 'NULL';
2416 } else {
2417 $theme_qpart = "'$theme'";
2418 }
2419
2420 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2421 WHERE theme_name = '$theme'");
2422
2423 if (db_num_rows($result) == 1) {
2424 $theme_id = db_fetch_result($result, 0, "id");
2425 $theme_path = db_fetch_result($result, 0, "theme_path");
2426 } else {
2427 $theme_id = "NULL";
2428 $theme_path = "";
2429 }
2430
2431 db_query($link, "UPDATE ttrss_users SET
2432 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2433
2434 $_SESSION["theme"] = $theme_path;
2435
2436 header("Location: prefs.php");
2437
2438 } else {
2439
2440 if (!SINGLE_USER_MODE) {
2441
2442 $result = db_query($link, "SELECT id FROM ttrss_users
2443 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2444 pwd_hash = 'SHA1:".sha1("password")."')");
2445
2446 if (db_num_rows($result) != 0) {
2447 print "<div class=\"warning\">
2448 Your password is at default value, please change it.
2449 </div>";
2450 }
2451
2452 if ($_SESSION["pwd_change_result"] == "failed") {
2453 print "<div class=\"warning\">
2454 There was an error while changing your password.
2455 </div>";
2456 }
2457
2458 if ($_SESSION["pwd_change_result"] == "ok") {
2459 print "<div class=\"notice\">
2460 Password changed successfully.
2461 </div>";
2462 }
2463
2464 $_SESSION["pwd_change_result"] = "";
2465
2466 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2467 print "<div class=\"notice\">
2468 Your configuration was reset to defaults.
2469 </div>";
2470 }
2471
2472 if ($_SESSION["prefs_op_result"] == "save-config") {
2473 print "<div class=\"notice\">
2474 Your configuration was saved successfully.
2475 </div>";
2476 }
2477
2478 $_SESSION["prefs_op_result"] = "";
2479
2480 print "<form action=\"backend.php\" method=\"POST\">";
2481
2482 print "<table width=\"100%\" class=\"prefPrefsList\">";
2483 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2484
2485 print "<tr><td width=\"40%\">Old password</td>";
2486 print "<td><input class=\"editbox\" type=\"password\"
2487 name=\"OLD_PASSWORD\"></td></tr>";
2488
2489 print "<tr><td width=\"40%\">New password</td>";
2490
2491 print "<td><input class=\"editbox\" type=\"password\"
2492 name=\"NEW_PASSWORD\"></td></tr>";
2493
2494 print "</table>";
2495
2496 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2497
2498 print "<p><input class=\"button\" type=\"submit\"
2499 value=\"Change password\" name=\"subop\">";
2500
2501 print "</form>";
2502
2503 }
2504
2505 $result = db_query($link, "SELECT
2506 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2507
2508 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2509
2510 $result = db_query($link, "SELECT
2511 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2512
2513 if (db_num_rows($result) > 0) {
2514
2515 print "<form action=\"backend.php\" method=\"POST\">";
2516 print "<table width=\"100%\" class=\"prefPrefsList\">";
2517 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2518 print "<tr><td width=\"40%\">Select theme</td>";
2519 print "<td><select name=\"theme\">";
2520 print "<option>Default</option>";
2521 print "<option disabled>--------</option>";
2522
2523 while ($line = db_fetch_assoc($result)) {
2524 if ($line["id"] == $user_theme_id) {
2525 $selected = "selected";
2526 } else {
2527 $selected = "";
2528 }
2529 print "<option $selected>" . $line["theme_name"] . "</option>";
2530 }
2531 print "</select></td></tr>";
2532 print "</table>";
2533 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2534 print "<p><input class=\"button\" type=\"submit\"
2535 value=\"Change theme\" name=\"subop\">";
2536 print "</form>";
2537 }
2538
2539 $result = db_query($link, "SELECT
2540 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
2541 section_name,def_value
2542 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
2543 WHERE type_id = ttrss_prefs_types.id AND
2544 section_id = ttrss_prefs_sections.id AND
2545 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2546 owner_uid = ".$_SESSION["uid"]."
2547 ORDER BY section_id,short_desc");
2548
2549 print "<form action=\"backend.php\" method=\"POST\">";
2550
2551 $lnum = 0;
2552
2553 $active_section = "";
2554
2555 while ($line = db_fetch_assoc($result)) {
2556
2557 if ($active_section != $line["section_name"]) {
2558
2559 if ($active_section != "") {
2560 print "</table>";
2561 }
2562
2563 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
2564
2565 $active_section = $line["section_name"];
2566
2567 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
2568 // print "<tr class=\"title\">
2569 // <td width=\"25%\">Option</td><td>Value</td></tr>";
2570
2571 $lnum = 0;
2572 }
2573
2574 // $class = ($lnum % 2) ? "even" : "odd";
2575
2576 print "<tr>";
2577
2578 $type_name = $line["type_name"];
2579 $pref_name = $line["pref_name"];
2580 $value = $line["value"];
2581 $def_value = $line["def_value"];
2582 $help_text = $line["help_text"];
2583
2584 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2585
2586 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2587
2588 print "</td>";
2589
2590 print "<td>";
2591
2592 if ($type_name == "bool") {
2593 // print_select($pref_name, $value, array("true", "false"));
2594
2595 if ($value == "true") {
2596 $value = "Yes";
2597 } else {
2598 $value = "No";
2599 }
2600
2601 print_radio($pref_name, $value, array("Yes", "No"));
2602
2603 } else {
2604 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2605 }
2606
2607 print "</td>";
2608
2609 print "</tr>";
2610
2611 $lnum++;
2612 }
2613
2614 print "</table>";
2615
2616 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2617
2618 print "<p><input class=\"button\" type=\"submit\"
2619 name=\"subop\" value=\"Save configuration\">";
2620
2621 print "&nbsp;<input class=\"button\" type=\"submit\"
2622 name=\"subop\" value=\"Reset to defaults\"></p>";
2623
2624 print "</form>";
2625
2626 }
2627
2628 }
2629
2630 if ($op == "pref-users") {
2631
2632 $subop = $_GET["subop"];
2633
2634 if ($subop == "editSave") {
2635
2636 if (!WEB_DEMO_MODE) {
2637
2638 $login = db_escape_string($_GET["l"]);
2639 $uid = db_escape_string($_GET["id"]);
2640 $access_level = sprintf("%d", $_GET["al"]);
2641
2642 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2643
2644 }
2645 } else if ($subop == "remove") {
2646
2647 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2648
2649 $ids = split(",", $_GET["ids"]);
2650
2651 foreach ($ids as $id) {
2652 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2653
2654 }
2655 }
2656 } else if ($subop == "add") {
2657
2658 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2659
2660 $login = db_escape_string(trim($_GET["login"]));
2661 $tmp_user_pwd = make_password(8);
2662 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2663
2664 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2665 VALUES ('$login', '$pwd_hash', 0)");
2666
2667
2668 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2669 login = '$login' AND pwd_hash = '$pwd_hash'");
2670
2671 if (db_num_rows($result) == 1) {
2672
2673 $new_uid = db_fetch_result($result, 0, "id");
2674
2675 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2676 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2677
2678 initialize_user($link, $new_uid);
2679
2680 } else {
2681
2682 print "<div class=\"warning\">Error while adding user <b>".
2683 $_GET["login"].".</b></div>";
2684
2685 }
2686 }
2687 } else if ($subop == "resetPass") {
2688
2689 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2690
2691 $uid = db_escape_string($_GET["id"]);
2692
2693 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2694
2695 $login = db_fetch_result($result, 0, "login");
2696 $tmp_user_pwd = make_password(8);
2697 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2698
2699 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2700 WHERE id = '$uid'");
2701
2702 print "<div class=\"notice\">Changed password of
2703 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2704
2705 }
2706 }
2707
2708 print "<div class=\"prefGenericAddBox\">
2709 <input id=\"uadd_box\" size=\"40\">&nbsp;";
2710
2711 print"<input type=\"submit\" class=\"button\"
2712 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
2713
2714 $result = db_query($link, "SELECT
2715 id,login,access_level,
2716 SUBSTRING(last_login,1,16) as last_login
2717 FROM
2718 ttrss_users
2719 ORDER by login");
2720
2721 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2722
2723 print "<p><table width=\"100%\" cellspacing=\"0\"
2724 class=\"prefUserList\" id=\"prefUserList\">";
2725
2726 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2727 Select:
2728 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2729 'UMRR-', 'UMCHK-', true)\">All</a>,
2730 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2731 'UMRR-', 'UMCHK-', false)\">None</a>
2732 </td</tr>";
2733
2734 print "<tr class=\"title\">
2735 <td width=\"5%\">Select</td>
2736 <td width='30%'>Username</td>
2737 <td width='30%'>Access Level</td>
2738 <td width='30%'>Last login</td></tr>";
2739
2740 $lnum = 0;
2741
2742 while ($line = db_fetch_assoc($result)) {
2743
2744 $class = ($lnum % 2) ? "even" : "odd";
2745
2746 $uid = $line["id"];
2747 $edit_uid = $_GET["id"];
2748
2749 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
2750 $class .= "Grayed";
2751 $this_row_id = "";
2752 } else {
2753 $this_row_id = "id=\"UMRR-$uid\"";
2754 }
2755
2756 print "<tr class=\"$class\" $this_row_id>";
2757
2758 $line["login"] = htmlspecialchars($line["login"]);
2759
2760 if ($uid == $_SESSION["uid"]) {
2761
2762 print "<td><input disabled=\"true\" type=\"checkbox\"
2763 id=\"UMCHK-".$line["id"]."\"></td>";
2764
2765 print "<td>".$line["login"]."</td>";
2766 print "<td>".$line["access_level"]."</td>";
2767
2768 } else if (!$edit_uid || $subop != "edit") {
2769
2770 print "<td><input onclick='toggleSelectRow(this);'
2771 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
2772
2773 print "<td><a href=\"javascript:editUser($uid);\">" .
2774 $line["login"] . "</td>";
2775
2776 print "<td><a href=\"javascript:editUser($uid);\">" .
2777 $line["access_level"] . "</td>";
2778
2779 } else if ($uid != $edit_uid) {
2780
2781 print "<td><input disabled=\"true\" type=\"checkbox\"
2782 id=\"UMCHK-".$line["id"]."\"></td>";
2783
2784 print "<td>".$line["login"]."</td>";
2785 print "<td>".$line["access_level"]."</td>";
2786
2787 } else {
2788
2789 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2790
2791 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2792 "\"></td>";
2793
2794 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2795 "\"></td>";
2796
2797 }
2798
2799 print "<td>".$line["last_login"]."</td>";
2800
2801 print "</tr>";
2802
2803 ++$lnum;
2804 }
2805
2806 print "</table>";
2807
2808 print "<p>";
2809
2810 if ($subop == "edit") {
2811 print "Edit label:
2812 <input type=\"submit\" class=\"button\"
2813 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2814 <input type=\"submit\" class=\"button\"
2815 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2816
2817 } else {
2818
2819 print "
2820 Selection:
2821 <input type=\"submit\" class=\"button\"
2822 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
2823 <input type=\"submit\" class=\"button\"
2824 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2825 <input type=\"submit\" class=\"button\"
2826 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2827 <input type=\"submit\" class=\"button\"
2828 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2829
2830 }
2831 }
2832
2833 if ($op == "user-details") {
2834
2835 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2836 return;
2837 }
2838
2839 /* print "<html><head>
2840 <title>Tiny Tiny RSS : User Details</title>
2841 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2842 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2843 </head><body>"; */
2844
2845 $uid = sprintf("%d", $_GET["id"]);
2846
2847 print "<div class='infoBoxContents'>";
2848
2849 $result = db_query($link, "SELECT login,
2850 SUBSTRING(last_login,1,16) AS last_login,
2851 access_level,
2852 (SELECT COUNT(int_id) FROM ttrss_user_entries
2853 WHERE owner_uid = id) AS stored_articles
2854 FROM ttrss_users
2855 WHERE id = '$uid'");
2856
2857 if (db_num_rows($result) == 0) {
2858 print "<h1>User not found</h1>";
2859 return;
2860 }
2861
2862 print "<h1>User Details</h1>";
2863
2864 print "<table width='100%'>";
2865
2866 $login = db_fetch_result($result, 0, "login");
2867 $last_login = db_fetch_result($result, 0, "last_login");
2868 $access_level = db_fetch_result($result, 0, "access_level");
2869 $stored_articles = db_fetch_result($result, 0, "stored_articles");
2870
2871 print "<tr><td>Username</td><td>$login</td></tr>";
2872 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2873 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
2874 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
2875
2876 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2877 WHERE owner_uid = '$uid'");
2878
2879 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2880
2881 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2882
2883 /* $result = db_query($link, "SELECT
2884 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
2885 FROM ttrss_user_entries,ttrss_entries
2886 WHERE owner_uid = '$uid' AND ref_id = id");
2887
2888 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
2889
2890 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
2891
2892 print "</table>";
2893
2894 print "<h1>Subscribed feeds</h1>";
2895
2896 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2897 WHERE owner_uid = '$uid' ORDER BY title");
2898
2899 print "<ul class=\"nomarks\">";
2900
2901 while ($line = db_fetch_assoc($result)) {
2902
2903 $icon_file = ICONS_URL."/".$line["id"].".ico";
2904
2905 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2906 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
2907 } else {
2908 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
2909 }
2910
2911 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2912 }
2913
2914 print "</ul>";
2915
2916 print "</div>";
2917
2918 print "<div align='center'>
2919 <input type='submit' class='button'
2920 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2921
2922 // print "</body></html>";
2923
2924 }
2925
2926 if ($op == "feed-details") {
2927
2928 $feed_id = $_GET["id"];
2929
2930 $result = db_query($link,
2931 "SELECT
2932 title,feed_url,last_updated,icon_url,site_url,
2933 (SELECT COUNT(int_id) FROM ttrss_user_entries
2934 WHERE feed_id = id) AS total,
2935 (SELECT COUNT(int_id) FROM ttrss_user_entries
2936 WHERE feed_id = id AND unread = true) AS unread,
2937 (SELECT COUNT(int_id) FROM ttrss_user_entries
2938 WHERE feed_id = id AND marked = true) AS marked
2939 FROM ttrss_feeds
2940 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2941
2942 if (db_num_rows($result) == 0) return;
2943
2944 $title = db_fetch_result($result, 0, "title");
2945 $last_updated = db_fetch_result($result, 0, "last_updated");
2946 $feed_url = db_fetch_result($result, 0, "feed_url");
2947 $icon_url = db_fetch_result($result, 0, "icon_url");
2948 $total = db_fetch_result($result, 0, "total");
2949 $unread = db_fetch_result($result, 0, "unread");
2950 $marked = db_fetch_result($result, 0, "marked");
2951 $site_url = db_fetch_result($result, 0, "site_url");
2952
2953 $result = db_query($link, "SELECT COUNT(id) AS subscribed
2954 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
2955
2956 $subscribed = db_fetch_result($result, 0, "subscribed");
2957
2958 print "<div class=\"infoBoxContents\">";
2959
2960 $icon_file = ICONS_DIR . "/$feed_id.ico";
2961
2962 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2963 $feed_icon = "<img width=\"16\" height=\"16\"
2964 src=\"" . ICONS_URL . "/$feed_id.ico\">";
2965 } else {
2966 $feed_icon = "";
2967 }
2968
2969 print "<h1>$feed_icon $title</h1>";
2970
2971 print "<table width='100%'>";
2972
2973 if ($site_url) {
2974 print "<tr><td width='30%'>Link</td>
2975 <td><a href=\"$site_url\">$site_url</a>
2976 <a href=\"$feed_url\">(feed)</a></td>
2977 </td></tr>";
2978 } else {
2979 print "<tr><td width='30%'>Feed URL</td>
2980 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
2981 }
2982 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
2983 print "<tr><td>Total articles</td><td>$total</td></tr>";
2984 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
2985 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
2986 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
2987
2988 print "</table>";
2989
2990 $result = db_query($link, "SELECT title,
2991 SUBSTRING(updated,1,16) AS updated,unread
2992 FROM ttrss_entries,ttrss_user_entries
2993 WHERE ref_id = id AND feed_id = '$feed_id'
2994 ORDER BY date_entered DESC LIMIT 5");
2995
2996 if (db_num_rows($result) > 0) {
2997
2998 print "<h1>Latest headlines</h1>";
2999
3000 print "<ul class=\"nomarks\">";
3001
3002 while ($line = db_fetch_assoc($result)) {
3003 if ($line["unread"] == "t" || $line["unread"] == "1") {
3004 $line["title"] = "<b>" . $line["title"] . "</b>";
3005 }
3006 print "<li>" . $line["title"].
3007 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
3008 }
3009
3010 print "</ul>";
3011
3012 print "</div>";
3013
3014 print "<div align='center'>
3015 <input type='submit' class='button'
3016 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3017 }
3018 }
3019
3020 db_close($link);
3021 ?>
3022
3023 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3024