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