<?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_dozdel'");
$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 l&ouml;schen</title>
</head>
<body onload=\"if(document.regist)document.regist.uid.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 l&ouml;schen</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=delete"; echo" method=\"POST\" name=\"doz_del\">
                      <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;</p>
                          </td>
                          <td width=\"25%\">
                          <p></p>
                          </td>
                        </tr>
                        <tr>
                          <td width=\"25%\">
                          <p></p>
                          </td>
                          <td width=\"50%\"colspan=\"2\">&nbsp;</td>
                          <td width=\"25%\">
                          <p></p>
                          </td>
                        </tr>
                        <tr>
                          <td width=\"25%\">
                          <p></p>
                          </td>
                          <td width=\"50%\" colspan=\"2\">
                          <p align=\"center\">
                          ";
                          $db = dbconnect();
                          $query = "SELECT doz_nr, doz_name, doz_vorname, doz_titel FROM doz order by doz_name";
                          $result = $db->query ($query)
                             or die ("Cannot execute query");
                          echo "<select size=\"5\" name=\"del\">";
                          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></p>
                          </td>
                        </tr>
                        <tr>
                          <td width=\"25%\">
                          <p></p>
                          </td>
                          <td width=\"50%\" colspan=\"2\" align=\"center\">
                          &nbsp;</td>
                          <td width=\"25%\">
                          <p></p>
                          </td>
                        </tr>
                        <tr>
                          <td width=\"25%\">
                          </td>
                          <td width=\"50%\" colspan=\"2\" align=\"center\">
                          <input type=\"submit\" value=\"L&ouml;schen\" 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>
                      </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 "delete":

if ($_POST[del] == "") {  // Abfrage wenn kein Dozent angeklickt wurde
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>Keine Auswahl</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\">Keine Auswahl</span><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
                    <p align=\"center\"><b>Sie m&uuml;ssen zuerst einen Dozent anklicken!</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;
}

$db = dbconnect();

    $abfr_dozkurs = $db->query ("SELECT KursNr, doz_nr FROM doz_kurs WHERE doz_nr=$_POST[del]");
    $belegt_kurs = $abfr_dozkurs->fetch_array();

    $abfr_Wpfdoz = $db->query ("SELECT id, doz_nr FROM wpf_doz WHERE doz_nr=$_POST[del]");
    $belegt_wpf = $abfr_Wpfdoz->fetch_array();

    $abfr_prsdoz = $db->query ("SELECT id, doz_nr FROM pros_doz WHERE doz_nr=$_POST[del]");
    $belegt_pros = $abfr_prsdoz->fetch_array();
    
    $abfr_verdoz = $db->query ("SELECT verid, doz_nr FROM ver_doz WHERE doz_nr=$_POST[del]");
    $belegt_ver = $abfr_verdoz->fetch_array();

if ($belegt_kurs == "" and $belegt_wpf =="" and $belegt_pros == "" and $belegt_ver == ""){
                $sql = $db->query ("DELETE FROM doz WHERE doz_nr =$_POST[del];");

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 gel&ouml;scht</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\">Dozent gel&ouml;scht</span><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
                    <p align=\"center\"><b>Der Dozent wurde aus dem System gel&ouml;scht!</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>";


} 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>>Dozent l&ouml;schen</title>
</head>
<body onload=\"if(document.regist)document.regist.uid.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 l&ouml;schen</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=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width=\"100%\">
                      <tr>
                        <td width=\"100%\" style=\"border-style: none; border-width: medium\" height=\"30\" colspan=\"2\"><br>
                        Der Dozent kann kann nicht gel&ouml;scht werden, da er noch f&uuml;r
                        folgende Kurse / Wahlpflichtf&auml;cher oder Fachprojekte zugeteilt ist:<br>
                        </td>
                      </tr>
                      <tr>
                        <td width=\"20%\"  style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 3px\">
                        <b>Nr.</b>
                        </td>
                        <td width=\"80%\"  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: 3px\">
                        <b>Bezeichnung</b>
                        </td>
                      </tr>";
                      $db = dbconnect();
                        $query = "SELECT kurs.kursnr, kurs.beschreibung 
                                    FROM doz_kurs,kurs
                                   WHERE doz_kurs.doz_nr = $_POST[del]
                                     AND doz_kurs.kursnr = kurs.kursnr";
                        $result = $db->query($query)
                               or die ("Cannot execute query");
                       while ($row1 = $result->fetch_array()){

                      echo "
                      <tr>
                        <td width=\"20%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                        Kurs: $row1[0]
                        </td>
                        <td width=\"80%\" 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\">
                        $row1[1]
                        </td>
                      </tr>";
                        }
                        $query1 = "SELECT wpf.wpfnr, wpf.id, wpf.Bezeichnung, wpf.jahr 
                                     FROM wpf_doz,wpf
                                    WHERE wpf_doz.doz_nr = $_POST[del]
                                      AND wpf_doz.id = wpf.id";
                        $result1 = $db->query($query1)
                               or die ("Cannot execute query1");
                       while ($row2 = $result1->fetch_array()){

                      echo "
                      <tr>
                        <td width=\"20%\"  style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                        Wpf: $row2[0]/$row2[3]
                        </td>
                        <td width=\"80%\"  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\">
                        $row2[2]
                        </td>
                      </tr>";
                        }
                        $query2 = "SELECT pros_proseminar.psnnr, pros_proseminar.id, pros_proseminar.Bezeichnung, pros_proseminar.Jahr 
                                     FROM fach_doz, pros_proseminar
                                    WHERE fach_doz.doz_nr = $_POST[del]
                                      AND fach_doz.id = pros_proseminar.id";
                        $result2 = $db->query($query2)
                               or die ("Cannot execute query2");
                       while ($row3 = $result2->fetch_array()){

                      echo "
                      <tr>
                        <td width=\"20%\"  style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                        Psn: $row3[0]/$row3[3]
                        </td>
                        <td width=\"80%\"  style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                        $row3[2]
                        </td>
                      </tr>";
                        }
                        
                        $query3 = "SELECT veranstaltung.VerID, veranstaltung.Bezeichnung
                                     FROM ver_doz, veranstaltung
                                    WHERE ver_doz.doz_nr = $_POST[del]
                                      AND ver_doz.VerID = veranstaltung.VerID";
                        $result3 = $db->query($query3)
                               or die ("Cannot execute query3");
                       while ($row4 = $result3->fetch_array()){

                      echo "
                      <tr>
                        <td width=\"20%\"  style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
                        VerID: $row4[0]
                        </td>
                        <td width=\"80%\"  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\">
                        $row4[1]
                        </td>
                      </tr>";
                        }
                      echo "
                    </table>
                    <p align=\"center\"><a href=\"doz_del.php\">
                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a></p>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\">
                    <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 if, wenn Dozent noch f&uuml;r Kurse eingeteilt ist



} // Ende Action script

?>