freeloader feature

main
Philip Häusler 11 years ago
parent 2c41fcdc09
commit c589219a96

@ -26,6 +26,9 @@ define('MIN_PASSWORD_LENGTH', 8);
// Wenn Engel beim Registrieren oder in ihrem Profil eine T-Shirt Größe angeben sollen, auf true setzen:
$enable_tshirt_size = true;
// Number of shifts to freeload until angel is locked for shift signup.
$max_freeloadable_shifts = 2;
// local timezone
date_default_timezone_set("Europe/Berlin");
@ -34,13 +37,13 @@ $PentabarfXMLhost = "cccv.pentabarf.org";
$PentabarfXMLpath = "Xcal/conference/";
$PentabarfXMLEventID = "31";
// multiply "night shifts" (start or end between 2 and 6 exclusive) by 2
// multiply "night shifts" and freeloaded shifts (start or end between 2 and 6 exclusive) by 2
$shift_sum_formula = "SUM(
(1+(
(HOUR(FROM_UNIXTIME(`Shifts`.`end`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) < 6)
OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`start`)) < 6)
OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) <= 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) >= 6)
))*(`Shifts`.`end` - `Shifts`.`start`)
))*(`Shifts`.`end` - `Shifts`.`start`)*(-2 * `ShiftEntry`.`freeloaded`)
)";
// weigh every shift the same

@ -1,3 +1,7 @@
/* freeloader */
ALTER TABLE `ShiftEntry` ADD `freeloaded` BOOLEAN NOT NULL, ADD INDEX ( `freeloaded` );
ALTER TABLE `ShiftEntry` ADD `freeload_comment` TEXT NULL DEFAULT NULL;
/* password recovery */
ALTER TABLE `User` ADD `password_recovery_token` VARCHAR( 32 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `Passwort` ,
ADD INDEX ( `password_recovery_token` );

@ -14,4 +14,14 @@ function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) {
");
}
/**
* Returns all freeloaded shifts for given user.
*/
function ShiftEntries_freeloaded_by_user($user) {
return sql_select("SELECT *
FROM `ShiftEntry`
WHERE `freeloaded` = 1
AND `UID`=" . sql_escape($user['UID']));
}
?>

@ -26,20 +26,45 @@ function user_myshifts() {
return template_render('../templates/user_myshifts_reset.html', array());
} elseif (isset($_REQUEST['edit']) && preg_match("/^[0-9]*$/", $_REQUEST['edit'])) {
$id = $_REQUEST['edit'];
$shift = sql_select("SELECT `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type` FROM `ShiftEntry` JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `ShiftEntry`.`id`=" . sql_escape($id) . " AND `UID`=" . sql_escape($shifts_user['UID']) . " LIMIT 1");
$shift = sql_select("SELECT
`ShiftEntry`.`freeloaded`,
`ShiftEntry`.`freeload_comment`,
`ShiftEntry`.`Comment`,
`ShiftEntry`.`UID`,
`Shifts`.*,
`Room`.`Name`,
`AngelTypes`.`name` as `angel_type`
FROM `ShiftEntry`
JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`)
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
WHERE `ShiftEntry`.`id`=" . sql_escape($id) . "
AND `UID`=" . sql_escape($shifts_user['UID']) . " LIMIT 1");
if (count($shift) > 0) {
$shift = $shift[0];
if (isset($_REQUEST['submit'])) {
$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');
$user_source = User($shift['UID']);
sql_query("UPDATE `ShiftEntry` SET `Comment`='" . sql_escape($comment) . "' WHERE `id`=" . sql_escape($id) . " LIMIT 1");
sql_query("UPDATE `ShiftEntry` SET
`Comment`='" . sql_escape($comment) . "',
`freeloaded`=" . sql_escape($freeloaded ? 1 : 0) . ",
`freeload_comment`='" . sql_escape($freeload_comment) . "'
WHERE `id`=" . sql_escape($id) . "
LIMIT 1");
engelsystem_log("Updated " . User_Nick_render($user_source) . "'s shift " . $shift['name'] . " from " . date("y-m-d H:i", $shift['start']) . " to " . date("y-m-d H:i", $shift['end']) . " with comment " . $comment);
success(_("Shift saved."));
redirect(page_link_to('user_myshifts'));
}
return ShiftEntry_edit_view(User_Nick_render($shifts_user), date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), $shift['Name'], $shift['name'], $shift['angel_type'], $shift['Comment']);
return ShiftEntry_edit_view(User_Nick_render($shifts_user), date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), $shift['Name'], $shift['name'], $shift['angel_type'], $shift['Comment'], $shift['freeloaded'], $shift['freeload_comment'], in_array("user_shifts_admin", $privileges));
} else
redirect(page_link_to('user_myshifts'));
} elseif (isset($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) {
@ -51,7 +76,7 @@ function user_myshifts() {
sql_query("DELETE FROM `ShiftEntry` WHERE `id`=" . sql_escape($id) . " LIMIT 1");
$msg .= success(_("You have been signed off from the shift."), true);
} else
$msg .= error(_("It's too late to sign yourself off the shift. If neccessary, as the dispatcher to do so."), true);
$msg .= error(_("It's too late to sign yourself off the shift. If neccessary, ask the dispatcher to do so."), true);
} else
redirect(page_link_to('user_myshifts'));
}
@ -66,13 +91,17 @@ function user_myshifts() {
foreach ($needed_angel_types_source as $needed_angel_type) {
$shift_info .= '<br><b>' . $needed_angel_type['name'] . ':</b> ';
$users_source = sql_select("SELECT `User`.* FROM `ShiftEntry` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` WHERE `ShiftEntry`.`SID`=" . sql_escape($shift['SID']) . " AND `ShiftEntry`.`TID`=" . sql_escape($needed_angel_type['id']));
$users_source = sql_select("SELECT `ShiftEntry`.`freeloaded`, `User`.* FROM `ShiftEntry` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` WHERE `ShiftEntry`.`SID`=" . sql_escape($shift['SID']) . " AND `ShiftEntry`.`TID`=" . sql_escape($needed_angel_type['id']));
$shift_entries = array();
foreach ($users_source as $user_source) {
if ($user['UID'] == $user_source['UID'])
$shift_entries[] = '<b>' . $user_source['Nick'] . '</b>';
$member = '<b>' . $user_source['Nick'] . '</b>';
else
$shift_entries[] = User_Nick_render($user_source);
$member = User_Nick_render($user_source);
if ($user_source['freeloaded'])
$member = '<strike>' . $member . '</strike>';
$shift_entries[] = $member;
}
$shift_info .= join(", ", $shift_entries);
}
@ -85,12 +114,22 @@ function user_myshifts() {
'comment' => $shift['Comment']
);
if ($shift['freeloaded']) {
if (in_array("user_shifts_admin", $privileges))
$myshift['comment'] .= '<br /><p class="error">' . _("Freeloaded") . ': ' . $shift['freeload_comment'] . '</p>';
else
$myshift['comment'] .= '<br /><p class="error">' . _("Freeloaded") . '</p>';
}
$myshift['actions'] = "";
if ($id == $user['UID'])
$myshift['actions'] .= img_button(page_link_to('user_myshifts') . '&edit=' . $shift['id'], 'pencil', _("edit"));
if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges))
$myshift['actions'] .= img_button(page_link_to('user_myshifts') . (($id != $user['UID']) ? '&id=' . $id : '') . '&cancel=' . $shift['id'], 'cross', _("sign off"));
if ($shift['freeloaded'])
$timesum += - 2 * ($shift['end'] - $shift['start']);
else
$timesum += $shift['end'] - $shift['start'];
$myshifts_table[] = $myshift;
}

