diff --git a/WebContent/html/webpages/index.html b/WebContent/html/webpages/index.html index 5f5a100..6796a98 100644 --- a/WebContent/html/webpages/index.html +++ b/WebContent/html/webpages/index.html @@ -53,7 +53,7 @@

Request

Check out our selection of devices that YOU have the chance to check out!

- +
@@ -244,7 +247,9 @@ 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(); } @@ -252,7 +257,22 @@ function returnDevice() 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; +} - \ No newline at end of file + + \ No newline at end of file diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index 404d095..69c1138 100644 --- a/src/database/MySQLAccess.java +++ b/src/database/MySQLAccess.java @@ -80,6 +80,27 @@ 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++){ + String current = deviceArray[i]; + } + } + public String[][] getResult(){ return result; }