|
|
@ -210,31 +210,43 @@ function user_shifts() {
|
|
|
|
'comment' => ""
|
|
|
|
'comment' => ""
|
|
|
|
));
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$shifts = sql_select("SELECT COUNT(*) AS `count` FROM `Shifts` ORDER BY `start`");
|
|
|
|
$days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) AS `id`, DATE(FROM_UNIXTIME(`start`)) AS `name` FROM `Shifts`");
|
|
|
|
$days = array ();
|
|
|
|
$rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
|
|
|
$rooms = array ();
|
|
|
|
$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']))
|
|
|
|
if (!isset ($_SESSION['user_shifts']))
|
|
|
|
$_SESSION['user_shifts'] = array ();
|
|
|
|
$_SESSION['user_shifts'] = array ();
|
|
|
|
|
|
|
|
|
|
|
|
if ($shifts[0]["count"] > 0) {
|
|
|
|
if (!isset ($_SESSION['user_shifts']['filled'])) {
|
|
|
|
$days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) FROM `Shifts`");
|
|
|
|
$_SESSION['user_shifts']['filled'] = array (0);
|
|
|
|
$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'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
|
|
|
foreach(array('rooms', 'types', 'filled') as $key) {
|
|
|
|
if (!isset ($_SESSION['user_shifts']['id']))
|
|
|
|
if (isset ($_REQUEST[$key])) {
|
|
|
|
$_SESSION['user_shifts']['id'] = 0;
|
|
|
|
$filtered = array_filter($_REQUEST[$key], 'is_numeric');
|
|
|
|
if (isset ($_REQUEST['room_id']) && preg_match("/^[0-9]*$/", $_REQUEST['room_id']))
|
|
|
|
if (!empty($filtered))
|
|
|
|
$_SESSION['user_shifts']['id'] = $_REQUEST['room_id'];
|
|
|
|
$_SESSION['user_shifts'][$key] = $filtered;
|
|
|
|
$day_timestamp = DateTime :: createFromFormat("Y-m-d-Hi", $_SESSION['user_shifts']['day'] . "-0000")->getTimestamp();
|
|
|
|
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)
|
|
|
|
if (isset($_REQUEST['days'])) {
|
|
|
|
$shifts = sql_select("SELECT * FROM `Shifts` JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `start` > " . sql_escape(time()) . " ORDER BY `start`");
|
|
|
|
$filtered = array_filter($_REQUEST['days'], create_function('$a', 'return preg_match("/^\d\d\d\d-\d\d-\d\d\\$/", $a);'));
|
|
|
|
else
|
|
|
|
if (!empty($filtered))
|
|
|
|
$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`");
|
|
|
|
$_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 = "";
|
|
|
|
$shifts_table = "";
|
|
|
|
$row_count = 0;
|
|
|
|
$row_count = 0;
|
|
|
@ -243,10 +255,21 @@ function user_shifts() {
|
|
|
|
if (in_array('admin_shifts', $privileges))
|
|
|
|
if (in_array('admin_shifts', $privileges))
|
|
|
|
$shift_row .= ' <a href="?p=user_shifts&edit_shift=' . $shift['SID'] . '">[edit]</a> <a href="?p=user_shifts&delete_shift=' . $shift['SID'] . '">[x]</a>';
|
|
|
|
$shift_row .= ' <a href="?p=user_shifts&edit_shift=' . $shift['SID'] . '">[edit]</a> <a href="?p=user_shifts&delete_shift=' . $shift['SID'] . '">[x]</a>';
|
|
|
|
$shift_row .= '<br />';
|
|
|
|
$shift_row .= '<br />';
|
|
|
|
$show_shift = false;
|
|
|
|
$is_free = 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`");
|
|
|
|
$shift_has_special_needs = 0 < sql_num_query("SELECT `id` FROM `NeededAngelTypes` WHERE `shift_id` = " . $shift['SID']);
|
|
|
|
if (count($angeltypes) == 0)
|
|
|
|
$query = "SELECT *
|
|
|
|
$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`");
|
|
|
|
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
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
|
|
if (count($angeltypes) > 0) {
|
|
|
|
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;
|
|
|
|
$my_shift = sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`=" . sql_escape($shift['SID']) . " AND `UID`=" . sql_escape($user['UID']) . " LIMIT 1") > 0;
|
|
|
@ -259,46 +282,57 @@ function user_shifts() {
|
|
|
|
else
|
|
|
|
else
|
|
|
|
$entry_list[] = $entry['Nick'];
|
|
|
|
$entry_list[] = $entry['Nick'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($angeltype['count'] - count($entries) > 0)
|
|
|
|
if ($angeltype['count'] - count($entries) > 0) {
|
|
|
|
if (!$my_shift || in_array('user_shifts_admin', $privileges)) {
|
|
|
|
if (!$my_shift || in_array('user_shifts_admin', $privileges)) {
|
|
|
|
$entry_list[] = '<a href="' . page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'] . '">' . ($angeltype['count'] - count($entries)) . ' Helfer' . ($angeltype['count'] - count($entries) != 1 ? '' : '') . ' gebraucht »</a>';
|
|
|
|
$entry_list[] = '<a href="' . page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'] . '">' . ($angeltype['count'] - count($entries)) . ' Helfer' . ($angeltype['count'] - count($entries) != 1 ? '' : '') . ' gebraucht »</a>';
|
|
|
|
$show_shift = true;
|
|
|
|
} else {
|
|
|
|
} else
|
|
|
|
|
|
|
|
$entry_list[] = ($angeltype['count'] - count($entries)) . ' Helfer gebraucht';
|
|
|
|
$entry_list[] = ($angeltype['count'] - count($entries)) . ' Helfer gebraucht';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_free = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$shift_row .= '<b>' . $angeltype['name'] . ':</b> ';
|
|
|
|
$shift_row .= '<b>' . $angeltype['name'] . ':</b> ';
|
|
|
|
$shift_row .= join(", ", $entry_list);
|
|
|
|
$shift_row .= join(", ", $entry_list);
|
|
|
|
$shift_row .= '<br />';
|
|
|
|
$shift_row .= '<br />';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (($is_free && in_array(0, $_SESSION['user_shifts']['filled']))
|
|
|
|
if ($_SESSION['user_shifts']['id'] != 0 || ($show_shift && $row_count++ < 15))
|
|
|
|
|| (!$is_free && in_array(1, $_SESSION['user_shifts']['filled']))) {
|
|
|
|
$shifts_table .= $shift_row . '</td></tr>';
|
|
|
|
$shifts_table .= $shift_row . '</td></tr>';
|
|
|
|
|
|
|
|
$row_count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return template_render('../templates/user_shifts.html', array (
|
|
|
|
return template_render('../templates/user_shifts.html', array (
|
|
|
|
'room_select' => make_room_select($rooms, $_SESSION['user_shifts']['id'], $_SESSION['user_shifts']['day']),
|
|
|
|
'room_select' => make_select($rooms, $_SESSION['user_shifts']['rooms'], "rooms", "Räume"),
|
|
|
|
'day_select' => make_day_select($days, $_SESSION['user_shifts']['day'], $_SESSION['user_shifts']['id']),
|
|
|
|
'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
|
|
|
|
'shifts_table' => $shifts_table
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function make_day_select($days, $day, $id) {
|
|
|
|
function get_ids_from_array($array) {
|
|
|
|
if ($id == 0)
|
|
|
|
return $array["id"];
|
|
|
|
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 make_room_select($rooms, $id, $day) {
|
|
|
|
function make_select($items, $selected, $name, $title = null) {
|
|
|
|
$html = array ();
|
|
|
|
$html_items = array ();
|
|
|
|
foreach ($rooms as $room) {
|
|
|
|
if(isset($title))
|
|
|
|
$html[] = button(page_link_to('user_shifts') . '&room_id=' . $room['RID'], $room['Name'], $room['RID'] == $id ? 'on' : '');
|
|
|
|
$html_items[] = '<li class="heading">' . $title . '</li>' . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html[] = button(page_link_to('user_shifts') . '&room_id=0', "Next free shifts.", $id == 0 ? 'on' : '');
|
|
|
|
foreach ($items as $i)
|
|
|
|
return buttons($html);
|
|
|
|
$html_items[] = '<li><label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '"' . (in_array($i['id'], $selected)? ' checked="checked"' : '') . '> ' . $i['name'] . '</label></li>';
|
|
|
|
|
|
|
|
$html = '<div class="selection ' . $name . '">' . "\n";
|
|
|
|
|
|
|
|
$html .= '<ul id="selection_' . $name . '">' . "\n";
|
|
|
|
|
|
|
|
$html .= implode("\n", $html_items);
|
|
|
|
|
|
|
|
$html .= '</ul>' . "\n";
|
|
|
|
|
|
|
|
$html .= buttons(array(
|
|
|
|
|
|
|
|
button("javascript: check_all('selection_" . $name . "')", "Alle", ""),
|
|
|
|
|
|
|
|
button("javascript: uncheck_all('selection_" . $name . "')", "Keine", "")
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
$html .= '</div>' . "\n";
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
?>
|
|
|
|