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

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"];

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

switch($action){
default:

$db = dbconnect();
include("kurs/pros/pros_useronline_write.php");     // F&uuml;r Statistik, wieviele User online sind

$result = $db->query("SELECT nachname, vorname, postrasse, poplz, poort, AG, Jahrgang, mail 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 vervollst&auml;ndigen</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=\"98%\" background=\"../images/box_top.gif\" valign=\"top\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Daten vervollst&auml;ndigen</font><br>
                    <span class=\"sh\">Halten Sie Ihre Daten bis zum Ende des Studiums aktuell</span><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=persdat"; echo" method=\"POST\" name=\"pers_daten\">
                        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-width:0; border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"142\">
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"32\">
                                <b>Vorname:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"32\">
                                <p>
                                <input type=\"text\" name=\"Vorname\" size=\"50\" value=\"$row[vorname]\"></p>
                                </td>
                            </tr>
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"32\">
                                <b>Nachname:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"32\">
                                <p>
                                <input type=\"text\" name=\"Nachname\" size=\"50\" value=\"$row[nachname]\"></p>
                                </td>
                            </tr>
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"32\">
                                <b>Stra&szlig;e:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"32\">
                                <p>
                                <input type=\"text\" name=\"strasse\" size=\"50\" value=\"$row[postrasse]\"></p>
                                </td>
                            </tr>
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"32\">
                                <b>PLZ / Ort:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"32\">
                                <p>
                                <input type=\"text\" name=\"plz\" size=\"5\" value=\"$row[poplz]\">&nbsp;
                                <input type=\"text\" name=\"ort\" size=\"40\" value=\"$row[poort]\"></p>
                                </td>
                            </tr>
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"32\">
                                <b>AG:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"32\">
                                <p>
                                <input type=\"text\" name=\"AG\" size=\"1\" value=\"$row[AG]\">
                                /
                                $row[Jahrgang]
                                </td>
                            </tr>
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"32\">
                                <b>E-Mail:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"32\">
                                <p>$row[mail]
                                </td>
                            </tr>
                            </tr>
                            <tr>
                                <td width=\"28%\" style=\"border-style: none; border-width: medium\" height=\"25\">&nbsp;</td>
                                <td width=\"72%\" align=\"left\" style=\"border-style: none; border-width: medium\" height=\"25\">&nbsp;</td>
                            </tr>
                            <tr>
                                <td width=\"98%\" style=\"border-style: none; border-width: medium\" height=\"25\" colspan=\"2\">
                                Alle Felder m&uuml;ssen ausgef&uuml;llt werden
                                </td>
                            </tr>
                            <tr>
                                <td width=\"28%\" style=\"border-style: none; border-width: medium\" height=\"25\">
                                <p>&nbsp;</p>
                                </td>
                                <td width=\"72%\" align=\"left\" style=\"border-style: none; border-width: medium\" height=\"25\">
                                <p>&nbsp;</p>
                                </td>
                            </tr>
                        </table>
                        <input type=\"submit\" value=\"Abschicken\" name=\"B1\" size=\"20\"></form>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";

break;
case "persdat":


if ($_POST['Vorname'] == "" or $_POST['Nachname'] == "" or $_POST['strasse'] == "" or $_POST['plz'] == "" or $_POST['ort'] == "" or $_POST['AG'] == ""){
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 alle Felder ausgef&uuml;llt werden!</b>
                    </p>
                    <p align=\"center\"><a href=\"javascript:history.back()\">
                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                    </p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p></p>
                    <p><br>
                    </p>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
exit;
}

$db = dbconnect();

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

$lv_vorname = 'false';
$lv_nachname = 'false';
$lv_strasse = 'false';
$lv_plz = 'false';
$lv_ort = 'false';
$lv_ag = '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 ($lv_vorname == 'true' or $lv_nachname == 'true' or $lv_strasse == 'true' or $lv_plz == 'true' or $lv_ort == 'true' or  $lv_ag == 'true'){
  $heute_format = date("Y-m-d H:i:s",time());
  $sql = $db->query ("UPDATE stud SET update_flag='$heute_format' WHERE uid=\"$uid1\"");

  $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>";
    }

    $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";


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

}
// UPDATE FLAG ENDE


$sql = $db->query ("UPDATE stud SET vorname='". $_POST['Vorname']."', nachname='". $_POST['Nachname']."', postrasse='". $_POST['strasse']."', poplz='". $_POST['plz']."', poort='". $_POST['ort']."', AG='". $_POST['AG']."' WHERE uid=\"$uid1\"");
$result1 = $db->query("SELECT Jahrgang FROM stud where uid=\"$uid1\"");
$row1 = $result1->fetch_array();

echo "

<html>
<head>
<meta http-equiv=\"refresh\" content=\"6; URL=../hauptframe.php\">
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Daten vervollst&auml;ndigen</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=\"98%\" background=\"../images/box_top.gif\" valign=\"top\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Daten ge&auml;ndert</font><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></font></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td>
                        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-width:0; border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"142\">
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"25\">
                                <b>Name:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"25\">
                                <p>
                                ". $_POST['Vorname']."  ".$_POST['Nachname']."</p>
                                </td>
                            </tr>
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"25\">
                                <b>Stra&szlig;e:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"25\">
                                <p>
                                ". $_POST['strasse']."</p>
                                </td>
                            </tr>
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"25\">
                                <b>PLZ / Ort:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"25\">
                                <p>
                                ". $_POST['plz']."&nbsp;". $_POST['ort']."</p>
                                </td>
                            </tr>
                            <tr>
                                <td style=\"border-style: none; border-width: medium\" height=\"25\">
                                <b>AG:</b>
                                </td>
                                <td align=\"left\" style=\"border-style: none; border-width: medium\" height=\"25\">
                                <p>
                                ". $_POST['AG']." /  $row1[Jahrgang]</p>
                                </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>";
} // Ende Action
?>