<?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 pros_admin_rechte, pros_admin_rechte_zuord , pros_admin where pros_admin_rechte.pros_admin_rolle = pros_admin_rechte_zuord.pros_admin_rolle AND pros_admin_rechte_zuord.faid = pros_admin.faid AND pros_admin.user = '$user_admin' AND pros_admin_rechte_zuord.pros_admin_rolle = 'a_dozbearb'");
$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>Dozent bearbeiten</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"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\">Dozent 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=dozbearb"; 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=\"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\">
						  <p align=\"center\">
						  ";
						  $db = dbconnect();
						  $query = "SELECT doz_nr, doz_titel, doz_name, doz_vorname from doz order by doz_name";
						  $result = $db->query ($query)
							 or die ("Cannot execute query");
						  echo "<select size=\"5\" name=\"dozbe\">";
						  while ($row = $result->fetch_array()){
						  echo "<option value=\"".$row['doz_nr']."\">".$row['doz_name'].",&nbsp;".$row['doz_vorname'].",&nbsp;&nbsp;&nbsp;".$row['doz_titel']."&nbsp;&nbsp;&nbsp;</option>\n";
						  }
						  echo "</select>";
						  echo "
						  </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=\"25%\">
						  </td>
						  <td width=\"50%\"colspan=\"2\" align=\"center\">
						  <input type=\"submit\" value=\"Abschicken\" name=\"B1\"></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 "dozbearb":

setcookie("ck_dozbe",$_POST['dozbe']);

$db = dbconnect();
                $bearb_doz = $db->query ("Select doz_uid, doz_name, doz_vorname, doz_titel, doz_mail, doz_strasse, doz_plz, doz_ort, doz_tel, doz_pwd FROM doz WHERE doz_nr=\"". $_POST['dozbe']."\"");
                $doz = $bearb_doz->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>Dozent bearbeiten</title>
</head>
<body onload=\"if(document.doz_bearbeit)document.doz_bearbeit.doz_titel.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\">Dozent 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 method=POST action=$_SERVER[PHP_SELF]?action=dozbearb1 name=doz_bearbeit>
					  <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%\">
						  Titel:
						  </td>
						  <td width=\"60%\">
						  <input type=\"text\" name=\"doz_titel\" value=\"$doz[doz_titel]\" size=\"10\">
						  </td>
						</tr>
						<tr>
						  <td width=\"40%\">
						  Vorname:
						  </td>
						  <td width=\"60%\">
						  <input type=\"text\" name=\"doz_vorname\"  value=\"$doz[doz_vorname]\"size=\"30\">
						  </td>
						</tr>
						<tr>
						  <td width=\"40%\">
						  Nachname:
						  </td>
						  <td width=\"60%\">
						  <input type=\"text\" name=\"doz_name\"  value=\"$doz[doz_name]\" size=\"30\">
						  </td>
						</tr>
						<tr>
						  <td width=\"40%\">
						  Stra&szlig;e:
						  </td>
						  <td width=\"60%\">
						  <input type=\"text\" name=\"doz_strasse\" value=\"$doz[doz_strasse]\" size=\"40\">
						  </td>
						</tr>
							<tr>
						  <td width=\"40%\">
						  PLZ:
						  </td>
						  <td width=\"60%\">
						  <input type=\"text\" name=\"doz_plz\"  value=\"$doz[doz_plz]\" size=\"5\">
						  </td>
						</tr>
						  <tr>
						  <td width=\"40%\">
						  Ort:
						  </td>
						  <td width=\"60%\">
						  <input type=\"text\" name=\"doz_ort\" value=\"$doz[doz_ort]\" size=\"40\">
						  </td>
						</tr>
						</tr>
						  <tr>
						  <td width=\"40%\">
						  Tel.:
						  </td>
						  <td width=\"60%\">
						  <input type=\"text\" name=\"doz_tel\" value=\"$doz[doz_tel]\" size=\"40\">
						  </td>
						<tr>
						<tr>
						  <td width=\"40%\">
						  Benutzerkennung:
						  </td>
						  <td width=\"60%\">
						  <input type=\"text\" name=\"doz_uid\" value=\"$doz[doz_uid]\" size=\"40\">
						  </td>
						</tr>
						  <tr>
							<td>E-Mail Adresse:</td>
							<td>
							<input type=\"text\" name=\"doz_mail\" value=\"$doz[doz_mail]\"size=\"40\">
							</td>
						  </tr>
						  <tr>
							<td>Kennwort neu setzen:</td>
							<td>
							  <input name=\"doz_pwd\"  type=\"password\" id=\"doz_pwd\" size=\"40\">
							</td>
						  </tr>
					  </table>
					  <br>
					  <br>
					<p align=\"center\"><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":
$db = dbconnect();

$ck_dozbe = $_COOKIE["ck_dozbe"];

if ($_POST['doz_pwd'] != '')
{
  $passwd = md5($_POST['doz_pwd']);
}else{
  $bearb_doz = $db->query ("SELECT doz_pwd FROM doz WHERE doz_nr=\"$ck_dozbe\"");
  $doz = $bearb_doz->fetch_array();
  $passwd = $doz['doz_pwd'];
}

$sql = $db->query ("UPDATE doz SET
                     doz_uid=\"". $_POST['doz_uid']."\"
                     , doz_name=\"". $_POST['doz_name']."\"
                     , doz_vorname=\"". $_POST['doz_vorname']."\"
                     , doz_titel=\"". $_POST['doz_titel']."\"
                     , doz_mail=\"". $_POST['doz_mail']."\"
                     , doz_strasse=\"". $_POST['doz_strasse']."\"
                     , doz_plz=\"". $_POST['doz_plz']."\"
                     , doz_ort=\"". $_POST['doz_ort']."\"
                     , doz_tel=\"". $_POST['doz_tel']."\"
                     , doz_pwd=\"$passwd\"
                     WHERE doz_nr=\"$ck_dozbe\"");

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>Bearbeiten erfolgreich</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\">Bearbeiten erfolgreich</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 erfolgreich vorgenommen</b>
                    </p>
                    <p align=\"center\"><a href=\"doz_bearb.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>";
//session_destroy();
} // Ende Action script

?>