add basic shift view

main
Philip Häusler 10 years ago
parent a791a75b0a
commit d02272afd6

@ -1,5 +1,66 @@
<?php <?php
function shift_link($shift) {
return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID'];
}
function shift_delete_link($shift) {
return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'];
}
function shift_edit_link($shift) {
return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'];
}
function shift_controller() {
global $user, $privileges;
if (! in_array('user_shifts', $privileges))
redirect(page_link_to('user_shifts'));
if (! isset($_REQUEST['shift_id']))
redirect(page_link_to('user_shifts'));
$shift = Shift($_REQUEST['shift_id']);
if ($shift === false)
engelsystem_error('Unable to load shift.');
if ($shift == null) {
error(_('Shift could not be found.'));
redirect(page_link_to('user_shifts'));
}
$shifttype = ShiftType($shift['shifttype_id']);
if ($shifttype === false || $shifttype == null)
engelsystem_error('Unable to load shift type.');
$room = Room($shift['RID']);
if ($room === false || $room == null)
engelsystem_error('Unable to load room.');
$angeltypes = AngelTypes();
if ($angeltypes === false)
engelsystem_error('Unable to load angeltypes.');
User_angeltypes($user);
return [
$shift['name'],
Shift_view($shift, $shifttype, $room, in_array('admin_shifts', $privileges), $angeltypes, in_array('user_shifts_admin', $privileges))
];
}
function shifts_controller() {
if (! isset($_REQUEST['action']))
redirect(page_link_to('user_shifts'));
switch ($_REQUEST['action']) {
default:
redirect(page_link_to('?'));
case 'view':
return shift_controller();
}
}
/** /**
* Export all shifts using api-key. * Export all shifts using api-key.
*/ */

