-
Notifications
You must be signed in to change notification settings - Fork 1
/
Book5.jsp
338 lines (259 loc) · 8.56 KB
/
Book5.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<%@page import="com.itextpdf.text.PageSize"%>
<%@page import="com.itextpdf.text.Font"%>
<%@page import="com.itextpdf.text.Element"%>
<%@page import="com.itextpdf.text.pdf.PdfPCell"%>
<%@page import="com.itextpdf.text.pdf.PdfPTable"%>
<%@page import="com.itextpdf.text.Image"%>
<%@page import="com.itextpdf.text.Paragraph"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="com.itextpdf.text.pdf.PdfWriter"%>
<%@page import="com.itextpdf.text.Document"%>
<%@page import="java.sql.Time"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
<head>
<title>Booking</title>
<meta name="keywords" content="Home" />
<link href="./css/templatemo_style.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.ennui.contentslider.css" rel="stylesheet" type="text/css" media="screen,projection" />
<%!
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
public void jspInit(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/train","root","");
}
catch(Exception e ){
e.printStackTrace();
}
}
%>
<script type="text/javascript">
//script to disable goback button of the browser
//function forwards to the next page from history of cache
function noBack(){
window.history.forward();
}
//Calls noBack() function
function Back(){
if (event.persisted){
noBack();
}
}
window.onload=noBack();
window.onpageshow = Back();
</script>
<!-- Special Font & Symbol -->
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script>
$(function(){
$("#header").load("header.html");
});
</script>
<script>
$(function(){
$("#footer").load("footer.html");
});
</script>
</head>
<body>
<div id="templatemo_wrapper">
<div id="templatemo_header">
<div id="site_title">
<h1><a href="home.jsp">
<img src="./images/logo.jpg" alt="Commuters Guide" width="480" height="93" />
</a></h1>
</div>
<!-- end of templatemo_menu -->
<div class="cleaner"></div>
</div> <!-- end of header -->
<div id="header"></div>
<div id="templatemo_content">
<!-- Form Body -->
<div>
<%
//Session Validation
try{
if(session.isNew()){
out.println("<h3><span style='color: red;'>Access Denied please login to access </span></h3>");
}
else{
String uname = (String)session.getAttribute("uname");
String ssid = (String)session.getAttribute("sid");
String author = (String)session.getAttribute("author");
String sessionid = (String)session.getId();
String uid = (String)session.getAttribute("uid");
if(ssid == sessionid && author.equals("user")) {
%>
<%
int pnrno=0;
String date_book="";
String date_dep="";
int tno=0;
int km=0;
String clas="";
String coach="";
int adult1=0;
int child1=0;
String src="";
String des="";
String source="";
String dest="";
double total1= 0;
try{
total1 = Double.parseDouble(request.getParameter("total1"));
//To get the amount from the credit table
String sql8 ="select amt from credit where user_id="+uid+" ";
pstmt = con.prepareStatement(sql8);
rs = pstmt.executeQuery();
double amount = 0;
if(rs.next()){
amount = rs.getDouble("amt");
}
double dec = amount - total1;
//to deduct amount from the credit based on userid
String sql9 = "update credit set amt=? where user_id="+uid+" ";
pstmt = con.prepareStatement(sql9);
pstmt.setDouble(1,dec);
pstmt.executeUpdate();
pnrno=Integer.parseInt(request.getParameter("pnrno"));
date_book=request.getParameter("date_book");
date_dep=request.getParameter("date_dep");
tno=Integer.parseInt(request.getParameter("tno"));
km=Integer.parseInt(request.getParameter("totalkm"));
clas=request.getParameter("clas");
coach=request.getParameter("coach");
src = request.getParameter("src");
des = request.getParameter("des");
//to get the station name based on station_id
String sql5 = "select * from route where station_id=?";
pstmt = con.prepareStatement(sql5);
pstmt.setString(1,src); //To fetch the details of source station
rs = pstmt.executeQuery();
if(rs.next()){
source = rs.getString("station_name");
}
pstmt.setString(1,des); //To fetch the details of destination station
rs = pstmt.executeQuery();
if(rs.next()){
dest = rs.getString("station_name");
}
adult1=Integer.parseInt(request.getParameter("adult1"));
child1=Integer.parseInt(request.getParameter("child1"));
int no = adult1+child1; //Total No Of Seats Per Ticket
Calendar cal1 = Calendar.getInstance();
int h = cal1.get(Calendar.HOUR_OF_DAY);
int m = cal1.get(Calendar.MINUTE);
int s = cal1.get(Calendar.SECOND);
String time1 = h+":"+m+":"+s; //To fetch current time in 24 hrs format
String sql1="insert into ticket_book (PNR, train_no, user_id, class, dep_date, adult, child, no_seats, board_station, dest_station, total_km, book_date, book_time) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = con.prepareStatement(sql1);
pstmt.setInt(1,pnrno);
pstmt.setInt(2,tno);
pstmt.setInt(3,Integer.parseInt(uid));
pstmt.setString(4,clas);
pstmt.setString(5,date_dep);
pstmt.setInt(6,adult1);
pstmt.setInt(7,child1);
pstmt.setInt(8,no);
pstmt.setString(9,source);
pstmt.setString(10,dest);
pstmt.setInt(11,km);
pstmt.setString(12,date_book);
pstmt.setString(13,time1);
pstmt.executeUpdate();
%>
<br/>
<br/>
<br/>
<br/>
<h3> BOOKING SUCCESSFULL WITH PNRNO: <span style="color: red;"> <%= pnrno %></span> <br/><br/>
<br/></h3>
<span style="color: red; font-size: 16px; font-weight: bold; font-style: italic;"> Right Click on the below link and select <span style="color: black;"> Save Target as.. or Save Link as.. </span>
<br/> To Download the Ticket in pdf format <br/><br/>
</span>
<%
}
catch(Exception e){
e.printStackTrace();
out.println("<h1> INPUT ERROR</h1>");
}
%>
<%
//Session Validation
}
else{
out.println("<h3><span style='color: red;'>Access Denied please login to access </span></h3>");
}
}
}
catch(Exception e){
out.println("<h3><span style='color: red;'>Access Denied please login to access </span></h3>");
}
%>
</div>
<!-- Form Body -->
</div> <!-- end of templatemo_content -->
<div id="templatemo_sidebar">
<div id="request_a_quote">
<%
try{
if(session.isNew()){ //session.isNew is true for the first time when the page is loaded
}
else{
String uname = (String)session.getAttribute("uname");
String ssid = (String)session.getAttribute("sid");
String author = (String)session.getAttribute("author");
String error = (String)session.getAttribute("error");
String sessionid = (String)session.getId();
if(error=="Y"){ //error=Y is set when the email and password are mismatched
}
else if(ssid == sessionid) { //To verify the session id of page and sid i.e session id set during session creation match
%>
<h2> Login Details</h2><br/>
<p style="font-size: 12pt">
<label style="color:#DD0000;"> UserName</label> <%= uname %> <br/>
<label style="color:#DD0000;"> Authority </label> <%= author.toUpperCase() %> <br/>
<br/>
<a href="<%= author%>home.jsp"> <%= author.toUpperCase() %> Home</a>
<a href='Logout.jsp'> Logout</a>
</p>
<%
}
else{ //if all cases fail login is prompted
}
}
}
catch(Exception e){
}
%>
</div>
<div id="sidebar_featured_project">
<div class="cleaner"></div>
<div class="cleaner"></div>
<div class="cleaner"></div>
<div class="cleaner"></div>
<h3>Information</h3>
<div class="right" >
<h6 ><a href="SearchTrain.jsp">Trains Btw Stations</a></h6>
<h6><a href="SearchSchedule.jsp">Train Schedules</a></h6>
<h6><a href="ViewFare.jsp">Fare List</a></h6>
<h6><a href="http://www.indianrail.gov.in" target="_new">Other Railway Websites </a></h6>
</div>
<div class="cleaner"></div>
</div>
<div class="cleaner"></div>
</div>
</div> <!-- end of wrapper -->
<div id="footer"></div>
</body>
</html>