diff --git a/WebContent/html/webpages/administration/adminApprove.jsp b/WebContent/html/webpages/administration/adminApprove.jsp index e144f39..1820d59 100644 --- a/WebContent/html/webpages/administration/adminApprove.jsp +++ b/WebContent/html/webpages/administration/adminApprove.jsp @@ -107,6 +107,7 @@ Location Name Device Name Status + Permanent? Return Date @@ -118,6 +119,7 @@ + @@ -133,6 +135,7 @@ Location Name Device Name Status + Permanent? Return Date @@ -167,18 +170,19 @@ var html = ""; for(var i = 0; i < tickets.length; i++){ //NEED TO ADD IN RETURN DATE AT END BUT THAT WOULD BREAK THINGS AT THE MOMENT - html += "" + tickets[i].id + "" + tickets[i].username + "" + tickets[i].locationname + "" + tickets[i].devicename + "" + tickets[i].status + "" + tickets[i].return + ""; + html += "" + tickets[i].id + "" + tickets[i].username + "" + tickets[i].locationname + "" + tickets[i].devicename + "" + tickets[i].status + "" + tickets[i].permanent + "" + tickets[i].return + ""; } document.getElementById("tablebodymain").innerHTML = html; } function ticketAction(){ var id = this.id; - var html = "" + tickets[id].id + "" + tickets[id].username + "" + tickets[id].locationname + "" + tickets[id].devicename + "" + tickets[id].status + "" + tickets[id].return + ""; + var html = "" + tickets[id].id + "" + tickets[id].username + "" + tickets[id].locationname + "" + tickets[id].devicename + "" + tickets[id].status + "" + tickets[id].permanent + "" + tickets[id].return + ""; document.getElementById("tablemodal").innerHTML = html; $("#ticketIDfield").val(tickets[id].id); $("#deviceIDfield").val(tickets[id].deviceID); $("#locationIDfield").val(tickets[id].location); + $("#permField").val(tickets[id].permanent); $("#Modal").show(); } diff --git a/WebContent/html/webpages/administration/ticketApprove.jsp b/WebContent/html/webpages/administration/ticketApprove.jsp new file mode 100644 index 0000000..7b35f4c --- /dev/null +++ b/WebContent/html/webpages/administration/ticketApprove.jsp @@ -0,0 +1,66 @@ +<%@ page import = "database.*,entities.Location" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + + + + + + Innovation Hub + + + + + + + + + + + +
+

Approving Tickets

+

Thanks for approving a ticket!

+

You can ship the devices to the following address:

+
+ Synchrony Financial

+
+
+ +
+
+ +<% +int locationid = -1; +for(Cookie c : usercookies){ + if(c.getName().equals("location")){ + locationid = Integer.parseInt(c.getValue()); + c.setMaxAge(0); + c.setPath("/"); + response.addCookie(c); + } +} +Location location = LocationQueries.getLocationByID(locationid); +String address = location.getAddress(); +String town = location.getTown(); +String state = location.getState(); +String zip = location.getZip(); +%> + + \ No newline at end of file diff --git a/WebContent/html/webpages/redirect/locationRedirect.jsp b/WebContent/html/webpages/redirect/locationRedirect.jsp index 8700f23..9c80f3d 100644 --- a/WebContent/html/webpages/redirect/locationRedirect.jsp +++ b/WebContent/html/webpages/redirect/locationRedirect.jsp @@ -37,7 +37,7 @@ String lng = request.getParameter("lng"); int er = 0; //add form was submitted if(request.getParameter("add") != null){ - Location location = new Location(0,name,address,town,state,zip,0,lat,lng); + Location location = new Location(0,name,address,town,state,zip,0,lat,lng,0,0); LocationQueries.addLocation(location); } //modify form was submitted @@ -46,7 +46,7 @@ if(request.getParameter("modify") != null){ String strID = request.getParameter("id"); //turn to int for constructor int id = Integer.parseInt(strID); - Location location = new Location(id,name,address,town,state,zip,0,lat,lng); + Location location = new Location(id,name,address,town,state,zip,0,lat,lng,0,0); LocationQueries.modifyLocation(location); } //delete form was submitted diff --git a/WebContent/html/webpages/redirect/orderFormHandler.jsp b/WebContent/html/webpages/redirect/orderFormHandler.jsp index b2c680a..aff74f9 100644 --- a/WebContent/html/webpages/redirect/orderFormHandler.jsp +++ b/WebContent/html/webpages/redirect/orderFormHandler.jsp @@ -43,11 +43,13 @@ String email = request.getParameter("email"); String[] options = request.getParameterValues("checkboxes"); int perm = 0; int urgent = 0; -for(int j = 0; j < options.length; j++){ - if(options[j].equals("perm")) - perm = 1; - if(options[j].equals("urgent")) - urgent = 1; +if(options != null){ + for(int j = 0; j < options.length; j++){ + if(options[j].equals("perm")) + perm = 1; + if(options[j].equals("urgent")) + urgent = 1; + } } // 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"));} diff --git a/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp b/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp index e85a30f..2ab57a0 100644 --- a/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp +++ b/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp @@ -23,27 +23,32 @@ -

Redirect Page

-

You shouldn't be seeing this page :)

- <% //make instance String ticketidstr = request.getParameter("ticketid"); String deviceidstr = request.getParameter("deviceid"); String locationidstr = request.getParameter("locationid"); +String permanent = request.getParameter("permField"); int ticketid = Integer.parseInt(ticketidstr); int deviceid = Integer.parseInt(deviceidstr); int locationid = Integer.parseInt(locationidstr); +int perm = permanent.equals("Yes") ? 1 : 0; //approve form was submitted if(request.getParameter("approve") != null){ - TicketQueries.acceptTicket(ticketid,deviceid,locationid,Integer.parseInt(navsso)); + Cookie location = new Cookie("location",Integer.toString(locationid)); + location.setMaxAge(30*60); + location.setPath("/"); + response.addCookie(location); + TicketQueries.acceptTicket(ticketid,deviceid,locationid,Integer.parseInt(navsso),perm); User client = EmployeeQueries.getEmployeeByID(TicketQueries.getUserID(ticketid)); boolean notificationPreferences = (Math.floor(client.getNotificationPreferences()/2)%2==1); //The second least significant bit of notificationPreferences - the 2's place - is used for ticket approval notifications. if(notificationPreferences){ NotificationQueue q = new NotificationQueue(client,"ticketConfirmations"); q.start(); + response.sendRedirect("../administration/ticketApprove.jsp"); + return; } } //reject form was submitted @@ -55,12 +60,10 @@ if(request.getParameter("reject") != null){ if(notificationPreferences){ NotificationQueue q = new NotificationQueue(client, "ticketRejections"); q.start(); + response.sendRedirect("../administration/adminApprove.jsp"); + return; } } %> - - \ No newline at end of file diff --git a/src/database/LocationQueries.java b/src/database/LocationQueries.java index db96484..d3e5222 100644 --- a/src/database/LocationQueries.java +++ b/src/database/LocationQueries.java @@ -386,4 +386,44 @@ public static Location[] getAllLocations() throws SQLException, ClassNotFoundExc connection.close(); return locations; } + + public static Location getLocationByID(int id) throws InterruptedException, ClassNotFoundException, SQLException{ + //database connect + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("SELECT * FROM location WHERE Location_ID = " + id); + resultSet.next(); + return new Location( + resultSet.getInt("Location_ID"), + resultSet.getString("Name"), + resultSet.getString("Address"), + resultSet.getString("Town"), + resultSet.getString("State"), + resultSet.getString("Zip_Code"), + resultSet.getInt("Employee_Flag"), + resultSet.getString("Latitude"), + resultSet.getString("Longitude"), + 0,0 + ); + } } \ No newline at end of file diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index 0f28d9e..65d29d7 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -102,7 +102,8 @@ public static Ticket[] getTickets() resultSet.getString("Return_Date"), resultSet.getString("username"), resultSet.getString("Device_Name"), - resultSet.getString("locationname") + resultSet.getString("locationname"), + resultSet.getInt("Permanent_Order") ); i++; } @@ -111,7 +112,7 @@ public static Ticket[] getTickets() return tickets; } - public static void acceptTicket(int ticketid, int deviceid, int locationid, int sso) + public static void acceptTicket(int ticketid, int deviceid, int locationid, int sso, int perm) throws SQLException, ClassNotFoundException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); @@ -141,6 +142,7 @@ public static void acceptTicket(int ticketid, int deviceid, int locationid, int +", devices.Ticket_ID = " + ticketid +", devices.Status = \"Ready to Ship\", devices.Renter = " + sso +", devices.Location = " + locationid + +", devices.Permanent = " + perm +" WHERE ticket.Ticket_ID = " + ticketid + " AND devices.Device_ID = " + deviceid; System.out.println("Executing query: "+query); stmt.executeUpdate(query); @@ -246,7 +248,8 @@ public static Ticket[] getRecentlyChangedTickets(int userID, String status, long results.getString("Return_Date"), results.getString("username"), results.getString("locationname"), - results.getString("Device_Name") + results.getString("Device_Name"), + results.getInt("Permanent_Order") ); i++; } diff --git a/src/entities/Ticket.java b/src/entities/Ticket.java index f66ec62..e6b1bea 100644 --- a/src/entities/Ticket.java +++ b/src/entities/Ticket.java @@ -15,8 +15,9 @@ public class Ticket { private String username; private String locationname; private String devicename; + private String permanent; - public Ticket(int id, int requestor, long requestDate, int location, int deviceId, String status, long statusDateFields, String returnDate, String username, String locationname, String devicename){ + public Ticket(int id, int requestor, long requestDate, int location, int deviceId, String status, long statusDateFields, String returnDate, String username, String locationname, String devicename, int permanent){ this._id = id; this._requestor = requestor; this._requestDate = requestDate; @@ -28,6 +29,10 @@ public Ticket(int id, int requestor, long requestDate, int location, int deviceI this.username = username; this.locationname = locationname; this.devicename = devicename; + if(permanent == 0) + this.permanent = "No"; + else + this.permanent = "Yes"; } public String toString(){ @@ -41,6 +46,7 @@ public String toString(){ sb.append("\"username\": \"").append(username).append("\"").append(comma); sb.append("\"locationname\": \"").append(locationname).append("\"").append(comma); sb.append("\"devicename\": \"").append(devicename).append("\"").append(comma); + sb.append("\"permanent\": \"").append(permanent).append("\"").append(comma); sb.append("\"return\": \"").append(_returnDate).append("\""); sb.append("}"); return sb.toString(); diff --git a/src/utilities/NotificationQueue.java b/src/utilities/NotificationQueue.java index 06bf161..62e39e0 100644 --- a/src/utilities/NotificationQueue.java +++ b/src/utilities/NotificationQueue.java @@ -99,7 +99,7 @@ private void startTicketApproveQueue(User employee) throws InterruptedException, long milliseconds = new Date().getTime()-5000; Thread.sleep(threadWaitTime); System.out.println("NotificationQueue: sending summary approval email from thread "+Thread.currentThread().getName()); - Ticket[] tickets = TicketQueries.getRecentlyChangedTickets(employee.getID(), "Shipped", milliseconds); + Ticket[] tickets = TicketQueries.getRecentlyChangedTickets(employee.getID(), "Approved", milliseconds); Mail mail = new Mail(employee); mail.sendTicketApproval(tickets); }