]> git.wh0rd.org - tt-rss.git/blob - backend.php
only allow linking to feeds in the same category
[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', 3);
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 setcookie("ttrss_icons_url", ICONS_URL);
59
60 if (!sanity_check($link)) { return; }
61
62 function getAllCounters($link) {
63 getLabelCounters($link);
64 getFeedCounters($link);
65 getTagCounters($link);
66 getGlobalCounters($link);
67 if (get_pref($link, 'ENABLE_FEED_CATS')) {
68 getCategoryCounters($link);
69 }
70 }
71
72 function getCategoryCounters($link) {
73 $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
74 FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id
75 AND unread = true)) AS unread FROM ttrss_feeds
76 WHERE
77 owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
78
79 while ($line = db_fetch_assoc($result)) {
80 $line["cat_id"] = sprintf("%d", $line["cat_id"]);
81 print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
82 $line["unread"]."\"/>";
83 }
84 }
85
86 function getFeedUnread($link, $feed) {
87 $n_feed = sprintf("%d", $feed);
88
89 if ($n_feed == -1) {
90 $match_part = "marked = true";
91 } else if ($feed > 0) {
92 $match_part = "feed_id = '$n_feed'";
93 } else if ($feed < -10) {
94 $label_id = -$feed - 11;
95
96 $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
97 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
98
99 $match_part = db_fetch_result($result, 0, "sql_exp");
100 }
101
102 if ($match_part) {
103
104 $result = db_query($link, "SELECT count(int_id) AS unread
105 FROM ttrss_user_entries
106 WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]);
107
108 } else {
109
110 $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
111 FROM ttrss_tags,ttrss_user_entries
112 WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND
113 ttrss_tags.owner_uid = " . $_SESSION["uid"]);
114 }
115
116 $unread = db_fetch_result($result, 0, "unread");
117 return $unread;
118 }
119
120 /* FIXME this needs reworking */
121
122 function getGlobalCounters($link) {
123 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
124 WHERE unread = true AND
125 ttrss_user_entries.ref_id = ttrss_entries.id AND
126 owner_uid = " . $_SESSION["uid"]);
127 $c_id = db_fetch_result($result, 0, "c_id");
128 print "<counter type=\"global\" id='global-unread' counter='$c_id'/>";
129 }
130
131 function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
132
133 if ($smart_mode) {
134 if (!$_SESSION["tctr_last_value"]) {
135 $_SESSION["tctr_last_value"] = array();
136 }
137 }
138
139 $old_counters = $_SESSION["tctr_last_value"];
140
141 $tctrs_modified = false;
142
143 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
144 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
145 ttrss_user_entries.ref_id = ttrss_entries.id AND
146 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
147 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
148 UNION
149 select tag_name,0 as count FROM ttrss_tags
150 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
151
152 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
153 FROM ttrss_user_entries WHERE int_id = post_int_id
154 AND unread = true)) AS count FROM ttrss_tags
155 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
156
157 $tags = array();
158
159 while ($line = db_fetch_assoc($result)) {
160 $tags[$line["tag_name"]] += $line["count"];
161 }
162
163 foreach (array_keys($tags) as $tag) {
164 $unread = $tags[$tag];
165
166 $tag = htmlspecialchars($tag);
167
168 if (!$smart_mode || $old_counters[$tag] != $unread) {
169 $old_counters[$tag] = $unread;
170 $tctrs_modified = true;
171 print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>";
172 }
173
174 }
175
176 if ($smart_mode && $tctrs_modified) {
177 $_SESSION["tctr_last_value"] = $old_counters;
178 }
179
180 }
181
182 function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
183
184 if ($smart_mode) {
185 if (!$_SESSION["lctr_last_value"]) {
186 $_SESSION["lctr_last_value"] = array();
187 }
188 }
189
190 $old_counters = $_SESSION["lctr_last_value"];
191 $lctrs_modified = false;
192
193 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
194 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
195 unread = true AND owner_uid = ".$_SESSION["uid"]);
196
197 $count = db_fetch_result($result, 0, "count");
198
199 print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>";
200
201 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
202 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
203
204 while ($line = db_fetch_assoc($result)) {
205
206 $id = -$line["id"] - 11;
207
208 error_reporting (0);
209
210 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
211 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
212 ttrss_user_entries.ref_id = ttrss_entries.id AND
213 owner_uid = ".$_SESSION["uid"]);
214
215 $count = db_fetch_result($tmp_result, 0, "count");
216
217 if (!$smart_mode || $old_counters[$id] != $count) {
218 $old_counters[$id] = $count;
219 $lctrs_modified = true;
220 print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>";
221 }
222
223 error_reporting (DEFAULT_ERROR_LEVEL);
224 }
225
226 if ($smart_mode && $lctrs_modified) {
227 $_SESSION["lctr_last_value"] = $old_counters;
228 }
229 }
230
231 function getFeedCounter($link, $id) {
232
233 $result = db_query($link, "SELECT
234 count(id) as count,last_error
235 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
236 WHERE feed_id = '$id' AND unread = true
237 AND ttrss_user_entries.feed_id = ttrss_feeds.id
238 AND ttrss_user_entries.ref_id = ttrss_entries.id");
239
240 $count = db_fetch_result($result, 0, "count");
241 $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error"));
242
243 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>";
244 }
245
246 function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
247
248 if ($smart_mode) {
249 if (!$_SESSION["fctr_last_value"]) {
250 $_SESSION["fctr_last_value"] = array();
251 }
252 }
253
254 $old_counters = $_SESSION["fctr_last_value"];
255
256 $result = db_query($link, "SELECT id,last_error,
257 (SELECT count(id)
258 FROM ttrss_entries,ttrss_user_entries
259 WHERE feed_id = ttrss_feeds.id AND
260 ttrss_user_entries.ref_id = ttrss_entries.id
261 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
262 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
263
264 $fctrs_modified = false;
265
266 while ($line = db_fetch_assoc($result)) {
267
268 $id = $line["id"];
269 $count = $line["count"];
270 $last_error = htmlspecialchars($line["last_error"]);
271
272 $has_img = is_file(ICONS_DIR . "/$id.ico");
273
274 if (!$smart_mode || $old_counters[$id] != $count) {
275 $old_counters[$id] = $count;
276 $fctrs_modified = true;
277
278 if ($last_error) {
279 $error_part = "error=\"$last_error\"";
280 } else {
281 $error_part = "";
282 }
283
284 if ($has_img) {
285 $has_img_part = "hi=\"$has_img\"";
286 } else {
287 $has_img_part = "";
288 }
289
290 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part/>";
291 }
292 }
293
294 if ($smart_mode && $fctrs_modified) {
295 $_SESSION["fctr_last_value"] = $old_counters;
296 }
297 }
298
299 function outputFeedList($link, $tags = false) {
300
301 print "<html><head>
302 <title>Tiny Tiny RSS : Feedlist</title>
303 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
304
305 $user_theme = $_SESSION["theme"];
306 if ($user_theme) {
307 print "<link rel=\"stylesheet\" type=\"text/css\"
308 href=\"themes/$user_theme/theme.css\">";
309 }
310
311 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
312 print "<link rel=\"stylesheet\" type=\"text/css\"
313 href=\"tt-rss_compact.css\"/>";
314 } else {
315 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
316 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
317 }
318
319 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
320 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
321 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
322 <!--[if gte IE 5.5000]>
323 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
324 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
325 <![endif]-->
326 </head><body onload=\"init()\">";
327
328 print "<ul class=\"feedList\" id=\"feedList\">";
329
330 $owner_uid = $_SESSION["uid"];
331
332 if (!$tags) {
333
334 /* virtual feeds */
335
336 if (get_pref($link, 'ENABLE_FEED_CATS')) {
337 print "<li class=\"feedCat\">Special</li>";
338 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
339 }
340
341 $result = db_query($link, "SELECT count(id) as num_starred
342 FROM ttrss_entries,ttrss_user_entries
343 WHERE marked = true AND
344 ttrss_user_entries.ref_id = ttrss_entries.id AND
345 unread = true AND owner_uid = '$owner_uid'");
346 $num_starred = db_fetch_result($result, 0, "num_starred");
347
348 $class = "virt";
349
350 if ($num_starred > 0) $class .= "Unread";
351
352 printFeedEntry(-1, $class, "Starred articles", $num_starred,
353 "images/mark_set.png", $link);
354
355 if (get_pref($link, 'ENABLE_FEED_CATS')) {
356 print "</li></ul>";
357 }
358
359 if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
360
361 $result = db_query($link, "SELECT id,sql_exp,description FROM
362 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
363
364 if (db_num_rows($result) > 0) {
365 if (get_pref($link, 'ENABLE_FEED_CATS')) {
366 print "<li class=\"feedCat\">Labels</li>";
367 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
368 } else {
369 print "<li><hr></li>";
370 }
371 }
372
373 while ($line = db_fetch_assoc($result)) {
374
375 error_reporting (0);
376
377 $tmp_result = db_query($link, "SELECT count(id) as count
378 FROM ttrss_entries,ttrss_user_entries
379 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
380 ttrss_user_entries.ref_id = ttrss_entries.id
381 AND owner_uid = '$owner_uid'");
382
383 $count = db_fetch_result($tmp_result, 0, "count");
384
385 $class = "label";
386
387 if ($count > 0) {
388 $class .= "Unread";
389 }
390
391 error_reporting (DEFAULT_ERROR_LEVEL);
392
393 printFeedEntry(-$line["id"]-11,
394 $class, $line["description"], $count, "images/label.png", $link);
395
396 }
397
398 if (db_num_rows($result) > 0) {
399 if (get_pref($link, 'ENABLE_FEED_CATS')) {
400 print "</li></ul>";
401 }
402 }
403
404 }
405
406 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
407 print "<li><hr></li>";
408 // }
409
410 if (get_pref($link, 'ENABLE_FEED_CATS')) {
411 $order_by_qpart = "category,title";
412 } else {
413 $order_by_qpart = "title";
414 }
415
416 $result = db_query($link, "SELECT *,
417 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
418 WHERE feed_id = ttrss_feeds.id AND
419 ttrss_user_entries.ref_id = ttrss_entries.id AND
420 owner_uid = '$owner_uid') AS total,
421 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
422 WHERE feed_id = ttrss_feeds.id AND unread = true
423 AND ttrss_user_entries.ref_id = ttrss_entries.id
424 AND owner_uid = '$owner_uid') as unread,
425 (SELECT title FROM ttrss_feed_categories
426 WHERE id = cat_id) AS category,
427 cat_id,last_error,
428 (SELECT collapsed FROM ttrss_feed_categories
429 WHERE id = cat_id) AS collapsed
430 FROM ttrss_feeds WHERE
431 owner_uid = '$owner_uid' AND parent_feed IS NULL
432 ORDER BY $order_by_qpart");
433
434 $actid = $_GET["actid"];
435
436 /* real feeds */
437
438 $lnum = 0;
439
440 $total_unread = 0;
441
442 $category = "";
443
444 while ($line = db_fetch_assoc($result)) {
445
446 $feed = db_unescape_string($line["title"]);
447 $feed_id = $line["id"];
448
449 $subop = $_GET["subop"];
450
451 $total = $line["total"];
452 $unread = $line["unread"];
453
454 $cat_id = $line["cat_id"];
455
456 $tmp_category = $line["category"];
457
458 if (!$tmp_category) {
459 $tmp_category = "Uncategorized";
460 }
461
462 // $class = ($lnum % 2) ? "even" : "odd";
463
464 if ($line["last_error"]) {
465 $class = "error";
466 } else {
467 $class = "feed";
468 }
469
470 if ($unread > 0) $class .= "Unread";
471
472 if ($actid == $feed_id) {
473 $class .= "Selected";
474 }
475
476 $total_unread += $unread;
477
478 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
479
480 if ($category) {
481 print "</li></ul></li>";
482 }
483
484 $category = $tmp_category;
485
486 $collapsed = $line["collapsed"];
487
488 // workaround for NULL category
489 if ($category == "Uncategorized") {
490 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
491 $collapsed = "t";
492 }
493 }
494
495 if ($collapsed == "t" || $collapsed == "1") {
496 $holder_class = "invisible";
497 $ellipsis = "...";
498 } else {
499 $holder_class = "";
500 $ellipsis = "";
501 }
502
503 if ($cat_id) {
504 $cat_id_qpart = "cat_id = '$cat_id'";
505 } else {
506 $cat_id_qpart = "cat_id IS NULL";
507 }
508
509 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
510 FROM ttrss_user_entries,ttrss_feeds WHERE
511 unread = true AND
512 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
513 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
514
515 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
516
517 $cat_id = sprintf("%d", $cat_id);
518
519 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
520 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category
521 <span id=\"FCATCTR-$cat_id\"
522 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span></a></li>";
523
524 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
525 // -> keyboard navigation, etc.
526 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
527 }
528
529 printFeedEntry($feed_id, $class, $feed, $unread,
530 "icons/$feed_id.ico", $link);
531
532 ++$lnum;
533 }
534
535 } else {
536
537 // tags
538
539 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
540 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
541 post_int_id = ttrss_user_entries.int_id AND
542 unread = true AND ref_id = ttrss_entries.id
543 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
544 UNION
545 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
546 ORDER BY tag_name"); */
547
548 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
549 FROM ttrss_user_entries WHERE int_id = post_int_id
550 AND unread = true)) AS count FROM ttrss_tags
551 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
552
553 $tags = array();
554
555 while ($line = db_fetch_assoc($result)) {
556 $tags[$line["tag_name"]] += $line["count"];
557 }
558
559 foreach (array_keys($tags) as $tag) {
560
561 $unread = $tags[$tag];
562
563 $class = "tag";
564
565 if ($unread > 0) {
566 $class .= "Unread";
567 }
568
569 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
570
571 }
572
573 }
574
575 if (db_num_rows($result) == 0) {
576 if ($tags) {
577 $what = "tags";
578 } else {
579 $what = "feeds";
580 }
581 print "<li>No $what to display.</li>";
582 }
583
584 print "</ul>";
585
586 }
587
588
589 if ($op == "rpc") {
590
591 $subop = $_GET["subop"];
592
593 if ($subop == "getLabelCounters") {
594 $aid = $_GET["aid"];
595 print "<rpc-reply>";
596 getLabelCounters($link);
597 if ($aid) {
598 getFeedCounter($link, $aid);
599 }
600 print "</rpc-reply>";
601 }
602
603 if ($subop == "getFeedCounters") {
604 print "<rpc-reply>";
605 getFeedCounters($link);
606 print "</rpc-reply>";
607 }
608
609 if ($subop == "getAllCounters") {
610 print "<rpc-reply>";
611 getAllCounters($link);
612 print "</rpc-reply>";
613 }
614
615 if ($subop == "mark") {
616 $mark = $_GET["mark"];
617 $id = db_escape_string($_GET["id"]);
618
619 if ($mark == "1") {
620 $mark = "true";
621 } else {
622 $mark = "false";
623 }
624
625 // FIXME this needs collision testing
626
627 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
628 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
629 }
630
631 if ($subop == "updateFeed") {
632 $feed_id = db_escape_string($_GET["feed"]);
633
634 $result = db_query($link,
635 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
636 AND owner_uid = " . $_SESSION["uid"]);
637
638 if (db_num_rows($result) > 0) {
639 $feed_url = db_fetch_result($result, 0, "feed_url");
640 update_rss_feed($link, $feed_url, $feed_id);
641 }
642
643 print "<rpc-reply>";
644 getFeedCounter($link, $feed_id);
645 print "</rpc-reply>";
646
647 return;
648 }
649
650 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
651
652 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
653
654 $omode = $_GET["omode"];
655
656 if (!$omode) $omode = "tfl";
657
658 print "<rpc-reply>";
659 if (strchr($omode, "l")) getLabelCounters($link);
660 if (strchr($omode, "f")) getFeedCounters($link);
661 if (strchr($omode, "t")) getTagCounters($link);
662 if (get_pref($link, 'ENABLE_FEED_CATS')) {
663 getCategoryCounters($link);
664 }
665 getGlobalCounters($link);
666 print "</rpc-reply>";
667 }
668
669 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
670 if ($subop == "catchupSelected") {
671
672 $ids = split(",", db_escape_string($_GET["ids"]));
673
674 $cmode = sprintf("%d", $_GET["cmode"]);
675
676 foreach ($ids as $id) {
677
678 if ($cmode == 0) {
679 db_query($link, "UPDATE ttrss_user_entries SET
680 unread = false,last_read = NOW()
681 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
682 } else if ($cmode == 1) {
683 db_query($link, "UPDATE ttrss_user_entries SET
684 unread = true
685 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
686 } else {
687 db_query($link, "UPDATE ttrss_user_entries SET
688 unread = NOT unread,last_read = NOW()
689 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
690 }
691 }
692 print "<rpc-reply>";
693 getAllCounters($link);
694 print "</rpc-reply>";
695 }
696
697 if ($subop == "markSelected") {
698
699 $ids = split(",", db_escape_string($_GET["ids"]));
700
701 $cmode = sprintf("%d", $_GET["cmode"]);
702
703 foreach ($ids as $id) {
704
705 if ($cmode == 0) {
706 db_query($link, "UPDATE ttrss_user_entries SET
707 marked = false
708 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
709 } else if ($cmode == 1) {
710 db_query($link, "UPDATE ttrss_user_entries SET
711 marked = true
712 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
713 } else {
714 db_query($link, "UPDATE ttrss_user_entries SET
715 marked = NOT marked
716 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
717 }
718 }
719 print "<rpc-reply>";
720 getAllCounters($link);
721 print "</rpc-reply>";
722 }
723
724 if ($subop == "sanityCheck") {
725 sanity_check();
726 }
727
728 if ($subop == "globalPurge") {
729
730 print "<rpc-reply>";
731 global_purge_old_posts($link, true);
732 print "</rpc-reply>";
733
734 }
735
736 }
737
738 if ($op == "feeds") {
739
740 $tags = $_GET["tags"];
741
742 $subop = $_GET["subop"];
743
744 if ($subop == "catchupAll") {
745 db_query($link, "UPDATE ttrss_user_entries SET
746 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
747 }
748
749 if ($subop == "collapse") {
750 $cat_id = db_escape_string($_GET["cid"]);
751
752 db_query($link, "UPDATE ttrss_feed_categories SET
753 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
754 $_SESSION["uid"]);
755 return;
756 }
757
758 outputFeedList($link, $tags);
759
760 }
761
762 if ($op == "view") {
763
764 $id = $_GET["id"];
765 $feed_id = $_GET["feed"];
766
767 $result = db_query($link, "UPDATE ttrss_user_entries
768 SET unread = false,last_read = NOW()
769 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
770
771 $addheader = $_GET["addheader"];
772
773 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
774 SUBSTRING(updated,1,16) as updated,
775 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
776 num_comments
777 FROM ttrss_entries,ttrss_user_entries
778 WHERE id = '$id' AND ref_id = id");
779
780 if ($addheader) {
781 print "<html><head>
782 <title>Tiny Tiny RSS : Article $id</title>
783 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
784
785 $user_theme = $_SESSION["theme"];
786 if ($user_theme) {
787 print "<link rel=\"stylesheet\" type=\"text/css\"
788 href=\"themes/$user_theme/theme.css\">";
789 }
790
791 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
792 print "<link rel=\"stylesheet\" type=\"text/css\"
793 href=\"tt-rss_compact.css\"/>";
794 } else {
795 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
796 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
797 }
798
799 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
800 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
801 </head><body>";
802 }
803
804 if ($result) {
805
806 $line = db_fetch_assoc($result);
807
808 if ($line["icon_url"]) {
809 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
810 } else {
811 $feed_icon = "&nbsp;";
812 }
813
814 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
815 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
816 } else {
817 $entry_comments = "";
818 } */
819
820 $num_comments = $line["num_comments"];
821 $entry_comments = "";
822
823 if ($num_comments > 0) {
824 if ($line["comments"]) {
825 $comments_url = $line["comments"];
826 } else {
827 $comments_url = $line["link"];
828 }
829 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
830 } else {
831 if ($line["comments"] && $line["link"] != $line["comments"]) {
832 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
833 }
834 }
835
836 print "<div class=\"postReply\">";
837
838 print "<div class=\"postHeader\"><table width=\"100%\">";
839
840 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] . "</a></td>";
841
842 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
843 strtotime($line["updated"]));
844
845 print "<td class=\"postDate\">$parsed_updated</td>";
846
847 print "</tr>";
848
849 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
850 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
851 ORDER BY tag_name");
852
853 $tags_str = "";
854 $f_tags_str = "";
855
856 $num_tags = 0;
857
858 while ($tmp_line = db_fetch_assoc($tmp_result)) {
859 $num_tags++;
860 $tag = $tmp_line["tag_name"];
861 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
862
863 if ($num_tags == 5) {
864 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
865 } else if ($num_tags < 5) {
866 $tags_str .= $tag_str;
867 }
868 $f_tags_str .= $tag_str;
869 }
870
871 $tags_str = preg_replace("/, $/", "", $tags_str);
872 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
873
874 // $truncated_link = truncate_string($line["link"], 60);
875
876 if ($tags_str || $entry_comments) {
877 print "<tr><td width='50%'>
878 $entry_comments</td>
879 <td align=\"right\">$tags_str</td></tr>";
880 }
881
882 print "</table></div>";
883
884 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
885 print "<div class=\"postContent\">";
886
887 if (db_num_rows($tmp_result) > 5) {
888 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
889 }
890
891 print $line["content"] . "</div>";
892
893 print "</div>";
894
895 print "<script type=\"text/javascript\">
896 update_all_counters('$feed_id');
897 </script>";
898 }
899
900 if ($addheader) {
901 print "</body></html>";
902 }
903 }
904
905 if ($op == "viewfeed") {
906
907 $feed = $_GET["feed"];
908 $skip = $_GET["skip"];
909 $subop = $_GET["subop"];
910 $view_mode = $_GET["view"];
911 $addheader = $_GET["addheader"];
912 $limit = $_GET["limit"];
913
914 if (!$feed) {
915 return;
916 }
917
918 if (!$skip) $skip = 0;
919
920 if ($subop == "undefined") $subop = "";
921
922 if ($addheader) {
923 print "<html><head>
924 <title>Tiny Tiny RSS : Feed $feed</title>
925 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
926
927 $user_theme = $_SESSION["theme"];
928 if ($user_theme) {
929 print "<link rel=\"stylesheet\" type=\"text/css\"
930 href=\"themes/$user_theme/theme.css\">";
931 }
932
933 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
934 print "<link rel=\"stylesheet\"
935 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
936
937 } else {
938 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
939 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
940 }
941
942 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
943 <script type=\"text/javascript\" src=\"functions.js\"></script>
944 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
945 <!--[if gte IE 5.5000]>
946 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
947 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
948 <![endif]-->
949 </head><body onload='init()'>";
950 }
951
952 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
953
954 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
955 WHERE id = '$feed'");
956
957 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
958
959 update_rss_feed($link, $feed_url, $feed);
960
961 }
962
963 if ($subop == "MarkAllRead") {
964
965 if (sprintf("%d", $feed) != 0) {
966
967 if ($feed > 0) {
968 db_query($link, "UPDATE ttrss_user_entries
969 SET unread = false,last_read = NOW()
970 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
971
972 } else if ($feed < 0 && $feed > -10) { // special, like starred
973
974 if ($feed == -1) {
975 db_query($link, "UPDATE ttrss_user_entries
976 SET unread = false,last_read = NOW()
977 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
978 }
979
980 } else if ($feed < -10) { // label
981
982 // TODO make this more efficient
983
984 $label_id = -$feed - 11;
985
986 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
987 WHERE id = '$label_id'");
988
989 if ($tmp_result) {
990 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
991
992 db_query($link, "BEGIN");
993
994 $tmp2_result = db_query($link,
995 "SELECT
996 int_id
997 FROM
998 ttrss_user_entries,ttrss_entries
999 WHERE
1000 ref_id = id AND
1001 $sql_exp AND
1002 owner_uid = " . $_SESSION["uid"]);
1003
1004 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
1005 db_query($link, "UPDATE
1006 ttrss_user_entries
1007 SET
1008 unread = false, last_read = NOW()
1009 WHERE
1010 int_id = " . $tmp_line["int_id"]);
1011 }
1012
1013 db_query($link, "COMMIT");
1014
1015 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
1016 SET unread = false,last_read = NOW()
1017 WHERE $sql_exp
1018 AND ref_id = id
1019 AND owner_uid = ".$_SESSION["uid"]); */
1020 }
1021 }
1022 } else { // tag
1023 db_query($link, "BEGIN");
1024
1025 $tag_name = db_escape_string($feed);
1026
1027 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
1028 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
1029
1030 while ($line = db_fetch_assoc($result)) {
1031 db_query($link, "UPDATE ttrss_user_entries SET
1032 unread = false, last_read = NOW()
1033 WHERE int_id = " . $line["post_int_id"]);
1034 }
1035 db_query($link, "COMMIT");
1036 }
1037
1038 }
1039
1040 $search = db_escape_string($_GET["search"]);
1041 $search_mode = db_escape_string($_GET["smode"]);
1042
1043 if ($search) {
1044 $search_query_part = "(upper(title) LIKE upper('%$search%')
1045 OR content LIKE '%$search%') AND";
1046 } else {
1047 $search_query_part = "";
1048 }
1049
1050 $view_query_part = "";
1051
1052 if ($view_mode == "Adaptive") {
1053 if ($feed != -1) {
1054 $unread = getFeedUnread($link, $feed);
1055 if ($unread > 0) {
1056 $view_query_part = " unread = true AND ";
1057 }
1058 }
1059 }
1060
1061 if ($view_mode == "Starred") {
1062 $view_query_part = " marked = true AND ";
1063 }
1064
1065 if ($view_mode == "Unread") {
1066 $view_query_part = " unread = true AND ";
1067 }
1068
1069 if ($limit && $limit != "All") {
1070 $limit_query_part = "LIMIT " . $limit;
1071 }
1072
1073 $vfeed_query_part = "";
1074
1075 // override query strategy and enable feed display when searching globally
1076 if ($search && $search_mode == "All feeds") {
1077 $query_strategy_part = "id > 0";
1078 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1079 } else if (sprintf("%d", $feed) == 0) {
1080 $query_strategy_part = "ttrss_entries.id > 0";
1081 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1082 id = feed_id) as feed_title,";
1083 } else if ($feed >= 0) {
1084
1085 $tmp_result = db_query($link, "SELECT id
1086 FROM ttrss_feeds WHERE parent_feed = '$feed'
1087 ORDER BY cat_id,title");
1088
1089 $parent_ids = array();
1090
1091 if (db_num_rows($tmp_result) > 0) {
1092 while ($p = db_fetch_assoc($tmp_result)) {
1093 array_push($parent_ids, "feed_id = " . $p["id"]);
1094 }
1095
1096 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
1097 $feed, implode(" OR ", $parent_ids));
1098
1099 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1100 } else {
1101 $query_strategy_part = "feed_id = '$feed'";
1102 }
1103 } else if ($feed == -1) { // starred virtual feed
1104 $query_strategy_part = "marked = true";
1105 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1106 } else if ($feed <= -10) { // labels
1107 $label_id = -$feed - 11;
1108
1109 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1110 WHERE id = '$label_id'");
1111
1112 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
1113
1114 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1115 } else {
1116 $query_strategy_part = "id > 0"; // dumb
1117 }
1118
1119 $order_by = "updated DESC";
1120
1121 // if ($feed < -10) {
1122 // $order_by = "feed_id,updated DESC";
1123 // }
1124
1125 $feed_title = "";
1126
1127 if ($search && $search_mode == "All feeds") {
1128 $feed_title = "Search results";
1129 } else if (sprintf("%d", $feed) == 0) {
1130 $feed_title = $feed;
1131 } else if ($feed > 0) {
1132 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
1133 WHERE id = '$feed'");
1134
1135 $feed_title = db_fetch_result($result, 0, "title");
1136 $feed_site_url = db_fetch_result($result, 0, "site_url");
1137 $last_error = db_fetch_result($result, 0, "last_error");
1138
1139 } else if ($feed == -1) {
1140 $feed_title = "Starred articles";
1141 } else if ($feed < -10) {
1142 $label_id = -$feed - 11;
1143 $result = db_query($link, "SELECT description FROM ttrss_labels
1144 WHERE id = '$label_id'");
1145 $feed_title = db_fetch_result($result, 0, "description");
1146 } else {
1147 $feed_title = "?";
1148 }
1149
1150 if ($feed < -10) error_reporting (0);
1151
1152 print "<div id=\"headlinesContainer\">";
1153
1154 if (sprintf("%d", $feed) != 0) {
1155
1156 if ($feed > 0) {
1157 $feed_kind = "Feeds";
1158 } else {
1159 $feed_kind = "Labels";
1160 }
1161
1162 // if (!$vfeed_query_part) {
1163 $content_query_part = "content as content_preview,";
1164 // } else {
1165 // $content_query_part = "";
1166 // }
1167
1168 $result = db_query($link, "SELECT
1169 ttrss_entries.id,ttrss_entries.title,
1170 SUBSTRING(updated,1,16) as updated,
1171 unread,feed_id,marked,link,last_read,
1172 SUBSTRING(last_read,1,19) as last_read_noms,
1173 $vfeed_query_part
1174 $content_query_part
1175 SUBSTRING(updated,1,19) as updated_noms
1176 FROM
1177 ttrss_entries,ttrss_user_entries,ttrss_feeds
1178 WHERE
1179 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1180 ttrss_user_entries.ref_id = ttrss_entries.id AND
1181 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1182 $search_query_part
1183 $view_query_part
1184 $query_strategy_part ORDER BY $order_by
1185 $limit_query_part");
1186
1187 } else {
1188 // browsing by tag
1189
1190 $feed_kind = "Tags";
1191
1192 $result = db_query($link, "SELECT
1193 ttrss_entries.id as id,title,
1194 SUBSTRING(updated,1,16) as updated,
1195 unread,feed_id,
1196 marked,link,last_read,
1197 SUBSTRING(last_read,1,19) as last_read_noms,
1198 $vfeed_query_part
1199 $content_query_part
1200 SUBSTRING(updated,1,19) as updated_noms
1201 FROM
1202 ttrss_entries,ttrss_user_entries,ttrss_tags
1203 WHERE
1204 ref_id = ttrss_entries.id AND
1205 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1206 post_int_id = int_id AND tag_name = '$feed' AND
1207 $view_query_part
1208 $search_query_part
1209 $query_strategy_part ORDER BY $order_by
1210 $limit_query_part");
1211 }
1212
1213 if (!$result) {
1214 print "<div align='center'>
1215 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
1216 return;
1217 }
1218
1219 if (db_num_rows($result) > 0) {
1220
1221 print "<table class=\"headlinesSubToolbar\"
1222 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1223
1224 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1225
1226 print "<td class=\"headlineActions\">
1227 Select:
1228 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1229 'RROW-', 'RCHK-', true)\">All</a>,
1230 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1231 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
1232 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1233 'RROW-', 'RCHK-', false)\">None</a>
1234 &nbsp;&nbsp;
1235 Toggle: <a href=\"javascript:selectionToggleUnread()\">Unread</a>,
1236 <a href=\"javascript:selectionToggleMarked()\">Starred</a>";
1237 print "</td>";
1238
1239 } else {
1240
1241 print "<td class=\"headlineActions\">
1242 Select:
1243 <a href=\"javascript:cdmSelectArticles('all')\">All</a>,
1244 <a href=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1245 <a href=\"javascript:cdmSelectArticles('none')\">None</a>
1246 &nbsp;&nbsp;
1247 Toggle: <a href=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1248 <a href=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1249
1250 print "</td>";
1251
1252
1253 }
1254
1255 if ($last_error) {
1256 print "<td align='center' class='small'>
1257 <a class=\"warning\" href=\"javascript:alert('TT-RSS encountered an error while trying to update this feed.\\n\\n$last_error')\">Could not update this feed.</a></td>";
1258 }
1259
1260 print "<td class=\"headlineTitle\">";
1261
1262 if ($feed_site_url) {
1263 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
1264 } else {
1265 print $feed_title;
1266 }
1267
1268 print "</td>";
1269 print "</tr></table>";
1270
1271 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1272 print "<table class=\"headlinesList\" id=\"headlinesList\"
1273 cellspacing=\"0\" width=\"100%\">";
1274 }
1275
1276 $lnum = 0;
1277
1278 error_reporting (DEFAULT_ERROR_LEVEL);
1279
1280 $num_unread = 0;
1281
1282 while ($line = db_fetch_assoc($result)) {
1283
1284 $class = ($lnum % 2) ? "even" : "odd";
1285
1286 $id = $line["id"];
1287 $feed_id = $line["feed_id"];
1288
1289 if ($line["last_read"] == "" &&
1290 ($line["unread"] != "t" && $line["unread"] != "1")) {
1291
1292 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1293 alt=\"Updated\">";
1294 } else {
1295 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1296 alt=\"Updated\">";
1297 }
1298
1299 if ($line["unread"] == "t" || $line["unread"] == "1") {
1300 $class .= "Unread";
1301 ++$num_unread;
1302 $is_unread = true;
1303 } else {
1304 $is_unread = false;
1305 }
1306
1307 if ($line["marked"] == "t" || $line["marked"] == "1") {
1308 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1309 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1310 } else {
1311 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1312 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1313 }
1314
1315 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1316 $line["title"] . "</a>";
1317
1318 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1319 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1320 } else {
1321 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1322 $updated_fmt = date($short_date, strtotime($line["updated"]));
1323 }
1324
1325 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1326 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1327 200);
1328 }
1329
1330 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1331
1332 print "<tr class='$class' id='RROW-$id'>";
1333
1334 print "<td class='hlUpdatePic'>$update_pic</td>";
1335
1336 print "<td class='hlSelectRow'>
1337 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1338 class=\"feedCheckBox\" id=\"RCHK-$id\">
1339 </td>";
1340
1341 print "<td class='hlMarkedPic'>$marked_pic</td>";
1342
1343 if ($line["feed_title"]) {
1344 print "<td class='hlContent'>$content_link</td>";
1345 print "<td class='hlFeed'>
1346 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>&nbsp;</td>";
1347 } else {
1348 print "<td class='hlContent' valign='middle'>";
1349
1350 print "<a href=\"javascript:view($id,$feed_id);\">" .
1351 $line["title"];
1352
1353 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1354
1355 if ($content_preview) {
1356 print "<span class=\"contentPreview\"> - $content_preview</span>";
1357 }
1358 }
1359
1360 print "</a>";
1361 print "</td>";
1362 }
1363
1364 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1365
1366 print "</tr>";
1367
1368 } else {
1369
1370 if ($is_unread) {
1371 $add_class = "Unread";
1372 } else {
1373 $add_class = "";
1374 }
1375
1376 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1377
1378 print "<div class=\"cdmHeader\">";
1379
1380 print "<div style=\"float : right\">$updated_fmt</div>";
1381
1382 print "<a href=\"".$line["link"]."\">".$line["title"]."</a>";
1383
1384 if ($line["feed_title"]) {
1385 print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1386 }
1387
1388 print "</div>";
1389
1390 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1391
1392 print "<div style=\"float : right\">$marked_pic</div>
1393 <div class=\"cdmFooter\">
1394 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1395 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1396
1397 print "</div>";
1398
1399 }
1400
1401 ++$lnum;
1402 }
1403
1404 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1405 print "</table>";
1406 }
1407
1408 } else {
1409 print "<div width='100%' align='center'>No articles found.</div>";
1410 }
1411
1412 print "</div>";
1413
1414 print "<script type=\"text/javascript\">
1415 document.onkeydown = hotkey_handler;
1416 update_all_counters('$feed');
1417 </script>";
1418
1419 if ($addheader) {
1420 print "</body></html>";
1421 }
1422 }
1423
1424 if ($op == "pref-rpc") {
1425
1426 $subop = $_GET["subop"];
1427
1428 if ($subop == "unread") {
1429 $ids = split(",", db_escape_string($_GET["ids"]));
1430 foreach ($ids as $id) {
1431 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1432 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1433 }
1434
1435 print "Marked selected feeds as unread.";
1436 }
1437
1438 if ($subop == "read") {
1439 $ids = split(",", db_escape_string($_GET["ids"]));
1440 foreach ($ids as $id) {
1441 db_query($link, "UPDATE ttrss_user_entries
1442 SET unread = false,last_read = NOW() WHERE
1443 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1444 }
1445
1446 print "Marked selected feeds as read.";
1447
1448 }
1449
1450 }
1451
1452 if ($op == "pref-feeds") {
1453
1454 $subop = $_REQUEST["subop"];
1455 $quiet = $_REQUEST["quiet"];
1456
1457 if ($subop == "editfeed") {
1458 $feed_id = db_escape_string($_GET["id"]);
1459
1460 $result = db_query($link,
1461 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1462 owner_uid = " . $_SESSION["uid"]);
1463
1464 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1465 0, "title")));
1466
1467 print "<div class=\"infoBoxContents\">";
1468
1469 $icon_file = ICONS_DIR . "/$feed_id.ico";
1470
1471 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1472 $feed_icon = "<img width=\"16\" height=\"16\"
1473 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1474 } else {
1475 $feed_icon = "";
1476 }
1477
1478 print "<h1>$feed_icon $title</h1>";
1479
1480 print "<table width='100%'>";
1481
1482 $row_class = "odd";
1483
1484 print "<tr class='$row_class'><td>Title:</td>";
1485 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1486
1487 $feed_url = db_fetch_result($result, 0, "feed_url");
1488 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1489 0, "feed_url")));
1490 $row_class = toggleEvenOdd($row_class);
1491
1492 print "<tr class='$row_class'><td>Feed URL:</td>";
1493 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1494
1495 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1496
1497 $cat_id = db_fetch_result($result, 0, "cat_id");
1498
1499 $row_class = toggleEvenOdd($row_class);
1500
1501 print "<tr class='$row_class'><td>Category:</td>";
1502 print "<td>";
1503 print "<select id=\"iedit_fcat\">";
1504 print "<option id=\"0\">Uncategorized</option>";
1505
1506 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1507 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1508
1509 if (db_num_rows($tmp_result) > 0) {
1510 print "<option disabled>--------</option>";
1511 }
1512
1513 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1514 if ($tmp_line["id"] == $cat_id) {
1515 $is_selected = "selected";
1516 } else {
1517 $is_selected = "";
1518 }
1519 printf("<option $is_selected id='%d'>%s</option>",
1520 $tmp_line["id"], $tmp_line["title"]);
1521 }
1522
1523 print "</select></td>";
1524 print "</td></tr>";
1525
1526 }
1527
1528 $update_interval = db_fetch_result($result, 0, "update_interval");
1529 $row_class = toggleEvenOdd($row_class);
1530
1531 print "<tr class='$row_class'><td>Update Interval:</td>";
1532 print "<td><input id=\"iedit_updintl\"
1533 value=\"$update_interval\"></td></tr>";
1534
1535 $row_class = toggleEvenOdd($row_class);
1536 print "<tr class='$row_class'><td>Link to:</td>";
1537
1538 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1539
1540 print "<select id=\"iedit_parent_feed\">";
1541 print "<option id=\"0\">None</option>";
1542
1543 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1544 if ($cat_id) {
1545 $cat_qpart = "AND cat_id = '$cat_id'";
1546 } else {
1547 $cat_qpart = "AND cat_id IS NULL";
1548 }
1549 }
1550
1551 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1552 WHERE owner_uid = ".$_SESSION["uid"]." $cat_qpart ORDER BY title");
1553
1554 if (db_num_rows($tmp_result) > 0) {
1555 print "<option disabled>--------</option>";
1556 }
1557
1558 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1559 if ($tmp_line["id"] == $parent_feed) {
1560 $is_selected = "selected";
1561 } else {
1562 $is_selected = "";
1563 }
1564 printf("<option $is_selected id='%d'>%s</option>",
1565 $tmp_line["id"], $tmp_line["title"]);
1566 }
1567
1568 print "</select></td>";
1569 print "</td></tr>";
1570
1571 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1572 $row_class = toggleEvenOdd($row_class);
1573
1574 print "<tr class='$row_class'><td>Purge Days:</td>";
1575 print "<td><input id=\"iedit_purgintl\"
1576 value=\"$purge_interval\"></td></tr>";
1577
1578 // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1579
1580 $row_class = toggleEvenOdd($row_class);
1581 $auth_login = db_fetch_result($result, 0, "auth_login");
1582
1583 print "<tr class='$row_class'><td>Login:</td>";
1584 print "<td><input id=\"iedit_login\"
1585 value=\"$auth_login\"></td></tr>";
1586
1587 $row_class = toggleEvenOdd($row_class);
1588 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1589
1590 print "<tr class='$row_class'><td>Password:</td>";
1591 print "<td><input type=\"password\" id=\"iedit_pass\"
1592 value=\"$auth_pass\"></td></tr>";
1593
1594 print "</table>";
1595 print "</div>";
1596
1597 print "<div align='center'>
1598 <input type='submit' class='button'
1599 onclick=\"feedEditCancel()\" value=\"Cancel\">
1600 <input type=\"submit\" class=\"button\"
1601 onclick=\"feedEditSave()\" value=\"Save\"></div>";
1602 return;
1603 }
1604
1605 if ($subop == "editSave") {
1606 $feed_title = db_escape_string($_POST["t"]);
1607 $feed_link = db_escape_string($_POST["l"]);
1608 $upd_intl = db_escape_string($_POST["ui"]);
1609 $purge_intl = db_escape_string($_POST["pi"]);
1610 $feed_id = db_escape_string($_POST["id"]);
1611 $cat_id = db_escape_string($_POST["catid"]);
1612 $auth_login = db_escape_string($_POST["login"]);
1613 $auth_pass = db_escape_string($_POST["pass"]);
1614 $parent_feed = db_escape_string($_POST["pfeed"]);
1615
1616 if (strtoupper($upd_intl) == "DEFAULT")
1617 $upd_intl = 0;
1618
1619 if (strtoupper($upd_intl) == "DISABLED")
1620 $upd_intl = -1;
1621
1622 if (strtoupper($purge_intl) == "DEFAULT")
1623 $purge_intl = 0;
1624
1625 if (strtoupper($purge_intl) == "DISABLED")
1626 $purge_intl = -1;
1627
1628 if ($cat_id != 0) {
1629 $category_qpart = "cat_id = '$cat_id'";
1630 } else {
1631 $category_qpart = 'cat_id = NULL';
1632 }
1633
1634 if ($parent_feed != 0) {
1635 $parent_qpart = "parent_feed = '$parent_feed'";
1636 } else {
1637 $parent_qpart = 'parent_feed = NULL';
1638 }
1639
1640 $result = db_query($link, "UPDATE ttrss_feeds SET
1641 $category_qpart,
1642 $parent_qpart,
1643 title = '$feed_title', feed_url = '$feed_link',
1644 update_interval = '$upd_intl',
1645 purge_interval = '$purge_intl',
1646 auth_login = '$auth_login',
1647 auth_pass = '$auth_pass'
1648 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1649 }
1650
1651 if ($subop == "saveCat") {
1652 $cat_title = db_escape_string($_GET["title"]);
1653 $cat_id = db_escape_string($_GET["id"]);
1654
1655 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1656 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1657
1658 }
1659
1660 if ($subop == "remove") {
1661
1662 if (!WEB_DEMO_MODE) {
1663
1664 $ids = split(",", db_escape_string($_GET["ids"]));
1665
1666 foreach ($ids as $id) {
1667 db_query($link, "DELETE FROM ttrss_feeds
1668 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1669
1670 $icons_dir = ICONS_DIR;
1671
1672 if (file_exists($icons_dir . "/$id.ico")) {
1673 unlink($icons_dir . "/$id.ico");
1674 }
1675 }
1676 }
1677 }
1678
1679 if ($subop == "add") {
1680
1681 if (!WEB_DEMO_MODE) {
1682
1683 $feed_link = db_escape_string(trim($_GET["link"]));
1684 $cat_id = db_escape_string($_GET["cid"]);
1685
1686 if ($cat_id == "0" || !$cat_id) {
1687 $cat_qpart = "NULL";
1688 } else {
1689 $cat_qpart = "'$cat_id'";
1690 }
1691
1692 $result = db_query($link,
1693 "SELECT id FROM ttrss_feeds
1694 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1695
1696 if (db_num_rows($result) == 0) {
1697
1698 $result = db_query($link,
1699 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1700 VALUES ('".$_SESSION["uid"]."', '$feed_link',
1701 '[Unknown]', $cat_qpart)");
1702
1703 $result = db_query($link,
1704 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1705 AND owner_uid = " . $_SESSION["uid"]);
1706
1707 $feed_id = db_fetch_result($result, 0, "id");
1708
1709 if ($feed_id) {
1710 update_rss_feed($link, $feed_link, $feed_id, true);
1711 }
1712 } else {
1713
1714 print "<div class=\"warning\">
1715 Feed <b>$feed_link</b> already exists in the database.
1716 </div>";
1717 }
1718 }
1719 }
1720
1721 if ($subop == "addCat") {
1722
1723 if (!WEB_DEMO_MODE) {
1724
1725 $feed_cat = db_escape_string(trim($_GET["cat"]));
1726
1727 $result = db_query($link,
1728 "SELECT id FROM ttrss_feed_categories
1729 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1730
1731 if (db_num_rows($result) == 0) {
1732
1733 $result = db_query($link,
1734 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1735 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1736
1737 } else {
1738
1739 print "<div class=\"warning\">
1740 Category <b>$feed_cat</b> already exists in the database.
1741 </div>";
1742 }
1743
1744
1745 }
1746 }
1747
1748 if ($subop == "removeCats") {
1749
1750 if (!WEB_DEMO_MODE) {
1751
1752 $ids = split(",", db_escape_string($_GET["ids"]));
1753
1754 foreach ($ids as $id) {
1755
1756 db_query($link, "BEGIN");
1757
1758 $result = db_query($link,
1759 "SELECT count(id) as num_feeds FROM ttrss_feeds
1760 WHERE cat_id = '$id'");
1761
1762 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1763
1764 if ($num_feeds == 0) {
1765 db_query($link, "DELETE FROM ttrss_feed_categories
1766 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1767 } else {
1768
1769 print "<div class=\"warning\">
1770 Unable to delete non empty feed categories.</div>";
1771
1772 }
1773
1774 db_query($link, "COMMIT");
1775 }
1776 }
1777 }
1778
1779 if ($subop == "categorize") {
1780
1781 if (!WEB_DEMO_MODE) {
1782
1783 $ids = split(",", db_escape_string($_GET["ids"]));
1784
1785 $cat_id = db_escape_string($_GET["cat_id"]);
1786
1787 if ($cat_id == 0) {
1788 $cat_id_qpart = 'NULL';
1789 } else {
1790 $cat_id_qpart = "'$cat_id'";
1791 }
1792
1793 db_query($link, "BEGIN");
1794
1795 foreach ($ids as $id) {
1796
1797 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1798 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1799 }
1800
1801 db_query($link, "COMMIT");
1802 }
1803
1804 }
1805
1806 if ($quiet) return;
1807
1808 // print "<h3>Edit Feeds</h3>";
1809
1810 $result = db_query($link, "SELECT id,title,feed_url,last_error
1811 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1812
1813 if (db_num_rows($result) > 0) {
1814
1815 print "<div class=\"warning\">";
1816
1817 // print"<img class=\"closeButton\"
1818 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1819
1820 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1821 <b>Feeds with update errors</b> (click to expand)</a>";
1822
1823 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1824
1825 while ($line = db_fetch_assoc($result)) {
1826 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1827 $line["last_error"];
1828 }
1829
1830 print "</ul>";
1831 print "</div>";
1832
1833 }
1834
1835 $feed_search = db_escape_string($_GET["search"]);
1836
1837 if (array_key_exists("search", $_GET)) {
1838 $_SESSION["prefs_feed_search"] = $feed_search;
1839 } else {
1840 $feed_search = $_SESSION["prefs_feed_search"];
1841 }
1842
1843 print "<table width='100%' class=\"prefGenericAddBox\"
1844 cellspacing='0' cellpadding='0'><tr>
1845 <td>
1846 <input id=\"fadd_link\"
1847 onchange=\"javascript:addFeed()\"
1848 size=\"40\">
1849 <input type=\"submit\" class=\"button\"
1850 onclick=\"javascript:addFeed()\" value=\"Add feed\">
1851 </td><td align='right'>
1852 <input id=\"feed_search\" size=\"20\"
1853 onchange=\"javascript:updateFeedList()\"
1854 value=\"$feed_search\">
1855 <input type=\"submit\" class=\"button\"
1856 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1857 </td>
1858 </tr></table>";
1859
1860 $feeds_sort = db_escape_string($_GET["sort"]);
1861
1862 if (!$feeds_sort || $feeds_sort == "undefined") {
1863 $feeds_sort = $_SESSION["pref_sort_feeds"];
1864 if (!$feeds_sort) $feeds_sort = "title";
1865 }
1866
1867 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1868
1869 if ($feed_search) {
1870 $search_qpart = "(UPPER(title) LIKE UPPER('%$feed_search%') OR
1871 UPPER(feed_url) LIKE UPPER('%$feed_search%')) AND";
1872 } else {
1873 $search_qpart = "";
1874 }
1875
1876 $result = db_query($link, "SELECT
1877 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1878 update_interval,purge_interval,cat_id,
1879 parent_feed AS parent_feed_id,
1880 (SELECT title FROM ttrss_feed_categories
1881 WHERE id = cat_id) AS category,
1882 (SELECT title FROM ttrss_feeds
1883 WHERE id = parent_feed_id) AS parent_title
1884 FROM
1885 ttrss_feeds
1886 WHERE
1887 $search_qpart owner_uid = '".$_SESSION["uid"]."'
1888 ORDER by category,$feeds_sort,title");
1889
1890 if (db_num_rows($result) != 0) {
1891
1892 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1893
1894 print "<p><table width=\"100%\" cellspacing=\"0\"
1895 class=\"prefFeedList\" id=\"prefFeedList\">";
1896 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1897 Select:
1898 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1899 'FEEDR-', 'FRCHK-', true)\">All</a>,
1900 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1901 'FEEDR-', 'FRCHK-', false)\">None</a>
1902 </td</tr>";
1903
1904 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1905 print "<tr class=\"title\">
1906 <td width='5%' align='center'>&nbsp;</td>
1907 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1908 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1909 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
1910 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
1911 }
1912
1913 $lnum = 0;
1914
1915 $cur_cat_id = -1;
1916
1917 while ($line = db_fetch_assoc($result)) {
1918
1919 $feed_id = $line["id"];
1920 $cat_id = $line["cat_id"];
1921
1922 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1923 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1924 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1925
1926 if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
1927 if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
1928 if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
1929 if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled";
1930
1931 if (!$edit_cat) $edit_cat = "Uncategorized";
1932
1933
1934 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1935 $lnum = 0;
1936
1937 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1938
1939 print "<tr class=\"title\">
1940 <td width='5%' align='center'>&nbsp;</td>
1941 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1942 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1943 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
1944 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
1945
1946 $cur_cat_id = $cat_id;
1947 }
1948
1949 $class = ($lnum % 2) ? "even" : "odd";
1950 $this_row_id = "id=\"FEEDR-$feed_id\"";
1951
1952 print "<tr class=\"$class\" $this_row_id>";
1953
1954 $icon_file = ICONS_DIR . "/$feed_id.ico";
1955
1956 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1957 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
1958 } else {
1959 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1960 }
1961 // print "<td class='feedIcon'>$feed_icon</td>";
1962
1963 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
1964 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1965
1966 $edit_title = truncate_string($edit_title, 40);
1967 $edit_link = truncate_string($edit_link, 60);
1968
1969 $parent_title = $line["parent_title"];
1970 if ($parent_title) {
1971 $parent_title = "<span class='groupPrompt'>(linked to
1972 $parent_title)</span>";
1973 }
1974
1975 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1976 "$feed_icon $edit_title $parent_title" . "</a></td>";
1977
1978 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1979 $edit_link . "</a></td>";
1980
1981 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
1982 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1983 $edit_cat . "</a></td>";
1984 } */
1985
1986 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1987 $line["update_interval"] . "</a></td>";
1988
1989 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1990 $line["purge_interval"] . "</a></td>";
1991
1992 print "</tr>";
1993
1994 ++$lnum;
1995 }
1996
1997 print "</table>";
1998
1999 print "<p>";
2000
2001 if ($subop == "edit") {
2002 print "Edit feed:&nbsp;
2003 <input type=\"submit\" class=\"button\"
2004 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
2005 <input type=\"submit\" class=\"button\"
2006 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
2007 } else {
2008
2009 print "
2010 Selection:&nbsp;
2011 <input type=\"submit\" class=\"button\"
2012 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
2013 <input type=\"submit\" class=\"button\"
2014 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2015 <input type=\"submit\" class=\"button\"
2016 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
2017
2018 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2019
2020 print "&nbsp;&nbsp;";
2021
2022 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2023 WHERE owner_uid = ".$_SESSION["uid"]."
2024 ORDER BY title");
2025
2026 print "<select id=\"sfeed_set_fcat\">";
2027 print "<option id=\"0\">Uncategorized</option>";
2028
2029 if (db_num_rows($result) != 0) {
2030
2031 print "<option disabled>--------</option>";
2032
2033 while ($line = db_fetch_assoc($result)) {
2034 printf("<option id='%d'>%s</option>",
2035 $line["id"], $line["title"]);
2036 }
2037 }
2038
2039 print "</select>";
2040
2041 print " <input type=\"submit\" class=\"button\"
2042 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2043
2044 }
2045
2046 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
2047 print "
2048 <input type=\"submit\" class=\"button\"
2049 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
2050 <input type=\"submit\" class=\"button\"
2051 onclick=\"javascript:readSelectedFeeds(false)\"
2052 value=\"Mark as unread\">&nbsp;";
2053 }
2054
2055 print "
2056 &nbsp;All feeds: <input type=\"submit\"
2057 class=\"button\" onclick=\"gotoExportOpml()\"
2058 value=\"Export OPML\">";
2059 }
2060 } else {
2061
2062 print "<p>No feeds defined.</p>";
2063
2064 }
2065
2066 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2067
2068 print "<h3>Edit Categories</h3>";
2069
2070 // print "<h3>Categories</h3>";
2071
2072 print "<div class=\"prefGenericAddBox\">
2073 <input id=\"fadd_cat\"
2074 onchange=\"javascript:addFeedCat()\"
2075 size=\"40\">&nbsp;
2076 <input
2077 type=\"submit\" class=\"button\"
2078 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2079
2080 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2081 WHERE owner_uid = ".$_SESSION["uid"]."
2082 ORDER BY title");
2083
2084 if (db_num_rows($result) != 0) {
2085
2086 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2087 cellspacing=\"0\" id=\"prefFeedCatList\">";
2088
2089 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2090 Select:
2091 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2092 'FCATR-', 'FCCHK-', true)\">All</a>,
2093 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2094 'FCATR-', 'FCCHK-', false)\">None</a>
2095 </td</tr>";
2096
2097 print "<tr class=\"title\">
2098 <td width=\"5%\"></td><td width=\"80%\">Title</td>
2099 </tr>";
2100
2101 $lnum = 0;
2102
2103 while ($line = db_fetch_assoc($result)) {
2104
2105 $class = ($lnum % 2) ? "even" : "odd";
2106
2107 $cat_id = $line["id"];
2108
2109 $edit_cat_id = $_GET["id"];
2110
2111 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2112 $class .= "Grayed";
2113 $this_row_id = "";
2114 } else {
2115 $this_row_id = "id=\"FCATR-$cat_id\"";
2116 }
2117
2118 print "<tr class=\"$class\" $this_row_id>";
2119
2120 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2121
2122 if (!$edit_cat_id || $subop != "editCat") {
2123
2124 print "<td align='center'><input onclick='toggleSelectRow(this);'
2125 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2126
2127 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2128 $edit_title . "</a></td>";
2129
2130 } else if ($cat_id != $edit_cat_id) {
2131
2132 print "<td><input disabled=\"true\" type=\"checkbox\"
2133 id=\"FRCHK-".$line["id"]."\"></td>";
2134
2135 print "<td>$edit_title</td>";
2136
2137 } else {
2138
2139 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2140
2141 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2142
2143 }
2144
2145 print "</tr>";
2146
2147 ++$lnum;
2148 }
2149
2150 print "</table>";
2151
2152 print "<p>";
2153
2154 if ($subop == "editCat") {
2155 print "Edit category:&nbsp;
2156 <input type=\"submit\" class=\"button\"
2157 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2158 <input type=\"submit\" class=\"button\"
2159 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2160 } else {
2161
2162 print "
2163 Selection:&nbsp;
2164 <input type=\"submit\" class=\"button\"
2165 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2166 <input type=\"submit\" class=\"button\"
2167 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2168
2169 }
2170
2171 } else {
2172 print "<p>No feed categories defined.</p>";
2173 }
2174 }
2175
2176 print "<h3>Import OPML</h3>
2177 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2178 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
2179 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2180 type=\"submit\" value=\"Import\">
2181 </form>";
2182
2183 }
2184
2185 if ($op == "pref-filters") {
2186
2187 $subop = $_GET["subop"];
2188 $quiet = $_GET["quiet"];
2189
2190 if ($subop == "editSave") {
2191
2192 $regexp = db_escape_string($_GET["r"]);
2193 $descr = db_escape_string($_GET["d"]);
2194 $match = db_escape_string($_GET["m"]);
2195 $filter_id = db_escape_string($_GET["id"]);
2196 $feed_id = db_escape_string($_GET["fid"]);
2197 $action_id = db_escape_string($_GET["aid"]);
2198
2199 if (!$feed_id) {
2200 $feed_id = 'NULL';
2201 } else {
2202 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2203 }
2204
2205 $result = db_query($link, "UPDATE ttrss_filters SET
2206 reg_exp = '$regexp',
2207 description = '$descr',
2208 feed_id = $feed_id,
2209 action_id = '$action_id',
2210 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2211 description = '$match')
2212 WHERE id = '$filter_id'");
2213 }
2214
2215 if ($subop == "remove") {
2216
2217 if (!WEB_DEMO_MODE) {
2218
2219 $ids = split(",", db_escape_string($_GET["ids"]));
2220
2221 foreach ($ids as $id) {
2222 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2223
2224 }
2225 }
2226 }
2227
2228 if ($subop == "add") {
2229
2230 if (!WEB_DEMO_MODE) {
2231
2232 $regexp = db_escape_string(trim($_GET["regexp"]));
2233 $match = db_escape_string(trim($_GET["match"]));
2234 $feed_id = db_escape_string($_GET["fid"]);
2235 $action_id = db_escape_string($_GET["aid"]);
2236
2237 if (!$feed_id) {
2238 $feed_id = 'NULL';
2239 } else {
2240 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2241 }
2242
2243 $result = db_query($link,
2244 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2245 action_id)
2246 VALUES
2247 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2248 description = '$match'),'".$_SESSION["uid"]."',
2249 $feed_id, '$action_id')");
2250 }
2251 }
2252
2253 if ($quiet) return;
2254
2255 $result = db_query($link, "SELECT description
2256 FROM ttrss_filter_types ORDER BY description");
2257
2258 $filter_types = array();
2259
2260 while ($line = db_fetch_assoc($result)) {
2261 array_push($filter_types, $line["description"]);
2262 }
2263
2264 print "<div class=\"prefGenericAddBox\">
2265 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2266
2267 print_select("fadd_match", "Title", $filter_types);
2268
2269 print "&nbsp;<select id=\"fadd_feed\">";
2270
2271 print "<option selected id=\"0\">All feeds</option>";
2272
2273 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2274 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2275
2276 if (db_num_rows($result) > 0) {
2277 print "<option disabled>--------</option>";
2278 }
2279
2280 while ($line = db_fetch_assoc($result)) {
2281 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2282 }
2283
2284 print "</select>&nbsp;";
2285
2286 print "&nbsp;Action: ";
2287
2288 print "<select id=\"fadd_action\">";
2289
2290 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2291 ORDER BY name");
2292
2293 while ($line = db_fetch_assoc($result)) {
2294 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2295 }
2296
2297 print "</select>&nbsp;";
2298
2299 print "<input type=\"submit\"
2300 class=\"button\" onclick=\"javascript:addFilter()\"
2301 value=\"Add filter\">";
2302
2303 print "</div>";
2304
2305 $result = db_query($link, "SELECT
2306 ttrss_filters.id AS id,reg_exp,
2307 ttrss_filters.description AS description,
2308 ttrss_filter_types.name AS filter_type_name,
2309 ttrss_filter_types.description AS filter_type_descr,
2310 feed_id,
2311 ttrss_filter_actions.description AS action_description,
2312 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2313 FROM
2314 ttrss_filters,ttrss_filter_types,ttrss_filter_actions
2315 WHERE
2316 filter_type = ttrss_filter_types.id AND
2317 ttrss_filter_actions.id = action_id AND
2318 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2319 ORDER by reg_exp");
2320
2321 if (db_num_rows($result) != 0) {
2322
2323 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2324 id=\"prefFilterList\">";
2325
2326 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2327 Select:
2328 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2329 'FILRR-', 'FICHK-', true)\">All</a>,
2330 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2331 'FILRR-', 'FICHK-', false)\">None</a>
2332 </td</tr>";
2333
2334 print "<tr class=\"title\">
2335 <td align='center' width=\"5%\">&nbsp;</td>
2336 <td width=\"20%\">Filter expression</td>
2337 <td width=\"20%\">Feed</td>
2338 <td width=\"15%\">Match</td>
2339 <td width=\"15%\">Action</td>
2340 <td width=\"30%\">Description</td></tr>";
2341
2342 $lnum = 0;
2343
2344 while ($line = db_fetch_assoc($result)) {
2345
2346 $class = ($lnum % 2) ? "even" : "odd";
2347
2348 $filter_id = $line["id"];
2349 $edit_filter_id = $_GET["id"];
2350
2351 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2352 $class .= "Grayed";
2353 $this_row_id = "";
2354 } else {
2355 $this_row_id = "id=\"FILRR-$filter_id\"";
2356 }
2357
2358 print "<tr class=\"$class\" $this_row_id>";
2359
2360 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2361 $line["description"] = htmlspecialchars($line["description"]);
2362
2363 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2364
2365 if (!$edit_filter_id || $subop != "edit") {
2366
2367 if (!$line["description"]) $line["description"] = "[No description]";
2368
2369 print "<td align='center'><input onclick='toggleSelectRow(this);'
2370 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2371
2372 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2373 $line["reg_exp"] . "</td>";
2374
2375 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2376 $line["feed_title"] . "</td>";
2377
2378 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2379 $line["filter_type_descr"] . "</td>";
2380
2381 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2382 $line["action_description"] . "</td>";
2383
2384 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2385 $line["description"] . "</td>";
2386
2387 } else if ($filter_id != $edit_filter_id) {
2388
2389 if (!$line["description"]) $line["description"] = "[No description]";
2390
2391 print "<td><input disabled=\"true\" type=\"checkbox\"
2392 id=\"FICHK-".$line["id"]."\"></td>";
2393
2394 print "<td>".$line["reg_exp"]."</td>";
2395 print "<td>".$line["feed_title"]."</td>";
2396 print "<td>".$line["filter_type_descr"]."</td>";
2397 print "<td>".$line["action_description"]."</td>";
2398 print "<td>".$line["description"]."</td>";
2399
2400 } else {
2401
2402 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2403
2404 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2405 "\"></td>";
2406
2407 print "<td>";
2408 print "<select id=\"iedit_feed\">";
2409 print "<option id=\"0\">All feeds</option>";
2410
2411 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2412 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2413
2414 if (db_num_rows($tmp_result) > 0) {
2415 print "<option disabled>--------</option>";
2416 }
2417
2418 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2419 if ($tmp_line["id"] == $line["feed_id"]) {
2420 $is_selected = "selected";
2421 } else {
2422 $is_selected = "";
2423 }
2424 printf("<option $is_selected id='%d'>%s</option>",
2425 $tmp_line["id"], $tmp_line["title"]);
2426 }
2427
2428 print "</select></td>";
2429
2430 print "<td>";
2431 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2432 print "</td>";
2433
2434 print "<td>";
2435 print "<select id=\"iedit_filter_action\">";
2436
2437 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2438 ORDER BY description");
2439
2440 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2441 if ($tmp_line["description"] == $line["action_description"]) {
2442 $is_selected = "selected";
2443 } else {
2444 $is_selected = "";
2445 }
2446 printf("<option $is_selected id='%d'>%s</option>",
2447 $tmp_line["id"], $tmp_line["description"]);
2448 }
2449
2450 print "</select></td>";
2451
2452
2453 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2454 "\"></td>";
2455
2456 print "</td>";
2457 }
2458
2459 print "</tr>";
2460
2461 ++$lnum;
2462 }
2463
2464 if ($lnum == 0) {
2465 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2466 }
2467
2468 print "</table>";
2469
2470 print "<p>";
2471
2472 if ($subop == "edit") {
2473 print "Edit feed:
2474 <input type=\"submit\" class=\"button\"
2475 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
2476 <input type=\"submit\" class=\"button\"
2477 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
2478
2479 } else {
2480
2481 print "
2482 Selection:
2483 <input type=\"submit\" class=\"button\"
2484 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2485 <input type=\"submit\" class=\"button\"
2486 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2487 }
2488
2489 } else {
2490
2491 print "<p>No filters defined.</p>";
2492
2493 }
2494 }
2495
2496 // We need to accept raw SQL data in label queries, so not everything is escaped
2497 // here, this is by design. If you don't like the whole idea, disable labels
2498 // altogether with GLOBAL_ENABLE_LABELS = false
2499
2500 if ($op == "pref-labels") {
2501
2502 if (!GLOBAL_ENABLE_LABELS) {
2503 return;
2504 }
2505
2506 $subop = $_GET["subop"];
2507
2508 if ($subop == "test") {
2509
2510 $expr = $_GET["expr"];
2511 $descr = $_GET["descr"];
2512
2513 print "<div class='infoBoxContents'>";
2514
2515 print "<h1>Label &laquo;$descr&raquo;</h1>";
2516
2517 // print "<p><b>Expression</b>: $expr</p>";
2518
2519 $result = db_query($link,
2520 "SELECT count(id) AS num_matches
2521 FROM ttrss_entries,ttrss_user_entries
2522 WHERE ($expr) AND
2523 ttrss_user_entries.ref_id = ttrss_entries.id AND
2524 owner_uid = " . $_SESSION["uid"]);
2525
2526 $num_matches = db_fetch_result($result, 0, "num_matches");;
2527
2528 if ($num_matches > 0) {
2529
2530 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2531
2532 $result = db_query($link,
2533 "SELECT title,
2534 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2535 FROM ttrss_entries,ttrss_user_entries
2536 WHERE ($expr) AND
2537 ttrss_user_entries.ref_id = ttrss_entries.id
2538 AND owner_uid = " . $_SESSION["uid"] . "
2539 ORDER BY date_entered DESC LIMIT 5");
2540
2541 print "<ul class=\"nomarks\">";
2542 while ($line = db_fetch_assoc($result)) {
2543 print "<li>".$line["title"].
2544 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2545 }
2546 print "</ul>";
2547
2548 } else {
2549 print "<p>Query didn't return any matches.</p>";
2550 }
2551
2552 print "</div>";
2553
2554 print "<div align='center'>
2555 <input type='submit' class='button'
2556 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2557 return;
2558 }
2559
2560 if ($subop == "editSave") {
2561
2562 $sql_exp = $_GET["s"];
2563 $descr = $_GET["d"];
2564 $label_id = db_escape_string($_GET["id"]);
2565
2566 // print "$sql_exp : $descr : $label_id";
2567
2568 $result = db_query($link, "UPDATE ttrss_labels SET
2569 sql_exp = '$sql_exp',
2570 description = '$descr'
2571 WHERE id = '$label_id'");
2572 }
2573
2574 if ($subop == "remove") {
2575
2576 if (!WEB_DEMO_MODE) {
2577
2578 $ids = split(",", db_escape_string($_GET["ids"]));
2579
2580 foreach ($ids as $id) {
2581 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2582
2583 }
2584 }
2585 }
2586
2587 if ($subop == "add") {
2588
2589 if (!WEB_DEMO_MODE) {
2590
2591 // no escaping is done here on purpose
2592 $exp = trim($_GET["exp"]);
2593
2594 $result = db_query($link,
2595 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2596 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2597 }
2598 }
2599
2600 print "<div class=\"prefGenericAddBox\">
2601 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
2602
2603 print"<input type=\"submit\" class=\"button\"
2604 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2605
2606 $result = db_query($link, "SELECT
2607 id,sql_exp,description
2608 FROM
2609 ttrss_labels
2610 WHERE
2611 owner_uid = ".$_SESSION["uid"]."
2612 ORDER by description");
2613
2614 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2615
2616 if (db_num_rows($result) != 0) {
2617
2618 print "<p><table width=\"100%\" cellspacing=\"0\"
2619 class=\"prefLabelList\" id=\"prefLabelList\">";
2620
2621 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2622 Select:
2623 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2624 'LILRR-', 'LICHK-', true)\">All</a>,
2625 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2626 'LILRR-', 'LICHK-', false)\">None</a>
2627 </td</tr>";
2628
2629 print "<tr class=\"title\">
2630 <td align='center' width=\"5%\">&nbsp;</td>
2631 <td width=\"40%\">SQL expression
2632 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2633 </td>
2634 <td width=\"40%\">Caption</td></tr>";
2635
2636 $lnum = 0;
2637
2638 while ($line = db_fetch_assoc($result)) {
2639
2640 $class = ($lnum % 2) ? "even" : "odd";
2641
2642 $label_id = $line["id"];
2643 $edit_label_id = $_GET["id"];
2644
2645 if ($subop == "edit" && $label_id != $edit_label_id) {
2646 $class .= "Grayed";
2647 $this_row_id = "";
2648 } else {
2649 $this_row_id = "id=\"LILRR-$label_id\"";
2650 }
2651
2652 print "<tr class=\"$class\" $this_row_id>";
2653
2654 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2655 $line["description"] = htmlspecialchars($line["description"]);
2656
2657 if (!$edit_label_id || $subop != "edit") {
2658
2659 if (!$line["description"]) $line["description"] = "[No caption]";
2660
2661 print "<td align='center'><input onclick='toggleSelectRow(this);'
2662 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2663
2664 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2665 $line["sql_exp"] . "</td>";
2666
2667 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2668 $line["description"] . "</td>";
2669
2670 } else if ($label_id != $edit_label_id) {
2671
2672 if (!$line["description"]) $line["description"] = "[No description]";
2673
2674 print "<td><input disabled=\"true\" type=\"checkbox\"
2675 id=\"LICHK-".$line["id"]."\"></td>";
2676
2677 print "<td>".$line["sql_exp"]."</td>";
2678 print "<td>".$line["description"]."</td>";
2679
2680 } else {
2681
2682 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2683
2684 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2685 "\"></td>";
2686
2687 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2688 "\"></td>";
2689
2690 }
2691
2692
2693 print "</tr>";
2694
2695 ++$lnum;
2696 }
2697
2698 if ($lnum == 0) {
2699 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2700 }
2701
2702 print "</table>";
2703
2704 print "<p>";
2705
2706 if ($subop == "edit") {
2707 print "Edit label:
2708 <input type=\"submit\" class=\"button\"
2709 onclick=\"javascript:labelTest()\" value=\"Test\">
2710 <input type=\"submit\" class=\"button\"
2711 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2712 <input type=\"submit\" class=\"button\"
2713 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2714
2715 } else {
2716
2717 print "
2718 Selection:
2719 <input type=\"submit\" class=\"button\"
2720 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2721 <input type=\"submit\" class=\"button\"
2722 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2723 }
2724 } else {
2725 print "<p>No labels defined.</p>";
2726 }
2727 }
2728
2729 if ($op == "error") {
2730 print "<div width=\"100%\" align='center'>";
2731 $msg = $_GET["msg"];
2732 print $msg;
2733 print "</div>";
2734 }
2735
2736 if ($op == "help") {
2737 if (!$_GET["noheaders"]) {
2738 print "<html><head>
2739 <title>Tiny Tiny RSS : Help</title>
2740 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2741 <script type=\"text/javascript\" src=\"functions.js\"></script>
2742 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2743 </head><body>";
2744 }
2745
2746 $tid = sprintf("%d", $_GET["tid"]);
2747
2748 print "<div class='infoBoxContents'>";
2749
2750 if (file_exists("help/$tid.php")) {
2751 include("help/$tid.php");
2752 } else {
2753 print "<p>Help topic not found.</p>";
2754 }
2755
2756 print "</div>";
2757
2758 print "<div align='center'>
2759 <input type='submit' class='button'
2760 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2761
2762 if (!$_GET["noheaders"]) {
2763 print "</body></html>";
2764 }
2765
2766 }
2767
2768 if ($op == "dlg") {
2769 $id = $_GET["id"];
2770 $param = $_GET["param"];
2771
2772 if ($id == "quickAddFeed") {
2773 print "
2774 Feed URL: <input
2775 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2776 id=\"qafInput\">";
2777
2778 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2779 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2780 WHERE owner_uid = ".$_SESSION["uid"]."
2781 ORDER BY title");
2782
2783 print " <select id=\"qafCat\">";
2784 print "<option id=\"0\">Uncategorized</option>";
2785
2786 if (db_num_rows($result) != 0) {
2787
2788 print "<option disabled>--------</option>";
2789
2790 while ($line = db_fetch_assoc($result)) {
2791 printf("<option id='%d'>%s</option>",
2792 $line["id"], $line["title"]);
2793 }
2794 }
2795
2796 print "</select>";
2797 }
2798
2799 print "&nbsp;<input class=\"button\"
2800 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2801 <input class=\"button\"
2802 type=\"submit\" onclick=\"javascript:closeDlg()\"
2803 value=\"Cancel\">";
2804 }
2805
2806 if ($id == "quickDelFeed") {
2807
2808 $param = db_escape_string($param);
2809
2810 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2811
2812 if ($result) {
2813
2814 $f_title = db_fetch_result($result, 0, "title");
2815
2816 print "Remove current feed (<b>$f_title</b>)?&nbsp;
2817 <input class=\"button\"
2818 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2819 <input class=\"button\"
2820 type=\"submit\" onclick=\"javascript:closeDlg()\"
2821 value=\"Cancel\">";
2822 } else {
2823 print "Error: Feed $param not found.&nbsp;
2824 <input class=\"button\"
2825 type=\"submit\" onclick=\"javascript:closeDlg()\"
2826 value=\"Cancel\">";
2827 }
2828 }
2829
2830 if ($id == "search") {
2831
2832 print "<input id=\"searchbox\" class=\"extSearch\"
2833 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2834 onchange=\"javascript:search()\">
2835 <select id=\"searchmodebox\">
2836 <option selected>All feeds</option>
2837 <option>This feed</option>
2838 </select>
2839 <input type=\"submit\"
2840 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2841 <input class=\"button\"
2842 type=\"submit\" onclick=\"javascript:closeDlg()\"
2843 value=\"Close\">";
2844
2845 }
2846
2847 if ($id == "quickAddFilter") {
2848
2849 $result = db_query($link, "SELECT description
2850 FROM ttrss_filter_types ORDER BY description");
2851
2852 $filter_types = array();
2853
2854 while ($line = db_fetch_assoc($result)) {
2855 array_push($filter_types, $line["description"]);
2856 }
2857
2858 print "<table>";
2859
2860 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2861
2862 print_select("fadd_match", "Title", $filter_types);
2863
2864 print "</td></tr>";
2865 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2866
2867 print "<option selected id=\"0\">All feeds</option>";
2868
2869 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2870 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2871
2872 if (db_num_rows($result) > 0) {
2873 print "<option disabled>--------</option>";
2874 }
2875
2876 while ($line = db_fetch_assoc($result)) {
2877 if ($param == $line["id"]) {
2878 $selected = "selected";
2879 } else {
2880 $selected = "";
2881 }
2882 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2883 }
2884
2885 print "</select></td></tr>";
2886
2887 print "<tr><td>Action:</td>";
2888
2889 print "<td><select id=\"fadd_action\">";
2890
2891 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2892 ORDER BY name");
2893
2894 while ($line = db_fetch_assoc($result)) {
2895 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2896 }
2897
2898 print "</select>";
2899
2900 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2901
2902 print "<input type=\"submit\"
2903 class=\"button\" onclick=\"javascript:qaddFilter()\"
2904 value=\"Add filter\"> ";
2905
2906 print "<input class=\"button\"
2907 type=\"submit\" onclick=\"javascript:closeDlg()\"
2908 value=\"Close\">";
2909
2910 print "</td></tr></table>";
2911 }
2912 }
2913
2914 // update feeds of all users, may be used anonymously
2915 if ($op == "globalUpdateFeeds") {
2916
2917 $result = db_query($link, "SELECT id FROM ttrss_users");
2918
2919 while ($line = db_fetch_assoc($result)) {
2920 $user_id = $line["id"];
2921 // print "<!-- updating feeds of uid $user_id -->";
2922 update_all_feeds($link, false, $user_id);
2923 }
2924
2925 print "<rpc-reply>
2926 <message msg=\"All feeds updated\"/>
2927 </rpc-reply>";
2928
2929 }
2930
2931 if ($op == "pref-prefs") {
2932
2933 $subop = $_REQUEST["subop"];
2934
2935 if ($subop == "Save configuration") {
2936
2937 if (WEB_DEMO_MODE) {
2938 header("Location: prefs.php");
2939 return;
2940 }
2941
2942 $_SESSION["prefs_op_result"] = "save-config";
2943
2944 foreach (array_keys($_POST) as $pref_name) {
2945
2946 $pref_name = db_escape_string($pref_name);
2947 $value = db_escape_string($_POST[$pref_name]);
2948
2949 $result = db_query($link, "SELECT type_name
2950 FROM ttrss_prefs,ttrss_prefs_types
2951 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2952
2953 if (db_num_rows($result) > 0) {
2954
2955 $type_name = db_fetch_result($result, 0, "type_name");
2956
2957 // print "$pref_name : $type_name : $value<br>";
2958
2959 if ($type_name == "bool") {
2960 if ($value == "1") {
2961 $value = "true";
2962 } else {
2963 $value = "false";
2964 }
2965 } else if ($type_name == "integer") {
2966 $value = sprintf("%d", $value);
2967 }
2968
2969 // print "$pref_name : $type_name : $value<br>";
2970
2971 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2972 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2973
2974 }
2975
2976 header("Location: prefs.php");
2977
2978 }
2979
2980 } else if ($subop == "getHelp") {
2981
2982 $pref_name = db_escape_string($_GET["pn"]);
2983
2984 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2985 WHERE pref_name = '$pref_name'");
2986
2987 if (db_num_rows($result) > 0) {
2988 $help_text = db_fetch_result($result, 0, "help_text");
2989 print $help_text;
2990 } else {
2991 print "Unknown option: $pref_name";
2992 }
2993
2994 } else if ($subop == "Change e-mail") {
2995
2996 if (WEB_DEMO_MODE) {
2997 header("Location: prefs.php");
2998 return;
2999 }
3000
3001 $email = db_escape_string($_GET["email"]);
3002 $active_uid = $_SESSION["uid"];
3003
3004 if ($email) {
3005 db_query($link, "UPDATE ttrss_users SET email = '$email'
3006 WHERE id = '$active_uid'");
3007 }
3008
3009 header("Location: prefs.php");
3010
3011 } else if ($subop == "Change password") {
3012
3013 if (WEB_DEMO_MODE) {
3014 header("Location: prefs.php");
3015 return;
3016 }
3017
3018 $old_pw = $_POST["OLD_PASSWORD"];
3019 $new_pw = $_POST["OLD_PASSWORD"];
3020
3021 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3022 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3023
3024 $active_uid = $_SESSION["uid"];
3025
3026 if ($old_pw && $new_pw) {
3027
3028 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3029
3030 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3031 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3032 pwd_hash = '$old_pw_hash')");
3033
3034 if (db_num_rows($result) == 1) {
3035 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3036 WHERE id = '$active_uid'");
3037
3038 $_SESSION["pwd_change_result"] = "ok";
3039 } else {
3040 $_SESSION["pwd_change_result"] = "failed";
3041 }
3042 }
3043
3044 header("Location: prefs.php");
3045
3046 } else if ($subop == "Reset to defaults") {
3047
3048 if (WEB_DEMO_MODE) {
3049 header("Location: prefs.php");
3050 return;
3051 }
3052
3053 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3054
3055 if (DB_TYPE == "pgsql") {
3056 db_query($link,"UPDATE ttrss_user_prefs
3057 SET value = ttrss_prefs.def_value
3058 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3059 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3060 } else {
3061 db_query($link, "DELETE FROM ttrss_user_prefs
3062 WHERE owner_uid = ".$_SESSION["uid"]);
3063 initialize_user_prefs($link, $_SESSION["uid"]);
3064 }
3065
3066 header("Location: prefs.php");
3067
3068 } else if ($subop == "Change theme") {
3069
3070 $theme = db_escape_string($_POST["theme"]);
3071
3072 if ($theme == "Default") {
3073 $theme_qpart = 'NULL';
3074 } else {
3075 $theme_qpart = "'$theme'";
3076 }
3077
3078 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3079 WHERE theme_name = '$theme'");
3080
3081 if (db_num_rows($result) == 1) {
3082 $theme_id = db_fetch_result($result, 0, "id");
3083 $theme_path = db_fetch_result($result, 0, "theme_path");
3084 } else {
3085 $theme_id = "NULL";
3086 $theme_path = "";
3087 }
3088
3089 db_query($link, "UPDATE ttrss_users SET
3090 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
3091
3092 $_SESSION["theme"] = $theme_path;
3093
3094 header("Location: prefs.php");
3095
3096 } else {
3097
3098 if (!SINGLE_USER_MODE) {
3099
3100 $result = db_query($link, "SELECT id,email FROM ttrss_users
3101 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3102 pwd_hash = 'SHA1:".sha1("password")."')");
3103
3104 if (db_num_rows($result) != 0) {
3105 print "<div class=\"warning\">
3106 Your password is at default value, please change it.
3107 </div>";
3108 }
3109
3110 if ($_SESSION["pwd_change_result"] == "failed") {
3111 print "<div class=\"warning\">
3112 There was an error while changing your password.
3113 </div>";
3114 }
3115
3116 if ($_SESSION["pwd_change_result"] == "ok") {
3117 print "<div class=\"notice\">
3118 Password changed successfully.
3119 </div>";
3120 }
3121
3122 $_SESSION["pwd_change_result"] = "";
3123
3124 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3125 print "<div class=\"notice\">
3126 Your configuration was reset to defaults.
3127 </div>";
3128 }
3129
3130 if ($_SESSION["prefs_op_result"] == "save-config") {
3131 print "<div class=\"notice\">
3132 Your configuration was saved successfully.
3133 </div>";
3134 }
3135
3136 $_SESSION["prefs_op_result"] = "";
3137
3138 print "<form action=\"backend.php\" method=\"GET\">";
3139
3140 print "<table width=\"100%\" class=\"prefPrefsList\">";
3141 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3142
3143 $result = db_query($link, "SELECT email FROM ttrss_users
3144 WHERE id = ".$_SESSION["uid"]);
3145
3146 $email = db_fetch_result($result, 0, "email");
3147
3148 print "<tr><td width=\"40%\">E-mail</td>";
3149 print "<td><input class=\"editbox\" name=\"email\"
3150 value=\"$email\"></td></tr>";
3151
3152 print "</table>";
3153
3154 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3155
3156 print "<p><input class=\"button\" type=\"submit\"
3157 value=\"Change e-mail\" name=\"subop\">";
3158
3159 print "<form action=\"backend.php\" method=\"POST\">";
3160
3161 print "<table width=\"100%\" class=\"prefPrefsList\">";
3162 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3163
3164 print "<tr><td width=\"40%\">Old password</td>";
3165 print "<td><input class=\"editbox\" type=\"password\"
3166 name=\"OLD_PASSWORD\"></td></tr>";
3167
3168 print "<tr><td width=\"40%\">New password</td>";
3169
3170 print "<td><input class=\"editbox\" type=\"password\"
3171 name=\"NEW_PASSWORD\"></td></tr>";
3172
3173 print "</table>";
3174
3175 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3176
3177 print "<p><input class=\"button\" type=\"submit\"
3178 value=\"Change password\" name=\"subop\">";
3179
3180 print "</form>";
3181
3182 }
3183
3184 $result = db_query($link, "SELECT
3185 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3186
3187 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3188
3189 $result = db_query($link, "SELECT
3190 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3191
3192 if (db_num_rows($result) > 0) {
3193
3194 print "<form action=\"backend.php\" method=\"POST\">";
3195 print "<table width=\"100%\" class=\"prefPrefsList\">";
3196 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3197 print "<tr><td width=\"40%\">Select theme</td>";
3198 print "<td><select name=\"theme\">";
3199 print "<option>Default</option>";
3200 print "<option disabled>--------</option>";
3201
3202 while ($line = db_fetch_assoc($result)) {
3203 if ($line["id"] == $user_theme_id) {
3204 $selected = "selected";
3205 } else {
3206 $selected = "";
3207 }
3208 print "<option $selected>" . $line["theme_name"] . "</option>";
3209 }
3210 print "</select></td></tr>";
3211 print "</table>";
3212 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3213 print "<p><input class=\"button\" type=\"submit\"
3214 value=\"Change theme\" name=\"subop\">";
3215 print "</form>";
3216 }
3217
3218 $result = db_query($link, "SELECT
3219 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3220 section_name,def_value
3221 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3222 WHERE type_id = ttrss_prefs_types.id AND
3223 section_id = ttrss_prefs_sections.id AND
3224 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3225 owner_uid = ".$_SESSION["uid"]."
3226 ORDER BY section_id,short_desc");
3227
3228 print "<form action=\"backend.php\" method=\"POST\">";
3229
3230 $lnum = 0;
3231
3232 $active_section = "";
3233
3234 while ($line = db_fetch_assoc($result)) {
3235
3236 if ($active_section != $line["section_name"]) {
3237
3238 if ($active_section != "") {
3239 print "</table>";
3240 }
3241
3242 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3243
3244 $active_section = $line["section_name"];
3245
3246 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3247 // print "<tr class=\"title\">
3248 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3249
3250 $lnum = 0;
3251 }
3252
3253 // $class = ($lnum % 2) ? "even" : "odd";
3254
3255 print "<tr>";
3256
3257 $type_name = $line["type_name"];
3258 $pref_name = $line["pref_name"];
3259 $value = $line["value"];
3260 $def_value = $line["def_value"];
3261 $help_text = $line["help_text"];
3262
3263 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3264
3265 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3266
3267 print "</td>";
3268
3269 print "<td>";
3270
3271 if ($type_name == "bool") {
3272 // print_select($pref_name, $value, array("true", "false"));
3273
3274 if ($value == "true") {
3275 $value = "Yes";
3276 } else {
3277 $value = "No";
3278 }
3279
3280 print_radio($pref_name, $value, array("Yes", "No"));
3281
3282 } else {
3283 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3284 }
3285
3286 print "</td>";
3287
3288 print "</tr>";
3289
3290 $lnum++;
3291 }
3292
3293 print "</table>";
3294
3295 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3296
3297 print "<p><input class=\"button\" type=\"submit\"
3298 name=\"subop\" value=\"Save configuration\">";
3299
3300 print "&nbsp;<input class=\"button\" type=\"submit\"
3301 name=\"subop\" onclick=\"return validatePrefsReset()\"
3302 value=\"Reset to defaults\"></p>";
3303
3304 print "</form>";
3305
3306 }
3307
3308 }
3309
3310 if ($op == "pref-users") {
3311
3312 $subop = $_GET["subop"];
3313
3314 if ($subop == "editSave") {
3315
3316 if (!WEB_DEMO_MODE) {
3317
3318 $login = db_escape_string($_GET["l"]);
3319 $uid = db_escape_string($_GET["id"]);
3320 $access_level = sprintf("%d", $_GET["al"]);
3321 $email = db_escape_string($_GET["e"]);
3322
3323 db_query($link, "UPDATE ttrss_users SET login = '$login',
3324 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3325
3326 }
3327 } else if ($subop == "remove") {
3328
3329 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3330
3331 $ids = split(",", db_escape_string($_GET["ids"]));
3332
3333 foreach ($ids as $id) {
3334 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3335
3336 }
3337 }
3338 } else if ($subop == "add") {
3339
3340 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3341
3342 $login = db_escape_string(trim($_GET["login"]));
3343 $tmp_user_pwd = make_password(8);
3344 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3345
3346 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
3347 VALUES ('$login', '$pwd_hash', 0)");
3348
3349
3350 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3351 login = '$login' AND pwd_hash = '$pwd_hash'");
3352
3353 if (db_num_rows($result) == 1) {
3354
3355 $new_uid = db_fetch_result($result, 0, "id");
3356
3357 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3358 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3359
3360 initialize_user($link, $new_uid);
3361
3362 } else {
3363
3364 print "<div class=\"warning\">Error while adding user <b>".
3365 $_GET["login"].".</b></div>";
3366
3367 }
3368 }
3369 } else if ($subop == "resetPass") {
3370
3371 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3372
3373 $uid = db_escape_string($_GET["id"]);
3374
3375 $result = db_query($link, "SELECT login,email
3376 FROM ttrss_users WHERE id = '$uid'");
3377
3378 $login = db_fetch_result($result, 0, "login");
3379 $email = db_fetch_result($result, 0, "email");
3380 $tmp_user_pwd = make_password(8);
3381 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3382
3383 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3384 WHERE id = '$uid'");
3385
3386 print "<div class=\"notice\">Changed password of
3387 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3388
3389 if (MAIL_RESET_PASS && $email) {
3390 print " Notifying <b>$email</b>.";
3391
3392 mail("$login <$email>", "Password reset notification",
3393 "Hi, $login.\n".
3394 "\n".
3395 "Your password for this TT-RSS installation was reset by".
3396 " an administrator.\n".
3397 "\n".
3398 "Your new password is $tmp_user_pwd, please remember".
3399 " it for later reference.\n".
3400 "\n".
3401 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3402 }
3403
3404 print "</div>";
3405
3406 }
3407 }
3408
3409 print "<div class=\"prefGenericAddBox\">
3410 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\">&nbsp;";
3411
3412 print"<input type=\"submit\" class=\"button\"
3413 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3414
3415 $result = db_query($link, "SELECT
3416 id,login,access_level,email,
3417 SUBSTRING(last_login,1,16) as last_login
3418 FROM
3419 ttrss_users
3420 ORDER by login");
3421
3422 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3423
3424 print "<p><table width=\"100%\" cellspacing=\"0\"
3425 class=\"prefUserList\" id=\"prefUserList\">";
3426
3427 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3428 Select:
3429 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3430 'UMRR-', 'UMCHK-', true)\">All</a>,
3431 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3432 'UMRR-', 'UMCHK-', false)\">None</a>
3433 </td</tr>";
3434
3435 print "<tr class=\"title\">
3436 <td align='center' width=\"5%\">&nbsp;</td>
3437 <td width='20%'>Username</td>
3438 <td width='20%'>E-mail</td>
3439 <td width='20%'>Access Level</td>
3440 <td width='20%'>Last login</td></tr>";
3441
3442 $lnum = 0;
3443
3444 while ($line = db_fetch_assoc($result)) {
3445
3446 $class = ($lnum % 2) ? "even" : "odd";
3447
3448 $uid = $line["id"];
3449 $edit_uid = $_GET["id"];
3450
3451 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
3452 $class .= "Grayed";
3453 $this_row_id = "";
3454 } else {
3455 $this_row_id = "id=\"UMRR-$uid\"";
3456 }
3457
3458 print "<tr class=\"$class\" $this_row_id>";
3459
3460 $line["login"] = htmlspecialchars($line["login"]);
3461
3462 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3463 strtotime($line["last_login"]));
3464
3465 /* if ($uid == $_SESSION["uid"]) {
3466
3467 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3468 id=\"UMCHK-".$line["id"]."\"></td>";
3469
3470 print "<td>".$line["login"]."</td>";
3471 print "<td>".$line["email"]."</td>";
3472 print "<td>".$line["access_level"]."</td>";
3473
3474 } else */ if (!$edit_uid || $subop != "edit") {
3475
3476 print "<td align='center'><input onclick='toggleSelectRow(this);'
3477 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3478
3479 print "<td><a href=\"javascript:editUser($uid);\">" .
3480 $line["login"] . "</td>";
3481
3482 print "<td><a href=\"javascript:editUser($uid);\">" .
3483 $line["email"] . "</td>";
3484
3485 print "<td><a href=\"javascript:editUser($uid);\">" .
3486 $line["access_level"] . "</td>";
3487
3488 } else if ($uid != $edit_uid) {
3489
3490 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3491 id=\"UMCHK-".$line["id"]."\"></td>";
3492
3493 print "<td>".$line["login"]."</td>";
3494 print "<td>".$line["email"]."</td>";
3495 print "<td>".$line["access_level"]."</td>";
3496
3497 } else {
3498
3499 print "<td align='center'>
3500 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3501
3502 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3503 "\"></td>";
3504
3505 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3506 "\"></td>";
3507
3508 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3509 "\"></td>";
3510
3511 }
3512
3513 print "<td>".$line["last_login"]."</td>";
3514
3515 print "</tr>";
3516
3517 ++$lnum;
3518 }
3519
3520 print "</table>";
3521
3522 print "<p>";
3523
3524 if ($subop == "edit") {
3525 print "Edit label:
3526 <input type=\"submit\" class=\"button\"
3527 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
3528 <input type=\"submit\" class=\"button\"
3529 onclick=\"javascript:userEditSave()\" value=\"Save\">";
3530
3531 } else {
3532
3533 print "
3534 Selection:
3535 <input type=\"submit\" class=\"button\"
3536 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3537 <input type=\"submit\" class=\"button\"
3538 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3539 <input type=\"submit\" class=\"button\"
3540 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3541 <input type=\"submit\" class=\"button\"
3542 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3543
3544 }
3545 }
3546
3547 if ($op == "user-details") {
3548
3549 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3550 return;
3551 }
3552
3553 /* print "<html><head>
3554 <title>Tiny Tiny RSS : User Details</title>
3555 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3556 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3557 </head><body>"; */
3558
3559 $uid = sprintf("%d", $_GET["id"]);
3560
3561 print "<div class='infoBoxContents'>";
3562
3563 $result = db_query($link, "SELECT login,
3564 SUBSTRING(last_login,1,16) AS last_login,
3565 access_level,
3566 (SELECT COUNT(int_id) FROM ttrss_user_entries
3567 WHERE owner_uid = id) AS stored_articles
3568 FROM ttrss_users
3569 WHERE id = '$uid'");
3570
3571 if (db_num_rows($result) == 0) {
3572 print "<h1>User not found</h1>";
3573 return;
3574 }
3575
3576 print "<h1>User Details</h1>";
3577
3578 print "<table width='100%'>";
3579
3580 $login = db_fetch_result($result, 0, "login");
3581 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3582 strtotime(db_fetch_result($result, 0, "last_login")));
3583 $access_level = db_fetch_result($result, 0, "access_level");
3584 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3585
3586 print "<tr><td>Username</td><td>$login</td></tr>";
3587 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3588 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3589 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3590
3591 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3592 WHERE owner_uid = '$uid'");
3593
3594 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3595
3596 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3597
3598 /* $result = db_query($link, "SELECT
3599 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3600 FROM ttrss_user_entries,ttrss_entries
3601 WHERE owner_uid = '$uid' AND ref_id = id");
3602
3603 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3604
3605 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3606
3607 print "</table>";
3608
3609 print "<h1>Subscribed feeds</h1>";
3610
3611 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3612 WHERE owner_uid = '$uid' ORDER BY title LIMIT 20");
3613
3614 print "<ul class=\"nomarks\">";
3615
3616 while ($line = db_fetch_assoc($result)) {
3617
3618 $icon_file = ICONS_URL."/".$line["id"].".ico";
3619
3620 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3621 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3622 } else {
3623 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3624 }
3625
3626 print "<li>$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3627 }
3628
3629 if (db_num_rows($result) < $num_feeds) {
3630 // FIXME - add link to show ALL subscribed feeds here somewhere
3631 print "<li><img
3632 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3633 }
3634
3635 print "</ul>";
3636
3637 print "</div>";
3638
3639 print "<div align='center'>
3640 <input type='submit' class='button'
3641 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3642
3643 // print "</body></html>";
3644
3645 }
3646
3647 if ($op == "feed-details") {
3648
3649 // $feed_id = $_GET["id"];
3650
3651 $feed_ids = split(",", db_escape_string($_GET["id"]));
3652
3653 print "<div class=\"infoBoxContents\">";
3654
3655 foreach ($feed_ids as $feed_id) {
3656
3657 $result = db_query($link,
3658 "SELECT
3659 title,feed_url,
3660 SUBSTRING(last_updated,1,16) as last_updated,
3661 icon_url,site_url,
3662 (SELECT COUNT(int_id) FROM ttrss_user_entries
3663 WHERE feed_id = id) AS total,
3664 (SELECT COUNT(int_id) FROM ttrss_user_entries
3665 WHERE feed_id = id AND unread = true) AS unread,
3666 (SELECT COUNT(int_id) FROM ttrss_user_entries
3667 WHERE feed_id = id AND marked = true) AS marked
3668 FROM ttrss_feeds
3669 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3670
3671 if (db_num_rows($result) == 0) return;
3672
3673 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3674 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3675 strtotime(db_fetch_result($result, 0, "last_updated")));
3676 $feed_url = db_fetch_result($result, 0, "feed_url");
3677 $icon_url = db_fetch_result($result, 0, "icon_url");
3678 $total = db_fetch_result($result, 0, "total");
3679 $unread = db_fetch_result($result, 0, "unread");
3680 $marked = db_fetch_result($result, 0, "marked");
3681 $site_url = db_fetch_result($result, 0, "site_url");
3682
3683 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3684 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
3685
3686 $subscribed = db_fetch_result($result, 0, "subscribed");
3687
3688 $icon_file = ICONS_DIR . "/$feed_id.ico";
3689
3690 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3691 $feed_icon = "<img width=\"16\" height=\"16\"
3692 src=\"" . ICONS_URL . "/$feed_id.ico\">";
3693 } else {
3694 $feed_icon = "";
3695 }
3696
3697 print "<h1>$feed_icon $title</h1>";
3698
3699 print "<table width='100%'>";
3700
3701 if ($site_url) {
3702 print "<tr><td width='30%'>Link</td>
3703 <td><a href=\"$site_url\">$site_url</a>
3704 <a href=\"$feed_url\">(feed)</a></td>
3705 </td></tr>";
3706 } else {
3707 print "<tr><td width='30%'>Feed URL</td>
3708 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3709 }
3710 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3711 print "<tr><td>Total articles</td><td>$total</td></tr>";
3712 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3713 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3714 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3715
3716 print "</table>";
3717
3718 /* $result = db_query($link, "SELECT title,
3719 SUBSTRING(updated,1,16) AS updated,unread
3720 FROM ttrss_entries,ttrss_user_entries
3721 WHERE ref_id = id AND feed_id = '$feed_id'
3722 ORDER BY date_entered DESC LIMIT 5");
3723
3724 if (db_num_rows($result) > 0) {
3725
3726 print "<h1>Latest headlines</h1>";
3727
3728 print "<ul class=\"nomarks\">";
3729
3730 while ($line = db_fetch_assoc($result)) {
3731 if ($line["unread"] == "t" || $line["unread"] == "1") {
3732 $line["title"] = "<b>" . $line["title"] . "</b>";
3733 }
3734 print "<li>" . $line["title"].
3735 "&nbsp;<span class=\"insensitive\">(" .
3736 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3737 strtotime($line["updated"])).
3738 ")</span></li>";
3739 }
3740
3741 print "</ul>";
3742
3743 } */
3744 }
3745
3746 print "</div>";
3747
3748 print "<div align='center'>
3749 <input type='submit' class='button'
3750 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3751 }
3752
3753 db_close($link);
3754 ?>
3755
3756 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3757