-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeitenklasse_fahrer.php
executable file
·122 lines (104 loc) · 3.73 KB
/
Seitenklasse_fahrer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
require_once './Page.php';
class Bestellung extends Page
{
protected function __construct() {
parent::__construct();
}
protected function __destruct() {
parent::__destruct();
}
protected function getViewData() {
$sql = "SELECT b.BestellungID, b.Vorname, b.Nachname, b.Adresse, Bestellzeitpunkt, a.PizzaName, be.Status,SUM(a.Preis) AS Gesamtpreis
FROM
bestellung b, angebot a, bestelltepizza be
WHERE b.BestellungID = be.fBestellungID
AND be.fPizzaNummer = a.PizzaNummer
AND (be.Status = 'fertig' OR be.Status = 'unterwegs')
GROUP BY BestellungID";
$recordset = $this->database->query ($sql);
if (!$recordset)
throw new Exception("Abfrage fehlgeschlagen: ".$this->database->error);
// read selected records into result array
$bestellungen = array();
$record = $recordset->fetch_assoc();
while ($record) {
//$pizzen[] = $record["PizzaName"];
$bestellungen[] = $record;
$record = $recordset->fetch_assoc();
}
$recordset->free();
return $bestellungen;
}
private function insert_option($indent, $name){
echo ($indent."<option>".htmlspecialchars($name)."</option>\n");
}
protected function generateView() {
$bestellungen = $this->getViewData();
$this->generatePageHeader('Fahrer');
echo <<<EOT
<!-- Fahrer -->
<h2 id="head_fahrer">Fahrer (auslieferbare Bestellungen)</h2>
EOT;
for($i=0; $i < count($bestellungen); $i++)
{
// Alle Pizzen sind vom jeweiligen Kunden fertig
echo '<div class="Fahrerstatus">';
echo '<span>Vorname: '. htmlspecialchars($bestellungen[$i]["Vorname"]) .'</span><br>';
echo '<span>Nachname: '. htmlspecialchars($bestellungen[$i]["Nachname"]) .'</span><br>';
echo '<span>Adresse: '. htmlspecialchars($bestellungen[$i]["Adresse"]) .'</span><br>';
echo '<span>Bestellzeitpunkt: '. htmlspecialchars($bestellungen[$i]["Bestellzeitpunkt"]).'</span><br>';
echo '<span>Gesamtpreis: '. htmlspecialchars($bestellungen[$i]["Gesamtpreis"]).'</span><br>';
echo '<span>Status: '. htmlspecialchars($bestellungen[$i]["Status"]).'</span><br>';
$current_status_unterwegs = '';
if(htmlspecialchars($bestellungen[$i]["Status"])== 'unterwegs') $current_status_unterwegs = ' checked';
echo <<<EOT
<span class="span-radio">unterwegs</span>
<span class="span-radio">geliefert</span>
<br>
<form id="fomr'.$i.'" action="Seitenklasse_fahrer.php" method="POST" accept-charset="UTF-8">
<fieldset id="form'.$i.'">
<input type="radio" class="radio" name="radio-status" value="unterwegs" $current_status_unterwegs />
<input type="radio" class="radio" name="radio-status" value="geliefert"/>
<br>
<button type="submit" value="$i" name="index_bestellnummer">Update</button>
</fieldset>
</form>
</div>
EOT;
}
$this->generatePageFooter();
}
protected function processReceivedData() {
parent::processReceivedData();
{
if(isset($_POST['radio-status']))
{
if($_POST['radio-status']=="unterwegs" || $_POST['radio-status']=="geliefert")
{
$status = $_POST['radio-status'];
$fbestellungid = mysqli_real_escape_string($this->database,$this->getViewData()[$_POST['index_bestellnummer']]['BestellungID']);
$sql = "UPDATE `BestelltePizza` SET `Status`= '$status' WHERE fBestellungID='$fbestellungid'";
$recordset = $this->database->query($sql);
if (!$recordset)
{
throw new Exception("UPDATE fehlgeschlagen: ".$this->database->error);
}
}
}
}
}
public static function main() {
try {
$page = new Bestellung();
$page->processReceivedData();
$page->generateView();
}
catch (Exception $e) {
header("Content-type: text/plain; charset=UTF-8");
echo $e->getMessage();
}
}
}
Bestellung::main();
?>