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