-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendarhouse.inc
234 lines (220 loc) · 9.99 KB
/
calendarhouse.inc
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
<?php
/*
* Copyright 2013 by Jerrick Hoang, Ivy Xing, Sam Roberts, James Cook,
* Johnny Coster, Judy Yang, Jackson Moniaga, Oliver Radwan,
* Maxwell Palmer, Nolan McNair, Taylor Talmage, and Allen Tucker.
* This program is part of RMH Homebase, which is free software. It comes with
* absolutely no warranty. You can redistribute and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation
* (see <http://www.gnu.org/licenses/ for more information).
*
*/
session_start();
session_cache_expire(30);
?>
<!--
calendar.inc
@author Max Palmer, Allen Tucker, Sam Roberts, James Cook
@version 3/26/08, revised 10/3/2013
-->
<?php
/**
* shows the "previous week"/"next week" menu, if the weeks exist
*/
function do_week_nav($week, $edit, $venue) {
$cur_id = $week->get_id();
// echo ("We are doing a nav for week ".$cur_id."<br>");
$prev_id = date("m-d-y", mktime(0, 0, 0, substr($cur_id, 0, 2), substr($cur_id, 3, 2) - 7, substr($cur_id, 6, 2)));
$next_id = date("m-d-y", mktime(0, 0, 0, substr($cur_id, 0, 2), substr($cur_id, 3, 2) + 7, substr($cur_id, 6, 2)));
$s = "<p><table id=\"weeknav\" align=\"left\"><tr><td align=\"left\" >";
// determines if there is a previous week
$prev_week = get_dbWeeks($prev_id);
if ($prev_week instanceof Week) {
$s = $s . '<a href="calendar.php?id=' . $prev_id . '&venue=' . $venue;
if ($edit)
$s = $s . "&edit=true";
$s = $s . "\" id=\"weeknavlink\"><< Previous Week</a>";
}
else $s = $s . " ";
if ($_SESSION['access_level'] >= 1)
if ($edit != true)
$s = $s . '<td align="left"> <a href="calendar.php?id=' . $cur_id . '&venue=' . $venue . '&edit=true"> (edit this week)</a></td>';
else
$s = $s . '<td align="left"> <a href="calendar.php?id=' . $cur_id . '&venue=' . $venue . '&edit=false"> (view this week)</a></td>';
if ($_SESSION['access_level'] >= 2)
$s = $s . '<td align="right"> <a href="addWeek.php?archive=false"> (manage weeks)</a></td>';
$s = $s . "</td><td align=\"right\">";
// determines if there is a next week
$next_week = get_dbWeeks($next_id);
if ($next_week instanceof Week) {
$s = $s . ' <a href="calendar.php?id=' . $next_id . '&venue=' . $venue;
if ($edit)
$s = $s . "&edit=true";
$s = $s . "\" id=\"weeknavlink\">Next Week >></a>";
}
else $s = $s . " ";
$s = $s . "</td></tr></table></p><br><br>";
return $s;
}
/**
* gets a week object, and displays it as a calendar
*/
function show_week($days, $week, $edit, $year, $doy, $venue) {
// gets all of the dates for this week
// sets up the table, with title, and then day of month
$free_hour = array();
for ($i = 0; $i < 91; $i++)
$free_hour[] = true;
// echo ("Showing week ". $week->get_id(). " for venue " . $venue . " and first day " . $days[0]->get_id() . "<br>");
$daynames = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
echo ('<table id="calendar" align="center" ><tr class="weekname"><td colspan="16" ' .
'align="center" >' . 'House calendar: ' . $week->get_name() . '</td></tr>
<tr><td bgcolor=lightblue></td>');
for ($i = 0; $i < 7; $i++)
echo ('<td class="dom">' . get_dom($days[$i]) . '</td><td class="dow"> ' . $daynames[$i] . '</td>');
echo('<td bgcolor=lightblue></td></tr>');
$limit = 22;
for ($hour = 9; $hour < $limit; $hour++) {
echo ("<tr><td class=\"hour\">" . show_hours($venue, $hour) . "</td>");
for ($i = 0; $i < 7; $i++) {
$shiftid = $days[$i]->get_shift_id($hour, $venue);
if ($shiftid) {
$shift_length = get_shift_end($shiftid) - get_shift_start($shiftid);
echo do_shift($days[$i], substr($shiftid, 9), $shift_length, $edit, $venue);
for ($j = $hour; $j < $hour + $shift_length; $j++)
$free_hour[7 * ($j - 9) + $i] = false;
}
else
if ($free_hour[7 * ($hour - 9) + $i])
echo "<td colspan='2' bgcolor=\"lightgray\"></td>";
}
echo ("<td class=\"hour\">" . show_hours($venue, $hour) . "</td></tr>");
}
// notes
echo do_day_notes($days, $edit, $year, $doy);
echo "<input type=\"hidden\" name=\"_submit_check_edit_notes\" value=\"1\">";
echo "<input type=\"hidden\" name=\"weekid\" value=\"" . $days[0]->get_id() . "\">";
echo "</table>";
}
function show_hours($venue, $hour) {
$d = 1;
$last_shift = 8;
if ($hour==21) {
return "overnight";
}
else {
$clock = $hour < 12 ? $hour . "am" : $hour - 12 . "pm";
$clockend = $hour + $d < 12 ? ($hour + $d) . "am" : ($hour - 12 + $d) . "pm";
if ($clock == "0pm")
$clock = "12pm";
if ($clockend == "0pm")
$clockend = "12pm";
if (($clock) % $d == 0){
if ($clock % $last_shift == 0)
return $clock . " - " . $clockend;
else
return $clock;
}
else
return "";
}
}
// return a string of html that contains a table cell for a shift
function do_shift($day, $shift, $length, $edit, $venue) {
// chooses size annd style of cell based on length
$s = "<td colspan=\"2\" ";
$s = $s . "rowspan='" . $length . "' class = 'shift'";
// checks that the shift is not in the past
$year = date("Y", time());
$doy = date("z", time()) + 1;
if ($edit) // && ($year < $day->get_year() || $year == $day->get_year() && $doy <= $day->get_day_of_year() ))
$s = $s . "e";
$s = $s . "\"><table id=\"shiftbox\"><tr><td class=\"persons\">";
if ($edit) // && ($year < $day->get_year() || $year == $day->get_year() && $doy <= $day->get_day_of_year() ))
$s = $s . "<a id=\"shiftlink\" href=\"editShift.php?shift=" . $day->get_id() . "-" . $shift . "&venue=" . $venue . "\">";
$s = $s . get_people_for_shift($day, $shift);
if ($edit) { //&& ($year < $day->get_year() || $year == $day->get_year() && $doy <= $day->get_day_of_year() )) {
$s = $s . "</a>";
// if manager, adds shift notes
if ($_SESSION['access_level'] >= 2 || $_SESSION['access_level'] >= 1.5) {
$s = $s . "</td></tr><tr><td class=\"notes\" align=\"center\">" .
"<textarea id=\"shift_notes\" rows=\"1\" name=\"shift_notes_" . $day->get_shift($shift)->get_id() . "\">"
. $day->get_shift($shift)->get_notes() . "</textarea>";
} else {
$shiftnote = $day->get_shift($shift)->get_notes();
$s = $s . "</td></tr><tr><td class=\"notes\"><p id=\"shift\">" . $shiftnote . "</p>";
}
}
else {
$shiftnote = $day->get_shift($shift)->get_notes();
$s = $s . "</td></tr><tr><td class=\"notes\"><p id=\"shift\">" . $shiftnote . "</p>";
}
$s = $s . "</td></tr></table></td>";
return $s;
}
function get_dom($day) {
$dom = $day->get_dom();
if (substr($dom, 0, 1) == "0")
return " " . substr($dom, 1);
return $dom;
}
function get_people_for_shift($day, $key) {
//echo "we are getting people for shift ".$day->get_shift($key);
$shift = $day->get_shift($key);
$people = $shift->get_persons();
if (!$people[0])
array_shift($people);
$p = "<br>";
$vac = $shift->num_vacancies();
// echo $shift->get_id()." slots = ".$shift->num_slots()." vac = ".$shift->num_vacancies()."<br>";
for ($i = 0; $i < sizeof($people); ++$i) {
if (!$people[$i] == "") {
$name_components = explode("+", $people[$i]);
$p = $p . " " . $name_components[1] . " " . $name_components[2] . "<br>";
}
}
if ($vac > 0)
$p = $p . " <b>Vacancies (" . $vac . ")</b>";
return substr($p, 0, strlen($p) - 4);
}
function do_day_notes($days, $edit, $year, $doy) {
if ($edit == false || $_SESSION['access_level'] < 1.5) {
$s = "<tr><td class=\"hour\">manager notes </td>";
for ($i = 0; $i < 7; ++$i) {
$s = $s . "<td class=\"note\" colspan=\"2\">" . $days[$i]->get_mgr_notes() . "</td>";
}
return $s . "<td class=\"hour\">manager notes </td></tr>";
} else {
$s = "<tr><td class=\"hour\">manager notes </td>";
for ($i = 0; $i < 7; ++$i) {
if ($year < $days[$i]->get_year() || $year == $days[$i]->get_year() && $doy <= $days[$i]->get_day_of_year()) {
$s = $s . "<td class=\"note_e\" colspan=\"2\"><textarea id=\"mgr_notes\"
rows=\"1\" name=\"mgr_notes" . $i . "\">"
. $days[$i]->get_mgr_notes() . "</textarea></td>";
}
else
$s = $s . "<td class=\"note\" colspan=\"2\">" . $days[$i]->get_mgr_notes() . "</td>";
}
return $s . "<td class=\"hour\">manager notes </td></tr>";
}
}
function process_edit_notes($week, $venue, $post) {
$days = $week->get_dates();
for ($i = 0; $i < 7; ++$i) {
$shifts = $days[$i]->get_shifts();
foreach ($shifts as $key => $shift) {
// if ($shift->get_venue()==$venue) {
$note = trim(str_replace('\"', '\\\"', str_replace('\'', '\\\'', htmlentities($post['shift_notes_' . $shift->get_id()]))));
$shift->set_notes($note);
update_dbShifts($shift);
// }
}
// if ($year < $days[$i]->get_year() || $year == $days[$i]->get_year() && $doy <= $days[$i]->get_day_of_year()) {
$mgr_note = trim(str_replace('\"', '\\\"', str_replace('\'', '\\\'', htmlentities($post['mgr_notes' . $i]))));
$days[$i] = select_dbDates($days[$i]->get_id());
$days[$i]->set_mgr_notes($mgr_note);
update_dbDates($days[$i]);
// }
}
}
?>