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