<?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

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 die Soziale Kompetenze des Studienjahrgangs $stud_jahr[Jahrgang]</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 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 Soziale Kompetenze des Studienjahrgangs $jahrgang</font><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=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width=\"100%\" id=\"AutoNumber1\">
                    <tr>
                    <td width=\"5%\">
                    <p align=\"center\"><b>Nr.</b></p>
                    </td>
                    <td width=\"70%\">
                    <b>Bezeichnung</b>
                    </td>
                    <td width=\"13%\">
                    <p align=\"center\"><b>Tats&auml;chliche<br>Teilnehmerzahl</b>
                    </td>
                    <td width=\"12%\">
                    <p align=\"center\"><b>Max. Teil-<br />
                    nehmer</b></p>
                    </td>
                    <td width=\"10%\">
                    <p align=\"center\"><b>Anwesenheitsliste</b>
                    </td>
                    </tr>";
					$db = dbconnect();
					$query = "SELECT id, FPRNr, Bezeichnung, TN_max, bemerkung FROM sozkom_kompetenz where Jahr=\"$jahrgang\" order by FPRNr asc";
					$result = $db->query($query)
							   or die ("Cannot execute query");
					while ($row = $result->fetch_array()){
					if ( $res=$db->query("SELECT COUNT( * )
                                             FROM sozkom_wunsch, stud
                                            WHERE id =$row[id]
                                              AND Prioritaet = '0'
                                              AND sozkom_wunsch.uid = stud.uid
                                              AND stud.durchgefallen !='Y'") ){
					if ( $row1=$res->fetch_array() ) {
					$result1=$row1[0];
					} else $result1=0;
					} else $result1=0;

					echo "
                        <tr>
                      <td width=\"5%\" 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=\"70%\" 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\">
                      $row[Bezeichnung]<br>
                      <span class=\"bemerkung\">$row[bemerkung]</span>
                      </td>
                      <td valign=\"middle\" width=\"13%\" 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\">$result1
                      </td>
                      <td width=\"12%\" 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\" style=\"margin-top: 4; margin-bottom: 4\">
                      $row[TN_max]</p>
                      </td>";
                      $sel_doznr = $db->query("SELECT doz_nr FROM doz where doz_uid=\"$doz_uid1\"");
                      $doz_nr = $sel_doznr->fetch_array();
                      
                      $sel_id = $db->query("SELECT count(*) Anz FROM sozkom_doz where doz_nr='$doz_nr[0]' and id='$row[id]'");  // ID herausfinden &uuml;br doz_nr
                      $id = $sel_id->fetch_array();

                      if($id[0] > 0){
                      echo"
                      <td width=\"10%\" 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\" style=\"margin-top: 4; margin-bottom: 4\">
                      <a href='../admin/anwesenheit.php?id=$row[id]' target='blank'><img src='../images/ico_pdf.gif' border='0'></a>
                      </td>";
                      }else{
                      echo"
                      <td width=\"10%\" 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\" style=\"margin-top: 4; margin-bottom: 4\">
                      &nbsp;
                      </td>";
                      }
                      echo"
                    </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>
        </div>
        </td>
    </tr>
</table>

</body>

</html>";
?>
