Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.45 KB | None | 0 0
  1. <?php   // UTF-8 marker äöüÄÖÜ߀
  2. /**
  3.  * Class PageTemplate for the exercises of the EWA lecture
  4.  * Demonstrates use of PHP including class and OO.
  5.  * Implements Zend coding standards.
  6.  * Generate documentation with Doxygen or phpdoc
  7.  *
  8.  * PHP Version 5
  9.  *
  10.  * @category File
  11.  * @package  Pizzaservice
  12.  * @author   Bernhard Kreling, <b.kreling@fbi.h-da.de>
  13.  * @author   Ralf Hahn, <ralf.hahn@h-da.de>
  14.  * @license  http://www.h-da.de  none
  15.  * @Release  1.2
  16.  * @link     http://www.fbi.h-da.de
  17.  */
  18.  
  19. // to do: change name 'PageTemplate' throughout this file
  20. require_once './Page.php';
  21.  
  22. /**
  23.  * This is a template for top level classes, which represent
  24.  * a complete web page and which are called directly by the user.
  25.  * Usually there will only be a single instance of such a class.
  26.  * The name of the template is supposed
  27.  * to be replaced by the name of the specific HTML page e.g. baker.
  28.  * The order of methods might correspond to the order of thinking
  29.  * during implementation.
  30.  
  31.  * @author   Bernhard Kreling, <b.kreling@fbi.h-da.de>
  32.  * @author   Ralf Hahn, <ralf.hahn@h-da.de>
  33.  */
  34. class PageTemplate extends Page
  35. {
  36.     // to do: declare reference variables for members
  37.     // representing substructures/blocks
  38.    
  39.     protected $pizzaName;
  40.     protected $pizzaPfad;
  41.     protected $pizzaPreis;
  42.  
  43.     /**
  44.      * Instantiates members (to be defined above).  
  45.      * Calls the constructor of the parent i.e. page class.
  46.      * So the database connection is established.
  47.      *
  48.      * @return none
  49.      */
  50.     protected function __construct()
  51.     {
  52.         parent::__construct();
  53.         // to do: instantiate members representing substructures/blocks
  54.  
  55.         $pizzaName = array();
  56.         $pizzaPfad = array();
  57.         $pizzaPreis = array();
  58.     }
  59.    
  60.     /**
  61.      * Cleans up what ever is needed.  
  62.      * Calls the destructor of the parent i.e. page class.
  63.      * So the database connection is closed.
  64.      *
  65.      * @return none
  66.      */
  67.     protected function __destruct()
  68.     {
  69.         parent::__destruct();
  70.     }
  71.  
  72.     /**
  73.      * Fetch all data that is necessary for later output.
  74.      * Data is stored in an easily accessible way e.g. as associative array.
  75.      *
  76.      * @return none
  77.      */
  78.     protected function getViewData()
  79.     {
  80.         // to do: fetch data for this view from the database
  81.     }
  82.    
  83.     /**
  84.      * First the necessary data is fetched and then the HTML is
  85.      * assembled for output. i.e. the header is generated, the content
  86.      * of the page ("view") is inserted and -if avaialable- the content of
  87.      * all views contained is generated.
  88.      * Finally the footer is added.
  89.      *
  90.      * @return none
  91.      */
  92.     protected function generateView()
  93.     {
  94.         $this->getViewData();
  95.         $this->generatePageHeader('Bestelung');
  96.         // to do: call generateView() for all members
  97.         // to do: output view of this page
  98.         $this->generateEchoView();
  99.         $this->generatePageFooter();
  100.     }
  101.    
  102.     protected function generateEchoView() {
  103.         echo <<<EOT
  104.         <body>
  105.     <div class="webseite">
  106.         <header class="header roundedCorners white background">
  107.             <h1>Pizza</h1>
  108.         </header>
  109.         <div class="main">
  110.             <nav class="menue roundedCorners white background">
  111.                 <p><a href="baecker.html" class="white">Baecker</a></p>
  112.                 <p><a href="bestellung.html"class="white">Bestellung</a></p>
  113.                 <p><a href="fahrer.html"class="white">Fahrer</a></p>
  114.                 <p><a href="kunde.html"class="white">Kunde</a></p>
  115.             </nav>
  116.             <main class="inhalt roundedCorners white background">
  117.                 <div class="row">
  118. EOT;
  119.  
  120. $this->insert_pizza();
  121.  
  122.         echo <<<EOT
  123.         </div>
  124.                 <div class="wahrenkorb">
  125.                 <form action="https://www.fbi.h-da.de/cgi-bin/Echo.pl" id="form1" accept-charset="UTF-8" method="POST">
  126.                     <select id="korb" name="warenkorb" size="5" >      
  127.                     </select> </br>
  128.                     <label> Vorname: </br>
  129.                         <input type="text" name="first" size="30" maxlength="40" placeholder="Vorname" />
  130.                     </label> </br>
  131.                     <label> Nachname: </br>
  132.                         <input type="text" name="last" size="30" maxlength="40" placeholder="Nachname"  />
  133.                     </label> </br>
  134.                     <label> Stadt: </br>
  135.                         <input type="text" name="city" size="30" maxlength="40" placeholder="Stadt"  />
  136.                     </label> </br>
  137.                     <label> Strasse: </br>
  138.                         <input type="text" name="street" size="30" maxlength="40" placeholder="Strasse"  />
  139.                     </label> </br>
  140.                     <label> Email: </br>
  141.                         <input type="text" name="email" size="30" maxlength="40" placeholder="Email"  />
  142.                     </label>  
  143.                 </form>
  144.                 </div>
  145.                 <div>
  146.                     <input type="submit" name="Bestellen" onclick="sel()"/>
  147.                     <button onclick="del()">Löschen</button>
  148.                 </div>
  149.                
  150.             </main>
  151.         </div>
  152.         <footer class="footer roundedCorners white background">
  153.  
  154.         </footer>
  155.     </div>
  156. </body>
  157. EOT;
  158.     }
  159.  
  160.     protected function insert_pizza() {
  161.         static $id = 0;
  162.         for($i = 0; $i < count($this->pizzaName); $i++) {
  163.             echo <<<EOT
  164.             <div id="$id" data-name="$this->pizzaName[$i]" data-preis="$this->pizzaPreis[$i]" onclick="addCart()"><img class="img" src="$this->pizzaPfad[$i]" /></div>
  165. EOT;
  166.         }
  167.     }
  168.     /**
  169.      * Processes the data that comes via GET or POST i.e. CGI.
  170.      * If this page is supposed to do something with submitted
  171.      * data do it here.
  172.      * If the page contains blocks, delegate processing of the
  173.      * respective subsets of data to them.
  174.      *
  175.      * @return none
  176.      */
  177.     protected function processReceivedData()
  178.     {
  179.         parent::processReceivedData();
  180.         // to do: call processReceivedData() for all members
  181.     }
  182.  
  183.     /**
  184.      * This main-function has the only purpose to create an instance
  185.      * of the class and to get all the things going.
  186.      * I.e. the operations of the class are called to produce
  187.      * the output of the HTML-file.
  188.      * The name "main" is no keyword for php. It is just used to
  189.      * indicate that function as the central starting point.
  190.      * To make it simpler this is a static function. That is you can simply
  191.      * call it without first creating an instance of the class.
  192.      *
  193.      * @return none
  194.      */    
  195.     public static function main()
  196.     {
  197.         try {
  198.             $page = new PageTemplate();
  199.             $page->processReceivedData();
  200.             $page->generateView();
  201.         }
  202.         catch (Exception $e) {
  203.             header("Content-type: text/plain; charset=UTF-8");
  204.             echo $e->getMessage();
  205.         }
  206.     }
  207. }
  208.  
  209. // This call is starting the creation of the page.
  210. // That is input is processed and output is created.
  211. PageTemplate::main();
  212.  
  213. // Zend standard does not like closing php-tag!
  214. // PHP doesn't require the closing tag (it is assumed when the file ends).
  215. // Not specifying the closing ? >  helps to prevent accidents
  216. // like additional whitespace which will cause session
  217. // initialization to fail ("headers already sent").
  218. //? >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement