Skip to content

Commit

Permalink
Merge pull request #33 from arc12012/Connor-Branch
Browse files Browse the repository at this point in the history
Connor branch
  • Loading branch information
clj13001 committed Mar 23, 2017
2 parents cf16ef8 + c5339d6 commit c725b69
Show file tree
Hide file tree
Showing 8 changed files with 749 additions and 18 deletions.
389 changes: 389 additions & 0 deletions WebContent/html/webpages/adminLocation.jsp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion WebContent/html/webpages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2>Request</h2>
<p>Check out our selection of devices that YOU have the chance to check out!</p>
</div>
</a>
<a class = "divlink" href="returnPage.html">
<a class = "divlink" href="returnPage.jsp">
<div class = "menuOption">
<h2>Return</h2>
<p>All set with a device? No problem! You can return it here!</p>
Expand Down
64 changes: 64 additions & 0 deletions WebContent/html/webpages/locationRedirect.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<%@ page import = "database.MySQLAccess,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>Synchrony Financial</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">
</nav>
</head>
<body>
<h2>Redirect Page</h2>
<p>You shouldn't be seeing this page :)</p>

<%
//make instance
MySQLAccess myaccess = new MySQLAccess();
String name = request.getParameter("name").replace("\"","\\\"");
String address = request.getParameter("address").replace("\"","\\\"");
String town = request.getParameter("town").replace("\"","\\\"");
String state = request.getParameter("state");
String zip = request.getParameter("zip");
//add form was submitted
if(request.getParameter("add") != null){
Location location = new Location(name,address,town,state,zip);
myaccess.addLocation(location);
}
//modify form was submitted
if(request.getParameter("modify") != null){
//getParameter() always returns string
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);
myaccess.modifyLocation(location);
}
//delete form was submitted
if(request.getParameter("delete") != null){
String strID = request.getParameter("id");
int id = Integer.parseInt(strID);
myaccess.deleteLocation(id);
}
%>
<script>
window.location.replace("adminLocation.jsp");
</script>
<!-- Navbar generation. -->
<script src = "../javascript/navbar.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions WebContent/html/webpages/profileSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
</head>

<body>
<!-- Header. -->
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
</nav>
<!-- Sidebar -->
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<h4>User Profile Settings</h4>
Expand All @@ -67,6 +69,7 @@ <h4>User Profile Settings</h4>
</ul>
</div>

<!-- Popup to indicate info is missing -->
<div class = "modal" id = "missingcontent">
<div class = "modal-content">
<div class = "modal-head">
Expand All @@ -78,15 +81,18 @@ <h4>User Profile Settings</h4>
</div>
</div>

<!-- All profile information -->
<div class = "profileContainer">
<div style = "display: inline-block;">
<!-- Where profile image gets edited -->
<div class = "imageContainer">
<img id = "profimg">
</div>
<br>
<p style = "display: inline-block;">Change profile image:</p>
<div id="my-icon-select" style = "display: inline-block;"></div>
</div>
<!-- Where main user information is edited -->
<form class = "infobar">
<h2>Profile Settings</h2>
<div class = "form-group">
Expand Down
39 changes: 39 additions & 0 deletions WebContent/html/webpages/returnComplete.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%@ page import = "database.MySQLAccess,entities.RentedDevice" %>
<%@ 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>Synchrony Financial</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">
</nav>
</head>
<body>
<h2>Returning Devices</h2>
<p>Thanks for returning some devices!</p>

<%
//make instance
MySQLAccess myaccess = new MySQLAccess();
//get string from request form
String devices = request.getParameter("devicesToReturn");
myaccess.returnDevices(devices);
%>
<!-- Navbar generation. -->
<script src = "../javascript/navbar.js"></script>
</body>
</html>
50 changes: 35 additions & 15 deletions WebContent/html/webpages/returnPage.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,22 @@
<h4>Please Review Your Return Choices</h4>
</div><br>
<div class="modal-body">
<!-- Table to display review data. -->
<table class="table table-bordered table-hover" id = "tabledisplay">
<thread>
<tr>
<th>Device Name</th>
<th>Model</th>
<th>Hardware</th>
</tr>
</thread>
<tbody id = "tablebody">
</tbody>
</table><br>
<button>Continue</button>
<!-- Table to display review data. -->
<table class="table table-bordered table-hover" id = "tabledisplay">
<thread>
<tr>
<th>Device Name</th>
<th>Model</th>
<th>Hardware</th>
</tr>
</thread>
<tbody id = "tablebody">
</tbody>
</table><br>
<form ACTION = "returnComplete.jsp" METHOD = "POST">
<input type = "text" id = "deviceArray" style = "display: none;" name = "devicesToReturn"></input>
<input type = "submit" value = "Submit">
</form>
</div>
</div>
</div>
Expand Down Expand Up @@ -244,15 +247,32 @@ function returnDevice()
}
//place html in body
document.getElementById("tablebody").innerHTML = html;
//show modal
//place input in form
$('#deviceArray').val(arrayToString(toReturn));
//show modal
$('#orderInfoModal').show();
}
//Call to exit modal
function hidePopup(){
$('#orderInfoModal').hide();
}
//Turns array to string, which can be submitted on the form when actually returning
//The string will contain the ID's of devices to be returned, and this will be sent to the database!
function arrayToString(array){
var sb = "[";
for(var i = 0; i < array.length; i++){
//get the return id, go to that index in queried devices, and get that id!
sb+= devices[array[i]].id;
if(i != array.length-1)
sb+=",";
}
sb+="]";
return sb;
}
</script>
<!-- Navbar generation. -->
<script src = "../javascript/navbar.js"></script>
</body>
</body>
</html>
110 changes: 108 additions & 2 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.sql.*;

