Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // UTF-8 marker äöüÄÖÜ߀
- /**
- * Class PageTemplate 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, <b.kreling@fbi.h-da.de>
- * @author Ralf Hahn, <ralf.hahn@h-da.de>
- * @license http://www.h-da.de none
- * @Release 1.2
- * @link http://www.fbi.h-da.de
- */
- // TODO: Sessions nur Kundenpizzas zeigen (passende ID in kundenstatus.php wählen)
- require_once 'Page.php';
- /**
- * This is a template for top level classes, which represent
- * a complete web page and which are called directly by the user.
- * Usually there will only be a single instance of such a class.
- * The name of the template is supposed
- * to be replaced by the name of the specific HTML page e.g. baker.
- * The order of methods might correspond to the order of thinking
- * during implementation.
- * @author Bernhard Kreling, <b.kreling@fbi.h-da.de>
- * @author Ralf Hahn, <ralf.hahn@h-da.de>
- */
- class Kunde extends Page
- {
- // to do: declare reference variables for members
- // representing substructures/blocks
- protected $kundenstatus = null;
- /**
- * Instantiates members (to be defined above).
- * Calls the constructor of the parent i.e. page class.
- * So the database connection is established.
- *
- * @return none
- */
- protected function __construct()
- {
- parent::__construct();
- // to do: instantiate members representing substructures/blocks
- require_once './divs/kundenstatus.php';
- $this->kundenstatus = new Kundenstatus($this->database);
- }
- /**
- * Cleans up what ever is needed.
- * Calls the destructor of the parent i.e. page class.
- * So the database connection is closed.
- *
- * @return none
- */
- protected function __destruct()
- {
- parent::__destruct();
- }
- /**
- * Fetch all data that is necessary for later output.
- * Data is stored in an easily accessible way e.g. as associative array.
- *
- * @return none
- */
- protected function getViewData()
- {
- // to do: fetch data for this view from the database
- }
- /**
- * First the necessary data is fetched and then the HTML is
- * assembled for output. i.e. the header is generated, the content
- * of the page ("view") is inserted and -if avaialable- the content of
- * all views contained is generated.
- * Finally the footer is added.
- *
- * @return none
- */
- protected function generateView()
- {
- $this->getViewData();
- $this->generatePageHeader("Kunde", true);
- echo <<< EOT
- <div id="site_body">
- <form action="kunde.php" method="post">
- <fieldset><legend>Kunde</legend>
- <table>
- <tr>
- <td></td>
- <td>bestellt</td>
- <td>im Ofen</td>
- <td>gebacken</td>
- <td>unterwegs</td>
- </tr>
- EOT;
- /* INHALT GENERATE BESTELLTE PIZZEN*/
- $this->kundenstatus->generateView("pizza");
- echo <<< EOT
- </table>
- <p><a class="button" href="bestellung.php">Bestellung</a></p>
- </fieldset>
- </form>
- EOT;
- // to do: output view of this page
- $this->generatePageFooter();
- }
- /**
- * Processes the data that comes via GET or POST i.e. CGI.
- * If this page is supposed to do something with submitted
- * data do it here.
- * If the page contains blocks, delegate processing of the
- * respective subsets of data to them.
- *
- * @return none
- */
- protected function processReceivedData()
- {
- parent::processReceivedData();
- // to do: call processReceivedData() for all members
- /** Serverseitige Überprüfung ob alle Felder ausgefüllt sind und Pizzen im Warenkorb */
- if (isset($_POST["Warenkorb"]) AND
- isset($_POST["nachname"]) AND
- isset($_POST["strasse"]) AND
- isset($_POST["plz"]) AND
- isset($_POST["ort"])) {
- /** Pizzaüberprüfung (Pizza im Warenkorb auch in Auswahl? TODO) */
- /*
- $pizzaNameArray = [];
- $isPizzaIn = true;
- $pizzaTable = $this->database->query("SELECT PizzaName FROM Angebot");
- while (($row = $pizzaTable->fetch_assoc()) != null)
- $pizzaNameArray[] = $row["PizzaName"];
- foreach ($pizzaNameArray as $pizza) // check if all pizzas are in pizzaNameArray (isPizzaIn true)
- echo $pizza . " ";
- echo "<br>";
- */
- /** Bestellung hinzufügen */
- $query = $this->database->prepare("INSERT INTO `Bestellung` (`BestellungID`, `Adresse`, `Bestellzeitpunkt`) VALUES (NULL, ?, CURRENT_TIMESTAMP)");
- $adress = $_POST["nachname"] . ", " . $_POST["strasse"] . ", " . $_POST["plz"] . " " . $_POST["ort"];
- $query->bind_param('s', mysqli_real_escape_string($this->database,$adress));
- $query->execute();
- $order_id = $query->insert_id;
- /** BestellungsID als SessionID setzen */
- setcookie("SessionID", "", time() - 3600);
- setcookie("SessionID", $order_id, time() + 3600);
- /** Bestellte Pizzen der Bestellung hinzufügen */
- foreach ($_POST["Warenkorb"] as $pizza) {
- $query2 = $this->database->prepare("INSERT INTO `BestelltePizza` (`PizzaID`, `fBestellungID`, `fPizzaName`) VALUES (NULL, ?, ?)");
- $query2->bind_param('is', $order_id, mysqli_real_escape_string($this->database,$pizza)); // mysql_real_escapestring binden!
- $query2->execute();
- }
- }
- }
- /**
- * This main-function has the only purpose to create an instance
- * of the class and to get all the things going.
- * I.e. the operations of the class are called to produce
- * the output of the HTML-file.
- * The name "main" is no keyword for php. It is just used to
- * indicate that function as the central starting point.
- * To make it simpler this is a static function. That is you can simply
- * call it without first creating an instance of the class.
- *
- * @return none
- */
- public static function main()
- {
- try {
- $page = new Kunde();
- $page->processReceivedData();
- $page->generateView();
- }
- catch (Exception $e) {
- header("Content-type: text/plain; charset=UTF-8");
- echo $e->getMessage();
- }
- }
- }
- // This call is starting the creation of the page.
- // That is input is processed and output is created.
- Kunde::main();
- // 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").
- //? >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement