]> git.wh0rd.org - tt-rss.git/blame - backend.php
label help uses infoboxes, real help system
[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
01c9c74a 1942 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
3b0feb9b
AD
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 2046 if ($op == "help") {
01c9c74a
AD
2047 if (!$_GET["noheaders"]) {
2048 print "<html><head>
2049 <title>Tiny Tiny RSS : Help</title>
2050 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2051 <script type=\"text/javascript\" src=\"functions.js\"></script>
2052 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2053 </head><body>";
2054 }
7dc66a61
AD
2055
2056 $tid = sprintf("%d", $_GET["tid"]);
2057
01c9c74a 2058 print "<div class='infoBoxContents'>";
7dc66a61 2059
01c9c74a
AD
2060 if (file_exists("help/$tid.php")) {
2061 include("help/$tid.php");
2062 } else {
2063 print "<p>Help topic not found.</p>";
2064 }
7dc66a61 2065
01c9c74a 2066 print "</div>";
7dc66a61
AD
2067
2068 print "<div align='center'>
01c9c74a
AD
2069 <input type='submit' class='button'
2070 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
7dc66a61 2071
01c9c74a
AD
2072 if (!$_GET["noheaders"]) {
2073 print "</body></html>";
2074 }
7dc66a61
AD
2075
2076 }
2077
f84a97a3
AD
2078 if ($op == "dlg") {
2079 $id = $_GET["id"];
6de5d056 2080 $param = $_GET["param"];
f84a97a3
AD
2081
2082 if ($id == "quickAddFeed") {
76332f3c
AD
2083 print "
2084 Feed URL: <input
033e47e0
AD
2085 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2086 id=\"qafInput\">
f84a97a3
AD
2087 <input class=\"button\"
2088 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2089 <input class=\"button\"
2090 type=\"submit\" onclick=\"javascript:closeDlg()\"
2091 value=\"Cancel\">";
2092 }
6de5d056
AD
2093
2094 if ($id == "quickDelFeed") {
2095
2096 $param = db_escape_string($param);
2097
2098 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2099
2100 if ($result) {
2101
2102 $f_title = db_fetch_result($result, 0, "title");
2103
76332f3c 2104 print "Remove current feed (<b>$f_title</b>)?&nbsp;
6de5d056
AD
2105 <input class=\"button\"
2106 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2107 <input class=\"button\"
2108 type=\"submit\" onclick=\"javascript:closeDlg()\"
2109 value=\"Cancel\">";
2110 } else {
2111 print "Error: Feed $param not found.&nbsp;
2112 <input class=\"button\"
2113 type=\"submit\" onclick=\"javascript:closeDlg()\"
2114 value=\"Cancel\">";
2115 }
2116 }
2117
033e47e0
AD
2118 if ($id == "search") {
2119
2120 print "<input id=\"searchbox\" class=\"extSearch\"
2121 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2122 onchange=\"javascript:search()\">
2123 <select id=\"searchmodebox\">
2124 <option selected>All feeds</option>
2125 <option>This feed</option>
2126 </select>
2127 <input type=\"submit\"
2128 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2129 <input class=\"button\"
2130 type=\"submit\" onclick=\"javascript:closeDlg()\"
2131 value=\"Close\">";
2132
2133 }
2134
f84a97a3
AD
2135 }
2136
a2770077
AD
2137 // update feeds of all users, may be used anonymously
2138 if ($op == "globalUpdateFeeds") {
2139
2140 $result = db_query($link, "SELECT id FROM ttrss_users");
2141
2142 while ($line = db_fetch_assoc($result)) {
2143 $user_id = $line["id"];
2144// print "<!-- updating feeds of uid $user_id -->";
2145 update_all_feeds($link, false, $user_id);
2146 }
e65af9c1 2147
a2770077
AD
2148 print "<rpc-reply>
2149 <message msg=\"All feeds updated\"/>
2150 </rpc-reply>";
e65af9c1
AD
2151
2152 }
2153
77e96719
AD
2154 if ($op == "pref-prefs") {
2155
b1895692 2156 $subop = $_REQUEST["subop"];
77e96719
AD
2157
2158 if ($subop == "Save configuration") {
2159
d2892032
AD
2160 if (WEB_DEMO_MODE) {
2161 header("Location: prefs.php");
2162 return;
2163 }
01d68cf9 2164
93cb4442
AD
2165 $_SESSION["prefs_op_result"] = "save-config";
2166
77e96719
AD
2167 foreach (array_keys($_POST) as $pref_name) {
2168
2169 $pref_name = db_escape_string($pref_name);
2170 $value = db_escape_string($_POST[$pref_name]);
2171
2172 $result = db_query($link, "SELECT type_name
2173 FROM ttrss_prefs,ttrss_prefs_types
2174 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2175
2176 if (db_num_rows($result) > 0) {
2177
2178 $type_name = db_fetch_result($result, 0, "type_name");
2179
5da169d9
AD
2180// print "$pref_name : $type_name : $value<br>";
2181
77e96719 2182 if ($type_name == "bool") {
5da169d9 2183 if ($value == "1") {
77e96719
AD
2184 $value = "true";
2185 } else {
2186 $value = "false";
2187 }
2188 } else if ($type_name == "integer") {
2189 $value = sprintf("%d", $value);
2190 }
2191
2192// print "$pref_name : $type_name : $value<br>";
2193
ff485f1d
AD
2194 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2195 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
2196
2197 }
2198
2199 header("Location: prefs.php");
2200
2201 }
2202
b1895692
AD
2203 } else if ($subop == "getHelp") {
2204
2205 $pref_name = db_escape_string($_GET["pn"]);
2206
2207 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2208 WHERE pref_name = '$pref_name'");
2209
2210 if (db_num_rows($result) > 0) {
2211 $help_text = db_fetch_result($result, 0, "help_text");
2212 print $help_text;
2213 } else {
2214 print "Unknown option: $pref_name";
2215 }
2216
1c7f75ed
AD
2217 } else if ($subop == "Change password") {
2218
d2892032
AD
2219 if (WEB_DEMO_MODE) {
2220 header("Location: prefs.php");
2221 return;
2222 }
1c7f75ed
AD
2223
2224 $old_pw = $_POST["OLD_PASSWORD"];
2225 $new_pw = $_POST["OLD_PASSWORD"];
2226
2227 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2228 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2229
2230 $active_uid = $_SESSION["uid"];
2231
2232 if ($old_pw && $new_pw) {
2233
2234 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2235
2236 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2237 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2238 pwd_hash = '$old_pw_hash')");
2239
2240 if (db_num_rows($result) == 1) {
2241 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2242 WHERE id = '$active_uid'");
b791095d
AD
2243
2244 $_SESSION["pwd_change_result"] = "ok";
2245 } else {
2246 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
2247 }
2248 }
2249
2250 header("Location: prefs.php");
b791095d 2251
77e96719
AD
2252 } else if ($subop == "Reset to defaults") {
2253
d2892032
AD
2254 if (WEB_DEMO_MODE) {
2255 header("Location: prefs.php");
2256 return;
2257 }
01d68cf9 2258
93cb4442
AD
2259 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2260
e1aa0559
AD
2261 if (DB_TYPE == "pgsql") {
2262 db_query($link,"UPDATE ttrss_user_prefs
2263 SET value = ttrss_prefs.def_value
2264 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2265 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2266 } else {
2267 db_query($link, "DELETE FROM ttrss_user_prefs
2268 WHERE owner_uid = ".$_SESSION["uid"]);
2269 initialize_user_prefs($link, $_SESSION["uid"]);
2270 }
5da169d9 2271
77e96719
AD
2272 header("Location: prefs.php");
2273
58f8ad54
AD
2274 } else if ($subop == "Change theme") {
2275
2276 $theme = db_escape_string($_POST["theme"]);
2277
2278 if ($theme == "Default") {
2279 $theme_qpart = 'NULL';
2280 } else {
2281 $theme_qpart = "'$theme'";
2282 }
2283
6752e330
AD
2284 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2285 WHERE theme_name = '$theme'");
2286
2287 if (db_num_rows($result) == 1) {
2288 $theme_id = db_fetch_result($result, 0, "id");
2289 $theme_path = db_fetch_result($result, 0, "theme_path");
2290 } else {
2291 $theme_id = "NULL";
2292 $theme_path = "";
2293 }
2294
58f8ad54 2295 db_query($link, "UPDATE ttrss_users SET
6752e330 2296 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 2297
6752e330 2298 $_SESSION["theme"] = $theme_path;
503eb349 2299
58f8ad54
AD
2300 header("Location: prefs.php");
2301
77e96719
AD
2302 } else {
2303
7d4c898a 2304 if (!SINGLE_USER_MODE) {
1c7f75ed 2305
a029d530
AD
2306 $result = db_query($link, "SELECT id FROM ttrss_users
2307 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2308 pwd_hash = 'SHA1:".sha1("password")."')");
2309
2310 if (db_num_rows($result) != 0) {
b791095d 2311 print "<div class=\"warning\">
a029d530
AD
2312 Your password is at default value, please change it.
2313 </div>";
2314 }
2315
b791095d
AD
2316 if ($_SESSION["pwd_change_result"] == "failed") {
2317 print "<div class=\"warning\">
2318 There was an error while changing your password.
2319 </div>";
2320 }
2321
2322 if ($_SESSION["pwd_change_result"] == "ok") {
2323 print "<div class=\"notice\">
2324 Password changed successfully.
2325 </div>";
2326 }
2327
2328 $_SESSION["pwd_change_result"] = "";
2329
93cb4442
AD
2330 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2331 print "<div class=\"notice\">
2332 Your configuration was reset to defaults.
2333 </div>";
2334 }
2335
2336 if ($_SESSION["prefs_op_result"] == "save-config") {
2337 print "<div class=\"notice\">
2338 Your configuration was saved successfully.
2339 </div>";
2340 }
2341
2342 $_SESSION["prefs_op_result"] = "";
2343
7d4c898a
AD
2344 print "<form action=\"backend.php\" method=\"POST\">";
2345
2346 print "<table width=\"100%\" class=\"prefPrefsList\">";
2347 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2348
2349 print "<tr><td width=\"40%\">Old password</td>";
2350 print "<td><input class=\"editbox\" type=\"password\"
2351 name=\"OLD_PASSWORD\"></td></tr>";
2352
2353 print "<tr><td width=\"40%\">New password</td>";
2354
2355 print "<td><input class=\"editbox\" type=\"password\"
2356 name=\"NEW_PASSWORD\"></td></tr>";
2357
2358 print "</table>";
2359
2360 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2361
2362 print "<p><input class=\"button\" type=\"submit\"
2363 value=\"Change password\" name=\"subop\">";
2364
2365 print "</form>";
1c7f75ed 2366
7d4c898a 2367 }
1c7f75ed 2368
58f8ad54
AD
2369 $result = db_query($link, "SELECT
2370 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2371
2372 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2373
2374 $result = db_query($link, "SELECT
2375 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2376
2377 if (db_num_rows($result) > 0) {
6752e330
AD
2378
2379 print "<form action=\"backend.php\" method=\"POST\">";
2380 print "<table width=\"100%\" class=\"prefPrefsList\">";
2381 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2382 print "<tr><td width=\"40%\">Select theme</td>";
2383 print "<td><select name=\"theme\">";
2384 print "<option>Default</option>";
58f8ad54 2385 print "<option disabled>--------</option>";
6752e330 2386
58f8ad54
AD
2387 while ($line = db_fetch_assoc($result)) {
2388 if ($line["id"] == $user_theme_id) {
2389 $selected = "selected";
2390 } else {
2391 $selected = "";
2392 }
2393 print "<option $selected>" . $line["theme_name"] . "</option>";
2394 }
6752e330
AD
2395 print "</select></td></tr>";
2396 print "</table>";
2397 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2398 print "<p><input class=\"button\" type=\"submit\"
2399 value=\"Change theme\" name=\"subop\">";
2400 print "</form>";
58f8ad54
AD
2401 }
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";
53226edc
AD
2614 $this_row_id = "";
2615 } else {
2616 $this_row_id = "id=\"UMRR-$uid\"";
2617 }
2618
2619 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
2620
2621 $line["login"] = htmlspecialchars($line["login"]);
2622
2623 if ($uid == $_SESSION["uid"]) {
2624
2625 print "<td><input disabled=\"true\" type=\"checkbox\"
2626 id=\"UMCHK-".$line["id"]."\"></td>";
2627
2628 print "<td>".$line["login"]."</td>";
2629 print "<td>".$line["access_level"]."</td>";
e6cb77a0
AD
2630
2631 } else if (!$edit_uid || $subop != "edit") {
2632
2633 print "<td><input onclick='toggleSelectRow(this);'
1a7572cb 2634 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
2635
2636 print "<td><a href=\"javascript:editUser($uid);\">" .
2637 $line["login"] . "</td>";
2638
2639 print "<td><a href=\"javascript:editUser($uid);\">" .
2640 $line["access_level"] . "</td>";
2641
2642 } else if ($uid != $edit_uid) {
2643
2644 print "<td><input disabled=\"true\" type=\"checkbox\"
2645 id=\"UMCHK-".$line["id"]."\"></td>";
2646
2647 print "<td>".$line["login"]."</td>";
2648 print "<td>".$line["access_level"]."</td>";
2649
2650 } else {
2651
2652 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2653
2654 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2655 "\"></td>";
2656
2657 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2658 "\"></td>";
2659
2660 }
2661
f6f32198
AD
2662 print "<td>".$line["last_login"]."</td>";
2663
e6cb77a0
AD
2664 print "</tr>";
2665
2666 ++$lnum;
2667 }
2668
2669 print "</table>";
2670
2671 print "<p>";
2672
2673 if ($subop == "edit") {
2674 print "Edit label:
2675 <input type=\"submit\" class=\"button\"
2676 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2677 <input type=\"submit\" class=\"button\"
2678 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2679
2680 } else {
2681
2682 print "
2683 Selection:
2684 <input type=\"submit\" class=\"button\"
717f5e64 2685 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
e6cb77a0
AD
2686 <input type=\"submit\" class=\"button\"
2687 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2688 <input type=\"submit\" class=\"button\"
717f5e64
AD
2689 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2690 <input type=\"submit\" class=\"button\"
2691 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2692
2693 }
2694 }
2695
2696 if ($op == "user-details") {
2697
2698 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2699 return;
2700 }
2701
1a7572cb 2702/* print "<html><head>
717f5e64
AD
2703 <title>Tiny Tiny RSS : User Details</title>
2704 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2705 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 2706 </head><body>"; */
717f5e64
AD
2707
2708 $uid = sprintf("%d", $_GET["id"]);
2709
c6c3a07f 2710 print "<div class='infoBoxContents'>";
717f5e64 2711
fe99ab12
AD
2712 $result = db_query($link, "SELECT login,
2713 SUBSTRING(last_login,1,16) AS last_login,
2714 access_level,
c6c3a07f
AD
2715 (SELECT COUNT(int_id) FROM ttrss_user_entries
2716 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
2717 FROM ttrss_users
2718 WHERE id = '$uid'");
2719
2720 if (db_num_rows($result) == 0) {
2721 print "<h1>User not found</h1>";
2722 return;
2723 }
2724
2725 print "<h1>User Details</h1>";
2726
2727 print "<table width='100%'>";
2728
2729 $login = db_fetch_result($result, 0, "login");
2730 $last_login = db_fetch_result($result, 0, "last_login");
2731 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 2732 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64
AD
2733
2734 print "<tr><td>Username</td><td>$login</td></tr>";
2735 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2736 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 2737 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
2738
2739 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2740 WHERE owner_uid = '$uid'");
2741
2742 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2743
2744 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2745
5d15d3ea 2746/* $result = db_query($link, "SELECT
717f5e64 2747 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
2748 FROM ttrss_user_entries,ttrss_entries
2749 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 2750
d9f115c3 2751 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 2752
c6c3a07f 2753 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
2754
2755 print "</table>";
2756
2757 print "<h1>Subscribed feeds</h1>";
2758
2759 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
d9f115c3 2760 WHERE owner_uid = '$uid' ORDER BY title");
717f5e64
AD
2761
2762 print "<ul class=\"nomarks\">";
2763
2764 while ($line = db_fetch_assoc($result)) {
2765
2766 $icon_file = ICONS_URL."/".$line["id"].".ico";
2767
2768 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 2769 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 2770 } else {
5951ded1 2771 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
2772 }
2773
2774 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
e6cb77a0 2775 }
717f5e64
AD
2776
2777 print "</ul>";
2778
717f5e64
AD
2779 print "</div>";
2780
1a7572cb
AD
2781 print "<div align='center'>
2782 <input type='submit' class='button'
c6c3a07f 2783 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
2784
2785// print "</body></html>";
717f5e64 2786
e6cb77a0
AD
2787 }
2788
c6c3a07f
AD
2789 if ($op == "feed-details") {
2790
2791 $feed_id = $_GET["id"];
2792
2793 $result = db_query($link,
2794 "SELECT
f324892e 2795 title,feed_url,last_updated,icon_url,site_url,
c6c3a07f
AD
2796 (SELECT COUNT(int_id) FROM ttrss_user_entries
2797 WHERE feed_id = id) AS total,
2798 (SELECT COUNT(int_id) FROM ttrss_user_entries
2799 WHERE feed_id = id AND unread = true) AS unread,
2800 (SELECT COUNT(int_id) FROM ttrss_user_entries
2801 WHERE feed_id = id AND marked = true) AS marked
2802 FROM ttrss_feeds
2803 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2804
2805 if (db_num_rows($result) == 0) return;
2806
2807 $title = db_fetch_result($result, 0, "title");
2808 $last_updated = db_fetch_result($result, 0, "last_updated");
2809 $feed_url = db_fetch_result($result, 0, "feed_url");
4fec9fd7 2810 $icon_url = db_fetch_result($result, 0, "icon_url");
c6c3a07f
AD
2811 $total = db_fetch_result($result, 0, "total");
2812 $unread = db_fetch_result($result, 0, "unread");
2813 $marked = db_fetch_result($result, 0, "marked");
f324892e 2814 $site_url = db_fetch_result($result, 0, "site_url");
4fec9fd7
AD
2815
2816 $result = db_query($link, "SELECT COUNT(id) AS subscribed
2817 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
2818
2819 $subscribed = db_fetch_result($result, 0, "subscribed");
2820
2821 print "<div class=\"infoBoxContents\">";
2822
2823 $icon_file = ICONS_DIR . "/$feed_id.ico";
2824
2825 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2826 $feed_icon = "<img width=\"16\" height=\"16\"
2827 src=\"" . ICONS_URL . "/$feed_id.ico\">";
2828 } else {
2829 $feed_icon = "";
2830 }
2831
2832 print "<h1>$feed_icon $title</h1>";
c6c3a07f
AD
2833
2834 print "<table width='100%'>";
2835
f324892e
AD
2836 if ($site_url) {
2837 print "<tr><td width='30%'>Link</td>
2838 <td><a href=\"$site_url\">$site_url</a>
2839 <a href=\"$feed_url\">(feed)</a></td>
2840 </td></tr>";
2841 } else {
2842 print "<tr><td width='30%'>Feed URL</td>
2843 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
2844 }
c6c3a07f
AD
2845 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
2846 print "<tr><td>Total articles</td><td>$total</td></tr>";
2847 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
2848 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
4fec9fd7 2849 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
c6c3a07f
AD
2850
2851 print "</table>";
2852
bffdddd0
AD
2853 $result = db_query($link, "SELECT title,
2854 SUBSTRING(updated,1,16) AS updated,unread
bca02305
AD
2855 FROM ttrss_entries,ttrss_user_entries
2856 WHERE ref_id = id AND feed_id = '$feed_id'
c565e1ef 2857 ORDER BY date_entered DESC LIMIT 5");
c6c3a07f 2858
bca02305
AD
2859 if (db_num_rows($result) > 0) {
2860
2861 print "<h1>Latest headlines</h1>";
c6c3a07f 2862
bca02305
AD
2863 print "<ul class=\"nomarks\">";
2864
2865 while ($line = db_fetch_assoc($result)) {
c565e1ef
AD
2866 if ($line["unread"] == "t" || $line["unread"] == "1") {
2867 $line["title"] = "<b>" . $line["title"] . "</b>";
2868 }
bca02305
AD
2869 print "<li>" . $line["title"].
2870 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
2871 }
2872
2873 print "</ul>";
2874
2875 print "</div>";
2876
2877 print "<div align='center'>
2878 <input type='submit' class='button'
2879 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2880 }
c6c3a07f
AD
2881 }
2882
4b3dff6e 2883 db_close($link);
1cd17194 2884?>
406d9489
AD
2885
2886<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
2887