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
- */
- // to do: change name 'PageTemplate' throughout this file
- 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 Fahrererbend 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();
- // 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()
- {
- // to do: fetch data for this view from the database
- $pizzaname = array();
- $pizzanamen = array();
- $bestellungen = array();
- $SQLorders = "Select BestellungID from bestellung";
- $Recordsetorders = $this->_database ->query ($SQLorders);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
- if (!$Recordsetorders)
- throw new Exception("Query failed: ".$Connection->error);
- while ($record = $Recordsetorders->fetch_assoc()){
- $bestellid=$record["BestellungID"];
- $SQLabfrage3 = "Select Status from angebot, pizzaverlauf, bestellung where fBestellungID=$bestellid and angebot.Pizzanummer=pizzaverlauf.fPizzaNummer";
- $Recordset3 = $this->_database ->query ($SQLabfrage3);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
- if (!$Recordset3)
- throw new Exception("Query failed: ".$Connection->error);
- $allefertig=true;
- while ($record3 = $Recordset3->fetch_assoc()){
- $statuspizzen = $record3["Status"];
- if($statuspizzen >=2 ){
- }else{
- $allefertig = false;
- break;
- }
- }
- if( $allefertig){
- $SQLabfrage = "Select Adresse from bestellung where BestellungID=$bestellid";
- $SQLabfrage2 = "Select SUM(angebot.Preis) as Preis from pizzaverlauf, angebot where fBestellungID=$bestellid and angebot.Pizzanummer=pizzaverlauf.fPizzaNummer";
- $SQLabfrage4 = "Select angebot.PizzaName from angebot, pizzaverlauf, bestellung where fBestellungID=$bestellid and angebot.Pizzanummer=pizzaverlauf.fPizzaNummer";
- $SQLabfrage5 = "Select Status from angebot, pizzaverlauf, bestellung where fBestellungID=$bestellid and angebot.Pizzanummer=pizzaverlauf.fPizzaNummer";
- $Recordset = $this->_database ->query ($SQLabfrage);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
- $Recordset2 = $this->_database ->query ($SQLabfrage2);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
- $Recordset4 = $this->_database ->query ($SQLabfrage4);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
- $Recordset5 = $this->_database ->query ($SQLabfrage5);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
- if (!$Recordset)
- throw new Exception("Query failed: ".$Connection->error);
- if (!$Recordset2)
- throw new Exception("Query failed: ".$Connection->error);
- if (!$Recordset4)
- throw new Exception("Query failed: ".$Connection->error);
- if (!$Recordset5)
- throw new Exception("Query failed: ".$Connection->error);
- while ($record = $Recordset->fetch_assoc()){
- $adresse = $record["Adresse"];
- echo "$adresse";
- }
- while ($record2 = $Recordset2->fetch_assoc()){
- $preis= $record2["Preis"];
- echo "$preis";
- }
- $counter=0;
- while ($record4 = $Recordset4->fetch_assoc()){
- $pizzaname[$counter] = $record4["PizzaName"];
- echo "$pizzaname[$counter], $counter";
- $counter++;
- //array_push($pizzanamen, $pizzaname);
- }
- while ($record5 = $Recordset5->fetch_assoc()){
- $status = $record5["Status"];
- }
- $neu= array( $adresse , $preis , $status ,$bestellid, $pizzaname);
- $bestellungen[ $bestellid ] = $neu;
- $Recordset->free();
- $Recordset2->free();
- $Recordset3->free();
- $Recordset4->free();
- $Recordset5->free();
- }
- }
- $Recordsetorders->free();
- return $bestellungen;
- }
- /**
- * 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()
- {
- echo('<script language="Javascript">setTimeout(function() {window.location.reload();}, 5000);</script>');
- $dbergebnisse= $this->getViewData();
- $this->generatePageHeader('Fahrer');
- // to do: call generateView() for all members
- echo <<< t20
- <body>
- <h1>Fahrer</h1> <!-- h0 gibt es nicht --> <!-- <b>tag machts auch nicht bolder -->
- <section> <!-- wenn jede section überschrift haben sollte auch möglich bestellinfos in eine zu packen -->
- t20;
- echo "<<form name='formidname[]' id='formid' action='http://127.0.0.1/pizzaservice/ewa/fahrererbend.php' method='POST'>>";
- foreach($dbergebnisse as $bestellung){
- $counter=0;
- $adresse = $bestellung[0];
- $preis = $bestellung[1];
- $aktstatus = $bestellung[2];
- $exemplar = $bestellung[3];
- $namen[]=$bestellung[4];
- echo <<< test1
- <p>$preis, $adresse</p>
- test1;
- foreach($namen as $pizzanamen){
- $pnamen=$pizzanamen[$counter];
- echo <<< test12
- <p>$pnamen </p>
- test12;
- $counter++;
- }
- if($aktstatus==2){
- echo <<< test12
- <input type='radio' name=$exemplar id = $exemplar value='fertig' checked onchange="document.forms['formid'].submit()">    
- <input type='radio' name=$exemplar id = $exemplar value='unterwegs' onchange="document.forms['formid'].submit()">       
- <input type='radio' name=$exemplar id = $exemplar value='ausgeliefert' onchange="document.forms['formid'].submit()">
- test12;
- }
- else if($aktstatus==3){
- echo <<< test13
- <input type='radio' name=$exemplar id = $exemplar value='fertig' onclick="document.forms['formid'].submit()">    
- <input type='radio' name=$exemplar id = $exemplar value='unterwegs' checked onclick="document.forms['formid'].submit()">       
- <input type='radio' name=$exemplar id = $exemplar value='ausgeliefert' onclick="document.forms['formid'].submit()">
- test13;
- }
- else if($aktstatus==4){
- echo <<< test14
- <input type='radio' name=$exemplar id = $exemplar value='fertig' onclick="document.forms['formid'].submit()">    
- <input type='radio' name=$exemplar id = $exemplar value='unterwegs' onclick="document.forms['formid'].submit()">       
- <input type='radio' name=$exemplar id = $exemplar value='ausgeliefert' checked onclick="document.forms['formid'].submit()">
- test14;
- }
- else{
- echo "problem";
- }
- echo "</section>";
- }
- echo <<< t27
- </body>
- t27;
- /* foreach($dbergebnisse as $pizza){
- $aktadresse = $pizza["Adresse"];
- $aktstatus = $pizza["Status"];
- $aktPreis = $pizza["Preis"];
- if($aktstatus==3 ||$aktstatus==4||$aktstatus==5 ){
- echo<<< t21
- <p> $aktadresse ,$aktPreis </p>
- <section> <!-- wenn jede section überschrift haben sollte auch möglich bestellinfos in eine zu packen -->
- bestellt
-    
- im Ofen
-    
- fertig
- <br>
- </section>
- t21;
- echo "<section> $aktname";
- if($aktstatus==3){
- echo <<< test12
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='bestellt' checked onclick="document.forms['formid'].submit()">    
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='imofen' onclick="document.forms['formid'].submit()">       
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='fertig' onclick="document.forms['formid'].submit()">
- test12;
- }
- else if($aktstatus==4){
- echo <<< test13
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='bestellt' onclick="document.forms['formid'].submit()">    
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='imofen' checked onclick="document.forms['formid'].submit()">       
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='fertig' onclick="document.forms['formid'].submit()">
- test13;
- }
- else if($aktstatus==5){
- echo <<< test14
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='bestellt' onclick="document.forms['formid'].submit()">    
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='imofen' onclick="document.forms['formid'].submit()">       
- <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='fertig' checked onclick="document.forms['formid'].submit()">
- test14;
- }
- else{
- echo "problem";
- }
- echo "</section>";
- }
- }
- echo <<< t27
- </body>
- t27;
- /*
- <body>
- <h1>Fahrer</h1> <!-- h0 gibt es nicht --> <!-- <b>tag machts auch nicht bolder -->
- <section> <!-- wenn jede section überschrift haben sollte auch möglich bestellinfos in eine zu packen -->
- <form action="http://echo.fbi.h-da.de" method="post">
- <p>
- <b> Schulz, Kasinostr. 5 13,50€ <br> Margherita, Salami, Tonno </b> <!-- echtes tab muss noch ergänzt werden wenn gewollt -->
- <br>
- <label for="pizza1fertig">fertig</label>
- <label for="pizza1unterwegs">unterwegs</label>
- <label for="pizza1geliefert">geliefert</label>
- <br>
- <input type="radio" name="pizza1status" id = "pizza1fertig" value="fertig">
- <input type="radio" name="pizza1status" id = "pizza1unterwegs" value="unterwegs">
- <input type="radio" name="pizza1status" id = "pizza1geliefert" value="geliefert">
- <p></p>
- <b> Müller, Rheinstraße 11 10,00€ <br> Salami, Prosciutto </b>
- <br>
- <label for="pizza2fertig">fertig</label>
- <label for="pizza2unterwegs">unterwegs</label>
- <label for="pizza2geliefert">geliefert</label>
- <br>
- <input type="radio" name="pizza2status" id = "pizza2fertig" value="fertig">
- <input type="radio" name="pizza2status" id = "pizza2unterwegs" value="unterwegs">
- <input type="radio" name="pizza2status" id = "pizza2geliefert" value="geliefert">
- <input type="submit">
- </form>
- </section>
- </body>
- */
- // 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
- if (!empty($_POST)) {
- $baecker = array();
- $SQLabfrage = "SELECT pizzaverlauf.PizzaExemplarID, `angebot`.`PizzaName`, `pizzaverlauf`.`Status` FROM `pizzaverlauf`, `angebot` where angebot.PizzaNummer = pizzaverlauf.fPizzaNummer";
- $Recordset = $this->_database ->query ($SQLabfrage);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
- if (!$Recordset)
- throw new Exception("Query failed: ".$Connection->error);
- $counter = 0;
- $pizza = array(); //konnte man iwie net drinnen definieren??
- while ($record = $Recordset->fetch_assoc()){
- $pizza["PizzaExemplarID"] = $record["PizzaExemplarID"];
- $pizza["PizzaName"] = $record["PizzaName"];
- $pizza["Status"] = $record["Status"];
- //$angebot[0] = $pizza;
- array_push($baecker, $pizza);
- }
- $Recordset->free();
- //$backstati = $_POST["formidname"];
- foreach ($_POST as $key => $value) { //von stackoverflow
- echo "Select pizzaverlauf.Status from pizzaverlauf where pizzaverlauf.fBestellungID = '". $key ."'";
- $dbwertquery = "Select `pizzaverlauf`.`Status` from `pizzaverlauf` where `pizzaverlauf`.fBestellungID = $key";
- $dbwertertrs = $this->_database->query ($dbwertquery); //Recordset
- $record = $dbwertertrs->fetch_assoc();
- $dbwert = $record["Status"];
- echo "bla $dbwert";
- $uwert = 10; //übergabewert
- if ($value == "fertig"){ $uwert = 2;}
- else if ($value == "unterwegs") { $uwert = 3;}
- else if ($value == "ausgeliefert") { $uwert = 4;}
- else {echo "fehler bei wertzuordnung zu übergebenem";};
- echo "blabla $uwert";
- if ($dbwert != $uwert) {
- echo "UPDATE pizzaverlauf SET Status = $uwert where fBestellungID=$key";
- $dbupdatequery = "UPDATE pizzaverlauf SET Status = $uwert where fBestellungID=$key";
- $this->_database->query ($dbupdatequery);
- }
- echo '<p>'.$key.'</p>';
- echo '<p>'.$value.'</p>';
- }
- header('Location: http://127.0.0.1/pizzaservice/ewa/Fahrererbend.php');
- }
- }
- /**
- * 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 Fahrererbend();
- $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.
- Fahrererbend::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