forked from Jmurrietasmith/EqManage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturn.php
109 lines (93 loc) · 4.03 KB
/
return.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
<?php
session_start();
if(!isset($_SESSION['loggedin'])){
header('Location: index.php');
exit();
}
?>
<!DOCTYPE html>
<html>
<?php
include('header.php')
?>
<body class="form-v8 loggedin" id="fade">
<div id="loader">
<div class="loader"><div></div><div></div><div></div><div></div></div>
</div>
<?php include('navbar.php'); ?>
<div class="content">
<div>
<h2>Return</h2>
<p>
<?php
include('serverconnect.php');
$name = $_SESSION['name'];
$user_id = $_SESSION['id'];
$resultset = mysqli_query($db, "
SELECT l.expectedReturnDate, l.users_id,E.id, E.equipment, E.leftQuantity, E.availability, l.returnDate, R.checkoutQty, l.checkoutRequests_id, l.checkoutDate
FROM EqManage.log l
LEFT JOIN EqManage.equipment E ON l.equipment_id=E.id
LEFT JOIN EqManage.requests R on l.checkoutRequests_id = R.id
where l.returnDate IS NULL and l.checkoutDate IS NOT NULL
GROUP BY l.id,E.id
"); //Fetch all checkedout equipments
echo $user_id;
// wh
//ile ($row = mysqli_fetch_array($resultset)){
// if($row['users_id'] = $user_id){
// echo $row['equipment_id'];
// $equipmentName = $row['equipment'];
// $equipmentID = $row['equipment_id'];
// echo "<option value='$equipmentID' >$equipment</option>";
// }
//
//
//
// }
?>
<div class="select-style" style="width:500px; margin: auto">
<form action="confirmation.php" style="width: 100%;" method="POST">
<select name="equipment" class="select-picker" onchange="getID(this)">
<option value="" disabled selected>Select the Equipment</option> <!-- TODO Add support for multiple checkout&return, fix the return system, might have to record the borrwed quantity in log-->
<?php
while ($row = mysqli_fetch_array($resultset)){
if($row['users_id'] = $user_id){
echo $row['equipment_id'];
$equipmentName = $row['equipment'];
$equipmentID = $row['equipment_id'];
$checkoutRequestsID = $row['checkoutRequests_id'];
$checkoutQty = $row['checkoutQty'];
$checkoutDate = $row['checkoutDate'];
$checkoutDateExplode = explode(" ", $checkoutDate);
$expectedReturnDate = $row['expectedReturnDate'];
$expectedReturnDateEx = explode(" ", $expectedReturnDate);
$today = date("Y-m-d H:i:s");
$todayExplode = explode(" ", $today);
echo $checkoutRequestsID;
echo "<option value='$equipmentID' data-checkoutRequestsID='$checkoutRequestsID'>";
if (strtotime($expectedReturnDateEx[0]) < strtotime($todayExplode[0])){
echo "[Overdue] ";
}
echo "$equipmentName | $checkoutQty Borrowing";
if (strtotime($expectedReturnDateEx[0]) >= strtotime($todayExplode[0])){
echo " | Due: ", $expectedReturnDateEx[0];
}
echo "</option>";
}
}
?>
</select>
<input type="hidden" id="checkoutRequestsID" name="checkoutRequestsID" value="">
<input name="request" type="submit" value="Return" style="width: 100%; margin-top: 20px">
</form>
</div>
</p>
</div>
</div>
<script>
function getID(id) {
id = id.options[id.selectedIndex].getAttribute('data-checkoutRequestsID');
console.log(id);
document.getElementById("checkoutRequestsID").setAttribute("value",id);
}
</script>