import entities.ListedDevice;
import entities.Location;
import entities.RentedDevice;

public class MySQLAccess {
Expand All @@ -24,7 +25,7 @@ public RentedDevice[] getUserDevices(String userID) throws SQLException, ClassNo
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
Statement stmt = connect.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Hardware, Model, Borrow_Date FROM devices WHERE Renter = " + userID);
ResultSet resultSet = stmt.executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Hardware, Model, Borrow_Date FROM devices WHERE Renter = " + userID + " AND Status <> \"Available\" AND Status <> \"Returning \"");
int counter = 0;

resultSet.last();
Expand All @@ -44,7 +45,7 @@ public RentedDevice[] getUserDevices(String userID) throws SQLException, ClassNo
}

public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundException{
//Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter
//database connect
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
Expand All @@ -68,6 +69,111 @@ public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundExceptio
return devices;
}

/**
* This function will take devices as input and return them.
* More specifically, the input will be a string that looks like an array.
* The values in this array correspond to device ID's.
* @param devices
* @throws ClassNotFoundException
* @throws SQLException
*/
public void returnDevices(String devices) throws ClassNotFoundException, SQLException{
//connect to DB
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
Statement stmt = connect.createStatement();
//make into string array; queries need to have numbers as strings!
String[] deviceArray = devices.replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\s","").split(",");
for(int i = 0; i < deviceArray.length; i++){
//update statement
stmt.executeUpdate("UPDATE devices SET Status = \"Returning\" WHERE Device_ID = " + deviceArray[i]);
}
System.out.println("\nUpdates complete\n");
}

public Location[] getLocations() throws ClassNotFoundException, SQLException{
//database connect
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
Statement stmt = connect.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * FROM location WHERE Zip_Code <> \"00000\"");
int counter = 0;

resultSet.last();
int rows = resultSet.getRow();
resultSet.beforeFirst();

//Covers amount of rows, and 6 attributes (indices 0-5)
Location[] locations = new Location[rows];

//iterate result set
while(resultSet.next()){
locations[counter] = new Location(resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Address"),resultSet.getString("Town"),resultSet.getString("State"),resultSet.getString("Zip_Code"));
counter++;
}
stmt.close();
connect.close();
return locations;
}

/**
* Adds location to mySQL database.
* @throws ClassNotFoundException
* @throws SQLException
*/
public void addLocation(Location location) throws ClassNotFoundException, SQLException{
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
Statement stmt = connect.createStatement();
int i = -1;
while(i <= 0){
ResultSet results = stmt.executeQuery("SELECT * from location ORDER BY Location_ID");
results.last();
//gets largest ID
int id = results.getInt("Location_ID");
id++;
//tries this statement, otherwise tries again with a new id
i = stmt.executeUpdate("INSERT INTO location (Location_ID,Name,Address,Town,State,Zip_Code) VALUES (" + id +",\"" + location.getName() + "\",\"" + location.getAddress()+ "\",\"" + location.getTown() + "\",\"" + location.getState() + "\",\"" + location.getZip()+ "\")");
}
stmt.close();
connect.close();
}

/**
* Updates a location, assuming that all input fields have been changed.
* @param location
* @throws ClassNotFoundException
* @throws SQLException
*/
public void modifyLocation(Location location) throws ClassNotFoundException, SQLException{
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
Statement stmt = connect.createStatement();
stmt.executeUpdate("UPDATE location SET Name = \"" + location.getName() + "\", Address = \"" + location.getAddress() + "\", Town = \"" + location.getTown() + "\", State = \"" + location.getState() + "\", Zip_Code = \"" + location.getZip() + "\" WHERE Location_ID = " + location.getID());
stmt.close();
connect.close();
}

/**
* Deletes a location based on input id.
* @param id
* @throws ClassNotFoundException
* @throws SQLException
*/
public void deleteLocation(int id) throws ClassNotFoundException, SQLException{
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
Statement stmt = connect.createStatement();
stmt.executeUpdate("DELETE from location WHERE Location_ID = " + id);
stmt.close();
connect.close();
}

public String[][] getResult(){
return result;
}
Expand Down
Loading

0 comments on commit c725b69

Please sign in to comment.