Voll Upload SGD Fachinformatiker PHP
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
class Buchung {
|
||||
private $tabelle = "buchung";
|
||||
|
||||
public function lesenAlleDaten() {
|
||||
$sql = "SELECT buchung.bnummer, kurs.titel AS kursTitel, dozenten.name AS dozentenName, termine.beginn, termine.ende, teilnehmer.name AS teilnehmerName, teilnehmer.vname AS teilnehmerVorname FROM buchung
|
||||
JOIN termine ON buchung.termnr = termine.termnr
|
||||
JOIN teilnehmer ON buchung.tnummer = teilnehmer.tnummer
|
||||
JOIN kurs ON termine.kursnr = kurs.kursnr
|
||||
JOIN dozenten ON termine.doznr = dozenten.doznr
|
||||
ORDER BY buchung.bnummer";
|
||||
|
||||
$this->baueBuchungTabelle($sql);
|
||||
}
|
||||
|
||||
private function baueBuchungTabelle($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>Kurs</th><th>Dozent</th><th>Beginn</th><th>Ende</th><th>Name</th><th>Vorname</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['bnummer'])
|
||||
|
||||
."</td>\n\t<td>"
|
||||
|
||||
. htmlspecialchars($z['kursTitel'])
|
||||
|
||||
."</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['teilnehmerName'])
|
||||
|
||||
."</td>\n\t<td>"
|
||||
|
||||
. htmlspecialchars($z['teilnehmerVorname'])
|
||||
|
||||
."</td>\n\t<td>"
|
||||
|
||||
."<a href=\"bbearbeiten.php?bnummer="
|
||||
|
||||
.htmlspecialchars($z['bnummer'])
|
||||
|
||||
."\">bearbeiten</a>"
|
||||
|
||||
."</td>\n</tr>";
|
||||
|
||||
}
|
||||
|
||||
echo "</tbody>\n</table>";
|
||||
}
|
||||
}
|
||||
|
||||
public function lesenDatensatz($id) {
|
||||
require("db.inc.php");
|
||||
|
||||
$sql = "SELECT buchung.bnummer, termine.termnr, kurs.titel, dozenten.name, termine.beginn, termine.ende, teilnehmer.name, teilnehmer.vname FROM $this->tabelle
|
||||
JOIN termine ON buchung.termnr = termine.termnr
|
||||
JOIN teilnehmer ON buchung.tnummer = teilnehmer.tnummer
|
||||
JOIN kurs ON termine.kursnr = kurs.kursnr
|
||||
JOIN dozenten ON termine.doznr = dozenten.doznr
|
||||
WHERE buchung.bnummer=:bnummer";
|
||||
|
||||
if($stmt = $pdo->prepare($sql)) {
|
||||
$stmt->bindParam(':bnummer', $id);
|
||||
$stmt->execute();
|
||||
return($stmt->fetch(PDO::FETCH_ASSOC));
|
||||
} else {
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function einfuegenSelect($tab, $val, $text, $def) {
|
||||
$s = "<select name =\"" .$val . "\" id= \"" . $val . "\">";
|
||||
|
||||
require("db.inc.php");
|
||||
|
||||
$sql = "SELECT " .$val . ", " . $text . " FROM " .$tab;
|
||||
|
||||
if ($stmt = $pdo->prepare($sql)) {
|
||||
$stmt->execute();
|
||||
|
||||
while ($z = $stmt->fetch()) {
|
||||
$s = $s . "<option value=\"" . $z[0] . "\"";
|
||||
|
||||
if($z[0] == $def) {
|
||||
$s = $s . " selected";
|
||||
}
|
||||
|
||||
$s = $s . ">" . $z[0] ." | " . $z[1] ."</option>";
|
||||
}
|
||||
$s = $s . "</select>";
|
||||
|
||||
return $s;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function anlegen() {
|
||||
require("db.inc.php");
|
||||
|
||||
$bnummer = NULL;
|
||||
$termnr = $_POST["termnr"];
|
||||
$tnummer = $_POST["tnummer"];
|
||||
|
||||
$sql= "INSERT INTO .$this->tabelle (bnummer,
|
||||
termnr,
|
||||
tnummer)
|
||||
VALUES (:bnummer, :termnr, :tnummer)";
|
||||
|
||||
if($stmt = $pdo->prepare($sql)) {
|
||||
|
||||
$param = array(
|
||||
':bnummer' => $bnummer,
|
||||
':termnr' => $termnr,
|
||||
':tnummer' => $tnummer,
|
||||
);
|
||||
|
||||
if($stmt->execute($param)) {
|
||||
echo "<h2>Datensatz gespeichert</h2>";
|
||||
} else {
|
||||
echo "<h2>Fehler beim speichern!</h2>";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public function bearbeiten(){
|
||||
require("db.inc.php");
|
||||
|
||||
$bnummer = $_POST["mode"];
|
||||
$termnr = $_POST["termnr"];
|
||||
$tnummer = $_POST["tnummer"];
|
||||
|
||||
$sql= "UPDATE " . $this->tabelle . " SET termnr = :termnr, tnummer = :tnummer WHERE bnummer = :bnummer";
|
||||
|
||||
if($stmt = $pdo->prepare($sql)) {
|
||||
|
||||
$param = array(
|
||||
':bnummer' => $bnummer,
|
||||
':termnr' => $termnr,
|
||||
':tnummer' => $tnummer,
|
||||
);
|
||||
|
||||
if($stmt->execute($param)) {
|
||||
echo "<h2>Datensatz gespeichert</h2>";
|
||||
}
|
||||
else {
|
||||
echo "<h2>Fehler beim speichern!</h2>";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user