<?php
 require "include/bittorrent.php";

 dbconn(false);

 loggedinorreturn();

 if ($_SERVER["REQUEST_METHOD"] == "POST")
 {


   $descr = trim($_POST["descr"]);  
   if ($descr == "")
   stderr("Fehler", "<center><h2>Fehler! Du musst eine Beschreibung angeben!</h2></center>");

   $streamer = trim($_POST["streamer"]);  
   if ($streamer == "")
   stderr("Fehler", "<center><h2>Fehler! Du musst eine Beschreibung angeben!</h2></center>");

   $catid = (0 + $_POST["type"]);
   if (!is_valid_id($catid)) 
   stderr("Fehler", "<center><h2>Du musst einen Tag auswählen</h2></center>");

   $catid1 = (0 + $_POST["type1"]);
   if (!is_valid_id($catid1)) 
   stderr("Fehler", "<center><h2>Du musst einen Tag auswählen</h2></center>");

   $catid2 = (0 + $_POST["type2"]);
   if (!is_valid_id($catid2)) 
   stderr("Fehler", "<center><h2>Du musst einen Monat auswählen</h2></center>");

   $catid3 = (0 + $_POST["type3"]);
   if (!is_valid_id($catid3)) 
   stderr("Fehler", "<center><h2>Du musst ein Jahr auswählen</h2></center>");

   $catid4 = (0 + $_POST["type4"]);
   if (!is_valid_id($catid4)) 
   stderr("Fehler", "<center><h2>Du musst die Stunde angeben</h2></center>");

   $catid5 = (0 + $_POST["type5"]);
   if (!is_valid_id($catid5)) 
   stderr("Fehler", "<center><h2>Du musst die Minuten angeben</h2></center>");


   $cat = 0 + $_POST["type"];
   $cat1 = 0 + $_POST["type1"];
   $cat2 = 0 + $_POST["type2"];
   $cat3 = 0 + $_POST["type3"];
   $cat4 = 0 + $_POST["type4"];
   $cat5 = 0 + $_POST["type5"];
   $streamer = sqlesc($streamer);
   $streamnr = $_POST["streamnr"];
   $addedby = $CURUSER["id"];
   $descr = sqlesc($descr);

   mysql_query("INSERT INTO stream (tage, days, months, years, hours, minutes, streamer, descr, addedby, streamnr) VALUES($cat, $cat1, $cat2, $cat3, $cat4, $cat5, $streamer, $descr, $addedby, $streamnr)") or sqlerr();

   header("Location: $BASEURL/sendeplan.php");
die;
 }
 
if (get_user_class() >= UC_USER)
 {
   $delete = $_GET["delete"]; 
   if (is_valid_id($delete))
   {
    $r = mysql_query("SELECT id, addedby FROM stream WHERE id=$delete") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($r) == 1)
    {
         $a = mysql_fetch_assoc($r);
      if ($a["addedby"] == $CURUSER["id"]){
        mysql_query("DELETE FROM stream WHERE id=$delete") or sqlerr(__FILE__, __LINE__);
          //   stderr("Warnung", "<center><h2>Die Datei konnte nicht gelöscht werden.</h2></center>");
      }
    }
   }
 }

