-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateAvailability.php
130 lines (95 loc) · 2.92 KB
/
updateAvailability.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
<?php
// Initialize the session
include "config.php";
session_start();
$days = [
0=> 'Monday',
1=> 'Tuesday',
2=> 'Wednesday',
3=> 'Thursday',
4 => 'Friday',
5=> 'Saturday',
6=>'Sunday'
];
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Update Availability</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body{ font: 14px sans-serif; text-align: center; }
</style>
</head>
<body>
<h1> Update Availability</h1>
<p>
<p>Go Back to <a href="patientView.php">Profile</a>.</p>
<?php
$patientId = $_SESSION["patientId"];
$query= "SELECT timeSlotId FROM PatientAvailability WHERE patientId = $patientId ";
$result= mysqli_query($link, $query);
while($row = mysqli_fetch_assoc($result)){
$new_array[]=$row['timeSlotId'];
}
//echo $new_array;
$query2= "SELECT timeSlotId,timeSlot, day FROM Calendar";
$result2= mysqli_query($link, $query2);
//$query2->execute();
?>
<form method= "post" action ="#">
<?php
while ( $row2= mysqli_fetch_assoc($result2)) {
if(in_array($row2['timeSlotId'], $new_array)){
?>
<div>
<input type="checkbox" id="slot" name="slot[]" value="<?php echo $row2['timeSlotId']?>" checked>
<label for="slot"><?php echo $row2['timeSlot'].$days[$row2['day']]?></label>
</div>
<?php
}
else{
?>
<div>
<input type="checkbox" id="slot" name="slot[]" value="<?php echo $row2['timeSlotId']?>">
<label for="slot"><?php echo $row2['timeSlot'].$days[$row2['day']]?></label>
</div>
<?php
}
}
?>
<input type="submit" name = 'update' class="btn btn-primary" value="Update">
</form>
</p>
<?php
if(isset($_POST['update'])){
if(!empty($_POST['slot'])){
//$values= $_POST['slot'];
$sql = "DELETE FROM PatientAvailability WHERE patientId= $patientId";
if(mysqli_query($link, $sql)){
foreach($_POST['slot'] as $value){
//echo "hi";
$sql2="INSERT INTO PatientAvailability (patientId, timeSlotId) VALUES (?,?)";
//echo "test1";
if($stmt= mysqli_prepare($link, $sql2)){
//echo "test 3";
mysqli_stmt_bind_param($stmt, "ii", $param_patientId, $param_timeSlotId);
$param_patientId=$patientId;
$param_timeSlotId=$value;
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
}
header("location: patientView.php");
}
}
else {echo "check at least one time Slot";}
}
?>
</body>
</html>