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