From 0dae68a9a3370fb517009f4d5aa31094851ff188 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sun, 30 Dec 2012 12:09:48 +0100 Subject: indicate colliding shifts in new shift view --- includes/pages/user_shifts.php | 79 +++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 24 deletions(-) (limited to 'includes') diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 162238e6..235208b9 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -364,6 +364,13 @@ function view_user_shifts() { $SQL .= " ORDER BY `start`"; $shifts = sql_select($SQL); + $ownshifts_source = sql_select("SELECT `Shifts`.* FROM `Shifts` INNER JOIN `ShiftEntry` ON (`Shifts`.`SID` = `ShiftEntry`.`SID` AND `ShiftEntry`.`UID` = '" . sql_escape($user['UID']) . "') + WHERE `Shifts`.`RID` IN (" . implode(',', $_SESSION['user_shifts']['rooms']) . ") + AND DATE(FROM_UNIXTIME(`start`)) IN ('" . implode("','", $_SESSION['user_shifts']['days']) . "') "); + $ownshifts = array(); + foreach ($ownshifts_source as $ownshift) + $ownshifts[$ownshift['SID']] = $ownshift; + unset($ownshifts_source); $shifts_table = ""; //qqqq @@ -383,33 +390,32 @@ function view_user_shifts() { ) */ if(count($_SESSION['user_shifts']['days'])==1 && $_SESSION['user_shifts']['new_style']) { - $myrooms = $rooms; - - // delete un-selected rooms from array - foreach($myrooms as $k => $v) - if(array_search($v["id"],$_SESSION['user_shifts']['rooms'])===FALSE) - unset($myrooms[$k]); - $first=date("U",strtotime($_SESSION['user_shifts']['days'][0]." 00:00:00")); $last=date("U",strtotime($_SESSION['user_shifts']['days'][0]." 23:59:59")); $maxshow=24*4; $block=array(); $todo=array(); + $myrooms = $rooms; - // initialize $block array - foreach($myrooms as $room) - $block[$room["id"]] = array_fill(0, $maxshow, 0); + // delete un-selected rooms from array + foreach($myrooms as $k => $v) { + if(array_search($v["id"],$_SESSION['user_shifts']['rooms'])===FALSE) + unset($myrooms[$k]); + // initialize $block array + $block[$v["id"]] = array_fill(0, $maxshow, 0); + } // calculate number of parallel shifts in each timeslot for each room - foreach($shifts as $shift) { + foreach($shifts as $k => $shift) { $rid = $shift["RID"]; $blocks = ($shift["end"]-$shift["start"]) / (15*60); $firstblock = floor(($shift["start"]-$first) / (15*60)); for($i = $firstblock; $i < $blocks + $firstblock && $i < $maxshow; $i++) $block[$rid][$i]++; + $shifts[$k]['own'] = in_array($shift['SID'], array_keys($ownshifts)); } - $shifts_table = ""; + $shifts_table = '
-
'; foreach($myrooms as $key => $room) { $rid = $room["id"]; if(array_sum($block[$rid]) == 0) { @@ -422,7 +428,7 @@ function view_user_shifts() { if($colspan == 0) $colspan = 1; $todo[$rid] = array_fill(0, $maxshow, $colspan); - $shifts_table.=" 1)? ' colspan="' . $colspan . '"' : '') . ">${room['name']}\n"; + $shifts_table .= " 1)? ' colspan="' . $colspan . '"' : '') . ">${room['name']}\n"; } unset($block, $blocks, $firstblock, $colspan, $key, $room); @@ -436,12 +442,23 @@ function view_user_shifts() { } foreach($myrooms as $room) { $rid = $room["id"]; + $empty_collides = false; foreach($shifts as $shift) { if($shift["RID"] == $rid) { if(floor($shift["start"]/(15*60)) == $thistime/(15*60)) { $blocks = ($shift["end"]-$shift["start"])/(15*60); if($blocks < 1) $blocks = 1; + + $collides = in_array($shift['SID'], array_keys($ownshifts)); + if(!$collides) + foreach ($ownshifts as $ownshift) { + if ($ownshift['start'] < $shift['end'] && $ownshift['end'] > $shift['start']) { + $collides = true; + break; + } + } + // qqqqqq $is_free = false; $shifts_row = $shift['name']; @@ -465,7 +482,6 @@ function view_user_shifts() { $angeltypes = sql_select($query); if (count($angeltypes) > 0) { - $my_shift = sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`=" . sql_escape($shift['SID']) . " AND `UID`=" . sql_escape($user['UID']) . " LIMIT 1") > 0; foreach ($angeltypes as $angeltype) { $entries = sql_select("SELECT * FROM `ShiftEntry` JOIN `User` ON (`ShiftEntry`.`UID` = `User`.`UID`) WHERE `SID`=" . sql_escape($shift['SID']) . " AND `TID`=" . sql_escape($angeltype['id']) . " ORDER BY `Nick`"); $entry_list = array (); @@ -484,8 +500,8 @@ function view_user_shifts() { // is the shift still running or alternatively is the user shift admin? $user_may_join_shift = true; - // you cannot join if user already joined this shift - $user_may_join_shift &= !$my_shift; + // you cannot join if user alread joined a parallel or this shift + $user_may_join_shift &= !$collides; // you cannot join if user is not of this angel type $user_may_join_shift &= isset($angeltype['user_id']); @@ -502,13 +518,14 @@ function view_user_shifts() { if ($user_may_join_shift) $entry_list[] = '' . $inner_text . ' »'; else { - if(time() > $shift['start']) { + if(time() > $shift['start']) $entry_list[] = $inner_text . ' (vorbei)'; - } elseif($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && !isset($angeltype['confirm_user_id'])) { + elseif($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && !isset($angeltype['confirm_user_id'])) $entry_list[] = $inner_text . ' unconfirmed'; - } else { + elseif($collides) + $entry_list[] = $inner_text; + else $entry_list[] = $inner_text . ' (Werde ' . $angeltype['name'] .')'; - } } unset($inner_text); @@ -523,9 +540,17 @@ function view_user_shifts() { $shifts_row .= 'Weitere Helfer eintragen »'; } } - $shifts_table.='"; for($j=0; $j < $blocks && $i+$j < $maxshow; $j++) { @@ -533,14 +558,20 @@ function view_user_shifts() { } } } + if ($shift['own'] && !in_array('admin_shifts', $privileges)) { + $blocks = ($shift["end"]-$shift["start"]) / (15*60); + $firstblock = floor(($shift["start"]-$first) / (15*60)); + if ($i >= $firstblock && $i < $firstblock + $blocks) + $empty_collides = true; + } } // fill up row with empty '; + $shifts_table .= ''; } $shifts_table .= "\n"; } - $shifts_table .= '
-'; + if ($shift['own'] && !in_array('admin_shifts', $privileges)) + $class = 'own'; + elseif ($collides && !in_array('admin_shifts', $privileges)) + $class = 'collides'; + elseif ($is_free) + $class = 'free'; + else + $class = 'occupied'; + $shifts_table.=''; if (($is_free && in_array(0, $_SESSION['user_shifts']['filled'])) || (!$is_free && in_array(1, $_SESSION['user_shifts']['filled']))) { - $shifts_table.=$shifts_row; + $shifts_table .= $shifts_row; } $shifts_table.=" while($todo[$rid][$i]-- > 0) - $shifts_table .= '
'; + $shifts_table .= ''; // qqq } else { $shifts_table = array(); -- cgit v1.2.3-54-g00ecf