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