]> git.wh0rd.org Git - tt-rss.git/blob - backend.php
globalPurge rpc call
[tt-rss.git] / backend.php
1 <?
2         session_start();
3
4         if (!$_SESSION["uid"]) { exit; }
5
6         define(SCHEMA_VERSION, 2);
7
8         require_once "config.php";
9         require_once "db.php";
10         require_once "db-prefs.php";
11         require_once "functions.php";
12         require_once "magpierss/rss_fetch.inc";
13
14         $op = $_REQUEST["op"];
15
16         if ($op == "rpc" || $op == "updateAllFeeds") {
17                 header("Content-Type: application/xml");
18         }
19
20         $script_started = getmicrotime();
21
22         $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
23
24         if (!$link) {
25                 if (DB_TYPE == "mysql") {
26                         print mysql_error();
27                 }
28                 // PG seems to display its own errors just fine by default.             
29                 return;
30         }
31
32         if (DB_TYPE == "pgsql") {
33                 pg_query("set client_encoding = 'utf-8'");
34         }
35
36 /*
37         $result = db_query($link, "SELECT schema_version FROM ttrss_version");
38
39         $schema_version = db_fetch_result($result, 0, "schema_version");
40
41         if ($schema_version != SCHEMA_VERSION) {
42                 print "Error: database schema is invalid
43                         (got version $schema_version; expected ".SCHEMA_VERSION.")";
44                 return;
45         }
46 */
47
48         $fetch = $_GET["fetch"];
49
50         /* FIXME this needs reworking */
51
52         function getGlobalCounters($link) {
53                 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
54                         WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
55                 $c_id = db_fetch_result($result, 0, "c_id");
56                 print "<counter id='global-unread' counter='$c_id'/>";
57         }
58
59         function getTagCounters($link) {
60                 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
61                         FROM ttrss_tags,ttrss_entries WHERE
62                         ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
63                         post_id = ttrss_entries.id AND unread = true GROUP BY tag_name 
64                 UNION
65                         select tag_name,0 as count FROM ttrss_tags
66                         WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
67
68                 $tags = array();
69
70                 while ($line = db_fetch_assoc($result)) {
71                         $tags[$line["tag_name"]] += $line["count"];
72                 }
73
74                 foreach (array_keys($tags) as $tag) {
75                         $unread = $tags[$tag];                  
76
77                         $tag = htmlspecialchars($tag);
78                         print "<tag id=\"$tag\" counter=\"$unread\"/>";
79                 } 
80         }
81
82         function getLabelCounters($link) {
83
84                 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
85                         WHERE marked = true AND unread = true AND owner_uid = ".$_SESSION["uid"]);
86
87                 $count = db_fetch_result($result, 0, "count");
88
89                 print "<label id=\"-1\" counter=\"$count\"/>";
90
91                 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
92                         ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
93         
94                 while ($line = db_fetch_assoc($result)) {
95
96                         $id = -$line["id"] - 11;
97
98                         error_reporting (0);
99
100                         $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
101                                 WHERE (" . $line["sql_exp"] . ") AND unread = true AND 
102                                 owner_uid = ".$_SESSION["uid"]);
103
104                         $count = db_fetch_result($tmp_result, 0, "count");
105
106                         print "<label id=\"$id\" counter=\"$count\"/>";
107
108                         error_reporting (E_ERROR | E_WARNING | E_PARSE);
109         
110                 }
111         }
112
113         function getFeedCounter($link, $id) {
114         
115                 $result = db_query($link, "SELECT 
116                                 count(id) as count FROM ttrss_entries
117                         WHERE feed_id = '$id' AND unread = true");
118         
119                         $count = db_fetch_result($result, 0, "count");
120                         
121                         print "<feed id=\"$id\" counter=\"$count\"/>";          
122         }
123
124         function getFeedCounters($link) {
125         
126                 $result = db_query($link, "SELECT id,
127                         (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id 
128                                 AND unread = true) as count
129                         FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
130         
131                 while ($line = db_fetch_assoc($result)) {
132                 
133                         $id = $line["id"];
134                         $count = $line["count"];
135
136                         print "<feed id=\"$id\" counter=\"$count\"/>";
137                 }
138         }
139
140         function outputFeedList($link, $tags = false) {
141
142                 print "<html><head>
143                         <title>Tiny Tiny RSS : Feedlist</title>
144                         <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
145
146                 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
147                         print "<link rel=\"stylesheet\" type=\"text/css\" 
148                                 href=\"tt-rss_compact.css\"/>";
149                 } else {
150                         print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" 
151                                         type=\"text/css\" href=\"tt-rss_compact.css\"/>";
152                 }
153
154                 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
155                         <script type=\"text/javascript\" src=\"feedlist.js\"></script>
156                         <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
157                         </head><body onload=\"init()\">";
158
159                 print "<ul class=\"feedList\" id=\"feedList\">";
160
161                 $owner_uid = $_SESSION["uid"];
162
163                 if (!$tags) {
164
165                         /* virtual feeds */
166
167                         $result = db_query($link, "SELECT count(id) as num_starred 
168                                 FROM ttrss_entries WHERE marked = true AND unread = true AND owner_uid = '$owner_uid'");
169                         $num_starred = db_fetch_result($result, 0, "num_starred");
170
171                         $class = "virt";
172
173                         if ($num_starred > 0) $class .= "Unread";
174
175                         printFeedEntry(-1, $class, "Starred articles", $num_starred, 
176                                 "images/mark_set.png", $link);
177
178                         if (get_pref($link, 'ENABLE_LABELS')) {
179         
180                                 $result = db_query($link, "SELECT id,sql_exp,description FROM
181                                         ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
182                 
183                                 if (db_num_rows($result) > 0) {
184                                         print "<li><hr></li>";
185                                 }
186                 
187                                 while ($line = db_fetch_assoc($result)) {
188         
189                                         error_reporting (0);
190                 
191                                         $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
192                                                 WHERE (" . $line["sql_exp"] . ") AND unread = true 
193                                                 AND owner_uid = '$owner_uid'");
194         
195                                         $count = db_fetch_result($tmp_result, 0, "count");
196         
197                                         $class = "label";
198         
199                                         if ($count > 0) {
200                                                 $class .= "Unread";
201                                         }
202                                         
203                                         error_reporting (E_ERROR | E_WARNING | E_PARSE);
204         
205                                         printFeedEntry(-$line["id"]-11, 
206                                                 $class, $line["description"], $count, "images/label.png", $link);
207                 
208                                 }
209                         }
210         
211                         print "<li><hr></li>";
212
213                         $result = db_query($link, "SELECT *,
214                                 (SELECT count(id) FROM ttrss_entries 
215                                         WHERE feed_id = ttrss_feeds.id) AS total,
216                                 (SELECT count(id) FROM ttrss_entries
217                                         WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
218                                 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");                       
219         
220                         $actid = $_GET["actid"];
221         
222                         /* real feeds */
223         
224                         $lnum = 0;
225         
226                         $total_unread = 0;
227         
228                         while ($line = db_fetch_assoc($result)) {
229                         
230                                 $feed = $line["title"];
231                                 $feed_id = $line["id"];   
232         
233                                 $subop = $_GET["subop"];
234                                 
235                                 $total = $line["total"];
236                                 $unread = $line["unread"];
237                                 
238         //                      $class = ($lnum % 2) ? "even" : "odd";
239         
240                                 $class = "feed";
241         
242                                 if ($unread > 0) $class .= "Unread";
243         
244                                 if ($actid == $feed_id) {
245                                         $class .= "Selected";
246                                 }
247         
248                                 $total_unread += $unread;
249         
250                                 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
251         
252                                 ++$lnum;
253                         }
254                 } else {
255
256                         // tags
257
258                         $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
259                                 FROM ttrss_tags,ttrss_entries WHERE
260                                 post_id = ttrss_entries.id AND unread = true 
261                                 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name                               
262                         UNION
263                                 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'");
264         
265                         $tags = array();
266         
267                         while ($line = db_fetch_assoc($result)) {
268                                 $tags[$line["tag_name"]] += $line["count"];
269                         }
270         
271                         foreach (array_keys($tags) as $tag) {
272         
273                                 $unread = $tags[$tag];
274         
275                                 $class = "odd";
276         
277                                 if ($unread > 0) {
278                                         $class .= "Unread";
279                                 }
280         
281                                 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
282         
283                         } 
284
285                 }
286
287                 if (db_num_rows($result) == 0) {
288                         print "<li>No tags/feeds to display.</li>";
289                 }
290
291                 print "</ul>";
292
293                 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
294
295         }
296
297
298         if ($op == "rpc") {
299
300                 $subop = $_GET["subop"];
301
302                 if ($subop == "getLabelCounters") {
303                         $aid = $_GET["aid"];            
304                         print "<rpc-reply>";
305                         getLabelCounters($link);
306                         if ($aid) {
307                                 getFeedCounter($link, $aid);
308                         }
309                         print "</rpc-reply>";
310                 }
311
312                 if ($subop == "getFeedCounters") {
313                         print "<rpc-reply>";
314                         getFeedCounters($link);
315                         print "</rpc-reply>";
316                 }
317
318                 if ($subop == "getAllCounters") {
319                         print "<rpc-reply>";
320                         getLabelCounters($link);
321                         getFeedCounters($link);
322                         getTagCounters($link);
323                         getGlobalCounters($link);
324                         print "</rpc-reply>";
325                 }
326
327                 if ($subop == "mark") {
328                         $mark = $_GET["mark"];
329                         $id = db_escape_string($_GET["id"]);
330
331                         if ($mark == "1") {
332                                 $mark = "true";
333                         } else {
334                                 $mark = "false";
335                         }
336
337                         $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
338                                 WHERE id = '$id'");
339                 }
340
341                 if ($subop == "updateFeed") {
342                         $feed_id = db_escape_string($_GET["feed"]);
343
344                         $result = db_query($link, 
345                                 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
346
347                         if (db_num_rows($result) > 0) {                 
348                                 $feed_url = db_fetch_result($result, 0, "feed_url");
349 //                              update_rss_feed($link, $feed_url, $feed_id);
350                         }
351
352                         print "DONE-$feed_id";
353
354                         return;
355                 }
356
357                 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
358                 
359                         update_all_feeds($link, true);                  
360
361                         $omode = $_GET["omode"];
362
363                         if (!$omode) $omode = "tfl";
364
365                         print "<rpc-reply>";
366                         if (strchr($omode, "l")) getLabelCounters($link);
367                         if (strchr($omode, "f")) getFeedCounters($link);
368                         if (strchr($omode, "t")) getTagCounters($link);
369                         getGlobalCounters($link);
370                         print "</rpc-reply>";
371                 }
372                 
373                 if ($subop == "catchupPage") {
374
375                         $ids = split(",", $_GET["ids"]);
376
377                         foreach ($ids as $id) {
378
379                                 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
380                                         WHERE id = '$id'");
381
382                         }
383
384                         print "Marked active page as read.";
385                 }
386
387                 if ($subop == "sanityCheck") {
388
389                         $error_code = 0;
390
391                         $result = db_query($link, "SELECT schema_version FROM ttrss_version");
392
393                         $schema_version = db_fetch_result($result, 0, "schema_version");
394
395                         if ($schema_version != SCHEMA_VERSION) {
396                                 $error_code = 5;
397                         }
398
399                         print "<error code='$error_code'/>";
400                 }
401
402                 if ($subop == "globalPurge") {
403
404                         print "<rpc-reply>";
405                         global_purge_old_posts($link, true);
406                         print "</rpc-reply>";
407
408                 }
409
410         }
411         
412         if ($op == "feeds") {
413
414                 $tags = $_GET["tags"];
415
416                 $subop = $_GET["subop"];
417
418                 if ($subop == "catchupAll") {
419                         db_query($link, "UPDATE ttrss_entries SET 
420                                 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
421                 }
422
423                 outputFeedList($link, $tags);
424
425         }
426
427         if ($op == "view") {
428
429                 $id = $_GET["id"];
430                 $feed_id = $_GET["feed"];
431
432                 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
433
434                 $addheader = $_GET["addheader"];
435
436                 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
437                         (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url 
438                         FROM ttrss_entries
439                         WHERE   id = '$id'");
440
441                 if ($addheader) {
442                         print "<html><head>
443                                 <title>Tiny Tiny RSS : Article $id</title>
444                                 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
445                                 <script type=\"text/javascript\" src=\"functions.js\"></script>
446                                 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
447                                 </head><body>";
448                 }
449
450                 if ($result) {
451
452                         $line = db_fetch_assoc($result);
453
454                         if ($line["icon_url"]) {
455                                 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
456                         } else {
457                                 $feed_icon = "&nbsp;";
458                         }
459
460                         if ($line["comments"] && $line["link"] != $line["comments"]) {
461                                 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
462                         } else {
463                                 $entry_comments = "";
464                         }
465
466                         print "<div class=\"postReply\">";
467
468                         print "<div class=\"postHeader\"><table>";
469
470                         print "<tr><td><b>Title:</b></td>
471                                 <td width='100%'>" . $line["title"] . "</td></tr>";
472                                 
473                         print "<tr><td><b>Link:</b></td>
474                                 <td width='100%'>
475                                 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
476                                 $entry_comments</td></tr>";
477                                         
478                         print "</table></div>";
479
480                         print "<div class=\"postIcon\">" . $feed_icon . "</div>";
481                         print "<div class=\"postContent\">" . $line["content"] . "</div>";
482                         
483                         print "</div>";
484
485                         print "<script type=\"text/javascript\">
486                                 update_label_counters('$feed_id');
487                         </script>";
488                 }
489
490                 if ($addheader) {
491                         print "</body></html>";
492                 }
493         }
494
495         if ($op == "viewfeed") {
496
497                 $feed = $_GET["feed"];
498                 $skip = $_GET["skip"];
499                 $subop = $_GET["subop"];
500                 $view_mode = $_GET["view"];
501                 $addheader = $_GET["addheader"];
502                 $limit = $_GET["limit"];
503
504                 if (!$feed) {
505                         print "Error: no feed to display.";
506                         return;
507                 }
508
509                 if (!$skip) $skip = 0;
510
511                 if ($subop == "undefined") $subop = "";
512
513                 if ($addheader) {
514                         print "<html><head>
515                                 <title>Tiny Tiny RSS : Feed $feed</title>
516                                 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
517
518                         if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
519                                 print "<link rel=\"stylesheet\" 
520                                                 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
521
522                         } else {
523                                 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" 
524                                                 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
525                         }
526                         print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">  
527                                 <script type=\"text/javascript\" src=\"functions.js\"></script>
528                                 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
529                                 </head><body onload='init()'>";
530                 }
531
532                 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
533
534                         $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
535                                 WHERE id = '$feed'");
536
537                         $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
538
539                         update_rss_feed($link, $feed_url, $feed);
540
541                 }
542
543                 if ($subop == "MarkAllRead")  {
544
545                         if (sprintf("%d", $feed) != 0) {
546                         
547                                 if ($feed > 0) {
548                                         db_query($link, "UPDATE ttrss_entries 
549                                                 SET unread = false,last_read = NOW() 
550                                                 WHERE feed_id = '$feed'");
551                                                 
552                                 } else if ($feed < 0 && $feed > -10) { // special, like starred
553
554                                         if ($feed == -1) {
555                                                 db_query($link, "UPDATE ttrss_entries 
556                                                         SET unread = false,last_read = NOW()
557                                                         WHERE marked = true");
558                                         }
559                         
560                                 } else if ($feed < -10) { // label
561
562                                         $label_id = -$feed - 11;
563
564                                         $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
565                                                 WHERE id = '$label_id'");
566
567                                         if ($tmp_result) {
568                                                 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
569
570                                                 db_query($link, "UPDATE ttrss_entries 
571                                                         SET unread = false,last_read = NOW()
572                                                         WHERE $sql_exp");
573                                         }
574                                 }
575                         } else { // tag
576                                 // FIXME, implement catchup for tags
577                         }
578
579                 }
580
581                 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
582
583                 $search = $_GET["search"];
584
585                 $search_mode = $_GET["smode"];
586
587                 if ($search) {
588                         $search_query_part = "(upper(title) LIKE upper('%$search%') 
589                                 OR content LIKE '%$search%') AND";
590                 } else {
591                         $search_query_part = "";
592                 }
593
594                 $view_query_part = "";
595
596                 if ($view_mode == "Starred") {
597                         $view_query_part = " marked = true AND ";
598                 }
599
600                 if ($view_mode == "Unread") {
601                         $view_query_part = " unread = true AND ";
602                 }
603
604                 if ($view_mode == "Unread or Starred") {
605                         $view_query_part = " (unread = true OR marked = true) AND ";
606                 }
607
608                 if ($view_mode == "Unread or Updated") {
609                         $view_query_part = " (unread = true OR last_read is NULL) AND ";
610                 }
611
612 /*              $result = db_query($link, "SELECT count(id) AS total_entries 
613                         FROM ttrss_entries WHERE 
614                         $search_query_part
615                         feed_id = '$feed'");
616
617                 $total_entries = db_fetch_result($result, 0, "total_entries"); */
618
619 /*              $result = db_query("SELECT count(id) AS unread_entries 
620                         FROM ttrss_entries WHERE 
621                         $search_query_part
622                         unread = true AND
623                         feed_id = '$feed'");
624
625                 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
626
627                 if ($limit && $limit != "All") {
628                         $limit_query_part = "LIMIT " . $limit;
629                 } 
630
631                 $vfeed_query_part = "";
632
633                 // override query strategy and enable feed display when searching globally
634                 if ($search_mode == "All feeds") {
635                         $query_strategy_part = "id > 0";
636                         $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
637                                 id = feed_id) as feed_title,";
638                 } else if (sprintf("%d", $feed) == 0) {
639                         $query_strategy_part = "ttrss_entries.id > 0";
640                         $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
641                                 id = feed_id) as feed_title,";
642                 } else if ($feed >= 0) {
643                         $query_strategy_part = "feed_id = '$feed'";
644                 } else if ($feed == -1) { // starred virtual feed
645                         $query_strategy_part = "marked = true";
646                         $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
647                                 id = feed_id) as feed_title,";
648                 } else if ($feed <= -10) { // labels
649                         $label_id = -$feed - 11;
650
651                         $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
652                                 WHERE id = '$label_id'");
653                 
654                         $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
655         
656                         $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
657                                 id = feed_id) as feed_title,";
658                 } else {
659                         $query_strategy_part = "id > 0"; // dumb
660                 }
661
662
663                 $order_by = "updated DESC";
664
665 //              if ($feed < -10) {
666 //                      $order_by = "feed_id,updated DESC";
667 //              }
668
669                 if ($feed < -10) error_reporting (0);
670
671                 if (sprintf("%d", $feed) != 0) {
672
673                         $result = db_query($link, "SELECT 
674                                         id,title,updated,unread,feed_id,marked,link,last_read,
675                                         SUBSTRING(last_read,1,19) as last_read_noms,
676                                         $vfeed_query_part
677                                         SUBSTRING(updated,1,19) as updated_noms
678                                 FROM
679                                         ttrss_entries 
680                                 WHERE
681                                 owner_uid = '".$_SESSION["uid"]."' AND
682                                 $search_query_part
683                                 $view_query_part
684                                 $query_strategy_part ORDER BY $order_by
685                                 $limit_query_part");
686
687                 } else {
688                         // browsing by tag
689
690                         $result = db_query($link, "SELECT
691                                 ttrss_entries.id as id,title,updated,unread,feed_id,
692                                 marked,link,last_read,
693                                 SUBSTRING(last_read,1,19) as last_read_noms,
694                                 $vfeed_query_part
695                                 SUBSTRING(updated,1,19) as updated_noms
696                                 FROM
697                                         ttrss_entries,ttrss_tags
698                                 WHERE
699                                         ttrss_entries.owner_uid = '".$_SESSION["uid"]."' AND
700                                         post_id = ttrss_entries.id AND tag_name = '$feed' AND
701                                         $view_query_part
702                                         $search_query_part
703                                         $query_strategy_part ORDER BY $order_by
704                                 $limit_query_part");    
705                 }
706
707                 if (!$result) {
708                         print "<tr><td colspan='4' align='center'>
709                                 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
710                         return;
711                 }
712
713                 $lnum = 0;
714
715                 error_reporting (E_ERROR | E_WARNING | E_PARSE);
716
717                 $num_unread = 0;
718
719                 while ($line = db_fetch_assoc($result)) {
720
721                         $class = ($lnum % 2) ? "even" : "odd";
722
723                         $id = $line["id"];
724                         $feed_id = $line["feed_id"];
725
726 //                      printf("L %d (%s) &gt; U %d (%s) = %d<br>", 
727 //                              strtotime($line["last_read_noms"]), $line["last_read_noms"],
728 //                              strtotime($line["updated"]), $line["updated"],
729 //                              strtotime($line["last_read"]) >= strtotime($line["updated"]));
730
731 /*                      if ($line["last_read"] != "" && $line["updated"] != "" &&
732                                 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
733
734                                 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" 
735                                         alt=\"Updated\">";
736
737                         } else {
738
739                                 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" 
740                                         alt=\"Updated\">";
741
742                         } */
743
744                         if ($line["last_read"] == "" && 
745                                         ($line["unread"] != "t" && $line["unread"] != "1")) {
746
747                                 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" 
748                                         alt=\"Updated\">";
749                         } else {
750                                 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" 
751                                         alt=\"Updated\">";
752                         }
753
754                         if ($line["unread"] == "t" || $line["unread"] == "1") {
755                                 $class .= "Unread";
756                                 ++$num_unread;
757                         }
758
759                         if ($line["marked"] == "t" || $line["marked"] == "1") {
760                                 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" 
761                                         alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
762                         } else {
763                                 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" 
764                                         alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
765                         }
766
767                         $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
768                                 $line["title"] . "</a>";
769                                 
770                         print "<tr class='$class' id='RROW-$id'>";
771                         // onclick=\"javascript:view($id,$feed_id)\">
772
773                         print "<td valign='center' align='center'>$update_pic</td>";
774                         print "<td valign='center' align='center'>$marked_pic</td>";
775
776                         print "<td width='25%'>
777                                 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
778
779                         if ($line["feed_title"]) {                      
780                                 print "<td width='50%'>$content_link</td>";
781                                 print "<td width='20%'>
782                                         <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
783                         } else {
784                                 print "<td width='70%'>$content_link</td>";
785                         }
786
787                         print "</tr>";
788
789                         ++$lnum;
790                 }
791
792                 if ($lnum == 0) {
793                         print "<tr><td align='center'>No articles found.</td></tr>";
794                 }
795                 
796                 print "</table>";
797                 
798                 print "<script type=\"text/javascript\">
799                         document.onkeydown = hotkey_handler;
800                         update_label_counters('$feed');
801                 </script>";
802
803                 if ($addheader) {
804                         print "</body></html>";
805                 }
806
807         }
808
809         if ($op == "pref-rpc") {
810
811                 $subop = $_GET["subop"];
812
813                 if ($subop == "unread") {
814                         $ids = split(",", $_GET["ids"]);
815                         foreach ($ids as $id) {
816                                 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
817                         }
818
819                         print "Marked selected feeds as read.";
820                 }
821
822                 if ($subop == "read") {
823                         $ids = split(",", $_GET["ids"]);
824                         foreach ($ids as $id) {
825                                 db_query($link, "UPDATE ttrss_entries 
826                                         SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
827                         }
828
829                         print "Marked selected feeds as unread.";
830
831                 }
832
833         }
834
835         if ($op == "pref-feeds") {
836         
837                 $subop = $_GET["subop"];
838
839                 if ($subop == "editSave") {
840                         $feed_title = db_escape_string($_GET["t"]);
841                         $feed_link = db_escape_string($_GET["l"]);
842                         $upd_intl = db_escape_string($_GET["ui"]);
843                         $purge_intl = db_escape_string($_GET["pi"]);
844                         $feed_id = $_GET["id"];
845
846                         if (strtoupper($upd_intl) == "DEFAULT")
847                                 $upd_intl = 0;
848
849                         if (strtoupper($purge_intl) == "DEFAULT")
850                                 $purge_intl = 0;
851
852                         if (strtoupper($purge_intl) == "DISABLED")
853                                 $purge_intl = -1;
854
855                         $result = db_query($link, "UPDATE ttrss_feeds SET 
856                                 title = '$feed_title', feed_url = '$feed_link',
857                                 update_interval = '$upd_intl',
858                                 purge_interval = '$purge_intl' 
859                                 WHERE id = '$feed_id'");                        
860
861                 }
862
863                 if ($subop == "remove") {
864
865                         if (!WEB_DEMO_MODE) {
866
867                                 $ids = split(",", $_GET["ids"]);
868
869                                 foreach ($ids as $id) {
870                                         db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
871
872                                         $icons_dir = ICONS_DIR;
873                                         
874                                         if (file_exists($icons_dir . "/$id.ico")) {
875                                                 unlink($icons_dir . "/$id.ico");
876                                         }
877                                 }
878                         }
879                 }
880
881                 if ($subop == "add") {
882                 
883                         if (!WEB_DEMO_MODE) {
884
885                                 $feed_link = db_escape_string($_GET["link"]);
886                                         
887                                 $result = db_query($link,
888                                         "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
889
890                                 $result = db_query($link,
891                                         "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
892
893                                 $feed_id = db_fetch_result($result, 0, "id");
894
895                                 if ($feed_id) {
896                                         update_rss_feed($link, $feed_link, $feed_id);
897                                 }
898                         }
899                 }
900
901                 $result = db_query($link, "SELECT id,title,feed_url,last_error 
902                         FROM ttrss_feeds WHERE last_error != ''");
903
904                 if (db_num_rows($result) > 0) {
905                 
906                         print "<div class=\"warning\">";
907                 
908                         print "<b>Feeds with update errors:</b>";
909
910                         print "<ul class=\"nomarks\">";
911                                                 
912                         while ($line = db_fetch_assoc($result)) {
913                                 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . 
914                                         $line["last_error"];
915                         }
916
917                         print "</ul>";
918                         print "</div>";
919
920                 }
921
922                 print "<table class=\"prefAddFeed\"><tr>
923                         <td><input id=\"fadd_link\"></td>
924                         <td colspan=\"4\" align=\"right\">
925                                 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
926                 </table>";
927
928                 $result = db_query($link, "SELECT 
929                                 id,title,feed_url,substring(last_updated,1,16) as last_updated,
930                                 update_interval,purge_interval
931                         FROM 
932                                 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
933
934                 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
935                 print "<tr class=\"title\">
936                                         <td>&nbsp;</td><td>Select</td><td width=\"30%\">Title</td>
937                                         <td width=\"30%\">Link</td>
938                                         <td width=\"10%\">Update Interval</td>
939                                         <td width=\"10%\">Purge Days</td>
940                                         <td>Last updated</td></tr>";
941                 
942                 $lnum = 0;
943                 
944                 while ($line = db_fetch_assoc($result)) {
945
946                         $class = ($lnum % 2) ? "even" : "odd";
947
948                         $feed_id = $line["id"];
949
950                         $edit_feed_id = $_GET["id"];
951
952                         if ($subop == "edit" && $feed_id != $edit_feed_id) {
953                                 $class .= "Grayed";
954                         }
955
956                         print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
957
958                         $icon_file = ICONS_DIR . "/$feed_id.ico";
959
960                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
961                                         $feed_icon = "<img width=\"16\" height=\"16\"
962                                                 src=\"" . ICONS_URL . "/$feed_id.ico\">";
963                         } else {
964                                 $feed_icon = "&nbsp;";
965                         }
966                         print "<td align='center'>$feed_icon</td>";             
967
968                         $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
969                         $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
970
971                         if (!$edit_feed_id || $subop != "edit") {
972
973                                 print "<td><input onclick='toggleSelectRow(this);' 
974                                 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
975
976                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
977                                         $edit_title . "</a></td>";              
978                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
979                                         $edit_link . "</a></td>";               
980
981                                 if ($line["update_interval"] == "0")
982                                         $line["update_interval"] = "Default";
983
984                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
985                                         $line["update_interval"] . "</a></td>";
986
987                                 if ($line["purge_interval"] == "0")
988                                         $line["purge_interval"] = "Default";
989
990                                 if ($line["purge_interval"] < 0)
991                                         $line["purge_interval"] = "Disabled";
992
993                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
994                                         $line["purge_interval"] . "</a></td>";
995
996                         } else if ($feed_id != $edit_feed_id) {
997
998                                 print "<td><input disabled=\"true\" type=\"checkbox\" 
999                                         id=\"FRCHK-".$line["id"]."\"></td>";
1000
1001                                 print "<td>$edit_title</td>";           
1002                                 print "<td>$edit_link</td>";            
1003
1004                                 if ($line["update_interval"] == "0")
1005                                         $line["update_interval"] = "Default";
1006
1007                                 print "<td>" . $line["update_interval"] . "</td>";
1008
1009                                 if ($line["purge_interval"] == "0")
1010                                         $line["purge_interval"] = "Default";
1011
1012                                 if ($line["purge_interval"] < 0)
1013                                         $line["purge_interval"] = "Disabled";
1014
1015                                 print "<td>" . $line["purge_interval"] . "</td>";
1016
1017                         } else {
1018
1019                                 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1020
1021                                 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1022                                 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1023                                 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
1024                                 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
1025                                         
1026                         }
1027
1028                         if (!$line["last_updated"]) $line["last_updated"] = "Never";
1029
1030                         print "<td>" . $line["last_updated"] . "</td>";
1031                         
1032                         print "</tr>";
1033
1034                         ++$lnum;
1035                 }
1036
1037                 if ($lnum == 0) {
1038                         print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1039                 }
1040
1041                 print "</table>";
1042
1043                 print "<p>";
1044
1045                 if ($subop == "edit") {
1046                         print "Edit feed:&nbsp;
1047                                 <input type=\"submit\" class=\"button\" 
1048                                         onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1049                                 <input type=\"submit\" class=\"button\" 
1050                                         onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1051                         } else {
1052
1053                         print "
1054                                 Selection:&nbsp;
1055                         <input type=\"submit\" class=\"button\" 
1056                                 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1057                         <input type=\"submit\" class=\"button\" 
1058                                 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1059                                 
1060                         if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1061                                 print "
1062                                 <input type=\"submit\" class=\"button\" 
1063                                         onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1064                                 <input type=\"submit\" class=\"button\" 
1065                                         onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
1066                         }
1067                         print "
1068                         All feeds: 
1069                                 <input type=\"submit\" 
1070                                         class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1071                 
1072                         }
1073
1074                 print "<h3>OPML Import</h3>
1075                 <form   enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1076                         File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1077                         <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1078                                 type=\"submit\" value=\"Import\">
1079                         </form>";
1080
1081         }
1082
1083         if ($op == "pref-filters") {
1084
1085                 $subop = $_GET["subop"];
1086
1087                 if ($subop == "editSave") {
1088
1089                         $regexp = db_escape_string($_GET["r"]);
1090                         $descr = db_escape_string($_GET["d"]);
1091                         $match = db_escape_string($_GET["m"]);
1092                         $filter_id = db_escape_string($_GET["id"]);
1093                         
1094                         $result = db_query($link, "UPDATE ttrss_filters SET 
1095                                 reg_exp = '$regexp', 
1096                                 description = '$descr',
1097                                 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1098                                         description = '$match')
1099                                 WHERE id = '$filter_id'");
1100                 }
1101
1102                 if ($subop == "remove") {
1103
1104                         if (!WEB_DEMO_MODE) {
1105
1106                                 $ids = split(",", $_GET["ids"]);
1107
1108                                 foreach ($ids as $id) {
1109                                         db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1110                                         
1111                                 }
1112                         }
1113                 }
1114
1115                 if ($subop == "add") {
1116                 
1117                         if (!WEB_DEMO_MODE) {
1118
1119                                 $regexp = db_escape_string($_GET["regexp"]);
1120                                 $match = db_escape_string($_GET["match"]);
1121                                         
1122                                 $result = db_query($link,
1123                                         "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES 
1124                                                 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1125                                                         description = '$match'),'".$_SESSION["uid"]."')");
1126                         } 
1127                 }
1128
1129                 $result = db_query($link, "SELECT description 
1130                         FROM ttrss_filter_types ORDER BY description");
1131
1132                 $filter_types = array();
1133
1134                 while ($line = db_fetch_assoc($result)) {
1135                         array_push($filter_types, $line["description"]);
1136                 }
1137
1138                 print "<table class=\"prefAddFeed\"><tr>
1139                         <td><input id=\"fadd_regexp\"></td>
1140                         <td>";
1141                         print_select("fadd_match", "Title", $filter_types);     
1142         
1143                 print"</td><td colspan=\"4\" align=\"right\">
1144                                 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1145                 </table>";
1146
1147                 $result = db_query($link, "SELECT 
1148                                 id,reg_exp,description,
1149                                 (SELECT name FROM ttrss_filter_types WHERE 
1150                                         id = filter_type) as filter_type_name,
1151                                 (SELECT description FROM ttrss_filter_types 
1152                                         WHERE id = filter_type) as filter_type_descr
1153                         FROM 
1154                                 ttrss_filters
1155                         WHERE
1156                                 owner_uid = ".$_SESSION["uid"]."
1157                         ORDER by reg_exp");
1158
1159                 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1160
1161                 print "<tr class=\"title\">
1162                                         <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1163                                         <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1164                 
1165                 $lnum = 0;
1166                 
1167                 while ($line = db_fetch_assoc($result)) {
1168
1169                         $class = ($lnum % 2) ? "even" : "odd";
1170
1171                         $filter_id = $line["id"];
1172                         $edit_filter_id = $_GET["id"];
1173
1174                         if ($subop == "edit" && $filter_id != $edit_filter_id) {
1175                                 $class .= "Grayed";
1176                         }
1177
1178                         print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1179
1180                         $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1181                         $line["description"] = htmlspecialchars($line["description"]);
1182
1183                         if (!$edit_filter_id || $subop != "edit") {
1184
1185                                 if (!$line["description"]) $line["description"] = "[No description]";
1186
1187                                 print "<td><input onclick='toggleSelectRow(this);' 
1188                                 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1189
1190                                 print "<td><a href=\"javascript:editFilter($filter_id);\">" . 
1191                                         $line["reg_exp"] . "</td>";             
1192                                         
1193                                 print "<td><a href=\"javascript:editFilter($filter_id);\">" . 
1194                                         $line["description"] . "</td>";                 
1195
1196                                 print "<td>".$line["filter_type_descr"]."</td>";
1197
1198                         } else if ($filter_id != $edit_filter_id) {
1199
1200                                 if (!$line["description"]) $line["description"] = "[No description]";
1201
1202                                 print "<td><input disabled=\"true\" type=\"checkbox\" 
1203                                         id=\"FICHK-".$line["id"]."\"></td>";
1204
1205                                 print "<td>".$line["reg_exp"]."</td>";          
1206                                 print "<td>".$line["description"]."</td>";              
1207                                 print "<td>".$line["filter_type_descr"]."</td>";
1208
1209                         } else {
1210
1211                                 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1212
1213                                 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1214                                         "\"></td>";
1215
1216                                 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1217                                         "\"></td>";
1218
1219                                 print "<td>";
1220                                 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1221                                 print "</td>";
1222                                                 
1223                         }
1224                                 
1225                         
1226                         print "</tr>";
1227
1228                         ++$lnum;
1229                 }
1230
1231                 if ($lnum == 0) {
1232                         print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1233                 }
1234
1235                 print "</table>";
1236
1237                 print "<p>";
1238
1239                 if ($subop == "edit") {
1240                         print "Edit feed:
1241                                 <input type=\"submit\" class=\"button\" 
1242                                         onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1243                                 <input type=\"submit\" class=\"button\" 
1244                                         onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1245                                         
1246                 } else {
1247
1248                         print "
1249                                 Selection:
1250                         <input type=\"submit\" class=\"button\" 
1251                                 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1252                         <input type=\"submit\" class=\"button\" 
1253                                 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1254                 }
1255         }
1256
1257         if ($op == "pref-labels") {
1258
1259                 $subop = $_GET["subop"];
1260
1261                 if ($subop == "editSave") {
1262
1263                         $sql_exp = $_GET["s"];
1264                         $descr = $_GET["d"];
1265                         $label_id = db_escape_string($_GET["id"]);
1266                         
1267 //                      print "$sql_exp : $descr : $label_id";
1268                         
1269                         $result = db_query($link, "UPDATE ttrss_labels SET 
1270                                 sql_exp = '$sql_exp', 
1271                                 description = '$descr'
1272                                 WHERE id = '$label_id'");
1273                 }
1274
1275                 if ($subop == "remove") {
1276
1277                         if (!WEB_DEMO_MODE) {
1278
1279                                 $ids = split(",", $_GET["ids"]);
1280
1281                                 foreach ($ids as $id) {
1282                                         db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1283                                         
1284                                 }
1285                         }
1286                 }
1287
1288                 if ($subop == "add") {
1289                 
1290                         if (!WEB_DEMO_MODE) {
1291
1292                                 $exp = $_GET["exp"];
1293                                         
1294                                 $result = db_query($link,
1295                                         "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) 
1296                                                 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
1297                         } 
1298                 }
1299
1300                 print "<table class=\"prefAddFeed\"><tr>
1301                         <td><input id=\"ladd_expr\"></td>";
1302                         
1303                 print"<td colspan=\"4\" align=\"right\">
1304                                 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1305                 </table>";
1306
1307                 $result = db_query($link, "SELECT 
1308                                 id,sql_exp,description
1309                         FROM 
1310                                 ttrss_labels 
1311                         WHERE 
1312                                 owner_uid = ".$_SESSION["uid"]."
1313                         ORDER by description");
1314
1315                 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1316
1317                 print "<tr class=\"title\">
1318                                         <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1319                                         <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1320                                         </td>
1321                                         <td width=\"40%\">Caption</td></tr>";
1322                 
1323                 $lnum = 0;
1324                 
1325                 while ($line = db_fetch_assoc($result)) {
1326
1327                         $class = ($lnum % 2) ? "even" : "odd";
1328
1329                         $label_id = $line["id"];
1330                         $edit_label_id = $_GET["id"];
1331
1332                         if ($subop == "edit" && $label_id != $edit_label_id) {
1333                                 $class .= "Grayed";
1334                         }
1335
1336                         print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1337
1338                         $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1339                         $line["description"] = htmlspecialchars($line["description"]);
1340
1341                         if (!$edit_label_id || $subop != "edit") {
1342
1343                                 if (!$line["description"]) $line["description"] = "[No caption]";
1344
1345                                 print "<td><input onclick='toggleSelectRow(this);' 
1346                                 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1347
1348                                 print "<td><a href=\"javascript:editLabel($label_id);\">" . 
1349                                         $line["sql_exp"] . "</td>";             
1350                                         
1351                                 print "<td><a href=\"javascript:editLabel($label_id);\">" . 
1352                                         $line["description"] . "</td>";                 
1353
1354                         } else if ($label_id != $edit_label_id) {
1355
1356                                 if (!$line["description"]) $line["description"] = "[No description]";
1357
1358                                 print "<td><input disabled=\"true\" type=\"checkbox\" 
1359                                         id=\"LICHK-".$line["id"]."\"></td>";
1360
1361                                 print "<td>".$line["sql_exp"]."</td>";          
1362                                 print "<td>".$line["description"]."</td>";              
1363
1364                         } else {
1365
1366                                 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1367
1368                                 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1369                                         "\"></td>";
1370
1371                                 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1372                                         "\"></td>";
1373                                                 
1374                         }
1375                                 
1376                         
1377                         print "</tr>";
1378
1379                         ++$lnum;
1380                 }
1381
1382                 if ($lnum == 0) {
1383                         print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1384                 }
1385
1386                 print "</table>";
1387
1388                 print "<p>";
1389
1390                 if ($subop == "edit") {
1391                         print "Edit label:
1392                                 <input type=\"submit\" class=\"button\" 
1393                                         onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1394                                 <input type=\"submit\" class=\"button\" 
1395                                         onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1396                                         
1397                 } else {
1398
1399                         print "
1400                                 Selection:
1401                         <input type=\"submit\" class=\"button\" 
1402                                 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1403                         <input type=\"submit\" class=\"button\" 
1404                                 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1405                 }
1406         }
1407
1408         if ($op == "error") {
1409                 print "<div width=\"100%\" align='center'>";
1410                 $msg = $_GET["msg"];
1411                 print $msg;
1412                 print "</div>";
1413         }
1414
1415         if ($op == "help") {
1416                 print "<html><head>
1417                         <title>Tiny Tiny RSS : Help</title>
1418                         <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1419                         <script type=\"text/javascript\" src=\"functions.js\"></script>
1420                         <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1421                         </head><body>";
1422
1423                 $tid = sprintf("%d", $_GET["tid"]);
1424
1425                 /* FIXME this badly needs real implementation */
1426
1427                 print "<div class='helpResponse'>";
1428
1429                 ?>
1430
1431                 <h1>Help for SQL expressions</h1>
1432
1433                 <h2>Description</h2>
1434
1435                 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
1436                         view feed query. You can match on ttrss_entries table fields
1437                         and even use subselect to query additional information. This 
1438                         functionality is considered to be advanced and requires basic
1439                         understanding of SQL.</p>
1440                         
1441                 <h2>Examples</h2>
1442
1443                 <pre>unread = true</pre>
1444
1445                 Matches all unread articles
1446
1447                 <pre>title like '%Linux%'</pre>
1448
1449                 Matches all articles which mention Linux in the title. You get the idea.
1450
1451                 <p>See the database schema included in the distribution package for gruesome
1452                 details.</p>
1453
1454                 <?
1455
1456                 print "<div align='center'>
1457                         <a class=\"helpLink\"
1458                         href=\"javascript:window.close()\">(Close this window)</a></div>";
1459
1460                 print "</div>";
1461
1462                 print "</body></html>";
1463
1464         }
1465
1466         if ($op == "dlg") {
1467                 $id = $_GET["id"];
1468                 $param = $_GET["param"];
1469
1470                 if ($id == "quickAddFeed") {
1471                         print "Feed URL: <input 
1472                         onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1473                         id=\"qafInput\">
1474                         <input class=\"button\"
1475                                 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1476                         <input class=\"button\"
1477                                 type=\"submit\" onclick=\"javascript:closeDlg()\" 
1478                                 value=\"Cancel\">";
1479                 }
1480
1481                 if ($id == "quickDelFeed") {
1482
1483                         $param = db_escape_string($param);
1484
1485                         $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1486
1487                         if ($result) {
1488
1489                                 $f_title = db_fetch_result($result, 0, "title");
1490                 
1491                                 print "Remove current feed ($f_title)?&nbsp;
1492                                 <input class=\"button\"
1493                                         type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1494                                 <input class=\"button\"
1495                                         type=\"submit\" onclick=\"javascript:closeDlg()\" 
1496                                         value=\"Cancel\">";
1497                         } else {
1498                                 print "Error: Feed $param not found.&nbsp;
1499                                 <input class=\"button\"
1500                                         type=\"submit\" onclick=\"javascript:closeDlg()\" 
1501                                         value=\"Cancel\">";             
1502                         }
1503                 }
1504
1505                 if ($id == "search") {
1506
1507                         print "<input id=\"searchbox\" class=\"extSearch\"                      
1508                         onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1509                         onchange=\"javascript:search()\">
1510                         <select id=\"searchmodebox\">
1511                                 <option selected>All feeds</option>
1512                                 <option>This feed</option>
1513                         </select>               
1514                         <input type=\"submit\" 
1515                                 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1516                         <input class=\"button\"
1517                                 type=\"submit\" onclick=\"javascript:closeDlg()\" 
1518                                 value=\"Close\">";
1519
1520                 }
1521
1522         }
1523
1524         if ($op == "updateAllFeeds") {
1525                 update_all_feeds($link, true);                  
1526
1527                 print "<rpc-reply>";
1528                 getLabelCounters($link);
1529                 getFeedCounters($link);
1530                 getTagCounters($link);
1531                 getGlobalCounters($link);
1532                 print "</rpc-reply>";
1533
1534         }
1535
1536         if ($op == "pref-prefs") {
1537
1538                 $subop = $_REQUEST["subop"];
1539
1540                 if ($subop == "Save configuration") {
1541
1542                         if (WEB_DEMO_MODE) return;
1543
1544                         foreach (array_keys($_POST) as $pref_name) {
1545                         
1546                                 $pref_name = db_escape_string($pref_name);
1547                                 $value = db_escape_string($_POST[$pref_name]);
1548
1549                                 $result = db_query($link, "SELECT type_name 
1550                                         FROM ttrss_prefs,ttrss_prefs_types 
1551                                         WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
1552
1553                                 if (db_num_rows($result) > 0) {
1554
1555                                         $type_name = db_fetch_result($result, 0, "type_name");
1556
1557 //                                      print "$pref_name : $type_name : $value<br>";
1558
1559                                         if ($type_name == "bool") {
1560                                                 if ($value == "1") {
1561                                                         $value = "true";
1562                                                 } else {
1563                                                         $value = "false";
1564                                                 }
1565                                         } else if ($type_name == "integer") {
1566                                                 $value = sprintf("%d", $value);
1567                                         }
1568
1569 //                                      print "$pref_name : $type_name : $value<br>";
1570
1571                                         db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' 
1572                                                 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
1573
1574                                 }
1575
1576                                 header("Location: prefs.php");
1577
1578                         }
1579
1580                 } else if ($subop == "getHelp") {
1581
1582                         $pref_name = db_escape_string($_GET["pn"]);
1583
1584                         $result = db_query($link, "SELECT help_text FROM ttrss_prefs
1585                                 WHERE pref_name = '$pref_name'");
1586
1587                         if (db_num_rows($result) > 0) {
1588                                 $help_text = db_fetch_result($result, 0, "help_text");
1589                                 print $help_text;
1590                         } else {
1591                                 print "Unknown option: $pref_name";
1592                         }
1593
1594                 } else if ($subop == "Change password") {
1595
1596                         if (WEB_DEMO_MODE) return;
1597
1598                         $old_pw = $_POST["OLD_PASSWORD"];
1599                         $new_pw = $_POST["OLD_PASSWORD"];
1600
1601                         $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
1602                         $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
1603
1604                         $active_uid = $_SESSION["uid"];
1605
1606                         if ($old_pw && $new_pw) {
1607
1608                                 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
1609
1610                                 $result = db_query($link, "SELECT id FROM ttrss_users WHERE 
1611                                         id = '$active_uid' AND (pwd_hash = '$old_pw' OR 
1612                                                 pwd_hash = '$old_pw_hash')");
1613
1614                                 if (db_num_rows($result) == 1) {
1615                                         db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' 
1616                                                 WHERE id = '$active_uid'");                             
1617                                 }
1618                         }
1619
1620                         header("Location: prefs.php");
1621         
1622                 } else if ($subop == "Reset to defaults") {
1623
1624                         if (WEB_DEMO_MODE) return;
1625
1626                         if (DB_TYPE == "pgsql") {
1627                                 db_query($link,"UPDATE ttrss_user_prefs 
1628                                         SET value = ttrss_prefs.def_value 
1629                                         WHERE owner_uid = '".$_SESSION["uid"]."' AND
1630                                         ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
1631                         } else {
1632                                 db_query($link, "DELETE FROM ttrss_user_prefs 
1633                                         WHERE owner_uid = ".$_SESSION["uid"]);
1634                                 initialize_user_prefs($link, $_SESSION["uid"]);
1635                         }
1636
1637                         header("Location: prefs.php");
1638
1639                 } else {
1640
1641                         if (!SINGLE_USER_MODE) {
1642
1643                                 print "<form action=\"backend.php\" method=\"POST\">";
1644         
1645                                 print "<table width=\"100%\" class=\"prefPrefsList\">";
1646                                 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
1647         
1648                                 print "<tr><td width=\"40%\">Old password</td>";
1649                                 print "<td><input class=\"editbox\" type=\"password\"
1650                                         name=\"OLD_PASSWORD\"></td></tr>";
1651         
1652                                 print "<tr><td width=\"40%\">New password</td>";
1653                                 
1654                                 print "<td><input class=\"editbox\" type=\"password\"
1655                                         name=\"NEW_PASSWORD\"></td></tr>";
1656         
1657                                 print "</table>";
1658         
1659                                 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1660         
1661                                 print "<p><input class=\"button\" type=\"submit\" 
1662                                         value=\"Change password\" name=\"subop\">";
1663         
1664                                 print "</form>";
1665
1666                         }
1667
1668                         $result = db_query($link, "SELECT 
1669                                 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
1670                                 section_name,def_value
1671                                 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
1672                                 WHERE type_id = ttrss_prefs_types.id AND 
1673                                         section_id = ttrss_prefs_sections.id AND
1674                                         ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
1675                                         owner_uid = ".$_SESSION["uid"]."
1676                                 ORDER BY section_id,short_desc");
1677
1678                         print "<form action=\"backend.php\" method=\"POST\">";
1679
1680                         $lnum = 0;
1681
1682                         $active_section = "";
1683         
1684                         while ($line = db_fetch_assoc($result)) {
1685
1686                                 if ($active_section != $line["section_name"]) {
1687
1688                                         if ($active_section != "") {
1689                                                 print "</table>";
1690                                         }
1691
1692                                         print "<p><table width=\"100%\" class=\"prefPrefsList\">";
1693                                 
1694                                         $active_section = $line["section_name"];                                
1695                                         
1696                                         print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
1697 //                                      print "<tr class=\"title\">
1698 //                                              <td width=\"25%\">Option</td><td>Value</td></tr>";
1699
1700                                         $lnum = 0;
1701                                 }
1702
1703 //                              $class = ($lnum % 2) ? "even" : "odd";
1704
1705                                 print "<tr>";
1706
1707                                 $type_name = $line["type_name"];
1708                                 $pref_name = $line["pref_name"];
1709                                 $value = $line["value"];
1710                                 $def_value = $line["def_value"];
1711                                 $help_text = $line["help_text"];
1712
1713                                 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
1714
1715                                 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
1716                                 
1717                                 print "</td>";
1718
1719                                 print "<td>";
1720
1721                                 if ($type_name == "bool") {
1722 //                                      print_select($pref_name, $value, array("true", "false"));
1723
1724                                         if ($value == "true") {
1725                                                 $value = "Yes";
1726                                         } else {
1727                                                 $value = "No";
1728                                         }
1729
1730                                         print_radio($pref_name, $value, array("Yes", "No"));
1731                         
1732                                 } else {
1733                                         print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
1734                                 }
1735
1736                                 print "</td>";
1737
1738                                 print "</tr>";
1739
1740                                 $lnum++;
1741                         }
1742
1743                         print "</table>";
1744
1745                         print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1746
1747                         print "<p><input class=\"button\" type=\"submit\" 
1748                                 name=\"subop\" value=\"Save configuration\">";
1749                                 
1750                         print "&nbsp;<input class=\"button\" type=\"submit\" 
1751                                 name=\"subop\" value=\"Reset to defaults\"></p>";
1752
1753                         print "</form>";
1754
1755                 }
1756
1757         }
1758
1759         if ($op == "pref-users") {
1760
1761                 $subop = $_GET["subop"];
1762
1763                 if ($subop == "editSave") {
1764         
1765                         if (!WEB_DEMO_MODE) {
1766
1767                                 $login = db_escape_string($_GET["l"]);
1768                                 $uid = db_escape_string($_GET["id"]);
1769                                 $access_level = sprintf("%d", $_GET["al"]);
1770
1771                                 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
1772
1773                         }
1774                 } else if ($subop == "remove") {
1775
1776                         if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1777
1778                                 $ids = split(",", $_GET["ids"]);
1779
1780                                 foreach ($ids as $id) {
1781                                         db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
1782                                         
1783                                 }
1784                         }
1785                 } else if ($subop == "add") {
1786                 
1787                         if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1788
1789                                 $login = db_escape_string($_GET["login"]);
1790                                 $tmp_user_pwd = make_password(8);
1791                                 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1792
1793                                 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
1794                                         VALUES ('$login', '$pwd_hash', 0)");
1795
1796
1797                                 $result = db_query($link, "SELECT id FROM ttrss_users WHERE 
1798                                         login = '$login' AND pwd_hash = '$pwd_hash'");
1799
1800                                 if (db_num_rows($result) == 1) {
1801
1802                                         $new_uid = db_fetch_result($result, 0, "id");
1803
1804                                         print "<div class=\"notice\">Added user <b>".$_GET["login"].
1805                                                 "</b> with password <b>$tmp_user_pwd</b>.</div>";
1806
1807                                         initialize_user($link, $new_uid);
1808
1809                                 } else {
1810                                 
1811                                         print "<div class=\"warning\">Error while adding user <b>".
1812                                         $_GET["login"].".</b></div>";
1813
1814                                 }
1815                         } 
1816                 } else if ($subop == "resetPass") {
1817
1818                         if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1819
1820                                 $uid = db_escape_string($_GET["id"]);
1821
1822                                 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
1823
1824                                 $login = db_fetch_result($result, 0, "login");
1825                                 $tmp_user_pwd = make_password(8);
1826                                 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1827
1828                                 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
1829                                         WHERE id = '$uid'");
1830
1831                                 print "<div class=\"notice\">Changed password of 
1832                                         user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";                             
1833
1834                         }
1835                 }
1836
1837                 print "<table class=\"prefAddFeed\"><tr>
1838                         <td><input id=\"uadd_box\"></td>";
1839                         
1840                 print"<td colspan=\"4\" align=\"right\">
1841                                 <a class=\"button\" href=\"javascript:addUser()\">Add user</a></td></tr>
1842                 </table>";
1843
1844                 $result = db_query($link, "SELECT 
1845                                 id,login,access_level,last_login
1846                         FROM 
1847                                 ttrss_users
1848                         ORDER by login");
1849
1850                 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
1851
1852                 print "<tr class=\"title\">
1853                                         <td width=\"5%\">Select</td>
1854                                         <td width='30%'>Username</td>
1855                                         <td width='30%'>Access Level</td>
1856                                         <td width='30%'>Last login</td></tr>";
1857                 
1858                 $lnum = 0;
1859                 
1860                 while ($line = db_fetch_assoc($result)) {
1861
1862                         $class = ($lnum % 2) ? "even" : "odd";
1863
1864                         $uid = $line["id"];
1865                         $edit_uid = $_GET["id"];
1866
1867                         if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
1868                                 $class .= "Grayed";
1869                         }
1870                 
1871                         print "<tr class=\"$class\" id=\"UMRR-$uid\">";
1872
1873                         $line["login"] = htmlspecialchars($line["login"]);
1874
1875                         if ($uid == $_SESSION["uid"]) {
1876
1877                                 print "<td><input disabled=\"true\" type=\"checkbox\" 
1878                                         id=\"UMCHK-".$line["id"]."\"></td>";
1879
1880                                 print "<td>".$line["login"]."</td>";            
1881                                 print "<td>".$line["access_level"]."</td>";             
1882
1883                         } else if (!$edit_uid || $subop != "edit") {
1884
1885                                 print "<td><input onclick='toggleSelectRow(this);' 
1886                                 type=\"checkbox\" id=\"UMCHK-".$line["id"]."\"></td>";
1887
1888                                 print "<td><a href=\"javascript:editUser($uid);\">" . 
1889                                         $line["login"] . "</td>";               
1890                                         
1891                                 print "<td><a href=\"javascript:editUser($uid);\">" . 
1892                                         $line["access_level"] . "</td>";                        
1893
1894                         } else if ($uid != $edit_uid) {
1895
1896                                 print "<td><input disabled=\"true\" type=\"checkbox\" 
1897                                         id=\"UMCHK-".$line["id"]."\"></td>";
1898
1899                                 print "<td>".$line["login"]."</td>";            
1900                                 print "<td>".$line["access_level"]."</td>";             
1901
1902                         } else {
1903
1904                                 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1905
1906                                 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
1907                                         "\"></td>";
1908
1909                                 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
1910                                         "\"></td>";
1911                                                 
1912                         }
1913                                 
1914                         print "<td>".$line["last_login"]."</td>";               
1915                 
1916                         print "</tr>";
1917
1918                         ++$lnum;
1919                 }
1920
1921                 print "</table>";
1922
1923                 print "<p>";
1924
1925                 if ($subop == "edit") {
1926                         print "Edit label:
1927                                 <input type=\"submit\" class=\"button\" 
1928                                         onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
1929                                 <input type=\"submit\" class=\"button\" 
1930                                         onclick=\"javascript:userEditSave()\" value=\"Save\">";
1931                                         
1932                 } else {
1933
1934                         print "
1935                                 Selection:
1936                         <input type=\"submit\" class=\"button\" 
1937                                 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
1938                         <input type=\"submit\" class=\"button\" 
1939                                 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
1940                         <input type=\"submit\" class=\"button\" 
1941                                 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
1942                         <input type=\"submit\" class=\"button\" 
1943                                 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
1944
1945                 }
1946         }
1947
1948         if ($op == "user-details") {
1949
1950                 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
1951                         return;
1952                 }
1953                           
1954                 print "<html><head>
1955                         <title>Tiny Tiny RSS : User Details</title>
1956                         <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1957                         <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1958                         </head><body>";
1959
1960                 $uid = sprintf("%d", $_GET["id"]);
1961
1962                 /* FIXME this badly needs real implementation */
1963
1964                 print "<div class='userDetails'>";
1965
1966                 $result = db_query($link, "SELECT login,last_login,access_level
1967                         FROM ttrss_users 
1968                         WHERE id = '$uid'");
1969                         
1970                 if (db_num_rows($result) == 0) {
1971                         print "<h1>User not found</h1>";
1972                         return;
1973                 }
1974                 
1975                 print "<h1>User Details</h1>";
1976
1977                 print "<table width='100%'>";
1978
1979                 $login = db_fetch_result($result, 0, "login");
1980                 $last_login = db_fetch_result($result, 0, "last_login");
1981                 $access_level = db_fetch_result($result, 0, "access_level");
1982
1983                 print "<tr><td>Username</td><td>$login</td></tr>";
1984                 print "<tr><td>Access level</td><td>$access_level</td></tr>";
1985                 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
1986
1987                 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
1988                         WHERE owner_uid = '$uid'");
1989
1990                 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1991
1992                 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
1993
1994                 $result = db_query($link, "SELECT 
1995                         SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size 
1996                         FROM ttrss_entries WHERE owner_uid = '$uid'");
1997
1998                 $db_size = db_fetch_result($result, 0, "db_size");
1999
2000                 print "<tr><td>Approx. DB size</td><td>$db_size bytes</td></tr>";
2001
2002                 print "</table>";
2003
2004                 print "<h1>Subscribed feeds</h1>";
2005
2006                 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2007                         WHERE owner_uid = '$uid'");
2008
2009                 print "<ul class=\"nomarks\">";
2010
2011                 while ($line = db_fetch_assoc($result)) {
2012
2013                         $icon_file = ICONS_URL."/".$line["id"].".ico";
2014
2015                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
2016                                 $feed_icon = "<img class=\"feedIcon\" src=\"$icon_file\">";
2017                         } else {
2018                                 $feed_icon = "<img class=\"feedIcon\" src=\"images/blank_icon.gif\">";
2019                         }
2020
2021                         print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2022                 }
2023
2024                 print "</ul>";
2025
2026                 print "<p align='center'>
2027                         <a      href=\"javascript:window.close()\">(Close this window)</a></p>";
2028
2029                 print "</div>";
2030
2031                 print "</body></html>";
2032
2033         }
2034
2035         db_close($link);
2036 ?>
2037
2038 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
2039