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