]> git.wh0rd.org - tt-rss.git/blob - backend.php
new options: SHORT_DATE_FORMAT, LONG_DATE_FORMAT
[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
687 if (!$feed) {
688 return;
689 }
690
691 if (!$skip) $skip = 0;
692
693 if ($subop == "undefined") $subop = "";
694
695 if ($addheader) {
696 print "<html><head>
697 <title>Tiny Tiny RSS : Feed $feed</title>
698 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
699
700 $user_theme = $_SESSION["theme"];
701 if ($user_theme) {
702 print "<link rel=\"stylesheet\" type=\"text/css\"
703 href=\"themes/$user_theme/theme.css\">";
704 }
705
706 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
707 print "<link rel=\"stylesheet\"
708 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
709
710 } else {
711 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
712 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
713 }
714
715 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
716 <script type=\"text/javascript\" src=\"functions.js\"></script>
717 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
718 </head><body onload='init()'>";
719 }
720
721 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
722
723 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
724 WHERE id = '$feed'");
725
726 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
727
728 update_rss_feed($link, $feed_url, $feed);
729
730 }
731
732 if ($subop == "MarkAllRead") {
733
734 if (sprintf("%d", $feed) != 0) {
735
736 if ($feed > 0) {
737 db_query($link, "UPDATE ttrss_user_entries
738 SET unread = false,last_read = NOW()
739 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
740
741 } else if ($feed < 0 && $feed > -10) { // special, like starred
742
743 if ($feed == -1) {
744 db_query($link, "UPDATE ttrss_user_entries
745 SET unread = false,last_read = NOW()
746 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
747 }
748
749 } else if ($feed < -10) { // label
750
751 // TODO make this more efficient
752
753 $label_id = -$feed - 11;
754
755 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
756 WHERE id = '$label_id'");
757
758 if ($tmp_result) {
759 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
760
761 db_query($link, "BEGIN");
762
763 $tmp2_result = db_query($link,
764 "SELECT
765 int_id
766 FROM
767 ttrss_user_entries,ttrss_entries
768 WHERE
769 ref_id = id AND
770 $sql_exp AND
771 owner_uid = " . $_SESSION["uid"]);
772
773 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
774 db_query($link, "UPDATE
775 ttrss_user_entries
776 SET
777 unread = false, last_read = NOW()
778 WHERE
779 int_id = " . $tmp_line["int_id"]);
780 }
781
782 db_query($link, "COMMIT");
783
784 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
785 SET unread = false,last_read = NOW()
786 WHERE $sql_exp
787 AND ref_id = id
788 AND owner_uid = ".$_SESSION["uid"]); */
789 }
790 }
791 } else { // tag
792 db_query($link, "BEGIN");
793
794 $tag_name = db_escape_string($feed);
795
796 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
797 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
798
799 while ($line = db_fetch_assoc($result)) {
800 db_query($link, "UPDATE ttrss_user_entries SET
801 unread = false, last_read = NOW()
802 WHERE int_id = " . $line["post_int_id"]);
803 }
804 db_query($link, "COMMIT");
805 }
806
807 }
808
809 $search = $_GET["search"];
810
811 $search_mode = $_GET["smode"];
812
813 if ($search) {
814 $search_query_part = "(upper(title) LIKE upper('%$search%')
815 OR content LIKE '%$search%') AND";
816 } else {
817 $search_query_part = "";
818 }
819
820 $view_query_part = "";
821
822 if ($view_mode == "Starred") {
823 $view_query_part = " marked = true AND ";
824 }
825
826 if ($view_mode == "Unread") {
827 $view_query_part = " unread = true AND ";
828 }
829
830 if ($view_mode == "Unread or Starred") {
831 $view_query_part = " (unread = true OR marked = true) AND ";
832 }
833
834 if ($view_mode == "Unread or Updated") {
835 $view_query_part = " (unread = true OR last_read is NULL) AND ";
836 }
837
838 /* $result = db_query($link, "SELECT count(id) AS total_entries
839 FROM ttrss_entries WHERE
840 $search_query_part
841 feed_id = '$feed'");
842
843 $total_entries = db_fetch_result($result, 0, "total_entries"); */
844
845 /* $result = db_query("SELECT count(id) AS unread_entries
846 FROM ttrss_entries WHERE
847 $search_query_part
848 unread = true AND
849 feed_id = '$feed'");
850
851 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
852
853 if ($limit && $limit != "All") {
854 $limit_query_part = "LIMIT " . $limit;
855 }
856
857 $vfeed_query_part = "";
858
859 // override query strategy and enable feed display when searching globally
860 if ($search && $search_mode == "All feeds") {
861 $query_strategy_part = "id > 0";
862 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
863 id = feed_id) as feed_title,";
864 } else if (sprintf("%d", $feed) == 0) {
865 $query_strategy_part = "ttrss_entries.id > 0";
866 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
867 id = feed_id) as feed_title,";
868 } else if ($feed >= 0) {
869 $query_strategy_part = "feed_id = '$feed'";
870 } else if ($feed == -1) { // starred virtual feed
871 $query_strategy_part = "marked = true";
872 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
873 id = feed_id) as feed_title,";
874 } else if ($feed <= -10) { // labels
875 $label_id = -$feed - 11;
876
877 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
878 WHERE id = '$label_id'");
879
880 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
881
882 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
883 id = feed_id) as feed_title,";
884 } else {
885 $query_strategy_part = "id > 0"; // dumb
886 }
887
888 $order_by = "updated DESC";
889
890 // if ($feed < -10) {
891 // $order_by = "feed_id,updated DESC";
892 // }
893
894 $feed_title = "";
895
896 if ($search && $search_mode == "All feeds") {
897 $feed_title = "Search results";
898 } else if (sprintf("%d", $feed) == 0) {
899 $feed_title = $feed;
900 } else if ($feed > 0) {
901 $result = db_query($link, "SELECT title,site_url FROM ttrss_feeds
902 WHERE id = '$feed'");
903
904 $feed_title = db_fetch_result($result, 0, "title");
905 $feed_site_url = db_fetch_result($result, 0, "site_url");
906
907 } else if ($feed == -1) {
908 $feed_title = "Starred articles";
909 } else if ($feed < -10) {
910 $label_id = -$feed - 11;
911 $result = db_query($link, "SELECT description FROM ttrss_labels
912 WHERE id = '$label_id'");
913 $feed_title = db_fetch_result($result, 0, "description");
914 } else {
915 $feed_title = "?";
916 }
917
918 print "<table class=\"headlinesSubToolbar\"
919 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
920
921 print "<td class=\"headlineActions\">
922 Select:
923 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
924 'RROW-', 'RCHK-', true)\">All</a>,
925 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
926 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
927 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
928 'RROW-', 'RCHK-', false)\">None</a>
929 &nbsp;&nbsp;
930 Toggle: <a href=\"javascript:toggleUnread()\">Unread</a>,
931 <a href=\"javascript:toggleStarred()\">Starred</a>";
932
933 /* print "&nbsp;&nbsp;
934 View:
935 <a href=\"javascript:limitView('All')\">All</a>,
936 <a href=\"javascript:limitView('Unread')\">Unread</a>,
937 <a href=\"javascript:limitView('Starred')\">Starred</a>
938 &nbsp;&nbsp;
939 Feed:
940 <a href=\"javascript:updateCurrentFeed()\">Update</a>,
941 <a href=\"javascript:catchupCurrentFeed()\">Mark as read</a>"; */
942
943 print "</td>";
944
945 print "<td class=\"headlineTitle\">";
946
947 if ($feed_site_url) {
948 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
949 } else {
950 print $feed_title;
951 }
952
953 print "</td>";
954 print "</tr></table>";
955
956 print "<table class=\"headlinesList\" id=\"headlinesList\"
957 cellspacing=\"0\" width=\"100%\">";
958
959
960 if ($feed < -10) error_reporting (0);
961
962 if (sprintf("%d", $feed) != 0) {
963
964 if ($feed > 0) {
965 $feed_kind = "Feeds";
966 } else {
967 $feed_kind = "Labels";
968 }
969
970 if (!$vfeed_query_part) {
971 $content_query_part = "content as content_preview,";
972 } else {
973 $content_query_part = "";
974 }
975
976 $result = db_query($link, "SELECT
977 id,title,
978 SUBSTRING(updated,1,16) as updated,
979 unread,feed_id,marked,link,last_read,
980 SUBSTRING(last_read,1,19) as last_read_noms,
981 $vfeed_query_part
982 $content_query_part
983 SUBSTRING(updated,1,19) as updated_noms
984 FROM
985 ttrss_entries,ttrss_user_entries
986 WHERE
987 ttrss_user_entries.ref_id = ttrss_entries.id AND
988 owner_uid = '".$_SESSION["uid"]."' AND
989 $search_query_part
990 $view_query_part
991 $query_strategy_part ORDER BY $order_by
992 $limit_query_part");
993
994 } else {
995 // browsing by tag
996
997 $feed_kind = "Tags";
998
999 $result = db_query($link, "SELECT
1000 ttrss_entries.id as id,title,
1001 SUBSTRING(updated,1,16) as updated,
1002 unread,feed_id,
1003 marked,link,last_read,
1004 SUBSTRING(last_read,1,19) as last_read_noms,
1005 $vfeed_query_part
1006 $content_query_part
1007 SUBSTRING(updated,1,19) as updated_noms
1008 FROM
1009 ttrss_entries,ttrss_user_entries,ttrss_tags
1010 WHERE
1011 ref_id = ttrss_entries.id AND
1012 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1013 post_int_id = int_id AND tag_name = '$feed' AND
1014 $view_query_part
1015 $search_query_part
1016 $query_strategy_part ORDER BY $order_by
1017 $limit_query_part");
1018 }
1019
1020 if (!$result) {
1021 print "<tr><td colspan='4' align='center'>
1022 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
1023 return;
1024 }
1025
1026 $lnum = 0;
1027
1028 error_reporting (DEFAULT_ERROR_LEVEL);
1029
1030 $num_unread = 0;
1031
1032 while ($line = db_fetch_assoc($result)) {
1033
1034 $class = ($lnum % 2) ? "even" : "odd";
1035
1036 $id = $line["id"];
1037 $feed_id = $line["feed_id"];
1038
1039 if ($line["last_read"] == "" &&
1040 ($line["unread"] != "t" && $line["unread"] != "1")) {
1041
1042 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1043 alt=\"Updated\">";
1044 } else {
1045 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1046 alt=\"Updated\">";
1047 }
1048
1049 if ($line["unread"] == "t" || $line["unread"] == "1") {
1050 $class .= "Unread";
1051 ++$num_unread;
1052 }
1053
1054 if ($line["marked"] == "t" || $line["marked"] == "1") {
1055 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1056 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
1057 } else {
1058 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1059 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
1060 }
1061
1062 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
1063 $line["title"] . "</a>";
1064
1065 print "<tr class='$class' id='RROW-$id'>";
1066 // onclick=\"javascript:view($id,$feed_id)\">
1067
1068 print "<td valign='center' class='hlUpdatePic'>$update_pic</td>";
1069
1070 print "<td valign='center' class='hlSelectRow'>
1071 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1072 class=\"feedCheckBox\" id=\"RCHK-$id\">
1073 </td>";
1074
1075 print "<td valign='center' class='hlMarkedPic'>$marked_pic</td>";
1076
1077 if ($line["feed_title"]) {
1078 print "<td class='hlContent'>$content_link</td>";
1079 print "<td class='hlFeed'>
1080 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
1081 } else {
1082 print "<td class='hlContent'>";
1083
1084 print "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
1085 $line["title"];
1086
1087 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1088
1089 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1090 101);
1091
1092 print "<span class=\"contentPreview\"> - $content_preview</span>";
1093 }
1094
1095 print "</a>";
1096 print "</td>";
1097 }
1098
1099 $updated_fmt = date(get_pref($link, 'SHORT_DATE_FORMAT'),
1100 strtotime($line["updated"]));
1101 print "<td class=\"hlUpdated\"><nobr>$updated_fmt</nobr></td>";
1102
1103 print "</tr>";
1104
1105 ++$lnum;
1106 }
1107
1108 if ($lnum == 0) {
1109 print "<tr><td align='center'>No articles found.</td></tr>";
1110 }
1111
1112 print "</table>";
1113
1114 print "<script type=\"text/javascript\">
1115 document.onkeydown = hotkey_handler;
1116 update_all_counters('$feed');
1117 </script>";
1118
1119 if ($addheader) {
1120 print "</body></html>";
1121 }
1122
1123 }
1124
1125 if ($op == "pref-rpc") {
1126
1127 $subop = $_GET["subop"];
1128
1129 if ($subop == "unread") {
1130 $ids = split(",", $_GET["ids"]);
1131 foreach ($ids as $id) {
1132 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1133 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1134 }
1135
1136 print "Marked selected feeds as unread.";
1137 }
1138
1139 if ($subop == "read") {
1140 $ids = split(",", $_GET["ids"]);
1141 foreach ($ids as $id) {
1142 db_query($link, "UPDATE ttrss_user_entries
1143 SET unread = false,last_read = NOW() WHERE
1144 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1145 }
1146
1147 print "Marked selected feeds as read.";
1148
1149 }
1150
1151 }
1152
1153 if ($op == "pref-feeds") {
1154
1155 $subop = $_GET["subop"];
1156
1157 if ($subop == "editSave") {
1158 $feed_title = db_escape_string($_GET["t"]);
1159 $feed_link = db_escape_string($_GET["l"]);
1160 $upd_intl = db_escape_string($_GET["ui"]);
1161 $purge_intl = db_escape_string($_GET["pi"]);
1162 $feed_id = db_escape_string($_GET["id"]);
1163 $cat_id = db_escape_string($_GET["catid"]);
1164
1165 if (strtoupper($upd_intl) == "DEFAULT")
1166 $upd_intl = 0;
1167
1168 if (strtoupper($purge_intl) == "DEFAULT")
1169 $purge_intl = 0;
1170
1171 if (strtoupper($purge_intl) == "DISABLED")
1172 $purge_intl = -1;
1173
1174 if ($cat_id != 0) {
1175 $category_qpart = "cat_id = '$cat_id'";
1176 } else {
1177 $category_qpart = 'cat_id = NULL';
1178 }
1179
1180 $result = db_query($link, "UPDATE ttrss_feeds SET
1181 $category_qpart,
1182 title = '$feed_title', feed_url = '$feed_link',
1183 update_interval = '$upd_intl',
1184 purge_interval = '$purge_intl'
1185 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1186
1187 }
1188
1189 if ($subop == "remove") {
1190
1191 if (!WEB_DEMO_MODE) {
1192
1193 $ids = split(",", $_GET["ids"]);
1194
1195 foreach ($ids as $id) {
1196 db_query($link, "DELETE FROM ttrss_feeds
1197 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1198
1199 $icons_dir = ICONS_DIR;
1200
1201 if (file_exists($icons_dir . "/$id.ico")) {
1202 unlink($icons_dir . "/$id.ico");
1203 }
1204 }
1205 }
1206 }
1207
1208 if ($subop == "add") {
1209
1210 if (!WEB_DEMO_MODE) {
1211
1212 $feed_link = db_escape_string(trim($_GET["link"]));
1213
1214 $result = db_query($link,
1215 "SELECT id FROM ttrss_feeds
1216 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1217
1218 if (db_num_rows($result) == 0) {
1219
1220 $result = db_query($link,
1221 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1222 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
1223
1224 $result = db_query($link,
1225 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1226 AND owner_uid = " . $_SESSION["uid"]);
1227
1228 $feed_id = db_fetch_result($result, 0, "id");
1229
1230 if ($feed_id) {
1231 update_rss_feed($link, $feed_link, $feed_id, true);
1232 }
1233 } else {
1234
1235 print "<div class=\"warning\">
1236 Feed <b>$feed_link</b> already exists in the database.
1237 </div>";
1238 }
1239 }
1240 }
1241
1242 if ($subop == "addCat") {
1243
1244 if (!WEB_DEMO_MODE) {
1245
1246 $feed_cat = db_escape_string(trim($_GET["cat"]));
1247
1248 $result = db_query($link,
1249 "SELECT id FROM ttrss_feed_categories
1250 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1251
1252 if (db_num_rows($result) == 0) {
1253
1254 $result = db_query($link,
1255 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1256 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1257
1258 } else {
1259
1260 print "<div class=\"warning\">
1261 Category <b>$feed_cat</b> already exists in the database.
1262 </div>";
1263 }
1264
1265
1266 }
1267 }
1268
1269 if ($subop == "removeCats") {
1270
1271 if (!WEB_DEMO_MODE) {
1272
1273 $ids = split(",", $_GET["ids"]);
1274
1275 foreach ($ids as $id) {
1276
1277 db_query($link, "BEGIN");
1278
1279 $result = db_query($link,
1280 "SELECT count(id) as num_feeds FROM ttrss_feeds
1281 WHERE cat_id = '$id'");
1282
1283 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1284
1285 if ($num_feeds == 0) {
1286 db_query($link, "DELETE FROM ttrss_feed_categories
1287 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1288 } else {
1289
1290 print "<div class=\"warning\">
1291 Unable to delete non empty feed categories.</div>";
1292
1293 }
1294
1295 db_query($link, "COMMIT");
1296 }
1297 }
1298 }
1299
1300 // print "<h3>Edit Feeds</h3>";
1301
1302 $result = db_query($link, "SELECT id,title,feed_url,last_error
1303 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1304
1305 if (db_num_rows($result) > 0) {
1306
1307 print "<div class=\"warning\">";
1308
1309 print "<b>Feeds with update errors:</b>";
1310
1311 print "<ul class=\"nomarks\">";
1312
1313 while ($line = db_fetch_assoc($result)) {
1314 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1315 $line["last_error"];
1316 }
1317
1318 print "</ul>";
1319 print "</div>";
1320
1321 }
1322
1323 print "<p><div class=\"prefGenericAddBox\">
1324 <input id=\"fadd_link\" size=\"40\">&nbsp;<input
1325 type=\"submit\" class=\"button\"
1326 onclick=\"javascript:addFeed()\" value=\"Add feed\"></div>";
1327
1328 $feeds_sort = db_escape_string($_GET["sort"]);
1329
1330 if (!$feeds_sort || $feeds_sort == "undefined") {
1331 $feeds_sort = $_SESSION["pref_sort_feeds"];
1332 if (!$feeds_sort) $feeds_sort = "title";
1333 }
1334
1335 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1336
1337 $result = db_query($link, "SELECT
1338 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1339 update_interval,purge_interval,
1340 (SELECT title FROM ttrss_feed_categories
1341 WHERE id = cat_id) AS category
1342 FROM
1343 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."'
1344 ORDER by $feeds_sort,title");
1345
1346 if (db_num_rows($result) != 0) {
1347
1348 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1349
1350 print "<p><table width=\"100%\" cellspacing=\"0\"
1351 class=\"prefFeedList\" id=\"prefFeedList\">";
1352 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1353 Select:
1354 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1355 'FEEDR-', 'FRCHK-', true)\">All</a>,
1356 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1357 'FEEDR-', 'FRCHK-', false)\">None</a>
1358 </td</tr>";
1359
1360 print "<tr class=\"title\">
1361 <td width=\"3%\">&nbsp;</td>
1362 <td width=\"3%\">Select</td>
1363 <td width=\"20%\">
1364 <a href=\"javascript:updateFeedList('title')\">Title</a></td>
1365 <td width=\"20%\">
1366 <a href=\"javascript:updateFeedList('feed_url')\">Link</a>
1367 </td>";
1368
1369 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1370 print "<td width=\"10%\">
1371 <a href=\"javascript:updateFeedList('category')\">Category</a></td>";
1372 }
1373
1374 print "
1375 <td width=\"10%\">
1376 <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a>
1377 </td>
1378 <td width=\"10%\">
1379 <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a>
1380 </td>
1381 </tr>";
1382
1383 $lnum = 0;
1384
1385 while ($line = db_fetch_assoc($result)) {
1386
1387 $class = ($lnum % 2) ? "even" : "odd";
1388
1389 $feed_id = $line["id"];
1390
1391 $edit_feed_id = $_GET["id"];
1392
1393 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1394 $class .= "Grayed";
1395 $this_row_id = "";
1396 } else {
1397 $this_row_id = "id=\"FEEDR-$feed_id\"";
1398 }
1399
1400 print "<tr class=\"$class\" $this_row_id>";
1401
1402 $icon_file = ICONS_DIR . "/$feed_id.ico";
1403
1404 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1405 $feed_icon = "<img width=\"16\" height=\"16\"
1406 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1407 } else {
1408 $feed_icon = "&nbsp;";
1409 }
1410 print "<td align='center'>$feed_icon</td>";
1411
1412 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1413 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1414 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1415
1416 if (!$edit_cat) $edit_cat = "Uncategorized";
1417
1418 if (!$edit_feed_id || $subop != "edit") {
1419
1420 print "<td><input onclick='toggleSelectRow(this);'
1421 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1422
1423 $edit_title = truncate_string($edit_title, 40);
1424 $edit_link = truncate_string($edit_link, 60);
1425
1426 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1427 $edit_title . "</a></td>";
1428
1429 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1430 $edit_link . "</a></td>";
1431
1432 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1433 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1434 $edit_cat . "</a></td>";
1435 }
1436
1437 if ($line["update_interval"] == "0")
1438 $line["update_interval"] = "Default";
1439
1440 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1441 $line["update_interval"] . "</a></td>";
1442
1443 if ($line["purge_interval"] == "0")
1444 $line["purge_interval"] = "Default";
1445
1446 if ($line["purge_interval"] < 0)
1447 $line["purge_interval"] = "Disabled";
1448
1449 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1450 $line["purge_interval"] . "</a></td>";
1451
1452 } else if ($feed_id != $edit_feed_id) {
1453
1454 print "<td><input disabled=\"true\" type=\"checkbox\"
1455 id=\"FRCHK-".$line["id"]."\"></td>";
1456
1457 $edit_title = truncate_string($edit_title, 40);
1458 $edit_link = truncate_string($edit_link, 60);
1459
1460 print "<td>$edit_title</td>";
1461 print "<td>$edit_link</td>";
1462
1463 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1464 print "<td>$edit_cat</td>";
1465 }
1466
1467 if ($line["update_interval"] == "0")
1468 $line["update_interval"] = "Default";
1469
1470 print "<td>" . $line["update_interval"] . "</td>";
1471
1472 if ($line["purge_interval"] == "0")
1473 $line["purge_interval"] = "Default";
1474
1475 if ($line["purge_interval"] < 0)
1476 $line["purge_interval"] = "Disabled";
1477
1478 print "<td>" . $line["purge_interval"] . "</td>";
1479
1480 } else {
1481
1482 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1483
1484 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1485 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1486
1487 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1488
1489 print "<td>";
1490 print "<select id=\"iedit_fcat\">";
1491 print "<option id=\"0\">Uncategorized</option>";
1492
1493 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1494 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1495
1496 if (db_num_rows($tmp_result) > 0) {
1497 print "<option disabled>--------</option>";
1498 }
1499
1500 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1501 if ($tmp_line["id"] == $line["cat_id"]) {
1502 $is_selected = "selected";
1503 } else {
1504 $is_selected = "";
1505 }
1506 printf("<option $is_selected id='%d'>%s</option>",
1507 $tmp_line["id"], $tmp_line["title"]);
1508 }
1509
1510 print "</select></td>";
1511 print "</td>";
1512
1513 }
1514
1515 print "<td><input id=\"iedit_updintl\"
1516 value=\"".$line["update_interval"]."\"></td>";
1517 print "<td><input id=\"iedit_purgintl\"
1518 value=\"".$line["purge_interval"]."\"></td>";
1519
1520 }
1521
1522 /* if (!$line["last_updated"]) $line["last_updated"] = "Never";
1523
1524 print "<td>" . $line["last_updated"] . "</td>"; */
1525
1526 print "</tr>";
1527
1528 ++$lnum;
1529 }
1530
1531 print "</table>";
1532
1533 print "<p>";
1534
1535 if ($subop == "edit") {
1536 print "Edit feed:&nbsp;
1537 <input type=\"submit\" class=\"button\"
1538 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1539 <input type=\"submit\" class=\"button\"
1540 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1541 } else {
1542
1543 print "
1544 Selection:&nbsp;
1545 <input type=\"submit\" class=\"button\"
1546 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1547 <input type=\"submit\" class=\"button\"
1548 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1549 <input type=\"submit\" class=\"button\"
1550 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1551
1552 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1553 print "
1554 <input type=\"submit\" class=\"button\"
1555 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
1556 <input type=\"submit\" class=\"button\"
1557 onclick=\"javascript:readSelectedFeeds(false)\"
1558 value=\"Mark as unread\">&nbsp;";
1559 }
1560
1561 print "
1562 All feeds: <input type=\"submit\"
1563 class=\"button\" onclick=\"gotoExportOpml()\"
1564 value=\"Export OPML\">";
1565 }
1566 } else {
1567
1568 print "<p>No feeds defined.</p>";
1569
1570 }
1571
1572 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1573
1574 print "<h3>Edit Categories</h3>";
1575
1576 // print "<h3>Categories</h3>";
1577
1578 print "<div class=\"prefGenericAddBox\">
1579 <input id=\"fadd_cat\" size=\"40\">&nbsp;<input
1580 type=\"submit\" class=\"button\"
1581 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1582
1583 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1584 WHERE owner_uid = ".$_SESSION["uid"]."
1585 ORDER BY title");
1586
1587 if (db_num_rows($result) != 0) {
1588
1589 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1590 cellspacing=\"0\" id=\"prefFeedCatList\">";
1591
1592 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1593 Select:
1594 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1595 'FCATR-', 'FCCHK-', true)\">All</a>,
1596 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1597 'FCATR-', 'FCCHK-', false)\">None</a>
1598 </td</tr>";
1599
1600 print "<tr class=\"title\">
1601 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1602 </tr>";
1603
1604 $lnum = 0;
1605
1606 while ($line = db_fetch_assoc($result)) {
1607
1608 $class = ($lnum % 2) ? "even" : "odd";
1609
1610 $cat_id = $line["id"];
1611
1612 $edit_cat_id = $_GET["id"];
1613
1614 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1615 $class .= "Grayed";
1616 $this_row_id = "";
1617 } else {
1618 $this_row_id = "id=\"FCATR-$cat_id\"";
1619 }
1620
1621 print "<tr class=\"$class\" $this_row_id>";
1622
1623 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1624
1625 if (!$edit_cat_id || $subop != "editCat") {
1626
1627 print "<td><input onclick='toggleSelectRow(this);'
1628 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1629
1630 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1631 $edit_title . "</a></td>";
1632
1633 } else if ($cat_id != $edit_cat_id) {
1634
1635 print "<td><input disabled=\"true\" type=\"checkbox\"
1636 id=\"FRCHK-".$line["id"]."\"></td>";
1637
1638 print "<td>$edit_title</td>";
1639
1640 } else {
1641
1642 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1643
1644 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1645
1646 }
1647
1648 print "</tr>";
1649
1650 ++$lnum;
1651 }
1652
1653 print "</table>";
1654
1655 print "<p>";
1656
1657 if ($subop == "editCat") {
1658 print "Edit category:&nbsp;
1659 <input type=\"submit\" class=\"button\"
1660 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1661 <input type=\"submit\" class=\"button\"
1662 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1663 } else {
1664
1665 print "
1666 Selection:&nbsp;
1667 <input type=\"submit\" class=\"button\"
1668 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1669 <input type=\"submit\" class=\"button\"
1670 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1671
1672 }
1673
1674 } else {
1675 print "<p>No feed categories defined.</p>";
1676 }
1677 }
1678
1679 print "<h3>Import OPML</h3>
1680 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1681 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1682 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1683 type=\"submit\" value=\"Import\">
1684 </form>";
1685
1686 }
1687
1688 if ($op == "pref-filters") {
1689
1690 $subop = $_GET["subop"];
1691
1692 if ($subop == "editSave") {
1693
1694 $regexp = db_escape_string($_GET["r"]);
1695 $descr = db_escape_string($_GET["d"]);
1696 $match = db_escape_string($_GET["m"]);
1697 $filter_id = db_escape_string($_GET["id"]);
1698 $feed_id = db_escape_string($_GET["fid"]);
1699
1700 if (!$feed_id) {
1701 $feed_id = 'NULL';
1702 } else {
1703 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1704 }
1705
1706 $result = db_query($link, "UPDATE ttrss_filters SET
1707 reg_exp = '$regexp',
1708 description = '$descr',
1709 feed_id = $feed_id,
1710 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1711 description = '$match')
1712 WHERE id = '$filter_id'");
1713 }
1714
1715 if ($subop == "remove") {
1716
1717 if (!WEB_DEMO_MODE) {
1718
1719 $ids = split(",", $_GET["ids"]);
1720
1721 foreach ($ids as $id) {
1722 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1723
1724 }
1725 }
1726 }
1727
1728 if ($subop == "add") {
1729
1730 if (!WEB_DEMO_MODE) {
1731
1732 $regexp = db_escape_string(trim($_GET["regexp"]));
1733 $match = db_escape_string(trim($_GET["match"]));
1734 $feed_id = db_escape_string($_GET["fid"]);
1735
1736 if (!$feed_id) {
1737 $feed_id = 'NULL';
1738 } else {
1739 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1740 }
1741
1742 $result = db_query($link,
1743 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
1744 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1745 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
1746 }
1747 }
1748
1749 $result = db_query($link, "SELECT description
1750 FROM ttrss_filter_types ORDER BY description");
1751
1752 $filter_types = array();
1753
1754 while ($line = db_fetch_assoc($result)) {
1755 array_push($filter_types, $line["description"]);
1756 }
1757
1758 print "<div class=\"prefGenericAddBox\">
1759 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
1760
1761 print_select("fadd_match", "Title", $filter_types);
1762
1763 print "&nbsp;<select id=\"fadd_feed\">";
1764
1765 print "<option selected id=\"0\">All feeds</option>";
1766
1767 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1768 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1769
1770 if (db_num_rows($result) > 0) {
1771 print "<option disabled>--------</option>";
1772 }
1773
1774 while ($line = db_fetch_assoc($result)) {
1775 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1776 }
1777
1778 print "</select>&nbsp;";
1779
1780 print "<input type=\"submit\"
1781 class=\"button\" onclick=\"javascript:addFilter()\"
1782 value=\"Add filter\">";
1783
1784 $result = db_query($link, "SELECT
1785 ttrss_filters.id AS id,reg_exp,
1786 ttrss_filters.description AS description,
1787 ttrss_filter_types.name AS filter_type_name,
1788 ttrss_filter_types.description AS filter_type_descr,
1789 feed_id,
1790 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1791 FROM
1792 ttrss_filters,ttrss_filter_types
1793 WHERE
1794 filter_type = ttrss_filter_types.id AND
1795 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
1796 ORDER by reg_exp");
1797
1798 if (db_num_rows($result) != 0) {
1799
1800 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
1801 id=\"prefFilterList\">";
1802
1803 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1804 Select:
1805 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1806 'FILRR-', 'FICHK-', true)\">All</a>,
1807 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1808 'FILRR-', 'FICHK-', false)\">None</a>
1809 </td</tr>";
1810
1811 print "<tr class=\"title\">
1812 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1813 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1814 <td width=\"30%\">Description</td></tr>";
1815
1816 $lnum = 0;
1817
1818 while ($line = db_fetch_assoc($result)) {
1819
1820 $class = ($lnum % 2) ? "even" : "odd";
1821
1822 $filter_id = $line["id"];
1823 $edit_filter_id = $_GET["id"];
1824
1825 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1826 $class .= "Grayed";
1827 $this_row_id = "";
1828 } else {
1829 $this_row_id = "id=\"FILRR-$filter_id\"";
1830 }
1831
1832 print "<tr class=\"$class\" $this_row_id>";
1833
1834 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1835 $line["description"] = htmlspecialchars($line["description"]);
1836
1837 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1838
1839 if (!$edit_filter_id || $subop != "edit") {
1840
1841 if (!$line["description"]) $line["description"] = "[No description]";
1842
1843 print "<td><input onclick='toggleSelectRow(this);'
1844 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1845
1846 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1847 $line["reg_exp"] . "</td>";
1848
1849 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1850 $line["feed_title"] . "</td>";
1851
1852 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1853 $line["filter_type_descr"] . "</td>";
1854
1855 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1856 $line["description"] . "</td>";
1857
1858 } else if ($filter_id != $edit_filter_id) {
1859
1860 if (!$line["description"]) $line["description"] = "[No description]";
1861
1862 print "<td><input disabled=\"true\" type=\"checkbox\"
1863 id=\"FICHK-".$line["id"]."\"></td>";
1864
1865 print "<td>".$line["reg_exp"]."</td>";
1866 print "<td>".$line["feed_title"]."</td>";
1867 print "<td>".$line["filter_type_descr"]."</td>";
1868 print "<td>".$line["description"]."</td>";
1869
1870 } else {
1871
1872 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1873
1874 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1875 "\"></td>";
1876
1877 print "<td>";
1878
1879 print "<select id=\"iedit_feed\">";
1880
1881 print "<option id=\"0\">All feeds</option>";
1882
1883 if (db_num_rows($result) > 0) {
1884 print "<option disabled>--------</option>";
1885 }
1886
1887 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1888 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1889
1890 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1891 if ($tmp_line["id"] == $line["feed_id"]) {
1892 $is_selected = "selected";
1893 } else {
1894 $is_selected = "";
1895 }
1896 printf("<option $is_selected id='%d'>%s</option>",
1897 $tmp_line["id"], $tmp_line["title"]);
1898 }
1899
1900 print "</select></td>";
1901
1902 print "<td>";
1903 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1904 print "</td>";
1905
1906 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1907 "\"></td>";
1908
1909 print "</td>";
1910 }
1911
1912 print "</tr>";
1913
1914 ++$lnum;
1915 }
1916
1917 if ($lnum == 0) {
1918 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1919 }
1920
1921 print "</table>";
1922
1923 print "<p>";
1924
1925 if ($subop == "edit") {
1926 print "Edit feed:
1927 <input type=\"submit\" class=\"button\"
1928 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1929 <input type=\"submit\" class=\"button\"
1930 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1931
1932 } else {
1933
1934 print "
1935 Selection:
1936 <input type=\"submit\" class=\"button\"
1937 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1938 <input type=\"submit\" class=\"button\"
1939 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1940 }
1941
1942 } else {
1943
1944 print "<p>No filters defined.</p>";
1945
1946 }
1947 }
1948
1949 if ($op == "pref-labels") {
1950
1951 $subop = $_GET["subop"];
1952
1953 if ($subop == "test") {
1954
1955 $expr = $_GET["expr"];
1956 $descr = $_GET["descr"];
1957
1958 print "<div class='infoBoxContents'>";
1959
1960 print "<h1>Label &laquo;$descr&raquo;</h1>";
1961
1962 // print "<p><b>Expression</b>: $expr</p>";
1963
1964 $result = db_query($link,
1965 "SELECT count(id) AS num_matches
1966 FROM ttrss_entries,ttrss_user_entries
1967 WHERE ($expr) AND
1968 ttrss_user_entries.ref_id = ttrss_entries.id AND
1969 owner_uid = " . $_SESSION["uid"]);
1970
1971 $num_matches = db_fetch_result($result, 0, "num_matches");;
1972
1973 if ($num_matches > 0) {
1974
1975 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
1976
1977 $result = db_query($link,
1978 "SELECT title,
1979 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1980 FROM ttrss_entries,ttrss_user_entries
1981 WHERE ($expr) AND
1982 ttrss_user_entries.ref_id = ttrss_entries.id
1983 AND owner_uid = " . $_SESSION["uid"] . "
1984 ORDER BY date_entered DESC LIMIT 5");
1985
1986 print "<ul class=\"nomarks\">";
1987 while ($line = db_fetch_assoc($result)) {
1988 print "<li>".$line["title"].
1989 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
1990 }
1991 print "</ul>";
1992
1993 } else {
1994 print "<p>Query didn't return any matches.</p>";
1995 }
1996
1997 print "</div>";
1998
1999 print "<div align='center'>
2000 <input type='submit' class='button'
2001 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2002 return;
2003 }
2004
2005 if ($subop == "editSave") {
2006
2007 $sql_exp = $_GET["s"];
2008 $descr = $_GET["d"];
2009 $label_id = db_escape_string($_GET["id"]);
2010
2011 // print "$sql_exp : $descr : $label_id";
2012
2013 $result = db_query($link, "UPDATE ttrss_labels SET
2014 sql_exp = '$sql_exp',
2015 description = '$descr'
2016 WHERE id = '$label_id'");
2017 }
2018
2019 if ($subop == "remove") {
2020
2021 if (!WEB_DEMO_MODE) {
2022
2023 $ids = split(",", $_GET["ids"]);
2024
2025 foreach ($ids as $id) {
2026 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2027
2028 }
2029 }
2030 }
2031
2032 if ($subop == "add") {
2033
2034 if (!WEB_DEMO_MODE) {
2035
2036 // no escaping is done here on purpose
2037 $exp = trim($_GET["exp"]);
2038
2039 $result = db_query($link,
2040 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2041 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2042 }
2043 }
2044
2045 print "<div class=\"prefGenericAddBox\">
2046 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
2047
2048 print"<input type=\"submit\" class=\"button\"
2049 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2050
2051 $result = db_query($link, "SELECT
2052 id,sql_exp,description
2053 FROM
2054 ttrss_labels
2055 WHERE
2056 owner_uid = ".$_SESSION["uid"]."
2057 ORDER by description");
2058
2059 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2060
2061 if (db_num_rows($result) != 0) {
2062
2063 print "<p><table width=\"100%\" cellspacing=\"0\"
2064 class=\"prefLabelList\" id=\"prefLabelList\">";
2065
2066 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2067 Select:
2068 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2069 'LILRR-', 'LICHK-', true)\">All</a>,
2070 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2071 'LILRR-', 'LICHK-', false)\">None</a>
2072 </td</tr>";
2073
2074 print "<tr class=\"title\">
2075 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
2076 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2077 </td>
2078 <td width=\"40%\">Caption</td></tr>";
2079
2080 $lnum = 0;
2081
2082 while ($line = db_fetch_assoc($result)) {
2083
2084 $class = ($lnum % 2) ? "even" : "odd";
2085
2086 $label_id = $line["id"];
2087 $edit_label_id = $_GET["id"];
2088
2089 if ($subop == "edit" && $label_id != $edit_label_id) {
2090 $class .= "Grayed";
2091 $this_row_id = "";
2092 } else {
2093 $this_row_id = "id=\"LILRR-$label_id\"";
2094 }
2095
2096 print "<tr class=\"$class\" $this_row_id>";
2097
2098 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2099 $line["description"] = htmlspecialchars($line["description"]);
2100
2101 if (!$edit_label_id || $subop != "edit") {
2102
2103 if (!$line["description"]) $line["description"] = "[No caption]";
2104
2105 print "<td><input onclick='toggleSelectRow(this);'
2106 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2107
2108 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2109 $line["sql_exp"] . "</td>";
2110
2111 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2112 $line["description"] . "</td>";
2113
2114 } else if ($label_id != $edit_label_id) {
2115
2116 if (!$line["description"]) $line["description"] = "[No description]";
2117
2118 print "<td><input disabled=\"true\" type=\"checkbox\"
2119 id=\"LICHK-".$line["id"]."\"></td>";
2120
2121 print "<td>".$line["sql_exp"]."</td>";
2122 print "<td>".$line["description"]."</td>";
2123
2124 } else {
2125
2126 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2127
2128 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2129 "\"></td>";
2130
2131 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2132 "\"></td>";
2133
2134 }
2135
2136
2137 print "</tr>";
2138
2139 ++$lnum;
2140 }
2141
2142 if ($lnum == 0) {
2143 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2144 }
2145
2146 print "</table>";
2147
2148 print "<p>";
2149
2150 if ($subop == "edit") {
2151 print "Edit label:
2152 <input type=\"submit\" class=\"button\"
2153 onclick=\"javascript:labelTest()\" value=\"Test\">
2154 <input type=\"submit\" class=\"button\"
2155 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2156 <input type=\"submit\" class=\"button\"
2157 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2158
2159 } else {
2160
2161 print "
2162 Selection:
2163 <input type=\"submit\" class=\"button\"
2164 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2165 <input type=\"submit\" class=\"button\"
2166 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2167 }
2168 } else {
2169 print "<p>No labels defined.</p>";
2170 }
2171 }
2172
2173 if ($op == "error") {
2174 print "<div width=\"100%\" align='center'>";
2175 $msg = $_GET["msg"];
2176 print $msg;
2177 print "</div>";
2178 }
2179
2180 if ($op == "help") {
2181 if (!$_GET["noheaders"]) {
2182 print "<html><head>
2183 <title>Tiny Tiny RSS : Help</title>
2184 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2185 <script type=\"text/javascript\" src=\"functions.js\"></script>
2186 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2187 </head><body>";
2188 }
2189
2190 $tid = sprintf("%d", $_GET["tid"]);
2191
2192 print "<div class='infoBoxContents'>";
2193
2194 if (file_exists("help/$tid.php")) {
2195 include("help/$tid.php");
2196 } else {
2197 print "<p>Help topic not found.</p>";
2198 }
2199
2200 print "</div>";
2201
2202 print "<div align='center'>
2203 <input type='submit' class='button'
2204 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2205
2206 if (!$_GET["noheaders"]) {
2207 print "</body></html>";
2208 }
2209
2210 }
2211
2212 if ($op == "dlg") {
2213 $id = $_GET["id"];
2214 $param = $_GET["param"];
2215
2216 if ($id == "quickAddFeed") {
2217 print "
2218 Feed URL: <input
2219 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2220 id=\"qafInput\">
2221 <input class=\"button\"
2222 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2223 <input class=\"button\"
2224 type=\"submit\" onclick=\"javascript:closeDlg()\"
2225 value=\"Cancel\">";
2226 }
2227
2228 if ($id == "quickDelFeed") {
2229
2230 $param = db_escape_string($param);
2231
2232 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2233
2234 if ($result) {
2235
2236 $f_title = db_fetch_result($result, 0, "title");
2237
2238 print "Remove current feed (<b>$f_title</b>)?&nbsp;
2239 <input class=\"button\"
2240 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2241 <input class=\"button\"
2242 type=\"submit\" onclick=\"javascript:closeDlg()\"
2243 value=\"Cancel\">";
2244 } else {
2245 print "Error: Feed $param not found.&nbsp;
2246 <input class=\"button\"
2247 type=\"submit\" onclick=\"javascript:closeDlg()\"
2248 value=\"Cancel\">";
2249 }
2250 }
2251
2252 if ($id == "search") {
2253
2254 print "<input id=\"searchbox\" class=\"extSearch\"
2255 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2256 onchange=\"javascript:search()\">
2257 <select id=\"searchmodebox\">
2258 <option selected>All feeds</option>
2259 <option>This feed</option>
2260 </select>
2261 <input type=\"submit\"
2262 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2263 <input class=\"button\"
2264 type=\"submit\" onclick=\"javascript:closeDlg()\"
2265 value=\"Close\">";
2266
2267 }
2268
2269 }
2270
2271 // update feeds of all users, may be used anonymously
2272 if ($op == "globalUpdateFeeds") {
2273
2274 $result = db_query($link, "SELECT id FROM ttrss_users");
2275
2276 while ($line = db_fetch_assoc($result)) {
2277 $user_id = $line["id"];
2278 // print "<!-- updating feeds of uid $user_id -->";
2279 update_all_feeds($link, false, $user_id);
2280 }
2281
2282 print "<rpc-reply>
2283 <message msg=\"All feeds updated\"/>
2284 </rpc-reply>";
2285
2286 }
2287
2288 if ($op == "pref-prefs") {
2289
2290 $subop = $_REQUEST["subop"];
2291
2292 if ($subop == "Save configuration") {
2293
2294 if (WEB_DEMO_MODE) {
2295 header("Location: prefs.php");
2296 return;
2297 }
2298
2299 $_SESSION["prefs_op_result"] = "save-config";
2300
2301 foreach (array_keys($_POST) as $pref_name) {
2302
2303 $pref_name = db_escape_string($pref_name);
2304 $value = db_escape_string($_POST[$pref_name]);
2305
2306 $result = db_query($link, "SELECT type_name
2307 FROM ttrss_prefs,ttrss_prefs_types
2308 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2309
2310 if (db_num_rows($result) > 0) {
2311
2312 $type_name = db_fetch_result($result, 0, "type_name");
2313
2314 // print "$pref_name : $type_name : $value<br>";
2315
2316 if ($type_name == "bool") {
2317 if ($value == "1") {
2318 $value = "true";
2319 } else {
2320 $value = "false";
2321 }
2322 } else if ($type_name == "integer") {
2323 $value = sprintf("%d", $value);
2324 }
2325
2326 // print "$pref_name : $type_name : $value<br>";
2327
2328 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2329 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2330
2331 }
2332
2333 header("Location: prefs.php");
2334
2335 }
2336
2337 } else if ($subop == "getHelp") {
2338
2339 $pref_name = db_escape_string($_GET["pn"]);
2340
2341 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2342 WHERE pref_name = '$pref_name'");
2343
2344 if (db_num_rows($result) > 0) {
2345 $help_text = db_fetch_result($result, 0, "help_text");
2346 print $help_text;
2347 } else {
2348 print "Unknown option: $pref_name";
2349 }
2350
2351 } else if ($subop == "Change password") {
2352
2353 if (WEB_DEMO_MODE) {
2354 header("Location: prefs.php");
2355 return;
2356 }
2357
2358 $old_pw = $_POST["OLD_PASSWORD"];
2359 $new_pw = $_POST["OLD_PASSWORD"];
2360
2361 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2362 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2363
2364 $active_uid = $_SESSION["uid"];
2365
2366 if ($old_pw && $new_pw) {
2367
2368 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2369
2370 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2371 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2372 pwd_hash = '$old_pw_hash')");
2373
2374 if (db_num_rows($result) == 1) {
2375 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2376 WHERE id = '$active_uid'");
2377
2378 $_SESSION["pwd_change_result"] = "ok";
2379 } else {
2380 $_SESSION["pwd_change_result"] = "failed";
2381 }
2382 }
2383
2384 header("Location: prefs.php");
2385
2386 } else if ($subop == "Reset to defaults") {
2387
2388 if (WEB_DEMO_MODE) {
2389 header("Location: prefs.php");
2390 return;
2391 }
2392
2393 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2394
2395 if (DB_TYPE == "pgsql") {
2396 db_query($link,"UPDATE ttrss_user_prefs
2397 SET value = ttrss_prefs.def_value
2398 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2399 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2400 } else {
2401 db_query($link, "DELETE FROM ttrss_user_prefs
2402 WHERE owner_uid = ".$_SESSION["uid"]);
2403 initialize_user_prefs($link, $_SESSION["uid"]);
2404 }
2405
2406 header("Location: prefs.php");
2407
2408 } else if ($subop == "Change theme") {
2409
2410 $theme = db_escape_string($_POST["theme"]);
2411
2412 if ($theme == "Default") {
2413 $theme_qpart = 'NULL';
2414 } else {
2415 $theme_qpart = "'$theme'";
2416 }
2417
2418 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2419 WHERE theme_name = '$theme'");
2420
2421 if (db_num_rows($result) == 1) {
2422 $theme_id = db_fetch_result($result, 0, "id");
2423 $theme_path = db_fetch_result($result, 0, "theme_path");
2424 } else {
2425 $theme_id = "NULL";
2426 $theme_path = "";
2427 }
2428
2429 db_query($link, "UPDATE ttrss_users SET
2430 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2431
2432 $_SESSION["theme"] = $theme_path;
2433
2434 header("Location: prefs.php");
2435
2436 } else {
2437
2438 if (!SINGLE_USER_MODE) {
2439
2440 $result = db_query($link, "SELECT id FROM ttrss_users
2441 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2442 pwd_hash = 'SHA1:".sha1("password")."')");
2443
2444 if (db_num_rows($result) != 0) {
2445 print "<div class=\"warning\">
2446 Your password is at default value, please change it.
2447 </div>";
2448 }
2449
2450 if ($_SESSION["pwd_change_result"] == "failed") {
2451 print "<div class=\"warning\">
2452 There was an error while changing your password.
2453 </div>";
2454 }
2455
2456 if ($_SESSION["pwd_change_result"] == "ok") {
2457 print "<div class=\"notice\">
2458 Password changed successfully.
2459 </div>";
2460 }
2461
2462 $_SESSION["pwd_change_result"] = "";
2463
2464 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2465 print "<div class=\"notice\">
2466 Your configuration was reset to defaults.
2467 </div>";
2468 }
2469
2470 if ($_SESSION["prefs_op_result"] == "save-config") {
2471 print "<div class=\"notice\">
2472 Your configuration was saved successfully.
2473 </div>";
2474 }
2475
2476 $_SESSION["prefs_op_result"] = "";
2477
2478 print "<form action=\"backend.php\" method=\"POST\">";
2479
2480 print "<table width=\"100%\" class=\"prefPrefsList\">";
2481 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2482
2483 print "<tr><td width=\"40%\">Old password</td>";
2484 print "<td><input class=\"editbox\" type=\"password\"
2485 name=\"OLD_PASSWORD\"></td></tr>";
2486
2487 print "<tr><td width=\"40%\">New password</td>";
2488
2489 print "<td><input class=\"editbox\" type=\"password\"
2490 name=\"NEW_PASSWORD\"></td></tr>";
2491
2492 print "</table>";
2493
2494 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2495
2496 print "<p><input class=\"button\" type=\"submit\"
2497 value=\"Change password\" name=\"subop\">";
2498
2499 print "</form>";
2500
2501 }
2502
2503 $result = db_query($link, "SELECT
2504 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2505
2506 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2507
2508 $result = db_query($link, "SELECT
2509 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2510
2511 if (db_num_rows($result) > 0) {
2512
2513 print "<form action=\"backend.php\" method=\"POST\">";
2514 print "<table width=\"100%\" class=\"prefPrefsList\">";
2515 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2516 print "<tr><td width=\"40%\">Select theme</td>";
2517 print "<td><select name=\"theme\">";
2518 print "<option>Default</option>";
2519 print "<option disabled>--------</option>";
2520
2521 while ($line = db_fetch_assoc($result)) {
2522 if ($line["id"] == $user_theme_id) {
2523 $selected = "selected";
2524 } else {
2525 $selected = "";
2526 }
2527 print "<option $selected>" . $line["theme_name"] . "</option>";
2528 }
2529 print "</select></td></tr>";
2530 print "</table>";
2531 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2532 print "<p><input class=\"button\" type=\"submit\"
2533 value=\"Change theme\" name=\"subop\">";
2534 print "</form>";
2535 }
2536
2537 $result = db_query($link, "SELECT
2538 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
2539 section_name,def_value
2540 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
2541 WHERE type_id = ttrss_prefs_types.id AND
2542 section_id = ttrss_prefs_sections.id AND
2543 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2544 owner_uid = ".$_SESSION["uid"]."
2545 ORDER BY section_id,short_desc");
2546
2547 print "<form action=\"backend.php\" method=\"POST\">";
2548
2549 $lnum = 0;
2550
2551 $active_section = "";
2552
2553 while ($line = db_fetch_assoc($result)) {
2554
2555 if ($active_section != $line["section_name"]) {
2556
2557 if ($active_section != "") {
2558 print "</table>";
2559 }
2560
2561 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
2562
2563 $active_section = $line["section_name"];
2564
2565 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
2566 // print "<tr class=\"title\">
2567 // <td width=\"25%\">Option</td><td>Value</td></tr>";
2568
2569 $lnum = 0;
2570 }
2571
2572 // $class = ($lnum % 2) ? "even" : "odd";
2573
2574 print "<tr>";
2575
2576 $type_name = $line["type_name"];
2577 $pref_name = $line["pref_name"];
2578 $value = $line["value"];
2579 $def_value = $line["def_value"];
2580 $help_text = $line["help_text"];
2581
2582 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2583
2584 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2585
2586 print "</td>";
2587
2588 print "<td>";
2589
2590 if ($type_name == "bool") {
2591 // print_select($pref_name, $value, array("true", "false"));
2592
2593 if ($value == "true") {
2594 $value = "Yes";
2595 } else {
2596 $value = "No";
2597 }
2598
2599 print_radio($pref_name, $value, array("Yes", "No"));
2600
2601 } else {
2602 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2603 }
2604
2605 print "</td>";
2606
2607 print "</tr>";
2608
2609 $lnum++;
2610 }
2611
2612 print "</table>";
2613
2614 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2615
2616 print "<p><input class=\"button\" type=\"submit\"
2617 name=\"subop\" value=\"Save configuration\">";
2618
2619 print "&nbsp;<input class=\"button\" type=\"submit\"
2620 name=\"subop\" value=\"Reset to defaults\"></p>";
2621
2622 print "</form>";
2623
2624 }
2625
2626 }
2627
2628 if ($op == "pref-users") {
2629
2630 $subop = $_GET["subop"];
2631
2632 if ($subop == "editSave") {
2633
2634 if (!WEB_DEMO_MODE) {
2635
2636 $login = db_escape_string($_GET["l"]);
2637 $uid = db_escape_string($_GET["id"]);
2638 $access_level = sprintf("%d", $_GET["al"]);
2639
2640 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2641
2642 }
2643 } else if ($subop == "remove") {
2644
2645 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2646
2647 $ids = split(",", $_GET["ids"]);
2648
2649 foreach ($ids as $id) {
2650 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2651
2652 }
2653 }
2654 } else if ($subop == "add") {
2655
2656 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2657
2658 $login = db_escape_string(trim($_GET["login"]));
2659 $tmp_user_pwd = make_password(8);
2660 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2661
2662 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2663 VALUES ('$login', '$pwd_hash', 0)");
2664
2665
2666 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2667 login = '$login' AND pwd_hash = '$pwd_hash'");
2668
2669 if (db_num_rows($result) == 1) {
2670
2671 $new_uid = db_fetch_result($result, 0, "id");
2672
2673 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2674 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2675
2676 initialize_user($link, $new_uid);
2677
2678 } else {
2679
2680 print "<div class=\"warning\">Error while adding user <b>".
2681 $_GET["login"].".</b></div>";
2682
2683 }
2684 }
2685 } else if ($subop == "resetPass") {
2686
2687 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2688
2689 $uid = db_escape_string($_GET["id"]);
2690
2691 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2692
2693 $login = db_fetch_result($result, 0, "login");
2694 $tmp_user_pwd = make_password(8);
2695 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2696
2697 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2698 WHERE id = '$uid'");
2699
2700 print "<div class=\"notice\">Changed password of
2701 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2702
2703 }
2704 }
2705
2706 print "<div class=\"prefGenericAddBox\">
2707 <input id=\"uadd_box\" size=\"40\">&nbsp;";
2708
2709 print"<input type=\"submit\" class=\"button\"
2710 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
2711
2712 $result = db_query($link, "SELECT
2713 id,login,access_level,
2714 SUBSTRING(last_login,1,16) as last_login
2715 FROM
2716 ttrss_users
2717 ORDER by login");
2718
2719 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2720
2721 print "<p><table width=\"100%\" cellspacing=\"0\"
2722 class=\"prefUserList\" id=\"prefUserList\">";
2723
2724 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2725 Select:
2726 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2727 'UMRR-', 'UMCHK-', true)\">All</a>,
2728 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2729 'UMRR-', 'UMCHK-', false)\">None</a>
2730 </td</tr>";
2731
2732 print "<tr class=\"title\">
2733 <td width=\"5%\">Select</td>
2734 <td width='30%'>Username</td>
2735 <td width='30%'>Access Level</td>
2736 <td width='30%'>Last login</td></tr>";
2737
2738 $lnum = 0;
2739
2740 while ($line = db_fetch_assoc($result)) {
2741
2742 $class = ($lnum % 2) ? "even" : "odd";
2743
2744 $uid = $line["id"];
2745 $edit_uid = $_GET["id"];
2746
2747 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
2748 $class .= "Grayed";
2749 $this_row_id = "";
2750 } else {
2751 $this_row_id = "id=\"UMRR-$uid\"";
2752 }
2753
2754 print "<tr class=\"$class\" $this_row_id>";
2755
2756 $line["login"] = htmlspecialchars($line["login"]);
2757
2758 if ($uid == $_SESSION["uid"]) {
2759
2760 print "<td><input disabled=\"true\" type=\"checkbox\"
2761 id=\"UMCHK-".$line["id"]."\"></td>";
2762
2763 print "<td>".$line["login"]."</td>";
2764 print "<td>".$line["access_level"]."</td>";
2765
2766 } else if (!$edit_uid || $subop != "edit") {
2767
2768 print "<td><input onclick='toggleSelectRow(this);'
2769 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
2770
2771 print "<td><a href=\"javascript:editUser($uid);\">" .
2772 $line["login"] . "</td>";
2773
2774 print "<td><a href=\"javascript:editUser($uid);\">" .
2775 $line["access_level"] . "</td>";
2776
2777 } else if ($uid != $edit_uid) {
2778
2779 print "<td><input disabled=\"true\" type=\"checkbox\"
2780 id=\"UMCHK-".$line["id"]."\"></td>";
2781
2782 print "<td>".$line["login"]."</td>";
2783 print "<td>".$line["access_level"]."</td>";
2784
2785 } else {
2786
2787 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2788
2789 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2790 "\"></td>";
2791
2792 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2793 "\"></td>";
2794
2795 }
2796
2797 print "<td>".$line["last_login"]."</td>";
2798
2799 print "</tr>";
2800
2801 ++$lnum;
2802 }
2803
2804 print "</table>";
2805
2806 print "<p>";
2807
2808 if ($subop == "edit") {
2809 print "Edit label:
2810 <input type=\"submit\" class=\"button\"
2811 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2812 <input type=\"submit\" class=\"button\"
2813 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2814
2815 } else {
2816
2817 print "
2818 Selection:
2819 <input type=\"submit\" class=\"button\"
2820 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
2821 <input type=\"submit\" class=\"button\"
2822 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2823 <input type=\"submit\" class=\"button\"
2824 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2825 <input type=\"submit\" class=\"button\"
2826 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2827
2828 }
2829 }
2830
2831 if ($op == "user-details") {
2832
2833 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2834 return;
2835 }
2836
2837 /* print "<html><head>
2838 <title>Tiny Tiny RSS : User Details</title>
2839 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2840 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2841 </head><body>"; */
2842
2843 $uid = sprintf("%d", $_GET["id"]);
2844
2845 print "<div class='infoBoxContents'>";
2846
2847 $result = db_query($link, "SELECT login,
2848 SUBSTRING(last_login,1,16) AS last_login,
2849 access_level,
2850 (SELECT COUNT(int_id) FROM ttrss_user_entries
2851 WHERE owner_uid = id) AS stored_articles
2852 FROM ttrss_users
2853 WHERE id = '$uid'");
2854
2855 if (db_num_rows($result) == 0) {
2856 print "<h1>User not found</h1>";
2857 return;
2858 }
2859
2860 print "<h1>User Details</h1>";
2861
2862 print "<table width='100%'>";
2863
2864 $login = db_fetch_result($result, 0, "login");
2865 $last_login = db_fetch_result($result, 0, "last_login");
2866 $access_level = db_fetch_result($result, 0, "access_level");
2867 $stored_articles = db_fetch_result($result, 0, "stored_articles");
2868
2869 print "<tr><td>Username</td><td>$login</td></tr>";
2870 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2871 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
2872 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
2873
2874 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2875 WHERE owner_uid = '$uid'");
2876
2877 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2878
2879 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2880
2881 /* $result = db_query($link, "SELECT
2882 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
2883 FROM ttrss_user_entries,ttrss_entries
2884 WHERE owner_uid = '$uid' AND ref_id = id");
2885
2886 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
2887
2888 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
2889
2890 print "</table>";
2891
2892 print "<h1>Subscribed feeds</h1>";
2893
2894 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2895 WHERE owner_uid = '$uid' ORDER BY title");
2896
2897 print "<ul class=\"nomarks\">";
2898
2899 while ($line = db_fetch_assoc($result)) {
2900
2901 $icon_file = ICONS_URL."/".$line["id"].".ico";
2902
2903 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2904 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
2905 } else {
2906 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
2907 }
2908
2909 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2910 }
2911
2912 print "</ul>";
2913
2914 print "</div>";
2915
2916 print "<div align='center'>
2917 <input type='submit' class='button'
2918 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2919
2920 // print "</body></html>";
2921
2922 }
2923
2924 if ($op == "feed-details") {
2925
2926 $feed_id = $_GET["id"];
2927
2928 $result = db_query($link,
2929 "SELECT
2930 title,feed_url,last_updated,icon_url,site_url,
2931 (SELECT COUNT(int_id) FROM ttrss_user_entries
2932 WHERE feed_id = id) AS total,
2933 (SELECT COUNT(int_id) FROM ttrss_user_entries
2934 WHERE feed_id = id AND unread = true) AS unread,
2935 (SELECT COUNT(int_id) FROM ttrss_user_entries
2936 WHERE feed_id = id AND marked = true) AS marked
2937 FROM ttrss_feeds
2938 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2939
2940 if (db_num_rows($result) == 0) return;
2941
2942 $title = db_fetch_result($result, 0, "title");
2943 $last_updated = db_fetch_result($result, 0, "last_updated");
2944 $feed_url = db_fetch_result($result, 0, "feed_url");
2945 $icon_url = db_fetch_result($result, 0, "icon_url");
2946 $total = db_fetch_result($result, 0, "total");
2947 $unread = db_fetch_result($result, 0, "unread");
2948 $marked = db_fetch_result($result, 0, "marked");
2949 $site_url = db_fetch_result($result, 0, "site_url");
2950
2951 $result = db_query($link, "SELECT COUNT(id) AS subscribed
2952 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
2953
2954 $subscribed = db_fetch_result($result, 0, "subscribed");
2955
2956 print "<div class=\"infoBoxContents\">";
2957
2958 $icon_file = ICONS_DIR . "/$feed_id.ico";
2959
2960 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2961 $feed_icon = "<img width=\"16\" height=\"16\"
2962 src=\"" . ICONS_URL . "/$feed_id.ico\">";
2963 } else {
2964 $feed_icon = "";
2965 }
2966
2967 print "<h1>$feed_icon $title</h1>";
2968
2969 print "<table width='100%'>";
2970
2971 if ($site_url) {
2972 print "<tr><td width='30%'>Link</td>
2973 <td><a href=\"$site_url\">$site_url</a>
2974 <a href=\"$feed_url\">(feed)</a></td>
2975 </td></tr>";
2976 } else {
2977 print "<tr><td width='30%'>Feed URL</td>
2978 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
2979 }
2980 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
2981 print "<tr><td>Total articles</td><td>$total</td></tr>";
2982 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
2983 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
2984 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
2985
2986 print "</table>";
2987
2988 $result = db_query($link, "SELECT title,
2989 SUBSTRING(updated,1,16) AS updated,unread
2990 FROM ttrss_entries,ttrss_user_entries
2991 WHERE ref_id = id AND feed_id = '$feed_id'
2992 ORDER BY date_entered DESC LIMIT 5");
2993
2994 if (db_num_rows($result) > 0) {
2995
2996 print "<h1>Latest headlines</h1>";
2997
2998 print "<ul class=\"nomarks\">";
2999
3000 while ($line = db_fetch_assoc($result)) {
3001 if ($line["unread"] == "t" || $line["unread"] == "1") {
3002 $line["title"] = "<b>" . $line["title"] . "</b>";
3003 }
3004 print "<li>" . $line["title"].
3005 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
3006 }
3007
3008 print "</ul>";
3009
3010 print "</div>";
3011
3012 print "<div align='center'>
3013 <input type='submit' class='button'
3014 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3015 }
3016 }
3017
3018 db_close($link);
3019 ?>
3020
3021 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3022