stdhead("Sendeplan von TurboWolke");
print("<br>");
begin_frame("Sendeplan von German Underground Torrents <a name=Kat0 id=Kat0></a>", FALSE, "850px");
print("<br>");
 //Untere Zeilen nur nötig falls 2 Streams vorhanden
 // print("<center><table class=tableoutborder border=0 cellspacing=1 width=800px cellpadding=5>\n");
 // print("<tr><td class=tabletitle align=center colspan=2><b>Auswahl</b></td></tr>");
 // print("<tr><td class=tableb align=center><b><a href=#Kat1 class=altlink>Radio 1</a></b></td><td class=tableb align=center><b><a href=#Kat2 class=altlink>Radio 2</a></b></td></tr></table>\n");
 // print("<br>");

 $res = mysql_query("SELECT * FROM stream WHERE streamnr = '1' ORDER by years, months, days, tage, hours") or sqlerr();
 if (mysql_num_rows($res) == 0)
   print("<center><h2>Keine Sendungen vorhanden auf Radio 1</h2>");
 else
 {
   print("<center><table class=tableoutborder border=0 cellspacing=1 width=800px cellpadding=5>\n");
   print("<tr><td class=tabletitle align=center colspan=5><a name=Kat1 id=Kat1><b>Radio 1</b></a> <a href=#Kat0 class=altlink><img style=border:none alt=Nach oben title=Nach_oben src=pic/top.gif></a></td></tr>");
   print("<tr><td class=tableb align=left><b>Datum</b></td><td class=tableb align=left><b>Zeit</b></td><td class=tableb><b>Streamer</b></td>" .
     "<td class=tableb><b>Beschreibung</b></td><td class=tableb><b>Eingetragen von</b></td></tr>\n");

   $mod = get_user_class() >= UC_MODERATOR;

   while ($arr = mysql_fetch_assoc($res))
   {
    $r = mysql_query("SELECT username FROM users WHERE id=$arr[addedby]") or sqlerr();
    $a = mysql_fetch_assoc($r);
    $r1 = mysql_query("SELECT name FROM tage WHERE id=$arr[tage]") or sqlerr();
    $a1 = mysql_fetch_assoc($r1);
    $r2 = mysql_query("SELECT name FROM days WHERE id=$arr[days]") or sqlerr();
    $a2 = mysql_fetch_assoc($r2);
    $r3 = mysql_query("SELECT name FROM months WHERE id=$arr[months]") or sqlerr();
    $a3 = mysql_fetch_assoc($r3);
    $r4 = mysql_query("SELECT name FROM years WHERE id=$arr[years]") or sqlerr();
    $a4 = mysql_fetch_assoc($r4);
    $r5 = mysql_query("SELECT name FROM hours WHERE id=$arr[hours]") or sqlerr();
    $a5 = mysql_fetch_assoc($r5);
    $r6 = mysql_query("SELECT name FROM minutes WHERE id=$arr[minutes]") or sqlerr();
    $a6 = mysql_fetch_assoc($r6);
    $datum = "<td class=tablea><b>$a1[name]</b>, $a2[name]. $a3[name] $a4[name]" .
    (get_user_class() >= UC_MODERATOR || $arr["addedby"] == $CURUSER["id"] ? " <font size=1 class=small><a href=?delete=$arr[id]>[Löschen]</a> <a href=editsendeplan.php?id=$arr[id]>[Ändern]</a></font>" : "") ."</td>\n";
    $zeit = "<td class=tablea>$a5[name]:$a6[name] Uhr</td>\n";
    $streamer = "<td class=tablea><b>" . $arr["streamer"] . "</b>\n"; 
    $descr = "<td class=tablea>" . $arr["descr"] . "</td>\n";
    $added = "<td class=tablea><a href=userdetails.php?id=".$arr['addedby']."><b>$a[username]</b></a></td>\n";
     print("<tr>$datum$zeit$streamer$descr$added</tr>\n");
   }
  print("</table></p><br>");
 }
