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

ProcessorUser::isVolunteerAdmin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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