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