Skip to content

Commit

Permalink
Cookies, yay!
Browse files Browse the repository at this point in the history
Also several bugfixes on shoppingcart page
  • Loading branch information
arc12012 committed Mar 30, 2017
1 parent 0a91d1b commit d983b8d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 48 deletions.
10 changes: 8 additions & 2 deletions WebContent/html/webpages/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ pageEncoding="ISO-8859-1"%>
<script type="text/javascript">
<%
MySQLAccess access = new MySQLAccess();
Cookie[] cookies = request.getCookies();
int sso = 0;
for(Cookie c : cookies)
{
if(c.getName().equals("ssoNum")) sso = Integer.parseInt(c.getValue());
}
// If location id is 0, it is a custom location which must be added to the database before employee preffered location can be updated
Expand All @@ -32,7 +38,7 @@ String userName = request.getParameter("name");
String phone = request.getParameter("phone");
// read location ID, but only if we haven't already generated it when adding new location to db
if(location==-1){ location = Integer.parseInt(request.getParameter("location_dropdown"));}
access.updateEmployee(1, userName, phone, location); //TODO get ID somehow
access.updateEmployee(sso, userName, phone, location);
System.out.print("updated employee "+userName);
// And now for the ticket
Expand All @@ -53,7 +59,7 @@ for(int i=0; i<idStringArray.length; i++)
// Now just call generateTicket once for each device
for(int i=0; i<devIDs.length; i++)
{
access.generateTicket(1, location, devIDs[i], request.getParameter("timeNeeded"));//TODO get ID somehow
access.generateTicket(sso, location, devIDs[i], request.getParameter("timeNeeded"));//TODO get ID somehow
}
%>
Expand Down
167 changes: 122 additions & 45 deletions WebContent/html/webpages/shoppingCart.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">

<%
Cookie[] cookies = request.getCookies();
int sso = 0;
for(Cookie c : cookies)
{
if(c.getName().equals("ssoNum")) sso = Integer.parseInt(c.getValue());
}
%>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand Down Expand Up @@ -66,59 +76,112 @@ pageEncoding="ISO-8859-1"%>
<input type="text" name="deviceIDs" style="display: none;">
<div class="form-group row">
<label for="name">Your name</label><br/>
<input type="text" class="form-control" name="name" placeholder="Name" />
<input type="text" class="form-control" name="name" placeholder="Name" required>
</div>
<div class="form-group row">
<label for="phone">Phone Number</label><br/>
<input type="text" class="form-control" name="phone" placeholder="203-867-5309">
<input type="text" class="form-control" name="phone" placeholder="203-867-5309" required>
</div>

<div class="form-group">
<label for="location_dropdown">Place to ship to</label><br/>
<select class="form-control" name="location_dropdown" id="dropdown" onchange="forceUpdateLocationMetadata()" style="width:65%; max-height: 80%; text-align: center; vertical-align: center; align-items: center; display: block; position: relative; margin: 5% auto;">
<select class="form-control" name="location_dropdown" id="dropdown" onchange="forceUpdateLocationMetadata()" style="width:65%; max-height: 80%; text-align: center; vertical-align: center; align-items: center; display: block; position: relative; margin: 5% auto; text-align-last:center;">
</select>
</div>
<div class="form-group row" style="display: block; align-items: center;margin: 5% auto;">
<div class="col-md-6" style="width:50%">
<div class="form-group row">
<label for="address">Street Address</label>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="address" placeholder="Address"/>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="address" placeholder="Address" required/>
</div>
<div class="form-group row">
<label for="city">City</label>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="city" placeholder="City"/>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="city" placeholder="City" required/>
</div>
</div>
<div class="col-md-6" style="width:50%">
<div class="form-group row">
<label for="state">State</label>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="state" placeholder="State"/>
</div>
<div class="form-group row">
<label for="zip">Zip</label>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="zip" placeholder="Zip Code"/>
</div>
<select required style = "width: 60%; text-align-last:center;" name = "state" class="form-control">
<option value="" disabled selected>Choose State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="form-group row">
<label for="zip">Zip</label>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="zip" placeholder="Zip Code" required/>
</div>
</div>
<div class="form-group row">
<label for="timeNeeded">How long you think you'll need it?</label><br/>
<input type="date" class="form-control" name="timeNeeded" style="40%" />
</div>
<button type="submit" class="btn btn-primary" name="Submit">Submit</button>
</form>
</div>

</div>
<div class="form-group row">
<label for="timeNeeded">How long you think you'll need it?</label><br/>
<input type="date" class="form-control" name="timeNeeded" style="40%" required/>
</div>
<button type="submit" class="btn btn-primary" name="Submit">Submit</button>
</form>
</div>

</div>
</div>

<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<h4>Shopping Cart Options</h4>
<li class = "option" id = "os"><a href="#">Order Selected</a></li>
<li class = "option" id = "ds"><a href="#">Remove Selected From Cart</a></li>
<li class = "option" id = "oa"><a href="#">Order All</a></li>
<li class = "option" id = "da"><a href="#">Remove All From Cart</a></li>
</ul>
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<h4>Shopping Cart Options</h4>
<li class = "option" id = "os"><a href="#">Order Selected</a></li>
<li class = "option" id = "ds"><a href="#">Remove Selected From Cart</a></li>
<li class = "option" id = "oa"><a href="#">Order All</a></li>
<li class = "option" id = "da"><a href="#">Remove All From Cart</a></li>
</ul>
</div>

<div class = "displayDevice">
Expand All @@ -131,7 +194,7 @@ pageEncoding="ISO-8859-1"%>
<!-- <script src = "../javascript/navbar.js"></script> -->
<script src = "../javascript/nhpup_1.1.js"></script>
<script type="text/javascript">
//adding event listeners to all the options, such as ordering and deleting
// adding event listeners to all the options, such as ordering and deleting
document.getElementById('os').addEventListener('click',orderSelected_showPopup);
document.getElementById('ds').addEventListener('click',deleteSelected);
document.getElementById('oa').addEventListener('click',orderAll_showPopup);
Expand Down Expand Up @@ -169,6 +232,7 @@ var employee = {
var checked = new Array();
var locations = getLocations();
alert("User is "+"<%=sso%>");
//debug_add_items_to_cart();
show(); //on load, we want to show everything
Expand Down Expand Up @@ -198,7 +262,7 @@ function show(){
if(cart.length !== 0){ //only continue if there are cart items
html += '<p>Tickets have been generated below based on your desired selections.</p><br>'
for(var i = 0; i < cart.length; i++){ //iterate cart
var id = cart[i].id; //this gets the id value from the cart
var id = cart[i].id; //this gets the id value from the cart
html += '<div> <input class = "deviceCheckbox" type = "checkbox" id = "' + id + '"> </input><a class = "divlink" href = "#" onmouseover = "'+ part1 + 'Hardware type: ' + cart[i].hardware + '<br><br>' + cart[i].description + part2 + '"><div id = "ticket' + id +'" class = "ticket"><p class = "tickettext">' + cart[i].name + '</p></div></a></div>'; //create listing of all the devices
}
}
Expand Down Expand Up @@ -282,7 +346,7 @@ function autoFillFields(orderAllBool) {
// get employee
<%
MySQLAccess access = new MySQLAccess();
User employee = access.getEmployeeByID(9); //replace with real ID
User employee = access.getEmployeeByID(sso);
int locationID = employee.getLocation();
String name = employee.getName();
String phone = employee.getPhone();
Expand All @@ -304,6 +368,18 @@ function autoFillFields(orderAllBool) {
forceUpdateLocationMetadata();
// finally mark hidden orderAll field appropriately
document.orderForm.orderAll.value=orderAllBool;
// Also, this is where I'm going to restrict the date input to the future
var dtToday = new Date();
var month = dtToday.getMonth() + 1;
var day = dtToday.getDate();
var year = dtToday.getFullYear();
if(month < 10)
month = '0' + month.toString();
if(day < 10)
day = '0' + day.toString();
var minDate = year + '-' + month + '-' + day;
document.orderForm.timeNeeded.min=minDate;
}
// Set all the shipping fields to the database values correspoding to the location selected in the dropdown
Expand All @@ -328,7 +404,11 @@ function forceDropdownCustomLocation() {
function getLocations() {
<%
Location[] loci = access.getLocations(9); //TODO get real ID
Location[] loci = access.getLocations( );
for(int i=0; i<loci.length; i++)
{
System.out.println(loci[i].getName());
}
%>
var loci = new Array(<%=loci.length%>);
<%
Expand All @@ -352,6 +432,8 @@ function getLocations() {
function submitOrderForm() {
// This is called just before order form is submitted. In order for any database activity to occur,
// we must first append the employees ID as well as the ids of whatever devices are selected.
// If nothing is checked then nust don't bother submitting form
if(checked.length == 0) break;
// First, employee id
userID=getUserID();
document.orderForm.userID.value=userID;
Expand All @@ -363,29 +445,24 @@ function submitOrderForm() {
document.orderForm.deviceIDs.value=selectedDeviceString;
// Finally remove selected items from the cart
var cart = getCartItems();
for(var i = 0; i < checked.length; i++){ //iterate all the checked off devices
for(var j = 0; j < cart.length; j++){ //iterate cart
if(cart[j] == checked[i]) //match id's
cart.splice(j,1); //remove from the cart
}
}
// And clear the checked array
checked=new Array();
deleteSelected(false);
return true;
}
/**
This function takes all the devices we selected and removes them from the shopping cart.
Prompt is a boolean.
**/
function deleteSelected(){
var response = confirm("Are you sure you'd like to remove the selected items from the cart?");
if(response == true){ //if they confirm
function deleteSelected() {deleteSelected(true);} //this should handle call from delete selected button
function deleteSelected(prompt){
var confirmDelete = prompt ? confirm("Are you sure you'd like to remove the selected items from the cart?") : true
if(confirmDelete){ //if they confirm
for(var i = 0; i < checked.length; i++){ //iterate all the checked off devices
var id = checked[i]; //get the id of each device
var cart = getCartItems(); //get the cart
for(var j = 0; j < cart.length; j++){ //iterate cart
if(cart[j] == id){ //match ids
if(cart[j].id == id){ //match ids
cart.splice(j,1); //remove from the cart
}
}
Expand Down Expand Up @@ -431,7 +508,7 @@ function deleteAll(){
}
function getUserID() {
return 9; //TODO actually get a userID
return <%=sso%>;
}
function debug_add_items_to_cart() {
employee.id=5;
Expand Down
2 changes: 1 addition & 1 deletion src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public Location[] getLocations() throws ClassNotFoundException, SQLException{

public Location[] getLocations(int userID) throws SQLException, ClassNotFoundException
{
String query = "SELECT * FROM location WHERE Employee_Flag = 0 OR Employee_Flag = "+userID; //TODO filter for custom locations (needs db change)
String query = "SELECT * FROM location WHERE Employee_Flag = 0 OR Employee_Flag = "+userID+" ORDER BY Name ASC"; //TODO filter for custom locations (needs db change)
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database,user,password);
Statement statement = connect.createStatement();
Expand Down

0 comments on commit d983b8d

Please sign in to comment.