<?php
class Termine {
    public function lesenAlleDaten() {
        $sql = "SELECT termine.termnr, kurs.titel AS Kursname, dozenten.name AS Dozentenname, termine.beginn, termine.ende, termine.dauer, termine.minanzahl, termine.maxanzahl, termine.vort FROM termine
        JOIN kurs ON termine.kursnr = kurs.kursnr
        JOIN dozenten ON termine.doznr = dozenten.doznr
        ORDER BY termine.beginn";
        
        $this->baueTerminTabelle($sql);
    }

    private function baueTerminTabelle($sql) {
        require("db.inc.php");

        if ($stmt = $pdo -> prepare($sql)) {
            $stmt -> execute();

            echo "<table id=\"zebra\">\n\t";
            echo "<thead>
            
            <tr>
            <th>Nummer</th><th>Kursname</th><th>Dozent</th><th>Beginn</th><th>Ende</th><th>Dauer</th><th>Min</th><th>Max</th><th>Raum</th><th>Bearbeiten</th>
            </tr> 
            </thead>";

            echo "<tbody>\n\t";
            $count = 0;

            while ($z = $stmt -> fetch()) {
                $count += 1;

                $zebratyp = "ungerade";

                echo "<tr ";

                if($count % 2 == 0) {
                    $zebratyp = "gerade";
                }
                
            echo "class=\"" .$zebratyp

            ."\">\n\t<td>"

            . htmlspecialchars($z['termnr'])

            ."</td>\n\t<td>"

            . htmlspecialchars($z['Kursname'])

            ."</td>\n\t<td>"

            . htmlspecialchars($z['Dozentenname'])

            ."</td>\n\t<td>"

            . htmlspecialchars($z['beginn'])

            ."</td>\n\t<td>"

            . htmlspecialchars($z['ende'])

            ."</td>\n\t<td>"

            . htmlspecialchars($z['dauer'])

            ."</td>\n\t<td>"

            . htmlspecialchars($z['minanzahl'])

            ."</td>\n\t<td>"

            . htmlspecialchars($z['maxanzahl'])

            ."</td>\n\t<td>"

            . htmlspecialchars($z['vort'])

            ."</td>\n\t<td>"

            ."<a href=\"terbearbeiten.php?termnr="

            .htmlspecialchars($z['termnr'])

            ."\">bearbeiten</a>"

            ."</td>\n</tr>";

            }

            echo "</tbody>\n</table>";
        }
    }
}
?>