<?php
$user_admin=$_COOKIE["user_admin"];
$jahrgang=$_COOKIE["jahrgang"];


if ($jahrgang == ""){ require("jahrgang.php"); exit;} //Wenn man kein Jahrgang ausgew&auml;hlt hat wird die Jahrgangsauswahlseite geladen

include("kurs/datenbankanbindung.php");     // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php

// Rechteüberprüfung
$db = dbconnect();
if ($user_admin == ""){ require("index.php"); exit;} //Wenn man nicht angemeldet ist, darf man nicht auf die Seite
$result = $db->query("SELECT 1 FROM stan_admin_rechte, stan_admin_rechte_zuord , stan_admin where stan_admin_rechte.stan_admin_rolle = stan_admin_rechte_zuord.stan_admin_rolle AND stan_admin_rechte_zuord.said = stan_admin.said AND stan_admin.user = '$user_admin' AND stan_admin_rechte_zuord.stan_admin_rolle = 'a_anzanm'");
$row = $result->fetch_array();
if ($row[0] != 1){ include("kurs/rechte.php"); exit;}
// Rechte&uuml;berpr&uuml;fung ende

// Rechteüberprüfung ende


if (isset($_GET['action']))
   $action = $_GET['action'];
else
   $action = "";

switch($action){
default:

echo "
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Einzel&uuml;bersicht</title>
</head>
<body onload=\"if(document.einzel)document.einzel.user1.focus();return false;\">
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
                <tr>
                    <td width=\"10\" background=\"../images/box_e1.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../images/box_top.gif\" valign=\"top\"></td>
                    <td width=\"95%\" background=\"../images/box_top.gif\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Anzahl Anmeldungen Student</font><br>
                    <font class=\"sh\">Anzahl der Anmeldungen für eine Praxisstelle</font><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
              <form action="; echo $_SERVER['PHP_SELF'] . "?action=ubersicht"; echo" method=\"POST\" name=\"einzel\">
			  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-width: 0\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"115\">
			    <tr>
			      <td width=\"25%\" height=\"17\">
			      </td>
			      <td width=\"25%\" height=\"17\">&nbsp;</td>
			      <td width=\"25%\" height=\"17\">
			      <p>&nbsp;</p>
			      </td>
			      <td width=\"25%\" height=\"17\">
			      <p></p>
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">&nbsp;</td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        Bitte Matrikelnr. eingeben:
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"left\">
                                <input type='text' size='10' name='user1'>
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        &nbsp;
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"center\">
                                &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      &nbsp;
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      oder
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        &nbsp;
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"center\">
                                &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      Benutzer auswählen
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			    			      ";
			    			      
			    
			    			      $db = dbconnect();
			    			      $query = "SELECT mtknr, vorname, nachname, durchgefallen
			    			                  FROM stud
			    			                 WHERE jahrgang='$jahrgang'
			    			                   AND uid IN (SELECT uid FROM stan_antrag)
			    			                 ORDER BY nachname";
			    			      $result = $db->query ($query)
			    			         or die ("Cannot execute query");
			    			      echo "<select size=\"5\" name=\"user2\">";
			    			      while ($row = $result->fetch_array()){
			                                    echo "<option value=\"".$row[mtknr]."\">$row[nachname], $row[vorname]";
			                                    if ($row[durchgefallen] == "Y"){
			                                      echo " *";
			                                    }
			                                    echo "
			                                    &nbsp;&nbsp;&nbsp;</option>\n";
			    			      }
			    			      echo "</select>";
			    
			      echo "
			      <br>
			      * = inaktiver Bewerber
			      
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      &nbsp;
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"100%\" \" colspan='2' align=\"center\">
			      <input type=\"submit\" value=\"Abschicken\" name=\"B1\"></td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"18\">
			      </td>
			      <td width=\"50%\">
			        &nbsp;
			      </td>

			    </tr>
                            <tr>
                              <td width=\"50%\">
                              </td>
                              <td width=\"50%\" align=\"center\">
                              </td>
                            </tr>
                            <tr>
                              <td width=\"50%\">
                              </td>
                              <td width=\"50%\" align=\"center\">
                                &nbsp;
                              </td>
                            </tr>
			  </table>
			  </form>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
break;
case "ubersicht":


$user = $_POST[user2];

if($_POST[user1] != ''){  // Wenn Matrikelnummer eingegeben, dann prüfen, ob es diese im System gibt

  $user = $_POST[user1]; // vorrangig die Matrikelnr bei Eingabe behandeln

  $result = $db->query("SELECT 1
                           FROM stud
                          WHERE mtknr ='$user1'");
  $row = $result->fetch_array();
  $bewerber = $row[bid];
  
  if($row[0] == ''){
  echo "
  <html>
  <head>
  <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
  <link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
  <title>Falsche Eingabe</title>
  </head>
  <body>
  <table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
     <tr>
         <td>
         <div align=\"center\">
             <table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
                 <tr>
                     <td width=\"10\" background=\"../images/box_e1.gif\">
                     <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                     <td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../images/box_top.gif\" valign=\"top\"></td>
                     <td width=\"95%\" background=\"../images/box_top.gif\">
                     <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                     <span class=\"sh\">Falsche Eingabe</span><br>
                     <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                     <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                     <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                 </tr>
                 <tr>
                     <td width=\"1%\" background=\"../images/box_l.gif\">
                     <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                     <td colspan=\"2\"><br>
                     <p align=\"center\"><b>Die Matrikelnummer ist im System nicht vorhanden</p></b>
                     </p>
                     <p align=\"center\"><a href=\"javascript:history.back()\">
                     <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                     </p>
                     <p></p>
                     <p></p>
                     <p></p>
                     <p></p>
                     <p><br>
                     </p>
                     </td>
                     <td width=\"1%\" background=\"../images/box_r.gif\">
                     <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                 </tr>
                 <tr>
                     <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                     <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                     <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                 </tr>
             </table>
         </div>
         </td>
     </tr>
  </table>
  </body>
  </html>";
  exit;
  }
}

$result = $db->query("SELECT uid
                         FROM stud
                        WHERE mtknr ='$user'");
$row = $result->fetch_array();

$uid = $row[uid];
setcookie("ck_uid","");
setcookie("ck_uid",$uid);


$result1 = $db->query("SELECT anzahl
                         FROM stan_anz_anm
                        WHERE uid ='$uid'");
$row1 = $result1->fetch_array();

if($row1[anzahl] == ''){
 $anzahl = 4;
}else{
 $anzahl = $row1[anzahl];
}


echo "
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Einzel&uuml;bersicht</title>
</head>
<body onload=\"if(document.einzel)document.einzel.anz.focus();return false;\">
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
                <tr>
                    <td width=\"10\" background=\"../images/box_e1.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../images/box_top.gif\" valign=\"top\"></td>
                    <td width=\"95%\" background=\"../images/box_top.gif\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Anzahl Anmeldungen Student</font><br>
                    <font class=\"sh\">Anzahl der Anmeldungen für eine Praxisstelle</font><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
              <form action="; echo $_SERVER['PHP_SELF'] . "?action=ubersicht2"; echo" method=\"POST\" name=\"einzel\">
			  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-width: 0\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"115\">
			    <tr>
			      <td width=\"25%\" height=\"17\">
			      </td>
			      <td width=\"25%\" height=\"17\">&nbsp;</td>
			      <td width=\"25%\" height=\"17\">
			      <p>&nbsp;</p>
			      </td>
			      <td width=\"25%\" height=\"17\">
			      <p></p>
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">&nbsp;</td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        Bitte die Anzahl der Anmeldungen für Praxisstellen eingeben:
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"left\">
                                <input type='text' size='10' name='anz' value='$anzahl'>
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        &nbsp;
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"center\">
                                &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      &nbsp;
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"100%\" \" colspan='2' align=\"center\">
			      <input type=\"submit\" value=\"Abschicken\" name=\"B1\"></td>
			    </tr>
			  </table>
			  </form>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
break;
case "ubersicht2":

$uid=$_COOKIE["ck_uid"];
$anz = $_POST[anz];

if (!(preg_match("/^[0-9]+$/",$anz))) {
echo "
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Eingabefehler</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" border=\"0\">
                <tr>
                    <td width=\"10\" background=\"../images/box_e1.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../images/box_top.gif\" valign=\"top\"></td>
                    <td width=\"95%\" background=\"../images/box_top.gif\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <span class=\"sh\">Eingabefehler</span><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
                    <p align=\"center\"><b>Es muss ein nummerischer Wert eingegeben werden</b>
                    </p>
                    <p align=\"center\"><a href=\"javascript:history.back()\">
                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                    </p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p><br>
                    </p>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
  exit;
}

  
  $sql = $db->query ("DELETE FROM stan_anz_anm WHERE uid = '$uid'");
if ($anz != 4){
  $sql = $db->query ("INSERT INTO stan_anz_anm (uid, anzahl) VALUES ('$uid', $anz)");
}

echo "
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Eingabefehler</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"60%\" border=\"0\">
                <tr>
                    <td width=\"10\" background=\"../images/box_e1.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../images/box_top.gif\" valign=\"top\"></td>
                    <td width=\"95%\" background=\"../images/box_top.gif\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <span class=\"sh\">Eintragung</span><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
                    <p align=\"center\"><b>Die Änderungen wurden vorgenommen</b>
                    </p>
                    <p align=\"center\"><a href=\"hauptframe_jahr.php\">
                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                    </p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p><br>
                    </p>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";

} // Ende Action script
?>