Skip to content

Commit

Permalink
Fixed bugs from previous commit. Notification preferences work now, j…
Browse files Browse the repository at this point in the history
…ust look bad.
  • Loading branch information
arc12012 committed Apr 20, 2017
1 parent ba78b24 commit 64ae85a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
10 changes: 6 additions & 4 deletions WebContent/html/webpages/profileSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@
<!-- Notification Settings -->
<div class = "notificationContainer" style = "visibility: hidden;">
<!-- Where main user information is edited -->
<form action = "redirect/notificationSettingsRedirect.jsp" class = "notificationForm" onsubmit="applyNotifications">
<form name="notificationForm" onsubmit="return applyNotifiationChanges()" action = "redirect/notificationSettingsRedirect.jsp" class = "infobar" method="post">
<h2>Email Notification Settings</h2>
<br>
<h4>Send me a messege when...</h4>
<input name="prefferedNotificationInteger" style="display: none;">
<input name="user" style="display: none;" value='"<%=self.getID()%>'>
<input name="user" style="display: none;" value='<%=self.getID()%>'>
<div style="float: left; margin-right: 10px;"><h5>Tickets are generated</h5></div>
<div style="float: right;">
<label class="switch">
Expand All @@ -153,7 +153,7 @@
<div class="slider round"></div>
</label></div><br><br><br>
<div style="text-align: center;">
<button name = "notification" type="submit" class="btn btn-primary" id = "applyNotifications">Apply Changes</button>
<button name = "notification" type="submit" class="btn btn-primary">Apply Changes</button>
<button name="leaveMeAlone" class="btn btn-primary" style="background-color: red">Please just leave me alone</button>
</div>
</form>
Expand Down Expand Up @@ -199,6 +199,7 @@
document.getElementById('closeBttn').addEventListener('click',function(){document.getElementById('missingcontent').style.display = "none";});
// Listeners for notification settings
document.getElementsByName('leaveMeAlone')[0].addEventListener('click',disableAllNotifications);
var typeTimer;
var doneTypingInterval = 2000 //ms
Expand Down Expand Up @@ -253,7 +254,8 @@
var bit2 = document.getElementById('notificationSlider2').checked ? 1 : 0;
var bit3 = document.getElementById('notificationSlider3').checked ? 1 : 0;
var newNotificationPreferenceInteger = 1*bit1 + 2*bit2 + 4*bit3;
document.notificationForm.prefferedNotificationInteger.value=NotificationPreferenceInteger;
document.notificationForm.prefferedNotificationInteger.value=newNotificationPreferenceInteger;
return true;
}
//populates form fields if info exists in db already
function populate(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pageEncoding="ISO-8859-1"%>
<%
int user = Integer.parseInt(request.getParameter("prefferedNotificationInteger"));
int prefs = Integer.parseInt(request.getParameter("user"));
EmployeeQueries.updateNotificationPreferences(user,prefs);
EmployeeQueries.updateNotificationPreferences(prefs,user);
%>
<script>
window.location.replace("../profileSettings.jsp");
Expand Down
9 changes: 6 additions & 3 deletions src/database/EmployeeQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public static User getEmployeeByID(int id) throws ClassNotFoundException, SQLExc
resultSet.getString("Name"),
resultSet.getString("Phone_Number"),
resultSet.getString("Email"),
resultSet.getInt("Img_Index")
resultSet.getInt("Img_Index"),
resultSet.getInt("Notification_Preference")
);
resultSet = stmt.executeQuery("SELECT Address FROM location WHERE Location_ID = "+employee.getLocation());
resultSet.next();
Expand Down Expand Up @@ -113,7 +114,7 @@ public static User[] getAllUsers() throws SQLException, ClassNotFoundException{

//iterate result set
while(resultSet.next()){
users[counter] = new User(resultSet.getInt("Employee_ID"),resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Phone_Number"),resultSet.getString("Email"),resultSet.getInt("Img_Index"));
users[counter] = new User(resultSet.getInt("Employee_ID"),resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Phone_Number"),resultSet.getString("Email"),resultSet.getInt("Img_Index"),resultSet.getInt("Notification_Preference"));
counter++;
}

Expand All @@ -127,7 +128,9 @@ public static void updateNotificationPreferences(int client, int preferences) th
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database, user, password);
Statement statement = connect.createStatement();
statement.executeQuery("UPDATE employee SET Notification_Preference = "+preferences+" WHERE Employee_ID = "+client+";");
String query = "UPDATE employee SET Notification_Preference = "+preferences+" WHERE Employee_ID = "+client+";";
System.out.println("Executing query: "+query);
statement.executeUpdate(query);
statement.close();
connect.close();
}
Expand Down
4 changes: 2 additions & 2 deletions src/entities/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class Admin extends User {
private int password_flag;
private int finger_flag;

public Admin(int id, int location, String name, String phone, String email, int icon, int pass, int finger) {
super(id, location, name, phone, email, icon);
public Admin(int id, int location, String name, String phone, String email, int icon, int pass, int finger, int notificationPreferences) {
super(id, location, name, phone, email, icon, notificationPreferences);
password_flag = pass;
finger_flag = finger;
}
Expand Down
4 changes: 2 additions & 2 deletions src/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public User(){
//empty
}

public User(int id, int location, String name, String phone, String email, int icon){
public User(int id, int location, String name, String phone, String email, int icon, int notificationPreferences){
this.id = id;
this.location = location;
this.name = name; //later will do table lookup to determine by id
this.phone = phone;
this.email = email;
this.icon = icon;
this.notificationPreferences = 1+2+4;
this.notificationPreferences = notificationPreferences;
}

public int getIcon(){
Expand Down

0 comments on commit 64ae85a

Please sign in to comment.