Advertisement
Guest User

Fahrer.php

a guest
Mar 11th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.59 KB | None | 0 0
  1. class PageTemplate extends Page
  2. {
  3.     private $query;
  4.     private $result;
  5.    
  6.     /**
  7.      * Instantiates members (to be defined above).  
  8.      * Calls the constructor of the parent i.e. page class.
  9.      * So the database connection is established.
  10.      *
  11.      * @return none
  12.      */
  13.     protected function __construct()
  14.     {
  15.         parent::__construct();
  16.         // to do: instantiate members representing substructures/blocks
  17.     }
  18.    
  19.     /**
  20.      * Cleans up what ever is needed.  
  21.      * Calls the destructor of the parent i.e. page class.
  22.      * So the database connection is closed.
  23.      *
  24.      * @return none
  25.      */
  26.     protected function __destruct()
  27.     {
  28.         parent::__destruct();
  29.     }
  30.  
  31.     /**
  32.      * Fetch all data that is necessary for later output.
  33.      * Data is stored in an easily accessible way e.g. as associative array.
  34.      *
  35.      * @return none
  36.      */
  37.     protected function getViewData()
  38.     {
  39.         $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";
  40.         $this->result = $this->_database->query($this->query);
  41.  
  42.         var_dump(mysqli_num_rows($this->result));
  43.        
  44.        
  45.         // Test ob neuer status
  46.         if(isset($_GET['bstID'])) {
  47.             $bstID = $_GET['bstID'];
  48.             $queryStatus = "UPDATE bestelltepizza SET status='4' WHERE fBestellungID = '$bstID'";
  49.             if($this->_database->query($queryStatus) === TRUE) {
  50.                 echo '<script type="text/javascript">alert("Status erfolgreich geändert!");</script>';
  51.             }
  52.         }
  53.        
  54.     }
  55.    
  56.     /**
  57.      * First the necessary data is fetched and then the HTML is
  58.      * assembled for output. i.e. the header is generated, the content
  59.      * of the page ("view") is inserted and -if avaialable- the content of
  60.      * all views contained is generated.
  61.      * Finally the footer is added.
  62.      *
  63.      * @return none
  64.      */
  65.     protected function generateView()
  66.     {
  67.         $this->getViewData();
  68.         $this->generatePageHeader('Fahrer');
  69.        
  70.         echo <<< HTML
  71.             <table class="fahrer"><thead><tr><th>Bestellung</th><th>Enthaltene Pizzas</th><th>Lieferadresse</th><th>Preis</th><th>Status</th></thead><tbody>
  72. HTML;
  73.        
  74.         while($row = mysqli_fetch_array($this->result)) {
  75.         var_dump(mysqli_num_rows($this->result));
  76.         var_dump($row);
  77.             $pizzaID = $row['PizzaID'];
  78.             $PizzaName = $row['PizzaName'];
  79.             $BestellID = $row['BestellungID'];
  80.             $status = intval($row['Status']);
  81.             $Adresse = $row['Adresse'];
  82.             $preis = number_format($row['Preis'], 2);
  83.            
  84.             $this->query = "SELECT fPizzaName FROM bestelltepizza WHERE fBestellungID = '$BestellID'";
  85.             var_dump($this->query);
  86.             $tmpResult = $this->_database->query($this->query);
  87.            
  88.             $count = mysqli_num_rows($tmpResult);
  89.            
  90.                         echo <<< HTML
  91.                 <tr>
  92.                     <td>$BestellID</td><td><ul class="pizzas">
  93. HTML;
  94.            
  95.             for($i = 0; $i < $count; $i++) {
  96.  
  97.                 $tmpVar = mysqli_fetch_array($this->result);
  98.                 //var_dump($count);
  99.                
  100.                 echo "<li>".$tmpVar['PizzaName']."</li>";
  101.             }
  102.  
  103.             echo <<< HTML
  104.                     </ul></td>
  105.                     <td>$Adresse</td>
  106.                     <td>$preis EUR</td>
  107.                     <td>
  108. HTML;
  109.             if($status == 3) {
  110.             echo <<< HTML
  111.                         <select class="baecker" id="$BestellID" data-pizza="$BestellID" onChange="javascript: statusDeliver(this);">
  112.                             <option selected>Warte auf Fahrer</option>
  113.                             <option>Wird ausgeliefert</option>
  114.                         </select>
  115. HTML;
  116.             } else if($status == 4) {
  117.             echo <<< HTML
  118.                 Wird ausgeliefert
  119. HTML;
  120.             }
  121.             echo <<< HTML
  122.                 </td>
  123.             </tr>
  124. HTML;
  125.         }
  126.        
  127.         echo  <<< HTML
  128.         </tbody>
  129.         </table>
  130. HTML;
  131.        
  132.        
  133.         $this->generatePageFooter();
  134.     }
  135.    
  136.     /**
  137.      * Processes the data that comes via GET or POST i.e. CGI.
  138.      * If this page is supposed to do something with submitted
  139.      * data do it here.
  140.      * If the page contains blocks, delegate processing of the
  141.      * respective subsets of data to them.
  142.      *
  143.      * @return none
  144.      */
  145.     protected function processReceivedData()
  146.     {
  147.         parent::processReceivedData();
  148.         // to do: call processReceivedData() for all members
  149.     }
  150.  
  151.     /**
  152.      * This main-function has the only purpose to create an instance
  153.      * of the class and to get all the things going.
  154.      * I.e. the operations of the class are called to produce
  155.      * the output of the HTML-file.
  156.      * The name "main" is no keyword for php. It is just used to
  157.      * indicate that function as the central starting point.
  158.      * To make it simpler this is a static function. That is you can simply
  159.      * call it without first creating an instance of the class.
  160.      *
  161.      * @return none
  162.      */    
  163.     public static function main()
  164.     {
  165.         try {
  166.             $page = new PageTemplate();
  167.             $page->processReceivedData();
  168.             $page->generateView();
  169.         }
  170.         catch (Exception $e) {
  171.             header("Content-type: text/plain; charset=UTF-8");
  172.             echo $e->getMessage();
  173.         }
  174.     }
  175. }
  176.  
  177. // This call is starting the creation of the page.
  178. // That is input is processed and output is created.
  179. PageTemplate::main();
  180.  
  181. // Zend standard does not like closing php-tag!
  182. // PHP doesn't require the closing tag (it is assumed when the file ends).
  183. // Not specifying the closing ? >  helps to prevent accidents
  184. // like additional whitespace which will cause session
  185. // initialization to fail ("headers already sent").
  186. //? >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement