<?

require "include/bittorrent.php";

dbconn(false);

loggedinorreturn();

ob_start("ob_gzhandler");

stdhead("Active Reports");

begin_main_frame();

if (get_user_class() < 25)
{
print("<h3 class=tabletitle>Fehler, Zugriff Verweigert</h3>");
end_main_frame();
stdfoot();
}

$type = $_GET["type"];
if ($type == "user")
$where = " WHERE type = 'user'";
else if ($type == "torrent")
$where = " WHERE type = 'torrent'";
else if ($type == "forum")
$where = " WHERE type = 'forum'";
else if ($type == "comment")
$where = " WHERE type = 'comment'";
else
$where = "";


$res = mysql_query("SELECT count(id) FROM reports $where") or die(mysql_error());
$row = mysql_fetch_array($res);

$count = $row[0];
$perpage = 25;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"] . "?type=" . $_GET["type"] . "&" );
begin_frame ();
print("<h1 class=tabletitle align=center>Gemeldete Torrents,Mitglieder und Kommentare</h1>");

echo $pagertop;

print("<table class=tablea border=1 cellspacing=0 cellpadding=5 align=center width=95%>\n");
print("<tr><td class=tabletitle align=left><b>Von</b></td><td class=tabletitle align=left><b>Gemeldetes Mitglied</b></td><td class=tabletitle align=left><b>Kategorie</b></td><td class=tabletitle align=left><b>Begründung</b></td><td class=tabletitle align=left><b>Status</b></td><td class=tabletitle align=center><b>Abhaken</b></td>");
if (get_user_class() >= 100)
 printf("<td class=tabletitle align=left><b>Löschen</b></td></tr>");
print("</tr>");
print("<form method=post action=takedelreport.php>");
$res = mysql_query("SELECT reports.id, reports.dealtwith,reports.dealtby, reports.addedby, reports.votedfor, reports.reason, reports.type, users.username FROM reports INNER JOIN users on reports.addedby = users.id $where ORDER BY id desc $limit");

while ($arr = mysql_fetch_assoc($res))
{
if ($arr[dealtwith])
{
 $res3 = mysql_query("SELECT username FROM users WHERE id=$arr[dealtby]");
 $arr3 = mysql_fetch_assoc($res3);
 $dealtwith = "<font color=green><b>Bearbeitet von - <a href=userdetails.php?id=$arr[dealtby]><b>$arr3[username]</b></a></b></font>";
}
else
 $dealtwith = "<font color=red><b>Offen</b></font>";
if ($arr[type] == "user")
{
 $type = "userdetails";
 $res2 = mysql_query("SELECT username FROM users WHERE id=$arr[votedfor]");
 $arr2 = mysql_fetch_assoc($res2);
 $name = $arr2[username];
}
else if ($arr[type] == "torrent")
{
 $type = "details";
 $res2 = mysql_query("SELECT name FROM torrents WHERE id=$arr[votedfor]");
 $arr2 = mysql_fetch_assoc($res2);
 $name = $arr2[name];
 if ($name == "")
  $name = "<b>[Gelöscht]</b>";
}
else if  ($arr[type] == "comment")
{
$type = "details";
$res2 = mysql_query("SELECT torrent, user FROM comments WHERE id=$arr[votedfor]");
$arr2 = mysql_fetch_assoc($res2);

$torrent = $arr2["torrent"];
$user_id = $arr2["user"];

$res_tn = mysql_query("SELECT name FROM torrents WHERE id=$torrent");
$arr_tn = mysql_fetch_assoc($res_tn);

$torrent_name = $arr_tn[name];

$res_usr = mysql_query("SELECT username FROM users WHERE id=$user_id");
$arr_usr = mysql_fetch_assoc($res_usr);

$comment_username=$arr_usr[username];
}
print("<tr><td><a href=userdetails.php?id=$arr[addedby]><b>$arr[username]</b></a></td><td align=left><a href=$type.php?id=$arr[votedfor]><b>$name</b></a></td><td align=left>$arr[type]</td><td align=left>$arr[reason]</td><td align=left>$dealtwith</td><td><input type=\"checkbox\" name=\"delreport[]\" value=\"" . $arr[id] . "\" /></td>\n");

if (get_user_class() >= 100)
print("<td><a href=delreport.php?id=$arr[id]><b>Lösche</b></a></td>");
print("</tr>");
}

print("</table>\n");

print("<p align=right><input type=submit value=Bearbeiten></p>");
print("</form>");

echo $pagerbottom;
end_main_frame();
stdfoot();

?>