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