Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.75 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 Bestellung extends Page
  35. {
  36.  
  37. // to do: declare reference variables for members
  38. // representing substructures/blocks
  39.  
  40. /**
  41. * Instantiates members (to be defined above).
  42. * Calls the constructor of the parent i.e. page class.
  43. * So the database connection is established.
  44. *
  45. * @return none
  46. */
  47. protected function __construct()
  48. {
  49. parent::__construct();
  50. // to do: instantiate members representing substructures/blocks
  51. }
  52.  
  53. /**
  54. * Cleans up what ever is needed.
  55. * Calls the destructor of the parent i.e. page class.
  56. * So the database connection is closed.
  57. *
  58. * @return none
  59. */
  60. protected function __destruct()
  61. {
  62. parent::__destruct();
  63. }
  64.  
  65. /**
  66. * Fetch all data that is necessary for later output.
  67. * Data is stored in an easily accessible way e.g. as associative array.
  68. *
  69. * @return none
  70. */
  71. protected function getViewData()
  72. {
  73. // to do: fetch data for this view from the database
  74. $angebot = array();
  75.  
  76. $SQLabfrage = "SELECT * FROM angebot";
  77. $Recordset = $this->_database ->query ($SQLabfrage);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
  78.  
  79. if (!$Recordset)
  80. throw new Exception("Query failed: ".$Connection->error);
  81.  
  82. //return $Recordset;
  83.  
  84.  
  85. $counter = 0;
  86. $pizza = array(); //konnte man iwie net drinnen definieren??
  87. while ($record = $Recordset->fetch_assoc()){
  88. $pizza["PizzaNummer"] = $record["PizzaNummer"];
  89. $pizza["PizzaName"] = $record["PizzaName"];
  90. $pizza["Preis"] = $record["Preis"];
  91. $pizza["Bilddatei"] = $record["Bilddatei"];
  92. //$angebot[0] = $pizza;
  93. array_push($angebot, $pizza);
  94. }
  95.  
  96. return $angebot;
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. /**
  105. * First the necessary data is fetched and then the HTML is
  106. * assembled for output. i.e. the header is generated, the content
  107. * of the page ("view") is inserted and -if avaialable- the content of
  108. * all views contained is generated.
  109. * Finally the footer is added.
  110. *
  111. * @return none
  112. */
  113. protected function generateView() //warum geht $record (in schleife) benutzen hier nicht, aber in getviewdata schon??
  114. {
  115.  
  116. $dbergebnisse = $this->getViewData();
  117. //$record = $this->$Recordset;
  118. //$aktnummer = $record["PizzaNummer"];
  119. $this->generatePageHeader('Bestellung');
  120. // to do: call generateView() for all members
  121. //<form action="https://echo.fbi.h-da.de/" method="POST">
  122. //<form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST"> //original
  123.  
  124. //$_SESSION["testwert"] = "bla";
  125. //<form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST">
  126. echo <<< test1
  127. <body onload="isorderable()">
  128.  
  129. <form action="http://127.0.0.1/pizzaservice/ewa/Kundeerbend.php" method="POST" onsubmit="selectAll()">
  130.  
  131. <h2> Bestellung</h2>
  132. <h2> Speisekarte</h2>
  133. test1;
  134.  
  135. foreach($dbergebnisse as $pizza){
  136. $aktpizzanummer = $pizza["PizzaNummer"];
  137. $aktname = $pizza["PizzaName"];
  138. $aktpreis = $pizza["Preis"];
  139. $aktbilddatei = $pizza["Bilddatei"];
  140. echo <<< test10
  141. <p hidden id= $aktpizzanummer data-preis=$aktpreis> idptemp </p>
  142. <p>$aktname</p>
  143. <p>$aktpreis €</p>
  144. <img src=$aktbilddatei alt="margherita" width="80" height="80" onclick="addpizza($aktpizzanummer,'$aktname',$aktpreis)" onclick="isorderable()">
  145. test10;
  146.  
  147. }
  148.  
  149. /*
  150. echo <<< test1
  151. <body>
  152. <form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST">
  153. <h2> Bestellung</h2>
  154. <h2> Speisekarte</h2>
  155. */
  156. /*
  157.  
  158. <!-- Pizzen aus Datenbank -->
  159. <img src="ewabild.jpg" alt="margherita" width="80" height="80">
  160. <p>Margherita</p>
  161. <p>4.00€</p>
  162. <img src="ewabild.jpg" alt="salami" width="80" height="80">
  163. <p>Salami</p>
  164. <p>4.50€</p>
  165. <img src="ewabild.jpg" alt="hawaii" width="80" height="80">
  166. <p>Hawaii</p>
  167. <p>5.50€</p>
  168. */
  169. $angebotsgroesse = count($dbergebnisse); //kein code in ausgabe!! (also nicht nach echo)
  170. echo <<< test1
  171. <h2>Warenkorb</h2>
  172.  
  173.  
  174. <select name="top[]" id= "warenkorb" size=" $angebotsgroesse " multiple>
  175. test1;
  176. /*
  177. foreach($dbergebnisse as $pizza){
  178. $aktpizzanummer = $pizza["PizzaNummer"];
  179. $aktname = $pizza["PizzaName"];
  180. $aktpreis = $pizza["Preis"];
  181. $aktbilddatei = $pizza["Bilddatei"];
  182.  
  183. echo <<< test1
  184. <option value = "$aktpizzanummer"> $aktname </option>
  185. test1;
  186. }
  187. */
  188. echo "</select>";
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. /*
  203. echo <<< test2
  204. <table name = "blatabelle" id="infoetc" size=" $angebotsgroesse " multiple>
  205. <tr>
  206. <td>"bla</td>
  207. </tr>
  208. test2;
  209.  
  210.  
  211. foreach($dbergebnisse as $pizza){
  212. $aktpizzanummer = $pizza["PizzaNummer"];
  213. $aktname = $pizza["PizzaName"];
  214. $aktpreis = $pizza["Preis"];
  215. $aktbilddatei = $pizza["Bilddatei"];
  216.  
  217. echo <<< test1
  218. <tr id = "$aktpizzanummer">
  219. <td data-name>$aktname</td>
  220. <td data-preis>$aktpreis</td>
  221. </tr>
  222. test1;
  223. }
  224.  
  225. echo "</table>";
  226. */
  227.  
  228.  
  229.  
  230. echo <<< test1
  231. <p id="gesamtpreisanzeige">0</p>
  232. <input id = "gesamtpreisanzeigeinput" type="hidden" name="gesamtpreis" value="14.50" />
  233. <p><label>
  234. <input type="text" id='kundenadresse' name="kundenadresse" onchange="isorderable()" onClick="selectAll()"/>
  235. </label></p>
  236. <input type="reset" name="Alle löschen" value="Alle Löschen" onclick= "deleteAll()"/>
  237. <input type="button" name="Auswahl löschen" value="Auswahl Löschen" onclick = "deleteSome()"/>
  238. <input type="submit" id="bestellen" name="bestellen" value="Bestellen" />
  239. </form>
  240. <script type ="text/javascript" src="MyJS.js"></script>
  241. <script type="text/javascript">
  242. isorderable();
  243. </script>
  244. </body>
  245.  
  246. test1;
  247.  
  248.  
  249.  
  250. // to do: output view of this page
  251. $this->generatePageFooter();
  252. }
  253.  
  254. /**
  255. * Processes the data that comes via GET or POST i.e. CGI.
  256. * If this page is supposed to do something with submitted
  257. * data do it here.
  258. * If the page contains blocks, delegate processing of the
  259. * respective subsets of data to them.
  260. *
  261. * @return none
  262. */
  263. protected function processReceivedData()
  264. {
  265. parent::processReceivedData();
  266. // to do: call processReceivedData() for all members
  267.  
  268. }
  269.  
  270. /**
  271. * This main-function has the only purpose to create an instance
  272. * of the class and to get all the things going.
  273. * I.e. the operations of the class are called to produce
  274. * the output of the HTML-file.
  275. * The name "main" is no keyword for php. It is just used to
  276. * indicate that function as the central starting point.
  277. * To make it simpler this is a static function. That is you can simply
  278. * call it without first creating an instance of the class.
  279. *
  280. * @return none
  281. */
  282. public static function main()
  283. {
  284. //session_start();
  285. try {
  286. $page = new Bestellung();
  287. $page->processReceivedData();
  288.  
  289. $page->generateView();
  290. }
  291. catch (Exception $e) {
  292. header("Content-type: text/plain; charset=UTF-8");
  293. echo $e->getMessage();
  294. }
  295. }
  296. }
  297.  
  298. // This call is starting the creation of the page.
  299. // That is input is processed and output is created.
  300. Bestellung::main();
  301.  
  302. // Zend standard does not like closing php-tag!
  303. // PHP doesn't require the closing tag (it is assumed when the file ends).
  304. // Not specifying the closing ? > helps to prevent accidents
  305. // like additional whitespace which will cause session
  306. // initialization to fail ("headers already sent").
  307. //? >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement