]> git.wh0rd.org Git - tt-rss.git/blob - backend.php
viewfeed() call in multifeed display
[tt-rss.git] / backend.php
1 <?
2         define(SCHEMA_VERSION, 1);
3
4         $op = $_GET["op"];
5
6         if ($op == "rpc") {
7                 header("Content-Type: application/xml");
8         }
9
10         require_once "config.php";
11         require_once "db.php";
12         require_once "functions.php";
13         require_once "magpierss/rss_fetch.inc";
14
15         $script_started = getmicrotime();
16
17         $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
18
19         if (!$link) {
20                 if (DB_TYPE == "mysql") {
21                         print mysql_error();
22                 }
23                 // PG seems to display its own errors just fine by default.             
24                 return;
25         }
26
27         if (DB_TYPE == "pgsql") {
28                 pg_query("set client_encoding = 'utf-8'");
29         }
30
31         $result = db_query($link, "SELECT schema_version FROM ttrss_version");
32
33         $schema_version = db_fetch_result($result, 0, "schema_version");
34
35         if ($schema_version != SCHEMA_VERSION) {
36                 print "Error: database schema is invalid
37                         (got version $schema_version; expected ".SCHEMA_VERSION.")";
38                 return;
39         }
40         
41         $fetch = $_GET["fetch"];
42
43         /* FIXME this needs reworking */
44
45         function getGlobalCounters($link) {
46                 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
47                         WHERE unread = true");
48                 $c_id = db_fetch_result($result, 0, "c_id");
49                 print "<counter id='global-unread' counter='$c_id'/>";
50         }
51
52         function getTagCounters($link) {
53                 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
54                         FROM ttrss_tags,ttrss_entries WHERE
55                         post_id = ttrss_entries.id AND unread = true GROUP BY tag_name 
56                 UNION
57                         select tag_name,0 as count FROM ttrss_tags");
58
59                 $tags = array();
60
61                 while ($line = db_fetch_assoc($result)) {
62                         $tags[$line["tag_name"]] += $line["count"];
63                 }
64
65                 foreach (array_keys($tags) as $tag) {
66                         $unread = $tags[$tag];                  
67
68                         $tag = htmlspecialchars($tag);
69                         print "<tag id=\"$tag\" counter=\"$unread\"/>";
70                 } 
71         }
72
73         function getLabelCounters($link) {
74
75                 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
76                         WHERE marked = true AND unread = true");
77
78                 $count = db_fetch_result($result, 0, "count");
79
80                 print "<label id=\"-1\" counter=\"$count\"/>";
81
82                 $result = db_query($link, "SELECT id,sql_exp,description FROM
83                         ttrss_labels ORDER by description");
84         
85                 while ($line = db_fetch_assoc($result)) {
86
87                         $id = -$line["id"] - 11;
88
89                         error_reporting (0);
90
91                         $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
92                                 WHERE (" . $line["sql_exp"] . ") AND unread = true");
93
94                         $count = db_fetch_result($tmp_result, 0, "count");
95
96                         print "<label id=\"$id\" counter=\"$count\"/>";
97
98                         error_reporting (E_ERROR | E_WARNING | E_PARSE);
99         
100                 }
101         }
102
103         function getFeedCounter($link, $id) {
104         
105                 $result = db_query($link, "SELECT 
106                                 count(id) as count FROM ttrss_entries
107                         WHERE feed_id = '$id'   AND unread = true");
108         
109                         $count = db_fetch_result($result, 0, "count");
110                         
111                         print "<feed id=\"$id\" counter=\"$count\"/>";          
112         }
113
114         function getFeedCounters($link) {
115         
116                 $result = db_query($link, "SELECT id,
117                         (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id 
118                                 AND unread = true) as count
119                         FROM ttrss_feeds");
120         
121                 while ($line = db_fetch_assoc($result)) {
122                 
123                         $id = $line["id"];
124                         $count = $line["count"];
125
126                         print "<feed id=\"$id\" counter=\"$count\"/>";
127                 }
128         }
129
130         function outputFeedList($link, $tags = false) {
131
132                 print "<html><head>
133                         <title>Tiny Tiny RSS : Feedlist</title>
134                         <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
135                         <script type=\"text/javascript\" src=\"functions.js\"></script>
136                         <script type=\"text/javascript\" src=\"feedlist.js\"></script>
137                         <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
138                         </head><body onload=\"init()\">";
139
140                 print "<ul class=\"feedList\" id=\"feedList\">";
141
142                 if (!$tags) {
143
144                         /* virtual feeds */
145
146                         $result = db_query($link, "SELECT count(id) as num_starred 
147                                 FROM ttrss_entries WHERE marked = true AND unread = true");
148                         $num_starred = db_fetch_result($result, 0, "num_starred");
149
150                         $class = "virt";
151
152                         if ($num_starred > 0) $class .= "Unread";
153
154                         printFeedEntry(-1, $class, "Starred articles", $num_starred, 
155                                 "images/mark_set.png");
156
157                         if (ENABLE_LABELS) {
158         
159                                 $result = db_query($link, "SELECT id,sql_exp,description FROM
160                                         ttrss_labels ORDER by description");
161                 
162                                 if (db_num_rows($result) > 0) {
163                                         print "<li><hr></li>";
164                                 }
165                 
166                                 while ($line = db_fetch_assoc($result)) {
167         
168                                         error_reporting (0);
169                 
170                                         $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
171                                                 WHERE (" . $line["sql_exp"] . ") AND unread = true");
172         
173                                         $count = db_fetch_result($tmp_result, 0, "count");
174         
175                                         $class = "label";
176         
177                                         if ($count > 0) {
178                                                 $class .= "Unread";
179                                         }
180                                         
181                                         error_reporting (E_ERROR | E_WARNING | E_PARSE);
182         
183                                         printFeedEntry(-$line["id"]-11, 
184                                                 $class, $line["description"], $count, "images/label.png");
185                 
186                                 }
187                         }
188         
189                         print "<li><hr></li>";
190
191                         $result = db_query($link, "SELECT *,
192                                 (SELECT count(id) FROM ttrss_entries 
193                                         WHERE feed_id = ttrss_feeds.id) AS total,
194                                 (SELECT count(id) FROM ttrss_entries
195                                         WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
196                                 FROM ttrss_feeds ORDER BY title");                      
197         
198                         $actid = $_GET["actid"];
199         
200                         /* real feeds */
201         
202                         $lnum = 0;
203         
204                         $total_unread = 0;
205         
206                         while ($line = db_fetch_assoc($result)) {
207                         
208                                 $feed = $line["title"];
209                                 $feed_id = $line["id"];   
210         
211                                 $subop = $_GET["subop"];
212                                 
213                                 $total = $line["total"];
214                                 $unread = $line["unread"];
215                                 
216         //                      $class = ($lnum % 2) ? "even" : "odd";
217         
218                                 $class = "feed";
219         
220                                 if ($unread > 0) $class .= "Unread";
221         
222                                 if ($actid == $feed_id) {
223                                         $class .= "Selected";
224                                 }
225         
226                                 $total_unread += $unread;
227         
228                                 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
229         
230                                 ++$lnum;
231                         }
232                 } else {
233
234                         // tags
235
236                         $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
237                                 FROM ttrss_tags,ttrss_entries WHERE
238                                 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name 
239                         UNION
240                                 select tag_name,0 as count FROM ttrss_tags");
241         
242                         $tags = array();
243         
244                         while ($line = db_fetch_assoc($result)) {
245                                 $tags[$line["tag_name"]] += $line["count"];
246                         }
247         
248                         foreach (array_keys($tags) as $tag) {
249         
250                                 $unread = $tags[$tag];
251         
252                                 $class = "odd";
253         
254                                 if ($unread > 0) {
255                                         $class .= "Unread";
256                                 }
257         
258                                 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
259         
260                         } 
261
262                 }
263
264                 if (db_num_rows($result) == 0) {
265                         print "<li>No tags to display.</li>";
266                 }
267
268                 print "</ul>";
269
270                 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
271
272         }
273
274
275         if ($op == "rpc") {
276
277                 $subop = $_GET["subop"];
278
279                 if ($subop == "getLabelCounters") {
280                         $aid = $_GET["aid"];            
281                         print "<rpc-reply>";
282                         getLabelCounters($link);
283                         if ($aid) {
284                                 getFeedCounter($link, $aid);
285                         }
286                         print "</rpc-reply>";
287                 }
288
289                 if ($subop == "getFeedCounters") {
290                         print "<rpc-reply>";
291                         getFeedCounters($link);
292                         print "</rpc-reply>";
293                 }
294
295                 if ($subop == "getAllCounters") {
296                         print "<rpc-reply>";
297                         getLabelCounters($link);
298                         getFeedCounters($link);
299                         getTagCounters($link);
300                         getGlobalCounters($link);
301                         print "</rpc-reply>";
302                 }
303
304                 if ($subop == "mark") {
305                         $mark = $_GET["mark"];
306                         $id = db_escape_string($_GET["id"]);
307
308                         if ($mark == "1") {
309                                 $mark = "true";
310                         } else {
311                                 $mark = "false";
312                         }
313
314                         $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
315                                 WHERE id = '$id'");
316                 }
317
318                 if ($subop == "updateFeed") {
319                         $feed_id = db_escape_string($_GET["feed"]);
320
321                         $result = db_query($link, 
322                                 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
323
324                         if (db_num_rows($result) > 0) {                 
325                                 $feed_url = db_fetch_result($result, 0, "feed_url");
326 //                              update_rss_feed($link, $feed_url, $feed_id);
327                         }
328
329                         print "DONE-$feed_id";
330
331                         return;
332                 }
333
334                 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
335                 
336                         update_all_feeds($link, true);                  
337
338                         $omode = $_GET["omode"];
339
340                         if (!$omode) $omode = "tfl";
341
342                         print "<rpc-reply>";
343                         if (strchr($omode, "l")) getLabelCounters($link);
344                         if (strchr($omode, "f")) getFeedCounters($link);
345                         if (strchr($omode, "t")) getTagCounters($link);
346                         getGlobalCounters($link);
347                         print "</rpc-reply>";
348                 }
349                 
350                 if ($subop == "catchupPage") {
351
352                         $ids = split(",", $_GET["ids"]);
353
354                         foreach ($ids as $id) {
355
356                                 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
357                                         WHERE id = '$id'");
358
359                         }
360
361                         print "Marked active page as read.";
362                 }
363         }
364         
365         if ($op == "feeds") {
366
367                 $tags = $_GET["tags"];
368
369                 $subop = $_GET["subop"];
370
371                 if ($subop == "catchupAll") {
372                         db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
373                 }
374
375                 outputFeedList($link, $tags);
376
377         }
378
379         if ($op == "view") {
380
381                 $id = $_GET["id"];
382                 $feed_id = $_GET["feed"];
383
384                 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
385
386                 $addheader = $_GET["addheader"];
387
388                 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
389                         (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url 
390                         FROM ttrss_entries
391                         WHERE   id = '$id'");
392
393                 if ($addheader) {
394                         print "<html><head>
395                                 <title>Tiny Tiny RSS : Article $id</title>
396                                 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
397                                 <script type=\"text/javascript\" src=\"functions.js\"></script>
398                                 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
399                                 </head><body>";
400                 }
401
402                 if ($result) {
403
404                         $line = db_fetch_assoc($result);
405
406                         if ($line["icon_url"]) {
407                                 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
408                         } else {
409                                 $feed_icon = "&nbsp;";
410                         }
411
412                         if ($line["comments"] && $line["link"] != $line["comments"]) {
413                                 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
414                         } else {
415                                 $entry_comments = "";
416                         }
417
418                         print "<div class=\"postReply\">";
419
420                         print "<div class=\"postHeader\"><table>";
421
422                         print "<tr><td><b>Title:</b></td>
423                                 <td width='100%'>" . $line["title"] . "</td></tr>";
424                                 
425                         print "<tr><td><b>Link:</b></td>
426                                 <td width='100%'>
427                                 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
428                                 $entry_comments</td></tr>";
429                                         
430                         print "</table></div>";
431
432                         print "<div class=\"postIcon\">" . $feed_icon . "</div>";
433                         print "<div class=\"postContent\">" . $line["content"] . "</div>";
434                         
435                         print "</div>";
436
437                         print "<script type=\"text/javascript\">
438                                 update_label_counters('$feed_id');
439                         </script>";
440                 }
441
442                 if ($addheader) {
443                         print "</body></html>";
444                 }
445         }
446
447         if ($op == "viewfeed") {
448
449                 $feed = $_GET["feed"];
450                 $skip = $_GET["skip"];
451                 $subop = $_GET["subop"];
452                 $view_mode = $_GET["view"];
453                 $addheader = $_GET["addheader"];
454                 $limit = $_GET["limit"];
455
456                 if (!$feed) {
457                         print "Error: no feed to display.";
458                         return;
459                 }
460
461                 if (!$skip) $skip = 0;
462
463                 if ($subop == "undefined") $subop = "";
464
465                 if ($addheader) {
466                         print "<html><head>
467                                 <title>Tiny Tiny RSS : Feed $feed</title>
468                                 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
469                                 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
470                                 <script type=\"text/javascript\" src=\"functions.js\"></script>
471                                 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
472                                 </head><body>";
473                 }
474
475                 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
476
477                         $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
478                                 WHERE id = '$feed'");
479
480                         $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
481
482                         update_rss_feed($link, $feed_url, $feed);
483
484                 }
485
486                 if ($subop == "MarkAllRead")  {
487
488                         if (sprintf("%d", $feed) != 0) {
489                         
490                                 if ($feed > 0) {
491                                         db_query($link, "UPDATE ttrss_entries 
492                                                 SET unread = false,last_read = NOW() 
493                                                 WHERE feed_id = '$feed'");
494                                                 
495                                 } else if ($feed < 0 && $feed > -10) { // special, like starred
496
497                                         if ($feed == -1) {
498                                                 db_query($link, "UPDATE ttrss_entries 
499                                                         SET unread = false,last_read = NOW()
500                                                         WHERE marked = true");
501                                         }
502                         
503                                 } else if ($feed < -10) { // label
504
505                                         $label_id = -$feed - 11;
506
507                                         $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
508                                                 WHERE id = '$label_id'");
509
510                                         if ($tmp_result) {
511                                                 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
512
513                                                 db_query($link, "UPDATE ttrss_entries 
514                                                         SET unread = false,last_read = NOW()
515                                                         WHERE $sql_exp");
516                                         }
517                                 }
518                         } else { // tag
519                                 // FIXME, implement catchup for tags
520                         }
521
522                 }
523
524                 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
525
526                 $search = $_GET["search"];
527
528                 $search_mode = $_GET["smode"];
529
530                 if ($search) {
531                         $search_query_part = "(upper(title) LIKE upper('%$search%') 
532                                 OR content LIKE '%$search%') AND";
533                 } else {
534                         $search_query_part = "";
535                 }
536
537                 $view_query_part = "";
538
539                 if ($view_mode == "Starred") {
540                         $view_query_part = " marked = true AND ";
541                 }
542
543                 if ($view_mode == "Unread") {
544                         $view_query_part = " unread = true AND ";
545                 }
546
547                 if ($view_mode == "Unread or Starred") {
548                         $view_query_part = " (unread = true OR marked = true) AND ";
549                 }
550
551                 if ($view_mode == "Unread or Updated") {
552                         $view_query_part = " (unread = true OR last_read is NULL) AND ";
553                 }
554
555 /*              $result = db_query($link, "SELECT count(id) AS total_entries 
556                         FROM ttrss_entries WHERE 
557                         $search_query_part
558                         feed_id = '$feed'");
559
560                 $total_entries = db_fetch_result($result, 0, "total_entries"); */
561
562 /*              $result = db_query("SELECT count(id) AS unread_entries 
563                         FROM ttrss_entries WHERE 
564                         $search_query_part
565                         unread = true AND
566                         feed_id = '$feed'");
567
568                 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
569
570                 if ($limit && $limit != "All") {
571                         $limit_query_part = "LIMIT " . $limit;
572                 } 
573
574                 $vfeed_query_part = "";
575
576                 // override query strategy and enable feed display when searching globally
577                 if ($search_mode == "All feeds") {
578                         $query_strategy_part = "id > 0";
579                         $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
580                                 id = feed_id) as feed_title,";
581                 } else if (sprintf("%d", $feed) == 0) {
582                         $query_strategy_part = "ttrss_entries.id > 0";
583                         $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
584                                 id = feed_id) as feed_title,";
585                 } else if ($feed >= 0) {
586                         $query_strategy_part = "feed_id = '$feed'";
587                 } else if ($feed == -1) { // starred virtual feed
588                         $query_strategy_part = "marked = true";
589                         $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
590                                 id = feed_id) as feed_title,";
591                 } else if ($feed <= -10) { // labels
592                         $label_id = -$feed - 11;
593
594                         $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
595                                 WHERE id = '$label_id'");
596                 
597                         $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
598         
599                         $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
600                                 id = feed_id) as feed_title,";
601                 } else {
602                         $query_strategy_part = "id > 0"; // dumb
603                 }
604
605
606                 $order_by = "updated DESC";
607
608 //              if ($feed < -10) {
609 //                      $order_by = "feed_id,updated DESC";
610 //              }
611
612                 if ($feed < -10) error_reporting (0);
613
614                 if (sprintf("%d", $feed) != 0) {
615
616                         $result = db_query($link, "SELECT 
617                                         id,title,updated,unread,feed_id,marked,link,last_read,
618                                         SUBSTRING(last_read,1,19) as last_read_noms,
619                                         $vfeed_query_part
620                                         SUBSTRING(updated,1,19) as updated_noms
621                                 FROM
622                                         ttrss_entries 
623                                 WHERE
624                                 $search_query_part
625                                 $view_query_part
626                                 $query_strategy_part ORDER BY $order_by
627                                 $limit_query_part");
628
629                 } else {
630                         // browsing by tag
631
632                         $result = db_query($link, "SELECT
633                                 ttrss_entries.id as id,title,updated,unread,feed_id,
634                                 marked,link,last_read,
635                                 SUBSTRING(last_read,1,19) as last_read_noms,
636                                 $vfeed_query_part
637                                 SUBSTRING(updated,1,19) as updated_noms
638                                 FROM
639                                         ttrss_entries,ttrss_tags
640                                 WHERE
641                                         post_id = ttrss_entries.id AND tag_name = '$feed' AND
642                                         $view_query_part
643                                         $search_query_part
644                                         $query_strategy_part ORDER BY $order_by
645                                 $limit_query_part");    
646                 }
647
648                 if (!$result) {
649                         print "<tr><td colspan='4' align='center'>
650                                 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
651                         return;
652                 }
653
654                 $lnum = 0;
655
656                 error_reporting (E_ERROR | E_WARNING | E_PARSE);
657
658                 $num_unread = 0;
659
660                 while ($line = db_fetch_assoc($result)) {
661
662                         $class = ($lnum % 2) ? "even" : "odd";
663
664                         $id = $line["id"];
665                         $feed_id = $line["feed_id"];
666
667 //                      printf("L %d (%s) &gt; U %d (%s) = %d<br>", 
668 //                              strtotime($line["last_read_noms"]), $line["last_read_noms"],
669 //                              strtotime($line["updated"]), $line["updated"],
670 //                              strtotime($line["last_read"]) >= strtotime($line["updated"]));
671
672 /*                      if ($line["last_read"] != "" && $line["updated"] != "" &&
673                                 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
674
675                                 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" 
676                                         alt=\"Updated\">";
677
678                         } else {
679
680                                 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" 
681                                         alt=\"Updated\">";
682
683                         } */
684
685                         if ($line["last_read"] == "" && 
686                                         ($line["unread"] != "t" && $line["unread"] != "1")) {
687
688                                 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" 
689                                         alt=\"Updated\">";
690                         } else {
691                                 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" 
692                                         alt=\"Updated\">";
693                         }
694
695                         if ($line["unread"] == "t" || $line["unread"] == "1") {
696                                 $class .= "Unread";
697                                 ++$num_unread;
698                         }
699
700                         if ($line["marked"] == "t" || $line["marked"] == "1") {
701                                 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" 
702                                         alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
703                         } else {
704                                 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" 
705                                         alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
706                         }
707
708                         $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
709                                 $line["title"] . "</a>";
710                                 
711                         print "<tr class='$class' id='RROW-$id'>";
712                         // onclick=\"javascript:view($id,$feed_id)\">
713
714                         print "<td valign='center' align='center'>$update_pic</td>";
715                         print "<td valign='center' align='center'>$marked_pic</td>";
716
717                         print "<td width='25%'>
718                                 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
719
720                         if ($line["feed_title"]) {                      
721                                 print "<td width='50%'>$content_link</td>";
722                                 print "<td width='20%'>
723                                         <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
724                         } else {
725                                 print "<td width='70%'>$content_link</td>";
726                         }
727
728                         print "</tr>";
729
730                         ++$lnum;
731                 }
732
733                 if ($lnum == 0) {
734                         print "<tr><td align='center'>No articles found.</td></tr>";
735                 }
736                 
737                 print "</table>";
738                 
739                 print "<script type=\"text/javascript\">
740                         document.onkeydown = hotkey_handler;
741                         update_label_counters('$feed');
742                 </script>";
743
744                 if ($addheader) {
745                         print "</body></html>";
746                 }
747
748         }
749
750         if ($op == "pref-rpc") {
751
752                 $subop = $_GET["subop"];
753
754                 if ($subop == "unread") {
755                         $ids = split(",", $_GET["ids"]);
756                         foreach ($ids as $id) {
757                                 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
758                         }
759
760                         print "Marked selected feeds as read.";
761                 }
762
763                 if ($subop == "read") {
764                         $ids = split(",", $_GET["ids"]);
765                         foreach ($ids as $id) {
766                                 db_query($link, "UPDATE ttrss_entries 
767                                         SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
768                         }
769
770                         print "Marked selected feeds as unread.";
771
772                 }
773
774         }
775
776         if ($op == "pref-feeds") {
777         
778                 $subop = $_GET["subop"];
779
780                 if ($subop == "editSave") {
781                         $feed_title = db_escape_string($_GET["t"]);
782                         $feed_link = db_escape_string($_GET["l"]);
783                         $upd_intl = db_escape_string($_GET["ui"]);
784                         $feed_id = $_GET["id"];
785
786                         if (strtoupper($upd_intl) == "DEFAULT")
787                                 $upd_intl = 0;
788
789                         $result = db_query($link, "UPDATE ttrss_feeds SET 
790                                 title = '$feed_title', feed_url = '$feed_link',
791                                 update_interval = '$upd_intl' WHERE id = '$feed_id'");                  
792
793                 }
794
795                 if ($subop == "remove") {
796
797                         if (!WEB_DEMO_MODE) {
798
799                                 $ids = split(",", $_GET["ids"]);
800
801                                 foreach ($ids as $id) {
802                                         db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
803                                         
804                                         if (file_exists(ICONS_DIR . "/$id.ico")) {
805                                                 unlink(ICONS_DIR . "/$id.ico");
806                                         }
807                                 }
808                         }
809                 }
810
811                 if ($subop == "add") {
812                 
813                         if (!WEB_DEMO_MODE) {
814
815                                 $feed_link = db_escape_string($_GET["link"]);
816                                         
817                                 $result = db_query($link,
818                                         "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
819
820                                 $result = db_query($link,
821                                         "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
822
823                                 $feed_id = db_fetch_result($result, 0, "id");
824
825                                 if ($feed_id) {
826                                         update_rss_feed($link, $feed_link, $feed_id);
827                                 }
828                         }
829                 }
830
831                 $result = db_query($link, "SELECT id,title,feed_url,last_error 
832                         FROM ttrss_feeds WHERE last_error != ''");
833
834                 if (db_num_rows($result) > 0) {
835                 
836                         print "<div class=\"warning\">";
837                 
838                         print "<b>Feeds with update errors:</b>";
839
840                         print "<ul class=\"nomarks\">";
841                                                 
842                         while ($line = db_fetch_assoc($result)) {
843                                 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . 
844                                         $line["last_error"];
845                         }
846
847                         print "</ul>";
848                         print "</div>";
849
850                 }
851
852                 print "<table class=\"prefAddFeed\"><tr>
853                         <td><input id=\"fadd_link\"></td>
854                         <td colspan=\"4\" align=\"right\">
855                                 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
856                 </table>";
857
858                 $result = db_query($link, "SELECT 
859                                 id,title,feed_url,substring(last_updated,1,16) as last_updated,
860                                 update_interval
861                         FROM 
862                                 ttrss_feeds ORDER by title");
863
864                 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
865                 print "<tr class=\"title\">
866                                         <td>&nbsp;</td><td>Select</td><td width=\"40%\">Title</td>
867                                         <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
868                                         <td>Last updated</td></tr>";
869                 
870                 $lnum = 0;
871                 
872                 while ($line = db_fetch_assoc($result)) {
873
874                         $class = ($lnum % 2) ? "even" : "odd";
875
876                         $feed_id = $line["id"];
877
878                         $edit_feed_id = $_GET["id"];
879
880                         if ($subop == "edit" && $feed_id != $edit_feed_id) {
881                                 $class .= "Grayed";
882                         }
883
884                         print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
885
886                         $icon_file = ICONS_DIR . "/$feed_id.ico";
887
888                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
889                                         $feed_icon = "<img width=\"16\" height=\"16\"
890                                                 src=\"" . ICONS_URL . "/$feed_id.ico\">";
891                         } else {
892                                 $feed_icon = "&nbsp;";
893                         }
894                         print "<td align='center'>$feed_icon</td>";             
895
896                         $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
897                         $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
898
899                         if (!$edit_feed_id || $subop != "edit") {
900
901                                 print "<td><input onclick='toggleSelectRow(this);' 
902                                 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
903
904                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
905                                         $edit_title . "</td>";          
906                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
907                                         $edit_link . "</td>";           
908
909                                 if ($line["update_interval"] == "0")
910                                         $line["update_interval"] = "Default";
911
912                                 print "<td>" . $line["update_interval"] . "</td>";
913
914
915                         } else if ($feed_id != $edit_feed_id) {
916
917                                 print "<td><input disabled=\"true\" type=\"checkbox\" 
918                                         id=\"FRCHK-".$line["id"]."\"></td>";
919
920                                 print "<td>$edit_title</td>";           
921                                 print "<td>$edit_link</td>";            
922
923                                 if ($line["update_interval"] == "0")
924                                         $line["update_interval"] = "Default";
925
926                                 print "<td>" . $line["update_interval"] . "</td>";
927
928                         } else {
929
930                                 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
931
932                                 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
933                                 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
934                                 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
935                                         
936                         }
937
938                         if (!$line["last_updated"]) $line["last_updated"] = "Never";
939
940                         print "<td>" . $line["last_updated"] . "</td>";
941                         
942                         print "</tr>";
943
944                         ++$lnum;
945                 }
946
947                 if ($lnum == 0) {
948                         print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
949                 }
950
951                 print "</table>";
952
953                 print "<p>";
954
955                 if ($subop == "edit") {
956                         print "Edit feed:&nbsp;
957                                 <input type=\"submit\" class=\"button\" 
958                                         onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
959                                 <input type=\"submit\" class=\"button\" 
960                                         onclick=\"javascript:feedEditSave()\" value=\"Save\">";
961                         } else {
962
963                         print "
964                                 Selection:&nbsp;
965                         <input type=\"submit\" class=\"button\" 
966                                 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
967                         <input type=\"submit\" class=\"button\" 
968                                 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
969                                 
970                         if (ENABLE_PREFS_CATCHUP_UNCATCHUP) {
971                                 print "
972                                 <input type=\"submit\" class=\"button\" 
973                                         onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
974                                 <input type=\"submit\" class=\"button\" 
975                                         onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
976                         }
977                         print "
978                         All feeds: 
979                                 <input type=\"submit\" 
980                                         class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
981                 
982                         }
983
984                 print "<h3>OPML Import</h3>
985                 <form   enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
986                         File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
987                         <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
988                                 type=\"submit\" value=\"Import\">
989                         </form>";
990
991         }
992
993         if ($op == "pref-filters") {
994
995                 $subop = $_GET["subop"];
996
997                 if ($subop == "editSave") {
998
999                         $regexp = db_escape_string($_GET["r"]);
1000                         $descr = db_escape_string($_GET["d"]);
1001                         $match = db_escape_string($_GET["m"]);
1002                         $filter_id = db_escape_string($_GET["id"]);
1003                         
1004                         $result = db_query($link, "UPDATE ttrss_filters SET 
1005                                 reg_exp = '$regexp', 
1006                                 description = '$descr',
1007                                 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1008                                         description = '$match')
1009                                 WHERE id = '$filter_id'");
1010                 }
1011
1012                 if ($subop == "remove") {
1013
1014                         if (!WEB_DEMO_MODE) {
1015
1016                                 $ids = split(",", $_GET["ids"]);
1017
1018                                 foreach ($ids as $id) {
1019                                         db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1020                                         
1021                                 }
1022                         }
1023                 }
1024
1025                 if ($subop == "add") {
1026                 
1027                         if (!WEB_DEMO_MODE) {
1028
1029                                 $regexp = db_escape_string($_GET["regexp"]);
1030                                 $match = db_escape_string($_GET["match"]);
1031                                         
1032                                 $result = db_query($link,
1033                                         "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES 
1034                                                 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1035                                                         description = '$match'))");
1036                         } 
1037                 }
1038
1039                 $result = db_query($link, "SELECT description 
1040                         FROM ttrss_filter_types ORDER BY description");
1041
1042                 $filter_types = array();
1043
1044                 while ($line = db_fetch_assoc($result)) {
1045                         array_push($filter_types, $line["description"]);
1046                 }
1047
1048                 print "<table class=\"prefAddFeed\"><tr>
1049                         <td><input id=\"fadd_regexp\"></td>
1050                         <td>";
1051                         print_select("fadd_match", "Title", $filter_types);     
1052         
1053                 print"</td><td colspan=\"4\" align=\"right\">
1054                                 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1055                 </table>";
1056
1057                 $result = db_query($link, "SELECT 
1058                                 id,reg_exp,description,
1059                                 (SELECT name FROM ttrss_filter_types WHERE 
1060                                         id = filter_type) as filter_type_name,
1061                                 (SELECT description FROM ttrss_filter_types 
1062                                         WHERE id = filter_type) as filter_type_descr
1063                         FROM 
1064                                 ttrss_filters ORDER by reg_exp");
1065
1066                 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1067
1068                 print "<tr class=\"title\">
1069                                         <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1070                                         <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1071                 
1072                 $lnum = 0;
1073                 
1074                 while ($line = db_fetch_assoc($result)) {
1075
1076                         $class = ($lnum % 2) ? "even" : "odd";
1077
1078                         $filter_id = $line["id"];
1079                         $edit_filter_id = $_GET["id"];
1080
1081                         if ($subop == "edit" && $filter_id != $edit_filter_id) {
1082                                 $class .= "Grayed";
1083                         }
1084
1085                         print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1086
1087                         $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1088                         $line["description"] = htmlspecialchars($line["description"]);
1089
1090                         if (!$edit_filter_id || $subop != "edit") {
1091
1092                                 if (!$line["description"]) $line["description"] = "[No description]";
1093
1094                                 print "<td><input onclick='toggleSelectRow(this);' 
1095                                 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1096
1097                                 print "<td><a href=\"javascript:editFilter($filter_id);\">" . 
1098                                         $line["reg_exp"] . "</td>";             
1099                                         
1100                                 print "<td><a href=\"javascript:editFilter($filter_id);\">" . 
1101                                         $line["description"] . "</td>";                 
1102
1103                                 print "<td>".$line["filter_type_descr"]."</td>";
1104
1105                         } else if ($filter_id != $edit_filter_id) {
1106
1107                                 if (!$line["description"]) $line["description"] = "[No description]";
1108
1109                                 print "<td><input disabled=\"true\" type=\"checkbox\" 
1110                                         id=\"FICHK-".$line["id"]."\"></td>";
1111
1112                                 print "<td>".$line["reg_exp"]."</td>";          
1113                                 print "<td>".$line["description"]."</td>";              
1114                                 print "<td>".$line["filter_type_descr"]."</td>";
1115
1116                         } else {
1117
1118                                 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1119
1120                                 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1121                                         "\"></td>";
1122
1123                                 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1124                                         "\"></td>";
1125
1126                                 print "<td>";
1127                                 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1128                                 print "</td>";
1129                                                 
1130                         }
1131                                 
1132                         
1133                         print "</tr>";
1134
1135                         ++$lnum;
1136                 }
1137
1138                 if ($lnum == 0) {
1139                         print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1140                 }
1141
1142                 print "</table>";
1143
1144                 print "<p>";
1145
1146                 if ($subop == "edit") {
1147                         print "Edit feed:
1148                                 <input type=\"submit\" class=\"button\" 
1149                                         onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1150                                 <input type=\"submit\" class=\"button\" 
1151                                         onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1152                                         
1153                 } else {
1154
1155                         print "
1156                                 Selection:
1157                         <input type=\"submit\" class=\"button\" 
1158                                 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1159                         <input type=\"submit\" class=\"button\" 
1160                                 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1161                 }
1162         }
1163
1164         if ($op == "pref-labels") {
1165
1166                 $subop = $_GET["subop"];
1167
1168                 if ($subop == "editSave") {
1169
1170                         $sql_exp = $_GET["s"];
1171                         $descr = $_GET["d"];
1172                         $label_id = db_escape_string($_GET["id"]);
1173                         
1174 //                      print "$sql_exp : $descr : $label_id";
1175                         
1176                         $result = db_query($link, "UPDATE ttrss_labels SET 
1177                                 sql_exp = '$sql_exp', 
1178                                 description = '$descr'
1179                                 WHERE id = '$label_id'");
1180                 }
1181
1182                 if ($subop == "remove") {
1183
1184                         if (!WEB_DEMO_MODE) {
1185
1186                                 $ids = split(",", $_GET["ids"]);
1187
1188                                 foreach ($ids as $id) {
1189                                         db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1190                                         
1191                                 }
1192                         }
1193                 }
1194
1195                 if ($subop == "add") {
1196                 
1197                         if (!WEB_DEMO_MODE) {
1198
1199                                 $exp = $_GET["exp"];
1200                                         
1201                                 $result = db_query($link,
1202                                         "INSERT INTO ttrss_labels (sql_exp,description) 
1203                                                 VALUES ('$exp', '$exp')");
1204                         } 
1205                 }
1206
1207                 print "<table class=\"prefAddFeed\"><tr>
1208                         <td><input id=\"ladd_expr\"></td>";
1209                         
1210                 print"<td colspan=\"4\" align=\"right\">
1211                                 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1212                 </table>";
1213
1214                 $result = db_query($link, "SELECT 
1215                                 id,sql_exp,description
1216                         FROM 
1217                                 ttrss_labels ORDER by description");
1218
1219                 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1220
1221                 print "<tr class=\"title\">
1222                                         <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1223                                         <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1224                                         </td>
1225                                         <td width=\"40%\">Caption</td></tr>";
1226                 
1227                 $lnum = 0;
1228                 
1229                 while ($line = db_fetch_assoc($result)) {
1230
1231                         $class = ($lnum % 2) ? "even" : "odd";
1232
1233                         $label_id = $line["id"];
1234                         $edit_label_id = $_GET["id"];
1235
1236                         if ($subop == "edit" && $label_id != $edit_label_id) {
1237                                 $class .= "Grayed";
1238                         }
1239
1240                         print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1241
1242                         $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1243                         $line["description"] = htmlspecialchars($line["description"]);
1244
1245                         if (!$edit_label_id || $subop != "edit") {
1246
1247                                 if (!$line["description"]) $line["description"] = "[No caption]";
1248
1249                                 print "<td><input onclick='toggleSelectRow(this);' 
1250                                 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1251
1252                                 print "<td><a href=\"javascript:editLabel($label_id);\">" . 
1253                                         $line["sql_exp"] . "</td>";             
1254                                         
1255                                 print "<td><a href=\"javascript:editLabel($label_id);\">" . 
1256                                         $line["description"] . "</td>";                 
1257
1258                         } else if ($label_id != $edit_label_id) {
1259
1260                                 if (!$line["description"]) $line["description"] = "[No description]";
1261
1262                                 print "<td><input disabled=\"true\" type=\"checkbox\" 
1263                                         id=\"LICHK-".$line["id"]."\"></td>";
1264
1265                                 print "<td>".$line["sql_exp"]."</td>";          
1266                                 print "<td>".$line["description"]."</td>";              
1267
1268                         } else {
1269
1270                                 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1271
1272                                 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1273                                         "\"></td>";
1274
1275                                 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1276                                         "\"></td>";
1277                                                 
1278                         }
1279                                 
1280                         
1281                         print "</tr>";
1282
1283                         ++$lnum;
1284                 }
1285
1286                 if ($lnum == 0) {
1287                         print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1288                 }
1289
1290                 print "</table>";
1291
1292                 print "<p>";
1293
1294                 if ($subop == "edit") {
1295                         print "Edit label:
1296                                 <input type=\"submit\" class=\"button\" 
1297                                         onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1298                                 <input type=\"submit\" class=\"button\" 
1299                                         onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1300                                         
1301                 } else {
1302
1303                         print "
1304                                 Selection:
1305                         <input type=\"submit\" class=\"button\" 
1306                                 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1307                         <input type=\"submit\" class=\"button\" 
1308                                 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1309                 }
1310         }
1311
1312         if ($op == "error") {
1313                 print "<div width=\"100%\" align='center'>";
1314                 $msg = $_GET["msg"];
1315                 print $msg;
1316                 print "</div>";
1317         }
1318
1319         if ($op == "help") {
1320                 print "<html><head>
1321                         <title>Tiny Tiny RSS : Help</title>
1322                         <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1323                         <script type=\"text/javascript\" src=\"functions.js\"></script>
1324                         <script type=\"text/javascript\" src=\"feedlist.js\"></script>
1325                         <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1326                         </head><body>";
1327
1328                 $tid = sprintf("%d", $_GET["tid"]);
1329
1330                 /* FIXME this badly needs real implementation */
1331
1332                 print "<div class='helpResponse'>";
1333
1334                 ?>
1335
1336                 <h1>Help for SQL expressions</h1>
1337
1338                 <h2>Description</h2>
1339
1340                 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
1341                         view feed query. You can match on ttrss_entries table fields
1342                         and even use subselect to query additional information. This 
1343                         functionality is considered to be advanced and requires basic
1344                         understanding of SQL.</p>
1345                         
1346                 <h2>Examples</h2>
1347
1348                 <pre>unread = true</pre>
1349
1350                 Matches all unread articles
1351
1352                 <pre>title like '%Linux%'</pre>
1353
1354                 Matches all articles which mention Linux in the title. You get the idea.
1355
1356                 <p>See the database schema included in the distribution package for gruesome
1357                 details.</p>
1358
1359                 <?
1360
1361                 print "<div align='center'>
1362                         <a class=\"helpLink\"
1363                         href=\"javascript:window.close()\">(Close this window)</a></div>";
1364
1365                 print "</div>";
1366
1367                 print "</body></html>";
1368
1369         }
1370
1371         if ($op == "dlg") {
1372                 $id = $_GET["id"];
1373                 $param = $_GET["param"];
1374
1375                 if ($id == "quickAddFeed") {
1376                         print "Feed URL: <input 
1377                         onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1378                         id=\"qafInput\">
1379                         <input class=\"button\"
1380                                 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1381                         <input class=\"button\"
1382                                 type=\"submit\" onclick=\"javascript:closeDlg()\" 
1383                                 value=\"Cancel\">";
1384                 }
1385
1386                 if ($id == "quickDelFeed") {
1387
1388                         $param = db_escape_string($param);
1389
1390                         $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1391
1392                         if ($result) {
1393
1394                                 $f_title = db_fetch_result($result, 0, "title");
1395                 
1396                                 print "Remove current feed ($f_title)?&nbsp;
1397                                 <input class=\"button\"
1398                                         type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1399                                 <input class=\"button\"
1400                                         type=\"submit\" onclick=\"javascript:closeDlg()\" 
1401                                         value=\"Cancel\">";
1402                         } else {
1403                                 print "Error: Feed $param not found.&nbsp;
1404                                 <input class=\"button\"
1405                                         type=\"submit\" onclick=\"javascript:closeDlg()\" 
1406                                         value=\"Cancel\">";             
1407                         }
1408                 }
1409
1410                 if ($id == "search") {
1411
1412                         print "<input id=\"searchbox\" class=\"extSearch\"                      
1413                         onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1414                         onchange=\"javascript:search()\">
1415                         <select id=\"searchmodebox\">
1416                                 <option selected>All feeds</option>
1417                                 <option>This feed</option>
1418                         </select>               
1419                         <input type=\"submit\" 
1420                                 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1421                         <input class=\"button\"
1422                                 type=\"submit\" onclick=\"javascript:closeDlg()\" 
1423                                 value=\"Close\">";
1424
1425                 }
1426
1427         }
1428
1429         db_close($link);
1430 ?>
1431
1432 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
1433