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