<?php
include("kurs/datenbankanbindung.php");		// f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
#require("func_check_vertiefungsbereich.php");	// Prüft, ob doppelte Vertiefungsbereiche abgegeben werden. 
require("func_pflichtfelder.php");		// Prüft, ob Pflichtfelder ausgefüllt wurden
require("func_vertiefungsbereich.php");		// Prüft, ob vertiefungsbereich gewählt wurde, wenn Stellen erfasst sind.

$db = dbconnect();
$ansp = $db->query("SELECT wert1, wert2 FROM parameter WHERE pid='2'");
$uhd = $ansp->fetch_array();
$ansprechpart = "$uhd[wert1]"; // Ansprechpartner bei Probleme
$helpmail = "$uhd[wert2]";     // Kontaktmailadresse bei Problemen

if ($_COOKIE["uid1"] == ""){ include("kurs/anmeldefehler_subdir.php"); exit;} //Wenn man nicht angemeldet ist soll man nichts ausw&auml;hlen k&ouml;nnen
$uid1=$_COOKIE["uid1"];

require("check_zweig.php");                 // Prüft, ob Innenverwaltung angemeldet ist: setzt datenbankanbindung.php voraus
#
include("kurs/sta/stan_useronline_write.php");     // F&uuml;r Statistik, wieviele User online sind





// &Uuml;Berpr&uuml;fung, ob die Anmeldefrist &uuml;berschritten ist
$heute  = mktime(0, 0, 0, date("m"), date("d"), date("Y"));  // heutiges Datum
$heute_format = date("Y-m-d", $heute);  // ISO-8601 Format wie in der Datenbank: Formatierung f&uuml;r Vergleiche erforderlich

$res = $db->query("SELECT Jahrgang FROM stud WHERE uid=\"$uid1\"");
$stud_jahr = $res->fetch_array();

$anm_schluss = $db->query("SELECT DATE_Format(anmeldebeginn, '%Y-%m-%d')AS beginndatum, DATE_Format(anmeldebeginn, '%d.%m.%Y um %H:%i:%s Uhr')AS beginnform, DATE_Format(anmeldeschluss, '%Y-%m-%d')AS enddatum 
                              FROM stan_frist
                             WHERE jahrgang=\"$stud_jahr[Jahrgang]\"");
$row_schluss = $anm_schluss->fetch_array(); // Herausfinden des Beginn- Schlussdatums

$a = strtotime ($heute_format); //Umrechnung des Fristgrenztages in eine Zahl
$b = strtotime ($row_schluss[enddatum]); // Umrechnung des Enddatums in eine Zahl
$c = strtotime ($row_schluss[beginndatum]); // Umrechnung des Beginndatums in eine Zahl

if ($a < $c){
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>Anmeldungen noch nicht m&ouml;glich!</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\">Anmeldungen noch nicht m&ouml;glich!</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>Antr&auml;ge können erst ab $row_schluss[beginnform] bearbeitet werden!</b>
                    </p>
                    <p align=\"center\"><a href=\"hauptframe.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>";
exit;
} // Ende &Uuml;berpr&uuml;fung der Zeit&uuml;berschreitung

if ($a >= $b){
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>Anmeldezeit vertstrichen</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\">Anmeldezeit vertstrichen</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\">Antr&auml;ge können nicht mehr bearbeitet werden!<br>Es sind nur noch <a href=\"antrag_aend.php\">Änderungsanträge</a> möglich
                    </p>
                    <p align=\"center\"><a href=\"hauptframe.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>";
exit;
} // Ende &Uuml;berpr&uuml;fung der Zeit&uuml;berschreitung


