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