This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
grablist.php
148 lines (131 loc) · 5.82 KB
/
grablist.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
<?php
session_start();
if(!isset($_SESSION['user_id']) || !isset($_SESSION['user_name'])){
header("Location: login");
exit;
}
?>
<?php include_once(dirname(__FILE__).'/Model/Date.php');?>
<?php include_once(dirname(__FILE__).'/Controller/DutyController.php');?>
<?php include_once(dirname(__FILE__).'/Controller/UserController.php');?>
<?php
$dutyController = DutyController::getInstance();
$userController = UserController::getInstance();
if ($userController->getDutyStatus($_SESSION['user_id']) == 0) {
header("Location: tracking");
exit;
}
if (isset($_POST['grab']) && $_POST['grab'] == 'yes') {
$startID = $_POST['start_id'];
$endID = $_POST['end_id'];
$date = $_POST['date'];
$month = $_POST['month'];
$year = $_POST['year'];
$day = (new Date($date,$month,$year))->getDay();
$venue = $_POST['venue'];
$user_id = $_SESSION['user_id'];
$user_name= $_SESSION['user_name'];
$user = new User($user_id, null, null, null, null, null, null, null);
for ($i = $startID; $i <= $endID; ++$i) {
if (isset($_POST[$i]) && $_POST[$i] == 'on') {
$dailyDuty = new DailyDuty($i, $day, null, null, $venue, $date, $month, $year);
if ($dutyController->getSupervisorID($dailyDuty) >= 0) {
header("Location: index");
exit;
}
$dutyController->grabDuty($user,$dailyDuty);
}
}
header("Location: index");
exit;
}
$availableDuties = $dutyController->getAvailableDuties(null,null,null,null);
?>
<html>
<head>
<title>NUSSU commIT</title>
<link href="includes/css/bootstrap.min.css" rel="stylesheet">
<link href="includes/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="includes/css/style.css" rel="stylesheet">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="includes/js/bootstrap.min.js"></script>
</head>
<body>
<?php $page = "grab"; ?>
<?php include(dirname(__FILE__).'/includes/header.php');?>
<div class="container">
<h1>Grab A Duty</h1>
<?php
if (count($availableDuties) > 0) {
?>
<h3>Available for grab :</h3>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Venue</th>
<th>Timeslots</th>
</tr>
</thead>
<?php
for ($i = 0; $i < count($availableDuties); ++$i) {
$date = $availableDuties[$i]["date"];
$month = $availableDuties[$i]["month"];
$year = $availableDuties[$i]["year"];
$venue = $availableDuties[$i]["venue"];
echo "<tr>";
echo "<td>".(new Date($date,$month,$year))->printToString()."</td>";
echo "<td>".$venue."</td>";
echo "<td>"; ?>
<script language="JavaScript">
function Click(i, k) {
for (var j = 0; j < k; ++j) {
if ($("#button" + i + "-" + j)[0].checked) {
$("#button" + i + "-" + j)[0].checked = false;
} else {
$("#button" + i + "-" + j)[0].checked = true;
}
}
}
</script>
<?php
$scheduleID = $dutyController->getAvailableDuties($date,$month,$year,$venue);
echo "<button onclick=Click(".$i.",".count($scheduleID).") class='btn btn-default'> Toggle All</button><br />";
?>
<form action='grablist.php' method='post'>
<input type="hidden" name="grab" value="yes">
<input type="hidden" name="date" value="<?php echo $date; ?>">
<input type="hidden" name="month" value="<?php echo $month; ?>">
<input type="hidden" name="year" value="<?php echo $year; ?>">
<input type="hidden" name="venue" value="<?php echo $venue; ?>">
<input type="hidden" name="start_id" value="1">
<input type="hidden" name="end_id" value="1000">
<?php
$indexID = 0;
for ($j = 0; $j < count($scheduleID); ++$j) {
echo "<div class='checkbox-inline'>"; ?>
<input id='<?php echo "button$i-$j";?>' type="checkbox" name="<?php echo $scheduleID[$j]["schedule_id"];?>"> <?php
echo $dutyController->getTimeDuty($scheduleID[$j]["schedule_id"]);
echo "</div>";
if (++$indexID % 3 == 0 || $j == count($scheduleID) - 1) {
echo "<br />";
}
}
echo "<button type='submit' name='submit' class='btn btn-primary'>Grab</button>";
echo "</form>";
echo "</td>";
echo "</tr>";
}
?>
</table>
<?php
} else { ?>
<div class="col-md-10">
No timeslot to grab
</div> <?php
}
?>
</div>
<?php include(dirname(__FILE__).'/includes/footer.php');?>
</body>
</html>