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