<?php
$jahrgang=$_COOKIE["jahrgang"];
$doz_uid1=$_COOKIE["doz_uid1"];

if ($jahrgang == ""){ require("jahrgang_doz.php"); exit;} //Wenn man nicht angemeldet ist soll man nichts ausw&auml;hlen k&ouml;nnen
if ($doz_uid1 == ""){ include("kurs/anmeldefehler_subdir.php"); exit;} //Wenn man nicht angemeldet ist soll man nichts ausw&auml;hlen k&ouml;nnen

include("kurs/datenbankanbindung.php");     // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
$db = dbconnect();
// &Uuml;Berpr&uuml;fung, ob die Anmeldefrist &uuml;berschritten ist
$heute  = mktime(0, 0, 0, date("m"), date("d"), date("Y"));  // heutiges Datum
$heute_format = date("Y-m-d", $heute);  // ISO-8601 Format wie in der Datenbank: Formatierung f&uuml;r Vergleiche erforderlich

$anm_schluss = $db->query("SELECT DATE_Format(proseminar_einsicht, '%Y-%m-%d')AS datum, DATE_Format(proseminar_einsicht, '%d.%m.%Y')AS einsicht1 FROM pros_ende where jahrgang=\"$jahrgang\"");
$row_schluss = $anm_schluss->fetch_array(); // Herausfinden des Beginndatums des vom Studenten gew&auml;hlten Kurses

$a = strtotime ($heute_format); //Umrechnung des Fristgrenztages in eine Zahl
$b = strtotime ($row_schluss[datum]); // Umrechnung des Beginndatums in eine Zahl

if ($a < $b){
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>Zugang gesperrt</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\">Zugang gesperrt</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 Adressliste der Proseminare kann nicht vor<br>$row_schluss[einsicht1]<br>abgerufen werden!</b>
                    </p>
                    <p align=\"center\"><a href=\"hauptframe_jahr.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>";
exit;
} // Ende &Uuml;berpr&uuml;fung der Zeit&uuml;berschreitung




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>Proseminarbescheinigung</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=\"100%\" border=\"0\">
                <tr>
                    <td align=\"left\" width=\"1%\" width=\"10\" background=\"../images/box_e1.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td align=\"left\" width=\"98%\" background=\"../images/box_top.gif\" valign=\"top\" colspan=\"2\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Proseminarbescheinigung</font>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td 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\">
					<form action="; echo $_SERVER['PHP_SELF'] . "?action=ausgabe"; echo" method=\"POST\" name=\"PSN_bearb\">
					<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width=\"100%\">
                        <tr>
                            <td width=\"8%\" rowspan=\"2\" 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\">
                            <p align=\"center\"><b>FPRNr</b></p>
                            </td>
                            <td width=\"56%\" rowspan=\"2\" 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\">
                            <b>
                            <p>Bezeichnung</p>
                            </b></td>
                            <td width=\"24%\" style=\"border-top-color: #111111; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium; border-right-style:none; border-right-width:medium\">
                            <b>
                            <p align=\"center\">Teilnehmer</p>
                            </b></td>
                            <td width=\"12%\" align=\"center\" rowspan=\"2\" 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\">
                            <b>Auswahl</b></td>
                        </tr>
                        <tr>
                            <td width=\"24%\" 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\">
                            <p align=\"center\"><b>Ist / Max </b></p>
                            </td>
                        </tr>";

							$db = dbconnect();

							$sel_doznr = $db->query("SELECT doz_nr FROM doz where doz_uid=\"$doz_uid1\"");
							$doz_nr = $sel_doznr->fetch_array();
							$sel_id = "SELECT id FROM pros_doz where doz_nr=\"$doz_nr[0]\"";  // ID herausfinden &uuml;br doz_nr
							$id = $db->query($sel_id)
								  or die ("Cannot execute ID");
							while ($row_id = $id->fetch_array()){           //Schleife1 diverse IDs durchlaufen
							$query = "SELECT id, FPRNr, Bezeichnung, Zweig, TN_max FROM pros_proseminar where Jahr=\"$jahrgang\" and id=\"$row_id[id]\" order by FPRNr asc"; //ID kann doppelt belegt sein
							$result = $db->query($query)
									  or die ("Cannot execute query");
							while ($row = $result->fetch_array()){   // Schleife2 Bezeichnung usw. anahnd der gelscheiften ID ausgeben
                                if ( $res=$db->query("SELECT COUNT( * )
                                                               FROM pros_wunsch, stud
                                                              WHERE id =$row[id]
                                                                AND Prioritaet = '0'
                                                                AND pros_wunsch.uid = stud.uid
                                                                AND stud.durchgefallen !='Y'") ){
								if ( $row1=$res->fetch_array() ) {
								$result_ist=$row1[0];
								} else $result_ist=0;
								} else $result_ist=0;
							echo "
                            <td width=\"8%\" 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\">
                            <p align=\"center\">$row[FPRNr]</p>
                            </td>
                            <td width=\"56%\" 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\">
                            <p>$row[Bezeichnung]<span class=\"bemerkung\"><br>
                            $row[bemerkung]</span></p>
                            </td>
                            <td width=\"24%\" 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\">
                            <p align=\"center\">$result_ist&nbsp;&nbsp; /&nbsp;&nbsp;
                            $row[TN_max]</p>
                            </td>
                            <td width=\"12%\" align=\"center\" 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\">
                            <p>";
                           $split = str_split($row[Zweig]);
                            $vt1 = $split[0];  // I
                            $vt2 = $split[1];  // R
                            $vt3 = $split[2];  // F
                            $vt4 = $split[3];  // S

                            $db = dbconnect();
                            $dat_vt1 = $db->query("SELECT proseminar_einsicht, DATE_Format(proseminar_einsicht, '%d.%m.%Y') pros_einsicht_form FROM pros_ende WHERE stg='$vt1' AND jahrgang='$jahrgang'");
                            $row_dat1 = $dat_vt1->fetch_array();
                            
                            $dat_vt2 = $db->query("SELECT proseminar_einsicht, DATE_Format(proseminar_einsicht, '%d.%m.%Y') pros_einsicht_form FROM pros_ende WHERE stg='$vt2' AND jahrgang='$jahrgang'");
                            $row_dat2 = $dat_vt2->fetch_array();
                            
                            $dat_vt3 = $db->query("SELECT proseminar_einsicht, DATE_Format(proseminar_einsicht, '%d.%m.%Y') pros_einsicht_form FROM pros_ende WHERE stg='$vt3' AND jahrgang='$jahrgang'");
                            $row_dat3 = $dat_vt3->fetch_array();
                            
                            $dat_vt4 = $db->query("SELECT proseminar_einsicht, DATE_Format(proseminar_einsicht, '%d.%m.%Y') pros_einsicht_form FROM pros_ende WHERE stg='$vt4' AND jahrgang='$jahrgang'");
                            $row_dat4 = $dat_vt4->fetch_array();
                            
                            $d1 = strtotime ($row_dat1[proseminar_einsicht]);
                            $d2 = strtotime ($row_dat2[proseminar_einsicht]);
                            $d3 = strtotime ($row_dat3[proseminar_einsicht]);
                            $d4 = strtotime ($row_dat4[proseminar_einsicht]);
                            
                            
                            if($d2!=''){
                             if($d1 < $d2){
                             $dat1 = $d1;
                             }else{
                             $dat1 = $d2;
                             }
                            }else{
                             $dat1 = $d1;  // dann gibts nur ein Bereich
                            }
                            
                            
                            if($d3!=''){
                             if($dat1 < d3){
                             $dat1 = $dat1;
                             }else{
                             $dat1 = $d3;
                             }
                            }
                            
                            if($d4!=''){
                            if($dat1 < d4){
                            $dat1 = $dat1;
                            }else{
                            $dat1 = $d4;
                            }
                            }
                            
                            $heute  = mktime(0, 0, 0, date("m"), date("d"), date("Y"));  // heutiges Datum
			    $heute_format = date("Y-m-d", $heute);  // ISO-8601 Format wie in der Datenbank: Formatierung f&uuml;r Vergleiche erforderlich
			    
			    $a = strtotime ($heute_format); //Umrechnung des Fristgrenztages in eine Zahl
                            
                            if($a>=$dat1){
                             echo"<input type=\"radio\" value=\"$row[id]\" name=\"ausw_ausg\" size=\"20\">";
                            }else{
                             echo "> ".date("d.m.Y", $dat1);
                            }
                            echo"
                            </td>
                        </tr>";
					   }
					   }
					  echo "
					  </table>
					  <br>
					  <input type=\"submit\" value=\"Abschicken\" name=\"B1\" size=\"20\"></p>
					  </form>
                      </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";

break;
case "ausgabe":

$db = dbconnect();
$sel_pros = $db->query("SELECT Bezeichnung FROM pros_proseminar where id=\"". $_POST['ausw_ausg']."\"");  // ausw_ausg =  proseminar.id
$pros = $sel_pros->fetch_array();

$abfrage = "SELECT stud.uid, Vorname, Nachname, AG, Jahrgang 
              FROM stud LEFT JOIN pros_ergebnis 
             USING ( uid ) 
             WHERE pros_ergebnis.uid = stud.uid 
               AND pros_ergebnis.id =  \"". $_POST['ausw_ausg']."\"
               AND stud.durchgefallen !='Y'
           ";

setcookie ("ck_ProsID", $_POST[ausw_ausg]);

echo "
<html>
<head>
<meta http-equiv=\"Content-Language\" content=\"de\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Ausgabe</title>
</head>

<body>

<span class=\"uberschrift\">Prosemianrbescheinigung</Span><br>
<b>$pros[Bezeichnung]</b></p>
<p>&nbsp;</p>
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" collapse bordercolor=\"#111111\" width=\"614\" id=\"AutoNumber1\" style=\"border-collapse: collapse\">
  <tr>
    <td width=\"13%\" class=\"contentfarbe\" style=\"padding-left:4; padding-right:4; padding-top:1; padding-bottom:1; border-left-style:solid; border-left-width:1; border-right-width:1; border-top-width:1; border-bottom-width:1\" height=\"20\">
    <p style=\"margin-left: 6; margin-top:4; margin-bottom:4\"><b>Vorname</b></p>
    </td>
    <td width=\"13%\" class=\"contentfarbe\" style=\"padding-left:4; padding-right:4; padding-top:1; padding-bottom:1; border-left-style:solid; border-left-width:1; border-right-width:1; border-top-width:1; border-bottom-width:1\" height=\"20\">
    <p style=\"margin-left: 6; margin-top:4; margin-bottom:4\"><b>Nachname</b></p>
    </td>
    <td width=\"9%\" align=\"left\" class=\"contentfarbe\" style=\"padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1; border-left-style:none; border-left-width:medium; border-top-width:1; border-bottom-width:1\" height=\"20\">
    <p style=\"margin-top: 4; margin-bottom: 4\"><b>AG</b></p>
    </td>
    <td width=\"65%\" align=\"center\" class=\"contentfarbe\" style=\"padding-left:4; padding-right:4; padding-top:1; padding-bottom:1; border-left-style:solid; border-left-width:1; border-right-width:1; border-top-width:1; border-bottom-width:1\" height=\"20\">
    <p style=\"margin-top: 4; margin-bottom: 4\"><b>Thema</b></p>
    </td>
  </tr>
  <tr>";
    $db = dbconnect();

    $sql = $db->query($abfrage); // $result= Alle Studenten, die das ausgew&auml;hlte proseminar belegt haben
    while ($res_ausg = $sql->fetch_array()){

    $sel_daten = $db->query("SELECT Thema, Note FROM pros_ergebnis where uid=\"$res_ausg[uid]\" and id=\"". $_POST['ausw_ausg']."\"");  // ausw_ausg =  proseminar.id
	$daten = $sel_daten->fetch_array();

    echo "
    <td width=\"13%\" style=\"padding-left:4; padding-right:4; padding-top:1; padding-bottom:1; border-left-style:none; border-left-width:medium\" height=\"21\">
    <p style=\"margin-left: 6; margin-top: 4; margin-bottom: 4\">$res_ausg[Vorname]
    </td>
    <td width=\"13%\" style=\"padding-left:4; padding-right:4; padding-top:1; padding-bottom:1; border-left-style:none; border-left-width:medium\" height=\"21\">
    <p style=\"margin-left: 6; margin-top: 4; margin-bottom: 4\">$res_ausg[Nachname]
    </td>
    <td width=\"9%\" align=\"left\" style=\"padding-left:4; padding-right:4; padding-top:1; padding-bottom:1; border-left-style:none; border-left-width:medium\" height=\"21\">
    <p style=\"margin-top: 4; margin-bottom: 4\">$res_ausg[AG]/$res_ausg[Jahrgang]
    </td>
    <td width=\"65%\" align=\"center\" style=\"padding-left:4; padding-right:4; padding-top:1; padding-bottom:1; border-left-style:solid; border-left-width:1\" height=\"21\">
    <p style=\"margin-top: 4; margin-bottom: 4\" align=\"left\">
    $daten[Thema]
    </td>

  </tr>";
  }
  echo"
  </table>
  <br><a href=\"../admin/proseminarscheine/seminarscheine.php\"><img border=\"0\" src=\"../images/proseminardruck.gif\"></a>
</body>

</html>";
} //Ende Action Abfrage
?>