Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
2017-CSE-Senior-Project-Team-2/WebContent/html/webpages/redirect/orderFormHandler.jsp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
122 lines (112 sloc)
4.78 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ page import = "database.*,entities.*,utilities.*,java.util.concurrent.*" %> | |
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" | |
pageEncoding="ISO-8859-1"%> | |
<!-- The purpose of this file is to capture order form submissions and forward them to MySQLAccess --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel = "stylesheet" type = "text/css" href = "../../css/stylesheet.css"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | |
</head> | |
<body> | |
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal"> | |
<%@include file="../components/navbar.jsp"%> | |
</nav> | |
<script type="text/javascript"> | |
<% | |
User self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso)); | |
// If location id is 0, it is a custom location which must be added to the database before employee preffered location can be updated | |
int location=-1; | |
if(Integer.parseInt(request.getParameter("location_dropdown"))==0) | |
{ | |
location = LocationQueries.addLocation(new Location( | |
0, | |
request.getParameter("locname"), | |
request.getParameter("address"), | |
request.getParameter("town"), | |
request.getParameter("state"), | |
request.getParameter("zip"), | |
Integer.parseInt(navsso), | |
"","",0,0) | |
); | |
} | |
//Now update employee | |
String userName = request.getParameter("name"); | |
String phone = request.getParameter("phone"); | |
String email = request.getParameter("email"); | |
String[] options = request.getParameterValues("checkboxes"); | |
int perm = 0; | |
boolean urgent = false; | |
if(options != null){ | |
for(int j = 0; j < options.length; j++){ | |
if(options[j].equals("perm")) | |
perm = 1; | |
if(options[j].equals("urgent")) | |
urgent = true; | |
} | |
} | |
// 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"));} | |
EmployeeQueries.updateEmployee(Integer.parseInt(navsso), userName, phone, location, email); | |
System.out.print("updated employee "+userName); | |
// And now for the ticket | |
// First we need to parse the string of devices | |
String rawJSONString = request.getParameter("deviceIDs"); | |
rawJSONString = rawJSONString.replace("[",""); | |
rawJSONString = rawJSONString.replace("]",""); | |
rawJSONString = rawJSONString.replace("\"",""); | |
String[] idStringArray = rawJSONString.split(","); | |
int[] devIDs = new int[idStringArray.length]; | |
int j=0; | |
for(int i=0; i<idStringArray.length; i++) | |
{ | |
devIDs[j]=Integer.parseInt(idStringArray[i]); | |
j++; | |
} | |
// Now just call generateTicket once for each device (and store ticket IDs) | |
int[] ticketIDs = new int[devIDs.length]; | |
Ticket[] tickets = new Ticket[ticketIDs.length]; | |
// Yeah, I know, this probably looks kinda silly if you're seeing it for the first time. | |
for(int i=0; i<devIDs.length; i++) | |
{ | |
ticketIDs[i] = TicketQueries.generateTicket(Integer.parseInt(navsso), location, devIDs[i], request.getParameter("timeNeeded"), perm); | |
// We weren't using employee name, location name or device name on this page originally-only the info needed for the above generateTicket query. | |
tickets[i] = new Ticket(ticketIDs[i], | |
Integer.parseInt(navsso), | |
0, | |
location, | |
devIDs[i], | |
"Ready to Ship", | |
0, | |
request.getParameter("timeNeeded"), | |
request.getParameter("name"), | |
request.getParameter("locname"), | |
"",//TODO get device name | |
perm); | |
// But now that we want to include the extra info in emails, I'm also fetching it and making a Ticket array | |
// to pass to the relevant notification queues below. | |
} | |
// ------------------------------------------------- Email notifications ------------------------------------------------- | |
// First clients | |
boolean emailNotificationEnabled = (self.getNotificationPreferences()%2==1); | |
// The rightmost, least significant bit of the notificationPreferences integer is used for ticket generation emails. | |
if(emailNotificationEnabled) | |
{ | |
new Mail(self).sendTicketConfirmation(ticketIDs); //'self' is the current user, and is defined in navbar.jsp | |
} | |
// Now admins. | |
User[] admins = EmployeeQueries.getAllAdmins(); | |
// If an order is marked urgent this should be easy; just immediately send emails to all admins. | |
// However because setting up an email takes some time and there are many admins, we will still | |
// route these emails through a notification queue. Therefore the only difference here between an | |
// urgent order and a regular order will be the instructions we pass to the queue. | |
String instructions = (urgent) ? "adminUrgentRequest" : "adminDeviceRequest"; | |
AdminNotificationQueue Q = new AdminNotificationQueue(admins,instructions,tickets); | |
Q.start(); | |
%> | |
window.location.replace("../shoppingCart.jsp"); | |
</script> | |
</body> | |
</html> |