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

$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
#require("check_weitere_daten.php");
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(anmeldeschluss, '%d.%m.%Y um %H:%i:%s Uhr')AS endeform, 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


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>Änderungsanträge nicht mö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\">Änderungsanträge nicht mö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\">&Auml;nderungsantr&auml;ge können erst<br><b>nach Anmeldeschluss</b><br>abgegeben werden!<br>
                                       <br>Sie können bis zum $row_schluss[endeform]<br>Anträge <a href=\"antrag.php\">abgeben</a> bzw <a href=\"bearbeiten.php\">bearbeiten</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>";
exit;
} // Ende &Uuml;berpr&uuml;fung der Zeit&uuml;berschreitung

#################



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>Änderungsantrag</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\">Änderungsantrag</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 = '0'
                                 AND (t1.zuweisung is NULL OR t1.zuweisung='Z')
                               ORDER BY saaid ASC
                             ";
                             
                    $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:</b></font>
                                  ";
                                        $db = dbconnect();
                                
                                
                                          $query1 = "SELECT vbid, bezeichnung
                                                      FROM stan_vertiefungsbereich
                                                     ORDER BY bezeichnung ASC
                                                   ";
                                                   
                                          $result1 = $db->query ($query1)
                                             or die ("Cannot execute query");
                                          echo "<select size=\"1\" name=\"vert$i\">
                                          <option value='x'>Bitte wählen Sie ein Vertiefungsbereich&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
                                          while ($row1 = $result1->fetch_array()){
                                          
                                          echo "<option value='$row1[vbid]'";if($row1[vbid] == $row[vert_bereich]){ echo " selected ";} echo">$row1[bezeichnung]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>\n";
                                          }
                                          echo"
                                  </td>
                                </tr>
                                </table>
                                ";
                              $query2 = "SELECT saaid, dst_id, date_format(beginn, '%d.%m.%Y') beginn, date_format(ende, '%d.%m.%Y') ende, bearbeitung
                                          FROM stan_antrag
                                         WHERE uid='$uid1'
                                            AND vert_bereich = '$row[vert_bereich]'
                                         ORDER BY saaid";
                              $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'];

if($staID == ''){
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>Auswahl treffen</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\">Auswahl treffen</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 müssen eine Praxisstelle wählen,<br>
                    für die Sie einen Änderungsantrag stellen wollen!</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>";
exit;
}


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>

        <script type=\"text/javascript\">
          function start(){

            document.getElementById('DivName3').style.display='none';
            document.getElementById('DivName6').style.display='none';
            document.getElementById('DivName9').style.display='none';
            document.getElementById('DivName12').style.display='none';
            if(document.getElementById('stellenart2').value != '1'){ splitt1('stell2', 'DivName2', '2');}
            if(document.getElementById('stellenart3').value != '1'){document.getElementById('DivName3').style.display='block';splitt1('stell3', 'DivName3', '3');}
            if(document.getElementById('stellenart5').value != '1'){splitt2('stell5', 'DivName5', '5');}
            if(document.getElementById('stellenart6').value != '1'){document.getElementById('DivName6').style.display='block';splitt2('stell6', 'DivName6', '6');}
            if(document.getElementById('stellenart8').value != '1'){splitt3('stell8', 'DivName8', '8');}
            if(document.getElementById('stellenart9').value != '1'){document.getElementById('DivName9').style.display='block';splitt3('stell9', 'DivName9', '9');}
            if(document.getElementById('stellenart11').value != '1'){splitt4('stell11', 'DivName11', '11');}
            if(document.getElementById('stellenart12').value != '1'){document.getElementById('DivName12').style.display='block';splitt4('stell12', 'DivName12', '12');}
	    
	    // beim Seitenload pro Vertiefungsbereich den zweiten Splitt-Button ausblenden
	    // If Abfragen dienen dazu, wenn nach dem Absenden wieder zurück geklickt wird,
	    // dann wird geprüft, ob in den gesplitteten Zeiträumen eine Stellenart ausgewählt wurde.
	    // Wenn ja, wird der sonst(beim Seitenladen) ausgeblendete splittbereich eingeblendet und der ggf. Splittbutton angezeigt.
	  }
	</script>	
	
</head>
<body onload=\"start();\">




