]> git.wh0rd.org - tt-rss.git/blame - backend.php
update README
[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 1262 $class .= "Grayed";
53226edc
AD
1263 $this_row_id = "";
1264 } else {
1265 $this_row_id = "id=\"FEEDR-$feed_id\"";
c64d5b03
AD
1266 }
1267
53226edc 1268 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1269
1270 $icon_file = ICONS_DIR . "/$feed_id.ico";
1271
1272 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1273 $feed_icon = "<img width=\"16\" height=\"16\"
1274 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1275 } else {
1276 $feed_icon = "&nbsp;";
1277 }
1278 print "<td align='center'>$feed_icon</td>";
c64d5b03
AD
1279
1280 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
3b0feb9b
AD
1281 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1282 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1283
1284 if (!$edit_cat) $edit_cat = "Uncategorized";
c64d5b03 1285
3b0feb9b 1286 if (!$edit_feed_id || $subop != "edit") {
c64d5b03
AD
1287
1288 print "<td><input onclick='toggleSelectRow(this);'
3b0feb9b 1289 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
3547842a
AD
1290
1291 $edit_title = truncate_string($edit_title, 40);
1292 $edit_link = truncate_string($edit_link, 60);
c64d5b03 1293
3b0feb9b 1294 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
c64d5b03 1295 $edit_title . "</a></td>";
3b0feb9b
AD
1296
1297 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1298 $edit_link . "</a></td>";
1299
1300 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1301 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1302 $edit_cat . "</a></td>";
1303 }
1304
1305 if ($line["update_interval"] == "0")
1306 $line["update_interval"] = "Default";
c64d5b03 1307
3b0feb9b
AD
1308 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1309 $line["update_interval"] . "</a></td>";
1310
1311 if ($line["purge_interval"] == "0")
1312 $line["purge_interval"] = "Default";
1313
1314 if ($line["purge_interval"] < 0)
1315 $line["purge_interval"] = "Disabled";
1316
1317 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1318 $line["purge_interval"] . "</a></td>";
1319
1320 } else if ($feed_id != $edit_feed_id) {
c64d5b03
AD
1321
1322 print "<td><input disabled=\"true\" type=\"checkbox\"
1323 id=\"FRCHK-".$line["id"]."\"></td>";
3547842a
AD
1324
1325 $edit_title = truncate_string($edit_title, 40);
1326 $edit_link = truncate_string($edit_link, 60);
1327
c64d5b03 1328 print "<td>$edit_title</td>";
3b0feb9b
AD
1329 print "<td>$edit_link</td>";
1330
1331 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1332 print "<td>$edit_cat</td>";
1333 }
1334
1335 if ($line["update_interval"] == "0")
1336 $line["update_interval"] = "Default";
1337
1338 print "<td>" . $line["update_interval"] . "</td>";
1339
1340 if ($line["purge_interval"] == "0")
1341 $line["purge_interval"] = "Default";
1342
1343 if ($line["purge_interval"] < 0)
1344 $line["purge_interval"] = "Disabled";
1345
1346 print "<td>" . $line["purge_interval"] . "</td>";
c64d5b03
AD
1347
1348 } else {
1349
1350 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1351
1352 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
3b0feb9b
AD
1353 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1354
1355 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1356
1357 print "<td>";
1358 print "<select id=\"iedit_fcat\">";
1359 print "<option id=\"0\">Uncategorized</option>";
1360
1361 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1362 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1363
1364 if (db_num_rows($tmp_result) > 0) {
1365 print "<option disabled>--------</option>";
1366 }
1367
1368 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1369 if ($tmp_line["id"] == $line["cat_id"]) {
1370 $is_selected = "selected";
1371 } else {
1372 $is_selected = "";
1373 }
1374 printf("<option $is_selected id='%d'>%s</option>",
1375 $tmp_line["id"], $tmp_line["title"]);
1376 }
1377
1378 print "</select></td>";
1379 print "</td>";
1380
1381 }
c64d5b03 1382
3b0feb9b
AD
1383 print "<td><input id=\"iedit_updintl\"
1384 value=\"".$line["update_interval"]."\"></td>";
1385 print "<td><input id=\"iedit_purgintl\"
1386 value=\"".$line["purge_interval"]."\"></td>";
1387
c64d5b03 1388 }
3b0feb9b 1389
3547842a 1390/* if (!$line["last_updated"]) $line["last_updated"] = "Never";
3b0feb9b 1391
3547842a 1392 print "<td>" . $line["last_updated"] . "</td>"; */
c64d5b03
AD
1393
1394 print "</tr>";
1395
1396 ++$lnum;
1397 }
1398
c64d5b03 1399 print "</table>";
3b0feb9b 1400
c64d5b03
AD
1401 print "<p>";
1402
3b0feb9b
AD
1403 if ($subop == "edit") {
1404 print "Edit feed:&nbsp;
c64d5b03 1405 <input type=\"submit\" class=\"button\"
3b0feb9b 1406 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
c64d5b03 1407 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1408 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1409 } else {
c64d5b03
AD
1410
1411 print "
1412 Selection:&nbsp;
1413 <input type=\"submit\" class=\"button\"
3b0feb9b 1414 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
c64d5b03 1415 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1416 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1417 <input type=\"submit\" class=\"button\"
1418 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1419
1420 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1421 print "
1422 <input type=\"submit\" class=\"button\"
4f3a84f4 1423 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
3b0feb9b 1424 <input type=\"submit\" class=\"button\"
4f3a84f4 1425 onclick=\"javascript:readSelectedFeeds(false)\"
3b0feb9b
AD
1426 value=\"Mark as unread\">&nbsp;";
1427 }
1428
1429 print "
1430 All feeds: <input type=\"submit\"
1431 class=\"button\" onclick=\"gotoExportOpml()\"
1432 value=\"Export OPML\">";
1433 }
1434 } else {
1435
1436 print "<p>No feeds defined.</p>";
1437
1438 }
1439
1440 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1441
1442 print "<h3>Edit Categories</h3>";
1443
1444 // print "<h3>Categories</h3>";
1445
1446 print "<div class=\"prefGenericAddBox\">
1447 <input id=\"fadd_cat\" size=\"40\">&nbsp;<input
1448 type=\"submit\" class=\"button\"
1449 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1450
1451 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1452 WHERE owner_uid = ".$_SESSION["uid"]."
1453 ORDER BY title");
1454
1455 if (db_num_rows($result) != 0) {
1456
35f3c923
AD
1457 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1458 id=\"prefFeedCatList\">";
1459
1460 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1461 Select:
1462 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 1463 'FCATR-', 'FCCHK-', true)\">All</a>,
35f3c923 1464 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 1465 'FCATR-', 'FCCHK-', false)\">None</a>
35f3c923
AD
1466 </td</tr>";
1467
3b0feb9b
AD
1468 print "<tr class=\"title\">
1469 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1470 </tr>";
1471
1472 $lnum = 0;
1473
1474 while ($line = db_fetch_assoc($result)) {
1475
1476 $class = ($lnum % 2) ? "even" : "odd";
1477
1478 $cat_id = $line["id"];
1479
1480 $edit_cat_id = $_GET["id"];
1481
1482 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1483 $class .= "Grayed";
53226edc
AD
1484 $this_row_id = "";
1485 } else {
1486 $this_row_id = "id=\"FCATR-$cat_id\"";
3b0feb9b
AD
1487 }
1488
53226edc 1489 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1490
1491 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1492
1493 if (!$edit_cat_id || $subop != "editCat") {
1494
1495 print "<td><input onclick='toggleSelectRow(this);'
1496 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1497
1498 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1499 $edit_title . "</a></td>";
1500
1501 } else if ($cat_id != $edit_cat_id) {
1502
1503 print "<td><input disabled=\"true\" type=\"checkbox\"
1504 id=\"FRCHK-".$line["id"]."\"></td>";
1505
1506 print "<td>$edit_title</td>";
1507
1508 } else {
1509
1510 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1511
1512 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1513
1514 }
1515
1516 print "</tr>";
1517
1518 ++$lnum;
1519 }
1520
1521 print "</table>";
1522
1523 print "<p>";
1524
1525 if ($subop == "editCat") {
1526 print "Edit category:&nbsp;
1527 <input type=\"submit\" class=\"button\"
1528 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1529 <input type=\"submit\" class=\"button\"
1530 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1531 } else {
1532
1533 print "
1534 Selection:&nbsp;
1535 <input type=\"submit\" class=\"button\"
1536 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1537 <input type=\"submit\" class=\"button\"
1538 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1539
1540 }
1541
1542 } else {
1543 print "<p>No feed categories defined.</p>";
1544 }
c64d5b03
AD
1545 }
1546
1547 print "<h3>Import OPML</h3>
f5a50b25
AD
1548 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1549 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1550 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1551 type=\"submit\" value=\"Import\">
1552 </form>";
1553
007bda35
AD
1554 }
1555
a0d53889
AD
1556 if ($op == "pref-filters") {
1557
1558 $subop = $_GET["subop"];
1559
1560 if ($subop == "editSave") {
a0d53889 1561
648472a7
AD
1562 $regexp = db_escape_string($_GET["r"]);
1563 $descr = db_escape_string($_GET["d"]);
1564 $match = db_escape_string($_GET["m"]);
1565 $filter_id = db_escape_string($_GET["id"]);
ead60402
AD
1566 $feed_id = db_escape_string($_GET["fid"]);
1567
1568 if (!$feed_id) {
1569 $feed_id = 'NULL';
1570 } else {
1571 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1572 }
0afbd851 1573
648472a7 1574 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 1575 reg_exp = '$regexp',
0afbd851 1576 description = '$descr',
ead60402 1577 feed_id = $feed_id,
0afbd851
AD
1578 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1579 description = '$match')
1580 WHERE id = '$filter_id'");
a0d53889
AD
1581 }
1582
1583 if ($subop == "remove") {
1584
1585 if (!WEB_DEMO_MODE) {
1586
1587 $ids = split(",", $_GET["ids"]);
1588
1589 foreach ($ids as $id) {
648472a7 1590 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
1591
1592 }
1593 }
1594 }
1595
1596 if ($subop == "add") {
1597
de435974 1598 if (!WEB_DEMO_MODE) {
a0d53889 1599
b6b535ca
AD
1600 $regexp = db_escape_string(trim($_GET["regexp"]));
1601 $match = db_escape_string(trim($_GET["match"]));
ead60402
AD
1602 $feed_id = db_escape_string($_GET["fid"]);
1603
1604 if (!$feed_id) {
1605 $feed_id = 'NULL';
1606 } else {
1607 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1608 }
4401bf04 1609
648472a7 1610 $result = db_query($link,
ead60402 1611 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
de435974 1612 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
ead60402 1613 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
de435974 1614 }
a0d53889
AD
1615 }
1616
648472a7 1617 $result = db_query($link, "SELECT description
a0d53889
AD
1618 FROM ttrss_filter_types ORDER BY description");
1619
1620 $filter_types = array();
1621
648472a7 1622 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1623 array_push($filter_types, $line["description"]);
1624 }
1625
2c7070b5
AD
1626 print "<div class=\"prefGenericAddBox\">
1627 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
1628
ead60402
AD
1629 print_select("fadd_match", "Title", $filter_types);
1630
1631 print "&nbsp;<select id=\"fadd_feed\">";
1632
1633 print "<option selected id=\"0\">All feeds</option>";
1634
1635 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1636 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1637
1638 if (db_num_rows($result) > 0) {
1639 print "<option disabled>--------</option>";
1640 }
1641
1642 while ($line = db_fetch_assoc($result)) {
1643 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1644 }
1645
2c7070b5 1646 print "</select>&nbsp;";
a0d53889 1647
2c7070b5
AD
1648 print "<input type=\"submit\"
1649 class=\"button\" onclick=\"javascript:addFilter()\"
1650 value=\"Add filter\">";
a0d53889 1651
648472a7 1652 $result = db_query($link, "SELECT
ead60402
AD
1653 ttrss_filters.id AS id,reg_exp,
1654 ttrss_filters.description AS description,
1655 ttrss_filter_types.name AS filter_type_name,
1656 ttrss_filter_types.description AS filter_type_descr,
1657 feed_id,
1658 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
a0d53889 1659 FROM
ead60402 1660 ttrss_filters,ttrss_filter_types
4356293a 1661 WHERE
ead60402
AD
1662 filter_type = ttrss_filter_types.id AND
1663 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
4356293a 1664 ORDER by reg_exp");
a0d53889 1665
3b0feb9b 1666 if (db_num_rows($result) != 0) {
a0d53889 1667
3b0feb9b 1668 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
35f3c923
AD
1669
1670 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1671 Select:
1672 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 1673 'FILRR-', 'FICHK-', true)\">All</a>,
35f3c923 1674 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 1675 'FILRR-', 'FICHK-', false)\">None</a>
35f3c923
AD
1676 </td</tr>";
1677
3b0feb9b
AD
1678 print "<tr class=\"title\">
1679 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1680 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1681 <td width=\"30%\">Description</td></tr>";
a0d53889 1682
3b0feb9b
AD
1683 $lnum = 0;
1684
1685 while ($line = db_fetch_assoc($result)) {
1686
1687 $class = ($lnum % 2) ? "even" : "odd";
1688
1689 $filter_id = $line["id"];
1690 $edit_filter_id = $_GET["id"];
1691
1692 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1693 $class .= "Grayed";
53226edc
AD
1694 $this_row_id = "";
1695 } else {
1696 $this_row_id = "id=\"FILRR-$filter_id\"";
ead60402 1697 }
3b0feb9b 1698
53226edc 1699 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1700
1701 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1702 $line["description"] = htmlspecialchars($line["description"]);
1703
1704 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1705
1706 if (!$edit_filter_id || $subop != "edit") {
1707
1708 if (!$line["description"]) $line["description"] = "[No description]";
1709
1710 print "<td><input onclick='toggleSelectRow(this);'
1711 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1712
1713 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1714 $line["reg_exp"] . "</td>";
1715
1716 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1717 $line["feed_title"] . "</td>";
1718
1719 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1720 $line["filter_type_descr"] . "</td>";
1721
1722 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1723 $line["description"] . "</td>";
1724
1725 } else if ($filter_id != $edit_filter_id) {
1726
1727 if (!$line["description"]) $line["description"] = "[No description]";
1728
1729 print "<td><input disabled=\"true\" type=\"checkbox\"
1730 id=\"FICHK-".$line["id"]."\"></td>";
1731
1732 print "<td>".$line["reg_exp"]."</td>";
1733 print "<td>".$line["feed_title"]."</td>";
1734 print "<td>".$line["filter_type_descr"]."</td>";
1735 print "<td>".$line["description"]."</td>";
1736
1737 } else {
1738
1739 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1740
1741 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1742 "\"></td>";
1743
1744 print "<td>";
1745
1746 print "<select id=\"iedit_feed\">";
1747
1748 print "<option id=\"0\">All feeds</option>";
1749
1750 if (db_num_rows($result) > 0) {
1751 print "<option disabled>--------</option>";
1752 }
1753
1754 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1755 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1756
1757 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1758 if ($tmp_line["id"] == $line["feed_id"]) {
1759 $is_selected = "selected";
1760 } else {
1761 $is_selected = "";
1762 }
1763 printf("<option $is_selected id='%d'>%s</option>",
1764 $tmp_line["id"], $tmp_line["title"]);
ead60402 1765 }
3b0feb9b
AD
1766
1767 print "</select></td>";
1768
1769 print "<td>";
1770 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1771 print "</td>";
1772
1773 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1774 "\"></td>";
1775
1776 print "</td>";
ead60402 1777 }
3b0feb9b
AD
1778
1779 print "</tr>";
1780
1781 ++$lnum;
a0d53889 1782 }
3b0feb9b
AD
1783
1784 if ($lnum == 0) {
1785 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1786 }
1787
1788 print "</table>";
1789
1790 print "<p>";
1791
1792 if ($subop == "edit") {
1793 print "Edit feed:
1794 <input type=\"submit\" class=\"button\"
1795 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1796 <input type=\"submit\" class=\"button\"
1797 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1798
1799 } else {
1800
1801 print "
1802 Selection:
e828e31e 1803 <input type=\"submit\" class=\"button\"
3b0feb9b 1804 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
e828e31e 1805 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1806 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1807 }
1808
a0d53889
AD
1809 } else {
1810
3b0feb9b
AD
1811 print "<p>No filters defined.</p>";
1812
a0d53889
AD
1813 }
1814 }
1815
48f0adb0
AD
1816 if ($op == "pref-labels") {
1817
1818 $subop = $_GET["subop"];
1819
d9dde1d6
AD
1820 if ($subop == "test") {
1821
1822 $expr = $_GET["expr"];
1823 $descr = $_GET["descr"];
1824
1825 print "<div class='infoBoxContents'>";
1826
1827 print "<h1>Label &laquo;$descr&raquo;</h1>";
1828
1829// print "<p><b>Expression</b>: $expr</p>";
1830
1831 $result = db_query($link,
1832 "SELECT count(id) AS num_matches
1833 FROM ttrss_entries,ttrss_user_entries
1834 WHERE ($expr) AND
1835 ttrss_user_entries.ref_id = ttrss_entries.id AND
1836 owner_uid = " . $_SESSION["uid"]);
1837
1838 $num_matches = db_fetch_result($result, 0, "num_matches");;
1839
1840 if ($num_matches > 0) {
1841
1842 print "<p>Query returned <b>$num_matches</b> matches, first 5:</p>";
1843
1844 $result = db_query($link,
1845 "SELECT title,
1846 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1847 FROM ttrss_entries,ttrss_user_entries
1848 WHERE ($expr) AND
1849 ttrss_user_entries.ref_id = ttrss_entries.id
1850 AND owner_uid = " . $_SESSION["uid"] . "
1851 ORDER BY date_entered DESC LIMIT 5");
1852
1853 print "<ul class=\"nomarks\">";
1854 while ($line = db_fetch_assoc($result)) {
1855 print "<li>".$line["title"].
1856 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
1857 }
1858 print "</ul>";
1859
1860 } else {
1861 print "<p>Query didn't return any matches.</p>";
1862 }
1863
1864 print "</div>";
1865
1866 print "<div align='center'>
1867 <input type='submit' class='button'
1868 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1869 return;
1870 }
1871
48f0adb0
AD
1872 if ($subop == "editSave") {
1873
1874 $sql_exp = $_GET["s"];
1875 $descr = $_GET["d"];
1876 $label_id = db_escape_string($_GET["id"]);
1877
1878// print "$sql_exp : $descr : $label_id";
1879
1880 $result = db_query($link, "UPDATE ttrss_labels SET
1881 sql_exp = '$sql_exp',
1882 description = '$descr'
1883 WHERE id = '$label_id'");
1884 }
1885
1886 if ($subop == "remove") {
1887
1888 if (!WEB_DEMO_MODE) {
1889
1890 $ids = split(",", $_GET["ids"]);
1891
1892 foreach ($ids as $id) {
1893 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1894
1895 }
1896 }
1897 }
1898
1899 if ($subop == "add") {
1900
1901 if (!WEB_DEMO_MODE) {
1902
4401bf04
AD
1903 // no escaping is done here on purpose
1904 $exp = trim($_GET["exp"]);
48f0adb0
AD
1905
1906 $result = db_query($link,
4356293a
AD
1907 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1908 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
1909 }
1910 }
1911
2c7070b5
AD
1912 print "<div class=\"prefGenericAddBox\">
1913 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
48f0adb0 1914
2c7070b5
AD
1915 print"<input type=\"submit\" class=\"button\"
1916 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
48f0adb0
AD
1917
1918 $result = db_query($link, "SELECT
1919 id,sql_exp,description
1920 FROM
4356293a
AD
1921 ttrss_labels
1922 WHERE
1923 owner_uid = ".$_SESSION["uid"]."
1924 ORDER by description");
48f0adb0 1925
d9dde1d6
AD
1926 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1927
3b0feb9b 1928 if (db_num_rows($result) != 0) {
48f0adb0 1929
3b0feb9b 1930 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
35f3c923
AD
1931
1932 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1933 Select:
1934 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 1935 'LILRR-', 'LICHK-', true)\">All</a>,
35f3c923 1936 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 1937 'LILRR-', 'LICHK-', false)\">None</a>
35f3c923
AD
1938 </td</tr>";
1939
3b0feb9b
AD
1940 print "<tr class=\"title\">
1941 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1942 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1943 </td>
1944 <td width=\"40%\">Caption</td></tr>";
1945
1946 $lnum = 0;
1947
1948 while ($line = db_fetch_assoc($result)) {
1949
1950 $class = ($lnum % 2) ? "even" : "odd";
1951
1952 $label_id = $line["id"];
1953 $edit_label_id = $_GET["id"];
1954
1955 if ($subop == "edit" && $label_id != $edit_label_id) {
1956 $class .= "Grayed";
53226edc
AD
1957 $this_row_id = "";
1958 } else {
1959 $this_row_id = "id=\"LILRR-$label_id\"";
3b0feb9b
AD
1960 }
1961
53226edc 1962 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1963
1964 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1965 $line["description"] = htmlspecialchars($line["description"]);
1966
1967 if (!$edit_label_id || $subop != "edit") {
1968
1969 if (!$line["description"]) $line["description"] = "[No caption]";
1970
1971 print "<td><input onclick='toggleSelectRow(this);'
1972 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1973
1974 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1975 $line["sql_exp"] . "</td>";
48f0adb0 1976
3b0feb9b
AD
1977 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1978 $line["description"] . "</td>";
1979
1980 } else if ($label_id != $edit_label_id) {
1981
1982 if (!$line["description"]) $line["description"] = "[No description]";
1983
1984 print "<td><input disabled=\"true\" type=\"checkbox\"
1985 id=\"LICHK-".$line["id"]."\"></td>";
1986
1987 print "<td>".$line["sql_exp"]."</td>";
1988 print "<td>".$line["description"]."</td>";
1989
1990 } else {
1991
1992 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1993
1994 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1995 "\"></td>";
1996
1997 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1998 "\"></td>";
1999
2000 }
2001
48f0adb0 2002
3b0feb9b
AD
2003 print "</tr>";
2004
2005 ++$lnum;
2006 }
2007
2008 if ($lnum == 0) {
2009 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2010 }
2011
2012 print "</table>";
2013
2014 print "<p>";
2015
2016 if ($subop == "edit") {
2017 print "Edit label:
d9dde1d6
AD
2018 <input type=\"submit\" class=\"button\"
2019 onclick=\"javascript:labelTest()\" value=\"Test\">
3b0feb9b
AD
2020 <input type=\"submit\" class=\"button\"
2021 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2022 <input type=\"submit\" class=\"button\"
2023 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2024
2025 } else {
2026
2027 print "
2028 Selection:
48f0adb0 2029 <input type=\"submit\" class=\"button\"
3b0feb9b 2030 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
48f0adb0 2031 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2032 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2033 }
48f0adb0 2034 } else {
3b0feb9b 2035 print "<p>No labels defined.</p>";
48f0adb0
AD
2036 }
2037 }
2038
e828e31e
AD
2039 if ($op == "error") {
2040 print "<div width=\"100%\" align='center'>";
2041 $msg = $_GET["msg"];
2042 print $msg;
2043 print "</div>";
2044 }
2045
7dc66a61
AD
2046 if ($op == "help") {
2047 print "<html><head>
2048 <title>Tiny Tiny RSS : Help</title>
2049 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2050 <script type=\"text/javascript\" src=\"functions.js\"></script>
7dc66a61
AD
2051 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2052 </head><body>";
2053
2054 $tid = sprintf("%d", $_GET["tid"]);
2055
2056 /* FIXME this badly needs real implementation */
2057
2058 print "<div class='helpResponse'>";
2059
2060 ?>
2061
2062 <h1>Help for SQL expressions</h1>
2063
2064 <h2>Description</h2>
2065
2066 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
d1f948d1 2067 view feed query. You can match on ttrss_entries table fields
7dc66a61
AD
2068 and even use subselect to query additional information. This
2069 functionality is considered to be advanced and requires basic
2070 understanding of SQL.</p>
2071
2072 <h2>Examples</h2>
2073
2074 <pre>unread = true</pre>
2075
2076 Matches all unread articles
2077
2078 <pre>title like '%Linux%'</pre>
2079
2080 Matches all articles which mention Linux in the title. You get the idea.
2081
2082 <p>See the database schema included in the distribution package for gruesome
2083 details.</p>
2084
2085 <?
2086
2087 print "<div align='center'>
2088 <a class=\"helpLink\"
2089 href=\"javascript:window.close()\">(Close this window)</a></div>";
2090
2091 print "</div>";
2092
2093 print "</body></html>";
2094
2095 }
2096
f84a97a3
AD
2097 if ($op == "dlg") {
2098 $id = $_GET["id"];
6de5d056 2099 $param = $_GET["param"];
f84a97a3
AD
2100
2101 if ($id == "quickAddFeed") {
033e47e0
AD
2102 print "Feed URL: <input
2103 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2104 id=\"qafInput\">
f84a97a3
AD
2105 <input class=\"button\"
2106 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2107 <input class=\"button\"
2108 type=\"submit\" onclick=\"javascript:closeDlg()\"
2109 value=\"Cancel\">";
2110 }
6de5d056
AD
2111
2112 if ($id == "quickDelFeed") {
2113
2114 $param = db_escape_string($param);
2115
2116 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2117
2118 if ($result) {
2119
2120 $f_title = db_fetch_result($result, 0, "title");
2121
2122 print "Remove current feed ($f_title)?&nbsp;
2123 <input class=\"button\"
2124 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2125 <input class=\"button\"
2126 type=\"submit\" onclick=\"javascript:closeDlg()\"
2127 value=\"Cancel\">";
2128 } else {
2129 print "Error: Feed $param not found.&nbsp;
2130 <input class=\"button\"
2131 type=\"submit\" onclick=\"javascript:closeDlg()\"
2132 value=\"Cancel\">";
2133 }
2134 }
2135
033e47e0
AD
2136 if ($id == "search") {
2137
2138 print "<input id=\"searchbox\" class=\"extSearch\"
2139 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2140 onchange=\"javascript:search()\">
2141 <select id=\"searchmodebox\">
2142 <option selected>All feeds</option>
2143 <option>This feed</option>
2144 </select>
2145 <input type=\"submit\"
2146 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2147 <input class=\"button\"
2148 type=\"submit\" onclick=\"javascript:closeDlg()\"
2149 value=\"Close\">";
2150
2151 }
2152
f84a97a3
AD
2153 }
2154
a2770077
AD
2155 // update feeds of all users, may be used anonymously
2156 if ($op == "globalUpdateFeeds") {
2157
2158 $result = db_query($link, "SELECT id FROM ttrss_users");
2159
2160 while ($line = db_fetch_assoc($result)) {
2161 $user_id = $line["id"];
2162// print "<!-- updating feeds of uid $user_id -->";
2163 update_all_feeds($link, false, $user_id);
2164 }
e65af9c1 2165
a2770077
AD
2166 print "<rpc-reply>
2167 <message msg=\"All feeds updated\"/>
2168 </rpc-reply>";
e65af9c1
AD
2169
2170 }
2171
77e96719
AD
2172 if ($op == "pref-prefs") {
2173
b1895692 2174 $subop = $_REQUEST["subop"];
77e96719
AD
2175
2176 if ($subop == "Save configuration") {
2177
d2892032
AD
2178 if (WEB_DEMO_MODE) {
2179 header("Location: prefs.php");
2180 return;
2181 }
01d68cf9 2182
93cb4442
AD
2183 $_SESSION["prefs_op_result"] = "save-config";
2184
77e96719
AD
2185 foreach (array_keys($_POST) as $pref_name) {
2186
2187 $pref_name = db_escape_string($pref_name);
2188 $value = db_escape_string($_POST[$pref_name]);
2189
2190 $result = db_query($link, "SELECT type_name
2191 FROM ttrss_prefs,ttrss_prefs_types
2192 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2193
2194 if (db_num_rows($result) > 0) {
2195
2196 $type_name = db_fetch_result($result, 0, "type_name");
2197
5da169d9
AD
2198// print "$pref_name : $type_name : $value<br>";
2199
77e96719 2200 if ($type_name == "bool") {
5da169d9 2201 if ($value == "1") {
77e96719
AD
2202 $value = "true";
2203 } else {
2204 $value = "false";
2205 }
2206 } else if ($type_name == "integer") {
2207 $value = sprintf("%d", $value);
2208 }
2209
2210// print "$pref_name : $type_name : $value<br>";
2211
ff485f1d
AD
2212 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2213 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
2214
2215 }
2216
2217 header("Location: prefs.php");
2218
2219 }
2220
b1895692
AD
2221 } else if ($subop == "getHelp") {
2222
2223 $pref_name = db_escape_string($_GET["pn"]);
2224
2225 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2226 WHERE pref_name = '$pref_name'");
2227
2228 if (db_num_rows($result) > 0) {
2229 $help_text = db_fetch_result($result, 0, "help_text");
2230 print $help_text;
2231 } else {
2232 print "Unknown option: $pref_name";
2233 }
2234
1c7f75ed
AD
2235 } else if ($subop == "Change password") {
2236
d2892032
AD
2237 if (WEB_DEMO_MODE) {
2238 header("Location: prefs.php");
2239 return;
2240 }
1c7f75ed
AD
2241
2242 $old_pw = $_POST["OLD_PASSWORD"];
2243 $new_pw = $_POST["OLD_PASSWORD"];
2244
2245 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2246 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2247
2248 $active_uid = $_SESSION["uid"];
2249
2250 if ($old_pw && $new_pw) {
2251
2252 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2253
2254 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2255 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2256 pwd_hash = '$old_pw_hash')");
2257
2258 if (db_num_rows($result) == 1) {
2259 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2260 WHERE id = '$active_uid'");
b791095d
AD
2261
2262 $_SESSION["pwd_change_result"] = "ok";
2263 } else {
2264 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
2265 }
2266 }
2267
2268 header("Location: prefs.php");
b791095d 2269
77e96719
AD
2270 } else if ($subop == "Reset to defaults") {
2271
d2892032
AD
2272 if (WEB_DEMO_MODE) {
2273 header("Location: prefs.php");
2274 return;
2275 }
01d68cf9 2276
93cb4442
AD
2277 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2278
e1aa0559
AD
2279 if (DB_TYPE == "pgsql") {
2280 db_query($link,"UPDATE ttrss_user_prefs
2281 SET value = ttrss_prefs.def_value
2282 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2283 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2284 } else {
2285 db_query($link, "DELETE FROM ttrss_user_prefs
2286 WHERE owner_uid = ".$_SESSION["uid"]);
2287 initialize_user_prefs($link, $_SESSION["uid"]);
2288 }
5da169d9 2289
77e96719
AD
2290 header("Location: prefs.php");
2291
58f8ad54
AD
2292 } else if ($subop == "Change theme") {
2293
2294 $theme = db_escape_string($_POST["theme"]);
2295
2296 if ($theme == "Default") {
2297 $theme_qpart = 'NULL';
2298 } else {
2299 $theme_qpart = "'$theme'";
2300 }
2301
6752e330
AD
2302 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2303 WHERE theme_name = '$theme'");
2304
2305 if (db_num_rows($result) == 1) {
2306 $theme_id = db_fetch_result($result, 0, "id");
2307 $theme_path = db_fetch_result($result, 0, "theme_path");
2308 } else {
2309 $theme_id = "NULL";
2310 $theme_path = "";
2311 }
2312
58f8ad54 2313 db_query($link, "UPDATE ttrss_users SET
6752e330 2314 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 2315
6752e330 2316 $_SESSION["theme"] = $theme_path;
503eb349 2317
58f8ad54
AD
2318 header("Location: prefs.php");
2319
77e96719
AD
2320 } else {
2321
7d4c898a 2322 if (!SINGLE_USER_MODE) {
1c7f75ed 2323
a029d530
AD
2324 $result = db_query($link, "SELECT id FROM ttrss_users
2325 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2326 pwd_hash = 'SHA1:".sha1("password")."')");
2327
2328 if (db_num_rows($result) != 0) {
b791095d 2329 print "<div class=\"warning\">
a029d530
AD
2330 Your password is at default value, please change it.
2331 </div>";
2332 }
2333
b791095d
AD
2334 if ($_SESSION["pwd_change_result"] == "failed") {
2335 print "<div class=\"warning\">
2336 There was an error while changing your password.
2337 </div>";
2338 }
2339
2340 if ($_SESSION["pwd_change_result"] == "ok") {
2341 print "<div class=\"notice\">
2342 Password changed successfully.
2343 </div>";
2344 }
2345
2346 $_SESSION["pwd_change_result"] = "";
2347
93cb4442
AD
2348 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2349 print "<div class=\"notice\">
2350 Your configuration was reset to defaults.
2351 </div>";
2352 }
2353
2354 if ($_SESSION["prefs_op_result"] == "save-config") {
2355 print "<div class=\"notice\">
2356 Your configuration was saved successfully.
2357 </div>";
2358 }
2359
2360 $_SESSION["prefs_op_result"] = "";
2361
7d4c898a
AD
2362 print "<form action=\"backend.php\" method=\"POST\">";
2363
2364 print "<table width=\"100%\" class=\"prefPrefsList\">";
2365 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2366
2367 print "<tr><td width=\"40%\">Old password</td>";
2368 print "<td><input class=\"editbox\" type=\"password\"
2369 name=\"OLD_PASSWORD\"></td></tr>";
2370
2371 print "<tr><td width=\"40%\">New password</td>";
2372
2373 print "<td><input class=\"editbox\" type=\"password\"
2374 name=\"NEW_PASSWORD\"></td></tr>";
2375
2376 print "</table>";
2377
2378 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2379
2380 print "<p><input class=\"button\" type=\"submit\"
2381 value=\"Change password\" name=\"subop\">";
2382
2383 print "</form>";
1c7f75ed 2384
7d4c898a 2385 }
1c7f75ed 2386
58f8ad54
AD
2387 $result = db_query($link, "SELECT
2388 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2389
2390 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2391
2392 $result = db_query($link, "SELECT
2393 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2394
2395 if (db_num_rows($result) > 0) {
6752e330
AD
2396
2397 print "<form action=\"backend.php\" method=\"POST\">";
2398 print "<table width=\"100%\" class=\"prefPrefsList\">";
2399 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2400 print "<tr><td width=\"40%\">Select theme</td>";
2401 print "<td><select name=\"theme\">";
2402 print "<option>Default</option>";
58f8ad54 2403 print "<option disabled>--------</option>";
6752e330 2404
58f8ad54
AD
2405 while ($line = db_fetch_assoc($result)) {
2406 if ($line["id"] == $user_theme_id) {
2407 $selected = "selected";
2408 } else {
2409 $selected = "";
2410 }
2411 print "<option $selected>" . $line["theme_name"] . "</option>";
2412 }
6752e330
AD
2413 print "</select></td></tr>";
2414 print "</table>";
2415 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2416 print "<p><input class=\"button\" type=\"submit\"
2417 value=\"Change theme\" name=\"subop\">";
2418 print "</form>";
58f8ad54
AD
2419 }
2420
77e96719 2421 $result = db_query($link, "SELECT
ff485f1d 2422 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 2423 section_name,def_value
ff485f1d 2424 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 2425 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 2426 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
2427 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2428 owner_uid = ".$_SESSION["uid"]."
650bc435 2429 ORDER BY section_id,short_desc");
77e96719
AD
2430
2431 print "<form action=\"backend.php\" method=\"POST\">";
2432
77e96719
AD
2433 $lnum = 0;
2434
2435 $active_section = "";
2436
2437 while ($line = db_fetch_assoc($result)) {
2438
2439 if ($active_section != $line["section_name"]) {
59a654ba
AD
2440
2441 if ($active_section != "") {
1c7f75ed 2442 print "</table>";
59a654ba 2443 }
1c7f75ed
AD
2444
2445 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
2446
2447 $active_section = $line["section_name"];
2448
77e96719 2449 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
2450// print "<tr class=\"title\">
2451// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
2452
2453 $lnum = 0;
77e96719
AD
2454 }
2455
650bc435 2456// $class = ($lnum % 2) ? "even" : "odd";
77e96719 2457
650bc435 2458 print "<tr>";
77e96719 2459
77e96719
AD
2460 $type_name = $line["type_name"];
2461 $pref_name = $line["pref_name"];
2462 $value = $line["value"];
2463 $def_value = $line["def_value"];
b1895692
AD
2464 $help_text = $line["help_text"];
2465
2466 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2467
2468 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2469
2470 print "</td>";
77e96719
AD
2471
2472 print "<td>";
2473
2474 if ($type_name == "bool") {
2475// print_select($pref_name, $value, array("true", "false"));
2476
2477 if ($value == "true") {
2478 $value = "Yes";
2479 } else {
2480 $value = "No";
2481 }
2482
2483 print_radio($pref_name, $value, array("Yes", "No"));
2484
2485 } else {
2486 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2487 }
2488
2489 print "</td>";
2490
2491 print "</tr>";
2492
2493 $lnum++;
2494 }
2495
2496 print "</table>";
2497
2498 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2499
2500 print "<p><input class=\"button\" type=\"submit\"
2501 name=\"subop\" value=\"Save configuration\">";
2502
2503 print "&nbsp;<input class=\"button\" type=\"submit\"
2504 name=\"subop\" value=\"Reset to defaults\"></p>";
2505
2506 print "</form>";
2507
2508 }
2509
2510 }
2511
e6cb77a0
AD
2512 if ($op == "pref-users") {
2513
2514 $subop = $_GET["subop"];
2515
2516 if ($subop == "editSave") {
2517
2518 if (!WEB_DEMO_MODE) {
2519
2520 $login = db_escape_string($_GET["l"]);
2521 $uid = db_escape_string($_GET["id"]);
2522 $access_level = sprintf("%d", $_GET["al"]);
2523
2524 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2525
2526 }
2527 } else if ($subop == "remove") {
2528
2529 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2530
2531 $ids = split(",", $_GET["ids"]);
2532
2533 foreach ($ids as $id) {
2534 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2535
2536 }
2537 }
2538 } else if ($subop == "add") {
2539
2540 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2541
b6b535ca 2542 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0
AD
2543 $tmp_user_pwd = make_password(8);
2544 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2545
2546 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2547 VALUES ('$login', '$pwd_hash', 0)");
2548
2549
2550 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2551 login = '$login' AND pwd_hash = '$pwd_hash'");
2552
2553 if (db_num_rows($result) == 1) {
2554
2555 $new_uid = db_fetch_result($result, 0, "id");
2556
2557 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2558 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2559
2560 initialize_user($link, $new_uid);
2561
2562 } else {
2563
2564 print "<div class=\"warning\">Error while adding user <b>".
2565 $_GET["login"].".</b></div>";
2566
2567 }
2568 }
2569 } else if ($subop == "resetPass") {
2570
2571 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2572
2573 $uid = db_escape_string($_GET["id"]);
2574
2575 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2576
2577 $login = db_fetch_result($result, 0, "login");
2578 $tmp_user_pwd = make_password(8);
2579 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2580
2581 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2582 WHERE id = '$uid'");
2583
2584 print "<div class=\"notice\">Changed password of
2585 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2586
2587 }
2588 }
2589
2c7070b5
AD
2590 print "<div class=\"prefGenericAddBox\">
2591 <input id=\"uadd_box\" size=\"40\">&nbsp;";
e6cb77a0 2592
2c7070b5
AD
2593 print"<input type=\"submit\" class=\"button\"
2594 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
e6cb77a0
AD
2595
2596 $result = db_query($link, "SELECT
fe99ab12
AD
2597 id,login,access_level,
2598 SUBSTRING(last_login,1,16) as last_login
e6cb77a0
AD
2599 FROM
2600 ttrss_users
2601 ORDER by login");
2602
2317ffaa 2603 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1a7572cb 2604
e6cb77a0
AD
2605 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
2606
35f3c923
AD
2607 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2608 Select:
2609 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 2610 'UMRR-', 'UMCHK-', true)\">All</a>,
35f3c923 2611 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 2612 'UMRR-', 'UMCHK-', false)\">None</a>
35f3c923
AD
2613 </td</tr>";
2614
e6cb77a0 2615 print "<tr class=\"title\">
f6f32198
AD
2616 <td width=\"5%\">Select</td>
2617 <td width='30%'>Username</td>
2618 <td width='30%'>Access Level</td>
2619 <td width='30%'>Last login</td></tr>";
e6cb77a0
AD
2620
2621 $lnum = 0;
2622
2623 while ($line = db_fetch_assoc($result)) {
2624
2625 $class = ($lnum % 2) ? "even" : "odd";
2626
2627 $uid = $line["id"];
2628 $edit_uid = $_GET["id"];
2629
2630 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
2631 $class .= "Grayed";
53226edc
AD
2632 $this_row_id = "";
2633 } else {
2634 $this_row_id = "id=\"UMRR-$uid\"";
2635 }
2636
2637 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
2638
2639 $line["login"] = htmlspecialchars($line["login"]);
2640
2641 if ($uid == $_SESSION["uid"]) {
2642
2643 print "<td><input disabled=\"true\" type=\"checkbox\"
2644 id=\"UMCHK-".$line["id"]."\"></td>";
2645
2646 print "<td>".$line["login"]."</td>";
2647 print "<td>".$line["access_level"]."</td>";
e6cb77a0
AD
2648
2649 } else if (!$edit_uid || $subop != "edit") {
2650
2651 print "<td><input onclick='toggleSelectRow(this);'
1a7572cb 2652 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
2653
2654 print "<td><a href=\"javascript:editUser($uid);\">" .
2655 $line["login"] . "</td>";
2656
2657 print "<td><a href=\"javascript:editUser($uid);\">" .
2658 $line["access_level"] . "</td>";
2659
2660 } else if ($uid != $edit_uid) {
2661
2662 print "<td><input disabled=\"true\" type=\"checkbox\"
2663 id=\"UMCHK-".$line["id"]."\"></td>";
2664
2665 print "<td>".$line["login"]."</td>";
2666 print "<td>".$line["access_level"]."</td>";
2667
2668 } else {
2669
2670 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2671
2672 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2673 "\"></td>";
2674
2675 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2676 "\"></td>";
2677
2678 }
2679
f6f32198
AD
2680 print "<td>".$line["last_login"]."</td>";
2681
e6cb77a0
AD
2682 print "</tr>";
2683
2684 ++$lnum;
2685 }
2686
2687 print "</table>";
2688
2689 print "<p>";
2690
2691 if ($subop == "edit") {
2692 print "Edit label:
2693 <input type=\"submit\" class=\"button\"
2694 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2695 <input type=\"submit\" class=\"button\"
2696 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2697
2698 } else {
2699
2700 print "
2701 Selection:
2702 <input type=\"submit\" class=\"button\"
717f5e64 2703 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
e6cb77a0
AD
2704 <input type=\"submit\" class=\"button\"
2705 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2706 <input type=\"submit\" class=\"button\"
717f5e64
AD
2707 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2708 <input type=\"submit\" class=\"button\"
2709 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2710
2711 }
2712 }
2713
2714 if ($op == "user-details") {
2715
2716 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2717 return;
2718 }
2719
1a7572cb 2720/* print "<html><head>
717f5e64
AD
2721 <title>Tiny Tiny RSS : User Details</title>
2722 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2723 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 2724 </head><body>"; */
717f5e64
AD
2725
2726 $uid = sprintf("%d", $_GET["id"]);
2727
c6c3a07f 2728 print "<div class='infoBoxContents'>";
717f5e64 2729
fe99ab12
AD
2730 $result = db_query($link, "SELECT login,
2731 SUBSTRING(last_login,1,16) AS last_login,
2732 access_level,
c6c3a07f
AD
2733 (SELECT COUNT(int_id) FROM ttrss_user_entries
2734 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
2735 FROM ttrss_users
2736 WHERE id = '$uid'");
2737
2738 if (db_num_rows($result) == 0) {
2739 print "<h1>User not found</h1>";
2740 return;
2741 }
2742
2743 print "<h1>User Details</h1>";
2744
2745 print "<table width='100%'>";
2746
2747 $login = db_fetch_result($result, 0, "login");
2748 $last_login = db_fetch_result($result, 0, "last_login");
2749 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 2750 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64
AD
2751
2752 print "<tr><td>Username</td><td>$login</td></tr>";
2753 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2754 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 2755 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
2756
2757 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2758 WHERE owner_uid = '$uid'");
2759
2760 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2761
2762 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2763
5d15d3ea 2764/* $result = db_query($link, "SELECT
717f5e64 2765 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
2766 FROM ttrss_user_entries,ttrss_entries
2767 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 2768
d9f115c3 2769 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 2770
c6c3a07f 2771 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
2772
2773 print "</table>";
2774
2775 print "<h1>Subscribed feeds</h1>";
2776
2777 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
d9f115c3 2778 WHERE owner_uid = '$uid' ORDER BY title");
717f5e64
AD
2779
2780 print "<ul class=\"nomarks\">";
2781
2782 while ($line = db_fetch_assoc($result)) {
2783
2784 $icon_file = ICONS_URL."/".$line["id"].".ico";
2785
2786 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 2787 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 2788 } else {
5951ded1 2789 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
2790 }
2791
2792 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
e6cb77a0 2793 }
717f5e64
AD
2794
2795 print "</ul>";
2796
717f5e64
AD
2797 print "</div>";
2798
1a7572cb
AD
2799 print "<div align='center'>
2800 <input type='submit' class='button'
c6c3a07f 2801 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
2802
2803// print "</body></html>";
717f5e64 2804
e6cb77a0
AD
2805 }
2806
c6c3a07f
AD
2807 if ($op == "feed-details") {
2808
2809 $feed_id = $_GET["id"];
2810
2811 $result = db_query($link,
2812 "SELECT
f324892e 2813 title,feed_url,last_updated,icon_url,site_url,
c6c3a07f
AD
2814 (SELECT COUNT(int_id) FROM ttrss_user_entries
2815 WHERE feed_id = id) AS total,
2816 (SELECT COUNT(int_id) FROM ttrss_user_entries
2817 WHERE feed_id = id AND unread = true) AS unread,
2818 (SELECT COUNT(int_id) FROM ttrss_user_entries
2819 WHERE feed_id = id AND marked = true) AS marked
2820 FROM ttrss_feeds
2821 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2822
2823 if (db_num_rows($result) == 0) return;
2824
2825 $title = db_fetch_result($result, 0, "title");
2826 $last_updated = db_fetch_result($result, 0, "last_updated");
2827 $feed_url = db_fetch_result($result, 0, "feed_url");
4fec9fd7 2828 $icon_url = db_fetch_result($result, 0, "icon_url");
c6c3a07f
AD
2829 $total = db_fetch_result($result, 0, "total");
2830 $unread = db_fetch_result($result, 0, "unread");
2831 $marked = db_fetch_result($result, 0, "marked");
f324892e 2832 $site_url = db_fetch_result($result, 0, "site_url");
4fec9fd7
AD
2833
2834 $result = db_query($link, "SELECT COUNT(id) AS subscribed
2835 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
2836
2837 $subscribed = db_fetch_result($result, 0, "subscribed");
2838
2839 print "<div class=\"infoBoxContents\">";
2840
2841 $icon_file = ICONS_DIR . "/$feed_id.ico";
2842
2843 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2844 $feed_icon = "<img width=\"16\" height=\"16\"
2845 src=\"" . ICONS_URL . "/$feed_id.ico\">";
2846 } else {
2847 $feed_icon = "";
2848 }
2849
2850 print "<h1>$feed_icon $title</h1>";
c6c3a07f
AD
2851
2852 print "<table width='100%'>";
2853
f324892e
AD
2854 if ($site_url) {
2855 print "<tr><td width='30%'>Link</td>
2856 <td><a href=\"$site_url\">$site_url</a>
2857 <a href=\"$feed_url\">(feed)</a></td>
2858 </td></tr>";
2859 } else {
2860 print "<tr><td width='30%'>Feed URL</td>
2861 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
2862 }
c6c3a07f
AD
2863 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
2864 print "<tr><td>Total articles</td><td>$total</td></tr>";
2865 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
2866 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
4fec9fd7 2867 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
c6c3a07f
AD
2868
2869 print "</table>";
2870
bffdddd0
AD
2871 $result = db_query($link, "SELECT title,
2872 SUBSTRING(updated,1,16) AS updated,unread
bca02305
AD
2873 FROM ttrss_entries,ttrss_user_entries
2874 WHERE ref_id = id AND feed_id = '$feed_id'
c565e1ef 2875 ORDER BY date_entered DESC LIMIT 5");
c6c3a07f 2876
bca02305
AD
2877 if (db_num_rows($result) > 0) {
2878
2879 print "<h1>Latest headlines</h1>";
c6c3a07f 2880
bca02305
AD
2881 print "<ul class=\"nomarks\">";
2882
2883 while ($line = db_fetch_assoc($result)) {
c565e1ef
AD
2884 if ($line["unread"] == "t" || $line["unread"] == "1") {
2885 $line["title"] = "<b>" . $line["title"] . "</b>";
2886 }
bca02305
AD
2887 print "<li>" . $line["title"].
2888 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
2889 }
2890
2891 print "</ul>";
2892
2893 print "</div>";
2894
2895 print "<div align='center'>
2896 <input type='submit' class='button'
2897 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2898 }
c6c3a07f
AD
2899 }
2900
4b3dff6e 2901 db_close($link);
1cd17194 2902?>
406d9489
AD
2903
2904<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
2905