]> git.wh0rd.org - tt-rss.git/blame - backend.php
add column for slash:comments and alike in ttrss_entries (+ add upgrade scripts for...
[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
1572afe5
AD
58 function getAllCounters($link) {
59 getLabelCounters($link);
60 getFeedCounters($link);
61 getTagCounters($link);
62 getGlobalCounters($link);
63 }
64
8143ae1f
AD
65 /* FIXME this needs reworking */
66
fc69e641 67 function getGlobalCounters($link) {
4c193675
AD
68 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
69 WHERE unread = true AND
70 ttrss_user_entries.ref_id = ttrss_entries.id AND
71 owner_uid = " . $_SESSION["uid"]);
fc69e641
AD
72 $c_id = db_fetch_result($result, 0, "c_id");
73 print "<counter id='global-unread' counter='$c_id'/>";
74 }
75
bbc92e50 76 function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
0477a326
AD
77
78 if ($smart_mode) {
79 if (!$_SESSION["tctr_last_value"]) {
80 $_SESSION["tctr_last_value"] = array();
81 }
82 }
83
84 $old_counters = $_SESSION["tctr_last_value"];
85
86 $tctrs_modified = false;
87
8143ae1f 88 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
4c193675
AD
89 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
90 ttrss_user_entries.ref_id = ttrss_entries.id AND
4356293a 91 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
05732aa0 92 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
8143ae1f 93 UNION
4356293a
AD
94 select tag_name,0 as count FROM ttrss_tags
95 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
8143ae1f
AD
96
97 $tags = array();
98
99 while ($line = db_fetch_assoc($result)) {
100 $tags[$line["tag_name"]] += $line["count"];
101 }
102
103 foreach (array_keys($tags) as $tag) {
104 $unread = $tags[$tag];
105
106 $tag = htmlspecialchars($tag);
0477a326
AD
107
108 if (!$smart_mode || $old_counters[$tag] != $unread) {
109 $old_counters[$tag] = $unread;
110 $tctrs_modified = true;
111 print "<tag id=\"$tag\" counter=\"$unread\"/>";
112 }
113
8143ae1f 114 }
0477a326
AD
115
116 if ($smart_mode && $tctrs_modified) {
117 $_SESSION["tctr_last_value"] = $old_counters;
118 }
119
8143ae1f
AD
120 }
121
bbc92e50
AD
122 function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
123
124 if ($smart_mode) {
125 if (!$_SESSION["lctr_last_value"]) {
126 $_SESSION["lctr_last_value"] = array();
127 }
128 }
129
130 $old_counters = $_SESSION["lctr_last_value"];
131 $lctrs_modified = false;
090e250b 132
4c193675
AD
133 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
134 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
135 unread = true AND owner_uid = ".$_SESSION["uid"]);
090e250b 136
d61fd764 137 $count = db_fetch_result($result, 0, "count");
090e250b
AD
138
139 print "<label id=\"-1\" counter=\"$count\"/>";
140
4356293a
AD
141 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
142 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
090e250b
AD
143
144 while ($line = db_fetch_assoc($result)) {
145
146 $id = -$line["id"] - 11;
147
148 error_reporting (0);
d61fd764 149
4c193675 150 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
655be073 151 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
4c193675 152 ttrss_user_entries.ref_id = ttrss_entries.id AND
655be073 153 owner_uid = ".$_SESSION["uid"]);
090e250b 154
d61fd764 155 $count = db_fetch_result($tmp_result, 0, "count");
090e250b 156
bbc92e50
AD
157 if (!$smart_mode || $old_counters[$id] != $count) {
158 $old_counters[$id] = $count;
159 $lctrs_modified = true;
160 print "<label id=\"$id\" counter=\"$count\"/>";
161 }
090e250b 162
cce28758 163 error_reporting (DEFAULT_ERROR_LEVEL);
bbc92e50
AD
164 }
165
166 if ($smart_mode && $lctrs_modified) {
167 $_SESSION["lctr_last_value"] = $old_counters;
090e250b
AD
168 }
169 }
170
8073cce7
AD
171 function getFeedCounter($link, $id) {
172
173 $result = db_query($link, "SELECT
4c193675
AD
174 count(id) as count FROM ttrss_entries,ttrss_user_entries
175 WHERE feed_id = '$id' AND unread = true
176 AND ttrss_user_entries.ref_id = ttrss_entries.id");
8073cce7
AD
177
178 $count = db_fetch_result($result, 0, "count");
179
180 print "<feed id=\"$id\" counter=\"$count\"/>";
181 }
090e250b 182
bbc92e50 183 function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
0477a326
AD
184
185 if ($smart_mode) {
186 if (!$_SESSION["fctr_last_value"]) {
187 $_SESSION["fctr_last_value"] = array();
188 }
189 }
190
191 $old_counters = $_SESSION["fctr_last_value"];
192
090e250b 193 $result = db_query($link, "SELECT id,
4c193675
AD
194 (SELECT count(id)
195 FROM ttrss_entries,ttrss_user_entries
196 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
b88917af 197 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
4356293a 198 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
0477a326
AD
199
200 $fctrs_modified = false;
201
090e250b
AD
202 while ($line = db_fetch_assoc($result)) {
203
204 $id = $line["id"];
205 $count = $line["count"];
206
0477a326
AD
207 if (!$smart_mode || $old_counters[$id] != $count) {
208 $old_counters[$id] = $count;
209 $fctrs_modified = true;
210 print "<feed id=\"$id\" counter=\"$count\"/>";
211 }
212 }
213
214 if ($smart_mode && $fctrs_modified) {
215 $_SESSION["fctr_last_value"] = $old_counters;
090e250b
AD
216 }
217 }
218
8143ae1f 219 function outputFeedList($link, $tags = false) {
175847de 220
1a66d16e
AD
221 print "<html><head>
222 <title>Tiny Tiny RSS : Feedlist</title>
430bf183
AD
223 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
224
503eb349
AD
225 $user_theme = $_SESSION["theme"];
226 if ($user_theme) {
227 print "<link rel=\"stylesheet\" type=\"text/css\"
228 href=\"themes/$user_theme/theme.css\">";
229 }
230
4769ddaf 231 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
232 print "<link rel=\"stylesheet\" type=\"text/css\"
233 href=\"tt-rss_compact.css\"/>";
234 } else {
235 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
236 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
237 }
238
239 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
1a66d16e
AD
240 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
241 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3745788e 242 </head><body onload=\"init()\">";
254e0e4b
AD
243
244 print "<ul class=\"feedList\" id=\"feedList\">";
245
4356293a
AD
246 $owner_uid = $_SESSION["uid"];
247
8143ae1f 248 if (!$tags) {
254e0e4b 249
8143ae1f 250 /* virtual feeds */
254e0e4b 251
91ff844a
AD
252 if (get_pref($link, 'ENABLE_FEED_CATS')) {
253 print "<li class=\"feedCat\">Special</li>";
703b632e 254 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a
AD
255 }
256
8143ae1f 257 $result = db_query($link, "SELECT count(id) as num_starred
4c193675
AD
258 FROM ttrss_entries,ttrss_user_entries
259 WHERE marked = true AND
260 ttrss_user_entries.ref_id = ttrss_entries.id AND
261 unread = true AND owner_uid = '$owner_uid'");
8143ae1f 262 $num_starred = db_fetch_result($result, 0, "num_starred");
254e0e4b 263
3745788e 264 $class = "virt";
8add756a
AD
265
266 if ($num_starred > 0) $class .= "Unread";
267
268 printFeedEntry(-1, $class, "Starred articles", $num_starred,
4668523d 269 "images/mark_set.png", $link);
48f0adb0 270
91ff844a 271 if (get_pref($link, 'ENABLE_FEED_CATS')) {
703b632e 272 print "</li></ul>";
91ff844a
AD
273 }
274
cfaba6df 275 if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
8143ae1f
AD
276
277 $result = db_query($link, "SELECT id,sql_exp,description FROM
4356293a 278 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
8143ae1f
AD
279
280 if (db_num_rows($result) > 0) {
91ff844a
AD
281 if (get_pref($link, 'ENABLE_FEED_CATS')) {
282 print "<li class=\"feedCat\">Labels</li>";
703b632e 283 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a
AD
284 } else {
285 print "<li><hr></li>";
286 }
8143ae1f
AD
287 }
288
289 while ($line = db_fetch_assoc($result)) {
48f0adb0 290
8143ae1f
AD
291 error_reporting (0);
292
4c193675
AD
293 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
294 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
295 ttrss_user_entries.ref_id = ttrss_entries.id
655be073 296 AND owner_uid = '$owner_uid'");
8143ae1f
AD
297
298 $count = db_fetch_result($tmp_result, 0, "count");
299
3745788e 300 $class = "label";
8143ae1f
AD
301
302 if ($count > 0) {
303 $class .= "Unread";
304 }
305
cce28758 306 error_reporting (DEFAULT_ERROR_LEVEL);
8143ae1f
AD
307
308 printFeedEntry(-$line["id"]-11,
4668523d 309 $class, $line["description"], $count, "images/label.png", $link);
8143ae1f
AD
310
311 }
91ff844a
AD
312
313 if (db_num_rows($result) > 0) {
314 if (get_pref($link, 'ENABLE_FEED_CATS')) {
703b632e 315 print "</li></ul>";
91ff844a
AD
316 }
317 }
318
319 }
320
321// if (!get_pref($link, 'ENABLE_FEED_CATS')) {
322 print "<li><hr></li>";
323// }
324
325 if (get_pref($link, 'ENABLE_FEED_CATS')) {
326 $order_by_qpart = "category,title";
327 } else {
328 $order_by_qpart = "title";
48f0adb0 329 }
8143ae1f
AD
330
331 $result = db_query($link, "SELECT *,
4c193675
AD
332 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
333 WHERE feed_id = ttrss_feeds.id AND
334 ttrss_user_entries.ref_id = ttrss_entries.id AND
335 owner_uid = '$owner_uid') AS total,
336 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
b88917af 337 WHERE feed_id = ttrss_feeds.id AND unread = true
4c193675 338 AND ttrss_user_entries.ref_id = ttrss_entries.id
91ff844a
AD
339 AND owner_uid = '$owner_uid') as unread,
340 (SELECT title FROM ttrss_feed_categories
341 WHERE id = cat_id) AS category
342 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart");
8143ae1f
AD
343
344 $actid = $_GET["actid"];
345
346 /* real feeds */
347
348 $lnum = 0;
349
350 $total_unread = 0;
91ff844a
AD
351
352 $category = "";
8143ae1f 353
48f0adb0 354 while ($line = db_fetch_assoc($result)) {
8143ae1f
AD
355
356 $feed = $line["title"];
357 $feed_id = $line["id"];
358
359 $subop = $_GET["subop"];
360
361 $total = $line["total"];
362 $unread = $line["unread"];
91ff844a
AD
363
364 $tmp_category = $line["category"];
365
366 if (!$tmp_category) {
367 $tmp_category = "Uncategorized";
368 }
8143ae1f
AD
369
370 // $class = ($lnum % 2) ? "even" : "odd";
48f0adb0 371
3745788e 372 $class = "feed";
8143ae1f
AD
373
374 if ($unread > 0) $class .= "Unread";
375
376 if ($actid == $feed_id) {
377 $class .= "Selected";
392d4563 378 }
48f0adb0 379
8143ae1f 380 $total_unread += $unread;
91ff844a
AD
381
382 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
383
384 if ($category) {
385 print "</li></ul></li>";
386 }
387
388 $category = $tmp_category;
389
390 print "<li class=\"feedCat\">$category</li>";
703b632e 391 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a 392 }
8143ae1f 393
91ff844a
AD
394 printFeedEntry($feed_id, $class, $feed, $unread,
395 "icons/$feed_id.ico", $link);
8143ae1f
AD
396
397 ++$lnum;
48f0adb0 398 }
91ff844a 399
8143ae1f 400 } else {
a1a8a2be 401
8143ae1f 402 // tags
a1a8a2be 403
8143ae1f 404 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
05732aa0
AD
405 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
406 post_int_id = ttrss_user_entries.int_id AND
407 unread = true AND ref_id = ttrss_entries.id
3b0948c4 408 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
8143ae1f 409 UNION
3b0948c4
AD
410 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
411 ORDER BY tag_name");
8143ae1f
AD
412
413 $tags = array();
414
415 while ($line = db_fetch_assoc($result)) {
416 $tags[$line["tag_name"]] += $line["count"];
1a66d16e 417 }
8143ae1f
AD
418
419 foreach (array_keys($tags) as $tag) {
420
421 $unread = $tags[$tag];
422
83957936 423 $class = "tag";
8143ae1f
AD
424
425 if ($unread > 0) {
426 $class .= "Unread";
427 }
428
4668523d 429 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
8143ae1f
AD
430
431 }
1a66d16e 432
e828e31e 433 }
82baad4a 434
dc33ec95 435 if (db_num_rows($result) == 0) {
8037c618
AD
436 if ($tags) {
437 $what = "tags";
438 } else {
439 $what = "feeds";
440 }
441 print "<li>No $what to display.</li>";
dc33ec95
AD
442 }
443
8143ae1f 444 print "</ul>";
1cd17194 445
c3b81db0
AD
446 }
447
448
449 if ($op == "rpc") {
450
451 $subop = $_GET["subop"];
452
090e250b 453 if ($subop == "getLabelCounters") {
8073cce7 454 $aid = $_GET["aid"];
090e250b
AD
455 print "<rpc-reply>";
456 getLabelCounters($link);
8073cce7
AD
457 if ($aid) {
458 getFeedCounter($link, $aid);
459 }
090e250b
AD
460 print "</rpc-reply>";
461 }
462
463 if ($subop == "getFeedCounters") {
464 print "<rpc-reply>";
465 getFeedCounters($link);
466 print "</rpc-reply>";
467 }
468
469 if ($subop == "getAllCounters") {
470 print "<rpc-reply>";
1572afe5 471 getAllCounters($link);
090e250b 472 print "</rpc-reply>";
090e250b
AD
473 }
474
f4c10d44
AD
475 if ($subop == "mark") {
476 $mark = $_GET["mark"];
648472a7 477 $id = db_escape_string($_GET["id"]);
f4c10d44
AD
478
479 if ($mark == "1") {
480 $mark = "true";
481 } else {
482 $mark = "false";
483 }
484
b5137506
AD
485 // FIXME this needs collision testing
486
487 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
488 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
f4c10d44
AD
489 }
490
caa4e57f 491 if ($subop == "updateFeed") {
648472a7 492 $feed_id = db_escape_string($_GET["feed"]);
9cfc649a 493
648472a7 494 $result = db_query($link,
a5873b2e
AD
495 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
496 AND owner_uid = " . $_SESSION["uid"]);
9cfc649a 497
648472a7
AD
498 if (db_num_rows($result) > 0) {
499 $feed_url = db_fetch_result($result, 0, "feed_url");
a5873b2e 500 update_rss_feed($link, $feed_url, $feed_id);
caa4e57f 501 }
9cfc649a 502
a5873b2e
AD
503 print "<rpc-reply>";
504 getFeedCounter($link, $feed_id);
505 print "</rpc-reply>";
506
caa4e57f 507 return;
9cfc649a
AD
508 }
509
090e250b 510 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
c5142cca 511
05732aa0 512 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
c3b81db0 513
ab3f3f72
AD
514 $omode = $_GET["omode"];
515
516 if (!$omode) $omode = "tfl";
517
090e250b 518 print "<rpc-reply>";
ab3f3f72
AD
519 if (strchr($omode, "l")) getLabelCounters($link);
520 if (strchr($omode, "f")) getFeedCounters($link);
521 if (strchr($omode, "t")) getTagCounters($link);
fc69e641 522 getGlobalCounters($link);
090e250b 523 print "</rpc-reply>";
c3b81db0 524 }
1572afe5
AD
525
526 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
b018b49b 527 if ($subop == "catchupSelected") {
c3b81db0 528
f932bc9f 529 $ids = split(",", db_escape_string($_GET["ids"]));
c3b81db0 530
1572afe5 531 $cmode = sprintf("%d", $_GET["cmode"]);
c3b81db0 532
1572afe5 533 foreach ($ids as $id) {
c3b81db0 534
1572afe5
AD
535 if ($cmode == 0) {
536 db_query($link, "UPDATE ttrss_user_entries SET
537 unread = false,last_read = NOW()
538 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
539 } else if ($cmode == 1) {
540 db_query($link, "UPDATE ttrss_user_entries SET
541 unread = true
542 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
543 } else {
544 db_query($link, "UPDATE ttrss_user_entries SET
545 unread = NOT unread,last_read = NOW()
546 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
547 }
c3b81db0 548 }
1572afe5
AD
549 print "<rpc-reply>";
550 getAllCounters($link);
551 print "</rpc-reply>";
552 }
c3b81db0 553
1572afe5
AD
554 if ($subop == "markSelected") {
555
f932bc9f 556 $ids = split(",", db_escape_string($_GET["ids"]));
1572afe5
AD
557
558 $cmode = sprintf("%d", $_GET["cmode"]);
559
560 foreach ($ids as $id) {
561
562 if ($cmode == 0) {
563 db_query($link, "UPDATE ttrss_user_entries SET
564 marked = false
565 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
566 } else if ($cmode == 1) {
567 db_query($link, "UPDATE ttrss_user_entries SET
568 marked = true
569 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
570 } else {
571 db_query($link, "UPDATE ttrss_user_entries SET
572 marked = NOT marked
573 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
574 }
575 }
576 print "<rpc-reply>";
577 getAllCounters($link);
578 print "</rpc-reply>";
c3b81db0 579 }
295f9b42
AD
580
581 if ($subop == "sanityCheck") {
582
583 $error_code = 0;
584
585 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
586
587 $schema_version = db_fetch_result($result, 0, "schema_version");
588
589 if ($schema_version != SCHEMA_VERSION) {
590 $error_code = 5;
591 }
592
262bd8ea 593 print "<error error-code='$error_code'/>";
295f9b42 594 }
fefa6ca3
AD
595
596 if ($subop == "globalPurge") {
597
598 print "<rpc-reply>";
599 global_purge_old_posts($link, true);
600 print "</rpc-reply>";
601
602 }
603
c3b81db0
AD
604 }
605
606 if ($op == "feeds") {
607
8143ae1f
AD
608 $tags = $_GET["tags"];
609
c3b81db0
AD
610 $subop = $_GET["subop"];
611
612 if ($subop == "catchupAll") {
b018b49b 613 db_query($link, "UPDATE ttrss_user_entries SET
6d15e1ef 614 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
c3b81db0
AD
615 }
616
8143ae1f 617 outputFeedList($link, $tags);
c3b81db0 618
1cd17194
AD
619 }
620
621 if ($op == "view") {
622
d76a3b03 623 $id = $_GET["id"];
8073cce7 624 $feed_id = $_GET["feed"];
d76a3b03 625
4c193675
AD
626 $result = db_query($link, "UPDATE ttrss_user_entries
627 SET unread = false,last_read = NOW()
628 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
a1a8a2be 629
70830c87
AD
630 $addheader = $_GET["addheader"];
631
21703604 632 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
9167e250 633 SUBSTRING(updated,1,16) as updated,
21703604 634 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
4c193675
AD
635 FROM ttrss_entries,ttrss_user_entries
636 WHERE id = '$id' AND ref_id = id");
1cd17194 637
70830c87 638 if ($addheader) {
f0601b87 639 print "<html><head>
70830c87 640 <title>Tiny Tiny RSS : Article $id</title>
503eb349
AD
641 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
642
643 $user_theme = $_SESSION["theme"];
644 if ($user_theme) {
645 print "<link rel=\"stylesheet\" type=\"text/css\"
646 href=\"themes/$user_theme/theme.css\">";
647 }
648
649 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
650 print "<link rel=\"stylesheet\" type=\"text/css\"
651 href=\"tt-rss_compact.css\"/>";
652 } else {
653 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
654 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
655 }
656
657 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
70830c87 658 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87 659 </head><body>";
70830c87
AD
660 }
661
d76a3b03 662 if ($result) {
1cd17194 663
648472a7 664 $line = db_fetch_assoc($result);
1cd17194 665
b7f4bda2
AD
666 if ($line["icon_url"]) {
667 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
668 } else {
669 $feed_icon = "&nbsp;";
670 }
d76a3b03 671
f7181e9b
AD
672 if ($line["comments"] && $line["link"] != $line["comments"]) {
673 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
674 } else {
675 $entry_comments = "";
676 }
677
e828e31e
AD
678 print "<div class=\"postReply\">";
679
21703604
AD
680 print "<div class=\"postHeader\"><table width=\"100%\">";
681
9167e250
AD
682 print "<tr><td>" . $line["title"] . "</td>";
683
684 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
685 strtotime($line["updated"]));
686
687 print "<td class=\"postDate\">$parsed_updated</td>";
688
689 print "</tr>";
21703604
AD
690
691 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
692 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
693 ORDER BY tag_name");
694
695 $tags_str = "";
42918a07
AD
696 $f_tags_str = "";
697
698 $num_tags = 0;
21703604
AD
699
700 while ($tmp_line = db_fetch_assoc($tmp_result)) {
42918a07
AD
701 $num_tags++;
702 $tag = $tmp_line["tag_name"];
703 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
704
705 if ($num_tags == 5) {
706 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
707 } else if ($num_tags < 5) {
708 $tags_str .= $tag_str;
709 }
710 $f_tags_str .= $tag_str;
711 }
21703604 712
42918a07
AD
713 $tags_str = preg_replace("/, $/", "", $tags_str);
714 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
e828e31e 715
b400ca77 716 print "<tr><td width='50%'>
f7181e9b 717 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
21703604
AD
718 $entry_comments</td>
719 <td align=\"right\">$tags_str</td></tr>";
720
721/* if ($tags_str) {
722 print "<tr><td><b>Tags:</b></td>
723 <td width='100%'>$tags_str</td></tr>";
724 } */
725
e828e31e
AD
726 print "</table></div>";
727
728 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
42918a07
AD
729 print "<div class=\"postContent\">";
730
731 if (db_num_rows($tmp_result) > 5) {
732 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
733 }
734
735 print $line["content"] . "</div>";
e828e31e
AD
736
737 print "</div>";
738
090e250b 739 print "<script type=\"text/javascript\">
4f3a84f4 740 update_all_counters('$feed_id');
090e250b 741 </script>";
d76a3b03 742 }
70830c87
AD
743
744 if ($addheader) {
745 print "</body></html>";
746 }
1cd17194
AD
747 }
748
749 if ($op == "viewfeed") {
750
751 $feed = $_GET["feed"];
d76a3b03 752 $skip = $_GET["skip"];
476cac42 753 $subop = $_GET["subop"];
f175937c 754 $view_mode = $_GET["view"];
f0601b87 755 $addheader = $_GET["addheader"];
cb1083a1 756 $limit = $_GET["limit"];
adccd201
AD
757 $omode = $_GET["omode"];
758
759 if ($omode == "xml") {
760 header("Content-Type: application/xml");
761 }
a1a8a2be 762
8d7008c7 763 if (!$feed) {
8d7008c7
AD
764 return;
765 }
766
ac53063a
AD
767 if (!$skip) $skip = 0;
768
476cac42 769 if ($subop == "undefined") $subop = "";
1cd17194 770
f0601b87
AD
771 if ($addheader) {
772 print "<html><head>
ac43eba1 773 <title>Tiny Tiny RSS : Feed $feed</title>
430bf183
AD
774 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
775
503eb349
AD
776 $user_theme = $_SESSION["theme"];
777 if ($user_theme) {
778 print "<link rel=\"stylesheet\" type=\"text/css\"
779 href=\"themes/$user_theme/theme.css\">";
780 }
781
4769ddaf 782 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
783 print "<link rel=\"stylesheet\"
784 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
785
786 } else {
787 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
788 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
789 }
503eb349 790
430bf183 791 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87
AD
792 <script type=\"text/javascript\" src=\"functions.js\"></script>
793 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
b623b3ed 794 </head><body onload='init()'>";
f0601b87
AD
795 }
796
7a232fc6 797 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
dcee8f61
AD
798
799 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
800 WHERE id = '$feed'");
801
802 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
803
804 update_rss_feed($link, $feed_url, $feed);
805
806 }
807
0e32076b 808 if ($subop == "MarkAllRead") {
d76a3b03 809
7a232fc6 810 if (sprintf("%d", $feed) != 0) {
0e32076b
AD
811
812 if ($feed > 0) {
f23a2177 813 db_query($link, "UPDATE ttrss_user_entries
0e32076b 814 SET unread = false,last_read = NOW()
f23a2177 815 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
0e32076b
AD
816
817 } else if ($feed < 0 && $feed > -10) { // special, like starred
818
819 if ($feed == -1) {
f23a2177 820 db_query($link, "UPDATE ttrss_user_entries
0e32076b 821 SET unread = false,last_read = NOW()
5859be02 822 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
0e32076b
AD
823 }
824
825 } else if ($feed < -10) { // label
826
f23a2177
AD
827 // TODO make this more efficient
828
7db95187 829 $label_id = -$feed - 11;
0e32076b 830
7db95187 831 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
f23a2177 832 WHERE id = '$label_id'");
7db95187
AD
833
834 if ($tmp_result) {
835 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
836
f23a2177
AD
837 db_query($link, "BEGIN");
838
839 $tmp2_result = db_query($link,
840 "SELECT
841 int_id
842 FROM
843 ttrss_user_entries,ttrss_entries
844 WHERE
845 ref_id = id AND
846 $sql_exp AND
847 owner_uid = " . $_SESSION["uid"]);
848
849 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
850 db_query($link, "UPDATE
851 ttrss_user_entries
852 SET
853 unread = false, last_read = NOW()
854 WHERE
855 int_id = " . $tmp_line["int_id"]);
856 }
857
858 db_query($link, "COMMIT");
859
860/* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
7db95187 861 SET unread = false,last_read = NOW()
f23a2177
AD
862 WHERE $sql_exp
863 AND ref_id = id
864 AND owner_uid = ".$_SESSION["uid"]); */
7db95187 865 }
254e0e4b 866 }
0e32076b 867 } else { // tag
7eec90cf
AD
868 db_query($link, "BEGIN");
869
870 $tag_name = db_escape_string($feed);
871
872 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
873 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
874
875 while ($line = db_fetch_assoc($result)) {
876 db_query($link, "UPDATE ttrss_user_entries SET
877 unread = false, last_read = NOW()
878 WHERE int_id = " . $line["post_int_id"]);
879 }
880 db_query($link, "COMMIT");
a1a8a2be 881 }
0e32076b 882
a1a8a2be 883 }
d76a3b03 884
f932bc9f
AD
885 $search = db_escape_string($_GET["search"]);
886 $search_mode = db_escape_string($_GET["smode"]);
52b51244 887
f175937c 888 if ($search) {
ac53063a
AD
889 $search_query_part = "(upper(title) LIKE upper('%$search%')
890 OR content LIKE '%$search%') AND";
f175937c
AD
891 } else {
892 $search_query_part = "";
893 }
894
895 $view_query_part = "";
896
897 if ($view_mode == "Starred") {
898 $view_query_part = " marked = true AND ";
ac53063a
AD
899 }
900
ac43eba1
AD
901 if ($view_mode == "Unread") {
902 $view_query_part = " unread = true AND ";
903 }
904
b5aa95e7
AD
905 if ($view_mode == "Unread or Starred") {
906 $view_query_part = " (unread = true OR marked = true) AND ";
907 }
908
bdd01d3f
AD
909 if ($view_mode == "Unread or Updated") {
910 $view_query_part = " (unread = true OR last_read is NULL) AND ";
911 }
912
254e0e4b 913/* $result = db_query($link, "SELECT count(id) AS total_entries
36bf7496
AD
914 FROM ttrss_entries WHERE
915 $search_query_part
916 feed_id = '$feed'");
e6d1c0a0 917
254e0e4b 918 $total_entries = db_fetch_result($result, 0, "total_entries"); */
e6d1c0a0 919
648472a7 920/* $result = db_query("SELECT count(id) AS unread_entries
ac43eba1
AD
921 FROM ttrss_entries WHERE
922 $search_query_part
923 unread = true AND
924 feed_id = '$feed'");
925
648472a7 926 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
ac43eba1 927
8d7008c7 928 if ($limit && $limit != "All") {
82c9223c 929 $limit_query_part = "LIMIT " . $limit;
ad3cb710 930 }
f0601b87 931
254e0e4b
AD
932 $vfeed_query_part = "";
933
52b51244 934 // override query strategy and enable feed display when searching globally
d3416913 935 if ($search && $search_mode == "All feeds") {
52b51244
AD
936 $query_strategy_part = "id > 0";
937 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
938 id = feed_id) as feed_title,";
7a232fc6 939 } else if (sprintf("%d", $feed) == 0) {
8143ae1f
AD
940 $query_strategy_part = "ttrss_entries.id > 0";
941 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
942 id = feed_id) as feed_title,";
943 } else if ($feed >= 0) {
254e0e4b 944 $query_strategy_part = "feed_id = '$feed'";
48f0adb0 945 } else if ($feed == -1) { // starred virtual feed
254e0e4b 946 $query_strategy_part = "marked = true";
48f0adb0
AD
947 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
948 id = feed_id) as feed_title,";
949 } else if ($feed <= -10) { // labels
950 $label_id = -$feed - 11;
951
952 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
953 WHERE id = '$label_id'");
954
955 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
956
254e0e4b
AD
957 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
958 id = feed_id) as feed_title,";
959 } else {
48f0adb0 960 $query_strategy_part = "id > 0"; // dumb
254e0e4b
AD
961 }
962
f99321a3
AD
963 $order_by = "updated DESC";
964
965// if ($feed < -10) {
966// $order_by = "feed_id,updated DESC";
967// }
968
1572afe5
AD
969 $feed_title = "";
970
971 if ($search && $search_mode == "All feeds") {
972 $feed_title = "Search results";
7a232fc6 973 } else if (sprintf("%d", $feed) == 0) {
1572afe5
AD
974 $feed_title = $feed;
975 } else if ($feed > 0) {
976 $result = db_query($link, "SELECT title,site_url FROM ttrss_feeds
977 WHERE id = '$feed'");
978
979 $feed_title = db_fetch_result($result, 0, "title");
980 $feed_site_url = db_fetch_result($result, 0, "site_url");
981
982 } else if ($feed == -1) {
983 $feed_title = "Starred articles";
984 } else if ($feed < -10) {
985 $label_id = -$feed - 11;
986 $result = db_query($link, "SELECT description FROM ttrss_labels
987 WHERE id = '$label_id'");
988 $feed_title = db_fetch_result($result, 0, "description");
989 } else {
990 $feed_title = "?";
991 }
992
48f0adb0
AD
993 if ($feed < -10) error_reporting (0);
994
7a232fc6 995 if (sprintf("%d", $feed) != 0) {
8143ae1f 996
21703604
AD
997 if ($feed > 0) {
998 $feed_kind = "Feeds";
999 } else {
1000 $feed_kind = "Labels";
1001 }
1002
bd34c528 1003 if (!$vfeed_query_part) {
d998a8a8 1004 $content_query_part = "SUBSTRING(content,1,300) as content_preview,";
bd34c528
AD
1005 } else {
1006 $content_query_part = "";
1007 }
1008
8143ae1f 1009 $result = db_query($link, "SELECT
1572afe5
AD
1010 id,title,
1011 SUBSTRING(updated,1,16) as updated,
1012 unread,feed_id,marked,link,last_read,
8143ae1f
AD
1013 SUBSTRING(last_read,1,19) as last_read_noms,
1014 $vfeed_query_part
bd34c528
AD
1015 $content_query_part
1016 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 1017 FROM
4c193675 1018 ttrss_entries,ttrss_user_entries
8143ae1f 1019 WHERE
4c193675 1020 ttrss_user_entries.ref_id = ttrss_entries.id AND
aee86c2e 1021 owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
1022 $search_query_part
1023 $view_query_part
1024 $query_strategy_part ORDER BY $order_by
1025 $limit_query_part");
1026
1027 } else {
1028 // browsing by tag
1029
21703604
AD
1030 $feed_kind = "Tags";
1031
8143ae1f 1032 $result = db_query($link, "SELECT
1572afe5
AD
1033 ttrss_entries.id as id,title,
1034 SUBSTRING(updated,1,16) as updated,
1035 unread,feed_id,
8143ae1f 1036 marked,link,last_read,
c05a19f3 1037 SUBSTRING(last_read,1,19) as last_read_noms,
254e0e4b 1038 $vfeed_query_part
bd34c528
AD
1039 $content_query_part
1040 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 1041 FROM
05732aa0 1042 ttrss_entries,ttrss_user_entries,ttrss_tags
8143ae1f 1043 WHERE
05732aa0
AD
1044 ref_id = ttrss_entries.id AND
1045 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1046 post_int_id = int_id AND tag_name = '$feed' AND
8143ae1f
AD
1047 $view_query_part
1048 $search_query_part
1049 $query_strategy_part ORDER BY $order_by
1050 $limit_query_part");
1051 }
d76a3b03 1052
48f0adb0 1053 if (!$result) {
adccd201
AD
1054 if ($omode != "xml") {
1055 print "<div align='center'>
1056 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
1057 return;
1058 } else {
1059 print "<error error-code=\"8\"/>";
48f0adb0 1060
adccd201
AD
1061 }
1062 }
1063
f56ec297
AD
1064 if (db_num_rows($result) > 0) {
1065
adccd201
AD
1066 if ($omode != "xml") {
1067
1068 print "<table class=\"headlinesSubToolbar\"
1069 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1070
1071 print "<td class=\"headlineActions\">
1072 Select:
1073 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1074 'RROW-', 'RCHK-', true)\">All</a>,
1075 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1076 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
1077 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1078 'RROW-', 'RCHK-', false)\">None</a>
1079 &nbsp;&nbsp;
c868b154
AD
1080 Toggle: <a href=\"javascript:selectionToggleUnread()\">Unread</a>,
1081 <a href=\"javascript:selectionToggleMarked()\">Starred</a>";
adccd201
AD
1082
1083 print "</td>";
1084
1085 print "<td class=\"headlineTitle\">";
1086
1087 if ($feed_site_url) {
1088 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
1089 } else {
1090 print $feed_title;
1091 }
1092
1093 print "</td>";
1094 print "</tr></table>";
1095
1096 print "<table class=\"headlinesList\" id=\"headlinesList\"
1097 cellspacing=\"0\" width=\"100%\">";
1098
f4c10d44 1099 } else {
adccd201 1100 print "<headlines feed=\"$feed\" title=\"$feed_title\" site_url=\"$feed_site_url\">";
f4c10d44 1101 }
e5a99b88
AD
1102
1103 $lnum = 0;
1104
1105 error_reporting (DEFAULT_ERROR_LEVEL);
1106
1107 $num_unread = 0;
1108
1109 while ($line = db_fetch_assoc($result)) {
adccd201 1110
e5a99b88
AD
1111 $class = ($lnum % 2) ? "even" : "odd";
1112
1113 $id = $line["id"];
1114 $feed_id = $line["feed_id"];
1115
1116 if ($line["last_read"] == "" &&
1117 ($line["unread"] != "t" && $line["unread"] != "1")) {
1118
1119 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1120 alt=\"Updated\">";
1121 } else {
1122 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1123 alt=\"Updated\">";
1124 }
1125
1126 if ($line["unread"] == "t" || $line["unread"] == "1") {
1127 $class .= "Unread";
1128 ++$num_unread;
adccd201
AD
1129 $is_unread = 'true';
1130 } else {
1131 $is_unread = 'false';
e5a99b88
AD
1132 }
1133
1134 if ($line["marked"] == "t" || $line["marked"] == "1") {
1135 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
9932fb06 1136 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
e5a99b88
AD
1137 } else {
1138 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
9932fb06 1139 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
e5a99b88
AD
1140 }
1141
e454a889 1142 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
e5a99b88 1143 $line["title"] . "</a>";
adccd201 1144
e5a99b88
AD
1145 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1146 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1147 } else {
1148 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1149 $updated_fmt = date($short_date, strtotime($line["updated"]));
1150 }
adccd201
AD
1151
1152 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
8fd0c717
AD
1153 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1154 60);
adccd201
AD
1155 }
1156
1157 if ($omode != "xml") {
1158
1159 print "<tr class='$class' id='RROW-$id'>";
1160 // onclick=\"javascript:view($id,$feed_id)\">
1161
1162 print "<td class='hlUpdatePic'>$update_pic</td>";
1163
1164 print "<td class='hlSelectRow'>
1165 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1166 class=\"feedCheckBox\" id=\"RCHK-$id\">
1167 </td>";
1168
1169 print "<td class='hlMarkedPic'>$marked_pic</td>";
1170
1171 if ($line["feed_title"]) {
1172 print "<td class='hlContent'>$content_link</td>";
1173 print "<td class='hlFeed'>
42918a07 1174 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>&nbsp;</td>";
adccd201
AD
1175 } else {
1176 print "<td class='hlContent'>";
1177
e454a889 1178 print "<a href=\"javascript:view($id,$feed_id);\">" .
adccd201
AD
1179 $line["title"];
1180
1181 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1182
1183 if ($content_preview) {
1184 print "<span class=\"contentPreview\"> - $content_preview</span>";
1185 }
1186 }
1187
1188 print "</a>";
1189 print "</td>";
1190 }
1191
1192 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1193
1194 print "</tr>";
1195
1196 } else {
1197
1198 print "<entry unread='$is_unread' id='$id'>";
1199 print "<title><![CDATA[" . $line["title"] . "]]></title>";
1200 print "<link>" . $line["link"] . "</link>";
1201 print "<updated>$updated_fmt</updated>";
1202 if ($content_preview) {
1203 print "<preview><![CDATA[ $content_preview ]]></preview>";
1204 }
1205
1206 if ($line["feed_title"]) {
1207 print "<feed id='$feed_id'><![CDATA[" . $line["feed_title"] . "]]></feed>";
1208 }
1209 print "</entry>";
1210
1211 }
e5a99b88 1212
e5a99b88
AD
1213
1214 ++$lnum;
254e0e4b 1215 }
adccd201
AD
1216
1217 if ($omode != "xml") {
1218 print "</table>";
1219 } else {
1220 print "</headlines>";
1221 }
d76a3b03 1222
e5a99b88
AD
1223 } else {
1224 print "<div width='100%' align='center'>No articles found.</div>";
a1a8a2be 1225 }
d76a3b03 1226
adccd201 1227 if ($omode != "xml") {
d76a3b03 1228
adccd201
AD
1229 print "<script type=\"text/javascript\">
1230 document.onkeydown = hotkey_handler;
1231 update_all_counters('$feed');
1232 </script>";
1233
1234 if ($addheader) {
1235 print "</body></html>";
1236 }
f0601b87 1237 }
1cd17194
AD
1238 }
1239
0e091d38 1240 if ($op == "pref-rpc") {
331900c6 1241
0e091d38 1242 $subop = $_GET["subop"];
331900c6 1243
83fe4d6d 1244 if ($subop == "unread") {
f932bc9f 1245 $ids = split(",", db_escape_string($_GET["ids"]));
83fe4d6d 1246 foreach ($ids as $id) {
a5873b2e
AD
1247 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1248 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1249 }
0e091d38 1250
a5873b2e 1251 print "Marked selected feeds as unread.";
83fe4d6d
AD
1252 }
1253
1254 if ($subop == "read") {
f932bc9f 1255 $ids = split(",", db_escape_string($_GET["ids"]));
83fe4d6d 1256 foreach ($ids as $id) {
a5873b2e
AD
1257 db_query($link, "UPDATE ttrss_user_entries
1258 SET unread = false,last_read = NOW() WHERE
1259 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1260 }
0e091d38 1261
a5873b2e 1262 print "Marked selected feeds as read.";
0e091d38
AD
1263
1264 }
1265
1266 }
1267
1268 if ($op == "pref-feeds") {
1269
1270 $subop = $_GET["subop"];
a24f525c 1271 $quiet = $_GET["quiet"];
0e091d38 1272
508a81e1 1273 if ($subop == "editSave") {
648472a7
AD
1274 $feed_title = db_escape_string($_GET["t"]);
1275 $feed_link = db_escape_string($_GET["l"]);
d148926e 1276 $upd_intl = db_escape_string($_GET["ui"]);
5d73494a 1277 $purge_intl = db_escape_string($_GET["pi"]);
91ff844a
AD
1278 $feed_id = db_escape_string($_GET["id"]);
1279 $cat_id = db_escape_string($_GET["catid"]);
508a81e1 1280
d148926e
AD
1281 if (strtoupper($upd_intl) == "DEFAULT")
1282 $upd_intl = 0;
1283
a88c1f36
AD
1284 if (strtoupper($upd_intl) == "DISABLED")
1285 $upd_intl = -1;
1286
5d73494a
AD
1287 if (strtoupper($purge_intl) == "DEFAULT")
1288 $purge_intl = 0;
1289
140aae81
AD
1290 if (strtoupper($purge_intl) == "DISABLED")
1291 $purge_intl = -1;
1292
91ff844a
AD
1293 if ($cat_id != 0) {
1294 $category_qpart = "cat_id = '$cat_id'";
1295 } else {
1296 $category_qpart = 'cat_id = NULL';
1297 }
1298
648472a7 1299 $result = db_query($link, "UPDATE ttrss_feeds SET
91ff844a 1300 $category_qpart,
d148926e 1301 title = '$feed_title', feed_url = '$feed_link',
5d73494a 1302 update_interval = '$upd_intl',
91ff844a 1303 purge_interval = '$purge_intl'
f72dbbde 1304 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
508a81e1 1305
83fe4d6d
AD
1306 }
1307
331900c6 1308 if ($subop == "remove") {
331900c6 1309
b0b4abcf 1310 if (!WEB_DEMO_MODE) {
331900c6 1311
f932bc9f 1312 $ids = split(",", db_escape_string($_GET["ids"]));
b0b4abcf
AD
1313
1314 foreach ($ids as $id) {
f72dbbde
AD
1315 db_query($link, "DELETE FROM ttrss_feeds
1316 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
4769ddaf 1317
273a2f6b 1318 $icons_dir = ICONS_DIR;
d5caaae5 1319
4769ddaf
AD
1320 if (file_exists($icons_dir . "/$id.ico")) {
1321 unlink($icons_dir . "/$id.ico");
d5caaae5 1322 }
b0b4abcf 1323 }
331900c6
AD
1324 }
1325 }
1326
1327 if ($subop == "add") {
b0b4abcf
AD
1328
1329 if (!WEB_DEMO_MODE) {
331900c6 1330
b6b535ca 1331 $feed_link = db_escape_string(trim($_GET["link"]));
331900c6 1332
648472a7 1333 $result = db_query($link,
7e9a3986
AD
1334 "SELECT id FROM ttrss_feeds
1335 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1336
1337 if (db_num_rows($result) == 0) {
1338
1339 $result = db_query($link,
1340 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1341 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
331900c6 1342
7e9a3986
AD
1343 $result = db_query($link,
1344 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1345 AND owner_uid = " . $_SESSION["uid"]);
1346
1347 $feed_id = db_fetch_result($result, 0, "id");
1348
1349 if ($feed_id) {
ddb68b81 1350 update_rss_feed($link, $feed_link, $feed_id, true);
7e9a3986
AD
1351 }
1352 } else {
331900c6 1353
7e9a3986
AD
1354 print "<div class=\"warning\">
1355 Feed <b>$feed_link</b> already exists in the database.
1356 </div>";
b0b4abcf
AD
1357 }
1358 }
331900c6 1359 }
a0d53889 1360
91ff844a
AD
1361 if ($subop == "addCat") {
1362
1363 if (!WEB_DEMO_MODE) {
1364
1365 $feed_cat = db_escape_string(trim($_GET["cat"]));
1366
1367 $result = db_query($link,
1368 "SELECT id FROM ttrss_feed_categories
1369 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1370
1371 if (db_num_rows($result) == 0) {
1372
1373 $result = db_query($link,
1374 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1375 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1376
1377 } else {
1378
1379 print "<div class=\"warning\">
1380 Category <b>$feed_cat</b> already exists in the database.
1381 </div>";
1382 }
1383
1384
1385 }
1386 }
1387
1388 if ($subop == "removeCats") {
1389
1390 if (!WEB_DEMO_MODE) {
1391
f932bc9f 1392 $ids = split(",", db_escape_string($_GET["ids"]));
91ff844a
AD
1393
1394 foreach ($ids as $id) {
1395
1396 db_query($link, "BEGIN");
1397
1398 $result = db_query($link,
1399 "SELECT count(id) as num_feeds FROM ttrss_feeds
1400 WHERE cat_id = '$id'");
1401
1402 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1403
1404 if ($num_feeds == 0) {
1405 db_query($link, "DELETE FROM ttrss_feed_categories
1406 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1407 } else {
1408
1409 print "<div class=\"warning\">
1410 Unable to delete non empty feed categories.</div>";
1411
1412 }
1413
1414 db_query($link, "COMMIT");
1415 }
1416 }
1417 }
1418
f932bc9f
AD
1419 if ($subop == "categorize") {
1420
1421 if (!WEB_DEMO_MODE) {
1422
1423 $ids = split(",", db_escape_string($_GET["ids"]));
1424
1425 $cat_id = db_escape_string($_GET["cat_id"]);
1426
1427 if ($cat_id == 0) {
1428 $cat_id_qpart = 'NULL';
1429 } else {
1430 $cat_id_qpart = "'$cat_id'";
1431 }
1432
1433 db_query($link, "BEGIN");
1434
1435 foreach ($ids as $id) {
1436
1437 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1438 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1439 }
1440
1441 db_query($link, "COMMIT");
1442 }
1443
1444 }
1445
a24f525c
AD
1446 if ($quiet) return;
1447
c64d5b03 1448// print "<h3>Edit Feeds</h3>";
91ff844a 1449
4904f845
AD
1450 $result = db_query($link, "SELECT id,title,feed_url,last_error
1451 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1452
1453 if (db_num_rows($result) > 0) {
1454
1455 print "<div class=\"warning\">";
1456
36aab70f
AD
1457 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1458 <b>Feeds with update errors</b> (click to expand)</a>";
4904f845 1459
36aab70f 1460 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
4904f845
AD
1461
1462 while ($line = db_fetch_assoc($result)) {
1463 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1464 $line["last_error"];
1465 }
1466
1467 print "</ul>";
1468 print "</div>";
1469
1470 }
1471
f932bc9f
AD
1472 $feed_search = db_escape_string($_GET["search"]);
1473
1474 if (array_key_exists("search", $_GET)) {
1475 $_SESSION["prefs_feed_search"] = $feed_search;
1476 } else {
1477 $feed_search = $_SESSION["prefs_feed_search"];
1478 }
1479
1480 print "<table width='100%' class=\"prefGenericAddBox\"
1481 cellspacing='0' cellpadding='0'><tr>
1482 <td>
1483 <input id=\"fadd_link\"
1484 onchange=\"javascript:addFeed()\"
1485 size=\"40\">
1486 <input type=\"submit\" class=\"button\"
1487 onclick=\"javascript:addFeed()\" value=\"Add feed\">
1488 </td><td align='right'>
1489 <input id=\"feed_search\" size=\"20\"
1490 onchange=\"javascript:updateFeedList()\"
1491 value=\"$feed_search\">
1492 <input type=\"submit\" class=\"button\"
1493 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1494 </td>
1495 </tr></table>";
a0d53889 1496
b83c7545
AD
1497 $feeds_sort = db_escape_string($_GET["sort"]);
1498
1499 if (!$feeds_sort || $feeds_sort == "undefined") {
1500 $feeds_sort = $_SESSION["pref_sort_feeds"];
1501 if (!$feeds_sort) $feeds_sort = "title";
1502 }
1503
1504 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1505
f932bc9f
AD
1506 if ($feed_search) {
1507 $search_qpart = "UPPER(title) LIKE UPPER('%$feed_search%') AND";
1508 } else {
1509 $search_qpart = "";
1510 }
1511
648472a7 1512 $result = db_query($link, "SELECT
d148926e 1513 id,title,feed_url,substring(last_updated,1,16) as last_updated,
76684fc7 1514 update_interval,purge_interval,cat_id,
91ff844a
AD
1515 (SELECT title FROM ttrss_feed_categories
1516 WHERE id = cat_id) AS category
c0e5a40e 1517 FROM
f932bc9f
AD
1518 ttrss_feeds
1519 WHERE
1520 $search_qpart owner_uid = '".$_SESSION["uid"]."'
b83c7545 1521 ORDER by $feeds_sort,title");
1cd17194 1522
3b0feb9b 1523 if (db_num_rows($result) != 0) {
91ff844a 1524
3b0feb9b 1525 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
35f3c923 1526
f4fe2cde
AD
1527 print "<p><table width=\"100%\" cellspacing=\"0\"
1528 class=\"prefFeedList\" id=\"prefFeedList\">";
35f3c923
AD
1529 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1530 Select:
1531 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 1532 'FEEDR-', 'FRCHK-', true)\">All</a>,
35f3c923 1533 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 1534 'FEEDR-', 'FRCHK-', false)\">None</a>
35f3c923
AD
1535 </td</tr>";
1536
3b0feb9b 1537 print "<tr class=\"title\">
3547842a
AD
1538 <td width=\"3%\">&nbsp;</td>
1539 <td width=\"3%\">Select</td>
3b0feb9b
AD
1540 <td width=\"20%\">
1541 <a href=\"javascript:updateFeedList('title')\">Title</a></td>
1542 <td width=\"20%\">
1543 <a href=\"javascript:updateFeedList('feed_url')\">Link</a>
1544 </td>";
54d3ba50 1545
3b0feb9b
AD
1546 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1547 print "<td width=\"10%\">
1548 <a href=\"javascript:updateFeedList('category')\">Category</a></td>";
603c27f8 1549 }
603c27f8 1550
f92db4f5 1551 print "
3b0feb9b
AD
1552 <td width=\"10%\">
1553 <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a>
1554 </td>
1555 <td width=\"10%\">
1556 <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a>
1557 </td>
3b0feb9b
AD
1558 </tr>";
1559
c64d5b03
AD
1560 $lnum = 0;
1561
1562 while ($line = db_fetch_assoc($result)) {
1563
1564 $class = ($lnum % 2) ? "even" : "odd";
1565
3b0feb9b 1566 $feed_id = $line["id"];
c64d5b03 1567
3b0feb9b 1568 $edit_feed_id = $_GET["id"];
c64d5b03 1569
3b0feb9b 1570 if ($subop == "edit" && $feed_id != $edit_feed_id) {
c64d5b03 1571 $class .= "Grayed";
53226edc
AD
1572 $this_row_id = "";
1573 } else {
1574 $this_row_id = "id=\"FEEDR-$feed_id\"";
c64d5b03
AD
1575 }
1576
53226edc 1577 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1578
1579 $icon_file = ICONS_DIR . "/$feed_id.ico";
1580
1581 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1582 $feed_icon = "<img width=\"16\" height=\"16\"
1583 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1584 } else {
1585 $feed_icon = "&nbsp;";
1586 }
1587 print "<td align='center'>$feed_icon</td>";
c64d5b03
AD
1588
1589 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
3b0feb9b
AD
1590 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1591 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1592
1593 if (!$edit_cat) $edit_cat = "Uncategorized";
c64d5b03 1594
3b0feb9b 1595 if (!$edit_feed_id || $subop != "edit") {
c64d5b03
AD
1596
1597 print "<td><input onclick='toggleSelectRow(this);'
3b0feb9b 1598 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
3547842a
AD
1599
1600 $edit_title = truncate_string($edit_title, 40);
1601 $edit_link = truncate_string($edit_link, 60);
c64d5b03 1602
3b0feb9b 1603 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
c64d5b03 1604 $edit_title . "</a></td>";
3b0feb9b
AD
1605
1606 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1607 $edit_link . "</a></td>";
1608
1609 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1610 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1611 $edit_cat . "</a></td>";
1612 }
1613
1614 if ($line["update_interval"] == "0")
1615 $line["update_interval"] = "Default";
c64d5b03 1616
a88c1f36
AD
1617 if ($line["update_interval"] == "-1")
1618 $line["update_interval"] = "Disabled";
1619
3b0feb9b
AD
1620 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1621 $line["update_interval"] . "</a></td>";
1622
1623 if ($line["purge_interval"] == "0")
1624 $line["purge_interval"] = "Default";
1625
1626 if ($line["purge_interval"] < 0)
1627 $line["purge_interval"] = "Disabled";
1628
1629 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1630 $line["purge_interval"] . "</a></td>";
1631
1632 } else if ($feed_id != $edit_feed_id) {
c64d5b03
AD
1633
1634 print "<td><input disabled=\"true\" type=\"checkbox\"
1635 id=\"FRCHK-".$line["id"]."\"></td>";
3547842a
AD
1636
1637 $edit_title = truncate_string($edit_title, 40);
1638 $edit_link = truncate_string($edit_link, 60);
1639
c64d5b03 1640 print "<td>$edit_title</td>";
3b0feb9b
AD
1641 print "<td>$edit_link</td>";
1642
1643 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1644 print "<td>$edit_cat</td>";
1645 }
1646
1647 if ($line["update_interval"] == "0")
1648 $line["update_interval"] = "Default";
1649
1650 print "<td>" . $line["update_interval"] . "</td>";
1651
1652 if ($line["purge_interval"] == "0")
1653 $line["purge_interval"] = "Default";
1654
1655 if ($line["purge_interval"] < 0)
1656 $line["purge_interval"] = "Disabled";
1657
1658 print "<td>" . $line["purge_interval"] . "</td>";
c64d5b03
AD
1659
1660 } else {
1661
1662 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1663
1664 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
3b0feb9b
AD
1665 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1666
1667 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1668
1669 print "<td>";
1670 print "<select id=\"iedit_fcat\">";
1671 print "<option id=\"0\">Uncategorized</option>";
1672
1673 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1674 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1675
1676 if (db_num_rows($tmp_result) > 0) {
1677 print "<option disabled>--------</option>";
1678 }
1679
1680 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1681 if ($tmp_line["id"] == $line["cat_id"]) {
1682 $is_selected = "selected";
1683 } else {
1684 $is_selected = "";
1685 }
1686 printf("<option $is_selected id='%d'>%s</option>",
1687 $tmp_line["id"], $tmp_line["title"]);
1688 }
1689
1690 print "</select></td>";
1691 print "</td>";
1692
1693 }
c64d5b03 1694
3b0feb9b
AD
1695 print "<td><input id=\"iedit_updintl\"
1696 value=\"".$line["update_interval"]."\"></td>";
1697 print "<td><input id=\"iedit_purgintl\"
1698 value=\"".$line["purge_interval"]."\"></td>";
1699
c64d5b03 1700 }
3b0feb9b 1701
3547842a 1702/* if (!$line["last_updated"]) $line["last_updated"] = "Never";
3b0feb9b 1703
3547842a 1704 print "<td>" . $line["last_updated"] . "</td>"; */
c64d5b03
AD
1705
1706 print "</tr>";
1707
1708 ++$lnum;
1709 }
1710
c64d5b03 1711 print "</table>";
3b0feb9b 1712
c64d5b03
AD
1713 print "<p>";
1714
3b0feb9b
AD
1715 if ($subop == "edit") {
1716 print "Edit feed:&nbsp;
c64d5b03 1717 <input type=\"submit\" class=\"button\"
3b0feb9b 1718 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
c64d5b03 1719 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1720 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1721 } else {
c64d5b03
AD
1722
1723 print "
1724 Selection:&nbsp;
1725 <input type=\"submit\" class=\"button\"
3b0feb9b 1726 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
c64d5b03 1727 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1728 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1729 <input type=\"submit\" class=\"button\"
1730 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
f932bc9f
AD
1731
1732 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1733
1734 print "&nbsp;&nbsp;";
1735
1736 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1737 WHERE owner_uid = ".$_SESSION["uid"]."
1738 ORDER BY title");
1739
1740 print "<select id=\"sfeed_set_fcat\">";
1741 print "<option id=\"0\">Uncategorized</option>";
1742
1743 if (db_num_rows($result) != 0) {
1744
1745 print "<option disabled>--------</option>";
1746
1747 while ($line = db_fetch_assoc($result)) {
1748 printf("<option id='%d'>%s</option>",
1749 $line["id"], $line["title"]);
1750 }
1751 }
1752
1753 print "</select>";
1754
1755 print " <input type=\"submit\" class=\"button\"
1756 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
1757
1758 }
1759
3b0feb9b
AD
1760 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1761 print "
1762 <input type=\"submit\" class=\"button\"
4f3a84f4 1763 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
3b0feb9b 1764 <input type=\"submit\" class=\"button\"
4f3a84f4 1765 onclick=\"javascript:readSelectedFeeds(false)\"
3b0feb9b
AD
1766 value=\"Mark as unread\">&nbsp;";
1767 }
1768
1769 print "
f932bc9f 1770 &nbsp;All feeds: <input type=\"submit\"
3b0feb9b
AD
1771 class=\"button\" onclick=\"gotoExportOpml()\"
1772 value=\"Export OPML\">";
1773 }
1774 } else {
1775
1776 print "<p>No feeds defined.</p>";
1777
1778 }
1779
1780 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1781
1782 print "<h3>Edit Categories</h3>";
1783
1784 // print "<h3>Categories</h3>";
1785
1786 print "<div class=\"prefGenericAddBox\">
f932bc9f
AD
1787 <input id=\"fadd_cat\"
1788 onchange=\"javascript:addFeedCat()\"
1789 size=\"40\">&nbsp;
1790 <input
3b0feb9b
AD
1791 type=\"submit\" class=\"button\"
1792 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1793
1794 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1795 WHERE owner_uid = ".$_SESSION["uid"]."
1796 ORDER BY title");
1797
1798 if (db_num_rows($result) != 0) {
1799
35f3c923 1800 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
f4fe2cde 1801 cellspacing=\"0\" id=\"prefFeedCatList\">";
35f3c923
AD
1802
1803 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1804 Select:
1805 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 1806 'FCATR-', 'FCCHK-', true)\">All</a>,
35f3c923 1807 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 1808 'FCATR-', 'FCCHK-', false)\">None</a>
35f3c923
AD
1809 </td</tr>";
1810
3b0feb9b
AD
1811 print "<tr class=\"title\">
1812 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1813 </tr>";
1814
1815 $lnum = 0;
1816
1817 while ($line = db_fetch_assoc($result)) {
1818
1819 $class = ($lnum % 2) ? "even" : "odd";
1820
1821 $cat_id = $line["id"];
1822
1823 $edit_cat_id = $_GET["id"];
1824
1825 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1826 $class .= "Grayed";
53226edc
AD
1827 $this_row_id = "";
1828 } else {
1829 $this_row_id = "id=\"FCATR-$cat_id\"";
3b0feb9b
AD
1830 }
1831
53226edc 1832 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1833
1834 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1835
1836 if (!$edit_cat_id || $subop != "editCat") {
1837
1838 print "<td><input onclick='toggleSelectRow(this);'
1839 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1840
1841 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1842 $edit_title . "</a></td>";
1843
1844 } else if ($cat_id != $edit_cat_id) {
1845
1846 print "<td><input disabled=\"true\" type=\"checkbox\"
1847 id=\"FRCHK-".$line["id"]."\"></td>";
1848
1849 print "<td>$edit_title</td>";
1850
1851 } else {
1852
1853 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1854
1855 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1856
1857 }
1858
1859 print "</tr>";
1860
1861 ++$lnum;
1862 }
1863
1864 print "</table>";
1865
1866 print "<p>";
1867
1868 if ($subop == "editCat") {
1869 print "Edit category:&nbsp;
1870 <input type=\"submit\" class=\"button\"
1871 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1872 <input type=\"submit\" class=\"button\"
1873 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1874 } else {
1875
1876 print "
1877 Selection:&nbsp;
1878 <input type=\"submit\" class=\"button\"
1879 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1880 <input type=\"submit\" class=\"button\"
1881 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1882
1883 }
1884
1885 } else {
1886 print "<p>No feed categories defined.</p>";
1887 }
c64d5b03
AD
1888 }
1889
1890 print "<h3>Import OPML</h3>
f5a50b25
AD
1891 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1892 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1893 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1894 type=\"submit\" value=\"Import\">
1895 </form>";
1896
007bda35
AD
1897 }
1898
a0d53889
AD
1899 if ($op == "pref-filters") {
1900
1901 $subop = $_GET["subop"];
a24f525c 1902 $quiet = $_GET["quiet"];
a0d53889
AD
1903
1904 if ($subop == "editSave") {
a0d53889 1905
648472a7
AD
1906 $regexp = db_escape_string($_GET["r"]);
1907 $descr = db_escape_string($_GET["d"]);
1908 $match = db_escape_string($_GET["m"]);
1909 $filter_id = db_escape_string($_GET["id"]);
ead60402 1910 $feed_id = db_escape_string($_GET["fid"]);
19c9cb11 1911 $action_id = db_escape_string($_GET["aid"]);
ead60402
AD
1912
1913 if (!$feed_id) {
1914 $feed_id = 'NULL';
1915 } else {
1916 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1917 }
0afbd851 1918
648472a7 1919 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 1920 reg_exp = '$regexp',
0afbd851 1921 description = '$descr',
ead60402 1922 feed_id = $feed_id,
19c9cb11 1923 action_id = '$action_id',
0afbd851
AD
1924 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1925 description = '$match')
1926 WHERE id = '$filter_id'");
a0d53889
AD
1927 }
1928
1929 if ($subop == "remove") {
1930
1931 if (!WEB_DEMO_MODE) {
1932
f932bc9f 1933 $ids = split(",", db_escape_string($_GET["ids"]));
a0d53889
AD
1934
1935 foreach ($ids as $id) {
648472a7 1936 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
1937
1938 }
1939 }
1940 }
1941
1942 if ($subop == "add") {
1943
de435974 1944 if (!WEB_DEMO_MODE) {
a0d53889 1945
b6b535ca
AD
1946 $regexp = db_escape_string(trim($_GET["regexp"]));
1947 $match = db_escape_string(trim($_GET["match"]));
ead60402 1948 $feed_id = db_escape_string($_GET["fid"]);
19c9cb11 1949 $action_id = db_escape_string($_GET["aid"]);
ead60402
AD
1950
1951 if (!$feed_id) {
1952 $feed_id = 'NULL';
1953 } else {
1954 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1955 }
4401bf04 1956
648472a7 1957 $result = db_query($link,
19c9cb11
AD
1958 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
1959 action_id)
1960 VALUES
de435974 1961 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
19c9cb11
AD
1962 description = '$match'),'".$_SESSION["uid"]."',
1963 $feed_id, '$action_id')");
de435974 1964 }
a0d53889
AD
1965 }
1966
a24f525c
AD
1967 if ($quiet) return;
1968
648472a7 1969 $result = db_query($link, "SELECT description
a0d53889
AD
1970 FROM ttrss_filter_types ORDER BY description");
1971
1972 $filter_types = array();
1973
648472a7 1974 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1975 array_push($filter_types, $line["description"]);
1976 }
1977
2c7070b5 1978 print "<div class=\"prefGenericAddBox\">
7cc1e5d6 1979 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2c7070b5 1980
ead60402
AD
1981 print_select("fadd_match", "Title", $filter_types);
1982
1983 print "&nbsp;<select id=\"fadd_feed\">";
1984
1985 print "<option selected id=\"0\">All feeds</option>";
1986
1987 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1988 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1989
1990 if (db_num_rows($result) > 0) {
1991 print "<option disabled>--------</option>";
1992 }
1993
1994 while ($line = db_fetch_assoc($result)) {
1995 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1996 }
1997
2c7070b5 1998 print "</select>&nbsp;";
19c9cb11
AD
1999
2000 print "&nbsp;Action: ";
2001
2002 print "<select id=\"fadd_action\">";
2003
2004 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2005 ORDER BY name");
2006
2007 while ($line = db_fetch_assoc($result)) {
2008 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2009 }
2010
2011 print "</select>&nbsp;";
2012
2c7070b5
AD
2013 print "<input type=\"submit\"
2014 class=\"button\" onclick=\"javascript:addFilter()\"
2015 value=\"Add filter\">";
a0d53889 2016
19c9cb11
AD
2017 print "</div>";
2018
648472a7 2019 $result = db_query($link, "SELECT
ead60402
AD
2020 ttrss_filters.id AS id,reg_exp,
2021 ttrss_filters.description AS description,
2022 ttrss_filter_types.name AS filter_type_name,
2023 ttrss_filter_types.description AS filter_type_descr,
2024 feed_id,
19c9cb11 2025 ttrss_filter_actions.description AS action_description,
ead60402 2026 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
a0d53889 2027 FROM
19c9cb11 2028 ttrss_filters,ttrss_filter_types,ttrss_filter_actions
4356293a 2029 WHERE
ead60402 2030 filter_type = ttrss_filter_types.id AND
19c9cb11 2031 ttrss_filter_actions.id = action_id AND
ead60402 2032 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
4356293a 2033 ORDER by reg_exp");
a0d53889 2034
3b0feb9b 2035 if (db_num_rows($result) != 0) {
a0d53889 2036
f4fe2cde
AD
2037 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2038 id=\"prefFilterList\">";
35f3c923
AD
2039
2040 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2041 Select:
2042 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 2043 'FILRR-', 'FICHK-', true)\">All</a>,
35f3c923 2044 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 2045 'FILRR-', 'FICHK-', false)\">None</a>
35f3c923
AD
2046 </td</tr>";
2047
3b0feb9b 2048 print "<tr class=\"title\">
19c9cb11
AD
2049 <td width=\"5%\">Select</td>
2050 <td width=\"20%\">Filter expression</td>
2051 <td width=\"20%\">Feed</td>
2052 <td width=\"15%\">Match</td>
2053 <td width=\"15%\">Action</td>
3b0feb9b 2054 <td width=\"30%\">Description</td></tr>";
a0d53889 2055
3b0feb9b
AD
2056 $lnum = 0;
2057
2058 while ($line = db_fetch_assoc($result)) {
2059
2060 $class = ($lnum % 2) ? "even" : "odd";
2061
2062 $filter_id = $line["id"];
2063 $edit_filter_id = $_GET["id"];
2064
2065 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2066 $class .= "Grayed";
53226edc
AD
2067 $this_row_id = "";
2068 } else {
2069 $this_row_id = "id=\"FILRR-$filter_id\"";
ead60402 2070 }
3b0feb9b 2071
53226edc 2072 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2073
2074 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2075 $line["description"] = htmlspecialchars($line["description"]);
2076
2077 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2078
2079 if (!$edit_filter_id || $subop != "edit") {
2080
2081 if (!$line["description"]) $line["description"] = "[No description]";
2082
2083 print "<td><input onclick='toggleSelectRow(this);'
2084 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2085
2086 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2087 $line["reg_exp"] . "</td>";
2088
2089 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2090 $line["feed_title"] . "</td>";
2091
2092 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2093 $line["filter_type_descr"] . "</td>";
19c9cb11
AD
2094
2095 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2096 $line["action_description"] . "</td>";
2097
3b0feb9b
AD
2098 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2099 $line["description"] . "</td>";
2100
2101 } else if ($filter_id != $edit_filter_id) {
2102
2103 if (!$line["description"]) $line["description"] = "[No description]";
2104
2105 print "<td><input disabled=\"true\" type=\"checkbox\"
2106 id=\"FICHK-".$line["id"]."\"></td>";
2107
2108 print "<td>".$line["reg_exp"]."</td>";
2109 print "<td>".$line["feed_title"]."</td>";
2110 print "<td>".$line["filter_type_descr"]."</td>";
19c9cb11 2111 print "<td>".$line["action_description"]."</td>";
3b0feb9b 2112 print "<td>".$line["description"]."</td>";
19c9cb11 2113
3b0feb9b
AD
2114 } else {
2115
2116 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2117
2118 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2119 "\"></td>";
2120
2121 print "<td>";
3b0feb9b 2122 print "<select id=\"iedit_feed\">";
3b0feb9b
AD
2123 print "<option id=\"0\">All feeds</option>";
2124
3b0feb9b
AD
2125 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2126 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
19c9cb11
AD
2127
2128 if (db_num_rows($tmp_result) > 0) {
2129 print "<option disabled>--------</option>";
2130 }
2131
3b0feb9b
AD
2132 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2133 if ($tmp_line["id"] == $line["feed_id"]) {
2134 $is_selected = "selected";
2135 } else {
2136 $is_selected = "";
2137 }
2138 printf("<option $is_selected id='%d'>%s</option>",
2139 $tmp_line["id"], $tmp_line["title"]);
ead60402 2140 }
3b0feb9b
AD
2141
2142 print "</select></td>";
2143
2144 print "<td>";
2145 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2146 print "</td>";
19c9cb11
AD
2147
2148 print "<td>";
2149 print "<select id=\"iedit_filter_action\">";
2150
2151 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2152 ORDER BY description");
2153
2154 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2155 if ($tmp_line["description"] == $line["action_description"]) {
2156 $is_selected = "selected";
2157 } else {
2158 $is_selected = "";
2159 }
2160 printf("<option $is_selected id='%d'>%s</option>",
2161 $tmp_line["id"], $tmp_line["description"]);
2162 }
3b0feb9b 2163
19c9cb11
AD
2164 print "</select></td>";
2165
2166
3b0feb9b
AD
2167 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2168 "\"></td>";
2169
2170 print "</td>";
ead60402 2171 }
3b0feb9b
AD
2172
2173 print "</tr>";
2174
2175 ++$lnum;
a0d53889 2176 }
3b0feb9b
AD
2177
2178 if ($lnum == 0) {
2179 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2180 }
2181
2182 print "</table>";
2183
2184 print "<p>";
2185
2186 if ($subop == "edit") {
2187 print "Edit feed:
2188 <input type=\"submit\" class=\"button\"
2189 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
2190 <input type=\"submit\" class=\"button\"
2191 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
2192
2193 } else {
2194
2195 print "
2196 Selection:
e828e31e 2197 <input type=\"submit\" class=\"button\"
3b0feb9b 2198 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
e828e31e 2199 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2200 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2201 }
2202
a0d53889
AD
2203 } else {
2204
3b0feb9b
AD
2205 print "<p>No filters defined.</p>";
2206
a0d53889
AD
2207 }
2208 }
2209
80dce858
AD
2210 // We need to accept raw SQL data in label queries, so not everything is escaped
2211 // here, this is by design. If you don't like the whole idea, disable labels
2212 // altogether with GLOBAL_ENABLE_LABELS = false
2213
48f0adb0
AD
2214 if ($op == "pref-labels") {
2215
cfaba6df
AD
2216 if (!GLOBAL_ENABLE_LABELS) {
2217 return;
2218 }
2219
48f0adb0
AD
2220 $subop = $_GET["subop"];
2221
d9dde1d6
AD
2222 if ($subop == "test") {
2223
2224 $expr = $_GET["expr"];
2225 $descr = $_GET["descr"];
2226
2227 print "<div class='infoBoxContents'>";
2228
2229 print "<h1>Label &laquo;$descr&raquo;</h1>";
2230
2231// print "<p><b>Expression</b>: $expr</p>";
2232
2233 $result = db_query($link,
2234 "SELECT count(id) AS num_matches
2235 FROM ttrss_entries,ttrss_user_entries
2236 WHERE ($expr) AND
2237 ttrss_user_entries.ref_id = ttrss_entries.id AND
2238 owner_uid = " . $_SESSION["uid"]);
2239
2240 $num_matches = db_fetch_result($result, 0, "num_matches");;
2241
2242 if ($num_matches > 0) {
2243
a31a7b39 2244 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
d9dde1d6
AD
2245
2246 $result = db_query($link,
2247 "SELECT title,
2248 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2249 FROM ttrss_entries,ttrss_user_entries
2250 WHERE ($expr) AND
2251 ttrss_user_entries.ref_id = ttrss_entries.id
2252 AND owner_uid = " . $_SESSION["uid"] . "
2253 ORDER BY date_entered DESC LIMIT 5");
2254
2255 print "<ul class=\"nomarks\">";
2256 while ($line = db_fetch_assoc($result)) {
2257 print "<li>".$line["title"].
2258 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2259 }
2260 print "</ul>";
2261
2262 } else {
2263 print "<p>Query didn't return any matches.</p>";
2264 }
2265
2266 print "</div>";
2267
2268 print "<div align='center'>
2269 <input type='submit' class='button'
2270 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2271 return;
2272 }
2273
48f0adb0
AD
2274 if ($subop == "editSave") {
2275
2276 $sql_exp = $_GET["s"];
2277 $descr = $_GET["d"];
2278 $label_id = db_escape_string($_GET["id"]);
2279
2280// print "$sql_exp : $descr : $label_id";
2281
2282 $result = db_query($link, "UPDATE ttrss_labels SET
2283 sql_exp = '$sql_exp',
2284 description = '$descr'
2285 WHERE id = '$label_id'");
2286 }
2287
2288 if ($subop == "remove") {
2289
2290 if (!WEB_DEMO_MODE) {
2291
f932bc9f 2292 $ids = split(",", db_escape_string($_GET["ids"]));
48f0adb0
AD
2293
2294 foreach ($ids as $id) {
2295 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2296
2297 }
2298 }
2299 }
2300
2301 if ($subop == "add") {
2302
2303 if (!WEB_DEMO_MODE) {
2304
4401bf04
AD
2305 // no escaping is done here on purpose
2306 $exp = trim($_GET["exp"]);
48f0adb0
AD
2307
2308 $result = db_query($link,
4356293a
AD
2309 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2310 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
2311 }
2312 }
2313
2c7070b5
AD
2314 print "<div class=\"prefGenericAddBox\">
2315 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
48f0adb0 2316
2c7070b5
AD
2317 print"<input type=\"submit\" class=\"button\"
2318 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
48f0adb0
AD
2319
2320 $result = db_query($link, "SELECT
2321 id,sql_exp,description
2322 FROM
4356293a
AD
2323 ttrss_labels
2324 WHERE
2325 owner_uid = ".$_SESSION["uid"]."
2326 ORDER by description");
48f0adb0 2327
d9dde1d6
AD
2328 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2329
3b0feb9b 2330 if (db_num_rows($result) != 0) {
48f0adb0 2331
f4fe2cde
AD
2332 print "<p><table width=\"100%\" cellspacing=\"0\"
2333 class=\"prefLabelList\" id=\"prefLabelList\">";
35f3c923
AD
2334
2335 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2336 Select:
2337 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 2338 'LILRR-', 'LICHK-', true)\">All</a>,
35f3c923 2339 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 2340 'LILRR-', 'LICHK-', false)\">None</a>
35f3c923
AD
2341 </td</tr>";
2342
3b0feb9b
AD
2343 print "<tr class=\"title\">
2344 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
01c9c74a 2345 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
3b0feb9b
AD
2346 </td>
2347 <td width=\"40%\">Caption</td></tr>";
2348
2349 $lnum = 0;
2350
2351 while ($line = db_fetch_assoc($result)) {
2352
2353 $class = ($lnum % 2) ? "even" : "odd";
2354
2355 $label_id = $line["id"];
2356 $edit_label_id = $_GET["id"];
2357
2358 if ($subop == "edit" && $label_id != $edit_label_id) {
2359 $class .= "Grayed";
53226edc
AD
2360 $this_row_id = "";
2361 } else {
2362 $this_row_id = "id=\"LILRR-$label_id\"";
3b0feb9b
AD
2363 }
2364
53226edc 2365 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2366
2367 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2368 $line["description"] = htmlspecialchars($line["description"]);
2369
2370 if (!$edit_label_id || $subop != "edit") {
2371
2372 if (!$line["description"]) $line["description"] = "[No caption]";
2373
2374 print "<td><input onclick='toggleSelectRow(this);'
2375 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2376
2377 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2378 $line["sql_exp"] . "</td>";
48f0adb0 2379
3b0feb9b
AD
2380 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2381 $line["description"] . "</td>";
2382
2383 } else if ($label_id != $edit_label_id) {
2384
2385 if (!$line["description"]) $line["description"] = "[No description]";
2386
2387 print "<td><input disabled=\"true\" type=\"checkbox\"
2388 id=\"LICHK-".$line["id"]."\"></td>";
2389
2390 print "<td>".$line["sql_exp"]."</td>";
2391 print "<td>".$line["description"]."</td>";
2392
2393 } else {
2394
2395 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2396
2397 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2398 "\"></td>";
2399
2400 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2401 "\"></td>";
2402
2403 }
2404
48f0adb0 2405
3b0feb9b
AD
2406 print "</tr>";
2407
2408 ++$lnum;
2409 }
2410
2411 if ($lnum == 0) {
2412 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2413 }
2414
2415 print "</table>";
2416
2417 print "<p>";
2418
2419 if ($subop == "edit") {
2420 print "Edit label:
d9dde1d6
AD
2421 <input type=\"submit\" class=\"button\"
2422 onclick=\"javascript:labelTest()\" value=\"Test\">
3b0feb9b
AD
2423 <input type=\"submit\" class=\"button\"
2424 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2425 <input type=\"submit\" class=\"button\"
2426 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2427
2428 } else {
2429
2430 print "
2431 Selection:
48f0adb0 2432 <input type=\"submit\" class=\"button\"
3b0feb9b 2433 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
48f0adb0 2434 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2435 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2436 }
48f0adb0 2437 } else {
3b0feb9b 2438 print "<p>No labels defined.</p>";
48f0adb0
AD
2439 }
2440 }
2441
e828e31e
AD
2442 if ($op == "error") {
2443 print "<div width=\"100%\" align='center'>";
2444 $msg = $_GET["msg"];
2445 print $msg;
2446 print "</div>";
2447 }
2448
7dc66a61 2449 if ($op == "help") {
01c9c74a
AD
2450 if (!$_GET["noheaders"]) {
2451 print "<html><head>
2452 <title>Tiny Tiny RSS : Help</title>
2453 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2454 <script type=\"text/javascript\" src=\"functions.js\"></script>
2455 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2456 </head><body>";
2457 }
7dc66a61
AD
2458
2459 $tid = sprintf("%d", $_GET["tid"]);
2460
01c9c74a 2461 print "<div class='infoBoxContents'>";
7dc66a61 2462
01c9c74a
AD
2463 if (file_exists("help/$tid.php")) {
2464 include("help/$tid.php");
2465 } else {
2466 print "<p>Help topic not found.</p>";
2467 }
7dc66a61 2468
01c9c74a 2469 print "</div>";
7dc66a61
AD
2470
2471 print "<div align='center'>
01c9c74a
AD
2472 <input type='submit' class='button'
2473 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
7dc66a61 2474
01c9c74a
AD
2475 if (!$_GET["noheaders"]) {
2476 print "</body></html>";
2477 }
7dc66a61
AD
2478
2479 }
2480
f84a97a3
AD
2481 if ($op == "dlg") {
2482 $id = $_GET["id"];
6de5d056 2483 $param = $_GET["param"];
f84a97a3
AD
2484
2485 if ($id == "quickAddFeed") {
76332f3c
AD
2486 print "
2487 Feed URL: <input
033e47e0
AD
2488 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2489 id=\"qafInput\">
f84a97a3
AD
2490 <input class=\"button\"
2491 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2492 <input class=\"button\"
2493 type=\"submit\" onclick=\"javascript:closeDlg()\"
2494 value=\"Cancel\">";
2495 }
6de5d056
AD
2496
2497 if ($id == "quickDelFeed") {
2498
2499 $param = db_escape_string($param);
2500
2501 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2502
2503 if ($result) {
2504
2505 $f_title = db_fetch_result($result, 0, "title");
2506
76332f3c 2507 print "Remove current feed (<b>$f_title</b>)?&nbsp;
6de5d056
AD
2508 <input class=\"button\"
2509 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2510 <input class=\"button\"
2511 type=\"submit\" onclick=\"javascript:closeDlg()\"
2512 value=\"Cancel\">";
2513 } else {
2514 print "Error: Feed $param not found.&nbsp;
2515 <input class=\"button\"
2516 type=\"submit\" onclick=\"javascript:closeDlg()\"
2517 value=\"Cancel\">";
2518 }
2519 }
2520
033e47e0
AD
2521 if ($id == "search") {
2522
2523 print "<input id=\"searchbox\" class=\"extSearch\"
2524 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2525 onchange=\"javascript:search()\">
2526 <select id=\"searchmodebox\">
2527 <option selected>All feeds</option>
2528 <option>This feed</option>
2529 </select>
2530 <input type=\"submit\"
2531 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2532 <input class=\"button\"
2533 type=\"submit\" onclick=\"javascript:closeDlg()\"
2534 value=\"Close\">";
2535
2536 }
2537
a24f525c
AD
2538 if ($id == "quickAddFilter") {
2539
2540 $result = db_query($link, "SELECT description
2541 FROM ttrss_filter_types ORDER BY description");
2542
2543 $filter_types = array();
2544
2545 while ($line = db_fetch_assoc($result)) {
2546 array_push($filter_types, $line["description"]);
2547 }
2548
2549 print "<table>";
2550
2551 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2552
2553 print_select("fadd_match", "Title", $filter_types);
2554
2555 print "</td></tr>";
2556 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2557
2558 print "<option selected id=\"0\">All feeds</option>";
2559
2560 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2561 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2562
2563 if (db_num_rows($result) > 0) {
2564 print "<option disabled>--------</option>";
2565 }
2566
2567 while ($line = db_fetch_assoc($result)) {
2568 if ($param == $line["id"]) {
2569 $selected = "selected";
2570 } else {
2571 $selected = "";
2572 }
2573 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2574 }
2575
2576 print "</select></td></tr>";
2577
2578 print "<tr><td>Action:</td>";
2579
2580 print "<td><select id=\"fadd_action\">";
2581
2582 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2583 ORDER BY name");
2584
2585 while ($line = db_fetch_assoc($result)) {
2586 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2587 }
2588
2589 print "</select>";
2590
2591 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2592
2593 print "<input type=\"submit\"
2594 class=\"button\" onclick=\"javascript:qaddFilter()\"
2595 value=\"Add filter\"> ";
2596
2597 print "<input class=\"button\"
2598 type=\"submit\" onclick=\"javascript:closeDlg()\"
2599 value=\"Close\">";
2600
2601 print "</td></tr></table>";
2602 }
f84a97a3
AD
2603 }
2604
a2770077
AD
2605 // update feeds of all users, may be used anonymously
2606 if ($op == "globalUpdateFeeds") {
2607
2608 $result = db_query($link, "SELECT id FROM ttrss_users");
2609
2610 while ($line = db_fetch_assoc($result)) {
2611 $user_id = $line["id"];
2612// print "<!-- updating feeds of uid $user_id -->";
2613 update_all_feeds($link, false, $user_id);
2614 }
e65af9c1 2615
a2770077
AD
2616 print "<rpc-reply>
2617 <message msg=\"All feeds updated\"/>
2618 </rpc-reply>";
e65af9c1
AD
2619
2620 }
2621
77e96719
AD
2622 if ($op == "pref-prefs") {
2623
b1895692 2624 $subop = $_REQUEST["subop"];
77e96719
AD
2625
2626 if ($subop == "Save configuration") {
2627
d2892032
AD
2628 if (WEB_DEMO_MODE) {
2629 header("Location: prefs.php");
2630 return;
2631 }
01d68cf9 2632
93cb4442
AD
2633 $_SESSION["prefs_op_result"] = "save-config";
2634
77e96719
AD
2635 foreach (array_keys($_POST) as $pref_name) {
2636
2637 $pref_name = db_escape_string($pref_name);
2638 $value = db_escape_string($_POST[$pref_name]);
2639
2640 $result = db_query($link, "SELECT type_name
2641 FROM ttrss_prefs,ttrss_prefs_types
2642 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2643
2644 if (db_num_rows($result) > 0) {
2645
2646 $type_name = db_fetch_result($result, 0, "type_name");
2647
5da169d9
AD
2648// print "$pref_name : $type_name : $value<br>";
2649
77e96719 2650 if ($type_name == "bool") {
5da169d9 2651 if ($value == "1") {
77e96719
AD
2652 $value = "true";
2653 } else {
2654 $value = "false";
2655 }
2656 } else if ($type_name == "integer") {
2657 $value = sprintf("%d", $value);
2658 }
2659
2660// print "$pref_name : $type_name : $value<br>";
2661
ff485f1d
AD
2662 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2663 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
2664
2665 }
2666
2667 header("Location: prefs.php");
2668
2669 }
2670
b1895692
AD
2671 } else if ($subop == "getHelp") {
2672
2673 $pref_name = db_escape_string($_GET["pn"]);
2674
2675 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2676 WHERE pref_name = '$pref_name'");
2677
2678 if (db_num_rows($result) > 0) {
2679 $help_text = db_fetch_result($result, 0, "help_text");
2680 print $help_text;
2681 } else {
2682 print "Unknown option: $pref_name";
2683 }
2684
1c7f75ed
AD
2685 } else if ($subop == "Change password") {
2686
d2892032
AD
2687 if (WEB_DEMO_MODE) {
2688 header("Location: prefs.php");
2689 return;
2690 }
1c7f75ed
AD
2691
2692 $old_pw = $_POST["OLD_PASSWORD"];
2693 $new_pw = $_POST["OLD_PASSWORD"];
2694
2695 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2696 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2697
2698 $active_uid = $_SESSION["uid"];
2699
2700 if ($old_pw && $new_pw) {
2701
2702 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2703
2704 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2705 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2706 pwd_hash = '$old_pw_hash')");
2707
2708 if (db_num_rows($result) == 1) {
2709 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2710 WHERE id = '$active_uid'");
b791095d
AD
2711
2712 $_SESSION["pwd_change_result"] = "ok";
2713 } else {
2714 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
2715 }
2716 }
2717
2718 header("Location: prefs.php");
b791095d 2719
77e96719
AD
2720 } else if ($subop == "Reset to defaults") {
2721
d2892032
AD
2722 if (WEB_DEMO_MODE) {
2723 header("Location: prefs.php");
2724 return;
2725 }
01d68cf9 2726
93cb4442
AD
2727 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2728
e1aa0559
AD
2729 if (DB_TYPE == "pgsql") {
2730 db_query($link,"UPDATE ttrss_user_prefs
2731 SET value = ttrss_prefs.def_value
2732 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2733 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2734 } else {
2735 db_query($link, "DELETE FROM ttrss_user_prefs
2736 WHERE owner_uid = ".$_SESSION["uid"]);
2737 initialize_user_prefs($link, $_SESSION["uid"]);
2738 }
5da169d9 2739
77e96719
AD
2740 header("Location: prefs.php");
2741
58f8ad54
AD
2742 } else if ($subop == "Change theme") {
2743
2744 $theme = db_escape_string($_POST["theme"]);
2745
2746 if ($theme == "Default") {
2747 $theme_qpart = 'NULL';
2748 } else {
2749 $theme_qpart = "'$theme'";
2750 }
2751
6752e330
AD
2752 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2753 WHERE theme_name = '$theme'");
2754
2755 if (db_num_rows($result) == 1) {
2756 $theme_id = db_fetch_result($result, 0, "id");
2757 $theme_path = db_fetch_result($result, 0, "theme_path");
2758 } else {
2759 $theme_id = "NULL";
2760 $theme_path = "";
2761 }
2762
58f8ad54 2763 db_query($link, "UPDATE ttrss_users SET
6752e330 2764 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 2765
6752e330 2766 $_SESSION["theme"] = $theme_path;
503eb349 2767
58f8ad54
AD
2768 header("Location: prefs.php");
2769
77e96719
AD
2770 } else {
2771
7d4c898a 2772 if (!SINGLE_USER_MODE) {
1c7f75ed 2773
a029d530
AD
2774 $result = db_query($link, "SELECT id FROM ttrss_users
2775 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2776 pwd_hash = 'SHA1:".sha1("password")."')");
2777
2778 if (db_num_rows($result) != 0) {
b791095d 2779 print "<div class=\"warning\">
a029d530
AD
2780 Your password is at default value, please change it.
2781 </div>";
2782 }
2783
b791095d
AD
2784 if ($_SESSION["pwd_change_result"] == "failed") {
2785 print "<div class=\"warning\">
2786 There was an error while changing your password.
2787 </div>";
2788 }
2789
2790 if ($_SESSION["pwd_change_result"] == "ok") {
2791 print "<div class=\"notice\">
2792 Password changed successfully.
2793 </div>";
2794 }
2795
2796 $_SESSION["pwd_change_result"] = "";
2797
93cb4442
AD
2798 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2799 print "<div class=\"notice\">
2800 Your configuration was reset to defaults.
2801 </div>";
2802 }
2803
2804 if ($_SESSION["prefs_op_result"] == "save-config") {
2805 print "<div class=\"notice\">
2806 Your configuration was saved successfully.
2807 </div>";
2808 }
2809
2810 $_SESSION["prefs_op_result"] = "";
2811
7d4c898a
AD
2812 print "<form action=\"backend.php\" method=\"POST\">";
2813
2814 print "<table width=\"100%\" class=\"prefPrefsList\">";
2815 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2816
2817 print "<tr><td width=\"40%\">Old password</td>";
2818 print "<td><input class=\"editbox\" type=\"password\"
2819 name=\"OLD_PASSWORD\"></td></tr>";
2820
2821 print "<tr><td width=\"40%\">New password</td>";
2822
2823 print "<td><input class=\"editbox\" type=\"password\"
2824 name=\"NEW_PASSWORD\"></td></tr>";
2825
2826 print "</table>";
2827
2828 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2829
2830 print "<p><input class=\"button\" type=\"submit\"
2831 value=\"Change password\" name=\"subop\">";
2832
2833 print "</form>";
1c7f75ed 2834
7d4c898a 2835 }
1c7f75ed 2836
58f8ad54
AD
2837 $result = db_query($link, "SELECT
2838 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2839
2840 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2841
2842 $result = db_query($link, "SELECT
2843 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2844
2845 if (db_num_rows($result) > 0) {
6752e330
AD
2846
2847 print "<form action=\"backend.php\" method=\"POST\">";
2848 print "<table width=\"100%\" class=\"prefPrefsList\">";
2849 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2850 print "<tr><td width=\"40%\">Select theme</td>";
2851 print "<td><select name=\"theme\">";
2852 print "<option>Default</option>";
58f8ad54 2853 print "<option disabled>--------</option>";
6752e330 2854
58f8ad54
AD
2855 while ($line = db_fetch_assoc($result)) {
2856 if ($line["id"] == $user_theme_id) {
2857 $selected = "selected";
2858 } else {
2859 $selected = "";
2860 }
2861 print "<option $selected>" . $line["theme_name"] . "</option>";
2862 }
6752e330
AD
2863 print "</select></td></tr>";
2864 print "</table>";
2865 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2866 print "<p><input class=\"button\" type=\"submit\"
2867 value=\"Change theme\" name=\"subop\">";
2868 print "</form>";
58f8ad54
AD
2869 }
2870
77e96719 2871 $result = db_query($link, "SELECT
ff485f1d 2872 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 2873 section_name,def_value
ff485f1d 2874 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 2875 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 2876 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
2877 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2878 owner_uid = ".$_SESSION["uid"]."
650bc435 2879 ORDER BY section_id,short_desc");
77e96719
AD
2880
2881 print "<form action=\"backend.php\" method=\"POST\">";
2882
77e96719
AD
2883 $lnum = 0;
2884
2885 $active_section = "";
2886
2887 while ($line = db_fetch_assoc($result)) {
2888
2889 if ($active_section != $line["section_name"]) {
59a654ba
AD
2890
2891 if ($active_section != "") {
1c7f75ed 2892 print "</table>";
59a654ba 2893 }
1c7f75ed
AD
2894
2895 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
2896
2897 $active_section = $line["section_name"];
2898
77e96719 2899 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
2900// print "<tr class=\"title\">
2901// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
2902
2903 $lnum = 0;
77e96719
AD
2904 }
2905
650bc435 2906// $class = ($lnum % 2) ? "even" : "odd";
77e96719 2907
650bc435 2908 print "<tr>";
77e96719 2909
77e96719
AD
2910 $type_name = $line["type_name"];
2911 $pref_name = $line["pref_name"];
2912 $value = $line["value"];
2913 $def_value = $line["def_value"];
b1895692
AD
2914 $help_text = $line["help_text"];
2915
2916 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2917
2918 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2919
2920 print "</td>";
77e96719
AD
2921
2922 print "<td>";
2923
2924 if ($type_name == "bool") {
2925// print_select($pref_name, $value, array("true", "false"));
2926
2927 if ($value == "true") {
2928 $value = "Yes";
2929 } else {
2930 $value = "No";
2931 }
2932
2933 print_radio($pref_name, $value, array("Yes", "No"));
2934
2935 } else {
2936 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2937 }
2938
2939 print "</td>";
2940
2941 print "</tr>";
2942
2943 $lnum++;
2944 }
2945
2946 print "</table>";
2947
2948 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2949
2950 print "<p><input class=\"button\" type=\"submit\"
2951 name=\"subop\" value=\"Save configuration\">";
2952
2953 print "&nbsp;<input class=\"button\" type=\"submit\"
2954 name=\"subop\" value=\"Reset to defaults\"></p>";
2955
2956 print "</form>";
2957
2958 }
2959
2960 }
2961
e6cb77a0
AD
2962 if ($op == "pref-users") {
2963
2964 $subop = $_GET["subop"];
2965
2966 if ($subop == "editSave") {
2967
2968 if (!WEB_DEMO_MODE) {
2969
2970 $login = db_escape_string($_GET["l"]);
2971 $uid = db_escape_string($_GET["id"]);
2972 $access_level = sprintf("%d", $_GET["al"]);
2973
2974 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2975
2976 }
2977 } else if ($subop == "remove") {
2978
2979 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2980
f932bc9f 2981 $ids = split(",", db_escape_string($_GET["ids"]));
e6cb77a0
AD
2982
2983 foreach ($ids as $id) {
2984 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2985
2986 }
2987 }
2988 } else if ($subop == "add") {
2989
2990 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2991
b6b535ca 2992 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0
AD
2993 $tmp_user_pwd = make_password(8);
2994 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2995
2996 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2997 VALUES ('$login', '$pwd_hash', 0)");
2998
2999
3000 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3001 login = '$login' AND pwd_hash = '$pwd_hash'");
3002
3003 if (db_num_rows($result) == 1) {
3004
3005 $new_uid = db_fetch_result($result, 0, "id");
3006
3007 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3008 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3009
3010 initialize_user($link, $new_uid);
3011
3012 } else {
3013
3014 print "<div class=\"warning\">Error while adding user <b>".
3015 $_GET["login"].".</b></div>";
3016
3017 }
3018 }
3019 } else if ($subop == "resetPass") {
3020
3021 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3022
3023 $uid = db_escape_string($_GET["id"]);
3024
3025 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
3026
3027 $login = db_fetch_result($result, 0, "login");
3028 $tmp_user_pwd = make_password(8);
3029 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3030
3031 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3032 WHERE id = '$uid'");
3033
3034 print "<div class=\"notice\">Changed password of
3035 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
3036
3037 }
3038 }
3039
2c7070b5 3040 print "<div class=\"prefGenericAddBox\">
f932bc9f 3041 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\">&nbsp;";
e6cb77a0 3042
2c7070b5
AD
3043 print"<input type=\"submit\" class=\"button\"
3044 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
e6cb77a0
AD
3045
3046 $result = db_query($link, "SELECT
fe99ab12
AD
3047 id,login,access_level,
3048 SUBSTRING(last_login,1,16) as last_login
e6cb77a0
AD
3049 FROM
3050 ttrss_users
3051 ORDER by login");
3052
2317ffaa 3053 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1a7572cb 3054
f4fe2cde
AD
3055 print "<p><table width=\"100%\" cellspacing=\"0\"
3056 class=\"prefUserList\" id=\"prefUserList\">";
e6cb77a0 3057
35f3c923
AD
3058 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3059 Select:
3060 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 3061 'UMRR-', 'UMCHK-', true)\">All</a>,
35f3c923 3062 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 3063 'UMRR-', 'UMCHK-', false)\">None</a>
35f3c923
AD
3064 </td</tr>";
3065
e6cb77a0 3066 print "<tr class=\"title\">
f6f32198
AD
3067 <td width=\"5%\">Select</td>
3068 <td width='30%'>Username</td>
3069 <td width='30%'>Access Level</td>
3070 <td width='30%'>Last login</td></tr>";
e6cb77a0
AD
3071
3072 $lnum = 0;
3073
3074 while ($line = db_fetch_assoc($result)) {
3075
3076 $class = ($lnum % 2) ? "even" : "odd";
3077
3078 $uid = $line["id"];
3079 $edit_uid = $_GET["id"];
3080
3081 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
3082 $class .= "Grayed";
53226edc
AD
3083 $this_row_id = "";
3084 } else {
3085 $this_row_id = "id=\"UMRR-$uid\"";
3086 }
3087
3088 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
3089
3090 $line["login"] = htmlspecialchars($line["login"]);
3091
6be6bc03
AD
3092 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3093 strtotime($line["last_login"]));
3094
e6cb77a0
AD
3095 if ($uid == $_SESSION["uid"]) {
3096
3097 print "<td><input disabled=\"true\" type=\"checkbox\"
3098 id=\"UMCHK-".$line["id"]."\"></td>";
3099
3100 print "<td>".$line["login"]."</td>";
3101 print "<td>".$line["access_level"]."</td>";
e6cb77a0
AD
3102
3103 } else if (!$edit_uid || $subop != "edit") {
3104
3105 print "<td><input onclick='toggleSelectRow(this);'
1a7572cb 3106 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
3107
3108 print "<td><a href=\"javascript:editUser($uid);\">" .
3109 $line["login"] . "</td>";
3110
3111 print "<td><a href=\"javascript:editUser($uid);\">" .
3112 $line["access_level"] . "</td>";
3113
3114 } else if ($uid != $edit_uid) {
3115
3116 print "<td><input disabled=\"true\" type=\"checkbox\"
3117 id=\"UMCHK-".$line["id"]."\"></td>";
3118
3119 print "<td>".$line["login"]."</td>";
3120 print "<td>".$line["access_level"]."</td>";
3121
3122 } else {
3123
3124 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
3125
3126 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3127 "\"></td>";
3128
3129 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3130 "\"></td>";
3131
3132 }
3133
f6f32198
AD
3134 print "<td>".$line["last_login"]."</td>";
3135
e6cb77a0
AD
3136 print "</tr>";
3137
3138 ++$lnum;
3139 }
3140
3141 print "</table>";
3142
3143 print "<p>";
3144
3145 if ($subop == "edit") {
3146 print "Edit label:
3147 <input type=\"submit\" class=\"button\"
3148 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
3149 <input type=\"submit\" class=\"button\"
3150 onclick=\"javascript:userEditSave()\" value=\"Save\">";
3151
3152 } else {
3153
3154 print "
3155 Selection:
3156 <input type=\"submit\" class=\"button\"
717f5e64 3157 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
e6cb77a0
AD
3158 <input type=\"submit\" class=\"button\"
3159 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3160 <input type=\"submit\" class=\"button\"
717f5e64
AD
3161 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3162 <input type=\"submit\" class=\"button\"
3163 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3164
3165 }
3166 }
3167
3168 if ($op == "user-details") {
3169
3170 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3171 return;
3172 }
3173
1a7572cb 3174/* print "<html><head>
717f5e64
AD
3175 <title>Tiny Tiny RSS : User Details</title>
3176 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3177 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 3178 </head><body>"; */
717f5e64
AD
3179
3180 $uid = sprintf("%d", $_GET["id"]);
3181
c6c3a07f 3182 print "<div class='infoBoxContents'>";
717f5e64 3183
fe99ab12
AD
3184 $result = db_query($link, "SELECT login,
3185 SUBSTRING(last_login,1,16) AS last_login,
3186 access_level,
c6c3a07f
AD
3187 (SELECT COUNT(int_id) FROM ttrss_user_entries
3188 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
3189 FROM ttrss_users
3190 WHERE id = '$uid'");
3191
3192 if (db_num_rows($result) == 0) {
3193 print "<h1>User not found</h1>";
3194 return;
3195 }
3196
3197 print "<h1>User Details</h1>";
3198
3199 print "<table width='100%'>";
3200
3201 $login = db_fetch_result($result, 0, "login");
6be6bc03
AD
3202 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3203 strtotime(db_fetch_result($result, 0, "last_login")));
717f5e64 3204 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 3205 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64
AD
3206
3207 print "<tr><td>Username</td><td>$login</td></tr>";
3208 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3209 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 3210 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
3211
3212 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3213 WHERE owner_uid = '$uid'");
3214
3215 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3216
3217 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3218
5d15d3ea 3219/* $result = db_query($link, "SELECT
717f5e64 3220 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
3221 FROM ttrss_user_entries,ttrss_entries
3222 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 3223
d9f115c3 3224 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 3225
c6c3a07f 3226 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
3227
3228 print "</table>";
3229
3230 print "<h1>Subscribed feeds</h1>";
3231
e94645ca 3232 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
a88c1f36 3233 WHERE owner_uid = '$uid' ORDER BY title LIMIT 20");
717f5e64
AD
3234
3235 print "<ul class=\"nomarks\">";
3236
3237 while ($line = db_fetch_assoc($result)) {
3238
3239 $icon_file = ICONS_URL."/".$line["id"].".ico";
3240
3241 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 3242 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 3243 } else {
5951ded1 3244 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
3245 }
3246
e94645ca 3247 print "<li>$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
e6cb77a0 3248 }
717f5e64 3249
a88c1f36
AD
3250 if (db_num_rows($result) < $num_feeds) {
3251 // FIXME - add link to show ALL subscribed feeds here somewhere
3252 print "<li><img
3253 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3254 }
3255
717f5e64
AD
3256 print "</ul>";
3257
717f5e64
AD
3258 print "</div>";
3259
1a7572cb
AD
3260 print "<div align='center'>
3261 <input type='submit' class='button'
c6c3a07f 3262 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
3263
3264// print "</body></html>";
717f5e64 3265
e6cb77a0
AD
3266 }
3267
c6c3a07f
AD
3268 if ($op == "feed-details") {
3269
3270 $feed_id = $_GET["id"];
3271
3272 $result = db_query($link,
3273 "SELECT
6be6bc03
AD
3274 title,feed_url,
3275 SUBSTRING(last_updated,1,16) as last_updated,
3276 icon_url,site_url,
c6c3a07f
AD
3277 (SELECT COUNT(int_id) FROM ttrss_user_entries
3278 WHERE feed_id = id) AS total,
3279 (SELECT COUNT(int_id) FROM ttrss_user_entries
3280 WHERE feed_id = id AND unread = true) AS unread,
3281 (SELECT COUNT(int_id) FROM ttrss_user_entries
3282 WHERE feed_id = id AND marked = true) AS marked
3283 FROM ttrss_feeds
3284 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3285
3286 if (db_num_rows($result) == 0) return;
3287
3288 $title = db_fetch_result($result, 0, "title");
6be6bc03
AD
3289 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3290 strtotime(db_fetch_result($result, 0, "last_updated")));
c6c3a07f 3291 $feed_url = db_fetch_result($result, 0, "feed_url");
4fec9fd7 3292 $icon_url = db_fetch_result($result, 0, "icon_url");
c6c3a07f
AD
3293 $total = db_fetch_result($result, 0, "total");
3294 $unread = db_fetch_result($result, 0, "unread");
3295 $marked = db_fetch_result($result, 0, "marked");
f324892e 3296 $site_url = db_fetch_result($result, 0, "site_url");
4fec9fd7
AD
3297
3298 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3299 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
3300
3301 $subscribed = db_fetch_result($result, 0, "subscribed");
3302
3303 print "<div class=\"infoBoxContents\">";
3304
3305 $icon_file = ICONS_DIR . "/$feed_id.ico";
3306
3307 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3308 $feed_icon = "<img width=\"16\" height=\"16\"
3309 src=\"" . ICONS_URL . "/$feed_id.ico\">";
3310 } else {
3311 $feed_icon = "";
3312 }
3313
3314 print "<h1>$feed_icon $title</h1>";
c6c3a07f
AD
3315
3316 print "<table width='100%'>";
3317
f324892e
AD
3318 if ($site_url) {
3319 print "<tr><td width='30%'>Link</td>
3320 <td><a href=\"$site_url\">$site_url</a>
3321 <a href=\"$feed_url\">(feed)</a></td>
3322 </td></tr>";
3323 } else {
3324 print "<tr><td width='30%'>Feed URL</td>
3325 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3326 }
c6c3a07f
AD
3327 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3328 print "<tr><td>Total articles</td><td>$total</td></tr>";
3329 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3330 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
4fec9fd7 3331 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
c6c3a07f
AD
3332
3333 print "</table>";
3334
bffdddd0
AD
3335 $result = db_query($link, "SELECT title,
3336 SUBSTRING(updated,1,16) AS updated,unread
bca02305
AD
3337 FROM ttrss_entries,ttrss_user_entries
3338 WHERE ref_id = id AND feed_id = '$feed_id'
c565e1ef 3339 ORDER BY date_entered DESC LIMIT 5");
c6c3a07f 3340
bca02305
AD
3341 if (db_num_rows($result) > 0) {
3342
3343 print "<h1>Latest headlines</h1>";
c6c3a07f 3344
bca02305
AD
3345 print "<ul class=\"nomarks\">";
3346
3347 while ($line = db_fetch_assoc($result)) {
c565e1ef
AD
3348 if ($line["unread"] == "t" || $line["unread"] == "1") {
3349 $line["title"] = "<b>" . $line["title"] . "</b>";
3350 }
bca02305 3351 print "<li>" . $line["title"].
6be6bc03
AD
3352 "&nbsp;<span class=\"insensitive\">(" .
3353 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3354 strtotime($line["updated"])).
3355 ")</span></li>";
bca02305
AD
3356 }
3357
3358 print "</ul>";
3359
3360 print "</div>";
3361
3362 print "<div align='center'>
3363 <input type='submit' class='button'
3364 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3365 }
c6c3a07f
AD
3366 }
3367
4b3dff6e 3368 db_close($link);
1cd17194 3369?>
406d9489
AD
3370
3371<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3372