<?php
$user_admin=$_COOKIE["user_admin"];
include("kurs/datenbankanbindung.php");     // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php

// Rechte&uuml;berpr&uuml;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 sozkom_admin_rechte, sozkom_admin_rechte_zuord , sozkom_admin where sozkom_admin_rechte.sozkom_admin_rolle = sozkom_admin_rechte_zuord.sozkom_admin_rolle AND sozkom_admin_rechte_zuord.faid = sozkom_admin.faid AND sozkom_admin.user = '$user_admin' AND sozkom_admin_rechte_zuord.sozkom_admin_rolle = 'a_studbear'");
$row = $result->fetch_array();
if ($row[0] != 1){ include("kurs/rechte.php"); exit;}
// Rechte&uuml;berpr&uuml;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>>Student bearbeiten</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.beleg)document.beleg.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=\"98%\" background=\"../images/box_top.gif\" valign=\"top\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Student bearbeiten</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>
                    <form action="; echo $_SERVER['PHP_SELF'] . "?action=studbearb"; echo" method=\"POST\" name=\"beleg\">
                      <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%\">
                          </td>
                          <td width=\"25%\">&nbsp;</td>
                          <td width=\"25%\">
                          <p>&nbsp;
                          </td>
                          <td width=\"25%\">
                          <p>
                          </td>
                        </tr>
                        <tr>
                          <td width=\"25%\">
                          <p>
                          </td>
                          <td width=\"50%\"colspan=\"2\">&nbsp;</td>
                          <td width=\"25%\">
                          <p>
                          </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;
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"left\">
                                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>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      Benutzer auswählen
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			    			      ";
			    			      
			    
			    			      $db = dbconnect();
			    			      $query = "SELECT uid, nachname, vorname, durchgefallen FROM stud WHERE hs='L' 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=\"25%\">
                          <p>
                          </td>
                          <td width=\"50%\" colspan=\"2\" align=\"center\">
                          &nbsp;</td>
                          <td width=\"25%\">
                          <p>
                          </td>
                        </tr>
                        <tr>
                          <td width=\"25%\">
                          </td>
                          <td width=\"50%\" colspan=\"2\" align=\"left\">
                          <input type=\"submit\" value=\"Bearbeiten\" name=\"B1\"></td>
                          <td width=\"25%\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"25%\">
                          </td>
                          <td width=\"50%\" colspan=\"2\" align=\"center\">
                          &nbsp;</td>
                          <td width=\"25%\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"25%\">
                          </td>
                          <td width=\"50%\" colspan=\"2\" align=\"center\">&nbsp;</td>
                          <td width=\"25%\">
                          </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\">
                    <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 "studbearb":


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]);
 
 
 
 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];
}
setcookie("ck_studbe",$uid1);

