<?php
/*
Coded by BeaVes from Fallen Angels Tracker
*/
require "include/bittorrent.php";
dbconn();
loggedinorreturn();

stdhead("Datenbank");

if($_GET['edit'] > 0){
if($CURUSER['class'] >= 25){
$sql="UPDATE `dox` SET `accessoff` = '".$_POST['class']."' WHERE `dox`.`id` =".$_GET['edit'];
mysql_query($sql);
echo "Erfolgreich geändert";
}else{
die("Kein Rechte zum Ändern!");
}
}

if($HTTP_POST_FILES['thefile']['name'] != ""){
if(file_exists("./dox/".$HTTP_POST_FILES['thefile']['name'])){
die("Datei existiert schon!");
}
copy($HTTP_POST_FILES['thefile']['tmp_name'], "./dox/".$HTTP_POST_FILES['thefile']['name']);



$uptime=date("Y-m-d G:i:s");
$sql="INSERT INTO `dox` ( `filename` , `uploadtime` , `size` , `accessoff` , `uploadby` )
VALUES ('".$HTTP_POST_FILES['thefile']['name']."', '".$uptime."', '".$HTTP_POST_FILES['thefile']['size']."', '".$_POST['class']."', '".$CURUSER['username']."');";
mysql_query($sql);
echo "Datei erfolgreich hochgeladen!";
}


if($_GET['download'] > 0){
if($CURUSER['class'] >= 25){
$sql="SELECT filename FROM `dox` WHERE ID = $_GET[download]";
$req=mysql_query($sql);
while($row = mysql_fetch_object($req)){
header("Location: ./dox/'.$row->filename.'");
}
}else{
die("Keine Rechte zum runterladen!");
}
}


if($_GET['delete'] > 0){
if($CURUSER['class'] >= 25){

$sql="SELECT filename FROM `dox` WHERE ID=".$_GET['delete'];
$req=mysql_query($sql);
while($row = mysql_fetch_object($req)){
$filename=$row->filename;
}
@unlink("./dox/".$filename) or die("Datei konnte nicht gelöscht werden!");
echo "Datei gelöscht";
$sql="DELETE FROM `dox` WHERE ID =".$_GET['delete'];
mysql_query($sql);
}else{
die("Keine Rechte zum löschen!");
}
}
?>
<table cellpadding="4" cellspacing="1" border="0" style="width:100%" class="tableinborder">
<tr class="tabletitle" width="100%">
<td colspan="10" width="100%"><span class="smallfont"><center>
<b>Datenbank</b>
</center></span></td></tr><tr><td width="100%" class="tablea">

<table width="95%"  border="0" cellspacing="1" cellpadding="3" align="center" class="tableinborder">
<tr><td class=tablecat><b>Dateiname</b></td><td class=tablecat><b>Größe</b></td><td class=tablecat><b>Time</b></td><td class=tablecat><b>Uploader</b></td><td class=tablecat><b>Verfügbar ab</b></td><td class=tablecat><b>Hits</b></td>

<?php
if($CURUSER['class'] >=25){
echo "<td class=tablecat><b>bearbeiten</b></td>";
echo "<td class=tablecat><b>löschen</b></td>";
}

$sql="SELECT class, username
FROM users
WHERE id = ".$CURUSER['id'];

$req=mysql_query($sql);
while($row = mysql_fetch_object($req)){
$userclass=$row->class+1;
}

$sql="SELECT *
FROM `dox`
WHERE accessoff < ".$userclass."
ORDER BY `uploadtime` DESC";

$req=mysql_query($sql);
while($row = mysql_fetch_object($req)){
    echo "<tr><td class=tablea><a href=getdox.php/$row->filename>$row->filename</a><p></td>";
    echo "<td class=tableb>".mksize($row->size)."</td>";
    echo "<td class=tablea>$row->uploadtime</td>";
    echo "<td class=tableb>$row->uploadby</td>";
	$accessoff=get_user_class_name($row->accessoff);
    echo "<td class=tablea>$accessoff</td>";
    echo "<td class=tablea>$row->hits</td>";

	if($CURUSER['class'] >=25){
	?>
	<td class=tableb><form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>?edit=<? echo $row->id; ?>" method="post">
	<select name=class onchange="document.form.submit()">
<?
        if (get_user_class() == UC_MODERATOR)
            $maxclass = UC_VIP;
        elseif (get_user_class() == UC_SYSOP)
            $maxclass = UC_SYSOP;
        else
            $maxclass = get_user_class() - 1;
        for ($i = 0; $i <= $maxclass; ++$i)
        if (get_user_class_name($i) != "")
            print("<option ".($row->accessoff == $i ? " selected" : "")." value=$i>$prefix" . get_user_class_name($i) . "\n");
        print("</select>\n");
?>
<input type="submit" value="ok"></form></td>

	<?
	$file = $_SERVER[PHP_SELF];
	echo "<td class=tablea><a href=$file?delete=$row->id>löschen</a></td>";
	}

}
?>
</table>
</table>

<?
if ($CURUSER['class'] >= UC_MODERATOR){
?>
<br><br>
<table cellpadding="4" cellspacing="1" border="0" style="width:100%" class="tableinborder">
<tr class="tabletitle" width="100%">
<td colspan="10" width="100%"><span class="smallfont"><center>
<b>Upload</b>
</center></span></td></tr><tr><td width="100%" class="tablea">


<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><center>Datei:<input name="thefile" type="file"></center></p>
<p><center>Verfügbar ab <select name=class>
<?
        if (get_user_class() == UC_MODERATOR)
            $maxclass = UC_VIP;
        elseif (get_user_class() == UC_SYSOP)
            $maxclass = UC_SYSOP;
        else
            $maxclass = get_user_class() - 1;
        for ($i = 0; $i <= $maxclass; ++$i)
        if (get_user_class_name($i) != "")
            print("<option value=$i" . ($user["class"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "\n");
        print("</select>\n");
?>
</center></p>
<p><center><input type="submit" value="Upload"></center></p>
</form>

<?

}


stdfoot();
?>