]> git.wh0rd.org - tt-rss.git/blob - backend.php
feed errors box in feed editor is collapsed by default
[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 "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1383 <b>Feeds with update errors</b> (click to expand)</a>";
1384
1385 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1386
1387 while ($line = db_fetch_assoc($result)) {
1388 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1389 $line["last_error"];
1390 }
1391
1392 print "</ul>";
1393 print "</div>";
1394
1395 }
1396
1397 $feed_search = db_escape_string($_GET["search"]);
1398
1399 if (array_key_exists("search", $_GET)) {
1400 $_SESSION["prefs_feed_search"] = $feed_search;
1401 } else {
1402 $feed_search = $_SESSION["prefs_feed_search"];
1403 }
1404
1405 print "<table width='100%' class=\"prefGenericAddBox\"
1406 cellspacing='0' cellpadding='0'><tr>
1407 <td>
1408 <input id=\"fadd_link\"
1409 onchange=\"javascript:addFeed()\"
1410 size=\"40\">
1411 <input type=\"submit\" class=\"button\"
1412 onclick=\"javascript:addFeed()\" value=\"Add feed\">
1413 </td><td align='right'>
1414 <input id=\"feed_search\" size=\"20\"
1415 onchange=\"javascript:updateFeedList()\"
1416 value=\"$feed_search\">
1417 <input type=\"submit\" class=\"button\"
1418 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1419 </td>
1420 </tr></table>";
1421
1422 $feeds_sort = db_escape_string($_GET["sort"]);
1423
1424 if (!$feeds_sort || $feeds_sort == "undefined") {
1425 $feeds_sort = $_SESSION["pref_sort_feeds"];
1426 if (!$feeds_sort) $feeds_sort = "title";
1427 }
1428
1429 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1430
1431 if ($feed_search) {
1432 $search_qpart = "UPPER(title) LIKE UPPER('%$feed_search%') AND";
1433 } else {
1434 $search_qpart = "";
1435 }
1436
1437 $result = db_query($link, "SELECT
1438 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1439 update_interval,purge_interval,
1440 (SELECT title FROM ttrss_feed_categories
1441 WHERE id = cat_id) AS category
1442 FROM
1443 ttrss_feeds
1444 WHERE
1445 $search_qpart owner_uid = '".$_SESSION["uid"]."'
1446 ORDER by $feeds_sort,title");
1447
1448 if (db_num_rows($result) != 0) {
1449
1450 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1451
1452 print "<p><table width=\"100%\" cellspacing=\"0\"
1453 class=\"prefFeedList\" id=\"prefFeedList\">";
1454 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1455 Select:
1456 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1457 'FEEDR-', 'FRCHK-', true)\">All</a>,
1458 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1459 'FEEDR-', 'FRCHK-', false)\">None</a>
1460 </td</tr>";
1461
1462 print "<tr class=\"title\">
1463 <td width=\"3%\">&nbsp;</td>
1464 <td width=\"3%\">Select</td>
1465 <td width=\"20%\">
1466 <a href=\"javascript:updateFeedList('title')\">Title</a></td>
1467 <td width=\"20%\">
1468 <a href=\"javascript:updateFeedList('feed_url')\">Link</a>
1469 </td>";
1470
1471 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1472 print "<td width=\"10%\">
1473 <a href=\"javascript:updateFeedList('category')\">Category</a></td>";
1474 }
1475
1476 print "
1477 <td width=\"10%\">
1478 <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a>
1479 </td>
1480 <td width=\"10%\">
1481 <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a>
1482 </td>
1483 </tr>";
1484
1485 $lnum = 0;
1486
1487 while ($line = db_fetch_assoc($result)) {
1488
1489 $class = ($lnum % 2) ? "even" : "odd";
1490
1491 $feed_id = $line["id"];
1492
1493 $edit_feed_id = $_GET["id"];
1494
1495 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1496 $class .= "Grayed";
1497 $this_row_id = "";
1498 } else {
1499 $this_row_id = "id=\"FEEDR-$feed_id\"";
1500 }
1501
1502 print "<tr class=\"$class\" $this_row_id>";
1503
1504 $icon_file = ICONS_DIR . "/$feed_id.ico";
1505
1506 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1507 $feed_icon = "<img width=\"16\" height=\"16\"
1508 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1509 } else {
1510 $feed_icon = "&nbsp;";
1511 }
1512 print "<td align='center'>$feed_icon</td>";
1513
1514 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1515 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1516 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1517
1518 if (!$edit_cat) $edit_cat = "Uncategorized";
1519
1520 if (!$edit_feed_id || $subop != "edit") {
1521
1522 print "<td><input onclick='toggleSelectRow(this);'
1523 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1524
1525 $edit_title = truncate_string($edit_title, 40);
1526 $edit_link = truncate_string($edit_link, 60);
1527
1528 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1529 $edit_title . "</a></td>";
1530
1531 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1532 $edit_link . "</a></td>";
1533
1534 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1535 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1536 $edit_cat . "</a></td>";
1537 }
1538
1539 if ($line["update_interval"] == "0")
1540 $line["update_interval"] = "Default";
1541
1542 if ($line["update_interval"] == "-1")
1543 $line["update_interval"] = "Disabled";
1544
1545 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1546 $line["update_interval"] . "</a></td>";
1547
1548 if ($line["purge_interval"] == "0")
1549 $line["purge_interval"] = "Default";
1550
1551 if ($line["purge_interval"] < 0)
1552 $line["purge_interval"] = "Disabled";
1553
1554 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1555 $line["purge_interval"] . "</a></td>";
1556
1557 } else if ($feed_id != $edit_feed_id) {
1558
1559 print "<td><input disabled=\"true\" type=\"checkbox\"
1560 id=\"FRCHK-".$line["id"]."\"></td>";
1561
1562 $edit_title = truncate_string($edit_title, 40);
1563 $edit_link = truncate_string($edit_link, 60);
1564
1565 print "<td>$edit_title</td>";
1566 print "<td>$edit_link</td>";
1567
1568 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1569 print "<td>$edit_cat</td>";
1570 }
1571
1572 if ($line["update_interval"] == "0")
1573 $line["update_interval"] = "Default";
1574
1575 print "<td>" . $line["update_interval"] . "</td>";
1576
1577 if ($line["purge_interval"] == "0")
1578 $line["purge_interval"] = "Default";
1579
1580 if ($line["purge_interval"] < 0)
1581 $line["purge_interval"] = "Disabled";
1582
1583 print "<td>" . $line["purge_interval"] . "</td>";
1584
1585 } else {
1586
1587 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1588
1589 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1590 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1591
1592 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1593
1594 print "<td>";
1595 print "<select id=\"iedit_fcat\">";
1596 print "<option id=\"0\">Uncategorized</option>";
1597
1598 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1599 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1600
1601 if (db_num_rows($tmp_result) > 0) {
1602 print "<option disabled>--------</option>";
1603 }
1604
1605 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1606 if ($tmp_line["id"] == $line["cat_id"]) {
1607 $is_selected = "selected";
1608 } else {
1609 $is_selected = "";
1610 }
1611 printf("<option $is_selected id='%d'>%s</option>",
1612 $tmp_line["id"], $tmp_line["title"]);
1613 }
1614
1615 print "</select></td>";
1616 print "</td>";
1617
1618 }
1619
1620 print "<td><input id=\"iedit_updintl\"
1621 value=\"".$line["update_interval"]."\"></td>";
1622 print "<td><input id=\"iedit_purgintl\"
1623 value=\"".$line["purge_interval"]."\"></td>";
1624
1625 }
1626
1627 /* if (!$line["last_updated"]) $line["last_updated"] = "Never";
1628
1629 print "<td>" . $line["last_updated"] . "</td>"; */
1630
1631 print "</tr>";
1632
1633 ++$lnum;
1634 }
1635
1636 print "</table>";
1637
1638 print "<p>";
1639
1640 if ($subop == "edit") {
1641 print "Edit feed:&nbsp;
1642 <input type=\"submit\" class=\"button\"
1643 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1644 <input type=\"submit\" class=\"button\"
1645 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1646 } else {
1647
1648 print "
1649 Selection:&nbsp;
1650 <input type=\"submit\" class=\"button\"
1651 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1652 <input type=\"submit\" class=\"button\"
1653 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1654 <input type=\"submit\" class=\"button\"
1655 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1656
1657 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1658
1659 print "&nbsp;&nbsp;";
1660
1661 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1662 WHERE owner_uid = ".$_SESSION["uid"]."
1663 ORDER BY title");
1664
1665 print "<select id=\"sfeed_set_fcat\">";
1666 print "<option id=\"0\">Uncategorized</option>";
1667
1668 if (db_num_rows($result) != 0) {
1669
1670 print "<option disabled>--------</option>";
1671
1672 while ($line = db_fetch_assoc($result)) {
1673 printf("<option id='%d'>%s</option>",
1674 $line["id"], $line["title"]);
1675 }
1676 }
1677
1678 print "</select>";
1679
1680 print " <input type=\"submit\" class=\"button\"
1681 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
1682
1683 }
1684
1685 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1686 print "
1687 <input type=\"submit\" class=\"button\"
1688 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
1689 <input type=\"submit\" class=\"button\"
1690 onclick=\"javascript:readSelectedFeeds(false)\"
1691 value=\"Mark as unread\">&nbsp;";
1692 }
1693
1694 print "
1695 &nbsp;All feeds: <input type=\"submit\"
1696 class=\"button\" onclick=\"gotoExportOpml()\"
1697 value=\"Export OPML\">";
1698 }
1699 } else {
1700
1701 print "<p>No feeds defined.</p>";
1702
1703 }
1704
1705 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1706
1707 print "<h3>Edit Categories</h3>";
1708
1709 // print "<h3>Categories</h3>";
1710
1711 print "<div class=\"prefGenericAddBox\">
1712 <input id=\"fadd_cat\"
1713 onchange=\"javascript:addFeedCat()\"
1714 size=\"40\">&nbsp;
1715 <input
1716 type=\"submit\" class=\"button\"
1717 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1718
1719 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1720 WHERE owner_uid = ".$_SESSION["uid"]."
1721 ORDER BY title");
1722
1723 if (db_num_rows($result) != 0) {
1724
1725 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1726 cellspacing=\"0\" id=\"prefFeedCatList\">";
1727
1728 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1729 Select:
1730 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1731 'FCATR-', 'FCCHK-', true)\">All</a>,
1732 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1733 'FCATR-', 'FCCHK-', false)\">None</a>
1734 </td</tr>";
1735
1736 print "<tr class=\"title\">
1737 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1738 </tr>";
1739
1740 $lnum = 0;
1741
1742 while ($line = db_fetch_assoc($result)) {
1743
1744 $class = ($lnum % 2) ? "even" : "odd";
1745
1746 $cat_id = $line["id"];
1747
1748 $edit_cat_id = $_GET["id"];
1749
1750 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1751 $class .= "Grayed";
1752 $this_row_id = "";
1753 } else {
1754 $this_row_id = "id=\"FCATR-$cat_id\"";
1755 }
1756
1757 print "<tr class=\"$class\" $this_row_id>";
1758
1759 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1760
1761 if (!$edit_cat_id || $subop != "editCat") {
1762
1763 print "<td><input onclick='toggleSelectRow(this);'
1764 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1765
1766 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1767 $edit_title . "</a></td>";
1768
1769 } else if ($cat_id != $edit_cat_id) {
1770
1771 print "<td><input disabled=\"true\" type=\"checkbox\"
1772 id=\"FRCHK-".$line["id"]."\"></td>";
1773
1774 print "<td>$edit_title</td>";
1775
1776 } else {
1777
1778 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1779
1780 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1781
1782 }
1783
1784 print "</tr>";
1785
1786 ++$lnum;
1787 }
1788
1789 print "</table>";
1790
1791 print "<p>";
1792
1793 if ($subop == "editCat") {
1794 print "Edit category:&nbsp;
1795 <input type=\"submit\" class=\"button\"
1796 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1797 <input type=\"submit\" class=\"button\"
1798 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1799 } else {
1800
1801 print "
1802 Selection:&nbsp;
1803 <input type=\"submit\" class=\"button\"
1804 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1805 <input type=\"submit\" class=\"button\"
1806 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1807
1808 }
1809
1810 } else {
1811 print "<p>No feed categories defined.</p>";
1812 }
1813 }
1814
1815 print "<h3>Import OPML</h3>
1816 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1817 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1818 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1819 type=\"submit\" value=\"Import\">
1820 </form>";
1821
1822 }
1823
1824 if ($op == "pref-filters") {
1825
1826 $subop = $_GET["subop"];
1827
1828 if ($subop == "editSave") {
1829
1830 $regexp = db_escape_string($_GET["r"]);
1831 $descr = db_escape_string($_GET["d"]);
1832 $match = db_escape_string($_GET["m"]);
1833 $filter_id = db_escape_string($_GET["id"]);
1834 $feed_id = db_escape_string($_GET["fid"]);
1835
1836 if (!$feed_id) {
1837 $feed_id = 'NULL';
1838 } else {
1839 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1840 }
1841
1842 $result = db_query($link, "UPDATE ttrss_filters SET
1843 reg_exp = '$regexp',
1844 description = '$descr',
1845 feed_id = $feed_id,
1846 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1847 description = '$match')
1848 WHERE id = '$filter_id'");
1849 }
1850
1851 if ($subop == "remove") {
1852
1853 if (!WEB_DEMO_MODE) {
1854
1855 $ids = split(",", db_escape_string($_GET["ids"]));
1856
1857 foreach ($ids as $id) {
1858 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1859
1860 }
1861 }
1862 }
1863
1864 if ($subop == "add") {
1865
1866 if (!WEB_DEMO_MODE) {
1867
1868 $regexp = db_escape_string(trim($_GET["regexp"]));
1869 $match = db_escape_string(trim($_GET["match"]));
1870 $feed_id = db_escape_string($_GET["fid"]);
1871
1872 if (!$feed_id) {
1873 $feed_id = 'NULL';
1874 } else {
1875 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1876 }
1877
1878 $result = db_query($link,
1879 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
1880 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1881 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
1882 }
1883 }
1884
1885 $result = db_query($link, "SELECT description
1886 FROM ttrss_filter_types ORDER BY description");
1887
1888 $filter_types = array();
1889
1890 while ($line = db_fetch_assoc($result)) {
1891 array_push($filter_types, $line["description"]);
1892 }
1893
1894 print "<div class=\"prefGenericAddBox\">
1895 <input id=\"fadd_regexp\" onchange=\"javascript:addFilter()\" size=\"40\">&nbsp;";
1896
1897 print_select("fadd_match", "Title", $filter_types);
1898
1899 print "&nbsp;<select id=\"fadd_feed\">";
1900
1901 print "<option selected id=\"0\">All feeds</option>";
1902
1903 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1904 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1905
1906 if (db_num_rows($result) > 0) {
1907 print "<option disabled>--------</option>";
1908 }
1909
1910 while ($line = db_fetch_assoc($result)) {
1911 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1912 }
1913
1914 print "</select>&nbsp;";
1915
1916 print "<input type=\"submit\"
1917 class=\"button\" onclick=\"javascript:addFilter()\"
1918 value=\"Add filter\">";
1919
1920 $result = db_query($link, "SELECT
1921 ttrss_filters.id AS id,reg_exp,
1922 ttrss_filters.description AS description,
1923 ttrss_filter_types.name AS filter_type_name,
1924 ttrss_filter_types.description AS filter_type_descr,
1925 feed_id,
1926 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1927 FROM
1928 ttrss_filters,ttrss_filter_types
1929 WHERE
1930 filter_type = ttrss_filter_types.id AND
1931 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
1932 ORDER by reg_exp");
1933
1934 if (db_num_rows($result) != 0) {
1935
1936 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
1937 id=\"prefFilterList\">";
1938
1939 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1940 Select:
1941 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1942 'FILRR-', 'FICHK-', true)\">All</a>,
1943 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1944 'FILRR-', 'FICHK-', false)\">None</a>
1945 </td</tr>";
1946
1947 print "<tr class=\"title\">
1948 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1949 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1950 <td width=\"30%\">Description</td></tr>";
1951
1952 $lnum = 0;
1953
1954 while ($line = db_fetch_assoc($result)) {
1955
1956 $class = ($lnum % 2) ? "even" : "odd";
1957
1958 $filter_id = $line["id"];
1959 $edit_filter_id = $_GET["id"];
1960
1961 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1962 $class .= "Grayed";
1963 $this_row_id = "";
1964 } else {
1965 $this_row_id = "id=\"FILRR-$filter_id\"";
1966 }
1967
1968 print "<tr class=\"$class\" $this_row_id>";
1969
1970 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1971 $line["description"] = htmlspecialchars($line["description"]);
1972
1973 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1974
1975 if (!$edit_filter_id || $subop != "edit") {
1976
1977 if (!$line["description"]) $line["description"] = "[No description]";
1978
1979 print "<td><input onclick='toggleSelectRow(this);'
1980 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1981
1982 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1983 $line["reg_exp"] . "</td>";
1984
1985 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1986 $line["feed_title"] . "</td>";
1987
1988 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1989 $line["filter_type_descr"] . "</td>";
1990
1991 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1992 $line["description"] . "</td>";
1993
1994 } else if ($filter_id != $edit_filter_id) {
1995
1996 if (!$line["description"]) $line["description"] = "[No description]";
1997
1998 print "<td><input disabled=\"true\" type=\"checkbox\"
1999 id=\"FICHK-".$line["id"]."\"></td>";
2000
2001 print "<td>".$line["reg_exp"]."</td>";
2002 print "<td>".$line["feed_title"]."</td>";
2003 print "<td>".$line["filter_type_descr"]."</td>";
2004 print "<td>".$line["description"]."</td>";
2005
2006 } else {
2007
2008 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2009
2010 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2011 "\"></td>";
2012
2013 print "<td>";
2014
2015 print "<select id=\"iedit_feed\">";
2016
2017 print "<option id=\"0\">All feeds</option>";
2018
2019 if (db_num_rows($result) > 0) {
2020 print "<option disabled>--------</option>";
2021 }
2022
2023 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2024 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2025
2026 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2027 if ($tmp_line["id"] == $line["feed_id"]) {
2028 $is_selected = "selected";
2029 } else {
2030 $is_selected = "";
2031 }
2032 printf("<option $is_selected id='%d'>%s</option>",
2033 $tmp_line["id"], $tmp_line["title"]);
2034 }
2035
2036 print "</select></td>";
2037
2038 print "<td>";
2039 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2040 print "</td>";
2041
2042 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2043 "\"></td>";
2044
2045 print "</td>";
2046 }
2047
2048 print "</tr>";
2049
2050 ++$lnum;
2051 }
2052
2053 if ($lnum == 0) {
2054 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2055 }
2056
2057 print "</table>";
2058
2059 print "<p>";
2060
2061 if ($subop == "edit") {
2062 print "Edit feed:
2063 <input type=\"submit\" class=\"button\"
2064 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
2065 <input type=\"submit\" class=\"button\"
2066 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
2067
2068 } else {
2069
2070 print "
2071 Selection:
2072 <input type=\"submit\" class=\"button\"
2073 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2074 <input type=\"submit\" class=\"button\"
2075 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2076 }
2077
2078 } else {
2079
2080 print "<p>No filters defined.</p>";
2081
2082 }
2083 }
2084
2085 if ($op == "pref-labels") {
2086
2087 $subop = $_GET["subop"];
2088
2089 if ($subop == "test") {
2090
2091 $expr = $_GET["expr"];
2092 $descr = $_GET["descr"];
2093
2094 print "<div class='infoBoxContents'>";
2095
2096 print "<h1>Label &laquo;$descr&raquo;</h1>";
2097
2098 // print "<p><b>Expression</b>: $expr</p>";
2099
2100 $result = db_query($link,
2101 "SELECT count(id) AS num_matches
2102 FROM ttrss_entries,ttrss_user_entries
2103 WHERE ($expr) AND
2104 ttrss_user_entries.ref_id = ttrss_entries.id AND
2105 owner_uid = " . $_SESSION["uid"]);
2106
2107 $num_matches = db_fetch_result($result, 0, "num_matches");;
2108
2109 if ($num_matches > 0) {
2110
2111 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2112
2113 $result = db_query($link,
2114 "SELECT title,
2115 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2116 FROM ttrss_entries,ttrss_user_entries
2117 WHERE ($expr) AND
2118 ttrss_user_entries.ref_id = ttrss_entries.id
2119 AND owner_uid = " . $_SESSION["uid"] . "
2120 ORDER BY date_entered DESC LIMIT 5");
2121
2122 print "<ul class=\"nomarks\">";
2123 while ($line = db_fetch_assoc($result)) {
2124 print "<li>".$line["title"].
2125 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2126 }
2127 print "</ul>";
2128
2129 } else {
2130 print "<p>Query didn't return any matches.</p>";
2131 }
2132
2133 print "</div>";
2134
2135 print "<div align='center'>
2136 <input type='submit' class='button'
2137 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2138 return;
2139 }
2140
2141 if ($subop == "editSave") {
2142
2143 $sql_exp = $_GET["s"];
2144 $descr = $_GET["d"];
2145 $label_id = db_escape_string($_GET["id"]);
2146
2147 // print "$sql_exp : $descr : $label_id";
2148
2149 $result = db_query($link, "UPDATE ttrss_labels SET
2150 sql_exp = '$sql_exp',
2151 description = '$descr'
2152 WHERE id = '$label_id'");
2153 }
2154
2155 if ($subop == "remove") {
2156
2157 if (!WEB_DEMO_MODE) {
2158
2159 $ids = split(",", db_escape_string($_GET["ids"]));
2160
2161 foreach ($ids as $id) {
2162 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2163
2164 }
2165 }
2166 }
2167
2168 if ($subop == "add") {
2169
2170 if (!WEB_DEMO_MODE) {
2171
2172 // no escaping is done here on purpose
2173 $exp = trim($_GET["exp"]);
2174
2175 $result = db_query($link,
2176 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2177 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2178 }
2179 }
2180
2181 print "<div class=\"prefGenericAddBox\">
2182 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
2183
2184 print"<input type=\"submit\" class=\"button\"
2185 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2186
2187 $result = db_query($link, "SELECT
2188 id,sql_exp,description
2189 FROM
2190 ttrss_labels
2191 WHERE
2192 owner_uid = ".$_SESSION["uid"]."
2193 ORDER by description");
2194
2195 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2196
2197 if (db_num_rows($result) != 0) {
2198
2199 print "<p><table width=\"100%\" cellspacing=\"0\"
2200 class=\"prefLabelList\" id=\"prefLabelList\">";
2201
2202 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2203 Select:
2204 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2205 'LILRR-', 'LICHK-', true)\">All</a>,
2206 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2207 'LILRR-', 'LICHK-', false)\">None</a>
2208 </td</tr>";
2209
2210 print "<tr class=\"title\">
2211 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
2212 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2213 </td>
2214 <td width=\"40%\">Caption</td></tr>";
2215
2216 $lnum = 0;
2217
2218 while ($line = db_fetch_assoc($result)) {
2219
2220 $class = ($lnum % 2) ? "even" : "odd";
2221
2222 $label_id = $line["id"];
2223 $edit_label_id = $_GET["id"];
2224
2225 if ($subop == "edit" && $label_id != $edit_label_id) {
2226 $class .= "Grayed";
2227 $this_row_id = "";
2228 } else {
2229 $this_row_id = "id=\"LILRR-$label_id\"";
2230 }
2231
2232 print "<tr class=\"$class\" $this_row_id>";
2233
2234 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2235 $line["description"] = htmlspecialchars($line["description"]);
2236
2237 if (!$edit_label_id || $subop != "edit") {
2238
2239 if (!$line["description"]) $line["description"] = "[No caption]";
2240
2241 print "<td><input onclick='toggleSelectRow(this);'
2242 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2243
2244 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2245 $line["sql_exp"] . "</td>";
2246
2247 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2248 $line["description"] . "</td>";
2249
2250 } else if ($label_id != $edit_label_id) {
2251
2252 if (!$line["description"]) $line["description"] = "[No description]";
2253
2254 print "<td><input disabled=\"true\" type=\"checkbox\"
2255 id=\"LICHK-".$line["id"]."\"></td>";
2256
2257 print "<td>".$line["sql_exp"]."</td>";
2258 print "<td>".$line["description"]."</td>";
2259
2260 } else {
2261
2262 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2263
2264 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2265 "\"></td>";
2266
2267 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2268 "\"></td>";
2269
2270 }
2271
2272
2273 print "</tr>";
2274
2275 ++$lnum;
2276 }
2277
2278 if ($lnum == 0) {
2279 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2280 }
2281
2282 print "</table>";
2283
2284 print "<p>";
2285
2286 if ($subop == "edit") {
2287 print "Edit label:
2288 <input type=\"submit\" class=\"button\"
2289 onclick=\"javascript:labelTest()\" value=\"Test\">
2290 <input type=\"submit\" class=\"button\"
2291 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2292 <input type=\"submit\" class=\"button\"
2293 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2294
2295 } else {
2296
2297 print "
2298 Selection:
2299 <input type=\"submit\" class=\"button\"
2300 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2301 <input type=\"submit\" class=\"button\"
2302 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2303 }
2304 } else {
2305 print "<p>No labels defined.</p>";
2306 }
2307 }
2308
2309 if ($op == "error") {
2310 print "<div width=\"100%\" align='center'>";
2311 $msg = $_GET["msg"];
2312 print $msg;
2313 print "</div>";
2314 }
2315
2316 if ($op == "help") {
2317 if (!$_GET["noheaders"]) {
2318 print "<html><head>
2319 <title>Tiny Tiny RSS : Help</title>
2320 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2321 <script type=\"text/javascript\" src=\"functions.js\"></script>
2322 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2323 </head><body>";
2324 }
2325
2326 $tid = sprintf("%d", $_GET["tid"]);
2327
2328 print "<div class='infoBoxContents'>";
2329
2330 if (file_exists("help/$tid.php")) {
2331 include("help/$tid.php");
2332 } else {
2333 print "<p>Help topic not found.</p>";
2334 }
2335
2336 print "</div>";
2337
2338 print "<div align='center'>
2339 <input type='submit' class='button'
2340 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2341
2342 if (!$_GET["noheaders"]) {
2343 print "</body></html>";
2344 }
2345
2346 }
2347
2348 if ($op == "dlg") {
2349 $id = $_GET["id"];
2350 $param = $_GET["param"];
2351
2352 if ($id == "quickAddFeed") {
2353 print "
2354 Feed URL: <input
2355 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2356 id=\"qafInput\">
2357 <input class=\"button\"
2358 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2359 <input class=\"button\"
2360 type=\"submit\" onclick=\"javascript:closeDlg()\"
2361 value=\"Cancel\">";
2362 }
2363
2364 if ($id == "quickDelFeed") {
2365
2366 $param = db_escape_string($param);
2367
2368 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2369
2370 if ($result) {
2371
2372 $f_title = db_fetch_result($result, 0, "title");
2373
2374 print "Remove current feed (<b>$f_title</b>)?&nbsp;
2375 <input class=\"button\"
2376 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2377 <input class=\"button\"
2378 type=\"submit\" onclick=\"javascript:closeDlg()\"
2379 value=\"Cancel\">";
2380 } else {
2381 print "Error: Feed $param not found.&nbsp;
2382 <input class=\"button\"
2383 type=\"submit\" onclick=\"javascript:closeDlg()\"
2384 value=\"Cancel\">";
2385 }
2386 }
2387
2388 if ($id == "search") {
2389
2390 print "<input id=\"searchbox\" class=\"extSearch\"
2391 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2392 onchange=\"javascript:search()\">
2393 <select id=\"searchmodebox\">
2394 <option selected>All feeds</option>
2395 <option>This feed</option>
2396 </select>
2397 <input type=\"submit\"
2398 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2399 <input class=\"button\"
2400 type=\"submit\" onclick=\"javascript:closeDlg()\"
2401 value=\"Close\">";
2402
2403 }
2404
2405 }
2406
2407 // update feeds of all users, may be used anonymously
2408 if ($op == "globalUpdateFeeds") {
2409
2410 $result = db_query($link, "SELECT id FROM ttrss_users");
2411
2412 while ($line = db_fetch_assoc($result)) {
2413 $user_id = $line["id"];
2414 // print "<!-- updating feeds of uid $user_id -->";
2415 update_all_feeds($link, false, $user_id);
2416 }
2417
2418 print "<rpc-reply>
2419 <message msg=\"All feeds updated\"/>
2420 </rpc-reply>";
2421
2422 }
2423
2424 if ($op == "pref-prefs") {
2425
2426 $subop = $_REQUEST["subop"];
2427
2428 if ($subop == "Save configuration") {
2429
2430 if (WEB_DEMO_MODE) {
2431 header("Location: prefs.php");
2432 return;
2433 }
2434
2435 $_SESSION["prefs_op_result"] = "save-config";
2436
2437 foreach (array_keys($_POST) as $pref_name) {
2438
2439 $pref_name = db_escape_string($pref_name);
2440 $value = db_escape_string($_POST[$pref_name]);
2441
2442 $result = db_query($link, "SELECT type_name
2443 FROM ttrss_prefs,ttrss_prefs_types
2444 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2445
2446 if (db_num_rows($result) > 0) {
2447
2448 $type_name = db_fetch_result($result, 0, "type_name");
2449
2450 // print "$pref_name : $type_name : $value<br>";
2451
2452 if ($type_name == "bool") {
2453 if ($value == "1") {
2454 $value = "true";
2455 } else {
2456 $value = "false";
2457 }
2458 } else if ($type_name == "integer") {
2459 $value = sprintf("%d", $value);
2460 }
2461
2462 // print "$pref_name : $type_name : $value<br>";
2463
2464 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2465 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2466
2467 }
2468
2469 header("Location: prefs.php");
2470
2471 }
2472
2473 } else if ($subop == "getHelp") {
2474
2475 $pref_name = db_escape_string($_GET["pn"]);
2476
2477 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2478 WHERE pref_name = '$pref_name'");
2479
2480 if (db_num_rows($result) > 0) {
2481 $help_text = db_fetch_result($result, 0, "help_text");
2482 print $help_text;
2483 } else {
2484 print "Unknown option: $pref_name";
2485 }
2486
2487 } else if ($subop == "Change password") {
2488
2489 if (WEB_DEMO_MODE) {
2490 header("Location: prefs.php");
2491 return;
2492 }
2493
2494 $old_pw = $_POST["OLD_PASSWORD"];
2495 $new_pw = $_POST["OLD_PASSWORD"];
2496
2497 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2498 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2499
2500 $active_uid = $_SESSION["uid"];
2501
2502 if ($old_pw && $new_pw) {
2503
2504 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2505
2506 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2507 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2508 pwd_hash = '$old_pw_hash')");
2509
2510 if (db_num_rows($result) == 1) {
2511 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2512 WHERE id = '$active_uid'");
2513
2514 $_SESSION["pwd_change_result"] = "ok";
2515 } else {
2516 $_SESSION["pwd_change_result"] = "failed";
2517 }
2518 }
2519
2520 header("Location: prefs.php");
2521
2522 } else if ($subop == "Reset to defaults") {
2523
2524 if (WEB_DEMO_MODE) {
2525 header("Location: prefs.php");
2526 return;
2527 }
2528
2529 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2530
2531 if (DB_TYPE == "pgsql") {
2532 db_query($link,"UPDATE ttrss_user_prefs
2533 SET value = ttrss_prefs.def_value
2534 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2535 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2536 } else {
2537 db_query($link, "DELETE FROM ttrss_user_prefs
2538 WHERE owner_uid = ".$_SESSION["uid"]);
2539 initialize_user_prefs($link, $_SESSION["uid"]);
2540 }
2541
2542 header("Location: prefs.php");
2543
2544 } else if ($subop == "Change theme") {
2545
2546 $theme = db_escape_string($_POST["theme"]);
2547
2548 if ($theme == "Default") {
2549 $theme_qpart = 'NULL';
2550 } else {
2551 $theme_qpart = "'$theme'";
2552 }
2553
2554 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2555 WHERE theme_name = '$theme'");
2556
2557 if (db_num_rows($result) == 1) {
2558 $theme_id = db_fetch_result($result, 0, "id");
2559 $theme_path = db_fetch_result($result, 0, "theme_path");
2560 } else {
2561 $theme_id = "NULL";
2562 $theme_path = "";
2563 }
2564
2565 db_query($link, "UPDATE ttrss_users SET
2566 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2567
2568 $_SESSION["theme"] = $theme_path;
2569
2570 header("Location: prefs.php");
2571
2572 } else {
2573
2574 if (!SINGLE_USER_MODE) {
2575
2576 $result = db_query($link, "SELECT id FROM ttrss_users
2577 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2578 pwd_hash = 'SHA1:".sha1("password")."')");
2579
2580 if (db_num_rows($result) != 0) {
2581 print "<div class=\"warning\">
2582 Your password is at default value, please change it.
2583 </div>";
2584 }
2585
2586 if ($_SESSION["pwd_change_result"] == "failed") {
2587 print "<div class=\"warning\">
2588 There was an error while changing your password.
2589 </div>";
2590 }
2591
2592 if ($_SESSION["pwd_change_result"] == "ok") {
2593 print "<div class=\"notice\">
2594 Password changed successfully.
2595 </div>";
2596 }
2597
2598 $_SESSION["pwd_change_result"] = "";
2599
2600 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2601 print "<div class=\"notice\">
2602 Your configuration was reset to defaults.
2603 </div>";
2604 }
2605
2606 if ($_SESSION["prefs_op_result"] == "save-config") {
2607 print "<div class=\"notice\">
2608 Your configuration was saved successfully.
2609 </div>";
2610 }
2611
2612 $_SESSION["prefs_op_result"] = "";
2613
2614 print "<form action=\"backend.php\" method=\"POST\">";
2615
2616 print "<table width=\"100%\" class=\"prefPrefsList\">";
2617 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2618
2619 print "<tr><td width=\"40%\">Old password</td>";
2620 print "<td><input class=\"editbox\" type=\"password\"
2621 name=\"OLD_PASSWORD\"></td></tr>";
2622
2623 print "<tr><td width=\"40%\">New password</td>";
2624
2625 print "<td><input class=\"editbox\" type=\"password\"
2626 name=\"NEW_PASSWORD\"></td></tr>";
2627
2628 print "</table>";
2629
2630 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2631
2632 print "<p><input class=\"button\" type=\"submit\"
2633 value=\"Change password\" name=\"subop\">";
2634
2635 print "</form>";
2636
2637 }
2638
2639 $result = db_query($link, "SELECT
2640 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2641
2642 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2643
2644 $result = db_query($link, "SELECT
2645 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2646
2647 if (db_num_rows($result) > 0) {
2648
2649 print "<form action=\"backend.php\" method=\"POST\">";
2650 print "<table width=\"100%\" class=\"prefPrefsList\">";
2651 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2652 print "<tr><td width=\"40%\">Select theme</td>";
2653 print "<td><select name=\"theme\">";
2654 print "<option>Default</option>";
2655 print "<option disabled>--------</option>";
2656
2657 while ($line = db_fetch_assoc($result)) {
2658 if ($line["id"] == $user_theme_id) {
2659 $selected = "selected";
2660 } else {
2661 $selected = "";
2662 }
2663 print "<option $selected>" . $line["theme_name"] . "</option>";
2664 }
2665 print "</select></td></tr>";
2666 print "</table>";
2667 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2668 print "<p><input class=\"button\" type=\"submit\"
2669 value=\"Change theme\" name=\"subop\">";
2670 print "</form>";
2671 }
2672
2673 $result = db_query($link, "SELECT
2674 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
2675 section_name,def_value
2676 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
2677 WHERE type_id = ttrss_prefs_types.id AND
2678 section_id = ttrss_prefs_sections.id AND
2679 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2680 owner_uid = ".$_SESSION["uid"]."
2681 ORDER BY section_id,short_desc");
2682
2683 print "<form action=\"backend.php\" method=\"POST\">";
2684
2685 $lnum = 0;
2686
2687 $active_section = "";
2688
2689 while ($line = db_fetch_assoc($result)) {
2690
2691 if ($active_section != $line["section_name"]) {
2692
2693 if ($active_section != "") {
2694 print "</table>";
2695 }
2696
2697 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
2698
2699 $active_section = $line["section_name"];
2700
2701 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
2702 // print "<tr class=\"title\">
2703 // <td width=\"25%\">Option</td><td>Value</td></tr>";
2704
2705 $lnum = 0;
2706 }
2707
2708 // $class = ($lnum % 2) ? "even" : "odd";
2709
2710 print "<tr>";
2711
2712 $type_name = $line["type_name"];
2713 $pref_name = $line["pref_name"];
2714 $value = $line["value"];
2715 $def_value = $line["def_value"];
2716 $help_text = $line["help_text"];
2717
2718 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2719
2720 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2721
2722 print "</td>";
2723
2724 print "<td>";
2725
2726 if ($type_name == "bool") {
2727 // print_select($pref_name, $value, array("true", "false"));
2728
2729 if ($value == "true") {
2730 $value = "Yes";
2731 } else {
2732 $value = "No";
2733 }
2734
2735 print_radio($pref_name, $value, array("Yes", "No"));
2736
2737 } else {
2738 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2739 }
2740
2741 print "</td>";
2742
2743 print "</tr>";
2744
2745 $lnum++;
2746 }
2747
2748 print "</table>";
2749
2750 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2751
2752 print "<p><input class=\"button\" type=\"submit\"
2753 name=\"subop\" value=\"Save configuration\">";
2754
2755 print "&nbsp;<input class=\"button\" type=\"submit\"
2756 name=\"subop\" value=\"Reset to defaults\"></p>";
2757
2758 print "</form>";
2759
2760 }
2761
2762 }
2763
2764 if ($op == "pref-users") {
2765
2766 $subop = $_GET["subop"];
2767
2768 if ($subop == "editSave") {
2769
2770 if (!WEB_DEMO_MODE) {
2771
2772 $login = db_escape_string($_GET["l"]);
2773 $uid = db_escape_string($_GET["id"]);
2774 $access_level = sprintf("%d", $_GET["al"]);
2775
2776 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2777
2778 }
2779 } else if ($subop == "remove") {
2780
2781 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2782
2783 $ids = split(",", db_escape_string($_GET["ids"]));
2784
2785 foreach ($ids as $id) {
2786 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2787
2788 }
2789 }
2790 } else if ($subop == "add") {
2791
2792 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2793
2794 $login = db_escape_string(trim($_GET["login"]));
2795 $tmp_user_pwd = make_password(8);
2796 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2797
2798 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2799 VALUES ('$login', '$pwd_hash', 0)");
2800
2801
2802 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2803 login = '$login' AND pwd_hash = '$pwd_hash'");
2804
2805 if (db_num_rows($result) == 1) {
2806
2807 $new_uid = db_fetch_result($result, 0, "id");
2808
2809 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2810 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2811
2812 initialize_user($link, $new_uid);
2813
2814 } else {
2815
2816 print "<div class=\"warning\">Error while adding user <b>".
2817 $_GET["login"].".</b></div>";
2818
2819 }
2820 }
2821 } else if ($subop == "resetPass") {
2822
2823 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2824
2825 $uid = db_escape_string($_GET["id"]);
2826
2827 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2828
2829 $login = db_fetch_result($result, 0, "login");
2830 $tmp_user_pwd = make_password(8);
2831 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2832
2833 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2834 WHERE id = '$uid'");
2835
2836 print "<div class=\"notice\">Changed password of
2837 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2838
2839 }
2840 }
2841
2842 print "<div class=\"prefGenericAddBox\">
2843 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\">&nbsp;";
2844
2845 print"<input type=\"submit\" class=\"button\"
2846 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
2847
2848 $result = db_query($link, "SELECT
2849 id,login,access_level,
2850 SUBSTRING(last_login,1,16) as last_login
2851 FROM
2852 ttrss_users
2853 ORDER by login");
2854
2855 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2856
2857 print "<p><table width=\"100%\" cellspacing=\"0\"
2858 class=\"prefUserList\" id=\"prefUserList\">";
2859
2860 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2861 Select:
2862 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2863 'UMRR-', 'UMCHK-', true)\">All</a>,
2864 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2865 'UMRR-', 'UMCHK-', false)\">None</a>
2866 </td</tr>";
2867
2868 print "<tr class=\"title\">
2869 <td width=\"5%\">Select</td>
2870 <td width='30%'>Username</td>
2871 <td width='30%'>Access Level</td>
2872 <td width='30%'>Last login</td></tr>";
2873
2874 $lnum = 0;
2875
2876 while ($line = db_fetch_assoc($result)) {
2877
2878 $class = ($lnum % 2) ? "even" : "odd";
2879
2880 $uid = $line["id"];
2881 $edit_uid = $_GET["id"];
2882
2883 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
2884 $class .= "Grayed";
2885 $this_row_id = "";
2886 } else {
2887 $this_row_id = "id=\"UMRR-$uid\"";
2888 }
2889
2890 print "<tr class=\"$class\" $this_row_id>";
2891
2892 $line["login"] = htmlspecialchars($line["login"]);
2893
2894 if ($uid == $_SESSION["uid"]) {
2895
2896 print "<td><input disabled=\"true\" type=\"checkbox\"
2897 id=\"UMCHK-".$line["id"]."\"></td>";
2898
2899 print "<td>".$line["login"]."</td>";
2900 print "<td>".$line["access_level"]."</td>";
2901
2902 } else if (!$edit_uid || $subop != "edit") {
2903
2904 print "<td><input onclick='toggleSelectRow(this);'
2905 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
2906
2907 print "<td><a href=\"javascript:editUser($uid);\">" .
2908 $line["login"] . "</td>";
2909
2910 print "<td><a href=\"javascript:editUser($uid);\">" .
2911 $line["access_level"] . "</td>";
2912
2913 } else if ($uid != $edit_uid) {
2914
2915 print "<td><input disabled=\"true\" type=\"checkbox\"
2916 id=\"UMCHK-".$line["id"]."\"></td>";
2917
2918 print "<td>".$line["login"]."</td>";
2919 print "<td>".$line["access_level"]."</td>";
2920
2921 } else {
2922
2923 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2924
2925 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2926 "\"></td>";
2927
2928 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2929 "\"></td>";
2930
2931 }
2932
2933 print "<td>".$line["last_login"]."</td>";
2934
2935 print "</tr>";
2936
2937 ++$lnum;
2938 }
2939
2940 print "</table>";
2941
2942 print "<p>";
2943
2944 if ($subop == "edit") {
2945 print "Edit label:
2946 <input type=\"submit\" class=\"button\"
2947 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2948 <input type=\"submit\" class=\"button\"
2949 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2950
2951 } else {
2952
2953 print "
2954 Selection:
2955 <input type=\"submit\" class=\"button\"
2956 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
2957 <input type=\"submit\" class=\"button\"
2958 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2959 <input type=\"submit\" class=\"button\"
2960 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2961 <input type=\"submit\" class=\"button\"
2962 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2963
2964 }
2965 }
2966
2967 if ($op == "user-details") {
2968
2969 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2970 return;
2971 }
2972
2973 /* print "<html><head>
2974 <title>Tiny Tiny RSS : User Details</title>
2975 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2976 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2977 </head><body>"; */
2978
2979 $uid = sprintf("%d", $_GET["id"]);
2980
2981 print "<div class='infoBoxContents'>";
2982
2983 $result = db_query($link, "SELECT login,
2984 SUBSTRING(last_login,1,16) AS last_login,
2985 access_level,
2986 (SELECT COUNT(int_id) FROM ttrss_user_entries
2987 WHERE owner_uid = id) AS stored_articles
2988 FROM ttrss_users
2989 WHERE id = '$uid'");
2990
2991 if (db_num_rows($result) == 0) {
2992 print "<h1>User not found</h1>";
2993 return;
2994 }
2995
2996 print "<h1>User Details</h1>";
2997
2998 print "<table width='100%'>";
2999
3000 $login = db_fetch_result($result, 0, "login");
3001 $last_login = db_fetch_result($result, 0, "last_login");
3002 $access_level = db_fetch_result($result, 0, "access_level");
3003 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3004
3005 print "<tr><td>Username</td><td>$login</td></tr>";
3006 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3007 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3008 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3009
3010 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3011 WHERE owner_uid = '$uid'");
3012
3013 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3014
3015 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3016
3017 /* $result = db_query($link, "SELECT
3018 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3019 FROM ttrss_user_entries,ttrss_entries
3020 WHERE owner_uid = '$uid' AND ref_id = id");
3021
3022 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3023
3024 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3025
3026 print "</table>";
3027
3028 print "<h1>Subscribed feeds</h1>";
3029
3030 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
3031 WHERE owner_uid = '$uid' ORDER BY title LIMIT 20");
3032
3033 print "<ul class=\"nomarks\">";
3034
3035 while ($line = db_fetch_assoc($result)) {
3036
3037 $icon_file = ICONS_URL."/".$line["id"].".ico";
3038
3039 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3040 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3041 } else {
3042 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3043 }
3044
3045 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
3046 }
3047
3048 if (db_num_rows($result) < $num_feeds) {
3049 // FIXME - add link to show ALL subscribed feeds here somewhere
3050 print "<li><img
3051 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3052 }
3053
3054 print "</ul>";
3055
3056 print "</div>";
3057
3058 print "<div align='center'>
3059 <input type='submit' class='button'
3060 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3061
3062 // print "</body></html>";
3063
3064 }
3065
3066 if ($op == "feed-details") {
3067
3068 $feed_id = $_GET["id"];
3069
3070 $result = db_query($link,
3071 "SELECT
3072 title,feed_url,last_updated,icon_url,site_url,
3073 (SELECT COUNT(int_id) FROM ttrss_user_entries
3074 WHERE feed_id = id) AS total,
3075 (SELECT COUNT(int_id) FROM ttrss_user_entries
3076 WHERE feed_id = id AND unread = true) AS unread,
3077 (SELECT COUNT(int_id) FROM ttrss_user_entries
3078 WHERE feed_id = id AND marked = true) AS marked
3079 FROM ttrss_feeds
3080 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3081
3082 if (db_num_rows($result) == 0) return;
3083
3084 $title = db_fetch_result($result, 0, "title");
3085 $last_updated = db_fetch_result($result, 0, "last_updated");
3086 $feed_url = db_fetch_result($result, 0, "feed_url");
3087 $icon_url = db_fetch_result($result, 0, "icon_url");
3088 $total = db_fetch_result($result, 0, "total");
3089 $unread = db_fetch_result($result, 0, "unread");
3090 $marked = db_fetch_result($result, 0, "marked");
3091 $site_url = db_fetch_result($result, 0, "site_url");
3092
3093 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3094 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
3095
3096 $subscribed = db_fetch_result($result, 0, "subscribed");
3097
3098 print "<div class=\"infoBoxContents\">";
3099
3100 $icon_file = ICONS_DIR . "/$feed_id.ico";
3101
3102 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3103 $feed_icon = "<img width=\"16\" height=\"16\"
3104 src=\"" . ICONS_URL . "/$feed_id.ico\">";
3105 } else {
3106 $feed_icon = "";
3107 }
3108
3109 print "<h1>$feed_icon $title</h1>";
3110
3111 print "<table width='100%'>";
3112
3113 if ($site_url) {
3114 print "<tr><td width='30%'>Link</td>
3115 <td><a href=\"$site_url\">$site_url</a>
3116 <a href=\"$feed_url\">(feed)</a></td>
3117 </td></tr>";
3118 } else {
3119 print "<tr><td width='30%'>Feed URL</td>
3120 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3121 }
3122 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3123 print "<tr><td>Total articles</td><td>$total</td></tr>";
3124 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3125 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3126 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3127
3128 print "</table>";
3129
3130 $result = db_query($link, "SELECT title,
3131 SUBSTRING(updated,1,16) AS updated,unread
3132 FROM ttrss_entries,ttrss_user_entries
3133 WHERE ref_id = id AND feed_id = '$feed_id'
3134 ORDER BY date_entered DESC LIMIT 5");
3135
3136 if (db_num_rows($result) > 0) {
3137
3138 print "<h1>Latest headlines</h1>";
3139
3140 print "<ul class=\"nomarks\">";
3141
3142 while ($line = db_fetch_assoc($result)) {
3143 if ($line["unread"] == "t" || $line["unread"] == "1") {
3144 $line["title"] = "<b>" . $line["title"] . "</b>";
3145 }
3146 print "<li>" . $line["title"].
3147 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
3148 }
3149
3150 print "</ul>";
3151
3152 print "</div>";
3153
3154 print "<div align='center'>
3155 <input type='submit' class='button'
3156 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3157 }
3158 }
3159
3160 db_close($link);
3161 ?>
3162
3163 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3164