diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 7cb28cfe..d065709c 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -210,95 +210,129 @@ function user_shifts() { 'comment' => "" )); } else { - $shifts = sql_select("SELECT COUNT(*) AS `count` FROM `Shifts` ORDER BY `start`"); - $days = array (); - $rooms = array (); + $days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) AS `id`, DATE(FROM_UNIXTIME(`start`)) AS `name` FROM `Shifts`"); + $rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`"); + $types = sql_select("SELECT `id`, `name` FROM `AngelTypes`"); + $filled = array(array('id' => '1', 'name' => 'Volle'), array('id' => '0', 'name' => 'Freie')); + if (!isset ($_SESSION['user_shifts'])) $_SESSION['user_shifts'] = array (); - if ($shifts[0]["count"] > 0) { - $days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) FROM `Shifts`"); - $days = array_map('array_pop', $days); - if (!isset ($_SESSION['user_shifts']['day'])) - $_SESSION['user_shifts']['day'] = $days[0]; - if (isset ($_REQUEST['day'])) - $_SESSION['user_shifts']['day'] = $_REQUEST['day']; + if (!isset ($_SESSION['user_shifts']['filled'])) { + $_SESSION['user_shifts']['filled'] = array (0); + } - $rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`"); - if (!isset ($_SESSION['user_shifts']['id'])) - $_SESSION['user_shifts']['id'] = 0; - if (isset ($_REQUEST['room_id']) && preg_match("/^[0-9]*$/", $_REQUEST['room_id'])) - $_SESSION['user_shifts']['id'] = $_REQUEST['room_id']; - $day_timestamp = DateTime :: createFromFormat("Y-m-d-Hi", $_SESSION['user_shifts']['day'] . "-0000")->getTimestamp(); + foreach(array('rooms', 'types', 'filled') as $key) { + if (isset ($_REQUEST[$key])) { + $filtered = array_filter($_REQUEST[$key], 'is_numeric'); + if (!empty($filtered)) + $_SESSION['user_shifts'][$key] = $filtered; + unset($filtered); + } + if (!isset ($_SESSION['user_shifts'][$key])) + $_SESSION['user_shifts'][$key] = array_map('get_ids_from_array', $$key); + } - if ($_SESSION['user_shifts']['id'] == 0) - $shifts = sql_select("SELECT * FROM `Shifts` JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `start` > " . sql_escape(time()) . " ORDER BY `start`"); + if (isset($_REQUEST['days'])) { + $filtered = array_filter($_REQUEST['days'], create_function('$a', 'return preg_match("/^\d\d\d\d-\d\d-\d\d\\$/", $a);')); + if (!empty($filtered)) + $_SESSION['user_shifts']['days'] = $filtered; + unset($filtered); + } + if (!isset ($_SESSION['user_shifts']['days'])) + $_SESSION['user_shifts']['days'] = array(date('Y-m-d')); + + $shifts = sql_select("SELECT * FROM `Shifts` + WHERE `RID` IN (" . implode(',', $_SESSION['user_shifts']['rooms']) . ") + AND DATE(FROM_UNIXTIME(`start`)) IN ('" . implode("','", $_SESSION['user_shifts']['days']) . "') + ORDER BY `start` + "); + + $shifts_table = ""; + $row_count = 0; + foreach ($shifts as $shift) { + $shift_row = '' . date(($_SESSION['user_shifts']['id'] == 0 ? "Y-m-d " : "") . "H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ($_SESSION['user_shifts']['id'] == 0 ? "
" . $shift['Name'] : "") . '' . $shift['name']; + if (in_array('admin_shifts', $privileges)) + $shift_row .= ' [edit] [x]'; + $shift_row .= '
'; + $is_free = false; + $shift_has_special_needs = 0 < sql_num_query("SELECT `id` FROM `NeededAngelTypes` WHERE `shift_id` = " . $shift['SID']); + $query = "SELECT * + FROM `NeededAngelTypes` + JOIN `AngelTypes` + ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) + WHERE "; + if($shift_has_special_needs) + $query .= "`shift_id` = " . sql_escape($shift['SID']); else - $shifts = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($_SESSION['user_shifts']['id']) . " AND `start` >= " . sql_escape($day_timestamp) . " AND `start` < " . sql_escape($day_timestamp +24 * 60 * 60) . " ORDER BY `start`"); + $query .= "`room_id` = " . sql_escape($shift['RID']); + $query .= " AND `count` > 0 + AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") + ORDER BY `AngelTypes`.`name`"; + $angeltypes = sql_select($query); - $shifts_table = ""; - $row_count = 0; - foreach ($shifts as $shift) { - $shift_row = '' . date(($_SESSION['user_shifts']['id'] == 0 ? "Y-m-d " : "") . "H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ($_SESSION['user_shifts']['id'] == 0 ? "
" . $shift['Name'] : "") . '' . $shift['name']; - if (in_array('admin_shifts', $privileges)) - $shift_row .= ' [edit] [x]'; - $shift_row .= '
'; - $show_shift = false; - $angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) WHERE `shift_id`=" . sql_escape($shift['SID']) . " AND `count` > 0 ORDER BY `AngelTypes`.`name`"); - if (count($angeltypes) == 0) - $angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) WHERE `room_id`=" . sql_escape($shift['RID']) . " AND `count` > 0 ORDER BY `AngelTypes`.`name`"); - - 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 (); - foreach ($entries as $entry) { - if (in_array('user_shifts_admin', $privileges)) - $entry_list[] = '' . $entry['Nick'] . ' [x]'; - else - $entry_list[] = $entry['Nick']; - } - if ($angeltype['count'] - count($entries) > 0) - if (!$my_shift || in_array('user_shifts_admin', $privileges)) { - $entry_list[] = '' . ($angeltype['count'] - count($entries)) . ' Helfer' . ($angeltype['count'] - count($entries) != 1 ? '' : '') . ' gebraucht »'; - $show_shift = true; - } else - $entry_list[] = ($angeltype['count'] - count($entries)) . ' Helfer gebraucht'; - - $shift_row .= '' . $angeltype['name'] . ': '; - $shift_row .= join(", ", $entry_list); - $shift_row .= '
'; + 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 (); + foreach ($entries as $entry) { + if (in_array('user_shifts_admin', $privileges)) + $entry_list[] = '' . $entry['Nick'] . ' [x]'; + else + $entry_list[] = $entry['Nick']; } + if ($angeltype['count'] - count($entries) > 0) { + if (!$my_shift || in_array('user_shifts_admin', $privileges)) { + $entry_list[] = '' . ($angeltype['count'] - count($entries)) . ' Helfer' . ($angeltype['count'] - count($entries) != 1 ? '' : '') . ' gebraucht »'; + } else { + $entry_list[] = ($angeltype['count'] - count($entries)) . ' Helfer gebraucht'; + } + $is_free = true; + } + + $shift_row .= '' . $angeltype['name'] . ': '; + $shift_row .= join(", ", $entry_list); + $shift_row .= '
'; } - if ($_SESSION['user_shifts']['id'] != 0 || ($show_shift && $row_count++ < 15)) + if (($is_free && in_array(0, $_SESSION['user_shifts']['filled'])) + || (!$is_free && in_array(1, $_SESSION['user_shifts']['filled']))) { $shifts_table .= $shift_row . ''; + $row_count++; + } } } return template_render('../templates/user_shifts.html', array ( - 'room_select' => make_room_select($rooms, $_SESSION['user_shifts']['id'], $_SESSION['user_shifts']['day']), - 'day_select' => make_day_select($days, $_SESSION['user_shifts']['day'], $_SESSION['user_shifts']['id']), + 'room_select' => make_select($rooms, $_SESSION['user_shifts']['rooms'], "rooms", "Räume"), + 'day_select' => make_select($days, $_SESSION['user_shifts']['days'], "days", "Tage"), + 'type_select' => make_select($types, $_SESSION['user_shifts']['types'], "types", "Aufgaben"), + 'filled_select' => make_select($filled, $_SESSION['user_shifts']['filled'], "filled", "Besetzung"), 'shifts_table' => $shifts_table )); } } -function make_day_select($days, $day, $id) { - if ($id == 0) - return ""; - $html = array (); - foreach ($days as $d) - $html[] = button(page_link_to('user_shifts') . '&day=' . $d, $d, $day == $d && $id != 0 ? 'on' : ''); - return buttons($html); +function get_ids_from_array($array) { + return $array["id"]; } -function make_room_select($rooms, $id, $day) { - $html = array (); - foreach ($rooms as $room) { - $html[] = button(page_link_to('user_shifts') . '&room_id=' . $room['RID'], $room['Name'], $room['RID'] == $id ? 'on' : ''); - } - $html[] = button(page_link_to('user_shifts') . '&room_id=0', "Next free shifts.", $id == 0 ? 'on' : ''); - return buttons($html); +function make_select($items, $selected, $name, $title = null) { + $html_items = array (); + if(isset($title)) + $html_items[] = '
  • ' . $title . '
  • ' . "\n"; + + foreach ($items as $i) + $html_items[] = '
  • '; + $html = '
    ' . "\n"; + $html .= '' . "\n"; + $html .= buttons(array( + button("javascript: check_all('selection_" . $name . "')", "Alle", ""), + button("javascript: uncheck_all('selection_" . $name . "')", "Keine", "") + )); + $html .= '
    ' . "\n"; + return $html; } ?> diff --git a/public/css/base.css b/public/css/base.css index 6fe914c4..30227ce5 100644 --- a/public/css/base.css +++ b/public/css/base.css @@ -351,3 +351,21 @@ tr:hover .hidden { .form ul { list-style: none; } + +.selection ul { + list-style: none; + padding: 0; +} + +.selection.rooms, +.selection.days, +.selection.types, +.selection.filled { + display: inline-block; + vertical-align: top; + margin-right: 15px; +} + +#filter { + padding: 10px; +} diff --git a/public/css/forms.js b/public/css/forms.js new file mode 100644 index 00000000..8a6e2c69 --- /dev/null +++ b/public/css/forms.js @@ -0,0 +1,17 @@ +function check_all(id) { + var obj = document.getElementById(id); + var boxes = obj.getElementsByTagName("input"); + for(var i = 0; i < boxes.length; i++) { + if(boxes[i].type == "checkbox") + boxes[i].checked = true; + } +} + +function uncheck_all(id) { + var obj = document.getElementById(id); + var boxes = obj.getElementsByTagName("input"); + for(var i = 0; i < boxes.length; i++) { + if(boxes[i].type == "checkbox") + boxes[i].checked = false; + } +} diff --git a/public/css/style11.css b/public/css/style11.css index b983d632..86720e6a 100644 --- a/public/css/style11.css +++ b/public/css/style11.css @@ -8,4 +8,13 @@ tr:hover > td { background: #f0f0f0; -} \ No newline at end of file +} + +.selection ul li.heading { + text-align: center; + font-weight: bold; +} + +.selection ul li:nth-child(even) { + background: #f0f0f0; +} diff --git a/templates/layout.html b/templates/layout.html index bcff1fe3..6865bfcd 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -10,7 +10,8 @@ - + diff --git a/templates/user_shifts.html b/templates/user_shifts.html index 99d62ea0..84bc34c6 100644 --- a/templates/user_shifts.html +++ b/templates/user_shifts.html @@ -1,5 +1,14 @@ +
    +
    Filter + %room_select% +%type_select% %day_select% +%filled_select% + +
    +
    +