<?php
require_once("config.inc.php");
$db = dbconnect();
session_start();
//mitgegebene Parameter einlesen:

$action = $_GET['action'];


if($action == ''){

  if (isset($_GET['imtuid'])) {  //welcher Datensatz
 	$imtuid = $_GET['imtuid'];
# 	$_SESSION["anr_imtuid_$imtuid"] = $imtuid;
  }
  
  #if (isset($_SESSION["anr_imtuid"])){
  #      $imtuid = $_SESSION["anr_imtuid"];
  #}


//Anzeige des Buttons entsprechend grün oder rot
      echo "<form action=\"?action=fak_save\" method='post' name='erfassen'>";

      $query_fak_vorh = $db->query("SELECT fakultaet
                                      FROM dep_user
                                     WHERE imtuid='$imtuid'");
      $row_fak_vorh  = $query_fak_vorh->fetch_array();
      $fakultaet = $row_fak_vorh['fakultaet'];
      
                 
      echo"<input type='hidden' name='user' value='$imtuid'>";
      
      echo "<select name=\"fakultaet\" onchange=\"this.form.submit()\">";
      echo "<option value=''>Bitte Fakultät wählen</option>";
      echo "<option value='1' ";if($fakultaet == 1){echo "selected"; } echo">Fakultät 1</option>";
      echo "<option value='2' ";if($fakultaet == 2){echo "selected"; } echo">Fakultät 2</option>";
      echo"</select>
           </form>
          ";
}
if($action == 'fak_save'){
$fakultaet = $_POST['fakultaet'];
$user   = $_POST['user'];
#$imtuid = $_SESSION["anr_imtuid"];

  if($user != '' AND $fakultaet != ''){
    $sql1 = $db->query("UPDATE dep_user 
                           SET fakultaet='$fakultaet'
                         WHERE imtuid='$user'
                       ");

    echo "<meta http-equiv=\"refresh\" content=\"0; URL=".$_SERVER['PHP_SELF']."?imtuid=$user\">";
  }else{
    echo "Unzulässige Eingabe";
    echo "<meta http-equiv=\"refresh\" content=\"1; URL=".$_SERVER['PHP_SELF']."?imtuid=$user\">";
  }


}


?>
