Completed
Push — FVSv2 ( e85196...534a54 )
by Patrick
01:34
created

signup.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
require_once('class.VolunteerPage.php');
3
require_once('api/v1/class.Processor.php');
4
require_once('app/VolunteerAutoload.php');
5
6
class ProcessorUser
0 ignored issues
show
There is one abstract method isVolunteerAdmin in this class; you could implement it, or declare this class as abstract.
Loading history...
7
{
8
  use Processor;
9
10
  protected $isAdmin;
11
12
  public function __construct($isAdmin)
13
  {
14
      $this->isAdmin = $isAdmin;
15
  }
16
}
17
18
$page = new VolunteerPage('Burning Flipside - Flipside Volunteer System');
19
$page->addJS('js/signup.js');
20
$processor = new ProcessorUser($page->user->isInGroupNamed('VolunteerAdmins'));
21
22
$page->body = '<div class="row"><h1>Shift Signup</h1></div>';
23
24
if(!isset($_GET['shiftID']))
25
{
26
  $page->body .= 'Error! Missing Shift ID. You must have followed a bad link!';
27
  $page->printPage();
28
  return;
29
}
30
31
$shiftID = $_GET['shiftID'];
32
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'shifts');
33
$filter = new \Data\Filter('_id eq '.$shiftID);
34
$shifts = $dataTable->read($filter);
35
if(empty($shifts))
36
{
37
  $page->body .= 'Error! Could not locate shift. You must have followed an old link!';
38
  $page->printPage();
39
  return;
40
}
41
$shift = $shifts[0];
42
$myShift = new \VolunteerShift(false, $shift);
43
44
$profile = new \VolunteerProfile($page->user->uid);
45
46
if($processor->isAdminForShift($shift, $page->user))
47
{
48
  if(isset($shift['groupID']) && strlen($shift['groupID'] > 0))
49
  {
50
    $page->body .= '
51
    <div class="alert alert-info" role="alert">
52
      You are an administrator for this shift. You can edit the shift <a href="_admin/shifts.php?shiftID='.$shiftID.'" class="alert-link">here</a>.
53
      Or you can edit the shift group <a href="_admin/shifts.php?groupID='.$shift['groupID'].'" class="alert-link">here</a>.
54
    </div>
55
    ';
56
  }
57
  else
58
  {
59
    $page->body .= '
60
    <div class="alert alert-info" role="alert">
61
      You are an administrator for this shift. You can edit the shift <a href="_admin/shifts.php?shiftID='.$shiftID.'" class="alert-link">here</a>.
62
    </div>
63
    ';
64
  }
65
}
66
67
//Is shift already taken?
68
if(isset($entry['status']) && ($entry['status'] === 'pending' || $entry['status'] === 'filled'))
69
{
70
  if(isset($shift['participant']) && $shift['participant'] === $page->user->uid)
71
  {
72
    $page->body .= '<div class="alert alert-success" role="alert">
73
      You already have this shift!
74
    </div>
75
    <div class="row">
76
      <button type="button" class="btn btn-secondary mr-auto" onClick="window.history.back();">Cancel</button>
77
      <button type="button" class="btn btn-primary" onclick="abandon();">Abandon Shift</button>
78
    </div>';
79
  }
80
  else
81
  {
82
    $page->body .= '<div class="alert alert-danger" role="alert">
83
      Someone else took this shift!
84
    </div>';
85
  }
86
  $page->printPage();
87
  return;
88
}
89
90
$overlap = false;
91
if($myShift->findOverlaps($page->user->uid, true))
92
{
93
    $page->body .= '<div class="alert alert-warning" role="alert">
94
      You already have a shift during this time. If you choose to signup for this shift the lead(s) for the departments will be notified and must approve.
95
    </div>
96
    <div class="row">
97
      <label for="department" class="col-sm-10 col-form-label">I understand I am signing up for multiple shifts at the same time.</label>
98
      <div class="col-sm-2">
99
        <input type="checkbox" class="form-control" onChange="revealPage();">
100
      </div>
101
    </div>';
102
    $overlap = true;
103
}
104
105
$deptName = $shift['departmentID'];
106
$roleName = $shift['roleID'];
107
108
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'departments');
109
$depts = $dataTable->read(new \Data\Filter('departmentID eq '.$shift['departmentID']));
110
if(!empty($depts))
111
{
112
  $deptName = $depts[0]['departmentName'];
113
}
114
115
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'events');
116
$events = $dataTable->read(new \Data\Filter('_id eq '.$shift['eventID']));
117
if(!empty($events))
118
{
119
  if($events[0]['tickets'])
120
  {
121
    //TODO... Event requires tickets. Does this account have tickets?
122
  }
123
}
124
125
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'roles');
126
$roles = $dataTable->read(new \Data\Filter('short_name eq '.$shift['roleID']));
127
if(!empty($roles))
128
{
129
  $roleName = $roles[0]['display_name'];
130
}
131
132
//Is user eligible for shift?
133
$canDo = $processor->canUserDoRole($profile, $roles[0]);
134
if($canDo !== true)
135
{
136
  $page->body .= '<div class="alert alert-danger" role="alert">';
137
  switch($canDo['whyClass'])
138
  {
139
    case 'INVITE':
140
      $page->body .= 'This shift requires an invite from the department lead. If you think you should have recieved such an invite please <a href="https://www.burningflipside.com/contact" class="alert-link">contact the lead</a>.';
141
      break;
142
    case 'CERT':
143
       $page->body .= $canDo['whyMsg'].' If you have this certification it is not recorded in your profile. You can <a href="certiciation.php" class="alert-link">record that certification</a> to sign up.';
144
       break;
145
    default:
146
      $page->body .= 'You are not eligible for this shift because: '.$canDo['whyMsg'];
147
      break;
148
  }
149
  $page->body .= '</div>';
150
  $page->printPage();
151
  return;  
152
}
153
154
$start = new \DateTime($shift['startTime']);
155
$end = new \DateTime($shift['endTime']);
156
$diff = $end->diff($start);
157
$shiftLength = $diff->h + ($diff->i / 60.0);
158
159
$page->body .= '<div id="signupContent" ';
160
if($overlap)
161
{
162
  $page->body .= 'class="d-none" ';
163
}
164
$page->body .= '/>';
165
$page->body .= '
166
<div class="row">
167
  <input type="hidden" id="shiftID" name="shiftID" value="'.$shiftID.'"/>
