-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-group.jsp
executable file
·131 lines (104 loc) · 3.59 KB
/
update-group.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<%@ page import='java.sql.*' %>
<%@ page import='javax.sql.*' %>
<%@ page import='javax.naming.*' %>
<%@ page import='java.util.Properties' %>
<!--$URL: http://svn.visualdistortion.org/repos/projects/crash/post-comments.jsp $-->
<!--$Rev: 504 $ $Date: 2003-12-16 19:57:26 -0600 (Tue, 16 Dec 2003) $-->
<%
Context env = (Context) new InitialContext().lookup("java:comp/env/");
DataSource source = (DataSource) env.lookup("jdbc/postgresql");
Connection conn = source.getConnection();
int crash_id = Integer.parseInt(request.getParameter("crash_id"));
int user_id = 0;
int group_id = 0;
String group_name = request.getParameter("group_name");
String reason = request.getParameter("reason");
try {
group_id = Integer.parseInt(request.getParameter("group"));
} catch (NumberFormatException e) {
group_id = 0;
}
try {
user_id = Integer.parseInt(request.getParameter("user_id"));
} catch (NumberFormatException e) {
out.print("<h1>Get a user_id!</h1>");
}
if(group_name != null && group_name.equals("") ){
group_name = null;
}
PreparedStatement pstmt = null;
ResultSet rset = null;
try {
if(group_id == 0 && group_name != null) {
pstmt = conn.prepareStatement("insert into crash.groups " +
"(created_by, description) values " +
"(?,?)");
pstmt.setInt(1, user_id);
pstmt.setString(2, group_name);
pstmt.executeUpdate();
pstmt = conn.prepareStatement("select group_id from crash.groups " +
" where description = ? ");
pstmt.setString(1, group_name);
rset = pstmt.executeQuery();
while(rset.next()) {
group_id = rset.getInt("group_id");
}
}
pstmt = conn.prepareStatement("insert into crash.group_history " +
"(user_id, crash_id, group_id, reason) values " +
"(?,?,?,?)");
pstmt.setInt(1, user_id);
pstmt.setInt(2, crash_id);
pstmt.setInt(3, group_id);
pstmt.setString(4, reason);
pstmt.executeUpdate();
pstmt = conn.prepareStatement("insert into crash.crash_group " +
" (crash_id, group_id) values " +
" (?, ?)");
pstmt.setInt(1, crash_id);
pstmt.setInt(2, group_id);
pstmt.executeUpdate();
/*
//send an email
Properties props = new Properties();
props.put("mail.smtp.host", "calvin.slamb.org");
Session s = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(s);
InternetAddress from;
try {
from = new InternetAddress(email);
message.setFrom(from);
} catch (AddressException ae) {
from = new InternetAddress("[email protected]");
message.setFrom(from);
} catch (MessagingException e) {
from = new InternetAddress("[email protected]");
message.setFrom(from);
}
InternetAddress to = new InternetAddress("[email protected]");
message.setRecipient(Message.RecipientType.TO, to);
message.setSubject("Feedback added to picture " + pic);
message.setText(name + "\n" +
email + "\n" +
subject + "\n" +
body + "\n\n" +
"\n\nhttp://www.visualdistortion.org/pictures/viewcomments.jsp?pic=" + pic);
try {
Transport.send(message);
} catch (SendFailedException e) {
InternetAddress from2 = new InternetAddress("[email protected]");
message.setFrom(from2);
Transport.send(message);
}
*/
response.sendRedirect("view.jsp?crash=" + crash_id);
} catch(SQLException e) {
out.print("Group not entered successfully!<br>");
out.print(e.getMessage());
}
finally {
conn.close();
}
%>
</body>
</html>