//untere Zeilen nur nötig falls 2 Streams vorhanden
 /*
$res = mysql_query("SELECT * FROM stream WHERE streamnr = '2' ORDER by years, months, days, tage, hours") or sqlerr();
 if (mysql_num_rows($res) == 0)
   print("<center><h2>Keine Sendungen vorhanden auf Radio 2</h2>");
 else
 {
   print("<center><table class=tableoutborder border=0 cellspacing=1 width=800px cellpadding=5>\n");
   print("<tr><td class=tabletitle align=center colspan=5><a name=Kat2 id=Kat2><b>Radio 2</b></a> <a href=#Kat0 class=altlink><img style=border:none alt=Nach oben title=Nach_oben src=pic/top.gif></a></td></tr>");
   print("<tr><td class=tableb align=left><b>Datum</b></td><td class=tableb align=left><b>Zeit</b></td><td class=tableb><b>Streamer</b></td>" .
     "<td class=tableb><b>Beschreibung</b></td><td class=tableb><b>Eingetragen von</b></td></tr>\n");

   $mod = get_user_class() >= UC_MODERATOR;

   while ($arr = mysql_fetch_assoc($res))
   {
    $r = mysql_query("SELECT username FROM users WHERE id=$arr[addedby]") or sqlerr();
    $a = mysql_fetch_assoc($r);
    $r1 = mysql_query("SELECT name FROM tage WHERE id=$arr[tage]") or sqlerr();
    $a1 = mysql_fetch_assoc($r1);
    $r2 = mysql_query("SELECT name FROM days WHERE id=$arr[days]") or sqlerr();
    $a2 = mysql_fetch_assoc($r2);
    $r3 = mysql_query("SELECT name FROM months WHERE id=$arr[months]") or sqlerr();
    $a3 = mysql_fetch_assoc($r3);
    $r4 = mysql_query("SELECT name FROM years WHERE id=$arr[years]") or sqlerr();
    $a4 = mysql_fetch_assoc($r4);
    $r5 = mysql_query("SELECT name FROM hours WHERE id=$arr[hours]") or sqlerr();
    $a5 = mysql_fetch_assoc($r5);
    $r6 = mysql_query("SELECT name FROM minutes WHERE id=$arr[minutes]") or sqlerr();
    $a6 = mysql_fetch_assoc($r6);
    $datum = "<td class=tablea><b>$a1[name]</b>, $a2[name]. $a3[name] $a4[name]" .
    (get_user_class() >= UC_MODERATOR || $arr["addedby"] == $CURUSER["id"] ? " <font size=1 class=small><a href=?delete=$arr[id]>[Löschen]</a> <a href=editsendeplan.php?id=$arr[id]>[Ändern]</a></font>" : "") ."</td>\n";
    $zeit = "<td class=tablea>$a5[name]:$a6[name] Uhr</td>\n";
    $streamer = "<td class=tablea><b>" . $arr["streamer"] . "</b>\n"; 
    $descr = "<td class=tablea>" . $arr["descr"] . "</td>\n";
    $added = "<td class=tablea><a href=userdetails.php?id=".$arr['addedby']."><b>$a[username]</b></a></td>\n";
     print("<tr>$datum$zeit$streamer$descr$added</tr>\n");
   }
  print("</table></p><br>");
 }
*/


 
if (get_user_class() >= UC_MODERATOR)
 {


begin_frame("Sendung eintragen", FALSE, "800px");
  print("<form enctype=multipart/form-data method=post action=?>\n");
  print("<table class=tableoutborder border=0 cellspacing=1 cellpadding=5 width=790px>\n");

$s = "<select name=\"type\">\n<option value=\"0\">(ausw&auml;hlen)</option>\n";
$cats = tagelist();

foreach ($cats as $row)
    $s .= "<option value=\"" . $row["id"] . "\">" . htmlspecialchars($row["name"]) . "</option>\n";

$s .= "</select>\n";

$s1 = "<select name=\"type1\">\n<option value=\"0\">(ausw&auml;hlen)</option>\n";
$cats1 = dayslist();

foreach ($cats1 as $row1)
    $s1 .= "<option value=\"" . $row1["id"] . "\">" . htmlspecialchars($row1["name"]) . "</option>\n";

$s1 .= "</select>\n";

$s2 = "<select name=\"type2\">\n<option value=\"0\">(ausw&auml;hlen)</option>\n";
$cats2 = monthslist();

foreach ($cats2 as $row2)
    $s2 .= "<option value=\"" . $row2["id"] . "\">" . htmlspecialchars($row2["name"]) . "</option>\n";

$s2 .= "</select>\n";

$s3 = "<select name=\"type3\">\n<option value=\"0\">(ausw&auml;hlen)</option>\n";
$cats3 = yearslist();

foreach ($cats3 as $row3)
    $s3 .= "<option value=\"" . $row3["id"] . "\">" . htmlspecialchars($row3["name"]) . "</option>\n";

$s3 .= "</select>\n";


  print("<tr><td class=tablea>Datum</td><td class=tablea align=left>Tag $s</td><td class=tablea align=left>$s1</td><td class=tablea align=left>Monat $s2</td><td class=tablea align=left>Jahr $s3</td></tr>\n");

$s4 = "<select name=\"type4\">\n<option value=\"0\">(ausw&auml;hlen)</option>\n";
$cats4 = hourslist();

foreach ($cats4 as $row4)
    $s4 .= "<option value=\"" . $row4["id"] . "\">" . htmlspecialchars($row4["name"]) . "</option>\n";

$s4 .= "</select>\n";

$s5 = "<select name=\"type5\">\n<option value=\"0\">(ausw&auml;hlen)</option>\n";
$cats5 = minuteslist();

foreach ($cats5 as $row5)
    $s5 .= "<option value=\"" . $row5["id"] . "\">" . htmlspecialchars($row5["name"]) . "</option>\n";

$s5 .= "</select>\n";

  print("<tr><td class=tablea>Zeit</td><td class=tablea align=left colspan=2>Stunden $s4</td><td class=tablea align=left colspan=2>Minuten $s5</td></tr>\n");
  print("<tr><td class=tablea>Streamer</td><td class=tablea align=left colspan=4><input type=text name=streamer size=60><br>(Nur Username angeben)</td></tr>\n");  
  print("<tr><td class=tablea>Beschreibung</td><td class=tablea align=left colspan=4><input type=text name=descr size=60></td></tr>\n");
  print("<tr><td class=tablea>Radio Nr.</td><td class=tablea align=left colspan=4><input type=text name=streamnr size=60><br>(Für Radio 1 -> 1, für Radio 2 -> 2 eingeben)</td></tr>\n");
   print("<tr><td class=tablea colspan=5 align=center><input type=submit value='Absenden' class=btn></td></tr>\n");
   print("</table>\n");
  print("</form></center>\n");
  end_frame();

}

end_frame();


stdfoot();
?>