forked from CS2102Project/PetCare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewAvai.php
70 lines (63 loc) · 2.67 KB
/
viewAvai.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
<?php
date_default_timezone_set('Asia/Singapore');
require_once("dbh.inc.php");
include 'header.php';
?>
<?php
$result=pg_query($conn, "SELECT * FROM availability ORDER BY aid ASC");
while ($row = pg_fetch_assoc($result)) {
echo "<div class='panel panel-warning'><div class='panel panel-heading'><h3>";
echo "Availability ID: ".$row['aid'];
echo "<form class='delete-form' action='viewAvai.php' method='POST'>
<input type='hidden' name='aId' value='".$row['aid']."' required >
<label>Update starting time</label>
<input type='date' name = 'newStart' placeholder='update start time'
value = '".$row['afrom']."' required >
<label> Update ending time</label>
<input type='date' name = 'newEnd' placeholder='update end time'
value = '".$row['ato']."' required >
<button class='btn btn-warning btn-xs' type='submit' name='update_avai'>
Update availability</button>
<button class='btn btn-warning btn-xs' type='submit' name='delete_avai'>
Delete availability</button>
</form>";
echo "</div><div class='panel panel-body'>";
echo "Carer ID : ".$row['cid']." ";
echo "<br>Prefered Pet Type: ".$row['ptype']. " ";
echo "<br>From: ".$row['afrom']. " ";
echo "<br>To: ".$row['ato']. " ";
echo "</div></div>";
}
if(isset($_POST['update_avai'])){
$start = $_POST['newStart'];
$end = $_POST['newEnd'];
$aid = $_POST['aId'];
$result=pg_query($conn, "UPDATE availability SET afrom ='$start', ato='$end'
WHERE aid='$aid'");
if(!$result) {
echo "<div class='alert alert-danger alert-dismissible' role='alert'>
Update availability time failed.
</div>";
} else {
echo "<div class='alert alert-success alert-dismissible' role='alert'>
Update availability time successfully!
</div>";
echo "<meta http-equiv='refresh' content = '3'>";
}
}
if(isset($_POST['delete_avai'])){
$aid = $_POST['aId'];
$result1=pg_query($conn, "DELETE FROM bid WHERE aid='$aid'");
$result2=pg_query($conn, "DELETE FROM availability WHERE aid='$aid'");
if(!$result2){
echo "<div class='alert alert-danger alert-dismissible' role='alert'>
Delete availability failed.
</div>";
} else {
echo "<div class='alert alert-success alert-dismissible' role='alert'>
Delete availability successfully!
</div>";
echo "<meta http-equiv='refresh' content = '3'>";
}
}
?>