6 if (($op == "rpc" ||
$op == "updateAllFeeds" ||
7 $op == "forceUpdateAllFeeds") && !$_REQUEST["noxml"]) {
8 header("Content-Type: application/xml");
11 if (!$_SESSION["uid"]) {
13 if (($op == "rpc" ||
$op == "updateAllFeeds" ||
14 $op == "forceUpdateAllFeeds")) {
15 print "<error error-code=\"6\"/>";
20 define(SCHEMA_VERSION
, 2);
22 require_once "config.php";
23 require_once "db.php";
24 require_once "db-prefs.php";
25 require_once "functions.php";
26 require_once "magpierss/rss_fetch.inc";
28 $script_started = getmicrotime();
30 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
33 if (DB_TYPE
== "mysql") {
36 // PG seems to display its own errors just fine by default.
40 if (DB_TYPE
== "pgsql") {
41 pg_query("set client_encoding = 'utf-8'");
45 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
47 $schema_version = db_fetch_result($result, 0, "schema_version");
49 if ($schema_version != SCHEMA_VERSION) {
50 print "Error: database schema is invalid
51 (got version $schema_version; expected ".SCHEMA_VERSION.")";
56 $fetch = $_GET["fetch"];
58 /* FIXME this needs reworking */
60 function getGlobalCounters($link) {
61 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
62 WHERE unread = true AND
63 ttrss_user_entries.ref_id = ttrss_entries.id AND
64 owner_uid = " . $_SESSION["uid"]);
65 $c_id = db_fetch_result($result, 0, "c_id");
66 print "<counter id='global-unread' counter='$c_id'/>";
69 function getTagCounters($link) {
71 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
72 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
73 ttrss_user_entries.ref_id = ttrss_entries.id AND
74 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
75 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
77 select tag_name,0 as count FROM ttrss_tags
78 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
82 while ($line = db_fetch_assoc($result)) {
83 $tags[$line["tag_name"]] +
= $line["count"];
86 foreach (array_keys($tags) as $tag) {
87 $unread = $tags[$tag];
89 $tag = htmlspecialchars($tag);
90 print "<tag id=\"$tag\" counter=\"$unread\"/>";
94 function getLabelCounters($link) {
96 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
97 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
98 unread = true AND owner_uid = ".$_SESSION["uid"]);
100 $count = db_fetch_result($result, 0, "count");
102 print "<label id=\"-1\" counter=\"$count\"/>";
104 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
105 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
107 while ($line = db_fetch_assoc($result)) {
109 $id = -$line["id"] - 11;
113 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
114 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
115 ttrss_user_entries.ref_id = ttrss_entries.id AND
116 owner_uid = ".$_SESSION["uid"]);
118 $count = db_fetch_result($tmp_result, 0, "count");
120 print "<label id=\"$id\" counter=\"$count\"/>";
122 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
127 function getFeedCounter($link, $id) {
129 $result = db_query($link, "SELECT
130 count(id) as count FROM ttrss_entries,ttrss_user_entries
131 WHERE feed_id = '$id' AND unread = true
132 AND ttrss_user_entries.ref_id = ttrss_entries.id");
134 $count = db_fetch_result($result, 0, "count");
136 print "<feed id=\"$id\" counter=\"$count\"/>";
139 function getFeedCounters($link) {
141 $result = db_query($link, "SELECT id,
143 FROM ttrss_entries,ttrss_user_entries
144 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
145 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
146 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
148 while ($line = db_fetch_assoc($result)) {
151 $count = $line["count"];
153 print "<feed id=\"$id\" counter=\"$count\"/>";
157 function outputFeedList($link, $tags = false) {
160 <title>Tiny Tiny RSS : Feedlist</title>
161 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
163 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
164 print "<link rel=\"stylesheet\" type=\"text/css\"
165 href=\"tt-rss_compact.css\"/>";
167 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
168 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
171 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
172 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
173 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
174 </head><body onload=\"init()\">";
176 print "<ul class=\"feedList\" id=\"feedList\">";
178 $owner_uid = $_SESSION["uid"];
184 $result = db_query($link, "SELECT count(id) as num_starred
185 FROM ttrss_entries,ttrss_user_entries
186 WHERE marked = true AND
187 ttrss_user_entries.ref_id = ttrss_entries.id AND
188 unread = true AND owner_uid = '$owner_uid'");
189 $num_starred = db_fetch_result($result, 0, "num_starred");
193 if ($num_starred > 0) $class .= "Unread";
195 printFeedEntry(-1, $class, "Starred articles", $num_starred,
196 "images/mark_set.png", $link);
198 if (get_pref($link, 'ENABLE_LABELS')) {
200 $result = db_query($link, "SELECT id,sql_exp,description FROM
201 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
203 if (db_num_rows($result) > 0) {
204 print "<li><hr></li>";
207 while ($line = db_fetch_assoc($result)) {
211 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
212 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
213 ttrss_user_entries.ref_id = ttrss_entries.id
214 AND owner_uid = '$owner_uid'");
216 $count = db_fetch_result($tmp_result, 0, "count");
224 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
226 printFeedEntry(-$line["id"]-11,
227 $class, $line["description"], $count, "images/label.png", $link);
232 print "<li><hr></li>";
234 $result = db_query($link, "SELECT *,
235 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
236 WHERE feed_id = ttrss_feeds.id AND
237 ttrss_user_entries.ref_id = ttrss_entries.id AND
238 owner_uid = '$owner_uid') AS total,
239 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
240 WHERE feed_id = ttrss_feeds.id AND unread = true
241 AND ttrss_user_entries.ref_id = ttrss_entries.id
242 AND owner_uid = '$owner_uid') as unread
243 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");
245 $actid = $_GET["actid"];
253 while ($line = db_fetch_assoc($result)) {
255 $feed = $line["title"];
256 $feed_id = $line["id"];
258 $subop = $_GET["subop"];
260 $total = $line["total"];
261 $unread = $line["unread"];
263 // $class = ($lnum % 2) ? "even" : "odd";
267 if ($unread > 0) $class .= "Unread";
269 if ($actid == $feed_id) {
270 $class .= "Selected";
273 $total_unread +
= $unread;
275 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
283 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
284 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
285 post_int_id = ttrss_user_entries.int_id AND
286 unread = true AND ref_id = ttrss_entries.id
287 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
289 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
294 while ($line = db_fetch_assoc($result)) {
295 $tags[$line["tag_name"]] +
= $line["count"];
298 foreach (array_keys($tags) as $tag) {
300 $unread = $tags[$tag];
308 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
314 if (db_num_rows($result) == 0) {
315 print "<li>No tags/feeds to display.</li>";
320 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
327 $subop = $_GET["subop"];
329 if ($subop == "getLabelCounters") {
332 getLabelCounters($link);
334 getFeedCounter($link, $aid);
336 print "</rpc-reply>";
339 if ($subop == "getFeedCounters") {
341 getFeedCounters($link);
342 print "</rpc-reply>";
345 if ($subop == "getAllCounters") {
347 getLabelCounters($link);
348 getFeedCounters($link);
349 getTagCounters($link);
350 getGlobalCounters($link);
351 print "</rpc-reply>";
354 if ($subop == "mark") {
355 $mark = $_GET["mark"];
356 $id = db_escape_string($_GET["id"]);
364 // FIXME this needs collision testing
366 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
367 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
370 if ($subop == "updateFeed") {
371 $feed_id = db_escape_string($_GET["feed"]);
373 $result = db_query($link,
374 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
376 if (db_num_rows($result) > 0) {
377 $feed_url = db_fetch_result($result, 0, "feed_url");
378 // update_rss_feed($link, $feed_url, $feed_id);
381 print "DONE-$feed_id";
386 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
388 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
390 $omode = $_GET["omode"];
392 if (!$omode) $omode = "tfl";
395 if (strchr($omode, "l")) getLabelCounters($link);
396 if (strchr($omode, "f")) getFeedCounters($link);
397 if (strchr($omode, "t")) getTagCounters($link);
398 getGlobalCounters($link);
399 print "</rpc-reply>";
402 if ($subop == "catchupPage") {
404 $ids = split(",", $_GET["ids"]);
406 foreach ($ids as $id) {
408 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
413 print "Marked active page as read.";
416 if ($subop == "sanityCheck") {
420 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
422 $schema_version = db_fetch_result($result, 0, "schema_version");
424 if ($schema_version != SCHEMA_VERSION
) {
428 print "<error error-code='$error_code'/>";
431 if ($subop == "globalPurge") {
434 global_purge_old_posts($link, true);
435 print "</rpc-reply>";
441 if ($op == "feeds") {
443 $tags = $_GET["tags"];
445 $subop = $_GET["subop"];
447 if ($subop == "catchupAll") {
448 db_query($link, "UPDATE ttrss_entries SET
449 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
452 outputFeedList($link, $tags);
459 $feed_id = $_GET["feed"];
461 $result = db_query($link, "UPDATE ttrss_user_entries
462 SET unread = false,last_read = NOW()
463 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
465 $addheader = $_GET["addheader"];
467 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
468 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
469 FROM ttrss_entries,ttrss_user_entries
470 WHERE id = '$id' AND ref_id = id");
474 <title>Tiny Tiny RSS : Article $id</title>
475 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
476 <script type=\"text/javascript\" src=\"functions.js\"></script>
477 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
483 $line = db_fetch_assoc($result);
485 if ($line["icon_url"]) {
486 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
488 $feed_icon = " ";
491 if ($line["comments"] && $line["link"] != $line["comments"]) {
492 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
494 $entry_comments = "";
497 print "<div class=\"postReply\">";
499 print "<div class=\"postHeader\"><table>";
501 print "<tr><td><b>Title:</b></td>
502 <td width='100%'>" . $line["title"] . "</td></tr>";
504 print "<tr><td><b>Link:</b></td>
506 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
507 $entry_comments</td></tr>";
509 print "</table></div>";
511 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
512 print "<div class=\"postContent\">" . $line["content"] . "</div>";
516 print "<script type=\"text/javascript\">
517 update_label_counters('$feed_id');
522 print "</body></html>";
526 if ($op == "viewfeed") {
528 $feed = $_GET["feed"];
529 $skip = $_GET["skip"];
530 $subop = $_GET["subop"];
531 $view_mode = $_GET["view"];
532 $addheader = $_GET["addheader"];
533 $limit = $_GET["limit"];
536 print "Error: no feed to display.";
540 if (!$skip) $skip = 0;
542 if ($subop == "undefined") $subop = "";
546 <title>Tiny Tiny RSS : Feed $feed</title>
547 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
549 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
550 print "<link rel=\"stylesheet\"
551 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
554 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
555 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
557 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
558 <script type=\"text/javascript\" src=\"functions.js\"></script>
559 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
560 </head><body onload='init()'>";
563 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
565 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
566 WHERE id = '$feed'");
568 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
570 update_rss_feed($link, $feed_url, $feed);
574 if ($subop == "MarkAllRead") {
576 if (sprintf("%d", $feed) != 0) {
579 db_query($link, "UPDATE ttrss_user_entries
580 SET unread = false,last_read = NOW()
581 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
583 } else if ($feed < 0 && $feed > -10) { // special, like starred
586 db_query($link, "UPDATE ttrss_user_entries
587 SET unread = false,last_read = NOW()
588 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
591 } else if ($feed < -10) { // label
593 // TODO make this more efficient
595 $label_id = -$feed - 11;
597 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
598 WHERE id = '$label_id'");
601 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
603 db_query($link, "BEGIN");
605 $tmp2_result = db_query($link,
609 ttrss_user_entries,ttrss_entries
613 owner_uid = " . $_SESSION["uid"]);
615 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
616 db_query($link, "UPDATE
619 unread = false, last_read = NOW()
621 int_id = " . $tmp_line["int_id"]);
624 db_query($link, "COMMIT");
626 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
627 SET unread = false,last_read = NOW()
630 AND owner_uid = ".$_SESSION["uid"]); */
634 // FIXME, implement catchup for tags
639 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
641 $search = $_GET["search"];
643 $search_mode = $_GET["smode"];
646 $search_query_part = "(upper(title) LIKE upper('%$search%')
647 OR content LIKE '%$search%') AND";
649 $search_query_part = "";
652 $view_query_part = "";
654 if ($view_mode == "Starred") {
655 $view_query_part = " marked = true AND ";
658 if ($view_mode == "Unread") {
659 $view_query_part = " unread = true AND ";
662 if ($view_mode == "Unread or Starred") {
663 $view_query_part = " (unread = true OR marked = true) AND ";
666 if ($view_mode == "Unread or Updated") {
667 $view_query_part = " (unread = true OR last_read is NULL) AND ";
670 /* $result = db_query($link, "SELECT count(id) AS total_entries
671 FROM ttrss_entries WHERE
675 $total_entries = db_fetch_result($result, 0, "total_entries"); */
677 /* $result = db_query("SELECT count(id) AS unread_entries
678 FROM ttrss_entries WHERE
683 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
685 if ($limit && $limit != "All") {
686 $limit_query_part = "LIMIT " . $limit;
689 $vfeed_query_part = "";
691 // override query strategy and enable feed display when searching globally
692 if ($search && $search_mode == "All feeds") {
693 $query_strategy_part = "id > 0";
694 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
695 id = feed_id) as feed_title,";
696 } else if (sprintf("%d", $feed) == 0) {
697 $query_strategy_part = "ttrss_entries.id > 0";
698 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
699 id = feed_id) as feed_title,";
700 } else if ($feed >= 0) {
701 $query_strategy_part = "feed_id = '$feed'";
702 } else if ($feed == -1) { // starred virtual feed
703 $query_strategy_part = "marked = true";
704 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
705 id = feed_id) as feed_title,";
706 } else if ($feed <= -10) { // labels
707 $label_id = -$feed - 11;
709 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
710 WHERE id = '$label_id'");
712 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
714 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
715 id = feed_id) as feed_title,";
717 $query_strategy_part = "id > 0"; // dumb
721 $order_by = "updated DESC";
723 // if ($feed < -10) {
724 // $order_by = "feed_id,updated DESC";
727 if ($feed < -10) error_reporting (0);
729 if (sprintf("%d", $feed) != 0) {
731 $result = db_query($link, "SELECT
732 id,title,updated,unread,feed_id,marked,link,last_read,
733 SUBSTRING(last_read,1,19) as last_read_noms,
735 SUBSTRING(updated,1,19) as updated_noms
737 ttrss_entries,ttrss_user_entries
739 ttrss_user_entries.ref_id = ttrss_entries.id AND
740 owner_uid = '".$_SESSION["uid"]."' AND
743 $query_strategy_part ORDER BY $order_by
749 $result = db_query($link, "SELECT
750 ttrss_entries.id as id,title,updated,unread,feed_id,
751 marked,link,last_read,
752 SUBSTRING(last_read,1,19) as last_read_noms,
754 SUBSTRING(updated,1,19) as updated_noms
756 ttrss_entries,ttrss_user_entries,ttrss_tags
758 ref_id = ttrss_entries.id AND
759 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
760 post_int_id = int_id AND tag_name = '$feed' AND
763 $query_strategy_part ORDER BY $order_by
768 print "<tr><td colspan='4' align='center'>
769 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
775 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
779 while ($line = db_fetch_assoc($result)) {
781 $class = ($lnum %
2) ?
"even" : "odd";
784 $feed_id = $line["feed_id"];
786 // printf("L %d (%s) > U %d (%s) = %d<br>",
787 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
788 // strtotime($line["updated"]), $line["updated"],
789 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
791 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
792 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
794 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
799 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
804 if ($line["last_read"] == "" &&
805 ($line["unread"] != "t" && $line["unread"] != "1")) {
807 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
810 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
814 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
819 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
820 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
821 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
823 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
824 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
827 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
828 $line["title"] . "</a>";
830 print "<tr class='$class' id='RROW-$id'>";
831 // onclick=\"javascript:view($id,$feed_id)\">
833 print "<td valign='center' align='center'>$update_pic</td>";
834 print "<td valign='center' align='center'>$marked_pic</td>";
836 print "<td width='25%'>
837 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
839 if ($line["feed_title"]) {
840 print "<td width='50%'>$content_link</td>";
841 print "<td width='20%'>
842 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
844 print "<td width='70%'>$content_link</td>";
853 print "<tr><td align='center'>No articles found.</td></tr>";
858 print "<script type=\"text/javascript\">
859 document.onkeydown = hotkey_handler;
860 update_label_counters('$feed');
864 print "</body></html>";
869 if ($op == "pref-rpc") {
871 $subop = $_GET["subop"];
873 if ($subop == "unread") {
874 $ids = split(",", $_GET["ids"]);
875 foreach ($ids as $id) {
876 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
879 print "Marked selected feeds as read.";
882 if ($subop == "read") {
883 $ids = split(",", $_GET["ids"]);
884 foreach ($ids as $id) {
885 db_query($link, "UPDATE ttrss_entries
886 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
889 print "Marked selected feeds as unread.";
895 if ($op == "pref-feeds") {
897 $subop = $_GET["subop"];
899 if ($subop == "editSave") {
900 $feed_title = db_escape_string($_GET["t"]);
901 $feed_link = db_escape_string($_GET["l"]);
902 $upd_intl = db_escape_string($_GET["ui"]);
903 $purge_intl = db_escape_string($_GET["pi"]);
904 $feed_id = $_GET["id"];
906 if (strtoupper($upd_intl) == "DEFAULT")
909 if (strtoupper($purge_intl) == "DEFAULT")
912 if (strtoupper($purge_intl) == "DISABLED")
915 $result = db_query($link, "UPDATE ttrss_feeds SET
916 title = '$feed_title', feed_url = '$feed_link',
917 update_interval = '$upd_intl',
918 purge_interval = '$purge_intl'
919 WHERE id = '$feed_id'");
923 if ($subop == "remove") {
925 if (!WEB_DEMO_MODE
) {
927 $ids = split(",", $_GET["ids"]);
929 foreach ($ids as $id) {
930 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
932 $icons_dir = ICONS_DIR
;
934 if (file_exists($icons_dir . "/$id.ico")) {
935 unlink($icons_dir . "/$id.ico");
941 if ($subop == "add") {
943 if (!WEB_DEMO_MODE
) {
945 $feed_link = db_escape_string($_GET["link"]);
947 $result = db_query($link,
948 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
950 $result = db_query($link,
951 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
953 $feed_id = db_fetch_result($result, 0, "id");
956 update_rss_feed($link, $feed_link, $feed_id);
961 $result = db_query($link, "SELECT id,title,feed_url,last_error
962 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
964 if (db_num_rows($result) > 0) {
966 print "<div class=\"warning\">";
968 print "<b>Feeds with update errors:</b>";
970 print "<ul class=\"nomarks\">";
972 while ($line = db_fetch_assoc($result)) {
973 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
982 print "<table class=\"prefAddFeed\"><tr>
983 <td><input id=\"fadd_link\"></td>
984 <td colspan=\"4\" align=\"right\">
985 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
988 $result = db_query($link, "SELECT
989 id,title,feed_url,substring(last_updated,1,16) as last_updated,
990 update_interval,purge_interval
992 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
994 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
995 print "<tr class=\"title\">
996 <td> </td><td>Select</td><td width=\"30%\">Title</td>
997 <td width=\"30%\">Link</td>
998 <td width=\"10%\">Update Interval</td>
999 <td width=\"10%\">Purge Days</td>
1000 <td>Last updated</td></tr>";
1004 while ($line = db_fetch_assoc($result)) {
1006 $class = ($lnum %
2) ?
"even" : "odd";
1008 $feed_id = $line["id"];
1010 $edit_feed_id = $_GET["id"];
1012 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1016 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
1018 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1020 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1021 $feed_icon = "<img width=\"16\" height=\"16\"
1022 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1024 $feed_icon = " ";
1026 print "<td align='center'>$feed_icon</td>";
1028 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1029 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1031 if (!$edit_feed_id ||
$subop != "edit") {
1033 print "<td><input onclick='toggleSelectRow(this);'
1034 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1036 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1037 $edit_title . "</a></td>";
1038 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1039 $edit_link . "</a></td>";
1041 if ($line["update_interval"] == "0")
1042 $line["update_interval"] = "Default";
1044 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1045 $line["update_interval"] . "</a></td>";
1047 if ($line["purge_interval"] == "0")
1048 $line["purge_interval"] = "Default";
1050 if ($line["purge_interval"] < 0)
1051 $line["purge_interval"] = "Disabled";
1053 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1054 $line["purge_interval"] . "</a></td>";
1056 } else if ($feed_id != $edit_feed_id) {
1058 print "<td><input disabled=\"true\" type=\"checkbox\"
1059 id=\"FRCHK-".$line["id"]."\"></td>";
1061 print "<td>$edit_title</td>";
1062 print "<td>$edit_link</td>";
1064 if ($line["update_interval"] == "0")
1065 $line["update_interval"] = "Default";
1067 print "<td>" . $line["update_interval"] . "</td>";
1069 if ($line["purge_interval"] == "0")
1070 $line["purge_interval"] = "Default";
1072 if ($line["purge_interval"] < 0)
1073 $line["purge_interval"] = "Disabled";
1075 print "<td>" . $line["purge_interval"] . "</td>";
1079 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1081 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1082 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1083 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
1084 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
1088 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1090 print "<td>" . $line["last_updated"] . "</td>";
1098 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1105 if ($subop == "edit") {
1106 print "Edit feed:
1107 <input type=\"submit\" class=\"button\"
1108 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1109 <input type=\"submit\" class=\"button\"
1110 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1115 <input type=\"submit\" class=\"button\"
1116 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1117 <input type=\"submit\" class=\"button\"
1118 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1120 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1122 <input type=\"submit\" class=\"button\"
1123 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1124 <input type=\"submit\" class=\"button\"
1125 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
1129 <input type=\"submit\"
1130 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1134 print "<h3>OPML Import</h3>
1135 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1136 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1137 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1138 type=\"submit\" value=\"Import\">
1143 if ($op == "pref-filters") {
1145 $subop = $_GET["subop"];
1147 if ($subop == "editSave") {
1149 $regexp = db_escape_string($_GET["r"]);
1150 $descr = db_escape_string($_GET["d"]);
1151 $match = db_escape_string($_GET["m"]);
1152 $filter_id = db_escape_string($_GET["id"]);
1154 $result = db_query($link, "UPDATE ttrss_filters SET
1155 reg_exp = '$regexp',
1156 description = '$descr',
1157 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1158 description = '$match')
1159 WHERE id = '$filter_id'");
1162 if ($subop == "remove") {
1164 if (!WEB_DEMO_MODE
) {
1166 $ids = split(",", $_GET["ids"]);
1168 foreach ($ids as $id) {
1169 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1175 if ($subop == "add") {
1177 if (!WEB_DEMO_MODE
) {
1179 $regexp = db_escape_string($_GET["regexp"]);
1180 $match = db_escape_string($_GET["match"]);
1182 $result = db_query($link,
1183 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES
1184 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1185 description = '$match'),'".$_SESSION["uid"]."')");
1189 $result = db_query($link, "SELECT description
1190 FROM ttrss_filter_types ORDER BY description");
1192 $filter_types = array();
1194 while ($line = db_fetch_assoc($result)) {
1195 array_push($filter_types, $line["description"]);
1198 print "<table class=\"prefAddFeed\"><tr>
1199 <td><input id=\"fadd_regexp\"></td>
1201 print_select("fadd_match", "Title", $filter_types);
1203 print"</td><td colspan=\"4\" align=\"right\">
1204 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1207 $result = db_query($link, "SELECT
1208 id,reg_exp,description,
1209 (SELECT name FROM ttrss_filter_types WHERE
1210 id = filter_type) as filter_type_name,
1211 (SELECT description FROM ttrss_filter_types
1212 WHERE id = filter_type) as filter_type_descr
1216 owner_uid = ".$_SESSION["uid"]."
1219 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1221 print "<tr class=\"title\">
1222 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1223 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1227 while ($line = db_fetch_assoc($result)) {
1229 $class = ($lnum %
2) ?
"even" : "odd";
1231 $filter_id = $line["id"];
1232 $edit_filter_id = $_GET["id"];
1234 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1238 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1240 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1241 $line["description"] = htmlspecialchars($line["description"]);
1243 if (!$edit_filter_id ||
$subop != "edit") {
1245 if (!$line["description"]) $line["description"] = "[No description]";
1247 print "<td><input onclick='toggleSelectRow(this);'
1248 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1250 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1251 $line["reg_exp"] . "</td>";
1253 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1254 $line["description"] . "</td>";
1256 print "<td>".$line["filter_type_descr"]."</td>";
1258 } else if ($filter_id != $edit_filter_id) {
1260 if (!$line["description"]) $line["description"] = "[No description]";
1262 print "<td><input disabled=\"true\" type=\"checkbox\"
1263 id=\"FICHK-".$line["id"]."\"></td>";
1265 print "<td>".$line["reg_exp"]."</td>";
1266 print "<td>".$line["description"]."</td>";
1267 print "<td>".$line["filter_type_descr"]."</td>";
1271 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1273 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1276 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1280 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1292 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1299 if ($subop == "edit") {
1301 <input type=\"submit\" class=\"button\"
1302 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1303 <input type=\"submit\" class=\"button\"
1304 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1310 <input type=\"submit\" class=\"button\"
1311 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1312 <input type=\"submit\" class=\"button\"
1313 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1317 if ($op == "pref-labels") {
1319 $subop = $_GET["subop"];
1321 if ($subop == "editSave") {
1323 $sql_exp = $_GET["s"];
1324 $descr = $_GET["d"];
1325 $label_id = db_escape_string($_GET["id"]);
1327 // print "$sql_exp : $descr : $label_id";
1329 $result = db_query($link, "UPDATE ttrss_labels SET
1330 sql_exp = '$sql_exp',
1331 description = '$descr'
1332 WHERE id = '$label_id'");
1335 if ($subop == "remove") {
1337 if (!WEB_DEMO_MODE
) {
1339 $ids = split(",", $_GET["ids"]);
1341 foreach ($ids as $id) {
1342 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1348 if ($subop == "add") {
1350 if (!WEB_DEMO_MODE
) {
1352 $exp = $_GET["exp"];
1354 $result = db_query($link,
1355 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1356 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
1360 print "<table class=\"prefAddFeed\"><tr>
1361 <td><input id=\"ladd_expr\"></td>";
1363 print"<td colspan=\"4\" align=\"right\">
1364 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1367 $result = db_query($link, "SELECT
1368 id,sql_exp,description
1372 owner_uid = ".$_SESSION["uid"]."
1373 ORDER by description");
1375 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1377 print "<tr class=\"title\">
1378 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1379 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1381 <td width=\"40%\">Caption</td></tr>";
1385 while ($line = db_fetch_assoc($result)) {
1387 $class = ($lnum %
2) ?
"even" : "odd";
1389 $label_id = $line["id"];
1390 $edit_label_id = $_GET["id"];
1392 if ($subop == "edit" && $label_id != $edit_label_id) {
1396 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1398 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1399 $line["description"] = htmlspecialchars($line["description"]);
1401 if (!$edit_label_id ||
$subop != "edit") {
1403 if (!$line["description"]) $line["description"] = "[No caption]";
1405 print "<td><input onclick='toggleSelectRow(this);'
1406 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1408 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1409 $line["sql_exp"] . "</td>";
1411 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1412 $line["description"] . "</td>";
1414 } else if ($label_id != $edit_label_id) {
1416 if (!$line["description"]) $line["description"] = "[No description]";
1418 print "<td><input disabled=\"true\" type=\"checkbox\"
1419 id=\"LICHK-".$line["id"]."\"></td>";
1421 print "<td>".$line["sql_exp"]."</td>";
1422 print "<td>".$line["description"]."</td>";
1426 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1428 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1431 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1443 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1450 if ($subop == "edit") {
1452 <input type=\"submit\" class=\"button\"
1453 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1454 <input type=\"submit\" class=\"button\"
1455 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1461 <input type=\"submit\" class=\"button\"
1462 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1463 <input type=\"submit\" class=\"button\"
1464 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1468 if ($op == "error") {
1469 print "<div width=\"100%\" align='center'>";
1470 $msg = $_GET["msg"];
1475 if ($op == "help") {
1477 <title>Tiny Tiny RSS : Help</title>
1478 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1479 <script type=\"text/javascript\" src=\"functions.js\"></script>
1480 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1483 $tid = sprintf("%d", $_GET["tid"]);
1485 /* FIXME this badly needs real implementation */
1487 print "<div class='helpResponse'>";
1491 <h1
>Help
for SQL expressions
</h1
>
1493 <h2
>Description
</h2
>
1495 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1496 view feed query
. You can match on ttrss_entries table fields
1497 and even
use subselect to query additional information
. This
1498 functionality is considered to be advanced
and requires basic
1499 understanding of SQL
.</p
>
1503 <pre
>unread
= true</pre
>
1505 Matches all unread articles
1507 <pre
>title like
'%Linux%'</pre
>
1509 Matches all articles which mention Linux in the title
. You get the idea
.
1511 <p
>See the database schema included in the distribution package
for gruesome
1516 print "<div align='center'>
1517 <a class=\"helpLink\"
1518 href=\"javascript:window.close()\">(Close this window)</a></div>";
1522 print "</body></html>";
1528 $param = $_GET["param"];
1530 if ($id == "quickAddFeed") {
1531 print "Feed URL: <input
1532 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1534 <input class=\"button\"
1535 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1536 <input class=\"button\"
1537 type=\"submit\" onclick=\"javascript:closeDlg()\"
1541 if ($id == "quickDelFeed") {
1543 $param = db_escape_string($param);
1545 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1549 $f_title = db_fetch_result($result, 0, "title");
1551 print "Remove current feed ($f_title)?
1552 <input class=\"button\"
1553 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1554 <input class=\"button\"
1555 type=\"submit\" onclick=\"javascript:closeDlg()\"
1558 print "Error: Feed $param not found.
1559 <input class=\"button\"
1560 type=\"submit\" onclick=\"javascript:closeDlg()\"
1565 if ($id == "search") {
1567 print "<input id=\"searchbox\" class=\"extSearch\"
1568 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1569 onchange=\"javascript:search()\">
1570 <select id=\"searchmodebox\">
1571 <option selected>All feeds</option>
1572 <option>This feed</option>
1574 <input type=\"submit\"
1575 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1576 <input class=\"button\"
1577 type=\"submit\" onclick=\"javascript:closeDlg()\"
1584 if ($op == "updateAllFeeds") {
1585 update_all_feeds($link, true);
1587 print "<rpc-reply>";
1588 getLabelCounters($link);
1589 getFeedCounters($link);
1590 getTagCounters($link);
1591 getGlobalCounters($link);
1592 print "</rpc-reply>";
1596 if ($op == "pref-prefs") {
1598 $subop = $_REQUEST["subop"];
1600 if ($subop == "Save configuration") {
1602 if (WEB_DEMO_MODE
) return;
1604 foreach (array_keys($_POST) as $pref_name) {
1606 $pref_name = db_escape_string($pref_name);
1607 $value = db_escape_string($_POST[$pref_name]);
1609 $result = db_query($link, "SELECT type_name
1610 FROM ttrss_prefs,ttrss_prefs_types
1611 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
1613 if (db_num_rows($result) > 0) {
1615 $type_name = db_fetch_result($result, 0, "type_name");
1617 // print "$pref_name : $type_name : $value<br>";
1619 if ($type_name == "bool") {
1620 if ($value == "1") {
1625 } else if ($type_name == "integer") {
1626 $value = sprintf("%d", $value);
1629 // print "$pref_name : $type_name : $value<br>";
1631 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
1632 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
1636 header("Location: prefs.php");
1640 } else if ($subop == "getHelp") {
1642 $pref_name = db_escape_string($_GET["pn"]);
1644 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
1645 WHERE pref_name = '$pref_name'");
1647 if (db_num_rows($result) > 0) {
1648 $help_text = db_fetch_result($result, 0, "help_text");
1651 print "Unknown option: $pref_name";
1654 } else if ($subop == "Change password") {
1656 if (WEB_DEMO_MODE
) return;
1658 $old_pw = $_POST["OLD_PASSWORD"];
1659 $new_pw = $_POST["OLD_PASSWORD"];
1661 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
1662 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
1664 $active_uid = $_SESSION["uid"];
1666 if ($old_pw && $new_pw) {
1668 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
1670 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1671 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
1672 pwd_hash = '$old_pw_hash')");
1674 if (db_num_rows($result) == 1) {
1675 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
1676 WHERE id = '$active_uid'");
1680 header("Location: prefs.php");
1682 } else if ($subop == "Reset to defaults") {
1684 if (WEB_DEMO_MODE
) return;
1686 if (DB_TYPE
== "pgsql") {
1687 db_query($link,"UPDATE ttrss_user_prefs
1688 SET value = ttrss_prefs.def_value
1689 WHERE owner_uid = '".$_SESSION["uid"]."' AND
1690 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
1692 db_query($link, "DELETE FROM ttrss_user_prefs
1693 WHERE owner_uid = ".$_SESSION["uid"]);
1694 initialize_user_prefs($link, $_SESSION["uid"]);
1697 header("Location: prefs.php");
1701 if (!SINGLE_USER_MODE
) {
1703 print "<form action=\"backend.php\" method=\"POST\">";
1705 print "<table width=\"100%\" class=\"prefPrefsList\">";
1706 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
1708 print "<tr><td width=\"40%\">Old password</td>";
1709 print "<td><input class=\"editbox\" type=\"password\"
1710 name=\"OLD_PASSWORD\"></td></tr>";
1712 print "<tr><td width=\"40%\">New password</td>";
1714 print "<td><input class=\"editbox\" type=\"password\"
1715 name=\"NEW_PASSWORD\"></td></tr>";
1719 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1721 print "<p><input class=\"button\" type=\"submit\"
1722 value=\"Change password\" name=\"subop\">";
1728 $result = db_query($link, "SELECT
1729 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
1730 section_name,def_value
1731 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
1732 WHERE type_id = ttrss_prefs_types.id AND
1733 section_id = ttrss_prefs_sections.id AND
1734 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
1735 owner_uid = ".$_SESSION["uid"]."
1736 ORDER BY section_id,short_desc");
1738 print "<form action=\"backend.php\" method=\"POST\">";
1742 $active_section = "";
1744 while ($line = db_fetch_assoc($result)) {
1746 if ($active_section != $line["section_name"]) {
1748 if ($active_section != "") {
1752 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
1754 $active_section = $line["section_name"];
1756 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
1757 // print "<tr class=\"title\">
1758 // <td width=\"25%\">Option</td><td>Value</td></tr>";
1763 // $class = ($lnum % 2) ? "even" : "odd";
1767 $type_name = $line["type_name"];
1768 $pref_name = $line["pref_name"];
1769 $value = $line["value"];
1770 $def_value = $line["def_value"];
1771 $help_text = $line["help_text"];
1773 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
1775 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
1781 if ($type_name == "bool") {
1782 // print_select($pref_name, $value, array("true", "false"));
1784 if ($value == "true") {
1790 print_radio($pref_name, $value, array("Yes", "No"));
1793 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
1805 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1807 print "<p><input class=\"button\" type=\"submit\"
1808 name=\"subop\" value=\"Save configuration\">";
1810 print " <input class=\"button\" type=\"submit\"
1811 name=\"subop\" value=\"Reset to defaults\"></p>";
1819 if ($op == "pref-users") {
1821 $subop = $_GET["subop"];
1823 if ($subop == "editSave") {
1825 if (!WEB_DEMO_MODE
) {
1827 $login = db_escape_string($_GET["l"]);
1828 $uid = db_escape_string($_GET["id"]);
1829 $access_level = sprintf("%d", $_GET["al"]);
1831 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
1834 } else if ($subop == "remove") {
1836 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
1838 $ids = split(",", $_GET["ids"]);
1840 foreach ($ids as $id) {
1841 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
1845 } else if ($subop == "add") {
1847 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
1849 $login = db_escape_string($_GET["login"]);
1850 $tmp_user_pwd = make_password(8);
1851 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1853 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
1854 VALUES ('$login', '$pwd_hash', 0)");
1857 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1858 login = '$login' AND pwd_hash = '$pwd_hash'");
1860 if (db_num_rows($result) == 1) {
1862 $new_uid = db_fetch_result($result, 0, "id");
1864 print "<div class=\"notice\">Added user <b>".$_GET["login"].
1865 "</b> with password <b>$tmp_user_pwd</b>.</div>";
1867 initialize_user($link, $new_uid);
1871 print "<div class=\"warning\">Error while adding user <b>".
1872 $_GET["login"].".</b></div>";
1876 } else if ($subop == "resetPass") {
1878 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
1880 $uid = db_escape_string($_GET["id"]);
1882 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
1884 $login = db_fetch_result($result, 0, "login");
1885 $tmp_user_pwd = make_password(8);
1886 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1888 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
1889 WHERE id = '$uid'");
1891 print "<div class=\"notice\">Changed password of
1892 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
1897 print "<table class=\"prefAddFeed\"><tr>
1898 <td><input id=\"uadd_box\"></td>";
1900 print"<td colspan=\"4\" align=\"right\">
1901 <a class=\"button\" href=\"javascript:addUser()\">Add user</a></td></tr>
1904 $result = db_query($link, "SELECT
1905 id,login,access_level,last_login
1910 print "<div id=\"prefUserDetails\">PLACEHOLDER</div>";
1912 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
1914 print "<tr class=\"title\">
1915 <td width=\"5%\">Select</td>
1916 <td width='30%'>Username</td>
1917 <td width='30%'>Access Level</td>
1918 <td width='30%'>Last login</td></tr>";
1922 while ($line = db_fetch_assoc($result)) {
1924 $class = ($lnum %
2) ?
"even" : "odd";
1927 $edit_uid = $_GET["id"];
1929 if ($uid == $_SESSION["uid"] ||
($subop == "edit" && $uid != $edit_uid)) {
1933 print "<tr class=\"$class\" id=\"UMRR-$uid\">";
1935 $line["login"] = htmlspecialchars($line["login"]);
1937 if ($uid == $_SESSION["uid"]) {
1939 print "<td><input disabled=\"true\" type=\"checkbox\"
1940 id=\"UMCHK-".$line["id"]."\"></td>";
1942 print "<td>".$line["login"]."</td>";
1943 print "<td>".$line["access_level"]."</td>";
1945 } else if (!$edit_uid ||
$subop != "edit") {
1947 print "<td><input onclick='toggleSelectRow(this);'
1948 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
1950 print "<td><a href=\"javascript:editUser($uid);\">" .
1951 $line["login"] . "</td>";
1953 print "<td><a href=\"javascript:editUser($uid);\">" .
1954 $line["access_level"] . "</td>";
1956 } else if ($uid != $edit_uid) {
1958 print "<td><input disabled=\"true\" type=\"checkbox\"
1959 id=\"UMCHK-".$line["id"]."\"></td>";
1961 print "<td>".$line["login"]."</td>";
1962 print "<td>".$line["access_level"]."</td>";
1966 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1968 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
1971 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
1976 print "<td>".$line["last_login"]."</td>";
1987 if ($subop == "edit") {
1989 <input type=\"submit\" class=\"button\"
1990 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
1991 <input type=\"submit\" class=\"button\"
1992 onclick=\"javascript:userEditSave()\" value=\"Save\">";
1998 <input type=\"submit\" class=\"button\"
1999 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
2000 <input type=\"submit\" class=\"button\"
2001 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2002 <input type=\"submit\" class=\"button\"
2003 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2004 <input type=\"submit\" class=\"button\"
2005 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2010 if ($op == "user-details") {
2012 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
2016 /* print "<html><head>
2017 <title>Tiny Tiny RSS : User Details</title>
2018 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2019 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2022 $uid = sprintf("%d", $_GET["id"]);
2024 print "<div class='userDetails'>";
2026 $result = db_query($link, "SELECT login,last_login,access_level
2028 WHERE id = '$uid'");
2030 if (db_num_rows($result) == 0) {
2031 print "<h1>User not found</h1>";
2035 print "<h1>User Details</h1>";
2037 print "<table width='100%'>";
2039 $login = db_fetch_result($result, 0, "login");
2040 $last_login = db_fetch_result($result, 0, "last_login");
2041 $access_level = db_fetch_result($result, 0, "access_level");
2043 print "<tr><td>Username</td><td>$login</td></tr>";
2044 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2045 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
2047 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2048 WHERE owner_uid = '$uid'");
2050 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2052 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2054 /* $result = db_query($link, "SELECT
2055 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
2056 FROM ttrss_entries WHERE owner_uid = '$uid'");
2058 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
2060 print "<tr><td>Approx. DB size</td><td>$db_size KBytes</td></tr>"; */
2064 print "<h1>Subscribed feeds</h1>";
2066 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2067 WHERE owner_uid = '$uid' ORDER BY title");
2069 print "<ul class=\"nomarks\">";
2071 while ($line = db_fetch_assoc($result)) {
2073 $icon_file = ICONS_URL
."/".$line["id"].".ico";
2075 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2076 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
2078 $feed_icon = "<img class=\"feedIcon\" src=\"images/blank_icon.gif\">";
2081 print "<li>$feed_icon <a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2088 print "<div align='center'>
2089 <input type='submit' class='button'
2090 onclick=\"closeUserDetails()\" value=\"Close this window\"></div>";
2092 // print "</body></html>";
2099 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->