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