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