Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.15 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 Fahrererbend extends Page
  35. {
  36. // to do: declare reference variables for members
  37. // representing substructures/blocks
  38.  
  39. /**
  40. * Instantiates members (to be defined above).
  41. * Calls the constructor of the parent i.e. page class.
  42. * So the database connection is established.
  43. *
  44. * @return none
  45. */
  46. protected function __construct()
  47. {
  48. parent::__construct();
  49. // to do: instantiate members representing substructures/blocks
  50. }
  51.  
  52. /**
  53. * Cleans up what ever is needed.
  54. * Calls the destructor of the parent i.e. page class.
  55. * So the database connection is closed.
  56. *
  57. * @return none
  58. */
  59. protected function __destruct()
  60. {
  61. parent::__destruct();
  62. }
  63.  
  64. /**
  65. * Fetch all data that is necessary for later output.
  66. * Data is stored in an easily accessible way e.g. as associative array.
  67. *
  68. * @return none
  69. */
  70. protected function getViewData()
  71. {
  72. // to do: fetch data for this view from the database
  73. $pizzaname = array();
  74. $pizzanamen = array();
  75. $bestellungen = array();
  76. $SQLorders = "Select BestellungID from bestellung";
  77. $Recordsetorders = $this->_database ->query ($SQLorders);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
  78. if (!$Recordsetorders)
  79. throw new Exception("Query failed: ".$Connection->error);
  80. while ($record = $Recordsetorders->fetch_assoc()){
  81. $bestellid=$record["BestellungID"];
  82. $SQLabfrage3 = "Select Status from angebot, pizzaverlauf, bestellung where fBestellungID=$bestellid and angebot.Pizzanummer=pizzaverlauf.fPizzaNummer";
  83. $Recordset3 = $this->_database ->query ($SQLabfrage3);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
  84. if (!$Recordset3)
  85. throw new Exception("Query failed: ".$Connection->error);
  86. $allefertig=true;
  87. while ($record3 = $Recordset3->fetch_assoc()){
  88.  
  89. $statuspizzen = $record3["Status"];
  90. if($statuspizzen >=2 ){
  91.  
  92. }else{
  93. $allefertig = false;
  94. break;
  95. }
  96.  
  97. }
  98.  
  99. if( $allefertig){
  100.  
  101. $SQLabfrage = "Select Adresse from bestellung where BestellungID=$bestellid";
  102. $SQLabfrage2 = "Select SUM(angebot.Preis) as Preis from pizzaverlauf, angebot where fBestellungID=$bestellid and angebot.Pizzanummer=pizzaverlauf.fPizzaNummer";
  103. $SQLabfrage4 = "Select angebot.PizzaName from angebot, pizzaverlauf, bestellung where fBestellungID=$bestellid and angebot.Pizzanummer=pizzaverlauf.fPizzaNummer";
  104. $SQLabfrage5 = "Select Status from angebot, pizzaverlauf, bestellung where fBestellungID=$bestellid and angebot.Pizzanummer=pizzaverlauf.fPizzaNummer";
  105.  
  106. $Recordset = $this->_database ->query ($SQLabfrage);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
  107. $Recordset2 = $this->_database ->query ($SQLabfrage2);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
  108. $Recordset4 = $this->_database ->query ($SQLabfrage4);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
  109. $Recordset5 = $this->_database ->query ($SQLabfrage5);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
  110.  
  111. if (!$Recordset)
  112. throw new Exception("Query failed: ".$Connection->error);
  113. if (!$Recordset2)
  114. throw new Exception("Query failed: ".$Connection->error);
  115. if (!$Recordset4)
  116. throw new Exception("Query failed: ".$Connection->error);
  117. if (!$Recordset5)
  118. throw new Exception("Query failed: ".$Connection->error);
  119.  
  120. while ($record = $Recordset->fetch_assoc()){
  121. $adresse = $record["Adresse"];
  122. echo "$adresse";
  123. }
  124. while ($record2 = $Recordset2->fetch_assoc()){
  125. $preis= $record2["Preis"];
  126. echo "$preis";
  127.  
  128. }
  129. $counter=0;
  130. while ($record4 = $Recordset4->fetch_assoc()){
  131.  
  132. $pizzaname[$counter] = $record4["PizzaName"];
  133. echo "$pizzaname[$counter], $counter";
  134.  
  135. $counter++;
  136. //array_push($pizzanamen, $pizzaname);
  137. }
  138.  
  139. while ($record5 = $Recordset5->fetch_assoc()){
  140.  
  141. $status = $record5["Status"];
  142.  
  143.  
  144. }
  145.  
  146.  
  147.  
  148.  
  149.  
  150. $neu= array( $adresse , $preis , $status ,$bestellid, $pizzaname);
  151. $bestellungen[ $bestellid ] = $neu;
  152.  
  153. $Recordset->free();
  154. $Recordset2->free();
  155. $Recordset3->free();
  156. $Recordset4->free();
  157. $Recordset5->free();
  158.  
  159. }
  160. }
  161.  
  162.  
  163. $Recordsetorders->free();
  164.  
  165.  
  166. return $bestellungen;
  167. }
  168.  
  169.  
  170.  
  171.  
  172. /**
  173. * First the necessary data is fetched and then the HTML is
  174. * assembled for output. i.e. the header is generated, the content
  175. * of the page ("view") is inserted and -if avaialable- the content of
  176. * all views contained is generated.
  177. * Finally the footer is added.
  178. *
  179. * @return none
  180. */
  181. protected function generateView()
  182. {
  183. echo('<script language="Javascript">setTimeout(function() {window.location.reload();}, 5000);</script>');
  184.  
  185. $dbergebnisse= $this->getViewData();
  186. $this->generatePageHeader('Fahrer');
  187. // to do: call generateView() for all members
  188. echo <<< t20
  189. <body>
  190. <h1>Fahrer</h1> <!-- h0 gibt es nicht --> <!-- <b>tag machts auch nicht bolder -->
  191.  
  192. <section> <!-- wenn jede section überschrift haben sollte auch möglich bestellinfos in eine zu packen -->
  193.  
  194.  
  195. t20;
  196. echo "<<form name='formidname[]' id='formid' action='http://127.0.0.1/pizzaservice/ewa/fahrererbend.php' method='POST'>>";
  197. foreach($dbergebnisse as $bestellung){
  198. $counter=0;
  199. $adresse = $bestellung[0];
  200. $preis = $bestellung[1];
  201. $aktstatus = $bestellung[2];
  202. $exemplar = $bestellung[3];
  203. $namen[]=$bestellung[4];
  204.  
  205.  
  206. echo <<< test1
  207. <p>$preis, $adresse</p>
  208. test1;
  209. foreach($namen as $pizzanamen){
  210. $pnamen=$pizzanamen[$counter];
  211.  
  212. echo <<< test12
  213. <p>$pnamen </p>
  214.  
  215. test12;
  216.  
  217. $counter++;
  218. }
  219.  
  220.  
  221. if($aktstatus==2){
  222. echo <<< test12
  223. <input type='radio' name=$exemplar id = $exemplar value='fertig' checked onchange="document.forms['formid'].submit()"> &ensp; &emsp;
  224. <input type='radio' name=$exemplar id = $exemplar value='unterwegs' onchange="document.forms['formid'].submit()">&ensp; &emsp;&ensp; &emsp;&ensp;
  225. <input type='radio' name=$exemplar id = $exemplar value='ausgeliefert' onchange="document.forms['formid'].submit()">
  226. test12;
  227. }
  228. else if($aktstatus==3){
  229. echo <<< test13
  230. <input type='radio' name=$exemplar id = $exemplar value='fertig' onclick="document.forms['formid'].submit()"> &ensp; &emsp;
  231. <input type='radio' name=$exemplar id = $exemplar value='unterwegs' checked onclick="document.forms['formid'].submit()">&ensp; &emsp;&ensp; &emsp;&ensp;
  232. <input type='radio' name=$exemplar id = $exemplar value='ausgeliefert' onclick="document.forms['formid'].submit()">
  233. test13;
  234. }
  235. else if($aktstatus==4){
  236. echo <<< test14
  237. <input type='radio' name=$exemplar id = $exemplar value='fertig' onclick="document.forms['formid'].submit()"> &ensp; &emsp;
  238. <input type='radio' name=$exemplar id = $exemplar value='unterwegs' onclick="document.forms['formid'].submit()">&ensp; &emsp;&ensp; &emsp;&ensp;
  239. <input type='radio' name=$exemplar id = $exemplar value='ausgeliefert' checked onclick="document.forms['formid'].submit()">
  240. test14;
  241. }
  242. else{
  243. echo "problem";
  244. }
  245. echo "</section>";
  246.  
  247.  
  248. }
  249. echo <<< t27
  250. </body>
  251. t27;
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263. /* foreach($dbergebnisse as $pizza){
  264. $aktadresse = $pizza["Adresse"];
  265. $aktstatus = $pizza["Status"];
  266. $aktPreis = $pizza["Preis"];
  267. if($aktstatus==3 ||$aktstatus==4||$aktstatus==5 ){
  268. echo<<< t21
  269. <p> $aktadresse ,$aktPreis </p>
  270. <section> <!-- wenn jede section überschrift haben sollte auch möglich bestellinfos in eine zu packen -->
  271.  
  272. bestellt
  273. &ensp; &emsp;
  274. im Ofen
  275. &ensp; &emsp;
  276. fertig
  277. <br>
  278. </section>
  279.  
  280. t21;
  281. echo "<section> $aktname";
  282.  
  283. if($aktstatus==3){
  284.  
  285. echo <<< test12
  286.  
  287. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='bestellt' checked onclick="document.forms['formid'].submit()"> &ensp; &emsp;
  288. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='imofen' onclick="document.forms['formid'].submit()">&ensp; &emsp;&ensp; &emsp;&ensp;
  289. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='fertig' onclick="document.forms['formid'].submit()">
  290.  
  291. test12;
  292.  
  293. }
  294. else if($aktstatus==4){
  295.  
  296.  
  297. echo <<< test13
  298.  
  299. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='bestellt' onclick="document.forms['formid'].submit()"> &ensp; &emsp;
  300. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='imofen' checked onclick="document.forms['formid'].submit()">&ensp; &emsp;&ensp; &emsp;&ensp;
  301. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='fertig' onclick="document.forms['formid'].submit()">
  302. test13;
  303. }
  304. else if($aktstatus==5){
  305. echo <<< test14
  306.  
  307. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='bestellt' onclick="document.forms['formid'].submit()"> &ensp; &emsp;
  308. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='imofen' onclick="document.forms['formid'].submit()">&ensp; &emsp;&ensp; &emsp;&ensp;
  309. <input type='radio' name=$PizzaExemplarID id = $PizzaExemplarID value='fertig' checked onclick="document.forms['formid'].submit()">
  310. test14;
  311. }
  312. else{
  313. echo "problem";
  314. }
  315. echo "</section>";
  316.  
  317. }
  318. }
  319. echo <<< t27
  320.  
  321. </body>
  322.  
  323. t27;
  324.  
  325.  
  326.  
  327. /*
  328.  
  329. <body>
  330. <h1>Fahrer</h1> <!-- h0 gibt es nicht --> <!-- <b>tag machts auch nicht bolder -->
  331.  
  332. <section> <!-- wenn jede section überschrift haben sollte auch möglich bestellinfos in eine zu packen -->
  333. <form action="http://echo.fbi.h-da.de" method="post">
  334. <p>
  335. <b> Schulz, Kasinostr. 5 13,50€ <br> Margherita, Salami, Tonno </b> <!-- echtes tab muss noch ergänzt werden wenn gewollt -->
  336. <br>
  337.  
  338.  
  339. <label for="pizza1fertig">fertig</label>
  340. <label for="pizza1unterwegs">unterwegs</label>
  341. <label for="pizza1geliefert">geliefert</label>
  342. <br>
  343. <input type="radio" name="pizza1status" id = "pizza1fertig" value="fertig">
  344. <input type="radio" name="pizza1status" id = "pizza1unterwegs" value="unterwegs">
  345. <input type="radio" name="pizza1status" id = "pizza1geliefert" value="geliefert">
  346.  
  347.  
  348. <p></p>
  349. <b> Müller, Rheinstraße 11 10,00€ <br> Salami, Prosciutto </b>
  350. <br>
  351.  
  352. <label for="pizza2fertig">fertig</label>
  353. <label for="pizza2unterwegs">unterwegs</label>
  354. <label for="pizza2geliefert">geliefert</label>
  355. <br>
  356. <input type="radio" name="pizza2status" id = "pizza2fertig" value="fertig">
  357. <input type="radio" name="pizza2status" id = "pizza2unterwegs" value="unterwegs">
  358. <input type="radio" name="pizza2status" id = "pizza2geliefert" value="geliefert">
  359.  
  360. <input type="submit">
  361. </form>
  362. </section>
  363. </body>
  364.  
  365. */
  366. // to do: output view of this page
  367. $this->generatePageFooter();
  368. }
  369.  
  370. /**
  371. * Processes the data that comes via GET or POST i.e. CGI.
  372. * If this page is supposed to do something with submitted
  373. * data do it here.
  374. * If the page contains blocks, delegate processing of the
  375. * respective subsets of data to them.
  376. *
  377. * @return none
  378. */
  379. protected function processReceivedData()
  380. {
  381. parent::processReceivedData();
  382. // to do: call processReceivedData() for all members
  383. if (!empty($_POST)) {
  384. $baecker = array();
  385. $SQLabfrage = "SELECT pizzaverlauf.PizzaExemplarID, `angebot`.`PizzaName`, `pizzaverlauf`.`Status` FROM `pizzaverlauf`, `angebot` where angebot.PizzaNummer = pizzaverlauf.fPizzaNummer";
  386. $Recordset = $this->_database ->query ($SQLabfrage);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
  387.  
  388. if (!$Recordset)
  389. throw new Exception("Query failed: ".$Connection->error);
  390.  
  391. $counter = 0;
  392. $pizza = array(); //konnte man iwie net drinnen definieren??
  393. while ($record = $Recordset->fetch_assoc()){
  394. $pizza["PizzaExemplarID"] = $record["PizzaExemplarID"];
  395. $pizza["PizzaName"] = $record["PizzaName"];
  396. $pizza["Status"] = $record["Status"];
  397. //$angebot[0] = $pizza;
  398. array_push($baecker, $pizza);
  399. }
  400. $Recordset->free();
  401.  
  402. //$backstati = $_POST["formidname"];
  403. foreach ($_POST as $key => $value) { //von stackoverflow
  404. echo "Select pizzaverlauf.Status from pizzaverlauf where pizzaverlauf.fBestellungID = '". $key ."'";
  405. $dbwertquery = "Select `pizzaverlauf`.`Status` from `pizzaverlauf` where `pizzaverlauf`.fBestellungID = $key";
  406. $dbwertertrs = $this->_database->query ($dbwertquery); //Recordset
  407. $record = $dbwertertrs->fetch_assoc();
  408. $dbwert = $record["Status"];
  409. echo "bla $dbwert";
  410.  
  411.  
  412. $uwert = 10; //übergabewert
  413. if ($value == "fertig"){ $uwert = 2;}
  414. else if ($value == "unterwegs") { $uwert = 3;}
  415. else if ($value == "ausgeliefert") { $uwert = 4;}
  416. else {echo "fehler bei wertzuordnung zu übergebenem";};
  417. echo "blabla $uwert";
  418.  
  419. if ($dbwert != $uwert) {
  420. echo "UPDATE pizzaverlauf SET Status = $uwert where fBestellungID=$key";
  421. $dbupdatequery = "UPDATE pizzaverlauf SET Status = $uwert where fBestellungID=$key";
  422. $this->_database->query ($dbupdatequery);
  423. }
  424.  
  425. echo '<p>'.$key.'</p>';
  426. echo '<p>'.$value.'</p>';
  427.  
  428.  
  429. }
  430. header('Location: http://127.0.0.1/pizzaservice/ewa/Fahrererbend.php');
  431. }
  432.  
  433. }
  434.  
  435. /**
  436. * This main-function has the only purpose to create an instance
  437. * of the class and to get all the things going.
  438. * I.e. the operations of the class are called to produce
  439. * the output of the HTML-file.
  440. * The name "main" is no keyword for php. It is just used to
  441. * indicate that function as the central starting point.
  442. * To make it simpler this is a static function. That is you can simply
  443. * call it without first creating an instance of the class.
  444. *
  445. * @return none
  446. */
  447. public static function main()
  448. {
  449.  
  450.  
  451. try {
  452. $page = new Fahrererbend();
  453. $page->processReceivedData();
  454.  
  455. $page->generateView();
  456. }
  457. catch (Exception $e) {
  458. header("Content-type: text/plain; charset=UTF-8");
  459. echo $e->getMessage();
  460. }
  461. }
  462. }
  463.  
  464. // This call is starting the creation of the page.
  465. // That is input is processed and output is created.
  466. Fahrererbend::main();
  467.  
  468. // Zend standard does not like closing php-tag!
  469. // PHP doesn't require the closing tag (it is assumed when the file ends).
  470. // Not specifying the closing ? > helps to prevent accidents
  471. // like additional whitespace which will cause session
  472. // initialization to fail ("headers already sent").
  473. //? >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement