-
Notifications
You must be signed in to change notification settings - Fork 0
/
cancel_booked_tickets_form_handler.php
117 lines (113 loc) · 3.35 KB
/
cancel_booked_tickets_form_handler.php
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
<?php
session_start();
?>
<html>
<head>
<title>
Cancel Booked Tickets
</title>
</head>
<body>
<?php
if(isset($_POST['Cancel_Ticket']))
{
$data_missing=array();
if(empty($_POST['pnr']))
{
$data_missing[]='PNR';
}
else
{
$pnr=trim($_POST['pnr']);
}
if(empty($data_missing))
{
require_once('Database Connection file/mysqli_connect.php');
$todays_date=date('Y-m-d');
$customer_id=$_SESSION['login_user'];
$query="SELECT count(*) from Ticket_Details t WHERE pnr=? and journey_date>=?";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"ss",$pnr,$todays_date);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt,$cnt);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
if($cnt!=1)
{
mysqli_close($dbc);
header("location: cancel_booked_tickets.php?msg=failed");
}
$query="UPDATE Ticket_Details SET booking_status='CANCELED' WHERE pnr=? and customer_id=?";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"ss",$pnr,$customer_id);
mysqli_stmt_execute($stmt);
$affected_rows=mysqli_stmt_affected_rows($stmt);
//echo $affected_rows."<br>";
// mysqli_stmt_bind_result($stmt,$cnt);
// mysqli_stmt_fetch($stmt);
// echo $cnt;
mysqli_stmt_close($stmt);
if($affected_rows==1)
{
$query="SELECT t.flight_no,t.journey_date,t.no_of_passengers,t.class,0.85*p.payment_amount as refund_amount from Ticket_Details t,Payment_Details p WHERE t.pnr=? and t.pnr=p.pnr";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"s",$pnr);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt,$flight_no,$journey_date,$no_of_pass,$class,$refund_amount);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
$_SESSION['refund_amount']=$refund_amount;
if($class=='economy')
{
$query="UPDATE Flight_Details SET seats_economy=seats_economy+? WHERE flight_no=? AND departure_date=?";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"iss",$no_of_pass,$flight_no,$journey_date);
mysqli_stmt_execute($stmt);
$affected_rows_1=mysqli_stmt_affected_rows($stmt);
echo $affected_rows_1.'<br>';
mysqli_stmt_close($stmt);
}
else if($class=='business')
{
$query="UPDATE Flight_Details SET seats_business=seats_business+? WHERE flight_no=? AND departure_date=?";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"iss",$no_of_pass,$flight_no,$journey_date);
mysqli_stmt_execute($stmt);
$affected_rows_1=mysqli_stmt_affected_rows($stmt);
echo $affected_rows_1.'<br>';
mysqli_stmt_close($stmt);
}
if($affected_rows_1==1)
{
header("location: cancel_booked_tickets_success.php");
}
else
{
echo "Submit Error";
echo mysqli_error();
}
}
else
{
echo "Submit Error";
echo mysqli_error();
header("location: cancel_booked_tickets.php?msg=failed");
}
mysqli_close($dbc);
}
else
{
echo "The following data fields were empty! <br>";
foreach($data_missing as $missing)
{
echo $missing ."<br>";
}
}
}
else
{
echo "Cancel request not received";
}
?>
</body>
</html>