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