From 88134641b83c3cadd25a428d9f9819d158a64c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20H=C3=A4usler?= Date: Thu, 27 Dec 2012 18:03:58 +0100 Subject: [PATCH] made angel types usable --- includes/pages/user_shifts.php | 45 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index e8aaa4ca..fadcc905 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -286,7 +286,7 @@ function view_user_shifts() { if(in_array('user_shifts_admin', $privileges)) $types = sql_select("SELECT `id`, `name` FROM `AngelTypes` ORDER BY `AngelTypes`.`name`"); else - $types = sql_select("SELECT `AngelTypes`.`id`, `AngelTypes`.`name`, (`AngelTypes`.`restricted`=0 OR NOT `UserAngelTypes`.`confirm_user_id` IS NULL) as `enabled` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` AND `UserAngelTypes`.`user_id`=" . sql_escape($user['UID']) . ") ORDER BY `AngelTypes`.`name`"); + $types = sql_select("SELECT `AngelTypes`.`id`, `AngelTypes`.`name`, (`AngelTypes`.`restricted`=0 OR (NOT `UserAngelTypes`.`confirm_user_id` IS NULL OR `UserAngelTypes`.`id` IS NULL)) as `enabled` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` AND `UserAngelTypes`.`user_id`=" . sql_escape($user['UID']) . ") ORDER BY `AngelTypes`.`name`"); if (empty($types)) $types = sql_select("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0"); $filled = array ( @@ -412,16 +412,16 @@ function view_user_shifts() { $shifts_row .= ' [edit] [x]'; $shifts_row.= '
'; $shift_has_special_needs = 0 < sql_num_query("SELECT `id` FROM `NeededAngelTypes` WHERE `shift_id` = " . $shift['SID']); - $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name` + $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name`, `UserAngelTypes`.`user_id` FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) - LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`) + LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`AND `UserAngelTypes`.`user_id`=" . sql_escape($user['UID']) . ") WHERE "; if ($shift_has_special_needs) $query .= "`shift_id` = " . sql_escape($shift['SID']); else $query .= "`room_id` = " . sql_escape($shift['RID']); - $query .= " AND `count` > 0 AND `UserAngelTypes`.`user_id`=" . sql_escape($user['UID']) . " "; + $query .= " AND `count` > 0 "; if (!empty($_SESSION['user_shifts']['types'])) $query .= "AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") "; $query .= "ORDER BY `AngelTypes`.`name`"; @@ -451,26 +451,30 @@ function view_user_shifts() { $user_may_join_shift &= !$my_shift; // you cannot join if user is not of this angel type - $user_may_join_shift &= in_array($angeltype['id'], $_SESSION['user_shifts']['types']); + $user_may_join_shift &= isset($angeltype['user_id']); + + // you cannot join if you are not confirmed + if($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) + $user_may_join_shift &= isset($angeltype['confirm_user_id']); // you can only join if the shift is in future or running $user_may_join_shift &= time() < $shift['end']; // User shift admins may join anybody in every shift $user_may_join_shift |= in_array('user_shifts_admin', $privileges); - if ($user_may_join_shift) $entry_list[] = '' . $inner_text . ' »'; else { - if(!in_array('user_shifts_admin', $privileges) && $angeltype['restricted'] == 1 && !isset($angeltype['confirm_user_id'])) { + if(time() > $shift['end']) { + $entry_list[] = $inner_text . ' (vorbei)'; + } elseif($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && !isset($angeltype['confirm_user_id'])) { $entry_list[] = $inner_text . ' unconfirmed'; - } elseif(time() < $shift['end']) { - $entry_list[] = $inner_text . ' (Werde ' . $angeltype['name'] .')'; } else { - $entry_list[] = $inner_text; + $entry_list[] = $inner_text . ' (Werde ' . $angeltype['name'] .')'; } } + unset($inner_text); $is_free = true; } @@ -528,16 +532,16 @@ function view_user_shifts() { $shift_row['entries'] .= '
'; $is_free = false; $shift_has_special_needs = 0 < sql_num_query("SELECT `id` FROM `NeededAngelTypes` WHERE `shift_id` = " . $shift['SID']); - $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name` + $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name`, `UserAngelTypes`.`user_id` FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) - LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`) + LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`AND `UserAngelTypes`.`user_id`=" . sql_escape($user['UID']) . ") WHERE "; if ($shift_has_special_needs) $query .= "`shift_id` = " . sql_escape($shift['SID']); else $query .= "`room_id` = " . sql_escape($shift['RID']); - $query .= " AND `count` > 0 AND `UserAngelTypes`.`user_id`=" . sql_escape($user['UID']) . " "; + $query .= " AND `count` > 0 "; if (!empty($_SESSION['user_shifts']['types'])) $query .= "AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") "; $query .= "ORDER BY `AngelTypes`.`name`"; @@ -563,23 +567,26 @@ function view_user_shifts() { $user_may_join_shift &= !$my_shift; // you cannot join if user is not of this angel type - $user_may_join_shift &= in_array($angeltype['id'], $_SESSION['user_shifts']['types']); + $user_may_join_shift &= isset($angeltype['user_id']); + + // you cannot join if you are not confirmed + if($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) + $user_may_join_shift &= isset($angeltype['confirm_user_id']); // you can only join if the shift is in future or running $user_may_join_shift &= time() < $shift['end']; // User shift admins may join anybody in every shift $user_may_join_shift |= in_array('user_shifts_admin', $privileges); - if ($user_may_join_shift) $entry_list[] = '' . $inner_text . ' »'; else { - if(!in_array('user_shifts_admin', $privileges) && $angeltype['restricted'] == 1 && !isset($angeltype['confirm_user_id'])) { + if(time() > $shift['end']) { + $entry_list[] = $inner_text . ' (vorbei)'; + } elseif($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && !isset($angeltype['confirm_user_id'])) { $entry_list[] = $inner_text . ' unconfirmed'; - } elseif(time() < $shift['end']) { - $entry_list[] = $inner_text . ' (Werde ' . $angeltype['name'] .')'; } else { - $entry_list[] = $inner_text; + $entry_list[] = $inner_text . ' (Werde ' . $angeltype['name'] .')'; } }