<?

require_once("include/bittorrent.php");
dbconn(true);
loggedinorreturn();
if (get_user_class() < UC_USER){
stderr("Fehler","Zugriff erst ab User!!!");
}

stdhead("Wunschliste");
$action = htmlentities($_GET["action"]);

if(empty($action)) {

$get_wunsch = mysql_query("SELECT * FROM wuensche ORDER BY id DESC");
begin_frame("Radio Wunschliste");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
<?
if (get_user_class() >= UC_USER){
?>
  <tr>
    <td class="tableb" width="100%"><center><a href="wunsch.php?action=create_wunsch">Musikwunsch eintragen</a></center></td>
  </tr>
<?
}
?>
</table>
<br />
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Titel</td>
    <td class="tableb">Interpret</td>
    <td class="tableb">Datum</td>
    <td class="tableb">Eingetragen</td>
    <td class="tableb">Optionen</td>
    <td class="tableb">Löschen</td>
  </tr>
<?
while($data_wunsch = mysql_fetch_array($get_wunsch)) {
?>
  <tr>
    <td class="tablea"><a href="wunsch.php" onmouseover="return overlib('<font color=red><b>Musik Genre</b></font><br><?php echo htmlentities($data_wunsch["genre"]); ?>', CSSCLASS);" onmouseout="return nd();"><?php echo htmlentities($data_wunsch["wunsch"]); ?></a></td>
    <td class="tablea"><?php echo htmlentities($data_wunsch["interpret"]); ?></td>
    <td class="tablea"><?php echo htmlentities($data_wunsch["datum"]); ?></td>
    <td class="tablea"><?php echo htmlentities($data_wunsch["von"]); ?></td>
<?
if (get_user_class() >= UC_MODERATOR OR $CURUSER['username'] == $data_wunsch['von']) {
?>
    <td class="tablea"><a href="wunsch.php?action=edit_wunsch&id=<?php echo htmlentities($data_wunsch["id"]); ?>">Editieren</a></td>
<?
}else{
?>
    <td class="tablea"><font color="#FF0000">Keine Optionen</font></td>
<?
}
if (get_user_class() >= UC_MODERATOR OR $CURUSER['username'] == $data_wunsch['von']){
?>
    <td class="tablea"><a href="wunsch.php?action=delete_wunsch&id=<?php echo htmlentities($data_wunsch["id"]); ?>">Löschen</a></td>
<?
}else{
?>
   <td class="tablea"><font color="#FF0000">Du kannst hier nicht löschen</font></td>
<?
}
?>
  </tr>
<? } ?>
</table>
<?
end_frame();
}
if($action == "create_wunsch") {
begin_frame("Wunsch hinzufügen");
?>
<form method="post" action="wunsch.php?action=create_wunsch_do">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Titel</td>
    <td class="tablea"><input type="text" name="wunsch" /></td>
  </tr>
  <tr>
    <td class="tableb">Interpret</td>
    <td class="tablea"><input type="text" name="interpret" /></td>
  </tr>
  <tr>
    <td class="tableb">Genre</td>
    <td class="tablea"><input type="text" name="genre" /></td>
  </tr>
    <input type="hidden" name="username" value="<?=$CURUSER["username"]?>"/>
  <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_wunsch") {
begin_frame("Wunsch Editieren");
$id = $_GET["id"];
$data_wunsch = mysql_fetch_array(mysql_query("SELECT * FROM wuensche WHERE id = '$id'"));
?>
<form method="post" action="wunsch.php?action=edit_wunsch_do&id=<?=$id?>">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Titel</td>
    <td class="tablea"><input type="text" name="wunsch" value="<?php echo htmlentities($data_wunsch["wunsch"]); ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Interpret</td>
    <td class="tablea"><input type="text" name="interpret" value="<?php echo htmlentities($data_wunsch["interpret"]); ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Genre</td>
    <td class="tablea"><input type="text" name="genre" value="<?php echo htmlentities($data_wunsch["genre"]); ?>" /></td>
  </tr>
    <input type="hidden" name="username" value="<?=$CURUSER["username"]?>"/>
  <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_wunsch_do") {

$error = 0;
$wunsch = $_POST["wunsch"];
$interpret = $_POST["interpret"];
$genre = $_POST["genre"];
$username = $_POST["username"];

if(empty($wunsch) OR empty($genre) OR empty($interpret)) { $error = 1; }

begin_frame("Wunsch Erstellen");
if($error == 1) {
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb"><font color="#FF0000">Du musst alle Felder ausfüllen.....</font> [<a href="wunsch.php?action=create_wunsch">Zurück</a>]</td>
  </tr>
</table>
<?
} else {
mysql_query("INSERT INTO wuensche (datum, von, genre, wunsch, interpret) Values( Now(), ".sqlesc($username).", ".sqlesc($genre).", ".sqlesc($wunsch).", ".sqlesc($interpret).")") or sqlerr(__FILE__,__LINE__);
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb"><font color="#009F00">Musikwunsch erfolgreich eingetragen.....</font> [<a href="wunsch.php">Weiter</a>]</td>
  </tr>
</table>
<?
}
$text = "[color=red][b][size=4]ES WURDE EIN MUSIKWUNSCH IN DER WUNSCHLISTE HINZUGEFÜGT ![/size][/b][/color] ";
//$date = gmdate("Y-m-d H:i:s");
$date=time();
//$query = "INSERT INTO shoutbox (id, userid, username, date, text) VALUES (NULL, '".$CURUSER['username']."', '".MakeSQLSafe($_POST['message'])."', '".$local_time."', '".$CURUSER['id']."')";

mysql_query("INSERT INTO shoutbox (id, userid, username, date, text) VALUES ('id'," . sqlesc('0') . ", " . sqlesc('System') . ", $date, " . sqlesc($text) . ")");
end_frame();
}
if($action == "edit_wunsch_do") {

$error = 0;
$id = $_GET["id"];
$wunsch = $_POST["wunsch"];
$interpret = $_POST["interpret"];
$genre = $_POST["genre"];

if(empty($wunsch) OR empty($genre) OR empty($interpret)) { $error = 1; }

begin_frame("Wunsch Editieren");
if($error == 1) {
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb"><font color="#FF0000">Du musst alle Felder ausfüllen.....</font> [<a href="wunsch.php?action=edit_wunsch&id=<?=$id?>">Zurück</a>]</td>
  </tr>
</table>
<?
} else {
mysql_query("UPDATE wuensche SET ".sqlesc($genre).", ".sqlesc($wunsch).", ".sqlesc($interpret)." WHERE id = '$id'");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb"><font color="#009F00">Wunsch erfolgreich editiert.....</font> [<a href="wunsch.php">Weiter</a>]</td>
  </tr>
</table>
<?
}
end_frame();
}
if($action == "delete_wunsch") {

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