<script type=\"text/javascript\" language=\"JavaScript\">
<!--
function splitt1(a, b, c){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display==\"none\"){
    e.style.display=\"block\"
    document.getElementById(b).innerHTML='<table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>löschen</b></font></td></tr></table>';
    if(b == 'DivName2'){
     document.getElementById('DivName3').style.display='block';
    }
  } else {
    e.style.display=\"none\"
    document.getElementById(b).innerHTML='<table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>splitten</b></font></td></tr></table>';
    document.getElementById('stellenart'+c).selectedIndex = 0;
    document.getElementById('str'+c).value = '';
    document.getElementById('bezeichnung'+c).value = '';
    document.getElementById('postfach'+c).value = '';
    document.getElementById('plz_postfach'+c).value = '';
    document.getElementById('plz'+c).value = '';
    document.getElementById('ort'+c).value = '';
    document.getElementById('bundesland'+c).value = '';
    document.getElementById('staat'+c).value = '';
    document.getElementById('beg_tag'+c).value = '';
    document.getElementById('beg_mon'+c).value = '';
    document.getElementById('beg_jahr'+c).value = '';
    document.getElementById('ende_tag'+c).value = '';
    document.getElementById('ende_mon'+c).value = '';
    document.getElementById('ende_jahr'+c).value = '';
    document.getElementById('abteilung'+c).value = '';
    document.getElementById('telabteilung'+c).value = '';
    
  }
  return true;
}



function splitt2(a, b, c){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display==\"none\"){
    e.style.display=\"block\"
    document.getElementById(b).innerHTML='<table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>löschen</b></font></td></tr></table>';
    if(b == 'DivName5'){
     document.getElementById('DivName6').style.display='block';
    }
  } else {
    e.style.display=\"none\"
    document.getElementById(b).innerHTML='<table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>splitten</b></font></td></tr></table>';
    document.getElementById('stellenart'+c).selectedIndex = 0;
    document.getElementById('str'+c).value = '';
    document.getElementById('bezeichnung'+c).value = '';
    document.getElementById('postfach'+c).value = '';
    document.getElementById('plz_postfach'+c).value = '';
    document.getElementById('plz'+c).value = '';
    document.getElementById('ort'+c).value = '';
    document.getElementById('bundesland'+c).value = '';
    document.getElementById('staat'+c).value = '';
    document.getElementById('beg_tag'+c).value = '';
    document.getElementById('beg_mon'+c).value = '';
    document.getElementById('beg_jahr'+c).value = '';
    document.getElementById('ende_tag'+c).value = '';
    document.getElementById('ende_mon'+c).value = '';
    document.getElementById('ende_jahr'+c).value = '';
    document.getElementById('abteilung'+c).value = '';
    document.getElementById('telabteilung'+c).value = '';
    
  }
  return true;
}


function splitt3(a, b, c){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display==\"none\"){
    e.style.display=\"block\"
    document.getElementById(b).innerHTML='<table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>löschen</b></font></td></tr></table>';
    if(b == 'DivName8'){
     document.getElementById('DivName9').style.display='block';
    }
  } else {
    e.style.display=\"none\"
    document.getElementById(b).innerHTML='<table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>splitten</b></font></td></tr></table>';
    document.getElementById('stellenart'+c).selectedIndex = 0;
    document.getElementById('str'+c).value = '';
    document.getElementById('bezeichnung'+c).value = '';
    document.getElementById('postfach'+c).value = '';
    document.getElementById('plz_postfach'+c).value = '';
    document.getElementById('plz'+c).value = '';
    document.getElementById('ort'+c).value = '';
    document.getElementById('bundesland'+c).value = '';
    document.getElementById('staat'+c).value = '';
    document.getElementById('beg_tag'+c).value = '';
    document.getElementById('beg_mon'+c).value = '';
    document.getElementById('beg_jahr'+c).value = '';
    document.getElementById('ende_tag'+c).value = '';
    document.getElementById('ende_mon'+c).value = '';
    document.getElementById('ende_jahr'+c).value = '';
    document.getElementById('abteilung'+c).value = '';
    document.getElementById('telabteilung'+c).value = '';
    
  }
  return true;
}



function splitt4(a, b, c){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display==\"none\"){
    e.style.display=\"block\"
    document.getElementById(b).innerHTML='<table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>löschen</b></font></td></tr></table>';
    if(b == 'DivName11'){
     document.getElementById('DivName12').style.display='block';
    }
  } else {
    e.style.display=\"none\"
    document.getElementById(b).innerHTML='<table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>splitten</b></font></td></tr></table>';
    document.getElementById('stellenart'+c).selectedIndex = 0;
    document.getElementById('str'+c).value = '';
    document.getElementById('bezeichnung'+c).value = '';
    document.getElementById('postfach'+c).value = '';
    document.getElementById('plz_postfach'+c).value = '';
    document.getElementById('plz'+c).value = '';
    document.getElementById('ort'+c).value = '';
    document.getElementById('bundesland'+c).value = '';
    document.getElementById('staat'+c).value = '';
    document.getElementById('beg_tag'+c).value = '';
    document.getElementById('beg_mon'+c).value = '';
    document.getElementById('beg_jahr'+c).value = '';
    document.getElementById('ende_tag'+c).value = '';
    document.getElementById('ende_mon'+c).value = '';
    document.getElementById('ende_jahr'+c).value = '';
    document.getElementById('abteilung'+c).value = '';
    document.getElementById('telabteilung'+c).value = '';
    
  }
  return true;
}

