summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/controller/angeltypes_controller.php38
-rw-r--r--includes/controller/event_config_controller.php3
-rw-r--r--includes/controller/rooms_controller.php88
-rw-r--r--includes/controller/shift_entries_controller.php168
-rw-r--r--includes/controller/shifts_controller.php186
-rw-r--r--includes/controller/shifttypes_controller.php6
-rw-r--r--includes/controller/user_angeltypes_controller.php104
-rw-r--r--includes/controller/user_driver_licenses_controller.php59
-rw-r--r--includes/controller/users_controller.php6
-rw-r--r--includes/engelsystem_provider.php8
-rw-r--r--includes/model/AngelType_model.php27
-rw-r--r--includes/model/EventConfig_model.php1
-rw-r--r--includes/model/NeededAngelTypes_model.php68
-rw-r--r--includes/model/Room_model.php11
-rw-r--r--includes/model/ShiftEntry_model.php6
-rw-r--r--includes/model/ShiftSignupState.php98
-rw-r--r--includes/model/ShiftTypes_model.php2
-rw-r--r--includes/model/ShiftsFilter.php112
-rw-r--r--includes/model/Shifts_model.php280
-rw-r--r--includes/model/UserAngelTypes_model.php63
-rw-r--r--includes/model/UserDriverLicenses_model.php19
-rw-r--r--includes/model/User_model.php88
-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.php355
-rw-r--r--includes/pages/user_shifts.php971
-rw-r--r--includes/sys_form.php256
-rw-r--r--includes/sys_menu.php32
-rw-r--r--includes/sys_page.php94
-rw-r--r--includes/sys_template.php267
-rw-r--r--includes/view/AngelTypes_view.php155
-rw-r--r--includes/view/Rooms_view.php11
-rw-r--r--includes/view/ShiftCalendarLane.php63
-rw-r--r--includes/view/ShiftCalendarRenderer.php240
-rw-r--r--includes/view/ShiftCalendarShiftRenderer.php181
-rw-r--r--includes/view/ShiftsFilterRenderer.php69
-rw-r--r--includes/view/Shifts_view.php6
-rw-r--r--includes/view/UserAngelTypes_view.php8
-rw-r--r--includes/view/UserDriverLicenses_view.php2
-rw-r--r--includes/view/User_view.php88
50 files changed, 2614 insertions, 1845 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
index cb2bb2fb..548cf3e7 100644
--- a/includes/controller/angeltypes_controller.php
+++ b/includes/controller/angeltypes_controller.php
@@ -50,9 +50,6 @@ function angeltypes_about_controller() {
} else {
$angeltypes = AngelTypes();
}
- if ($angeltypes === false) {
- engelsystem_error("Unable to load angeltypes.");
- }
return [
_("Teams/Job description"),
@@ -71,9 +68,6 @@ function angeltype_delete_controller() {
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
redirect(page_link_to('angeltypes'));
}
@@ -109,9 +103,6 @@ function angeltype_edit_controller() {
if (isset($_REQUEST['angeltype_id'])) {
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
redirect(page_link_to('angeltypes'));
}
@@ -121,7 +112,7 @@ function angeltype_edit_controller() {
$description = $angeltype['description'];
$requires_driver_license = $angeltype['requires_driver_license'];
- if (! User_is_AngelType_coordinator($user, $angeltype)) {
+ if (! User_is_AngelType_supporter($user, $angeltype)) {
redirect(page_link_to('angeltypes'));
}
} else {
@@ -130,13 +121,13 @@ function angeltype_edit_controller() {
}
}
- // In coordinator mode only allow to modify description
- $coordinator_mode = ! in_array('admin_angel_types', $privileges);
+ // In supporter mode only allow to modify description
+ $supporter_mode = ! in_array('admin_angel_types', $privileges);
if (isset($_REQUEST['submit'])) {
$valid = true;
- if (! $coordinator_mode) {
+ if (! $supporter_mode) {
if (isset($_REQUEST['name'])) {
$result = AngelType_validate_name($_REQUEST['name'], $angeltype);
$name = $result->getValue();
@@ -177,7 +168,7 @@ function angeltype_edit_controller() {
return [
sprintf(_("Edit %s"), $name),
- AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license)
+ AngelType_edit_view($name, $restricted, $description, $supporter_mode, $requires_driver_license)
];
}
@@ -196,23 +187,12 @@ function angeltype_controller() {
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
redirect(page_link_to('angeltypes'));
}
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype === false) {
- engelsystem_error("Unable to load user angeltype.");
- }
-
$user_driver_license = UserDriverLicense($user['UID']);
- if ($user_driver_license === false) {
- engelsystem_error("Unable to load user driver license.");
- }
-
$members = Users_by_angeltype($angeltype);
if ($members === false) {
engelsystem_error("Unable to load members.");
@@ -220,7 +200,7 @@ function angeltype_controller() {
return [
sprintf(_("Team %s"), $angeltype['name']),
- AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator'], $user_driver_license, $user)
+ AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['supporter'], in_array('admin_angel_types', $privileges), $user_angeltype['supporter'], $user_driver_license, $user)
];
}
@@ -235,9 +215,6 @@ function angeltypes_list_controller() {
}
$angeltypes = AngelTypes_with_user($user);
- if ($angeltypes === false) {
- engelsystem_error("Unable to load angeltypes.");
- }
foreach ($angeltypes as &$angeltype) {
$actions = [
@@ -277,9 +254,6 @@ function load_angeltype() {
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php
index a9709d38..4f07fe4c 100644
--- a/includes/controller/event_config_controller.php
+++ b/includes/controller/event_config_controller.php
@@ -19,9 +19,6 @@ function event_config_edit_controller() {
$teardown_end_date = null;
$event_config = EventConfig();
- if ($event_config === false) {
- engelsystem_error('Unable to load event config.');
- }
if ($event_config != null) {
$event_name = $event_config['event_name'];
$buildup_start_date = $event_config['buildup_start_date'];
diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php
index 5d55e1b7..0e8560d5 100644
--- a/includes/controller/rooms_controller.php
+++ b/includes/controller/rooms_controller.php
@@ -1,7 +1,95 @@
<?php
+use Engelsystem\ShiftsFilterRenderer;
+use Engelsystem\ShiftsFilter;
+use Engelsystem\ShiftCalendarRenderer;
+
+/**
+ * Room controllers for managing everything room related.
+ */
+
+/**
+ * View a room with its shifts.
+ */
+function room_controller() {
+ global $privileges, $user;
+
+ if (! in_array('view_rooms', $privileges)) {
+ redirect(page_link_to());
+ }
+
+ $room = load_room();
+ $all_shifts = Shifts_by_room($room);
+ $days = [];
+ foreach ($all_shifts as $shift) {
+ $day = date("Y-m-d", $shift['start']);
+ if (! in_array($day, $days)) {
+ $days[] = $day;
+ }
+ }
+
+ $shiftsFilter = new ShiftsFilter(true, [
+ $room['RID']
+ ], AngelType_ids());
+ $selected_day = date("Y-m-d");
+ if (! empty($days)) {
+ $selected_day = $days[0];
+ }
+ if (isset($_REQUEST['shifts_filter_day'])) {
+ $selected_day = $_REQUEST['shifts_filter_day'];
+ }
+ $shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $selected_day . ' 00:00'));
+ $shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $selected_day . ' 23:59'));
+
+ $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
+ $shiftsFilterRenderer->enableDaySelection($days);
+
+ $shifts = Shifts_by_ShiftsFilter($shiftsFilter, $user);
+
+ return [
+ $room['Name'],
+ Room_view($room, $shiftsFilterRenderer, new ShiftCalendarRenderer($shifts, $shiftsFilter))
+ ];
+}
+
+/**
+ * Dispatch different room actions.
+ */
+function rooms_controller() {
+ if (! isset($_REQUEST['action'])) {
+ $_REQUEST['action'] = 'list';
+ }
+
+ switch ($_REQUEST['action']) {
+ default:
+ case 'list':
+ redirect(page_link_to('admin_rooms'));
+ case 'view':
+ return room_controller();
+ }
+}
function room_link($room) {
+ return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
+}
+
+function room_edit_link($room) {
return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
}
+/**
+ * Loads room by request param room_id
+ */
+function load_room() {
+ if (! test_request_int('room_id')) {
+ redirect(page_link_to());
+ }
+
+ $room = Room($_REQUEST['room_id']);
+ if ($room == null) {
+ redirect(page_link_to());
+ }
+
+ return $room;
+}
+
?> \ No newline at end of file
diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php
new file mode 100644
index 00000000..1b1a4d02
--- /dev/null
+++ b/includes/controller/shift_entries_controller.php
@@ -0,0 +1,168 @@
+<?php
+
+/**
+ * Sign up for a shift.
+ */
+function shift_entry_add_controller() {
+ global $privileges, $user;
+
+ if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) {
+ $shift_id = $_REQUEST['shift_id'];
+ } else {
+ redirect(page_link_to('user_shifts'));
+ }
+
+ // 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'];
+ }
+
+ $shift = Shift($shift_id);
+ $shift['Name'] = $room_array[$shift['RID']];
+ 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];
+
+ $shift_signup_allowed = Shift_signup_allowed(User($user_id), $shift, $type);
+ if (! $shift_signup_allowed->isSignupAllowed()) {
+ 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'];
+ }
+ $angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
+ } else {
+ $user_text = User_Nick_render($user);
+ $angeltype_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'], $angeltype_select, "", false, null, in_array('user_shifts_admin', $privileges));
+}
+
+/**
+ * Remove somebody from a shift.
+ */
+function shift_entry_delete_controller() {
+ global $privileges;
+
+ if (! in_array('user_shifts_admin', $privileges)) {
+ redirect(page_link_to('user_shifts'));
+ }
+
+ if (! isset($_REQUEST['entry_id']) || ! test_request_int('entry_id')) {
+ redirect(page_link_to('user_shifts'));
+ }
+ $entry_id = $_REQUEST['entry_id'];
+
+ $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'));
+}
+
+?> \ No newline at end of file
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index b29a819f..be0cf127 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -12,6 +12,172 @@ function shift_edit_link($shift) {
return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'];
}
+/**
+ * Edit a single shift.
+ */
+function shift_edit_controller() {
+ global $privileges;
+
+ // Schicht bearbeiten
+ $msg = "";
+ $valid = true;
+
+ if (! in_array('admin_shifts', $privileges)) {
+ redirect(page_link_to('user_shifts'));
+ }
+
+ if (! isset($_REQUEST['edit_shift']) || ! test_request_int('edit_shift')) {
+ redirect(page_link_to('user_shifts'));
+ }
+ $shift_id = $_REQUEST['edit_shift'];
+
+ $shift = Shift($shift_id);
+
+ $room = select_array(Rooms(), 'RID', 'Name');
+ $angeltypes = select_array(AngelTypes(), 'id', 'name');
+ $shifttypes = select_array(ShiftTypes(), 'id', 'name');
+
+ $needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'id', 'count');
+ foreach (array_keys($angeltypes) as $angeltype_id) {
+ if (! isset($needed_angel_types[$angeltype_id])) {
+ $needed_angel_types[$angeltype_id] = 0;
+ }
+ }
+
+ $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[$_REQUEST['rid']])) {
+ $rid = $_REQUEST['rid'];
+ } else {
+ $valid = false;
+ $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 = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
+ $start = $tmp;
+ } else {
+ $valid = false;
+ $msg .= error(_("Please enter a valid starting time for the shifts."), true);
+ }
+
+ if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
+ $end = $tmp;
+ } 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 as $needed_angeltype_id => $needed_angeltype_name) {
+ if (isset($_REQUEST['type_' . $needed_angeltype_id]) && test_request_int('type_' . $needed_angeltype_id)) {
+ $needed_angel_types[$needed_angeltype_id] = trim($_REQUEST['type_' . $needed_angeltype_id]);
+ } else {
+ $valid = false;
+ $msg .= error(sprintf(_("Please check your input for needed angels of type %s."), $needed_angeltype_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.');
+ }
+ NeededAngelTypes_delete_by_shift($shift_id);
+ $needed_angel_types_info = [];
+ foreach ($needed_angel_types as $type_id => $count) {
+ NeededAngelType_add($shift_id, $type_id, null, $count);
+ $needed_angel_types_info[] = $angeltypes[$type_id] . ": " . $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_spinner = "";
+ foreach ($angeltypes as $angeltype_id => $angeltype_name) {
+ $angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name, $needed_angel_types[$angeltype_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, $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_spinner,
+ form_submit('submit', _("Save"))
+ ])
+ ]);
+}
+
+function shift_delete_controller() {
+ global $privileges;
+
+ if (! in_array('user_shifts_admin', $privileges)) {
+ redirect(page_link_to('user_shifts'));
+ }
+
+ // 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'])) {
+ redirect(page_link_to('user_shifts'));
+ }
+ $shift_id = $_REQUEST['delete_shift'];
+
+ $shift = Shift($shift_id);
+ if ($shift == null) {
+ redirect(page_link_to('user_shifts'));
+ }
+
+ // Schicht löschen bestätigt
+ if (isset($_REQUEST['delete'])) {
+ Shift_delete($shift_id);
+
+ 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>'
+ ]);
+}
+
function shift_controller() {
global $user, $privileges;
@@ -24,33 +190,15 @@ function shift_controller() {
}
$shift = Shift($_REQUEST['shift_id']);
- if ($shift === false) {
- engelsystem_error('Unable to load shift.');
- }
if ($shift == null) {
- error(_('Shift could not be found.'));
+ error(_("Shift could not be found."));
redirect(page_link_to('user_shifts'));
}
$shifttype = ShiftType($shift['shifttype_id']);
- if ($shifttype === false || $shifttype == null) {
- engelsystem_error('Unable to load shift type.');
- }
-
$room = Room($shift['RID']);
- if ($room === false || $room == null) {
- engelsystem_error('Unable to load room.');
- }
-
$angeltypes = AngelTypes();
- if ($angeltypes === false) {
- engelsystem_error('Unable to load angeltypes.');
- }
-
$user_shifts = Shifts_by_user($user);
- if ($user_shifts === false) {
- engelsystem_error('Unable to load users shifts.');
- }
$signed_up = false;
foreach ($user_shifts as $user_shift) {
diff --git a/includes/controller/shifttypes_controller.php b/includes/controller/shifttypes_controller.php
index 88feffed..456e39ae 100644
--- a/includes/controller/shifttypes_controller.php
+++ b/includes/controller/shifttypes_controller.php
@@ -48,9 +48,6 @@ function shifttype_edit_controller() {
$description = "";
$angeltypes = AngelTypes();
- if ($angeltypes === false) {
- engelsystem_error("Unable to load angel types.");
- }
if (isset($_REQUEST['shifttype_id'])) {
$shifttype = ShiftType($_REQUEST['shifttype_id']);
@@ -128,9 +125,6 @@ function shifttype_controller() {
$angeltype = null;
if ($shifttype['angeltype_id'] != null) {
$angeltype = AngelType($shifttype['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error('Unable to load angeltype.');
- }
}
return [
diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php
index 418f21f9..f58187b2 100644
--- a/includes/controller/user_angeltypes_controller.php
+++ b/includes/controller/user_angeltypes_controller.php
@@ -1,15 +1,12 @@
<?php
/**
- * Display a hint for team/angeltype coordinators if there are unconfirmed users for his angeltype.
+ * Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype.
*/
function user_angeltypes_unconfirmed_hint() {
global $user;
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user);
- if ($unconfirmed_user_angeltypes === false) {
- engelsystem_error("Unable to load user angeltypes.");
- }
if (count($unconfirmed_user_angeltypes) == 0) {
return '';
}
@@ -34,24 +31,18 @@ function user_angeltypes_delete_all_controller() {
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
- if (! User_is_AngelType_coordinator($user, $angeltype)) {
+ if (! User_is_AngelType_supporter($user, $angeltype)) {
error(_("You are not allowed to delete all users for this angeltype."));
redirect(page_link_to('angeltypes'));
}
if (isset($_REQUEST['confirmed'])) {
- $result = UserAngelTypes_delete_all($angeltype['id']);
- if ($result === false) {
- engelsystem_error("Unable to confirm all users.");
- }
+ UserAngelTypes_delete_all($angeltype['id']);
engelsystem_log(sprintf("Denied all users for angeltype %s", AngelType_name_render($angeltype)));
success(sprintf(_("Denied all users for angeltype %s."), AngelType_name_render($angeltype)));
@@ -76,33 +67,24 @@ function user_angeltypes_confirm_all_controller() {
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype === false) {
- engelsystem_error("Unable to load user angeltype.");
- }
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
- if (! in_array('admin_user_angeltypes', $privileges) && ! $user_angeltype['coordinator']) {
+ if (! in_array('admin_user_angeltypes', $privileges) && ! $user_angeltype['supporter']) {
error(_("You are not allowed to confirm all users for this angeltype."));
redirect(page_link_to('angeltypes'));
}
if (isset($_REQUEST['confirmed'])) {
- $result = UserAngelTypes_confirm_all($angeltype['id'], $user);
- if ($result === false) {
- engelsystem_error("Unable to confirm all users.");
- }
+ UserAngelTypes_confirm_all($angeltype['id'], $user);
engelsystem_log(sprintf("Confirmed all users for angeltype %s", AngelType_name_render($angeltype)));
success(sprintf(_("Confirmed all users for angeltype %s."), AngelType_name_render($angeltype)));
@@ -127,32 +109,23 @@ function user_angeltype_confirm_controller() {
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype === false) {
- engelsystem_error("Unable to load user angeltype.");
- }
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
- if (! User_is_AngelType_coordinator($user, $angeltype)) {
+ if (! User_is_AngelType_supporter($user, $angeltype)) {
error(_("You are not allowed to confirm this users angeltype."));
redirect(page_link_to('angeltypes'));
}
$user_source = User($user_angeltype['user_id']);
- if ($user_source === false) {
- engelsystem_error("Unable to load user.");
- }
if ($user_source == null) {
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -187,33 +160,24 @@ function user_angeltype_delete_controller() {
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype === false) {
- engelsystem_error("Unable to load user angeltype.");
- }
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$user_source = User($user_angeltype['user_id']);
- if ($user_source === false) {
- engelsystem_error("Unable to load user.");
- }
if ($user_source == null) {
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
}
- if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_coordinator($user, $angeltype)) {
+ if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_supporter($user, $angeltype)) {
error(_("You are not allowed to delete this users angeltype."));
redirect(page_link_to('angeltypes'));
}
@@ -244,7 +208,7 @@ function user_angeltype_update_controller() {
global $privileges;
if (! in_array('admin_angel_types', $privileges)) {
- error(_("You are not allowed to set coordinator rights."));
+ error(_("You are not allowed to set supporter rights."));
redirect(page_link_to('angeltypes'));
}
@@ -253,47 +217,35 @@ function user_angeltype_update_controller() {
redirect(page_link_to('angeltypes'));
}
- if (isset($_REQUEST['coordinator']) && preg_match("/^[01]$/", $_REQUEST['coordinator'])) {
- $coordinator = $_REQUEST['coordinator'] == "1";
+ if (isset($_REQUEST['supporter']) && preg_match("/^[01]$/", $_REQUEST['supporter'])) {
+ $supporter = $_REQUEST['supporter'] == "1";
} else {
- error(_("No coordinator update given."));
+ error(_("No supporter update given."));
redirect(page_link_to('angeltypes'));
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype === false) {
- engelsystem_error("Unable to load user angeltype.");
- }
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype === false) {
- engelsystem_error("Unable to load angeltype.");
- }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$user_source = User($user_angeltype['user_id']);
- if ($user_source === false) {
- engelsystem_error("Unable to load user.");
- }
if ($user_source == null) {
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
}
if (isset($_REQUEST['confirmed'])) {
- $result = UserAngelType_update($user_angeltype['id'], $coordinator);
- if ($result === false) {
- engelsystem_error("Unable to update coordinator rights.");
- }
+ UserAngelType_update($user_angeltype['id'], $supporter);
- $success_message = sprintf($coordinator ? _("Added coordinator rights for %s to %s.") : _("Removed coordinator rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source));
+ $success_message = sprintf($supporter ? _("Added supporter rights for %s to %s.") : _("Removed supporter rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source));
engelsystem_log($success_message);
success($success_message);
@@ -301,13 +253,13 @@ function user_angeltype_update_controller() {
}
return [
- $coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"),
- UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $coordinator)
+ $supporter ? _("Add supporter rights") : _("Remove supporter rights"),
+ UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter)
];
}
/**
- * User joining an Angeltype (Or Coordinator doing this for him).
+ * User joining an Angeltype (Or supporter doing this for him).
*/
function user_angeltype_add_controller() {
global $user;
@@ -315,7 +267,7 @@ function user_angeltype_add_controller() {
$angeltype = load_angeltype();
// User is joining by itself
- if (! User_is_AngelType_coordinator($user, $angeltype)) {
+ if (! User_is_AngelType_supporter($user, $angeltype)) {
return user_angeltype_join_controller($angeltype);
}
@@ -326,26 +278,17 @@ function user_angeltype_add_controller() {
// Load possible users, that are not in the angeltype already
$users_source = Users_by_angeltype_inverted($angeltype);
- if ($users_source === false) {
- engelsystem_error("Unable to load users.");
- }
if (isset($_REQUEST['submit'])) {
$user_source = load_user();
if (! UserAngelType_exists($user_source, $angeltype)) {
$user_angeltype_id = UserAngelType_create($user_source, $angeltype);
- if ($user_angeltype_id === false) {
- engelsystem_error("Unable to create user angeltype.");
- }
engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), AngelType_name_render($angeltype)));
success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
- $result = UserAngelType_confirm($user_angeltype_id, $user_source);
- if ($result === false) {
- engelsystem_error("Unable to confirm user angeltype.");
- }
+ UserAngelType_confirm($user_angeltype_id, $user_source);
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
@@ -365,9 +308,6 @@ function user_angeltype_join_controller($angeltype) {
global $user, $privileges;
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype === false) {
- engelsystem_error("Unable to load user angeltype.");
- }
if ($user_angeltype != null) {
error(sprintf(_("You are already a %s."), $angeltype['name']));
redirect(page_link_to('angeltypes'));
@@ -375,19 +315,13 @@ function user_angeltype_join_controller($angeltype) {
if (isset($_REQUEST['confirmed'])) {
$user_angeltype_id = UserAngelType_create($user, $angeltype);
- if ($user_angeltype_id === false) {
- engelsystem_error("Unable to create user angeltype.");
- }
$success_message = sprintf(_("You joined %s."), $angeltype['name']);
engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
success($success_message);
if (in_array('admin_user_angeltypes', $privileges)) {
- $result = UserAngelType_confirm($user_angeltype_id, $user);
- if ($result === false) {
- engelsystem_error("Unable to confirm user angeltype.");
- }
+ UserAngelType_confirm($user_angeltype_id, $user);
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
}
diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php
index 5c629777..a76d5507 100644
--- a/includes/controller/user_driver_licenses_controller.php
+++ b/includes/controller/user_driver_licenses_controller.php
@@ -7,26 +7,19 @@ function user_driver_license_required_hint() {
global $user;
$angeltypes = User_angeltypes($user);
- if ($angeltypes === false) {
- engelsystem_error("Unable to load user angeltypes.");
- }
$user_driver_license = UserDriverLicense($user['UID']);
- if ($user_driver_license === false) {
- engelsystem_error("Unable to load user driver license.");
+
+ // User has already entered data, no hint needed.
+ if ($user_driver_license != null) {
+ return '';
}
- $driving_license_information_required = false;
foreach ($angeltypes as $angeltype) {
if ($angeltype['requires_driver_license']) {
- $driving_license_information_required = true;
- break;
+ return info(sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>'), true);
}
}
- if ($driving_license_information_required && $user_driver_license == null) {
- return info(sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>'), true);
- }
-
return '';
}
@@ -64,26 +57,34 @@ function user_driver_license_edit_link($user = null) {
}
/**
- * Edit a users driver license information.
+ * Loads the user for the driver license.
*/
-function user_driver_license_edit_controller() {
- global $privileges, $user;
+function user_driver_license_load_user() {
+ global $user;
$user_source = $user;
if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']);
- if ($user_source === false) {
- engelsystem_error('Unable to load angeltype.');
- }
if ($user_source == null) {
redirect(user_driver_license_edit_link());
}
-
- // only privilege admin_user can edit other users driver license information
- if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) {
- redirect(user_driver_license_edit_link());
- }
+ }
+
+ return $user_source;
+}
+
+/**
+ * Edit a users driver license information.
+ */
+function user_driver_license_edit_controller() {
+ global $privileges, $user;
+
+ $user_source = user_driver_license_load_user();
+
+ // only privilege admin_user can edit other users driver license information
+ if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) {
+ redirect(user_driver_license_edit_link());
}
$wants_to_drive = false;
@@ -95,9 +96,6 @@ function user_driver_license_edit_controller() {
$has_license_forklift = false;
$user_driver_license = UserDriverLicense($user_source['UID']);
- if ($user_driver_license === false) {
- engelsystem_error('Unable to load user driver license.');
- }
if ($user_driver_license != null) {
$wants_to_drive = true;
$has_car = $user_driver_license['has_car'];
@@ -125,10 +123,7 @@ function user_driver_license_edit_controller() {
if ($valid) {
if (! $wants_to_drive && $user_driver_license != null) {
- $result = UserDriverLicenses_delete($user_source['UID']);
- if ($result === false) {
- engelsystem_error("Unable to remove user driver license information");
- }
+ UserDriverLicenses_delete($user_source['UID']);
engelsystem_log("Driver license information removed.");
success(_("Your driver license information has been removed."));
} else {
@@ -138,10 +133,6 @@ function user_driver_license_edit_controller() {
} else {
$result = UserDriverLicenses_update($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift);
}
-
- if ($result === false) {
- engelsystem_error("Unable to save user driver license information.");
- }
engelsystem_log("Driver license information updated.");
}
success(_("Your driver license information has been saved."));
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index 9ead4bca..beaf2538 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -142,17 +142,13 @@ function user_edit_vouchers_controller() {
function user_controller() {
global $privileges, $user;
+ $user_source = $user;
if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']);
- if ($user_source === false) {
- engelsystem_error("Unable to load user.");
- }
if ($user_source == null) {
error(_("User not found."));
redirect('?');
}
- } else {
- $user_source = $user;
}
$shifts = Shifts_by_user($user_source);
diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php
index 84a73275..84383bba 100644
--- a/includes/engelsystem_provider.php
+++ b/includes/engelsystem_provider.php
@@ -5,6 +5,7 @@
require_once realpath(__DIR__ . '/../includes/mysqli_provider.php');
require_once realpath(__DIR__ . '/../includes/sys_auth.php');
+require_once realpath(__DIR__ . '/../includes/sys_form.php');
require_once realpath(__DIR__ . '/../includes/sys_log.php');
require_once realpath(__DIR__ . '/../includes/sys_menu.php');
require_once realpath(__DIR__ . '/../includes/sys_page.php');
@@ -18,6 +19,8 @@ require_once realpath(__DIR__ . '/../includes/model/NeededAngelTypes_model.php')
require_once realpath(__DIR__ . '/../includes/model/Room_model.php');
require_once realpath(__DIR__ . '/../includes/model/ShiftEntry_model.php');
require_once realpath(__DIR__ . '/../includes/model/Shifts_model.php');
+require_once realpath(__DIR__ . '/../includes/model/ShiftsFilter.php');
+require_once realpath(__DIR__ . '/../includes/model/ShiftSignupState.php');
require_once realpath(__DIR__ . '/../includes/model/ShiftTypes_model.php');
require_once realpath(__DIR__ . '/../includes/model/UserAngelTypes_model.php');
require_once realpath(__DIR__ . '/../includes/model/UserDriverLicenses_model.php');
@@ -28,6 +31,10 @@ require_once realpath(__DIR__ . '/../includes/view/AngelTypes_view.php');
require_once realpath(__DIR__ . '/../includes/view/EventConfig_view.php');
require_once realpath(__DIR__ . '/../includes/view/Questions_view.php');
require_once realpath(__DIR__ . '/../includes/view/Rooms_view.php');
+require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarLane.php');
+require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarRenderer.php');
+require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarShiftRenderer.php');
+require_once realpath(__DIR__ . '/../includes/view/ShiftsFilterRenderer.php');
require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php');
@@ -38,6 +45,7 @@ require_once realpath(__DIR__ . '/../includes/view/User_view.php');
require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/event_config_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/rooms_controller.php');
+require_once realpath(__DIR__ . '/../includes/controller/shift_entries_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/users_controller.php');
diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php
index 73b746f0..fa81349d 100644
--- a/includes/model/AngelType_model.php
+++ b/includes/model/AngelType_model.php
@@ -91,39 +91,44 @@ function AngelType_validate_name($name, $angeltype) {
* @param User $user
*/
function AngelTypes_with_user($user) {
- return sql_select("
+ $result = sql_select("
SELECT `AngelTypes`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`,
- `UserAngelTypes`.`coordinator`
+ `UserAngelTypes`.`supporter`
FROM `AngelTypes`
LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id`
AND `UserAngelTypes`.`user_id`=" . $user['UID'] . "
ORDER BY `name`");
+ if ($result === false) {
+ engelsystem_error("Unable to load angeltypes.");
+ }
+ return $result;
}
/**
* Returns all angeltypes.
*/
function AngelTypes() {
- return sql_select("
+ $result = sql_select("
SELECT *
FROM `AngelTypes`
ORDER BY `name`");
+ if ($result === false) {
+ engelsystem_error("Unable to load angeltypes.");
+ }
+ return $result;
}
/**
* Returns AngelType id array
*/
function AngelType_ids() {
- $angelType_source = sql_select("SELECT `id` FROM `AngelTypes`");
- if ($angelType_source === false) {
- return false;
- }
- if (count($angelType_source) > 0) {
- return $angelType_source;
+ $result = sql_select("SELECT `id` FROM `AngelTypes`");
+ if ($result === false) {
+ engelsystem_error("Unable to load angeltypes.");
}
- return null;
+ return select_array($result, 'id', 'id');
}
/**
@@ -135,7 +140,7 @@ function AngelType_ids() {
function AngelType($angeltype_id) {
$angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "' LIMIT 1");
if ($angelType_source === false) {
- return false;
+ engelsystem_error("Unable to load angeltype.");
}
if (count($angelType_source) > 0) {
return $angelType_source[0];
diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php
index ac8d5e72..de5073d0 100644
--- a/includes/model/EventConfig_model.php
+++ b/includes/model/EventConfig_model.php
@@ -6,6 +6,7 @@
function EventConfig() {
$event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1");
if ($event_config === false) {
+ engelsystem_error("Unable to load event config.");
return false;
}
if (count($event_config) > 0) {
diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php
index 96ceca83..ba24c6bd 100644
--- a/includes/model/NeededAngelTypes_model.php
+++ b/includes/model/NeededAngelTypes_model.php
@@ -1,13 +1,63 @@
<?php
/**
+ * Entity needed angeltypes describes how many angels of given type are needed for a shift or in a room.
+ */
+
+/**
+ * Insert a new needed angel type.
+ *
+ * @param int $shift_id
+ * The shift. Can be null, but then a room_id must be given.
+ * @param int $angeltype_id
+ * The angeltype
+ * @param int $room_id
+ * The room. Can be null, but then a shift_id must be given.
+ * @param int $count
+ * How many angels are needed?
+ */
+function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count) {
+ $result = sql_query("
+ INSERT INTO `NeededAngelTypes` SET
+ `shift_id`=" . sql_null($shift_id) . ",
+ `angel_type_id`='" . sql_escape($angeltype_id) . "',
+ `room_id`=" . sql_null($room_id) . ",
+ `count`='" . sql_escape($count) . "'");
+ if ($result === false) {
+ return false;
+ }
+ return sql_id();
+}
+
+/**
+ * Deletes all needed angel types from given shift.
+ *
+ * @param int $shift_id
+ * id of the shift
+ */
+function NeededAngelTypes_delete_by_shift($shift_id) {
+ return sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`='" . sql_escape($shift_id) . "'");
+}
+
+/**
+ * Deletes all needed angel types from given room.
+ *
+ * @param int $room_id
+ * id of the room
+ */
+function NeededAngelTypes_delete_by_room($room_id) {
+ return sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
+}
+
+/**
* Returns all needed angeltypes and already taken needs.
*
- * @param shiftID id of shift
+ * @param int $shiftID
+ * id of shift
*/
function NeededAngelTypes_by_shift($shiftId) {
$needed_angeltypes_source = sql_select("
- SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted`
+ SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`
FROM `NeededAngelTypes`
JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id`
WHERE `shift_id`='" . sql_escape($shiftId) . "'
@@ -15,7 +65,7 @@ function NeededAngelTypes_by_shift($shiftId) {
ORDER BY `room_id` DESC
");
if ($needed_angeltypes_source === false) {
- return false;
+ engelsystem_error("Unable to load needed angeltypes.");
}
// Use settings from room
@@ -30,18 +80,22 @@ function NeededAngelTypes_by_shift($shiftId) {
ORDER BY `room_id` DESC
");
if ($needed_angeltypes_source === false) {
- return false;
+ engelsystem_error("Unable to load needed angeltypes.");
}
}
$needed_angeltypes = [];
foreach ($needed_angeltypes_source as $angeltype) {
$shift_entries = ShiftEntries_by_shift_and_angeltype($shiftId, $angeltype['angel_type_id']);
- if ($shift_entries === false) {
- return false;
+
+ $angeltype['taken'] = 0;
+ foreach($shift_entries as $shift_entry) {
+ if($shift_entry['freeloaded'] == 0) {
+ $angeltype['taken']++;
+ }
}
- $angeltype['taken'] = count($shift_entries);
+ $angeltype['shift_entries'] = $shift_entries;
$needed_angeltypes[] = $angeltype;
}
diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php
index 4d03260a..6b6e269e 100644
--- a/includes/model/Room_model.php
+++ b/includes/model/Room_model.php
@@ -1,8 +1,17 @@
<?php
/**
+ * returns a list of rooms.
+ * @param boolean $show_all returns also hidden rooms when true
+ */
+function Rooms($show_all = false) {
+ return sql_select("SELECT * FROM `Room`" . ($show_all ? "" : " WHERE `show`='Y'") . " ORDER BY `Name`");
+}
+
+/**
* Delete a room
- * @param int $room_id
+ *
+ * @param int $room_id
*/
function Room_delete($room_id) {
return sql_query("DELETE FROM `Room` WHERE `RID`=" . sql_escape($room_id));
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index 425b92e8..63127bc7 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -110,12 +110,16 @@ function ShiftEntries_finished_by_user($user) {
* @param int $angeltype_id
*/
function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) {
- return sql_select("
+ $result = sql_select("
SELECT *
FROM `ShiftEntry`
WHERE `SID`=" . sql_escape($shift_id) . "
AND `TID`=" . sql_escape($angeltype_id) . "
");
+ if ($result === false) {
+ engelsystem_error("Unable to load shift entries.");
+ }
+ return $result;
}
/**
diff --git a/includes/model/ShiftSignupState.php b/includes/model/ShiftSignupState.php
new file mode 100644
index 00000000..f9226375
--- /dev/null
+++ b/includes/model/ShiftSignupState.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Engelsystem;
+
+/**
+ * BO to represent if there are free slots on a shift for a given angeltype
+ * and if signup for a given user is possible (or not, because of collisions, etc.)
+ */
+class ShiftSignupState {
+
+ /**
+ * Shift has free places
+ */
+ const FREE = 'FREE';
+
+ /**
+ * Shift collides with users shifts
+ */
+ const COLLIDES = 'COLLIDES';
+
+ /**
+ * User cannot join because of a restricted angeltype or user is not in the angeltype
+ */
+ const ANGELTYPE = 'ANGELTYPE';
+
+ /**
+ * Shift is full
+ */
+ const OCCUPIED = 'OCCUPIED';
+
+ /**
+ * User is admin and can do what he wants.
+ */
+ const ADMIN = 'ADMIN';
+
+ /**
+ * Shift has already ended, no signup
+ */
+ const SHIFT_ENDED = 'SHIFT_ENDED';
+
+ /**
+ * User is already signed up
+ */
+ const SIGNED_UP = 'SIGNED_UP';
+
+ private $state;
+
+ private $freeEntries;
+
+ public function __construct($state, $free_entries) {
+ $this->state = $state;
+ $this->freeEntries = $free_entries;
+ }
+
+ /**
+ * Combine this state with another state from the same shift.
+ *
+ * @param ShiftSignupState $shiftSignupState
+ * The other state to combine
+ */
+ public function combineWith(ShiftSignupState $shiftSignupState) {
+ $this->freeEntries += $shiftSignupState->getFreeEntries();
+
+ switch ($this->state) {
+ case ShiftSignupState::ANGELTYPE:
+ case ShiftSignupState::OCCUPIED:
+ $this->state = $shiftSignupState->getState();
+ }
+ }
+
+ /**
+ * Returns true, if signup is allowed
+ */
+ public function isSignupAllowed() {
+ switch ($this->state) {
+ case ShiftSignupState::FREE:
+ case ShiftSignupState::ADMIN:
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return the shift signup state
+ */
+ public function getState() {
+ return $this->state;
+ }
+
+ /**
+ * How many places are free in this shift for the angeltype?
+ */
+ public function getFreeEntries() {
+ return $this->freeEntries;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php
index a9cf77bd..89704a65 100644
--- a/includes/model/ShiftTypes_model.php
+++ b/includes/model/ShiftTypes_model.php
@@ -51,7 +51,7 @@ function ShiftType_create($name, $angeltype_id, $description) {
function ShiftType($shifttype_id) {
$shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
if ($shifttype === false) {
- return false;
+ engelsystem_error('Unable to load shift type.');
}
if ($shifttype == null) {
return null;
diff --git a/includes/model/ShiftsFilter.php b/includes/model/ShiftsFilter.php
new file mode 100644
index 00000000..044b32dd
--- /dev/null
+++ b/includes/model/ShiftsFilter.php
@@ -0,0 +1,112 @@
+<?php
+
+namespace Engelsystem;
+
+/**
+ * BO Class that stores all parameters used to filter shifts for users.
+ *
+ * @author msquare
+ */
+class ShiftsFilter {
+
+ /**
+ * Shift is completely full.
+ */
+ const FILLED_FILLED = 1;
+
+ /**
+ * Shift has some free slots.
+ */
+ const FILLED_FREE = 0;
+
+ /**
+ * Has the user "user shifts admin" privilege?
+ *
+ * @var boolean
+ */
+ private $userShiftsAdmin;
+
+ private $filled = [];
+
+ private $rooms = [];
+
+ private $types = [];
+
+ private $startTime = null;
+
+ private $endTime = null;
+
+ public function __construct($user_shifts_admin, $rooms, $types) {
+ $this->user_shifts_admin = $user_shifts_admin;
+ $this->rooms = $rooms;
+ $this->types = $types;
+
+ $this->filled = [
+ ShiftsFilter::FILLED_FREE
+ ];
+
+ if ($user_shifts_admin) {
+ $this->filled[] = ShiftsFilter::FILLED_FILLED;
+ }
+ }
+
+ public function getStartTime() {
+ return $this->startTime;
+ }
+
+ public function setStartTime($startTime) {
+ $this->startTime = $startTime;
+ }
+
+ public function getEndTime() {
+ return $this->endTime;
+ }
+
+ public function setEndTime($endTime) {
+ $this->endTime = $endTime;
+ }
+
+ public function getTypes() {
+ if (count($this->types) == 0) {
+ return [
+ 0
+ ];
+ }
+ return $this->types;
+ }
+
+ public function setTypes($types) {
+ $this->types = $types;
+ }
+
+ public function getRooms() {
+ if (count($this->rooms) == 0) {
+ return [
+ 0
+ ];
+ }
+ return $this->rooms;
+ }
+
+ public function setRooms($rooms) {
+ $this->rooms = $rooms;
+ }
+
+ public function isUserShiftsAdmin() {
+ return $this->userShiftsAdmin;
+ }
+
+ public function setUserShiftsAdmin($userShiftsAdmin) {
+ $this->userShiftsAdmin = $userShiftsAdmin;
+ }
+
+ public function getFilled() {
+ return $this->filled;
+ }
+
+ public function setFilled($filled) {
+ $this->filled = $filled;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index a827c6b5..2db0a3d3 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -1,9 +1,83 @@
<?php
+use Engelsystem\ShiftsFilter;
+use Engelsystem\ShiftSignupState;
+
+function Shifts_by_room($room) {
+ $result = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($room['RID']) . " ORDER BY `start`");
+ if ($result === false) {
+ engelsystem_error("Unable to load shifts.");
+ }
+ return $result;
+}
+
+function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
+ $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(',', $shiftsFilter->getTypes()) . ")
+ 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(',', $shiftsFilter->getRooms()) . ")
+ AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime();
+
+ if (count($shiftsFilter->getFilled()) == 1) {
+ if ($shiftsFilter->getFilled()[0] == ShiftsFilter::FILLED_FREE) {
+ $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] == ShiftsFilter::FILLED_FILLED) {
+ $SQL .= "
+ AND (
+ nat.`count` <= entries.`count`
+ OR EXISTS (
+ SELECT `SID`
+ FROM `ShiftEntry`
+ WHERE `UID` = '" . sql_escape($user['UID']) . "'
+ AND `ShiftEntry`.`SID` = `Shifts`.`SID`
+ )
+ )";
+ }
+ }
+ $SQL .= "
+ ORDER BY `start`";
+
+ $result = sql_select($SQL);
+ if ($result === false) {
+ engelsystem_error("Unable to load shifts by filter.");
+ }
+ return $result;
+}
/**
* Check if a shift collides with other shifts (in time).
- * @param Shift $shift
- * @param array<Shift> $shifts
+ *
+ * @param Shift $shift
+ * @param array<Shift> $shifts
*/
function Shift_collides($shift, $shifts) {
foreach ($shifts as $other_shift) {
@@ -17,29 +91,51 @@ function Shift_collides($shift, $shifts) {
}
/**
- * Check if an angel can sign up for given shift.
+ * Returns the number of needed angels/free shift entries for an angeltype.
*
- * @param Shift $shift
- * @param AngelType $angeltype
- * @param array<Shift> $user_shifts
+ * @param int $shift_id
+ * ID of the shift to check
+ * @param int $angeltype_id
+ * ID of the angeltype that should be checked
*/
-function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_shifts = null) {
- global $user, $privileges;
+function Shift_free_entries($shift_id, $angeltype_id) {
+ $needed_angeltypes = NeededAngelTypes_by_shift($shift_id);
- if ($user_shifts == null) {
- $user_shifts = Shifts_by_user($user);
- if ($user_shifts === false) {
- engelsystem_error('Unable to load users shifts.');
+ foreach ($needed_angeltypes as $needed_angeltype) {
+ if ($needed_angeltype['angel_type_id'] == $angeltype_id) {
+ return max(0, $needed_angeltype['count'] - $needed_angeltype['taken']);
}
}
- $collides = Shift_collides($shift, $user_shifts);
+ return 0;
+}
+
+/**
+ * Check if an angel can sign up for given shift.
+ *
+ * @param Shift $shift
+ * The shift
+ * @param AngelType $angeltype
+ * The angeltype to which the user wants to sign up
+ * @param array<Shift> $user_shifts
+ * List of the users shifts
+ */
+function Shift_signup_allowed($user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null) {
+ global $privileges;
- if ($user_angeltype == null) {
- $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype === false) {
- engelsystem_error('Unable to load user angeltype.');
+ $free_entries = Shift_free_entries($shift['SID'], $angeltype['id']);
+
+ if (in_array('user_shifts_admin', $privileges)) {
+ if ($free_entries == 0) {
+ // User shift admins may join anybody in every shift
+ return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
}
+
+ return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
+ }
+
+ if ($user_shifts == null) {
+ $user_shifts = Shifts_by_user($user);
}
$signed_up = false;
@@ -50,45 +146,37 @@ function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_
}
}
- $needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
- if ($needed_angeltypes === false) {
- engelsystem_error('Unable to load needed angel types.');
+ if ($signed_up) {
+ // you cannot join if you already singed up for this shift
+ return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries);
}
- // is the shift still running or alternatively is the user shift admin?
- $user_may_join_shift = true;
-
- // you canot join if shift is full
- foreach ($needed_angeltypes as $needed_angeltype) {
- if ($needed_angeltype['angel_type_id'] == $angeltype['id']) {
- if ($needed_angeltype['taken'] >= $needed_angeltype['count']) {
- $user_may_join_shift = false;
- }
- break;
- }
+ if (time() > $shift['start']) {
+ // you can only join if the shift is in future
+ return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
+ }
+ if ($free_entries == 0) {
+ // you cannot join if shift is full
+ return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
}
- // you cannot join if user alread joined a parallel or this shift
- $user_may_join_shift &= ! $collides;
-
- // you cannot join if you already singed up for this shift
- $user_may_join_shift &= ! $signed_up;
-
- // you cannot join if user is not of this angel type
- $user_may_join_shift &= $user_angeltype != null;
-
- // you cannot join if you are not confirmed
- if ($angeltype['restricted'] == 1 && $user_angeltype != null) {
- $user_may_join_shift &= isset($user_angeltype['confirm_user_id']);
+ if ($user_angeltype == null) {
+ $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
}
- // you can only join if the shift is in future
- $user_may_join_shift &= time() < $shift['start'];
+ if ($user_angeltype == null || ($angeltype['restricted'] == 1 && $user_angeltype != null && ! isset($user_angeltype['confirm_user_id']))) {
+ // you cannot join if user is not of this angel type
+ // you cannot join if you are not confirmed
+ return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries);
+ }
- // User shift admins may join anybody in every shift
- $user_may_join_shift |= in_array('user_shifts_admin', $privileges);
+ if (Shift_collides($shift, $user_shifts)) {
+ // you cannot join if user alread joined a parallel or this shift
+ return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries);
+ }
- return $user_may_join_shift;
+ // Hooray, shift is free for you!
+ return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
}
/**
@@ -104,7 +192,11 @@ function Shift_delete_by_psid($shift_psid) {
function Shift_delete($shift_id) {
mail_shift_delete(Shift($shift_id));
- return sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
+ $result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
+ if ($result === false) {
+ engelsystem_error('Unable to delete shift.');
+ }
+ return $result;
}
/**
@@ -170,7 +262,7 @@ function Shift_create($shift) {
* Return users shifts.
*/
function Shifts_by_user($user) {
- return sql_select("
+ $result = sql_select("
SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.*, `Shifts`.*, `Room`.*
FROM `ShiftEntry`
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
@@ -179,52 +271,10 @@ function Shifts_by_user($user) {
WHERE `UID`='" . sql_escape($user['UID']) . "'
ORDER BY `start`
");
-}
-
-/**
- * TODO: $_REQUEST is not allowed in model!
- * Returns Shift id array
- */
-function Shifts_filtered() {
- global $_REQUEST;
- $filter = "";
-
- // filterRoom (Array of integer) - Array of Room IDs (optional, for list request)
- if (isset($_REQUEST['filterRoom']) && is_array($_REQUEST['filterRoom'])) {
- foreach ($_REQUEST['filterRoom'] as $key => $value) {
- $filter .= ", `RID`='" . sql_escape($value) . "' ";
- }
- }
-
- // filterTask (Array of integer) - Array if Task (optional, for list request)
- if (isset($_REQUEST['filterTask']) && is_array($_REQUEST['filterTask'])) {
- foreach ($_REQUEST['filterTask'] as $key => $value) {
- // TODO $filter .= ", `RID`=" . sql_escape($value) . " ";
- }
- }
-
- // filterOccupancy (integer) - Occupancy state: (optional, for list request)
- // 1 occupied, 2 free, 3 occupied and free
- if (isset($_REQUEST['filterOccupancy']) && is_array($_REQUEST['filterOccupancy'])) {
- foreach ($_REQUEST['filterOccupancy'] as $key => $value) {
- // TODO $filter .= ", `RID`=" . sql_escape($value) . " ";
- }
- }
-
- // format filter
- if ($filter != "") {
- $filter = ' WHERE ' . substr($filter, 1);
- }
-
- // real request
- $shifts_source = sql_select("SELECT `SID` FROM `Shifts`" . $filter);
- if ($shifts_source === false) {
- return false;
- }
- if (count($shifts_source) > 0) {
- return $shifts_source;
+ if ($result === false) {
+ engelsystem_error('Unable to load users shifts.');
}
- return null;
+ return $result;
}
/**
@@ -242,27 +292,29 @@ function Shift($shift_id) {
$shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'");
if ($shifts_source === false) {
- return false;
+ engelsystem_error('Unable to load shift.');
}
- if (count($shifts_source) > 0) {
- $result = $shifts_source[0];
-
- $result['ShiftEntry'] = $shiftsEntry_source;
- $result['NeedAngels'] = [];
-
- $temp = NeededAngelTypes_by_shift($shift_id);
- foreach ($temp as $e) {
- $result['NeedAngels'][] = [
- 'TID' => $e['angel_type_id'],
- 'count' => $e['count'],
- 'restricted' => $e['restricted'],
- 'taken' => $e['taken']
- ];
- }
-
- return $result;
+
+ if (empty($shifts_source)) {
+ return null;
}
- return null;
+
+ $result = $shifts_source[0];
+
+ $result['ShiftEntry'] = $shiftsEntry_source;
+ $result['NeedAngels'] = [];
+
+ $temp = NeededAngelTypes_by_shift($shift_id);
+ foreach ($temp as $e) {
+ $result['NeedAngels'][] = [
+ 'TID' => $e['angel_type_id'],
+ 'count' => $e['count'],
+ 'restricted' => $e['restricted'],
+ 'taken' => $e['taken']
+ ];
+ }
+
+ return $result;
}
/**
diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php
index fe5293f8..92b35321 100644
--- a/includes/model/UserAngelTypes_model.php
+++ b/includes/model/UserAngelTypes_model.php
@@ -28,21 +28,26 @@ function UserAngelType_exists($user, $angeltype) {
* @param User $user
*/
function User_angeltypes($user) {
- return sql_select("
- SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`coordinator`
+ $result = sql_select("
+ SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter`
FROM `UserAngelTypes`
JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`
WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "'
");
+ if ($result === false) {
+ engelsystem_error("Unable to load user angeltypes.");
+ return false;
+ }
+ return $result;
}
/**
- * Gets unconfirmed user angeltypes for angeltypes of which the given user is a coordinator.
+ * Gets unconfirmed user angeltypes for angeltypes of which the given user is a supporter.
*
* @param User $user
*/
function User_unconfirmed_AngelTypes($user) {
- return sql_select("
+ $result = sql_select("
SELECT
`UserAngelTypes`.*,
`AngelTypes`.`name`,
@@ -51,41 +56,49 @@ function User_unconfirmed_AngelTypes($user) {
JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id`
JOIN `UserAngelTypes` as `UnconfirmedMembers` ON `UserAngelTypes`.`angeltype_id`=`UnconfirmedMembers`.`angeltype_id`
WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "'
- AND `UserAngelTypes`.`coordinator`=TRUE
+ AND `UserAngelTypes`.`supporter`=TRUE
AND `AngelTypes`.`restricted`=TRUE
AND `UnconfirmedMembers`.`confirm_user_id` IS NULL
GROUP BY `UserAngelTypes`.`angeltype_id`
ORDER BY `AngelTypes`.`name`");
+ if ($result === false) {
+ engelsystem_error("Unable to load user angeltypes.");
+ }
+ return $result;
}
/**
- * Returns true if user is angeltype coordinator or has privilege admin_user_angeltypes.
+ * Returns true if user is angeltype supporter or has privilege admin_user_angeltypes.
*
* @param User $user
* @param AngelType $angeltype
*/
-function User_is_AngelType_coordinator($user, $angeltype) {
+function User_is_AngelType_supporter($user, $angeltype) {
return (sql_num_query("
SELECT `id`
FROM `UserAngelTypes`
WHERE `user_id`='" . sql_escape($user['UID']) . "'
AND `angeltype_id`='" . sql_escape($angeltype['id']) . "'
- AND `coordinator`=TRUE
+ AND `supporter`=TRUE
LIMIT 1") > 0) || in_array('admin_user_angeltypes', privileges_for_user($user['UID']));
}
/**
- * Add or remove coordinator rights.
+ * Add or remove supporter rights.
*
* @param int $user_angeltype_id
- * @param bool $coordinator
+ * @param bool $supporter
*/
-function UserAngelType_update($user_angeltype_id, $coordinator) {
- return sql_query("
+function UserAngelType_update($user_angeltype_id, $supporter) {
+ $result = sql_query("
UPDATE `UserAngelTypes`
- SET `coordinator`=" . sql_bool($coordinator) . "
+ SET `supporter`=" . sql_bool($supporter) . "
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1");
+ if ($result === false) {
+ engelsystem_error("Unable to update supporter rights.");
+ }
+ return $result;
}
/**
@@ -94,10 +107,14 @@ function UserAngelType_update($user_angeltype_id, $coordinator) {
* @param int $angeltype_id
*/
function UserAngelTypes_delete_all($angeltype_id) {
- return sql_query("
+ $result = sql_query("
DELETE FROM `UserAngelTypes`
WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "'
AND `confirm_user_id` IS NULL");
+ if ($result === false) {
+ engelsystem_error("Unable to delete all unconfirmed users.");
+ }
+ return $result;
}
/**
@@ -107,11 +124,15 @@ function UserAngelTypes_delete_all($angeltype_id) {
* @param User $confirm_user
*/
function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) {
- return sql_query("
+ $result = sql_query("
UPDATE `UserAngelTypes`
SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "'
WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "'
AND `confirm_user_id` IS NULL");
+ if ($result === false) {
+ engelsystem_error("Unable to confirm all users.");
+ }
+ return $result;
}
/**
@@ -121,11 +142,15 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) {
* @param User $confirm_user
*/
function UserAngelType_confirm($user_angeltype_id, $confirm_user) {
- return sql_query("
+ $result = sql_query("
UPDATE `UserAngelTypes`
SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "'
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1");
+ if ($result === false) {
+ engelsystem_error("Unable to confirm user angeltype.");
+ }
+ return $result;
}
/**
@@ -152,7 +177,7 @@ function UserAngelType_create($user, $angeltype) {
`user_id`='" . sql_escape($user['UID']) . "',
`angeltype_id`='" . sql_escape($angeltype['id']) . "'");
if ($result === false) {
- return false;
+ engelsystem_error("Unable to create user angeltype.");
}
return sql_id();
}
@@ -169,7 +194,7 @@ function UserAngelType($user_angeltype_id) {
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1");
if ($angeltype === false) {
- return false;
+ engelsystem_error("Unable to load user angeltype.");
}
if (count($angeltype) == 0) {
return null;
@@ -191,7 +216,7 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) {
AND `angeltype_id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1");
if ($angeltype === false) {
- return false;
+ engelsystem_error("Unable to load user angeltype.");
}
if (count($angeltype) == 0) {
return null;
diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php
index 19f87e63..32785c92 100644
--- a/includes/model/UserDriverLicenses_model.php
+++ b/includes/model/UserDriverLicenses_model.php
@@ -7,6 +7,7 @@
function UserDriverLicense($user_id) {
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
if ($user_driver_license === false) {
+ engelsystem_error('Unable to load user driver license.');
return false;
}
if (count($user_driver_license) > 0) {
@@ -27,7 +28,7 @@ function UserDriverLicense($user_id) {
* @param bool $has_license_forklift
*/
function UserDriverLicenses_create($user_id, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) {
- return sql_query("
+ $result = sql_query("
INSERT INTO `UserDriverLicenses` SET
`user_id`=" . sql_escape($user_id) . ",
`has_car`=" . sql_bool($has_car) . ",
@@ -36,6 +37,10 @@ function UserDriverLicenses_create($user_id, $has_car, $has_license_car, $has_li
`has_license_7_5t_truck`=" . sql_bool($has_license_7_5t_truck) . ",
`has_license_12_5t_truck`=" . sql_bool($has_license_12_5t_truck) . ",
`has_license_forklift`=" . sql_bool($has_license_forklift));
+ if ($result === false) {
+ engelsystem_error('Unable to create user driver license');
+ }
+ return $result;
}
/**
@@ -50,7 +55,7 @@ function UserDriverLicenses_create($user_id, $has_car, $has_license_car, $has_li
* @param bool $has_license_forklift
*/
function UserDriverLicenses_update($user_id, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) {
- return sql_query("UPDATE `UserDriverLicenses` SET
+ $result = sql_query("UPDATE `UserDriverLicenses` SET
`has_car`=" . sql_bool($has_car) . ",
`has_license_car`=" . sql_bool($has_license_car) . ",
`has_license_3_5t_transporter`=" . sql_bool($has_license_3_5t_transporter) . ",
@@ -58,6 +63,10 @@ function UserDriverLicenses_update($user_id, $has_car, $has_license_car, $has_li
`has_license_12_5t_truck`=" . sql_bool($has_license_12_5t_truck) . ",
`has_license_forklift`=" . sql_bool($has_license_forklift) . "
WHERE `user_id`='" . sql_escape($user_id) . "'");
+ if ($result === false) {
+ engelsystem_error("Unable to update user driver license information");
+ }
+ return $result;
}
/**
@@ -66,6 +75,10 @@ function UserDriverLicenses_update($user_id, $has_car, $has_license_car, $has_li
* @param int $user_id
*/
function UserDriverLicenses_delete($user_id) {
- return sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
+ $result = sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
+ if ($result === false) {
+ engelsystem_error("Unable to remove user driver license information");
+ }
+ return $result;
}
?> \ No newline at end of file
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index 576bb3f5..66aa52e5 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -29,6 +29,7 @@ function User_update($user) {
`Handy`='" . sql_escape($user['Handy']) . "',
`email`='" . sql_escape($user['email']) . "',
`email_shiftinfo`=" . sql_bool($user['email_shiftinfo']) . ",
+ `email_by_human_allowed`=" . sql_bool($user['email_by_human_allowed']) . ",
`jabber`='" . sql_escape($user['jabber']) . "',
`Size`='" . sql_escape($user['Size']) . "',
`Gekommen`='" . sql_escape($user['Gekommen']) . "',
@@ -40,7 +41,8 @@ function User_update($user) {
`Hometown`='" . sql_escape($user['Hometown']) . "',
`got_voucher`='" . sql_escape($user['got_voucher']) . "',
`arrival_date`='" . sql_escape($user['arrival_date']) . "',
- `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "'
+ `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "',
+ `planned_departure_date`='" . sql_escape($user['planned_departure_date']) . "'
WHERE `UID`='" . sql_escape($user['UID']) . "'");
}
@@ -113,12 +115,16 @@ function User_is_freeloader($user) {
* @param Angeltype $angeltype
*/
function Users_by_angeltype_inverted($angeltype) {
- return sql_select("
+ $result = sql_select("
SELECT `User`.*
FROM `User`
LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "')
WHERE `UserAngelTypes`.`id` IS NULL
ORDER BY `Nick`");
+ if ($result === false) {
+ engelsystem_error("Unable to load users.");
+ }
+ return $result;
}
/**
@@ -132,7 +138,7 @@ function Users_by_angeltype($angeltype) {
`User`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`,
- `UserAngelTypes`.`coordinator`,
+ `UserAngelTypes`.`supporter`,
`UserDriverLicenses`.*
FROM `User`
JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id`
@@ -158,6 +164,80 @@ function User_validate_Nick($nick) {
}
/**
+ * Validate user email address.
+ *
+ * @param string $mail
+ * The email address to validate
+ * @return ValidationResult
+ */
+function User_validate_mail($mail) {
+ $mail = strip_item($mail);
+ return new ValidationResult(check_email($mail), $mail);
+}
+
+/**
+ * Validate the planned arrival date
+ *
+ * @param int $planned_arrival_date
+ * Unix timestamp
+ * @return ValidationResult
+ */
+function User_validate_planned_arrival_date($planned_arrival_date) {
+ if ($planned_arrival_date == null) {
+ // null is not okay
+ return new ValidationResult(false, time());
+ }
+ $event_config = EventConfig();
+ if ($event_config == null) {
+ // Nothing to validate against
+ return new ValidationResult(true, $planned_arrival_date);
+ }
+ if (isset($event_config['buildup_start_date']) && $planned_arrival_date < $event_config['buildup_start_date']) {
+ // Planned arrival can not be before buildup start date
+ return new ValidationResult(false, $event_config['buildup_start_date']);
+ }
+ if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) {
+ // Planned arrival can not be after teardown end date
+ return new ValidationResult(false, $event_config['teardown_end_date']);
+ }
+ return new ValidationResult(true, $planned_arrival_date);
+}
+
+/**
+ * Validate the planned departure date
+ *
+ * @param int $planned_arrival_date
+ * Unix timestamp
+ * @param int $planned_departure_date
+ * Unix timestamp
+ * @return ValidationResult
+ */
+function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date) {
+ if ($planned_departure_date == null) {
+ // null is okay
+ return new ValidationResult(true, null);
+ }
+ if ($planned_arrival_date > $planned_departure_date) {
+ // departure cannot be before arrival
+ return new ValidationResult(false, $planned_arrival_date);
+ }
+ $event_config = EventConfig();
+ if ($event_config == null) {
+ // Nothing to validate against
+ return new ValidationResult(true, $planned_departure_date);
+ }
+ if (isset($event_config['buildup_start_date']) && $planned_departure_date < $event_config['buildup_start_date']) {
+ // Planned arrival can not be before buildup start date
+ return new ValidationResult(false, $event_config['buildup_start_date']);
+ }
+ if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) {
+ // Planned arrival can not be after teardown end date
+ return new ValidationResult(false, $event_config['teardown_end_date']);
+ }
+ return new ValidationResult(true, $planned_departure_date);
+}
+
+/**
* Returns user by id.
*
* @param $user_id UID
@@ -165,7 +245,7 @@ function User_validate_Nick($nick) {
function User($user_id) {
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
if ($user_source === false) {
- return false;
+ engelsystem_error("Unable to load user.");
}
if (count($user_source) > 0) {
return $user_source[0];
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') . '&amp;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..0a6d8c71 100644
--- a/includes/pages/user_settings.php
+++ b/includes/pages/user_settings.php
@@ -4,215 +4,184 @@ 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_mail($_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'));
+ }
+}
+
+/**
+ * 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'));
+ }
+}
+
+/**
+ * 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'));
+ }
+}
+
+/**
+ * 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_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_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_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"];
}
diff --git a/includes/sys_form.php b/includes/sys_form.php
new file mode 100644
index 00000000..960be401
--- /dev/null
+++ b/includes/sys_form.php
@@ -0,0 +1,256 @@
+<?php
+// Methods to build a html form.
+
+/**
+ * Renders a hidden input
+ *
+ * @param string $name
+ * Name of the input
+ * @param string $value
+ * The value
+ * @return string rendered html
+ */
+function form_hidden($name, $value) {
+ return '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
+}
+
+/**
+ * Rendert ein Zahlenfeld mit Buttons zum verstellen
+ */
+function form_spinner($name, $label, $value) {
+ return form_element($label, '
+ <div class="input-group">
+ <input id="spinner-' . $name . '" class="form-control" type="text" name="' . $name . '" value="' . $value . '" />
+ <div class="input-group-btn">
+ <button id="spinner-' . $name . '-down" class="btn btn-default" type="button">
+ <span class="glyphicon glyphicon-minus"></span>
+ </button>
+ <button id="spinner-' . $name . '-up" class="btn btn-default" type="button">
+ <span class="glyphicon glyphicon-plus"></span>
+ </button>
+ </div>
+ </div>
+ <script type="text/javascript">
+ $("#spinner-' . $name . '-down").click(function(e) {
+ $("#spinner-' . $name . '").val(parseInt($("#spinner-' . $name . '").val()) - 1);
+ });
+ $("#spinner-' . $name . '-up").click(function(e) {
+ $("#spinner-' . $name . '").val(parseInt($("#spinner-' . $name . '").val()) + 1);
+ });
+ </script>
+ ');
+}
+
+/**
+ * Render a bootstrap datepicker
+ *
+ * @param string $name
+ * Name of the parameter
+ * @param string $label
+ * Label
+ * @param int $value
+ * Unix Timestamp
+ * @param int $min_date
+ * Earliest possible date
+ * @return HTML
+ */
+function form_date($name, $label, $value, $start_date = '', $end_date = '') {
+ $dom_id = $name . '-date';
+ $value = is_numeric($value) ? date('Y-m-d', $value) : '';
+ $start_date = is_numeric($start_date) ? date('Y-m-d', $start_date) : '';
+ $end_date = is_numeric($end_date) ? date('Y-m-d', $end_date) : '';
+ return form_element($label, '
+ <div class="input-group date" id="' . $dom_id . '">
+ <input type="text" name="' . $name . '" class="form-control" value="' . $value . '"><span class="input-group-addon">' . glyph('th') . '</span>
+ </div>
+ <script type="text/javascript">
+ $(function(){
+ $("#' . $dom_id . '").datepicker({
+ language: "' . locale_short() . '",
+ todayBtn: "linked",
+ format: "yyyy-mm-dd",
+ startDate: "' . $start_date . '",
+ endDate: "' . $end_date . '"
+ });
+ });
+ </script>
+ ', $dom_id);
+}
+
+/**
+ * Rendert eine Liste von Checkboxen für ein Formular
+ *
+ * @param
+ * name Die Namen der Checkboxen werden aus name_key gebildet
+ * @param
+ * label Die Beschriftung der Liste
+ * @param
+ * items Array mit den einzelnen Checkboxen
+ * @param
+ * selected Array mit den Keys, die ausgewählt sind
+ */
+function form_checkboxes($name, $label, $items, $selected) {
+ $html = form_element($label, '');
+ foreach ($items as $key => $item) {
+ $html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false);
+ }
+ return $html;
+}
+
+/**
+ * Rendert eine Tabelle von Checkboxen für ein Formular
+ *
+ * @param
+ * names Assoziatives Array mit Namen der Checkboxen als Keys und Überschriften als Values
+ * @param
+ * label Die Beschriftung der gesamten Tabelle
+ * @param
+ * items Array mit den Beschriftungen der Zeilen
+ * @param
+ * selected Mehrdimensionales Array, wobei $selected[foo] ein Array der in der Datenreihe foo markierten Checkboxen ist
+ * @param
+ * disabled Wie selected, nur dass die entsprechenden Checkboxen deaktiviert statt markiert sind
+ */
+function form_multi_checkboxes($names, $label, $items, $selected, $disabled = []) {
+ $html = "<table><thead><tr>";
+ foreach ($names as $title) {
+ $html .= "<th>$title</th>";
+ }
+ $html .= "</tr></thead><tbody>";
+ foreach ($items as $key => $item) {
+ $html .= "<tr>";
+ foreach ($names as $name => $title) {
+ $dom_id = $name . '_' . $key;
+ $sel = array_search($key, $selected[$name]) !== false ? ' checked="checked"' : "";
+ if (! empty($disabled) && ! empty($disabled[$name]) && array_search($key, $disabled[$name]) !== false) {
+ $sel .= ' disabled="disabled"';
+ }
+ $html .= '<td style="text-align: center;"><input type="checkbox" id="' . $dom_id . '" name="' . $name . '[]" value="' . $key . '"' . $sel . ' /></td>';
+ }
+ $html .= '<td><label for="' . $dom_id . '">' . $item . '</label></td></tr>';
+ }
+ $html .= "</tbody></table>";
+ return form_element($label, $html);
+}
+
+/**
+ * Rendert eine Checkbox
+ */
+function form_checkbox($name, $label, $selected, $value = 'checked') {
+ return '<div class="checkbox"><label><input type="checkbox" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
+}
+
+/**
+ * Rendert einen Radio
+ */
+function form_radio($name, $label, $selected, $value) {
+ return '<div class="radio"><label><input type="radio" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
+}
+
+/**
+ * Rendert einen Infotext in das Formular
+ */
+function form_info($label, $text = "") {
+ if ($label == "") {
+ return '<span class="help-block">' . glyph('info-sign') . $text . '</span>';
+ }
+ if ($text == "") {
+ return '<h4>' . $label . '</h4>';
+ }
+ return form_element($label, '<p class="form-control-static">' . $text . '</p>', '');
+}
+
+/**
+ * Rendert den Absenden-Button eines Formulars
+ */
+function form_submit($name, $label) {
+ return form_element('<input class="btn btn-primary" type="submit" name="' . $name . '" value="' . $label . '" />', "");
+}
+
+/**
+ * Rendert ein Formular-Textfeld
+ */
+function form_text($name, $label, $value, $disabled = false) {
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
+}
+
+/**
+ * Rendert ein Formular-Emailfeld
+ */
+function form_email($name, $label, $value, $disabled = false) {
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<input class="form-control" id="form_' . $name . '" type="email" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
+}
+
+/**
+ * Rendert ein Formular-Dateifeld
+ */
+function form_file($name, $label) {
+ return form_element($label, '<input id="form_' . $name . '" type="file" name="' . $name . '" />', 'form_' . $name);
+}
+
+/**
+ * Rendert ein Formular-Passwortfeld
+ */
+function form_password($name, $label, $disabled = false) {
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" ' . $disabled . '/>', 'form_' . $name);
+}
+
+/**
+ * Rendert ein Formular-Textfeld
+ */
+function form_textarea($name, $label, $value, $disabled = false) {
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<textarea rows="5" class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" ' . $disabled . '>' . $value . '</textarea>', 'form_' . $name);
+}
+
+/**
+ * Rendert ein Formular-Auswahlfeld
+ */
+function form_select($name, $label, $values, $selected) {
+ return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name);
+}
+
+/**
+ * Rendert ein Formular-Element
+ */
+function form_element($label, $input, $for = "") {
+ if ($label == '') {
+ return '<div class="form-group">' . $input . '</div>';
+ }
+
+ return '<div class="form-group">' . '<label for="' . $for . '">' . $label . '</label>' . $input . '</div>';
+}
+
+/**
+ * Rendert ein Formular
+ */
+function form($elements, $action = "") {
+ return '<form role="form" action="' . $action . '" enctype="multipart/form-data" method="post">' . join($elements) . '</form>';
+}
+
+function html_options($name, $options, $selected = "") {
+ $html = "";
+ foreach ($options as $value => $label) {
+ $html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
+ }
+
+ return $html;
+}
+
+function html_select_key($dom_id, $name, $rows, $selected) {
+ $html = '<select class="form-control" id="' . $dom_id . '" name="' . $name . '">';
+ foreach ($rows as $key => $row) {
+ if (($key == $selected) || ($row == $selected)) {
+ $html .= '<option value="' . $key . '" selected="selected">' . $row . '</option>';
+ } else {
+ $html .= '<option value="' . $key . '">' . $row . '</option>';
+ }
+ }
+ $html .= '</select>';
+ return $html;
+}
+
+?> \ No newline at end of file
diff --git a/includes/sys_menu.php b/includes/sys_menu.php
index 112c490f..9d70cf10 100644
--- a/includes/sys_menu.php
+++ b/includes/sys_menu.php
@@ -129,6 +129,8 @@ function make_navigation() {
}
}
+ $menu = make_room_navigation($menu);
+
$admin_menu = [];
$admin_pages = [
"admin_arrive" => admin_arrive_title(),
@@ -158,6 +160,36 @@ function make_navigation() {
return toolbar($menu);
}
+/**
+ * Adds room navigation to the given menu.
+ *
+ * @param string[] $menu
+ * Rendered menu
+ */
+function make_room_navigation($menu) {
+ global $privileges;
+
+ if (! in_array('view_rooms', $privileges)) {
+ return $menu;
+ }
+
+ $rooms = Rooms();
+ $room_menu = [];
+ if (in_array('admin_rooms', $privileges)) {
+ $room_menu[] = toolbar_item_link(page_link_to('admin_rooms'), 'list', _("Manage rooms"));
+ }
+ if (count($room_menu) > 0) {
+ $room_menu[] = toolbar_item_divider();
+ }
+ foreach ($rooms as $room) {
+ $room_menu[] = toolbar_item_link(room_link($room), 'map-marker', $room['Name']);
+ }
+ if (count($room_menu > 0)) {
+ $menu[] = toolbar_dropdown('map-marker', _("Rooms"), $room_menu);
+ }
+ return $menu;
+}
+
function make_menu() {
return make_navigation();
}
diff --git a/includes/sys_page.php b/includes/sys_page.php
index e336261d..713dd33b 100644
--- a/includes/sys_page.php
+++ b/includes/sys_page.php
@@ -1,6 +1,53 @@
<?php
/**
+ * Provide page/request helper functions
+ */
+
+/**
+ * Parse a date from da day and a time textfield.
+ *
+ * @param string $date_name
+ * Name of the textfield containing the day (format Y-m-d)
+ * @param string $time_name
+ * Name of the textfield containing the time (format H:i)
+ * @param string[] $allowed_days
+ * List of allowed days in format Y-m-d
+ * @param int $default_value
+ * Default value unix timestamp
+ */
+function check_request_datetime($date_name, $time_name, $allowed_days, $default_value) {
+ $time = date("H:i", $default_value);
+ $day = date("Y-m-d", $default_value);
+
+ if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) {
+ $time = trim($_REQUEST[$time_name]);
+ }
+ if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) {
+ $day = $_REQUEST[$date_name];
+ }
+
+ return parse_date("Y-m-d H:i", $day . " " . $time);
+}
+
+/**
+ * Parse a date into unix timestamp
+ *
+ * @param string $pattern
+ * The date pattern (i.e. Y-m-d H:i)
+ * @param string $value
+ * The string to parse
+ * @return The parsed unix timestamp
+ */
+function parse_date($pattern, $value) {
+ $datetime = DateTime::createFromFormat($pattern, trim($value));
+ if ($datetime == null) {
+ return null;
+ }
+ return $datetime->getTimestamp();
+}
+
+/**
* Leitet den Browser an die übergebene URL weiter und hält das Script an.
*/
function redirect($url) {
@@ -11,7 +58,8 @@ function redirect($url) {
/**
* Echoes given output and dies.
*
- * @param String $output
+ * @param String $output
+ * String to display
*/
function raw_output($output) {
echo $output;
@@ -19,6 +67,37 @@ function raw_output($output) {
}
/**
+ * Helper function for transforming list of entities into array for select boxes.
+ *
+ * @param array $data
+ * The data array
+ * @param string $key_name
+ * name of the column to use as id/key
+ * @param string $value_name
+ * name of the column to use as displayed value
+ */
+function select_array($data, $key_name, $value_name) {
+ $ret = [];
+ foreach ($data as $value) {
+ $ret[$value[$key_name]] = $value[$value_name];
+ }
+ return $ret;
+}
+
+/**
+ * Returns an int[] from given request param name.
+ *
+ * @param String $name
+ * Name of the request param
+ */
+function check_request_int_array($name) {
+ if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) {
+ return array_filter($_REQUEST[$name], 'is_numeric');
+ }
+ return [];
+}
+
+/**
* Checks if given request item (name) can be parsed to a date.
* If not parsable, given error message is put into msg() and null is returned.
*
@@ -50,8 +129,8 @@ function check_request_date($name, $error_message = null, $null_allowed = false)
* @return ValidationResult containing the parsed date
*/
function check_date($input, $error_message = null, $null_allowed = false) {
- if (DateTime::createFromFormat("Y-m-d", trim($input))) {
- return new ValidationResult(true, DateTime::createFromFormat("Y-m-d", trim($input))->getTimestamp());
+ if ($tmp = parse_date("Y-m-d", trim($input))) {
+ return new ValidationResult(true, $tmp);
}
if ($null_allowed) {
return new ValidationResult(true, null);
@@ -62,10 +141,13 @@ function check_date($input, $error_message = null, $null_allowed = false) {
}
/**
- * Gibt den gefilterten REQUEST Wert ohne Zeilenumbrüche zurück
+ * Returns REQUEST value filtered or default value (null) if not set.
*/
-function strip_request_item($name) {
- return strip_item($_REQUEST[$name]);
+function strip_request_item($name, $default_value = null) {
+ if (isset($_REQUEST[$name])) {
+ return strip_item($_REQUEST[$name]);
+ }
+ return $default_value;
}
/**
diff --git a/includes/sys_template.php b/includes/sys_template.php
index 2faf98c3..4ae046e6 100644
--- a/includes/sys_template.php
+++ b/includes/sys_template.php
@@ -19,6 +19,18 @@ function mute($text) {
return '<span class="text-muted">' . $text . '</span>';
}
+/**
+ * Renders a bootstrap label with given content and class.
+ *
+ * @param string $content
+ * The text
+ * @param string $class
+ * default, primary, info, success, warning, danger
+ */
+function label($content, $class = 'default') {
+ return '<span class="label label-' . $class . '">' . $content . '</span>';
+}
+
function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '') {
return '<div class="progress"><div class="progress-bar ' . $class . '" role="progressbar" aria-valuenow="' . $valuenow . '" aria-valuemin="' . $valuemin . '" aria-valuemax="' . $valuemax . '" style="width: ' . (($valuenow - $valuemin) * 100 / ($valuemax - $valuemin)) . '%">' . $content . '</div></div>';
}
@@ -42,8 +54,11 @@ function glyph_bool($boolean) {
}
function div($class, $content = [], $dom_id = "") {
+ if (is_array($content)) {
+ $content = join("\n", $content);
+ }
$dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : '';
- return '<div' . $dom_id . ' class="' . $class . '">' . join("\n", $content) . '</div>';
+ return '<div' . $dom_id . ' class="' . $class . '">' . $content . '</div>';
}
function heading($content, $number = 1) {
@@ -60,6 +75,10 @@ function toolbar($items = [], $right = false) {
return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>';
}
+function toolbar_pills($items) {
+ return '<ul class="nav nav-pills">' . join("\n", $items) . '</ul>';
+}
+
/**
* Render a link for a toolbar.
*
@@ -100,224 +119,6 @@ function toolbar_popover($glyphicon, $label, $content, $class = '') {
</script></li>';
}
-function form_hidden($name, $value) {
- return '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
-}
-
-/**
- * Rendert ein Zahlenfeld mit Buttons zum verstellen
- */
-function form_spinner($name, $label, $value) {
- return form_element($label, '
- <div class="input-group">
- <input id="spinner-' . $name . '" class="form-control" type="text" name="' . $name . '" value="' . $value . '" />
- <div class="input-group-btn">
- <button id="spinner-' . $name . '-down" class="btn btn-default" type="button">
- <span class="glyphicon glyphicon-minus"></span>
- </button>
- <button id="spinner-' . $name . '-up" class="btn btn-default" type="button">
- <span class="glyphicon glyphicon-plus"></span>
- </button>
- </div>
- </div>
- <script type="text/javascript">
- $("#spinner-' . $name . '-down").click(function(e) {
- $("#spinner-' . $name . '").val(parseInt($("#spinner-' . $name . '").val()) - 1);
- });
- $("#spinner-' . $name . '-up").click(function(e) {
- $("#spinner-' . $name . '").val(parseInt($("#spinner-' . $name . '").val()) + 1);
- });
- </script>
- ');
-}
-
-/**
- * Render a bootstrap datepicker
- *
- * @param string $name
- * Name of the parameter
- * @param string $label
- * Label
- * @param int $value
- * Unix Timestamp
- * @param int $min_date
- * Earliest possible date
- * @return HTML
- */
-function form_date($name, $label, $value, $start_date = '') {
- $dom_id = $name . '-date';
- $value = is_numeric($value) ? date('Y-m-d', $value) : '';
- $start_date = is_numeric($start_date) ? date('Y-m-d', $start_date) : '';
- return form_element($label, '
- <div class="input-group date" id="' . $dom_id . '">
- <input type="text" name="' . $name . '" class="form-control" value="' . $value . '"><span class="input-group-addon">' . glyph('th') . '</span>
- </div>
- <script type="text/javascript">
- $(function(){
- $("#' . $dom_id . '").datepicker({
- language: "' . locale_short() . '",
- todayBtn: "linked",
- format: "yyyy-mm-dd",
- startDate: "' . $start_date . '"
- });
- });
- </script>
- ', $dom_id);
-}
-
-/**
- * Rendert eine Liste von Checkboxen für ein Formular
- *
- * @param
- * name Die Namen der Checkboxen werden aus name_key gebildet
- * @param
- * label Die Beschriftung der Liste
- * @param
- * items Array mit den einzelnen Checkboxen
- * @param
- * selected Array mit den Keys, die ausgewählt sind
- */
-function form_checkboxes($name, $label, $items, $selected) {
- $html = form_element($label, '');
- foreach ($items as $key => $item) {
- $html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false);
- }
- return $html;
-}
-
-/**
- * Rendert eine Tabelle von Checkboxen für ein Formular
- *
- * @param
- * names Assoziatives Array mit Namen der Checkboxen als Keys und Überschriften als Values
- * @param
- * label Die Beschriftung der gesamten Tabelle
- * @param
- * items Array mit den Beschriftungen der Zeilen
- * @param
- * selected Mehrdimensionales Array, wobei $selected[foo] ein Array der in der Datenreihe foo markierten Checkboxen ist
- * @param
- * disabled Wie selected, nur dass die entsprechenden Checkboxen deaktiviert statt markiert sind
- */
-function form_multi_checkboxes($names, $label, $items, $selected, $disabled = []) {
- $html = "<table><thead><tr>";
- foreach ($names as $title) {
- $html .= "<th>$title</th>";
- }
- $html .= "</tr></thead><tbody>";
- foreach ($items as $key => $item) {
- $html .= "<tr>";
- foreach ($names as $name => $title) {
- $dom_id = $name . '_' . $key;
- $sel = array_search($key, $selected[$name]) !== false ? ' checked="checked"' : "";
- if (! empty($disabled) && ! empty($disabled[$name]) && array_search($key, $disabled[$name]) !== false) {
- $sel .= ' disabled="disabled"';
- }
- $html .= '<td style="text-align: center;"><input type="checkbox" id="' . $dom_id . '" name="' . $name . '[]" value="' . $key . '"' . $sel . ' /></td>';
- }
- $html .= '<td><label for="' . $dom_id . '">' . $item . '</label></td></tr>';
- }
- $html .= "</tbody></table>";
- return form_element($label, $html);
-}
-
-/**
- * Rendert eine Checkbox
- */
-function form_checkbox($name, $label, $selected, $value = 'checked') {
- return '<div class="checkbox"><label><input type="checkbox" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
-}
-
-/**
- * Rendert einen Radio
- */
-function form_radio($name, $label, $selected, $value) {
- return '<div class="radio"><label><input type="radio" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
-}
-
-/**
- * Rendert einen Infotext in das Formular
- */
-function form_info($label, $text = "") {
- if ($label == "") {
- return '<span class="help-block">' . glyph('info-sign') . $text . '</span>';
- }
- if ($text == "") {
- return '<h4>' . $label . '</h4>';
- }
- return form_element($label, '<p class="form-control-static">' . $text . '</p>', '');
-}
-
-/**
- * Rendert den Absenden-Button eines Formulars
- */
-function form_submit($name, $label) {
- return form_element('<input class="btn btn-primary" type="submit" name="' . $name . '" value="' . $label . '" />', "");
-}
-
-/**
- * Rendert ein Formular-Textfeld
- */
-function form_text($name, $label, $value, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element($label, '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
-}
-
-/**
- * Rendert ein Formular-Emailfeld
- */
-function form_email($name, $label, $value, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element($label, '<input class="form-control" id="form_' . $name . '" type="email" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
-}
-
-/**
- * Rendert ein Formular-Dateifeld
- */
-function form_file($name, $label) {
- return form_element($label, '<input id="form_' . $name . '" type="file" name="' . $name . '" />', 'form_' . $name);
-}
-
-/**
- * Rendert ein Formular-Passwortfeld
- */
-function form_password($name, $label, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element($label, '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" ' . $disabled . '/>', 'form_' . $name);
-}
-
-/**
- * Rendert ein Formular-Textfeld
- */
-function form_textarea($name, $label, $value, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element($label, '<textarea rows="5" class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" ' . $disabled . '>' . $value . '</textarea>', 'form_' . $name);
-}
-
-/**
- * Rendert ein Formular-Auswahlfeld
- */
-function form_select($name, $label, $values, $selected) {
- return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name);
-}
-
-/**
- * Rendert ein Formular-Element
- */
-function form_element($label, $input, $for = "") {
- if ($label == '') {
- return '<div class="form-group">' . $input . '</div>';
- }
-
- return '<div class="form-group">' . '<label for="' . $for . '">' . $label . '</label>' . $input . '</div>';
-}
-
-/**
- * Rendert ein Formular
- */
-function form($elements, $action = "") {
- return '<form role="form" action="' . $action . '" enctype="multipart/form-data" method="post">' . join($elements) . '</form>';
-}
/**
* Generiert HTML Code für eine "Seite".
@@ -374,11 +175,11 @@ function render_table($columns, $rows, $data = true) {
foreach ($rows as $row) {
$html .= '<tr>';
foreach ($columns as $key => $column) {
+ $value = "&nbsp;";
if (isset($row[$key])) {
- $html .= '<td class="column_' . $key . '">' . $row[$key] . '</td>';
- } else {
- $html .= '<td class="column_' . $key . '">&nbsp;</td>';
+ $value = $row[$key];
}
+ $html .= '<td class="column_' . $key . '">' . $value . '</td>';
}
$html .= '</tr>';
}
@@ -449,28 +250,6 @@ function table_body($array) {
return $html;
}
-function html_options($name, $options, $selected = "") {
- $html = "";
- foreach ($options as $value => $label) {
- $html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
- }
-
- return $html;
-}
-
-function html_select_key($dom_id, $name, $rows, $selected) {
- $html = '<select class="form-control" id="' . $dom_id . '" name="' . $name . '">';
- foreach ($rows as $key => $row) {
- if (($key == $selected) || ($row == $selected)) {
- $html .= '<option value="' . $key . '" selected="selected">' . $row . '</option>';
- } else {
- $html .= '<option value="' . $key . '">' . $row . '</option>';
- }
- }
- $html .= '</select>';
- return $html;
-}
-
function ReplaceSmilies($neueckig) {
$neueckig = str_replace(";o))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig);
$neueckig = str_replace(":-))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig);
diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php
index cdaa9f12..485ce384 100644
--- a/includes/view/AngelTypes_view.php
+++ b/includes/view/AngelTypes_view.php
@@ -25,12 +25,12 @@ function AngelType_render_membership($user_angeltype) {
if ($user_angeltype['restricted']) {
if ($user_angeltype['confirm_user_id'] == null) {
return glyph('lock') . _("Unconfirmed");
- } elseif ($user_angeltype['coordinator']) {
- return glyph_bool(true) . _("Coordinator");
+ } elseif ($user_angeltype['supporter']) {
+ return glyph_bool(true) . _("supporter");
}
return glyph_bool(true) . _("Member");
- } elseif ($user_angeltype['coordinator']) {
- return glyph_bool(true) . _("Coordinator");
+ } elseif ($user_angeltype['supporter']) {
+ return glyph_bool(true) . _("supporter");
}
return glyph_bool(true) . _("Member");
}
@@ -47,16 +47,16 @@ function AngelType_delete_view($angeltype) {
]);
}
-function AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license) {
+function AngelType_edit_view($name, $restricted, $description, $supporter_mode, $requires_driver_license) {
return page_with_title(sprintf(_("Edit %s"), $name), [
buttons([
button(page_link_to('angeltypes'), _("Angeltypes"), 'back')
]),
msg(),
form([
- $coordinator_mode ? form_info(_("Name"), $name) : form_text('name', _("Name"), $name),
- $coordinator_mode ? form_info(_("Restricted"), $restricted ? _("Yes") : _("No")) : form_checkbox('restricted', _("Restricted"), $restricted),
- $coordinator_mode ? form_info(_("Requires driver license"), $requires_driver_license ? _("Yes") : _("No")) : form_checkbox('requires_driver_license', _("Requires driver license"), $requires_driver_license),
+ $supporter_mode ? form_info(_("Name"), $name) : form_text('name', _("Name"), $name),
+ $supporter_mode ? form_info(_("Restricted"), $restricted ? _("Yes") : _("No")) : form_checkbox('restricted', _("Restricted"), $restricted),
+ $supporter_mode ? form_info(_("Requires driver license"), $requires_driver_license ? _("Yes") : _("No")) : form_checkbox('requires_driver_license', _("Requires driver license"), $requires_driver_license),
form_info("", _("Restricted angel types can only be used by an angel if enabled by an archangel (double opt-in).")),
form_textarea('description', _("Description"), $description),
form_info("", _("Please use markdown for the description.")),
@@ -65,7 +65,10 @@ function AngelType_edit_view($name, $restricted, $description, $coordinator_mode
]);
}
-function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angeltypes, $admin_angeltypes, $coordinator, $user_driver_license, $user) {
+/**
+ * Renders the buttons for the angeltype view.
+ */
+function AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user) {
$buttons = [
button(page_link_to('angeltypes'), _("Angeltypes"), 'back')
];
@@ -87,25 +90,23 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
$buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'], _("leave"), 'cancel');
}
- if ($admin_angeltypes || $coordinator) {
+ if ($admin_angeltypes || $supporter) {
$buttons[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), 'edit');
}
if ($admin_angeltypes) {
$buttons[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), 'delete');
}
- $page = [
- msg(),
- buttons($buttons)
- ];
-
- $page[] = '<h3>' . _("Description") . '</h3>';
- $parsedown = new Parsedown();
- if ($angeltype['description'] != "") {
- $page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
- }
-
- $coordinators = [];
+ return buttons($buttons);
+}
+
+/**
+ * Renders and sorts the members of an angeltype into supporters, members and unconfirmed members.
+ *
+ * @return [supporters, members, unconfirmed members]
+ */
+function AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $admin_angeltypes) {
+ $supporters = [];
$members_confirmed = [];
$members_unconfirmed = [];
foreach ($members as $member) {
@@ -127,19 +128,19 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $member['user_angeltype_id'], _("deny"), 'btn-xs')
]);
$members_unconfirmed[] = $member;
- } elseif ($member['coordinator']) {
+ } elseif ($member['supporter']) {
if ($admin_angeltypes) {
$member['actions'] = table_buttons([
- button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&coordinator=0', _("Remove coordinator rights"), 'btn-xs')
+ button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&supporter=0', _("Remove supporter rights"), 'btn-xs')
]);
} else {
$member['actions'] = '';
}
- $coordinators[] = $member;
+ $supporters[] = $member;
} else {
if ($admin_user_angeltypes) {
$member['actions'] = table_buttons([
- $admin_angeltypes ? button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&coordinator=1', _("Add coordinator rights"), 'btn-xs') : '',
+ $admin_angeltypes ? button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&supporter=1', _("Add supporter rights"), 'btn-xs') : '',
button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $member['user_angeltype_id'], _("remove"), 'btn-xs')
]);
}
@@ -147,14 +148,19 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
}
}
- $table_headers = [
- 'Nick' => _("Nick"),
- 'DECT' => _("DECT"),
- 'actions' => ''
+ return [
+ $supporters,
+ $members_confirmed,
+ $members_unconfirmed
];
-
- if ($angeltype['requires_driver_license'] && ($coordinator || $admin_angeltypes)) {
- $table_headers = [
+}
+
+/**
+ * Creates the needed member table headers according to given rights and settings from the angeltype.
+ */
+function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes) {
+ if ($angeltype['requires_driver_license'] && ($supporter || $admin_angeltypes)) {
+ return [
'Nick' => _("Nick"),
'DECT' => _("DECT"),
'wants_to_drive' => _("Driver"),
@@ -167,10 +173,34 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
'actions' => ''
];
}
+ return [
+ 'Nick' => _("Nick"),
+ 'DECT' => _("DECT"),
+ 'actions' => ''
+ ];
+}
+
+/**
+ * Render an angeltype page containing the member lists.
+ */
+function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angeltypes, $admin_angeltypes, $supporter, $user_driver_license, $user) {
+ $page = [
+ msg(),
+ AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user)
+ ];
+
+ $page[] = '<h3>' . _("Description") . '</h3>';
+ $parsedown = new Parsedown();
+ if ($angeltype['description'] != "") {
+ $page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
+ }
+
+ list($supporters, $members_confirmed, $members_unconfirmed) = AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $admin_angeltypes);
+ $table_headers = AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes);
- if (count($coordinators) > 0) {
- $page[] = '<h3>' . _("Coordinators") . '</h3>';
- $page[] = table($table_headers, $coordinators);
+ if (count($supporters) > 0) {
+ $page[] = '<h3>' . _("supporters") . '</h3>';
+ $page[] = table($table_headers, $supporters);
}
if (count($members_confirmed) > 0) {
@@ -230,6 +260,38 @@ function AngelTypes_list_view($angeltypes, $admin_angeltypes) {
]);
}
+/**
+ * Renders the about info for an angeltype.
+ */
+function AngelTypes_about_view_angeltype($angeltype) {
+ $parsedown = new Parsedown();
+
+ $html = '<h2>' . $angeltype['name'] . '</h2>';
+
+ if (isset($angeltype['user_angeltype_id'])) {
+ $buttons = [];
+ if ($angeltype['user_angeltype_id'] != null) {
+ $buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), 'cancel');
+ } else {
+ $buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
+ }
+ $html .= buttons($buttons);
+ }
+
+ if ($angeltype['restricted']) {
+ $html .= info(_("This angeltype is restricted by double-opt-in by a team supporter. Please show up at the according introduction meetings."), true);
+ }
+ if ($angeltype['description'] != "") {
+ $html .= '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
+ }
+ $html .= '<hr />';
+
+ return $html;
+}
+
+/**
+ * Renders a site that contains every angeltype and its description, basically as an overview of the needed help types.
+ */
function AngelTypes_about_view($angeltypes, $user_logged_in) {
global $faq_url;
@@ -243,27 +305,8 @@ function AngelTypes_about_view($angeltypes, $user_logged_in) {
'<p>' . _("Here is the list of teams and their tasks. If you have questions, read the FAQ.") . '</p>',
'<hr />'
];
- $parsedown = new Parsedown();
foreach ($angeltypes as $angeltype) {
- $content[] = '<h2>' . $angeltype['name'] . '</h2>';
-
- if (isset($angeltype['user_angeltype_id'])) {
- $buttons = [];
- if ($angeltype['user_angeltype_id'] != null) {
- $buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), 'cancel');
- } else {
- $buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
- }
- $content[] = buttons($buttons);
- }
-
- if ($angeltype['restricted']) {
- $content[] = info(_("This angeltype is restricted by double-opt-in by a team coordinator. Please show up at the according introduction meetings."), true);
- }
- if ($angeltype['description'] != "") {
- $content[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
- }
- $content[] = '<hr />';
+ $content[] = AngelTypes_about_view_angeltype($angeltype);
}
return page_with_title(_("Teams/Job description"), $content);
diff --git a/includes/view/Rooms_view.php b/includes/view/Rooms_view.php
index c820e983..7afdc67b 100644
--- a/includes/view/Rooms_view.php
+++ b/includes/view/Rooms_view.php
@@ -1,8 +1,17 @@
<?php
+use Engelsystem\ShiftsFilterRenderer;
+use Engelsystem\ShiftCalendarRenderer;
+
+function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalendarRenderer $shiftCalendarRenderer) {
+ return page_with_title(glyph('map-marker') . $room['Name'], [
+ $shiftsFilterRenderer->render(room_link($room)) ,
+ $shiftCalendarRenderer->render()
+ ]);
+}
function Room_name_render($room) {
global $privileges;
- if (in_array('admin_rooms', $privileges)) {
+ if (in_array('view_rooms', $privileges)) {
return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>';
}
return glyph('map-marker') . $room['Name'];
diff --git a/includes/view/ShiftCalendarLane.php b/includes/view/ShiftCalendarLane.php
new file mode 100644
index 00000000..33fccec3
--- /dev/null
+++ b/includes/view/ShiftCalendarLane.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Engelsystem;
+
+/**
+ * Represents a single lane in a shifts calendar.
+ */
+class ShiftCalendarLane {
+
+ private $firstBlockStartTime;
+
+ private $blockCount;
+
+ private $header;
+
+ private $shifts = [];
+
+ public function __construct($header, $firstBlockStartTime, $blockCount) {
+ $this->header = $header;
+ $this->firstBlockStartTime = $firstBlockStartTime;
+ $this->blockCount = $blockCount;
+ }
+
+ /**
+ * Adds a shift to the lane, but only if it fits.
+ * Returns true on success.
+ *
+ * @param Shift $shift
+ * The shift to add
+ * @return boolean true on success
+ */
+ public function addShift($shift) {
+ if ($this->shiftFits($shift)) {
+ $this->shifts[] = $shift;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if given shift fits into this lane.
+ *
+ * @param Shift $shift
+ * The shift to fit into this lane
+ */
+ public function shiftFits($newShift) {
+ foreach ($this->shifts as $laneShift) {
+ if (! ($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public function getHeader() {
+ return $this->header;
+ }
+
+ public function getShifts() {
+ return $this->shifts;
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php
new file mode 100644
index 00000000..89c1be4c
--- /dev/null
+++ b/includes/view/ShiftCalendarRenderer.php
@@ -0,0 +1,240 @@
+<?php
+
+namespace Engelsystem;
+
+class ShiftCalendarRenderer {
+
+ /**
+ * 15m * 60s/m = 900s
+ */
+ const SECONDS_PER_ROW = 900;
+
+ /**
+ * Height of a block in pixel.
+ * Do not change - corresponds with theme/css
+ */
+ const BLOCK_HEIGHT = 30;
+
+ /**
+ * Distance between two shifts in pixels
+ */
+ const MARGIN = 5;
+
+ private $lanes;
+
+ private $shiftsFilter;
+
+ private $firstBlockStartTime = null;
+
+ private $lastBlockEndTime = null;
+
+ private $blocksPerSlot = null;
+
+ public function __construct($shifts, ShiftsFilter $shiftsFilter) {
+ $this->shiftsFilter = $shiftsFilter;
+ $this->firstBlockStartTime = $this->calcFirstBlockStartTime($shifts);
+ $this->lastBlockEndTime = $this->calcLastBlockEndTime($shifts);
+ $this->lanes = $this->assignShiftsToLanes($shifts);
+ }
+
+ /**
+ * Assigns the shifts to different lanes per room if they collide
+ *
+ * @param Shift[] $shifts
+ * The shifts to assign
+ *
+ * @return Returns an array that assigns a room_id to an array of ShiftCalendarLane containing the shifts
+ */
+ private function assignShiftsToLanes($shifts) {
+ // array that assigns a room id to a list of lanes (per room)
+ $lanes = [];
+
+ foreach ($shifts as $shift) {
+ $room_id = $shift['RID'];
+ if (! isset($lanes[$room_id])) {
+ // initialize room with one lane
+ $header = Room_name_render([
+ 'RID' => $room_id,
+ 'Name' => $shift['room_name']
+ ]);
+ $lanes[$room_id] = [
+ new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot())
+ ];
+ }
+ // Try to add the shift to the existing lanes for this room
+ $shift_added = false;
+ foreach ($lanes[$room_id] as $lane) {
+ $shift_added = $lane->addShift($shift);
+ if ($shift_added == true) {
+ break;
+ }
+ }
+ // If all lanes for this room are busy, create a new lane and add shift to it
+ if ($shift_added == false) {
+ $newLane = new ShiftCalendarLane("", $this->getFirstBlockStartTime(), $this->getBlocksPerSlot());
+ if (! $newLane->addShift($shift)) {
+ engelsystem_error("Unable to add shift to new lane.");
+ }
+ $lanes[$room_id][] = $newLane;
+ }
+ }
+
+ return $lanes;
+ }
+
+ public function getFirstBlockStartTime() {
+ return $this->firstBlockStartTime;
+ }
+
+ public function getLastBlockEndTime() {
+ return $this->lastBlockEndTime;
+ }
+
+ public function getBlocksPerSlot() {
+ if ($this->blocksPerSlot == null) {
+ $this->blocksPerSlot = $this->calcBlocksPerSlot();
+ }
+ return $this->blocksPerSlot;
+ }
+
+ /**
+ * Renders the whole calendar
+ *
+ * @return the generated html
+ */
+ public function render() {
+ return div('shift-calendar', [
+ $this->renderTimeLane(),
+ $this->renderShiftLanes()
+ ]) . $this->renderLegend();
+ }
+
+ /**
+ * Renders the lanes containing the shifts
+ */
+ private function renderShiftLanes() {
+ $html = "";
+ foreach ($this->lanes as $room_lanes) {
+ foreach ($room_lanes as $lane) {
+ $html .= $this->renderLane($lane);
+ }
+ }
+ return $html;
+ }
+
+ /**
+ * Renders a single lane
+ *
+ * @param ShiftCalendarLane $lane
+ * The lane to render
+ */
+ private function renderLane(ShiftCalendarLane $lane) {
+ global $user;
+
+ $shift_renderer = new ShiftCalendarShiftRenderer();
+ $html = "";
+ $rendered_until = $this->getFirstBlockStartTime();
+ foreach ($lane->getShifts() as $shift) {
+ while ($rendered_until + ShiftCalendarRenderer::SECONDS_PER_ROW <= $shift['start']) {
+ $html .= $this->renderTick($rendered_until);
+ $rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
+ }
+
+ list($shift_height, $shift_html) = $shift_renderer->render($shift, $user);
+ $html .= $shift_html;
+ $rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
+ }
+ while ($rendered_until < $this->getLastBlockEndTime()) {
+ $html .= $this->renderTick($rendered_until);
+ $rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
+ }
+
+ return div('lane', [
+ div('header', $lane->getHeader()),
+ $html
+ ]);
+ }
+
+ /**
+ * Renders a tick/block for given time
+ *
+ * @param int $time
+ * unix timestamp
+ * @param boolean $label
+ * Should time labels be generated?
+ * @return rendered tick html
+ */
+ private function renderTick($time, $label = false) {
+ if ($time % (24 * 60 * 60) == 23 * 60 * 60) {
+ if (! $label) {
+ return div('tick day');
+ }
+ return div('tick day', [
+ date('Y-m-d<b\r />H:i', $time)
+ ]);
+ } elseif ($time % (60 * 60) == 0) {
+ if (! $label) {
+ return div('tick hour');
+ }
+ return div('tick hour', [
+ date('H:i', $time)
+ ]);
+ }
+ return div('tick');
+ }
+
+ /**
+ * Renders the left time lane including hour/day ticks
+ */
+ private function renderTimeLane() {
+ $time_slot = [
+ div('header', [
+ _("Time")
+ ])
+ ];
+ for ($block = 0; $block < $this->getBlocksPerSlot(); $block ++) {
+ $thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW);
+ $time_slot[] = $this->renderTick($thistime, true);
+ }
+ return div('lane time', $time_slot);
+ }
+
+ private function calcFirstBlockStartTime($shifts) {
+ $start_time = $this->shiftsFilter->getEndTime();
+ foreach ($shifts as $shift) {
+ if ($shift['start'] < $start_time) {
+ $start_time = $shift['start'];
+ }
+ }
+ return ShiftCalendarRenderer::SECONDS_PER_ROW * floor(($start_time - 60 * 60) / ShiftCalendarRenderer::SECONDS_PER_ROW);
+ }
+
+ private function calcLastBlockEndTime($shifts) {
+ $end_time = $this->shiftsFilter->getStartTime();
+ foreach ($shifts as $shift) {
+ if ($shift['end'] > $end_time) {
+ $end_time = $shift['end'];
+ }
+ }
+ return ShiftCalendarRenderer::SECONDS_PER_ROW * ceil(($end_time + 60 * 60) / ShiftCalendarRenderer::SECONDS_PER_ROW);
+ }
+
+ private function calcBlocksPerSlot() {
+ return ceil(($this->getLastBlockEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW);
+ }
+
+ /**
+ * Renders a legend explaining the shift coloring
+ */
+ private function renderLegend() {
+ return div('legend', [
+ label(_('Your shift'), 'primary'),
+ label(_('Help needed'), 'danger'),
+ label(_('Other angeltype needed / collides with my shifts'), 'warning'),
+ label(_('Shift is full'), 'success'),
+ label(_('Shift running/ended'), 'default')
+ ]);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php
new file mode 100644
index 00000000..7aa79e07
--- /dev/null
+++ b/includes/view/ShiftCalendarShiftRenderer.php
@@ -0,0 +1,181 @@
+<?php
+
+namespace Engelsystem;
+
+/**
+ * Renders a single shift for the shift calendar
+ */
+class ShiftCalendarShiftRenderer {
+
+ /**
+ * Renders a shift
+ *
+ * @param Shift $shift
+ * The shift to render
+ * @param User $user
+ * The user who is viewing the shift calendar
+ */
+ public function render($shift, $user) {
+ $info_text = "";
+ if ($shift['title'] != '') {
+ $info_text = glyph('info-sign') . $shift['title'] . '<br>';
+ }
+ list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $user);
+ $class = $this->classForSignupState($shift_signup_state);
+
+ $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW);
+ $blocks = max(1, $blocks);
+ return [
+ $blocks,
+ '<td class="shift" rowspan="' . $blocks . '">' . div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [
+ $this->renderShiftHead($shift),
+ div('panel-body', [
+ $info_text,
+ Room_name_render([
+ 'RID' => $shift['RID'],
+ 'Name' => $shift['room_name']
+ ])
+ ]),
+ $shifts_row,
+ div('shift-spacer')
+ ]) . '</td>'
+ ];
+ }
+
+ private function classForSignupState(ShiftSignupState $shiftSignupState) {
+ switch ($shiftSignupState->getState()) {
+ case ShiftSignupState::ADMIN:
+ case ShiftSignupState::OCCUPIED:
+ return 'success';
+
+ case ShiftSignupState::SIGNED_UP:
+ return 'primary';
+
+ case ShiftSignupState::SHIFT_ENDED:
+ return 'default';
+
+ case ShiftSignupState::ANGELTYPE:
+ case ShiftSignupState::COLLIDES:
+ return 'warning';
+
+ case ShiftSignupState::FREE:
+ return 'danger';
+ }
+ }
+
+ private function renderShiftNeededAngeltypes($shift, $user) {
+ global $privileges;
+
+ $html = "";
+ $shift_signup_state = null;
+ $angeltypes = NeededAngelTypes_by_shift($shift['SID']);
+ foreach ($angeltypes as $angeltype) {
+ list($angeltype_signup_state, $angeltype_html) = $this->renderShiftNeededAngeltype($shift, $angeltype, $user);
+ if ($shift_signup_state == null) {
+ $shift_signup_state = $angeltype_signup_state;
+ } else {
+ $shift_signup_state->combineWith($angeltype_signup_state);
+ }
+ $html .= $angeltype_html;
+ }
+ if (in_array('user_shifts_admin', $privileges)) {
+ $html .= '<li class="list-group-item">' . button(page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs') . '</li>';
+ }
+ if ($html != '') {
+ return [
+ $shift_signup_state,
+ '<ul class="list-group">' . $html . '</ul>'
+ ];
+ }
+ return [
+ $shift_signup_state,
+ ""
+ ];
+ }
+
+ /**
+ * Renders a list entry containing the needed angels for an angeltype
+ *
+ * @param Shift $shift
+ * The shift which is rendered
+ * @param Angeltype $angeltype
+ * The angeltype, containing informations about needed angeltypes and already signed up angels
+ * @param User $user
+ * The user who is viewing the shift calendar
+ */
+ private function renderShiftNeededAngeltype($shift, $angeltype, $user) {
+ $entry_list = [];
+ foreach ($angeltype['shift_entries'] as $entry) {
+ $style = $entry['freeloaded'] ? " text-decoration: line-through;" : '';
+ $entry_list[] = "<span style=\"$style\">" . User_Nick_render(User($entry['UID'])) . "</span>";
+ }
+ $shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype);
+ $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $shift_signup_state->getFreeEntries()), $shift_signup_state->getFreeEntries());
+ switch ($shift_signup_state->getState()) {
+ case ShiftSignupState::ADMIN:
+ case ShiftSignupState::FREE:
+ // When admin or free display a link + button for sign up
+ $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 btn-primary');
+ break;
+
+ case ShiftSignupState::SHIFT_ENDED:
+ // No link and add a text hint, when the shift ended
+ $entry_list[] = $inner_text . ' (' . _('ended') . ')';
+ break;
+
+ case ShiftSignupState::ANGELTYPE:
+ if ($angeltype['restricted'] == 1) {
+ // User has to be confirmed on the angeltype first
+ $entry_list[] = $inner_text . glyph('lock');
+ } else {
+ // Add link to join the angeltype first
+ $entry_list[] = $inner_text . '<br />' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs');
+ }
+ break;
+
+ case ShiftSignupState::COLLIDES:
+ case ShiftSignupState::SIGNED_UP:
+ // Shift collides or user is already signed up: No signup allowed
+ $entry_list[] = $inner_text;
+ break;
+
+ case ShiftSignupState::OCCUPIED:
+ // Shift is full
+ break;
+ }
+
+ $shifts_row = '<li class="list-group-item">';
+ $shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> ';
+ $shifts_row .= join(", ", $entry_list);
+ $shifts_row .= '</li>';
+ return [
+ $shift_signup_state,
+ $shifts_row
+ ];
+ }
+
+ /**
+ * Renders the shift header
+ *
+ * @param Shift $shift
+ * The shift
+ */
+ private function renderShiftHead($shift) {
+ global $privileges;
+
+ $header_buttons = "";
+ if (in_array('admin_shifts', $privileges)) {
+ $header_buttons = '<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>';
+ }
+ $shift_heading = date('H:i', $shift['start']) . ' &dash; ' . date('H:i', $shift['end']) . ' &mdash; ' . ShiftType($shift['shifttype_id'])['name'];
+ return div('panel-heading', [
+ '<a href="' . shift_link($shift) . '">' . $shift_heading . '</a>',
+ $header_buttons
+ ]);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/includes/view/ShiftsFilterRenderer.php b/includes/view/ShiftsFilterRenderer.php
new file mode 100644
index 00000000..301f31a2
--- /dev/null
+++ b/includes/view/ShiftsFilterRenderer.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Engelsystem;
+
+class ShiftsFilterRenderer {
+
+ /**
+ * The shiftFilter to render.
+ *
+ * @var ShiftsFilter
+ */
+ private $shiftsFilter;
+
+ /**
+ * Should the filter display a day selection.
+ *
+ * @var boolean
+ */
+ private $daySelectionEnabled = false;
+
+ /**
+ * Days that can be selected.
+ * Format Y-m-d
+ *
+ * @var string[]
+ */
+ private $days = [];
+
+ public function __construct(ShiftsFilter $shiftsFilter) {
+ $this->shiftsFilter = $shiftsFilter;
+ }
+
+ /**
+ * Renders the filter.
+ *
+ * @return Generated HTML
+ */
+ public function render($link_base) {
+ $toolbar = [];
+ if ($this->daySelectionEnabled && ! empty($this->days)) {
+ $selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
+ $day_dropdown_items = [];
+ foreach ($this->days as $day) {
+ $day_dropdown_items[] = toolbar_item_link($link_base . '&shifts_filter_day=' . $day, '', $day);
+ }
+ $toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
+ }
+ return div('form-group', [
+ toolbar_pills($toolbar)
+ ]);
+ }
+
+ /**
+ * Should the filter display a day selection.
+ */
+ public function enableDaySelection($days) {
+ $this->daySelectionEnabled = true;
+ $this->days = $days;
+ }
+
+ /**
+ * Should the filter display a day selection.
+ */
+ public function isDaySelectionEnabled() {
+ return $this->daySelectionEnabled;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php
index 95282eb5..8e52eb9d 100644
--- a/includes/view/Shifts_view.php
+++ b/includes/view/Shifts_view.php
@@ -16,12 +16,10 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null,
if ($user_angeltype == null) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype === false) {
- engelsystem_error('Unable to load user angeltype.');
- }
}
- if (Shift_signup_allowed($shift, $angeltype, $user_angeltype, $user_shifts)) {
+ $shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype, $user_angeltype, $user_shifts);
+ if ($shift_signup_state->isSignupAllowed()) {
return button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'));
} elseif ($user_angeltype == null) {
return button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']));
diff --git a/includes/view/UserAngelTypes_view.php b/includes/view/UserAngelTypes_view.php
index 802ec5aa..da4a2352 100644
--- a/includes/view/UserAngelTypes_view.php
+++ b/includes/view/UserAngelTypes_view.php
@@ -1,12 +1,12 @@
<?php
-function UserAngelType_update_view($user_angeltype, $user, $angeltype, $coordinator) {
- return page_with_title($coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"), [
+function UserAngelType_update_view($user_angeltype, $user, $angeltype, $supporter) {
+ return page_with_title($supporter ? _("Add supporter rights") : _("Remove supporter rights"), [
msg(),
- info(sprintf($coordinator ? _("Do you really want to add coordinator rights for %s to %s?") : _("Do you really want to remove coordinator rights for %s from %s?"), $angeltype['name'], User_Nick_render($user)), true),
+ info(sprintf($supporter ? _("Do you really want to add supporter rights for %s to %s?") : _("Do you really want to remove supporter rights for %s from %s?"), $angeltype['name'], User_Nick_render($user)), true),
buttons([
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
- button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $user_angeltype['id'] . '&coordinator=' . ($coordinator ? '1' : '0') . '&confirmed', _("yes"), 'ok')
+ button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $user_angeltype['id'] . '&supporter=' . ($supporter ? '1' : '0') . '&confirmed', _("yes"), 'ok')
])
]);
}
diff --git a/includes/view/UserDriverLicenses_view.php b/includes/view/UserDriverLicenses_view.php
index 041c8734..c07e5e1f 100644
--- a/includes/view/UserDriverLicenses_view.php
+++ b/includes/view/UserDriverLicenses_view.php
@@ -18,7 +18,7 @@ function UserDriverLicense_edit_view($user_source, $wants_to_drive, $has_car, $h
]),
msg(),
form([
- form_info(_("Privacy"), _("Your driving license information is only visible for coordinators and admins.")),
+ form_info(_("Privacy"), _("Your driving license information is only visible for supporters and admins.")),
form_checkbox('wants_to_drive', _("I am willing to operate cars for the PL"), $wants_to_drive),
div('panel panel-default', [
div('panel-body', [
diff --git a/includes/view/User_view.php b/includes/view/User_view.php
index a620aa80..7d677f33 100644
--- a/includes/view/User_view.php
+++ b/includes/view/User_view.php
@@ -20,6 +20,66 @@ $tshirt_sizes = [
];
/**
+ * Renders user settings page
+ *
+ * @param User $user_source
+ * The user
+ * @param array<String> $locales
+ * Available languages
+ * @param array<String> $themes
+ * Available themes
+ */
+function User_settings_view($user_source, $locales, $themes, $buildup_start_date, $teardown_end_date, $enable_tshirt_size, $tshirt_sizes) {
+ return page_with_title(settings_title(), [
+ 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"), $user_source['Nick'], true),
+ form_text('lastname', _("Last name"), $user_source['Name']),
+ form_text('prename', _("First name"), $user_source['Vorname']),
+ form_date('planned_arrival_date', _("Planned date of arrival") . ' ' . entry_required(), $user_source['planned_arrival_date'], $buildup_start_date, $teardown_end_date),
+ form_date('planned_departure_date', _("Planned date of departure"), $user_source['planned_departure_date'], $buildup_start_date, $teardown_end_date),
+ form_text('age', _("Age"), $user_source['Alter']),
+ form_text('tel', _("Phone"), $user_source['Telefon']),
+ form_text('dect', _("DECT"), $user_source['DECT']),
+ form_text('mobile', _("Mobile"), $user_source['Handy']),
+ form_text('mail', _("E-Mail") . ' ' . entry_required(), $user_source['email']),
+ form_checkbox('email_shiftinfo', _("The engelsystem is allowed to send me an email (e.g. when my shifts change)"), $user_source['email_shiftinfo']),
+ form_checkbox('email_by_human_allowed', _("Humans are allowed to send me an email (e.g. for ticket vouchers)"), $user_source['email_by_human_allowed']),
+ form_text('jabber', _("Jabber"), $user_source['jabber']),
+ form_text('hometown', _("Hometown"), $user_source['Hometown']),
+ $enable_tshirt_size ? form_select('tshirt_size', _("Shirt size"), $tshirt_sizes, $user_source['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, $user_source['color']),
+ form_submit('submit_theme', _("Save"))
+ ]),
+ form([
+ form_info(_("Here you can choose your language:")),
+ form_select('language', _("Language:"), $locales, $user_source['Sprache']),
+ form_submit('submit_language', _("Save"))
+ ])
+ ])
+ ])
+ ]);
+}
+
+/**
* Displays the welcome message to the user and shows a login form.
*/
function User_registration_success_view($event_welcome_message) {
@@ -112,24 +172,24 @@ function Users_view($users, $order_by, $arrived_count, $active_count, $force_act
'actions' => '<strong>' . count($users) . '</strong>'
];
- return page_with_title(_('All users'), [
+ return page_with_title(_("All users"), [
msg(),
buttons([
- button(page_link_to('register'), glyph('plus') . _('New user'))
+ button(page_link_to('register'), glyph('plus') . _("New user"))
]),
table([
- 'Nick' => Users_table_header_link('Nick', _('Nick'), $order_by),
- 'Vorname' => Users_table_header_link('Vorname', _('Prename'), $order_by),
- 'Name' => Users_table_header_link('Name', _('Name'), $order_by),
- 'DECT' => Users_table_header_link('DECT', _('DECT'), $order_by),
- 'Gekommen' => Users_table_header_link('Gekommen', _('Arrived'), $order_by),
- 'got_voucher' => Users_table_header_link('got_voucher', _('Voucher'), $order_by),
+ 'Nick' => Users_table_header_link('Nick', _("Nick"), $order_by),
+ 'Vorname' => Users_table_header_link('Vorname', _("Prename"), $order_by),
+ 'Name' => Users_table_header_link('Name', _("Name"), $order_by),
+ 'DECT' => Users_table_header_link('DECT', _("DECT"), $order_by),
+ 'Gekommen' => Users_table_header_link('Gekommen', _("Arrived"), $order_by),
+ 'got_voucher' => Users_table_header_link('got_voucher', _("Voucher"), $order_by),
'freeloads' => _('Freeloads'),
- 'Aktiv' => Users_table_header_link('Aktiv', _('Active'), $order_by),
- 'force_active' => Users_table_header_link('force_active', _('Forced'), $order_by),
- 'Tshirt' => Users_table_header_link('Tshirt', _('T-Shirt'), $order_by),
- 'Size' => Users_table_header_link('Size', _('Size'), $order_by),
- 'lastLogIn' => Users_table_header_link('lastLogIn', _('Last login'), $order_by),
+ 'Aktiv' => Users_table_header_link('Aktiv', _("Active"), $order_by),
+ 'force_active' => Users_table_header_link('force_active', _("Forced"), $order_by),
+ 'Tshirt' => Users_table_header_link('Tshirt', _("T-Shirt"), $order_by),
+ 'Size' => Users_table_header_link('Size', _("Size"), $order_by),
+ 'lastLogIn' => Users_table_header_link('lastLogIn', _("Last login"), $order_by),
'actions' => ''
], $users)
]);
@@ -332,7 +392,7 @@ function User_angeltypes_render($user_angeltypes) {
} else {
$class = 'text-success';
}
- $output[] = '<a href="' . angeltype_link($angeltype['id']) . '" class="' . $class . '">' . ($angeltype['coordinator'] ? glyph('education') : '') . $angeltype['name'] . '</a>';
+ $output[] = '<a href="' . angeltype_link($angeltype['id']) . '" class="' . $class . '">' . ($angeltype['supporter'] ? glyph('education') : '') . $angeltype['name'] . '</a>';
}
return join('<br />', $output);
}