<%@ page language="java" %>
<%@ page import="JavaBeans.*"%>
<%@ page import="java.util.*"%>

<jsp:useBean id='customer_interface' scope='session' class='JavaBeans.Customer_Interface'/>

<jsp:useBean id='customer_data' scope='session' class='JavaBeans.Customer_Data'/>
<jsp:setProperty name='customer_data' property="*"/>

<jsp:useBean id='creditcard_data' scope='session' class='JavaBeans.CreditCard_Data'/>
<jsp:setProperty name='creditcard_data' property="*"/>

<jsp:useBean id='address_data' scope='session' class='JavaBeans.Address_Data'/>
<jsp:setProperty name='address_data' property="*"/>

<jsp:useBean id='coffeepreference_data' scope='session' class='JavaBeans.CoffeePreference_Data'/>
<jsp:setProperty name='coffeepreference_data' property="*"/>

<% if(request.getParameter("action").equals("Update User Profile")){
customer_data = customer_interface.getCustomer();
address_data = customer_interface.getAddress();
coffeepreference_data = customer_data.getPreference();
}
if(customer_data ==null){
	out.println("HELLO customer.");
	out.println();
}
if (address_data == null){
	out.println("HELLO address.");
	out.println();
}
%>

<% if(request.getParameter("action") != null){
if(request.getParameter("action").equals("Update Profile")){
customer_interface.processRequest(request.getParameter("action"), customer_data, creditcard_data, address_data, coffeepreference_data);
}
}
%>
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Customer Update</title>
</head>
<body bgcolor="#FFFFFF">
<form method=POST action="customerUpdate.jsp">
<table align="center" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td><p align="center"><img src="CoffeeBanner.gif"></p>
		</td>
	</tr>
	<tr>
		<td bgcolor=#F0F8FF><br><p align="center">
		<p align="center"><font face="Geneva, Arial, Helvetica, sans-serif" size="-1"><i>Use this page to update your personal details, coffee preferences and delivery details.</i></font></p>
		<!--Please feel free to order a coffee, update your details or increase your remaining balance.<br><br></p-->
			
		</td>
	</tr>
	<tr><td>
		<table align="center" border="0" cellpadding="0" cellspacing="0" width=100%>
			<td width="50%" bgcolor=#D3D3D3>					
  					
  					<p align="center"></p>
  					<table>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>First Name: </b></td>
	  						<td align="left" > <input align = "center" type="text" size="20" name="firstName" maxlength="255" value = <%= customer_data.getFirstName() != null ? "'"+customer_data.getFirstName()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Last Name: </b></td>
	  						<td align="left" > <input align = "center" type="text" size="20" name="lastName" maxlength="50" value = <%= customer_data.getLastName() != null ? "'"+customer_data.getLastName()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Phone Number: </b></td>
	  						<td align="left" > <input align = "center" type="text" size="20" name="phoneNumber" maxlength="30" value = <%= address_data.getPhoneNumber() != null ? "'"+address_data.getPhoneNumber()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Email Address: </b></td>
	  						<td align="left" > <input align = "center" type="text" size="20" name="email" maxlength="384" value = <%= address_data.getEmail() != null ? "'"+address_data.getEmail()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Password: </b></td>
	  						<td align="left" > <input align = "center" type="password" size="20" name="password" maxlength="30" value = <%= customer_data.getVerifier() != null ? "'"+customer_data.getVerifier()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Re Enter Password: </b></td>
	  						<td align="left" > <input align = "center" type="password" size="20" name="verifier" maxlength="30" value = <%= customer_data.getVerifier() != null ? "'"+customer_data.getVerifier()+"'" : "" %> ></td>
  						</tr>
  						</font>
  						<% if(request.getParameter("action") != null){
					if(request.getParameter("action").equals("Update Profile")){
						customer_data.setFirstName(request.getParameter("firstName"));
					  	customer_data.setLastName(request.getParameter("lastName"));
					 }
					 }
					 %>
  					</table>  					
					
					
				</td>
			<td  width="50%" bgcolor=#D3D3D3>
					<p align="center"><font face="Geneva, Arial, Helvetica, sans-serif" size="-1"></p>
			
			<table>
					<tr>
	  						<td align ="right"> </td>
	  						<td align="left" > </td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Office Number: </b></td>
	  						<td align="left" > <input type="text" size="20" maxlength="40" name="office" value = 
	  						<%= address_data.getOffice() != null ? "'"+address_data.getOffice()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Floor: </b></td>
	  						<td align="left" > <input type="text" size="20" maxlength="40" name="floor"  value = <%= address_data.getFloor() != null ? "'"+address_data.getFloor()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Building: </b></td>
	  						<td align="left" > <input type="text" size="20" maxlength="40" name="building"  value = <%= address_data.getBuilding() != null ? "'"+address_data.getBuilding()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>Street: </b></td>
	  						<td align="left" > <input type="text" size="20" maxlength="40" name="street"  value = <%= address_data.getStreet() != null ? "'"+address_data.getStreet()+"'" : "" %> ></td>
  						</tr>
  						<tr>
	  						<td align ="right"><font face="Verdana" size="-1"><b>City: </b></td>
	  						<td align="left" > <input type="text" size="20" maxlength="40" name="city" value = <%= address_data.getCity() != null ? "'"+address_data.getCity()+"'" : "" %> ></td>
  						</font>
  						</tr>
  						<% if(request.getParameter("action") != null){
					if(request.getParameter("action").equals("Update Profile")){ 
						creditcard_data.setExpirydate(request.getParameter("date") 
						+ request.getParameter("month") 
						+ request.getParameter("year"));
						}
					}
					%>
  					</table>  						
					
					
				
			</td>
		</table>
		</td>
	</tr>

	<tr>
		<td>
		<table align="center" border="0" cellpadding="0" cellspacing="0" width=100%>
			<td  bgcolor=#ADD8E6>					
  					<p align="center"><font face="Geneva, Arial, Helvetica, sans-serif" size="-1"></p>
  					
  					<p align  ="center">  					
						  	  <br><font face="Verdana" size="-1"><b>Flavour: </b><select size="1" name="description" value=<%= coffeepreference_data.getDescription() != null ? "'"+coffeepreference_data.getDescription()+"'" : "" %>>
			      				  <option <% if(coffeepreference_data.getDescription().equals("Caffe Latte - small $2.80")) out.print("selected");%>>Caffe Latte - small $2.80</option>
				  				  <option <% if(coffeepreference_data.getDescription().equals("Caffe Latte - medium $3.30")) out.print("selected");%>>Caffe Latte - medium $3.30</option>
							  	  <option <% if(coffeepreference_data.getDescription().equals("Caffe Latte - large $3.60")) out.print("selected");%>>Caffe Latte - large $3.60</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Cappuccino - small $2.50")) out.print("selected");%>>Cappuccino - small $2.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Cappuccino - medium $3.50")) out.print("selected");%>>Cappuccino - medium $3.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Cappuccino - large $4.50")) out.print("selected");%>>Cappuccino - large $4.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Espresso - small $2.50")) out.print("selected");%>>Espresso - small $2.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Espresso - medium $3.50")) out.print("selected");%>>Espresso - medium $3.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Espresso - large $4.50")) out.print("selected");%>>Espresso - large $4.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Iced Cafe Latte - small $2.50")) out.print("selected");%>>Iced Cafe Latte - small $2.50</option>
							  	  <option <% if(coffeepreference_data.getDescription().equals("Iced Cafe Latte - medium $3.50")) out.print("selected");%>>Iced Cafe Latte - medium $3.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Iced Cafe Latte - large $4.50")) out.print("selected");%>>Iced Cafe Latte - large $4.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Mocha - small $2.50")) out.print("selected");%>>Mocha - small $2.50</option>
							  	  <option <% if(coffeepreference_data.getDescription().equals("Mocha - medium $3.50")) out.print("selected");%>>Mocha - medium $3.50</option>
								  <option <% if(coffeepreference_data.getDescription().equals("Mocha - large $4.50")) out.print("selected");%>>Mocha - large $4.50</option>
							</select>
						<font face="Verdana" size="-1"><b>Quantity: </b><select size="1" name="quantity" value=<%= coffeepreference_data.getQuantity() != null ? "'"+coffeepreference_data.getQuantity()+"'" : "" %>>
							  <option <% if(coffeepreference_data.getQuantity().equals("1")) out.print("selected");%>>1</option>
							  <option <% if(coffeepreference_data.getQuantity().equals("2")) out.print("selected");%>>2</option>
							  <option <% if(coffeepreference_data.getQuantity().equals("3")) out.print("selected");%>>3</option>
							  <option <% if(coffeepreference_data.getQuantity().equals("4")) out.print("selected");%>>4</option>
							  <option <% if(coffeepreference_data.getQuantity().equals("5")) out.print("selected");%>>5</option>
							</select>
						<br><font face="Verdana" size="-1"><b>Time coffee required: </b><select size="1" name="deliveryHour">
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("07")) out.print("selected");%>>07</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("08")) out.print("selected");%>>08</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("09")) out.print("selected");%>>09</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("10")) out.print("selected");%>>10</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("11")) out.print("selected");%>>11</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("12")) out.print("selected");%>>12</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("13")) out.print("selected");%>>13</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("14")) out.print("selected");%>>14</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("15")) out.print("selected");%>>15</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("16")) out.print("selected");%>>16</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("17")) out.print("selected");%>>17</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("18")) out.print("selected");%>>18</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("19")) out.print("selected");%>>19</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("20")) out.print("selected");%>>20</option>
							  <option <% if((coffeepreference_data.getDeliveryHour()).equals("21")) out.print("selected");%>>21</option>
							</select><select size="1" name="deliveryMinute">
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("00")) out.print("selected");%>>00</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("05")) out.print("selected");%>>05</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("10")) out.print("selected");%>>10</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("15")) out.print("selected");%>>15</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("20")) out.print("selected");%>>20</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("25")) out.print("selected");%>>25</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("30")) out.print("selected");%>>30</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("35")) out.print("selected");%>>35</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("40")) out.print("selected");%>>40</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("45")) out.print("selected");%>>45</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("50")) out.print("selected");%>>50</option>
							  <option <% if((coffeepreference_data.getDeliveryMinute()).equals("55")) out.print("selected");%>>55</option>
							</select></p>
						
						<p align="center"><input type="submit" value="Update Profile" name="action"></p>
						<p align="center"><font size="-1" face="Geneva, Arial, Helvetica, sans-serif" color = "FF0000">
					  	<b><%if(request.getParameter("action") != null){
					  	if(request.getParameter("action").equals("Update Profile")){
							out.println( customer_interface.getMessage());
							}
						}
						%></b></p>
					</form>
						
						
				</tr>
			<tr>
			<td bgcolor=#F0F8FF>
				<p align="center">
					<!--Please feel free to order a coffee, update your details or increase your remaining balance.<br><br></p-->
					<form method=post action="order.jsp">
						<input type="submit" value="Go to Order" name="action">
					</form>
				</p>
			</td>
			</tr>	
		</table>
		
</body></html>