Skip to content

Commit

Permalink
I have learned to hate JSON.
Browse files Browse the repository at this point in the history
Goodnight.
  • Loading branch information
clj13001 committed Apr 21, 2017
1 parent 1f3595a commit 684f004
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 22 deletions.
8 changes: 6 additions & 2 deletions WebContent/html/webpages/administration/adminApprove.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<th>Location Name</th>
<th>Device Name</th>
<th>Status</th>
<th>Permanent?</th>
<th>Return Date</th>
</tr>
</thead>
Expand All @@ -118,6 +119,7 @@
<input type = "text" id = "ticketIDfield" name = "ticketid" style = "display: none;">
<input type = "text" id = "deviceIDfield" name = "deviceid" style = "display: none;">
<input type = "text" id = "locationIDfield" name = "locationid" style = "display: none;">
<input type = "text" id = "permField" name = "permField" style = "display: none;">
</form>
</div>
</div>
Expand All @@ -133,6 +135,7 @@
<th>Location Name</th>
<th>Device Name</th>
<th>Status</th>
<th>Permanent?</th>
<th>Return Date</th>
</tr>
</thead>
Expand Down Expand Up @@ -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 += "<tr class = 'entry' id = '" + i + "'><td>" + tickets[i].id + "</td><td>" + tickets[i].username + "</td><td>" + tickets[i].locationname + "</td><td>" + tickets[i].devicename + "</td><td>" + tickets[i].status + "</td><td>" + tickets[i].return + "</td></tr>";
html += "<tr class = 'entry' id = '" + i + "'><td>" + tickets[i].id + "</td><td>" + tickets[i].username + "</td><td>" + tickets[i].locationname + "</td><td>" + tickets[i].devicename + "</td><td>" + tickets[i].status + "</td><td>" + tickets[i].permanent + "</td><td>" + tickets[i].return + "</td></tr>";
}
document.getElementById("tablebodymain").innerHTML = html;
}
function ticketAction(){
var id = this.id;
var html = "<tr><td>" + tickets[id].id + "</td><td>" + tickets[id].username + "</td><td>" + tickets[id].locationname + "</td><td>" + tickets[id].devicename + "</td><td>" + tickets[id].status + "</td><td>" + tickets[id].return + "</td></tr>";
var html = "<tr><td>" + tickets[id].id + "</td><td>" + tickets[id].username + "</td><td>" + tickets[id].locationname + "</td><td>" + tickets[id].devicename + "</td><td>" + tickets[id].status + "</td><td>" + tickets[id].permanent + "</td><td>" + tickets[id].return + "</td></tr>";
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();
}
Expand Down
66 changes: 66 additions & 0 deletions WebContent/html/webpages/administration/ticketApprove.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<%@ page import = "database.*,entities.Location" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
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">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">

<title>Innovation Hub</title>

<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.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>
<link rel = "stylesheet" type = "text/css" href = "../../css/stylesheet.css">
<link rel = "shortcut icon" href = "../../imgs/synchrony-financial-logo-dlpx_1.ico">
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="../components/navbar.jsp"%>
</nav>
<style>
p{
margin: 0px;
}
</style>
</head>
<body>
<div style = "margin-left: 15px;">
<h2>Approving Tickets</h2>
<p>Thanks for approving a ticket!</p>
<p>You can ship the devices to the following address:</p>
<div style = "background-color: white; display: inline-block; padding: 10px; margin-bottom: 5px; border-radius: 5px;">
Synchrony Financial<br><p id="name"></p><p id="address"></p><p id = "location"></p><p id = "zip"></p>
</div>
<form action = "../returnPage.jsp">
<button type = "submit" class = "btn btn-primary">Go Back</button>
</form>
</div>
</body>
<%
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();
%>
<script>
var name = '<%=navname%>';
document.getElementById("name").innerHTML = "ATTN: " + name;
document.getElementById("address").innerHTML = '<%=address%>';
document.getElementById("location").innerHTML = '<%=town%>' + ", " + '<%=state%>' + " " + '<%=zip%>';
</script>
</html>
4 changes: 2 additions & 2 deletions WebContent/html/webpages/redirect/locationRedirect.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions WebContent/html/webpages/redirect/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));}
Expand Down
19 changes: 11 additions & 8 deletions WebContent/html/webpages/redirect/ticketAdminRedirect.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,32 @@
</nav>
</head>
<body>
<h2>Redirect Page</h2>
<p>You shouldn't be seeing this page :)</p>

<%
//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
Expand All @@ -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;
}
}
%>
<script>
window.location.replace("../administration/adminApprove.jsp");
</script>
<!-- Navbar generation. -->
</body>
</html>
40 changes: 40 additions & 0 deletions src/database/LocationQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
9 changes: 6 additions & 3 deletions src/database/TicketQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++;
}
Expand Down
8 changes: 7 additions & 1 deletion src/entities/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(){
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/NotificationQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 684f004

Please sign in to comment.