NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

<?php // UTF-8 marker äöüÄÖÜ߀
/**
* Class kunde 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 7
*
* @file kunde.php
* @package Page Templates
* @author Bernhard Kreling, <[email protected]>
* @author Ralf Hahn, <[email protected]>
* @version 2.0
*/

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, <[email protected]>
* @author Ralf Hahn, <[email protected]>
*/
class kunde extends Page {

// to do: declare reference variables for members
// representing substructures/blocks

/**
* 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();
session_start();
// to do: instantiate members representing substructures/blocks
}

/**
* Cleans up what ever is needed.
* Calls the destructor of the parent i.e. page class.
* So the database connection is closed.
*
* @return none
*/
public 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() {

if(isset($_SESSION['BestellungID']) && isset($_SESSION['BestellungID']['id']) && is_numeric($_SESSION['BestellungID']['id'])){
$BestellID = $this->_database->real_escape_string($_SESSION['BestellungID']['id']);

$SQLAbfrage1 = "SELECT * FROM `ordered_articles` LEFT JOIN `article` ON `ordered_articles`.`f_article_id` = `article`.`id` WHERE `f_order_id` = '$BestellID' ;";
}
else{
return false;
}
$dbRecordset = $this->_database->query ($SQLAbfrage1);
while ($dbRecord = $dbRecordset->fetch_assoc()) {
$o_array[] = $dbRecord;
}
$dbRecordset->free();//freigeben des Speichers
return $o_array;
}

protected function generateOrderingView($dbRecord) {
$o_number = $dbRecord['f_order_id'];
$p_name = htmlspecialchars($dbRecord['name']);

if ($dbRecord['status'] === '1') {
$status = 'Bestellt';
}
elseif ($dbRecord['status'] === '2') {
$status = 'Im Ofen';
}
elseif ($dbRecord['status'] === '3') {
$status = 'Fertig gebacken';
}
elseif ($dbRecord['status'] === '4') {
$status = 'In Lieferung';
}
elseif ($dbRecord['status'] === '4') {
$status = 'Geliefert!';
}
else {
$status = "Unbekannt";
}

// $article_id = $dbRecord['f_article_id'];

echo <<< EOT
<article class="ordering">
<p style="font-size:16px">Pizza $p_name <br/>Status: $status </p>
<br/>
</article>
EOT;
}


/**
* 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() {

$o_array = $this->getViewData();
$this->generatePageHeader('Kunde');

echo <<< EOT
<h1 style="font-size:40px">Bestellübersicht</h1>
<section>
<h2>Lieferstatus</h2>
<article>
<h3>Bestellungen</h3>
<div>
EOT;


echo("<p id='orderNr'>Ihre Bestellnummer lautet: ".$_SESSION['BestellungID']['id']."</p>");
foreach($o_array as $ordering) {
$this->generateOrderingView($ordering);
}
$TestJsonString='[{"name":"Gourmet","status":"3"},{"name":"Vierku00e4se","status":"3"}]';


echo <<< EOT
</div>
</article>
<br/>
<h2>Weitere Bestellungen</h2>
<p>Möchten Sie eine <b>neue Bestellung</b> aufgeben?</p>
<p><input type="button" onclick="self.location.href='/Praktikum/Prak3/bestellung.php'" value="Jetzt Bestellen" /></p>
</section>
EOT;

$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();

if (isset($_POST["Adresse"]) && isset($_POST["pizza"])) {
foreach($_POST["pizza"] as $onePizza) {
if(is_numeric($onePizza))
$ordered_pizzas[] = $onePizza;
var_dump($onePizza);
}
$adress = $this->_database->real_escape_string($_POST["Adresse"]);
$this->new_Order($adress, $ordered_pizzas);
header('Location: kunde.php');
}
}

protected function new_Order($adress, $p_numbers) {
$SQLAbfrage2 = "INSERT INTO `ordering`(`address`) VALUES (". '"' . $adress . '"' . ");";
if (!$this->_database->query($SQLAbfrage2)) {
throw new Exception("Query failed: ".$this->_database->error);
}

$SQLAbfrage3 = "SELECT `id` FROM `ordering` WHERE `address` = '". $adress . "';";
$dbRecordset = $this->_database->query($SQLAbfrage3);

if(!$dbRecordset) {
throw new Exception("Query failed: ".$this->_database->error);
}

while($dbRecord = $dbRecordset->fetch_assoc()) {
$o_id_array[] = $dbRecord;
}

$dbRecordset->free();
$o_id = max($o_id_array);

var_dump($o_id);
foreach($p_numbers as $onePizza_number)
{
$SQLAbfrage4 = "INSERT INTO `ordered_articles`(`f_order_id`, `f_article_id`, `status`) VALUES (" . $o_id["id"] . "," . $onePizza_number . ",1);";
if(!$this->_database->query($SQLAbfrage4))
throw new Exception("Query failed: ".$this->_database->error);
}
}

/**
* 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").
//? >
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.