PluginProbe
ShiftController Employee Shift Scheduling / 3.2.4
ShiftController Employee Shift Scheduling v3.2.4
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / application / config / acl.php

acl.php in ShiftController Employee Shift Scheduling 3.2.4, at application/config/acl.php

453 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $acl[] = new Shiftcontroller_Admin_HC_Acl;
3 $acl[] = new Shiftcontroller_HC_Acl;
4
5 class Shiftcontroller_Admin_HC_Acl
6 {
7 public function __call( $what, $args )
8 {
9 $u = array_shift( $args );
10 $o = array_shift( $args );
11
12 if( $u->level >= $u->_const("LEVEL_MANAGER") ){
13 return TRUE;
14 }
15 return;
16 }
17
18 // only active shifts are allowed
19 function shift_validate_status2( $u, $o, $new_value )
20 {
21 if( $o->status == $new_value ){
22 return TRUE;
23 }
24
25 $app_conf = HC_App::app_conf();
26 if( $o->type == $o->_const('TYPE_TIMEOFF') ){
27 return TRUE;
28 }
29 else {
30 if( $new_value == $o->_const('STATUS_ACTIVE') ){
31 return TRUE;
32 }
33 else {
34 return FALSE;
35 }
36 }
37 }
38 }
39
40 class Shiftcontroller_HC_Acl
41 {
42 private $_edit_delete = array(
43 'view_active' => array(
44 'edit_active' => 0,
45 'edit_draft' => 0,
46 'delete_active' => 0,
47 'delete_draft' => 0
48 ),
49 'view_draft' => array(
50 'edit_active' => 0,
51 'edit_draft' => 0,
52 'delete_active' => 0,
53 'delete_draft' => 0
54 ),
55 'create_draft' => array(
56 'edit_active' => 0,
57 'edit_draft' => 1,
58 'delete_active' => 0,
59 'delete_draft' => 1
60 ),
61 'confirm_draft' => array(
62 'edit_active' => 0,
63 'edit_draft' => 1,
64 'delete_active' => 0,
65 'delete_draft' => 0
66 ),
67 'create_active' => array(
68 'edit_active' => 1,
69 'edit_draft' => 1,
70 'delete_active' => 1,
71 'delete_draft' => 1
72 )
73 );
74
75 private function _shift_add( $u, $o )
76 {
77 $app_conf = HC_App::app_conf();
78 $staff_shift_acl = $app_conf->get('staff:shift_acl');
79 $staff_shift_acl = $app_conf->get('staff:shift_acl');
80 if( ! is_array($staff_shift_acl) ){
81 $staff_shift_acl = array( $staff_shift_acl );
82 }
83
84 if( array_intersect(array('create_draft', 'create_active'), $staff_shift_acl) ){
85 return TRUE;
86 }
87 return;
88 }
89
90 private function _timeoff_add( $u, $o )
91 {
92 if( $o->user_id != $u->id ){
93 return;
94 }
95
96 $app_conf = HC_App::app_conf();
97 if( $o->status !== NULL ){
98 $timeoff_approval_required = $app_conf->get("timeoff:approval_required");
99 if( $timeoff_approval_required ){
100 if( ! in_array($o->status, array($o->_const("STATUS_DRAFT"))) ){
101 return FALSE;
102 }
103 }
104 else {
105 return TRUE;
106 }
107 }
108 else {
109 return TRUE;
110 }
111 return;
112 }
113
114 function shift_add( $u, $o )
115 {
116 if( ! $o->user_id ){
117 return;
118 }
119
120 if( $o->user_id != $u->id ){
121 return;
122 }
123
124 /* timeoffs */
125 if( in_array($o->type, array($o->_const("TYPE_TIMEOFF"))) ){
126 return $this->_timeoff_add($u, $o);
127 }
128 /* shifts */
129 else {
130 return $this->_shift_add($u, $o);
131 }
132 }
133
134 function shift_view( $u, $o )
135 {
136 $app_conf = HC_App::app_conf();
137 $staff_shift_acl = $app_conf->get("staff:shift_acl");
138
139 /* can view own pending timeoffs, otherwise no */
140 $show_draft = hc_in_array("view_draft", $staff_shift_acl);
141
142 if( $o->user_id && ($u->id == $o->user_id) ){
143 if( $o->status != $o->_const("STATUS_ACTIVE") ){
144 if( $show_draft ){
145 return TRUE;
146 }
147 else {
148 return FALSE;
149 }
150 }
151 else {
152 return TRUE;
153 }
154 }
155 elseif( $o->status != $o->_const("STATUS_ACTIVE") ){
156 return FALSE;
157 }
158
159 /* if anonymous */
160 if( ! $u->id ){
161 /* cannot view timeoffs */
162 if(in_array($o->type, array($o->_const('TYPE_TIMEOFF'))) ){
163 return;
164 }
165
166 /* cannot view open shifts */
167 if( ! $o->user_id ){
168 $wall_show_open = $app_conf->get('wall:show_open');
169 if( $wall_show_open ){
170 return TRUE;
171 }
172 return;
173 }
174 }
175
176 /* cannot view others timeoffs */
177 if( ($u->id != $o->user_id) && (in_array($o->type, array($o->_const("TYPE_TIMEOFF")))) ){
178 return FALSE;
179 }
180
181 $ri = HC_Lib::ri();
182 if( $ri ){
183 /* shortcode so can view it anyway */
184 return TRUE;
185 }
186 else {
187 $user_level = $u->level ? $u->level : 0;
188 $wall_schedule_display = $app_conf->get("wall:schedule_display");
189
190 if( $user_level >= $wall_schedule_display ){
191 return TRUE;
192 }
193 }
194 return;
195 }
196
197 private function _timeoff_edit( $u, $o )
198 {
199 $app_conf = HC_App::app_conf();
200
201 if( $o->status !== NULL ){
202 $timeoff_approval_required = $app_conf->get('timeoff:approval_required');
203 if( $timeoff_approval_required ){
204 if( ! in_array($o->status, array($o->_const('STATUS_DRAFT'))) ){
205 return FALSE;
206 }
207 }
208 return TRUE;
209 }
210 }
211
212 private function _shift_edit( $u, $o, $what = 'edit' )
213 {
214 $app_conf = HC_App::app_conf();
215
216 $staff_shift_acl = $app_conf->get('staff:shift_acl');
217 if( ! is_array($staff_shift_acl) ){
218 $staff_shift_acl = array( $staff_shift_acl );
219 }
220
221 if( $o->status == $o->_const('STATUS_DRAFT') ){
222 $acl_key2 = $what . '_draft';
223 }
224 else {
225 $acl_key2 = $what . '_active';
226 }
227
228 $return = NULL;
229 foreach( $staff_shift_acl as $acl_key1 ){
230 $return = NULL;
231 if( isset($this->_edit_delete[$acl_key1][$acl_key2]) ){
232 $return = $this->_edit_delete[$acl_key1][$acl_key2];
233 if( $return ){
234 $return = TRUE;
235 break;
236 }
237 }
238 }
239 return $return;
240 }
241
242 function shift_edit( $u, $o )
243 {
244 if( ! $u->id ){
245 return FALSE;
246 }
247 if( $o->user_id != $u->id ){
248 return FALSE;
249 }
250
251 /* timeoffs */
252 if( in_array($o->type, array($o->_const("TYPE_TIMEOFF"))) ){
253 return $this->_timeoff_edit($u, $o);
254 }
255 /* shifts */
256 else {
257 return $this->_shift_edit($u, $o, 'edit');
258 }
259 return;
260 }
261
262 function shift_delete( $u, $o )
263 {
264 if( ! $u->id ){
265 return FALSE;
266 }
267 if( $o->user_id != $u->id ){
268 return FALSE;
269 }
270
271 /* timeoffs */
272 if( in_array($o->type, array($o->_const("TYPE_TIMEOFF"))) ){
273 return $this->_timeoff_edit($u, $o);
274 }
275 /* shifts */
276 else {
277 return $this->_shift_edit($u, $o, 'delete');
278 }
279 return;
280 }
281
282 private function _timeoff_validate( $u, $o )
283 {
284 $app_conf = HC_App::app_conf();
285
286 if( $o->status !== NULL ){
287 $timeoff_approval_required = $app_conf->get("timeoff:approval_required");
288 if( $timeoff_approval_required ){
289 if( ! in_array($o->status, array($o->_const("STATUS_DRAFT"))) ){
290 return FALSE;
291 }
292 }
293 else {
294 if( ! in_array($o->status, array($o->_const("STATUS_ACTIVE"))) ){
295 return FALSE;
296 }
297 }
298 }
299 else {
300 return TRUE;
301 }
302 }
303
304 function shift_validate_location( $u, $o, $new_value )
305 {
306 if( $o->location_id == $new_value ){
307 return TRUE;
308 }
309
310 if( $o->status === NULL ){
311 return TRUE;
312 }
313
314 $app_conf = HC_App::app_conf();
315 $staff_shift_acl = $app_conf->get("staff:shift_acl");
316
317 /* create draft shifts */
318 if( hc_in_array('create_draft', $staff_shift_acl) ){
319 if( $o->status == $o->_const('STATUS_DRAFT') ){
320 return TRUE;
321 }
322 }
323
324 /* create active shifts */
325 if( hc_in_array('create_active', $staff_shift_acl) ){
326 return TRUE;
327 }
328 }
329
330 function shift_validate_status( $u, $o, $new_value )
331 {
332 if( $o->status == $new_value ){
333 return TRUE;
334 }
335
336 $app_conf = HC_App::app_conf();
337 if( $o->type == $o->_const('TYPE_TIMEOFF') ){
338 $timeoff_approval_required = $app_conf->get("timeoff:approval_required");
339 if( (! $timeoff_approval_required) OR ($new_value == $o->_const('STATUS_DRAFT')) ){
340 return TRUE;
341 }
342 }
343 else {
344 $staff_shift_acl = $app_conf->get("staff:shift_acl");
345
346 /* create draft shifts */
347 if( hc_in_array('create_draft', $staff_shift_acl) ){
348 if( ($o->status != $o->_const('STATUS_ACTIVE')) &&
349 ($new_value == $o->_const('STATUS_DRAFT')) ){
350 return TRUE;
351 }
352 }
353
354 /* approve draft shifts */
355 if( hc_in_array('confirm_draft', $staff_shift_acl) ){
356 if( ($o->id) && ($new_value == $o->_const('STATUS_ACTIVE')) ){
357 return TRUE;
358 }
359 }
360
361 /* create active shifts */
362 if( hc_in_array('create_active', $staff_shift_acl) ){
363 return TRUE;
364 }
365 }
366 }
367
368 function shift_validate_user( $u, $o, $new_value )
369 {
370 if( $new_value == $u->id ){
371 return TRUE;
372 }
373 }
374
375 function shift_edit_time( $u, $o )
376 {
377 $app_conf = HC_App::app_conf();
378 $staff_shift_acl = $app_conf->get("staff:shift_acl");
379
380 /* create draft shifts */
381 if( hc_in_array('create_draft', $staff_shift_acl) ){
382 if( $o->status == $o->_const('STATUS_DRAFT') ){
383 return TRUE;
384 }
385 }
386
387 /* create active shifts */
388 if( hc_in_array('create_active', $staff_shift_acl) ){
389 return TRUE;
390 }
391 }
392
393 private function _shift_validate( $u, $o )
394 {
395 $app_conf = HC_App::app_conf();
396
397 $staff_shift_acl = $app_conf->get("staff:shift_acl");
398
399 /* approve existing graft shifts */
400 if( hc_in_array('confirm_draft', $staff_shift_acl) ){
401 if( $o->id && ($o->status !== NULL) ){
402 return TRUE;
403 }
404 }
405
406 $staff_add_shifts = 0;
407 if( hc_in_array("create_draft", $staff_shift_acl) ){
408 $staff_add_shifts = $o->_const("STATUS_DRAFT");
409 }
410 if( hc_in_array("create_active", $staff_shift_acl) ){
411 $staff_add_shifts = $o->_const("STATUS_ACTIVE");
412 }
413
414 if( ! $staff_add_shifts ){
415 return FALSE;
416 }
417
418 if( $o->status !== NULL ){
419 switch( $staff_add_shifts ){
420 case $o->_const("STATUS_ACTIVE"):
421 break;
422
423 case $o->_const("STATUS_DRAFT"):
424 if( ! in_array($o->status, array($o->_const("STATUS_DRAFT"))) ){
425 return FALSE;
426 }
427 break;
428 }
429 }
430 }
431
432 function shift_validate( $u, $o )
433 {
434 if( ! $u->id ){
435 return FALSE;
436 }
437 if( $o->user_id != $u->id ){
438 return FALSE;
439 }
440
441 $app_conf = HC_App::app_conf();
442
443 /* timeoffs */
444 if( in_array($o->type, array($o->_const("TYPE_TIMEOFF"))) ){
445 return $this->_timeoff_validate($u, $o);
446 }
447 /* shifts */
448 else {
449 return $this->_shift_validate($u, $o);
450 }
451 return TRUE;
452 }
453 }