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