forked from SecareLupus/fc_pos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.php
318 lines (282 loc) · 11 KB
/
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<?php
/**
* @file schedule.php
* @brief schedule.php displays the default schedule, as well as the actual
* schedule for a given time period.
*
* This file includes:
* funcs.inc:
* - Used for the config.inc include
* - selectInputDate()
* - checkMemberReg()
*
* schedule.inc:
* - selectSchedVolunteer()
* - showVolunteer()
* - selectVolunteer()
*
* Possible Arguments:
* SESSION:
* - mem - Used to determine whether the active user has membership
* coordinator privs, allowing them to change the schedule.
*
* POST:
* - dis - If this variable is set to 'no', we display 'noheader.inc'
* instead of 'header.inc'.
* - date - This is a submit button, which will populate with a value
* if there is work to be done.
* - startyear - The values included
* - startmonth - in the start and end
* - startday - variables are used for
* - endyear - identifying the desired
* - endmonth - period for editing
* - endday - or viewing the schedule.
* - change[ ] - This array tells us for each day and shift, whether
* we need to do any work on it, or if it doesn't need to be changed.
* - s[ ] - This array of values tells FC which of the upcoming shifts
* need to be amended, and what their new value should be.
* - sched[ ] - This array of values tells FC which of the recurring shifts
* need to be amended, and what their new value should be.
*
* GET:
* - dis - If this variable is set to 'no', we display 'noheader.inc'
* instead of 'header.inc'.
* - start - This string is the start date of the desired period. It
* will be set from POST, if appropriate values have been set.
* - end - This string is the end date of the desired period. It
* will be set from POST, if appropriate values have been set.
*
* @link http://www.worldsapartgames.org/fc/schedule.php @endlink
*
* @author Michael Whitehouse
* @author Creidieki Crouch
* @author Desmond Duval
* @copyright 2009-2014 Pioneer Valley Gaming Collective
* @version 1.8d
* @since Project has existed since time immemorial.
*/
$title = 'Schedule';
$version = '1.8d';
$securePage = true;
require_once 'funcs.inc';
require_once 'schedule.inc';
// Check permissions and set mem to indicate if user can make changes
$mem = $_SESSION['mem'];
if ($_GET['dis'] == 'no' || $_POST['dis'] == 'no') {
$mem = 0;
include 'noheader.php';
} else {
include 'header.php';
}
$cxn = open_stream();
if ($mem == 1) {
echo "<form action='schedule.php' method='post'>\n";
}
if (isset($_POST['date'])) {
extract($_POST);
$_GET['start'] = $startyear . '-' . $startmonth . '-' . $startday;
$_GET['end'] = $endyear . '-' . $endmonth . '-' . $endday;
} else {
$startyear = substr($_GET['start'], 0, 4);
$startmonth = substr($_GET['start'], 5, 2);
$startday = substr($_GET ['start'], 8, 2);
$endyear = substr($_GET['end'], 0, 4);
$endmonth = substr($_GET['end'], 5, 2);
$endday = substr($_GET ['end'], 8, 2);
}
echo "<form action='schedule.php' method='post'>
<b>View Another Set of Dates</b><br>
Start: ";
selectInputDate('startmonth', 'startday', 'startyear', 2008, date('Y', strtotime('+1 year')), $startmonth, $startday, $startyear);
echo "<br>End: ";
selectInputDate('endmonth', 'endday', 'endyear', 2008, date('Y', strtotime('+1 year')), $endmonth, $endday, $endyear);
echo "<br>";
if ($_GET['dis'] == 'no') {
echo "<input type='hidden' name='dis' value='no'>\n";
}
echo "<input type='submit' name='date' value='submit date'><hr>\n";
// Check POST data. If there is any, confirm for each one as we go that it is a valid member with REG permissions
// if not, print error message and do not make change
if (is_array($_POST) && $mem == 1) {
extract($_POST);
if (is_array($s)) {
foreach ($s as $shift => $thiss) {
if (is_array($thiss)) {
foreach ($thiss as $date => $member) {
if (checkMemberReg($member) || ($member == -1)) {
if ($change[$date][$shift] == 1) {
$sql = "UPDATE schedule
SET staffID='$member',
approved='0'
WHERE day='$date'
AND shift='$shift'";
query($cxn, $sql);
} else {
$sql = "INSERT INTO schedule
(day, staffID, shift)
VALUES ('$date', '$member', '$shift')";
query($cxn, $sql);
}
} elseif ($member == 0) {
$sql = "DELETE FROM schedule WHERE day='$date' AND shift='$shift'";
query($cxn, $sql);
} else {
echo "<b>$member is an invalid Member ID<br>Did not assign shift $shift on $date<p>\n";
}
$member = 0; // reset $member
}
}
}
}
// take new recurring schedule changes
if (is_array($sched)) {
foreach ($sched as $shift => $s) {
if (is_array($s)) {
foreach ($s as $day => $member) {
if ($member == 0) {
$sql = "DELETE FROM recurringSchedule WHERE day='$day' AND shift='$shift'";
query($cxn, $sql);
} else {
if (checkMemberReg($member)) {
$sql = "SELECT * FROM recurringSchedule WHERE day='$day' AND shift='$shift'";
query($cxn, $sql);
if ($cxn->affected_rows == 1) {
$sql = "UPDATE recurringSchedule
SET staffID='$member'
WHERE day='$day'
AND shift='$shift'";
query($cxn, $sql);
} else {
$sql = "INSERT INTO recurringSchedule
(staffID, day, shift)
VALUES ('$member', '$day', '$shift')";
query($cxn, $sql);
}
}
}
}
}
}
}
}
$sql = "SELECT * FROM recurringSchedule";
$result = query($cxn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
extract($row);
$recSched[$day][$shift] = $staffID;
}
mysqli_free_result($result);
// link to display schedule
echo "<a href='http://www.worldsapartgames.com/fc/schedule.php?dis=no'>Show Printable Schedule</a><p>";
// Display Recurring Schedule
echo "<h2>Recurring Schedule</h2><br>
<table border><tr><td>Shift</td>
<td>Sunday</td>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
<td>Saturday</td></tr>";
for ($shift = 1; $shift <= 3; $shift++) {
echo "<tr><td>Shift #$shift</td>";
for ($day = 1; $day <= 7; $day++) {
echo "<td>";
if (isset($recSched[$day][$shift])) {
if ($mem == 1) {
selectSchedVolunteer("sched[$shift][$day]", $recSched[$day][$shift]);
} else {
showVolunteer($recSched[$day][$shift], 0);
}
} else {
if ($mem == 1) {
selectSchedVolunteer("sched[$shift][$day]", 0);
} else {
showVolunteer($recSched[$day][$shift], 0);
}
}
echo "</td>\n";
}
echo "</tr>";
}
echo "</table>";
echo "<a name='bookmark'>\n";
// Display selected period. If MEM, display inputs to change assignments
$start = date_create((isset($_GET['start'])) ? $_GET['start'] : date("Y-m-d"));
if (!isset($_GET['end'])) {
$end = date_create();
date_modify($end, "+2 weeks");
} else {
$end = date_create($_GET['end']);
}
// make strings we can send in the query
$startStr = date_format($start, "Y-m-d");
$endStr = date_format($end, "Y-m-d");
$sql = "SELECT * FROM schedule WHERE day BETWEEN '$startStr' AND '$endStr' "
. "ORDER BY day, shift";
// initialize counters
$curShift = 1; // current shift to display
if ($result = query($cxn, $sql)) {
// if there is an error, we don't display nothin'
$row = mysqli_fetch_assoc($result);
$rowDate = date_create($row['day']);
$rowDay = $row['day'];
$rowShift = $row['shift'];
// this tells it that this spot already exists so it doesn't create a new one
if ($mem == 1) {
echo "<input type='hidden' name='change[$rowDay][$rowShift]' value='1'>\n";
}
echo "<h2>Non-Recurring Daily Schedule</h2>
From $startStr to $endStr<br>
<table border><tr><td width=150>Day</td>
<td width=200>Shift #1<br>10 AM to 2 PM</td>
<td width=200>Shift #2<br>2 PM to 6 PM</td>
<td width=200>Shift #3<br>6 PM to 10 PM</td></tr>\n";
// cycle through days
for ($date = $start; $date <= $end; date_modify($date, "+1 day")) {
// cycle through shifts
echo "<tr>"; // start the row
for ($curShift = 1; $curShift <= 3; $curShift++) {
if ($curShift == 1) {
echo "<tr><td>" . date_format($date, "l") . "<br>"
. date_format($date, "M jS") . "</td>";
}
echo "<td>";
// display shift info
// if we have one of these, it should be displayed
// staffer is sent as default. If it's 0, selectVolunteer knows it's undefinied, otherwise it
// notes that it is assigned. If we use this one then we need to fetch a new one
// if the new on is empty, it will never trip this if and the program will continue printing blank boxes for filling
$dayNum = date_format($date, "w") + 1;
$rsn = $recSched[$dayNum][$curShift]; // this is so we can display if the staffer is the regular one
if (($date == $rowDate) && ($curShift == $row['shift'])) {
$staffer = $row['staffID'];
// get the next one
$row = mysqli_fetch_assoc($result);
$rowDate = date_create($row['day']);
$rowDay = $row['day'];
$rowShift = $row['shift'];
// this tells it that this spot already exists so it doesn't create a new one
if ($mem == 1) {
echo "<input type='hidden' name='change[$rowDay][$rowShift]' value='1'>\n";
}
}
if ($mem == 1) {
$dateStr = date_format($date, "Y-m-d");
selectVolunteer("s[$curShift][$dateStr]", $staffer, $rsn);
} else {
showVolunteer($staffer, $rsn);
}
$staffer = 0; // reset var
echo "</td>";
}
echo "</tr>"; // end the row
}
echo "</table><p>";
}
if ($mem == 1) {
echo "<input type='submit' name='submit changes' value='submit changes'>
</form>";
}
require 'footer.php';
?>