]> git.wh0rd.org - tt-rss.git/blame - backend.php
simplify update/purge interval selection
[tt-rss.git] / backend.php
CommitLineData
1cd17194 1<?
36bfab86
AD
2 require_once "sessions.php";
3
59b8192f 4 header("Cache-Control: no-cache, must-revalidate");
ce0619bb
AD
5 header("Pragma: no-cache");
6 header("Expires: -1");
de696427 7
cce28758
AD
8 if ($_GET["debug"]) {
9 define('DEFAULT_ERROR_LEVEL', E_ALL);
10 } else {
11 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
12 }
13
14 error_reporting(DEFAULT_ERROR_LEVEL);
15
262bd8ea
AD
16 $op = $_REQUEST["op"];
17
a2770077 18 if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
262bd8ea
AD
19 header("Content-Type: application/xml");
20 }
21
a2770077 22 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
262bd8ea 23
a2770077 24 if ($op == "rpc") {
262bd8ea 25 print "<error error-code=\"6\"/>";
04269460
AD
26 } else {
27 print "
28 <html><body>
29 <p>Error: Not logged in.</p>
30 <script type=\"text/javascript\">
31 if (parent.window != 'undefined') {
32 parent.window.location = \"login.php\";
33 } else {
34 window.location = \"login.php\";
35 }
36 </script>
37 </body></html>
38 ";
262bd8ea
AD
39 }
40 exit;
41 }
1c7f75ed 42
a2770077
AD
43 if (!$op) {
44 print "<error error-code=\"7\"/>";
45 exit;
46 }
47
70f6dbb1 48 define('SCHEMA_VERSION', 7);
1cd17194 49
66581886 50 require_once "sanity_check.php";
82baad4a 51 require_once "config.php";
648472a7 52 require_once "db.php";
3bac89ad 53 require_once "db-prefs.php";
82baad4a
AD
54 require_once "functions.php";
55 require_once "magpierss/rss_fetch.inc";
1cd17194 56
ad815c71
AD
57 $purge_intervals = array(
58 0 => "Default",
59 -1 => "Never purge",
60 5 => "1 week",
61 14 => "2 weeks",
62 31 => "1 month",
63 60 => "2 months",
64 90 => "3 months");
65
66 $update_intervals = array(
67 0 => "Default",
68 -1 => "Disable updates",
69 30 => "30 minutes",
70 60 => "1 hour",
71 240 => "4 hours",
72 720 => "12 hours",
73 1440 => "Daily",
74 10080 => "Weekly");
75
406d9489
AD
76 $script_started = getmicrotime();
77
648472a7 78 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
d76a3b03 79
5136011e
AD
80 if (!$link) {
81 if (DB_TYPE == "mysql") {
82 print mysql_error();
83 }
84 // PG seems to display its own errors just fine by default.
85 return;
86 }
87
648472a7
AD
88 if (DB_TYPE == "pgsql") {
89 pg_query("set client_encoding = 'utf-8'");
90 }
7ec2a838 91
4053b540
AD
92 if ($_SESSION["uid"]) {
93 if (get_pref($link, "HIDE_READ_FEEDS") == "true") {
94 setcookie("ttrss_vf_hreadf", 1);
95 } else {
96 setcookie("ttrss_vf_hreadf", 0);
97 }
f5de0d8d
AD
98
99 setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH);
c6784aea 100 setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON);
4053b540 101 }
7f123cda 102
331900c6 103 $fetch = $_GET["fetch"];
175847de 104
023fe037 105 setcookie("ttrss_icons_url", ICONS_URL);
b2804af7
AD
106
107 if (!sanity_check($link)) { return; }
023fe037 108
1572afe5
AD
109 function getAllCounters($link) {
110 getLabelCounters($link);
111 getFeedCounters($link);
112 getTagCounters($link);
113 getGlobalCounters($link);
280ee9a3
AD
114 if (get_pref($link, 'ENABLE_FEED_CATS')) {
115 getCategoryCounters($link);
116 }
1572afe5
AD
117 }
118
280ee9a3 119 function getCategoryCounters($link) {
987170e6
AD
120 $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
121 FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id
122 AND unread = true)) AS unread FROM ttrss_feeds
60103089
AD
123 WHERE
124 owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
280ee9a3
AD
125
126 while ($line = db_fetch_assoc($result)) {
127 $line["cat_id"] = sprintf("%d", $line["cat_id"]);
128 print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
129 $line["unread"]."\"/>";
130 }
131 }
132
0ee2d12f
AD
133 function getFeedUnread($link, $feed) {
134 $n_feed = sprintf("%d", $feed);
135
136 if ($n_feed == -1) {
137 $match_part = "marked = true";
138 } else if ($feed > 0) {
139 $match_part = "feed_id = '$n_feed'";
140 } else if ($feed < -10) {
141 $label_id = -$feed - 11;
142
143 $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
144 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
145
146 $match_part = db_fetch_result($result, 0, "sql_exp");
147 }
148
149 if ($match_part) {
150
151 $result = db_query($link, "SELECT count(int_id) AS unread
152 FROM ttrss_user_entries
153 WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]);
154
155 } else {
156
157 $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
158 FROM ttrss_tags,ttrss_user_entries
159 WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND
160 ttrss_tags.owner_uid = " . $_SESSION["uid"]);
161 }
162
163 $unread = db_fetch_result($result, 0, "unread");
164 return $unread;
165 }
166
8143ae1f
AD
167 /* FIXME this needs reworking */
168
78ea1de0 169 function getGlobalUnread($link) {
4c193675
AD
170 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
171 WHERE unread = true AND
172 ttrss_user_entries.ref_id = ttrss_entries.id AND
173 owner_uid = " . $_SESSION["uid"]);
fc69e641 174 $c_id = db_fetch_result($result, 0, "c_id");
78ea1de0
AD
175 return $c_id;
176 }
177
178 function getGlobalCounters($link, $global_unread = -1) {
179 if ($global_unread == -1) {
180 $global_unread = getGlobalUnread($link);
181 }
182 print "<counter type=\"global\" id='global-unread' counter='$global_unread'/>";
fc69e641
AD
183 }
184
bbc92e50 185 function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
0477a326
AD
186
187 if ($smart_mode) {
188 if (!$_SESSION["tctr_last_value"]) {
189 $_SESSION["tctr_last_value"] = array();
190 }
191 }
192
193 $old_counters = $_SESSION["tctr_last_value"];
194
195 $tctrs_modified = false;
196
987170e6 197/* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
4c193675
AD
198 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
199 ttrss_user_entries.ref_id = ttrss_entries.id AND
4356293a 200 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
05732aa0 201 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
8143ae1f 202 UNION
4356293a 203 select tag_name,0 as count FROM ttrss_tags
987170e6 204 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
8143ae1f 205
987170e6
AD
206 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
207 FROM ttrss_user_entries WHERE int_id = post_int_id
208 AND unread = true)) AS count FROM ttrss_tags
209 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
210
8143ae1f
AD
211 $tags = array();
212
213 while ($line = db_fetch_assoc($result)) {
214 $tags[$line["tag_name"]] += $line["count"];
215 }
216
217 foreach (array_keys($tags) as $tag) {
218 $unread = $tags[$tag];
219
220 $tag = htmlspecialchars($tag);
0477a326
AD
221
222 if (!$smart_mode || $old_counters[$tag] != $unread) {
223 $old_counters[$tag] = $unread;
224 $tctrs_modified = true;
280ee9a3 225 print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>";
0477a326
AD
226 }
227
8143ae1f 228 }
0477a326
AD
229
230 if ($smart_mode && $tctrs_modified) {
231 $_SESSION["tctr_last_value"] = $old_counters;
232 }
233
8143ae1f
AD
234 }
235
bbc92e50
AD
236 function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
237
238 if ($smart_mode) {
239 if (!$_SESSION["lctr_last_value"]) {
240 $_SESSION["lctr_last_value"] = array();
241 }
242 }
243
244 $old_counters = $_SESSION["lctr_last_value"];
245 $lctrs_modified = false;
090e250b 246
4c193675
AD
247 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
248 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
249 unread = true AND owner_uid = ".$_SESSION["uid"]);
090e250b 250
d61fd764 251 $count = db_fetch_result($result, 0, "count");
090e250b 252
280ee9a3 253 print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>";
090e250b 254
4356293a
AD
255 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
256 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
090e250b
AD
257
258 while ($line = db_fetch_assoc($result)) {
259
260 $id = -$line["id"] - 11;
261
262 error_reporting (0);
d61fd764 263
4c193675 264 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
655be073 265 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
4c193675 266 ttrss_user_entries.ref_id = ttrss_entries.id AND
655be073 267 owner_uid = ".$_SESSION["uid"]);
090e250b 268
d61fd764 269 $count = db_fetch_result($tmp_result, 0, "count");
090e250b 270
bbc92e50
AD
271 if (!$smart_mode || $old_counters[$id] != $count) {
272 $old_counters[$id] = $count;
273 $lctrs_modified = true;
280ee9a3 274 print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>";
bbc92e50 275 }
090e250b 276
cce28758 277 error_reporting (DEFAULT_ERROR_LEVEL);
bbc92e50
AD
278 }
279
280 if ($smart_mode && $lctrs_modified) {
281 $_SESSION["lctr_last_value"] = $old_counters;
090e250b
AD
282 }
283 }
284
db42b934 285/* function getFeedCounter($link, $id) {
8073cce7
AD
286
287 $result = db_query($link, "SELECT
d246bc99
AD
288 count(id) as count,last_error
289 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
4c193675 290 WHERE feed_id = '$id' AND unread = true
d246bc99 291 AND ttrss_user_entries.feed_id = ttrss_feeds.id
4c193675 292 AND ttrss_user_entries.ref_id = ttrss_entries.id");
8073cce7
AD
293
294 $count = db_fetch_result($result, 0, "count");
dd0e3728 295 $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error"));
8073cce7 296
d246bc99 297 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>";
db42b934 298 } */
090e250b 299
bbc92e50 300 function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
0477a326
AD
301
302 if ($smart_mode) {
303 if (!$_SESSION["fctr_last_value"]) {
304 $_SESSION["fctr_last_value"] = array();
305 }
306 }
307
308 $old_counters = $_SESSION["fctr_last_value"];
309
db42b934 310 $result = db_query($link, "SELECT id,last_error,parent_feed,
4c193675
AD
311 (SELECT count(id)
312 FROM ttrss_entries,ttrss_user_entries
d246bc99
AD
313 WHERE feed_id = ttrss_feeds.id AND
314 ttrss_user_entries.ref_id = ttrss_entries.id
b88917af 315 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
db42b934
AD
316 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
317 AND parent_feed IS NULL");
0477a326
AD
318
319 $fctrs_modified = false;
320
090e250b
AD
321 while ($line = db_fetch_assoc($result)) {
322
323 $id = $line["id"];
324 $count = $line["count"];
db42b934
AD
325 $last_error = htmlspecialchars($line["last_error"]);
326
023fe037
AD
327 $has_img = is_file(ICONS_DIR . "/$id.ico");
328
db42b934
AD
329 $tmp_result = db_query($link,
330 "SELECT id,COUNT(unread) AS unread
331 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
332 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
333 WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id");
334
335 if (db_num_rows($tmp_result) > 0) {
336 while ($l = db_fetch_assoc($tmp_result)) {
337 $count += $l["unread"];
338 }
339 }
340
0477a326
AD
341 if (!$smart_mode || $old_counters[$id] != $count) {
342 $old_counters[$id] = $count;
343 $fctrs_modified = true;
d246bc99
AD
344
345 if ($last_error) {
346 $error_part = "error=\"$last_error\"";
347 } else {
348 $error_part = "";
349 }
023fe037
AD
350
351 if ($has_img) {
352 $has_img_part = "hi=\"$has_img\"";
353 } else {
354 $has_img_part = "";
355 }
356
357 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part/>";
0477a326
AD
358 }
359 }
360
361 if ($smart_mode && $fctrs_modified) {
362 $_SESSION["fctr_last_value"] = $old_counters;
090e250b
AD
363 }
364 }
365
8143ae1f 366 function outputFeedList($link, $tags = false) {
175847de 367
1a66d16e
AD
368 print "<html><head>
369 <title>Tiny Tiny RSS : Feedlist</title>
430bf183
AD
370 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
371
503eb349
AD
372 $user_theme = $_SESSION["theme"];
373 if ($user_theme) {
374 print "<link rel=\"stylesheet\" type=\"text/css\"
375 href=\"themes/$user_theme/theme.css\">";
376 }
377
4769ddaf 378 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
379 print "<link rel=\"stylesheet\" type=\"text/css\"
380 href=\"tt-rss_compact.css\"/>";
381 } else {
382 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
383 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
384 }
385
386 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
1a66d16e
AD
387 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
388 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
beac550b
AD
389 <!--[if gte IE 5.5000]>
390 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
2f52ca1b 391 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
beac550b 392 <![endif]-->
97dcd654
AD
393 </head><body>
394 <script type=\"text/javascript\">
395 if (document.addEventListener) {
396 document.addEventListener(\"DOMContentLoaded\", init, null);
397 }
398 window.onload = init;
399 </script>";
254e0e4b 400
140ff9db 401 print "<ul class=\"feedList\" id=\"feedList\">\n";
254e0e4b 402
4356293a
AD
403 $owner_uid = $_SESSION["uid"];
404
8143ae1f 405 if (!$tags) {
254e0e4b 406
8143ae1f 407 /* virtual feeds */
254e0e4b 408
91ff844a 409 if (get_pref($link, 'ENABLE_FEED_CATS')) {
937881b5
AD
410 print "<li class=\"feedCat\">Special</li>";
411 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a
AD
412 }
413
8143ae1f 414 $result = db_query($link, "SELECT count(id) as num_starred
4c193675
AD
415 FROM ttrss_entries,ttrss_user_entries
416 WHERE marked = true AND
417 ttrss_user_entries.ref_id = ttrss_entries.id AND
418 unread = true AND owner_uid = '$owner_uid'");
8143ae1f 419 $num_starred = db_fetch_result($result, 0, "num_starred");
254e0e4b 420
3745788e 421 $class = "virt";
8add756a
AD
422
423 if ($num_starred > 0) $class .= "Unread";
424
425 printFeedEntry(-1, $class, "Starred articles", $num_starred,
4668523d 426 "images/mark_set.png", $link);
48f0adb0 427
91ff844a 428 if (get_pref($link, 'ENABLE_FEED_CATS')) {
140ff9db 429 print "</ul>\n";
91ff844a
AD
430 }
431
cfaba6df 432 if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
8143ae1f
AD
433
434 $result = db_query($link, "SELECT id,sql_exp,description FROM
4356293a 435 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
8143ae1f
AD
436
437 if (db_num_rows($result) > 0) {
91ff844a 438 if (get_pref($link, 'ENABLE_FEED_CATS')) {
937881b5
AD
439 print "<li class=\"feedCat\">Labels</li>";
440 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a 441 } else {
937881b5 442 print "<li><hr></li>";
91ff844a 443 }
8143ae1f
AD
444 }
445
446 while ($line = db_fetch_assoc($result)) {
48f0adb0 447
8143ae1f
AD
448 error_reporting (0);
449
280ee9a3
AD
450 $tmp_result = db_query($link, "SELECT count(id) as count
451 FROM ttrss_entries,ttrss_user_entries
4c193675
AD
452 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
453 ttrss_user_entries.ref_id = ttrss_entries.id
655be073 454 AND owner_uid = '$owner_uid'");
8143ae1f
AD
455
456 $count = db_fetch_result($tmp_result, 0, "count");
457
3745788e 458 $class = "label";
8143ae1f
AD
459
460 if ($count > 0) {
461 $class .= "Unread";
462 }
463
cce28758 464 error_reporting (DEFAULT_ERROR_LEVEL);
8143ae1f
AD
465
466 printFeedEntry(-$line["id"]-11,
4668523d 467 $class, $line["description"], $count, "images/label.png", $link);
8143ae1f
AD
468
469 }
91ff844a
AD
470
471 if (db_num_rows($result) > 0) {
472 if (get_pref($link, 'ENABLE_FEED_CATS')) {
140ff9db 473 print "</ul>";
91ff844a
AD
474 }
475 }
476
477 }
478
479// if (!get_pref($link, 'ENABLE_FEED_CATS')) {
480 print "<li><hr></li>";
481// }
482
483 if (get_pref($link, 'ENABLE_FEED_CATS')) {
484 $order_by_qpart = "category,title";
485 } else {
486 $order_by_qpart = "title";
48f0adb0 487 }
8143ae1f 488
db42b934
AD
489 $result = db_query($link, "SELECT ttrss_feeds.*,
490 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
4c193675
AD
491 WHERE feed_id = ttrss_feeds.id AND
492 ttrss_user_entries.ref_id = ttrss_entries.id AND
493 owner_uid = '$owner_uid') AS total,
db42b934 494 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
b88917af 495 WHERE feed_id = ttrss_feeds.id AND unread = true
4c193675 496 AND ttrss_user_entries.ref_id = ttrss_entries.id
91ff844a 497 AND owner_uid = '$owner_uid') as unread,
023fe037 498 cat_id,last_error,
db42b934
AD
499 ttrss_feed_categories.title AS category,
500 ttrss_feed_categories.collapsed
501 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
502 ON (ttrss_feed_categories.id = cat_id)
503 WHERE
504 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
505 ORDER BY $order_by_qpart");
506
8143ae1f
AD
507 $actid = $_GET["actid"];
508
509 /* real feeds */
510
511 $lnum = 0;
512
513 $total_unread = 0;
91ff844a
AD
514
515 $category = "";
8143ae1f 516
48f0adb0 517 while ($line = db_fetch_assoc($result)) {
8143ae1f 518
69668465 519 $feed = db_unescape_string($line["title"]);
8143ae1f
AD
520 $feed_id = $line["id"];
521
522 $subop = $_GET["subop"];
523
524 $total = $line["total"];
525 $unread = $line["unread"];
91ff844a 526
db42b934
AD
527 $tmp_result = db_query($link,
528 "SELECT id,COUNT(unread) AS unread
529 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
530 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
531 WHERE parent_feed = '$feed_id' AND unread = true
532 GROUP BY ttrss_feeds.id");
533
534 if (db_num_rows($tmp_result) > 0) {
535 while ($l = db_fetch_assoc($tmp_result)) {
536 $unread += $l["unread"];
537 }
538 }
539
fe14aeb8
AD
540 $cat_id = $line["cat_id"];
541
91ff844a
AD
542 $tmp_category = $line["category"];
543
544 if (!$tmp_category) {
545 $tmp_category = "Uncategorized";
546 }
8143ae1f
AD
547
548 // $class = ($lnum % 2) ? "even" : "odd";
023fe037
AD
549
550 if ($line["last_error"]) {
551 $class = "error";
552 } else {
553 $class = "feed";
554 }
8143ae1f
AD
555
556 if ($unread > 0) $class .= "Unread";
557
558 if ($actid == $feed_id) {
559 $class .= "Selected";
392d4563 560 }
48f0adb0 561
8143ae1f 562 $total_unread += $unread;
91ff844a
AD
563
564 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
565
566 if ($category) {
140ff9db 567 print "</ul></li>";
91ff844a
AD
568 }
569
570 $category = $tmp_category;
fe14aeb8
AD
571
572 $collapsed = $line["collapsed"];
573
65f85814
AD
574 // workaround for NULL category
575 if ($category == "Uncategorized") {
576 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
577 $collapsed = "t";
578 }
579 }
580
fe14aeb8
AD
581 if ($collapsed == "t" || $collapsed == "1") {
582 $holder_class = "invisible";
65f85814 583 $ellipsis = "...";
fe14aeb8
AD
584 } else {
585 $holder_class = "";
65f85814 586 $ellipsis = "";
280ee9a3
AD
587 }
588
589 if ($cat_id) {
590 $cat_id_qpart = "cat_id = '$cat_id'";
591 } else {
592 $cat_id_qpart = "cat_id IS NULL";
593 }
594
595 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
596 FROM ttrss_user_entries,ttrss_feeds WHERE
597 unread = true AND
598 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
599 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
600
601 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
602
603 $cat_id = sprintf("%d", $cat_id);
91ff844a 604
fe14aeb8 605 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
ff2c6e6a 606 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
99ff73f4 607 <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
280ee9a3 608 <span id=\"FCATCTR-$cat_id\"
ff2c6e6a
AD
609 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span></a>
610 <!-- <div style=\"float : right\">
611 <a href=\"javascript:viewCategory($cat_id)\">[view]</a>
612 </div> -->
613 </li>";
c3f348c2
AD
614
615 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
616 // -> keyboard navigation, etc.
96737ce9 617 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
91ff844a 618 }
8143ae1f 619
91ff844a
AD
620 printFeedEntry($feed_id, $class, $feed, $unread,
621 "icons/$feed_id.ico", $link);
8143ae1f
AD
622
623 ++$lnum;
48f0adb0 624 }
91ff844a 625
8143ae1f 626 } else {
a1a8a2be 627
8143ae1f 628 // tags
a1a8a2be 629
987170e6 630/* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
05732aa0
AD
631 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
632 post_int_id = ttrss_user_entries.int_id AND
633 unread = true AND ref_id = ttrss_entries.id
3b0948c4 634 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
8143ae1f 635 UNION
3b0948c4 636 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
987170e6
AD
637 ORDER BY tag_name"); */
638
639 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
640 FROM ttrss_user_entries WHERE int_id = post_int_id
641 AND unread = true)) AS count FROM ttrss_tags
642 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
643
8143ae1f
AD
644 $tags = array();
645
646 while ($line = db_fetch_assoc($result)) {
647 $tags[$line["tag_name"]] += $line["count"];
1a66d16e 648 }
8143ae1f
AD
649
650 foreach (array_keys($tags) as $tag) {
651
652 $unread = $tags[$tag];
653
83957936 654 $class = "tag";
8143ae1f
AD
655
656 if ($unread > 0) {
657 $class .= "Unread";
658 }
659
4668523d 660 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
8143ae1f
AD
661
662 }
1a66d16e 663
e828e31e 664 }
82baad4a 665
dc33ec95 666 if (db_num_rows($result) == 0) {
8037c618
AD
667 if ($tags) {
668 $what = "tags";
669 } else {
670 $what = "feeds";
671 }
672 print "<li>No $what to display.</li>";
dc33ec95
AD
673 }
674
8143ae1f 675 print "</ul>";
1cd17194 676
97dcd654
AD
677 print '
678 <script type="text/javascript">
679 /* for IE */
680 function statechange() {
681 if (document.readyState == "interactive") init();
682 }
683
684 if (document.readyState) {
685 if (document.readyState == "interactive" || document.readyState == "complete") {
686 init();
687 } else {
688 document.onreadystatechange = statechange;
689 }
690 }
691 </script></body></html>';
c3b81db0
AD
692 }
693
694
695 if ($op == "rpc") {
696
697 $subop = $_GET["subop"];
698
7f123cda
AD
699 if ($subop == "setpref") {
700 if (WEB_DEMO_MODE) {
701 return;
702 }
703
704 print "<rpc-reply>";
705
706 $key = db_escape_string($_GET["key"]);
707 $value = db_escape_string($_GET["value"]);
708
709 set_pref($link, $key, $value);
710
711 print "<param-set key=\"$key\" value=\"$value\"/>";
712
713 print "</rpc-reply>";
714
715 }
716
090e250b 717 if ($subop == "getLabelCounters") {
8073cce7 718 $aid = $_GET["aid"];
090e250b
AD
719 print "<rpc-reply>";
720 getLabelCounters($link);
8073cce7
AD
721 if ($aid) {
722 getFeedCounter($link, $aid);
723 }
090e250b
AD
724 print "</rpc-reply>";
725 }
726
727 if ($subop == "getFeedCounters") {
728 print "<rpc-reply>";
729 getFeedCounters($link);
730 print "</rpc-reply>";
731 }
732
733 if ($subop == "getAllCounters") {
734 print "<rpc-reply>";
1572afe5 735 getAllCounters($link);
090e250b 736 print "</rpc-reply>";
090e250b
AD
737 }
738
f4c10d44
AD
739 if ($subop == "mark") {
740 $mark = $_GET["mark"];
648472a7 741 $id = db_escape_string($_GET["id"]);
f4c10d44
AD
742
743 if ($mark == "1") {
744 $mark = "true";
745 } else {
746 $mark = "false";
747 }
748
b5137506
AD
749 // FIXME this needs collision testing
750
751 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
752 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
f4c10d44
AD
753 }
754
caa4e57f 755 if ($subop == "updateFeed") {
648472a7 756 $feed_id = db_escape_string($_GET["feed"]);
9cfc649a 757
648472a7 758 $result = db_query($link,
a5873b2e
AD
759 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
760 AND owner_uid = " . $_SESSION["uid"]);
9cfc649a 761
648472a7
AD
762 if (db_num_rows($result) > 0) {
763 $feed_url = db_fetch_result($result, 0, "feed_url");
a5873b2e 764 update_rss_feed($link, $feed_url, $feed_id);
caa4e57f 765 }
9cfc649a 766
a5873b2e
AD
767 print "<rpc-reply>";
768 getFeedCounter($link, $feed_id);
769 print "</rpc-reply>";
770
caa4e57f 771 return;
9cfc649a
AD
772 }
773
090e250b 774 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
9d1ef64e 775
085a5a74 776 if (ENABLE_UPDATE_DAEMON) {
c3b81db0 777
b8a6ff30 778 if ($subop == "forceUpdateAllFeeds") {
8b911251 779
b8a6ff30
AD
780 $result = db_query($link, "SELECT count(id) AS cid FROM
781 ttrss_scheduled_updates WHERE feed_id IS NULL AND
782 owner_uid = " . $_SESSION["uid"]);
783
784 $cid = db_fetch_result($result, 0, "cid");
785
786# print "<rpc-reply>";
787
788 if ($cid == 0) {
789
790 db_query($link, "INSERT INTO ttrss_scheduled_updates
791 (owner_uid, feed_id, entered) VALUES
792 (".$_SESSION["uid"].", NULL, NOW())");
793
36cf32bc 794// print "<!-- ScheduledOK -->";
8b911251 795
b8a6ff30 796 } else {
36cf32bc 797// print "<!-- RequestAlreadyInQueue -->";
b8a6ff30
AD
798 }
799
800# print "</rpc-reply>";
8b911251 801 }
1f4ad53c 802
cd907b7c 803 } else {
1f4ad53c
AD
804 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
805 }
806
78ea1de0
AD
807 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
808 $global_unread = getGlobalUnread($link);
cd907b7c 809
085a5a74 810 print "<rpc-reply>";
78ea1de0
AD
811
812 if ($global_unread_caller != $global_unread) {
813
814 $omode = $_GET["omode"];
815
2bf6e0a8 816 if (!$omode) $omode = "tflc";
78ea1de0
AD
817
818 if (strchr($omode, "l")) getLabelCounters($link);
819 if (strchr($omode, "f")) getFeedCounters($link);
820 if (strchr($omode, "t")) getTagCounters($link);
2bf6e0a8
AD
821 if (strchr($omode, "c")) {
822 if (get_pref($link, 'ENABLE_FEED_CATS')) {
823 getCategoryCounters($link);
824 }
825 }
601a5e04 826 }
e50d3212
AD
827
828 getGlobalCounters($link, $global_unread);
829
085a5a74
AD
830 print "</rpc-reply>";
831
c3b81db0 832 }
1572afe5
AD
833
834 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
b018b49b 835 if ($subop == "catchupSelected") {
c3b81db0 836
f932bc9f 837 $ids = split(",", db_escape_string($_GET["ids"]));
c3b81db0 838
1572afe5 839 $cmode = sprintf("%d", $_GET["cmode"]);
c3b81db0 840
1572afe5 841 foreach ($ids as $id) {
c3b81db0 842
1572afe5
AD
843 if ($cmode == 0) {
844 db_query($link, "UPDATE ttrss_user_entries SET
845 unread = false,last_read = NOW()
846 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
847 } else if ($cmode == 1) {
848 db_query($link, "UPDATE ttrss_user_entries SET
849 unread = true
850 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
851 } else {
852 db_query($link, "UPDATE ttrss_user_entries SET
853 unread = NOT unread,last_read = NOW()
854 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
855 }
c3b81db0 856 }
1572afe5
AD
857 print "<rpc-reply>";
858 getAllCounters($link);
859 print "</rpc-reply>";
860 }
c3b81db0 861
1572afe5
AD
862 if ($subop == "markSelected") {
863
f932bc9f 864 $ids = split(",", db_escape_string($_GET["ids"]));
1572afe5
AD
865
866 $cmode = sprintf("%d", $_GET["cmode"]);
867
868 foreach ($ids as $id) {
869
870 if ($cmode == 0) {
871 db_query($link, "UPDATE ttrss_user_entries SET
872 marked = false
873 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
874 } else if ($cmode == 1) {
875 db_query($link, "UPDATE ttrss_user_entries SET
876 marked = true
877 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
878 } else {
879 db_query($link, "UPDATE ttrss_user_entries SET
880 marked = NOT marked
881 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
882 }
883 }
884 print "<rpc-reply>";
885 getAllCounters($link);
886 print "</rpc-reply>";
c3b81db0 887 }
295f9b42
AD
888
889 if ($subop == "sanityCheck") {
bc236938
AD
890 if (sanity_check($link)) {
891 print "<error error-code=\"0\"/>";
892 }
295f9b42 893 }
fefa6ca3
AD
894
895 if ($subop == "globalPurge") {
896
897 print "<rpc-reply>";
898 global_purge_old_posts($link, true);
899 print "</rpc-reply>";
900
901 }
902
c3b81db0
AD
903 }
904
905 if ($op == "feeds") {
906
8143ae1f
AD
907 $tags = $_GET["tags"];
908
c3b81db0
AD
909 $subop = $_GET["subop"];
910
911 if ($subop == "catchupAll") {
b018b49b 912 db_query($link, "UPDATE ttrss_user_entries SET
6d15e1ef 913 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
c3b81db0
AD
914 }
915
fe14aeb8
AD
916 if ($subop == "collapse") {
917 $cat_id = db_escape_string($_GET["cid"]);
280ee9a3 918
fe14aeb8
AD
919 db_query($link, "UPDATE ttrss_feed_categories SET
920 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
921 $_SESSION["uid"]);
922 return;
923 }
924
8143ae1f 925 outputFeedList($link, $tags);
c3b81db0 926
1cd17194
AD
927 }
928
929 if ($op == "view") {
930
70f6dbb1
AD
931 $id = db_escape_string($_GET["id"]);
932 $feed_id = db_escape_string($_GET["feed"]);
933
934 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
935 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
936
937 if (db_num_rows($result) == 1) {
938 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
939 } else {
940 $rtl_content = false;
941 }
942
943 if ($rtl_content) {
944 $rtl_tag = "dir=\"RTL\"";
945 } else {
946 $rtl_tag = "";
947 }
d76a3b03 948
4c193675
AD
949 $result = db_query($link, "UPDATE ttrss_user_entries
950 SET unread = false,last_read = NOW()
951 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
a1a8a2be 952
21703604 953 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
9167e250 954 SUBSTRING(updated,1,16) as updated,
11b0dce2 955 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
a545b564
AD
956 num_comments,
957 author
4c193675
AD
958 FROM ttrss_entries,ttrss_user_entries
959 WHERE id = '$id' AND ref_id = id");
1cd17194 960
59b8192f
AD
961 print "<html><head>
962 <title>Tiny Tiny RSS : Article $id</title>
963 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
503eb349 964
59b8192f
AD
965 $user_theme = $_SESSION["theme"];
966 if ($user_theme) {
967 print "<link rel=\"stylesheet\" type=\"text/css\"
968 href=\"themes/$user_theme/theme.css\">";
969 }
503eb349 970
59b8192f
AD
971 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
972 print "<link rel=\"stylesheet\" type=\"text/css\"
973 href=\"tt-rss_compact.css\"/>";
974 } else {
975 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
976 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
70830c87
AD
977 }
978
59b8192f
AD
979 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
980 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
70f6dbb1 981 </head><body $rtl_tag>";
59b8192f 982
d76a3b03 983 if ($result) {
1cd17194 984
648472a7 985 $line = db_fetch_assoc($result);
1cd17194 986
b7f4bda2
AD
987 if ($line["icon_url"]) {
988 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
989 } else {
990 $feed_icon = "&nbsp;";
991 }
d76a3b03 992
11b0dce2 993/* if ($line["comments"] && $line["link"] != $line["comments"]) {
f7181e9b
AD
994 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
995 } else {
996 $entry_comments = "";
11b0dce2
AD
997 } */
998
999 $num_comments = $line["num_comments"];
1000 $entry_comments = "";
1001
1002 if ($num_comments > 0) {
1003 if ($line["comments"]) {
1004 $comments_url = $line["comments"];
1005 } else {
1006 $comments_url = $line["link"];
1007 }
6a1ad084 1008 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
11b0dce2
AD
1009 } else {
1010 if ($line["comments"] && $line["link"] != $line["comments"]) {
672366bd 1011 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
11b0dce2 1012 }
f7181e9b
AD
1013 }
1014
e828e31e
AD
1015 print "<div class=\"postReply\">";
1016
21703604
AD
1017 print "<div class=\"postHeader\"><table width=\"100%\">";
1018
a545b564
AD
1019 $entry_author = $line["author"];
1020
1021 if ($entry_author) {
1022 $entry_author = " - by $entry_author";
1023 }
1024
1025 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] .
1026 "</a>$entry_author</td>";
9167e250
AD
1027
1028 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
1029 strtotime($line["updated"]));
1030
1031 print "<td class=\"postDate\">$parsed_updated</td>";
1032
1033 print "</tr>";
21703604
AD
1034
1035 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
1036 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
1037 ORDER BY tag_name");
1038
1039 $tags_str = "";
42918a07
AD
1040 $f_tags_str = "";
1041
1042 $num_tags = 0;
21703604
AD
1043
1044 while ($tmp_line = db_fetch_assoc($tmp_result)) {
42918a07
AD
1045 $num_tags++;
1046 $tag = $tmp_line["tag_name"];
1047 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
1048
1049 if ($num_tags == 5) {
1050 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
1051 } else if ($num_tags < 5) {
1052 $tags_str .= $tag_str;
1053 }
1054 $f_tags_str .= $tag_str;
1055 }
21703604 1056
42918a07
AD
1057 $tags_str = preg_replace("/, $/", "", $tags_str);
1058 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
e828e31e 1059
6a1ad084 1060// $truncated_link = truncate_string($line["link"], 60);
21703604 1061
6a1ad084
AD
1062 if ($tags_str || $entry_comments) {
1063 print "<tr><td width='50%'>
1064 $entry_comments</td>
1065 <td align=\"right\">$tags_str</td></tr>";
1066 }
21703604 1067
e828e31e
AD
1068 print "</table></div>";
1069
1070 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
42918a07
AD
1071 print "<div class=\"postContent\">";
1072
1073 if (db_num_rows($tmp_result) > 5) {
1074 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
1075 }
1076
68511f86
AD
1077 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
1078 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
1079 }
1080
42918a07 1081 print $line["content"] . "</div>";
e828e31e
AD
1082
1083 print "</div>";
1084
090e250b 1085 print "<script type=\"text/javascript\">
4f3a84f4 1086 update_all_counters('$feed_id');
090e250b 1087 </script>";
d76a3b03 1088 }
70830c87 1089
59b8192f 1090 print "</body></html>";
1cd17194
AD
1091 }
1092
1093 if ($op == "viewfeed") {
1094
1095 $feed = $_GET["feed"];
d76a3b03 1096 $skip = $_GET["skip"];
476cac42 1097 $subop = $_GET["subop"];
f175937c 1098 $view_mode = $_GET["view"];
cb1083a1 1099 $limit = $_GET["limit"];
ff2c6e6a 1100 $cat_view = $_GET["cat"];
a1a8a2be 1101
ac53063a
AD
1102 if (!$skip) $skip = 0;
1103
476cac42 1104 if ($subop == "undefined") $subop = "";
1cd17194 1105
59b8192f
AD
1106 print "<html><head>
1107 <title>Tiny Tiny RSS : Feed $feed</title>
1108 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
503eb349 1109
59b8192f
AD
1110 $user_theme = $_SESSION["theme"];
1111 if ($user_theme) {
1112 print "<link rel=\"stylesheet\" type=\"text/css\"
1113 href=\"themes/$user_theme/theme.css\">";
1114 }
430bf183 1115
59b8192f
AD
1116 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
1117 print "<link rel=\"stylesheet\"
1118 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
503eb349 1119
59b8192f
AD
1120 } else {
1121 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
1122 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
f0601b87
AD
1123 }
1124
70f6dbb1
AD
1125 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
1126 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1127
1128 if (db_num_rows($result) == 1) {
1129 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1130 } else {
1131 $rtl_content = false;
1132 }
1133
1134 if ($rtl_content) {
1135 $rtl_tag = "dir=\"RTL\"";
1136 } else {
1137 $rtl_tag = "";
1138 }
1139
59b8192f
AD
1140 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1141 <script type=\"text/javascript\" src=\"functions.js\"></script>
1142 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
1143 <!--[if gte IE 5.5000]>
1144 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
1145 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
1146 <![endif]-->
1147 </head><body>
1148 <script type=\"text/javascript\">
1149 if (document.addEventListener) {
1150 document.addEventListener(\"DOMContentLoaded\", init, null);
1151 }
1152 window.onload = init;
1153 </script>";
1154
7a232fc6 1155 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
dcee8f61 1156
085a5a74 1157/* if (ENABLE_UPDATE_DAEMON) {
8b911251
AD
1158
1159 if ($cid == 0) {
1160
1161 db_query($link, "INSERT INTO ttrss_scheduled_updates
1162 (owner_uid, feed_id, entered) VALUES
1163 (".$_SESSION["uid"].", '$feed', NOW())");
1164 }
dcee8f61 1165
633d263b
AD
1166 } else {
1167 // fixme update_rss_feed...
1168 } */
1169
ff2c6e6a 1170 if ($cat_view) {
99ff73f4
AD
1171
1172 if ($feed > 0) {
1173 $cat_qpart = "cat_id = '$feed'";
1174 } else {
1175 $cat_qpart = "cat_id IS NULL";
1176 }
1177
ff2c6e6a 1178 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
99ff73f4 1179 WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]);
ff2c6e6a
AD
1180
1181 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1182 $feed_url = $tmp_line["feed_url"];
1183 update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON);
1184 }
1185
1186 } else {
1187 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
1188 WHERE id = '$feed'");
1189 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
1190 update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON);
1191 }
dcee8f61
AD
1192 }
1193
0e32076b 1194 if ($subop == "MarkAllRead") {
d76a3b03 1195
d0bb308e 1196 if (preg_match("/^[0-9][0-9]*$/", $feed) != false && $feed >= 0) {
0e32076b 1197
ff2c6e6a
AD
1198 if ($cat_view) {
1199
99ff73f4
AD
1200 if ($feed > 0) {
1201 $cat_qpart = "cat_id = '$feed'";
1202 } else {
1203 $cat_qpart = "cat_id IS NULL";
1204 }
1205
ff2c6e6a 1206 $tmp_result = db_query($link, "SELECT id
99ff73f4 1207 FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " .
ff2c6e6a
AD
1208 $_SESSION["uid"]);
1209
1210 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1211
1212 $tmp_feed = $tmp_line["id"];
1213
1214 db_query($link, "UPDATE ttrss_user_entries
1215 SET unread = false,last_read = NOW()
1216 WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]);
1217 }
1218
1219 } else if ($feed > 0) {
f33371c0
AD
1220
1221 $tmp_result = db_query($link, "SELECT id
1222 FROM ttrss_feeds WHERE parent_feed = '$feed'
1223 ORDER BY cat_id,title");
1224
1225 $parent_ids = array();
1226
1227 if (db_num_rows($tmp_result) > 0) {
1228 while ($p = db_fetch_assoc($tmp_result)) {
1229 array_push($parent_ids, "feed_id = " . $p["id"]);
1230 }
1231
1232 $children_qpart = implode(" OR ", $parent_ids);
1233
1234 db_query($link, "UPDATE ttrss_user_entries
1235 SET unread = false,last_read = NOW()
1236 WHERE (feed_id = '$feed' OR $children_qpart)
1237 AND owner_uid = " . $_SESSION["uid"]);
1238
1239 } else {
1240 db_query($link, "UPDATE ttrss_user_entries
1241 SET unread = false,last_read = NOW()
1242 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1243 }
0e32076b
AD
1244
1245 } else if ($feed < 0 && $feed > -10) { // special, like starred
1246
1247 if ($feed == -1) {
f23a2177 1248 db_query($link, "UPDATE ttrss_user_entries
0e32076b 1249 SET unread = false,last_read = NOW()
5859be02 1250 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
0e32076b
AD
1251 }
1252
1253 } else if ($feed < -10) { // label
1254
f23a2177
AD
1255 // TODO make this more efficient
1256
7db95187 1257 $label_id = -$feed - 11;
0e32076b 1258
7db95187 1259 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
f23a2177 1260 WHERE id = '$label_id'");
7db95187
AD
1261
1262 if ($tmp_result) {
1263 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
1264
f23a2177
AD
1265 db_query($link, "BEGIN");
1266
1267 $tmp2_result = db_query($link,
1268 "SELECT
1269 int_id
1270 FROM
1271 ttrss_user_entries,ttrss_entries
1272 WHERE
1273 ref_id = id AND
1274 $sql_exp AND
1275 owner_uid = " . $_SESSION["uid"]);
1276
1277 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
1278 db_query($link, "UPDATE
1279 ttrss_user_entries
1280 SET
1281 unread = false, last_read = NOW()
1282 WHERE
1283 int_id = " . $tmp_line["int_id"]);
1284 }
1285
1286 db_query($link, "COMMIT");
1287
1288/* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
7db95187 1289 SET unread = false,last_read = NOW()
f23a2177
AD
1290 WHERE $sql_exp
1291 AND ref_id = id
1292 AND owner_uid = ".$_SESSION["uid"]); */
7db95187 1293 }
254e0e4b 1294 }
0e32076b 1295 } else { // tag
7eec90cf
AD
1296 db_query($link, "BEGIN");
1297
1298 $tag_name = db_escape_string($feed);
1299
1300 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
1301 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
1302
1303 while ($line = db_fetch_assoc($result)) {
1304 db_query($link, "UPDATE ttrss_user_entries SET
1305 unread = false, last_read = NOW()
1306 WHERE int_id = " . $line["post_int_id"]);
1307 }
1308 db_query($link, "COMMIT");
a1a8a2be 1309 }
0e32076b 1310
a1a8a2be 1311 }
d76a3b03 1312
f932bc9f
AD
1313 $search = db_escape_string($_GET["search"]);
1314 $search_mode = db_escape_string($_GET["smode"]);
52b51244 1315
f175937c 1316 if ($search) {
8e84993b
AD
1317 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
1318 OR ttrss_entries.content LIKE '%$search%') AND";
f175937c
AD
1319 } else {
1320 $search_query_part = "";
1321 }
1322
1323 $view_query_part = "";
1324
0ee2d12f 1325 if ($view_mode == "Adaptive") {
f18d0d94
AD
1326 if ($search) {
1327 $view_query_part = " ";
1328 } else if ($feed != -1) {
0ee2d12f
AD
1329 $unread = getFeedUnread($link, $feed);
1330 if ($unread > 0) {
1331 $view_query_part = " unread = true AND ";
1332 }
1333 }
1334 }
1335
f175937c
AD
1336 if ($view_mode == "Starred") {
1337 $view_query_part = " marked = true AND ";
ac53063a
AD
1338 }
1339
ac43eba1
AD
1340 if ($view_mode == "Unread") {
1341 $view_query_part = " unread = true AND ";
1342 }
1343
8d7008c7 1344 if ($limit && $limit != "All") {
82c9223c 1345 $limit_query_part = "LIMIT " . $limit;
ad3cb710 1346 }
f0601b87 1347
254e0e4b
AD
1348 $vfeed_query_part = "";
1349
52b51244 1350 // override query strategy and enable feed display when searching globally
d3416913 1351 if ($search && $search_mode == "All feeds") {
8e84993b 1352 $query_strategy_part = "ttrss_entries.id > 0";
b0005823 1353 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
d0bb308e 1354 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
8143ae1f
AD
1355 $query_strategy_part = "ttrss_entries.id > 0";
1356 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1357 id = feed_id) as feed_title,";
b0005823
AD
1358 } else if ($feed >= 0 && $search && $search_mode == "This category") {
1359
1360 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1361
1362 $tmp_result = db_query($link, "SELECT id
1363 FROM ttrss_feeds WHERE cat_id =
1364 (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'");
1365
1366 $cat_siblings = array();
1367
1368 if (db_num_rows($tmp_result) > 0) {
1369 while ($p = db_fetch_assoc($tmp_result)) {
1370 array_push($cat_siblings, "feed_id = " . $p["id"]);
1371 }
1372
1373 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
1374 $feed, implode(" OR ", $cat_siblings));
1375
1376 } else {
1377 $query_strategy_part = "ttrss_entries.id > 0";
1378 }
ff2c6e6a 1379
8143ae1f 1380 } else if ($feed >= 0) {
60103089 1381
ff2c6e6a 1382 if ($cat_view) {
b0005823 1383
99ff73f4
AD
1384 if ($feed > 0) {
1385 $query_strategy_part = "cat_id = '$feed'";
1386 } else {
1387 $query_strategy_part = "cat_id IS NULL";
1388 }
1389
60103089 1390 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
ff2c6e6a
AD
1391
1392 } else {
1393 $tmp_result = db_query($link, "SELECT id
1394 FROM ttrss_feeds WHERE parent_feed = '$feed'
1395 ORDER BY cat_id,title");
1396
1397 $parent_ids = array();
1398
1399 if (db_num_rows($tmp_result) > 0) {
1400 while ($p = db_fetch_assoc($tmp_result)) {
1401 array_push($parent_ids, "feed_id = " . $p["id"]);
1402 }
1403
1404 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
1405 $feed, implode(" OR ", $parent_ids));
1406
1407 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1408 } else {
1409 $query_strategy_part = "feed_id = '$feed'";
1410 }
60103089 1411 }
48f0adb0 1412 } else if ($feed == -1) { // starred virtual feed
254e0e4b 1413 $query_strategy_part = "marked = true";
60103089 1414 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
48f0adb0
AD
1415 } else if ($feed <= -10) { // labels
1416 $label_id = -$feed - 11;
1417
1418 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1419 WHERE id = '$label_id'");
1420
1421 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
1422
60103089 1423 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
254e0e4b 1424 } else {
48f0adb0 1425 $query_strategy_part = "id > 0"; // dumb
254e0e4b
AD
1426 }
1427
f99321a3
AD
1428 $order_by = "updated DESC";
1429
1430// if ($feed < -10) {
1431// $order_by = "feed_id,updated DESC";
1432// }
1433
1572afe5
AD
1434 $feed_title = "";
1435
1436 if ($search && $search_mode == "All feeds") {
49b7cbd3 1437 $feed_title = "Global search results ($search)";
d0bb308e 1438 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
49b7cbd3 1439 $feed_title = "Feed search results ($search, $feed)";
d0bb308e
AD
1440 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
1441 $feed_title = $feed;
1442 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
1572afe5 1443
ff2c6e6a 1444 if ($cat_view) {
ff2c6e6a 1445
019ce9f3
AD
1446 if ($feed != 0) {
1447 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
1448 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1449 $feed_title = db_fetch_result($result, 0, "title");
1450 } else {
1451 $feed_title = "Uncategorized";
1452 }
ff2c6e6a
AD
1453 } else {
1454
1455 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
1456 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1457
1458 $feed_title = db_fetch_result($result, 0, "title");
1459 $feed_site_url = db_fetch_result($result, 0, "site_url");
1460 $last_error = db_fetch_result($result, 0, "last_error");
1461
1462 }
1572afe5
AD
1463
1464 } else if ($feed == -1) {
1465 $feed_title = "Starred articles";
1466 } else if ($feed < -10) {
1467 $label_id = -$feed - 11;
1468 $result = db_query($link, "SELECT description FROM ttrss_labels
1469 WHERE id = '$label_id'");
1470 $feed_title = db_fetch_result($result, 0, "description");
1471 } else {
1472 $feed_title = "?";
1473 }
1474
48f0adb0
AD
1475 if ($feed < -10) error_reporting (0);
1476
386cbf27
AD
1477 print "<div id=\"headlinesContainer\">";
1478
d0bb308e 1479 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
8143ae1f 1480
99ff73f4 1481 if ($feed >= 0) {
21703604
AD
1482 $feed_kind = "Feeds";
1483 } else {
1484 $feed_kind = "Labels";
1485 }
1486
386cbf27
AD
1487// if (!$vfeed_query_part) {
1488 $content_query_part = "content as content_preview,";
1489// } else {
1490// $content_query_part = "";
1491// }
bd34c528 1492
8143ae1f 1493 $result = db_query($link, "SELECT
60103089 1494 ttrss_entries.id,ttrss_entries.title,
1572afe5
AD
1495 SUBSTRING(updated,1,16) as updated,
1496 unread,feed_id,marked,link,last_read,
8143ae1f
AD
1497 SUBSTRING(last_read,1,19) as last_read_noms,
1498 $vfeed_query_part
bd34c528
AD
1499 $content_query_part
1500 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 1501 FROM
60103089 1502 ttrss_entries,ttrss_user_entries,ttrss_feeds
8143ae1f 1503 WHERE
60103089 1504 ttrss_user_entries.feed_id = ttrss_feeds.id AND
4c193675 1505 ttrss_user_entries.ref_id = ttrss_entries.id AND
60103089 1506 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
1507 $search_query_part
1508 $view_query_part
1509 $query_strategy_part ORDER BY $order_by
1510 $limit_query_part");
1511
1512 } else {
1513 // browsing by tag
1514
21703604
AD
1515 $feed_kind = "Tags";
1516
8143ae1f 1517 $result = db_query($link, "SELECT
1572afe5
AD
1518 ttrss_entries.id as id,title,
1519 SUBSTRING(updated,1,16) as updated,
1520 unread,feed_id,
1e471f3b 1521 marked,link,last_read,
c05a19f3 1522 SUBSTRING(last_read,1,19) as last_read_noms,
254e0e4b 1523 $vfeed_query_part
bd34c528
AD
1524 $content_query_part
1525 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 1526 FROM
05732aa0 1527 ttrss_entries,ttrss_user_entries,ttrss_tags
8143ae1f 1528 WHERE
05732aa0
AD
1529 ref_id = ttrss_entries.id AND
1530 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1531 post_int_id = int_id AND tag_name = '$feed' AND
8143ae1f
AD
1532 $view_query_part
1533 $search_query_part
1534 $query_strategy_part ORDER BY $order_by
1535 $limit_query_part");
1536 }
d76a3b03 1537
48f0adb0 1538 if (!$result) {
386cbf27
AD
1539 print "<div align='center'>
1540 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
1541 return;
adccd201 1542 }
98bea1b1 1543
e0a7121b
AD
1544 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
1545 $bottom = false) {
f56ec297 1546
e0a7121b
AD
1547 if (!$bottom) {
1548 $class = "headlinesSubToolbar";
1549 $tid = "headlineActionsTop";
1550 } else {
1551 $class = "invisible";
1552 $tid = "headlineActionsBottom";
1553 }
1554
1555 print "<table class=\"$class\" id=\"$tid\"
386cbf27
AD
1556 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1557
1558 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201 1559
adccd201
AD
1560 print "<td class=\"headlineActions\">
1561 Select:
e7811ea5
AD
1562 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
1563 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
1564 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
386cbf27 1565 &nbsp;&nbsp;
e7811ea5
AD
1566 Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
1567 <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
adccd201 1568 print "</td>";
386cbf27
AD
1569
1570 } else {
1571
1572 print "<td class=\"headlineActions\">
1573 Select:
e7811ea5
AD
1574 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>,
1575 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1576 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a>
386cbf27 1577 &nbsp;&nbsp;
e7811ea5
AD
1578 Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1579 <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>";
386cbf27 1580
adccd201 1581 print "</td>";
386cbf27 1582
386cbf27
AD
1583 }
1584
078cb996
AD
1585 if ($last_error) {
1586 print "<td align='center' class='small'>
1587 <a class=\"warning\" href=\"javascript:alert('TT-RSS encountered an error while trying to update this feed.\\n\\n$last_error')\">Could not update this feed.</a></td>";
98bea1b1 1588 }
078cb996 1589
386cbf27 1590 print "<td class=\"headlineTitle\">";
adccd201 1591
386cbf27 1592 if ($feed_site_url) {
c7a8abe6
AD
1593 if (!$bottom) {
1594 $target = "target=\"_blank\"";
1595 }
1596 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
386cbf27
AD
1597 } else {
1598 print $feed_title;
1599 }
1600
1601 print "</td>";
1602 print "</tr></table>";
1603
98bea1b1
AD
1604 }
1605
1606 if (db_num_rows($result) > 0) {
1607
1608 print_headline_subtoolbar($link, $feed_site_url, $feed_title);
1609
386cbf27 1610 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201 1611 print "<table class=\"headlinesList\" id=\"headlinesList\"
70f6dbb1 1612 cellspacing=\"0\" width=\"100%\" $rtl_tag>";
f4c10d44 1613 }
386cbf27 1614
e5a99b88
AD
1615 $lnum = 0;
1616
1617 error_reporting (DEFAULT_ERROR_LEVEL);
1618
1619 $num_unread = 0;
1620
1621 while ($line = db_fetch_assoc($result)) {
adccd201 1622
e5a99b88
AD
1623 $class = ($lnum % 2) ? "even" : "odd";
1624
1625 $id = $line["id"];
1626 $feed_id = $line["feed_id"];
1627
1628 if ($line["last_read"] == "" &&
1629 ($line["unread"] != "t" && $line["unread"] != "1")) {
1630
1631 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1632 alt=\"Updated\">";
1633 } else {
1634 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1635 alt=\"Updated\">";
1636 }
1637
1638 if ($line["unread"] == "t" || $line["unread"] == "1") {
1639 $class .= "Unread";
1640 ++$num_unread;
386cbf27 1641 $is_unread = true;
adccd201 1642 } else {
386cbf27 1643 $is_unread = false;
e5a99b88
AD
1644 }
1645
1646 if ($line["marked"] == "t" || $line["marked"] == "1") {
1647 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
9932fb06 1648 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
e5a99b88
AD
1649 } else {
1650 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
9932fb06 1651 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
e5a99b88
AD
1652 }
1653
e454a889 1654 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
e5a99b88 1655 $line["title"] . "</a>";
adccd201 1656
e5a99b88
AD
1657 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1658 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1659 } else {
1660 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1661 $updated_fmt = date($short_date, strtotime($line["updated"]));
1662 }
adccd201
AD
1663
1664 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
8fd0c717 1665 $content_preview = truncate_string(strip_tags($line["content_preview"]),
070d0d2a 1666 100);
adccd201
AD
1667 }
1668
386cbf27 1669 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201
AD
1670
1671 print "<tr class='$class' id='RROW-$id'>";
adccd201
AD
1672
1673 print "<td class='hlUpdatePic'>$update_pic</td>";
1674
1675 print "<td class='hlSelectRow'>
1676 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1677 class=\"feedCheckBox\" id=\"RCHK-$id\">
1678 </td>";
1679
1680 print "<td class='hlMarkedPic'>$marked_pic</td>";
1681
1682 if ($line["feed_title"]) {
1683 print "<td class='hlContent'>$content_link</td>";
1684 print "<td class='hlFeed'>
9b1424fe
AD
1685 <a href='javascript:viewfeed($feed_id)'>".
1686 $line["feed_title"]."</a>&nbsp;</td>";
adccd201 1687 } else {
de244d27 1688 print "<td class='hlContent' valign='middle'>";
adccd201 1689
e454a889 1690 print "<a href=\"javascript:view($id,$feed_id);\">" .
adccd201
AD
1691 $line["title"];
1692
70f6dbb1 1693 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
adccd201
AD
1694 if ($content_preview) {
1695 print "<span class=\"contentPreview\"> - $content_preview</span>";
1696 }
1697 }
1698
1699 print "</a>";
1700 print "</td>";
1701 }
1702
1703 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1704
1705 print "</tr>";
1706
1707 } else {
386cbf27
AD
1708
1709 if ($is_unread) {
1710 $add_class = "Unread";
1711 } else {
1712 $add_class = "";
1713 }
1714
1715 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1716
1717 print "<div class=\"cdmHeader\">";
adccd201 1718
386cbf27
AD
1719 print "<div style=\"float : right\">$updated_fmt</div>";
1720
86383df6 1721 print "<a target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
adccd201 1722
386cbf27
AD
1723 if ($line["feed_title"]) {
1724 print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
adccd201 1725 }
adccd201 1726
386cbf27
AD
1727 print "</div>";
1728
1729 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1730
1731 print "<div style=\"float : right\">$marked_pic</div>
1732 <div class=\"cdmFooter\">
1733 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1734 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1735
1736 print "</div>";
1737
1738 }
e5a99b88
AD
1739
1740 ++$lnum;
254e0e4b 1741 }
adccd201 1742
386cbf27 1743 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201 1744 print "</table>";
adccd201 1745 }
d76a3b03 1746
e0a7121b
AD
1747 print_headline_subtoolbar($link,
1748 "javascript:catchupPage()", "Mark page as read", true);
98bea1b1
AD
1749
1750
e5a99b88
AD
1751 } else {
1752 print "<div width='100%' align='center'>No articles found.</div>";
a1a8a2be 1753 }
d76a3b03 1754
386cbf27 1755 print "</div>";
d76a3b03 1756
386cbf27
AD
1757 print "<script type=\"text/javascript\">
1758 document.onkeydown = hotkey_handler;
5a494a0b 1759 // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
386cbf27
AD
1760 update_all_counters('$feed');
1761 </script>";
adccd201 1762
97dcd654
AD
1763 print '
1764 <script type="text/javascript">
1765 /* for IE */
1766 function statechange() {
1767 if (document.readyState == "interactive") init();
1768 }
1769
1770 if (document.readyState) {
1771 if (document.readyState == "interactive" || document.readyState == "complete") {
1772 init();
1773 } else {
1774 document.onreadystatechange = statechange;
1775 }
1776 }
1777 </script>';
1778
59b8192f 1779 print "</body></html>";
1cd17194
AD
1780 }
1781
0e091d38 1782 if ($op == "pref-rpc") {
331900c6 1783
0e091d38 1784 $subop = $_GET["subop"];
331900c6 1785
83fe4d6d 1786 if ($subop == "unread") {
f932bc9f 1787 $ids = split(",", db_escape_string($_GET["ids"]));
83fe4d6d 1788 foreach ($ids as $id) {
a5873b2e
AD
1789 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1790 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1791 }
0e091d38 1792
a5873b2e 1793 print "Marked selected feeds as unread.";
83fe4d6d
AD
1794 }
1795
1796 if ($subop == "read") {
f932bc9f 1797 $ids = split(",", db_escape_string($_GET["ids"]));
83fe4d6d 1798 foreach ($ids as $id) {
a5873b2e
AD
1799 db_query($link, "UPDATE ttrss_user_entries
1800 SET unread = false,last_read = NOW() WHERE
1801 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1802 }
0e091d38 1803
a5873b2e 1804 print "Marked selected feeds as read.";
0e091d38
AD
1805
1806 }
1807
1808 }
1809
1810 if ($op == "pref-feeds") {
1811
47c6c988
AD
1812 $subop = $_REQUEST["subop"];
1813 $quiet = $_REQUEST["quiet"];
0e091d38 1814
a0476535
AD
1815 if ($subop == "massSubscribe") {
1816 $ids = split(",", db_escape_string($_GET["ids"]));
1817
a7f22b70
AD
1818 $subscribed = array();
1819
a0476535
AD
1820 foreach ($ids as $id) {
1821 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1822 WHERE id = '$id'");
1823
1824 $feed_url = db_fetch_result($result, 0, "feed_url");
1825 $title = db_fetch_result($result, 0, "title");
1826
1827 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1828 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1829
1830 if (db_num_rows($result) == 0) {
1831 $result = db_query($link,
1832 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1833 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
a7f22b70
AD
1834
1835 array_push($subscribed, $title);
1836 }
1837 }
1838
1839 if (count($subscribed) > 0) {
1840 print "<div class=\"notice\">";
1841 print "<b>Subscribed to feeds:</b>";
1842 print "<ul class=\"nomarks\">";
1843 foreach ($subscribed as $title) {
1844 print "<li>$title</li>";
a0476535 1845 }
a7f22b70
AD
1846 print "</ul>";
1847 print "</div>";
a0476535
AD
1848 }
1849 }
1850
f9cb39ac 1851 if ($subop == "browse") {
e2f728be
AD
1852
1853 if (!ENABLE_FEED_BROWSER) {
1854 print "Feed browser is administratively disabled.";
1855 return;
1856 }
f9cb39ac
AD
1857
1858 print "<div class=\"infoBoxContents\">";
1859
1860 print "<h1>Feed browser</h1>";
1861
1862 print "<p>Showing top 50 registered feeds, sorted by popularity:</p>";
1863
1864 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
e3c99f3b
AD
1865 FROM ttrss_feeds
1866 WHERE auth_login = '' AND auth_pass = '' AND private = false
24b18114 1867 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50");
f9cb39ac
AD
1868
1869 print "<ul class='browseFeedList' id='browseFeedList'>";
dc932d0a
AD
1870
1871 $feedctr = 0;
f9cb39ac
AD
1872
1873 while ($line = db_fetch_assoc($result)) {
1874 $feed_url = $line["feed_url"];
1875 $subscribers = $line["subscribers"];
dc932d0a
AD
1876
1877 $sub_result = db_query($link, "SELECT id
1878 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
1879 $_SESSION["uid"]);
1880
1881 if (db_num_rows($sub_result) > 0) {
1882 continue; // already subscribed
1883 }
f9cb39ac
AD
1884
1885 $det_result = db_query($link, "SELECT site_url,title,id
1886 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1887
1888 $details = db_fetch_assoc($det_result);
1889
1890 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1891
1892 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1893 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1894 "/".$details["id"].".ico\">";
1895 } else {
1896 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1897 }
1898
b92e6209
AD
1899 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1900 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
f9cb39ac 1901
b92e6209
AD
1902 $class = ($feedctr % 2) ? "even" : "odd";
1903
1904 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1905 "$feed_icon " . db_unescape_string($details["title"]) .
f9cb39ac 1906 "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
dc932d0a
AD
1907
1908 ++$feedctr;
1909 }
1910
1911 if ($feedctr == 0) {
1912 print "<li>No feeds found to subscribe.</li>";
1913 }
f9cb39ac
AD
1914
1915 print "</ul>";
1916
1917 print "<div align='center'>
f9cb39ac 1918 <input type=\"submit\" class=\"button\"
d10fabe4
AD
1919 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1920 <input type='submit' class='button'
1921 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
f9cb39ac
AD
1922
1923 print "</div>";
1924 return;
1925 }
1926
0ea4fb50
AD
1927 if ($subop == "editfeed") {
1928 $feed_id = db_escape_string($_GET["id"]);
1929
1930 $result = db_query($link,
1931 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1932 owner_uid = " . $_SESSION["uid"]);
1933
1934 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1935 0, "title")));
1936
1937 print "<div class=\"infoBoxContents\">";
1938
1939 $icon_file = ICONS_DIR . "/$feed_id.ico";
1940
1941 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1942 $feed_icon = "<img width=\"16\" height=\"16\"
1943 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1944 } else {
1945 $feed_icon = "";
1946 }
1947
1948 print "<h1>$feed_icon $title</h1>";
1949
1950 print "<table width='100%'>";
1951
1952 $row_class = "odd";
1953
1954 print "<tr class='$row_class'><td>Title:</td>";
1955 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1956
1957 $feed_url = db_fetch_result($result, 0, "feed_url");
1958 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1959 0, "feed_url")));
1960 $row_class = toggleEvenOdd($row_class);
1961
1962 print "<tr class='$row_class'><td>Feed URL:</td>";
1963 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
ad815c71 1964
0ea4fb50
AD
1965 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1966
1967 $cat_id = db_fetch_result($result, 0, "cat_id");
1968
1969 $row_class = toggleEvenOdd($row_class);
1970
1971 print "<tr class='$row_class'><td>Category:</td>";
1972 print "<td>";
1973 print "<select id=\"iedit_fcat\">";
1974 print "<option id=\"0\">Uncategorized</option>";
1975
1976 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1977 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1978
1979 if (db_num_rows($tmp_result) > 0) {
1980 print "<option disabled>--------</option>";
1981 }
1982
1983 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1984 if ($tmp_line["id"] == $cat_id) {
1985 $is_selected = "selected";
1986 } else {
1987 $is_selected = "";
1988 }
1989 printf("<option $is_selected id='%d'>%s</option>",
1990 $tmp_line["id"], $tmp_line["title"]);
1991 }
1992
1993 print "</select></td>";
1994 print "</td></tr>";
1995
1996 }
1997
1998 $update_interval = db_fetch_result($result, 0, "update_interval");
1999 $row_class = toggleEvenOdd($row_class);
2000
2001 print "<tr class='$row_class'><td>Update Interval:</td>";
ad815c71
AD
2002// print "<td><input id=\"iedit_updintl\"
2003// value=\"$update_interval\"></td></tr>";
2004
2005 print "<td>";
2006
2007 print "<select id=\"iedit_updintl\">";
2008
2009 foreach (array_keys($update_intervals) as $i) {
2010
2011 if ($i == $update_interval) {
2012 $selected = "selected";
2013 } else {
2014 $selected = "";
2015 }
2016 print "<option $selected id=\"$i\">" . $update_intervals[$i] . "</option>";
2017 }
2018
2019 print "</select>";
2020
2021 print "</td>";
0ea4fb50 2022
1da7e457
AD
2023 $row_class = toggleEvenOdd($row_class);
2024 print "<tr class='$row_class'><td>Link to:</td>";
2025
3b0027a4
AD
2026 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
2027 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
2028
2029 $linked_count = db_fetch_result($tmp_result, 0, "count");
2030
1da7e457 2031 $parent_feed = db_fetch_result($result, 0, "parent_feed");
3b0027a4
AD
2032
2033 if ($linked_count > 0) {
2034 $disabled = "disabled";
2035 }
2036
2037 print "<select $disabled id=\"iedit_parent_feed\">";
2038
eac46afb 2039 print "<option id=\"0\">Not linked</option>";
1da7e457 2040
8a53e029
AD
2041 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2042 if ($cat_id) {
2043 $cat_qpart = "AND cat_id = '$cat_id'";
2044 } else {
2045 $cat_qpart = "AND cat_id IS NULL";
2046 }
2047 }
2048
1da7e457 2049 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
262c2426
AD
2050 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
2051 $cat_qpart ORDER BY title");
1da7e457
AD
2052
2053 if (db_num_rows($tmp_result) > 0) {
2054 print "<option disabled>--------</option>";
2055 }
2056
2057 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2058 if ($tmp_line["id"] == $parent_feed) {
2059 $is_selected = "selected";
2060 } else {
2061 $is_selected = "";
2062 }
2063 printf("<option $is_selected id='%d'>%s</option>",
2064 $tmp_line["id"], $tmp_line["title"]);
2065 }
2066
2067 print "</select></td>";
2068 print "</td></tr>";
2069
0ea4fb50
AD
2070 $purge_interval = db_fetch_result($result, 0, "purge_interval");
2071 $row_class = toggleEvenOdd($row_class);
2072
2073 print "<tr class='$row_class'><td>Purge Days:</td>";
ad815c71
AD
2074// print "<td><input id=\"iedit_purgintl\"
2075// value=\"$purge_interval\"></td></tr>";
2076
2077 print "<td>";
2078
2079 print "<select id=\"iedit_purgintl\">";
2080
2081 foreach (array_keys($purge_intervals) as $i) {
2082
2083 if ($i == $purge_interval) {
2084 $selected = "selected";
2085 } else {
2086 $selected = "";
2087 }
2088 print "<option $selected id=\"$i\">" . $purge_intervals[$i] . "</option>";
2089 }
2090
2091 print "</select>";
2092
2093 print "</td>";
0ea4fb50 2094
47c6c988
AD
2095// print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
2096
2097 $row_class = toggleEvenOdd($row_class);
2098 $auth_login = db_fetch_result($result, 0, "auth_login");
2099
2100 print "<tr class='$row_class'><td>Login:</td>";
2101 print "<td><input id=\"iedit_login\"
2102 value=\"$auth_login\"></td></tr>";
2103
2104 $row_class = toggleEvenOdd($row_class);
2105 $auth_pass = db_fetch_result($result, 0, "auth_pass");
2106
2107 print "<tr class='$row_class'><td>Password:</td>";
2108 print "<td><input type=\"password\" id=\"iedit_pass\"
2109 value=\"$auth_pass\"></td></tr>";
2110
e3c99f3b
AD
2111 $row_class = toggleEvenOdd($row_class);
2112 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
2113
2114 if ($private) {
2115 $checked = "checked";
2116 } else {
2117 $checked = "";
2118 }
2119
991ee9e2 2120 print "<tr class='$row_class'><td valign='top'>Options:</td>";
e3c99f3b 2121 print "<td><input type=\"checkbox\" id=\"iedit_private\"
70f6dbb1
AD
2122 $checked><label for=\"iedit_private\">Hide from feed browser</label>";
2123
2124 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
2125
2126 if ($rtl_content) {
2127 $checked = "checked";
2128 } else {
2129 $checked = "";
2130 }
2131
2132 print "<br><input type=\"checkbox\" id=\"iedit_rtl\"
2133 $checked><label for=\"iedit_rtl\">Right-to-left content</label>";
2134
2135 print "</td></tr>";
e3c99f3b 2136
0ea4fb50
AD
2137 print "</table>";
2138 print "</div>";
2139
2140 print "<div align='center'>
0ea4fb50 2141 <input type=\"submit\" class=\"button\"
d10fabe4
AD
2142 onclick=\"feedEditSave()\" value=\"Save\">
2143 <input type='submit' class='button'
2144 onclick=\"feedEditCancel()\" value=\"Cancel\"></div>";
0ea4fb50
AD
2145 return;
2146 }
2147
508a81e1 2148 if ($subop == "editSave") {
47c6c988
AD
2149 $feed_title = db_escape_string($_POST["t"]);
2150 $feed_link = db_escape_string($_POST["l"]);
2151 $upd_intl = db_escape_string($_POST["ui"]);
2152 $purge_intl = db_escape_string($_POST["pi"]);
2153 $feed_id = db_escape_string($_POST["id"]);
2154 $cat_id = db_escape_string($_POST["catid"]);
2155 $auth_login = db_escape_string($_POST["login"]);
2156 $auth_pass = db_escape_string($_POST["pass"]);
1da7e457 2157 $parent_feed = db_escape_string($_POST["pfeed"]);
19ded366 2158 $private = db_escape_string($_POST["is_pvt"]);
70f6dbb1 2159 $rtl_content = db_escape_string($_POST["is_rtl"]);
508a81e1 2160
d148926e
AD
2161 if (strtoupper($upd_intl) == "DEFAULT")
2162 $upd_intl = 0;
2163
a88c1f36
AD
2164 if (strtoupper($upd_intl) == "DISABLED")
2165 $upd_intl = -1;
2166
5d73494a
AD
2167 if (strtoupper($purge_intl) == "DEFAULT")
2168 $purge_intl = 0;
2169
140aae81
AD
2170 if (strtoupper($purge_intl) == "DISABLED")
2171 $purge_intl = -1;
2172
91ff844a
AD
2173 if ($cat_id != 0) {
2174 $category_qpart = "cat_id = '$cat_id'";
2175 } else {
2176 $category_qpart = 'cat_id = NULL';
2177 }
2178
1da7e457
AD
2179 if ($parent_feed != 0) {
2180 $parent_qpart = "parent_feed = '$parent_feed'";
2181 } else {
2182 $parent_qpart = 'parent_feed = NULL';
2183 }
2184
648472a7 2185 $result = db_query($link, "UPDATE ttrss_feeds SET
91ff844a 2186 $category_qpart,
1da7e457 2187 $parent_qpart,
d148926e 2188 title = '$feed_title', feed_url = '$feed_link',
5d73494a 2189 update_interval = '$upd_intl',
47c6c988
AD
2190 purge_interval = '$purge_intl',
2191 auth_login = '$auth_login',
e3c99f3b 2192 auth_pass = '$auth_pass',
70f6dbb1
AD
2193 private = '$private',
2194 rtl_content = '$rtl_content'
f72dbbde 2195 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
5ddadb4c
AD
2196 }
2197
2198 if ($subop == "saveCat") {
2199 $cat_title = db_escape_string($_GET["title"]);
2200 $cat_id = db_escape_string($_GET["id"]);
2201
2202 $result = db_query($link, "UPDATE ttrss_feed_categories SET
2203 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
508a81e1 2204
83fe4d6d
AD
2205 }
2206
331900c6 2207 if ($subop == "remove") {
331900c6 2208
b0b4abcf 2209 if (!WEB_DEMO_MODE) {
331900c6 2210
f932bc9f 2211 $ids = split(",", db_escape_string($_GET["ids"]));
b0b4abcf
AD
2212
2213 foreach ($ids as $id) {
f72dbbde
AD
2214 db_query($link, "DELETE FROM ttrss_feeds
2215 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
4769ddaf 2216
273a2f6b 2217 $icons_dir = ICONS_DIR;
d5caaae5 2218
4769ddaf
AD
2219 if (file_exists($icons_dir . "/$id.ico")) {
2220 unlink($icons_dir . "/$id.ico");
d5caaae5 2221 }
b0b4abcf 2222 }
331900c6
AD
2223 }
2224 }
2225
2226 if ($subop == "add") {
b0b4abcf
AD
2227
2228 if (!WEB_DEMO_MODE) {
331900c6 2229
b6b535ca 2230 $feed_link = db_escape_string(trim($_GET["link"]));
15da5cc1
AD
2231 $cat_id = db_escape_string($_GET["cid"]);
2232
5edfe303 2233 if ($cat_id == "0" || !$cat_id) {
15da5cc1
AD
2234 $cat_qpart = "NULL";
2235 } else {
2236 $cat_qpart = "'$cat_id'";
2237 }
331900c6 2238
648472a7 2239 $result = db_query($link,
7e9a3986
AD
2240 "SELECT id FROM ttrss_feeds
2241 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
2242
2243 if (db_num_rows($result) == 0) {
2244
2245 $result = db_query($link,
15da5cc1 2246 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
746b249f
AD
2247 VALUES ('".$_SESSION["uid"]."', '$feed_link',
2248 '[Unknown]', $cat_qpart)");
331900c6 2249
7e9a3986 2250 $result = db_query($link,
746b249f 2251 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
7e9a3986
AD
2252 AND owner_uid = " . $_SESSION["uid"]);
2253
2254 $feed_id = db_fetch_result($result, 0, "id");
2255
2256 if ($feed_id) {
ddb68b81 2257 update_rss_feed($link, $feed_link, $feed_id, true);
7e9a3986
AD
2258 }
2259 } else {
331900c6 2260
7e9a3986
AD
2261 print "<div class=\"warning\">
2262 Feed <b>$feed_link</b> already exists in the database.
2263 </div>";
b0b4abcf
AD
2264 }
2265 }
331900c6 2266 }
a0d53889 2267
91ff844a
AD
2268 if ($subop == "addCat") {
2269
2270 if (!WEB_DEMO_MODE) {
2271
2272 $feed_cat = db_escape_string(trim($_GET["cat"]));
2273
2274 $result = db_query($link,
2275 "SELECT id FROM ttrss_feed_categories
2276 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
2277
2278 if (db_num_rows($result) == 0) {
2279
2280 $result = db_query($link,
2281 "INSERT INTO ttrss_feed_categories (owner_uid,title)
2282 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
2283
2284 } else {
2285
2286 print "<div class=\"warning\">
2287 Category <b>$feed_cat</b> already exists in the database.
2288 </div>";
2289 }
2290
2291
2292 }
2293 }
2294
2295 if ($subop == "removeCats") {
2296
2297 if (!WEB_DEMO_MODE) {
2298
f932bc9f 2299 $ids = split(",", db_escape_string($_GET["ids"]));
91ff844a
AD
2300
2301 foreach ($ids as $id) {
2302
2303 db_query($link, "BEGIN");
2304
2305 $result = db_query($link,
2306 "SELECT count(id) as num_feeds FROM ttrss_feeds
2307 WHERE cat_id = '$id'");
2308
2309 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2310
2311 if ($num_feeds == 0) {
2312 db_query($link, "DELETE FROM ttrss_feed_categories
2313 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
2314 } else {
2315
2316 print "<div class=\"warning\">
2317 Unable to delete non empty feed categories.</div>";
2318
2319 }
2320
2321 db_query($link, "COMMIT");
2322 }
2323 }
2324 }
2325
f932bc9f
AD
2326 if ($subop == "categorize") {
2327
2328 if (!WEB_DEMO_MODE) {
2329
2330 $ids = split(",", db_escape_string($_GET["ids"]));
2331
2332 $cat_id = db_escape_string($_GET["cat_id"]);
2333
2334 if ($cat_id == 0) {
2335 $cat_id_qpart = 'NULL';
2336 } else {
2337 $cat_id_qpart = "'$cat_id'";
2338 }
2339
2340 db_query($link, "BEGIN");
2341
2342 foreach ($ids as $id) {
2343
2344 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
2345 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
2346 }
2347
2348 db_query($link, "COMMIT");
2349 }
2350
2351 }
2352
a24f525c
AD
2353 if ($quiet) return;
2354
c64d5b03 2355// print "<h3>Edit Feeds</h3>";
91ff844a 2356
4904f845
AD
2357 $result = db_query($link, "SELECT id,title,feed_url,last_error
2358 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
2359
2360 if (db_num_rows($result) > 0) {
2361
2362 print "<div class=\"warning\">";
a9b0bfd5
AD
2363
2364// print"<img class=\"closeButton\"
2365// onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
2366
36aab70f
AD
2367 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
2368 <b>Feeds with update errors</b> (click to expand)</a>";
4904f845 2369
36aab70f 2370 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
4904f845
AD
2371
2372 while ($line = db_fetch_assoc($result)) {
2373 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
2374 $line["last_error"];
2375 }
2376
2377 print "</ul>";
2378 print "</div>";
2379
2380 }
2381
f932bc9f
AD
2382 $feed_search = db_escape_string($_GET["search"]);
2383
2384 if (array_key_exists("search", $_GET)) {
2385 $_SESSION["prefs_feed_search"] = $feed_search;
2386 } else {
2387 $feed_search = $_SESSION["prefs_feed_search"];
2388 }
2389
2390 print "<table width='100%' class=\"prefGenericAddBox\"
2391 cellspacing='0' cellpadding='0'><tr>
2392 <td>
2393 <input id=\"fadd_link\"
2394 onchange=\"javascript:addFeed()\"
2395 size=\"40\">
2396 <input type=\"submit\" class=\"button\"
e2f728be
AD
2397 onclick=\"javascript:addFeed()\" value=\"Add feed\">";
2398
2399 if (ENABLE_FEED_BROWSER) {
2400 print "&nbsp;(<a href='javascript:browseFeeds()'>Top 50</a>)";
2401 }
2402
2403 print "</td><td align='right'>
f932bc9f
AD
2404 <input id=\"feed_search\" size=\"20\"
2405 onchange=\"javascript:updateFeedList()\"
2406 value=\"$feed_search\">
2407 <input type=\"submit\" class=\"button\"
2408 onclick=\"javascript:updateFeedList()\" value=\"Search\">
2409 </td>
2410 </tr></table>";
a0d53889 2411
b83c7545
AD
2412 $feeds_sort = db_escape_string($_GET["sort"]);
2413
2414 if (!$feeds_sort || $feeds_sort == "undefined") {
2415 $feeds_sort = $_SESSION["pref_sort_feeds"];
2416 if (!$feeds_sort) $feeds_sort = "title";
2417 }
2418
2419 $_SESSION["pref_sort_feeds"] = $feeds_sort;
2420
f932bc9f 2421 if ($feed_search) {
11de82c3
AD
2422 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
2423 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
f932bc9f
AD
2424 } else {
2425 $search_qpart = "";
2426 }
2427
648472a7 2428 $result = db_query($link, "SELECT
db42b934
AD
2429 F1.id,
2430 F1.title,
2431 F1.feed_url,
2432 substring(F1.last_updated,1,16) AS last_updated,
2433 F1.parent_feed,
2434 F1.update_interval,
2435 F1.purge_interval,
2436 F1.cat_id,
2437 F2.title AS parent_title,
2438 C1.title AS category
c0e5a40e 2439 FROM
db42b934
AD
2440 ttrss_feeds AS F1
2441 LEFT JOIN ttrss_feeds AS F2
2442 ON (F1.parent_feed = F2.id)
2443 LEFT JOIN ttrss_feed_categories AS C1
2444 ON (F1.cat_id = C1.id)
f932bc9f 2445 WHERE
db42b934 2446 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
0ea4fb50 2447 ORDER by category,$feeds_sort,title");
1cd17194 2448
3b0feb9b 2449 if (db_num_rows($result) != 0) {
91ff844a 2450
3b0feb9b 2451 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
35f3c923 2452
f4fe2cde
AD
2453 print "<p><table width=\"100%\" cellspacing=\"0\"
2454 class=\"prefFeedList\" id=\"prefFeedList\">";
35f3c923
AD
2455 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2456 Select:
2457 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 2458 'FEEDR-', 'FRCHK-', true)\">All</a>,
35f3c923 2459 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 2460 'FEEDR-', 'FRCHK-', false)\">None</a>
35f3c923
AD
2461 </td</tr>";
2462
0ea4fb50
AD
2463 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
2464 print "<tr class=\"title\">
e325c6e7 2465 <td width='5%' align='center'>&nbsp;</td>
62ac0cc8 2466 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
f42e9435 2467 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
62ac0cc8 2468 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
ad815c71 2469 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>";
603c27f8 2470 }
603c27f8 2471
c64d5b03 2472 $lnum = 0;
0ea4fb50
AD
2473
2474 $cur_cat_id = -1;
c64d5b03
AD
2475
2476 while ($line = db_fetch_assoc($result)) {
2477
3b0feb9b 2478 $feed_id = $line["id"];
0ea4fb50
AD
2479 $cat_id = $line["cat_id"];
2480
2481 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2482 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
2483 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
c64d5b03 2484
ad815c71
AD
2485// if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
2486// if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
2487// if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
2488// if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled";
0ea4fb50
AD
2489
2490 if (!$edit_cat) $edit_cat = "Uncategorized";
2491
0ea4fb50 2492 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
cb58d0df
AD
2493 $lnum = 0;
2494
0ea4fb50
AD
2495 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
2496
2497 print "<tr class=\"title\">
e325c6e7 2498 <td width='5%' align='center'>&nbsp;</td>
62ac0cc8 2499 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
f42e9435 2500 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
62ac0cc8 2501 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
ad815c71 2502 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>";
0ea4fb50
AD
2503
2504 $cur_cat_id = $cat_id;
c64d5b03 2505 }
0ea4fb50 2506
cb58d0df 2507 $class = ($lnum % 2) ? "even" : "odd";
0ea4fb50
AD
2508 $this_row_id = "id=\"FEEDR-$feed_id\"";
2509
53226edc 2510 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2511
2512 $icon_file = ICONS_DIR . "/$feed_id.ico";
2513
2514 if (file_exists($icon_file) && filesize($icon_file) > 0) {
327a3bbe 2515 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
3b0feb9b 2516 } else {
327a3bbe 2517 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3b0feb9b 2518 }
327a3bbe 2519// print "<td class='feedIcon'>$feed_icon</td>";
c64d5b03 2520
62ac0cc8 2521 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
0ea4fb50 2522 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
3547842a 2523
0ea4fb50
AD
2524 $edit_title = truncate_string($edit_title, 40);
2525 $edit_link = truncate_string($edit_link, 60);
a88c1f36 2526
1da7e457
AD
2527 $parent_title = $line["parent_title"];
2528 if ($parent_title) {
2529 $parent_title = "<span class='groupPrompt'>(linked to
2530 $parent_title)</span>";
2531 }
2532
0ea4fb50 2533 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1da7e457 2534 "$feed_icon $edit_title $parent_title" . "</a></td>";
0ea4fb50
AD
2535
2536 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2537 $edit_link . "</a></td>";
3547842a 2538
0ea4fb50
AD
2539/* if (get_pref($link, 'ENABLE_FEED_CATS')) {
2540 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2541 $edit_cat . "</a></td>";
2542 } */
3547842a 2543
0ea4fb50 2544 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
ad815c71 2545 $update_intervals[$line["update_interval"]] . "</a></td>";
3b0feb9b 2546
0ea4fb50 2547 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
ad815c71 2548 $purge_intervals[$line["purge_interval"]] . "</a></td>";
3b0feb9b 2549
c64d5b03
AD
2550 print "</tr>";
2551
2552 ++$lnum;
2553 }
2554
c64d5b03 2555 print "</table>";
3b0feb9b 2556
c64d5b03
AD
2557 print "<p>";
2558
3b0feb9b
AD
2559 if ($subop == "edit") {
2560 print "Edit feed:&nbsp;
c64d5b03 2561 <input type=\"submit\" class=\"button\"
3b0feb9b 2562 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
c64d5b03 2563 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2564 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
2565 } else {
c64d5b03
AD
2566
2567 print "
2568 Selection:&nbsp;
2569 <input type=\"submit\" class=\"button\"
3b0feb9b 2570 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
c64d5b03 2571 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2572 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2573 <input type=\"submit\" class=\"button\"
2574 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
f932bc9f
AD
2575
2576 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2577
2578 print "&nbsp;&nbsp;";
2579
2580 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2581 WHERE owner_uid = ".$_SESSION["uid"]."
2582 ORDER BY title");
2583
2584 print "<select id=\"sfeed_set_fcat\">";
2585 print "<option id=\"0\">Uncategorized</option>";
2586
2587 if (db_num_rows($result) != 0) {
2588
2589 print "<option disabled>--------</option>";
2590
2591 while ($line = db_fetch_assoc($result)) {
2592 printf("<option id='%d'>%s</option>",
2593 $line["id"], $line["title"]);
2594 }
2595 }
2596
2597 print "</select>";
2598
2599 print " <input type=\"submit\" class=\"button\"
2600 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2601
2602 }
2603
3b0feb9b
AD
2604 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
2605 print "
2606 <input type=\"submit\" class=\"button\"
4f3a84f4 2607 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
3b0feb9b 2608 <input type=\"submit\" class=\"button\"
4f3a84f4 2609 onclick=\"javascript:readSelectedFeeds(false)\"
3b0feb9b
AD
2610 value=\"Mark as unread\">&nbsp;";
2611 }
2612
2613 print "
f932bc9f 2614 &nbsp;All feeds: <input type=\"submit\"
3b0feb9b
AD
2615 class=\"button\" onclick=\"gotoExportOpml()\"
2616 value=\"Export OPML\">";
2617 }
2618 } else {
2619
2620 print "<p>No feeds defined.</p>";
2621
2622 }
2623
2624 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2625
2626 print "<h3>Edit Categories</h3>";
2627
2628 // print "<h3>Categories</h3>";
2629
2630 print "<div class=\"prefGenericAddBox\">
f932bc9f
AD
2631 <input id=\"fadd_cat\"
2632 onchange=\"javascript:addFeedCat()\"
2633 size=\"40\">&nbsp;
2634 <input
3b0feb9b
AD
2635 type=\"submit\" class=\"button\"
2636 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2637
2638 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2639 WHERE owner_uid = ".$_SESSION["uid"]."
2640 ORDER BY title");
2641
2642 if (db_num_rows($result) != 0) {
2643
35f3c923 2644 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
f4fe2cde 2645 cellspacing=\"0\" id=\"prefFeedCatList\">";
35f3c923
AD
2646
2647 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2648 Select:
2649 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 2650 'FCATR-', 'FCCHK-', true)\">All</a>,
35f3c923 2651 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 2652 'FCATR-', 'FCCHK-', false)\">None</a>
35f3c923
AD
2653 </td</tr>";
2654
3b0feb9b 2655 print "<tr class=\"title\">
a426e532 2656 <td width=\"5%\"></td><td width=\"80%\">Title</td>
3b0feb9b
AD
2657 </tr>";
2658
2659 $lnum = 0;
2660
2661 while ($line = db_fetch_assoc($result)) {
2662
2663 $class = ($lnum % 2) ? "even" : "odd";
2664
2665 $cat_id = $line["id"];
2666
2667 $edit_cat_id = $_GET["id"];
2668
2669 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2670 $class .= "Grayed";
53226edc
AD
2671 $this_row_id = "";
2672 } else {
2673 $this_row_id = "id=\"FCATR-$cat_id\"";
3b0feb9b
AD
2674 }
2675
53226edc 2676 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2677
2678 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2679
2680 if (!$edit_cat_id || $subop != "editCat") {
2681
a426e532 2682 print "<td align='center'><input onclick='toggleSelectRow(this);'
3b0feb9b
AD
2683 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2684
2685 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2686 $edit_title . "</a></td>";
2687
2688 } else if ($cat_id != $edit_cat_id) {
2689
2690 print "<td><input disabled=\"true\" type=\"checkbox\"
2691 id=\"FRCHK-".$line["id"]."\"></td>";
2692
2693 print "<td>$edit_title</td>";
2694
2695 } else {
2696
2697 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2698
2699 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2700
2701 }
2702
2703 print "</tr>";
2704
2705 ++$lnum;
2706 }
2707
2708 print "</table>";
2709
2710 print "<p>";
2711
2712 if ($subop == "editCat") {
2713 print "Edit category:&nbsp;
2714 <input type=\"submit\" class=\"button\"
2715 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2716 <input type=\"submit\" class=\"button\"
2717 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2718 } else {
2719
2720 print "
2721 Selection:&nbsp;
2722 <input type=\"submit\" class=\"button\"
2723 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2724 <input type=\"submit\" class=\"button\"
2725 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2726
2727 }
2728
2729 } else {
2730 print "<p>No feed categories defined.</p>";
2731 }
c64d5b03
AD
2732 }
2733
2734 print "<h3>Import OPML</h3>
f5a50b25
AD
2735 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2736 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
2737 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2738 type=\"submit\" value=\"Import\">
2739 </form>";
2740
007bda35
AD
2741 }
2742
a0d53889
AD
2743 if ($op == "pref-filters") {
2744
2745 $subop = $_GET["subop"];
a24f525c 2746 $quiet = $_GET["quiet"];
a0d53889
AD
2747
2748 if ($subop == "editSave") {
a0d53889 2749
648472a7
AD
2750 $regexp = db_escape_string($_GET["r"]);
2751 $descr = db_escape_string($_GET["d"]);
2752 $match = db_escape_string($_GET["m"]);
2753 $filter_id = db_escape_string($_GET["id"]);
ead60402 2754 $feed_id = db_escape_string($_GET["fid"]);
19c9cb11 2755 $action_id = db_escape_string($_GET["aid"]);
ead60402
AD
2756
2757 if (!$feed_id) {
2758 $feed_id = 'NULL';
2759 } else {
2760 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2761 }
0afbd851 2762
648472a7 2763 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 2764 reg_exp = '$regexp',
0afbd851 2765 description = '$descr',
ead60402 2766 feed_id = $feed_id,
19c9cb11 2767 action_id = '$action_id',
0afbd851
AD
2768 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2769 description = '$match')
2770 WHERE id = '$filter_id'");
a0d53889
AD
2771 }
2772
2773 if ($subop == "remove") {
2774
2775 if (!WEB_DEMO_MODE) {
2776
f932bc9f 2777 $ids = split(",", db_escape_string($_GET["ids"]));
a0d53889
AD
2778
2779 foreach ($ids as $id) {
648472a7 2780 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
2781
2782 }
2783 }
2784 }
2785
2786 if ($subop == "add") {
2787
de435974 2788 if (!WEB_DEMO_MODE) {
a0d53889 2789
b6b535ca
AD
2790 $regexp = db_escape_string(trim($_GET["regexp"]));
2791 $match = db_escape_string(trim($_GET["match"]));
ead60402 2792 $feed_id = db_escape_string($_GET["fid"]);
19c9cb11 2793 $action_id = db_escape_string($_GET["aid"]);
ead60402
AD
2794
2795 if (!$feed_id) {
2796 $feed_id = 'NULL';
2797 } else {
2798 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2799 }
4401bf04 2800
648472a7 2801 $result = db_query($link,
19c9cb11
AD
2802 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2803 action_id)
2804 VALUES
de435974 2805 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
19c9cb11
AD
2806 description = '$match'),'".$_SESSION["uid"]."',
2807 $feed_id, '$action_id')");
de435974 2808 }
a0d53889
AD
2809 }
2810
a24f525c
AD
2811 if ($quiet) return;
2812
648472a7 2813 $result = db_query($link, "SELECT description
a0d53889
AD
2814 FROM ttrss_filter_types ORDER BY description");
2815
2816 $filter_types = array();
2817
648472a7 2818 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
2819 array_push($filter_types, $line["description"]);
2820 }
2821
2c7070b5 2822 print "<div class=\"prefGenericAddBox\">
7cc1e5d6 2823 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2c7070b5 2824
ead60402
AD
2825 print_select("fadd_match", "Title", $filter_types);
2826
2827 print "&nbsp;<select id=\"fadd_feed\">";
2828
2829 print "<option selected id=\"0\">All feeds</option>";
2830
2831 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2832 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2833
2834 if (db_num_rows($result) > 0) {
2835 print "<option disabled>--------</option>";
2836 }
2837
2838 while ($line = db_fetch_assoc($result)) {
2839 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2840 }
2841
2c7070b5 2842 print "</select>&nbsp;";
19c9cb11
AD
2843
2844 print "&nbsp;Action: ";
2845
2846 print "<select id=\"fadd_action\">";
2847
2848 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2849 ORDER BY name");
2850
2851 while ($line = db_fetch_assoc($result)) {
2852 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2853 }
2854
2855 print "</select>&nbsp;";
2856
2c7070b5
AD
2857 print "<input type=\"submit\"
2858 class=\"button\" onclick=\"javascript:addFilter()\"
2859 value=\"Add filter\">";
a0d53889 2860
19c9cb11
AD
2861 print "</div>";
2862
648472a7 2863 $result = db_query($link, "SELECT
ead60402
AD
2864 ttrss_filters.id AS id,reg_exp,
2865 ttrss_filters.description AS description,
2866 ttrss_filter_types.name AS filter_type_name,
2867 ttrss_filter_types.description AS filter_type_descr,
2868 feed_id,
19c9cb11 2869 ttrss_filter_actions.description AS action_description,
11de82c3 2870 ttrss_feeds.title AS feed_title
a0d53889 2871 FROM
5890c3f4
AD
2872 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2873 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
4356293a 2874 WHERE
ead60402 2875 filter_type = ttrss_filter_types.id AND
19c9cb11 2876 ttrss_filter_actions.id = action_id AND
ead60402 2877 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
4356293a 2878 ORDER by reg_exp");
a0d53889 2879
3b0feb9b 2880 if (db_num_rows($result) != 0) {
a0d53889 2881
f4fe2cde
AD
2882 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2883 id=\"prefFilterList\">";
35f3c923
AD
2884
2885 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2886 Select:
2887 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 2888 'FILRR-', 'FICHK-', true)\">All</a>,
35f3c923 2889 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 2890 'FILRR-', 'FICHK-', false)\">None</a>
35f3c923
AD
2891 </td</tr>";
2892
3b0feb9b 2893 print "<tr class=\"title\">
e325c6e7 2894 <td align='center' width=\"5%\">&nbsp;</td>
19c9cb11
AD
2895 <td width=\"20%\">Filter expression</td>
2896 <td width=\"20%\">Feed</td>
2897 <td width=\"15%\">Match</td>
2898 <td width=\"15%\">Action</td>
3b0feb9b 2899 <td width=\"30%\">Description</td></tr>";
a0d53889 2900
3b0feb9b
AD
2901 $lnum = 0;
2902
2903 while ($line = db_fetch_assoc($result)) {
2904
2905 $class = ($lnum % 2) ? "even" : "odd";
2906
2907 $filter_id = $line["id"];
2908 $edit_filter_id = $_GET["id"];
2909
2910 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2911 $class .= "Grayed";
53226edc
AD
2912 $this_row_id = "";
2913 } else {
2914 $this_row_id = "id=\"FILRR-$filter_id\"";
ead60402 2915 }
3b0feb9b 2916
53226edc 2917 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2918
2919 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2920 $line["description"] = htmlspecialchars($line["description"]);
2921
2922 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2923
2924 if (!$edit_filter_id || $subop != "edit") {
2925
2926 if (!$line["description"]) $line["description"] = "[No description]";
2927
a426e532 2928 print "<td align='center'><input onclick='toggleSelectRow(this);'
3b0feb9b
AD
2929 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2930
2931 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2932 $line["reg_exp"] . "</td>";
2933
2934 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2935 $line["feed_title"] . "</td>";
2936
2937 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2938 $line["filter_type_descr"] . "</td>";
19c9cb11
AD
2939
2940 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2941 $line["action_description"] . "</td>";
2942
3b0feb9b
AD
2943 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2944 $line["description"] . "</td>";
2945
2946 } else if ($filter_id != $edit_filter_id) {
2947
2948 if (!$line["description"]) $line["description"] = "[No description]";
2949
2950 print "<td><input disabled=\"true\" type=\"checkbox\"
2951 id=\"FICHK-".$line["id"]."\"></td>";
2952
2953 print "<td>".$line["reg_exp"]."</td>";
2954 print "<td>".$line["feed_title"]."</td>";
2955 print "<td>".$line["filter_type_descr"]."</td>";
19c9cb11 2956 print "<td>".$line["action_description"]."</td>";
3b0feb9b 2957 print "<td>".$line["description"]."</td>";
19c9cb11 2958
3b0feb9b
AD
2959 } else {
2960
2961 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2962
2963 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2964 "\"></td>";
2965
2966 print "<td>";
3b0feb9b 2967 print "<select id=\"iedit_feed\">";
3b0feb9b
AD
2968 print "<option id=\"0\">All feeds</option>";
2969
3b0feb9b
AD
2970 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2971 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
19c9cb11
AD
2972
2973 if (db_num_rows($tmp_result) > 0) {
2974 print "<option disabled>--------</option>";
2975 }
2976
3b0feb9b
AD
2977 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2978 if ($tmp_line["id"] == $line["feed_id"]) {
2979 $is_selected = "selected";
2980 } else {
2981 $is_selected = "";
2982 }
2983 printf("<option $is_selected id='%d'>%s</option>",
2984 $tmp_line["id"], $tmp_line["title"]);
ead60402 2985 }
3b0feb9b
AD
2986
2987 print "</select></td>";
2988
2989 print "<td>";
2990 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2991 print "</td>";
19c9cb11
AD
2992
2993 print "<td>";
2994 print "<select id=\"iedit_filter_action\">";
2995
2996 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2997 ORDER BY description");
2998
2999 while ($tmp_line = db_fetch_assoc($tmp_result)) {
3000 if ($tmp_line["description"] == $line["action_description"]) {
3001 $is_selected = "selected";
3002 } else {
3003 $is_selected = "";
3004 }
3005 printf("<option $is_selected id='%d'>%s</option>",
3006 $tmp_line["id"], $tmp_line["description"]);
3007 }
3b0feb9b 3008
19c9cb11
AD
3009 print "</select></td>";
3010
3011
3b0feb9b
AD
3012 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
3013 "\"></td>";
3014
3015 print "</td>";
ead60402 3016 }
3b0feb9b
AD
3017
3018 print "</tr>";
3019
3020 ++$lnum;
a0d53889 3021 }
3b0feb9b
AD
3022
3023 if ($lnum == 0) {
3024 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
3025 }
3026
3027 print "</table>";
3028
3029 print "<p>";
3030
3031 if ($subop == "edit") {
d10fabe4 3032 print "Edit filter:
3b0feb9b 3033 <input type=\"submit\" class=\"button\"
d10fabe4 3034 onclick=\"javascript:filterEditSave()\" value=\"Save\">
3b0feb9b 3035 <input type=\"submit\" class=\"button\"
d10fabe4 3036 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
3b0feb9b
AD
3037
3038 } else {
3039
3040 print "
3041 Selection:
e828e31e 3042 <input type=\"submit\" class=\"button\"
3b0feb9b 3043 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
e828e31e 3044 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
3045 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
3046 }
3047
a0d53889
AD
3048 } else {
3049
3b0feb9b
AD
3050 print "<p>No filters defined.</p>";
3051
a0d53889
AD
3052 }
3053 }
3054
80dce858
AD
3055 // We need to accept raw SQL data in label queries, so not everything is escaped
3056 // here, this is by design. If you don't like the whole idea, disable labels
3057 // altogether with GLOBAL_ENABLE_LABELS = false
3058
48f0adb0
AD
3059 if ($op == "pref-labels") {
3060
cfaba6df
AD
3061 if (!GLOBAL_ENABLE_LABELS) {
3062 return;
3063 }
3064
48f0adb0
AD
3065 $subop = $_GET["subop"];
3066
d9dde1d6
AD
3067 if ($subop == "test") {
3068
3069 $expr = $_GET["expr"];
3070 $descr = $_GET["descr"];
3071
3072 print "<div class='infoBoxContents'>";
3073
3074 print "<h1>Label &laquo;$descr&raquo;</h1>";
3075
3076// print "<p><b>Expression</b>: $expr</p>";
3077
3078 $result = db_query($link,
3079 "SELECT count(id) AS num_matches
3080 FROM ttrss_entries,ttrss_user_entries
3081 WHERE ($expr) AND
3082 ttrss_user_entries.ref_id = ttrss_entries.id AND
3083 owner_uid = " . $_SESSION["uid"]);
3084
3085 $num_matches = db_fetch_result($result, 0, "num_matches");;
3086
3087 if ($num_matches > 0) {
3088
a31a7b39 3089 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
d9dde1d6
AD
3090
3091 $result = db_query($link,
3092 "SELECT title,
3093 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
3094 FROM ttrss_entries,ttrss_user_entries
3095 WHERE ($expr) AND
3096 ttrss_user_entries.ref_id = ttrss_entries.id
3097 AND owner_uid = " . $_SESSION["uid"] . "
3098 ORDER BY date_entered DESC LIMIT 5");
3099
3100 print "<ul class=\"nomarks\">";
3101 while ($line = db_fetch_assoc($result)) {
3102 print "<li>".$line["title"].
3103 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
3104 }
3105 print "</ul>";
3106
3107 } else {
3108 print "<p>Query didn't return any matches.</p>";
3109 }
3110
3111 print "</div>";
3112
3113 print "<div align='center'>
3114 <input type='submit' class='button'
3115 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3116 return;
3117 }
3118
48f0adb0
AD
3119 if ($subop == "editSave") {
3120
3121 $sql_exp = $_GET["s"];
3122 $descr = $_GET["d"];
3123 $label_id = db_escape_string($_GET["id"]);
3124
3125// print "$sql_exp : $descr : $label_id";
3126
3127 $result = db_query($link, "UPDATE ttrss_labels SET
3128 sql_exp = '$sql_exp',
3129 description = '$descr'
3130 WHERE id = '$label_id'");
3131 }
3132
3133 if ($subop == "remove") {
3134
3135 if (!WEB_DEMO_MODE) {
3136
f932bc9f 3137 $ids = split(",", db_escape_string($_GET["ids"]));
48f0adb0
AD
3138
3139 foreach ($ids as $id) {
3140 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
3141
3142 }
3143 }
3144 }
3145
3146 if ($subop == "add") {
3147
3148 if (!WEB_DEMO_MODE) {
3149
4401bf04
AD
3150 // no escaping is done here on purpose
3151 $exp = trim($_GET["exp"]);
48f0adb0
AD
3152
3153 $result = db_query($link,
4356293a
AD
3154 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
3155 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
3156 }
3157 }
3158
2c7070b5
AD
3159 print "<div class=\"prefGenericAddBox\">
3160 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
48f0adb0 3161
2c7070b5
AD
3162 print"<input type=\"submit\" class=\"button\"
3163 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
48f0adb0
AD
3164
3165 $result = db_query($link, "SELECT
3166 id,sql_exp,description
3167 FROM
4356293a
AD
3168 ttrss_labels
3169 WHERE
3170 owner_uid = ".$_SESSION["uid"]."
3171 ORDER by description");
48f0adb0 3172
d9dde1d6
AD
3173 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3174
3b0feb9b 3175 if (db_num_rows($result) != 0) {
48f0adb0 3176
f4fe2cde
AD
3177 print "<p><table width=\"100%\" cellspacing=\"0\"
3178 class=\"prefLabelList\" id=\"prefLabelList\">";
35f3c923
AD
3179
3180 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3181 Select:
3182 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 3183 'LILRR-', 'LICHK-', true)\">All</a>,
35f3c923 3184 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 3185 'LILRR-', 'LICHK-', false)\">None</a>
35f3c923
AD
3186 </td</tr>";
3187
3b0feb9b 3188 print "<tr class=\"title\">
e325c6e7
AD
3189 <td align='center' width=\"5%\">&nbsp;</td>
3190 <td width=\"40%\">SQL expression
01c9c74a 3191 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
3b0feb9b
AD
3192 </td>
3193 <td width=\"40%\">Caption</td></tr>";
3194
3195 $lnum = 0;
3196
3197 while ($line = db_fetch_assoc($result)) {
3198
3199 $class = ($lnum % 2) ? "even" : "odd";
3200
3201 $label_id = $line["id"];
3202 $edit_label_id = $_GET["id"];
3203
3204 if ($subop == "edit" && $label_id != $edit_label_id) {
3205 $class .= "Grayed";
53226edc
AD
3206 $this_row_id = "";
3207 } else {
3208 $this_row_id = "id=\"LILRR-$label_id\"";
3b0feb9b
AD
3209 }
3210
53226edc 3211 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
3212
3213 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
3214 $line["description"] = htmlspecialchars($line["description"]);
3215
3216 if (!$edit_label_id || $subop != "edit") {
3217
3218 if (!$line["description"]) $line["description"] = "[No caption]";
3219
a426e532 3220 print "<td align='center'><input onclick='toggleSelectRow(this);'
3b0feb9b
AD
3221 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
3222
3223 print "<td><a href=\"javascript:editLabel($label_id);\">" .
3224 $line["sql_exp"] . "</td>";
48f0adb0 3225
3b0feb9b
AD
3226 print "<td><a href=\"javascript:editLabel($label_id);\">" .
3227 $line["description"] . "</td>";
3228
3229 } else if ($label_id != $edit_label_id) {
3230
3231 if (!$line["description"]) $line["description"] = "[No description]";
3232
3233 print "<td><input disabled=\"true\" type=\"checkbox\"
3234 id=\"LICHK-".$line["id"]."\"></td>";
3235
3236 print "<td>".$line["sql_exp"]."</td>";
3237 print "<td>".$line["description"]."</td>";
3238
3239 } else {
3240
3241 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
3242
3243 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
3244 "\"></td>";
3245
3246 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
3247 "\"></td>";
3248
3249 }
3250
48f0adb0 3251
3b0feb9b
AD
3252 print "</tr>";
3253
3254 ++$lnum;
3255 }
3256
3257 if ($lnum == 0) {
3258 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
3259 }
3260
3261 print "</table>";
3262
3263 print "<p>";
3264
3265 if ($subop == "edit") {
3266 print "Edit label:
d9dde1d6
AD
3267 <input type=\"submit\" class=\"button\"
3268 onclick=\"javascript:labelTest()\" value=\"Test\">
3b0feb9b 3269 <input type=\"submit\" class=\"button\"
d10fabe4 3270 onclick=\"javascript:labelEditSave()\" value=\"Save\">
3b0feb9b 3271 <input type=\"submit\" class=\"button\"
d10fabe4 3272 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
3b0feb9b
AD
3273
3274 } else {
3275
3276 print "
3277 Selection:
48f0adb0 3278 <input type=\"submit\" class=\"button\"
3b0feb9b 3279 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
48f0adb0 3280 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
3281 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
3282 }
48f0adb0 3283 } else {
3b0feb9b 3284 print "<p>No labels defined.</p>";
48f0adb0
AD
3285 }
3286 }
3287
e828e31e
AD
3288 if ($op == "error") {
3289 print "<div width=\"100%\" align='center'>";
3290 $msg = $_GET["msg"];
3291 print $msg;
3292 print "</div>";
3293 }
3294
7dc66a61 3295 if ($op == "help") {
01c9c74a
AD
3296 if (!$_GET["noheaders"]) {
3297 print "<html><head>
3298 <title>Tiny Tiny RSS : Help</title>
3299 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3300 <script type=\"text/javascript\" src=\"functions.js\"></script>
3301 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3302 </head><body>";
3303 }
7dc66a61
AD
3304
3305 $tid = sprintf("%d", $_GET["tid"]);
3306
01c9c74a 3307 print "<div class='infoBoxContents'>";
7dc66a61 3308
01c9c74a
AD
3309 if (file_exists("help/$tid.php")) {
3310 include("help/$tid.php");
3311 } else {
3312 print "<p>Help topic not found.</p>";
3313 }
7dc66a61 3314
01c9c74a 3315 print "</div>";
7dc66a61
AD
3316
3317 print "<div align='center'>
01c9c74a
AD
3318 <input type='submit' class='button'
3319 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
7dc66a61 3320
01c9c74a
AD
3321 if (!$_GET["noheaders"]) {
3322 print "</body></html>";
3323 }
7dc66a61
AD
3324
3325 }
3326
f84a97a3
AD
3327 if ($op == "dlg") {
3328 $id = $_GET["id"];
6de5d056 3329 $param = $_GET["param"];
f84a97a3
AD
3330
3331 if ($id == "quickAddFeed") {
76332f3c
AD
3332 print "
3333 Feed URL: <input
033e47e0 3334 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
15da5cc1
AD
3335 id=\"qafInput\">";
3336
3337 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3338 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
3339 WHERE owner_uid = ".$_SESSION["uid"]."
3340 ORDER BY title");
3341
3342 print " <select id=\"qafCat\">";
3343 print "<option id=\"0\">Uncategorized</option>";
3344
3345 if (db_num_rows($result) != 0) {
3346
3347 print "<option disabled>--------</option>";
3348
3349 while ($line = db_fetch_assoc($result)) {
3350 printf("<option id='%d'>%s</option>",
3351 $line["id"], $line["title"]);
3352 }
3353 }
3354
3355 print "</select>";
3356 }
3357
3358 print "&nbsp;<input class=\"button\"
f84a97a3
AD
3359 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
3360 <input class=\"button\"
3361 type=\"submit\" onclick=\"javascript:closeDlg()\"
3362 value=\"Cancel\">";
3363 }
6de5d056
AD
3364
3365 if ($id == "quickDelFeed") {
3366
3367 $param = db_escape_string($param);
3368
3369 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
3370
3371 if ($result) {
3372
3373 $f_title = db_fetch_result($result, 0, "title");
3374
76332f3c 3375 print "Remove current feed (<b>$f_title</b>)?&nbsp;
6de5d056
AD
3376 <input class=\"button\"
3377 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
3378 <input class=\"button\"
3379 type=\"submit\" onclick=\"javascript:closeDlg()\"
3380 value=\"Cancel\">";
3381 } else {
3382 print "Error: Feed $param not found.&nbsp;
3383 <input class=\"button\"
3384 type=\"submit\" onclick=\"javascript:closeDlg()\"
3385 value=\"Cancel\">";
3386 }
3387 }
3388
033e47e0
AD
3389 if ($id == "search") {
3390
49b7cbd3
AD
3391 $active_feed_id = db_escape_string($_GET["param"]);
3392
033e47e0
AD
3393 print "<input id=\"searchbox\" class=\"extSearch\"
3394 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
3395 onchange=\"javascript:search()\">
3396 <select id=\"searchmodebox\">
49b7cbd3
AD
3397 <option selected>All feeds</option>";
3398
3399 if ($active_feed_id) {
3400 print "<option>This feed</option>";
3401 } else {
3402 print "<option disabled>This feed</option>";
3403 }
b0005823
AD
3404
3405 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3406 print "<option>This category</option>";
3407 }
3408
49b7cbd3 3409 print "</select>
033e47e0
AD
3410 <input type=\"submit\"
3411 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
3412 <input class=\"button\"
3413 type=\"submit\" onclick=\"javascript:closeDlg()\"
3414 value=\"Close\">";
3415
3416 }
3417
a24f525c
AD
3418 if ($id == "quickAddFilter") {
3419
3420 $result = db_query($link, "SELECT description
3421 FROM ttrss_filter_types ORDER BY description");
3422
3423 $filter_types = array();
3424
3425 while ($line = db_fetch_assoc($result)) {
3426 array_push($filter_types, $line["description"]);
3427 }
3428
3429 print "<table>";
3430
3431 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\">&nbsp;";
3432
3433 print_select("fadd_match", "Title", $filter_types);
3434
3435 print "</td></tr>";
3436 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
3437
3438 print "<option selected id=\"0\">All feeds</option>";
3439
3440 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
3441 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
3442
3443 if (db_num_rows($result) > 0) {
3444 print "<option disabled>--------</option>";
3445 }
3446
3447 while ($line = db_fetch_assoc($result)) {
3448 if ($param == $line["id"]) {
3449 $selected = "selected";
3450 } else {
3451 $selected = "";
3452 }
3453 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
3454 }
3455
3456 print "</select></td></tr>";
3457
3458 print "<tr><td>Action:</td>";
3459
3460 print "<td><select id=\"fadd_action\">";
3461
3462 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
3463 ORDER BY name");
3464
3465 while ($line = db_fetch_assoc($result)) {
3466 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
3467 }
3468
3469 print "</select>";
3470
3471 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
3472
3473 print "<input type=\"submit\"
3474 class=\"button\" onclick=\"javascript:qaddFilter()\"
3475 value=\"Add filter\"> ";
3476
3477 print "<input class=\"button\"
3478 type=\"submit\" onclick=\"javascript:closeDlg()\"
3479 value=\"Close\">";
3480
3481 print "</td></tr></table>";
3482 }
f84a97a3
AD
3483 }
3484
a2770077
AD
3485 // update feeds of all users, may be used anonymously
3486 if ($op == "globalUpdateFeeds") {
3487
3488 $result = db_query($link, "SELECT id FROM ttrss_users");
3489
3490 while ($line = db_fetch_assoc($result)) {
3491 $user_id = $line["id"];
3492// print "<!-- updating feeds of uid $user_id -->";
3493 update_all_feeds($link, false, $user_id);
3494 }
e65af9c1 3495
a2770077
AD
3496 print "<rpc-reply>
3497 <message msg=\"All feeds updated\"/>
3498 </rpc-reply>";
e65af9c1
AD
3499
3500 }
3501
77e96719
AD
3502 if ($op == "pref-prefs") {
3503
b1895692 3504 $subop = $_REQUEST["subop"];
77e96719
AD
3505
3506 if ($subop == "Save configuration") {
3507
d2892032
AD
3508 if (WEB_DEMO_MODE) {
3509 header("Location: prefs.php");
3510 return;
3511 }
01d68cf9 3512
93cb4442
AD
3513 $_SESSION["prefs_op_result"] = "save-config";
3514
11de82c3
AD
3515 $_SESSION["prefs_cache"] = false;
3516
77e96719
AD
3517 foreach (array_keys($_POST) as $pref_name) {
3518
3519 $pref_name = db_escape_string($pref_name);
3520 $value = db_escape_string($_POST[$pref_name]);
3521
3522 $result = db_query($link, "SELECT type_name
3523 FROM ttrss_prefs,ttrss_prefs_types
3524 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
3525
3526 if (db_num_rows($result) > 0) {
3527
3528 $type_name = db_fetch_result($result, 0, "type_name");
3529
5da169d9
AD
3530// print "$pref_name : $type_name : $value<br>";
3531
77e96719 3532 if ($type_name == "bool") {
5da169d9 3533 if ($value == "1") {
77e96719
AD
3534 $value = "true";
3535 } else {
3536 $value = "false";
3537 }
3538 } else if ($type_name == "integer") {
3539 $value = sprintf("%d", $value);
3540 }
3541
3542// print "$pref_name : $type_name : $value<br>";
3543
ff485f1d
AD
3544 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
3545 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
3546
3547 }
3548
3549 header("Location: prefs.php");
3550
3551 }
3552
b1895692
AD
3553 } else if ($subop == "getHelp") {
3554
3555 $pref_name = db_escape_string($_GET["pn"]);
3556
3557 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
3558 WHERE pref_name = '$pref_name'");
3559
3560 if (db_num_rows($result) > 0) {
3561 $help_text = db_fetch_result($result, 0, "help_text");
3562 print $help_text;
3563 } else {
3564 print "Unknown option: $pref_name";
3565 }
3566
cbb01696
AD
3567 } else if ($subop == "Change e-mail") {
3568
3569 if (WEB_DEMO_MODE) {
3570 header("Location: prefs.php");
3571 return;
3572 }
3573
3574 $email = db_escape_string($_GET["email"]);
3575 $active_uid = $_SESSION["uid"];
3576
3577 if ($email) {
3578 db_query($link, "UPDATE ttrss_users SET email = '$email'
3579 WHERE id = '$active_uid'");
3580 }
3581
3582 header("Location: prefs.php");
3583
1c7f75ed
AD
3584 } else if ($subop == "Change password") {
3585
d2892032
AD
3586 if (WEB_DEMO_MODE) {
3587 header("Location: prefs.php");
3588 return;
3589 }
1c7f75ed
AD
3590
3591 $old_pw = $_POST["OLD_PASSWORD"];
3592 $new_pw = $_POST["OLD_PASSWORD"];
3593
3594 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3595 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3596
3597 $active_uid = $_SESSION["uid"];
3598
3599 if ($old_pw && $new_pw) {
3600
3601 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3602
3603 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3604 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3605 pwd_hash = '$old_pw_hash')");
3606
3607 if (db_num_rows($result) == 1) {
3608 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3609 WHERE id = '$active_uid'");
b791095d
AD
3610
3611 $_SESSION["pwd_change_result"] = "ok";
3612 } else {
3613 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
3614 }
3615 }
3616
3617 header("Location: prefs.php");
b791095d 3618
77e96719
AD
3619 } else if ($subop == "Reset to defaults") {
3620
d2892032
AD
3621 if (WEB_DEMO_MODE) {
3622 header("Location: prefs.php");
3623 return;
3624 }
01d68cf9 3625
93cb4442
AD
3626 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3627
e1aa0559
AD
3628 if (DB_TYPE == "pgsql") {
3629 db_query($link,"UPDATE ttrss_user_prefs
3630 SET value = ttrss_prefs.def_value
3631 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3632 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3633 } else {
3634 db_query($link, "DELETE FROM ttrss_user_prefs
3635 WHERE owner_uid = ".$_SESSION["uid"]);
3636 initialize_user_prefs($link, $_SESSION["uid"]);
3637 }
5da169d9 3638
77e96719
AD
3639 header("Location: prefs.php");
3640
58f8ad54
AD
3641 } else if ($subop == "Change theme") {
3642
3643 $theme = db_escape_string($_POST["theme"]);
3644
3645 if ($theme == "Default") {
3646 $theme_qpart = 'NULL';
3647 } else {
3648 $theme_qpart = "'$theme'";
3649 }
3650
6752e330
AD
3651 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3652 WHERE theme_name = '$theme'");
3653
3654 if (db_num_rows($result) == 1) {
3655 $theme_id = db_fetch_result($result, 0, "id");
3656 $theme_path = db_fetch_result($result, 0, "theme_path");
3657 } else {
3658 $theme_id = "NULL";
3659 $theme_path = "";
3660 }
3661
58f8ad54 3662 db_query($link, "UPDATE ttrss_users SET
6752e330 3663 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 3664
6752e330 3665 $_SESSION["theme"] = $theme_path;
503eb349 3666
58f8ad54
AD
3667 header("Location: prefs.php");
3668
77e96719
AD
3669 } else {
3670
7d4c898a 3671 if (!SINGLE_USER_MODE) {
1c7f75ed 3672
cbb01696 3673 $result = db_query($link, "SELECT id,email FROM ttrss_users
a029d530
AD
3674 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3675 pwd_hash = 'SHA1:".sha1("password")."')");
3676
3677 if (db_num_rows($result) != 0) {
b791095d 3678 print "<div class=\"warning\">
a029d530
AD
3679 Your password is at default value, please change it.
3680 </div>";
3681 }
3682
b791095d
AD
3683 if ($_SESSION["pwd_change_result"] == "failed") {
3684 print "<div class=\"warning\">
3685 There was an error while changing your password.
3686 </div>";
3687 }
3688
3689 if ($_SESSION["pwd_change_result"] == "ok") {
3690 print "<div class=\"notice\">
3691 Password changed successfully.
3692 </div>";
3693 }
3694
3695 $_SESSION["pwd_change_result"] = "";
3696
93cb4442
AD
3697 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3698 print "<div class=\"notice\">
3699 Your configuration was reset to defaults.
3700 </div>";
3701 }
3702
3703 if ($_SESSION["prefs_op_result"] == "save-config") {
3704 print "<div class=\"notice\">
3705 Your configuration was saved successfully.
3706 </div>";
3707 }
3708
3709 $_SESSION["prefs_op_result"] = "";
3710
cbb01696
AD
3711 print "<form action=\"backend.php\" method=\"GET\">";
3712
3713 print "<table width=\"100%\" class=\"prefPrefsList\">";
3714 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3715
3716 $result = db_query($link, "SELECT email FROM ttrss_users
3717 WHERE id = ".$_SESSION["uid"]);
3718
3719 $email = db_fetch_result($result, 0, "email");
3720
3721 print "<tr><td width=\"40%\">E-mail</td>";
3722 print "<td><input class=\"editbox\" name=\"email\"
3723 value=\"$email\"></td></tr>";
3724
3725 print "</table>";
3726
3727 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3728
3729 print "<p><input class=\"button\" type=\"submit\"
3730 value=\"Change e-mail\" name=\"subop\">";
3731
a132b8b1
AD
3732 print "</form>";
3733
7d4c898a
AD
3734 print "<form action=\"backend.php\" method=\"POST\">";
3735
3736 print "<table width=\"100%\" class=\"prefPrefsList\">";
3737 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3738
3739 print "<tr><td width=\"40%\">Old password</td>";
3740 print "<td><input class=\"editbox\" type=\"password\"
3741 name=\"OLD_PASSWORD\"></td></tr>";
3742
3743 print "<tr><td width=\"40%\">New password</td>";
3744
3745 print "<td><input class=\"editbox\" type=\"password\"
3746 name=\"NEW_PASSWORD\"></td></tr>";
3747
3748 print "</table>";
3749
3750 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3751
3752 print "<p><input class=\"button\" type=\"submit\"
3753 value=\"Change password\" name=\"subop\">";
3754
3755 print "</form>";
1c7f75ed 3756
7d4c898a 3757 }
1c7f75ed 3758
58f8ad54
AD
3759 $result = db_query($link, "SELECT
3760 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3761
3762 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3763
3764 $result = db_query($link, "SELECT
3765 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3766
3767 if (db_num_rows($result) > 0) {
6752e330
AD
3768
3769 print "<form action=\"backend.php\" method=\"POST\">";
3770 print "<table width=\"100%\" class=\"prefPrefsList\">";
3771 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3772 print "<tr><td width=\"40%\">Select theme</td>";
3773 print "<td><select name=\"theme\">";
3774 print "<option>Default</option>";
58f8ad54 3775 print "<option disabled>--------</option>";
6752e330 3776
58f8ad54
AD
3777 while ($line = db_fetch_assoc($result)) {
3778 if ($line["id"] == $user_theme_id) {
3779 $selected = "selected";
3780 } else {
3781 $selected = "";
3782 }
3783 print "<option $selected>" . $line["theme_name"] . "</option>";
3784 }
6752e330
AD
3785 print "</select></td></tr>";
3786 print "</table>";
3787 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3788 print "<p><input class=\"button\" type=\"submit\"
3789 value=\"Change theme\" name=\"subop\">";
3790 print "</form>";
58f8ad54
AD
3791 }
3792
77e96719 3793 $result = db_query($link, "SELECT
ff485f1d 3794 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 3795 section_name,def_value
ff485f1d 3796 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 3797 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 3798 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
3799 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3800 owner_uid = ".$_SESSION["uid"]."
650bc435 3801 ORDER BY section_id,short_desc");
77e96719
AD
3802
3803 print "<form action=\"backend.php\" method=\"POST\">";
3804
77e96719
AD
3805 $lnum = 0;
3806
3807 $active_section = "";
3808
3809 while ($line = db_fetch_assoc($result)) {
3810
3811 if ($active_section != $line["section_name"]) {
59a654ba
AD
3812
3813 if ($active_section != "") {
1c7f75ed 3814 print "</table>";
59a654ba 3815 }
1c7f75ed
AD
3816
3817 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
3818
3819 $active_section = $line["section_name"];
3820
77e96719 3821 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
3822// print "<tr class=\"title\">
3823// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
3824
3825 $lnum = 0;
77e96719
AD
3826 }
3827
650bc435 3828// $class = ($lnum % 2) ? "even" : "odd";
77e96719 3829
650bc435 3830 print "<tr>";
77e96719 3831
77e96719
AD
3832 $type_name = $line["type_name"];
3833 $pref_name = $line["pref_name"];
3834 $value = $line["value"];
3835 $def_value = $line["def_value"];
b1895692
AD
3836 $help_text = $line["help_text"];
3837
3838 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3839
3840 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3841
3842 print "</td>";
77e96719
AD
3843
3844 print "<td>";
3845
3846 if ($type_name == "bool") {
3847// print_select($pref_name, $value, array("true", "false"));
3848
3849 if ($value == "true") {
3850 $value = "Yes";
3851 } else {
3852 $value = "No";
3853 }
3854
3855 print_radio($pref_name, $value, array("Yes", "No"));
3856
3857 } else {
3858 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3859 }
3860
3861 print "</td>";
3862
3863 print "</tr>";
3864
3865 $lnum++;
3866 }
3867
3868 print "</table>";
3869
3870 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3871
3872 print "<p><input class=\"button\" type=\"submit\"
3873 name=\"subop\" value=\"Save configuration\">";
3874
3875 print "&nbsp;<input class=\"button\" type=\"submit\"
69668465
AD
3876 name=\"subop\" onclick=\"return validatePrefsReset()\"
3877 value=\"Reset to defaults\"></p>";
77e96719
AD
3878
3879 print "</form>";
3880
3881 }
3882
3883 }
3884
e6cb77a0
AD
3885 if ($op == "pref-users") {
3886
3887 $subop = $_GET["subop"];
3888
3889 if ($subop == "editSave") {
3890
3891 if (!WEB_DEMO_MODE) {
3892
3893 $login = db_escape_string($_GET["l"]);
3894 $uid = db_escape_string($_GET["id"]);
3895 $access_level = sprintf("%d", $_GET["al"]);
72932a75 3896 $email = db_escape_string($_GET["e"]);
e6cb77a0 3897
72932a75
AD
3898 db_query($link, "UPDATE ttrss_users SET login = '$login',
3899 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
e6cb77a0
AD
3900
3901 }
3902 } else if ($subop == "remove") {
3903
3904 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3905
f932bc9f 3906 $ids = split(",", db_escape_string($_GET["ids"]));
e6cb77a0
AD
3907
3908 foreach ($ids as $id) {
3909 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3910
3911 }
3912 }
3913 } else if ($subop == "add") {
3914
3915 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3916
b6b535ca 3917 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0
AD
3918 $tmp_user_pwd = make_password(8);
3919 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3920
69c0d759
AD
3921 db_query($link, "INSERT INTO ttrss_users
3922 (login,pwd_hash,access_level,last_login)
3923 VALUES ('$login', '$pwd_hash', 0, NOW())");
e6cb77a0
AD
3924
3925
3926 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3927 login = '$login' AND pwd_hash = '$pwd_hash'");
3928
3929 if (db_num_rows($result) == 1) {
3930
3931 $new_uid = db_fetch_result($result, 0, "id");
3932
3933 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3934 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3935
3936 initialize_user($link, $new_uid);
3937
3938 } else {
3939
3940 print "<div class=\"warning\">Error while adding user <b>".
3941 $_GET["login"].".</b></div>";
3942
3943 }
3944 }
3945 } else if ($subop == "resetPass") {
3946
3947 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3948
3949 $uid = db_escape_string($_GET["id"]);
3950
72932a75
AD
3951 $result = db_query($link, "SELECT login,email
3952 FROM ttrss_users WHERE id = '$uid'");
e6cb77a0
AD
3953
3954 $login = db_fetch_result($result, 0, "login");
72932a75 3955 $email = db_fetch_result($result, 0, "email");
e6cb77a0
AD
3956 $tmp_user_pwd = make_password(8);
3957 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3958
3959 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3960 WHERE id = '$uid'");
3961
3962 print "<div class=\"notice\">Changed password of
72932a75
AD
3963 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3964
3965 if (MAIL_RESET_PASS && $email) {
3966 print " Notifying <b>$email</b>.";
3967
3968 mail("$login <$email>", "Password reset notification",
3969 "Hi, $login.\n".
3970 "\n".
3971 "Your password for this TT-RSS installation was reset by".
3972 " an administrator.\n".
3973 "\n".
3974 "Your new password is $tmp_user_pwd, please remember".
3975 " it for later reference.\n".
3976 "\n".
3977 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3978 }
3979
3980 print "</div>";
e6cb77a0
AD
3981
3982 }
3983 }
3984
2c7070b5 3985 print "<div class=\"prefGenericAddBox\">
f932bc9f 3986 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\">&nbsp;";
e6cb77a0 3987
2c7070b5
AD
3988 print"<input type=\"submit\" class=\"button\"
3989 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
e6cb77a0
AD
3990
3991 $result = db_query($link, "SELECT
72932a75 3992 id,login,access_level,email,
fe99ab12 3993 SUBSTRING(last_login,1,16) as last_login
e6cb77a0
AD
3994 FROM
3995 ttrss_users
3996 ORDER by login");
3997
2317ffaa 3998 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1a7572cb 3999
f4fe2cde
AD
4000 print "<p><table width=\"100%\" cellspacing=\"0\"
4001 class=\"prefUserList\" id=\"prefUserList\">";
e6cb77a0 4002
35f3c923
AD
4003 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
4004 Select:
4005 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 4006 'UMRR-', 'UMCHK-', true)\">All</a>,
35f3c923 4007 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 4008 'UMRR-', 'UMCHK-', false)\">None</a>
35f3c923
AD
4009 </td</tr>";
4010
e6cb77a0 4011 print "<tr class=\"title\">
e325c6e7 4012 <td align='center' width=\"5%\">&nbsp;</td>
72932a75
AD
4013 <td width='20%'>Username</td>
4014 <td width='20%'>E-mail</td>
4015 <td width='20%'>Access Level</td>
4016 <td width='20%'>Last login</td></tr>";
e6cb77a0
AD
4017
4018 $lnum = 0;
4019
4020 while ($line = db_fetch_assoc($result)) {
4021
4022 $class = ($lnum % 2) ? "even" : "odd";
4023
4024 $uid = $line["id"];
4025 $edit_uid = $_GET["id"];
4026
4154a415 4027 if ($subop == "edit" && $uid != $edit_uid) {
e6cb77a0 4028 $class .= "Grayed";
53226edc
AD
4029 $this_row_id = "";
4030 } else {
4031 $this_row_id = "id=\"UMRR-$uid\"";
4032 }
4033
4034 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
4035
4036 $line["login"] = htmlspecialchars($line["login"]);
4037
6be6bc03
AD
4038 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
4039 strtotime($line["last_login"]));
4040
5917a8e4
AD
4041 $access_level_names = array(0 => "User", 10 => "Administrator");
4042
72932a75 4043/* if ($uid == $_SESSION["uid"]) {
e6cb77a0 4044
a426e532 4045 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
e6cb77a0
AD
4046 id=\"UMCHK-".$line["id"]."\"></td>";
4047
72932a75
AD
4048 print "<td>".$line["login"]."</td>";
4049 print "<td>".$line["email"]."</td>";
4050 print "<td>".$line["access_level"]."</td>";
e6cb77a0 4051
72932a75 4052 } else */ if (!$edit_uid || $subop != "edit") {
e6cb77a0 4053
a426e532 4054 print "<td align='center'><input onclick='toggleSelectRow(this);'
1a7572cb 4055 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
4056
4057 print "<td><a href=\"javascript:editUser($uid);\">" .
4058 $line["login"] . "</td>";
72932a75
AD
4059
4060 print "<td><a href=\"javascript:editUser($uid);\">" .
4061 $line["email"] . "</td>";
4062
e6cb77a0 4063 print "<td><a href=\"javascript:editUser($uid);\">" .
5917a8e4 4064 $access_level_names[$line["access_level"]] . "</td>";
e6cb77a0
AD
4065
4066 } else if ($uid != $edit_uid) {
4067
72932a75 4068 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
e6cb77a0
AD
4069 id=\"UMCHK-".$line["id"]."\"></td>";
4070
4071 print "<td>".$line["login"]."</td>";
72932a75 4072 print "<td>".$line["email"]."</td>";
5917a8e4 4073 print "<td>".$access_level_names[$line["access_level"]]."</td>";
e6cb77a0
AD
4074
4075 } else {
4076
72932a75
AD
4077 print "<td align='center'>
4078 <input disabled=\"true\" type=\"checkbox\" checked></td>";
e6cb77a0
AD
4079
4080 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
4081 "\"></td>";
4082
72932a75
AD
4083 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
4084 "\"></td>";
4085
5917a8e4
AD
4086// print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
4087// "\"></td>";
4088
4089 print "<td>";
4090 print "<select id=\"iedit_ulevel\">";
4091 foreach (array_keys($access_level_names) as $al) {
4092 if ($al == $line["access_level"]) {
4093 $selected = "selected";
4094 } else {
4095 $selected = "";
4096 }
4097 print "<option $selected id=\"$al\">" .
4098 $access_level_names[$al] . "</option>";
4099 }
4100 print "</select>";
4101 print "</td>";
4102
e6cb77a0
AD
4103 }
4104
f6f32198
AD
4105 print "<td>".$line["last_login"]."</td>";
4106
e6cb77a0
AD
4107 print "</tr>";
4108
4109 ++$lnum;
4110 }
4111
4112 print "</table>";
4113
4114 print "<p>";
4115
4116 if ($subop == "edit") {
d10fabe4 4117 print "Edit user:
e6cb77a0 4118 <input type=\"submit\" class=\"button\"
d10fabe4 4119 onclick=\"javascript:userEditSave()\" value=\"Save\">
e6cb77a0 4120 <input type=\"submit\" class=\"button\"
d10fabe4 4121 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
e6cb77a0
AD
4122
4123 } else {
4124
4125 print "
4126 Selection:
4127 <input type=\"submit\" class=\"button\"
717f5e64 4128 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
e6cb77a0
AD
4129 <input type=\"submit\" class=\"button\"
4130 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
4131 <input type=\"submit\" class=\"button\"
717f5e64
AD
4132 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
4133 <input type=\"submit\" class=\"button\"
4134 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
4135
4136 }
4137 }
4138
4139 if ($op == "user-details") {
4140
4141 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
4142 return;
4143 }
4144
1a7572cb 4145/* print "<html><head>
717f5e64
AD
4146 <title>Tiny Tiny RSS : User Details</title>
4147 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
4148 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 4149 </head><body>"; */
717f5e64
AD
4150
4151 $uid = sprintf("%d", $_GET["id"]);
4152
c6c3a07f 4153 print "<div class='infoBoxContents'>";
717f5e64 4154
fe99ab12
AD
4155 $result = db_query($link, "SELECT login,
4156 SUBSTRING(last_login,1,16) AS last_login,
4157 access_level,
c6c3a07f
AD
4158 (SELECT COUNT(int_id) FROM ttrss_user_entries
4159 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
4160 FROM ttrss_users
4161 WHERE id = '$uid'");
4162
4163 if (db_num_rows($result) == 0) {
4164 print "<h1>User not found</h1>";
4165 return;
4166 }
4167
4168 print "<h1>User Details</h1>";
4169
4170 print "<table width='100%'>";
4171
4172 $login = db_fetch_result($result, 0, "login");
6be6bc03
AD
4173 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
4174 strtotime(db_fetch_result($result, 0, "last_login")));
717f5e64 4175 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 4176 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64
AD
4177
4178 print "<tr><td>Username</td><td>$login</td></tr>";
4179 print "<tr><td>Access level</td><td>$access_level</td></tr>";
4180 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 4181 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
4182
4183 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
4184 WHERE owner_uid = '$uid'");
4185
4186 $num_feeds = db_fetch_result($result, 0, "num_feeds");
4187
4188 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
4189
5d15d3ea 4190/* $result = db_query($link, "SELECT
717f5e64 4191 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
4192 FROM ttrss_user_entries,ttrss_entries
4193 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 4194
d9f115c3 4195 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 4196
c6c3a07f 4197 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
4198
4199 print "</table>";
4200
4201 print "<h1>Subscribed feeds</h1>";
4202
e94645ca 4203 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
9b3e2cc7 4204 WHERE owner_uid = '$uid' ORDER BY title");
717f5e64 4205
9b3e2cc7 4206 print "<ul class=\"userFeedList\">";
717f5e64
AD
4207
4208 while ($line = db_fetch_assoc($result)) {
4209
4210 $icon_file = ICONS_URL."/".$line["id"].".ico";
4211
4212 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 4213 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 4214 } else {
5951ded1 4215 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
4216 }
4217
e94645ca 4218 print "<li>$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
e6cb77a0 4219 }
717f5e64 4220
a88c1f36
AD
4221 if (db_num_rows($result) < $num_feeds) {
4222 // FIXME - add link to show ALL subscribed feeds here somewhere
4223 print "<li><img
4224 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
4225 }
4226
717f5e64
AD
4227 print "</ul>";
4228
717f5e64
AD
4229 print "</div>";
4230
1a7572cb
AD
4231 print "<div align='center'>
4232 <input type='submit' class='button'
c6c3a07f 4233 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
4234
4235// print "</body></html>";
717f5e64 4236
e6cb77a0
AD
4237 }
4238
c6c3a07f
AD
4239 if ($op == "feed-details") {
4240
df268d47 4241// $feed_id = $_GET["id"];
4fec9fd7 4242
df268d47 4243 $feed_ids = split(",", db_escape_string($_GET["id"]));
c6c3a07f 4244
df268d47 4245 print "<div class=\"infoBoxContents\">";
bca02305 4246
df268d47 4247 foreach ($feed_ids as $feed_id) {
c6c3a07f 4248
df268d47
AD
4249 $result = db_query($link,
4250 "SELECT
4251 title,feed_url,
4252 SUBSTRING(last_updated,1,16) as last_updated,
4253 icon_url,site_url,
4254 (SELECT COUNT(int_id) FROM ttrss_user_entries
4255 WHERE feed_id = id) AS total,
4256 (SELECT COUNT(int_id) FROM ttrss_user_entries
4257 WHERE feed_id = id AND unread = true) AS unread,
4258 (SELECT COUNT(int_id) FROM ttrss_user_entries
4259 WHERE feed_id = id AND marked = true) AS marked
4260 FROM ttrss_feeds
4261 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
4262
4263 if (db_num_rows($result) == 0) return;
4264
4265 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
4266 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
4267 strtotime(db_fetch_result($result, 0, "last_updated")));
4268 $feed_url = db_fetch_result($result, 0, "feed_url");
4269 $icon_url = db_fetch_result($result, 0, "icon_url");
4270 $total = db_fetch_result($result, 0, "total");
4271 $unread = db_fetch_result($result, 0, "unread");
4272 $marked = db_fetch_result($result, 0, "marked");
4273 $site_url = db_fetch_result($result, 0, "site_url");
bca02305 4274
df268d47 4275 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3803fa6a 4276 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false");
df268d47
AD
4277
4278 $subscribed = db_fetch_result($result, 0, "subscribed");
4279
4280 $icon_file = ICONS_DIR . "/$feed_id.ico";
4281
4282 if (file_exists($icon_file) && filesize($icon_file) > 0) {
4283 $feed_icon = "<img width=\"16\" height=\"16\"
4284 src=\"" . ICONS_URL . "/$feed_id.ico\">";
4285 } else {
4286 $feed_icon = "";
bca02305
AD
4287 }
4288
df268d47 4289 print "<h1>$feed_icon $title</h1>";
bca02305 4290
df268d47 4291 print "<table width='100%'>";
bca02305 4292
df268d47
AD
4293 if ($site_url) {
4294 print "<tr><td width='30%'>Link</td>
4295 <td><a href=\"$site_url\">$site_url</a>
4296 <a href=\"$feed_url\">(feed)</a></td>
4297 </td></tr>";
4298 } else {
4299 print "<tr><td width='30%'>Feed URL</td>
4300 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
4301 }
4302 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
4303 print "<tr><td>Total articles</td><td>$total</td></tr>";
4304 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
4305 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
4306 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
4307
4308 print "</table>";
4309
4310/* $result = db_query($link, "SELECT title,
4311 SUBSTRING(updated,1,16) AS updated,unread
4312 FROM ttrss_entries,ttrss_user_entries
4313 WHERE ref_id = id AND feed_id = '$feed_id'
4314 ORDER BY date_entered DESC LIMIT 5");
4315
4316 if (db_num_rows($result) > 0) {
4317
4318 print "<h1>Latest headlines</h1>";
4319
4320 print "<ul class=\"nomarks\">";
4321
4322 while ($line = db_fetch_assoc($result)) {
4323 if ($line["unread"] == "t" || $line["unread"] == "1") {
4324 $line["title"] = "<b>" . $line["title"] . "</b>";
4325 }
4326 print "<li>" . $line["title"].
4327 "&nbsp;<span class=\"insensitive\">(" .
4328 date(get_pref($link, 'SHORT_DATE_FORMAT'),
4329 strtotime($line["updated"])).
4330 ")</span></li>";
4331 }
4332
4333 print "</ul>";
4334
4335 } */
bca02305 4336 }
df268d47
AD
4337
4338 print "</div>";
4339
4340 print "<div align='center'>
4341 <input type='submit' class='button'
4342 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
4343 }
c6c3a07f 4344
c6232e43
AD
4345 if ($op == "pref-feed-browser") {
4346
e2f728be
AD
4347 if (!ENABLE_FEED_BROWSER) {
4348 print "Feed browser is administratively disabled.";
4349 return;
4350 }
4351
c6232e43
AD
4352 $subop = $_REQUEST["subop"];
4353
4354 if ($subop == "details") {
4355 $id = db_escape_string($_GET["id"]);
c2b2aee0 4356
072f1ee2
AD
4357 print "<div class=\"browserFeedInfo\">";
4358 print "<b>Feed information:</b>";
4359 print "<div class=\"detailsPart\">";
4360
4361 $result = db_query($link, "SELECT
4362 feed_url,site_url,
4363 SUBSTRING(last_updated,1,19) AS last_updated
4364 FROM ttrss_feeds WHERE id = '$id'");
4365
4366 $feed_url = db_fetch_result($result, 0, "feed_url");
4367 $site_url = db_fetch_result($result, 0, "site_url");
4368 $last_updated = db_fetch_result($result, 0, "last_updated");
4369
4370 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
4371 $last_updated = smart_date_time(strtotime($last_updated));
4372 } else {
4373 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
4374 $last_updated = date($short_date, strtotime($last_updated));
4375 }
4376
4377 print "Site: <a href='$site_url'>$site_url</a> ".
4378 "(<a href='$feed_url'>feed</a>), ".
4379 "Last updated: $last_updated";
4380
4381 print "</div>";
4382
4383 $result = db_query($link, "SELECT
4384 ttrss_entries.title,
4385 content,
c2b2aee0
AD
4386 substring(date_entered,1,19) as date_entered,
4387 substring(updated,1,19) as updated
072f1ee2
AD
4388 FROM ttrss_entries,ttrss_user_entries
4389 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
c2b2aee0
AD
4390 ORDER BY updated DESC LIMIT 5");
4391
4392 if (db_num_rows($result) > 0) {
c2b2aee0
AD
4393
4394 print "<b>Last headlines:</b><br>";
4395
4396 print "<div class=\"detailsPart\">";
4397 print "<ul class=\"compact\">";
4398 while ($line = db_fetch_assoc($result)) {
4399
4400 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
4401 $entry_dt = smart_date_time(strtotime($line["updated"]));
4402 } else {
4403 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
4404 $entry_dt = date($short_date, strtotime($line["updated"]));
4405 }
4406
4407 print "<li>" . $line["title"] .
4408 "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";
4409 }
4410 print "</ul></div>";
4411 }
072f1ee2
AD
4412
4413 print "</div>";
c2b2aee0 4414
c6232e43
AD
4415 return;
4416 }
65f28a40 4417
c6232e43
AD
4418 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
4419 FROM ttrss_feeds
4420 WHERE auth_login = '' AND auth_pass = '' AND private = false
65f28a40 4421 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100");
c6232e43 4422
0fefdacc 4423 print "<ul class='nomarks' id='browseBigFeedList'>";
c6232e43
AD
4424
4425 $feedctr = 0;
4426
4427 while ($line = db_fetch_assoc($result)) {
4428 $feed_url = $line["feed_url"];
4429 $subscribers = $line["subscribers"];
4430
4431 $sub_result = db_query($link, "SELECT id
4432 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
4433 $_SESSION["uid"]);
4434
4435 if (db_num_rows($sub_result) > 0) {
4436 continue; // already subscribed
4437 }
4438
4439 $det_result = db_query($link, "SELECT site_url,title,id
4440 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
4441
4442 $details = db_fetch_assoc($det_result);
4443
4444 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
4445
4446 if (file_exists($icon_file) && filesize($icon_file) > 0) {
4447 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
4448 "/".$details["id"].".ico\">";
4449 } else {
4450 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
4451 }
4452
4453 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
4454 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
4455
4456 $class = ($feedctr % 2) ? "even" : "odd";
4457
4458 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
4459 "$feed_icon ";
4460
c2b2aee0 4461 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
c6232e43
AD
4462 $details["title"] ."</a>&nbsp;" .
4463 "<span class='subscribers'>($subscribers)</span>";
4464
4465 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
4466 print "</div>";
4467
4468 print "</li>";
4469
4470 ++$feedctr;
4471 }
4472
4473 if ($feedctr == 0) {
4474 print "<li>No feeds found to subscribe.</li>";
4475 }
4476
4477 print "</ul>";
4478
0010d872
AD
4479 print "<p>Selection:
4480 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
4481 value=\"Subscribe\"></p>";
c6232e43
AD
4482
4483 print "</div>";
4484
4485 }
4486
4b3dff6e 4487 db_close($link);
1cd17194 4488?>
406d9489
AD
4489
4490<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
4491