summaryrefslogtreecommitdiffstats
path: root/Bachelor/Entwicklung webbasierter Anwendungen/Praktikum5_6/f-fahrer.php
blob: 696a9fd542a1884bd5ae4040bfbb352aef799629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
	include ("classes.inc");
	$Con=mysql_connect('localhost','ewa','ewa',3306)
		or die('Could not connect: ' . mysql_error());
	mysql_select_db('ewa') or die('Could not select database');
	$query = "SELECT b.AuftragNr, b.SessionId, p.Bezeichnung, b.Lieferadresse, b.Zustand
		FROM t_bestellung b 
		NATURAL JOIN t_pizza p
		WHERE Zustand='unterwegs' or Zustand='geliefert' or Zustand='fertig'
		ORDER BY Zeitpunkt
		";
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	
	$Best = array();
	$Adressen = array();
	
	$n=0;
	while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
		$Best[$n] = new Bestellung($line[AuftragNr],
														$line[SessionId],
														$line[Lieferadresse],
														$line[Bezeichnung],
														$line[Zustand]
														);
		$n++;
	}
	$adr_query = 
		"SELECT DISTINCT Lieferadresse 
		 FROM t_bestellung 
		 WHERE Zustand='unterwegs' or Zustand='geliefert' or Zustand='fertig'
		";
	$adr_result = mysql_query($adr_query) or die('Query failed: ' . mysql_error());
	$a=0;
	while($adr_line = mysql_fetch_array($adr_result, MYSQL_ASSOC)) {
		$Adressen[$a] = $adr_line[Lieferadresse];
		$a++;
	}
	
	//if (isset($_POST))
	if (isset($_GET))
	{
    foreach ($_GET as $key => $val)
    {
      //echo "$key $val \n";
      $auftrg_nr = substr($key,2);
    }
    //if (is_array($Best))
    {
      foreach ($Best as $aktBest) {
        if ($aktBest->AuftNr == $auftrg_nr)
        {
          $pzAktZust = $aktBest->getzustand();
          $newZustand=$pzAktZust;
          if ($pzAktZust == 'fertig')
              $newZustand = 'unterwegs';
          else if ($pzAktZust == 'unterwegs')
              $newZustand = 'geliefert';
        }
      }
    }
	/*else
	{
		echo "HERE" ;
	}*/

    $update_str = "UPDATE t_bestellung b SET Zustand='$newZustand' WHERE b.AuftragNr = '$auftrg_nr'";
    $res = mysql_query($update_str) or die('Query failed: ' . mysql_error());
    $del_str = "DELETE FROM t_bestellung WHERE Zustand = 'geliefert' or Zustand=''";
    $res = mysql_query($del_str) or die('Query failed: ' . mysql_error());
  }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Fahrer</title>
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
	<link rel="stylesheet" type="text/css" href="formats.css">
	<script type="text/javascript">
	<!--
		function submit_form() {
			document.fahrer.submit();
			//parent.location.reload();
		}
	-->
	</script>
</head>

<body>
	  <h1>Fahrer</h1>
	  <?php 
	  	//echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\" name=\"fahrer\">";
		echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"GET\" name=\"fahrer\">";
	  	//echo "<form action=\"http://www.fbi.h-da.de/cgi-bin/Echo.pl\" method=\"POST\" name=\"baecker\">";
	  ?>
	  <table>
	  		 <tr>
			 <td class="dummy">
			 </td>
			 </tr>
			 <tr>
			 	 <td class="dummy">
				 </td>
			 	 <td>unterwegs
				 </td>
			 	 <td>geliefert
				 </td>
			 </tr>
			 <?php
			 
		//if(is_array($Adressen))
			 foreach($Adressen as $akt_adr)
			 {
			 //if(is_array($Best))
			 {
			 	foreach ($Best as $aktBest)
			 	{
			 	 if ($akt_adr == $aktBest->adresse)
			 	 {
			 	 	echo "<tr>\n";
			 	 	echo "<td>";
			 	 	$aktName = $aktBest->getpiz_name();
			 	 	$nr = $aktBest->getauftnr();
			 		$aktZustand = $aktBest->getzustand();
			 	 	echo $aktName;
			 	 	echo "</td>\n";
					if ($aktZustand == 'fertig') {
				 		echo "<td><input type=\"radio\" onclick=\"submit_form()\" name=\"nr$nr\" ></td>\n";
				 		echo "<td><input type=\"radio\" name=\"nr$nr\" DISABLED></td>\n";
				 	} else if ($aktZustand == 'unterwegs') {
				 		echo "<td><input type=\"radio\" name=\"nr$nr\" DISABLED CHECKED> </td>\n";
				 		echo "<td><input type=\"radio\" onclick=\"submit_form()\" name=\"nr$nr\"></td>\n";
				 	}  else if ($aktZustand == 'geliefert') {
				 		echo "<td><input type=\"radio\" name=\"nr$nr\" DISABLED CHECKED> </td>\n";
				 		echo "<td><input type=\"radio\" name=\"nr$nr\" DISABLED CHECKED> </td>\n";
				 	}
				 	echo "</tr>\n";
				 }
			 	}
			}

			 	?>
					  <!-- Adresse -->
	  		<tr>
          <td class="kunde" colspan="2">
       <?php
           echo $akt_adr."\n</td>\n";
          $preis_query = "SELECT sum(Preis) FROM t_pizza p NATURAL JOIN t_bestellung WHERE Lieferadresse = '$akt_adr'";
          $preis_result = mysql_query($preis_query) or die('Query failed: ' . mysql_error());
	        $preis = number_format(mysql_result($preis_result,0),2,".",",");
	        ?>
          <td class="kunde" id="preis">
          <?php echo $preis ?> 
          &euro;</td>
        </tr>
        <?php } ?>
	  </table>
	  </form>
</body>
</html>