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

if ($jahrgang == ""){ require("jahrgang.php"); exit;} //Wenn man kein Jahrgang ausgew&auml;hlt hat wird die Jahrgangsauswahlseite geladen
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 stan_admin_rechte, stan_admin_rechte_zuord , stan_admin where stan_admin_rechte.stan_admin_rolle = stan_admin_rechte_zuord.stan_admin_rolle AND stan_admin_rechte_zuord.said = stan_admin.said AND stan_admin.user = '$user_admin' AND stan_admin_rechte_zuord.stan_admin_rolle = 'a_wlist'");
$row = $result->fetch_array();
if ($row[0] != 1){ include("kurs/rechte.php"); exit;}
// Rechte&uuml;berpr&uuml;fung ende

 
$sort = $_GET["sort"];

if(!isset($sort)){
 $sort = "nachname";
}

$db = dbconnect();

$result2 = $db->query("SELECT count(*) anz
                          FROM stud a
                         WHERE stg = 'W'
                           AND a.jahrgang='$jahrgang'
                           AND a.durchgefallen='N'");
           
$row2 = $result2->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>&Uuml;bersicht &uuml;ber zugewiesene PU-Standorte $stud_jahr[Jahrgang]</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"90%\">
    <tr>
        <td>
        <div align=\"center\">
            <a href=\"anschreiben/listendruck_w.php?sort=$sort\" target='_blank'><img src=\"../images/ico_pdf.gif\" border=\"0\"></a>
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"90%\" 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\">&Uuml;bersicht &uuml;ber die Studenten des W-Zweiges Jahrgang $jahrgang</font><br>
                    <span class=\"sh\">Anzahl: $row2[anz]</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>
            <table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width=\"100%\">
              <tr>
                <td width=\"60%\" 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\">
                  ";
                  if($sort == 'nachname'){
                    echo "<font size=\"2\"><a href=$_SERVER[PHP_SELF]?sort=nachname><b>Name, Vorname</b></a></font>";
                  }else{
                    echo "<font size=\"2\"><a href=$_SERVER[PHP_SELF]?sort=nachname>Name, Vorname</a></font>";
                  }
                  echo"
                </td>
                <td width=\"20%\" 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\">
                ";
                if($sort == 'ag'){
                  echo"<font size=\"2\"><a href=$_SERVER[PHP_SELF]?sort=ag><b>AG</b></a></font>";
                }else{
                  echo"<font size=\"2\"><a href=$_SERVER[PHP_SELF]?sort=ag>AG</a></font>";
                }
                echo"
                </td>
                <td width=\"20%\" 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\">
                ";
                if($sort == 'stg'){
                  echo"<font size=\"2\"><a href=$_SERVER[PHP_SELF]?sort=stg><b>Zweig</b></a></font>";
                }else{
                  echo"<font size=\"2\"><a href=$_SERVER[PHP_SELF]?sort=stg>Zweig</a></font>";
                }
                echo"
                </td>
              </tr>";


                $db = dbconnect();
                $query = "SELECT a.uid, a.nachname, a.vorname, a.ag, a.jahrgang, a.stg
                            FROM stud a
                           WHERE stg = 'W'
                             AND a.jahrgang='$jahrgang'
                             AND a.durchgefallen='N'
                           ORDER BY $sort, nachname";
                $result = $db->query($query)
                       or die ("Cannot execute query");
               while ($row = $result->fetch_array()){

                echo "
              <tr>
                <td width=\"60%\" 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\">
                <font size=\"2\">$row[nachname], $row[vorname]</font>
                </td>
                <td width=\"20%\" 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\">
                <font size=\"2\">$row[ag]/$row[jahrgang]</font></td>
                <td width=\"20%\" 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\">
                <font size=\"2\">$row[stg]</font></td>
              </tr>";
                   }

            echo "


            </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>
            <br>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
?>