<?
require "include/bittorrent.php";

dbconn(false);

loggedinorreturn();

if (get_user_class() >= UC_MODERATOR){
$remove = $HTTP_GET_VARS['remove'];
if (is_valid_id($remove))
{
mysql_query("DELETE FROM shitlist WHERE id=$remove") or sqlerr();
//write_log("A user has been deleted from the Shitlist by $CURUSER[id] ($CURUSER[username])");
}
}

if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST" && get_user_class() >= UC_ADMINISTRATOR)
{
$ime = trim($HTTP_POST_VARS["ime"]);
$usrid = trim($HTTP_POST_VARS["usrid"]);
$email = trim($HTTP_POST_VARS["email"]);
$komentar = trim($HTTP_POST_VARS["komentar"]);
//$ip = trim($HTTP_POST_VARS["ip"]);
if (!$ime || !$email || !$komentar)
stderr("Error", "du hast was vergessen einzugeben");
$ime = sqlesc($ime);
$usrid = sqlesc($usrid);
$email = sqlesc($email);
$komentar = sqlesc($komentar);
$dodan = sqlesc(get_date_time());
mysql_query("INSERT INTO shitlist (dodan, ime, usrid, email, komentar) VALUES($dodan, $ime,$usrid, $email, $komentar)") or sqlerr(__FILE__, __LINE__);
header("Location: $BASEURL$HTTP_SERVER_VARS[REQUEST_URI]");
die;
}

ob_start("ob_gzhandler");


stdhead("Sündenregister");

if (get_user_class() >= UC_MODERATOR)
{
print("<h2>User hinzufügen</h2>\n");
print("<table border=1 cellspacing=0 cellpadding=5 class=tableb>\n");
print("<form method=post action=shitlist.php>\n");
print("<tr><td class=rowhead>Username</td><td><input type=text name=ime size=40></td>\n");
print("<tr><td class=rowhead>User ID</td><td><input type=text name=usrid size=6></td>\n");
print("<tr><td class=rowhead>Email</td><td><input type=text name=email size=40></td>\n");
print("<tr><td class=rowhead>Erwischt als/mit</td><td><input type=text name=komentar size=80></td>\n");
print("<tr><td colspan=2><input type=submit value='Okay' class=btn></td></tr>\n");
print("</form>\n</table>\n");
} 

$res2 = mysql_query("SELECT count(id) FROM shitlist") or die(mysql_error());
$row = mysql_fetch_array($res2);

$url = " .$_SERVER[PHP_SELF]?";
$count = $row[0];
$perpage = 40;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $url);


print("<h1>User im Sündenregister ($count)</h1>\n");

if ($count == 0)
print("<p align=center><b>Das Sündenregister ist leer</b></p>\n");
else
{

echo $pagertop;

print("<table border=1 cellspacing=0 cellpadding=5 width=770 class=tableb>\n");
print("<tr>");
print("<td class=tabletitle align=left><b>Username</b></td>");
print("<td class=tabletitle align=left><b>Email</b></td>");
print("<td class=tabletitle align=left><b>Erwischt als / mit</b></td>");
print("<td class=tabletitle align=left><b>Hinzugefügt</b></td>");
if (get_user_class() >=UC_ADMINISTRATOR){

print("<td class=tabletitle align=left><b>Entfernen</b></td>");
}
print("</tr>");

$res = mysql_query("SELECT * FROM shitlist ORDER BY dodan DESC $limit") or sqlerr();

while ($arr = mysql_fetch_assoc($res))
{
$arr["ip"] = long2ip($arr["ip"]);
print("<tr>");
print("<td class=tableb align=left><a href=userdetails.php?id=$arr[usrid]>$arr[ime]" . "</a></td>");
print("<td class=tableb align=left>$arr[email]</td>");
print("<td class=tableb align=left>$arr[komentar]</td>");
print("<td class=tableb align=left>$arr[dodan]</td>");
if (get_user_class() >=UC_ADMINISTRATOR)
{
print("<td class=tableb align=left><a href=shitlist.php?remove=$arr[id]>Entfernen</a></td></tr>");

}
print("</tr>\n");
}

print("</table>\n");
echo $pagerbottom;
}


stdfoot();

?>