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