-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-schedule.php
executable file
·158 lines (131 loc) · 6.05 KB
/
my-schedule.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Schedule</title>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<?php
$active_menu="schedule";
include "includes/customer-menu.php";
?>
<div class="content">
<h1>My Schedule</h1>
<table class="order-list">
<thead>
<tr>
<th style="width:10%">Day</th>
<th style="width:10%">Time</th>
<th>Stylist</th>
<th>Services</th>
<!-- <th style="width:8%">Status</th> -->
<th>Reschedule</th>
<th style="width:10%">Cancel</th>
<th style="width:10%">Payment Ref</th>
</tr>
</thead>
<tbody>
<?php
require_once("includes/database.php");
//$_SESSION["userid"]=1;
$sqlStatement=
'SELECT appointment.transactionid,appointmentdate,start_time,concat(barber.first_name," ",barber.last_name) AS stylist,transactions.paymentid
FROM appointment,payment,transactions,barber
WHERE transactions.transactionid=appointment.transactionid
AND transactions.paymentid=payment.paymentid
AND barber.barberid=appointment.barberid
AND cast(concat(appointmentdate," ",start_time) as datetime)>=NOW()
AND transactions.is_cancelled = 0
AND appointment.no_show=1
AND transactions.customerid='.$conn->quote($_SESSION["customer_userid"]).'
ORDER BY appointmentdate DESC, start_time
;';
// GROUP BY appointment.transactionid;';
$Results=$conn->query($sqlStatement);
$numRows=$Results->rowCount();
if ($numRows==0) echo "<td colspan=\"100%\" style=\"text-align: center;background-color:#F2F2F2\"> No upcoming appointment </td>";
else{
$i=0;
while($row=$Results->fetch()){
if($i==0){
echo "<tr class=\"even\">";
$i=1;
}
else{
echo "<tr>";
$i=0;
}
echo "<td>".date("D",strtotime($row["appointmentdate"]))." ".$row["appointmentdate"]."</td>";
echo "<td>".date("H:i",strtotime($row["start_time"]))." GMT+4</td>";
echo "<td>".$row["stylist"]."</td>";
$serviceSQL=
"SELECT service.name
FROM appointmentdetails,service
WHERE service.serviceid=appointmentdetails.serviceid
AND transactionid=".$row["transactionid"].";";
$serviceResults=$conn->query($serviceSQL);//USE PREPARED STATEMENTS AFTERWARDS
$services=$serviceResults->fetchall();
$string="";
for($j=0;$j<sizeof($services)-1;$j++){
$string.=$services[$j]["name"].", ";
}
$string.=$services[sizeof($services)-1]["name"];
// echo $string;
echo "<td>".$string."</td>";
echo "<td><span style=\"cursor:pointer; color:#003f87;font-weight: 500;\">Reschedule</span></td>";
echo "<td><span style=\"cursor:pointer; color:#003f87;font-weight: 500;\" class=\"cancel\" id='".$row["transactionid"]."'>Cancel</span></td>";
echo "<td>#".$row["paymentid"]."</td>";
}
}
?>
</tbody>
</table>
</div>
</body>
<script>
$(document).ready(function(){
$(".cancel").click(function(event){
const transactionid = $(this).attr("id")
const row = $(this).parents("tr");
const adjacent_TR_Length = $(this).parents("tr").siblings().length;
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, go ahead!'
}).then((result) => {
if (result.isConfirmed) {
$.post(
"cancelTransaction.php",
{transactionid: transactionid, option: "appointment"},
function(data){
if (data=="success"){
if (adjacent_TR_Length==0){
$(row).parent().html(`<td colspan=\"100%\" style=\"text-align: center;background-color:#F2F2F2\"> No upcoming appointment </td>`)
}else{
row.remove()
}
Swal.fire(
'Cancellation successful!',
'Your appointment has been cancelled',
'success'
)
}else{
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Something went wrong!',
})
}
}
);
}
})
})
})
</script>
</html>