forked from megandalster/rmhc-homebase
/
subCallList.php
executable file
·305 lines (287 loc) · 11.2 KB
/
subCallList.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
<?php
/*
* Copyright 2015 by Adrienne Beebe, Connor Hargus, Phuong Le,
* Xun Wang, and Allen Tucker. This program is part of RMHP-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).new SCL
*
* Modifications February 2015, Adrienne Beebe
*/
session_start();
session_cache_expire(30);
?>
<!-- page generated by the BowdoinRMH software package -->
<html>
<head>
<title>
Sub Call Lists
</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
<link rel="stylesheet" href="calendar.css" type="text/css" />
</head>
<body>
<div id="container">
<?PHP include('header.php');?>
<div id="content">
<?php
include_once('database/dbSCL.php');
include_once('database/dbShifts.php');
include_once('database/dbLog.php');
include_once('database/dbPersons.php');
$id=$_GET['shift'];
$venue=$_GET['venue'];
generate_scl($id); //creates a sub call list based on the id of the shift
if(array_key_exists('_submit_generate_scl',$_POST)) {
$id=$_POST['_shiftid'];
}
else if (array_key_exists('_submit_view_scl',$_POST)) {
$id=$_POST['_shiftid'];
}
else if(array_key_exists('_submit_save_scl_changes',$_POST)) {
$id=process_edit_scl($_POST);
}
if($id) {
$id=view_scl($id,$venue);
}
else {
// The first 8 characters of the shift id shows the dates for the week.
$yy_mm_dd = substr($_GET['shift'], 0, 8);
// Displays the option of going back to the Calendar.
back_to_calendar($yy_mm_dd, 700, $venue);
do_scl_index($id,$venue);
}
?>
</div>
<?PHP include('footer.inc');?>
</div>
</body>
</html>
<?php
/*
* Generate a new SCL for a shift. If one is already there, remove it and regenerate it.
*/
function generate_scl($id) {
// echo "<br>we are here";
$shift=select_dbShifts($id);
$vacancies=$shift->num_vacancies();
$day=$shift->get_day();
$time=$shift->get_time_of_day();
$venue = $shift->get_venue();
$shift_persons=$shift->get_persons();
if(!$shift_persons[0])
array_shift($shift_persons);
connect();
$query="SELECT * FROM dbPersons WHERE (status = 'active' AND type LIKE '%sub%' AND availability LIKE '%".$day.":".$time.":".$venue."%') ORDER BY last_name,first_name";
$persons_result=mysql_query($query);
mysql_close();
for($i=0;$i<mysql_num_rows($persons_result);++$i) {
$row=mysql_fetch_row($persons_result);
$id_and_name=$row[0]."+".$row[3]."+".$row[4];
if (!in_array($id_and_name, $shift_persons) && !in_array($id_and_name, $shift->get_removed_persons())) {
$persons[]=array($row[0], $row[3], $row[4], $row[9]." ".$row[10], $row[11]." ".$row[12], "", "", "?");
}
}
$new_scl=new SCL($id, $persons, "open", $vacancies, get_sub_call_list_timestamp($id));
if (!select_dbSCL($id)){
insert_dbSCL($new_scl);
$shift->open_sub_call_list();
update_dbShifts($shift);
}
else $new_scl = select_dbSCL($id);
add_log_entry('<a href=\"personEdit.php?id='.$_SESSION['_id'].'\">'.$_SESSION['f_name'].' '.
$_SESSION['l_name'].'</a> generated a <a href=\"subCallList.php?shift='.$shift->get_id().'\">sub call list</a> for the shift: <a href=\"editShift.php?shift='.
$shift->get_id().'&venue='.$venue.'\">'.get_shift_name_from_id($shift->get_id()).'</a>.');
}
function do_scl_index($id,$venue) {
//$venue = substr(strrchr($id,":"),1);
connect();
$query="SELECT * FROM dbSCL ORDER BY time";
$result=mysql_query($query);
mysql_close();
$cur_date=date("Ymd",time());
if(array_key_exists('_shiftid',$_POST))
show_back_navigation($_POST['_shiftid'],494,$venue);
echo "<p><table width=\"600\" align=\"center\" border=\"1px\"><tr><td align=\"center\" colspan=\"2\"><b>Index of Sub Call Lists with Vacancies</b></td></tr>
<tr><td> Shift<br> </td><td> Vacancies<br> </td></tr>";
for($i=0;$i<mysql_num_rows($result);++$i) {
$row=mysql_fetch_row($result);
$scl_date_formatted=substr($row[4], 0, strlen(date("Ymd",time())));
if($row[2]=="open" && $scl_date_formatted<=$cur_date) {
$scl=select_dbSCL($row[0]);
$scl->set_status("closed");
echo "<br><br><br>";
update_dbSCL($scl);
$row[2]="closed";
}
echo "<tr><td> <a href=\"subCallList.php?shift=".$row[0]."\">"
.get_shift_name_from_id($row[0]).
"</a></td>
<td> ".$row[3]."</td></tr>";
}
echo "<tr><td colspan=\"2\" align=\"center\">";
echo "</td></tr></table></p>";
}
function view_scl($id,$venue) {
$scl=select_dbSCL($id);
$shift=select_dbShifts($id);
if(!$scl instanceof SCL) {
return null;
}
$persons=$scl->get_persons();
$status=$scl->get_status();
$venue = substr(strrchr($id,":"),1);
if(array_key_exists('_shiftid',$_POST))
show_back_navigation($_POST['_shiftid'],692,$venue); // show_back_navigation($id,692);
echo "<table width=\"700\" align=\"center\" border=\"0px\">
<tr><td colspan=\"5\" align=\"center\"><b>Sub Call List for ".get_shift_name_from_id($id)."</b></td></tr>" ;
echo "<tr><td colspan=\"5\"><br>";
$v=$shift->num_vacancies();
if($v==1)
echo " 1 sub";
else
echo " ".$v." subs";
echo " needed for this shift.<br><br></td></tr>
<br><br><tr><td> Name</td><td>Phone</td><td>Date Called</td><td>Notes</td><td>Accepted</td></tr>";
echo "<form method=\"POST\" style=\"margin-bottom:0;\">";
for($i=0;$i<count($persons);++$i) {
if ($_SESSION['access_level']>=2)
echo "<tr><td> <a href=\"personEdit.php?id=".$persons[$i][0]."\">".$persons[$i][1]." ".$persons[$i][2]."</a></td><td>";
else echo "<tr><td> ".$persons[$i][1]." ".$persons[$i][2]."</td><td>";
echo format_phone_number($persons[$i][3])."<br>".format_phone_number($persons[$i][4])."</td>
<td><textarea rows=\"2\" cols=\"20\" name=\"datecalled_".$i."\">".$persons[$i][5]."</textarea></td>
<td><textarea rows=\"2\" cols=\"20\" name=\"notes_".$i."\">".$persons[$i][6]."</textarea></td>
<td valign=\"top\">";
if($persons[$i][7]=="Yes") {
echo "<br>Yes<input type=\"hidden\" name=\"accepted_".$i."\" value=\"Yes\">";
}
else if($persons[$i][7]=="No")
echo "<br>No<input type=\"hidden\" name=\"accepted_".$i."\" value=\"No\">";
else {
echo "<select name=\"accepted_".$i."\">
<option value=\"-\" selected=\"selected\">-</option>
<option value=\"Yes\">Yes</option>
<option value=\"No\">No</option></select>";
}
echo "</td></tr>";
}
echo "<tr><td align=\"right\" colspan=\"5\"><br>
<input type=\"hidden\" name=\"_submit_save_scl_changes\" value=\"1\">
<input type=\"hidden\" name=\"_shiftid\" value=\"".$id."\">
<input type=\"submit\" value=\"Assign Subs / Save Changes\" name=\"submit\" style=\"width: 200px\">
</td></tr>";
echo "</table>";
return $id;
}
function process_edit_scl($post) {
$id=$post['_shiftid'];
$shift=select_dbShifts($id);
$venue = substr(strrchr($id,":"),1);
$scl=select_dbSCL($id);
$persons_old=$scl->get_persons();
$vacancies=$shift->num_vacancies();
$new_acceptances=0;
for($i=0;$i<count($persons_old);++$i) {
$p_new=array($persons_old[$i][0],$persons_old[$i][1],$persons_old[$i][2],$persons_old[$i][3],
$persons_old[$i][4], trim(str_replace(',',',',str_replace('+','+',str_replace('\'','\\\'',htmlentities($post['datecalled_'.$i]))))),
trim(str_replace(',',',',str_replace('+','+',str_replace('\'','\\\'',htmlentities($post['notes_'.$i]))))),$post['accepted_'.$i]);
$persons_new[]=$p_new;
if($post['accepted_'.$i]=="Yes" && $persons_old[$i][7]!="Yes") {
++$new_acceptances;
$accepted_people[]=$i;
}
}
if($new_acceptances>$vacancies){
for($j=0;$j<count($accepted_people);++$j) {
if($j==0)
$s=$persons_new[$accepted_people[$j]][1]." ".$persons_new[$accepted_people[$j]][2];
else if($j==count($accepted_people)-1)
$s=$s." and ".$persons_new[$accepted_people[$j]][1]." ".$persons_new[$accepted_people[$j]][2];
else
$s=$s.", ".$persons_new[$accepted_people[$j]][1]." ".$persons_new[$accepted_people[$j]][2];
$persons_new[$accepted_people[$j]][7]="?";
}
if($vacancies==1) {
echo "You assigned <b>".$s."</b> to this shift, but there is only ".$vacancies." open slot.<br>
Please assign volunteers again.</p>";
}
else{
echo "You assigned <b>".$s."</b> to this shift, but there are only ".$vacancies." open slots.<br>
Please assign volunteers again.</p>";
}
update_sub_call_list($scl,$persons_new,$vacancies,"open");
return $id;
}
else {
$p=$shift->get_persons();
for($j=0;$j<count($accepted_people);++$j) {
$s=$persons_new[$accepted_people[$j]][0]."+".$persons_new[$accepted_people[$j]][1].
"+".$persons_new[$accepted_people[$j]][2];
$p[]=$s;
--$vacancies;
$shift->ignore_vacancy();
}
$shift->assign_persons($p);
update_dbShifts($shift);
for($j=0;$j<count($accepted_people);++$j) {
add_log_entry('<a href=\"personEdit.php?id='.$_SESSION['_id'].'\">'.
$_SESSION['f_name'].' '.$_SESSION['l_name'].'</a> assigned <a href=\"personEdit.php?id='.$persons_new[$accepted_people[$j]][0].'\">'.
$persons_new[$accepted_people[$j]][1].' '.$persons_new[$accepted_people[$j]][2].'</a> to the shift: <a href=\"editShift.php?shift='.
$shift->get_id().'&venue='.$venue.'\">'.get_shift_name_from_id($shift->get_id()).'</a>.');
}
//print_r($shift);
if($vacancies==0)
$status="closed";
else
$status="open";
update_sub_call_list($scl,$persons_new,$vacancies,$status);
}
}
function update_sub_call_list($scl,$persons,$vacancies,$status) {
$scl->set_persons($persons);
$scl->set_vacancies($vacancies);
$scl->set_status($status);
update_dbSCL($scl);
}
function do_name($id) {
$id=substr($id,9);
$i=strpos($id,"-");
if ($i>0) {
$start = substr($id,0,$i);
if ($start>12)
$start = $start - 12 . "pm";
else if ($start==12)
$start = $start."pm";
else $start = $start."am";
$end = substr($id,$i+1);
if ($end>12) $end = $end - 12 . "pm";
else if ($end==12)
$end = $end . "pm";
else $end = $end . "am";
return("from ". $start . " to " . $end );
}
else return $id;
}
function get_sub_call_list_timestamp($id) {
$m=substr($id,0,2);
$d=substr($id,3,2);
$y="20".substr($id,6,2);
$s=substr($id,9,1);
return $y.$m.$d.$s;
}
function show_back_navigation($id,$width,$venue) {
echo "<br><table align=\"center\"><tr><td align=\"center\" width=\"".$width."\">
<a href=\"editShift.php?shift=".substr($id, 0, strrpos($id, ":")) ."&venue=".$venue."\">Back to Shift</a></td></tr></table>" ;
return true;
}
function back_to_calendar($date,$width,$venue) {
echo "<br><table align=\"center\"><tr><td align=\"center\" width=\"".$width."\">
<a href=\"calendar.php?id=".$date.":".$venue."&venue=".$venue."\">Back to Calendar</a></td></tr></table>" ;
return true;
}
function format_phone_number($s){
if(strlen($s)!=10)
return $s;
else return "(".substr($s,0,3).") ".substr($s,3,3)."-".substr($s,6);
}
?>