<?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 sozkom_admin_rechte, sozkom_admin_rechte_zuord , sozkom_admin where sozkom_admin_rechte.sozkom_admin_rolle = sozkom_admin_rechte_zuord.sozkom_admin_rolle AND sozkom_admin_rechte_zuord.faid = sozkom_admin.faid AND sozkom_admin.user = '$user_admin' AND sozkom_admin_rechte_zuord.sozkom_admin_rolle = 'a_studlog'");
$row = $result->fetch_array();
if ($row[0] != 1){ include("kurs/rechte.php"); exit;}
// Rechte&uuml;berpr&uuml;fung ende

$table    = "sozkom_studlog";    // Der Name der Datenbanktabelle

// Datendefinition f&uuml;r die Clientausgabe
$start = (isset($_GET['start'])) ? abs((int)$_GET['start']) : 0;

$limit = 13;                     // Datens&auml;tze pro Ausgabeseite

// Feststellen der Anzahl der verf&uuml;gbaren Datens&auml;tze.
$resultID = @$db->query("SELECT COUNT(*) Anz FROM ".$table);
$rowID    = @$resultID->fetch_array();
$total    = $rowID['Anz'];

// Ggf. $start korrigieren (falls Parameter in
// der URL manipuliert wurde)
$start    = ($_GET['start'] >= $total) ? $total - $limit : $start;


// Datenbankabfrage ausf&uuml;hren.
$query    = "SELECT datum as datorder, DATE_Format(datum, '%d.%m.%Y') as datum, DATE_Format(datum, '%H:%i:%s')AS zeit,IP,UID,Jahrgang FROM ".$table." ORDER BY datorder DESC"
           ." LIMIT ".$start.",".$limit;
$resultID = @$db->query($query);

// Ergebnisse lesen und an den Client ausgeben



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 Wahlpflichtf&auml;cher Studienjahrgang $stud_jahr[Jahrgang]</title>
</head>

<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"95%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table valign=\"top\" 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 Logins</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 valign=\"top\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width=\"100%\" id=\"AutoNumber1\">
                    <tr>
                    <td width=\"20%\">
                    <p align=\"left\"><b>Datum</b></p>
                    </td>
                    <td width=\"20%\">
                    <b>Uhrzeit</b>
                    </td>
                    <td width=\"15%\">
                    <b>IP-Adresse</b>
                    </td>
                    <td width=\"15%\">
                    <p align=\"center\"><b>Benutzername</b></p>
                    </td>
                    </td>
                    <td width=\"30%\">
                    <p align=\"center\"><b>Jahrgang</b></p>
                    </td>
                    </tr>";
                      while ($data = $resultID->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\">
                      <p align=\"left\">
                      $data[datum]</p>
                      </td>
                      <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\">
                      $data[zeit]<br>
                      </td>
                      <td valign=\"middle\" width=\"15%\" 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\">
                      $data[IP]
                      </td>
                      <td width=\"15%\" 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\">
                      $data[UID]
                      </td>
                      </td>
                      <td width=\"30%\" 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\">
                      $data[Jahrgang]
                      </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>
        </div>
        </td>
    </tr>
</table>
</body>
</html>
";

$show = ceil($total/$limit);           //Seitenzahlen aufrunden
$last = floor($total/$limit)*$limit;   //Sprungziel zur letzten Seite BSP abrunden(1954/13)*13 ==> 150*13=1950 Sprungmarke auf Zeile 1950, 4 DS werden angezeigt
$akt = round((($start-$limit)/$limit+2),0);

echo"<div align=center>";
// Zur&uuml;ck- und Vorbl&auml;ttern
if ($start > 0)
{
  $newStart = ($start - $limit < 0) ? 0 : ($start-$limit); // wenn $start-$limit kleiner 0 dann $newstart=0 sonst $start-$limit
  echo "<a href=".$_SERVER['PHP_SELF']."?start=0><img border=\"0\" src=\"../images/left_first.gif\"></a>";
  echo "<a href=".$_SERVER['PHP_SELF']."?start=$newStart><img border=\"0\" src=\"../images/left.gif\"></a>";
      
}else{
   echo"<img border=\"0\" src=\"../images/left_first_grey.gif\">";
   echo"<img border=\"0\" src=\"../images/left_grey.gif\">";
}

echo"$akt/$show";

if ($start + $limit < $total)
{
  $newStart = $start + $limit;
  echo "<a href=".$_SERVER['PHP_SELF']."?start=$newStart><img border=\"0\" src=\"../images/right.gif\"></a>";
  echo "<a href=".$_SERVER['PHP_SELF']."?start=$last><img border=\"0\" src=\"../images/right_last.gif\"></a>";
}else{
   echo"<img border=\"0\" src=\"../images/right_grey.gif\">";
   echo"<img border=\"0\" src=\"../images/right_last_grey.gif\">";
}
echo"</div>";
?>