]> git.wh0rd.org - tt-rss.git/blame - backend.php
selected row was not marked in labellist_callback
[tt-rss.git] / backend.php
CommitLineData
1cd17194 1<?
4356293a 2 session_start();
090e250b 3
1c7f75ed
AD
4 if (!$_SESSION["uid"]) { exit; }
5
4356293a 6 define(SCHEMA_VERSION, 2);
1cd17194 7
82baad4a 8 require_once "config.php";
648472a7 9 require_once "db.php";
3bac89ad 10 require_once "db-prefs.php";
82baad4a
AD
11 require_once "functions.php";
12 require_once "magpierss/rss_fetch.inc";
1cd17194 13
4356293a
AD
14 $op = $_REQUEST["op"];
15
16 if ($op == "rpc" || $op == "updateAllFeeds") {
17 header("Content-Type: application/xml");
18 }
19
406d9489
AD
20 $script_started = getmicrotime();
21
648472a7 22 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
d76a3b03 23
5136011e
AD
24 if (!$link) {
25 if (DB_TYPE == "mysql") {
26 print mysql_error();
27 }
28 // PG seems to display its own errors just fine by default.
29 return;
30 }
31
648472a7
AD
32 if (DB_TYPE == "pgsql") {
33 pg_query("set client_encoding = 'utf-8'");
34 }
7ec2a838 35
295f9b42 36/*
7ec2a838
AD
37 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
38
39 $schema_version = db_fetch_result($result, 0, "schema_version");
40
41 if ($schema_version != SCHEMA_VERSION) {
42 print "Error: database schema is invalid
43 (got version $schema_version; expected ".SCHEMA_VERSION.")";
44 return;
45 }
295f9b42
AD
46*/
47
331900c6 48 $fetch = $_GET["fetch"];
175847de 49
8143ae1f
AD
50 /* FIXME this needs reworking */
51
fc69e641
AD
52 function getGlobalCounters($link) {
53 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
4356293a 54 WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
fc69e641
AD
55 $c_id = db_fetch_result($result, 0, "c_id");
56 print "<counter id='global-unread' counter='$c_id'/>";
57 }
58
8143ae1f
AD
59 function getTagCounters($link) {
60 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
61 FROM ttrss_tags,ttrss_entries WHERE
4356293a 62 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
8143ae1f
AD
63 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
64 UNION
4356293a
AD
65 select tag_name,0 as count FROM ttrss_tags
66 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
8143ae1f
AD
67
68 $tags = array();
69
70 while ($line = db_fetch_assoc($result)) {
71 $tags[$line["tag_name"]] += $line["count"];
72 }
73
74 foreach (array_keys($tags) as $tag) {
75 $unread = $tags[$tag];
76
77 $tag = htmlspecialchars($tag);
78 print "<tag id=\"$tag\" counter=\"$unread\"/>";
79 }
80 }
81
090e250b
AD
82 function getLabelCounters($link) {
83
84 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
4356293a 85 WHERE marked = true AND unread = true AND owner_uid = ".$_SESSION["uid"]);
090e250b 86
d61fd764 87 $count = db_fetch_result($result, 0, "count");
090e250b
AD
88
89 print "<label id=\"-1\" counter=\"$count\"/>";
90
4356293a
AD
91 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
92 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
090e250b
AD
93
94 while ($line = db_fetch_assoc($result)) {
95
96 $id = -$line["id"] - 11;
97
98 error_reporting (0);
d61fd764
AD
99
100 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
655be073
AD
101 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
102 owner_uid = ".$_SESSION["uid"]);
090e250b 103
d61fd764 104 $count = db_fetch_result($tmp_result, 0, "count");
090e250b 105
ab3f3f72 106 print "<label id=\"$id\" counter=\"$count\"/>";
090e250b
AD
107
108 error_reporting (E_ERROR | E_WARNING | E_PARSE);
109
110 }
111 }
112
8073cce7
AD
113 function getFeedCounter($link, $id) {
114
115 $result = db_query($link, "SELECT
116 count(id) as count FROM ttrss_entries
4356293a 117 WHERE feed_id = '$id' AND unread = true");
8073cce7
AD
118
119 $count = db_fetch_result($result, 0, "count");
120
121 print "<feed id=\"$id\" counter=\"$count\"/>";
122 }
090e250b 123
8073cce7
AD
124 function getFeedCounters($link) {
125
090e250b
AD
126 $result = db_query($link, "SELECT id,
127 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
128 AND unread = true) as count
4356293a 129 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
090e250b
AD
130
131 while ($line = db_fetch_assoc($result)) {
132
133 $id = $line["id"];
134 $count = $line["count"];
135
136 print "<feed id=\"$id\" counter=\"$count\"/>";
137 }
138 }
139
8143ae1f 140 function outputFeedList($link, $tags = false) {
175847de 141
1a66d16e
AD
142 print "<html><head>
143 <title>Tiny Tiny RSS : Feedlist</title>
430bf183
AD
144 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
145
4769ddaf 146 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
147 print "<link rel=\"stylesheet\" type=\"text/css\"
148 href=\"tt-rss_compact.css\"/>";
149 } else {
150 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
151 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
152 }
153
154 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
1a66d16e
AD
155 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
156 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3745788e 157 </head><body onload=\"init()\">";
254e0e4b
AD
158
159 print "<ul class=\"feedList\" id=\"feedList\">";
160
4356293a
AD
161 $owner_uid = $_SESSION["uid"];
162
8143ae1f 163 if (!$tags) {
254e0e4b 164
8143ae1f 165 /* virtual feeds */
254e0e4b 166
8143ae1f 167 $result = db_query($link, "SELECT count(id) as num_starred
4356293a 168 FROM ttrss_entries WHERE marked = true AND unread = true AND owner_uid = '$owner_uid'");
8143ae1f 169 $num_starred = db_fetch_result($result, 0, "num_starred");
254e0e4b 170
3745788e 171 $class = "virt";
8add756a
AD
172
173 if ($num_starred > 0) $class .= "Unread";
174
175 printFeedEntry(-1, $class, "Starred articles", $num_starred,
4668523d 176 "images/mark_set.png", $link);
48f0adb0 177
4769ddaf 178 if (get_pref($link, 'ENABLE_LABELS')) {
8143ae1f
AD
179
180 $result = db_query($link, "SELECT id,sql_exp,description FROM
4356293a 181 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
8143ae1f
AD
182
183 if (db_num_rows($result) > 0) {
184 print "<li><hr></li>";
185 }
186
187 while ($line = db_fetch_assoc($result)) {
48f0adb0 188
8143ae1f
AD
189 error_reporting (0);
190
191 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
655be073
AD
192 WHERE (" . $line["sql_exp"] . ") AND unread = true
193 AND owner_uid = '$owner_uid'");
8143ae1f
AD
194
195 $count = db_fetch_result($tmp_result, 0, "count");
196
3745788e 197 $class = "label";
8143ae1f
AD
198
199 if ($count > 0) {
200 $class .= "Unread";
201 }
202
203 error_reporting (E_ERROR | E_WARNING | E_PARSE);
204
205 printFeedEntry(-$line["id"]-11,
4668523d 206 $class, $line["description"], $count, "images/label.png", $link);
8143ae1f
AD
207
208 }
48f0adb0
AD
209 }
210
8143ae1f
AD
211 print "<li><hr></li>";
212
213 $result = db_query($link, "SELECT *,
214 (SELECT count(id) FROM ttrss_entries
215 WHERE feed_id = ttrss_feeds.id) AS total,
216 (SELECT count(id) FROM ttrss_entries
217 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
4356293a 218 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");
8143ae1f
AD
219
220 $actid = $_GET["actid"];
221
222 /* real feeds */
223
224 $lnum = 0;
225
226 $total_unread = 0;
227
48f0adb0 228 while ($line = db_fetch_assoc($result)) {
8143ae1f
AD
229
230 $feed = $line["title"];
231 $feed_id = $line["id"];
232
233 $subop = $_GET["subop"];
234
235 $total = $line["total"];
236 $unread = $line["unread"];
237
238 // $class = ($lnum % 2) ? "even" : "odd";
48f0adb0 239
3745788e 240 $class = "feed";
8143ae1f
AD
241
242 if ($unread > 0) $class .= "Unread";
243
244 if ($actid == $feed_id) {
245 $class .= "Selected";
392d4563 246 }
48f0adb0 247
8143ae1f
AD
248 $total_unread += $unread;
249
4668523d 250 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
8143ae1f
AD
251
252 ++$lnum;
48f0adb0 253 }
8143ae1f 254 } else {
a1a8a2be 255
8143ae1f 256 // tags
a1a8a2be 257
8143ae1f
AD
258 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
259 FROM ttrss_tags,ttrss_entries WHERE
4356293a 260 post_id = ttrss_entries.id AND unread = true
3b0948c4 261 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
8143ae1f 262 UNION
3b0948c4
AD
263 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
264 ORDER BY tag_name");
8143ae1f
AD
265
266 $tags = array();
267
268 while ($line = db_fetch_assoc($result)) {
269 $tags[$line["tag_name"]] += $line["count"];
1a66d16e 270 }
8143ae1f
AD
271
272 foreach (array_keys($tags) as $tag) {
273
274 $unread = $tags[$tag];
275
276 $class = "odd";
277
278 if ($unread > 0) {
279 $class .= "Unread";
280 }
281
4668523d 282 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
8143ae1f
AD
283
284 }
1a66d16e 285
e828e31e 286 }
82baad4a 287
dc33ec95 288 if (db_num_rows($result) == 0) {
4356293a 289 print "<li>No tags/feeds to display.</li>";
dc33ec95
AD
290 }
291
8143ae1f 292 print "</ul>";
1cd17194 293
caa4e57f
AD
294 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
295
c3b81db0
AD
296 }
297
298
299 if ($op == "rpc") {
300
301 $subop = $_GET["subop"];
302
090e250b 303 if ($subop == "getLabelCounters") {
8073cce7 304 $aid = $_GET["aid"];
090e250b
AD
305 print "<rpc-reply>";
306 getLabelCounters($link);
8073cce7
AD
307 if ($aid) {
308 getFeedCounter($link, $aid);
309 }
090e250b
AD
310 print "</rpc-reply>";
311 }
312
313 if ($subop == "getFeedCounters") {
314 print "<rpc-reply>";
315 getFeedCounters($link);
316 print "</rpc-reply>";
317 }
318
319 if ($subop == "getAllCounters") {
320 print "<rpc-reply>";
321 getLabelCounters($link);
322 getFeedCounters($link);
8143ae1f 323 getTagCounters($link);
fc69e641 324 getGlobalCounters($link);
090e250b 325 print "</rpc-reply>";
090e250b
AD
326 }
327
f4c10d44
AD
328 if ($subop == "mark") {
329 $mark = $_GET["mark"];
648472a7 330 $id = db_escape_string($_GET["id"]);
f4c10d44
AD
331
332 if ($mark == "1") {
333 $mark = "true";
334 } else {
335 $mark = "false";
336 }
337
648472a7 338 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
f4c10d44
AD
339 WHERE id = '$id'");
340 }
341
caa4e57f 342 if ($subop == "updateFeed") {
648472a7 343 $feed_id = db_escape_string($_GET["feed"]);
9cfc649a 344
648472a7 345 $result = db_query($link,
caa4e57f 346 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
9cfc649a 347
648472a7
AD
348 if (db_num_rows($result) > 0) {
349 $feed_url = db_fetch_result($result, 0, "feed_url");
caa4e57f
AD
350// update_rss_feed($link, $feed_url, $feed_id);
351 }
9cfc649a 352
caa4e57f 353 print "DONE-$feed_id";
9cfc649a 354
caa4e57f 355 return;
9cfc649a
AD
356 }
357
090e250b 358 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
c5142cca 359
c3b81db0 360 update_all_feeds($link, true);
c3b81db0 361
ab3f3f72
AD
362 $omode = $_GET["omode"];
363
364 if (!$omode) $omode = "tfl";
365
090e250b 366 print "<rpc-reply>";
ab3f3f72
AD
367 if (strchr($omode, "l")) getLabelCounters($link);
368 if (strchr($omode, "f")) getFeedCounters($link);
369 if (strchr($omode, "t")) getTagCounters($link);
fc69e641 370 getGlobalCounters($link);
090e250b 371 print "</rpc-reply>";
c3b81db0
AD
372 }
373
374 if ($subop == "catchupPage") {
375
376 $ids = split(",", $_GET["ids"]);
377
378 foreach ($ids as $id) {
379
648472a7 380 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
c3b81db0
AD
381 WHERE id = '$id'");
382
383 }
384
385 print "Marked active page as read.";
386 }
295f9b42
AD
387
388 if ($subop == "sanityCheck") {
389
390 $error_code = 0;
391
392 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
393
394 $schema_version = db_fetch_result($result, 0, "schema_version");
395
396 if ($schema_version != SCHEMA_VERSION) {
397 $error_code = 5;
398 }
399
400 print "<error code='$error_code'/>";
401 }
fefa6ca3
AD
402
403 if ($subop == "globalPurge") {
404
405 print "<rpc-reply>";
406 global_purge_old_posts($link, true);
407 print "</rpc-reply>";
408
409 }
410
c3b81db0
AD
411 }
412
413 if ($op == "feeds") {
414
8143ae1f
AD
415 $tags = $_GET["tags"];
416
c3b81db0
AD
417 $subop = $_GET["subop"];
418
419 if ($subop == "catchupAll") {
6d15e1ef
AD
420 db_query($link, "UPDATE ttrss_entries SET
421 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
c3b81db0
AD
422 }
423
8143ae1f 424 outputFeedList($link, $tags);
c3b81db0 425
1cd17194
AD
426 }
427
428 if ($op == "view") {
429
d76a3b03 430 $id = $_GET["id"];
8073cce7 431 $feed_id = $_GET["feed"];
d76a3b03 432
648472a7 433 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
a1a8a2be 434
70830c87
AD
435 $addheader = $_GET["addheader"];
436
648472a7 437 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
b7f4bda2
AD
438 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
439 FROM ttrss_entries
d76a3b03 440 WHERE id = '$id'");
1cd17194 441
70830c87 442 if ($addheader) {
f0601b87 443 print "<html><head>
70830c87
AD
444 <title>Tiny Tiny RSS : Article $id</title>
445 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
c05608c2 446 <script type=\"text/javascript\" src=\"functions.js\"></script>
70830c87 447 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87 448 </head><body>";
70830c87
AD
449 }
450
d76a3b03 451 if ($result) {
1cd17194 452
648472a7 453 $line = db_fetch_assoc($result);
1cd17194 454
b7f4bda2
AD
455 if ($line["icon_url"]) {
456 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
457 } else {
458 $feed_icon = "&nbsp;";
459 }
d76a3b03 460
f7181e9b
AD
461 if ($line["comments"] && $line["link"] != $line["comments"]) {
462 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
463 } else {
464 $entry_comments = "";
465 }
466
e828e31e
AD
467 print "<div class=\"postReply\">";
468
469 print "<div class=\"postHeader\"><table>";
470
471 print "<tr><td><b>Title:</b></td>
472 <td width='100%'>" . $line["title"] . "</td></tr>";
f7181e9b 473
e828e31e 474 print "<tr><td><b>Link:</b></td>
f7181e9b
AD
475 <td width='100%'>
476 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
477 $entry_comments</td></tr>";
e828e31e
AD
478
479 print "</table></div>";
480
481 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
482 print "<div class=\"postContent\">" . $line["content"] . "</div>";
483
484 print "</div>";
485
090e250b 486 print "<script type=\"text/javascript\">
8143ae1f 487 update_label_counters('$feed_id');
090e250b 488 </script>";
d76a3b03 489 }
70830c87
AD
490
491 if ($addheader) {
492 print "</body></html>";
493 }
1cd17194
AD
494 }
495
496 if ($op == "viewfeed") {
497
498 $feed = $_GET["feed"];
d76a3b03 499 $skip = $_GET["skip"];
476cac42 500 $subop = $_GET["subop"];
f175937c 501 $view_mode = $_GET["view"];
f0601b87 502 $addheader = $_GET["addheader"];
cb1083a1 503 $limit = $_GET["limit"];
a1a8a2be 504
8d7008c7
AD
505 if (!$feed) {
506 print "Error: no feed to display.";
507 return;
508 }
509
ac53063a
AD
510 if (!$skip) $skip = 0;
511
476cac42 512 if ($subop == "undefined") $subop = "";
1cd17194 513
f0601b87
AD
514 if ($addheader) {
515 print "<html><head>
ac43eba1 516 <title>Tiny Tiny RSS : Feed $feed</title>
430bf183
AD
517 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
518
4769ddaf 519 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
520 print "<link rel=\"stylesheet\"
521 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
522
523 } else {
524 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
525 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
526 }
527 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87
AD
528 <script type=\"text/javascript\" src=\"functions.js\"></script>
529 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
b623b3ed 530 </head><body onload='init()'>";
f0601b87
AD
531 }
532
dcee8f61
AD
533 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
534
535 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
536 WHERE id = '$feed'");
537
538 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
539
540 update_rss_feed($link, $feed_url, $feed);
541
542 }
543
0e32076b 544 if ($subop == "MarkAllRead") {
d76a3b03 545
0e32076b
AD
546 if (sprintf("%d", $feed) != 0) {
547
548 if ($feed > 0) {
549 db_query($link, "UPDATE ttrss_entries
550 SET unread = false,last_read = NOW()
254e0e4b 551 WHERE feed_id = '$feed'");
0e32076b
AD
552
553 } else if ($feed < 0 && $feed > -10) { // special, like starred
554
555 if ($feed == -1) {
556 db_query($link, "UPDATE ttrss_entries
557 SET unread = false,last_read = NOW()
558 WHERE marked = true");
559 }
560
561 } else if ($feed < -10) { // label
562
7db95187 563 $label_id = -$feed - 11;
0e32076b 564
7db95187
AD
565 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
566 WHERE id = '$label_id'");
567
568 if ($tmp_result) {
569 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
570
571 db_query($link, "UPDATE ttrss_entries
572 SET unread = false,last_read = NOW()
573 WHERE $sql_exp");
574 }
254e0e4b 575 }
0e32076b
AD
576 } else { // tag
577 // FIXME, implement catchup for tags
a1a8a2be 578 }
0e32076b 579
a1a8a2be 580 }
d76a3b03 581
175847de 582 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
ac53063a 583
c374a3fe
AD
584 $search = $_GET["search"];
585
52b51244
AD
586 $search_mode = $_GET["smode"];
587
f175937c 588 if ($search) {
ac53063a
AD
589 $search_query_part = "(upper(title) LIKE upper('%$search%')
590 OR content LIKE '%$search%') AND";
f175937c
AD
591 } else {
592 $search_query_part = "";
593 }
594
595 $view_query_part = "";
596
597 if ($view_mode == "Starred") {
598 $view_query_part = " marked = true AND ";
ac53063a
AD
599 }
600
ac43eba1
AD
601 if ($view_mode == "Unread") {
602 $view_query_part = " unread = true AND ";
603 }
604
b5aa95e7
AD
605 if ($view_mode == "Unread or Starred") {
606 $view_query_part = " (unread = true OR marked = true) AND ";
607 }
608
bdd01d3f
AD
609 if ($view_mode == "Unread or Updated") {
610 $view_query_part = " (unread = true OR last_read is NULL) AND ";
611 }
612
254e0e4b 613/* $result = db_query($link, "SELECT count(id) AS total_entries
36bf7496
AD
614 FROM ttrss_entries WHERE
615 $search_query_part
616 feed_id = '$feed'");
e6d1c0a0 617
254e0e4b 618 $total_entries = db_fetch_result($result, 0, "total_entries"); */
e6d1c0a0 619
648472a7 620/* $result = db_query("SELECT count(id) AS unread_entries
ac43eba1
AD
621 FROM ttrss_entries WHERE
622 $search_query_part
623 unread = true AND
624 feed_id = '$feed'");
625
648472a7 626 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
ac43eba1 627
8d7008c7 628 if ($limit && $limit != "All") {
82c9223c 629 $limit_query_part = "LIMIT " . $limit;
ad3cb710 630 }
f0601b87 631
254e0e4b
AD
632 $vfeed_query_part = "";
633
52b51244
AD
634 // override query strategy and enable feed display when searching globally
635 if ($search_mode == "All feeds") {
636 $query_strategy_part = "id > 0";
637 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
638 id = feed_id) as feed_title,";
639 } else if (sprintf("%d", $feed) == 0) {
8143ae1f
AD
640 $query_strategy_part = "ttrss_entries.id > 0";
641 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
642 id = feed_id) as feed_title,";
643 } else if ($feed >= 0) {
254e0e4b 644 $query_strategy_part = "feed_id = '$feed'";
48f0adb0 645 } else if ($feed == -1) { // starred virtual feed
254e0e4b 646 $query_strategy_part = "marked = true";
48f0adb0
AD
647 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
648 id = feed_id) as feed_title,";
649 } else if ($feed <= -10) { // labels
650 $label_id = -$feed - 11;
651
652 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
653 WHERE id = '$label_id'");
654
655 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
656
254e0e4b
AD
657 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
658 id = feed_id) as feed_title,";
659 } else {
48f0adb0 660 $query_strategy_part = "id > 0"; // dumb
254e0e4b
AD
661 }
662
52b51244 663
f99321a3
AD
664 $order_by = "updated DESC";
665
666// if ($feed < -10) {
667// $order_by = "feed_id,updated DESC";
668// }
669
48f0adb0
AD
670 if ($feed < -10) error_reporting (0);
671
8143ae1f
AD
672 if (sprintf("%d", $feed) != 0) {
673
674 $result = db_query($link, "SELECT
675 id,title,updated,unread,feed_id,marked,link,last_read,
676 SUBSTRING(last_read,1,19) as last_read_noms,
677 $vfeed_query_part
678 SUBSTRING(updated,1,19) as updated_noms
679 FROM
680 ttrss_entries
681 WHERE
aee86c2e 682 owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
683 $search_query_part
684 $view_query_part
685 $query_strategy_part ORDER BY $order_by
686 $limit_query_part");
687
688 } else {
689 // browsing by tag
690
691 $result = db_query($link, "SELECT
692 ttrss_entries.id as id,title,updated,unread,feed_id,
693 marked,link,last_read,
c05a19f3 694 SUBSTRING(last_read,1,19) as last_read_noms,
254e0e4b 695 $vfeed_query_part
c05a19f3 696 SUBSTRING(updated,1,19) as updated_noms
8143ae1f
AD
697 FROM
698 ttrss_entries,ttrss_tags
699 WHERE
aee86c2e 700 ttrss_entries.owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
701 post_id = ttrss_entries.id AND tag_name = '$feed' AND
702 $view_query_part
703 $search_query_part
704 $query_strategy_part ORDER BY $order_by
705 $limit_query_part");
706 }
d76a3b03 707
48f0adb0
AD
708 if (!$result) {
709 print "<tr><td colspan='4' align='center'>
710 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
711 return;
712 }
713
a1a8a2be 714 $lnum = 0;
48f0adb0
AD
715
716 error_reporting (E_ERROR | E_WARNING | E_PARSE);
717
e1123aee 718 $num_unread = 0;
d76a3b03 719
648472a7 720 while ($line = db_fetch_assoc($result)) {
d76a3b03 721
a1a8a2be 722 $class = ($lnum % 2) ? "even" : "odd";
d76a3b03 723
ad99045e
AD
724 $id = $line["id"];
725 $feed_id = $line["feed_id"];
726
c43f77f5 727// printf("L %d (%s) &gt; U %d (%s) = %d<br>",
c05a19f3 728// strtotime($line["last_read_noms"]), $line["last_read_noms"],
c43f77f5
AD
729// strtotime($line["updated"]), $line["updated"],
730// strtotime($line["last_read"]) >= strtotime($line["updated"]));
731
ecb14114 732/* if ($line["last_read"] != "" && $line["updated"] != "" &&
c05a19f3 733 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
c43f77f5
AD
734
735 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
736 alt=\"Updated\">";
737
738 } else {
739
5bfef089 740 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
c43f77f5
AD
741 alt=\"Updated\">";
742
ecb14114
AD
743 } */
744
4cc6ea5e
AD
745 if ($line["last_read"] == "" &&
746 ($line["unread"] != "t" && $line["unread"] != "1")) {
747
ecb14114
AD
748 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
749 alt=\"Updated\">";
750 } else {
751 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
752 alt=\"Updated\">";
c43f77f5 753 }
b197f117 754
8158c57a 755 if ($line["unread"] == "t" || $line["unread"] == "1") {
a1a8a2be 756 $class .= "Unread";
e1123aee
AD
757 ++$num_unread;
758 }
d76a3b03 759
8158c57a 760 if ($line["marked"] == "t" || $line["marked"] == "1") {
f4c10d44
AD
761 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
762 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
763 } else {
764 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
765 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
766 }
767
ac43eba1 768 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
b197f117
AD
769 $line["title"] . "</a>";
770
d5224f0d 771 print "<tr class='$class' id='RROW-$id'>";
5f89f780 772 // onclick=\"javascript:view($id,$feed_id)\">
b197f117 773
8d7008c7
AD
774 print "<td valign='center' align='center'>$update_pic</td>";
775 print "<td valign='center' align='center'>$marked_pic</td>";
b197f117 776
8d7008c7 777 print "<td width='25%'>
a3ee2a38 778 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
254e0e4b
AD
779
780 if ($line["feed_title"]) {
781 print "<td width='50%'>$content_link</td>";
2db4190c
AD
782 print "<td width='20%'>
783 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
254e0e4b
AD
784 } else {
785 print "<td width='70%'>$content_link</td>";
786 }
d76a3b03 787
a1a8a2be 788 print "</tr>";
d76a3b03 789
a1a8a2be
AD
790 ++$lnum;
791 }
d76a3b03 792
ac53063a 793 if ($lnum == 0) {
a82065a1 794 print "<tr><td align='center'>No articles found.</td></tr>";
047bae73 795 }
a2015351 796
a1a8a2be 797 print "</table>";
6113ef7d
AD
798
799 print "<script type=\"text/javascript\">
bb7cface 800 document.onkeydown = hotkey_handler;
8143ae1f 801 update_label_counters('$feed');
6113ef7d 802 </script>";
d76a3b03 803
f0601b87
AD
804 if ($addheader) {
805 print "</body></html>";
806 }
807
1cd17194
AD
808 }
809
0e091d38 810 if ($op == "pref-rpc") {
331900c6 811
0e091d38 812 $subop = $_GET["subop"];
331900c6 813
83fe4d6d
AD
814 if ($subop == "unread") {
815 $ids = split(",", $_GET["ids"]);
816 foreach ($ids as $id) {
648472a7 817 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
83fe4d6d 818 }
0e091d38
AD
819
820 print "Marked selected feeds as read.";
83fe4d6d
AD
821 }
822
823 if ($subop == "read") {
824 $ids = split(",", $_GET["ids"]);
825 foreach ($ids as $id) {
648472a7 826 db_query($link, "UPDATE ttrss_entries
b197f117 827 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
83fe4d6d 828 }
0e091d38
AD
829
830 print "Marked selected feeds as unread.";
831
832 }
833
834 }
835
836 if ($op == "pref-feeds") {
837
838 $subop = $_GET["subop"];
839
508a81e1 840 if ($subop == "editSave") {
648472a7
AD
841 $feed_title = db_escape_string($_GET["t"]);
842 $feed_link = db_escape_string($_GET["l"]);
d148926e 843 $upd_intl = db_escape_string($_GET["ui"]);
5d73494a 844 $purge_intl = db_escape_string($_GET["pi"]);
508a81e1
AD
845 $feed_id = $_GET["id"];
846
d148926e
AD
847 if (strtoupper($upd_intl) == "DEFAULT")
848 $upd_intl = 0;
849
5d73494a
AD
850 if (strtoupper($purge_intl) == "DEFAULT")
851 $purge_intl = 0;
852
140aae81
AD
853 if (strtoupper($purge_intl) == "DISABLED")
854 $purge_intl = -1;
855
648472a7 856 $result = db_query($link, "UPDATE ttrss_feeds SET
d148926e 857 title = '$feed_title', feed_url = '$feed_link',
5d73494a
AD
858 update_interval = '$upd_intl',
859 purge_interval = '$purge_intl'
860 WHERE id = '$feed_id'");
508a81e1 861
83fe4d6d
AD
862 }
863
331900c6 864 if ($subop == "remove") {
331900c6 865
b0b4abcf 866 if (!WEB_DEMO_MODE) {
331900c6 867
b0b4abcf
AD
868 $ids = split(",", $_GET["ids"]);
869
870 foreach ($ids as $id) {
648472a7 871 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
4769ddaf 872
273a2f6b 873 $icons_dir = ICONS_DIR;
d5caaae5 874
4769ddaf
AD
875 if (file_exists($icons_dir . "/$id.ico")) {
876 unlink($icons_dir . "/$id.ico");
d5caaae5 877 }
b0b4abcf 878 }
331900c6
AD
879 }
880 }
881
882 if ($subop == "add") {
b0b4abcf
AD
883
884 if (!WEB_DEMO_MODE) {
331900c6 885
648472a7 886 $feed_link = db_escape_string($_GET["link"]);
b0b4abcf 887
648472a7 888 $result = db_query($link,
4356293a 889 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
331900c6 890
648472a7 891 $result = db_query($link,
e9c54861 892 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
331900c6 893
648472a7 894 $feed_id = db_fetch_result($result, 0, "id");
331900c6 895
b0b4abcf
AD
896 if ($feed_id) {
897 update_rss_feed($link, $feed_link, $feed_id);
898 }
899 }
331900c6 900 }
a0d53889 901
ab3d0b99
AD
902 $result = db_query($link, "SELECT id,title,feed_url,last_error
903 FROM ttrss_feeds WHERE last_error != ''");
904
905 if (db_num_rows($result) > 0) {
906
907 print "<div class=\"warning\">";
908
909 print "<b>Feeds with update errors:</b>";
910
911 print "<ul class=\"nomarks\">";
912
913 while ($line = db_fetch_assoc($result)) {
914 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
915 $line["last_error"];
916 }
917
918 print "</ul>";
919 print "</div>";
920
921 }
922
a0d53889
AD
923 print "<table class=\"prefAddFeed\"><tr>
924 <td><input id=\"fadd_link\"></td>
925 <td colspan=\"4\" align=\"right\">
926 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
927 </table>";
928
648472a7 929 $result = db_query($link, "SELECT
d148926e 930 id,title,feed_url,substring(last_updated,1,16) as last_updated,
5d73494a 931 update_interval,purge_interval
c0e5a40e 932 FROM
4356293a 933 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
1cd17194 934
331900c6 935 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
007bda35 936 print "<tr class=\"title\">
5d73494a
AD
937 <td>&nbsp;</td><td>Select</td><td width=\"30%\">Title</td>
938 <td width=\"30%\">Link</td>
939 <td width=\"10%\">Update Interval</td>
940 <td width=\"10%\">Purge Days</td>
d148926e 941 <td>Last updated</td></tr>";
007bda35
AD
942
943 $lnum = 0;
944
648472a7 945 while ($line = db_fetch_assoc($result)) {
007bda35
AD
946
947 $class = ($lnum % 2) ? "even" : "odd";
9b307248 948
331900c6 949 $feed_id = $line["id"];
603c27f8
AD
950
951 $edit_feed_id = $_GET["id"];
952
9b307248
AD
953 if ($subop == "edit" && $feed_id != $edit_feed_id) {
954 $class .= "Grayed";
955 }
956
331900c6 957 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
007bda35 958
273a2f6b 959 $icon_file = ICONS_DIR . "/$feed_id.ico";
c0e5a40e
AD
960
961 if (file_exists($icon_file) && filesize($icon_file) > 0) {
962 $feed_icon = "<img width=\"16\" height=\"16\"
273a2f6b 963 src=\"" . ICONS_URL . "/$feed_id.ico\">";
c0e5a40e
AD
964 } else {
965 $feed_icon = "&nbsp;";
966 }
967 print "<td align='center'>$feed_icon</td>";
968
6e0584e9
AD
969 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
970 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
971
9b307248 972 if (!$edit_feed_id || $subop != "edit") {
603c27f8
AD
973
974 print "<td><input onclick='toggleSelectRow(this);'
331900c6 975 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
603c27f8
AD
976
977 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
5d73494a 978 $edit_title . "</a></td>";
603c27f8 979 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
5d73494a 980 $edit_link . "</a></td>";
d148926e
AD
981
982 if ($line["update_interval"] == "0")
983 $line["update_interval"] = "Default";
984
5d73494a
AD
985 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
986 $line["update_interval"] . "</a></td>";
d148926e 987
5d73494a
AD
988 if ($line["purge_interval"] == "0")
989 $line["purge_interval"] = "Default";
990
140aae81
AD
991 if ($line["purge_interval"] < 0)
992 $line["purge_interval"] = "Disabled";
993
5d73494a
AD
994 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
995 $line["purge_interval"] . "</a></td>";
9b307248
AD
996
997 } else if ($feed_id != $edit_feed_id) {
998
e9c54861
AD
999 print "<td><input disabled=\"true\" type=\"checkbox\"
1000 id=\"FRCHK-".$line["id"]."\"></td>";
9b307248 1001
6e0584e9
AD
1002 print "<td>$edit_title</td>";
1003 print "<td>$edit_link</td>";
9b307248 1004
d148926e
AD
1005 if ($line["update_interval"] == "0")
1006 $line["update_interval"] = "Default";
1007
1008 print "<td>" . $line["update_interval"] . "</td>";
1009
5d73494a
AD
1010 if ($line["purge_interval"] == "0")
1011 $line["purge_interval"] = "Default";
1012
140aae81
AD
1013 if ($line["purge_interval"] < 0)
1014 $line["purge_interval"] = "Disabled";
1015
5d73494a
AD
1016 print "<td>" . $line["purge_interval"] . "</td>";
1017
603c27f8
AD
1018 } else {
1019
e6cb77a0 1020 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
603c27f8 1021
6e0584e9
AD
1022 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1023 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
d148926e 1024 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
5d73494a 1025 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
d148926e 1026
603c27f8 1027 }
0afbd851
AD
1028
1029 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1030
007bda35 1031 print "<td>" . $line["last_updated"] . "</td>";
603c27f8 1032
007bda35
AD
1033 print "</tr>";
1034
1035 ++$lnum;
1036 }
1037
0afbd851
AD
1038 if ($lnum == 0) {
1039 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1040 }
1041
007bda35
AD
1042 print "</table>";
1043
603c27f8
AD
1044 print "<p>";
1045
1046 if ($subop == "edit") {
1047 print "Edit feed:&nbsp;
e828e31e
AD
1048 <input type=\"submit\" class=\"button\"
1049 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1050 <input type=\"submit\" class=\"button\"
8158c57a 1051 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
603c27f8
AD
1052 } else {
1053
603c27f8
AD
1054 print "
1055 Selection:&nbsp;
e828e31e
AD
1056 <input type=\"submit\" class=\"button\"
1057 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1058 <input type=\"submit\" class=\"button\"
1059 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1060
4769ddaf 1061 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
f92db4f5 1062 print "
e828e31e
AD
1063 <input type=\"submit\" class=\"button\"
1064 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1065 <input type=\"submit\" class=\"button\"
1066 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
f92db4f5
AD
1067 }
1068 print "
e828e31e
AD
1069 All feeds:
1070 <input type=\"submit\"
8158c57a 1071 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
10c5820d 1072
603c27f8
AD
1073 }
1074
f5a50b25
AD
1075 print "<h3>OPML Import</h3>
1076 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1077 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1078 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1079 type=\"submit\" value=\"Import\">
1080 </form>";
1081
007bda35
AD
1082 }
1083
a0d53889
AD
1084 if ($op == "pref-filters") {
1085
1086 $subop = $_GET["subop"];
1087
1088 if ($subop == "editSave") {
a0d53889 1089
648472a7
AD
1090 $regexp = db_escape_string($_GET["r"]);
1091 $descr = db_escape_string($_GET["d"]);
1092 $match = db_escape_string($_GET["m"]);
1093 $filter_id = db_escape_string($_GET["id"]);
0afbd851 1094
648472a7 1095 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 1096 reg_exp = '$regexp',
0afbd851
AD
1097 description = '$descr',
1098 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1099 description = '$match')
1100 WHERE id = '$filter_id'");
a0d53889
AD
1101 }
1102
1103 if ($subop == "remove") {
1104
1105 if (!WEB_DEMO_MODE) {
1106
1107 $ids = split(",", $_GET["ids"]);
1108
1109 foreach ($ids as $id) {
648472a7 1110 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
1111
1112 }
1113 }
1114 }
1115
1116 if ($subop == "add") {
1117
de435974 1118 if (!WEB_DEMO_MODE) {
a0d53889 1119
8158c57a 1120 $regexp = db_escape_string($_GET["regexp"]);
648472a7 1121 $match = db_escape_string($_GET["match"]);
a0d53889 1122
648472a7 1123 $result = db_query($link,
4356293a 1124 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES
de435974 1125 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
4356293a 1126 description = '$match'),'".$_SESSION["uid"]."')");
de435974 1127 }
a0d53889
AD
1128 }
1129
648472a7 1130 $result = db_query($link, "SELECT description
a0d53889
AD
1131 FROM ttrss_filter_types ORDER BY description");
1132
1133 $filter_types = array();
1134
648472a7 1135 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1136 array_push($filter_types, $line["description"]);
1137 }
1138
1139 print "<table class=\"prefAddFeed\"><tr>
ea6774cf 1140 <td><input id=\"fadd_regexp\"></td>
a0d53889 1141 <td>";
bdc00fe0 1142 print_select("fadd_match", "Title", $filter_types);
a0d53889
AD
1143
1144 print"</td><td colspan=\"4\" align=\"right\">
1145 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1146 </table>";
1147
648472a7 1148 $result = db_query($link, "SELECT
4b3dff6e 1149 id,reg_exp,description,
a0d53889
AD
1150 (SELECT name FROM ttrss_filter_types WHERE
1151 id = filter_type) as filter_type_name,
1152 (SELECT description FROM ttrss_filter_types
1153 WHERE id = filter_type) as filter_type_descr
1154 FROM
4356293a
AD
1155 ttrss_filters
1156 WHERE
1157 owner_uid = ".$_SESSION["uid"]."
1158 ORDER by reg_exp");
a0d53889
AD
1159
1160 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1161
1162 print "<tr class=\"title\">
0afbd851
AD
1163 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1164 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
a0d53889
AD
1165
1166 $lnum = 0;
1167
648472a7 1168 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1169
1170 $class = ($lnum % 2) ? "even" : "odd";
1171
1172 $filter_id = $line["id"];
1173 $edit_filter_id = $_GET["id"];
1174
1175 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1176 $class .= "Grayed";
1177 }
1178
1179 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1180
4b3dff6e 1181 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
ea6774cf
AD
1182 $line["description"] = htmlspecialchars($line["description"]);
1183
a0d53889
AD
1184 if (!$edit_filter_id || $subop != "edit") {
1185
0afbd851
AD
1186 if (!$line["description"]) $line["description"] = "[No description]";
1187
a0d53889
AD
1188 print "<td><input onclick='toggleSelectRow(this);'
1189 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1190
1191 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
4b3dff6e 1192 $line["reg_exp"] . "</td>";
a0d53889
AD
1193
1194 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1195 $line["description"] . "</td>";
1196
1197 print "<td>".$line["filter_type_descr"]."</td>";
1198
1199 } else if ($filter_id != $edit_filter_id) {
1200
0afbd851
AD
1201 if (!$line["description"]) $line["description"] = "[No description]";
1202
a0d53889
AD
1203 print "<td><input disabled=\"true\" type=\"checkbox\"
1204 id=\"FICHK-".$line["id"]."\"></td>";
1205
4b3dff6e 1206 print "<td>".$line["reg_exp"]."</td>";
a0d53889
AD
1207 print "<td>".$line["description"]."</td>";
1208 print "<td>".$line["filter_type_descr"]."</td>";
1209
1210 } else {
1211
e6cb77a0 1212 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
a0d53889 1213
4b3dff6e 1214 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
a0d53889
AD
1215 "\"></td>";
1216
1217 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1218 "\"></td>";
1219
1220 print "<td>";
1221 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1222 print "</td>";
1223
1224 }
1225
1226
1227 print "</tr>";
1228
1229 ++$lnum;
1230 }
1231
0afbd851
AD
1232 if ($lnum == 0) {
1233 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1234 }
1235
a0d53889
AD
1236 print "</table>";
1237
1238 print "<p>";
1239
1240 if ($subop == "edit") {
e828e31e
AD
1241 print "Edit feed:
1242 <input type=\"submit\" class=\"button\"
1243 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1244 <input type=\"submit\" class=\"button\"
1245 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
a0d53889
AD
1246
1247 } else {
1248
1249 print "
e828e31e
AD
1250 Selection:
1251 <input type=\"submit\" class=\"button\"
1252 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1253 <input type=\"submit\" class=\"button\"
1254 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
a0d53889
AD
1255 }
1256 }
1257
48f0adb0
AD
1258 if ($op == "pref-labels") {
1259
1260 $subop = $_GET["subop"];
1261
1262 if ($subop == "editSave") {
1263
1264 $sql_exp = $_GET["s"];
1265 $descr = $_GET["d"];
1266 $label_id = db_escape_string($_GET["id"]);
1267
1268// print "$sql_exp : $descr : $label_id";
1269
1270 $result = db_query($link, "UPDATE ttrss_labels SET
1271 sql_exp = '$sql_exp',
1272 description = '$descr'
1273 WHERE id = '$label_id'");
1274 }
1275
1276 if ($subop == "remove") {
1277
1278 if (!WEB_DEMO_MODE) {
1279
1280 $ids = split(",", $_GET["ids"]);
1281
1282 foreach ($ids as $id) {
1283 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1284
1285 }
1286 }
1287 }
1288
1289 if ($subop == "add") {
1290
1291 if (!WEB_DEMO_MODE) {
1292
1293 $exp = $_GET["exp"];
1294
1295 $result = db_query($link,
4356293a
AD
1296 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1297 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
1298 }
1299 }
1300
1301 print "<table class=\"prefAddFeed\"><tr>
1302 <td><input id=\"ladd_expr\"></td>";
1303
1304 print"<td colspan=\"4\" align=\"right\">
1305 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1306 </table>";
1307
1308 $result = db_query($link, "SELECT
1309 id,sql_exp,description
1310 FROM
4356293a
AD
1311 ttrss_labels
1312 WHERE
1313 owner_uid = ".$_SESSION["uid"]."
1314 ORDER by description");
48f0adb0
AD
1315
1316 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1317
1318 print "<tr class=\"title\">
7dc66a61
AD
1319 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1320 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1321 </td>
48f0adb0
AD
1322 <td width=\"40%\">Caption</td></tr>";
1323
1324 $lnum = 0;
1325
1326 while ($line = db_fetch_assoc($result)) {
1327
1328 $class = ($lnum % 2) ? "even" : "odd";
1329
1330 $label_id = $line["id"];
1331 $edit_label_id = $_GET["id"];
1332
1333 if ($subop == "edit" && $label_id != $edit_label_id) {
1334 $class .= "Grayed";
1335 }
1336
1337 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1338
1339 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1340 $line["description"] = htmlspecialchars($line["description"]);
1341
1342 if (!$edit_label_id || $subop != "edit") {
1343
1344 if (!$line["description"]) $line["description"] = "[No caption]";
1345
1346 print "<td><input onclick='toggleSelectRow(this);'
1347 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1348
1349 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1350 $line["sql_exp"] . "</td>";
1351
1352 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1353 $line["description"] . "</td>";
1354
1355 } else if ($label_id != $edit_label_id) {
1356
1357 if (!$line["description"]) $line["description"] = "[No description]";
1358
1359 print "<td><input disabled=\"true\" type=\"checkbox\"
1360 id=\"LICHK-".$line["id"]."\"></td>";
1361
1362 print "<td>".$line["sql_exp"]."</td>";
1363 print "<td>".$line["description"]."</td>";
1364
1365 } else {
1366
e6cb77a0 1367 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
48f0adb0
AD
1368
1369 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1370 "\"></td>";
1371
1372 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1373 "\"></td>";
1374
1375 }
1376
1377
1378 print "</tr>";
1379
1380 ++$lnum;
1381 }
1382
1383 if ($lnum == 0) {
1384 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1385 }
1386
1387 print "</table>";
1388
1389 print "<p>";
1390
1391 if ($subop == "edit") {
1392 print "Edit label:
1393 <input type=\"submit\" class=\"button\"
1394 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1395 <input type=\"submit\" class=\"button\"
1396 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1397
1398 } else {
1399
1400 print "
1401 Selection:
1402 <input type=\"submit\" class=\"button\"
1403 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1404 <input type=\"submit\" class=\"button\"
1405 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1406 }
1407 }
1408
e828e31e
AD
1409 if ($op == "error") {
1410 print "<div width=\"100%\" align='center'>";
1411 $msg = $_GET["msg"];
1412 print $msg;
1413 print "</div>";
1414 }
1415
7dc66a61
AD
1416 if ($op == "help") {
1417 print "<html><head>
1418 <title>Tiny Tiny RSS : Help</title>
1419 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1420 <script type=\"text/javascript\" src=\"functions.js\"></script>
7dc66a61
AD
1421 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1422 </head><body>";
1423
1424 $tid = sprintf("%d", $_GET["tid"]);
1425
1426 /* FIXME this badly needs real implementation */
1427
1428 print "<div class='helpResponse'>";
1429
1430 ?>
1431
1432 <h1>Help for SQL expressions</h1>
1433
1434 <h2>Description</h2>
1435
1436 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
d1f948d1 1437 view feed query. You can match on ttrss_entries table fields
7dc66a61
AD
1438 and even use subselect to query additional information. This
1439 functionality is considered to be advanced and requires basic
1440 understanding of SQL.</p>
1441
1442 <h2>Examples</h2>
1443
1444 <pre>unread = true</pre>
1445
1446 Matches all unread articles
1447
1448 <pre>title like '%Linux%'</pre>
1449
1450 Matches all articles which mention Linux in the title. You get the idea.
1451
1452 <p>See the database schema included in the distribution package for gruesome
1453 details.</p>
1454
1455 <?
1456
1457 print "<div align='center'>
1458 <a class=\"helpLink\"
1459 href=\"javascript:window.close()\">(Close this window)</a></div>";
1460
1461 print "</div>";
1462
1463 print "</body></html>";
1464
1465 }
1466
f84a97a3
AD
1467 if ($op == "dlg") {
1468 $id = $_GET["id"];
6de5d056 1469 $param = $_GET["param"];
f84a97a3
AD
1470
1471 if ($id == "quickAddFeed") {
033e47e0
AD
1472 print "Feed URL: <input
1473 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1474 id=\"qafInput\">
f84a97a3
AD
1475 <input class=\"button\"
1476 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1477 <input class=\"button\"
1478 type=\"submit\" onclick=\"javascript:closeDlg()\"
1479 value=\"Cancel\">";
1480 }
6de5d056
AD
1481
1482 if ($id == "quickDelFeed") {
1483
1484 $param = db_escape_string($param);
1485
1486 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1487
1488 if ($result) {
1489
1490 $f_title = db_fetch_result($result, 0, "title");
1491
1492 print "Remove current feed ($f_title)?&nbsp;
1493 <input class=\"button\"
1494 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1495 <input class=\"button\"
1496 type=\"submit\" onclick=\"javascript:closeDlg()\"
1497 value=\"Cancel\">";
1498 } else {
1499 print "Error: Feed $param not found.&nbsp;
1500 <input class=\"button\"
1501 type=\"submit\" onclick=\"javascript:closeDlg()\"
1502 value=\"Cancel\">";
1503 }
1504 }
1505
033e47e0
AD
1506 if ($id == "search") {
1507
1508 print "<input id=\"searchbox\" class=\"extSearch\"
1509 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1510 onchange=\"javascript:search()\">
1511 <select id=\"searchmodebox\">
1512 <option selected>All feeds</option>
1513 <option>This feed</option>
1514 </select>
1515 <input type=\"submit\"
1516 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1517 <input class=\"button\"
1518 type=\"submit\" onclick=\"javascript:closeDlg()\"
1519 value=\"Close\">";
1520
1521 }
1522
f84a97a3
AD
1523 }
1524
e65af9c1
AD
1525 if ($op == "updateAllFeeds") {
1526 update_all_feeds($link, true);
1527
1528 print "<rpc-reply>";
1529 getLabelCounters($link);
1530 getFeedCounters($link);
1531 getTagCounters($link);
1532 getGlobalCounters($link);
1533 print "</rpc-reply>";
1534
1535 }
1536
77e96719
AD
1537 if ($op == "pref-prefs") {
1538
b1895692 1539 $subop = $_REQUEST["subop"];
77e96719
AD
1540
1541 if ($subop == "Save configuration") {
1542
01d68cf9
AD
1543 if (WEB_DEMO_MODE) return;
1544
77e96719
AD
1545 foreach (array_keys($_POST) as $pref_name) {
1546
1547 $pref_name = db_escape_string($pref_name);
1548 $value = db_escape_string($_POST[$pref_name]);
1549
1550 $result = db_query($link, "SELECT type_name
1551 FROM ttrss_prefs,ttrss_prefs_types
1552 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
1553
1554 if (db_num_rows($result) > 0) {
1555
1556 $type_name = db_fetch_result($result, 0, "type_name");
1557
5da169d9
AD
1558// print "$pref_name : $type_name : $value<br>";
1559
77e96719 1560 if ($type_name == "bool") {
5da169d9 1561 if ($value == "1") {
77e96719
AD
1562 $value = "true";
1563 } else {
1564 $value = "false";
1565 }
1566 } else if ($type_name == "integer") {
1567 $value = sprintf("%d", $value);
1568 }
1569
1570// print "$pref_name : $type_name : $value<br>";
1571
ff485f1d
AD
1572 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
1573 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
1574
1575 }
1576
1577 header("Location: prefs.php");
1578
1579 }
1580
b1895692
AD
1581 } else if ($subop == "getHelp") {
1582
1583 $pref_name = db_escape_string($_GET["pn"]);
1584
1585 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
1586 WHERE pref_name = '$pref_name'");
1587
1588 if (db_num_rows($result) > 0) {
1589 $help_text = db_fetch_result($result, 0, "help_text");
1590 print $help_text;
1591 } else {
1592 print "Unknown option: $pref_name";
1593 }
1594
1c7f75ed
AD
1595 } else if ($subop == "Change password") {
1596
1597 if (WEB_DEMO_MODE) return;
1598
1599 $old_pw = $_POST["OLD_PASSWORD"];
1600 $new_pw = $_POST["OLD_PASSWORD"];
1601
1602 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
1603 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
1604
1605 $active_uid = $_SESSION["uid"];
1606
1607 if ($old_pw && $new_pw) {
1608
1609 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
1610
1611 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1612 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
1613 pwd_hash = '$old_pw_hash')");
1614
1615 if (db_num_rows($result) == 1) {
1616 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
1617 WHERE id = '$active_uid'");
1618 }
1619 }
1620
1621 header("Location: prefs.php");
1622
77e96719
AD
1623 } else if ($subop == "Reset to defaults") {
1624
01d68cf9
AD
1625 if (WEB_DEMO_MODE) return;
1626
e1aa0559
AD
1627 if (DB_TYPE == "pgsql") {
1628 db_query($link,"UPDATE ttrss_user_prefs
1629 SET value = ttrss_prefs.def_value
1630 WHERE owner_uid = '".$_SESSION["uid"]."' AND
1631 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
1632 } else {
1633 db_query($link, "DELETE FROM ttrss_user_prefs
1634 WHERE owner_uid = ".$_SESSION["uid"]);
1635 initialize_user_prefs($link, $_SESSION["uid"]);
1636 }
5da169d9 1637
77e96719
AD
1638 header("Location: prefs.php");
1639
1640 } else {
1641
7d4c898a 1642 if (!SINGLE_USER_MODE) {
1c7f75ed 1643
7d4c898a
AD
1644 print "<form action=\"backend.php\" method=\"POST\">";
1645
1646 print "<table width=\"100%\" class=\"prefPrefsList\">";
1647 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
1648
1649 print "<tr><td width=\"40%\">Old password</td>";
1650 print "<td><input class=\"editbox\" type=\"password\"
1651 name=\"OLD_PASSWORD\"></td></tr>";
1652
1653 print "<tr><td width=\"40%\">New password</td>";
1654
1655 print "<td><input class=\"editbox\" type=\"password\"
1656 name=\"NEW_PASSWORD\"></td></tr>";
1657
1658 print "</table>";
1659
1660 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1661
1662 print "<p><input class=\"button\" type=\"submit\"
1663 value=\"Change password\" name=\"subop\">";
1664
1665 print "</form>";
1c7f75ed 1666
7d4c898a 1667 }
1c7f75ed 1668
77e96719 1669 $result = db_query($link, "SELECT
ff485f1d 1670 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 1671 section_name,def_value
ff485f1d 1672 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 1673 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 1674 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
1675 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
1676 owner_uid = ".$_SESSION["uid"]."
650bc435 1677 ORDER BY section_id,short_desc");
77e96719
AD
1678
1679 print "<form action=\"backend.php\" method=\"POST\">";
1680
77e96719
AD
1681 $lnum = 0;
1682
1683 $active_section = "";
1684
1685 while ($line = db_fetch_assoc($result)) {
1686
1687 if ($active_section != $line["section_name"]) {
59a654ba
AD
1688
1689 if ($active_section != "") {
1c7f75ed 1690 print "</table>";
59a654ba 1691 }
1c7f75ed
AD
1692
1693 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
1694
1695 $active_section = $line["section_name"];
1696
77e96719 1697 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
1698// print "<tr class=\"title\">
1699// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
1700
1701 $lnum = 0;
77e96719
AD
1702 }
1703
650bc435 1704// $class = ($lnum % 2) ? "even" : "odd";
77e96719 1705
650bc435 1706 print "<tr>";
77e96719 1707
77e96719
AD
1708 $type_name = $line["type_name"];
1709 $pref_name = $line["pref_name"];
1710 $value = $line["value"];
1711 $def_value = $line["def_value"];
b1895692
AD
1712 $help_text = $line["help_text"];
1713
1714 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
1715
1716 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
1717
1718 print "</td>";
77e96719
AD
1719
1720 print "<td>";
1721
1722 if ($type_name == "bool") {
1723// print_select($pref_name, $value, array("true", "false"));
1724
1725 if ($value == "true") {
1726 $value = "Yes";
1727 } else {
1728 $value = "No";
1729 }
1730
1731 print_radio($pref_name, $value, array("Yes", "No"));
1732
1733 } else {
1734 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
1735 }
1736
1737 print "</td>";
1738
1739 print "</tr>";
1740
1741 $lnum++;
1742 }
1743
1744 print "</table>";
1745
1746 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1747
1748 print "<p><input class=\"button\" type=\"submit\"
1749 name=\"subop\" value=\"Save configuration\">";
1750
1751 print "&nbsp;<input class=\"button\" type=\"submit\"
1752 name=\"subop\" value=\"Reset to defaults\"></p>";
1753
1754 print "</form>";
1755
1756 }
1757
1758 }
1759
e6cb77a0
AD
1760 if ($op == "pref-users") {
1761
1762 $subop = $_GET["subop"];
1763
1764 if ($subop == "editSave") {
1765
1766 if (!WEB_DEMO_MODE) {
1767
1768 $login = db_escape_string($_GET["l"]);
1769 $uid = db_escape_string($_GET["id"]);
1770 $access_level = sprintf("%d", $_GET["al"]);
1771
1772 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
1773
1774 }
1775 } else if ($subop == "remove") {
1776
1777 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1778
1779 $ids = split(",", $_GET["ids"]);
1780
1781 foreach ($ids as $id) {
1782 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
1783
1784 }
1785 }
1786 } else if ($subop == "add") {
1787
1788 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1789
1790 $login = db_escape_string($_GET["login"]);
1791 $tmp_user_pwd = make_password(8);
1792 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1793
1794 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
1795 VALUES ('$login', '$pwd_hash', 0)");
1796
1797
1798 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1799 login = '$login' AND pwd_hash = '$pwd_hash'");
1800
1801 if (db_num_rows($result) == 1) {
1802
1803 $new_uid = db_fetch_result($result, 0, "id");
1804
1805 print "<div class=\"notice\">Added user <b>".$_GET["login"].
1806 "</b> with password <b>$tmp_user_pwd</b>.</div>";
1807
1808 initialize_user($link, $new_uid);
1809
1810 } else {
1811
1812 print "<div class=\"warning\">Error while adding user <b>".
1813 $_GET["login"].".</b></div>";
1814
1815 }
1816 }
1817 } else if ($subop == "resetPass") {
1818
1819 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1820
1821 $uid = db_escape_string($_GET["id"]);
1822
1823 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
1824
1825 $login = db_fetch_result($result, 0, "login");
1826 $tmp_user_pwd = make_password(8);
1827 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1828
1829 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
1830 WHERE id = '$uid'");
1831
1832 print "<div class=\"notice\">Changed password of
1833 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
1834
1835 }
1836 }
1837
1838 print "<table class=\"prefAddFeed\"><tr>
1839 <td><input id=\"uadd_box\"></td>";
1840
1841 print"<td colspan=\"4\" align=\"right\">
1842 <a class=\"button\" href=\"javascript:addUser()\">Add user</a></td></tr>
1843 </table>";
1844
1845 $result = db_query($link, "SELECT
f6f32198 1846 id,login,access_level,last_login
e6cb77a0
AD
1847 FROM
1848 ttrss_users
1849 ORDER by login");
1850
1a7572cb
AD
1851 print "<div id=\"prefUserDetails\">PLACEHOLDER</div>";
1852
e6cb77a0
AD
1853 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
1854
1855 print "<tr class=\"title\">
f6f32198
AD
1856 <td width=\"5%\">Select</td>
1857 <td width='30%'>Username</td>
1858 <td width='30%'>Access Level</td>
1859 <td width='30%'>Last login</td></tr>";
e6cb77a0
AD
1860
1861 $lnum = 0;
1862
1863 while ($line = db_fetch_assoc($result)) {
1864
1865 $class = ($lnum % 2) ? "even" : "odd";
1866
1867 $uid = $line["id"];
1868 $edit_uid = $_GET["id"];
1869
1870 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
1871 $class .= "Grayed";
1872 }
1873
1874 print "<tr class=\"$class\" id=\"UMRR-$uid\">";
1875
1876 $line["login"] = htmlspecialchars($line["login"]);
1877
1878 if ($uid == $_SESSION["uid"]) {
1879
1880 print "<td><input disabled=\"true\" type=\"checkbox\"
1881 id=\"UMCHK-".$line["id"]."\"></td>";
1882
1883 print "<td>".$line["login"]."</td>";
1884 print "<td>".$line["access_level"]."</td>";
e6cb77a0
AD
1885
1886 } else if (!$edit_uid || $subop != "edit") {
1887
1888 print "<td><input onclick='toggleSelectRow(this);'
1a7572cb 1889 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
1890
1891 print "<td><a href=\"javascript:editUser($uid);\">" .
1892 $line["login"] . "</td>";
1893
1894 print "<td><a href=\"javascript:editUser($uid);\">" .
1895 $line["access_level"] . "</td>";
1896
1897 } else if ($uid != $edit_uid) {
1898
1899 print "<td><input disabled=\"true\" type=\"checkbox\"
1900 id=\"UMCHK-".$line["id"]."\"></td>";
1901
1902 print "<td>".$line["login"]."</td>";
1903 print "<td>".$line["access_level"]."</td>";
1904
1905 } else {
1906
1907 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1908
1909 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
1910 "\"></td>";
1911
1912 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
1913 "\"></td>";
1914
1915 }
1916
f6f32198
AD
1917 print "<td>".$line["last_login"]."</td>";
1918
e6cb77a0
AD
1919 print "</tr>";
1920
1921 ++$lnum;
1922 }
1923
1924 print "</table>";
1925
1926 print "<p>";
1927
1928 if ($subop == "edit") {
1929 print "Edit label:
1930 <input type=\"submit\" class=\"button\"
1931 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
1932 <input type=\"submit\" class=\"button\"
1933 onclick=\"javascript:userEditSave()\" value=\"Save\">";
1934
1935 } else {
1936
1937 print "
1938 Selection:
1939 <input type=\"submit\" class=\"button\"
717f5e64 1940 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
e6cb77a0
AD
1941 <input type=\"submit\" class=\"button\"
1942 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
1943 <input type=\"submit\" class=\"button\"
717f5e64
AD
1944 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
1945 <input type=\"submit\" class=\"button\"
1946 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
1947
1948 }
1949 }
1950
1951 if ($op == "user-details") {
1952
1953 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
1954 return;
1955 }
1956
1a7572cb 1957/* print "<html><head>
717f5e64
AD
1958 <title>Tiny Tiny RSS : User Details</title>
1959 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1960 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 1961 </head><body>"; */
717f5e64
AD
1962
1963 $uid = sprintf("%d", $_GET["id"]);
1964
717f5e64
AD
1965 print "<div class='userDetails'>";
1966
1967 $result = db_query($link, "SELECT login,last_login,access_level
1968 FROM ttrss_users
1969 WHERE id = '$uid'");
1970
1971 if (db_num_rows($result) == 0) {
1972 print "<h1>User not found</h1>";
1973 return;
1974 }
1975
1976 print "<h1>User Details</h1>";
1977
1978 print "<table width='100%'>";
1979
1980 $login = db_fetch_result($result, 0, "login");
1981 $last_login = db_fetch_result($result, 0, "last_login");
1982 $access_level = db_fetch_result($result, 0, "access_level");
1983
1984 print "<tr><td>Username</td><td>$login</td></tr>";
1985 print "<tr><td>Access level</td><td>$access_level</td></tr>";
1986 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
1987
1988 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
1989 WHERE owner_uid = '$uid'");
1990
1991 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1992
1993 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
1994
1995 $result = db_query($link, "SELECT
1996 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
1997 FROM ttrss_entries WHERE owner_uid = '$uid'");
1998
1999 $db_size = db_fetch_result($result, 0, "db_size");
2000
2001 print "<tr><td>Approx. DB size</td><td>$db_size bytes</td></tr>";
2002
2003 print "</table>";
2004
2005 print "<h1>Subscribed feeds</h1>";
2006
2007 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2008 WHERE owner_uid = '$uid'");
2009
2010 print "<ul class=\"nomarks\">";
2011
2012 while ($line = db_fetch_assoc($result)) {
2013
2014 $icon_file = ICONS_URL."/".$line["id"].".ico";
2015
2016 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2017 $feed_icon = "<img class=\"feedIcon\" src=\"$icon_file\">";
2018 } else {
2019 $feed_icon = "<img class=\"feedIcon\" src=\"images/blank_icon.gif\">";
2020 }
2021
2022 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
e6cb77a0 2023 }
717f5e64
AD
2024
2025 print "</ul>";
2026
717f5e64
AD
2027 print "</div>";
2028
1a7572cb
AD
2029 print "<div align='center'>
2030 <input type='submit' class='button'
2031 onclick=\"closeUserDetails()\" value=\"Close this window\"></div>";
2032
2033// print "</body></html>";
717f5e64 2034
e6cb77a0
AD
2035 }
2036
4b3dff6e 2037 db_close($link);
1cd17194 2038?>
406d9489
AD
2039
2040<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
2041