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

$user_admin=$_COOKIE["user_admin"];
$jahrgang=$_COOKIE["jahrgang"];
$hs=$_COOKIE["ck_hs"];



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



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

switch($action){
default:

echo "
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Einzel&uuml;bersicht</title>
	<script type=\"text/javascript\" src=\"livesearch/ajax.js\"></script>
	<script type=\"text/javascript\" src=\"livesearch/ajax-dynamic-list.js\"></script>
<style type=\"text/css\">
select{
	width:250px;
}



	/* Big box with list of options */
	#ajax_listOfOptions{
		position:absolute;	/* Never change this one */
		width:320px;	/* 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;
	}
</style>
</head>
<body onload=\"if(document.einzel)document.einzel.stud.focus();return false;\">
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
                <tr>
                    <td width=\"10\" background=\"../images/box_e1.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../images/box_top.gif\" valign=\"top\"></td>
                    <td width=\"95%\" background=\"../images/box_top.gif\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">&Uuml;bersicht</font><br>
                    <font class=\"sh\">&Uuml;bersicht über die eingegangen Stellenanträge</font><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
              <form action="; echo $_SERVER['PHP_SELF'] . "?action=ubersicht"; echo" method=\"POST\" name=\"einzel\">
			  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-width: 0\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"115\">
			    <tr>
			      <td width=\"25%\" height=\"17\">
			      </td>
			      <td width=\"25%\" height=\"17\">&nbsp;</td>
			      <td width=\"25%\" height=\"17\">
			      <p>&nbsp;</p>
			      </td>
			      <td width=\"25%\" height=\"17\">
			      <p></p>
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">&nbsp;</td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        Bitte Matrikelnr. eingeben:
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"left\">
                                <input type=\"text\" id=\"stud\" name=\"stud\" value=\"\" onkeyup=\"ajax_showOptions(this,'getWord',event)\" size=\"50\">
				<input type=\"hidden\" id=\"stud_hidden\" name=\"stud_ID\"><!-- THE ID OF the textstelle will be inserted into this hidden input -->

			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        &nbsp;
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"center\">
                                &nbsp;
			      </td>
			    </tr>
         		    <tr>
			      <td width=\"50%\"  height=\"17\">
			      &nbsp;
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      oder
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        &nbsp;
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"center\">
                                &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      Benutzer auswählen
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			    			      ";
			    			      
			    
			    			      $db = dbconnect();
			    			      $query = "SELECT distinct a.uid, mtknr, vorname, nachname, durchgefallen
			    			                  FROM stud a, stan_antrag b
			    			                 WHERE a.uid = b.uid
			    			                   AND jahrgang='$jahrgang'
			    			                   AND stg = 'I'
			    			                   AND hs = '$hs'
			    			                 ORDER BY nachname";
			    			      $result = $db->query ($query)
			    			         or die ("Cannot execute query");
			    			      echo "<select size=\"5\" name=\"user2\">";
			    			      while ($row = $result->fetch_array()){
			                                    echo "<option value=\"".$row[uid]."\">$row[nachname], $row[vorname]";
			                                    if ($row[durchgefallen] == "Y"){
			                                      echo " *";
			                                    }
			                                    echo "
			                                    &nbsp;&nbsp;&nbsp;</option>\n";
			    			      }
			    			      echo "</select>";
			    
			      echo "
			      <br>
			      * = inaktiver Bewerber
			      
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      &nbsp;
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"100%\" \" colspan='2' align=\"center\">
			      <input type=\"submit\" value=\"Abschicken\" name=\"B1\"></td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"18\">
			      </td>
			      <td width=\"50%\">
			        &nbsp;
			      </td>

			    </tr>
                            <tr>
                              <td width=\"50%\">
                              </td>
                              <td width=\"50%\" align=\"center\">
                              </td>
                            </tr>
                            <tr>
                              <td width=\"50%\">
                              </td>
                              <td width=\"50%\" align=\"center\">
                                &nbsp;
                              </td>
                            </tr>
			  </table>
			  </form>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
break;
case "ubersicht":
if($_POST[stud]!=''){
 $stud = $_POST[stud];
 $pos1 = strpos  ($stud, '(')+1;
 $pos2 = strpos  ($stud, ')')-$pos1;


 $str = substr($stud, $pos1,$pos2);

 $str = explode(",",$str);
 
 $mtknr=trim($str[0]);
 $uid1=trim($str[1]);
 
  $result = $db->query("SELECT uid, stg, vorname, nachname
                           FROM stud
                          WHERE uid ='$uid1'");
  $row_uid = $result->fetch_array();

 
 
 if($_POST[stud] == ''){
   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>Falsches Datum</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\">Pflichtfelder ausfüllen</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>Bitte füllen Sie alle Pflichtfelder aus!</p></b>
                    </p>
                    <p align=\"center\"><a href=\"javascript:history.back()\">
                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                    </p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p><br>
                    </p>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
  </table>
  </body>
  </html>";
  exit;
 }
}

if($_POST[user2] != ''){ // Wenn Stud über dropdown gewählt wurde
 $db = dbconnect();
 $result = $db->query("SELECT uid, stg, vorname, nachname
                          FROM stud
                         WHERE uid ='$_POST[user2]'");
 $row_uid = $result->fetch_array();
 $mtknr=$row_uid[mtknr];
 $uid1=$row_uid[uid];
}

if(isset($_GET["uid"])){
 $uid1=$_GET["uid"];
 
 $db = dbconnect();
 $result = $db->query("SELECT uid, stg, vorname, nachname
                          FROM stud
                         WHERE uid ='$_POST[user2]'");
 $row_uid = $result->fetch_array();
 $mtknr=$row_uid[mtknr];
}

 setcookie("ck_uid1","");
 setcookie("ck_uid1",$uid1);
 
 setcookie("ck_mtknr","");
 setcookie("ck_mtknr",$mtknr);

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>


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

</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\">AG-Standorte wählen für $row_uid[vorname] $row_uid[nachname]</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 t2.status !='2' #hinzugefügt am 10.06.2009, weil Status 2 angezeigt wurde
                                                  )
                                 AND t1.uid = '$uid1'
                                 AND (t1.zuweisung is NULL OR t1.zuweisung='Z')
                               ORDER BY vert_bereich
                             ";

                    $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:
                                  ";
                                        $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 t1.saaid
					     , t1.dst_id
					     , date_format(t1.beginn, '%d.%m.%Y') beginn
					     , date_format(t1.beginn, '%Y%m%d') beginn_form
					     , date_format(t1.ende, '%d.%m.%Y') ende
					     , t1.bearbeitung
					  FROM stan_antrag t1
					 WHERE t1.status = (
					                    SELECT MAX(t2.status)
					                      FROM stan_antrag t2
					                     WHERE t1.aendid = t2.aendid
					                       AND t2.status !='2' #hinzugefügt am 10.06.2009, weil Status 2 angezeigt wurde
					                   )
                                            AND t1.uid = '$uid1'
                                            AND vert_bereich = '$row[vert_bereich]'
                                            AND (t1.zuweisung is NULL OR t1.zuweisung='Z')
                                            #AND (zuweisung != 'G' or zuweisung is null)
                                            #AND (zuweisung != 'GV' or zuweisung is null)
                                           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 "
                               <form action="; echo $_SERVER['PHP_SELF'] . "?action=bearbeiten"; echo" method=\"POST\">

                               <table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width=\"100%\" id=\"AutoNumber1\">
                               <tr>
                                 <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\">
                                   $dst_bez<br>
                                 </td>
                                 <td valign=\"middle\" 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\">
                                 ";
                                 $db = dbconnect();
                                 $res6 = $db->query("SELECT saaid, wagsid FROM stan_ag_standort_wunsch WHERE uid='$uid1' AND saaid = '$row3[saaid]' AND prio='1'");
                                 $row6 = $res6->fetch_array();

                                 # Nur einmal ein Standort abspeichern


                                    $query1 = "SELECT agsid, standort
                                                 FROM stan_ag_standort a, stan_standort b
                                                WHERE jahr='$jahrgang'
                                                  AND vbid = '$row[vert_bereich]'
                                                  AND a.sid=b.sid
                                                ORDER BY standort ASC
                                              ";

                                    $result1 = $db->query ($query1)
                                       or die ("Cannot execute query");
                                    echo "<select size=\"1\" name=\"$row3[saaid]_1\">
                                    <option value='x1'>Priorität 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                                    ";
                                    $nr=0;
                                    while ($row1 = $result1->fetch_array()){

                                      $res6 = $db->query("SELECT saaid, wagsid FROM stan_ag_standort_wunsch WHERE uid='$uid1' AND saaid = '$row3[saaid]' AND prio='1'");
                                      $row6 = $res6->fetch_array();


                                      if($nr==0){
                                        $nr=1;
                                        echo"<option value='8888'"; if($row6[wagsid] == '8888'){ echo " selected "; } echo">keine (Praxisstelle außerhalb BW)</option>";
                                      }

                                       echo "<option value='$row1[agsid]'"; if($row1[agsid] == $row6[wagsid]){ echo " selected "; } echo">$row1[standort]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>\n";
                                    }
                                    echo "</select>";
                                    #Wenn noch nicht alle Standorte gewählt, dann Abschickenbutton anzeigen
                                    $button_send='X';

                                   echo"
                                 </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\">
                                 ";
                                 $db = dbconnect();
                                 $res6 = $db->query("SELECT saaid, wagsid FROM stan_ag_standort_wunsch WHERE uid='$uid1' AND saaid = '$row3[saaid]' AND prio='2'");
                                 $row6 = $res6->fetch_array();



                                      $query1 = "SELECT agsid, standort
                                                  FROM stan_ag_standort a, stan_standort b
                                                 WHERE jahr='$jahrgang'
                                                   AND vbid = '$row[vert_bereich]'
                                                   AND a.sid=b.sid
                                                 ORDER BY standort ASC
                                               ";

                                      $result1 = $db->query ($query1)
                                         or die ("Cannot execute query");

                                      echo "<select size=\"1\" name=\"$row3[saaid]_2\">
                                      <option value='x2'>Priorität 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                                      ";
                                      $nr=0;
                                      while ($row1 = $result1->fetch_array()){

                                       $res7 = $db->query("SELECT wagsid FROM stan_ag_standort_wunsch WHERE uid='$uid1' AND saaid = '$row3[saaid]' AND prio='2'");
                                       $row7 = $res7->fetch_array();


                                       if($nr==0){
                                         $nr=1;
                                         echo"<option value='9999'"; if($row7[wagsid] == '9999'){ echo " selected "; } echo">keine (Praxisstelle außerhalb BW)</option>";
                                       }
                                        echo "<option value='$row1[agsid]'"; if($row1[agsid] == $row7[wagsid]){ echo " selected "; } echo">$row1[standort]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>\n";
                                      }
                                      echo "</select>";

                                      #Wenn noch nicht alle Standorte gewählt, dann Abschickenbutton anzeigen
                                      $button_send='X';
                                   echo"
                                 </td>
                               </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>
            <br>";
            if(isset($button_send)){
	     echo"<input type=\"submit\" value=\"Abschicken\" name=\"B1\" size=\"20\"></p>";
	    }
	     echo"
             </form>
        </div>
        </td>
    </tr>
</table>

</body>

</html>";

break;
case "bearbeiten":
$uid1=$_COOKIE["ck_uid1"];
$db = dbconnect();
$result8 = $db->query("SELECT distinct t1.saaid
                             , concat(saaid,'_1') prio1
                             , concat(saaid,'_2') prio2
                          FROM stan_antrag t1
                         WHERE t1.status = (
                                            SELECT MAX(t2.status)
                                              FROM stan_antrag t2
                                             WHERE t1.aendid = t2.aendid
                                               AND t2.status !='2' #hinzugefügt am 10.06.2009, weil Status 2 angezeigt wurde
                                           )
                           AND t1.uid = '$uid1'
                           AND (t1.zuweisung is NULL OR t1.zuweisung='Z')
                      ");

while ($row8 = $result8->fetch_array()){

      $saaid= $row8[saaid];
      $prio1= $_POST[$row8[prio1]];
      $prio2= $_POST[$row8[prio2]];

if($prio1 == $prio2){
 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\">Gleiche Prioritäten</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 bei einer (oder mehreren) Stelle(n) gleiche AG-Standorte angegeben</b>
                    </p>
                        <p align=\"center\"><a href=\"javascript:history.back()\">
                        <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                    </p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p><br>
                    </p>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>
 ";
 exit;
 }


 if(($prio1 != 'x1' AND $prio2 =='x2')or($prio1 == 'x1' AND $prio2 !='x2')){
  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\">Falsche Prioritäten</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 dürfen nicht nur 1 Priorität setzen</b>
                     <br>
                     </p>
                         <p align=\"center\"><a href=\"javascript:history.back()\">
                         <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                     </p>
                     <p></p>
                     <p></p>
                     <p></p>
                     <p></p>
                     <p><br>
                     </p>
                     </td>
                     <td width=\"1%\" background=\"../images/box_r.gif\">
                     <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                 </tr>
                 <tr>
                     <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                     <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                     <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                 </tr>
             </table>
         </div>
         </td>
     </tr>
 </table>
 </body>
 </html>
  ";
  exit;
 }

      $db = dbconnect();
      if($prio1 != 'x1' AND $prio1 != 'exists1'){
        $sql = $db->query ("DELETE FROM stan_ag_standort_wunsch 
                                  WHERE uid='$uid1'
                                    AND saaid='$saaid'
                                    AND prio='1'");
        $sql = $db->query ("INSERT INTO stan_ag_standort_wunsch (uid, saaid, wagsid, prio)
                             VALUES ('$uid1', '$saaid', '$prio1' ,1)"); // hier entspricht die uid den namen des Dropdownfeldes in der die neue Nr des PSN steht
/*                             
echo "DELETE FROM stan_ag_standort_wunsch 
                                  WHERE uid='$uid1'
                                    AND saaid='$saaid'
                                    AND wagsid='$prio1'
                                    AND prio='1'<br>
INSERT INTO stan_ag_standort_wunsch (uid, saaid, wagsid, prio)
                             VALUES ('$uid1', '$saaid', '$prio1' ,1)<p>                                    
                                    ";
*/
      }
      if($prio2 != 'x2' AND $prio2 != 'exists2'){
        $sql = $db->query ("DELETE FROM stan_ag_standort_wunsch 
                                  WHERE uid='$uid1'
                                    AND saaid='$saaid'
                                    AND prio='2'");
        $sql = $db->query ("INSERT INTO stan_ag_standort_wunsch (uid, saaid, wagsid, prio)
                             VALUES ('$uid1', '$saaid', '$prio2' ,2)"); // hier entspricht die uid den namen des Dropdownfeldes in der die neue Nr des PSN steht
      }
}

 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\">AG-Standorte erfasst</span><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
                    <p align=\"center\"><b>Die Standorte wurden erfasst!</b>
                    </p>
                        <p align=\"center\"><a href=\"ag_tage_admin.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>";


}
?>