]> git.wh0rd.org - tt-rss.git/blob - backend.php
rework label counter behaviour
[tt-rss.git] / backend.php
1 <?
2 $op = $_GET["op"];
3
4 if ($op == "rpc") {
5 header("Content-Type: application/xml");
6 }
7
8 require_once "config.php";
9 require_once "db.php";
10 require_once "functions.php";
11 require_once "magpierss/rss_fetch.inc";
12
13 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
14
15 if (DB_TYPE == "pgsql") {
16 pg_query("set client_encoding = 'utf-8'");
17 }
18
19 $fetch = $_GET["fetch"];
20
21 function getLabelCounters($link) {
22
23 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
24 WHERE marked = true");
25
26 $count = db_fetch_result($result, 0, "count");
27
28 print "<label id=\"-1\" counter=\"$count\"/>";
29
30 $result = db_query($link, "SELECT id,sql_exp,description FROM
31 ttrss_labels ORDER by description");
32
33 while ($line = db_fetch_assoc($result)) {
34
35 $id = -$line["id"] - 11;
36
37 error_reporting (0);
38
39 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
40 WHERE (" . $line["sql_exp"] . ") AND unread = true");
41
42 $count = db_fetch_result($tmp_result, 0, "count");
43
44 print "<feed id=\"$id\" counter=\"$count\"/>";
45
46 error_reporting (E_ERROR | E_WARNING | E_PARSE);
47
48 }
49 }
50
51 function getFeedCounters($link) {
52
53 $result = db_query($link, "SELECT id,
54 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
55 AND unread = true) as count
56 FROM ttrss_feeds");
57
58 while ($line = db_fetch_assoc($result)) {
59
60 $id = $line["id"];
61 $count = $line["count"];
62
63 print "<feed id=\"$id\" counter=\"$count\"/>";
64 }
65 }
66
67 function outputFeedList($link) {
68
69 print "<html><head>
70 <title>Tiny Tiny RSS : Feedlist</title>
71 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
72 <script type=\"text/javascript\" src=\"functions.js\"></script>
73 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
74 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
75 </head><body>";
76
77 print "<ul class=\"feedList\" id=\"feedList\">";
78
79 /* virtual feeds */
80
81 $result = db_query($link, "SELECT count(id) as num_starred
82 FROM ttrss_entries WHERE marked = true");
83 $num_starred = db_fetch_result($result, 0, "num_starred");
84
85 printFeedEntry(-1, "odd", "Starred articles", $num_starred, "images/mark_set.png");
86
87 if (ENABLE_LABELS) {
88
89 $result = db_query($link, "SELECT id,sql_exp,description FROM
90 ttrss_labels ORDER by description");
91
92 if (db_num_rows($result) > 0) {
93 print "<li><hr></li>";
94 }
95
96 while ($line = db_fetch_assoc($result)) {
97
98 error_reporting (0);
99
100 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
101 WHERE (" . $line["sql_exp"] . ") AND unread = true");
102
103 $count = db_fetch_result($tmp_result, 0, "count");
104
105 $class = "odd";
106
107 if ($count > 0) {
108 $class .= "Unread";
109 }
110
111 error_reporting (E_ERROR | E_WARNING | E_PARSE);
112
113 printFeedEntry(-$line["id"]-11,
114 $class, $line["description"], $count, "images/label.png");
115
116 }
117 }
118
119 print "<li><hr></li>";
120
121 $result = db_query($link, "SELECT *,
122 (SELECT count(id) FROM ttrss_entries
123 WHERE feed_id = ttrss_feeds.id) AS total,
124 (SELECT count(id) FROM ttrss_entries
125 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
126 FROM ttrss_feeds ORDER BY title");
127
128 $actid = $_GET["actid"];
129
130 /* real feeds */
131
132 $lnum = 0;
133
134 $total_unread = 0;
135
136 while ($line = db_fetch_assoc($result)) {
137
138 $feed = $line["title"];
139 $feed_id = $line["id"];
140
141 $subop = $_GET["subop"];
142
143 $total = $line["total"];
144 $unread = $line["unread"];
145
146 // $class = ($lnum % 2) ? "even" : "odd";
147
148 $class = "odd";
149
150 if ($unread > 0) $class .= "Unread";
151
152 if ($actid == $feed_id) {
153 $class .= "Selected";
154 }
155
156 $total_unread += $unread;
157
158 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
159
160 ++$lnum;
161 }
162
163 print "</table>";
164
165 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
166
167 }
168
169
170 if ($op == "rpc") {
171
172 $subop = $_GET["subop"];
173
174 if ($subop == "getLabelCounters") {
175 print "<rpc-reply>";
176 getLabelCounters($link);
177 print "</rpc-reply>";
178 }
179
180 if ($subop == "getFeedCounters") {
181 print "<rpc-reply>";
182 getFeedCounters($link);
183 print "</rpc-reply>";
184 }
185
186 if ($subop == "getAllCounters") {
187 print "<rpc-reply>";
188 getLabelCounters($link);
189 getFeedCounters($link);
190 print "</rpc-reply>";
191
192 }
193
194 if ($subop == "mark") {
195 $mark = $_GET["mark"];
196 $id = db_escape_string($_GET["id"]);
197
198 if ($mark == "1") {
199 $mark = "true";
200 } else {
201 $mark = "false";
202 }
203
204 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
205 WHERE id = '$id'");
206 }
207
208 if ($subop == "updateFeed") {
209 $feed_id = db_escape_string($_GET["feed"]);
210
211 $result = db_query($link,
212 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
213
214 if (db_num_rows($result) > 0) {
215 $feed_url = db_fetch_result($result, 0, "feed_url");
216 // update_rss_feed($link, $feed_url, $feed_id);
217 }
218
219 print "DONE-$feed_id";
220
221 return;
222 }
223
224 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
225 update_all_feeds($link, true);
226
227 print "<rpc-reply>";
228 getLabelCounters($link);
229 getFeedCounters($link);
230 print "</rpc-reply>";
231 }
232
233 if ($subop == "catchupPage") {
234
235 $ids = split(",", $_GET["ids"]);
236
237 foreach ($ids as $id) {
238
239 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
240 WHERE id = '$id'");
241
242 }
243
244 print "Marked active page as read.";
245 }
246 }
247
248 if ($op == "feeds") {
249
250 $subop = $_GET["subop"];
251
252 if ($subop == "catchupAll") {
253 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
254 }
255
256 outputFeedList($link);
257
258 }
259
260 if ($op == "view") {
261
262 $id = $_GET["id"];
263
264 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
265
266 $addheader = $_GET["addheader"];
267
268 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
269 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
270 FROM ttrss_entries
271 WHERE id = '$id'");
272
273 if ($addheader) {
274 print "<html><head>
275 <title>Tiny Tiny RSS : Article $id</title>
276 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
277 <script type=\"text/javascript\" src=\"functions.js\"></script>
278 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
279 </head><body>";
280 }
281
282 if ($result) {
283
284 $line = db_fetch_assoc($result);
285
286 if ($line["icon_url"]) {
287 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
288 } else {
289 $feed_icon = "&nbsp;";
290 }
291
292 if ($line["comments"] && $line["link"] != $line["comments"]) {
293 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
294 } else {
295 $entry_comments = "";
296 }
297
298 print "<div class=\"postReply\">";
299
300 print "<div class=\"postHeader\"><table>";
301
302 print "<tr><td><b>Title:</b></td>
303 <td width='100%'>" . $line["title"] . "</td></tr>";
304
305 print "<tr><td><b>Link:</b></td>
306 <td width='100%'>
307 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
308 $entry_comments</td></tr>";
309
310 print "</table></div>";
311
312 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
313 print "<div class=\"postContent\">" . $line["content"] . "</div>";
314
315 print "</div>";
316
317 print "<script type=\"text/javascript\">
318 update_label_counters();
319 </script>";
320 }
321
322 if ($addheader) {
323 print "</body></html>";
324 }
325 }
326
327 if ($op == "viewfeed") {
328
329 $feed = $_GET["feed"];
330 $skip = $_GET["skip"];
331 $subop = $_GET["subop"];
332 $view_mode = $_GET["view"];
333 $addheader = $_GET["addheader"];
334 $limit = $_GET["limit"];
335
336 if (!$feed) {
337 print "Error: no feed to display.";
338 return;
339 }
340
341 if (!$skip) $skip = 0;
342
343 if ($subop == "undefined") $subop = "";
344
345 if ($addheader) {
346 print "<html><head>
347 <title>Tiny Tiny RSS : Feed $feed</title>
348 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
349 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
350 <script type=\"text/javascript\" src=\"functions.js\"></script>
351 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
352 </head><body>";
353 }
354
355 if ($feed >= 0) {
356
357 $result = db_query($link,
358 "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s
359 FROM ttrss_feeds WHERE id = '$feed'");
360
361 if ($result) {
362
363 $line = db_fetch_assoc($result);
364
365 update_rss_feed($link, $line["feed_url"], $feed);
366
367 if ($subop == "MarkAllRead") {
368
369 db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW()
370 WHERE feed_id = '$feed'");
371 }
372 }
373 }
374
375 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
376
377 $search = $_GET["search"];
378
379 if ($search) {
380 $search_query_part = "(upper(title) LIKE upper('%$search%')
381 OR content LIKE '%$search%') AND";
382 } else {
383 $search_query_part = "";
384 }
385
386 $view_query_part = "";
387
388 if ($view_mode == "Starred") {
389 $view_query_part = " marked = true AND ";
390 }
391
392 if ($view_mode == "Unread") {
393 $view_query_part = " unread = true AND ";
394 }
395
396 /* $result = db_query($link, "SELECT count(id) AS total_entries
397 FROM ttrss_entries WHERE
398 $search_query_part
399 feed_id = '$feed'");
400
401 $total_entries = db_fetch_result($result, 0, "total_entries"); */
402
403 /* $result = db_query("SELECT count(id) AS unread_entries
404 FROM ttrss_entries WHERE
405 $search_query_part
406 unread = true AND
407 feed_id = '$feed'");
408
409 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
410
411 if ($limit && $limit != "All") {
412 $limit_query_part = "LIMIT " . $limit;
413 }
414
415 $vfeed_query_part = "";
416
417 if ($feed >= 0) {
418 $query_strategy_part = "feed_id = '$feed'";
419 } else if ($feed == -1) { // starred virtual feed
420 $query_strategy_part = "marked = true";
421 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
422 id = feed_id) as feed_title,";
423 } else if ($feed <= -10) { // labels
424 $label_id = -$feed - 11;
425
426 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
427 WHERE id = '$label_id'");
428
429 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
430
431 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
432 id = feed_id) as feed_title,";
433 } else {
434 $query_strategy_part = "id > 0"; // dumb
435 }
436
437 if ($feed < -10) error_reporting (0);
438
439 $result = db_query($link, "SELECT
440 id,title,updated,unread,feed_id,marked,link,last_read,
441 SUBSTRING(last_read,1,19) as last_read_noms,
442 $vfeed_query_part
443 SUBSTRING(updated,1,19) as updated_noms
444 FROM
445 ttrss_entries
446 WHERE
447 $search_query_part
448 $view_query_part
449 $query_strategy_part ORDER BY updated DESC
450 $limit_query_part");
451
452 if (!$result) {
453 print "<tr><td colspan='4' align='center'>
454 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
455 return;
456 }
457
458 $lnum = 0;
459
460 error_reporting (E_ERROR | E_WARNING | E_PARSE);
461
462 $num_unread = 0;
463
464 while ($line = db_fetch_assoc($result)) {
465
466 $class = ($lnum % 2) ? "even" : "odd";
467
468 $id = $line["id"];
469 $feed_id = $line["feed_id"];
470
471 // printf("L %d (%s) &gt; U %d (%s) = %d<br>",
472 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
473 // strtotime($line["updated"]), $line["updated"],
474 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
475
476 if ($line["last_read"] != "" && $line["updated"] != "" &&
477 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
478
479 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
480 alt=\"Updated\">";
481
482 } else {
483
484 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
485 alt=\"Updated\">";
486
487 }
488
489 if ($line["unread"] == "t" || $line["unread"] == "1") {
490 $class .= "Unread";
491 ++$num_unread;
492 }
493
494 if ($line["marked"] == "t" || $line["marked"] == "1") {
495 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
496 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
497 } else {
498 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
499 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
500 }
501
502 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
503 $line["title"] . "</a>";
504
505 print "<tr class='$class' id='RROW-$id'>";
506 // onclick=\"javascript:view($id,$feed_id)\">
507
508 print "<td valign='center' align='center'>$update_pic</td>";
509 print "<td valign='center' align='center'>$marked_pic</td>";
510
511 print "<td width='25%'>
512 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
513
514 if ($line["feed_title"]) {
515 print "<td width='50%'>$content_link</td>";
516 print "<td width='20%'>".$line["feed_title"]."</td>";
517 } else {
518 print "<td width='70%'>$content_link</td>";
519 }
520
521 print "</tr>";
522
523 ++$lnum;
524 }
525
526 if ($lnum == 0) {
527 print "<tr><td align='center'>No articles found.</td></tr>";
528 }
529
530 /* while ($lnum < HEADLINES_PER_PAGE) {
531 ++$lnum;
532 print "<tr><td>&nbsp;</td></tr>";
533 } */
534
535 print "</table>";
536
537 if ($feed >= 0) {
538
539 $result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries
540 WHERE feed_id = '$feed' AND $query_strategy_part
541 AND unread = true");
542
543 $unread = db_fetch_result($result, 0, "unread");
544
545 } else if ($feed == -1) {
546 $result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries
547 WHERE $query_strategy_part");
548
549 $unread = db_fetch_result($result, 0, "unread");
550
551 } else {
552 // print "[viewfeed] feed type not implemented<br>";
553
554 error_reporting(0);
555 $result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries
556 WHERE $query_strategy_part");
557
558 $unread = db_fetch_result($result, 0, "unread");
559
560 error_reporting (E_ERROR | E_WARNING | E_PARSE);
561 }
562
563 if (!$unread) $unread = 0;
564
565 // update unread/total counters and status for active feed in the feedlist
566 // kludge, because iframe doesn't seem to support onload()
567
568 print "<script type=\"text/javascript\">
569 document.onkeydown = hotkey_handler;
570
571 var p_document = parent.frames['feeds-frame'].document;
572
573 var feedr = p_document.getElementById(\"FEEDR-\" + $feed);
574 var feedu = p_document.getElementById(\"FEEDU-\" + $feed);
575
576 if (feedu) {
577 feedu.innerHTML = \"$unread\";
578 }
579
580 var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed);
581
582 if ($unread > 0 && $feed >= 0 && !feedr.className.match(\"Unread\")) {
583 feedr.className = feedr.className + \"Unread\";
584 feedctr.className = '';
585 } else if ($unread <= 0) {
586 feedr.className = feedr.className.replace(\"Unread\", \"\");
587 feedctr.className = 'invisible';
588 }
589
590 update_label_counters();
591
592 // p_notify(\"\");
593
594 </script>";
595
596 if ($addheader) {
597 print "</body></html>";
598 }
599
600 }
601
602 if ($op == "pref-rpc") {
603
604 $subop = $_GET["subop"];
605
606 if ($subop == "unread") {
607 $ids = split(",", $_GET["ids"]);
608 foreach ($ids as $id) {
609 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
610 }
611
612 print "Marked selected feeds as read.";
613 }
614
615 if ($subop == "read") {
616 $ids = split(",", $_GET["ids"]);
617 foreach ($ids as $id) {
618 db_query($link, "UPDATE ttrss_entries
619 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
620 }
621
622 print "Marked selected feeds as unread.";
623
624 }
625
626 }
627
628 if ($op == "pref-feeds") {
629
630 $subop = $_GET["subop"];
631
632 if ($subop == "editSave") {
633 $feed_title = db_escape_string($_GET["t"]);
634 $feed_link = db_escape_string($_GET["l"]);
635 $feed_id = $_GET["id"];
636
637 $result = db_query($link, "UPDATE ttrss_feeds SET
638 title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'");
639
640 }
641
642 if ($subop == "remove") {
643
644 if (!WEB_DEMO_MODE) {
645
646 $ids = split(",", $_GET["ids"]);
647
648 foreach ($ids as $id) {
649 db_query($link, "BEGIN");
650 db_query($link, "DELETE FROM ttrss_entries WHERE feed_id = '$id'");
651 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
652 db_query($link, "COMMIT");
653
654 if (file_exists(ICONS_DIR . "/$id.ico")) {
655 unlink(ICONS_DIR . "/$id.ico");
656 }
657 }
658 }
659 }
660
661 if ($subop == "add") {
662
663 if (!WEB_DEMO_MODE) {
664
665 $feed_link = db_escape_string($_GET["link"]);
666
667 $result = db_query($link,
668 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
669
670 $result = db_query($link,
671 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
672
673 $feed_id = db_fetch_result($result, 0, "id");
674
675 if ($feed_id) {
676 update_rss_feed($link, $feed_link, $feed_id);
677 }
678 }
679 }
680
681 print "<table class=\"prefAddFeed\"><tr>
682 <td><input id=\"fadd_link\"></td>
683 <td colspan=\"4\" align=\"right\">
684 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
685 </table>";
686
687 $result = db_query($link, "SELECT
688 id,title,feed_url,substring(last_updated,1,16) as last_updated
689 FROM
690 ttrss_feeds ORDER by title");
691
692 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
693 print "<tr class=\"title\">
694 <td>&nbsp;</td><td>Select</td><td width=\"40%\">Title</td>
695 <td width=\"40%\">Link</td><td>Last updated</td></tr>";
696
697 $lnum = 0;
698
699 while ($line = db_fetch_assoc($result)) {
700
701 $class = ($lnum % 2) ? "even" : "odd";
702
703 $feed_id = $line["id"];
704
705 $edit_feed_id = $_GET["id"];
706
707 if ($subop == "edit" && $feed_id != $edit_feed_id) {
708 $class .= "Grayed";
709 }
710
711 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
712
713 $icon_file = ICONS_DIR . "/$feed_id.ico";
714
715 if (file_exists($icon_file) && filesize($icon_file) > 0) {
716 $feed_icon = "<img width=\"16\" height=\"16\"
717 src=\"" . ICONS_URL . "/$feed_id.ico\">";
718 } else {
719 $feed_icon = "&nbsp;";
720 }
721 print "<td align='center'>$feed_icon</td>";
722
723 if (!$edit_feed_id || $subop != "edit") {
724
725 print "<td><input onclick='toggleSelectRow(this);'
726 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
727
728 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
729 $line["title"] . "</td>";
730 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
731 $line["feed_url"] . "</td>";
732
733
734 } else if ($feed_id != $edit_feed_id) {
735
736 print "<td><input disabled=\"true\" type=\"checkbox\"
737 id=\"FRCHK-".$line["id"]."\"></td>";
738
739 print "<td>".$line["title"]."</td>";
740 print "<td>".$line["feed_url"]."</td>";
741
742 } else {
743
744 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
745
746 print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>";
747 print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>";
748
749 }
750
751 if (!$line["last_updated"]) $line["last_updated"] = "Never";
752
753 print "<td>" . $line["last_updated"] . "</td>";
754
755 print "</tr>";
756
757 ++$lnum;
758 }
759
760 if ($lnum == 0) {
761 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
762 }
763
764 print "</table>";
765
766 print "<p>";
767
768 if ($subop == "edit") {
769 print "Edit feed:&nbsp;
770 <input type=\"submit\" class=\"button\"
771 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
772 <input type=\"submit\" class=\"button\"
773 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
774 } else {
775
776 print "
777 Selection:&nbsp;
778 <input type=\"submit\" class=\"button\"
779 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
780 <input type=\"submit\" class=\"button\"
781 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
782
783 if (ENABLE_PREFS_CATCHUP_UNCATCHUP) {
784 print "
785 <input type=\"submit\" class=\"button\"
786 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
787 <input type=\"submit\" class=\"button\"
788 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
789 }
790 print "
791 All feeds:
792 <input type=\"submit\"
793 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
794
795 }
796
797 }
798
799 if ($op == "pref-filters") {
800
801 $subop = $_GET["subop"];
802
803 if ($subop == "editSave") {
804
805 $regexp = db_escape_string($_GET["r"]);
806 $descr = db_escape_string($_GET["d"]);
807 $match = db_escape_string($_GET["m"]);
808 $filter_id = db_escape_string($_GET["id"]);
809
810 $result = db_query($link, "UPDATE ttrss_filters SET
811 reg_exp = '$regexp',
812 description = '$descr',
813 filter_type = (SELECT id FROM ttrss_filter_types WHERE
814 description = '$match')
815 WHERE id = '$filter_id'");
816 }
817
818 if ($subop == "remove") {
819
820 if (!WEB_DEMO_MODE) {
821
822 $ids = split(",", $_GET["ids"]);
823
824 foreach ($ids as $id) {
825 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
826
827 }
828 }
829 }
830
831 if ($subop == "add") {
832
833 if (!WEB_DEMO_MODE) {
834
835 $regexp = db_escape_string($_GET["regexp"]);
836 $match = db_escape_string($_GET["match"]);
837
838 $result = db_query($link,
839 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
840 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
841 description = '$match'))");
842 }
843 }
844
845 $result = db_query($link, "SELECT description
846 FROM ttrss_filter_types ORDER BY description");
847
848 $filter_types = array();
849
850 while ($line = db_fetch_assoc($result)) {
851 array_push($filter_types, $line["description"]);
852 }
853
854 print "<table class=\"prefAddFeed\"><tr>
855 <td><input id=\"fadd_regexp\"></td>
856 <td>";
857 print_select("fadd_match", "Title", $filter_types);
858
859 print"</td><td colspan=\"4\" align=\"right\">
860 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
861 </table>";
862
863 $result = db_query($link, "SELECT
864 id,reg_exp,description,
865 (SELECT name FROM ttrss_filter_types WHERE
866 id = filter_type) as filter_type_name,
867 (SELECT description FROM ttrss_filter_types
868 WHERE id = filter_type) as filter_type_descr
869 FROM
870 ttrss_filters ORDER by reg_exp");
871
872 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
873
874 print "<tr class=\"title\">
875 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
876 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
877
878 $lnum = 0;
879
880 while ($line = db_fetch_assoc($result)) {
881
882 $class = ($lnum % 2) ? "even" : "odd";
883
884 $filter_id = $line["id"];
885 $edit_filter_id = $_GET["id"];
886
887 if ($subop == "edit" && $filter_id != $edit_filter_id) {
888 $class .= "Grayed";
889 }
890
891 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
892
893 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
894 $line["description"] = htmlspecialchars($line["description"]);
895
896 if (!$edit_filter_id || $subop != "edit") {
897
898 if (!$line["description"]) $line["description"] = "[No description]";
899
900 print "<td><input onclick='toggleSelectRow(this);'
901 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
902
903 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
904 $line["reg_exp"] . "</td>";
905
906 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
907 $line["description"] . "</td>";
908
909 print "<td>".$line["filter_type_descr"]."</td>";
910
911 } else if ($filter_id != $edit_filter_id) {
912
913 if (!$line["description"]) $line["description"] = "[No description]";
914
915 print "<td><input disabled=\"true\" type=\"checkbox\"
916 id=\"FICHK-".$line["id"]."\"></td>";
917
918 print "<td>".$line["reg_exp"]."</td>";
919 print "<td>".$line["description"]."</td>";
920 print "<td>".$line["filter_type_descr"]."</td>";
921
922 } else {
923
924 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
925
926 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
927 "\"></td>";
928
929 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
930 "\"></td>";
931
932 print "<td>";
933 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
934 print "</td>";
935
936 }
937
938
939 print "</tr>";
940
941 ++$lnum;
942 }
943
944 if ($lnum == 0) {
945 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
946 }
947
948 print "</table>";
949
950 print "<p>";
951
952 if ($subop == "edit") {
953 print "Edit feed:
954 <input type=\"submit\" class=\"button\"
955 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
956 <input type=\"submit\" class=\"button\"
957 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
958
959 } else {
960
961 print "
962 Selection:
963 <input type=\"submit\" class=\"button\"
964 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
965 <input type=\"submit\" class=\"button\"
966 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
967 }
968 }
969
970 if ($op == "pref-labels") {
971
972 $subop = $_GET["subop"];
973
974 if ($subop == "editSave") {
975
976 $sql_exp = $_GET["s"];
977 $descr = $_GET["d"];
978 $label_id = db_escape_string($_GET["id"]);
979
980 // print "$sql_exp : $descr : $label_id";
981
982 $result = db_query($link, "UPDATE ttrss_labels SET
983 sql_exp = '$sql_exp',
984 description = '$descr'
985 WHERE id = '$label_id'");
986 }
987
988 if ($subop == "remove") {
989
990 if (!WEB_DEMO_MODE) {
991
992 $ids = split(",", $_GET["ids"]);
993
994 foreach ($ids as $id) {
995 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
996
997 }
998 }
999 }
1000
1001 if ($subop == "add") {
1002
1003 if (!WEB_DEMO_MODE) {
1004
1005 $exp = $_GET["exp"];
1006
1007 $result = db_query($link,
1008 "INSERT INTO ttrss_labels (sql_exp,description)
1009 VALUES ('$exp', '$exp')");
1010 }
1011 }
1012
1013 print "<table class=\"prefAddFeed\"><tr>
1014 <td><input id=\"ladd_expr\"></td>";
1015
1016 print"<td colspan=\"4\" align=\"right\">
1017 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1018 </table>";
1019
1020 $result = db_query($link, "SELECT
1021 id,sql_exp,description
1022 FROM
1023 ttrss_labels ORDER by description");
1024
1025 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1026
1027 print "<tr class=\"title\">
1028 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression</td>
1029 <td width=\"40%\">Caption</td></tr>";
1030
1031 $lnum = 0;
1032
1033 while ($line = db_fetch_assoc($result)) {
1034
1035 $class = ($lnum % 2) ? "even" : "odd";
1036
1037 $label_id = $line["id"];
1038 $edit_label_id = $_GET["id"];
1039
1040 if ($subop == "edit" && $label_id != $edit_label_id) {
1041 $class .= "Grayed";
1042 }
1043
1044 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1045
1046 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1047 $line["description"] = htmlspecialchars($line["description"]);
1048
1049 if (!$edit_label_id || $subop != "edit") {
1050
1051 if (!$line["description"]) $line["description"] = "[No caption]";
1052
1053 print "<td><input onclick='toggleSelectRow(this);'
1054 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1055
1056 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1057 $line["sql_exp"] . "</td>";
1058
1059 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1060 $line["description"] . "</td>";
1061
1062 } else if ($label_id != $edit_label_id) {
1063
1064 if (!$line["description"]) $line["description"] = "[No description]";
1065
1066 print "<td><input disabled=\"true\" type=\"checkbox\"
1067 id=\"LICHK-".$line["id"]."\"></td>";
1068
1069 print "<td>".$line["sql_exp"]."</td>";
1070 print "<td>".$line["description"]."</td>";
1071
1072 } else {
1073
1074 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1075
1076 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1077 "\"></td>";
1078
1079 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1080 "\"></td>";
1081
1082 }
1083
1084
1085 print "</tr>";
1086
1087 ++$lnum;
1088 }
1089
1090 if ($lnum == 0) {
1091 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1092 }
1093
1094 print "</table>";
1095
1096 print "<p>";
1097
1098 if ($subop == "edit") {
1099 print "Edit label:
1100 <input type=\"submit\" class=\"button\"
1101 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1102 <input type=\"submit\" class=\"button\"
1103 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1104
1105 } else {
1106
1107 print "
1108 Selection:
1109 <input type=\"submit\" class=\"button\"
1110 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1111 <input type=\"submit\" class=\"button\"
1112 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1113 }
1114 }
1115
1116 if ($op == "error") {
1117 print "<div width=\"100%\" align='center'>";
1118 $msg = $_GET["msg"];
1119 print $msg;
1120 print "</div>";
1121 }
1122
1123 db_close($link);
1124 ?>