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