PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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 / sh4 / schedule / html / view / index.php

index.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/schedule/html/view/index.php

778 lines 19.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 class SH4_Schedule_Html_View_Index
3 {
4 protected $linksInFooter = TRUE;
5
6 public function __construct(
7 HC3_Hooks $hooks,
8 HC3_Time $t,
9 HC3_Request $request,
10 HC3_Settings $settings,
11 HC3_Ui $ui,
12 HC3_Auth $auth,
13 HC3_Acl $acl,
14
15 HC3_Uri $uri,
16
17 HC3_Ui_Layout1 $layout,
18 HC3_Enqueuer $enqueuer,
19
20 SH4_App_Query $appQuery,
21
22 SH4_Calendars_Permissions $cp,
23 SH4_Schedule_Html_View_Common $common,
24
25 SH4_Schedule_Html_View_List $viewList,
26 SH4_Schedule_Html_View_Day $viewDay,
27 SH4_Schedule_Html_View_Week $viewWeek,
28 SH4_Schedule_Html_View_FourWeeks $viewFourWeeks,
29 SH4_Schedule_Html_View_TwoWeeks $viewTwoWeeks,
30 SH4_Schedule_Html_View_Month $viewMonth,
31 SH4_Schedule_Html_View_Report $viewReport,
32 SH4_Schedule_Html_View_Download $viewDownload,
33
34 SH4_Schedule_Html_View_ControlOptions $viewControlOptions,
35 SH4_Schedule_Html_View_MiscOptions $viewMiscOptions,
36 SH4_Schedule_Html_View_NewOptions $viewNewOptions,
37 SH4_Schedule_Html_View_ControlDates $viewControlDates
38 )
39 {
40 $this->cp = $hooks->wrap( $cp );
41 $this->common = $hooks->wrap( $common );
42
43 $this->self = $hooks->wrap( $this );
44 $this->layout = $layout;
45 $this->auth = $auth;
46 $this->acl = $acl;
47
48 $this->appQuery = $hooks->wrap( $appQuery );
49 $this->settings = $hooks->wrap( $settings );
50
51 $this->ui = $ui;
52 $this->uri = $uri;
53 $this->t = $t;
54 $this->request = $request;
55
56 $this->viewList = $hooks->wrap( $viewList );
57 $this->viewDay = $hooks->wrap( $viewDay );
58 $this->viewWeek = $hooks->wrap( $viewWeek );
59 $this->viewMonth = $hooks->wrap( $viewMonth );
60 $this->viewFourWeeks = $hooks->wrap( $viewFourWeeks );
61 $this->viewTwoWeeks = $hooks->wrap( $viewTwoWeeks );
62 $this->viewReport = $hooks->wrap( $viewReport );
63 $this->viewDownload = $hooks->wrap( $viewDownload );
64
65 $this->viewControlOptions = $hooks->wrap( $viewControlOptions );
66 $this->viewControlDates = $hooks->wrap( $viewControlDates );
67 $this->viewMiscOptions = $hooks->wrap( $viewMiscOptions );
68 $this->viewNewOptions = $hooks->wrap( $viewNewOptions );
69
70 $enqueuer->addScript('schedule', 'sh4/schedule/assets/js/calendar.js?hcver=' . SH4_VERSION);
71
72 $this->linksInFooter = $this->settings->get( 'datetime_hide_bottom_date_navigation', false ) ? false : true;
73 }
74
75 public function renderMy()
76 {
77 $out = NULL;
78 $slug = $this->request->getSlug();
79
80 $currentUser = $this->auth->getCurrentUser();
81 $currentUserId = $currentUser->getId();
82 if( ! $currentUserId ){
83 return $out;
84 }
85
86 // as employee
87 $meEmployee = $this->appQuery->findEmployeeByUser( $currentUser );
88 if( ! $meEmployee ){
89 return $out;
90 }
91
92 $meEmployeeId = $meEmployee->getId();
93
94 $start = $this->t->setNow()->formatDateDb();
95 $end = $this->t->modify('+6 days')->formatDateDb();
96
97 $type = NULL;
98 $type = HC3_Session::instance()->getUserdata('scheduleViewType'); // week/list/report
99 if( ! $type ){
100 $type = $this->settings->get( 'default_schedule_view' );
101 }
102 if( ! $type ){
103 $type = 'week';
104 }
105
106 $groupby = NULL;
107 $groupby = HC3_Session::instance()->getUserdata('scheduleViewGroupby');
108 if( ! $groupby ){
109 $groupby = $this->settings->get( 'default_schedule_groupby' );
110 }
111 if( (! $groupby) OR ($groupby == 'employee') ){
112 $groupby = 'none';
113 }
114
115 $allowed = array();
116
117 $employee = array( $meEmployeeId );
118
119 $calendar = HC3_Session::instance()->getUserdata('scheduleViewCalendar');
120 if( ! $calendar ){
121 $calendar = array();
122 }
123
124 $hideui = array(
125 'filter-employee',
126 // 'filter-calendar',
127 // 'groupby',
128 // 'type-month', 'type-day', 'type-week',
129 );
130 // type
131 // type-month
132 // type-week
133 // type-day
134 // type-list
135 // type-report
136 // groupby
137 // print
138 // download
139 // filter-calendar
140 // filter-employee
141
142 $defaultParams = array(
143 'conflict' => 0,
144 'pickup' => 0,
145 'type' => $type,
146 'groupby' => $groupby,
147 'start' => $start,
148 'end' => $end,
149 'employee' => $employee,
150 'calendar' => $calendar,
151 'hideui' => $hideui
152 );
153
154 $params = $this->request->getParams();
155 $params = array_merge( $defaultParams, $params );
156
157 foreach( $params as $k => $v ){
158 $this->request
159 ->initParam( $k, $v )
160 ;
161 }
162
163 // $params['employee'] = HC3_Functions::removeFromArray( $params['employee'], 'x' );
164 $params['calendar'] = HC3_Functions::removeFromArray( $params['calendar'], 'x' );
165
166 $this->request
167 // ->setParam('employee', $params['employee'])
168 ->setParam('calendar', $params['calendar'])
169 ;
170
171 HC3_Session::instance()
172 ->setUserdata( 'scheduleViewType', $params['type'] )
173 ->setUserdata( 'scheduleViewGroupby', $params['groupby'] )
174 // ->setUserdata( 'scheduleViewEmployee', $params['employee'] )
175 ->setUserdata( 'scheduleViewCalendar', $params['calendar'] )
176 ;
177
178 $toParams = $this->request->getParams('withoutdefault');
179 $scheduleLink = array( $slug, $toParams );
180
181 HC3_Session::instance()
182 ->setUserdata( 'scheduleLink', $scheduleLink )
183 ;
184
185 // $scheduleLink2 = HC3_Session::instance()
186 // ->getUserdata( 'scheduleLink' )
187 // ;
188 // $to = $this->uri->makeUrl( $scheduleLink2 );
189 // echo "TO = '$to'<br>";
190 // exit;
191
192 $type = $params['type'];
193 $groupby = $params['groupby'];
194
195 $view = NULL;
196
197 if( array_key_exists('download', $params) && $params['download'] ){
198 $view = $this->viewDownload;
199 $groupby = NULL;
200 }
201 else {
202 switch( $type ){
203 case '4weeks':
204 $view = $this->viewFourWeeks;
205 break;
206 case '2weeks':
207 $view = $this->viewTwoWeeks;
208 break;
209 case 'month':
210 $view = $this->viewMonth;
211 break;
212 case 'week':
213 $view = $this->viewWeek;
214 break;
215 case 'day':
216 $view = $this->viewDay;
217 break;
218 case 'list':
219 $view = $this->viewList;
220 break;
221 case 'report':
222 $view = $this->viewReport;
223 break;
224 }
225 }
226
227 switch( $groupby ){
228 // case 'employee':
229 // $out = $view->renderByEmployee();
230 // break;
231 case 'calendar':
232 $out = $view->renderByCalendar();
233 break;
234 default:
235 $out = $view->render();
236 break;
237 }
238
239 if( ! in_array($type, array('report')) ){
240 $miscOptions = $this->viewMiscOptions->options();
241 if( $this->request->isPrintView() ){
242 $miscOptions[2] = NULL;
243 $miscOptions[3] = NULL;
244 }
245
246 if( $miscOptions ){
247 $misc = $this->ui->makeGrid();
248 $misc->add( isset($miscOptions[1]) ? $miscOptions[1] : NULL, 3, 12 );
249 $misc->add( isset($miscOptions[2]) ? $miscOptions[2] : NULL, 7, 12 );
250 $misc->add( isset($miscOptions[3]) ? $miscOptions[3] : NULL, 2, 12 );
251
252 $out = $this->ui->makeList( array($misc, $out) )
253 ->gutter(3)
254 ;
255 }
256 }
257
258 $src = $this->uri->currentUrl();
259 $this->uri->fromUrl( $src );
260
261 $uriParams = $this->uri->getParams();
262 $src = $this->uri
263 ->makeUrl( array('myschedule', $uriParams) )
264 ;
265
266 $out = $this->ui->makeBlock( $out )
267 ->addAttr( 'id', 'sh4-shifts-calendar' )
268 ->addAttr( 'data-src', $src )
269 ;
270
271 if( $this->request->isAjax() ){
272 return $out;
273 }
274
275 if( ! $this->request->isPrintView() ){
276 $headerControl = $this->viewControlOptions->render();
277 if( $headerControl ){
278 $out = $this->ui->makeList( array($headerControl, $out) );
279 }
280 }
281
282 if( ! in_array($type, array('report')) ){
283 if( ! $this->request->isPrintView() ){
284 $new = $this->viewNewOptions->render();
285 $out = $this->ui->makeList( array($new, $out) )
286 ->gutter(3)
287 ;
288 }
289 }
290
291 $headerDate = $this->viewControlDates->render();
292 if( $headerDate ){
293 $out = $this->ui->makeList( array($headerDate, $out) );
294 }
295
296 $modal = $this->_renderModal();
297 $out = $this->ui->makeCollection( array($out, $modal) );
298
299 $header = '__My Schedule__';
300 $header = $this->ui->makeBlock( $header )
301 ->tag('font-size', 5)
302 ;
303
304 $toCheck = 'schedule';
305 $everyoneScheduleDisabled = $this->checkEveryoneScheduleDisabled();
306
307 if( 0 ){
308 if( (! $everyoneScheduleDisabled) && $this->acl->check('get:' . $toCheck) ){
309 $label = "__Everyone's Schedule__";
310 $headerLink = $this->ui->makeAhref( $toCheck, $label )
311 ->tag('secondary')
312 ;
313 $header = $this->ui->makeListInline( array($header, $headerLink) );
314 }
315 }
316
317 $out = $this->ui->makeList( array($header, $out) )
318 ->gutter(3)
319 ;
320
321 // is wp?
322 if( defined('WPINC') && (! is_admin()) ){
323 $tos = $this->self->toplinks();
324 // $tos = array(
325 // array( 'admin', '__Administration__' ),
326 // array( 'user/profile', '__Profile__' ),
327 // );
328
329 $headerLinks = array();
330 foreach( $tos as $to ){
331 $checkTo = is_array( $to[0] ) ? $to[0][0] : $to[0];
332 if( ! $this->acl->check('get:' . $checkTo) ){
333 continue;
334 }
335
336 $headerLinks[] = $this->ui->makeAhref( $to[0], $to[1] )
337 ->tag('secondary')
338 ;
339 }
340
341 if( $headerLinks ){
342 $headerLinks = $this->ui->makeListInline( $headerLinks )
343 ->gutter(2)
344 ;
345 $out = $this->ui->makeList( array($headerLinks, $out) )
346 ->gutter(3)
347 ;
348 }
349 }
350
351 // add links to footer
352 if( $this->linksInFooter && $headerDate ){
353 $out = $this->ui->makeList( array($out, $headerDate) )
354 ->gutter(3)
355 ;
356 }
357
358 $this->layout
359 ->setContent( $out )
360 // ->setHeader( $header )
361 ;
362
363 $out = $this->layout->render();
364
365 return $out;
366 }
367
368 public function checkEmployee()
369 {
370 $return = NULL;
371
372 // CHECK IF EVERYTHING IS DISABLED FOR EMPLOYEE THEN REDIRECT TO MYSCHEDULE
373 $somethingAllowed = FALSE;
374
375 $perms = array(
376 'employee_view_others_publish',
377 'employee_view_others_draft',
378 'employee_view_open_publish',
379 'employee_view_open_draft',
380 'employee_pickup_others'
381 );
382
383 $allCalendars = $this->common->findAllCalendars();
384 foreach( $allCalendars as $calendar ){
385 reset( $perms );
386 foreach( $perms as $perm ){
387 if( $this->cp->get($calendar, $perm) ){
388 $somethingAllowed = TRUE;
389 break;
390 }
391 }
392
393 if( $somethingAllowed ){
394 break;
395 }
396 }
397
398 if( ! $somethingAllowed ){
399 $return = array( 'myschedule', NULL );
400 }
401
402 return $return;
403 }
404
405 public function checkAnon()
406 {
407 $return = NULL;
408
409 if( $this->settings->get('users_login_required') ){
410 $return = array( 'login', NULL );
411 return $return;
412 }
413
414 // CHECK IF EVERYTHING IS DISABLED FOR VISITOR THEN REDIRECT TO LOGIN
415 $somethingAllowed = FALSE;
416
417 $perms = array(
418 'visitor_view_others_publish',
419 'visitor_view_others_draft',
420 'visitor_view_open_publish',
421 'visitor_view_open_draft'
422 );
423
424 $allCalendars = $this->common->findAllCalendars();
425 foreach( $allCalendars as $calendar ){
426 reset( $perms );
427 foreach( $perms as $perm ){
428 if( $this->cp->get($calendar, $perm) ){
429 $somethingAllowed = TRUE;
430 break;
431 }
432 }
433
434 if( $somethingAllowed ){
435 break;
436 }
437 }
438
439 if( ! $somethingAllowed ){
440 $return = array( 'login', NULL );
441 }
442
443 return $return;
444 }
445
446 public function checkEveryoneScheduleDisabled()
447 {
448 $return = NULL;
449
450 $currentUserId = $this->auth->getCurrentUserId();
451 if( $currentUserId ){
452 $currentUser = $this->auth->getCurrentUser();
453 $managedCalendars = $this->appQuery->findCalendarsManagedByUser( $currentUser );
454 if( $managedCalendars ){
455 return $return;
456 }
457 $viewedCalendars = $this->appQuery->findCalendarsViewedByUser( $currentUser );
458 if( $viewedCalendars ){
459 return $return;
460 }
461
462 $return = $this->checkEmployee();
463 if( $return ){
464 return $return;
465 }
466 }
467
468 if( ! $currentUserId ){
469 $return = $this->checkAnon();
470 if( $return ){
471 return $return;
472 }
473 }
474
475 return $return;
476 }
477
478 public function render()
479 {
480 $return = $this->checkEveryoneScheduleDisabled();
481 if( $return ){
482 return $return;
483 }
484
485 $slug = $this->request->getSlug();
486
487 $start = $this->t->setNow()->formatDateDb();
488 $end = $this->t->modify('+6 days')->formatDateDb();
489
490 $type = NULL;
491 $type = HC3_Session::instance()->getUserdata('scheduleViewType'); // week/list/report
492 if( ! $type ){
493 $type = $this->settings->get( 'default_schedule_view' );
494 }
495 if( ! $type ){
496 $type = 'week';
497 }
498
499 $groupby = NULL;
500 $groupby = HC3_Session::instance()->getUserdata('scheduleViewGroupby');
501 if( ! $groupby ){
502 $groupby = $this->settings->get( 'default_schedule_groupby' );
503 }
504 if( ! $groupby ){
505 $groupby = 'employee';
506 }
507
508 // $employee = HC3_Session::instance()->getUserdata('scheduleViewEmployee');
509 // if( ! $employee ){
510 $employee = array();
511 // }
512
513 // $calendar = HC3_Session::instance()->getUserdata('scheduleViewCalendar');
514 // if( ! $calendar ){
515 $calendar = array();
516 // }
517
518 $hideui = array();
519
520 $defaultParams = array(
521 'conflict' => 0,
522 'pickup' => 0,
523 'type' => $type,
524 'groupby' => $groupby,
525 'start' => $start,
526 'end' => $end,
527 'employee' => $employee,
528 'calendar' => $calendar,
529 'hideui' => $hideui
530 );
531
532 $params = $this->request->getParams();
533 $params = array_merge( $defaultParams, $params );
534
535 foreach( $params as $k => $v ){
536 $this->request
537 ->initParam( $k, $v )
538 ;
539 }
540
541 $params['employee'] = HC3_Functions::removeFromArray( $params['employee'], 'x' );
542 $params['calendar'] = HC3_Functions::removeFromArray( $params['calendar'], 'x' );
543
544 $this->request
545 ->setParam('employee', $params['employee'])
546 ->setParam('calendar', $params['calendar'])
547 ;
548
549 HC3_Session::instance()
550 ->setUserdata( 'scheduleViewType', $params['type'] )
551 ->setUserdata( 'scheduleViewGroupby', $params['groupby'] )
552 ->setUserdata( 'scheduleViewEmployee', $params['employee'] )
553 ->setUserdata( 'scheduleViewCalendar', $params['calendar'] )
554 ;
555
556 $toParams = $this->request->getParams('withoutdefault');
557 $scheduleLink = array( $slug, $toParams );
558
559 HC3_Session::instance()
560 ->setUserdata( 'scheduleLink', $scheduleLink )
561 ;
562
563 $type = $params['type'];
564 $groupby = $params['groupby'];
565
566 $hideui = $params['hideui'];
567 if( ('employee' == $groupby) && in_array('groupby-employee', $hideui) ){
568 $groupby = NULL;
569 }
570 if( ('calendar' == $groupby) && in_array('groupby-calendar', $hideui) ){
571 $groupby = NULL;
572 }
573
574 $view = NULL;
575
576 if( array_key_exists('download', $params) && $params['download'] ){
577 $view = $this->viewDownload;
578 $groupby = NULL;
579 }
580 else {
581 switch( $type ){
582 case '4weeks':
583 $view = $this->viewFourWeeks;
584 break;
585 case '2weeks':
586 $view = $this->viewTwoWeeks;
587 break;
588 case 'month':
589 $view = $this->viewMonth;
590 break;
591 case 'day':
592 $view = $this->viewDay;
593 break;
594 case 'list':
595 $view = $this->viewList;
596 break;
597 case 'report':
598 $view = $this->viewReport;
599 break;
600 default:
601 $view = $this->viewWeek;
602 break;
603 }
604 }
605
606 switch( $groupby ){
607 case 'employee':
608 $out = $view->renderByEmployee();
609 break;
610 case 'calendar':
611 $out = $view->renderByCalendar();
612 break;
613 default:
614 $out = $view->render();
615 break;
616 }
617
618 if( ! in_array($type, array('report')) ){
619 $miscOptions = $this->viewMiscOptions->options();
620 if( $this->request->isPrintView() ){
621 $miscOptions[2] = NULL;
622 $miscOptions[3] = NULL;
623 }
624
625 if( $miscOptions ){
626 $misc = $this->ui->makeGrid();
627 $misc->add( isset($miscOptions[1]) ? $miscOptions[1] : NULL, 3, 12 );
628 $misc->add( isset($miscOptions[2]) ? $miscOptions[2] : NULL, 7, 12 );
629 $misc->add( isset($miscOptions[3]) ? $miscOptions[3] : NULL, 2, 12 );
630
631 $out = $this->ui->makeList( array($misc, $out) )
632 ->gutter(3)
633 ;
634 }
635 }
636
637 $src = $this->uri->currentUrl();
638 $out = $this->ui->makeBlock( $out )
639 ->addAttr( 'id', 'sh4-shifts-calendar' )
640 ->addAttr( 'data-src', $src )
641 ;
642
643 if( $this->request->isAjax() ){
644 return $out;
645 }
646
647 if( ! $this->request->isPrintView() ){
648 $headerControl = $this->viewControlOptions->render();
649 if( $headerControl ){
650 $out = $this->ui->makeList( array($headerControl, $out) );
651 }
652 }
653 else {
654 $header = $this->viewControlOptions->render();
655 if( $header ){
656 $out = $this->ui->makeList( array($header, $out) );
657 }
658 }
659
660 if( ! in_array($type, array('report')) ){
661 if( ! $this->request->isPrintView() ){
662 $new = $this->viewNewOptions->render();
663 $out = $this->ui->makeList( array($new, $out) )
664 ->gutter(3)
665 ;
666 }
667 }
668
669 $headerDate = $this->viewControlDates->render();
670 if( $headerDate ){
671 $out = $this->ui->makeList( array($headerDate, $out) );
672 }
673
674 $modal = $this->_renderModal();
675 $out = $this->ui->makeCollection( array($out, $modal) );
676
677 $toCheck = 'myschedule';
678 if( $this->acl->check('get:' . $toCheck) ){
679 $header = "__Everyone's Schedule__";
680 $header = $this->ui->makeBlock( $header )
681 ->tag('font-size', 5)
682 ;
683
684 if( 0 ){
685 $label = '__My Schedule__';
686 $headerLink = $this->ui->makeAhref( $toCheck, $label )
687 ->tag('secondary')
688 ;
689 $header = $this->ui->makeListInline( array($header, $headerLink) );
690 }
691
692 $out = $this->ui->makeList( array($header, $out) )
693 ->gutter(3)
694 ;
695 }
696
697 // is wp?
698 if( defined('WPINC') && (! is_admin()) ){
699 $tos = $this->self->toplinks();
700 // $tos = array(
701 // array( 'admin', '__Administration__' ),
702 // array( 'user/profile', '__Profile__' ),
703 // );
704
705 $headerLinks = array();
706 foreach( $tos as $to ){
707 $checkTo = is_array( $to[0] ) ? $to[0][0] : $to[0];
708 if( ! $this->acl->check('get:' . $checkTo) ){
709 continue;
710 }
711
712 $headerLinks[] = $this->ui->makeAhref( $to[0], $to[1] )
713 ->tag('secondary')
714 ;
715 }
716
717 if( $headerLinks ){
718 $headerLinks = $this->ui->makeListInline( $headerLinks )
719 ->gutter(2)
720 ;
721 $out = $this->ui->makeList( array($headerLinks, $out) )
722 ->gutter(3)
723 ;
724 }
725 }
726
727 // add links to footer
728 if( $this->linksInFooter && $headerDate ){
729 $out = $this->ui->makeList( array($out, $headerDate) )
730 ->gutter(3)
731 ;
732 }
733
734 $this->layout
735 ->setContent( $out )
736 // ->setHeader( $this->self->header() )
737 ;
738
739 $out = $this->layout->render();
740 return $out;
741 }
742
743 public function toplinks()
744 {
745 $ret = array();
746
747 $ret['admin'] = array( 'admin', '__Administration__' );
748 $ret['user/profile'] = array( 'user/profile', '__Profile__' );
749
750 return $ret;
751 }
752
753 protected function _renderModal()
754 {
755 $modalContent = $this->ui->makeBlock( '' )
756 ->addAttr( 'id', 'sh4-shifts-details-content' )
757 ;
758 $modalCloser = $this->ui->makeAhref( '', '&times;' . ' ' . '__Close__' )
759 ->tag('padding', 2)
760 ->addAttr( 'id', 'sh4-shifts-details-closer' )
761 ->tag('border')
762 ->tag('color', 'red')
763 ->tag('font-size', 5)
764 ->addAttr('class', 'hc-closer')
765 ->addAttr('style', 'position: absolute; right: .2em; top: .2em;')
766 ;
767
768 $modal = $this->ui->makeBlock( $this->ui->makeCollection(array($modalContent, $modalCloser)) )
769 ->addAttr( 'style', 'position: relative; display: none;' )
770 ->addAttr( 'id', 'sh4-shifts-details' )
771 ->tag('border')
772 ->tag('border-color', 'gray')
773 ->tag('padding', 3)
774 ;
775
776 return $modal;
777 }
778 }