168
  <label for="department" class="col-sm-2 col-form-label">Department:</label>
169
  <div class="col-sm-10">
170
    <input type="text" name="department" id="department" class="form-control" readonly="readonly" value="'.$deptName.'">
171
  </div>
172
  <label for="role" class="col-sm-2 col-form-label">Role:</label>
173
  <div class="col-sm-10">
174
    <input type="text" name="role" id="role" class="form-control" readonly="readonly" value="'.$roleName.'">
175
  </div>
176
  <label for="startTime" class="col-sm-2 col-form-label">Start Time:</label>
177
  <div class="col-sm-10">
178
    <input type="datetime-local" name="startTime" id="startTime" class="form-control" readonly="readonly" value="'.$shift['startTime'].'">
179
  </div>
180
  <label for="endTime" class="col-sm-2 col-form-label">End Time:</label>
181
  <div class="col-sm-10">
182
    <input type="datetime-local" name="endTime" id="endTime" class="form-control" readonly="readonly" value="'.$shift['endTime'].'">
183
  </div>
184
  <label for="length" class="col-sm-2 col-form-label">Length:</label>
185
  <div class="col-sm-10">
186
    <input type="text" name="length" id="length" class="form-control" readonly="readonly" value="'.$shiftLength.' hours">
187
  </div>
188
</div>
189
<div class="row">
190
  <div class="alert alert-info" role="alert">
191
    By signing up for a Burning Flipside shift you are commiting to showing up on time for your shift prepared to work. Please make sure you are prepared to make this commitment before clicking signup below.
192
  </div>
193
</div>
194
<div class="row">
195
  <button type="button" class="btn btn-secondary mr-auto" onClick="window.history.back();">Cancel</button>
196
  <button type="button" class="btn btn-primary" onclick="signup();">Signup</button>
197
</div></div>
198
';
199
200
//Is group eligible?
201
if(isset($shift['groupID']) && isset($roles[0]['groups_allowed']) && $roles[0]['groups_allowed'])
202
{
203
  $page->body .= '
204
  <div class="row">
205
    <div class="alert alert-primary" role="alert">
206
      You have selected a group eligible shift. This means you can generate a link for your friends to sign up on the shift with you. Would you like to sign up for the shift and generate that link now?
207
    </div>
208
  </div>
209
  <div class="row">
210
    <button type="button" class="btn btn-secondary" onclick="groupSignup();">Signup and Generate Group Link</button>
211
  </div>
212
  ';
213
}
214
215
$page->printPage();
216