# Wenn Erstanträge abgesendet wurden, dürfen keine Stellen mehr vorgemerkt werden
$res2 = $db->query("SELECT distinct status 
                      FROM stan_antrag
                     WHERE uid='$uid1'
                     LIMIT 1");
$stud_status = $res2->fetch_array();

if($stud_status[status] == '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>Anmeldungen noch nicht m&ouml;glich!</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\">Anmeldungen nicht m&ouml;glich!</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>Sie haben bereits die Erstanträge gespeichert<br>
                    Es sind nur noch Änderungsanträge möglich</b>
                    </p>
                    <p align=\"center\"><a href=\"hauptframe.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>";
exit;
}
#################



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>Anträge bearbeiten</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=\"98%\" background=\"../images/box_top.gif\" valign=\"top\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Anträge bearbeiten</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>";

                        
                    $db = dbconnect();

                    $query = "SELECT distinct vert_bereich
                                FROM stan_antrag t1
                               WHERE t1.status = (
                                                  SELECT MAX(t2.status)
                                                    FROM stan_antrag t2
                                                   WHERE t1.aendid = t2.aendid
                                                  )
                                 AND t1.uid = '$uid1'
                                 AND t1.status = '-1'
                                 AND (t1.zuweisung is NULL OR t1.zuweisung='Z')
                             ";
                             
                    $result = $db->query ($query)
                       or die ("Cannot execute query");

                        while ($row = $result->fetch_array()){


				echo"
                                <table width='100%' bgcolor=#6487DC> 
                                <tr>
                                  <td width='60%' style='border-style: none; border-width: medium' height='0'>
                                  <font color='#FFFFFF'><b>Vertiefungsbereich $i:
                                  ";
                                        $db = dbconnect();
                                
                                
                                          $query1 = $db->query ("SELECT vbid, bezeichnung
                                                                    FROM stan_vertiefungsbereich
                                                                   WHERE vbid = '$row[vert_bereich]'");
                                                   
                                          $row1 = $query1->fetch_array();
                                          
                                          
                                          echo"
                                          $row1[bezeichnung]
                                          </b></font>
                                  </td>
                                </tr>
                                </table>
                                ";
                              $query2 = "SELECT saaid, dst_id, date_format(beginn, '%d.%m.%Y') beginn,date_format(beginn, '%Y%m%d') beginn_form, date_format(ende, '%d.%m.%Y') ende, bearbeitung
                                          FROM stan_antrag
                                         WHERE uid='$uid1'
                                            AND vert_bereich = '$row[vert_bereich]'
                                         ORDER BY beginn_form";
                              $result2 = $db->query ($query2)
                                 or die ("Cannot execute query");

                             while ($row3 = $result2->fetch_array()){
                                
                                $res4 = $db->query("SELECT bez, ort FROM stan_dienststellen WHERE dst_id='$row3[dst_id]'");
                                $row4 = $res4->fetch_array();
                                if($row4[bez] != ''){
                                  $dst_bez = $row4[bez]." ".$row4[name];
                                  $ort = $row4[ort];
                                }else{
                                  $res5 = $db->query("SELECT bez, ort FROM stan_dienststellen_tmp WHERE dst_id='$row3[dst_id]'");
                                  $row5 = $res5->fetch_array();
                                  $dst_bez = $row5[bez]." ".$row5[name];
                                  $ort = $row5[ort];
                                }
                              
                               echo "
                               <table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width=\"100%\" id=\"AutoNumber1\">
                               <tr>
                                 <td width=\"20%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                                   $dst_bez<br>
                                 </td>
                                 <td width=\"40%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                                   $ort
                                 </td>
                                 <td width=\"30%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                                   $row3[beginn] - $row3[ende]
                                 </td>
                                 ";
                                 
                                 if($row3[bearbeitung] == 'N'){
                                 echo"
                                 <td valign=\"middle\" width=\"5%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                                 <p align=\"center\">
                                 
                                       <a href=".$_SERVER['PHP_SELF'] ."?action=bearbeiten&ID=$row3[saaid]>
	                               <img title = \"Antrag bearbeiten\"border=\"0\" src=\"../images/edit.png\"></a>
                                 </td>
                                 <td width=\"5%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                                 <p align=\"center\" style=\"margin-top: 4; margin-bottom: 4\">
                                       <a href=".$_SERVER['PHP_SELF'] ."?action=del&ID=$row3[saaid]>
                                       <img title = \"Antrag l&ouml;schen\"border=\"0\" src=\"../images/drop.png\"></a>
                                 </p>
                                 </td>";
                                 }else{
                                 echo"
                                 <td valign=\"middle\" width=\"5%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                                 <p align=\"center\">
                                   <img title = \"Antrag bearbeiten nicht möglich\"border=\"0\" src=\"../images/edit_grey.png\">
                                 </td>
                                 <td width=\"5%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                                 <p align=\"center\" style=\"margin-top: 4; margin-bottom: 4\">
                                   <img title = \"Antrag l&ouml;schen nicht möglich\"border=\"0\" src=\"../images/drop_grey.png\">
                                 </p>
                                 </td>";
                                 
                                 }
                               echo"
                               </tr>
                               </table>";
                               
                             }
                           
                        }
                    echo "
                    
                    </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\">
                    <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 "bearbeiten":


$staID = $_GET['ID'];
setcookie("ck_staID","");
setcookie("ck_staID",$staID);





$db = dbconnect();


$result3 = $db->query("SELECT vert_bereich
                             , art
                             , dst_id
                             , DATE_Format(beginn, '%d')AS beg_tag
                             , DATE_Format(beginn, '%m')AS beg_mon
                             , DATE_Format(beginn, '%Y')AS beg_jahr
                             , DATE_Format(ende, '%d')AS end_tag
                             , DATE_Format(ende, '%m')AS end_mon
                             , DATE_Format(ende, '%Y')AS end_jahr
                             , abteilung
                             , tel_abteilung
                          FROM stan_antrag
                         WHERE saaid='$staID'");
$row3 = $result3->fetch_array();


$result4 = $db->query("SELECT 1 FROM stan_dienststellen WHERE dst_id = '$row3[dst_id]'");
$row4 = $result4->fetch_array();
if($row4[0] == '1'){
  $result5 = $db->query("SELECT bez
                               , str
                               , plz
                               , postfach
                               , plz_postfach
                               , ort
                               , bundesland
                               , staat
                            FROM stan_dienststellen
                           WHERE dst_id='$row3[dst_id]'");
  $row5 = $result5->fetch_array();
}else{
  $result5 = $db->query("SELECT bez
                               , str
                               , plz
                               , postfach
                               , plz_postfach
                               , ort
                               , bundesland
                               , staat
                            FROM stan_dienststellen_tmp
                           WHERE dst_id='$row3[dst_id]'");
  $row5 = $result5->fetch_array();
}

$bezeichnung = $row5[bez];
$str = $row5[str];
$plz = $row5[plz];
$postfach = $row5[postfach];
$plz_postfach = $row5[plz_postfach];
$ort = $row5[ort];
$bundesland = $row5[bundesland];
$staat = $row5[staat];


$db = dbconnect();
$result = $db->query("SELECT nachname, vorname, jahrgang, stg FROM stud where uid=\"$uid1\"");
$row = $result->fetch_array();

$anm_schluss = $db->query("SELECT DATE_Format(anmeldeschluss, '%d.%m.%Y um %H:%i:%s Uhr') anmeldeschluss, DATE_Format(antrag_von, '%d.%m.%Y') antrag_von, DATE_Format(antrag_bis, '%d.%m.%Y') antrag_bis
                              FROM stan_frist
                             WHERE jahrgang='$row[jahrgang]'");
$row_schluss = $anm_schluss->fetch_array(); // Auslesen des Datenbankdatum, um davon ein Tag abziehen zu k&ouml;nnen



echo"
<html>
<head>

<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
	<script type=\"text/javascript\" src=\"livesearch/ajax.js\"></script>
	<script type=\"text/javascript\" src=\"livesearch/ajax-dynamic-list.js\">
	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, April 2006

	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.

	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.

	Thank you!

	www.dhtmlgoodies.com
	Alf Magne Kalleland

	************************************************************************************************************/
	</script>
	
	

	<style type=\"text/css\">
select{
	width:325px;
}



	/* Big box with list of options */
	#ajax_listOfOptions{
		position:absolute;	/* Never change this one */
		width:324px;	/* Width of box */
		height:200px;	/* Height of box */
		overflow:auto;	/* Scrolling features */
		border:1px solid #6487DC;	/* Dark blue border */
		background-color:#FFF;	/* White background color */
		text-align:left;
		font-family		:	verdana, arial;
		z-index:10000;
	}
	#ajax_listOfOptions div{	/* General rule for both .optionDiv and .optionDivSelected */
		margin:1px;
		padding:1px;
		cursor:pointer;
		font-size:0.9em;
	}
	#ajax_listOfOptions .optionDiv{	/* Div for each item in list */

	}
	#ajax_listOfOptions .optionDivSelected{ /* Selected item in the list */
		background-color:#D6DFF7;
		color:#002276;
		font-family		:	verdana, arial;
		font-weight		:	bold;
	}
	#ajax_listOfOptions_iframe{
		background-color:#F00;
		position:absolute;
		z-index:500;
	}

	form{
		display:inline;
	}

	</style>

	
	
</head>
<body>






			<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=\"98%\" background=\"../images/box_top.gif\" valign=\"top\">
                                        <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                                        <font class=\"hd\">Stellenantrag für $row[vorname] $row[nachname]</font><br>
                                        <span class='sh'>Anträge können bis zum <font color='red'><b>$row_schluss[0]</b></font> abgegeben werden<br>
                                        Antragszeitraum: <font color='red'><b>$row_schluss[antrag_von] - $row_schluss[antrag_bis]</b></font>
                                        </span>
                                        <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></font></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>

<form action="; echo $_SERVER['PHP_SELF'] . "?action=persdat"; echo" method=\"POST\" name='searchform'>
<table width='100%' bgcolor=#6487DC> 
<tr>
  <td width='60%' style='border-style: none; border-width: medium' height='0'>
  <font color='#FFFFFF'><b>Vertiefungsbereich: 
  ";
        $db = dbconnect();


                                          $query1 = $db->query ("SELECT vbid, bezeichnung
                                                                    FROM stan_vertiefungsbereich
                                                                   WHERE vbid = '$row3[vert_bereich]'");
                                                   
                                          $row1 = $query1->fetch_array();
                                          
                                          
                                          echo"
                                          $row1[bezeichnung]</b></font>

  </td>
</tr>
</table>

        <table cellspacing='0' style='width:100%;'>
          <tr>
            <td width='10%' style='border-style: none; border-width: medium' height='0'>
              &nbsp;
            </td>
            <td width='30%' style='border-style: none; border-width: medium' height='0'>
              <b>Art der Praxisstelle*</b>
            </td>
            <td width='60%' style='border-style: none; border-width: medium' height='0'>";
            $db = dbconnect();
            
            
    
              $query1 = "SELECT artid, bezeichnung
                          FROM stan_stellenart
                         ORDER BY artid ASC
                       ";
                       
              $result1 = $db->query ($query1)
                 or die ("Cannot execute query");
              echo "<select size=\"5\" name=\"stellenart\" id='stellenart'>";
              while ($row1 = $result1->fetch_array()){
              echo "<option value='$row1[artid]'";if($row1[artid] == $row3[art]){echo "selected";} echo">$row1[bezeichnung]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>\n";
              }
              
              echo"
            </td>
          </tr>
          <tr>
            <td width='10%' style='border-style: none; border-width: medium' height='0'>
              &nbsp;
            </td>
            <td width='30%' style='border-style: none; border-width: medium' height='0'>
              <b>Bezeichnung der Praxisstelle*:</b>
            </td>
          <td width='60%' style='border-style: none; border-width: medium' height='0'>
            <!--<input type='text' name='bezeichnung'id='bezeichnung' size='50'>-->
  				<input type=\"text\" id=\"bezeichnung\" name=\"bezeichnung\" value=\"$bezeichnung\" onkeyup=\"ajax_showOptions(this,'getStadt',event,'')\" size=\"50\">
  				<input type=\"hidden\" id=\"bezeichnung_hidden\" name=\"bezeichnung_ID\"><!-- THE ID OF the textstelle will be inserted into this hidden input -->
  	               
          </td>
          </tr>
          <tr>
            <td width='10%' style='border-style: none; border-width: medium' height='0'>
              &nbsp;
            </td>
            <td width='30%' style='border-style: none; border-width: medium' height='0'>
              <b>Straße und Hausnummer der Praxisstelle*:</b>
            </td>
            <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
              <input type='text' id='str' name='str' value='$str' size='50'>
            </td>
          </tr>
          <tr>
            <td width='10%' style='border-style: none; border-width: medium' height='0'>
              &nbsp;
            </td>
            <td width='30%' style='border-style: none; border-width: medium' height='0'>
              <b>PLZ Ort*:</b>
            </td>
            <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
              <input type='text' name='plz' id='plz' size='5' value='$plz'>&nbsp;<input type='text' name='ort' id='ort' size='40' value='$ort'>
            </td>
          </tr>
          <tr>
            <td width='10%' style='border-style: none; border-width: medium' height='0'>
              &nbsp;
            </td>
            <td width='30%' style='border-style: none; border-width: medium' height='0'>
              <b>PLZ Postfach:</b>
            </td>
            <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
              <input type='text' name='plz_postfach' id='plz_postfach' size='5' value='$plz_postfach'>&nbsp;<input type='text' name='postfach' id='postfach' size='40' value='$postfach'>
            </td>
          </tr>
          <tr>
            <td width='10%' style='border-style: none; border-width: medium' height='0'>
              &nbsp;
            </td>
            <td width='30%' style='border-style: none; border-width: medium' height='0'>
              <b>Bundesland*:</b>
            </td>
            <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
              <input type='text' name='bundesland' id='bundesland' size='50' value='$bundesland'>
            </td>
          </tr>
          <tr>
            <td width='10%' style='border-style: none; border-width: medium' height='0'>
              &nbsp;
            </td>
            <td width='30%' style='border-style: none; border-width: medium' height='0'>
              <b>Staat*:</b>
            </td>
            <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
              <input type='text' name='staat' id='staat' size='50' value='$staat'>
            </td>
          </tr>
            <td width='10%' style='border-style: none; border-width: medium' height='0'>
              &nbsp;
            </td>
            <td width='30%' style='border-style: none; border-width: medium' height='0'>
             <b>Zeitraum der bei dieser Praxisstelle*: </b> 
            </td>
            <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
             <input type=\"text\" name=\"beg_tag\" id='beg_tag' size=\"1\" value='$row3[beg_tag]' onFocus=\"if(this.value=='TT'){ this.value='';}\">.<input type=\"text\" name=\"beg_mon\" id='beg_mon' value='$row3[beg_mon]' ID=\"text1\" size=\"1\" onFocus=\"if(this.value=='MM'){ this.value='';}\">.<input type=\"text\" name='beg_jahr' id='beg_jahr' ID=\"text1\" value='$row3[beg_jahr]' size=\"3\" onFocus=\"if(this.value=='JJJJ'){ this.value='';}\">
             bis
             <input type=\"text\" name=\"ende_tag\" id='ende_tag' ID=\"text\" size=\"1\" value='$row3[end_tag]' onFocus=\"if(this.value=='TT'){ this.value='';}\">.<input type=\"text\" name=\"ende_mon\" id='ende_mon' value='$row3[end_mon]' ID=\"text1\" size=\"1\" onFocus=\"if(this.value=='MM'){ this.value='';}\">.<input type=\"text\" name=\"ende_jahr\" id='ende_jahr' ID=\"text1\" value='$row3[end_jahr]' size=\"3\" onFocus=\"if(this.value=='JJJJ'){ this.value='';}\">
            </td>
          </tr>
        <tr>
          <td width='10%' style='border-style: none; border-width: medium' height='0'>
            &nbsp;
          </td>
          <td width='30%' style='border-style: none; border-width: medium' height='0'>
            <b>Abteilung:</b>
          </td>
          <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
            <input type='text' name='abteilung' id='abteilung' size='50' value='$row3[abteilung]'>
          </td>
        </tr>
        <tr>
          <td width='10%' style='border-style: none; border-width: medium' height='0'>
            &nbsp;
          </td>
          <td width='30%' style='border-style: none; border-width: medium' height='0'>
            <b>Tel. der Abteilung:</b>
          </td>
          <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
            <input type='text' name='telabteilung' id='telabteilung' size='50' value='$row3[tel_abteilung]'>
          </td>
        </tr>
          </table>
        <br>";
echo"
 <br>
 * = Pflichtfelder<br><br>
      <input type=\"submit\" value=\"Abschicken\" name=\"B1\" size=\"20\">
  </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'>
					<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 "persdat":
$staID = $_COOKIE['ck_staID'];
### doppelte Vertiefungsbereiche prüfen ###
#  check_vertiefungsbereich();
### Ende doppelte Vertiefungsbereiche prüfen ###


### Prüft, ob vertiefungsbereich gewählt wurde###
#  vertiefungsbereich();
### Ende, ob vertiefungsbereich gewählt wurde###


### Pflichtfelder prüfen ###
#  pflichtfelder();
### Ende Pflichtfelder prüfen ###


$db = dbconnect();

$result3 = $db->query("SELECT vert_bereich
                          FROM stan_antrag
                         WHERE saaid='$staID'");
$row3 = $result3->fetch_array();

$vertiefungsbereich =$row3[vert_bereich];
$stellenart	= $_POST[stellenart]; // Vom Formular gesendetes Objekt in Variable schreiben
$bezeichnung	= $_POST[bezeichnung];
$str		= $_POST[str];
$postfach	= $_POST[postfach];
$plz_postfach	= $_POST[plz_postfach];
$plz		= $_POST[plz];
$ort		= $_POST[ort];
$bundesland	= $_POST[bundesland];
$staat		= $_POST[staat];
$beginndatum	= $_POST[beg_jahr].'-'.$_POST[beg_mon].'-'.$_POST[beg_tag];
$enddatum	= $_POST[ende_jahr].'-'.$_POST[ende_mon].'-'.$_POST[ende_tag];
$abteilung	= $_POST[abteilung];
$telabteilung	= $_POST[telabteilung];

if($bezeichnung == '' OR $str == '' OR $plz == '' OR $ort == '' OR $bundesland == '' OR $staat == '' OR $beginndatum == 'JJJJ-MM-TT' OR $beginndatum == '--' OR $enddatum == 'JJJJ-MM-TT' OR $enddatum == '--'){
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>Anmeldung[]en noch nicht m&ouml;glich!</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=\"80%\" 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\">Pflichtfelder!</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>
                      Es wurden nicht alle Pflichtfelder ausgefüllt!<br>
                    <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;
}
    
    ## Dienstellen prüfen, ob es eine eigeneist, oder ob sie aus der Datenbank übernommen wurde.  
    $res = $db->query("SELECT dst_id FROM stan_dienststellen WHERE bez='$bezeichnung' AND str='$str' AND plz='$plz' AND ort='$ort' AND postfach='$postfach' AND plz_postfach='$plz_postfach'");
    $row_key = $res->fetch_array();

    ## Entweder es gibt zur DSTS einen Schlüssel, oder es wird einer angelegt und DS in tmp Tabelle gespeichert, bis Admin sie umträgt
    if($row_key[dst_id]  == ''){
      $res2 = $db->query("SELECT dst_id FROM stan_dienststellen_tmp WHERE bez='$bezeichnung' AND str='$str' AND plz='$plz' AND ort='$ort' AND postfach='$postfach' AND plz_postfach='$plz_postfach'");
      $row_key2 = $res2->fetch_array();
      
      if($row_key2[dst_id] == ''){
        ## Herausfinden, welches die max Dienststellen ID ist. Simulation einer Sequence
        $res1 = $db->query("SELECT max(dst_id)+1 next FROM stan_dienststellen");
        $row_next1 = $res1->fetch_array();
        
        $res2 = $db->query("SELECT max(dst_id)+1 next FROM stan_dienststellen_tmp");
        $row_next2 = $res2->fetch_array();
        
        if($row_next1[next] >= $row_next2[next]){
          $dst_id = $row_next1[next];
        }else{
          $dst_id = $row_next2[next];
        }
              
        $db = dbconnect();
        $res_stellanrt = $db->query("SELECT Merkmal
                                        FROM stan_stellenart
                                       WHERE artid='$stellenart'
                                    ");    
        $row_art = $res_stellanrt->fetch_array();
        
        if($row_art[Merkmal] == 'A' AND $bezeichnung == ''){ //wenn Textfelder bei Auslandspraktikum leer gelassen werden, dann wird 0 als dst_id eingetragen. Dies geht nur mit bei Ausland (StellenartID=6)
          $dst_id = 0;
        }
              
              
        $sql = $db->query ("INSERT INTO stan_dienststellen_tmp (dst_id, bez, str, plz_postfach, postfach, plz, ort, bundesland, staat) 
                             VALUES ($dst_id, '$bezeichnung', '$str', '$plz_postfach', '$postfach', '$plz', '$ort', '$bundesland', '$staat')");

        if($row_art[Merkmal] == 'A' AND $bezeichnung == ''){ //Wenn Auslandspraktikum leer gelassen wird, soll nicht ein leerer Ort in die tmp Tabelle eingetragen werden.
          $result_tmp1 = $db->query("DELETE FROM stan_dienststellen_tmp WHERE dst_id='$dst_id'");
        }
        
                             
      }else{
        $dst_id = $row_key2[dst_id];  // wenn adresse in tmp Tabelle vorhanden ist.
      }
    }else{
      $dst_id = $row_key[dst_id];  // wenn adresse in dst Tabelle vorhanden ist.
    }


##### Vertiefungsbereich muss zuvor als Cookie abgespeichert werden.


    $sql = $db->query ("DELETE FROM stan_antrag WHERE saaid='$staID' AND status = '-1'");

    $sql = $db->query ("INSERT INTO stan_antrag (uid, vert_bereich, art, dst_id, beginn, ende, abteilung, tel_abteilung, status, zuweisung
                                               ) VALUES (
                                                 '$uid1', '$vertiefungsbereich', '$stellenart', '$dst_id', '$beginndatum', '$enddatum', '$abteilung'
                                               , '$telabteilung','-1', Null)");
    $aendid = $db->insert_id;
    $sql1 = $db->query ("update stan_antrag set aendid='$aendid' where saaid = '$aendid'");
    
    
    if($sql){
      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>Antrag nicht gestellt</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\">Antrag gestellt</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>Der Antrag wurde erfasst!</b>
                        </p>
                        <p align=\"center\"><a href=".$_SERVER['PHP_SELF'] .">
                        <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>
      ";
    }else{
      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>Antrag nicht gestellt</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\">Antrag nicht gestellt</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>Der Antrag konnte aufgrund eines Fehlers nicht erfasst werden!</b>
                        <br>
                        </p>
                        <p align=\"center\"><a href=".$_SERVER['PHP_SELF'] .">
                        <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>";
    }
  


break;
Case "del":

$staID = $_GET['ID'];
setcookie("ck_staID","");
setcookie("ck_staID",$staID);


$res6 = $db->query("SELECT dst_id FROM stan_antrag WHERE saaid='$staID'");
$row6 = $res6->fetch_array();

$res = $db->query("SELECT ort FROM stan_dienststellen WHERE dst_id='$row6[dst_id]'");
$row = $res->fetch_array();

if($row[ort] == ''){ // wenn nicht in der DST-Tabelle, dann in tmp schauen...
  $res = $db->query("SELECT ort FROM stan_dienststellen_tmp WHERE dst_id='$row6[dst_id]'");
  $row = $res->fetch_array();
}


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>Datensatz l&ouml;schen</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=\"70%\" 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=\"98%\" background=\"../images/box_top.gif\" valign=\"top\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Datensatz l&ouml;schen</font><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></font></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>
                    <table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width=\"100%\" id=\"AutoNumber1\">
                    <tr>
                      <td width=\"100%\">
                        <p align=\"center\">
                        M&ouml;chten sie den Antrag<br><b>$row[ort]</b><br>wirklich löschen?<br><br>
                            <a href=".$_SERVER['PHP_SELF'] ."?action=del3>
	                    <img title = \"Abbrechen\"border=\"0\" src=\"../images/nein.gif\"></a>
	                     &nbsp;
                            <a href=".$_SERVER['PHP_SELF'] ."?action=del2>
	                    <img title = \"Antrag l&ouml;schen\"border=\"0\" src=\"../images/ja.gif\"></a>
                      </td>
                      </tr>
                    </table>
                    </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\">
                    <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 "del2":

$saaid = $_COOKIE['ck_staID'];

//Nochmals &uuml;berpr&uuml;fen, ob L&ouml;schung noch zul&auml;ssig ist! Falls jemand die Seite vor Fristablauf schon ge&ouml;ffnet hat
$heute_format = date("Y-m-d H:i:s",time());
$anm_schluss = $db->query("SELECT DATE_Format(anmeldeschluss, '%Y-%m-%d %H:%i:%s')AS Anmeldeschluss
                              FROM stan_frist , stud
                             WHERE stan_frist.jahrgang = stud.jahrgang
                               AND stud.uid = '$uid1'");
$row_schluss = $anm_schluss->fetch_array(); // Herausfinden der Anmeldefrist des vom Studenten gew&auml;hlten Kurses
$a = strtotime ($heute_format); //Umrechnung des Fristgrenztages in eine Zahl
$b = strtotime ($row_schluss[Anmeldeschluss]); // Umrechnung des Enddatums in eine Zahl

if($a>=$b)
{
  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>L&ouml;schrist abgelaufen</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\">L&ouml;schrist abgelaufen</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>Eine L&ouml;schung f&uuml;r diese Veranstaltung ist nicht mehr m&ouml;glich</b>
                      </p>
                      <p align=\"center\"><a href=\"hauptframe.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>";
  exit;
}

$sql = $db->query ("DELETE FROM stan_antrag WHERE saaid='$saaid'");

if ($sql)  // Best&auml;tigungsseite bei Erfolg sonst Nichterfolgsmeldung
  {
    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>Datensatz gelöscht</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\">Datensatz gelöscht</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>Der Datensatz wurde gelöscht!</b>
                      </p>
                      <p align=\"center\"><a href=\"hauptframe.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>";
  }else{
    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>unerwarteter Fehler</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\">unerwarteter Fehler</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 ist ein interner Fehler aufgetreten!<br>
                      Wenden Sie sich bitte umgehend an
                      <a href=\"mailto:$_POST[helpmail]?subject=Fehler bei der Antragsbearbeitung im Stellenatragssystem\">$_POST[ansprechpart]</a></b>
                      </p>
                      <p align=\"center\"><a href=\"hauptframe.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>";
  }

break;
case "del3":

$Link = basename($_SERVER['PHP_SELF']);
echo "
  <meta http-equiv=\"refresh\" content=\"0; URL=$Link\">
";
 
}
?>