Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PageTemplate extends Page
- {
- private $query;
- private $result;
- /**
- * 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
- }
- /**
- * 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()
- {
- $this->query = "SELECT PizzaID, BestellungID, Adresse, PizzaName, Preis, Status FROM angebot, bestelltepizza, bestellung where bestellung.bestellungid = bestelltepizza.fbestellungid and angebot.PizzaName = bestelltepizza.fPizzaName and (select min(status) from bestelltepizza where bestellung.bestellungid = fbestellungid) >2 ORDER BY Status, BestellungID";
- $this->result = $this->_database->query($this->query);
- var_dump(mysqli_num_rows($this->result));
- // Test ob neuer status
- if(isset($_GET['bstID'])) {
- $bstID = $_GET['bstID'];
- $queryStatus = "UPDATE bestelltepizza SET status='4' WHERE fBestellungID = '$bstID'";
- if($this->_database->query($queryStatus) === TRUE) {
- echo '<script type="text/javascript">alert("Status erfolgreich geändert!");</script>';
- }
- }
- }
- /**
- * 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('Fahrer');
- echo <<< HTML
- <table class="fahrer"><thead><tr><th>Bestellung</th><th>Enthaltene Pizzas</th><th>Lieferadresse</th><th>Preis</th><th>Status</th></thead><tbody>
- HTML;
- while($row = mysqli_fetch_array($this->result)) {
- var_dump(mysqli_num_rows($this->result));
- var_dump($row);
- $pizzaID = $row['PizzaID'];
- $PizzaName = $row['PizzaName'];
- $BestellID = $row['BestellungID'];
- $status = intval($row['Status']);
- $Adresse = $row['Adresse'];
- $preis = number_format($row['Preis'], 2);
- $this->query = "SELECT fPizzaName FROM bestelltepizza WHERE fBestellungID = '$BestellID'";
- var_dump($this->query);
- $tmpResult = $this->_database->query($this->query);
- $count = mysqli_num_rows($tmpResult);
- echo <<< HTML
- <tr>
- <td>$BestellID</td><td><ul class="pizzas">
- HTML;
- for($i = 0; $i < $count; $i++) {
- $tmpVar = mysqli_fetch_array($this->result);
- //var_dump($count);
- echo "<li>".$tmpVar['PizzaName']."</li>";
- }
- echo <<< HTML
- </ul></td>
- <td>$Adresse</td>
- <td>$preis EUR</td>
- <td>
- HTML;
- if($status == 3) {
- echo <<< HTML
- <select class="baecker" id="$BestellID" data-pizza="$BestellID" onChange="javascript: statusDeliver(this);">
- <option selected>Warte auf Fahrer</option>
- <option>Wird ausgeliefert</option>
- </select>
- HTML;
- } else if($status == 4) {
- echo <<< HTML
- Wird ausgeliefert
- HTML;
- }
- echo <<< HTML
- </td>
- </tr>
- HTML;
- }
- echo <<< HTML
- </tbody>
- </table>
- HTML;
- $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
- }
- /**
- * 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 PageTemplate();
- $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.
- PageTemplate::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