<?

require_once("include/bittorrent.php");
dbconn(true);

loggedinorreturn();
if (get_user_class() < UC_MODERATOR)
  die;

stdhead("Alles auf Zeit-Only Upload");
$action = $_GET["action"];

if(empty($action)) {

$get_outime = mysql_query("SELECT * FROM outime ORDER BY id DESC");
begin_frame("Alle Zeit-Only Uploads in einer Übersicht");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb" width="50%"><a href="outime.php?action=create_ou">Zeit-Only Upload hinzufügen</a></td>
    <td class="tableb" width="50%"><div align="right">Gesamt: <?php echo mysql_num_rows($get_outime); ?></div></td>
  </tr>
</table>
<br />
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb"><center>ID</center></td>
    <td class="tableb">Only Upload</td>
    <td class="tableb"><center>Datum</center></td>
    <td class="tableb">Tage</td>
    <td class="tableb">Aktiv</td>
    <td class="tableb" colspan="2">Optionen</td>
  </tr>
<?
while($data_outime = mysql_fetch_array($get_outime)) {
?>
  <tr>
    <td class="tablea"><center><?php echo $data_outime["id"]; ?></center></td>
    <td class="tablea"><?php echo $data_outime["name"]; ?></a></td>
    <td class="tablea"><center><?php echo $data_outime["datum"]; ?></center></td>
    <td class="tablea"><?php echo $data_outime["outage"]; ?></a></td>
    <td class="tablea"><center><?php echo $data_outime["aktiv"]; ?></center></td>
    <td class="tablea"><center><a href="outime.php?action=edit_ou&id=<?php echo $data_outime["id"]; ?>">Editieren</a></center></td>
    <td class="tablea"><center><a href="outime.php?action=delete_ou&id=<?php echo $data_outime["id"]; ?>">Löschen</a></center></td>
  </tr>
<? } ?>
</table>
<?
end_frame();
}
if($action == "create_ou") {
begin_frame("Neues Zeit-Only Upload Eintragen");
?>
<form method="post" action="outime.php?action=create_ou_do">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Only Upload (Warum)</td>
    <td class="tablea"><input type="text" name="name" /></td>
  </tr>
  <tr>
    <td class="tableb">Datum (Ab wann alles auf OU? Format Jahr-Monat-Tag)</td>
    <td class="tablea"><input type="text" name="datum" /></td>
  </tr>
  <tr>
    <td class="tableb">Wie lange OU (Tage)</td>
    <td class="tablea"><input type="text" name="outage" /></td>
  </tr>
  <tr>
    <td class="tableb">Aktiv</td>
    <td class="tablea"><input type="checkbox" name="aktiv" /></td>
  </tr>
  <tr>
    <td class="tableb">Optionen</td>
    <td class="tablea"><input name="submit" type="submit" value="Eintragen" /> <input name="reset" type="reset" /></td>
  </tr>
</table>
</form>
<?
end_frame();
}
if($action == "edit_ou") {
begin_frame("Zeit-Only Upload Editieren");
$id = $_GET["id"];
$data_outime = mysql_fetch_array(mysql_query("SELECT * FROM outime WHERE id = '$id'"));
?>
<form method="post" action="outime.php?action=edit_ou_do&id=<?=$id?>">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Only Upload (Warum)</td>
    <td class="tablea"><input type="text" name="name" value="<?php echo $data_outime["name"]; ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Datum (Ab wann alles auf OU? Format Jahr-Monat-Tag)</td>
    <td class="tablea"><input type="text" name="datum" value="<?php echo $data_outime["datum"]; ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Wie lange OU (Tage)</td>
    <td class="tablea"><input type="text" name="outage" value="<?php echo $data_outime["outage"]; ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Aktiv</td>
    <td class="tablea"><input type="checkbox" name="aktiv" value="<?php echo $data_outime["aktiv"]; ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Optionen</td>
    <td class="tablea"><input name="submit" type="submit" value="Eintragen" /> <input name="reset" type="reset" /></td>
  </tr>
</table>
</form>
<?
end_frame();
}
if($action == "create_ou_do") {

$error = 0;
$name = $_POST["name"];
$datum = $_POST["datum"];
$outage = $_POST["outage"];
$aktiv = $_POST["aktiv"];

if(empty($name) OR empty($datum) OR empty($outage) OR empty($datum)) { $error = 1; }

begin_frame("Zeit-Only Upload Erstellen");
if($error == 1) {
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Du musst alle Felder ausfüllen..... [<a href="outime.php?action=create_ou">Zurück</a>]</td>
  </tr>
</table>
<?
} else {
mysql_query("INSERT INTO outime (name, datum, outage, aktiv) VALUES ('$name','$datum','$outage','no')") or sqlerr(__FILE__, __LINE__);
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Feiertag erfolgreich eingetragen..... [<a href="outime.php">Weiter</a>]</td>
  </tr>
</table>
<?
}
end_frame();
}
if($action == "edit_ou_do") {

$error = 0;
$id = $_GET["id"];
$name = $_POST["name"];
$datum = $_POST["datum"];
$outage = $_POST["outage"];
$aktiv = $_POST["aktiv"];

if(empty($name) OR empty($datum) OR empty($outage) OR empty($datum)) { $error = 1; }

begin_frame("Zeit-Only Upload Editieren");
if($error == 1) {
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Du musst alle Felder ausfüllen..... [<a href="outime.php?action=edit_ou&id=<?=$id?>">Zurück</a>]</td>
  </tr>
</table>
<?
} else {
mysql_query("UPDATE outime SET name='$name', datum='$datum', outage='$outage', aktiv='no' WHERE id = '$id'") or sqlerr(__FILE__, __LINE__);
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Zeit-Only Upload erfolgreich editiert..... [<a href="outime.php">Weiter</a>]</td>
  </tr>
</table>
<?
}
end_frame();
}
if($action == "delete_ou") {

$id = $_GET["id"];
mysql_query("DELETE FROM outime WHERE id = '$id'");
begin_frame("Zeit-Only Upload Löschen");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Zeit-Only Upload erfolgreich gelöscht..... [<a href="outime.php">Weiter</a>]</td>
  </tr>
</table>
<?
end_frame();
}
stdfoot();
?>