@ -4,7 +4,10 @@ function shifts_title() {
}
}
function user_shifts() {
function user_shifts() {
global $user, $privileges;
global $user, $privileges, $max_freeloadable_shifts;
if (count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts)
redirect(page_link_to('user_myshifts'));
// Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins
// Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins
if (isset($_REQUEST['entry_id']) & & in_array('user_shifts_admin', $privileges)) {
if (isset($_REQUEST['entry_id']) & & in_array('user_shifts_admin', $privileges)) {
@ -239,8 +242,21 @@ function user_shifts() {
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'"))
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'"))
return error("This angel does already have an entry for this shift.", true);
return error("This angel does already have an entry for this shift.", true);
$freeloaded = $shift['freeloaded'];
$freeload_comment = $shift['freeload_comment'];
if (in_array("user_shifts_admin", $privileges)) {
$freeloaded = isset($_REQUEST['freeloaded']);
$freeload_comment = strip_request_item_nl('freeload_comment');
}
$comment = strip_request_item_nl('comment');
$comment = strip_request_item_nl('comment');
sql_query("INSERT INTO `ShiftEntry` SET `Comment`='" . sql_escape($comment) . "', `UID`=" . sql_escape($user_id) . ", `TID`=" . sql_escape($selected_type_id) . ", `SID`=" . sql_escape($shift_id));
sql_query("INSERT INTO `ShiftEntry` SET
`Comment`='" . sql_escape($comment) . "',
`freeloaded`=" . sql_escape($freeloaded ? 1 : 0) . ",
`freeload_comment`='" . sql_escape($freeload_comment) . "',
`UID`=" . sql_escape($user_id) . ",
`TID`=" . sql_escape($selected_type_id) . ",
`SID`=" . sql_escape($shift_id));
if ($type['restricted'] == 0 & & sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "' ") == 0)
if ($type['restricted'] == 0 & & sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "' ") == 0)
sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')");
sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')");
@ -251,10 +267,11 @@ function user_shifts() {
}
}
if (in_array('user_shifts_admin', $privileges)) {
if (in_array('user_shifts_admin', $privileges)) {
$users = sql_select("SELECT * FROM `User` ORDER BY `Nick`");
$users = sql_select("SELECT *, (SELECT count(*) FROM `ShiftEntry` WHERE `freeloaded`=1 AND `ShiftEntry`.`UID`=`User`.`UID`) AS `freeloaded` FROM `User` ORDER BY `Nick`");
$users_select = array();
$users_select = array();
foreach ($users as $usr)
foreach ($users as $usr)
$users_select[$usr['UID']] = $usr['Nick'];
$users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? "" : " (" . _("Freeloader") . ")") ;
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
@ -267,7 +284,7 @@ function user_shifts() {
$angeltyppe_select = $type['name'];
$angeltyppe_select = $type['name'];
}
}
return ShiftEntry_edit_view(date("Y-m-d H:i", $shift['start']) . ' – ' . date('Y-m-d H:i', $shift['end']) . ' (' . shift_length($shift) . ')', $shift['name'], $shift['Name'], $user_text, $angeltyppe_select, "");
return ShiftEntry_edit_view(date("Y-m-d H:i", $shift['start']) . ' – ' . date('Y-m-d H:i', $shift['end']) . ' (' . shift_length($shift) . ')', $shift['name'], $shift['Name'], $user_text, $angeltyppe_select, "", false, null, in_array('user_shifts_admin', $privileges) );
} else {
} else {
return view_user_shifts();
return view_user_shifts();
}
}
@ -350,17 +367,17 @@ function view_user_shifts() {
if ($_SESSION['user_shifts']['start_day'] == $_SESSION['user_shifts']['end_day'] & & $_SESSION['user_shifts']['start_time'] >= $_SESSION['user_shifts']['end_time'])
if ($_SESSION['user_shifts']['start_day'] == $_SESSION['user_shifts']['end_day'] & & $_SESSION['user_shifts']['start_time'] >= $_SESSION['user_shifts']['end_time'])
$_SESSION['user_shifts']['end_time'] = '23:59';
$_SESSION['user_shifts']['end_time'] = '23:59';
if(isset($_SESSION['user_shifts']['start_day'])) {
if (isset($_SESSION['user_shifts']['start_day'])) {
$starttime = DateTime::createFromFormat("Y-m-d H:i", $_SESSION['user_shifts']['start_day'] . $_SESSION['user_shifts']['start_time']);
$starttime = DateTime::createFromFormat("Y-m-d H:i", $_SESSION['user_shifts']['start_day'] . $_SESSION['user_shifts']['start_time']);
$starttime = $starttime->getTimestamp();
$starttime = $starttime->getTimestamp();
} else
} else
$starttime = now();
$starttime = now();
if(isset($_SESSION['user_shifts']['end_day'])) {
if (isset($_SESSION['user_shifts']['end_day'])) {
$endtime = DateTime::createFromFormat("Y-m-d H:i", $_SESSION['user_shifts']['end_day'] . $_SESSION['user_shifts']['end_time']);
$endtime = DateTime::createFromFormat("Y-m-d H:i", $_SESSION['user_shifts']['end_day'] . $_SESSION['user_shifts']['end_time']);
$endtime = $endtime->getTimestamp();
$endtime = $endtime->getTimestamp();
} else
} else
$endtime = now() + 24*60*60;
$endtime = now() + 24 * 60 * 60;
if (! isset($_SESSION['user_shifts']['rooms']) || count($_SESSION['user_shifts']['rooms']) == 0)
if (! isset($_SESSION['user_shifts']['rooms']) || count($_SESSION['user_shifts']['rooms']) == 0)
$_SESSION['user_shifts']['rooms'] = array(
$_SESSION['user_shifts']['rooms'] = array(
@ -495,17 +512,22 @@ function view_user_shifts() {
foreach ($angeltypes as $angeltype) {
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`");
$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();
$entry_list = array();
$freeloader = 0;
foreach ($entries as $entry) {
foreach ($entries as $entry) {
if ($entry['Gekommen'] == 1)
if ($entry['Gekommen'] == 1)
$style = "font-weight:bold;";
$style = "font-weight:bold;";
else
else
$style = "font-weight:normal;";
$style = "font-weight:normal;";
if ($entry['freeloaded']) {
$freeloader ++;
$style .= " text-decoration: line-through;";
}
if (in_array('user_shifts_admin', $privileges))
if (in_array('user_shifts_admin', $privileges))
$entry_list[] = "< span style = \"$style\" > " . User_Nick_render($entry) . ' ' . img_button(page_link_to('user_shifts') . '& entry_id=' . $entry['id'], 'bin', _("delete")) . '< / span > ';
$entry_list[] = "< span style = \"$style\" > " . User_Nick_render($entry) . ' ' . img_button(page_link_to('user_shifts') . '& entry_id=' . $entry['id'], 'bin', _("delete")) . '< / span > ';
else
else
$entry_list[] = "< span style = \"$style\" > " . User_Nick_render($entry) . "< / span > ";
$entry_list[] = "< span style = \"$style\" > " . User_Nick_render($entry) . "< / span > ";
}
}
if ($angeltype['count'] - count($entries) > 0) {
if ($angeltype['count'] - count($entries) - $freeloader > 0) {
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries)), $angeltype['count'] - count($entries));
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries)), $angeltype['count'] - count($entries));
// is the shift still running or alternatively is the user shift admin?
// is the shift still running or alternatively is the user shift admin?
$user_may_join_shift = true;
$user_may_join_shift = true;
@ -547,7 +569,7 @@ function view_user_shifts() {
$shifts_row .= '< br / > ';
$shifts_row .= '< br / > ';
}
}
if (in_array('user_shifts_admin', $privileges)) {
if (in_array('user_shifts_admin', $privileges)) {
$shifts_row .= '< a href = "' . page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'] . '" > ' . _("Add more angels") .' » < / a > ';
$shifts_row .= '< a href = "' . page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'] . '" > ' . _("Add more angels") . ' » < / a > ';
}
}
}
}
if ($shift['own'] & & ! in_array('user_shifts_admin', $privileges))
if ($shift['own'] & & ! in_array('user_shifts_admin', $privileges))
@ -619,19 +641,26 @@ function view_user_shifts() {
$angeltypes = sql_select($query);
$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;
foreach ($angeltypes as & $angeltype) {
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`");
$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();
$entry_list = array();
$freeloader = 0;
foreach ($entries as $entry) {
foreach ($entries as $entry) {
if (in_array('user_shifts_admin', $privileges))
if (in_array('user_shifts_admin', $privileges))
$ent ry_list[] = User_Nick_render($entry) . ' ' . img_button(page_link_to('user_shifts') . '& entry_id=' . $entry['id'], 'bin', _("delete"));
$memb er = User_Nick_render($entry) . ' ' . img_button(page_link_to('user_shifts') . '& entry_id=' . $entry['id'], 'bin', _("delete"));
else
else
$entry_list[] = User_Nick_render($entry);
$member = User_Nick_render($entry);
if ($entry['freeloaded']) {
$member = '< strike > ' . $member . '< / strike > ';
$freeloader ++;
}
}
$angeltype['taken'] = count($entries);
$entry_list[] = $member;
}
$angeltype['taken'] = count($entries) - $freeloader;
// do we need more angles of this type?
// do we need more angles of this type?
if ($angeltype['count'] - count($entries) > 0) {
if ($angeltype['count'] - count($entries) + $freeloader > 0) {
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries)), $angeltype['count'] - count($entries));
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries) + $freeloader ), $angeltype['count'] - count($entries) + $freeloader );
// is the shift still running or alternatively is the user shift admin?
// is the shift still running or alternatively is the user shift admin?
$user_may_join_shift = true;
$user_may_join_shift = true;