$db = dbconnect();
$bearb_stud = $db->query ("SELECT uid, nachname, vorname, mtknr, stg, poplz, poOrt, poStrasse, AG, Jahrgang, Pwd, Mail, durchgefallen
                              FROM stud
                             WHERE uid='$uid1'");
$stud = $bearb_stud->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>>Student bearbeiten</title>
</head>
<body onload=\"if(document.beleg)document.beleg.vorname.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=\"98%\" background=\"../images/box_top.gif\" valign=\"top\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Student bearbeiten</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>
                    <form action="; echo $_SERVER['PHP_SELF'] . "?action=dozbearb1"; echo" method=\"POST\" name=\"beleg\">
                      <table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse; border-width: 0\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"246\">
                        <tr>
                          <td width=\"40%\">
                          <b>Vorname*:</b>
                          </td>
                          <td width=\"60%\">
                          <input type=\"text\" name=\"vorname\"  value=\"$stud[vorname]\"size=\"40\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"40%\">
                          <b>Nachname*:</b>
                          </td>
                          <td width=\"60%\">
                          <input type=\"text\" name=\"nachname\"  value=\"$stud[nachname]\" size=\"40\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"40%\">
                          <b>Stra&szlig;e:</b>
                          </td>
                          <td width=\"60%\">
                          <input type=\"text\" name=\"strasse\" value=\"$stud[poStrasse]\" size=\"40\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"40%\">
                          <b>PLZ:</b>
                          </td>
                          <td width=\"60%\">
                          <input type=\"text\" name=\"plz\"  value=\"$stud[poplz]\" size=\"5\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"40%\">
                          <b>Ort:</b>
                          </td>
                          <td width=\"60%\">
                          <input type=\"text\" name=\"ort\" value=\"$stud[poOrt]\" size=\"40\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"40%\" valign=\"top\">
                          <b>Studienzweig*:</b><br>
                          </td>
                          <td width=\"60%\" align=\"left\">
                          <select size=\"6\" name=\"zweig\">
                            <option value=\"F\""; if ($stud[stg] == 'F'){echo " selected";} echo ">Finanzverwaltung &nbsp;&nbsp;&nbsp;</option>
                            <option value=\"R\""; if ($stud[stg] == 'R'){echo " selected";} echo ">Rentenversicherung &nbsp;&nbsp;&nbsp;</option>
                            <option value=\"I\""; if ($stud[stg] == 'I'){echo " selected";} echo ">Innenverwaltung &nbsp;&nbsp;&nbsp;</option>
                            <option value=\"V\""; if ($stud[stg] == 'V'){echo " selected";} echo ">Innenverwaltung (V-Zweig)&nbsp;&nbsp;&nbsp;</option>
                            <option value=\"W\""; if ($stud[stg] == 'W'){echo " selected";} echo ">Innenverwaltung (W-Zweig)&nbsp;&nbsp;&nbsp;</option>
                            <option value=\"S\""; if ($stud[stg] == 'S'){echo " selected";} echo ">Steuerverwaltung &nbsp;&nbsp;&nbsp;</option>
                          </select>
                          </td>
                        </tr>
                        <tr>
                          <tr>
                          <td width=\"40%\">
                          <b>AG*:</b>
                          </td>
                          <td width=\"60%\">
                            <input type=\"text\" name=\"ag\" value=\"$stud[AG]\" size=\"1\"> /
                            <input type=\"text\" name=\"jahr\" value=\"$stud[Jahrgang]\" size=\"2\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"40%\">
                          <b>Matrikelnr.:</b>
                          </td>
                          <td width=\"60%\">
                            <input type=\"text\" name=\"mtknr\" value=\"$stud[mtknr]\" size=\"6\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"40%\">
                          <b>Benutzerkennung:</b>
                          </td>
                          <td width=\"60%\">
                          $stud[uid]
                          </td>
                        </tr>
                        <tr>
                            <td>
                            <b>E-Mail Adresse*:</b>
                            </td>
                            <td>
                            <input type=\"text\" name=\"mail\" value=\"$stud[Mail]\"size=\"40\">
                            </td>
                          </tr>
                          <tr>
                            <td>
                            <b>Durchgefallen:</b>
                            </td>
                            <td>";
                              echo "
                              <input type=\"radio\" value=\"N\" name=\"durchgefallen\"";
                                IF ($stud[durchgefallen] == "N" )
                                  echo " checked";
                                ELSEIF ($stud[durchgefallen] == "" )
                                  echo " checked";
	                          echo ">Nein<br>
                                        <input type=\"radio\" value=\"Y\" name=\"durchgefallen\"";

		                if ($stud[durchgefallen] == "Y") echo " checked";
		                echo ">Ja
                            </td>
                          </tr>
                      </table>
                      * = Pflichtfelder
                      <br>
                      <br>
                        <input type=\"submit\" value=\"Abschicken\" name=\"B1\">
                    </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 "dozbearb1":

if ($_POST[vorname] ==  "" or $_POST[nachname] ==  ""  or $_POST[zweig] ==  "" or $_POST[ag] ==  "" or $_POST[jahr] == ""  or $_POST[mail] ==  "" ){
echo"
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Eingabefehler</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"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\">Eingabefehler</span><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
                    <p align=\"center\"><b>Es m&uuml;ssen mindestens die Pflichtfelder ausgef&uuml;llt werden!</b>
                    <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><br>
                    </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 If

if ($_POST['zweig']== 'F'){ $stgtext ='Finanzverwaltung';}
if ($_POST['zweig']== 'R'){ $stgtext ='Rentenversicherung';}
if ($_POST['zweig']== 'I'){ $stgtext ='Innenverwaltung';}
if ($_POST['zweig']== 'V'){ $stgtext ='Innenverwaltung';}
if ($_POST['zweig']== 'W'){ $stgtext ='Innenverwaltung';}
if ($_POST['zweig']== 'S'){ $stgtext ='Steuerverwaltung';}


$db = dbconnect();
$ck_studbe = $_COOKIE["ck_studbe"]; //Cookie in Variable schreiben

// UPDATE FLAG setzen
$result2 = $db->query("SELECT vorname, nachname, mtknr, postrasse, poplz, poort, ag, jahrgang FROM stud where uid=\"$ck_studbe\"");
$row2 = $result2->fetch_array();

$lv_vorname = 'false';
$lv_nachname = 'false';
$lv_strasse = 'false';
$lv_plz = 'false';
$lv_ort = 'false';
$lv_ag = 'false';
$lv_jahr = 'false';

if ($row2[vorname] != $_POST[vorname]){
  $lv_vorname = 'true';
}

if ($row2[nachname] != $_POST[nachname]){
  $lv_nachname = 'true';
}

if ($row2[postrasse] != $_POST[strasse]){
  $lv_strasse = 'true';
}

if ($row2[poplz] != $_POST[plz]){
  $lv_plz = 'true';
}

if ($row2[poort] != $_POST[ort]){
  $lv_ort = 'true';
}

if ($row2[ag] != $_POST[ag]){
  $lv_ag = 'true';
}

if ($row2[jahrgang] != $_POST[jahr]){
  $lv_jahr = 'true';
}


if ($lv_vorname == 'true' or $lv_nachname == 'true' or $lv_strasse == 'true' or $lv_plz == 'true' or $lv_ort == 'true' or  $lv_ag == 'true' or  $lv_jahr == 'true'){
  $heute_format = date("Y-m-d H:i:s",time());
  $sql = $db->query ("UPDATE stud SET update_flag='$heute_format' WHERE uid=\"$ck_studbe\"");

  $result3 = $db->query("SELECT wert1, wert2 FROM parameter WHERE pid=3");
  $row3 = $result3->fetch_array();

  $empfaenger = "$row3[wert2]";
  $betreff = "$row3[wert1]";
  $text = "
    <html>
    <head>
    <title>Adress&auml;nderung</title>
    </head>
    <body>
    <font face='Arial' size='2'>
    Guten Tag!<br><br>
    Im Kurssystem wurden bei dem Student / der Studentin <b>$row2[vorname] $row2[nachname]</b><br>mit der Matrikelnummer <b>$row2[mtknr]</b> folgende Adressdaten ge&auml;ndert:<br>
    <br>
    <table>";
    if ($lv_vorname == 'true'){
     $text .= "
     <tr>
       <td valign='top'>
         <font face='Arial' size='2'>
           Vorname:
         </font>
       </td>
       <td valign='top'>
         <font face='Arial' size='2'>
           <b>$_POST[vorname]</b>
         </font>
       </td>
     </tr>";
    }

    if ($lv_nachname == 'true'){
     $text .= "
     <tr>
       <td valign='top'>
         <font face='Arial' size='2'>
           Nachname:
         </font>
       </td>
       <td valign='top'>
         <font face='Arial' size='2'>
           <b>$_POST[nachname]</b>
         </font>
       </td>
     </tr>";
    }

    if ($lv_strasse == 'true'){
    $text .= "
     <tr>
       <td valign='top'>
         <font face='Arial' size='2'>
           Stra&szlig;e:
         </font>
       </td>
       <td valign='top'>
         <font face='Arial' size='2'>
           <b>$_POST[strasse]</b>
         </font>
       </td>
     </tr>";
    }

    if ($lv_plz == 'true'){
    $text .= "
     <tr>
       <td valign='top'>
         <font face='Arial' size='2'>
           PLZ:
         </font>
       </td>
       <td valign='top'>
         <font face='Arial' size='2'>
           <b>$_POST[plz]</b>
         </font>
       </td>
     </tr>";
    }

    if ($lv_ort == 'true'){
    $text .= "
     <tr>
       <td valign='top'>
         <font face='Arial' size='2'>
           Ort:
         </font>
       </td>
       <td valign='top'>
         <font face='Arial' size='2'>
           <b>$_POST[ort]</b>
         </font>
       </td>
     </tr>";
    }

    if ($lv_ag == 'true'){
    $text .= "
     <tr>
       <td valign='top'>
         <font face='Arial' size='2'>
           AG:
         </font>
       </td>
       <td valign='top'>
         <font face='Arial' size='2'>
           <b>$_POST[ag]</b>
         </font>
       </td>
     </tr>";
    }

    if ($lv_jahr == 'true'){
    $text .= "
     <tr>
       <td valign='top'>
         <font face='Arial' size='2'>
           Jahr:
         </font>
       </td>
       <td valign='top'>
         <font face='Arial' size='2'>
           <b>$_POST[jahr]</b>
         </font>
       </td>
     </tr>";
    }

    $text .= "
    </table>
    <br>
    Diese Mail wurde automatisch generiert!<br>
    Antworten Sie daher nicht auf diese Mail<br>
    <br>
    Vielen Dank
    </body>
    </html>";


    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=utf-8\r\n";

    /* zusa"tzliche Header */
    // $headers .= "From: Kurssystem <mager@fh-ludwigsburg.de.de>\r\n";
    // $headers .= "Cc: $cc\r\n";

    $return = @mail($empfaenger, $betreff, $text,  $headers);

}


// UPDATE FLAG ENDE


$sql =  "UPDATE stud SET
         nachname=\"". $_POST['nachname']."\"
       , vorname=\"". $_POST['vorname']."\"
       , poplz=\"". $_POST['plz']."\"
       , poOrt=\"". $_POST['ort']."\"
       , poStrasse=\"". $_POST['strasse']."\"
       , stg=\"". $_POST['zweig']."\"
       , stgtext='$stgtext'
       , AG=\"". $_POST['ag']."\"
       , Jahrgang=\"". $_POST['jahr']."\"
       , mtknr=\"". $_POST['mtknr']."\"
       , Mail=\"". $_POST['mail']."\"
       , durchgefallen=\"". $_POST['durchgefallen']."\"
       WHERE uid=\"$ck_studbe\"";
$sql2 = $db->query ($sql);

if ($sql2)
{


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>Student bearbeitet</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\">Student bearbeitet</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 &Auml;nderungen wurden gespeichert!</b>

                    <p align=\"center\"><a href=\"stud_bearb.php\">
                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>

                    <p>
                    <p>
                    <p>
                    <p>
                    <p><br>

                    </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>Student bearbeitet</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\">Student bearbeitet</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 &Auml;nderungen konnten nicht gespeichert werdeb!</b>

                    <p align=\"center\"><a href=\"stud_bearb.php\">
                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>

                    <p>
                    <p>
                    <p>
                    <p>
                    <p><br>

                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
}



} // Ende Action script
?>