summaryrefslogtreecommitdiff
path: root/includes/pages
diff options
context:
space:
mode:
Diffstat (limited to 'includes/pages')
-rw-r--r--includes/pages/admin_active.php4
-rw-r--r--includes/pages/admin_free.php2
-rw-r--r--includes/pages/admin_import.php4
-rw-r--r--includes/pages/admin_news.php100
-rw-r--r--includes/pages/admin_questions.php10
-rw-r--r--includes/pages/admin_rooms.php39
-rw-r--r--includes/pages/admin_shifts.php14
-rw-r--r--includes/pages/admin_user.php9
-rw-r--r--includes/pages/guest_login.php23
-rw-r--r--includes/pages/user_messages.php6
-rw-r--r--includes/pages/user_news.php6
-rw-r--r--includes/pages/user_questions.php3
-rw-r--r--includes/pages/user_settings.php361
-rw-r--r--includes/pages/user_shifts.php971
14 files changed, 382 insertions, 1170 deletions
diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php
index 8d71b147..4e2ca89f 100644
--- a/includes/pages/admin_active.php
+++ b/includes/pages/admin_active.php
@@ -5,7 +5,7 @@ function admin_active_title() {
}
function admin_active() {
- global $tshirt_sizes;
+ global $tshirt_sizes, $shift_sum_formula;
$msg = "";
$search = "";
@@ -40,7 +40,7 @@ function admin_active() {
if (isset($_REQUEST['ack'])) {
sql_query("UPDATE `User` SET `Aktiv` = 0 WHERE `Tshirt` = 0");
$users = sql_select("
- SELECT `User`.*, COUNT(`ShiftEntry`.`id`) as `shift_count`, ${shift_sum_formula} as `shift_length`
+ SELECT `User`.*, COUNT(`ShiftEntry`.`id`) as `shift_count`, $shift_sum_formula as `shift_length`
FROM `User`
LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID`
diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php
index d3b5b01b..427de61a 100644
--- a/includes/pages/admin_free.php
+++ b/includes/pages/admin_free.php
@@ -67,7 +67,7 @@ function admin_free() {
'shift_state' => User_shift_state_render($usr),
'dect' => $usr['DECT'],
'jabber' => $usr['jabber'],
- 'email' => $usr['email'],
+ 'email' => $usr['email_by_human_allowed'] ? $usr['email'] : glyph('eye-close'),
'actions' => in_array('admin_user', $privileges) ? button(page_link_to('admin_user') . '&id=' . $usr['UID'], _("edit"), 'btn-xs') : ''
];
}
diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php
index 2c36e681..4af09dca 100644
--- a/includes/pages/admin_import.php
+++ b/includes/pages/admin_import.php
@@ -312,8 +312,8 @@ function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_e
'event-id' });
$shifts_pb[$event_id] = [
'shifttype_id' => $shifttype_id,
- 'start' => DateTime::createFromFormat("Ymd\THis", $event->dtstart)->getTimestamp() - $add_minutes_start * 60,
- 'end' => DateTime::createFromFormat("Ymd\THis", $event->dtend)->getTimestamp() + $add_minutes_end * 60,
+ 'start' => parse_date("Ymd\THis", $event->dtstart) - $add_minutes_start * 60,
+ 'end' => parse_date("Ymd\THis", $event->dtend) + $add_minutes_end * 60,
'RID' => $rooms_import[trim($event->location)],
'title' => trim($event->summary),
'URL' => trim($event->url),
diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php
index 4226e6ba..789fc728 100644
--- a/includes/pages/admin_news.php
+++ b/includes/pages/admin_news.php
@@ -5,66 +5,62 @@ function admin_news() {
if (! isset($_GET["action"])) {
redirect(page_link_to("news"));
+ }
+
+ $html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
+ if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
+ $news_id = $_REQUEST['id'];
} else {
- $html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
- if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
- $news_id = $_REQUEST['id'];
- } else {
- return error("Incomplete call, missing News ID.", true);
- }
+ return error("Incomplete call, missing News ID.", true);
+ }
+
+ $news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
+ if (empty($news)) {
+ return error("No News found.", true);
+ }
+ switch ($_REQUEST["action"]) {
+ default:
+ redirect(page_link_to('news'));
+ case 'edit':
+ list($news) = $news;
+
+ $user_source = User($news['UID']);
+
+ $html .= form([
+ form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])),
+ form_info(_("Author"), User_Nick_render($user_source)),
+ form_text('eBetreff', _("Subject"), $news['Betreff']),
+ form_textarea('eText', _("Message"), $news['Text']),
+ form_checkbox('eTreffen', _("Meeting"), $news['Treffen'] == 1, 1),
+ form_submit('submit', _("Save"))
+ ], page_link_to('admin_news&action=save&id=' . $news_id));
+
+ $html .= '<a class="btn btn-danger" href="' . page_link_to('admin_news&action=delete&id=' . $news_id) . '"><span class="glyphicon glyphicon-trash"></span> ' . _("Delete") . '</a>';
+ break;
- $news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
- if (count($news) > 0) {
- switch ($_REQUEST["action"]) {
- default:
- redirect(page_link_to('news'));
- case 'edit':
- list($news) = $news;
-
- $user_source = User($news['UID']);
- if ($user_source === false) {
- engelsystem_error("Unable to load user.");
- }
-
- $html .= form([
- form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])),
- form_info(_("Author"), User_Nick_render($user_source)),
- form_text('eBetreff', _("Subject"), $news['Betreff']),
- form_textarea('eText', _("Message"), $news['Text']),
- form_checkbox('eTreffen', _("Meeting"), $news['Treffen'] == 1, 1),
- form_submit('submit', _("Save"))
- ], page_link_to('admin_news&action=save&id=' . $news_id));
-
- $html .= '<a class="btn btn-danger" href="' . page_link_to('admin_news&action=delete&id=' . $news_id) . '"><span class="glyphicon glyphicon-trash"></span> ' . _("Delete") . '</a>';
- break;
-
- case 'save':
- list($news) = $news;
-
- sql_query("UPDATE `News` SET
+ case 'save':
+ list($news) = $news;
+
+ sql_query("UPDATE `News` SET
`Datum`='" . sql_escape(time()) . "',
`Betreff`='" . sql_escape($_POST["eBetreff"]) . "',
`Text`='" . sql_escape($_POST["eText"]) . "',
`UID`='" . sql_escape($user['UID']) . "',
`Treffen`='" . sql_escape($_POST["eTreffen"]) . "'
WHERE `ID`='" . sql_escape($news_id) . "'");
- engelsystem_log("News updated: " . $_POST["eBetreff"]);
- success(_("News entry updated."));
- redirect(page_link_to("news"));
- break;
-
- case 'delete':
- list($news) = $news;
-
- sql_query("DELETE FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
- engelsystem_log("News deleted: " . $news['Betreff']);
- success(_("News entry deleted."));
- redirect(page_link_to("news"));
- break;
- }
- } else {
- return error("No News found.", true);
- }
+ engelsystem_log("News updated: " . $_POST["eBetreff"]);
+ success(_("News entry updated."));
+ redirect(page_link_to("news"));
+ break;
+
+ case 'delete':
+ list($news) = $news;
+
+ sql_query("DELETE FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
+ engelsystem_log("News deleted: " . $news['Betreff']);
+ success(_("News entry deleted."));
+ redirect(page_link_to("news"));
+ break;
}
return $html . '</div>';
}
diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php
index 8e7507da..8c16255c 100644
--- a/includes/pages/admin_questions.php
+++ b/includes/pages/admin_questions.php
@@ -26,9 +26,6 @@ function admin_questions() {
$questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL");
foreach ($questions as $question) {
$user_source = User($question['UID']);
- if ($user_source === false) {
- engelsystem_error("Unable to load user.");
- }
$unanswered_questions_table[] = [
'from' => User_Nick_render($user_source),
@@ -45,14 +42,7 @@ function admin_questions() {
$questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL");
foreach ($questions as $question) {
$user_source = User($question['UID']);
- if ($user_source === false) {
- engelsystem_error("Unable to load user.");
- }
-
$answer_user_source = User($question['AID']);
- if ($answer_user_source === false) {
- engelsystem_error("Unable to load user.");
- }
$answered_questions_table[] = [
'from' => User_Nick_render($user_source),
'question' => str_replace("\n", "<br />", $question['Question']),
diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php
index d34d4386..129ed423 100644
--- a/includes/pages/admin_rooms.php
+++ b/includes/pages/admin_rooms.php
@@ -9,10 +9,10 @@ function admin_rooms() {
$rooms = [];
foreach ($rooms_source as $room) {
$rooms[] = [
- 'name' => $room['Name'],
+ 'name' => Room_name_render($room),
'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '&#10003;' : '',
'public' => $room['show'] == 'Y' ? '&#10003;' : '',
- 'actions' => buttons([
+ 'actions' => table_buttons([
button(page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'], _("edit"), 'btn-xs'),
button(page_link_to('admin_rooms') . '&show=delete&id=' . $room['RID'], _("delete"), 'btn-xs')
])
@@ -36,20 +36,24 @@ function admin_rooms() {
}
if (test_request_int('id')) {
- $room = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($_REQUEST['id']) . "'");
- if (count($room) > 0) {
- $room_id = $_REQUEST['id'];
- $name = $room[0]['Name'];
- $from_pentabarf = $room[0]['FromPentabarf'];
- $public = $room[0]['show'];
- $number = $room[0]['Number'];
- $needed_angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
- foreach ($needed_angeltypes as $needed_angeltype) {
- $angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count'];
- }
- } else {
+ $room = Room($_REQUEST['id']);
+ if ($room === false) {
+ engelsystem_error("Unable to load room.");
+ }
+ if ($room == null) {
redirect(page_link_to('admin_rooms'));
}
+
+ $room_id = $_REQUEST['id'];
+ $name = $room['Name'];
+ $from_pentabarf = $room['FromPentabarf'];
+ $public = $room['show'];
+ $number = $room['Number'];
+
+ $needed_angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
+ foreach ($needed_angeltypes as $needed_angeltype) {
+ $angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count'];
+ }
}
if ($_REQUEST['show'] == 'edit') {
@@ -106,15 +110,12 @@ function admin_rooms() {
engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
}
- sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
+ NeededAngelTypes_delete_by_room($room_id);
$needed_angeltype_info = [];
foreach ($angeltypes_count as $angeltype_id => $angeltype_count) {
$angeltype = AngelType($angeltype_id);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype != null) {
- sql_query("INSERT INTO `NeededAngelTypes` SET `room_id`='" . sql_escape($room_id) . "', `angel_type_id`='" . sql_escape($angeltype_id) . "', `count`='" . sql_escape($angeltype_count) . "'");
+ NeededAngelType_add(null, $angeltype_id, $room_id, $angeltype_count);
$needed_angeltype_info[] = $angeltype['name'] . ": " . $angeltype_count;
}
}
diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php
index 3dd22f3a..42a8c682 100644
--- a/includes/pages/admin_shifts.php
+++ b/includes/pages/admin_shifts.php
@@ -9,7 +9,7 @@ function admin_shifts() {
$valid = true;
$rid = 0;
- $start = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d") . " 00:00")->getTimestamp();
+ $start = parse_date("Y-m-d H:i", date("Y-m-d") . " 00:00");
$end = $start;
$mode = 'single';
$angelmode = 'manually';
@@ -71,15 +71,15 @@ function admin_shifts() {
error(_('Please select a location.'));
}
- if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) {
- $start = $tmp->getTimestamp();
+ if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
+ $start = $tmp;
} else {
$valid = false;
error(_('Please select a start time.'));
}
- if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end']))) {
- $end = $tmp->getTimestamp();
+ if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
+ $end = $tmp;
} else {
$valid = false;
error(_('Please select an end time.'));
@@ -188,7 +188,7 @@ function admin_shifts() {
} while ($shift_end < $end);
} elseif ($mode == 'variable') {
rsort($change_hours);
- $day = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d", $start) . " 00:00")->getTimestamp();
+ $day = parse_date("Y-m-d H:i", date("Y-m-d", $start) . " 00:00");
$change_index = 0;
// Ersten/nächsten passenden Schichtwechsel suchen
foreach ($change_hours as $i => $change_hour) {
@@ -205,7 +205,7 @@ function admin_shifts() {
$shift_start = $start;
do {
- $day = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00")->getTimestamp();
+ $day = parse_date("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00");
$shift_end = $day + $change_hours[$change_index] * 60 * 60;
if ($shift_end > $end) {
diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php
index 56987e12..9b1bc0df 100644
--- a/includes/pages/admin_user.php
+++ b/includes/pages/admin_user.php
@@ -16,9 +16,6 @@ function admin_user() {
$user_id = $_REQUEST['id'];
if (! isset($_REQUEST['action'])) {
$user_source = User($user_id);
- if ($user_source === false) {
- engelsystem_error('Unable to load user.');
- }
if ($user_source == null) {
error(_('This user does not exist.'));
redirect(users_link());
@@ -39,8 +36,9 @@ function admin_user() {
$html .= " <tr><td>Telefon</td><td>" . "<input type=\"text\" size=\"40\" name=\"eTelefon\" value=\"" . $user_source['Telefon'] . "\"></td></tr>\n";
$html .= " <tr><td>Handy</td><td>" . "<input type=\"text\" size=\"40\" name=\"eHandy\" value=\"" . $user_source['Handy'] . "\"></td></tr>\n";
$html .= " <tr><td>DECT</td><td>" . "<input type=\"text\" size=\"4\" name=\"eDECT\" value=\"" . $user_source['DECT'] . "\"></td></tr>\n";
- $html .= " <tr><td>email</td><td>" . "<input type=\"text\" size=\"40\" name=\"eemail\" value=\"" . $user_source['email'] . "\"></td></tr>\n";
- $html .= "<tr><td>" . form_checkbox('email_shiftinfo', _("Please send me an email if my shifts change"), $user_source['email_shiftinfo']) . "</td></tr>\n";
+ if ($user_source['email_by_human_allowed']) {
+ $html .= " <tr><td>email</td><td>" . "<input type=\"text\" size=\"40\" name=\"eemail\" value=\"" . $user_source['email'] . "\"></td></tr>\n";
+ }
$html .= " <tr><td>jabber</td><td>" . "<input type=\"text\" size=\"40\" name=\"ejabber\" value=\"" . $user_source['jabber'] . "\"></td></tr>\n";
$html .= " <tr><td>Size</td><td>" . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size']) . "</td></tr>\n";
@@ -176,7 +174,6 @@ function admin_user() {
`Alter` = '" . sql_escape($_POST["eAlter"]) . "',
`DECT` = '" . sql_escape($_POST["eDECT"]) . "',
`email` = '" . sql_escape($_POST["eemail"]) . "',
- `email_shiftinfo` = " . sql_bool(isset($_REQUEST['email_shiftinfo'])) . ",
`jabber` = '" . sql_escape($_POST["ejabber"]) . "',
`Size` = '" . sql_escape($_POST["eSize"]) . "',
`Gekommen`= '" . sql_escape($_POST["eGekommen"]) . "',
diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php
index a2139cc1..69201161 100644
--- a/includes/pages/guest_login.php
+++ b/includes/pages/guest_login.php
@@ -17,9 +17,6 @@ function guest_register() {
global $tshirt_sizes, $enable_tshirt_size, $default_theme, $user;
$event_config = EventConfig();
- if ($event_config === false) {
- engelsystem_error("Unable to load event config.");
- }
$msg = "";
$nick = "";
@@ -31,6 +28,7 @@ function guest_register() {
$mobile = "";
$mail = "";
$email_shiftinfo = false;
+ $email_by_human_allowed = false;
$jabber = "";
$hometown = "";
$comment = "";
@@ -39,7 +37,7 @@ function guest_register() {
$selected_angel_types = [];
$planned_arrival_date = null;
- $angel_types_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
+ $angel_types_source = AngelTypes();
$angel_types = [];
foreach ($angel_types_source as $angel_type) {
$angel_types[$angel_type['id']] = $angel_type['name'] . ($angel_type['restricted'] ? " (restricted)" : "");
@@ -77,6 +75,10 @@ function guest_register() {
$email_shiftinfo = true;
}
+ if (isset($_REQUEST['email_by_human_allowed'])) {
+ $email_by_human_allowed = true;
+ }
+
if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) {
$jabber = strip_request_item('jabber');
if (! check_email($jabber)) {
@@ -104,8 +106,8 @@ function guest_register() {
$msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), MIN_PASSWORD_LENGTH), true);
}
- if (isset($_REQUEST['planned_arrival_date']) && DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))) {
- $planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp();
+ if (isset($_REQUEST['planned_arrival_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date'])) {
+ $planned_arrival_date = $tmp;
} else {
$valid = false;
$msg .= error(_("Please enter your planned date of arrival."), true);
@@ -157,6 +159,7 @@ function guest_register() {
`Handy`='" . sql_escape($mobile) . "',
`email`='" . sql_escape($mail) . "',
`email_shiftinfo`=" . sql_bool($email_shiftinfo) . ",
+ `email_by_human_allowed`=" . sql_bool($email_by_human_allowed) . ",
`jabber`='" . sql_escape($jabber) . "',
`Size`='" . sql_escape($tshirt_size) . "',
`Passwort`='" . sql_escape($password_hash) . "',
@@ -182,7 +185,7 @@ function guest_register() {
engelsystem_log("User " . User_Nick_render(User($user_id)) . " signed up as: " . join(", ", $user_angel_types_info));
success(_("Angel registration successful!"));
- // User is already logged in - that means a coordinator has registered an angel. Return to register page.
+ // User is already logged in - that means a supporter has registered an angel. Return to register page.
if (isset($user)) {
redirect(page_link_to('register'));
}
@@ -209,7 +212,8 @@ function guest_register() {
]),
div('col-sm-8', [
form_email('mail', _("E-Mail") . ' ' . entry_required(), $mail),
- form_checkbox('email_shiftinfo', _("Please send me an email if my shifts change"), $email_shiftinfo)
+ form_checkbox('email_shiftinfo', _("The engelsystem is allowed to send me an email (e.g. when my shifts change)"), $email_shiftinfo),
+ form_checkbox('email_by_human_allowed', _("Humans are allowed to send me an email (e.g. for ticket vouchers)"), $email_by_human_allowed)
])
]),
div('row', [
@@ -318,9 +322,6 @@ function guest_login() {
}
$event_config = EventConfig();
- if ($event_config === false) {
- engelsystem_error("Unable to load event config.");
- }
return page([
div('col-md-12', [
diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php
index 4af2a0cb..eb07deea 100644
--- a/includes/pages/user_messages.php
+++ b/includes/pages/user_messages.php
@@ -47,13 +47,7 @@ function user_messages() {
foreach ($messages as $message) {
$sender_user_source = User($message['SUID']);
- if ($sender_user_source === false) {
- engelsystem_error(_("Unable to load user."));
- }
$receiver_user_source = User($message['RUID']);
- if ($receiver_user_source === false) {
- engelsystem_error(_("Unable to load user."));
- }
$messages_table_entry = [
'new' => $message['isRead'] == 'N' ? '<span class="glyphicon glyphicon-envelope"></span>' : '',
diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php
index c5791134..97f7ec83 100644
--- a/includes/pages/user_news.php
+++ b/includes/pages/user_news.php
@@ -62,9 +62,6 @@ function display_news($news) {
$html .= '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $news['Datum']) . '&emsp;';
$user_source = User($news['UID']);
- if ($user_source === false) {
- engelsystem_error(_("Unable to load user."));
- }
$html .= User_Nick_render($user_source);
if ($page != "news_comments") {
@@ -94,9 +91,6 @@ function user_news_comments() {
$comments = sql_select("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($nid) . "' ORDER BY 'ID'");
foreach ($comments as $comment) {
$user_source = User($comment['UID']);
- if ($user_source === false) {
- engelsystem_error(_("Unable to load user."));
- }
$html .= '<div class="panel panel-default">';
$html .= '<div class="panel-body">' . nl2br($comment['Text']) . '</div>';
diff --git a/includes/pages/user_questions.php b/includes/pages/user_questions.php
index 10e8fef6..7acdee78 100644
--- a/includes/pages/user_questions.php
+++ b/includes/pages/user_questions.php
@@ -13,9 +13,6 @@ function user_questions() {
$answered_questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
foreach ($answered_questions as &$question) {
$answer_user_source = User($question['AID']);
- if ($answer_user_source === false) {
- engelsystem_error(_("Unable to load user."));
- }
$question['answer_user'] = User_Nick_render($answer_user_source);
}
diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php
index b2ea5752..02c61a20 100644
--- a/includes/pages/user_settings.php
+++ b/includes/pages/user_settings.php
@@ -4,215 +4,190 @@ function settings_title() {
return _("Settings");
}
-function user_settings() {
- global $enable_tshirt_size, $tshirt_sizes, $themes, $locales;
- global $user;
+/**
+ * Change user main attributes (name, dates, etc.)
+ *
+ * @param User $user_source
+ * The user
+ */
+function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) {
+ $valid = true;
- $msg = "";
- $nick = $user['Nick'];
- $lastname = $user['Name'];
- $prename = $user['Vorname'];
- $age = $user['Alter'];
- $tel = $user['Telefon'];
- $dect = $user['DECT'];
- $mobile = $user['Handy'];
- $mail = $user['email'];
- $email_shiftinfo = $user['email_shiftinfo'];
- $jabber = $user['jabber'];
- $hometown = $user['Hometown'];
- $tshirt_size = $user['Size'];
- $selected_theme = $user['color'];
- $selected_language = $user['Sprache'];
- $planned_arrival_date = $user['planned_arrival_date'];
- $planned_departure_date = $user['planned_departure_date'];
-
- if (isset($_REQUEST['submit'])) {
- $valid = true;
-
- if (isset($_REQUEST['mail']) && strlen(strip_request_item('mail')) > 0) {
- $mail = strip_request_item('mail');
- if (! check_email($mail)) {
- $valid = false;
- $msg .= error(_("E-mail address is not correct."), true);
- }
- } else {
+ if (isset($_REQUEST['mail'])) {
+ $result = User_validate_mail($_REQUEST['mail']);
+ $user_source['email'] = $result->getValue();
+ if (! $result->isValid()) {
$valid = false;
- $msg .= error(_("Please enter your e-mail."), true);
+ error(_("E-mail address is not correct."));
}
-
- $email_shiftinfo = isset($_REQUEST['email_shiftinfo']);
-
- if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) {
- $jabber = strip_request_item('jabber');
- if (! check_email($jabber)) {
- $valid = false;
- $msg .= error(_("Please check your jabber account information."), true);
- }
+ } else {
+ $valid = false;
+ error(_("Please enter your e-mail."));
+ }
+
+ $user_source['email_shiftinfo'] = isset($_REQUEST['email_shiftinfo']);
+ $user_source['email_by_human_allowed'] = isset($_REQUEST['email_by_human_allowed']);
+
+ if (isset($_REQUEST['jabber'])) {
+ $result = User_validate_jabber($_REQUEST['jabber']);
+ $user_source['jabber'] = $result->getValue();
+ if (! $result->isValid()) {
+ $valid = false;
+ error(_("Please check your jabber account information."));
}
-
- if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']])) {
- $tshirt_size = $_REQUEST['tshirt_size'];
- } elseif ($enable_tshirt_size) {
+ }
+
+ if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']])) {
+ $user_source['Size'] = $_REQUEST['tshirt_size'];
+ } elseif ($enable_tshirt_size) {
+ $valid = false;
+ }
+
+ if (isset($_REQUEST['planned_arrival_date'])) {
+ $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date']);
+ $result = User_validate_planned_arrival_date($tmp);
+ $user_source['planned_arrival_date'] = $result->getValue();
+ if (! $result->isValid()) {
$valid = false;
+ error(_("Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date."));
}
-
- if (isset($_REQUEST['planned_arrival_date']) && DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))) {
- $planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp();
- } else {
+ }
+
+ if (isset($_REQUEST['planned_departure_date'])) {
+ $tmp = parse_date("Y-m-d", $_REQUEST['planned_departure_date']);
+ $result = User_validate_planned_departure_date($user_source['planned_arrival_date'], $tmp);
+ $user_source['planned_departure_date'] = $result->getValue();
+ if (! $result->isValid()) {
$valid = false;
- $msg .= error(_("Please enter your planned date of arrival."), true);
+ error(_("Please enter your planned date of departure. It should be after your planned arrival date and after buildup start date and before teardown end date."));
}
+ }
+
+ // Trivia
+ $user_source['Name'] = strip_request_item('lastname', $user_source['Name']);
+ $user_source['Vorname'] = strip_request_item('prename', $user_source['Vorname']);
+ $user_source['Alter'] = strip_request_item('age', $user_source['Alter']);
+ $user_source['Telefon'] = strip_request_item('tel', $user_source['Telefon']);
+ $user_source['DECT'] = strip_request_item('dect', $user_source['DECT']);
+ $user_source['Handy'] = strip_request_item('mobile', $user_source['Handy']);
+ $user_source['Hometown'] = strip_request_item('hometown', $user_source['Hometown']);
+
+ if ($valid) {
+ User_update($user_source);
+ success(_("Settings saved."));
+ redirect(page_link_to('user_settings'));
+ }
+
+ return $user_source;
+}
+
+/**
+ * Change user password.
+ *
+ * @param User $user_source
+ * The user
+ */
+function user_settings_password($user_source) {
+ if (! isset($_REQUEST['password']) || ! verify_password($_REQUEST['password'], $user_source['Passwort'], $user_source['UID'])) {
+ error(_("-> not OK. Please try again."));
+ } elseif (strlen($_REQUEST['new_password']) < MIN_PASSWORD_LENGTH) {
+ error(_("Your password is to short (please use at least 6 characters)."));
+ } elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2']) {
+ error(_("Your passwords don't match."));
+ } elseif (set_password($user_source['UID'], $_REQUEST['new_password'])) {
+ success(_("Password saved."));
+ } else {
+ error(_("Failed setting password."));
+ }
+ redirect(page_link_to('user_settings'));
+}
+
+/**
+ * Change user theme
+ *
+ * @param User $user_sources
+ * The user
+ * @param array<String> $themes
+ * List of available themes
+ */
+function user_settings_theme($user_source, $themes) {
+ $valid = true;
+
+ if (isset($_REQUEST['theme']) && isset($themes[$_REQUEST['theme']])) {
+ $user_source['color'] = $_REQUEST['theme'];
+ } else {
+ $valid = false;
+ }
+
+ if ($valid) {
+ sql_query("UPDATE `User` SET `color`='" . sql_escape($user_source['color']) . "' WHERE `UID`='" . sql_escape($user_source['UID']) . "'");
- if (isset($_REQUEST['planned_departure_date']) && $_REQUEST['planned_departure_date'] != '') {
- if (DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_departure_date']))) {
- $planned_departure_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_departure_date']))->getTimestamp();
- } else {
- $valid = false;
- $msg .= error(_("Please enter your planned date of departure."), true);
- }
- } else {
- $planned_departure_date = null;
- }
+ success(_("Theme changed."));
+ redirect(page_link_to('user_settings'));
+ }
+
+ return $user_source;
+}
+
+/**
+ * Change use locale
+ *
+ * @param User $user_source
+ * The user
+ * @param array<String> $locales
+ * List of available locales
+ */
+function user_settings_locale($user_source, $locales) {
+ $valid = true;
+
+ if (isset($_REQUEST['language']) && isset($locales[$_REQUEST['language']])) {
+ $user_source['Sprache'] = $_REQUEST['language'];
+ } else {
+ $valid = false;
+ }
+
+ if ($valid) {
+ sql_query("UPDATE `User` SET `Sprache`='" . sql_escape($user_source['Sprache']) . "' WHERE `UID`='" . sql_escape($user_source['UID']) . "'");
+ $_SESSION['locale'] = $user_source['Sprache'];
- // Trivia
- if (isset($_REQUEST['lastname'])) {
- $lastname = strip_request_item('lastname');
- }
- if (isset($_REQUEST['prename'])) {
- $prename = strip_request_item('prename');
- }
- if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age'])) {
- $age = strip_request_item('age');
- }
- if (isset($_REQUEST['tel'])) {
- $tel = strip_request_item('tel');
- }
- if (isset($_REQUEST['dect'])) {
- $dect = strip_request_item('dect');
- }
- if (isset($_REQUEST['mobile'])) {
- $mobile = strip_request_item('mobile');
- }
- if (isset($_REQUEST['hometown'])) {
- $hometown = strip_request_item('hometown');
+ success("Language changed.");
+ redirect(page_link_to('user_settings'));
+ }
+
+ return $user_source;
+}
+
+/**
+ * Main user settings page/controller
+ */
+function user_settings() {
+ global $enable_tshirt_size, $tshirt_sizes, $themes, $locales;
+ global $user;
+
+ $buildup_start_date = null;
+ $teardown_end_date = null;
+ $event_config = EventConfig();
+ if ($event_config != null) {
+ if (isset($event_config['buildup_start_date'])) {
+ $buildup_start_date = $event_config['buildup_start_date'];
}
-
- if ($valid) {
- sql_query("
- UPDATE `User` SET
- `Nick`='" . sql_escape($nick) . "',
- `Vorname`='" . sql_escape($prename) . "',
- `Name`='" . sql_escape($lastname) . "',
- `Alter`='" . sql_escape($age) . "',
- `Telefon`='" . sql_escape($tel) . "',
- `DECT`='" . sql_escape($dect) . "',
- `Handy`='" . sql_escape($mobile) . "',
- `email`='" . sql_escape($mail) . "',
- `email_shiftinfo`=" . sql_bool($email_shiftinfo) . ",
- `jabber`='" . sql_escape($jabber) . "',
- `Size`='" . sql_escape($tshirt_size) . "',
- `Hometown`='" . sql_escape($hometown) . "',
- `planned_arrival_date`='" . sql_escape($planned_arrival_date) . "',
- `planned_departure_date`=" . sql_null($planned_departure_date) . "
- WHERE `UID`='" . sql_escape($user['UID']) . "'");
-
- success(_("Settings saved."));
- redirect(page_link_to('user_settings'));
+ if (isset($event_config['teardown_end_date'])) {
+ $teardown_end_date = $event_config['teardown_end_date'];
}
+ }
+
+ $user_source = $user;
+
+ if (isset($_REQUEST['submit'])) {
+ $user_source = user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes);
} elseif (isset($_REQUEST['submit_password'])) {
- $valid = true;
-
- if (! isset($_REQUEST['password']) || ! verify_password($_REQUEST['password'], $user['Passwort'], $user['UID'])) {
- $msg .= error(_("-> not OK. Please try again."), true);
- } elseif (strlen($_REQUEST['new_password']) < MIN_PASSWORD_LENGTH) {
- $msg .= error(_("Your password is to short (please use at least 6 characters)."), true);
- } elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2']) {
- $msg .= error(_("Your passwords don't match."), true);
- } elseif (set_password($user['UID'], $_REQUEST['new_password'])) {
- success(_("Password saved."));
- } else {
- error(_("Failed setting password."));
- }
- redirect(page_link_to('user_settings'));
+ user_settings_password($user_source);
} elseif (isset($_REQUEST['submit_theme'])) {
- $valid = true;
-
- if (isset($_REQUEST['theme']) && isset($themes[$_REQUEST['theme']])) {
- $selected_theme = $_REQUEST['theme'];
- } else {
- $valid = false;
- }
-
- if ($valid) {
- sql_query("UPDATE `User` SET `color`='" . sql_escape($selected_theme) . "' WHERE `UID`='" . sql_escape($user['UID']) . "'");
-
- success(_("Theme changed."));
- redirect(page_link_to('user_settings'));
- }
+ $user_source = user_settings_theme($user_source, $themes);
} elseif (isset($_REQUEST['submit_language'])) {
- $valid = true;
-
- if (isset($_REQUEST['language']) && isset($locales[$_REQUEST['language']])) {
- $selected_language = $_REQUEST['language'];
- } else {
- $valid = false;
- }
-
- if ($valid) {
- sql_query("UPDATE `User` SET `Sprache`='" . sql_escape($selected_language) . "' WHERE `UID`='" . sql_escape($user['UID']) . "'");
- $_SESSION['locale'] = $selected_language;
-
- success("Language changed.");
- redirect(page_link_to('user_settings'));
- }
+ $user_source = user_settings_locale($user_source, $locales);
}
- return page_with_title(settings_title(), [
- $msg,
- msg(),
- div('row', [
- div('col-md-6', [
- form([
- form_info('', _("Here you can change your user details.")),
- form_info(entry_required() . ' = ' . _("Entry required!")),
- form_text('nick', _("Nick"), $nick, true),
- form_text('lastname', _("Last name"), $lastname),
- form_text('prename', _("First name"), $prename),
- form_date('planned_arrival_date', _("Planned date of arrival") . ' ' . entry_required(), $planned_arrival_date, time()),
- form_date('planned_departure_date', _("Planned date of departure"), $planned_departure_date, time()),
- form_text('age', _("Age"), $age),
- form_text('tel', _("Phone"), $tel),
- form_text('dect', _("DECT"), $dect),
- form_text('mobile', _("Mobile"), $mobile),
- form_text('mail', _("E-Mail") . ' ' . entry_required(), $mail),
- form_checkbox('email_shiftinfo', _("Please send me an email if my shifts change"), $email_shiftinfo),
- form_text('jabber', _("Jabber"), $jabber),
- form_text('hometown', _("Hometown"), $hometown),
- $enable_tshirt_size ? form_select('tshirt_size', _("Shirt size"), $tshirt_sizes, $tshirt_size) : '',
- form_info('', _('Please visit the angeltypes page to manage your angeltypes.')),
- form_submit('submit', _("Save"))
- ])
- ]),
- div('col-md-6', [
- form([
- form_info(_("Here you can change your password.")),
- form_password('password', _("Old password:")),
- form_password('new_password', _("New password:")),
- form_password('new_password2', _("Password confirmation:")),
- form_submit('submit_password', _("Save"))
- ]),
- form([
- form_info(_("Here you can choose your color settings:")),
- form_select('theme', _("Color settings:"), $themes, $selected_theme),
- form_submit('submit_theme', _("Save"))
- ]),
- form([
- form_info(_("Here you can choose your language:")),
- form_select('language', _("Language:"), $locales, $selected_language),
- form_submit('submit_language', _("Save"))
- ])
- ])
- ])
- ]);
+ return User_settings_view($user_source, $locales, $themes, $buildup_start_date, $teardown_end_date, $enable_tshirt_size, $tshirt_sizes);
}
?>
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index 9ad532ca..e5fd27ef 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -1,893 +1,177 @@
<?php
+use Engelsystem\ShiftsFilter;
+use Engelsystem\ShiftCalendarRenderer;
function shifts_title() {
return _("Shifts");
}
+/**
+ * Start different controllers for deleting shifts and shift_entries, edit shifts and add shift entries.
+ */
function user_shifts() {
- global $user, $privileges;
+ global $user;
if (User_is_freeloader($user)) {
redirect(page_link_to('user_myshifts'));
}
- // Locations laden
- $rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
- $room_array = [];
- foreach ($rooms as $room) {
- $room_array[$room['RID']] = $room['Name'];
- }
-
// 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']) && test_request_int('entry_id')) {
- $entry_id = $_REQUEST['entry_id'];
- } else {
- redirect(page_link_to('user_shifts'));
- }
-
- $shift_entry_source = sql_select("
- SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type`
- FROM `ShiftEntry`
- JOIN `User` ON (`User`.`UID`=`ShiftEntry`.`UID`)
- JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`)
- JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
- JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
- JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
- WHERE `ShiftEntry`.`id`='" . sql_escape($entry_id) . "'");
- if (count($shift_entry_source) > 0) {
- $shift_entry_source = $shift_entry_source[0];
-
- $result = ShiftEntry_delete($entry_id);
- if ($result === false) {
- engelsystem_error('Unable to delete shift entry.');
- }
-
- engelsystem_log("Deleted " . User_Nick_render($shift_entry_source) . "'s shift: " . $shift_entry_source['name'] . " at " . $shift_entry_source['Name'] . " from " . date("Y-m-d H:i", $shift_entry_source['start']) . " to " . date("Y-m-d H:i", $shift_entry_source['end']) . " as " . $shift_entry_source['angel_type']);
- success(_("Shift entry deleted."));
- } else {
- error(_("Entry not found."));
- }
- redirect(page_link_to('user_shifts'));
- } elseif (isset($_REQUEST['edit_shift']) && in_array('admin_shifts', $privileges)) {
- // Schicht bearbeiten
- $msg = "";
- $valid = true;
-
- if (isset($_REQUEST['edit_shift']) && test_request_int('edit_shift')) {
- $shift_id = $_REQUEST['edit_shift'];
- } else {
- redirect(page_link_to('user_shifts'));
- }
-
- $shift = sql_select("
- SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.* FROM `Shifts`
- JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
- JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
- WHERE `SID`='" . sql_escape($shift_id) . "'");
- if (count($shift) == 0) {
- redirect(page_link_to('user_shifts'));
- }
- $shift = $shift[0];
-
- // Engeltypen laden
- $types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
- $angel_types = [];
- $needed_angel_types = [];
- foreach ($types as $type) {
- $angel_types[$type['id']] = $type;
- $needed_angel_types[$type['id']] = 0;
- }
-
- $shifttypes_source = ShiftTypes();
- $shifttypes = [];
- foreach ($shifttypes_source as $shifttype) {
- $shifttypes[$shifttype['id']] = $shifttype['name'];
- }
-
- // Benötigte Engeltypen vom Raum
- $needed_angel_types_source = sql_select("SELECT `AngelTypes`.*, `NeededAngelTypes`.`count` FROM `AngelTypes` LEFT JOIN `NeededAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id` AND `NeededAngelTypes`.`room_id`='" . sql_escape($shift['RID']) . "') ORDER BY `AngelTypes`.`name`");
- foreach ($needed_angel_types_source as $type) {
- if ($type['count'] != "") {
- $needed_angel_types[$type['id']] = $type['count'];
- }
- }
-
- // Benötigte Engeltypen von der Schicht
- $needed_angel_types_source = sql_select("SELECT `AngelTypes`.*, `NeededAngelTypes`.`count` FROM `AngelTypes` LEFT JOIN `NeededAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id` AND `NeededAngelTypes`.`shift_id`='" . sql_escape($shift_id) . "') ORDER BY `AngelTypes`.`name`");
- foreach ($needed_angel_types_source as $type) {
- if ($type['count'] != "") {
- $needed_angel_types[$type['id']] = $type['count'];
- }
- }
-
- $shifttype_id = $shift['shifttype_id'];
- $title = $shift['title'];
- $rid = $shift['RID'];
- $start = $shift['start'];
- $end = $shift['end'];
-
- if (isset($_REQUEST['submit'])) {
- // Name/Bezeichnung der Schicht, darf leer sein
- $title = strip_request_item('title');
-
- // Auswahl der sichtbaren Locations für die Schichten
- if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room_array[$_REQUEST['rid']])) {
- $rid = $_REQUEST['rid'];
- } else {
- $valid = false;
- $rid = $rooms[0]['RID'];
- $msg .= error(_("Please select a room."), true);
- }
-
- if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
- $shifttype_id = $_REQUEST['shifttype_id'];
- } else {
- $valid = false;
- $msg .= error(_('Please select a shifttype.'), true);
- }
-
- if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) {
- $start = $tmp->getTimestamp();
- } else {
- $valid = false;
- $msg .= error(_("Please enter a valid starting time for the shifts."), true);
- }
-
- if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end']))) {
- $end = $tmp->getTimestamp();
- } else {
- $valid = false;
- $msg .= error(_("Please enter a valid ending time for the shifts."), true);
- }
-
- if ($start >= $end) {
- $valid = false;
- $msg .= error(_("The ending time has to be after the starting time."), true);
- }
-
- foreach ($needed_angel_types_source as $type) {
- if (isset($_REQUEST['type_' . $type['id']]) && preg_match("/^[0-9]+$/", trim($_REQUEST['type_' . $type['id']]))) {
- $needed_angel_types[$type['id']] = trim($_REQUEST['type_' . $type['id']]);
- } else {
- $valid = false;
- $msg .= error(sprintf(_("Please check your input for needed angels of type %s."), $type['name']), true);
- }
- }
-
- if ($valid) {
- $shift['shifttype_id'] = $shifttype_id;
- $shift['title'] = $title;
- $shift['RID'] = $rid;
- $shift['start'] = $start;
- $shift['end'] = $end;
-
- $result = Shift_update($shift);
- if ($result === false) {
- engelsystem_error('Unable to update shift.');
- }
- sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`='" . sql_escape($shift_id) . "'");
- $needed_angel_types_info = [];
- foreach ($needed_angel_types as $type_id => $count) {
- sql_query("INSERT INTO `NeededAngelTypes` SET `shift_id`='" . sql_escape($shift_id) . "', `angel_type_id`='" . sql_escape($type_id) . "', `count`='" . sql_escape($count) . "'");
- $needed_angel_types_info[] = $angel_types[$type_id]['name'] . ": " . $count;
- }
-
- engelsystem_log("Updated shift '" . $shifttypes[$shifttype_id] . ", " . $title . "' 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."));
-
- redirect(shift_link([
- 'SID' => $shift_id
- ]));
- }
- }
-
- $angel_types = "";
- foreach ($types as $type) {
- $angel_types .= form_spinner('type_' . $type['id'], $type['name'], $needed_angel_types[$type['id']]);
- }
-
- return page_with_title(shifts_title(), [
- msg(),
- '<noscript>' . info(_("This page is much more comfortable with javascript."), true) . '</noscript>',
- form([
- form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
- form_text('title', _("Title"), $title),
- form_select('rid', _("Room:"), $room_array, $rid),
- form_text('start', _("Start:"), date("Y-m-d H:i", $start)),
- form_text('end', _("End:"), date("Y-m-d H:i", $end)),
- '<h2>' . _("Needed angels") . '</h2>',
- $angel_types,
- form_submit('submit', _("Save"))
- ])
- ]);
- } elseif (isset($_REQUEST['delete_shift']) && in_array('user_shifts_admin', $privileges)) {
- // Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
- if (isset($_REQUEST['delete_shift']) && preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) {
- $shift_id = $_REQUEST['delete_shift'];
- } else {
- redirect(page_link_to('user_shifts'));
- }
-
- $shift = Shift($shift_id);
- if ($shift === false) {
- engelsystem_error('Unable to load shift.');
- }
- if ($shift == null) {
- redirect(page_link_to('user_shifts'));
- }
-
- // Schicht löschen bestätigt
- if (isset($_REQUEST['delete'])) {
- $result = Shift_delete($shift_id);
- if ($result === false) {
- engelsystem_error('Unable to delete shift.');
- }
-
- engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
- success(_("Shift deleted."));
- redirect(page_link_to('user_shifts'));
- }
-
- return page_with_title(shifts_title(), [
- error(sprintf(_("Do you want to delete the shift %s from %s to %s?"), $shift['name'], date("Y-m-d H:i", $shift['start']), date("H:i", $shift['end'])), true),
- '<a class="button" href="?p=user_shifts&delete_shift=' . $shift_id . '&delete">' . _("delete") . '</a>'
- ]);
+ if (isset($_REQUEST['entry_id'])) {
+ return shift_entry_delete_controller();
+ } elseif (isset($_REQUEST['edit_shift'])) {
+ return shift_edit_controller();
+ } elseif (isset($_REQUEST['delete_shift'])) {
+ return shift_delete_controller();
} elseif (isset($_REQUEST['shift_id'])) {
- if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) {
- $shift_id = $_REQUEST['shift_id'];
- } else {
- redirect(page_link_to('user_shifts'));
- }
-
- $shift = Shift($shift_id);
- $room;
- $shift['Name'] = $room_array[$shift['RID']];
- if ($shift === false) {
- engelsystem_error('Unable to load shift.');
- }
- if ($shift == null) {
- redirect(page_link_to('user_shifts'));
- }
-
- if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id'])) {
- $type_id = $_REQUEST['type_id'];
- } else {
- redirect(page_link_to('user_shifts'));
- }
-
- if (in_array('user_shifts_admin', $privileges)) {
- $type = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($type_id) . "' LIMIT 1");
- } else {
- $type = sql_select("SELECT * FROM `UserAngelTypes` JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`) WHERE `AngelTypes`.`id` = '" . sql_escape($type_id) . "' AND (`AngelTypes`.`restricted` = 0 OR (`UserAngelTypes`.`user_id` = '" . sql_escape($user['UID']) . "' AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL)) LIMIT 1");
- }
-
- if (count($type) == 0) {
- redirect(page_link_to('user_shifts'));
- }
- $type = $type[0];
-
- if (! Shift_signup_allowed($shift, $type)) {
- error(_('You are not allowed to sign up for this shift. Maybe shift is full or already running.'));
- redirect(shift_link($shift));
- }
-
- if (isset($_REQUEST['submit'])) {
- $selected_type_id = $type_id;
- if (in_array('user_shifts_admin', $privileges)) {
- if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id'])) {
- $user_id = $_REQUEST['user_id'];
- } else {
- $user_id = $user['UID'];
- }
-
- if (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1") == 0) {
- redirect(page_link_to('user_shifts'));
- }
-
- if (isset($_REQUEST['angeltype_id']) && test_request_int('angeltype_id') && sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($_REQUEST['angeltype_id']) . "' LIMIT 1") > 0) {
- $selected_type_id = $_REQUEST['angeltype_id'];
- }
- } else {
- $user_id = $user['UID'];
- }
-
- 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');
- $result = ShiftEntry_create([
- 'SID' => $shift_id,
- 'TID' => $selected_type_id,
- 'UID' => $user_id,
- 'Comment' => $comment,
- 'freeloaded' => $freeloaded,
- 'freeload_comment' => $freeload_comment
- ]);
- if ($result === false) {
- engelsystem_error('Unable to create shift entry.');
- }
-
- 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) . "')");
- }
-
- $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']));
- success(_("You are subscribed. Thank you!") . ' <a href="' . page_link_to('user_myshifts') . '">' . _("My shifts") . ' &raquo;</a>');
- redirect(shift_link($shift));
- }
-
- if (in_array('user_shifts_admin', $privileges)) {
- $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 = [];
-
- foreach ($users as $usr) {
- $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`");
- $angeltypes = [];
- foreach ($angeltypes_source as $angeltype) {
- $angeltypes[$angeltype['id']] = $angeltype['name'];
- }
- $angeltyppe_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
- } else {
- $user_text = User_Nick_render($user);
- $angeltyppe_select = $type['name'];
- }
-
- return ShiftEntry_edit_view($user_text, date("Y-m-d H:i", $shift['start']) . ' &ndash; ' . date('Y-m-d H:i', $shift['end']) . ' (' . shift_length($shift) . ')', $shift['Name'], $shift['name'], $angeltyppe_select, "", false, null, in_array('user_shifts_admin', $privileges));
- } else {
- return view_user_shifts();
+ return shift_entry_add_controller();
}
+ return view_user_shifts();
}
-function view_user_shifts() {
- global $user, $privileges;
- global $ical_shifts;
-
- $ical_shifts = [];
+/**
+ * Helper function that updates the start and end time from request data.
+ * Use update_ShiftsFilter().
+ *
+ * @param ShiftsFilter $shiftsFilter
+ * The shiftfilter to update.
+ */
+function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) {
+ $shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, time()));
+ $shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, time() + 24 * 60 * 60));
+
+ if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) {
+ $shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60);
+ }
+}
+
+/**
+ * Update given ShiftsFilter with filter params from user input
+ *
+ * @param ShiftsFilter $shiftsFilter
+ * The shifts filter to update from request data
+ * @param boolean $user_shifts_admin
+ * Has the user user_shift_admin privilege?
+ * @param string[] $days
+ * An array of available filter days
+ */
+function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $days) {
+ $shiftsFilter->setUserShiftsAdmin($user_shifts_admin);
+ if (isset($_REQUEST['filled'])) {
+ $shiftsFilter->setFilled(check_request_int_array('filled'));
+ }
+ if (isset($_REQUEST['rooms'])) {
+ $shiftsFilter->setRooms(check_request_int_array('rooms'));
+ }
+ if (isset($_REQUEST['types'])) {
+ $shiftsFilter->setTypes(check_request_int_array('types'));
+ }
+ if ((isset($_REQUEST['start_time']) && isset($_REQUEST['start_day']) && isset($_REQUEST['end_time']) && isset($_REQUEST['end_day'])) || $shiftsFilter->getStartTime() == null || $shiftsFilter->getEndTime() == null) {
+ update_ShiftsFilter_timerange($shiftsFilter, $days);
+ }
+}
+
+function load_rooms() {
+ $rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
+ if (count($rooms) == 0) {
+ error(_("The administration has not configured any rooms yet."));
+ redirect('?');
+ }
+ return $rooms;
+}
+
+function load_days() {
$days = sql_select_single_col("
SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) AS `id`, DATE(FROM_UNIXTIME(`start`)) AS `name`
FROM `Shifts`
ORDER BY `start`");
-
if (count($days) == 0) {
error(_("The administration has not configured any shifts yet."));
redirect('?');
}
+ return $days;
+}
+
+function load_types() {
+ global $user;
- $rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
-
- if (count($rooms) == 0) {
- error(_("The administration has not configured any rooms yet."));
- redirect('?');
- }
-
- if (in_array('user_shifts_admin', $privileges)) {
- $types = sql_select("SELECT `id`, `name` FROM `AngelTypes` ORDER BY `AngelTypes`.`name`");
- } else {
- $types = sql_select("SELECT `AngelTypes`.`id`, `AngelTypes`.`name`, (`AngelTypes`.`restricted`=0 OR (NOT `UserAngelTypes`.`confirm_user_id` IS NULL OR `UserAngelTypes`.`id` IS NULL)) as `enabled` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "') ORDER BY `AngelTypes`.`name`");
- }
- if (empty($types)) {
- $types = sql_select("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0");
- }
- $filled = [
- [
- 'id' => '1',
- 'name' => _("occupied")
- ],
- [
- 'id' => '0',
- 'name' => _("free")
- ]
- ];
-
- if (count($types) == 0) {
+ if (sql_num_query("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0") == 0) {
error(_("The administration has not configured any angeltypes yet - or you are not subscribed to any angeltype."));
redirect('?');
}
-
- if (! isset($_SESSION['user_shifts'])) {
- $_SESSION['user_shifts'] = [];
- }
-
- if (! isset($_SESSION['user_shifts']['filled'])) {
- // User shift admins see free and occupied shifts by default
- $_SESSION['user_shifts']['filled'] = in_array('user_shifts_admin', $privileges) ? [
- 0,
- 1
- ] : [
- 0
- ];
- }
-
- foreach ([
- 'rooms',
- 'types',
- 'filled'
- ] as $key) {
- if (isset($_REQUEST[$key])) {
- $filtered = array_filter($_REQUEST[$key], 'is_numeric');
- if (! empty($filtered)) {
- $_SESSION['user_shifts'][$key] = $filtered;
- }
- unset($filtered);
- }
- if (! isset($_SESSION['user_shifts'][$key])) {
- $_SESSION['user_shifts'][$key] = array_map('get_ids_from_array', $$key);
- }
- }
-
- if (isset($_REQUEST['rooms'])) {
- if (isset($_REQUEST['new_style'])) {
- $_SESSION['user_shifts']['new_style'] = true;
- } else {
- $_SESSION['user_shifts']['new_style'] = false;
- }
- }
- if (! isset($_SESSION['user_shifts']['new_style'])) {
- $_SESSION['user_shifts']['new_style'] = true;
- }
- foreach ([
- 'start',
- 'end'
- ] as $key) {
- if (isset($_REQUEST[$key . '_day']) && in_array($_REQUEST[$key . '_day'], $days)) {
- $_SESSION['user_shifts'][$key . '_day'] = $_REQUEST[$key . '_day'];
- }
- if (isset($_REQUEST[$key . '_time']) && preg_match('#^\d{1,2}:\d\d$#', $_REQUEST[$key . '_time'])) {
- $_SESSION['user_shifts'][$key . '_time'] = $_REQUEST[$key . '_time'];
- }
- if (! isset($_SESSION['user_shifts'][$key . '_day'])) {
- $time = date('Y-m-d', time() + ($key == 'end' ? 24 * 60 * 60 : 0));
- $_SESSION['user_shifts'][$key . '_day'] = in_array($time, $days) ? $time : ($key == 'end' ? max($days) : min($days));
- }
- if (! isset($_SESSION['user_shifts'][$key . '_time'])) {
- $_SESSION['user_shifts'][$key . '_time'] = date('H:i');
- }
- }
- if ($_SESSION['user_shifts']['start_day'] > $_SESSION['user_shifts']['end_day']) {
- $_SESSION['user_shifts']['end_day'] = $_SESSION['user_shifts']['start_day'];
- }
- 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';
- }
-
- 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 = $starttime->getTimestamp();
- } else {
- $starttime = now();
- }
-
- 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 = $endtime->getTimestamp();
- } else {
- $endtime = now() + 24 * 60 * 60;
- }
-
- if (! isset($_SESSION['user_shifts']['rooms']) || count($_SESSION['user_shifts']['rooms']) == 0) {
- $_SESSION['user_shifts']['rooms'] = [
- 0
- ];
+ $types = sql_select("SELECT `AngelTypes`.`id`, `AngelTypes`.`name`, (`AngelTypes`.`restricted`=0 OR (NOT `UserAngelTypes`.`confirm_user_id` IS NULL OR `UserAngelTypes`.`id` IS NULL)) as `enabled` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "') ORDER BY `AngelTypes`.`name`");
+ if (empty($types)) {
+ return sql_select("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0");
}
+ return $types;
+}
+
+function view_user_shifts() {
+ global $user, $privileges;
+ global $ical_shifts;
- $SQL = "SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`, nat2.`special_needs` > 0 AS 'has_special_needs'
- FROM `Shifts`
- INNER JOIN `Room` USING (`RID`)
- INNER JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
- LEFT JOIN (SELECT COUNT(*) AS special_needs , nat3.`shift_id` FROM `NeededAngelTypes` AS nat3 WHERE `shift_id` IS NOT NULL GROUP BY nat3.`shift_id`) AS nat2 ON nat2.`shift_id` = `Shifts`.`SID`
- INNER JOIN `NeededAngelTypes` AS nat ON nat.`count` != 0 AND nat.`angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") AND ((nat2.`special_needs` > 0 AND nat.`shift_id` = `Shifts`.`SID`) OR ((nat2.`special_needs` = 0 OR nat2.`special_needs` IS NULL) AND nat.`room_id` = `RID`))
- LEFT JOIN (SELECT se.`SID`, se.`TID`, COUNT(*) as count FROM `ShiftEntry` AS se GROUP BY se.`SID`, se.`TID`) AS entries ON entries.`SID` = `Shifts`.`SID` AND entries.`TID` = nat.`angel_type_id`
- WHERE `Shifts`.`RID` IN (" . implode(',', $_SESSION['user_shifts']['rooms']) . ")
- AND `start` BETWEEN " . $starttime . " AND " . $endtime;
+ $ical_shifts = [];
+ $days = load_days();
+ $rooms = load_rooms();
+ $types = load_types();
- if (count($_SESSION['user_shifts']['filled']) == 1) {
- if ($_SESSION['user_shifts']['filled'][0] == 0) {
- $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`))";
- } elseif ($_SESSION['user_shifts']['filled'][0] == 1) {
- $SQL .= "
- AND (nat.`count` <= entries.`count` OR EXISTS (SELECT `SID` FROM `ShiftEntry` WHERE `UID` = '" . sql_escape($user['UID']) . "' AND `ShiftEntry`.`SID` = `Shifts`.`SID`))";
- }
+ if (! isset($_SESSION['ShiftsFilter'])) {
+ $room_ids = array_map('get_ids_from_array', $rooms);
+ $type_ids = array_map('get_ids_from_array', $types);
+ $_SESSION['ShiftsFilter'] = new ShiftsFilter(in_array('user_shifts_admin', $privileges), $room_ids, $type_ids);
}
- $SQL .= "
- ORDER BY `start`";
+ update_ShiftsFilter($_SESSION['ShiftsFilter'], in_array('user_shifts_admin', $privileges), $days);
+ $shiftsFilter = $_SESSION['ShiftsFilter'];
- $shifts = sql_select($SQL);
+ $shifts = Shifts_by_ShiftsFilter($shiftsFilter, $user);
$ownshifts_source = sql_select("
SELECT `ShiftTypes`.`name`, `Shifts`.*
FROM `Shifts`
INNER JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
INNER JOIN `ShiftEntry` ON (`Shifts`.`SID` = `ShiftEntry`.`SID` AND `ShiftEntry`.`UID` = '" . sql_escape($user['UID']) . "')
- WHERE `Shifts`.`RID` IN (" . implode(',', $_SESSION['user_shifts']['rooms']) . ")
- AND `start` BETWEEN " . $starttime . " AND " . $endtime);
+ WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
+ AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime());
$ownshifts = [];
foreach ($ownshifts_source as $ownshift) {
$ownshifts[$ownshift['SID']] = $ownshift;
}
unset($ownshifts_source);
- $shifts_table = "";
- /*
- * [0] => Array ( [SID] => 1 [start] => 1355958000 [end] => 1355961600 [RID] => 1 [name] => [URL] => [PSID] => [room_name] => test1 [has_special_needs] => 1 [is_full] => 0 )
- */
- if ($_SESSION['user_shifts']['new_style']) {
- $first = 15 * 60 * floor($starttime / (15 * 60));
- $maxshow = ceil(($endtime - $first) / (60 * 15));
- $block = [];
- $todo = [];
- $myrooms = $rooms;
-
- // delete un-selected rooms from array
- foreach ($myrooms as $k => $v) {
- if (array_search($v["id"], $_SESSION['user_shifts']['rooms']) === false) {
- unset($myrooms[$k]);
- }
- // initialize $block array
- $block[$v["id"]] = array_fill(0, $maxshow, 0);
- }
-
- // calculate number of parallel shifts in each timeslot for each room
- foreach ($shifts as $k => $shift) {
- $rid = $shift["RID"];
- $blocks = ($shift["end"] - $shift["start"]) / (15 * 60);
- $firstblock = floor(($shift["start"] - $first) / (15 * 60));
- for ($i = $firstblock; $i < $blocks + $firstblock && $i < $maxshow; $i ++) {
- $block[$rid][$i] ++;
- }
- $shifts[$k]['own'] = in_array($shift['SID'], array_keys($ownshifts));
- }
-
- $shifts_table = '<div class="shifts-table"><table id="shifts" class="table scrollable"><thead><tr><th>-</th>';
- foreach ($myrooms as $key => $room) {
- $rid = $room["id"];
- if (array_sum($block[$rid]) == 0) {
- // do not display columns without entries
- unset($block[$rid]);
- unset($myrooms[$key]);
- continue;
- }
- $colspan = call_user_func_array('max', $block[$rid]);
- if ($colspan == 0) {
- $colspan = 1;
- }
- $todo[$rid] = array_fill(0, $maxshow, $colspan);
- $shifts_table .= "<th" . (($colspan > 1) ? ' colspan="' . $colspan . '"' : '') . ">" . Room_name_render([
- 'RID' => $room['id'],
- 'Name' => $room['name']
- ]) . "</th>\n";
- }
- unset($block, $blocks, $firstblock, $colspan, $key, $room);
-
- $shifts_table .= "</tr></thead><tbody>";
- for ($i = 0; $i < $maxshow; $i ++) {
- $thistime = $first + ($i * 15 * 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 .= date('Y-m-d<b\r />H:i', $thistime);
- } elseif ($thistime % (60 * 60) == 0) {
- $shifts_table .= "<tr class=\"row-hour\"><th>";
- $shifts_table .= date("H:i", $thistime);
- } else {
- $shifts_table .= "<tr><th>";
- }
- $shifts_table .= "</th>";
- foreach ($myrooms as $room) {
- $rid = $room["id"];
- foreach ($shifts as $shift) {
- if ($shift["RID"] == $rid) {
- if (floor($shift["start"] / (15 * 60)) == $thistime / (15 * 60)) {
- $blocks = ($shift["end"] - $shift["start"]) / (15 * 60);
- if ($blocks < 1) {
- $blocks = 1;
- }
-
- $collides = in_array($shift['SID'], array_keys($ownshifts));
- if (! $collides) {
- foreach ($ownshifts as $ownshift) {
- 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']) {
- $collides = true;
- break;
- }
- }
- }
-
- $is_free = false;
- $shifts_row = '';
- if (in_array('admin_shifts', $privileges)) {
- $shifts_row .= '<div class="pull-right">' . table_buttons([
- button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
- button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs')
- ]) . '</div>';
- }
- $shifts_row .= Room_name_render([
- 'RID' => $room['id'],
- 'Name' => $room['name']
- ]) . '<br />';
- $shifts_row .= '<a href="' . shift_link($shift) . '">' . date('Y-m-d H:i', $shift['start']);
- $shifts_row .= " &ndash; ";
- $shifts_row .= date('H:i', $shift['end']);
- $shifts_row .= "<br /><b>";
- $shifts_row .= ShiftType($shift['shifttype_id'])['name'];
- $shifts_row .= "</b><br />";
- if ($shift['title'] != '') {
- $shifts_row .= $shift['title'];
- $shifts_row .= "<br />";
- }
- $shifts_row .= '</a>';
- $shifts_row .= '<br />';
- $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name`, `UserAngelTypes`.`user_id`
- FROM `NeededAngelTypes`
- JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`)
- LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "')
- WHERE
- `count` > 0
- AND ";
- if ($shift['has_special_needs']) {
- $query .= "`shift_id` = '" . sql_escape($shift['SID']) . "'";
- } else {
- $query .= "`room_id` = '" . sql_escape($shift['RID']) . "'";
- }
- if (! empty($_SESSION['user_shifts']['types'])) {
- $query .= " AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") ";
- }
- $query .= " ORDER BY `AngelTypes`.`name`";
- $angeltypes = sql_select($query);
-
- if (count($angeltypes) > 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 = [];
- $freeloader = 0;
- foreach ($entries as $entry) {
- $style = '';
- 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) . ' ' . table_buttons([
- button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], glyph('trash'), 'btn-xs')
- ]) . '</span>';
- } else {
- $entry_list[] = "<span style=\"$style\">" . User_Nick_render($entry) . "</span>";
- }
- }
- 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;
-
- // you cannot join if user alread joined a parallel or this shift
- $user_may_join_shift &= ! $collides;
-
- // you cannot join if user is not of this angel type
- $user_may_join_shift &= isset($angeltype['user_id']);
-
- // you cannot join if you are not confirmed
- if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) {
- $user_may_join_shift &= isset($angeltype['confirm_user_id']);
- }
-
- // you can only join if the shift is in future or running
- $user_may_join_shift &= time() < $shift['start'];
-
- // User shift admins may join anybody in every shift
- $user_may_join_shift |= in_array('user_shifts_admin', $privileges);
- if ($user_may_join_shift) {
- $entry_list[] = '<a href="' . page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'] . '">' . $inner_text . '</a> ' . button(page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'], _('Sign up'), 'btn-xs');
- } else {
- if (time() > $shift['start']) {
- $entry_list[] = $inner_text . ' (' . _('ended') . ')';
- } elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) {
- $entry_list[] = $inner_text . glyph('lock');
- } elseif ($angeltype['restricted'] == 1) {
- $entry_list[] = $inner_text;
- } elseif ($collides) {
- $entry_list[] = $inner_text;
- } else {
- $entry_list[] = $inner_text . '<br />' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs');
- }
- }
-
- unset($inner_text);
- $is_free = true;
- }
-
- $shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> ';
- $shifts_row .= join(", ", $entry_list);
- $shifts_row .= '<br />';
- }
- if (in_array('user_shifts_admin', $privileges)) {
- $shifts_row .= ' ' . button(page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs');
- }
- }
- if ($shift['own'] && ! in_array('user_shifts_admin', $privileges)) {
- $class = 'own';
- } elseif ($collides && ! in_array('user_shifts_admin', $privileges)) {
- $class = 'collides';
- } elseif ($is_free) {
- $class = 'free';
- } else {
- $class = 'occupied';
- }
- $shifts_table .= '<td rowspan="' . $blocks . '" class="' . $class . '">';
- $shifts_table .= $shifts_row;
- $shifts_table .= "</td>";
- for ($j = 0; $j < $blocks && $i + $j < $maxshow; $j ++) {
- $todo[$rid][$i + $j] --;
- }
- }
- }
- }
- // fill up row with empty <td>
- while ($todo[$rid][$i] -- > 0) {
- $shifts_table .= '<td class="empty"></td>';
- }
- }
- $shifts_table .= "</tr>\n";
- }
- $shifts_table .= '</tbody></table></div>';
- } else {
- $shifts_table = [];
- foreach ($shifts as $shift) {
- $info = [];
- if ($_SESSION['user_shifts']['start_day'] != $_SESSION['user_shifts']['end_day']) {
- $info[] = date("Y-m-d", $shift['start']);
- }
- $info[] = date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']);
- if (count($_SESSION['user_shifts']['rooms']) > 1) {
- $info[] = Room_name_render([
- 'Name' => $shift['room_name'],
- 'RID' => $shift['RID']
- ]);
- }
-
- $shift_row = [
- 'info' => join('<br />', $info),
- 'entries' => '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>' . ($shift['title'] ? '<br />' . $shift['title'] : '')
- ];
-
- if (in_array('admin_shifts', $privileges)) {
- $shift_row['info'] .= ' ' . table_buttons([
- button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
- button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs')
- ]);
- }
- $shift_row['entries'] .= '<br />';
- $is_free = false;
- $shift_has_special_needs = 0 < sql_num_query("SELECT `id` FROM `NeededAngelTypes` WHERE `shift_id` = " . $shift['SID']);
- $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name`, `UserAngelTypes`.`user_id`
- FROM `NeededAngelTypes`
- JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`)
- LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "')
- 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 ";
- if (! empty($_SESSION['user_shifts']['types'])) {
- $query .= "AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") ";
- }
- $query .= "ORDER BY `AngelTypes`.`name`";
- $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 = [];
- $entry_nicks = [];
- $freeloader = 0;
- foreach ($entries as $entry) {
- if (in_array('user_shifts_admin', $privileges)) {
- $member = User_Nick_render($entry) . ' ' . table_buttons([
- button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], glyph('trash'), 'btn-xs')
- ]);
- } else {
- $member = User_Nick_render($entry);
- }
- if ($entry['freeloaded']) {
- $member = '<strike>' . $member . '</strike>';
- $freeloader ++;
- }
- $entry_list[] = $member;
- $entry_nicks[] = $entry['Nick'];
- }
- $angeltype['taken'] = count($entries) - $freeloader;
- $angeltype['angels'] = $entry_nicks;
-
- // do we need more angles of this type?
- 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;
-
- /* you cannot join if user already joined this shift */
- $user_may_join_shift &= ! $my_shift;
-
- // you cannot join if user is not of this angel type
- $user_may_join_shift &= isset($angeltype['user_id']);
-
- // you cannot join if you are not confirmed
- if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) {
- $user_may_join_shift &= isset($angeltype['confirm_user_id']);
- }
-
- // you can only join if the shift is in future or running
- $user_may_join_shift &= time() < $shift['start'];
-
- // User shift admins may join anybody in every shift
- $user_may_join_shift |= in_array('user_shifts_admin', $privileges);
- if ($user_may_join_shift) {
- $entry_list[] = '<a href="' . page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'] . '">' . $inner_text . ' &raquo;</a>';
- } else {
- if (time() > $shift['end']) {
- $entry_list[] = $inner_text . ' (vorbei)';
- } elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) {
- $entry_list[] = $inner_text . glyph("lock");
- } else {
- $entry_list[] = $inner_text . ' <a href="' . page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'] . '">' . sprintf(_('Become %s'), $angeltype['name']) . '</a>';
- }
- }
-
- unset($inner_text);
- $is_free = true;
- }
-
- $shift_row['entries'] .= '<b>' . $angeltype['name'] . ':</b> ';
- $shift_row['entries'] .= join(", ", $entry_list);
- $shift_row['entries'] .= '<br />';
- }
- if (in_array('user_shifts_admin', $privileges)) {
- $shift_row['entries'] .= '<a href="' . page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'] . '">' . _('Add more angels') . ' &raquo;</a>';
- }
- $shifts_table[] = $shift_row;
- $shift['angeltypes'] = $angeltypes;
- $ical_shifts[] = $shift;
- }
- }
- $shifts_table = table([
- 'info' => _("Time") . "/" . _("Room"),
- 'entries' => _("Entries")
- ], $shifts_table);
- }
-
if ($user['api_key'] == "") {
User_reset_api_key($user, false);
}
+ $filled = [
+ [
+ 'id' => '1',
+ 'name' => _("occupied")
+ ],
+ [
+ 'id' => '0',
+ 'name' => _("free")
+ ]
+ ];
+ $start_day = date("Y-m-d", $shiftsFilter->getStartTime());
+ $start_time = date("H:i", $shiftsFilter->getStartTime());
+ $end_day = date("Y-m-d", $shiftsFilter->getEndTime());
+ $end_time = date("H:i", $shiftsFilter->getEndTime());
+
+ $shiftCalendarRenderer = new ShiftCalendarRenderer($shifts, $shiftsFilter);
return page([
div('col-md-12', [
msg(),
template_render('../templates/user_shifts.html', [
'title' => shifts_title(),
- 'room_select' => make_select($rooms, $_SESSION['user_shifts']['rooms'], "rooms", _("Rooms")),
- 'start_select' => html_select_key("start_day", "start_day", array_combine($days, $days), $_SESSION['user_shifts']['start_day']),
- 'start_time' => $_SESSION['user_shifts']['start_time'],
- 'end_select' => html_select_key("end_day", "end_day", array_combine($days, $days), $_SESSION['user_shifts']['end_day']),
- 'end_time' => $_SESSION['user_shifts']['end_time'],
- 'type_select' => make_select($types, $_SESSION['user_shifts']['types'], "types", _("Angeltypes") . '<sup>1</sup>'),
- 'filled_select' => make_select($filled, $_SESSION['user_shifts']['filled'], "filled", _("Occupancy")),
- 'task_notice' => '<sup>1</sup>' . _("The tasks shown here are influenced by the preferences you defined in your settings!") . " <a href=\"" . page_link_to('angeltypes') . '&action=about' . "\">" . _("Description of the jobs.") . "</a>",
- 'new_style_checkbox' => '<label><input type="checkbox" name="new_style" value="1" ' . ($_SESSION['user_shifts']['new_style'] ? ' checked' : '') . '> ' . _("Use new style if possible") . '</label>',
- 'shifts_table' => msg() . $shifts_table,
+ 'room_select' => make_select($rooms, $shiftsFilter->getRooms(), "rooms", _("Rooms")),
+ 'start_select' => html_select_key("start_day", "start_day", array_combine($days, $days), $start_day),
+ 'start_time' => $start_time,
+ 'end_select' => html_select_key("end_day", "end_day", array_combine($days, $days), $end_day),
+ 'end_time' => $end_time,
+ 'type_select' => make_select($types, $shiftsFilter->getTypes(), "types", _("Angeltypes") . '<sup>1</sup>'),
+ 'filled_select' => make_select($filled, $shiftsFilter->getFilled(), "filled", _("Occupancy")),
+ 'task_notice' => '<sup>1</sup>' . _("The tasks shown here are influenced by the angeltypes you joined already!") . " <a href=\"" . page_link_to('angeltypes') . '&action=about' . "\">" . _("Description of the jobs.") . "</a>",
+ 'shifts_table' => msg() . $shiftCalendarRenderer->render(),
'ical_text' => '<h2>' . _("iCal export") . '</h2><p>' . sprintf(_("Export of shown shifts. <a href=\"%s\">iCal format</a> or <a href=\"%s\">JSON format</a> available (please keep secret, otherwise <a href=\"%s\">reset the api key</a>)."), page_link_to_absolute('ical') . '&key=' . $user['api_key'], page_link_to_absolute('shifts_json_export') . '&key=' . $user['api_key'], page_link_to('user_myshifts') . '&reset') . '</p>',
'filter' => _("Filter")
])
@@ -895,23 +179,6 @@ function view_user_shifts() {
]);
}
-function make_user_shifts_export_link($page, $key) {
- $link = "&start_day=" . $_SESSION['user_shifts']['start_day'];
- $link = "&start_time=" . $_SESSION['user_shifts']['start_time'];
- $link = "&end_day=" . $_SESSION['user_shifts']['end_day'];
- $link = "&end_time=" . $_SESSION['user_shifts']['end_time'];
- foreach ($_SESSION['user_shifts']['rooms'] as $room) {
- $link .= '&rooms[]=' . $room;
- }
- foreach ($_SESSION['user_shifts']['types'] as $type) {
- $link .= '&types[]=' . $type;
- }
- foreach ($_SESSION['user_shifts']['filled'] as $filled) {
- $link .= '&filled[]=' . $filled;
- }
- return page_link_to_absolute($page) . $link . '&export=user_shifts&key=' . $key;
-}
-
function get_ids_from_array($array) {
return $array["id"];
}