diff options
Diffstat (limited to 'includes/pages')
-rw-r--r-- | includes/pages/admin_active.php | 84 | ||||
-rw-r--r-- | includes/pages/admin_arrive.php | 138 | ||||
-rw-r--r-- | includes/pages/admin_import.php | 4 | ||||
-rw-r--r-- | includes/pages/admin_rooms.php | 104 | ||||
-rw-r--r-- | includes/pages/admin_shifts.php | 6 | ||||
-rw-r--r-- | includes/pages/admin_user.php | 6 | ||||
-rw-r--r-- | includes/pages/guest_login.php | 26 | ||||
-rw-r--r-- | includes/pages/user_myshifts.php | 7 | ||||
-rw-r--r-- | includes/pages/user_settings.php | 29 | ||||
-rw-r--r-- | includes/pages/user_shifts.php | 14 |
10 files changed, 304 insertions, 114 deletions
diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 9046ca2d..e3fa0996 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -1,22 +1,27 @@ <?php + function admin_active_title() { return _("Active angels"); } function admin_active() { global $tshirt_sizes, $shift_sum_formula; - + $msg = ""; $search = ""; $forced_count = sql_num_query("SELECT * FROM `User` WHERE `force_active`=1"); $count = $forced_count; $limit = ""; $set_active = ""; + if (isset($_REQUEST['search'])) $search = strip_request_item('search'); + + $show_all_shifts = isset($_REQUEST['show_all_shifts']); + if (isset($_REQUEST['set_active'])) { $ok = true; - + if (isset($_REQUEST['count']) && preg_match("/^[0-9]+$/", $_REQUEST['count'])) { $count = strip_request_item('count'); if ($count < $forced_count) { @@ -27,7 +32,7 @@ function admin_active() { $ok = false; $msg .= error(_("Please enter a number of angels to be marked as active."), true); } - + if ($ok) $limit = " LIMIT " . $count; if (isset($_REQUEST['ack'])) { @@ -45,15 +50,16 @@ function admin_active() { sql_query("UPDATE `User` SET `Aktiv` = 1 WHERE `UID`='" . sql_escape($usr['UID']) . "'"); $user_nicks[] = User_Nick_render($usr); } + sql_query("UPDATE `User` SET `Aktiv`=1 WHERE `force_active`=TRUE"); engelsystem_log("These angels are active now: " . join(", ", $user_nicks)); - + $limit = ""; $msg = success(_("Marked angels."), true); } else { $set_active = '<a href="' . page_link_to('admin_active') . '&serach=' . $search . '">« ' . _("back") . '</a> | <a href="' . page_link_to('admin_active') . '&search=' . $search . '&count=' . $count . '&set_active&ack">' . _("apply") . '</a>'; } } - + if (isset($_REQUEST['active']) && preg_match("/^[0-9]+$/", $_REQUEST['active'])) { $id = $_REQUEST['active']; $user_source = User($id); @@ -91,15 +97,16 @@ function admin_active() { } else $msg = error(_("Angel not found."), true); } - + $users = sql_select(" 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` - WHERE `User`.`Gekommen` = 1 + WHERE `User`.`Gekommen` = 1 + " . ($show_all_shifts ? "" : "AND (`Shifts`.`end` < " . time() . " OR `Shifts`.`end` IS NULL)") . " GROUP BY `User`.`UID` ORDER BY `force_active` DESC, `shift_length` DESC" . $limit); - + $matched_users = array(); if ($search == "") $tokens = array(); @@ -123,41 +130,47 @@ function admin_active() { $usr['active'] = glyph_bool($usr['Aktiv'] == 1); $usr['force_active'] = glyph_bool($usr['force_active'] == 1); $usr['tshirt'] = glyph_bool($usr['Tshirt'] == 1); - + $actions = array(); if ($usr['Aktiv'] == 0) - $actions[] = '<a href="' . page_link_to('admin_active') . '&active=' . $usr['UID'] . '&search=' . $search . '">' . _("set active") . '</a>'; + $actions[] = '<a href="' . page_link_to('admin_active') . '&active=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("set active") . '</a>'; if ($usr['Aktiv'] == 1 && $usr['Tshirt'] == 0) { - $actions[] = '<a href="' . page_link_to('admin_active') . '&not_active=' . $usr['UID'] . '&search=' . $search . '">' . _("remove active") . '</a>'; - $actions[] = '<a href="' . page_link_to('admin_active') . '&tshirt=' . $usr['UID'] . '&search=' . $search . '">' . _("got t-shirt") . '</a>'; + $actions[] = '<a href="' . page_link_to('admin_active') . '&not_active=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("remove active") . '</a>'; + $actions[] = '<a href="' . page_link_to('admin_active') . '&tshirt=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("got t-shirt") . '</a>'; } if ($usr['Tshirt'] == 1) - $actions[] = '<a href="' . page_link_to('admin_active') . '&not_tshirt=' . $usr['UID'] . '&search=' . $search . '">' . _("remove t-shirt") . '</a>'; - + $actions[] = '<a href="' . page_link_to('admin_active') . '&not_tshirt=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("remove t-shirt") . '</a>'; + $usr['actions'] = join(' ', $actions); - + $matched_users[] = $usr; } - - $shirt_statistics = sql_select(" - SELECT `Size`, count(`Size`) AS `count` - FROM `User` - WHERE `Tshirt`=1 - GROUP BY `Size` - ORDER BY `count` DESC"); - $shirt_statistics[] = array( - 'Size' => '<b>' . _("Sum") . '</b>', - 'count' => '<b>' . sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Tshirt`=1") . '</b>' - ); - + + $shirt_statistics = []; + foreach ($tshirt_sizes as $size => $_) { + if ($size != '') { + $shirt_statistics[] = [ + 'size' => $size, + 'needed' => sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Size`='" . sql_escape($size) . "' AND `Gekommen`=1"), + 'given' => sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Size`='" . sql_escape($size) . "' AND `Tshirt`=1") + ]; + } + } + $shirt_statistics[] = [ + 'size' => '<b>' . _("Sum") . '</b>', + 'needed' => '<b>' . User_arrived_count() . '</b>', + 'given' => '<b>' . sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Tshirt`=1") . '</b>' + ]; + return page_with_title(admin_active_title(), array( form(array( form_text('search', _("Search angel:"), $search), - form_submit('submit', _("Search")) - )), + form_checkbox('show_all_shifts', _("Show all shifts"), $show_all_shifts), + form_submit('submit', _("Search")) + ), page_link_to('admin_active')), $set_active == "" ? form(array( form_text('count', _("How much angels should be active?"), $count), - form_submit('set_active', _("Preview")) + form_submit('set_active', _("Preview")) )) : $set_active, msg(), table(array( @@ -168,13 +181,14 @@ function admin_active() { 'active' => _("Active?"), 'force_active' => _("Forced"), 'tshirt' => _("T-shirt?"), - 'actions' => "" + 'actions' => "" ), $matched_users), - '<h2>' . _("Given shirts") . '</h2>', + '<h2>' . _("Shirt statistics") . '</h2>', table(array( - 'Size' => _("Size"), - 'count' => _("Count") - ), $shirt_statistics) + 'size' => _("Size"), + 'needed' => _("Needed shirts"), + 'given' => _("Given shirts") + ), $shirt_statistics) )); } ?> diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index f51ef7ac..c7fcab63 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -1,4 +1,5 @@ <?php + function admin_arrive_title() { return _("Arrived angels"); } @@ -13,7 +14,7 @@ function admin_arrive() { $id = $_REQUEST['reset']; $user_source = User($id); if ($user_source != null) { - sql_query("UPDATE `User` SET `Gekommen`=0 WHERE `UID`='" . sql_escape($id) . "' LIMIT 1"); + sql_query("UPDATE `User` SET `Gekommen`=0, `arrival_date` = NULL WHERE `UID`='" . sql_escape($id) . "' LIMIT 1"); engelsystem_log("User set to not arrived: " . User_Nick_render($user_source)); $msg = success(_("Reset done. Angel has not arrived."), true); } else @@ -22,7 +23,7 @@ function admin_arrive() { $id = $_REQUEST['arrived']; $user_source = User($id); if ($user_source != null) { - sql_query("UPDATE `User` SET `Gekommen`=1 WHERE `UID`='" . sql_escape($id) . "' LIMIT 1"); + sql_query("UPDATE `User` SET `Gekommen`=1, `arrival_date`='" . time() . "' WHERE `UID`='" . sql_escape($id) . "' LIMIT 1"); engelsystem_log("User set has arrived: " . User_Nick_render($user_source)); $msg = success(_("Angel has been marked as arrived."), true); } else @@ -30,10 +31,13 @@ function admin_arrive() { } $users = sql_select("SELECT * FROM `User` ORDER BY `Nick`"); + $arrival_count_at_day = []; + $planned_arrival_count_at_day = []; + $planned_departure_count_at_day = []; $table = ""; - $users_matched = array(); + $users_matched = []; if ($search == "") - $tokens = array(); + $tokens = []; else $tokens = explode(" ", $search); foreach ($users as $usr) { @@ -48,18 +52,78 @@ function admin_arrive() { if (! $match) continue; } - $table .= '<tr>'; - $table .= '<td>' . User_Nick_render($usr) . '</td>'; + $usr['nick'] = User_Nick_render($usr); + if ($usr['planned_departure_date'] != null) + $usr['rendered_planned_departure_date'] = date('Y-m-d', $usr['planned_departure_date']); + else + $usr['rendered_planned_departure_date'] = '-'; + $usr['rendered_planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']); + $usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-"; $usr['arrived'] = $usr['Gekommen'] == 1 ? _("yes") : ""; $usr['actions'] = $usr['Gekommen'] == 1 ? '<a href="' . page_link_to('admin_arrive') . '&reset=' . $usr['UID'] . '&search=' . $search . '">' . _("reset") . '</a>' : '<a href="' . page_link_to('admin_arrive') . '&arrived=' . $usr['UID'] . '&search=' . $search . '">' . _("arrived") . '</a>'; - if ($usr['Gekommen'] == 1) - $table .= '<td>yes</td><td><a href="' . page_link_to('admin_arrive') . '&reset=' . $usr['UID'] . '&search=' . $search . '">reset</a></td>'; - else - $table .= '<td></td><td><a href="' . page_link_to('admin_arrive') . '&arrived=' . $usr['UID'] . '&search=' . $search . '">arrived</a></td>'; - $table .= '</tr>'; + + if ($usr['arrival_date'] > 0) { + $day = date('Y-m-d', $usr['arrival_date']); + if (! isset($arrival_count_at_day[$day])) + $arrival_count_at_day[$day] = 0; + $arrival_count_at_day[$day] ++; + } + + if ($usr['planned_arrival_date'] != null) { + $day = date('Y-m-d', $usr['planned_arrival_date']); + if (! isset($planned_arrival_count_at_day[$day])) + $planned_arrival_count_at_day[$day] = 0; + $planned_arrival_count_at_day[$day] ++; + } + + if ($usr['planned_departure_date'] != null && $usr['Gekommen'] == 1) { + $day = date('Y-m-d', $usr['planned_departure_date']); + if (! isset($planned_departure_count_at_day[$day])) + $planned_departure_count_at_day[$day] = 0; + $planned_departure_count_at_day[$day] ++; + } + $users_matched[] = $usr; } + + ksort($arrival_count_at_day); + ksort($planned_arrival_count_at_day); + ksort($planned_departure_count_at_day); + + $arrival_at_day = []; + $arrival_sum = 0; + foreach ($arrival_count_at_day as $day => $count) { + $arrival_sum += $count; + $arrival_at_day[$day] = [ + 'day' => $day, + 'count' => $count, + 'sum' => $arrival_sum + ]; + } + + $planned_arrival_sum_at_day = []; + $planned_arrival_sum = 0; + foreach ($planned_arrival_count_at_day as $day => $count) { + $planned_arrival_sum += $count; + $planned_arrival_at_day[$day] = [ + 'day' => $day, + 'count' => $count, + 'sum' => $planned_arrival_sum + ]; + } + + $planned_departure_at_day = []; + $planned_departure_sum = 0; + foreach ($planned_departure_count_at_day as $day => $count) { + $planned_departure_sum += $count; + $planned_departure_at_day[$day] = [ + 'day' => $day, + 'count' => $count, + 'sum' => $planned_departure_sum + ]; + } + return page_with_title(admin_arrive_title(), array( msg(), form(array( @@ -68,9 +132,59 @@ function admin_arrive() { )), table(array( 'nick' => _("Nickname"), + 'rendered_planned_arrival_date' => _("Planned arrival"), 'arrived' => _("Arrived?"), + 'rendered_arrival_date' => _("Arrival date"), + 'rendered_planned_departure_date' => _("Planned departure"), 'actions' => "" - ), $users_matched) + ), $users_matched), + div('row', [ + div('col-md-4', [ + heading(_("Planned arrival statistics"), 2), + bargraph('planned_arrives', 'day', [ + 'count' => _("arrived"), + 'sum' => _("arrived sum") + ], [ + 'count' => '#090', + 'sum' => '#888' + ], $planned_arrival_at_day), + table([ + 'day' => _("Date"), + 'count' => _("Count"), + 'sum' => _("Sum") + ], $planned_arrival_at_day) + ]), + div('col-md-4', [ + heading(_("Arrival statistics"), 2), + bargraph('arrives', 'day', [ + 'count' => _("arrived"), + 'sum' => _("arrived sum") + ], [ + 'count' => '#090', + 'sum' => '#888' + ], $arrival_at_day), + table([ + 'day' => _("Date"), + 'count' => _("Count"), + 'sum' => _("Sum") + ], $arrival_at_day) + ]), + div('col-md-4', [ + heading(_("Planned departure statistics"), 2), + bargraph('planned_departures', 'day', [ + 'count' => _("arrived"), + 'sum' => _("arrived sum") + ], [ + 'count' => '#090', + 'sum' => '#888' + ], $planned_departure_at_day), + table([ + 'day' => _("Date"), + 'count' => _("Count"), + 'sum' => _("Sum") + ], $planned_departure_at_day) + ]) + ]) )); } ?> diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php index 786ea08b..63104026 100644 --- a/includes/pages/admin_import.php +++ b/includes/pages/admin_import.php @@ -162,7 +162,9 @@ function admin_import() { list($rooms_new, $rooms_deleted) = prepare_rooms($import_file); foreach ($rooms_new as $room) { - sql_query("INSERT INTO `Room` SET `Name`='" . sql_escape($room) . "', `FromPentabarf`='Y', `Show`='Y'"); + $result = Room_create($room, true, true); + if ($result === false) + engelsystem_error('Unable to create room.'); $rooms_import[trim($room)] = sql_id(); } foreach ($rooms_deleted as $room) diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php index 777ff6be..2d5e5ae4 100644 --- a/includes/pages/admin_rooms.php +++ b/includes/pages/admin_rooms.php @@ -1,11 +1,12 @@ <?php + function admin_rooms_title() { return _("Rooms"); } function admin_rooms() { global $user; - + $rooms_source = sql_select("SELECT * FROM `Room` ORDER BY `Name`"); $rooms = array(); foreach ($rooms_source as $room) @@ -15,17 +16,17 @@ function admin_rooms() { 'public' => $room['show'] == 'Y' ? '✓' : '', 'actions' => buttons(array( 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') - )) + button(page_link_to('admin_rooms') . '&show=delete&id=' . $room['RID'], _("delete"), 'btn-xs') + )) ); - + if (isset($_REQUEST['show'])) { $msg = ""; $name = ""; $from_pentabarf = ""; $public = 'Y'; $number = ""; - + $angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); $angeltypes = array(); $angeltypes_count = array(); @@ -33,7 +34,7 @@ function admin_rooms() { $angeltypes[$angeltype['id']] = $angeltype['name']; $angeltypes_count[$angeltype['id']] = 0; } - + if (test_request_int('id')) { $room = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($_REQUEST['id']) . "'"); if (count($room) > 0) { @@ -47,33 +48,33 @@ function admin_rooms() { } else redirect(page_link_to('admin_rooms')); } - + if ($_REQUEST['show'] == 'edit') { if (isset($_REQUEST['submit'])) { $ok = true; - + if (isset($_REQUEST['name']) && strlen(strip_request_item('name')) > 0) $name = strip_request_item('name'); else { $ok = false; $msg .= error(_("Please enter a name."), true); } - + if (isset($_REQUEST['from_pentabarf'])) $from_pentabarf = 'Y'; else $from_pentabarf = ''; - + if (isset($_REQUEST['public'])) $public = 'Y'; else $public = ''; - + if (isset($_REQUEST['number'])) $number = strip_request_item('number'); else $ok = false; - + foreach ($angeltypes as $angeltype_id => $angeltype) { if (isset($_REQUEST['angeltype_count_' . $angeltype_id]) && preg_match("/^[0-9]{1,4}$/", $_REQUEST['angeltype_count_' . $angeltype_id])) $angeltypes_count[$angeltype_id] = $_REQUEST['angeltype_count_' . $angeltype_id]; @@ -82,27 +83,30 @@ function admin_rooms() { $msg .= error(sprintf(_("Please enter needed angels for type %s.", $angeltype)), true); } } - + if ($ok) { if (isset($id)) { sql_query("UPDATE `Room` SET `Name`='" . sql_escape($name) . "', `FromPentabarf`='" . sql_escape($from_pentabarf) . "', `show`='" . sql_escape($public) . "', `Number`='" . sql_escape($number) . "' WHERE `RID`='" . sql_escape($id) . "' LIMIT 1"); engelsystem_log("Room updated: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number); } else { - sql_query("INSERT INTO `Room` SET `Name`='" . sql_escape($name) . "', `FromPentabarf`='" . sql_escape($from_pentabarf) . "', `show`='" . sql_escape($public) . "', `Number`='" . sql_escape($number) . "'"); - $id = sql_id(); + $id = Room_create($name, $from_pentabarf, $public, $number); + if ($id === false) + engelsystem_error("Unable to create room."); engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number); } - + sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($id) . "'"); $needed_angeltype_info = array(); foreach ($angeltypes_count as $angeltype_id => $angeltype_count) { - $angeltype_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "' LIMIT 1"); - if (count($angeltype_source) > 0) { + $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($id) . "', `angel_type_id`='" . sql_escape($angeltype_id) . "', `count`='" . sql_escape($angeltype_count) . "'"); - $needed_angeltype_info[] = $angeltypes_source[0]['name'] . ": " . $angeltype_count; + $needed_angeltype_info[] = $angeltype['name'] . ": " . $angeltype_count; } } - + engelsystem_log("Set needed angeltypes of room " . $name . " to: " . join(", ", $needed_angeltype_info)); success(_("Room saved.")); redirect(page_link_to("admin_rooms")); @@ -110,66 +114,68 @@ function admin_rooms() { } $angeltypes_count_form = array(); foreach ($angeltypes as $angeltype_id => $angeltype) - $angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', array(form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id]))); - + $angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', array( + form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id]) + )); + return page_with_title(admin_rooms_title(), array( buttons(array( - button(page_link_to('admin_rooms'), _("back"), 'back') + button(page_link_to('admin_rooms'), _("back"), 'back') )), $msg, form(array( - div('row', array( - div('col-md-6', array( - form_text('name', _("Name"), $name), - form_checkbox('from_pentabarf', _("Frab import"), $from_pentabarf), - form_checkbox('public', _("Public"), $public), - form_text('number', _("Room number"), $number) - )), - div('col-md-6', array( - div('row', array( - div('col-md-12', array( - form_info(_("Needed angels:")), + div('row', array( + div('col-md-6', array( + form_text('name', _("Name"), $name), + form_checkbox('from_pentabarf', _("Frab import"), $from_pentabarf), + form_checkbox('public', _("Public"), $public), + form_text('number', _("Room number"), $number) )), - join($angeltypes_count_form) - )) - )) - )), - form_submit('submit', _("Save")) - )) + div('col-md-6', array( + div('row', array( + div('col-md-12', array( + form_info(_("Needed angels:")) + )), + join($angeltypes_count_form) + )) + )) + )), + form_submit('submit', _("Save")) + )) )); } elseif ($_REQUEST['show'] == 'delete') { if (isset($_REQUEST['ack'])) { sql_query("DELETE FROM `Room` WHERE `RID`='" . sql_escape($id) . "' LIMIT 1"); sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($id) . "' LIMIT 1"); - + engelsystem_log("Room deleted: " . $name); success(sprintf(_("Room %s deleted."), $name)); redirect(page_link_to('admin_rooms')); } - + return page_with_title(admin_rooms_title(), array( buttons(array( - button(page_link_to('admin_rooms'), _("back"), 'back') + button(page_link_to('admin_rooms'), _("back"), 'back') )), sprintf(_("Do you want to delete room %s?"), $name), buttons(array( - button(page_link_to('admin_rooms') . '&show=delete&id=' . $id . '&ack', _("Delete"), 'delete') - )) + button(page_link_to('admin_rooms') . '&show=delete&id=' . $id . '&ack', _("Delete"), 'delete') + )) )); } } - + return page_with_title(admin_rooms_title(), array( buttons(array( - button(page_link_to('admin_rooms') . '&show=edit', _("add")) + button(page_link_to('admin_rooms') . '&show=edit', _("add")) )), msg(), table(array( 'name' => _("Name"), 'from_pentabarf' => _("Frab import"), 'public' => _("Public"), - 'actions' => "" - ), $rooms) + 'actions' => "" + ), $rooms) )); } ?> diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 5ff46fc9..346e9046 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -10,7 +10,7 @@ function admin_shifts() { $rid = 0; $start = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d") . " 00:00")->getTimestamp(); - $end = $start + 24 * 60 * 60; + $end = $start; $mode = 'single'; $angelmode = 'manually'; $length = ''; @@ -293,7 +293,7 @@ function admin_shifts() { $room_select = html_select_key('rid', 'rid', $room_array, $_REQUEST['rid']); $angel_types = ""; foreach ($types as $type) - $angel_types .= form_spinner('type_' . $type['id'], $type['name'], $needed_angel_types[$type['id']]); + $angel_types .= '<div class="col-md-4">' . form_spinner('type_' . $type['id'], $type['name'], $needed_angel_types[$type['id']]) . '</div>'; return page_with_title(admin_shifts_title(), array( msg(), @@ -316,7 +316,7 @@ function admin_shifts() { form_info(_("Needed angels"), ''), form_radio('angelmode', _("Take needed angels from room settings"), $angelmode == 'location', 'location'), form_radio('angelmode', _("The following angels are needed"), $angelmode == 'manually', 'manually'), - $angel_types, + '<div class="row">'.$angel_types.'</div>', '</div>', '</div>', form_submit('preview', _("Preview")) diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 18ed6210..ee244925 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -71,7 +71,7 @@ function admin_user() { $html .= " <tr><td>Hometown</td><td>" . "<input type=\"text\" size=\"40\" name=\"Hometown\" value=\"" . $user_source['Hometown'] . "\"></td></tr>\n"; - $html .= "</table>\n</td><td valign=\"top\">" . User_Avatar_render($user_source) . "</td></tr>"; + $html .= "</table>\n</td><td valign=\"top\"></td></tr>"; $html .= "</td></tr>\n"; $html .= "</table>\n<br />\n"; @@ -93,11 +93,11 @@ function admin_user() { $html .= "<hr />"; - $my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `uid` LIMIT 1"); + $my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id` LIMIT 1"); if (count($my_highest_group) > 0) $my_highest_group = $my_highest_group[0]['group_id']; - $his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($id) . "' ORDER BY `uid` LIMIT 1"); + $his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($id) . "' ORDER BY `group_id` LIMIT 1"); if (count($his_highest_group) > 0) $his_highest_group = $his_highest_group[0]['group_id']; diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 8f128d9e..677b057b 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -32,6 +32,7 @@ function guest_register() { $tshirt_size = ''; $password_hash = ""; $selected_angel_types = array(); + $planned_arrival_date = null; $angel_types_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); $angel_types = array(); @@ -96,6 +97,13 @@ 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(); + } else { + $ok = false; + $msg .= error(_("Please enter your planned date of arrival."), true); + } + $selected_angel_types = array(); foreach ($angel_types as $angel_type_id => $angel_type_name) if (isset($_REQUEST['angel_types_' . $angel_type_id])) @@ -131,14 +139,16 @@ function guest_register() { `DECT`='" . sql_escape($dect) . "', `Handy`='" . sql_escape($mobile) . "', `email`='" . sql_escape($mail) . "', - `email_shiftinfo`='" . sql_escape($email_shiftinfo ? 'TRUE' : 'FALSE') . "', + `email_shiftinfo`=" . sql_bool($email_shiftinfo) . ", `jabber`='" . sql_escape($jabber) . "', `Size`='" . sql_escape($tshirt_size) . "', `Passwort`='" . sql_escape($password_hash) . "', `kommentar`='" . sql_escape($comment) . "', `Hometown`='" . sql_escape($hometown) . "', `CreateDate`=NOW(), - `Sprache`='" . sql_escape($_SESSION["locale"]) . "'"); + `Sprache`='" . sql_escape($_SESSION["locale"]) . "', + `arrival_date`=NULL, + `planned_arrival_date`='" . sql_escape($planned_arrival_date) . "'"); // Assign user-group and set password $user_id = sql_id(); @@ -170,11 +180,18 @@ function guest_register() { form_text('nick', _("Nick") . ' ' . entry_required(), $nick) )), div('col-sm-8', array( - form_text('mail', _("E-Mail") . ' ' . entry_required(), $mail), + form_email('mail', _("E-Mail") . ' ' . entry_required(), $mail), form_checkbox('email_shiftinfo', _("Please send me an email if my shifts change"), $email_shiftinfo) )) )), - $enable_tshirt_size ? form_select('tshirt_size', _("Shirt size") . ' ' . entry_required(), $tshirt_sizes, $tshirt_size) : '', + div('row', array( + div('col-sm-6', array( + form_date('planned_arrival_date', _("Planned date of arrival") . ' ' . entry_required(), $planned_arrival_date, time()) + )), + div('col-sm-6', array( + $enable_tshirt_size ? form_select('tshirt_size', _("Shirt size") . ' ' . entry_required(), $tshirt_sizes, $tshirt_size) : '' + )) + )), div('row', array( div('col-sm-6', array( form_password('password', _("Password") . ' ' . entry_required()) @@ -269,6 +286,7 @@ function guest_login() { if ($ok) { $_SESSION['uid'] = $login_user['UID']; $_SESSION['locale'] = $login_user['Sprache']; + redirect(page_link_to('news')); } } diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 4a6a1838..ee3cf1be 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -79,7 +79,7 @@ function user_myshifts() { } elseif (isset($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) { $id = $_REQUEST['cancel']; $shift = sql_select(" - SELECT `Shifts`.`start` + SELECT * FROM `Shifts` INNER JOIN `ShiftEntry` USING (`SID`) WHERE `ShiftEntry`.`id`='" . sql_escape($id) . "' AND `UID`='" . sql_escape($shifts_user['UID']) . "'"); @@ -89,6 +89,11 @@ function user_myshifts() { $result = ShiftEntry_delete($id); if ($result === false) engelsystem_error('Unable to delete shift entry.'); + $room = Room($shift['RID']); + $angeltype = AngelType($shift['TID']); + $shifttype = ShiftType($shift['shifttype_id']); + + engelsystem_log("Deleted own shift: " . $shifttype['name'] . " at " . $room['Name'] . " from " . date("y-m-d H:i", $shift['start']) . " to " . date("y-m-d H:i", $shift['end']) . " as " . $angeltype['name']); success(_("You have been signed off from the shift.")); } else error(_("It's too late to sign yourself off the shift. If neccessary, ask the dispatcher to do so.")); diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php index 20ed3468..466d3c3e 100644 --- a/includes/pages/user_settings.php +++ b/includes/pages/user_settings.php @@ -24,6 +24,8 @@ function user_settings() { $password_hash = ""; $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'])) { $ok = true; @@ -54,6 +56,23 @@ function user_settings() { elseif ($enable_tshirt_size) { $ok = false; } + + 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 { + $ok = false; + $msg .= error(_("Please enter your planned date of arrival."), true); + } + + 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 { + $ok = false; + $msg .= error(_("Please enter your planned date of departure."), true); + } + } else + $planned_departure_date = null; // Trivia if (isset($_REQUEST['lastname'])) @@ -82,10 +101,12 @@ function user_settings() { `DECT`='" . sql_escape($dect) . "', `Handy`='" . sql_escape($mobile) . "', `email`='" . sql_escape($mail) . "', - `email_shiftinfo`='" . sql_escape($email_shiftinfo ? 'TRUE' : 'FALSE') . "', + `email_shiftinfo`=" . sql_bool($email_shiftinfo) . ", `jabber`='" . sql_escape($jabber) . "', `Size`='" . sql_escape($tshirt_size) . "', - `Hometown`='" . sql_escape($hometown) . "' + `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.")); @@ -144,9 +165,11 @@ function user_settings() { form(array( form_info('', _("Here you can change your user details.")), form_info(entry_required() . ' = ' . _("Entry required!")), - form_text('nick', _("Nick") . ' ' . entry_required(), $nick, true), + 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), diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index c32fb220..8c01eef8 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -371,9 +371,13 @@ function view_user_shifts() { $_SESSION['user_shifts'] = array(); if (! isset($_SESSION['user_shifts']['filled'])) { - $_SESSION['user_shifts']['filled'] = array( + // User shift admins see free and occupied shifts by default + $_SESSION['user_shifts']['filled'] = in_array('user_shifts_admin', $privileges) ? [ + 0, + 1 + ] : [ 0 - ); + ]; } foreach (array( @@ -727,6 +731,7 @@ function view_user_shifts() { foreach ($angeltypes as &$angeltype) { $entries = sql_select("SELECT * FROM `ShiftEntry` JOIN `User` ON (`ShiftEntry`.`UID` = `User`.`UID`) WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `TID`='" . sql_escape($angeltype['id']) . "' ORDER BY `Nick`"); $entry_list = array(); + $entry_nicks = []; $freeloader = 0; foreach ($entries as $entry) { if (in_array('user_shifts_admin', $privileges)) @@ -740,8 +745,11 @@ function view_user_shifts() { $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); @@ -810,7 +818,7 @@ function view_user_shifts() { '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", _("Tasks") . '<sup>1</sup>'), + '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>', |