-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPage.php
231 lines (200 loc) · 6.72 KB
/
Page.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php // UTF-8 marker äöüÄÖÜ߀
/**
* Class Page for the exercises of the EWA lecture
* Demonstrates use of PHP including class and OO.
* Implements Zend coding standards.
* Generate documentation with Doxygen or phpdoc
*
* PHP Version 5
*
* @category File
* @package Pizzaservice
* @author Bernhard Kreling, <[email protected]>
* @author Ralf Hahn, <[email protected]>
* @license http://www.h-da.de none
* @Release 1.2
* @link http://www.fbi.h-da.de
*/
/**
* This abstract class is a common base class for all
* HTML-pages to be created.
* It manages access to the database and provides operations
* for outputting header and footer of a page.
* Specific pages have to inherit from that class.
* Each inherited class can use these operations for accessing the db
* and for creating the generic parts of a HTML-page.
*
* @author Bernhard Kreling, <[email protected]>
* @author Ralf Hahn, <[email protected]>
*/
abstract class Page
{
// --- ATTRIBUTES ---
/**
* Reference to the MySQLi-Database that is
* accessed by all operations of the class.
*/
protected $_database = null;
// --- OPERATIONS ---
/**
* Connects to DB and stores
* the connection in member $_database.
* Needs name of DB, user, password.
*
* @return none
*/
protected function __construct()
{
// activate full error checking
error_reporting(E_ALL);
// open database
$host = "localhost";
$user = "root";
$pwd = "";
$this->database = new MySQLi($host, $user, $pwd, "pizzaservice");
// check connection to database
if (mysqli_connect_errno()) {
throw new Exception("Keine Verbindung zur Datenbank: " . mysqli_connect_error());
}
// set character encoding to UTF-8
if (!$this->database->set_charset("utf8")) {
throw new Exception("Fehler beim Laden des Zeichensatzes UTF-8: " . $this->database->error);
}
}
/**
* Closes the DB connection and cleans up
*
* @return none
*/
protected function __destruct()
{
// to do: close database
$this->database->close();
}
/**
* Generates the header section of the page.
* i.e. starting from the content type up to the body-tag.
* Takes care that all strings passed from outside
* are converted to safe HTML by htmlspecialchars.
*
* @param $headline $headline is the text to be used as title of the page
*
* @return none
*/
protected function generatePageHeader($headline = "")
{
$headline = htmlspecialchars($headline);
$kunde_active = '';
$bestellung_active = '';
$fahrer_active = '';
$pizzabäcker_active = '';
$index_active = '';
if ($headline == 'Pizzabäcker') {
$pizzabäcker_active = 'active';
}
if ($headline == 'Bestellung') {
$bestellung_active = 'active';
}
if ($headline == 'Kunde') {
$kunde_active = 'active';
}
if ($headline == 'Fahrer') {
$fahrer_active = 'active';
}
if ($headline == 'Index') {
$index_active = 'active';
}
header("Content-type: text/html; charset=UTF-8");
// to do: output common beginning of HTML code
// including the individual headline
// output HTML header
echo <<<EOT
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8"/>
EOT;
if ($headline == 'Fahrer') {
echo '<meta http-equiv="refresh" content="7; url=Seitenklasse_fahrer.php" />';
}
if ($headline == 'Pizzabäcker') {
echo '<meta http-equiv="refresh" content="7; url=Seitenklasse_pizzabaecker.php" />';
}
echo <<<EOT
<title>$headline</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
</head>
<body>
<header class="header">
<div class="wrap">
<h2 class="logo"><a href="Seitenklasse_index.php">Pi<span>zz</span>a</a></h2>
<a id="menu-icon">☰ Menu</a>
<nav class="navbar">
<ul class="menu">
<li><a class="$index_active" href="Seitenklasse_index.php">Home</a></li><!--
--><li><a class="$bestellung_active" href="Seitenklasse_bestellung.php">Bestellung</a></li><!--
--><li><a class="$kunde_active" href="Seitenklasse_kunde.php">Kunde</a></li><!--
--><li><a class="$pizzabäcker_active " href="Seitenklasse_pizzabaecker.php">Pizzabäcker</a></li><!--
--><li><a class="$fahrer_active" href="Seitenklasse_fahrer.php">Fahrer</a></li>
</ul>
</nav>
</div>
</header>
<script src="./script.js"></script>
EOT;
}
/**
* Outputs the end of the HTML-file i.e. /body etc.
*
* @return none
*/
protected function generatePageFooter()
{
// to do: output common end of HTML code
echo <<<EOT
</body>
</html>
EOT;
}
/**
* Processes the data that comes via GET or POST i.e. CGI.
* If every page is supposed to do something with submitted
* data do it here. E.g. checking the settings of PHP that
* influence passing the parameters (e.g. magic_quotes).
*
* @return none
*/
protected function processReceivedData()
{
if (get_magic_quotes_gpc()) {
throw new Exception
("Bitte schalten Sie magic_quotes_gpc in php.ini aus!");
}
}
} // end of class
// Zend standard does not like closing php-tag!
// PHP doesn't require the closing tag (it is assumed when the file ends).
// Not specifying the closing ? > helps to prevent accidents
// like additional whitespace which will cause session
// initialization to fail ("headers already sent").
//? >
// <header class="header">
// <div class="wrap">
// <h2 class="logo"><a href="#">Website Logo</a></h2>
// <a id="menu-icon">☰ Menu</a>
// <nav class="navbar">
// <ul class="menu">
// <li><a class="active" href="#">Home</a></li><!--
// --><li><a href="#">About</a></li><!--
// --><li><a href="#">Blog</a></li><!--
// --><li><a href="#">Work</a></li><!--
// --><li><a href="#">Contact</a></li>
// </ul>
// </nav>
// </div>
// </header>
// <div class="content">
// <h2>Simple Responsive Navigation Menu created by <a title="Follow me at twitter" href="https://twitter.com/mithicher">@mithicher</a></h2>
// <p>Built with Sass & Compass.</p>
// </div>