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