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

dbconn();

if(isset($_POST['submit']) && "saveit" == $_POST['submit'])
  {
   $sql = "DELETE FROM sendeplan WHERE day = '".$_POST['day']."' AND time = '".$_POST['time']."'";
   mysql_query($sql) OR die(mysql_error());
   $sql = "INSERT INTO sendeplan (day,time,mod,genre) VALUES ('".$_POST['day']."','".$_POST['time']."','".addslashes(htmlspecialchars($_POST['mod']))."','".addslashes(htmlspecialchars($_POST['genre']))."')";
   mysql_query($sql) OR die(mysql_error());
   echo "<br><font color='red'><b>Daten erfolgreich gespeichert.</b></font>";
  }
   else
  {
   if(isset($_POST['submit']) && "save" == $_POST['submit'])
     {
      $sql    = "SELECT * FROM sendeplan WHERE day = '".$_POST['day']."' AND time = '".$_POST['time']."' AND mod = '".$_POST['mod']."'";
      $result = mysql_query($sql) OR die(mysql_error());
      $row    = mysql_fetch_assoc($result);
      echo "
      <form action='sendedit.php?section=sendedit' method='post'>
              Tag:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='day' value='".$_POST['day']."'></input>
      <br><br>Zeit:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='time' value='".$_POST['time']."'></input>
      <br><br>Moderator: <input type='text' name='mod' value='".$_POST['mod']."'></input>
      <br><br>Genre:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type='text' name='genre' value='".stripslashes($row['genre'])."'></input>
      <br><br><input type='submit' name='submit' value='saveit'></input></form>";
     }
      else
     {
   if(isset($_POST['submit']) && "edit" == $_POST['submit'])
     {
      $sql    = "SELECT * FROM sendeplan WHERE day = '".$_POST['day']."' AND time = '".$_POST['time']."'";
      $result = mysql_query($sql) OR die(mysql_error());
      $row    = mysql_fetch_assoc($result);
      echo "
      <form action='sendedit.php?section=sendedit' method='post'>
              Tag:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='day' value='".$_POST['day']."'></input>
      <br><br>Zeit:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='time' value='".$_POST['time']."'></input>
      <br><br>Moderator: <input type='text' name='mod' value='".stripslashes($row['mod'])."'></input>
      <br><br><input type='submit' name='submit' value='save'></input></form>";
     }
      else
     {
      if(isset($_POST['submit']) && "GO" == $_POST['submit'])
        {
         echo "
         <form action='sendedit.php?section=sendedit' method='post'>
         <input type='hidden' name='day' value='".$_POST['day']."'></input>
                 Tag:&nbsp;<input type='text' name='day' value='".$_POST['day']."'></input>
         <br><br>Zeit: <select name='time'>";
         $time = "0";
         while($time < 24)
              {
               if($time < 10)
                 {
                  $time2 = "0$time";
                 }
                  else
                 {
                  $time2 = "$time";
                 }
               echo "
               <option value='$time'>$time2</option>";
               $time++;
              }
         echo "</select>
         <br><br><input type='submit' name='submit' value='edit'></input></form>";
        }
         else
        {
         echo "
         <form action='sendedit.php?section=sendedit' method='post'>
          Tag :
         <select name='day'>
         <option value='Samstag'>Samstag</option>
         <option value='Sonntag'>Sonntag</option>
         <option value='Montag'>Montag</option>
         <option value='Dienstag'>Dienstag</option>
         <option value='Mittwoch'>Mittwoch</option>
         <option value='Donnerstag'>Donnerstag</option>
         <option value='Freitag'>Freitag</option>
         </select>
         <br><br><input type='submit' name='submit' value='GO'></input></form>";
        }
      }
   }
}
?>