@ -71,7 +71,7 @@ function Shift_create($shift) {
*/ */
function Shifts_by_user($user) { function Shifts_by_user($user) {
return sql_select(" return sql_select("
SELECT * SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.*, `Shifts`.*, `Room`.*
FROM `ShiftEntry` FROM `ShiftEntry`
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
@ -138,7 +138,7 @@ function Shift($id) {
FROM `Shifts` FROM `Shifts`
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
WHERE `SID`=" . sql_escape($id)); WHERE `SID`=" . sql_escape($id));
$shiftsEntry_source = sql_select("SELECT `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`=" . sql_escape($id)); $shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`=" . sql_escape($id));
if ($shifts_source === false) if ($shifts_source === false)
return false; return false;

@ -48,10 +48,6 @@ function user_shifts() {
else else
redirect(page_link_to('user_shifts')); redirect(page_link_to('user_shifts'));
/*
* if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`=" . sql_escape($shift_id) . " LIMIT 1") > 0) { error("Du kannst nur Schichten bearbeiten, bei denen niemand eingetragen ist."); redirect(page_link_to('user_shift')); }
*/
$shift = sql_select(" $shift = sql_select("
SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.* FROM `Shifts` SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.* FROM `Shifts`
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
@ -153,7 +149,7 @@ function user_shifts() {
engelsystem_log("Updated shift '" . $name . "' from " . date("y-m-d H:i", $start) . " to " . date("y-m-d H:i", $end) . " with angel types " . join(", ", $needed_angel_types_info)); engelsystem_log("Updated shift '" . $name . "' from " . date("y-m-d H:i", $start) . " to " . date("y-m-d H:i", $end) . " with angel types " . join(", ", $needed_angel_types_info));
success(_("Shift updated.")); success(_("Shift updated."));
redirect(page_link_to('user_shifts')); redirect(shift_link($shift_id));
} }
} }
@ -232,7 +228,7 @@ function user_shifts() {
// Schicht läuft schon, Eintragen für Engel nicht mehr möglich // Schicht läuft schon, Eintragen für Engel nicht mehr möglich
if (! in_array('user_shifts_admin', $privileges) && time() > $shift['start']) { if (! in_array('user_shifts_admin', $privileges) && time() > $shift['start']) {
error(_("This shift is running now or ended already. Please contact a dispatcher to join the shift.")); error(_("This shift is running now or ended already. Please contact a dispatcher to join the shift."));
redirect(page_link_to('user_shifts')); redirect(shift_link($shift));
} }
// Another shift the user is signed up for collides with this one // Another shift the user is signed up for collides with this one
@ -242,7 +238,7 @@ function user_shifts() {
INNER JOIN `ShiftEntry` ON (`Shifts`.`SID` = `ShiftEntry`.`SID` AND `ShiftEntry`.`UID` = " . sql_escape($user['UID']) . ") INNER JOIN `ShiftEntry` ON (`Shifts`.`SID` = `ShiftEntry`.`SID` AND `ShiftEntry`.`UID` = " . sql_escape($user['UID']) . ")
WHERE `start` < '" . sql_escape($shift['end']) . "' AND `end` > '" . sql_escape($shift['start']) . "'") > 0) { WHERE `start` < '" . sql_escape($shift['end']) . "' AND `end` > '" . sql_escape($shift['start']) . "'") > 0) {
error(_("You already subscribed to shift in the same timeslot. Please contact a dispatcher to join the shift.")); error(_("You already subscribed to shift in the same timeslot. Please contact a dispatcher to join the shift."));
redirect(page_link_to('user_shifts')); redirect(shift_link($shift));
} }
if (in_array('user_shifts_admin', $privileges)) if (in_array('user_shifts_admin', $privileges))
@ -298,7 +294,7 @@ function user_shifts() {
$user_source = User($user_id); $user_source = User($user_id);
engelsystem_log("User " . User_Nick_render($user_source) . " signed up for shift " . $shift['name'] . " from " . date("y-m-d H:i", $shift['start']) . " to " . date("y-m-d H:i", $shift['end'])); engelsystem_log("User " . User_Nick_render($user_source) . " signed up for shift " . $shift['name'] . " from " . date("y-m-d H:i", $shift['start']) . " to " . date("y-m-d H:i", $shift['end']));
success(_("You are subscribed. Thank you!") . ' <a href="' . page_link_to('user_myshifts') . '">' . _("My shifts") . ' &raquo;</a>'); success(_("You are subscribed. Thank you!") . ' <a href="' . page_link_to('user_myshifts') . '">' . _("My shifts") . ' &raquo;</a>');
redirect(page_link_to('user_shifts')); redirect(shift_link($shift));
} }
if (in_array('user_shifts_admin', $privileges)) { if (in_array('user_shifts_admin', $privileges)) {
@ -524,8 +520,7 @@ function view_user_shifts() {
if ($thistime % (24 * 60 * 60) == 23 * 60 * 60 && $endtime - $starttime > 24 * 60 * 60) { if ($thistime % (24 * 60 * 60) == 23 * 60 * 60 && $endtime - $starttime > 24 * 60 * 60) {
$shifts_table .= "<tr class=\"row-day\"><th class=\"row-header\">"; $shifts_table .= "<tr class=\"row-day\"><th class=\"row-header\">";
$shifts_table .= date('y-m-d<b\r />H:i', $thistime); $shifts_table .= date('y-m-d<b\r />H:i', $thistime);
} } elseif ($thistime % (60 * 60) == 0) {
elseif ($thistime % (60 * 60) == 0) {
$shifts_table .= "<tr class=\"row-hour\"><th>"; $shifts_table .= "<tr class=\"row-hour\"><th>";
$shifts_table .= date("H:i", $thistime); $shifts_table .= date("H:i", $thistime);
} else { } else {
@ -544,10 +539,7 @@ function view_user_shifts() {
$collides = in_array($shift['SID'], array_keys($ownshifts)); $collides = in_array($shift['SID'], array_keys($ownshifts));
if (! $collides) if (! $collides)
foreach ($ownshifts as $ownshift) { foreach ($ownshifts as $ownshift) {
if ($ownshift['start'] >= $shift['start'] && $ownshift['start'] < $shift['end'] || if ($ownshift['start'] >= $shift['start'] && $ownshift['start'] < $shift['end'] || $ownshift['end'] > $shift['start'] && $ownshift['end'] <= $shift['end'] || $ownshift['start'] < $shift['start'] && $ownshift['end'] > $shift['end']) {
$ownshift['end'] > $shift['start'] && $ownshift['end'] <= $shift['end'] ||
$ownshift['start'] < $shift['start'] && $ownshift['end'] > $shift['end'])
{
$collides = true; $collides = true;
break; break;
} }
@ -555,7 +547,7 @@ function view_user_shifts() {
// qqqqqq // qqqqqq
$is_free = false; $is_free = false;
$shifts_row = $shift['name']; $shifts_row = '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>';
if (in_array('admin_shifts', $privileges)) if (in_array('admin_shifts', $privileges))
$shifts_row .= ' ' . table_buttons(array( $shifts_row .= ' ' . table_buttons(array(
button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),

@ -14,7 +14,7 @@ function page_link_to_absolute($page) {
* Renders the header toolbar containing search, login/logout, user and settings links. * Renders the header toolbar containing search, login/logout, user and settings links.
*/ */
function header_toolbar() { function header_toolbar() {
global $p, $privileges, $user, $enable_tshirt_size; global $p, $privileges, $user, $enable_tshirt_size, $max_freeloadable_shifts;
$toolbar_items = array(); $toolbar_items = array();

@ -9,6 +9,10 @@ $themes = array(
"2" => "Engelsystem 31c3" "2" => "Engelsystem 31c3"
); );
function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '') {
return '<div class="progress"><div class="progress-bar ' . $class . '" role="progressbar" aria-valuenow="' . $valuenow . '" aria-valuemin="' . $valuemin . '" aria-valuemax="' . $valuemax . '" style="width: ' . (($valuenow - $valuemin) * 100 / ($valuemax - $valuemin)) . '%">' . $content . '</div></div>';
}
/** /**
* Render glyphicon * Render glyphicon
* *

@ -1,6 +1,93 @@
<?php <?php
function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $user_shift_admin) {
$parsedown = new Parsedown();
$angeltypes = [];
foreach ($angeltypes_source as $angeltype)
$angeltypes[$angeltype['id']] = $angeltype;
$needed_angels = '';
foreach ($shift['NeedAngels'] as $needed_angeltype) {
$class = 'progress-bar-warning';
if ($needed_angeltype['taken'] == 0)
$class = 'progress-bar-danger';
if ($needed_angeltype['taken'] >= $needed_angeltype['count'])
$class = 'progress-bar-success';
$needed_angels .= '<div class="list-group-item">';
$needed_angels .= '<div class="pull-right">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $needed_angeltype['TID'], _('Sign up')) . '</div>';
$needed_angels .= '<h3>' . $angeltypes[$needed_angeltype['TID']]['name'] . '</h3>';
$needed_angels .= progress_bar(0, $needed_angeltype['count'], $needed_angeltype['taken'], $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']);
$angels = [];
foreach ($shift['ShiftEntry'] as $shift_entry) {
if ($shift_entry['TID'] == $needed_angeltype['TID']) {
$entry = User_Nick_render(User($shift_entry['UID']));
if ($shift_entry['freeloaded'])
$entry = '<strike>' . $entry . '</strike>';
if ($user_shift_admin) {
$entry .= ' <div class="btn-group">';
$entry .= button_glyph(page_link_to('user_myshifts') . '&edit=' . $shift['SID'] . '&id=' . $shift_entry['UID'], 'pencil', 'btn-xs');
$entry .= button_glyph(page_link_to('user_shifts') . '&entry_id=' . $shift_entry['id'], 'trash', 'btn-xs');
$entry .= '</div>';
}
$angels[] = $entry;
}
}
$needed_angels .= join(', ', $angels);
$needed_angels .= '</div>';
}
return page_with_title($shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
msg(),
$shift_admin ? buttons([
button(shift_edit_link($shift), glyph('pencil') . _('edit')),
button(shift_delete_link($shift), glyph('trash') . _('delete'))
]) : '',
div('row', [
div('col-sm-3', [
'<h4>' . _('Start') . '</h4>',
'<p class="lead">',
date('y-m-d', $shift['start']),
'<br />',
date('H:i', $shift['start']),
'</p>'
]),
div('col-sm-3', [
'<h4>' . _('End') . '</h4>',
'<p class="lead">',
date('y-m-d', $shift['end']),
'<br />',
date('H:i', $shift['end']),
'</p>'
]),
div('col-sm-3', [
'<h4>' . _('Location') . '</h4>',
'<p class="lead">' . $room['Name'] . '</p>'
]),
div('col-sm-3', [
'<h4>' . _('More info') . '</h4>',
$shift['URL'] != '' ? '<a href="' . $shift['URL'] . '">' . $shift['URL'] . '</a>' : ''
])
]),
div('row', [
div('col-sm-6', [
'<h2>' . _('Needed angels') . '</h2>',
'<div class="list-group">' . $needed_angels . '</div>'
]),
div('col-sm-6', [
'<h2>' . _('Description') . '</h2>',
$parsedown->parse($shifttype['description'])
])
])
]);
}
/** /**
* Calc shift length in format 12:23h. * Calc shift length in format 12:23h.
*
* @param Shift $shift * @param Shift $shift
*/ */
function shift_length($shift) { function shift_length($shift) {

@ -98,7 +98,7 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
$html = ""; $html = "";
$timesum = 0; $timesum = 0;
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
$shift_info = $shift['name']; $shift_info = '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>';
foreach ($shift['needed_angeltypes'] as $needed_angel_type) { foreach ($shift['needed_angeltypes'] as $needed_angel_type) {
$shift_info .= '<br><b>' . $needed_angel_type['name'] . ':</b> '; $shift_info .= '<br><b>' . $needed_angel_type['name'] . ':</b> ';
@ -131,7 +131,9 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
$myshift['comment'] .= '<br /><p class="error">' . _("Freeloaded") . '</p>'; $myshift['comment'] .= '<br /><p class="error">' . _("Freeloaded") . '</p>';
} }
$myshift['actions'] = array(); $myshift['actions'] = [
button(shift_link($shift), glyph('eye-open') . _('view'), 'btn-xs')
];
if ($its_me || in_array('user_shifts_admin', $privileges)) if ($its_me || in_array('user_shifts_admin', $privileges))
$myshift['actions'][] = button(page_link_to('user_myshifts') . '&edit=' . $shift['id'] . '&id=' . $user_source['UID'], glyph('edit') . _('edit'), 'btn-xs'); $myshift['actions'][] = button(page_link_to('user_myshifts') . '&edit=' . $shift['id'] . '&id=' . $user_source['UID'], glyph('edit') . _('edit'), 'btn-xs');
if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges))

@ -29,6 +29,7 @@ require_once realpath(__DIR__ . '/../includes/view/UserAngelTypes_view.php');
require_once realpath(__DIR__ . '/../includes/view/User_view.php'); require_once realpath(__DIR__ . '/../includes/view/User_view.php');
require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/users_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/users_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/user_angeltypes_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/user_angeltypes_controller.php');
@ -88,6 +89,7 @@ $free_pages = array(
'users', 'users',
'ical', 'ical',
'shifts_json_export', 'shifts_json_export',
'shifts',
'atom' 'atom'
); );
@ -127,6 +129,8 @@ if (isset($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && (i
$content = user_password_recovery_controller(); $content = user_password_recovery_controller();
} elseif ($p == "angeltypes") { } elseif ($p == "angeltypes") {
list($title, $content) = angeltypes_controller(); list($title, $content) = angeltypes_controller();
} elseif ($p == "shifts") {
list($title, $content) = shifts_controller();
} elseif ($p == "users") { } elseif ($p == "users") {
list($title, $content) = users_controller(); list($title, $content) = users_controller();
} elseif ($p == "user_angeltypes") { } elseif ($p == "user_angeltypes") {

Loading…
Cancel
Save