//-->
</script>


			<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=antrag"; echo" method=\"POST\" name='searchform'>";
for ($i= 1;$i<= 1;$i++)  // 1 Vertiefungsbereiche, daher 1 mal die Schleife
{
$j = $j+1;  // läuft dann von 1 bis 12
echo"
<table width='100%' bgcolor=#6487DC> 
<tr>
  <td width='60%' style='border-style: none; border-width: medium' height='0'>
  <font color='#FFFFFF'><b>Vertiefungsbereich:</b></font>
  ";
        $db = dbconnect();


          $query1 = "SELECT vbid, bezeichnung
                      FROM stan_vertiefungsbereich
                     ORDER BY bezeichnung ASC
                   ";
                   
          $result1 = $db->query ($query1)
             or die ("Cannot execute query");
          echo "<select size=\"1\" name=\"vert$i\">
          <option value='x'>Bitte wählen Sie ein Vertiefungsbereich&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
          while ($row1 = $result1->fetch_array()){
          
          echo "<option value='$row1[vbid]'";if($row1[vbid] == $row3[vert_bereich]){echo "selected";} echo">$row1[bezeichnung]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>\n";
          }
          echo"
  </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$j\" id='stellenart$j'>";
              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$j'id='bezeichnung$j' size='50'>-->
  				<input type=\"text\" id=\"bezeichnung$j\" name=\"bezeichnung$j\" value=\"$bezeichnung\" onkeyup=\"ajax_showOptions(this,'getStadt',event,$j)\" size=\"50\">
  				<input type=\"hidden\" id=\"bezeichnung_hidden$j\" name=\"bezeichnung_ID$j\"><!-- 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$j' name='str$j' 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$j' id='plz$j' size='5' value='$plz'>&nbsp;<input type='text' name='ort$j' id='ort$j' 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$j' id='plz_postfach$j' size='5' value='$plz_postfach'>&nbsp;<input type='text' name='postfach$j' id='postfach$j' 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$j' id='bundesland$j' 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$j' id='staat$j' 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$j\" id='beg_tag$j' size=\"1\" value='$row3[beg_tag]' onFocus=\"if(this.value=='TT'){ this.value='';}\">.<input type=\"text\" name=\"beg_mon$j\" id='beg_mon$j' value='$row3[beg_mon]' ID=\"text1\" size=\"1\" onFocus=\"if(this.value=='MM'){ this.value='';}\">.<input type=\"text\" name='beg_jahr$j' id='beg_jahr$j' ID=\"text1\" value='$row3[beg_jahr]' size=\"3\" onFocus=\"if(this.value=='JJJJ'){ this.value='';}\">
             bis
             <input type=\"text\" name=\"ende_tag$j\" id='ende_tag$j' ID=\"text\" size=\"1\" value='$row3[end_tag]' onFocus=\"if(this.value=='TT'){ this.value='';}\">.<input type=\"text\" name=\"ende_mon$j\" id='ende_mon$j' value='$row3[end_mon]' ID=\"text1\" size=\"1\" onFocus=\"if(this.value=='MM'){ this.value='';}\">.<input type=\"text\" name=\"ende_jahr$j\" id='ende_jahr$j' 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$j' id='abteilung$j' 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$j' id='telabteilung$j' size='50' value='$row3[tel_abteilung]'>
          </td>
        </tr>
          </table>
        <br>";
$j = $j + 1;
echo"
<p align=right>
<a onclick=\"return splitt$i('stell$j', 'DivName$j', '$j')\" href=\"javascript:void(0)\"><div id='DivName$j' onMouseOver=\"this.style.cursor='hand'\"><table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>splitten</b></font></td></tr></table></div></a>
</p>
  <div id=\"stell$j\" style=\"display: none;\">
  
        <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$j\" id='stellenart$j'>";
              while ($row1 = $result1->fetch_array()){
              echo "<option value='$row1[artid]'";if($row1[artid] == 1){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$j'id='bezeichnung$j' size='50'>-->
  				<input type=\"text\" id=\"bezeichnung$j\" name=\"bezeichnung$j\" value=\"\" onkeyup=\"ajax_showOptions(this,'getStadt',event,$j)\" size=\"50\">
  				<input type=\"hidden\" id=\"bezeichnung_hidden$j\" name=\"bezeichnung_ID$j\"><!-- 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$j' name='str$j' 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$j' id='plz$j' size='5'>&nbsp;<input type='text' name='ort$j' id='ort$j' size='40'>
            </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$j' id='plz_postfach$j' size='5'>&nbsp;<input type='text' name='postfach$j' id='postfach$j' size='40'>
            </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$j' id='bundesland$j' 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>Staat*:</b>
            </td>
            <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
              <input type='text' name='staat$j' id='staat$j' size='50'>
            </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$j\" id='beg_tag$j' ID=\"text\" size=\"1\" value='TT' onFocus=\"if(this.value=='TT'){ this.value='';}\">.<input type=\"text\" name=\"beg_mon$j\" id='beg_mon$j' value='MM' ID=\"text1\" size=\"1\" onFocus=\"if(this.value=='MM'){ this.value='';}\">.<input type=\"text\" name='beg_jahr$j' id='beg_jahr$j' ID=\"text2\" value='JJJJ' size=\"3\" onFocus=\"if(this.value=='JJJJ'){ this.value='';}\">
             bis
             <input type=\"text\" name=\"ende_tag$j\" id='ende_tag$j' ID=\"text\" size=\"1\" value='TT' onFocus=\"if(this.value=='TT'){ this.value='';}\">.<input type=\"text\" name=\"ende_mon$j\" id='ende_mon$j' value='MM' ID=\"text1\" size=\"1\" onFocus=\"if(this.value=='MM'){ this.value='';}\">.<input type=\"text\" name=\"ende_jahr$j\" id='ende_jahr$j' ID=\"text2\" value='JJJJ' 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$j' id='abteilung$j' 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>Tel. der Abteilung:</b>
          </td>
          <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
            <input type='text' name='telabteilung$j' id='telabteilung$j' size='50'>
          </td>
        </tr>
          </table>
        <br>
  </div>


<br><br>";
$j = $j + 1;
echo"
<p align=right>
<a onclick=\"return splitt$i('stell$j', 'DivName$j', '$j')\" href=\"javascript:void(0)\"><div id='DivName$j' onMouseOver=\"this.style.cursor='hand'\"><table width=10% bgcolor=#6487DC><tr><td onMouseOver=\"this.style.cursor=\"hand\";\" align=center><font color=\"#FFFFFF\"><b>splitten</b></font></td></tr></table></div></a>
</p>
  <div id=\"stell$j\" style=\"display: none;\">
        <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$j\" id='stellenart$j'>";
              while ($row1 = $result1->fetch_array()){
              echo "<option value='$row1[artid]'";if($row1[artid] == 1){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$j'id='bezeichnung$j' size='50'>-->
  				<input type=\"text\" id=\"bezeichnung$j\" name=\"bezeichnung$j\" value=\"\" onkeyup=\"ajax_showOptions(this,'getStadt',event,$j)\" size=\"50\">
  				<input type=\"hidden\" id=\"bezeichnung_hidden$j\" name=\"bezeichnung_ID$j\"><!-- 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$j' name='str$j' 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$j' id='plz$j' size='5'>&nbsp;<input type='text' name='ort$j' id='ort$j' size='40'>
            </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$j' id='plz_postfach$j' size='5'>&nbsp;<input type='text' name='postfach$j' id='postfach$j' size='40'>
            </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$j' id='bundesland$j' 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>Staat*:</b>
            </td>
            <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
              <input type='text' name='staat$j' id='staat$j' size='50'>
            </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$j\" id='beg_tag$j' ID=\"text\" size=\"1\" value='TT' onFocus=\"if(this.value=='TT'){ this.value='';}\">.<input type=\"text\" name=\"beg_mon$j\" id='beg_mon$j' value='MM' ID=\"text1\" size=\"1\" onFocus=\"if(this.value=='MM'){ this.value='';}\">.<input type=\"text\" name='beg_jahr$j' id='beg_jahr$j' ID=\"text2\" value='JJJJ' size=\"3\" onFocus=\"if(this.value=='JJJJ'){ this.value='';}\">
             bis
             <input type=\"text\" name=\"ende_tag$j\" id='ende_tag$j' ID=\"text\" size=\"1\" value='TT' onFocus=\"if(this.value=='TT'){ this.value='';}\">.<input type=\"text\" name=\"ende_mon$j\" id='ende_mon$j' value='MM' ID=\"text1\" size=\"1\" onFocus=\"if(this.value=='MM'){ this.value='';}\">.<input type=\"text\" name=\"ende_jahr$j\" id='ende_jahr$j' ID=\"text2\" value='JJJJ' 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$j' id='abteilung$j' 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>Tel. der Abteilung:</b>
          </td>
          <td width='60%' align='left' style='border-style: none; border-width: medium' height='0'>
            <input type='text' name='telabteilung$j' id='telabteilung$j' size='50'>
          </td>
        </tr>
          </table>
        <br>
  </div>

  
  <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 "antrag":

require('check_aendantrag.php');  // Überprüft, ob Krieterien erfüllt sind: Ausgegeliedert damit sie fürs bearbeiten/Antrag stellen ebenfalls verwendet werden können

$saaid = $_COOKIE['ck_staID'];


session_start();

$_SESSION['stellenbezeichnung'] = $_POST[stellenbezeichnung];
$_SESSION['stellenart'] = $_POST[stellenart];
$_SESSION['bereich'] = $_POST[bereich];
$_SESSION['ansprechpartner'] = $_POST[ansprechpartner];
$_SESSION['funktion_ansprechpartner'] = $_POST[funktion_ansprechpartner];
$_SESSION['str'] = $_POST[str];
$_SESSION['plz'] = $_POST[plz];
$_SESSION['ort'] = $_POST[ort];
$_SESSION['zuw_bezeichnung'] = $_POST[zuw_bezeichnung];
$_SESSION['zuw_ansppart'] = $_POST[zuw_ansppart];
$_SESSION['zuw_str'] = $_POST[zuw_str];
$_SESSION['zuw_plz'] = $_POST[zuw_plz];
$_SESSION['zuw_ort'] = $_POST[zuw_ort];
$_SESSION['land'] = $_POST[land];
$_SESSION['telefon'] = $_POST[telefon];
$_SESSION['mail'] = $_POST[mail];
$_SESSION['einver_dsts'] = $_POST[einverstanden];
$_SESSION['sachbereich'] = $_POST[sachbereich];
$_SESSION['beg_tag'] = $_POST[beg_tag];
$_SESSION['beg_mon'] = $_POST[beg_mon];
$_SESSION['beg_jahr'] = $_POST[beg_jahr];
$_SESSION['ende_tag'] = $_POST[ende_tag];
$_SESSION['ende_mon'] = $_POST[ende_mon];
$_SESSION['ende_jahr'] = $_POST[ende_jahr];
$_SESSION['zuw_adr_chk'] = $_POST[zuw_adr_chk];

/*
setcookie("ck_aend","");
setcookie("ck_aend[stellenbezeichnung]",$_POST[stellenbezeichnung]);

#setcookie("ck_stellenart","");
setcookie("ck_aend[stellenart]",$_POST[stellenart]);

#setcookie("ck_bereich","");
setcookie("ck_aend[bereich]",$_POST[bereich]);

#setcookie("ck_ansprechpartner","");
setcookie("ck_aend[ansprechpartner]",$_POST[ansprechpartner]);

#setcookie("ck_funktion_ansprechpartner","");
setcookie("ck_aend[funktion_ansprechpartner]",$_POST[funktion_ansprechpartner]);

#setcookie("ck_str","");
setcookie("ck_aend[str]",$_POST[str]);

#setcookie("ck_plz","");
setcookie("ck_aend[plz]",$_POST[plz]);

#setcookie("ck_ort","");
setcookie("ck_aend[ort]",$_POST[ort]);

#setcookie("ck_land","");
setcookie("ck_aend[land]",$_POST[land]);

#setcookie("ck_telefon","");
setcookie("ck_aend[telefon]",$_POST[telefon]);

#setcookie("ck_mail","");
setcookie("ck_aend[mail]",$_POST[mail]);

#setcookie("ck_einver_dsts","");
setcookie("ck_aend[einver_dsts]",$_POST[einverstanden]);

#setcookie("ck_sachbereich","");
setcookie("ck_aend[sachbereich]",$_POST[sachbereich]);

#setcookie("1_beg_tag","");
setcookie("ck_aend[beg_tag]",$_POST[beg_tag]);

#setcookie("2_beg_mon","");
setcookie("ck_aend[beg_mon]",$_POST[beg_mon]);

#setcookie("3_beg_jahr","");
setcookie("ck_aend[beg_jahr]",$_POST[beg_jahr]);

#setcookie("4_ende_tag","");
setcookie("ck_aend[ende_tag]",$_POST[ende_tag]);

#setcookie("5_ende_mon","");
setcookie("ck_aend[ende_mon]",$_POST[ende_mon]);

#setcookie("6_ende_jahr","");
setcookie("ck_aend[ende_jahr]",$_POST[ende_jahr]);
*/


$anfang_neu = $_POST[beg_jahr].'-'.$_POST[beg_mon].'-'.$_POST[beg_tag];
$ende_neu = $_POST[ende_jahr].'-'.$_POST[ende_mon].'-'.$_POST[ende_tag];


$db = dbconnect();
$result = $db->query("SELECT nachname, vorname, postrasse, poplz, poort, stgtext, AG, Jahrgang, mail, mail2, mtknr, stg FROM stud where uid=\"$uid1\"");
$row = $result->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>Daten prüfen</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"70%\" 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\">Daten prüfen</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>";
                                
                                $result3 = $db->query("SELECT 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]'");
                                $row3 = $result3->fetch_array();
                                
                                
				$result_tmp1 = $db->query("DELETE FROM stan_tmp_check_data WHERE uid='$uid1'");
				$result_tmp1 = $db->query("INSERT INTO stan_tmp_check_data SELECT NULL, '$uid1', beginn, ende, 'Praxisbegleitender Unterricht' FROM stan_sperrzeit WHERE jahrgang ='$row[Jahrgang]' AND kennung = '$row[stg]'");

				$result_tmp1 = $db->query("INSERT INTO stan_tmp_check_data
			                                         SELECT t1.saaid
								      , t1.uid
								      , t1.beginn
								      , t1.ende
								      , t1.ort
								   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.zuweisung is NULL OR t1.zuweisung='Z')
                                                          ");
				
				
				$result_tmp1 = $db->query("DELETE FROM stan_tmp_check_data WHERE saaid='$saaid' and saaid !=0");
				if($saaid == 'X'){
				
				  $result = $db->query("SELECT max(saaid) max_id FROM stan_tmp_check_data WHERE uid='$uid1'");
				  $row4 = $result->fetch_array();
				  $saaid_neu = $row4[max_id] + 1;
				  $result_tmp1 = $db->query("INSERT INTO stan_tmp_check_data (saaid, uid, beginn, ende, bezeichnung) VALUES ($saaid_neu, '$uid1', '$anfang_neu', '$ende_neu', '$_POST[ort]')");
				}else{
				  $result_tmp1 = $db->query("INSERT INTO stan_tmp_check_data (saaid, uid, beginn, ende, bezeichnung) VALUES ($saaid, '$uid1', '$anfang_neu', '$ende_neu', '$_POST[ort]')");
				}
				$result_tmp1 = $db->query("INSERT INTO stan_tmp_check_data SELECT NULL, '$uid1', DATE_SUB(antrag_von, INTERVAL 1 DAY), DATE_SUB(antrag_von, INTERVAL 1 DAY), 'Antragszeitraum Beginn' FROM stan_frist WHERE jahrgang ='$row[Jahrgang]'");
				$result_tmp1 = $db->query("INSERT INTO stan_tmp_check_data SELECT NULL, '$uid1', DATE_ADD(antrag_bis, INTERVAL 1 DAY), DATE_ADD(antrag_bis, INTERVAL 1 DAY), 'Antragszeitraum Ende' FROM stan_frist WHERE jahrgang ='$row[Jahrgang]'");
                                $query = "SELECT ma.uid, DATE_FORMAT(beginn, '%d.%m.%Y') beginn, DATE_FORMAT(ende, '%d.%m.%Y') ende, bezeichnung, COALESCE( luecke, 'OK' ) AS Luecke
                                            FROM stan_tmp_check_data ma
                                            LEFT JOIN ( SELECT saaid, 'Lücke folgt' AS luecke 
                                                          FROM stan_tmp_check_data a
                                                         WHERE a.ende != (SELECT MAX( ende ) FROM stan_tmp_check_data x WHERE x.uid = a.uid)
                                                           AND NOT EXISTS ( SELECT saaid FROM stan_tmp_check_data b
                                                                             WHERE a.uid = b.uid
                                                                               AND b.beginn = DATE_ADD( a.ende, INTERVAL 1 DAY )
                                                                          )
                                                            OR ( a.beginn IN (select beginn FROM stan_tmp_check_data d WHERE d.saaid != a.saaid)
                                                                 AND a.ende  IN (select ende FROM stan_tmp_check_data e WHERE e.saaid != a.saaid AND e.uid = '$uid1')
                                                               )
                                                      ) L
                                              ON L.saaid = ma.saaid
                                           WHERE ma.uid = '$uid1'
                                           ORDER BY ma.uid, ma.beginn";

				$result = $db->query($query)
				          or die ("Cannot execute query");
				echo "<table width='100%'>";
                                while ($row2 = $result->fetch_array()){
                                echo"
                                <tr>
                                  <td width='35%'>
                                    $row2[bezeichnung]
                                  </td>
                                  <td width='35%'>";
                                    if($row2[bezeichnung] == 'Antragszeitraum Beginn'){
                                      echo"$row3[antrag_von]";
                                    }elseif($row2[bezeichnung] == 'Antragszeitraum Ende'){
				      echo"$row3[antrag_bis]";
                                    }else{
                                      echo"$row2[beginn] - $row2[ende]";
                                    }
                                    
                                    
                                    echo"
                                  </td>
                                  <td width='30%' align='center'>";
                                    if($row2[Luecke] != 'OK'){
                                      echo "<img border=\"0\" src=\"../images/leerer_zeitraum.gif\">";
                                    }else{
                                      echo "<img border=\"0\" src=\"../images/gueltig.png\">";
                                    }
                                    
                                   
                                    echo"
                                  </td>
                                </tr>
                                ";
                                }
                                #$result_tmp1 = $db->query("DELETE FROM stan_tmp_check_data WHERE uid='$uid1'");
                                echo"
                                </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>
<p align='center'>
<table border=\"0\" style=\"border-collapse: collapse\" width='40%'  cellpadding=\"0\">
<tr>
  <td>
     <div align=\"center\">
       <table cellspacing=\"0\" cellpadding=\"0\"  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\">Änderungsantrag vormerken?</font><br>
            <span class=\"sh\">Es werden alle Änderunsanträge gesammelt.<br>Im Schritt 2 werden diese gesammelt beantragt.</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>
            <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\">
            <tr>
              <td width=\"33%\"><font size=\"1\">
                &nbsp;
              </td>
              <td width=\"33%\"><font size=\"1\">
                &nbsp;
              </td>
              <td width=\"34%\"><font size=\"1\">
                &nbsp;
              </td>
            </tr>
            <tr>
              <td width=\"33%\" align='left'>
                <a href=".$_SERVER['PHP_SELF'] ."?action=aenderung2>ja</a>
              </td>
              <td width=\"33%\" align='center'>
                <a href=\"javascript:history.back()\">überarbeiten</a>
              </td>
              <td width=\"34%\" align='right'>
                <a href=\"hauptframe.php\">nein</a>
              </td>
            </tr>
            <tr>
              <td width=\"33%\"><font size=\"1\">
                &nbsp;
              </td>
              <td width=\"33%\"><font size=\"1\">
                &nbsp;
              </td>
              <td width=\"34%\"><font size=\"1\">
                &nbsp;
              </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 "aenderung2":
#echo "$uid1";
#exit;
session_start();

$saaid 				= $_COOKIE['ck_saaid'];
$art 				= $_SESSION['stellenart'];
$stellenbezeichnung 		= $_SESSION['stellenbezeichnung'];
$bereich 			= $_SESSION['bereich'];
$ansprechpartner 		= $_SESSION['ansprechpartner'];
$funktion_ansprechpartner 	= $_SESSION['funktion_ansprechpartner'];
$str 				= $_SESSION['str'];
$plz 				= $_SESSION['plz'];
$ort 				= $_SESSION['ort'];
$zuw_bezeichnung		= $_SESSION['zuw_bezeichnung'];
$zuw_ansppart			= $_SESSION['zuw_ansppart'];
$zuw_str			= $_SESSION['zuw_str'];
$zuw_plz			= $_SESSION['zuw_plz'];
$zuw_ort 			= $_SESSION['zuw_ort'];
$land 				= $_SESSION['land'];
$telefon 			= $_SESSION['telefon'];
$mail 				= $_SESSION['mail'];
$einver_dsts 			= $_SESSION['einver_dsts'];
$sachbereich 			= $_SESSION['sachbereich'] ;
$aendid 			= $_COOKIE['ck_aendid'];
$beg_tag 			= $_SESSION['beg_tag'];
$beg_mon 			= $_SESSION['beg_mon'];
$beg_jahr 			= $_SESSION['beg_jahr'];
$ende_tag 			= $_SESSION['ende_tag'];
$ende_mon 			= $_SESSION['ende_mon'];
$ende_jahr 			= $_SESSION['ende_jahr'];
$zuw_adr_chk			= $_SESSION['zuw_adr_chk'];

$beginndatum = $beg_jahr.'-'.$beg_mon.'-'.$beg_tag;
$enddatum = $ende_jahr.'-'.$ende_mon.'-'.$ende_tag;
$datum=date("Y-m-d H:i:s");

if($zuw_adr_chk == 'zuw_same'){
  $zuw_bezeichnung = $stellenbezeichnung;
  $zuw_ansppart = $ansprechpartner;
  $zuw_str = $str;
  $zuw_plz = $plz;
  $zuw_ort = $ort;
}else{
  $zuw_bezeichnung = $zuw_bezeichnung;
  $zuw_ansppart = $zuw_ansppart;
  $zuw_str = $zuw_str;
  $zuw_plz = $zuw_plz;
  $zuw_ort = $zuw_ort;
}


$db = dbconnect();
## Erst delete durchführen, bevor insert gemacht wird, da beim Refresh sonst die Daten nochmals geschrieben werden.
## Alternativ zum delete kann mit $ln_number = $ln_number + 1 gearbeitet werden

/*
$aend = $db->query("SELECT bearbeitung
                       FROM `stan_antrag_aend`
                      WHERE uid='$uid1'
                        AND aendid = $saaid");
$aend_antr = $aend->fetch_array();

if($aend_antr[bearbeitung] != 'Y'){
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>Änderungsanträge nicht mö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\">Änderungsanträge nicht mö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\">Der &Auml;nderungsantr&auml;g befindet sich<br>durch den Sachbearbeiter in Bearbeitung<br>
                                        In dieser Zeit können sie keine &Auml;nderungsantr&auml;ge stellen!
                    </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;   
}
*/

#$sql1 = $db->query ("DELETE FROM stan_antrag WHERE saaid='$saaid' AND status = '2'");
$sql1 = $db->query ("DELETE FROM stan_antrag WHERE aendid='$aendid' AND status = '2'");
$sql = $db->query ("INSERT INTO stan_antrag (uid, art, bezeichnung, bereich, ansprechpartner
                                           , funktion, str, plz, ort, zuw_bezeichnung, zuw_ansprechpartner, zuw_str, zuw_plz, zuw_ort, land, telefon, mail, einver_dsts
                                           , sachbereich, beginn, ende, aendid, status
                                           , bearbeitung, zuweisung
                                           ) VALUES (
                                             '$uid1', '$art', '$stellenbezeichnung'
                                           , '$bereich', '$ansprechpartner'
                                           , '$funktion_ansprechpartner', '$str'
                                           , '$plz', '$ort', '$zuw_bezeichnung', '$zuw_ansppart', '$zuw_str', '$zuw_plz', '$zuw_ort', '$land', '$telefon', '$mail'
                                           , '$einver_dsts', '$sachbereich', '$beginndatum'
                                           , '$enddatum', '$aendid', '2', 'Y', NULL)");


$res = $db->query("SELECT count(*) neu_im_aend
                      FROM stan_antrag
                     WHERE saaid ='$aendid'
                       AND status = '0'
                   ");
$row_aend = $res->fetch_array();  // Wenn ursprünglich mal ein neuer Datensatz im ÄA eingefügt wurde
                                      // muss die saaid immer gleich der aendid bleiben, da es vorkommen könnten
                                      // dass ein neuer DS eingefügt wird und beim nochmaligen ändern würde der
                                      // ursprünglich neu eingetragene gelöscht werden. Dann würde sich die aendid
                                      // auf einen DS beziehen, der nicht mehr in der DB vorhanden ist.


if($saaid == 'X' or $row_aend[neu_im_aend] == 0){
  $sql1 = $db->query ("UPDATE stan_antrag SET aendid = '".$db->insert_id."' WHERE saaid = '".$db->insert_id."'");
}

if($sql){
$res = $db->query("SELECT bezeichnung
                      FROM stan_stellenbereiche
                     WHERE sbid='$sachbereich'");
$row_sach = $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>Antrag 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 vorgemerkt</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 Änderungsantrag wurde vorgemerkt!</b><br><br>

    <table>
      <tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Bezeichnung:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$stellenbezeichnung</font>
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Bezeichnung des Bereichs:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$bereich</font>
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Name des Ansprechpartners:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$ansprechpartner</font>
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Funktion des Ansprechpartners:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$funktion_ansprechpartner</font>
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Straße und Hausnummer:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$str</font>
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>PLZ und Ort:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$plz $ort</font>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Telefon Ansprechpartner:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$telefon</font>
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Mail Ansprechpartner:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$mail</font>
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  &nbsp;
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  &nbsp;
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Sachbereich:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <p>
                  <font face='Arial' size='2'>$row_sach[bezeichnung]</font>
                  </p>
		</td>
	</tr>
	<tr>
		<td width='60%' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'><b>Zeitraum:</b></font>
		</td>
		<td width='40%' align='left' style='border-style: none; border-width: medium' height='32'>
		  <font face='Arial' size='2'>$beg_tag.$beg_mon.$beg_jahr - $ende_tag.$ende_mon.$ende_jahr</font>
		</td>
	</tr>
    </table>
                    <p align=\"center\"><a href=".$_SERVER['PHP_SELF'] .">
                    <img border=\"0\" src=\"../images/weitere_aend.gif\"></a>
                    &nbsp; &nbsp;
                    <a href='check_aend.php'>
                    <img border=\"0\" src=\"../images/daten_prfen.gif\"></a>
                    </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>Es ist ein Fehler aufgetreten. Sie müssen den Antrag erneut stellen!</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>";
}
session_destroy();
 
}
?>