4 if (!$_SESSION["uid"]) { exit; }
6 define(SCHEMA_VERSION
, 2);
8 require_once "config.php";
10 require_once "db-prefs.php";
11 require_once "functions.php";
12 require_once "magpierss/rss_fetch.inc";
14 // $_SESSION["uid"] = PLACEHOLDER_UID; // FIXME: placeholder
15 // $_SESSION["name"] = PLACEHOLDER_NAME;
17 $op = $_REQUEST["op"];
19 if ($op == "rpc" ||
$op == "updateAllFeeds") {
20 header("Content-Type: application/xml");
23 $script_started = getmicrotime();
25 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
28 if (DB_TYPE
== "mysql") {
31 // PG seems to display its own errors just fine by default.
35 if (DB_TYPE
== "pgsql") {
36 pg_query("set client_encoding = 'utf-8'");
40 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
42 $schema_version = db_fetch_result($result, 0, "schema_version");
44 if ($schema_version != SCHEMA_VERSION) {
45 print "Error: database schema is invalid
46 (got version $schema_version; expected ".SCHEMA_VERSION.")";
51 $fetch = $_GET["fetch"];
53 /* FIXME this needs reworking */
55 function getGlobalCounters($link) {
56 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
57 WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
58 $c_id = db_fetch_result($result, 0, "c_id");
59 print "<counter id='global-unread' counter='$c_id'/>";
62 function getTagCounters($link) {
63 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
64 FROM ttrss_tags,ttrss_entries WHERE
65 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
66 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
68 select tag_name,0 as count FROM ttrss_tags
69 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
73 while ($line = db_fetch_assoc($result)) {
74 $tags[$line["tag_name"]] +
= $line["count"];
77 foreach (array_keys($tags) as $tag) {
78 $unread = $tags[$tag];
80 $tag = htmlspecialchars($tag);
81 print "<tag id=\"$tag\" counter=\"$unread\"/>";
85 function getLabelCounters($link) {
87 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
88 WHERE marked = true AND unread = true AND owner_uid = ".$_SESSION["uid"]);
90 $count = db_fetch_result($result, 0, "count");
92 print "<label id=\"-1\" counter=\"$count\"/>";
94 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
95 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
97 while ($line = db_fetch_assoc($result)) {
99 $id = -$line["id"] - 11;
103 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
104 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
105 owner_uid = ".$_SESSION["uid"]);
107 $count = db_fetch_result($tmp_result, 0, "count");
109 print "<label id=\"$id\" counter=\"$count\"/>";
111 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
116 function getFeedCounter($link, $id) {
118 $result = db_query($link, "SELECT
119 count(id) as count FROM ttrss_entries
120 WHERE feed_id = '$id' AND unread = true");
122 $count = db_fetch_result($result, 0, "count");
124 print "<feed id=\"$id\" counter=\"$count\"/>";
127 function getFeedCounters($link) {
129 $result = db_query($link, "SELECT id,
130 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
131 AND unread = true) as count
132 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
134 while ($line = db_fetch_assoc($result)) {
137 $count = $line["count"];
139 print "<feed id=\"$id\" counter=\"$count\"/>";
143 function outputFeedList($link, $tags = false) {
146 <title>Tiny Tiny RSS : Feedlist</title>
147 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
149 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
150 print "<link rel=\"stylesheet\" type=\"text/css\"
151 href=\"tt-rss_compact.css\"/>";
153 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
154 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
157 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
158 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
159 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
160 </head><body onload=\"init()\">";
162 print "<ul class=\"feedList\" id=\"feedList\">";
164 $owner_uid = $_SESSION["uid"];
170 $result = db_query($link, "SELECT count(id) as num_starred
171 FROM ttrss_entries WHERE marked = true AND unread = true AND owner_uid = '$owner_uid'");
172 $num_starred = db_fetch_result($result, 0, "num_starred");
176 if ($num_starred > 0) $class .= "Unread";
178 printFeedEntry(-1, $class, "Starred articles", $num_starred,
179 "images/mark_set.png", $link);
181 if (get_pref($link, 'ENABLE_LABELS')) {
183 $result = db_query($link, "SELECT id,sql_exp,description FROM
184 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
186 if (db_num_rows($result) > 0) {
187 print "<li><hr></li>";
190 while ($line = db_fetch_assoc($result)) {
194 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
195 WHERE (" . $line["sql_exp"] . ") AND unread = true
196 AND owner_uid = '$owner_uid'");
198 $count = db_fetch_result($tmp_result, 0, "count");
206 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
208 printFeedEntry(-$line["id"]-11,
209 $class, $line["description"], $count, "images/label.png", $link);
214 print "<li><hr></li>";
216 $result = db_query($link, "SELECT *,
217 (SELECT count(id) FROM ttrss_entries
218 WHERE feed_id = ttrss_feeds.id) AS total,
219 (SELECT count(id) FROM ttrss_entries
220 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
221 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");
223 $actid = $_GET["actid"];
231 while ($line = db_fetch_assoc($result)) {
233 $feed = $line["title"];
234 $feed_id = $line["id"];
236 $subop = $_GET["subop"];
238 $total = $line["total"];
239 $unread = $line["unread"];
241 // $class = ($lnum % 2) ? "even" : "odd";
245 if ($unread > 0) $class .= "Unread";
247 if ($actid == $feed_id) {
248 $class .= "Selected";
251 $total_unread +
= $unread;
253 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
261 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
262 FROM ttrss_tags,ttrss_entries WHERE
263 post_id = ttrss_entries.id AND unread = true
264 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
266 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'");
270 while ($line = db_fetch_assoc($result)) {
271 $tags[$line["tag_name"]] +
= $line["count"];
274 foreach (array_keys($tags) as $tag) {
276 $unread = $tags[$tag];
284 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
290 if (db_num_rows($result) == 0) {
291 print "<li>No tags/feeds to display.</li>";
296 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
303 $subop = $_GET["subop"];
305 if ($subop == "getLabelCounters") {
308 getLabelCounters($link);
310 getFeedCounter($link, $aid);
312 print "</rpc-reply>";
315 if ($subop == "getFeedCounters") {
317 getFeedCounters($link);
318 print "</rpc-reply>";
321 if ($subop == "getAllCounters") {
323 getLabelCounters($link);
324 getFeedCounters($link);
325 getTagCounters($link);
326 getGlobalCounters($link);
327 print "</rpc-reply>";
330 if ($subop == "mark") {
331 $mark = $_GET["mark"];
332 $id = db_escape_string($_GET["id"]);
340 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
344 if ($subop == "updateFeed") {
345 $feed_id = db_escape_string($_GET["feed"]);
347 $result = db_query($link,
348 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
350 if (db_num_rows($result) > 0) {
351 $feed_url = db_fetch_result($result, 0, "feed_url");
352 // update_rss_feed($link, $feed_url, $feed_id);
355 print "DONE-$feed_id";
360 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
362 update_all_feeds($link, true);
364 $omode = $_GET["omode"];
366 if (!$omode) $omode = "tfl";
369 if (strchr($omode, "l")) getLabelCounters($link);
370 if (strchr($omode, "f")) getFeedCounters($link);
371 if (strchr($omode, "t")) getTagCounters($link);
372 getGlobalCounters($link);
373 print "</rpc-reply>";
376 if ($subop == "catchupPage") {
378 $ids = split(",", $_GET["ids"]);
380 foreach ($ids as $id) {
382 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
387 print "Marked active page as read.";
390 if ($subop == "sanityCheck") {
394 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
396 $schema_version = db_fetch_result($result, 0, "schema_version");
398 if ($schema_version != SCHEMA_VERSION
) {
402 print "<error code='$error_code'/>";
406 if ($op == "feeds") {
408 $tags = $_GET["tags"];
410 $subop = $_GET["subop"];
412 if ($subop == "catchupAll") {
413 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
416 outputFeedList($link, $tags);
423 $feed_id = $_GET["feed"];
425 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
427 $addheader = $_GET["addheader"];
429 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
430 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
436 <title>Tiny Tiny RSS : Article $id</title>
437 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
438 <script type=\"text/javascript\" src=\"functions.js\"></script>
439 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
445 $line = db_fetch_assoc($result);
447 if ($line["icon_url"]) {
448 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
450 $feed_icon = " ";
453 if ($line["comments"] && $line["link"] != $line["comments"]) {
454 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
456 $entry_comments = "";
459 print "<div class=\"postReply\">";
461 print "<div class=\"postHeader\"><table>";
463 print "<tr><td><b>Title:</b></td>
464 <td width='100%'>" . $line["title"] . "</td></tr>";
466 print "<tr><td><b>Link:</b></td>
468 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
469 $entry_comments</td></tr>";
471 print "</table></div>";
473 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
474 print "<div class=\"postContent\">" . $line["content"] . "</div>";
478 print "<script type=\"text/javascript\">
479 update_label_counters('$feed_id');
484 print "</body></html>";
488 if ($op == "viewfeed") {
490 $feed = $_GET["feed"];
491 $skip = $_GET["skip"];
492 $subop = $_GET["subop"];
493 $view_mode = $_GET["view"];
494 $addheader = $_GET["addheader"];
495 $limit = $_GET["limit"];
498 print "Error: no feed to display.";
502 if (!$skip) $skip = 0;
504 if ($subop == "undefined") $subop = "";
508 <title>Tiny Tiny RSS : Feed $feed</title>
509 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
511 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
512 print "<link rel=\"stylesheet\"
513 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
516 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
517 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
519 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
520 <script type=\"text/javascript\" src=\"functions.js\"></script>
521 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
522 </head><body onload='init()'>";
525 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
527 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
528 WHERE id = '$feed'");
530 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
532 update_rss_feed($link, $feed_url, $feed);
536 if ($subop == "MarkAllRead") {
538 if (sprintf("%d", $feed) != 0) {
541 db_query($link, "UPDATE ttrss_entries
542 SET unread = false,last_read = NOW()
543 WHERE feed_id = '$feed'");
545 } else if ($feed < 0 && $feed > -10) { // special, like starred
548 db_query($link, "UPDATE ttrss_entries
549 SET unread = false,last_read = NOW()
550 WHERE marked = true");
553 } else if ($feed < -10) { // label
555 $label_id = -$feed - 11;
557 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
558 WHERE id = '$label_id'");
561 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
563 db_query($link, "UPDATE ttrss_entries
564 SET unread = false,last_read = NOW()
569 // FIXME, implement catchup for tags
574 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
576 $search = $_GET["search"];
578 $search_mode = $_GET["smode"];
581 $search_query_part = "(upper(title) LIKE upper('%$search%')
582 OR content LIKE '%$search%') AND";
584 $search_query_part = "";
587 $view_query_part = "";
589 if ($view_mode == "Starred") {
590 $view_query_part = " marked = true AND ";
593 if ($view_mode == "Unread") {
594 $view_query_part = " unread = true AND ";
597 if ($view_mode == "Unread or Starred") {
598 $view_query_part = " (unread = true OR marked = true) AND ";
601 if ($view_mode == "Unread or Updated") {
602 $view_query_part = " (unread = true OR last_read is NULL) AND ";
605 /* $result = db_query($link, "SELECT count(id) AS total_entries
606 FROM ttrss_entries WHERE
610 $total_entries = db_fetch_result($result, 0, "total_entries"); */
612 /* $result = db_query("SELECT count(id) AS unread_entries
613 FROM ttrss_entries WHERE
618 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
620 if ($limit && $limit != "All") {
621 $limit_query_part = "LIMIT " . $limit;
624 $vfeed_query_part = "";
626 // override query strategy and enable feed display when searching globally
627 if ($search_mode == "All feeds") {
628 $query_strategy_part = "id > 0";
629 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
630 id = feed_id) as feed_title,";
631 } else if (sprintf("%d", $feed) == 0) {
632 $query_strategy_part = "ttrss_entries.id > 0";
633 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
634 id = feed_id) as feed_title,";
635 } else if ($feed >= 0) {
636 $query_strategy_part = "feed_id = '$feed'";
637 } else if ($feed == -1) { // starred virtual feed
638 $query_strategy_part = "marked = true";
639 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
640 id = feed_id) as feed_title,";
641 } else if ($feed <= -10) { // labels
642 $label_id = -$feed - 11;
644 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
645 WHERE id = '$label_id'");
647 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
649 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
650 id = feed_id) as feed_title,";
652 $query_strategy_part = "id > 0"; // dumb
656 $order_by = "updated DESC";
658 // if ($feed < -10) {
659 // $order_by = "feed_id,updated DESC";
662 if ($feed < -10) error_reporting (0);
664 if (sprintf("%d", $feed) != 0) {
666 $result = db_query($link, "SELECT
667 id,title,updated,unread,feed_id,marked,link,last_read,
668 SUBSTRING(last_read,1,19) as last_read_noms,
670 SUBSTRING(updated,1,19) as updated_noms
674 owner_uid = '".$_SESSION["uid"]."' AND
677 $query_strategy_part ORDER BY $order_by
683 $result = db_query($link, "SELECT
684 ttrss_entries.id as id,title,updated,unread,feed_id,
685 marked,link,last_read,
686 SUBSTRING(last_read,1,19) as last_read_noms,
688 SUBSTRING(updated,1,19) as updated_noms
690 ttrss_entries,ttrss_tags
692 ttrss_entries.owner_uid = '".$_SESSION["uid"]."' AND
693 post_id = ttrss_entries.id AND tag_name = '$feed' AND
696 $query_strategy_part ORDER BY $order_by
701 print "<tr><td colspan='4' align='center'>
702 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
708 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
712 while ($line = db_fetch_assoc($result)) {
714 $class = ($lnum %
2) ?
"even" : "odd";
717 $feed_id = $line["feed_id"];
719 // printf("L %d (%s) > U %d (%s) = %d<br>",
720 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
721 // strtotime($line["updated"]), $line["updated"],
722 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
724 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
725 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
727 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
732 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
737 if ($line["last_read"] == "" &&
738 ($line["unread"] != "t" && $line["unread"] != "1")) {
740 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
743 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
747 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
752 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
753 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
754 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
756 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
757 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
760 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
761 $line["title"] . "</a>";
763 print "<tr class='$class' id='RROW-$id'>";
764 // onclick=\"javascript:view($id,$feed_id)\">
766 print "<td valign='center' align='center'>$update_pic</td>";
767 print "<td valign='center' align='center'>$marked_pic</td>";
769 print "<td width='25%'>
770 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
772 if ($line["feed_title"]) {
773 print "<td width='50%'>$content_link</td>";
774 print "<td width='20%'>
775 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
777 print "<td width='70%'>$content_link</td>";
786 print "<tr><td align='center'>No articles found.</td></tr>";
791 print "<script type=\"text/javascript\">
792 document.onkeydown = hotkey_handler;
793 update_label_counters('$feed');
797 print "</body></html>";
802 if ($op == "pref-rpc") {
804 $subop = $_GET["subop"];
806 if ($subop == "unread") {
807 $ids = split(",", $_GET["ids"]);
808 foreach ($ids as $id) {
809 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
812 print "Marked selected feeds as read.";
815 if ($subop == "read") {
816 $ids = split(",", $_GET["ids"]);
817 foreach ($ids as $id) {
818 db_query($link, "UPDATE ttrss_entries
819 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
822 print "Marked selected feeds as unread.";
828 if ($op == "pref-feeds") {
830 $subop = $_GET["subop"];
832 if ($subop == "editSave") {
833 $feed_title = db_escape_string($_GET["t"]);
834 $feed_link = db_escape_string($_GET["l"]);
835 $upd_intl = db_escape_string($_GET["ui"]);
836 $purge_intl = db_escape_string($_GET["pi"]);
837 $feed_id = $_GET["id"];
839 if (strtoupper($upd_intl) == "DEFAULT")
842 if (strtoupper($purge_intl) == "DEFAULT")
845 if (strtoupper($purge_intl) == "DISABLED")
848 $result = db_query($link, "UPDATE ttrss_feeds SET
849 title = '$feed_title', feed_url = '$feed_link',
850 update_interval = '$upd_intl',
851 purge_interval = '$purge_intl'
852 WHERE id = '$feed_id'");
856 if ($subop == "remove") {
858 if (!WEB_DEMO_MODE
) {
860 $ids = split(",", $_GET["ids"]);
862 foreach ($ids as $id) {
863 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
865 $icons_dir = ICONS_DIR
;
867 if (file_exists($icons_dir . "/$id.ico")) {
868 unlink($icons_dir . "/$id.ico");
874 if ($subop == "add") {
876 if (!WEB_DEMO_MODE
) {
878 $feed_link = db_escape_string($_GET["link"]);
880 $result = db_query($link,
881 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
883 $result = db_query($link,
884 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
886 $feed_id = db_fetch_result($result, 0, "id");
889 update_rss_feed($link, $feed_link, $feed_id);
894 $result = db_query($link, "SELECT id,title,feed_url,last_error
895 FROM ttrss_feeds WHERE last_error != ''");
897 if (db_num_rows($result) > 0) {
899 print "<div class=\"warning\">";
901 print "<b>Feeds with update errors:</b>";
903 print "<ul class=\"nomarks\">";
905 while ($line = db_fetch_assoc($result)) {
906 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
915 print "<table class=\"prefAddFeed\"><tr>
916 <td><input id=\"fadd_link\"></td>
917 <td colspan=\"4\" align=\"right\">
918 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
921 $result = db_query($link, "SELECT
922 id,title,feed_url,substring(last_updated,1,16) as last_updated,
923 update_interval,purge_interval
925 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
927 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
928 print "<tr class=\"title\">
929 <td> </td><td>Select</td><td width=\"30%\">Title</td>
930 <td width=\"30%\">Link</td>
931 <td width=\"10%\">Update Interval</td>
932 <td width=\"10%\">Purge Days</td>
933 <td>Last updated</td></tr>";
937 while ($line = db_fetch_assoc($result)) {
939 $class = ($lnum %
2) ?
"even" : "odd";
941 $feed_id = $line["id"];
943 $edit_feed_id = $_GET["id"];
945 if ($subop == "edit" && $feed_id != $edit_feed_id) {
949 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
951 $icon_file = ICONS_DIR
. "/$feed_id.ico";
953 if (file_exists($icon_file) && filesize($icon_file) > 0) {
954 $feed_icon = "<img width=\"16\" height=\"16\"
955 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
957 $feed_icon = " ";
959 print "<td align='center'>$feed_icon</td>";
961 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
962 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
964 if (!$edit_feed_id ||
$subop != "edit") {
966 print "<td><input onclick='toggleSelectRow(this);'
967 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
969 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
970 $edit_title . "</a></td>";
971 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
972 $edit_link . "</a></td>";
974 if ($line["update_interval"] == "0")
975 $line["update_interval"] = "Default";
977 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
978 $line["update_interval"] . "</a></td>";
980 if ($line["purge_interval"] == "0")
981 $line["purge_interval"] = "Default";
983 if ($line["purge_interval"] < 0)
984 $line["purge_interval"] = "Disabled";
986 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
987 $line["purge_interval"] . "</a></td>";
989 } else if ($feed_id != $edit_feed_id) {
991 print "<td><input disabled=\"true\" type=\"checkbox\"
992 id=\"FRCHK-".$line["id"]."\"></td>";
994 print "<td>$edit_title</td>";
995 print "<td>$edit_link</td>";
997 if ($line["update_interval"] == "0")
998 $line["update_interval"] = "Default";
1000 print "<td>" . $line["update_interval"] . "</td>";
1002 if ($line["purge_interval"] == "0")
1003 $line["purge_interval"] = "Default";
1005 if ($line["purge_interval"] < 0)
1006 $line["purge_interval"] = "Disabled";
1008 print "<td>" . $line["purge_interval"] . "</td>";
1012 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1014 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1015 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1016 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
1017 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
1021 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1023 print "<td>" . $line["last_updated"] . "</td>";
1031 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1038 if ($subop == "edit") {
1039 print "Edit feed:
1040 <input type=\"submit\" class=\"button\"
1041 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1042 <input type=\"submit\" class=\"button\"
1043 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1048 <input type=\"submit\" class=\"button\"
1049 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1050 <input type=\"submit\" class=\"button\"
1051 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1053 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1055 <input type=\"submit\" class=\"button\"
1056 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1057 <input type=\"submit\" class=\"button\"
1058 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
1062 <input type=\"submit\"
1063 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1067 print "<h3>OPML Import</h3>
1068 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1069 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1070 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1071 type=\"submit\" value=\"Import\">
1076 if ($op == "pref-filters") {
1078 $subop = $_GET["subop"];
1080 if ($subop == "editSave") {
1082 $regexp = db_escape_string($_GET["r"]);
1083 $descr = db_escape_string($_GET["d"]);
1084 $match = db_escape_string($_GET["m"]);
1085 $filter_id = db_escape_string($_GET["id"]);
1087 $result = db_query($link, "UPDATE ttrss_filters SET
1088 reg_exp = '$regexp',
1089 description = '$descr',
1090 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1091 description = '$match')
1092 WHERE id = '$filter_id'");
1095 if ($subop == "remove") {
1097 if (!WEB_DEMO_MODE
) {
1099 $ids = split(",", $_GET["ids"]);
1101 foreach ($ids as $id) {
1102 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1108 if ($subop == "add") {
1110 if (!WEB_DEMO_MODE
) {
1112 $regexp = db_escape_string($_GET["regexp"]);
1113 $match = db_escape_string($_GET["match"]);
1115 $result = db_query($link,
1116 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES
1117 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1118 description = '$match'),'".$_SESSION["uid"]."')");
1122 $result = db_query($link, "SELECT description
1123 FROM ttrss_filter_types ORDER BY description");
1125 $filter_types = array();
1127 while ($line = db_fetch_assoc($result)) {
1128 array_push($filter_types, $line["description"]);
1131 print "<table class=\"prefAddFeed\"><tr>
1132 <td><input id=\"fadd_regexp\"></td>
1134 print_select("fadd_match", "Title", $filter_types);
1136 print"</td><td colspan=\"4\" align=\"right\">
1137 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1140 $result = db_query($link, "SELECT
1141 id,reg_exp,description,
1142 (SELECT name FROM ttrss_filter_types WHERE
1143 id = filter_type) as filter_type_name,
1144 (SELECT description FROM ttrss_filter_types
1145 WHERE id = filter_type) as filter_type_descr
1149 owner_uid = ".$_SESSION["uid"]."
1152 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1154 print "<tr class=\"title\">
1155 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1156 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1160 while ($line = db_fetch_assoc($result)) {
1162 $class = ($lnum %
2) ?
"even" : "odd";
1164 $filter_id = $line["id"];
1165 $edit_filter_id = $_GET["id"];
1167 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1171 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1173 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1174 $line["description"] = htmlspecialchars($line["description"]);
1176 if (!$edit_filter_id ||
$subop != "edit") {
1178 if (!$line["description"]) $line["description"] = "[No description]";
1180 print "<td><input onclick='toggleSelectRow(this);'
1181 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1183 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1184 $line["reg_exp"] . "</td>";
1186 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1187 $line["description"] . "</td>";
1189 print "<td>".$line["filter_type_descr"]."</td>";
1191 } else if ($filter_id != $edit_filter_id) {
1193 if (!$line["description"]) $line["description"] = "[No description]";
1195 print "<td><input disabled=\"true\" type=\"checkbox\"
1196 id=\"FICHK-".$line["id"]."\"></td>";
1198 print "<td>".$line["reg_exp"]."</td>";
1199 print "<td>".$line["description"]."</td>";
1200 print "<td>".$line["filter_type_descr"]."</td>";
1204 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1206 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1209 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1213 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1225 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1232 if ($subop == "edit") {
1234 <input type=\"submit\" class=\"button\"
1235 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1236 <input type=\"submit\" class=\"button\"
1237 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1243 <input type=\"submit\" class=\"button\"
1244 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1245 <input type=\"submit\" class=\"button\"
1246 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1250 if ($op == "pref-labels") {
1252 $subop = $_GET["subop"];
1254 if ($subop == "editSave") {
1256 $sql_exp = $_GET["s"];
1257 $descr = $_GET["d"];
1258 $label_id = db_escape_string($_GET["id"]);
1260 // print "$sql_exp : $descr : $label_id";
1262 $result = db_query($link, "UPDATE ttrss_labels SET
1263 sql_exp = '$sql_exp',
1264 description = '$descr'
1265 WHERE id = '$label_id'");
1268 if ($subop == "remove") {
1270 if (!WEB_DEMO_MODE
) {
1272 $ids = split(",", $_GET["ids"]);
1274 foreach ($ids as $id) {
1275 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1281 if ($subop == "add") {
1283 if (!WEB_DEMO_MODE
) {
1285 $exp = $_GET["exp"];
1287 $result = db_query($link,
1288 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1289 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
1293 print "<table class=\"prefAddFeed\"><tr>
1294 <td><input id=\"ladd_expr\"></td>";
1296 print"<td colspan=\"4\" align=\"right\">
1297 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1300 $result = db_query($link, "SELECT
1301 id,sql_exp,description
1305 owner_uid = ".$_SESSION["uid"]."
1306 ORDER by description");
1308 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1310 print "<tr class=\"title\">
1311 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1312 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1314 <td width=\"40%\">Caption</td></tr>";
1318 while ($line = db_fetch_assoc($result)) {
1320 $class = ($lnum %
2) ?
"even" : "odd";
1322 $label_id = $line["id"];
1323 $edit_label_id = $_GET["id"];
1325 if ($subop == "edit" && $label_id != $edit_label_id) {
1329 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1331 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1332 $line["description"] = htmlspecialchars($line["description"]);
1334 if (!$edit_label_id ||
$subop != "edit") {
1336 if (!$line["description"]) $line["description"] = "[No caption]";
1338 print "<td><input onclick='toggleSelectRow(this);'
1339 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1341 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1342 $line["sql_exp"] . "</td>";
1344 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1345 $line["description"] . "</td>";
1347 } else if ($label_id != $edit_label_id) {
1349 if (!$line["description"]) $line["description"] = "[No description]";
1351 print "<td><input disabled=\"true\" type=\"checkbox\"
1352 id=\"LICHK-".$line["id"]."\"></td>";
1354 print "<td>".$line["sql_exp"]."</td>";
1355 print "<td>".$line["description"]."</td>";
1359 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1361 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1364 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1376 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1383 if ($subop == "edit") {
1385 <input type=\"submit\" class=\"button\"
1386 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1387 <input type=\"submit\" class=\"button\"
1388 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1394 <input type=\"submit\" class=\"button\"
1395 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1396 <input type=\"submit\" class=\"button\"
1397 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1401 if ($op == "error") {
1402 print "<div width=\"100%\" align='center'>";
1403 $msg = $_GET["msg"];
1408 if ($op == "help") {
1410 <title>Tiny Tiny RSS : Help</title>
1411 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1412 <script type=\"text/javascript\" src=\"functions.js\"></script>
1413 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1416 $tid = sprintf("%d", $_GET["tid"]);
1418 /* FIXME this badly needs real implementation */
1420 print "<div class='helpResponse'>";
1424 <h1
>Help
for SQL expressions
</h1
>
1426 <h2
>Description
</h2
>
1428 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1429 view feed query
. You can match on ttrss_entries table fields
1430 and even
use subselect to query additional information
. This
1431 functionality is considered to be advanced
and requires basic
1432 understanding of SQL
.</p
>
1436 <pre
>unread
= true</pre
>
1438 Matches all unread articles
1440 <pre
>title like
'%Linux%'</pre
>
1442 Matches all articles which mention Linux in the title
. You get the idea
.
1444 <p
>See the database schema included in the distribution package
for gruesome
1449 print "<div align='center'>
1450 <a class=\"helpLink\"
1451 href=\"javascript:window.close()\">(Close this window)</a></div>";
1455 print "</body></html>";
1461 $param = $_GET["param"];
1463 if ($id == "quickAddFeed") {
1464 print "Feed URL: <input
1465 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1467 <input class=\"button\"
1468 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1469 <input class=\"button\"
1470 type=\"submit\" onclick=\"javascript:closeDlg()\"
1474 if ($id == "quickDelFeed") {
1476 $param = db_escape_string($param);
1478 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1482 $f_title = db_fetch_result($result, 0, "title");
1484 print "Remove current feed ($f_title)?
1485 <input class=\"button\"
1486 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1487 <input class=\"button\"
1488 type=\"submit\" onclick=\"javascript:closeDlg()\"
1491 print "Error: Feed $param not found.
1492 <input class=\"button\"
1493 type=\"submit\" onclick=\"javascript:closeDlg()\"
1498 if ($id == "search") {
1500 print "<input id=\"searchbox\" class=\"extSearch\"
1501 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1502 onchange=\"javascript:search()\">
1503 <select id=\"searchmodebox\">
1504 <option selected>All feeds</option>
1505 <option>This feed</option>
1507 <input type=\"submit\"
1508 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1509 <input class=\"button\"
1510 type=\"submit\" onclick=\"javascript:closeDlg()\"
1517 if ($op == "updateAllFeeds") {
1518 update_all_feeds($link, true);
1520 print "<rpc-reply>";
1521 getLabelCounters($link);
1522 getFeedCounters($link);
1523 getTagCounters($link);
1524 getGlobalCounters($link);
1525 print "</rpc-reply>";
1529 if ($op == "pref-prefs") {
1531 $subop = $_REQUEST["subop"];
1533 if ($subop == "Save configuration") {
1535 if (WEB_DEMO_MODE
) return;
1537 foreach (array_keys($_POST) as $pref_name) {
1539 $pref_name = db_escape_string($pref_name);
1540 $value = db_escape_string($_POST[$pref_name]);
1542 $result = db_query($link, "SELECT type_name
1543 FROM ttrss_prefs,ttrss_prefs_types
1544 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
1546 if (db_num_rows($result) > 0) {
1548 $type_name = db_fetch_result($result, 0, "type_name");
1550 // print "$pref_name : $type_name : $value<br>";
1552 if ($type_name == "bool") {
1553 if ($value == "1") {
1558 } else if ($type_name == "integer") {
1559 $value = sprintf("%d", $value);
1562 // print "$pref_name : $type_name : $value<br>";
1564 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
1565 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
1569 header("Location: prefs.php");
1573 } else if ($subop == "getHelp") {
1575 $pref_name = db_escape_string($_GET["pn"]);
1577 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
1578 WHERE pref_name = '$pref_name'");
1580 if (db_num_rows($result) > 0) {
1581 $help_text = db_fetch_result($result, 0, "help_text");
1584 print "Unknown option: $pref_name";
1587 } else if ($subop == "Change password") {
1589 if (WEB_DEMO_MODE
) return;
1591 $old_pw = $_POST["OLD_PASSWORD"];
1592 $new_pw = $_POST["OLD_PASSWORD"];
1594 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
1595 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
1597 $active_uid = $_SESSION["uid"];
1599 if ($old_pw && $new_pw) {
1601 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
1603 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1604 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
1605 pwd_hash = '$old_pw_hash')");
1607 if (db_num_rows($result) == 1) {
1608 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
1609 WHERE id = '$active_uid'");
1613 header("Location: prefs.php");
1615 } else if ($subop == "Reset to defaults") {
1617 if (WEB_DEMO_MODE
) return;
1619 if (DB_TYPE
== "pgsql") {
1620 db_query($link,"UPDATE ttrss_user_prefs
1621 SET value = ttrss_prefs.def_value
1622 WHERE owner_uid = '".$_SESSION["uid"]."' AND
1623 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
1625 db_query($link, "DELETE FROM ttrss_user_prefs
1626 WHERE owner_uid = ".$_SESSION["uid"]);
1627 initialize_user_prefs($link, $_SESSION["uid"]);
1630 header("Location: prefs.php");
1634 if (!SINGLE_USER_MODE
) {
1636 print "<form action=\"backend.php\" method=\"POST\">";
1638 print "<table width=\"100%\" class=\"prefPrefsList\">";
1639 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
1641 print "<tr><td width=\"40%\">Old password</td>";
1642 print "<td><input class=\"editbox\" type=\"password\"
1643 name=\"OLD_PASSWORD\"></td></tr>";
1645 print "<tr><td width=\"40%\">New password</td>";
1647 print "<td><input class=\"editbox\" type=\"password\"
1648 name=\"NEW_PASSWORD\"></td></tr>";
1652 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1654 print "<p><input class=\"button\" type=\"submit\"
1655 value=\"Change password\" name=\"subop\">";
1661 $result = db_query($link, "SELECT
1662 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
1663 section_name,def_value
1664 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
1665 WHERE type_id = ttrss_prefs_types.id AND
1666 section_id = ttrss_prefs_sections.id AND
1667 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
1668 owner_uid = ".$_SESSION["uid"]."
1669 ORDER BY section_id,short_desc");
1671 print "<form action=\"backend.php\" method=\"POST\">";
1675 $active_section = "";
1677 while ($line = db_fetch_assoc($result)) {
1679 if ($active_section != $line["section_name"]) {
1681 if ($active_section != "") {
1685 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
1687 $active_section = $line["section_name"];
1689 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
1690 // print "<tr class=\"title\">
1691 // <td width=\"25%\">Option</td><td>Value</td></tr>";
1696 // $class = ($lnum % 2) ? "even" : "odd";
1700 $type_name = $line["type_name"];
1701 $pref_name = $line["pref_name"];
1702 $value = $line["value"];
1703 $def_value = $line["def_value"];
1704 $help_text = $line["help_text"];
1706 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
1708 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
1714 if ($type_name == "bool") {
1715 // print_select($pref_name, $value, array("true", "false"));
1717 if ($value == "true") {
1723 print_radio($pref_name, $value, array("Yes", "No"));
1726 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
1738 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1740 print "<p><input class=\"button\" type=\"submit\"
1741 name=\"subop\" value=\"Save configuration\">";
1743 print " <input class=\"button\" type=\"submit\"
1744 name=\"subop\" value=\"Reset to defaults\"></p>";
1752 if ($op == "pref-users") {
1754 $subop = $_GET["subop"];
1756 if ($subop == "editSave") {
1758 if (!WEB_DEMO_MODE
) {
1760 $login = db_escape_string($_GET["l"]);
1761 $uid = db_escape_string($_GET["id"]);
1762 $access_level = sprintf("%d", $_GET["al"]);
1764 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
1767 } else if ($subop == "remove") {
1769 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
1771 $ids = split(",", $_GET["ids"]);
1773 foreach ($ids as $id) {
1774 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
1778 } else if ($subop == "add") {
1780 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
1782 $login = db_escape_string($_GET["login"]);
1783 $tmp_user_pwd = make_password(8);
1784 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1786 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
1787 VALUES ('$login', '$pwd_hash', 0)");
1790 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1791 login = '$login' AND pwd_hash = '$pwd_hash'");
1793 if (db_num_rows($result) == 1) {
1795 $new_uid = db_fetch_result($result, 0, "id");
1797 print "<div class=\"notice\">Added user <b>".$_GET["login"].
1798 "</b> with password <b>$tmp_user_pwd</b>.</div>";
1800 initialize_user($link, $new_uid);
1804 print "<div class=\"warning\">Error while adding user <b>".
1805 $_GET["login"].".</b></div>";
1809 } else if ($subop == "resetPass") {
1811 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
1813 $uid = db_escape_string($_GET["id"]);
1815 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
1817 $login = db_fetch_result($result, 0, "login");
1818 $tmp_user_pwd = make_password(8);
1819 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1821 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
1822 WHERE id = '$uid'");
1824 print "<div class=\"notice\">Changed password of
1825 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
1830 print "<table class=\"prefAddFeed\"><tr>
1831 <td><input id=\"uadd_box\"></td>";
1833 print"<td colspan=\"4\" align=\"right\">
1834 <a class=\"button\" href=\"javascript:addUser()\">Add user</a></td></tr>
1837 $result = db_query($link, "SELECT
1838 id,login,access_level,last_login
1843 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
1845 print "<tr class=\"title\">
1846 <td width=\"5%\">Select</td>
1847 <td width='30%'>Username</td>
1848 <td width='30%'>Access Level</td>
1849 <td width='30%'>Last login</td></tr>";
1853 while ($line = db_fetch_assoc($result)) {
1855 $class = ($lnum %
2) ?
"even" : "odd";
1858 $edit_uid = $_GET["id"];
1860 if ($uid == $_SESSION["uid"] ||
($subop == "edit" && $uid != $edit_uid)) {
1864 print "<tr class=\"$class\" id=\"UMRR-$uid\">";
1866 $line["login"] = htmlspecialchars($line["login"]);
1868 if ($uid == $_SESSION["uid"]) {
1870 print "<td><input disabled=\"true\" type=\"checkbox\"
1871 id=\"UMCHK-".$line["id"]."\"></td>";
1873 print "<td>".$line["login"]."</td>";
1874 print "<td>".$line["access_level"]."</td>";
1876 } else if (!$edit_uid ||
$subop != "edit") {
1878 print "<td><input onclick='toggleSelectRow(this);'
1879 type=\"checkbox\" id=\"UMCHK-".$line["id"]."\"></td>";
1881 print "<td><a href=\"javascript:editUser($uid);\">" .
1882 $line["login"] . "</td>";
1884 print "<td><a href=\"javascript:editUser($uid);\">" .
1885 $line["access_level"] . "</td>";
1887 } else if ($uid != $edit_uid) {
1889 print "<td><input disabled=\"true\" type=\"checkbox\"
1890 id=\"UMCHK-".$line["id"]."\"></td>";
1892 print "<td>".$line["login"]."</td>";
1893 print "<td>".$line["access_level"]."</td>";
1897 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1899 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
1902 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
1907 print "<td>".$line["last_login"]."</td>";
1918 if ($subop == "edit") {
1920 <input type=\"submit\" class=\"button\"
1921 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
1922 <input type=\"submit\" class=\"button\"
1923 onclick=\"javascript:userEditSave()\" value=\"Save\">";
1929 <input type=\"submit\" class=\"button\"
1930 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">
1931 <input type=\"submit\" class=\"button\"
1932 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
1933 <input type=\"submit\" class=\"button\"
1934 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">";
1942 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->