@ -4,7 +4,10 @@ function shifts_title() {
}
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
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) . "'"))
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');
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)
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)) {
$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();
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']);
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
@ -267,7 +284,7 @@ function user_shifts() {
$angeltyppe_select = $type['name'];
}
return ShiftEntry_edit_view(date("Y-m-d H:i", $shift['start']) . ' &ndash; ' . 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']) . ' &ndash; ' . 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 {
return view_user_shifts();
}
@ -495,17 +512,22 @@ function view_user_shifts() {
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();
$freeloader = 0;
foreach ($entries as $entry) {
if ($entry['Gekommen'] == 1)
$style = "font-weight:bold;";
else
$style = "font-weight:normal;";
if ($entry['freeloaded']) {
$freeloader ++;
$style .= " text-decoration: line-through;";
}
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>';
else
$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));
// is the shift still running or alternatively is the user shift admin?
$user_may_join_shift = true;
@ -619,19 +641,26 @@ function view_user_shifts() {
$angeltypes = sql_select($query);
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();
$freeloader = 0;
foreach ($entries as $entry) {
if (in_array('user_shifts_admin', $privileges))
$entry_list[] = User_Nick_render($entry) . ' ' . img_button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], 'bin', _("delete"));
$member = User_Nick_render($entry) . ' ' . img_button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], 'bin', _("delete"));
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?
if ($angeltype['count'] - count($entries) > 0) {
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries)), $angeltype['count'] - count($entries));
if ($angeltype['count'] - count($entries) + $freeloader > 0) {
$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?
$user_may_join_shift = true;

@ -11,7 +11,15 @@
*
* @return string
*/
function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment) {
function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment, $freeloaded, $freeload_comment, $user_admin_shifts = false) {
if ($user_admin_shifts) {
$freeload_form = array(
form_checkbox('freeloaded', _("Freeloaded"), $freeloaded),
form_textarea('freeload_comment', _("Freeload comment (Only for shift coordination):"), $freeload_comment)
);
} else {
$freeload_form = $freeloaded ? "" : "";
}
return page(array(
form(array(
form_info(_("Angel:"), $angel),
@ -20,6 +28,7 @@ function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment)
form_info(_("Title:"), $title),
form_info(_("Type:"), $type),
form_textarea('comment', _("Comment (for your eyes only):"), $comment),
join("", $freeload_form),
form_submit('submit', _("Save"))
))
));

@ -196,6 +196,10 @@ if (isset($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && (i
}
if (isset($user)) {
$freeloaded_shifts_count = count(ShiftEntries_freeloaded_by_user($user));
if($freeloaded_shifts_count >= $max_freeloadable_shifts)
$content = error(sprintf(_("You freeloaded %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again."), $freeloaded_shifts_count), true) . $content;
// Hinweis für ungelesene Nachrichten
if ($p != "user_messages")
$content = user_unread_messages() . $content;

Loading…
Cancel
Save