<?

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

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

stdhead("Feiertage");
$action = $_GET["action"];

if(empty($action)) {

$get_happydays = mysql_query("SELECT * FROM happydays ORDER BY id DESC");
begin_frame("Alle Feiertage in einer Übersicht");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb" width="50%"><a href="happydays.php?action=create_happy">Feiertag hinzufügen</a></td>
    <td class="tableb" width="50%"><div align="right">Gesamt: <?php echo mysql_num_rows($get_happydays); ?></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">Name</td>
    <td class="tableb"><center>Datum (Format Jahr-Monat-Tag)</center></td>
    <td class="tableb">Gutschrift (GB)</td>
    <td class="tableb">Cleanupsize (B)</td>
    <td class="tableb" colspan="2">Optionen</td>
  </tr>
<?
while($data_happydays = mysql_fetch_array($get_happydays)) {
?>
  <tr>
    <td class="tablea"><center><?php echo $data_happydays["id"]; ?></center></td>
    <td class="tablea"><?php echo $data_happydays["name"]; ?></a></td>
    <td class="tablea"><center><?php echo $data_happydays["datum"]; ?></center></td>
    <td class="tablea"><?php echo $data_happydays["gbbetrag"]; ?></a></td>
    <td class="tablea"><center><?php echo $data_happydays["cleanupsize"]; ?></center></td>
    <td class="tablea"><center><a href="happydays.php?action=edit_happy&id=<?php echo $data_happydays["id"]; ?>">Editieren</a></center></td>
    <td class="tablea"><center><a href="happydays.php?action=delete_happy&id=<?php echo $data_happydays["id"]; ?>">Löschen</a></center></td>
  </tr>
<? } ?>
</table>
<?
end_frame();
}
if($action == "create_happy") {
begin_frame("Neuen Feiertag Eintragen");
?>
<form method="post" action="happydays.php?action=create_happy_do">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Name</td>
    <td class="tablea"><input type="text" name="name" /></td>
  </tr>
  <tr>
    <td class="tableb">Datum (Format Jahr-Monat-Tag)</td>
    <td class="tablea"><input type="text" name="datum" /></td>
  </tr>
  <tr>
    <td class="tableb">Gutschrift (GB)</td>
    <td class="tablea"><input type="text" name="gbbetrag" /></td>
  </tr>
  <tr>
    <td class="tableb">Cleanupsize (B)</td>
    <td class="tablea"><input type="text" name="cleanupsize" /></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_happy") {
begin_frame("Feiertag Editieren");
$id = $_GET["id"];
$data_happydays = mysql_fetch_array(mysql_query("SELECT * FROM happydays WHERE id = '$id'"));
?>
<form method="post" action="happydays.php?action=edit_happy_do&id=<?=$id?>">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Name</td>
    <td class="tablea"><input type="text" name="name" value="<?php echo $data_happydays["name"]; ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Datum (Format Jahr-Monat-Tag)</td>
    <td class="tablea"><input type="text" name="datum" value="<?php echo $data_happydays["datum"]; ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Gutschrift (GB)</td>
    <td class="tablea"><input type="text" name="gbbetrag" value="<?php echo $data_happydays["gbbetrag"]; ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Cleanupsize (B)</td>
    <td class="tablea"><input type="text" name="cleanupsize" value="<?php echo $data_happydays["cleanupsize"]; ?>" /></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_happy_do") {

$error = 0;
$name = $_POST["name"];
$datum = $_POST["datum"];
$gbbetrag = $_POST["gbbetrag"];
$cleanupsize = $_POST["cleanupsize"];

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

begin_frame("Feiertag 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="happydays.php?action=create_happy">Zurück</a>]</td>
  </tr>
</table>
<?
} else {
mysql_query("INSERT INTO happydays (name, datum, gbbetrag, cleanupsize) VALUES ('$name','$datum','$gbbetrag','$cleanupsize')");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Feiertag erfolgreich eingetragen..... [<a href="happydays.php">Weiter</a>]</td>
  </tr>
</table>
<?
}
end_frame();
}
if($action == "edit_happy_do") {

$error = 0;
$id = $_GET["id"];
$name = $_POST["name"];
$datum = $_POST["datum"];
$gbbetrag = $_POST["gbbetrag"];
$cleanupsize = $_POST["cleanupsize"];

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

begin_frame("Feiertag 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="happydays.php?action=edit_happy&id=<?=$id?>">Zurück</a>]</td>
  </tr>
</table>
<?
} else {
mysql_query("UPDATE happydays SET name='$name', datum='$datum', gbbetrag='$gbbetrag', cleanupsize='$cleanupsize' WHERE id = '$id'");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Feiertag erfolgreich editiert..... [<a href="happydays.php">Weiter</a>]</td>
  </tr>
</table>
<?
}
end_frame();
}
if($action == "delete_happy") {

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