]> git.wh0rd.org - tt-rss.git/blob - backend.php
headlines: xml output mode (omode=xml)
[tt-rss.git] / backend.php
1 <?
2 session_start();
3
4 if ($_GET["debug"]) {
5 define('DEFAULT_ERROR_LEVEL', E_ALL);
6 } else {
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
8 }
9
10 error_reporting(DEFAULT_ERROR_LEVEL);
11
12 $op = $_REQUEST["op"];
13
14 if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
15 header("Content-Type: application/xml");
16 }
17
18 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
19
20 if ($op == "rpc") {
21 print "<error error-code=\"6\"/>";
22 }
23 exit;
24 }
25
26 if (!$op) {
27 print "<error error-code=\"7\"/>";
28 exit;
29 }
30
31 define('SCHEMA_VERSION', 2);
32
33 require_once "sanity_check.php";
34 require_once "config.php";
35 require_once "db.php";
36 require_once "db-prefs.php";
37 require_once "functions.php";
38 require_once "magpierss/rss_fetch.inc";
39
40 $script_started = getmicrotime();
41
42 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
43
44 if (!$link) {
45 if (DB_TYPE == "mysql") {
46 print mysql_error();
47 }
48 // PG seems to display its own errors just fine by default.
49 return;
50 }
51
52 if (DB_TYPE == "pgsql") {
53 pg_query("set client_encoding = 'utf-8'");
54 }
55
56 $fetch = $_GET["fetch"];
57
58 function getAllCounters($link) {
59 getLabelCounters($link);
60 getFeedCounters($link);
61 getTagCounters($link);
62 getGlobalCounters($link);
63 }
64
65 /* FIXME this needs reworking */
66
67 function getGlobalCounters($link) {
68 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
69 WHERE unread = true AND
70 ttrss_user_entries.ref_id = ttrss_entries.id AND
71 owner_uid = " . $_SESSION["uid"]);
72 $c_id = db_fetch_result($result, 0, "c_id");
73 print "<counter id='global-unread' counter='$c_id'/>";
74 }
75
76 function getTagCounters($link) {
77
78 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
79 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
80 ttrss_user_entries.ref_id = ttrss_entries.id AND
81 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
82 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
83 UNION
84 select tag_name,0 as count FROM ttrss_tags
85 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
86
87 $tags = array();
88
89 while ($line = db_fetch_assoc($result)) {
90 $tags[$line["tag_name"]] += $line["count"];
91 }
92
93 foreach (array_keys($tags) as $tag) {
94 $unread = $tags[$tag];
95
96 $tag = htmlspecialchars($tag);
97 print "<tag id=\"$tag\" counter=\"$unread\"/>";
98 }
99 }
100
101 function getLabelCounters($link) {
102
103 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
104 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
105 unread = true AND owner_uid = ".$_SESSION["uid"]);
106
107 $count = db_fetch_result($result, 0, "count");
108
109 print "<label id=\"-1\" counter=\"$count\"/>";
110
111 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
112 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
113
114 while ($line = db_fetch_assoc($result)) {
115
116 $id = -$line["id"] - 11;
117
118 error_reporting (0);
119
120 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
121 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
122 ttrss_user_entries.ref_id = ttrss_entries.id AND
123 owner_uid = ".$_SESSION["uid"]);
124
125 $count = db_fetch_result($tmp_result, 0, "count");
126
127 print "<label id=\"$id\" counter=\"$count\"/>";
128
129 error_reporting (DEFAULT_ERROR_LEVEL);
130
131 }
132 }
133
134 function getFeedCounter($link, $id) {
135
136 $result = db_query($link, "SELECT
137 count(id) as count FROM ttrss_entries,ttrss_user_entries
138 WHERE feed_id = '$id' AND unread = true
139 AND ttrss_user_entries.ref_id = ttrss_entries.id");
140
141 $count = db_fetch_result($result, 0, "count");
142
143 print "<feed id=\"$id\" counter=\"$count\"/>";
144 }
145
146 function getFeedCounters($link) {
147
148 $result = db_query($link, "SELECT id,
149 (SELECT count(id)
150 FROM ttrss_entries,ttrss_user_entries
151 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
152 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
153 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
154
155 while ($line = db_fetch_assoc($result)) {
156
157 $id = $line["id"];
158 $count = $line["count"];
159
160 print "<feed id=\"$id\" counter=\"$count\"/>";
161 }
162 }
163
164 function outputFeedList($link, $tags = false) {
165
166 print "<html><head>
167 <title>Tiny Tiny RSS : Feedlist</title>
168 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
169
170 $user_theme = $_SESSION["theme"];
171 if ($user_theme) {
172 print "<link rel=\"stylesheet\" type=\"text/css\"
173 href=\"themes/$user_theme/theme.css\">";
174 }
175
176 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
177 print "<link rel=\"stylesheet\" type=\"text/css\"
178 href=\"tt-rss_compact.css\"/>";
179 } else {
180 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
181 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
182 }
183
184 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
185 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
186 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
187 </head><body onload=\"init()\">";
188
189 print "<ul class=\"feedList\" id=\"feedList\">";
190
191 $owner_uid = $_SESSION["uid"];
192
193 if (!$tags) {
194
195 /* virtual feeds */
196
197 if (get_pref($link, 'ENABLE_FEED_CATS')) {
198 print "<li class=\"feedCat\">Special</li>";
199 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
200 }
201
202 $result = db_query($link, "SELECT count(id) as num_starred
203 FROM ttrss_entries,ttrss_user_entries
204 WHERE marked = true AND
205 ttrss_user_entries.ref_id = ttrss_entries.id AND
206 unread = true AND owner_uid = '$owner_uid'");
207 $num_starred = db_fetch_result($result, 0, "num_starred");
208
209 $class = "virt";
210
211 if ($num_starred > 0) $class .= "Unread";
212
213 printFeedEntry(-1, $class, "Starred articles", $num_starred,
214 "images/mark_set.png", $link);
215
216 if (get_pref($link, 'ENABLE_FEED_CATS')) {
217 print "</li></ul>";
218 }
219
220 if (get_pref($link, 'ENABLE_LABELS')) {
221
222 $result = db_query($link, "SELECT id,sql_exp,description FROM
223 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
224
225 if (db_num_rows($result) > 0) {
226 if (get_pref($link, 'ENABLE_FEED_CATS')) {
227 print "<li class=\"feedCat\">Labels</li>";
228 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
229 } else {
230 print "<li><hr></li>";
231 }
232 }
233
234 while ($line = db_fetch_assoc($result)) {
235
236 error_reporting (0);
237
238 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
239 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
240 ttrss_user_entries.ref_id = ttrss_entries.id
241 AND owner_uid = '$owner_uid'");
242
243 $count = db_fetch_result($tmp_result, 0, "count");
244
245 $class = "label";
246
247 if ($count > 0) {
248 $class .= "Unread";
249 }
250
251 error_reporting (DEFAULT_ERROR_LEVEL);
252
253 printFeedEntry(-$line["id"]-11,
254 $class, $line["description"], $count, "images/label.png", $link);
255
256 }
257
258 if (db_num_rows($result) > 0) {
259 if (get_pref($link, 'ENABLE_FEED_CATS')) {
260 print "</li></ul>";
261 }
262 }
263
264 }
265
266 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
267 print "<li><hr></li>";
268 // }
269
270 if (get_pref($link, 'ENABLE_FEED_CATS')) {
271 $order_by_qpart = "category,title";
272 } else {
273 $order_by_qpart = "title";
274 }
275
276 $result = db_query($link, "SELECT *,
277 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
278 WHERE feed_id = ttrss_feeds.id AND
279 ttrss_user_entries.ref_id = ttrss_entries.id AND
280 owner_uid = '$owner_uid') AS total,
281 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
282 WHERE feed_id = ttrss_feeds.id AND unread = true
283 AND ttrss_user_entries.ref_id = ttrss_entries.id
284 AND owner_uid = '$owner_uid') as unread,
285 (SELECT title FROM ttrss_feed_categories
286 WHERE id = cat_id) AS category
287 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart");
288
289 $actid = $_GET["actid"];
290
291 /* real feeds */
292
293 $lnum = 0;
294
295 $total_unread = 0;
296
297 $category = "";
298
299 while ($line = db_fetch_assoc($result)) {
300
301 $feed = $line["title"];
302 $feed_id = $line["id"];
303
304 $subop = $_GET["subop"];
305
306 $total = $line["total"];
307 $unread = $line["unread"];
308
309 $tmp_category = $line["category"];
310
311 if (!$tmp_category) {
312 $tmp_category = "Uncategorized";
313 }
314
315 // $class = ($lnum % 2) ? "even" : "odd";
316
317 $class = "feed";
318
319 if ($unread > 0) $class .= "Unread";
320
321 if ($actid == $feed_id) {
322 $class .= "Selected";
323 }
324
325 $total_unread += $unread;
326
327 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
328
329 if ($category) {
330 print "</li></ul></li>";
331 }
332
333 $category = $tmp_category;
334
335 print "<li class=\"feedCat\">$category</li>";
336 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
337 }
338
339 printFeedEntry($feed_id, $class, $feed, $unread,
340 "icons/$feed_id.ico", $link);
341
342 ++$lnum;
343 }
344
345 } else {
346
347 // tags
348
349 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
350 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
351 post_int_id = ttrss_user_entries.int_id AND
352 unread = true AND ref_id = ttrss_entries.id
353 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
354 UNION
355 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
356 ORDER BY tag_name");
357
358 $tags = array();
359
360 while ($line = db_fetch_assoc($result)) {
361 $tags[$line["tag_name"]] += $line["count"];
362 }
363
364 foreach (array_keys($tags) as $tag) {
365
366 $unread = $tags[$tag];
367
368 $class = "tag";
369
370 if ($unread > 0) {
371 $class .= "Unread";
372 }
373
374 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
375
376 }
377
378 }
379
380 if (db_num_rows($result) == 0) {
381 if ($tags) {
382 $what = "tags";
383 } else {
384 $what = "feeds";
385 }
386 print "<li>No $what to display.</li>";
387 }
388
389 print "</ul>";
390
391 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
392
393 }
394
395
396 if ($op == "rpc") {
397
398 $subop = $_GET["subop"];
399
400 if ($subop == "getLabelCounters") {
401 $aid = $_GET["aid"];
402 print "<rpc-reply>";
403 getLabelCounters($link);
404 if ($aid) {
405 getFeedCounter($link, $aid);
406 }
407 print "</rpc-reply>";
408 }
409
410 if ($subop == "getFeedCounters") {
411 print "<rpc-reply>";
412 getFeedCounters($link);
413 print "</rpc-reply>";
414 }
415
416 if ($subop == "getAllCounters") {
417 print "<rpc-reply>";
418 getAllCounters($link);
419 print "</rpc-reply>";
420 }
421
422 if ($subop == "mark") {
423 $mark = $_GET["mark"];
424 $id = db_escape_string($_GET["id"]);
425
426 if ($mark == "1") {
427 $mark = "true";
428 } else {
429 $mark = "false";
430 }
431
432 // FIXME this needs collision testing
433
434 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
435 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
436 }
437
438 if ($subop == "updateFeed") {
439 $feed_id = db_escape_string($_GET["feed"]);
440
441 $result = db_query($link,
442 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
443 AND owner_uid = " . $_SESSION["uid"]);
444
445 if (db_num_rows($result) > 0) {
446 $feed_url = db_fetch_result($result, 0, "feed_url");
447 update_rss_feed($link, $feed_url, $feed_id);
448 }
449
450 print "<rpc-reply>";
451 getFeedCounter($link, $feed_id);
452 print "</rpc-reply>";
453
454 return;
455 }
456
457 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
458
459 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
460
461 $omode = $_GET["omode"];
462
463 if (!$omode) $omode = "tfl";
464
465 print "<rpc-reply>";
466 if (strchr($omode, "l")) getLabelCounters($link);
467 if (strchr($omode, "f")) getFeedCounters($link);
468 if (strchr($omode, "t")) getTagCounters($link);
469 getGlobalCounters($link);
470 print "</rpc-reply>";
471 }
472
473 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
474 if ($subop == "catchupSelected") {
475
476 $ids = split(",", $_GET["ids"]);
477
478 $cmode = sprintf("%d", $_GET["cmode"]);
479
480 foreach ($ids as $id) {
481
482 if ($cmode == 0) {
483 db_query($link, "UPDATE ttrss_user_entries SET
484 unread = false,last_read = NOW()
485 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
486 } else if ($cmode == 1) {
487 db_query($link, "UPDATE ttrss_user_entries SET
488 unread = true
489 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
490 } else {
491 db_query($link, "UPDATE ttrss_user_entries SET
492 unread = NOT unread,last_read = NOW()
493 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
494 }
495 }
496 print "<rpc-reply>";
497 getAllCounters($link);
498 print "</rpc-reply>";
499 }
500
501 if ($subop == "markSelected") {
502
503 $ids = split(",", $_GET["ids"]);
504
505 $cmode = sprintf("%d", $_GET["cmode"]);
506
507 foreach ($ids as $id) {
508
509 if ($cmode == 0) {
510 db_query($link, "UPDATE ttrss_user_entries SET
511 marked = false
512 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
513 } else if ($cmode == 1) {
514 db_query($link, "UPDATE ttrss_user_entries SET
515 marked = true
516 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
517 } else {
518 db_query($link, "UPDATE ttrss_user_entries SET
519 marked = NOT marked
520 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
521 }
522 }
523 print "<rpc-reply>";
524 getAllCounters($link);
525 print "</rpc-reply>";
526 }
527
528 if ($subop == "sanityCheck") {
529
530 $error_code = 0;
531
532 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
533
534 $schema_version = db_fetch_result($result, 0, "schema_version");
535
536 if ($schema_version != SCHEMA_VERSION) {
537 $error_code = 5;
538 }
539
540 print "<error error-code='$error_code'/>";
541 }
542
543 if ($subop == "globalPurge") {
544
545 print "<rpc-reply>";
546 global_purge_old_posts($link, true);
547 print "</rpc-reply>";
548
549 }
550
551 }
552
553 if ($op == "feeds") {
554
555 $tags = $_GET["tags"];
556
557 $subop = $_GET["subop"];
558
559 if ($subop == "catchupAll") {
560 db_query($link, "UPDATE ttrss_user_entries SET
561 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
562 }
563
564 outputFeedList($link, $tags);
565
566 }
567
568 if ($op == "view") {
569
570 $id = $_GET["id"];
571 $feed_id = $_GET["feed"];
572
573 $result = db_query($link, "UPDATE ttrss_user_entries
574 SET unread = false,last_read = NOW()
575 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
576
577 $addheader = $_GET["addheader"];
578
579 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
580 SUBSTRING(updated,1,16) as updated,
581 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
582 FROM ttrss_entries,ttrss_user_entries
583 WHERE id = '$id' AND ref_id = id");
584
585 if ($addheader) {
586 print "<html><head>
587 <title>Tiny Tiny RSS : Article $id</title>
588 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
589
590 $user_theme = $_SESSION["theme"];
591 if ($user_theme) {
592 print "<link rel=\"stylesheet\" type=\"text/css\"
593 href=\"themes/$user_theme/theme.css\">";
594 }
595
596 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
597 print "<link rel=\"stylesheet\" type=\"text/css\"
598 href=\"tt-rss_compact.css\"/>";
599 } else {
600 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
601 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
602 }
603
604 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
605 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
606 </head><body>";
607 }
608
609 if ($result) {
610
611 $line = db_fetch_assoc($result);
612
613 if ($line["icon_url"]) {
614 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
615 } else {
616 $feed_icon = "&nbsp;";
617 }
618
619 if ($line["comments"] && $line["link"] != $line["comments"]) {
620 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
621 } else {
622 $entry_comments = "";
623 }
624
625 print "<div class=\"postReply\">";
626
627 print "<div class=\"postHeader\"><table width=\"100%\">";
628
629 print "<tr><td>" . $line["title"] . "</td>";
630
631 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
632 strtotime($line["updated"]));
633
634 print "<td class=\"postDate\">$parsed_updated</td>";
635
636 print "</tr>";
637
638 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
639 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
640 ORDER BY tag_name");
641
642 $tags_str = "";
643
644 while ($tmp_line = db_fetch_assoc($tmp_result)) {
645 $tag = $tmp_line["tag_name"];
646 $tags_str .= "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
647 }
648
649 $tags_str = preg_replace("/, $/", "", $tags_str);
650
651 print "<tr><td width='50%'>
652 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
653 $entry_comments</td>
654 <td align=\"right\">$tags_str</td></tr>";
655
656 /* if ($tags_str) {
657 print "<tr><td><b>Tags:</b></td>
658 <td width='100%'>$tags_str</td></tr>";
659 } */
660
661 print "</table></div>";
662
663 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
664 print "<div class=\"postContent\">" . $line["content"] . "</div>";
665
666 print "</div>";
667
668 print "<script type=\"text/javascript\">
669 update_all_counters('$feed_id');
670 </script>";
671 }
672
673 if ($addheader) {
674 print "</body></html>";
675 }
676 }
677
678 if ($op == "viewfeed") {
679
680 $feed = $_GET["feed"];
681 $skip = $_GET["skip"];
682 $subop = $_GET["subop"];
683 $view_mode = $_GET["view"];
684 $addheader = $_GET["addheader"];
685 $limit = $_GET["limit"];
686 $omode = $_GET["omode"];
687
688 if ($omode == "xml") {
689 header("Content-Type: application/xml");
690 }
691
692 if (!$feed) {
693 return;
694 }
695
696 if (!$skip) $skip = 0;
697
698 if ($subop == "undefined") $subop = "";
699
700 if ($addheader) {
701 print "<html><head>
702 <title>Tiny Tiny RSS : Feed $feed</title>
703 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
704
705 $user_theme = $_SESSION["theme"];
706 if ($user_theme) {
707 print "<link rel=\"stylesheet\" type=\"text/css\"
708 href=\"themes/$user_theme/theme.css\">";
709 }
710
711 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
712 print "<link rel=\"stylesheet\"
713 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
714
715 } else {
716 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
717 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
718 }
719
720 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
721 <script type=\"text/javascript\" src=\"functions.js\"></script>
722 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
723 </head><body onload='init()'>";
724 }
725
726 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
727
728 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
729 WHERE id = '$feed'");
730
731 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
732
733 update_rss_feed($link, $feed_url, $feed);
734
735 }
736
737 if ($subop == "MarkAllRead") {
738
739 if (sprintf("%d", $feed) != 0) {
740
741 if ($feed > 0) {
742 db_query($link, "UPDATE ttrss_user_entries
743 SET unread = false,last_read = NOW()
744 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
745
746 } else if ($feed < 0 && $feed > -10) { // special, like starred
747
748 if ($feed == -1) {
749 db_query($link, "UPDATE ttrss_user_entries
750 SET unread = false,last_read = NOW()
751 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
752 }
753
754 } else if ($feed < -10) { // label
755
756 // TODO make this more efficient
757
758 $label_id = -$feed - 11;
759
760 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
761 WHERE id = '$label_id'");
762
763 if ($tmp_result) {
764 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
765
766 db_query($link, "BEGIN");
767
768 $tmp2_result = db_query($link,
769 "SELECT
770 int_id
771 FROM
772 ttrss_user_entries,ttrss_entries
773 WHERE
774 ref_id = id AND
775 $sql_exp AND
776 owner_uid = " . $_SESSION["uid"]);
777
778 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
779 db_query($link, "UPDATE
780 ttrss_user_entries
781 SET
782 unread = false, last_read = NOW()
783 WHERE
784 int_id = " . $tmp_line["int_id"]);
785 }
786
787 db_query($link, "COMMIT");
788
789 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
790 SET unread = false,last_read = NOW()
791 WHERE $sql_exp
792 AND ref_id = id
793 AND owner_uid = ".$_SESSION["uid"]); */
794 }
795 }
796 } else { // tag
797 db_query($link, "BEGIN");
798
799 $tag_name = db_escape_string($feed);
800
801 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
802 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
803
804 while ($line = db_fetch_assoc($result)) {
805 db_query($link, "UPDATE ttrss_user_entries SET
806 unread = false, last_read = NOW()
807 WHERE int_id = " . $line["post_int_id"]);
808 }
809 db_query($link, "COMMIT");
810 }
811
812 }
813
814 $search = $_GET["search"];
815
816 $search_mode = $_GET["smode"];
817
818 if ($search) {
819 $search_query_part = "(upper(title) LIKE upper('%$search%')
820 OR content LIKE '%$search%') AND";
821 } else {
822 $search_query_part = "";
823 }
824
825 $view_query_part = "";
826
827 if ($view_mode == "Starred") {
828 $view_query_part = " marked = true AND ";
829 }
830
831 if ($view_mode == "Unread") {
832 $view_query_part = " unread = true AND ";
833 }
834
835 if ($view_mode == "Unread or Starred") {
836 $view_query_part = " (unread = true OR marked = true) AND ";
837 }
838
839 if ($view_mode == "Unread or Updated") {
840 $view_query_part = " (unread = true OR last_read is NULL) AND ";
841 }
842
843 /* $result = db_query($link, "SELECT count(id) AS total_entries
844 FROM ttrss_entries WHERE
845 $search_query_part
846 feed_id = '$feed'");
847
848 $total_entries = db_fetch_result($result, 0, "total_entries"); */
849
850 /* $result = db_query("SELECT count(id) AS unread_entries
851 FROM ttrss_entries WHERE
852 $search_query_part
853 unread = true AND
854 feed_id = '$feed'");
855
856 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
857
858 if ($limit && $limit != "All") {
859 $limit_query_part = "LIMIT " . $limit;
860 }
861
862 $vfeed_query_part = "";
863
864 // override query strategy and enable feed display when searching globally
865 if ($search && $search_mode == "All feeds") {
866 $query_strategy_part = "id > 0";
867 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
868 id = feed_id) as feed_title,";
869 } else if (sprintf("%d", $feed) == 0) {
870 $query_strategy_part = "ttrss_entries.id > 0";
871 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
872 id = feed_id) as feed_title,";
873 } else if ($feed >= 0) {
874 $query_strategy_part = "feed_id = '$feed'";
875 } else if ($feed == -1) { // starred virtual feed
876 $query_strategy_part = "marked = true";
877 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
878 id = feed_id) as feed_title,";
879 } else if ($feed <= -10) { // labels
880 $label_id = -$feed - 11;
881
882 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
883 WHERE id = '$label_id'");
884
885 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
886
887 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
888 id = feed_id) as feed_title,";
889 } else {
890 $query_strategy_part = "id > 0"; // dumb
891 }
892
893 $order_by = "updated DESC";
894
895 // if ($feed < -10) {
896 // $order_by = "feed_id,updated DESC";
897 // }
898
899 $feed_title = "";
900
901 if ($search && $search_mode == "All feeds") {
902 $feed_title = "Search results";
903 } else if (sprintf("%d", $feed) == 0) {
904 $feed_title = $feed;
905 } else if ($feed > 0) {
906 $result = db_query($link, "SELECT title,site_url FROM ttrss_feeds
907 WHERE id = '$feed'");
908
909 $feed_title = db_fetch_result($result, 0, "title");
910 $feed_site_url = db_fetch_result($result, 0, "site_url");
911
912 } else if ($feed == -1) {
913 $feed_title = "Starred articles";
914 } else if ($feed < -10) {
915 $label_id = -$feed - 11;
916 $result = db_query($link, "SELECT description FROM ttrss_labels
917 WHERE id = '$label_id'");
918 $feed_title = db_fetch_result($result, 0, "description");
919 } else {
920 $feed_title = "?";
921 }
922
923 if ($feed < -10) error_reporting (0);
924
925 if (sprintf("%d", $feed) != 0) {
926
927 if ($feed > 0) {
928 $feed_kind = "Feeds";
929 } else {
930 $feed_kind = "Labels";
931 }
932
933 if (!$vfeed_query_part) {
934 $content_query_part = "content as content_preview,";
935 } else {
936 $content_query_part = "";
937 }
938
939 $result = db_query($link, "SELECT
940 id,title,
941 SUBSTRING(updated,1,16) as updated,
942 unread,feed_id,marked,link,last_read,
943 SUBSTRING(last_read,1,19) as last_read_noms,
944 $vfeed_query_part
945 $content_query_part
946 SUBSTRING(updated,1,19) as updated_noms
947 FROM
948 ttrss_entries,ttrss_user_entries
949 WHERE
950 ttrss_user_entries.ref_id = ttrss_entries.id AND
951 owner_uid = '".$_SESSION["uid"]."' AND
952 $search_query_part
953 $view_query_part
954 $query_strategy_part ORDER BY $order_by
955 $limit_query_part");
956
957 } else {
958 // browsing by tag
959
960 $feed_kind = "Tags";
961
962 $result = db_query($link, "SELECT
963 ttrss_entries.id as id,title,
964 SUBSTRING(updated,1,16) as updated,
965 unread,feed_id,
966 marked,link,last_read,
967 SUBSTRING(last_read,1,19) as last_read_noms,
968 $vfeed_query_part
969 $content_query_part
970 SUBSTRING(updated,1,19) as updated_noms
971 FROM
972 ttrss_entries,ttrss_user_entries,ttrss_tags
973 WHERE
974 ref_id = ttrss_entries.id AND
975 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
976 post_int_id = int_id AND tag_name = '$feed' AND
977 $view_query_part
978 $search_query_part
979 $query_strategy_part ORDER BY $order_by
980 $limit_query_part");
981 }
982
983 if (!$result) {
984 if ($omode != "xml") {
985 print "<div align='center'>
986 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
987 return;
988 } else {
989 print "<error error-code=\"8\"/>";
990
991 }
992 }
993
994 if (db_num_rows($result) > 0) {
995
996 if ($omode != "xml") {
997
998 print "<table class=\"headlinesSubToolbar\"
999 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1000
1001 print "<td class=\"headlineActions\">
1002 Select:
1003 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1004 'RROW-', 'RCHK-', true)\">All</a>,
1005 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1006 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
1007 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1008 'RROW-', 'RCHK-', false)\">None</a>
1009 &nbsp;&nbsp;
1010 Toggle: <a href=\"javascript:toggleUnread()\">Unread</a>,
1011 <a href=\"javascript:toggleStarred()\">Starred</a>";
1012
1013 print "</td>";
1014
1015 print "<td class=\"headlineTitle\">";
1016
1017 if ($feed_site_url) {
1018 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
1019 } else {
1020 print $feed_title;
1021 }
1022
1023 print "</td>";
1024 print "</tr></table>";
1025
1026 print "<table class=\"headlinesList\" id=\"headlinesList\"
1027 cellspacing=\"0\" width=\"100%\">";
1028
1029 } else {
1030 print "<headlines feed=\"$feed\" title=\"$feed_title\" site_url=\"$feed_site_url\">";
1031 }
1032
1033 $lnum = 0;
1034
1035 error_reporting (DEFAULT_ERROR_LEVEL);
1036
1037 $num_unread = 0;
1038
1039 while ($line = db_fetch_assoc($result)) {
1040
1041 $class = ($lnum % 2) ? "even" : "odd";
1042
1043 $id = $line["id"];
1044 $feed_id = $line["feed_id"];
1045
1046 if ($line["last_read"] == "" &&
1047 ($line["unread"] != "t" && $line["unread"] != "1")) {
1048
1049 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1050 alt=\"Updated\">";
1051 } else {
1052 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1053 alt=\"Updated\">";
1054 }
1055
1056 if ($line["unread"] == "t" || $line["unread"] == "1") {
1057 $class .= "Unread";
1058 ++$num_unread;
1059 $is_unread = 'true';
1060 } else {
1061 $is_unread = 'false';
1062 }
1063
1064 if ($line["marked"] == "t" || $line["marked"] == "1") {
1065 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1066 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
1067 } else {
1068 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1069 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
1070 }
1071
1072 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
1073 $line["title"] . "</a>";
1074
1075 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1076 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1077 } else {
1078 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1079 $updated_fmt = date($short_date, strtotime($line["updated"]));
1080 }
1081
1082 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1083 $content_preview = truncate_string(strip_tags($line["content_preview"]), 101);
1084 }
1085
1086 if ($omode != "xml") {
1087
1088 print "<tr class='$class' id='RROW-$id'>";
1089 // onclick=\"javascript:view($id,$feed_id)\">
1090
1091 print "<td class='hlUpdatePic'>$update_pic</td>";
1092
1093 print "<td class='hlSelectRow'>
1094 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1095 class=\"feedCheckBox\" id=\"RCHK-$id\">
1096 </td>";
1097
1098 print "<td class='hlMarkedPic'>$marked_pic</td>";
1099
1100 if ($line["feed_title"]) {
1101 print "<td class='hlContent'>$content_link</td>";
1102 print "<td class='hlFeed'>
1103 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
1104 } else {
1105 print "<td class='hlContent'>";
1106
1107 print "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
1108 $line["title"];
1109
1110 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1111
1112 if ($content_preview) {
1113 print "<span class=\"contentPreview\"> - $content_preview</span>";
1114 }
1115 }
1116
1117 print "</a>";
1118 print "</td>";
1119 }
1120
1121 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1122
1123 print "</tr>";
1124
1125 } else {
1126
1127 print "<entry unread='$is_unread' id='$id'>";
1128 print "<title><![CDATA[" . $line["title"] . "]]></title>";
1129 print "<link>" . $line["link"] . "</link>";
1130 print "<updated>$updated_fmt</updated>";
1131 if ($content_preview) {
1132 print "<preview><![CDATA[ $content_preview ]]></preview>";
1133 }
1134
1135 if ($line["feed_title"]) {
1136 print "<feed id='$feed_id'><![CDATA[" . $line["feed_title"] . "]]></feed>";
1137 }
1138 print "</entry>";
1139
1140 }
1141
1142
1143 ++$lnum;
1144 }
1145
1146 if ($omode != "xml") {
1147 print "</table>";
1148 } else {
1149 print "</headlines>";
1150 }
1151
1152 } else {
1153 print "<div width='100%' align='center'>No articles found.</div>";
1154 }
1155
1156 if ($omode != "xml") {
1157
1158 print "<script type=\"text/javascript\">
1159 document.onkeydown = hotkey_handler;
1160 update_all_counters('$feed');
1161 </script>";
1162
1163 if ($addheader) {
1164 print "</body></html>";
1165 }
1166 }
1167 }
1168
1169 if ($op == "pref-rpc") {
1170
1171 $subop = $_GET["subop"];
1172
1173 if ($subop == "unread") {
1174 $ids = split(",", $_GET["ids"]);
1175 foreach ($ids as $id) {
1176 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1177 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1178 }
1179
1180 print "Marked selected feeds as unread.";
1181 }
1182
1183 if ($subop == "read") {
1184 $ids = split(",", $_GET["ids"]);
1185 foreach ($ids as $id) {
1186 db_query($link, "UPDATE ttrss_user_entries
1187 SET unread = false,last_read = NOW() WHERE
1188 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1189 }
1190
1191 print "Marked selected feeds as read.";
1192
1193 }
1194
1195 }
1196
1197 if ($op == "pref-feeds") {
1198
1199 $subop = $_GET["subop"];
1200
1201 if ($subop == "editSave") {
1202 $feed_title = db_escape_string($_GET["t"]);
1203 $feed_link = db_escape_string($_GET["l"]);
1204 $upd_intl = db_escape_string($_GET["ui"]);
1205 $purge_intl = db_escape_string($_GET["pi"]);
1206 $feed_id = db_escape_string($_GET["id"]);
1207 $cat_id = db_escape_string($_GET["catid"]);
1208
1209 if (strtoupper($upd_intl) == "DEFAULT")
1210 $upd_intl = 0;
1211
1212 if (strtoupper($purge_intl) == "DEFAULT")
1213 $purge_intl = 0;
1214
1215 if (strtoupper($purge_intl) == "DISABLED")
1216 $purge_intl = -1;
1217
1218 if ($cat_id != 0) {
1219 $category_qpart = "cat_id = '$cat_id'";
1220 } else {
1221 $category_qpart = 'cat_id = NULL';
1222 }
1223
1224 $result = db_query($link, "UPDATE ttrss_feeds SET
1225 $category_qpart,
1226 title = '$feed_title', feed_url = '$feed_link',
1227 update_interval = '$upd_intl',
1228 purge_interval = '$purge_intl'
1229 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1230
1231 }
1232
1233 if ($subop == "remove") {
1234
1235 if (!WEB_DEMO_MODE) {
1236
1237 $ids = split(",", $_GET["ids"]);
1238
1239 foreach ($ids as $id) {
1240 db_query($link, "DELETE FROM ttrss_feeds
1241 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1242
1243 $icons_dir = ICONS_DIR;
1244
1245 if (file_exists($icons_dir . "/$id.ico")) {
1246 unlink($icons_dir . "/$id.ico");
1247 }
1248 }
1249 }
1250 }
1251
1252 if ($subop == "add") {
1253
1254 if (!WEB_DEMO_MODE) {
1255
1256 $feed_link = db_escape_string(trim($_GET["link"]));
1257
1258 $result = db_query($link,
1259 "SELECT id FROM ttrss_feeds
1260 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1261
1262 if (db_num_rows($result) == 0) {
1263
1264 $result = db_query($link,
1265 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1266 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
1267
1268 $result = db_query($link,
1269 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1270 AND owner_uid = " . $_SESSION["uid"]);
1271
1272 $feed_id = db_fetch_result($result, 0, "id");
1273
1274 if ($feed_id) {
1275 update_rss_feed($link, $feed_link, $feed_id, true);
1276 }
1277 } else {
1278
1279 print "<div class=\"warning\">
1280 Feed <b>$feed_link</b> already exists in the database.
1281 </div>";
1282 }
1283 }
1284 }
1285
1286 if ($subop == "addCat") {
1287
1288 if (!WEB_DEMO_MODE) {
1289
1290 $feed_cat = db_escape_string(trim($_GET["cat"]));
1291
1292 $result = db_query($link,
1293 "SELECT id FROM ttrss_feed_categories
1294 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1295
1296 if (db_num_rows($result) == 0) {
1297
1298 $result = db_query($link,
1299 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1300 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1301
1302 } else {
1303
1304 print "<div class=\"warning\">
1305 Category <b>$feed_cat</b> already exists in the database.
1306 </div>";
1307 }
1308
1309
1310 }
1311 }
1312
1313 if ($subop == "removeCats") {
1314
1315 if (!WEB_DEMO_MODE) {
1316
1317 $ids = split(",", $_GET["ids"]);
1318
1319 foreach ($ids as $id) {
1320
1321 db_query($link, "BEGIN");
1322
1323 $result = db_query($link,
1324 "SELECT count(id) as num_feeds FROM ttrss_feeds
1325 WHERE cat_id = '$id'");
1326
1327 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1328
1329 if ($num_feeds == 0) {
1330 db_query($link, "DELETE FROM ttrss_feed_categories
1331 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1332 } else {
1333
1334 print "<div class=\"warning\">
1335 Unable to delete non empty feed categories.</div>";
1336
1337 }
1338
1339 db_query($link, "COMMIT");
1340 }
1341 }
1342 }
1343
1344 // print "<h3>Edit Feeds</h3>";
1345
1346 $result = db_query($link, "SELECT id,title,feed_url,last_error
1347 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1348
1349 if (db_num_rows($result) > 0) {
1350
1351 print "<div class=\"warning\">";
1352
1353 print "<b>Feeds with update errors:</b>";
1354
1355 print "<ul class=\"nomarks\">";
1356
1357 while ($line = db_fetch_assoc($result)) {
1358 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1359 $line["last_error"];
1360 }
1361
1362 print "</ul>";
1363 print "</div>";
1364
1365 }
1366
1367 print "<p><div class=\"prefGenericAddBox\">
1368 <input id=\"fadd_link\" size=\"40\">&nbsp;<input
1369 type=\"submit\" class=\"button\"
1370 onclick=\"javascript:addFeed()\" value=\"Add feed\"></div>";
1371
1372 $feeds_sort = db_escape_string($_GET["sort"]);
1373
1374 if (!$feeds_sort || $feeds_sort == "undefined") {
1375 $feeds_sort = $_SESSION["pref_sort_feeds"];
1376 if (!$feeds_sort) $feeds_sort = "title";
1377 }
1378
1379 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1380
1381 $result = db_query($link, "SELECT
1382 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1383 update_interval,purge_interval,
1384 (SELECT title FROM ttrss_feed_categories
1385 WHERE id = cat_id) AS category
1386 FROM
1387 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."'
1388 ORDER by $feeds_sort,title");
1389
1390 if (db_num_rows($result) != 0) {
1391
1392 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1393
1394 print "<p><table width=\"100%\" cellspacing=\"0\"
1395 class=\"prefFeedList\" id=\"prefFeedList\">";
1396 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1397 Select:
1398 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1399 'FEEDR-', 'FRCHK-', true)\">All</a>,
1400 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1401 'FEEDR-', 'FRCHK-', false)\">None</a>
1402 </td</tr>";
1403
1404 print "<tr class=\"title\">
1405 <td width=\"3%\">&nbsp;</td>
1406 <td width=\"3%\">Select</td>
1407 <td width=\"20%\">
1408 <a href=\"javascript:updateFeedList('title')\">Title</a></td>
1409 <td width=\"20%\">
1410 <a href=\"javascript:updateFeedList('feed_url')\">Link</a>
1411 </td>";
1412
1413 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1414 print "<td width=\"10%\">
1415 <a href=\"javascript:updateFeedList('category')\">Category</a></td>";
1416 }
1417
1418 print "
1419 <td width=\"10%\">
1420 <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a>
1421 </td>
1422 <td width=\"10%\">
1423 <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a>
1424 </td>
1425 </tr>";
1426
1427 $lnum = 0;
1428
1429 while ($line = db_fetch_assoc($result)) {
1430
1431 $class = ($lnum % 2) ? "even" : "odd";
1432
1433 $feed_id = $line["id"];
1434
1435 $edit_feed_id = $_GET["id"];
1436
1437 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1438 $class .= "Grayed";
1439 $this_row_id = "";
1440 } else {
1441 $this_row_id = "id=\"FEEDR-$feed_id\"";
1442 }
1443
1444 print "<tr class=\"$class\" $this_row_id>";
1445
1446 $icon_file = ICONS_DIR . "/$feed_id.ico";
1447
1448 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1449 $feed_icon = "<img width=\"16\" height=\"16\"
1450 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1451 } else {
1452 $feed_icon = "&nbsp;";
1453 }
1454 print "<td align='center'>$feed_icon</td>";
1455
1456 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1457 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1458 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1459
1460 if (!$edit_cat) $edit_cat = "Uncategorized";
1461
1462 if (!$edit_feed_id || $subop != "edit") {
1463
1464 print "<td><input onclick='toggleSelectRow(this);'
1465 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1466
1467 $edit_title = truncate_string($edit_title, 40);
1468 $edit_link = truncate_string($edit_link, 60);
1469
1470 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1471 $edit_title . "</a></td>";
1472
1473 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1474 $edit_link . "</a></td>";
1475
1476 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1477 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1478 $edit_cat . "</a></td>";
1479 }
1480
1481 if ($line["update_interval"] == "0")
1482 $line["update_interval"] = "Default";
1483
1484 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1485 $line["update_interval"] . "</a></td>";
1486
1487 if ($line["purge_interval"] == "0")
1488 $line["purge_interval"] = "Default";
1489
1490 if ($line["purge_interval"] < 0)
1491 $line["purge_interval"] = "Disabled";
1492
1493 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1494 $line["purge_interval"] . "</a></td>";
1495
1496 } else if ($feed_id != $edit_feed_id) {
1497
1498 print "<td><input disabled=\"true\" type=\"checkbox\"
1499 id=\"FRCHK-".$line["id"]."\"></td>";
1500
1501 $edit_title = truncate_string($edit_title, 40);
1502 $edit_link = truncate_string($edit_link, 60);
1503
1504 print "<td>$edit_title</td>";
1505 print "<td>$edit_link</td>";
1506
1507 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1508 print "<td>$edit_cat</td>";
1509 }
1510
1511 if ($line["update_interval"] == "0")
1512 $line["update_interval"] = "Default";
1513
1514 print "<td>" . $line["update_interval"] . "</td>";
1515
1516 if ($line["purge_interval"] == "0")
1517 $line["purge_interval"] = "Default";
1518
1519 if ($line["purge_interval"] < 0)
1520 $line["purge_interval"] = "Disabled";
1521
1522 print "<td>" . $line["purge_interval"] . "</td>";
1523
1524 } else {
1525
1526 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1527
1528 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1529 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1530
1531 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1532
1533 print "<td>";
1534 print "<select id=\"iedit_fcat\">";
1535 print "<option id=\"0\">Uncategorized</option>";
1536
1537 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1538 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1539
1540 if (db_num_rows($tmp_result) > 0) {
1541 print "<option disabled>--------</option>";
1542 }
1543
1544 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1545 if ($tmp_line["id"] == $line["cat_id"]) {
1546 $is_selected = "selected";
1547 } else {
1548 $is_selected = "";
1549 }
1550 printf("<option $is_selected id='%d'>%s</option>",
1551 $tmp_line["id"], $tmp_line["title"]);
1552 }
1553
1554 print "</select></td>";
1555 print "</td>";
1556
1557 }
1558
1559 print "<td><input id=\"iedit_updintl\"
1560 value=\"".$line["update_interval"]."\"></td>";
1561 print "<td><input id=\"iedit_purgintl\"
1562 value=\"".$line["purge_interval"]."\"></td>";
1563
1564 }
1565
1566 /* if (!$line["last_updated"]) $line["last_updated"] = "Never";
1567
1568 print "<td>" . $line["last_updated"] . "</td>"; */
1569
1570 print "</tr>";
1571
1572 ++$lnum;
1573 }
1574
1575 print "</table>";
1576
1577 print "<p>";
1578
1579 if ($subop == "edit") {
1580 print "Edit feed:&nbsp;
1581 <input type=\"submit\" class=\"button\"
1582 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1583 <input type=\"submit\" class=\"button\"
1584 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1585 } else {
1586
1587 print "
1588 Selection:&nbsp;
1589 <input type=\"submit\" class=\"button\"
1590 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1591 <input type=\"submit\" class=\"button\"
1592 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1593 <input type=\"submit\" class=\"button\"
1594 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1595
1596 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1597 print "
1598 <input type=\"submit\" class=\"button\"
1599 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
1600 <input type=\"submit\" class=\"button\"
1601 onclick=\"javascript:readSelectedFeeds(false)\"
1602 value=\"Mark as unread\">&nbsp;";
1603 }
1604
1605 print "
1606 All feeds: <input type=\"submit\"
1607 class=\"button\" onclick=\"gotoExportOpml()\"
1608 value=\"Export OPML\">";
1609 }
1610 } else {
1611
1612 print "<p>No feeds defined.</p>";
1613
1614 }
1615
1616 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1617
1618 print "<h3>Edit Categories</h3>";
1619
1620 // print "<h3>Categories</h3>";
1621
1622 print "<div class=\"prefGenericAddBox\">
1623 <input id=\"fadd_cat\" size=\"40\">&nbsp;<input
1624 type=\"submit\" class=\"button\"
1625 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1626
1627 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1628 WHERE owner_uid = ".$_SESSION["uid"]."
1629 ORDER BY title");
1630
1631 if (db_num_rows($result) != 0) {
1632
1633 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1634 cellspacing=\"0\" id=\"prefFeedCatList\">";
1635
1636 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1637 Select:
1638 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1639 'FCATR-', 'FCCHK-', true)\">All</a>,
1640 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1641 'FCATR-', 'FCCHK-', false)\">None</a>
1642 </td</tr>";
1643
1644 print "<tr class=\"title\">
1645 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1646 </tr>";
1647
1648 $lnum = 0;
1649
1650 while ($line = db_fetch_assoc($result)) {
1651
1652 $class = ($lnum % 2) ? "even" : "odd";
1653
1654 $cat_id = $line["id"];
1655
1656 $edit_cat_id = $_GET["id"];
1657
1658 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1659 $class .= "Grayed";
1660 $this_row_id = "";
1661 } else {
1662 $this_row_id = "id=\"FCATR-$cat_id\"";
1663 }
1664
1665 print "<tr class=\"$class\" $this_row_id>";
1666
1667 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1668
1669 if (!$edit_cat_id || $subop != "editCat") {
1670
1671 print "<td><input onclick='toggleSelectRow(this);'
1672 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1673
1674 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1675 $edit_title . "</a></td>";
1676
1677 } else if ($cat_id != $edit_cat_id) {
1678
1679 print "<td><input disabled=\"true\" type=\"checkbox\"
1680 id=\"FRCHK-".$line["id"]."\"></td>";
1681
1682 print "<td>$edit_title</td>";
1683
1684 } else {
1685
1686 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1687
1688 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1689
1690 }
1691
1692 print "</tr>";
1693
1694 ++$lnum;
1695 }
1696
1697 print "</table>";
1698
1699 print "<p>";
1700
1701 if ($subop == "editCat") {
1702 print "Edit category:&nbsp;
1703 <input type=\"submit\" class=\"button\"
1704 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1705 <input type=\"submit\" class=\"button\"
1706 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1707 } else {
1708
1709 print "
1710 Selection:&nbsp;
1711 <input type=\"submit\" class=\"button\"
1712 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1713 <input type=\"submit\" class=\"button\"
1714 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1715
1716 }
1717
1718 } else {
1719 print "<p>No feed categories defined.</p>";
1720 }
1721 }
1722
1723 print "<h3>Import OPML</h3>
1724 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1725 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1726 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1727 type=\"submit\" value=\"Import\">
1728 </form>";
1729
1730 }
1731
1732 if ($op == "pref-filters") {
1733
1734 $subop = $_GET["subop"];
1735
1736 if ($subop == "editSave") {
1737
1738 $regexp = db_escape_string($_GET["r"]);
1739 $descr = db_escape_string($_GET["d"]);
1740 $match = db_escape_string($_GET["m"]);
1741 $filter_id = db_escape_string($_GET["id"]);
1742 $feed_id = db_escape_string($_GET["fid"]);
1743
1744 if (!$feed_id) {
1745 $feed_id = 'NULL';
1746 } else {
1747 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1748 }
1749
1750 $result = db_query($link, "UPDATE ttrss_filters SET
1751 reg_exp = '$regexp',
1752 description = '$descr',
1753 feed_id = $feed_id,
1754 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1755 description = '$match')
1756 WHERE id = '$filter_id'");
1757 }
1758
1759 if ($subop == "remove") {
1760
1761 if (!WEB_DEMO_MODE) {
1762
1763 $ids = split(",", $_GET["ids"]);
1764
1765 foreach ($ids as $id) {
1766 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1767
1768 }
1769 }
1770 }
1771
1772 if ($subop == "add") {
1773
1774 if (!WEB_DEMO_MODE) {
1775
1776 $regexp = db_escape_string(trim($_GET["regexp"]));
1777 $match = db_escape_string(trim($_GET["match"]));
1778 $feed_id = db_escape_string($_GET["fid"]);
1779
1780 if (!$feed_id) {
1781 $feed_id = 'NULL';
1782 } else {
1783 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1784 }
1785
1786 $result = db_query($link,
1787 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
1788 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1789 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
1790 }
1791 }
1792
1793 $result = db_query($link, "SELECT description
1794 FROM ttrss_filter_types ORDER BY description");
1795
1796 $filter_types = array();
1797
1798 while ($line = db_fetch_assoc($result)) {
1799 array_push($filter_types, $line["description"]);
1800 }
1801
1802 print "<div class=\"prefGenericAddBox\">
1803 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
1804
1805 print_select("fadd_match", "Title", $filter_types);
1806
1807 print "&nbsp;<select id=\"fadd_feed\">";
1808
1809 print "<option selected id=\"0\">All feeds</option>";
1810
1811 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1812 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1813
1814 if (db_num_rows($result) > 0) {
1815 print "<option disabled>--------</option>";
1816 }
1817
1818 while ($line = db_fetch_assoc($result)) {
1819 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1820 }
1821
1822 print "</select>&nbsp;";
1823
1824 print "<input type=\"submit\"
1825 class=\"button\" onclick=\"javascript:addFilter()\"
1826 value=\"Add filter\">";
1827
1828 $result = db_query($link, "SELECT
1829 ttrss_filters.id AS id,reg_exp,
1830 ttrss_filters.description AS description,
1831 ttrss_filter_types.name AS filter_type_name,
1832 ttrss_filter_types.description AS filter_type_descr,
1833 feed_id,
1834 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1835 FROM
1836 ttrss_filters,ttrss_filter_types
1837 WHERE
1838 filter_type = ttrss_filter_types.id AND
1839 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
1840 ORDER by reg_exp");
1841
1842 if (db_num_rows($result) != 0) {
1843
1844 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
1845 id=\"prefFilterList\">";
1846
1847 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1848 Select:
1849 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1850 'FILRR-', 'FICHK-', true)\">All</a>,
1851 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1852 'FILRR-', 'FICHK-', false)\">None</a>
1853 </td</tr>";
1854
1855 print "<tr class=\"title\">
1856 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1857 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1858 <td width=\"30%\">Description</td></tr>";
1859
1860 $lnum = 0;
1861
1862 while ($line = db_fetch_assoc($result)) {
1863
1864 $class = ($lnum % 2) ? "even" : "odd";
1865
1866 $filter_id = $line["id"];
1867 $edit_filter_id = $_GET["id"];
1868
1869 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1870 $class .= "Grayed";
1871 $this_row_id = "";
1872 } else {
1873 $this_row_id = "id=\"FILRR-$filter_id\"";
1874 }
1875
1876 print "<tr class=\"$class\" $this_row_id>";
1877
1878 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1879 $line["description"] = htmlspecialchars($line["description"]);
1880
1881 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1882
1883 if (!$edit_filter_id || $subop != "edit") {
1884
1885 if (!$line["description"]) $line["description"] = "[No description]";
1886
1887 print "<td><input onclick='toggleSelectRow(this);'
1888 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1889
1890 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1891 $line["reg_exp"] . "</td>";
1892
1893 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1894 $line["feed_title"] . "</td>";
1895
1896 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1897 $line["filter_type_descr"] . "</td>";
1898
1899 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1900 $line["description"] . "</td>";
1901
1902 } else if ($filter_id != $edit_filter_id) {
1903
1904 if (!$line["description"]) $line["description"] = "[No description]";
1905
1906 print "<td><input disabled=\"true\" type=\"checkbox\"
1907 id=\"FICHK-".$line["id"]."\"></td>";
1908
1909 print "<td>".$line["reg_exp"]."</td>";
1910 print "<td>".$line["feed_title"]."</td>";
1911 print "<td>".$line["filter_type_descr"]."</td>";
1912 print "<td>".$line["description"]."</td>";
1913
1914 } else {
1915
1916 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1917
1918 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1919 "\"></td>";
1920
1921 print "<td>";
1922
1923 print "<select id=\"iedit_feed\">";
1924
1925 print "<option id=\"0\">All feeds</option>";
1926
1927 if (db_num_rows($result) > 0) {
1928 print "<option disabled>--------</option>";
1929 }
1930
1931 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1932 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1933
1934 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1935 if ($tmp_line["id"] == $line["feed_id"]) {
1936 $is_selected = "selected";
1937 } else {
1938 $is_selected = "";
1939 }
1940 printf("<option $is_selected id='%d'>%s</option>",
1941 $tmp_line["id"], $tmp_line["title"]);
1942 }
1943
1944 print "</select></td>";
1945
1946 print "<td>";
1947 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1948 print "</td>";
1949
1950 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1951 "\"></td>";
1952
1953 print "</td>";
1954 }
1955
1956 print "</tr>";
1957
1958 ++$lnum;
1959 }
1960
1961 if ($lnum == 0) {
1962 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1963 }
1964
1965 print "</table>";
1966
1967 print "<p>";
1968
1969 if ($subop == "edit") {
1970 print "Edit feed:
1971 <input type=\"submit\" class=\"button\"
1972 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1973 <input type=\"submit\" class=\"button\"
1974 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1975
1976 } else {
1977
1978 print "
1979 Selection:
1980 <input type=\"submit\" class=\"button\"
1981 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1982 <input type=\"submit\" class=\"button\"
1983 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1984 }
1985
1986 } else {
1987
1988 print "<p>No filters defined.</p>";
1989
1990 }
1991 }
1992
1993 if ($op == "pref-labels") {
1994
1995 $subop = $_GET["subop"];
1996
1997 if ($subop == "test") {
1998
1999 $expr = $_GET["expr"];
2000 $descr = $_GET["descr"];
2001
2002 print "<div class='infoBoxContents'>";
2003
2004 print "<h1>Label &laquo;$descr&raquo;</h1>";
2005
2006 // print "<p><b>Expression</b>: $expr</p>";
2007
2008 $result = db_query($link,
2009 "SELECT count(id) AS num_matches
2010 FROM ttrss_entries,ttrss_user_entries
2011 WHERE ($expr) AND
2012 ttrss_user_entries.ref_id = ttrss_entries.id AND
2013 owner_uid = " . $_SESSION["uid"]);
2014
2015 $num_matches = db_fetch_result($result, 0, "num_matches");;
2016
2017 if ($num_matches > 0) {
2018
2019 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2020
2021 $result = db_query($link,
2022 "SELECT title,
2023 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2024 FROM ttrss_entries,ttrss_user_entries
2025 WHERE ($expr) AND
2026 ttrss_user_entries.ref_id = ttrss_entries.id
2027 AND owner_uid = " . $_SESSION["uid"] . "
2028 ORDER BY date_entered DESC LIMIT 5");
2029
2030 print "<ul class=\"nomarks\">";
2031 while ($line = db_fetch_assoc($result)) {
2032 print "<li>".$line["title"].
2033 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2034 }
2035 print "</ul>";
2036
2037 } else {
2038 print "<p>Query didn't return any matches.</p>";
2039 }
2040
2041 print "</div>";
2042
2043 print "<div align='center'>
2044 <input type='submit' class='button'
2045 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2046 return;
2047 }
2048
2049 if ($subop == "editSave") {
2050
2051 $sql_exp = $_GET["s"];
2052 $descr = $_GET["d"];
2053 $label_id = db_escape_string($_GET["id"]);
2054
2055 // print "$sql_exp : $descr : $label_id";
2056
2057 $result = db_query($link, "UPDATE ttrss_labels SET
2058 sql_exp = '$sql_exp',
2059 description = '$descr'
2060 WHERE id = '$label_id'");
2061 }
2062
2063 if ($subop == "remove") {
2064
2065 if (!WEB_DEMO_MODE) {
2066
2067 $ids = split(",", $_GET["ids"]);
2068
2069 foreach ($ids as $id) {
2070 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2071
2072 }
2073 }
2074 }
2075
2076 if ($subop == "add") {
2077
2078 if (!WEB_DEMO_MODE) {
2079
2080 // no escaping is done here on purpose
2081 $exp = trim($_GET["exp"]);
2082
2083 $result = db_query($link,
2084 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2085 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2086 }
2087 }
2088
2089 print "<div class=\"prefGenericAddBox\">
2090 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
2091
2092 print"<input type=\"submit\" class=\"button\"
2093 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2094
2095 $result = db_query($link, "SELECT
2096 id,sql_exp,description
2097 FROM
2098 ttrss_labels
2099 WHERE
2100 owner_uid = ".$_SESSION["uid"]."
2101 ORDER by description");
2102
2103 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2104
2105 if (db_num_rows($result) != 0) {
2106
2107 print "<p><table width=\"100%\" cellspacing=\"0\"
2108 class=\"prefLabelList\" id=\"prefLabelList\">";
2109
2110 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2111 Select:
2112 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2113 'LILRR-', 'LICHK-', true)\">All</a>,
2114 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2115 'LILRR-', 'LICHK-', false)\">None</a>
2116 </td</tr>";
2117
2118 print "<tr class=\"title\">
2119 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
2120 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2121 </td>
2122 <td width=\"40%\">Caption</td></tr>";
2123
2124 $lnum = 0;
2125
2126 while ($line = db_fetch_assoc($result)) {
2127
2128 $class = ($lnum % 2) ? "even" : "odd";
2129
2130 $label_id = $line["id"];
2131 $edit_label_id = $_GET["id"];
2132
2133 if ($subop == "edit" && $label_id != $edit_label_id) {
2134 $class .= "Grayed";
2135 $this_row_id = "";
2136 } else {
2137 $this_row_id = "id=\"LILRR-$label_id\"";
2138 }
2139
2140 print "<tr class=\"$class\" $this_row_id>";
2141
2142 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2143 $line["description"] = htmlspecialchars($line["description"]);
2144
2145 if (!$edit_label_id || $subop != "edit") {
2146
2147 if (!$line["description"]) $line["description"] = "[No caption]";
2148
2149 print "<td><input onclick='toggleSelectRow(this);'
2150 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2151
2152 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2153 $line["sql_exp"] . "</td>";
2154
2155 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2156 $line["description"] . "</td>";
2157
2158 } else if ($label_id != $edit_label_id) {
2159
2160 if (!$line["description"]) $line["description"] = "[No description]";
2161
2162 print "<td><input disabled=\"true\" type=\"checkbox\"
2163 id=\"LICHK-".$line["id"]."\"></td>";
2164
2165 print "<td>".$line["sql_exp"]."</td>";
2166 print "<td>".$line["description"]."</td>";
2167
2168 } else {
2169
2170 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2171
2172 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2173 "\"></td>";
2174
2175 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2176 "\"></td>";
2177
2178 }
2179
2180
2181 print "</tr>";
2182
2183 ++$lnum;
2184 }
2185
2186 if ($lnum == 0) {
2187 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2188 }
2189
2190 print "</table>";
2191
2192 print "<p>";
2193
2194 if ($subop == "edit") {
2195 print "Edit label:
2196 <input type=\"submit\" class=\"button\"
2197 onclick=\"javascript:labelTest()\" value=\"Test\">
2198 <input type=\"submit\" class=\"button\"
2199 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2200 <input type=\"submit\" class=\"button\"
2201 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2202
2203 } else {
2204
2205 print "
2206 Selection:
2207 <input type=\"submit\" class=\"button\"
2208 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2209 <input type=\"submit\" class=\"button\"
2210 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2211 }
2212 } else {
2213 print "<p>No labels defined.</p>";
2214 }
2215 }
2216
2217 if ($op == "error") {
2218 print "<div width=\"100%\" align='center'>";
2219 $msg = $_GET["msg"];
2220 print $msg;
2221 print "</div>";
2222 }
2223
2224 if ($op == "help") {
2225 if (!$_GET["noheaders"]) {
2226 print "<html><head>
2227 <title>Tiny Tiny RSS : Help</title>
2228 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2229 <script type=\"text/javascript\" src=\"functions.js\"></script>
2230 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2231 </head><body>";
2232 }
2233
2234 $tid = sprintf("%d", $_GET["tid"]);
2235
2236 print "<div class='infoBoxContents'>";
2237
2238 if (file_exists("help/$tid.php")) {
2239 include("help/$tid.php");
2240 } else {
2241 print "<p>Help topic not found.</p>";
2242 }
2243
2244 print "</div>";
2245
2246 print "<div align='center'>
2247 <input type='submit' class='button'
2248 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2249
2250 if (!$_GET["noheaders"]) {
2251 print "</body></html>";
2252 }
2253
2254 }
2255
2256 if ($op == "dlg") {
2257 $id = $_GET["id"];
2258 $param = $_GET["param"];
2259
2260 if ($id == "quickAddFeed") {
2261 print "
2262 Feed URL: <input
2263 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2264 id=\"qafInput\">
2265 <input class=\"button\"
2266 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2267 <input class=\"button\"
2268 type=\"submit\" onclick=\"javascript:closeDlg()\"
2269 value=\"Cancel\">";
2270 }
2271
2272 if ($id == "quickDelFeed") {
2273
2274 $param = db_escape_string($param);
2275
2276 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2277
2278 if ($result) {
2279
2280 $f_title = db_fetch_result($result, 0, "title");
2281
2282 print "Remove current feed (<b>$f_title</b>)?&nbsp;
2283 <input class=\"button\"
2284 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2285 <input class=\"button\"
2286 type=\"submit\" onclick=\"javascript:closeDlg()\"
2287 value=\"Cancel\">";
2288 } else {
2289 print "Error: Feed $param not found.&nbsp;
2290 <input class=\"button\"
2291 type=\"submit\" onclick=\"javascript:closeDlg()\"
2292 value=\"Cancel\">";
2293 }
2294 }
2295
2296 if ($id == "search") {
2297
2298 print "<input id=\"searchbox\" class=\"extSearch\"
2299 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2300 onchange=\"javascript:search()\">
2301 <select id=\"searchmodebox\">
2302 <option selected>All feeds</option>
2303 <option>This feed</option>
2304 </select>
2305 <input type=\"submit\"
2306 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2307 <input class=\"button\"
2308 type=\"submit\" onclick=\"javascript:closeDlg()\"
2309 value=\"Close\">";
2310
2311 }
2312
2313 }
2314
2315 // update feeds of all users, may be used anonymously
2316 if ($op == "globalUpdateFeeds") {
2317
2318 $result = db_query($link, "SELECT id FROM ttrss_users");
2319
2320 while ($line = db_fetch_assoc($result)) {
2321 $user_id = $line["id"];
2322 // print "<!-- updating feeds of uid $user_id -->";
2323 update_all_feeds($link, false, $user_id);
2324 }
2325
2326 print "<rpc-reply>
2327 <message msg=\"All feeds updated\"/>
2328 </rpc-reply>";
2329
2330 }
2331
2332 if ($op == "pref-prefs") {
2333
2334 $subop = $_REQUEST["subop"];
2335
2336 if ($subop == "Save configuration") {
2337
2338 if (WEB_DEMO_MODE) {
2339 header("Location: prefs.php");
2340 return;
2341 }
2342
2343 $_SESSION["prefs_op_result"] = "save-config";
2344
2345 foreach (array_keys($_POST) as $pref_name) {
2346
2347 $pref_name = db_escape_string($pref_name);
2348 $value = db_escape_string($_POST[$pref_name]);
2349
2350 $result = db_query($link, "SELECT type_name
2351 FROM ttrss_prefs,ttrss_prefs_types
2352 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2353
2354 if (db_num_rows($result) > 0) {
2355
2356 $type_name = db_fetch_result($result, 0, "type_name");
2357
2358 // print "$pref_name : $type_name : $value<br>";
2359
2360 if ($type_name == "bool") {
2361 if ($value == "1") {
2362 $value = "true";
2363 } else {
2364 $value = "false";
2365 }
2366 } else if ($type_name == "integer") {
2367 $value = sprintf("%d", $value);
2368 }
2369
2370 // print "$pref_name : $type_name : $value<br>";
2371
2372 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2373 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2374
2375 }
2376
2377 header("Location: prefs.php");
2378
2379 }
2380
2381 } else if ($subop == "getHelp") {
2382
2383 $pref_name = db_escape_string($_GET["pn"]);
2384
2385 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2386 WHERE pref_name = '$pref_name'");
2387
2388 if (db_num_rows($result) > 0) {
2389 $help_text = db_fetch_result($result, 0, "help_text");
2390 print $help_text;
2391 } else {
2392 print "Unknown option: $pref_name";
2393 }
2394
2395 } else if ($subop == "Change password") {
2396
2397 if (WEB_DEMO_MODE) {
2398 header("Location: prefs.php");
2399 return;
2400 }
2401
2402 $old_pw = $_POST["OLD_PASSWORD"];
2403 $new_pw = $_POST["OLD_PASSWORD"];
2404
2405 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2406 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2407
2408 $active_uid = $_SESSION["uid"];
2409
2410 if ($old_pw && $new_pw) {
2411
2412 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2413
2414 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2415 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2416 pwd_hash = '$old_pw_hash')");
2417
2418 if (db_num_rows($result) == 1) {
2419 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2420 WHERE id = '$active_uid'");
2421
2422 $_SESSION["pwd_change_result"] = "ok";
2423 } else {
2424 $_SESSION["pwd_change_result"] = "failed";
2425 }
2426 }
2427
2428 header("Location: prefs.php");
2429
2430 } else if ($subop == "Reset to defaults") {
2431
2432 if (WEB_DEMO_MODE) {
2433 header("Location: prefs.php");
2434 return;
2435 }
2436
2437 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2438
2439 if (DB_TYPE == "pgsql") {
2440 db_query($link,"UPDATE ttrss_user_prefs
2441 SET value = ttrss_prefs.def_value
2442 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2443 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2444 } else {
2445 db_query($link, "DELETE FROM ttrss_user_prefs
2446 WHERE owner_uid = ".$_SESSION["uid"]);
2447 initialize_user_prefs($link, $_SESSION["uid"]);
2448 }
2449
2450 header("Location: prefs.php");
2451
2452 } else if ($subop == "Change theme") {
2453
2454 $theme = db_escape_string($_POST["theme"]);
2455
2456 if ($theme == "Default") {
2457 $theme_qpart = 'NULL';
2458 } else {
2459 $theme_qpart = "'$theme'";
2460 }
2461
2462 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2463 WHERE theme_name = '$theme'");
2464
2465 if (db_num_rows($result) == 1) {
2466 $theme_id = db_fetch_result($result, 0, "id");
2467 $theme_path = db_fetch_result($result, 0, "theme_path");
2468 } else {
2469 $theme_id = "NULL";
2470 $theme_path = "";
2471 }
2472
2473 db_query($link, "UPDATE ttrss_users SET
2474 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2475
2476 $_SESSION["theme"] = $theme_path;
2477
2478 header("Location: prefs.php");
2479
2480 } else {
2481
2482 if (!SINGLE_USER_MODE) {
2483
2484 $result = db_query($link, "SELECT id FROM ttrss_users
2485 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2486 pwd_hash = 'SHA1:".sha1("password")."')");
2487
2488 if (db_num_rows($result) != 0) {
2489 print "<div class=\"warning\">
2490 Your password is at default value, please change it.
2491 </div>";
2492 }
2493
2494 if ($_SESSION["pwd_change_result"] == "failed") {
2495 print "<div class=\"warning\">
2496 There was an error while changing your password.
2497 </div>";
2498 }
2499
2500 if ($_SESSION["pwd_change_result"] == "ok") {
2501 print "<div class=\"notice\">
2502 Password changed successfully.
2503 </div>";
2504 }
2505
2506 $_SESSION["pwd_change_result"] = "";
2507
2508 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2509 print "<div class=\"notice\">
2510 Your configuration was reset to defaults.
2511 </div>";
2512 }
2513
2514 if ($_SESSION["prefs_op_result"] == "save-config") {
2515 print "<div class=\"notice\">
2516 Your configuration was saved successfully.
2517 </div>";
2518 }
2519
2520 $_SESSION["prefs_op_result"] = "";
2521
2522 print "<form action=\"backend.php\" method=\"POST\">";
2523
2524 print "<table width=\"100%\" class=\"prefPrefsList\">";
2525 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2526
2527 print "<tr><td width=\"40%\">Old password</td>";
2528 print "<td><input class=\"editbox\" type=\"password\"
2529 name=\"OLD_PASSWORD\"></td></tr>";
2530
2531 print "<tr><td width=\"40%\">New password</td>";
2532
2533 print "<td><input class=\"editbox\" type=\"password\"
2534 name=\"NEW_PASSWORD\"></td></tr>";
2535
2536 print "</table>";
2537
2538 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2539
2540 print "<p><input class=\"button\" type=\"submit\"
2541 value=\"Change password\" name=\"subop\">";
2542
2543 print "</form>";
2544
2545 }
2546
2547 $result = db_query($link, "SELECT
2548 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2549
2550 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2551
2552 $result = db_query($link, "SELECT
2553 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2554
2555 if (db_num_rows($result) > 0) {
2556
2557 print "<form action=\"backend.php\" method=\"POST\">";
2558 print "<table width=\"100%\" class=\"prefPrefsList\">";
2559 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2560 print "<tr><td width=\"40%\">Select theme</td>";
2561 print "<td><select name=\"theme\">";
2562 print "<option>Default</option>";
2563 print "<option disabled>--------</option>";
2564
2565 while ($line = db_fetch_assoc($result)) {
2566 if ($line["id"] == $user_theme_id) {
2567 $selected = "selected";
2568 } else {
2569 $selected = "";
2570 }
2571 print "<option $selected>" . $line["theme_name"] . "</option>";
2572 }
2573 print "</select></td></tr>";
2574 print "</table>";
2575 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2576 print "<p><input class=\"button\" type=\"submit\"
2577 value=\"Change theme\" name=\"subop\">";
2578 print "</form>";
2579 }
2580
2581 $result = db_query($link, "SELECT
2582 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
2583 section_name,def_value
2584 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
2585 WHERE type_id = ttrss_prefs_types.id AND
2586 section_id = ttrss_prefs_sections.id AND
2587 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2588 owner_uid = ".$_SESSION["uid"]."
2589 ORDER BY section_id,short_desc");
2590
2591 print "<form action=\"backend.php\" method=\"POST\">";
2592
2593 $lnum = 0;
2594
2595 $active_section = "";
2596
2597 while ($line = db_fetch_assoc($result)) {
2598
2599 if ($active_section != $line["section_name"]) {
2600
2601 if ($active_section != "") {
2602 print "</table>";
2603 }
2604
2605 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
2606
2607 $active_section = $line["section_name"];
2608
2609 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
2610 // print "<tr class=\"title\">
2611 // <td width=\"25%\">Option</td><td>Value</td></tr>";
2612
2613 $lnum = 0;
2614 }
2615
2616 // $class = ($lnum % 2) ? "even" : "odd";
2617
2618 print "<tr>";
2619
2620 $type_name = $line["type_name"];
2621 $pref_name = $line["pref_name"];
2622 $value = $line["value"];
2623 $def_value = $line["def_value"];
2624 $help_text = $line["help_text"];
2625
2626 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2627
2628 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2629
2630 print "</td>";
2631
2632 print "<td>";
2633
2634 if ($type_name == "bool") {
2635 // print_select($pref_name, $value, array("true", "false"));
2636
2637 if ($value == "true") {
2638 $value = "Yes";
2639 } else {
2640 $value = "No";
2641 }
2642
2643 print_radio($pref_name, $value, array("Yes", "No"));
2644
2645 } else {
2646 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2647 }
2648
2649 print "</td>";
2650
2651 print "</tr>";
2652
2653 $lnum++;
2654 }
2655
2656 print "</table>";
2657
2658 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2659
2660 print "<p><input class=\"button\" type=\"submit\"
2661 name=\"subop\" value=\"Save configuration\">";
2662
2663 print "&nbsp;<input class=\"button\" type=\"submit\"
2664 name=\"subop\" value=\"Reset to defaults\"></p>";
2665
2666 print "</form>";
2667
2668 }
2669
2670 }
2671
2672 if ($op == "pref-users") {
2673
2674 $subop = $_GET["subop"];
2675
2676 if ($subop == "editSave") {
2677
2678 if (!WEB_DEMO_MODE) {
2679
2680 $login = db_escape_string($_GET["l"]);
2681 $uid = db_escape_string($_GET["id"]);
2682 $access_level = sprintf("%d", $_GET["al"]);
2683
2684 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2685
2686 }
2687 } else if ($subop == "remove") {
2688
2689 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2690
2691 $ids = split(",", $_GET["ids"]);
2692
2693 foreach ($ids as $id) {
2694 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2695
2696 }
2697 }
2698 } else if ($subop == "add") {
2699
2700 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2701
2702 $login = db_escape_string(trim($_GET["login"]));
2703 $tmp_user_pwd = make_password(8);
2704 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2705
2706 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2707 VALUES ('$login', '$pwd_hash', 0)");
2708
2709
2710 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2711 login = '$login' AND pwd_hash = '$pwd_hash'");
2712
2713 if (db_num_rows($result) == 1) {
2714
2715 $new_uid = db_fetch_result($result, 0, "id");
2716
2717 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2718 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2719
2720 initialize_user($link, $new_uid);
2721
2722 } else {
2723
2724 print "<div class=\"warning\">Error while adding user <b>".
2725 $_GET["login"].".</b></div>";
2726
2727 }
2728 }
2729 } else if ($subop == "resetPass") {
2730
2731 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2732
2733 $uid = db_escape_string($_GET["id"]);
2734
2735 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2736
2737 $login = db_fetch_result($result, 0, "login");
2738 $tmp_user_pwd = make_password(8);
2739 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2740
2741 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2742 WHERE id = '$uid'");
2743
2744 print "<div class=\"notice\">Changed password of
2745 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2746
2747 }
2748 }
2749
2750 print "<div class=\"prefGenericAddBox\">
2751 <input id=\"uadd_box\" size=\"40\">&nbsp;";
2752
2753 print"<input type=\"submit\" class=\"button\"
2754 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
2755
2756 $result = db_query($link, "SELECT
2757 id,login,access_level,
2758 SUBSTRING(last_login,1,16) as last_login
2759 FROM
2760 ttrss_users
2761 ORDER by login");
2762
2763 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2764
2765 print "<p><table width=\"100%\" cellspacing=\"0\"
2766 class=\"prefUserList\" id=\"prefUserList\">";
2767
2768 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2769 Select:
2770 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2771 'UMRR-', 'UMCHK-', true)\">All</a>,
2772 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2773 'UMRR-', 'UMCHK-', false)\">None</a>
2774 </td</tr>";
2775
2776 print "<tr class=\"title\">
2777 <td width=\"5%\">Select</td>
2778 <td width='30%'>Username</td>
2779 <td width='30%'>Access Level</td>
2780 <td width='30%'>Last login</td></tr>";
2781
2782 $lnum = 0;
2783
2784 while ($line = db_fetch_assoc($result)) {
2785
2786 $class = ($lnum % 2) ? "even" : "odd";
2787
2788 $uid = $line["id"];
2789 $edit_uid = $_GET["id"];
2790
2791 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
2792 $class .= "Grayed";
2793 $this_row_id = "";
2794 } else {
2795 $this_row_id = "id=\"UMRR-$uid\"";
2796 }
2797
2798 print "<tr class=\"$class\" $this_row_id>";
2799
2800 $line["login"] = htmlspecialchars($line["login"]);
2801
2802 if ($uid == $_SESSION["uid"]) {
2803
2804 print "<td><input disabled=\"true\" type=\"checkbox\"
2805 id=\"UMCHK-".$line["id"]."\"></td>";
2806
2807 print "<td>".$line["login"]."</td>";
2808 print "<td>".$line["access_level"]."</td>";
2809
2810 } else if (!$edit_uid || $subop != "edit") {
2811
2812 print "<td><input onclick='toggleSelectRow(this);'
2813 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
2814
2815 print "<td><a href=\"javascript:editUser($uid);\">" .
2816 $line["login"] . "</td>";
2817
2818 print "<td><a href=\"javascript:editUser($uid);\">" .
2819 $line["access_level"] . "</td>";
2820
2821 } else if ($uid != $edit_uid) {
2822
2823 print "<td><input disabled=\"true\" type=\"checkbox\"
2824 id=\"UMCHK-".$line["id"]."\"></td>";
2825
2826 print "<td>".$line["login"]."</td>";
2827 print "<td>".$line["access_level"]."</td>";
2828
2829 } else {
2830
2831 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2832
2833 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2834 "\"></td>";
2835
2836 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2837 "\"></td>";
2838
2839 }
2840
2841 print "<td>".$line["last_login"]."</td>";
2842
2843 print "</tr>";
2844
2845 ++$lnum;
2846 }
2847
2848 print "</table>";
2849
2850 print "<p>";
2851
2852 if ($subop == "edit") {
2853 print "Edit label:
2854 <input type=\"submit\" class=\"button\"
2855 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2856 <input type=\"submit\" class=\"button\"
2857 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2858
2859 } else {
2860
2861 print "
2862 Selection:
2863 <input type=\"submit\" class=\"button\"
2864 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
2865 <input type=\"submit\" class=\"button\"
2866 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2867 <input type=\"submit\" class=\"button\"
2868 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2869 <input type=\"submit\" class=\"button\"
2870 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2871
2872 }
2873 }
2874
2875 if ($op == "user-details") {
2876
2877 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2878 return;
2879 }
2880
2881 /* print "<html><head>
2882 <title>Tiny Tiny RSS : User Details</title>
2883 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2884 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2885 </head><body>"; */
2886
2887 $uid = sprintf("%d", $_GET["id"]);
2888
2889 print "<div class='infoBoxContents'>";
2890
2891 $result = db_query($link, "SELECT login,
2892 SUBSTRING(last_login,1,16) AS last_login,
2893 access_level,
2894 (SELECT COUNT(int_id) FROM ttrss_user_entries
2895 WHERE owner_uid = id) AS stored_articles
2896 FROM ttrss_users
2897 WHERE id = '$uid'");
2898
2899 if (db_num_rows($result) == 0) {
2900 print "<h1>User not found</h1>";
2901 return;
2902 }
2903
2904 print "<h1>User Details</h1>";
2905
2906 print "<table width='100%'>";
2907
2908 $login = db_fetch_result($result, 0, "login");
2909 $last_login = db_fetch_result($result, 0, "last_login");
2910 $access_level = db_fetch_result($result, 0, "access_level");
2911 $stored_articles = db_fetch_result($result, 0, "stored_articles");
2912
2913 print "<tr><td>Username</td><td>$login</td></tr>";
2914 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2915 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
2916 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
2917
2918 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2919 WHERE owner_uid = '$uid'");
2920
2921 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2922
2923 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2924
2925 /* $result = db_query($link, "SELECT
2926 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
2927 FROM ttrss_user_entries,ttrss_entries
2928 WHERE owner_uid = '$uid' AND ref_id = id");
2929
2930 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
2931
2932 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
2933
2934 print "</table>";
2935
2936 print "<h1>Subscribed feeds</h1>";
2937
2938 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2939 WHERE owner_uid = '$uid' ORDER BY title");
2940
2941 print "<ul class=\"nomarks\">";
2942
2943 while ($line = db_fetch_assoc($result)) {
2944
2945 $icon_file = ICONS_URL."/".$line["id"].".ico";
2946
2947 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2948 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
2949 } else {
2950 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
2951 }
2952
2953 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2954 }
2955
2956 print "</ul>";
2957
2958 print "</div>";
2959
2960 print "<div align='center'>
2961 <input type='submit' class='button'
2962 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2963
2964 // print "</body></html>";
2965
2966 }
2967
2968 if ($op == "feed-details") {
2969
2970 $feed_id = $_GET["id"];
2971
2972 $result = db_query($link,
2973 "SELECT
2974 title,feed_url,last_updated,icon_url,site_url,
2975 (SELECT COUNT(int_id) FROM ttrss_user_entries
2976 WHERE feed_id = id) AS total,
2977 (SELECT COUNT(int_id) FROM ttrss_user_entries
2978 WHERE feed_id = id AND unread = true) AS unread,
2979 (SELECT COUNT(int_id) FROM ttrss_user_entries
2980 WHERE feed_id = id AND marked = true) AS marked
2981 FROM ttrss_feeds
2982 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2983
2984 if (db_num_rows($result) == 0) return;
2985
2986 $title = db_fetch_result($result, 0, "title");
2987 $last_updated = db_fetch_result($result, 0, "last_updated");
2988 $feed_url = db_fetch_result($result, 0, "feed_url");
2989 $icon_url = db_fetch_result($result, 0, "icon_url");
2990 $total = db_fetch_result($result, 0, "total");
2991 $unread = db_fetch_result($result, 0, "unread");
2992 $marked = db_fetch_result($result, 0, "marked");
2993 $site_url = db_fetch_result($result, 0, "site_url");
2994
2995 $result = db_query($link, "SELECT COUNT(id) AS subscribed
2996 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
2997
2998 $subscribed = db_fetch_result($result, 0, "subscribed");
2999
3000 print "<div class=\"infoBoxContents\">";
3001
3002 $icon_file = ICONS_DIR . "/$feed_id.ico";
3003
3004 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3005 $feed_icon = "<img width=\"16\" height=\"16\"
3006 src=\"" . ICONS_URL . "/$feed_id.ico\">";
3007 } else {
3008 $feed_icon = "";
3009 }
3010
3011 print "<h1>$feed_icon $title</h1>";
3012
3013 print "<table width='100%'>";
3014
3015 if ($site_url) {
3016 print "<tr><td width='30%'>Link</td>
3017 <td><a href=\"$site_url\">$site_url</a>
3018 <a href=\"$feed_url\">(feed)</a></td>
3019 </td></tr>";
3020 } else {
3021 print "<tr><td width='30%'>Feed URL</td>
3022 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3023 }
3024 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3025 print "<tr><td>Total articles</td><td>$total</td></tr>";
3026 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3027 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3028 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3029
3030 print "</table>";
3031
3032 $result = db_query($link, "SELECT title,
3033 SUBSTRING(updated,1,16) AS updated,unread
3034 FROM ttrss_entries,ttrss_user_entries
3035 WHERE ref_id = id AND feed_id = '$feed_id'
3036 ORDER BY date_entered DESC LIMIT 5");
3037
3038 if (db_num_rows($result) > 0) {
3039
3040 print "<h1>Latest headlines</h1>";
3041
3042 print "<ul class=\"nomarks\">";
3043
3044 while ($line = db_fetch_assoc($result)) {
3045 if ($line["unread"] == "t" || $line["unread"] == "1") {
3046 $line["title"] = "<b>" . $line["title"] . "</b>";
3047 }
3048 print "<li>" . $line["title"].
3049 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
3050 }
3051
3052 print "</ul>";
3053
3054 print "</div>";
3055
3056 print "<div align='center'>
3057 <input type='submit' class='button'
3058 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3059 }
3060 }
3061
3062 db_close($link);
3063 ?>
3064
3065 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3066