]> git.wh0rd.org - tt-rss.git/blob - backend.php
updated NEWS
[tt-rss.git] / backend.php
1 <?
2 // header("Content-Type: application/xml");
3
4 require_once "config.php";
5 require_once "functions.php";
6 require_once "magpierss/rss_fetch.inc";
7
8 error_reporting(0);
9
10 $link = pg_connect(DB_CONN);
11
12 error_reporting (E_ERROR | E_WARNING | E_PARSE);
13
14 if (!$link) {
15 print "Could not connect to database. Please check local configuration.";
16 return;
17 }
18
19 pg_query("set client_encoding = 'utf-8'");
20
21 $op = $_GET["op"];
22 $fetch = $_GET["fetch"];
23
24 function outputFeedList($link) {
25
26 print "<html><head>
27 <title>Tiny Tiny RSS : Feedlist</title>
28 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
29 <script type=\"text/javascript\" src=\"functions.js\"></script>
30 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
31 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
32 </head><body>";
33
34 $result = pg_query($link, "SELECT *,
35 (SELECT count(id) FROM ttrss_entries
36 WHERE feed_id = ttrss_feeds.id) AS total,
37 (SELECT count(id) FROM ttrss_entries
38 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
39 FROM ttrss_feeds ORDER BY title");
40
41 $actid = $_GET["actid"];
42
43 print "<table width=\"100%\" class=\"feedsList\" id=\"feedsList\">";
44
45 $lnum = 0;
46
47 $total_unread = 0;
48
49 while ($line = pg_fetch_assoc($result)) {
50
51 $feed = $line["title"];
52 $feed_id = $line["id"];
53
54 $subop = $_GET["subop"];
55
56 $total = $line["total"];
57 $unread = $line["unread"];
58
59 $class = ($lnum % 2) ? "even" : "odd";
60
61 if ($unread > 0) $class .= "Unread";
62
63 if ($actid == $feed_id) {
64 $class .= "Selected";
65 }
66
67 $total_unread += $unread;
68
69 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
70
71 $icon_file = ICONS_DIR . "/$feed_id.ico";
72
73 if ($subop != "piggie") {
74
75 if (file_exists($icon_file) && filesize($icon_file) > 0) {
76 $feed_icon = "<img width=\"16\" height=\"16\"
77 src=\"" . ICONS_URL . "/$feed_id.ico\">";
78 } else {
79 $feed_icon = "&nbsp;";
80 }
81 } else {
82 $feed_icon = "<img width=\"16\" height=\"16\"
83 src=\"http://madoka.spb.ru/stuff/fox/tiny_piggie.png\">";
84 }
85
86 $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>";
87 if (ENABLE_FEED_ICONS) {
88 print "<td>$feed_icon</td>";
89 }
90 print "<td id=\"FEEDN-$feed_id\">$feed</td>";
91 print "<td>";
92 print "<span id=\"FEEDU-$feed_id\">$unread</span>&nbsp;/&nbsp;";
93 print "<span id=\"FEEDT-$feed_id\">$total</span>";
94 print "</td>";
95
96 print "</tr>";
97 ++$lnum;
98 }
99
100 // print "<tr><td class=\"footer\" colspan=\"3\">
101 // <a href=\"javascript:update_feed_list(false,true)\">Update all feeds</a></td></tr>";
102
103 // print "<tr><td class=\"footer\" colspan=\"2\">&nbsp;";
104 // print "</td></tr>";
105
106 print "</table>";
107
108 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
109 print "<div class=\"invisible\" id=\"ACTFEEDID\">$actid</div>";
110
111 /*
112 print "<p align=\"center\">All feeds:
113 <a class=\"button\"
114 href=\"javascript:scheduleFeedUpdate(true)\">Update</a>";
115
116 print "&nbsp;<a class=\"button\"
117 href=\"javascript:catchupAllFeeds()\">Mark as read</a></p>";
118
119 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
120 */
121
122
123
124 }
125
126
127 if ($op == "rpc") {
128
129 $subop = $_GET["subop"];
130
131 if ($subop == "mark") {
132 $mark = $_GET["mark"];
133 $id = pg_escape_string($_GET["id"]);
134
135 if ($mark == "1") {
136 $mark = "true";
137 } else {
138 $mark = "false";
139 }
140
141 $result = pg_query("UPDATE ttrss_entries SET marked = $mark
142 WHERE id = '$id'");
143 }
144
145 if ($subop == "updateFeed") {
146 $feed_id = pg_escape_string($_GET["feed"]);
147
148 $result = pg_query($link,
149 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
150
151 if (pg_num_rows($result) > 0) {
152 $feed_url = pg_fetch_result($result, 0, "feed_url");
153 // update_rss_feed($link, $feed_url, $feed_id);
154 }
155
156 print "DONE-$feed_id";
157
158 return;
159 }
160
161 if ($subop == "forceUpdateAllFeeds") {
162 update_all_feeds($link, true);
163 }
164
165 if ($subop == "updateAllFeeds") {
166 update_all_feeds($link, false);
167 }
168
169 if ($subop == "catchupPage") {
170
171 $ids = split(",", $_GET["ids"]);
172
173 foreach ($ids as $id) {
174
175 pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW()
176 WHERE id = '$id'");
177
178 }
179
180 print "Marked active page as read.";
181 }
182
183 }
184
185 if ($op == "feeds") {
186
187 $subop = $_GET["subop"];
188
189 if ($subop == "catchupAll") {
190 pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false");
191 }
192
193 outputFeedList($link);
194
195 }
196
197 if ($op == "view") {
198
199 $id = $_GET["id"];
200
201 $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
202
203 $addheader = $_GET["addheader"];
204
205 $result = pg_query("SELECT title,link,content,feed_id,comments,
206 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
207 FROM ttrss_entries
208 WHERE id = '$id'");
209
210 if ($addheader) {
211 print "<html><head>
212 <title>Tiny Tiny RSS : Article $id</title>
213 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
214 <script type=\"text/javascript\" src=\"functions.js\"></script>
215 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
216 </head><body>";
217 }
218
219 if ($result) {
220
221 $line = pg_fetch_assoc($result);
222
223 if ($line["icon_url"]) {
224 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
225 } else {
226 $feed_icon = "&nbsp;";
227 }
228
229 print "<table class=\"postTable\" width=\"100%\" cellspacing=\"0\"
230 cellpadding=\"0\">";
231
232 print "<tr class=\"titleTop\"><td align=\"right\"><b>Title:</b></td>
233 <td width=\"100%\">".$line["title"]."</td>
234 <td>&nbsp;</td></tr>";
235
236 if ($line["comments"] && $line["comments"] != $line["link"]) {
237 $comments_prompt = "(<a href=\"".$line["comments"]."\">Comments</a>)";
238 }
239
240 print "<tr class=\"titleBottom\"><td align=\"right\"><b>Link:</b></td>
241 <td><a href=\"".$line["link"]."\">".$line["link"]."</a> $comments_prompt</td>
242 <td>&nbsp;</td></tr>";
243 print "<tr><td valign=\"top\" class=\"post\"
244 colspan=\"2\" width=\"100%\">" . $line["content"] . "</td>
245 <td valign=\"top\">$feed_icon</td>
246 </tr>";
247 print "</table>";
248
249 }
250
251 if ($addheader) {
252 print "</body></html>";
253 }
254 }
255
256 if ($op == "viewfeed") {
257
258 $feed = $_GET["feed"];
259 $skip = $_GET["skip"];
260 $subop = $_GET["subop"];
261 $view_mode = $_GET["view"];
262 $addheader = $_GET["addheader"];
263 $limit = $_GET["limit"];
264
265 if (!$skip) $skip = 0;
266
267 if ($subop == "undefined") $subop = "";
268
269 if ($addheader) {
270 print "<html><head>
271 <title>Tiny Tiny RSS : Feed $feed</title>
272 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
273 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
274 <script type=\"text/javascript\" src=\"functions.js\"></script>
275 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
276 </head><body>";
277 }
278
279 // FIXME: check for null value here
280
281 $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s,
282 EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout
283 FROM ttrss_feeds WHERE id = '$feed'");
284
285 if ($result) {
286
287 $line = pg_fetch_assoc($result);
288
289 if ($subop == "ForceUpdate" ||
290 $line["last_updated"] == "" ||
291 $line["update_timeout"] > MIN_UPDATE_TIME) {
292
293 update_rss_feed($link, $line["feed_url"], $feed);
294
295 } else {
296
297 if ($subop == "MarkAllRead") {
298
299 pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW()
300 WHERE feed_id = '$feed'");
301 }
302 }
303 }
304
305 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
306
307 $feed_last_updated = "Updated: " . $line["last_updated"];
308
309 $search = $_GET["search"];
310
311 if ($search) {
312 $search_query_part = "(upper(title) LIKE upper('%$search%')
313 OR content LIKE '%$search%') AND";
314 } else {
315 $search_query_part = "";
316 }
317
318 $view_query_part = "";
319
320 if ($view_mode == "Starred") {
321 $view_query_part = " marked = true AND ";
322 }
323
324 if ($view_mode == "Unread") {
325 $view_query_part = " unread = true AND ";
326 }
327
328 $result = pg_query("SELECT count(id) AS total_entries
329 FROM ttrss_entries WHERE
330 $search_query_part
331 feed_id = '$feed'");
332
333 $total_entries = pg_fetch_result($result, 0, "total_entries");
334
335 /* $result = pg_query("SELECT count(id) AS unread_entries
336 FROM ttrss_entries WHERE
337 $search_query_part
338 unread = true AND
339 feed_id = '$feed'");
340
341 $unread_entries = pg_fetch_result($result, 0, "unread_entries"); */
342
343 /* if ($limit < $unread_entries)
344 $limit = $unread_entries;
345
346 if ($limit != "All") {
347 $limit_query_part = "LIMIT " . $limit;
348 } */
349
350 $result = pg_query("SELECT
351 id,title,updated,unread,feed_id,marked,link,
352 EXTRACT(EPOCH FROM last_read) AS last_read_ts,
353 EXTRACT(EPOCH FROM updated) AS updated_ts
354 FROM
355 ttrss_entries
356 WHERE
357 $search_query_part
358 $view_query_part
359 feed_id = '$feed' ORDER BY updated DESC
360 $limit_query_part");
361
362 $lnum = 0;
363
364 $num_unread = 0;
365
366 while ($line = pg_fetch_assoc($result)) {
367
368 $class = ($lnum % 2) ? "even" : "odd";
369
370 if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") {
371 $update_pic = "<img src=\"images/updated.png\" alt=\"Updated\">";
372 ++$num_unread;
373 } else {
374 $update_pic = "&nbsp;";
375 }
376
377 if ($line["unread"] == "t") {
378 $class .= "Unread";
379 ++$num_unread;
380 }
381
382 $id = $line["id"];
383 $feed_id = $line["feed_id"];
384
385 if ($line["marked"] == "t") {
386 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
387 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
388 } else {
389 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
390 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
391 }
392
393 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
394 $line["title"] . "</a>";
395
396 print "<tr class='$class' id='RROW-$id'";
397 // onclick=\"javascript:view($id,$feed_id)\">
398
399 print "<td id='FUPDPIC-$id' valign='center'
400 class='headlineUpdateMark'>$update_pic</td>";
401
402 print "<td valign='center'
403 class='headlineUpdateMark'>$marked_pic</td>";
404
405 print "<td class='headlineUpdated'>
406 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
407 print "<td class='headlineTitle'>$content_link</td>";
408
409 print "</tr>";
410
411 ++$lnum;
412 }
413
414 if ($lnum == 0) {
415 print "<tr><td align='center'>No entries found.</td></tr>";
416 }
417
418 while ($lnum < HEADLINES_PER_PAGE) {
419 ++$lnum;
420 print "<tr><td>&nbsp;</td></tr>";
421 }
422
423 print "</table>";
424
425 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
426 WHERE feed_id = ttrss_feeds.id) AS total,
427 (SELECT count(id) FROM ttrss_entries
428 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
429 FROM ttrss_feeds WHERE id = '$feed'");
430
431 $total = pg_fetch_result($result, 0, "total");
432 $unread = pg_fetch_result($result, 0, "unread");
433
434 // update unread/total counters and status for active feed in the feedlist
435 // kludge, because iframe doesn't seem to support onload()
436
437 print "<script type=\"text/javascript\">
438 document.onkeydown = hotkey_handler;
439
440 var p_document = parent.frames['feeds-frame'].document;
441
442 var feedr = p_document.getElementById(\"FEEDR-\" + $feed);
443 var feedt = p_document.getElementById(\"FEEDT-\" + $feed);
444 var feedu = p_document.getElementById(\"FEEDU-\" + $feed);
445
446 feedt.innerHTML = \"$total\";
447 feedu.innerHTML = \"$unread\";
448
449 if ($unread > 0 && !feedr.className.match(\"Unread\")) {
450 feedr.className = feedr.className + \"Unread\";
451 } else if ($unread <= 0) {
452 feedr.className = feedr.className.replace(\"Unread\", \"\");
453 }
454
455 //p_notify('');
456 </script>";
457
458 if ($addheader) {
459 print "</body></html>";
460 }
461
462 }
463
464 if ($op == "pref-rpc") {
465
466 $subop = $_GET["subop"];
467
468 if ($subop == "unread") {
469 $ids = split(",", $_GET["ids"]);
470 foreach ($ids as $id) {
471 pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
472 }
473
474 print "Marked selected feeds as read.";
475 }
476
477 if ($subop == "read") {
478 $ids = split(",", $_GET["ids"]);
479 foreach ($ids as $id) {
480 pg_query("UPDATE ttrss_entries
481 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
482 }
483
484 print "Marked selected feeds as unread.";
485
486 }
487
488 }
489
490 if ($op == "pref-feeds") {
491
492 $subop = $_GET["subop"];
493
494 if ($subop == "editSave") {
495 $feed_title = pg_escape_string($_GET["t"]);
496 $feed_link = pg_escape_string($_GET["l"]);
497 $feed_id = $_GET["id"];
498
499 $result = pg_query("UPDATE ttrss_feeds SET
500 title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'");
501
502 }
503
504 if ($subop == "remove") {
505
506 if (!WEB_DEMO_MODE) {
507
508 $ids = split(",", $_GET["ids"]);
509
510 foreach ($ids as $id) {
511 pg_query("BEGIN");
512 pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'");
513 pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'");
514 pg_query("COMMIT");
515
516 if (file_exists(ICONS_DIR . "/$id.ico")) {
517 unlink(ICONS_DIR . "/$id.ico");
518 }
519 }
520 }
521 }
522
523 if ($subop == "add") {
524
525 if (!WEB_DEMO_MODE) {
526
527 $feed_link = pg_escape_string($_GET["link"]);
528
529 $result = pg_query(
530 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
531
532 $result = pg_query(
533 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
534
535 $feed_id = pg_fetch_result($result, 0, "id");
536
537 if ($feed_id) {
538 update_rss_feed($link, $feed_link, $feed_id);
539 }
540 }
541 }
542
543 print "<table class=\"prefAddFeed\"><tr>
544 <td><input id=\"fadd_link\"></td>
545 <td colspan=\"4\" align=\"right\">
546 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
547 </table>";
548
549 $result = pg_query("SELECT
550 id,title,feed_url,substring(last_updated,1,16) as last_updated
551 FROM
552 ttrss_feeds ORDER by title");
553
554 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
555 print "<tr class=\"title\">
556 <td>&nbsp;</td><td>Select</td><td width=\"40%\">Title</td>
557 <td width=\"40%\">Link</td><td>Last updated</td></tr>";
558
559 $lnum = 0;
560
561 while ($line = pg_fetch_assoc($result)) {
562
563 $class = ($lnum % 2) ? "even" : "odd";
564
565 $feed_id = $line["id"];
566
567 $edit_feed_id = $_GET["id"];
568
569 if ($subop == "edit" && $feed_id != $edit_feed_id) {
570 $class .= "Grayed";
571 }
572
573 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
574
575 $icon_file = ICONS_DIR . "/$feed_id.ico";
576
577 if (file_exists($icon_file) && filesize($icon_file) > 0) {
578 $feed_icon = "<img width=\"16\" height=\"16\"
579 src=\"" . ICONS_URL . "/$feed_id.ico\">";
580 } else {
581 $feed_icon = "&nbsp;";
582 }
583 print "<td align='center'>$feed_icon</td>";
584
585 if (!$edit_feed_id || $subop != "edit") {
586
587 print "<td><input onclick='toggleSelectRow(this);'
588 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
589
590 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
591 $line["title"] . "</td>";
592 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
593 $line["feed_url"] . "</td>";
594
595
596 } else if ($feed_id != $edit_feed_id) {
597
598 print "<td><input disabled=\"true\" type=\"checkbox\"
599 id=\"FRCHK-".$line["id"]."\"></td>";
600
601 print "<td>".$line["title"]."</td>";
602 print "<td>".$line["feed_url"]."</td>";
603
604 } else {
605
606 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
607
608 print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>";
609 print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>";
610
611 }
612
613 if (!$line["last_updated"]) $line["last_updated"] = "Never";
614
615 print "<td>" . $line["last_updated"] . "</td>";
616
617 print "</tr>";
618
619 ++$lnum;
620 }
621
622 if ($lnum == 0) {
623 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
624 }
625
626 print "</table>";
627
628 print "<p>";
629
630 if ($subop == "edit") {
631 print "Edit feed:&nbsp;
632 <a class=\"button\" href=\"javascript:feedEditCancel()\">Cancel</a>&nbsp;
633 <a class=\"button\" href=\"javascript:feedEditSave()\">Save</a>";
634 } else {
635
636 print "
637 Selection:&nbsp;
638 <a class=\"button\"
639 href=\"javascript:editSelectedFeed()\">Edit</a>&nbsp;
640 <a class=\"buttonWarn\"
641 href=\"javascript:removeSelectedFeeds()\">Remove</a>&nbsp;";
642 if (ENABLE_PREFS_CATCHUP_UNCATCHUP) {
643 print "
644 <a class=\"button\"
645 href=\"javascript:readSelectedFeeds()\">Mark as read</a>&nbsp;
646 <a class=\"button\"
647 href=\"javascript:unreadSelectedFeeds()\">Mark as unread</a>&nbsp;";
648 }
649 print "
650 All feeds:&nbsp;
651 <a class=\"button\" href=\"opml.php?op=Export\">Export OPML</a>";
652
653 }
654
655 }
656
657 if ($op == "pref-filters") {
658
659 $subop = $_GET["subop"];
660
661 if ($subop == "editSave") {
662
663 $regexp = pg_escape_string($_GET["r"]);
664 $descr = pg_escape_string($_GET["d"]);
665 $match = pg_escape_string($_GET["m"]);
666 $filter_id = pg_escape_string($_GET["id"]);
667
668 $result = pg_query("UPDATE ttrss_filters SET
669 regexp = '$regexp',
670 description = '$descr',
671 filter_type = (SELECT id FROM ttrss_filter_types WHERE
672 description = '$match')
673 WHERE id = '$filter_id'");
674 }
675
676 if ($subop == "remove") {
677
678 if (!WEB_DEMO_MODE) {
679
680 $ids = split(",", $_GET["ids"]);
681
682 foreach ($ids as $id) {
683 pg_query("DELETE FROM ttrss_filters WHERE id = '$id'");
684
685 }
686 }
687 }
688
689 if ($subop == "add") {
690
691 if (!WEB_DEMO_MODE) {
692
693 $regexp = pg_escape_string($_GET["regexp"]);
694 $match = pg_escape_string($_GET["match"]);
695
696 $result = pg_query(
697 "INSERT INTO ttrss_filters (regexp,filter_type) VALUES
698 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
699 description = '$match'))");
700 }
701 }
702
703 $result = pg_query("SELECT description
704 FROM ttrss_filter_types ORDER BY description");
705
706 $filter_types = array();
707
708 while ($line = pg_fetch_assoc($result)) {
709 array_push($filter_types, $line["description"]);
710 }
711
712 print "<table class=\"prefAddFeed\"><tr>
713 <td><input id=\"fadd_regexp\"></td>
714 <td>";
715 print_select("fadd_match", "Title", $filter_types);
716
717 print"</td><td colspan=\"4\" align=\"right\">
718 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
719 </table>";
720
721 $result = pg_query("SELECT
722 id,regexp,description,
723 (SELECT name FROM ttrss_filter_types WHERE
724 id = filter_type) as filter_type_name,
725 (SELECT description FROM ttrss_filter_types
726 WHERE id = filter_type) as filter_type_descr
727 FROM
728 ttrss_filters ORDER by regexp");
729
730 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
731
732 print "<tr class=\"title\">
733 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
734 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
735
736 $lnum = 0;
737
738 while ($line = pg_fetch_assoc($result)) {
739
740 $class = ($lnum % 2) ? "even" : "odd";
741
742 $filter_id = $line["id"];
743 $edit_filter_id = $_GET["id"];
744
745 if ($subop == "edit" && $filter_id != $edit_filter_id) {
746 $class .= "Grayed";
747 }
748
749 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
750
751 $line["regexp"] = htmlspecialchars($line["regexp"]);
752 $line["description"] = htmlspecialchars($line["description"]);
753
754 if (!$edit_filter_id || $subop != "edit") {
755
756 if (!$line["description"]) $line["description"] = "[No description]";
757
758 print "<td><input onclick='toggleSelectRow(this);'
759 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
760
761 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
762 $line["regexp"] . "</td>";
763
764 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
765 $line["description"] . "</td>";
766
767 print "<td>".$line["filter_type_descr"]."</td>";
768
769 } else if ($filter_id != $edit_filter_id) {
770
771 if (!$line["description"]) $line["description"] = "[No description]";
772
773 print "<td><input disabled=\"true\" type=\"checkbox\"
774 id=\"FICHK-".$line["id"]."\"></td>";
775
776 print "<td>".$line["regexp"]."</td>";
777 print "<td>".$line["description"]."</td>";
778 print "<td>".$line["filter_type_descr"]."</td>";
779
780 } else {
781
782 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
783
784 print "<td><input id=\"iedit_regexp\" value=\"".$line["regexp"].
785 "\"></td>";
786
787 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
788 "\"></td>";
789
790 print "<td>";
791 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
792 print "</td>";
793
794 }
795
796
797 print "</tr>";
798
799 ++$lnum;
800 }
801
802 if ($lnum == 0) {
803 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
804 }
805
806 print "</table>";
807
808 print "<p>";
809
810 if ($subop == "edit") {
811 print "Edit feed:&nbsp;
812 <a class=\"button\" href=\"javascript:filterEditCancel()\">Cancel</a>&nbsp;
813 <a class=\"button\" href=\"javascript:filterEditSave()\">Save</a>";
814
815 } else {
816
817 print "
818 Selection:&nbsp;
819 <a class=\"button\"
820 href=\"javascript:editSelectedFilter()\">Edit</a>&nbsp;
821 <a class=\"buttonWarn\"
822 href=\"javascript:removeSelectedFilters()\">Remove</a>&nbsp;";
823 }
824 }
825
826 pg_close($link);
827 ?>