This repository has been archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
replyMsg.jsp
180 lines (166 loc) · 6.76 KB
/
replyMsg.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<%@page import="com.sun.mail.smtp.SMTPTransport"%>
<%@page import="java.util.Date"%>
<%@page import="javax.mail.internet.InternetAddress"%>
<%@page import="javax.mail.internet.MimeMessage"%>
<%@page import="javax.mail.Message"%>
<%@page import="javax.mail.Session"%>
<%@page import="java.util.Properties"%>
<%@page import="java.io.File"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.security.cert.CertPathValidatorException.Reason"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ include file="jspConfig.jsp" %>
<%@ include file="mail.jsp" %>
<%@ taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
try {
if(session.getAttribute("user") == null)
{
%>
<script>document.location = "/hostelFeedback/"</script>
<%
}
else
{
String roll = (String)session.getAttribute("user");
String type = "";
String subject = "";
String replied = "";
String msg = "";
String alert = "";
String hostel = "";
String contentType1 = request.getContentType();
int maxFileSize = 5000 * 1024;
int maxMemSize = 5000 * 1024;
ServletContext context = pageContext.getServletContext();
if ((contentType1.indexOf("multipart/form-data") >= 0)) {
DiskFileItemFactory factory1 = new DiskFileItemFactory();
// maximum size that will be stored in memory
factory1.setSizeThreshold(maxMemSize);
// Location to save data that is larger than maxMemSize.
//factory1.setRepository(new File("c:\\temp"));
// Create a new file upload handler
ServletFileUpload upload1 = new ServletFileUpload(factory1);
// maximum file size to be uploaded.
upload1.setSizeMax( maxFileSize );
// Parse the request to get file items.
List fileItems1 = upload1.parseRequest(request);
// Process the uploaded file items
Iterator i1 = fileItems1.iterator();
FileItem fi1;
String name = "";
String param = "";
while ( i1.hasNext () ) {
fi1 = (FileItem)i1.next();
if ( fi1.isFormField () ) {
// Get the uploaded file parameters
name = fi1.getFieldName();
param = fi1.getString();
if(name.equals("type"))
type = param;
else if(name.equals("replyingSubject"))
subject = param;
else if(name.equals("replyingId"))
replied = param;
else if(name.equals("reply"))
msg = param;
}
if(name.equals("reply"))
break;
}
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(mysqlURL,mysqlUser,mysqlPass);
PreparedStatement ps;
ResultSet rs;
ps = conn.prepareStatement("insert into message (user,type,subject,msg,repliedToId,ref_group) values (?,?,?,?,?,?)");
ps.setString(1, roll);
ps.setString(2, type);
ps.setString(3, subject);
ps.setString(4, msg);
ps.setString(5, replied);
ps.setString(6, "student");
ps.executeUpdate();
ps = conn.prepareStatement("select msgId from message where user = ? order by msgId desc");
ps.setString(1, roll);
rs = ps.executeQuery();
rs.next();
int id = rs.getInt(1);
ps = conn.prepareStatement("select data,hostel from student where email = ?");
ps.setString(1, roll);
rs = ps.executeQuery();
rs.next();
String data = rs.getString(1);
hostel = rs.getString(2);
ps = conn.prepareStatement("update message set viewed = 0 where msgId = ?");
ps.setString(1, replied);
ps.executeUpdate();
//ps = conn.prepareStatement("select email from hostelAdmin where hostel = ? union select email from typeOfMessageAdmin where type = ?");
//ps.setString(1, hostel);
//ps.setString(2, type);
//rs = ps.executeQuery();
//while(rs.next())
//{
// to = rs.getString(1);
//sendMail(to,"[Hostel Feedback System] New message recieved","There is an update. Please check your account" + "\n\n\nNote:This message was sent via the Hostel Feedback System by " + session.getAttribute("name") + "\nEmail ID:" + roll + "@cit.ac.in");
//}
conn.close();
File file ;
File newPath = new File(storageURL + data + "/" + id);
if(newPath.isDirectory() == false)
newPath.mkdir();
String filePath = storageURL + data + "/" + id + "/";
//if ((contentType1.indexOf("multipart/form-data") >= 0))
DiskFileItemFactory factory = new DiskFileItemFactory();
try {
// Parse the request to get file items.
//List fileItems = upload.parseRequest(request);
// Process the uploaded file items
//Iterator i = fileItems.iterator();
while(i1.hasNext()) {
fi1 = (FileItem)i1.next();
if ( !fi1.isFormField () ) {
// Get the uploaded file parameters
String fieldName = fi1.getFieldName();
String fileName = fi1.getName();
fileName = fileName.replace(" ", "");
if(fileName.equals("") == false )
{
boolean isInMemory = fi1.isInMemory();
long sizeInBytes = fi1.getSize();
// Write the file
if( fileName.lastIndexOf("/") >= 0 ) {
file = new File( filePath +
fileName.substring( fileName.lastIndexOf("/"))) ;
} else {
file = new File( filePath +
fileName.substring(fileName.lastIndexOf("/")+1)) ;
}
fi1.write( file ) ;
}
}
}
} catch(Exception ex) {
}
} else {
}
alert = "Message Sent...";
session.setAttribute("alert", alert);
%>
<script>document.location = "/hostelFeedback/"</script>
<%
}
}
catch(Exception e) {
%>
<jsp:forward page="/error/"></jsp:forward>
<%
}
%>