@ -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") . ' » < / a > ');
success(_("You are subscribed. Thank you!") . ' < a href = "' . page_link_to('user_myshifts') . '" > ' . _("My shifts") . ' » < / 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)) {
@ -451,10 +447,10 @@ function view_user_shifts() {
if (count($_SESSION['user_shifts']['filled']) == 1) {
if (count($_SESSION['user_shifts']['filled']) == 1) {
if ($_SESSION['user_shifts']['filled'][0] == 0)
if ($_SESSION['user_shifts']['filled'][0] == 0)
$SQL .= "
$SQL .= "
AND (nat.`count` > entries.`count` OR entries.`count` IS NULL OR EXISTS (SELECT `SID` FROM `ShiftEntry` WHERE `UID` = " .sql_escape($user['UID']) . " AND `ShiftEntry`.`SID` = `Shifts`.`SID`))";
AND (nat.`count` > entries.`count` OR entries.`count` IS NULL OR EXISTS (SELECT `SID` FROM `ShiftEntry` WHERE `UID` = " . sql_escape($user['UID']) . " AND `ShiftEntry`.`SID` = `Shifts`.`SID`))";
elseif ($_SESSION['user_shifts']['filled'][0] == 1)
elseif ($_SESSION['user_shifts']['filled'][0] == 1)
$SQL .= "
$SQL .= "
AND (nat.`count` < = entries.`count` OR EXISTS (SELECT `SID` FROM `ShiftEntry` WHERE `UID` = " .sql_escape($user['UID']) . " AND `ShiftEntry`.`SID` = `Shifts`.`SID`))";
AND (nat.`count` < = entries.`count` OR EXISTS (SELECT `SID` FROM `ShiftEntry` WHERE `UID` = " . sql_escape($user['UID']) . " AND `ShiftEntry`.`SID` = `Shifts`.`SID`))";
}
}
$SQL .= "
$SQL .= "
ORDER BY `start`";
ORDER BY `start`";
@ -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'),