Formatting & Docstrings

This commit is contained in:
Bot 2017-12-25 23:12:52 +01:00 committed by Igor Scheller
parent 879918864a
commit 952c7892f3
60 changed files with 947 additions and 513 deletions

View File

@ -42,7 +42,7 @@ before_script:
.test_template: &test_definition .test_template: &test_definition
stage: test stage: test
artifacts: artifacts:
name: "${CI_JOB_NAME}_${CI_PROJECT_ID}_${PHP_VERSION}" name: "${CI_JOB_NAME}_${CI_PROJECT_ID}"
expire_in: 1 week expire_in: 1 week
paths: paths:
- ./coverage/ - ./coverage/

View File

@ -24,7 +24,7 @@ To report bugs use [engelsystem/issues](https://github.com/engelsystem/engelsyst
On production systems it is recommended to use On production systems it is recommended to use
```bash ```bash
composer install --no-dev composer install --no-dev
composerdump-autoload --optimize composer dump-autoload --optimize
``` ```
to install the engelsystem to install the engelsystem
* The webserver must have write access to the 'import' directory and read access for all other directories * The webserver must have write access to the 'import' directory and read access for all other directories

View File

@ -41,11 +41,11 @@ ALTER TABLE `Room` DROP `Number`;
ALTER TABLE `Room` DROP `show`; ALTER TABLE `Room` DROP `show`;
ALTER TABLE `Room` DROP `Man`; ALTER TABLE `Room` DROP `Man`;
ALTER TABLE `Room` ADD `from_frab` BOOLEAN NOT NULL AFTER `FromPentabarf`; ALTER TABLE `Room` ADD `from_frab` BOOLEAN NOT NULL AFTER `FromPentabarf`;
update Room set `from_frab`=(`FromPentabarf`='Y'); UPDATE Room SET `from_frab` = (`FromPentabarf` = 'Y');
ALTER TABLE `Room` DROP `FromPentabarf`; ALTER TABLE `Room` DROP `FromPentabarf`;
ALTER TABLE `Room` ADD `map_url` VARCHAR(300) NULL AFTER `from_frab`; ALTER TABLE `Room` ADD `map_url` VARCHAR(300) NULL AFTER `from_frab`;
ALTER TABLE `Room` ADD `description` TEXT NULL AFTER `map_url`; ALTER TABLE `Room` ADD `description` TEXT NULL AFTER `map_url`;
-- Dashboard -- Dashboard
ALTER TABLE `AngelTypes` ADD `show_on_dashboard` BOOLEAN NOT NULL AFTER `contact_email`; ALTER TABLE `AngelTypes` ADD `show_on_dashboard` BOOLEAN NOT NULL AFTER `contact_email`;
UPDATE `AngelTypes` SET `show_on_dashboard`=TRUE; UPDATE `AngelTypes` SET `show_on_dashboard` = TRUE;

View File

@ -2,6 +2,7 @@
use Engelsystem\ShiftsFilter; use Engelsystem\ShiftsFilter;
use Engelsystem\ShiftsFilterRenderer; use Engelsystem\ShiftsFilterRenderer;
/** /**
* Text for Angeltype related links. * Text for Angeltype related links.
* *
@ -39,8 +40,8 @@ function angeltypes_controller()
/** /**
* Path to angeltype view. * Path to angeltype view.
* *
* @param int $angeltype_id AngelType id * @param int $angeltype_id AngelType id
* @param array $params additional params * @param array $params additional params
* @return string * @return string
*/ */
function angeltype_link($angeltype_id, $params = []) function angeltype_link($angeltype_id, $params = [])
@ -197,7 +198,8 @@ function angeltype_controller()
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter); $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
$request = request(); $request = request();
$tab = 0; $tab = 0;
if($request->has('shifts_filter_day')) {
if ($request->has('shifts_filter_day')) {
$tab = 1; $tab = 1;
} }
@ -222,10 +224,11 @@ function angeltype_controller()
/** /**
* On which days do shifts for this angeltype occur? Needed for shiftCalendar. * On which days do shifts for this angeltype occur? Needed for shiftCalendar.
* *
* @param Angeltype $angeltype * @param array $angeltype
* @return array * @return array
*/ */
function angeltype_controller_shiftsFilterDays($angeltype) { function angeltype_controller_shiftsFilterDays($angeltype)
{
$all_shifts = Shifts_by_angeltype($angeltype); $all_shifts = Shifts_by_angeltype($angeltype);
$days = []; $days = [];
foreach ($all_shifts as $shift) { foreach ($all_shifts as $shift) {
@ -240,11 +243,12 @@ function angeltype_controller_shiftsFilterDays($angeltype) {
/** /**
* Sets up the shift filter for the angeltype. * Sets up the shift filter for the angeltype.
* *
* @param Angeltype $angeltype * @param array $angeltype
* @param array $days * @param array $days
* @return ShiftsFilter * @return ShiftsFilter
*/ */
function angeltype_controller_shiftsFilter($angeltype, $days) { function angeltype_controller_shiftsFilter($angeltype, $days)
{
global $privileges; global $privileges;
$request = request(); $request = request();
@ -252,7 +256,7 @@ function angeltype_controller_shiftsFilter($angeltype, $days) {
in_array('user_shifts_admin', $privileges), in_array('user_shifts_admin', $privileges),
Room_ids(), Room_ids(),
[$angeltype['id']] [$angeltype['id']]
); );
$selected_day = date('Y-m-d'); $selected_day = date('Y-m-d');
if (!empty($days)) { if (!empty($days)) {
$selected_day = $days[0]; $selected_day = $days[0];

View File

@ -101,7 +101,8 @@ function event_config_edit_controller()
); );
engelsystem_log( engelsystem_log(
sprintf('Changed event config: %s, %s, %s, %s, %s, %s', sprintf(
'Changed event config: %s, %s, %s, %s, %s, %s',
$event_name, $event_name,
$event_welcome_msg, $event_welcome_msg,
date('Y-m-d', $buildup_start_date), date('Y-m-d', $buildup_start_date),

View File

@ -2,21 +2,23 @@
/** /**
* Loads all data for the public dashboard * Loads all data for the public dashboard
*
* @return array
*/ */
function public_dashboard_controller() function public_dashboard_controller()
{ {
$stats = [ $stats = [
'needed-3-hours' => stats_angels_needed_three_hours(), 'needed-3-hours' => stats_angels_needed_three_hours(),
'needed-night' => stats_angels_needed_for_nightshifts(), 'needed-night' => stats_angels_needed_for_nightshifts(),
'angels-working' => stats_currently_working(), 'angels-working' => stats_currently_working(),
'hours-to-work' => stats_hours_to_work() 'hours-to-work' => stats_hours_to_work()
]; ];
$free_shifts_source = Shifts_free(time(), time() + 12 * 60 * 60); $free_shifts_source = Shifts_free(time(), time() + 12 * 60 * 60);
$free_shifts = []; $free_shifts = [];
foreach ($free_shifts_source as $shift) { foreach ($free_shifts_source as $shift) {
$free_shift = public_dashboard_controller_free_shift($shift); $free_shift = public_dashboard_controller_free_shift($shift);
if(count($free_shift['needed_angels']) > 0) { if (count($free_shift['needed_angels']) > 0) {
$free_shifts[] = $free_shift; $free_shifts[] = $free_shift;
} }
} }
@ -31,6 +33,7 @@ function public_dashboard_controller()
* Gathers information for free shifts to display. * Gathers information for free shifts to display.
* *
* @param array $shift * @param array $shift
* @return array
*/ */
function public_dashboard_controller_free_shift($shift) function public_dashboard_controller_free_shift($shift)
{ {
@ -38,15 +41,15 @@ function public_dashboard_controller_free_shift($shift)
$room = Room($shift['RID']); $room = Room($shift['RID']);
$free_shift = [ $free_shift = [
'SID' => $shift['SID'], 'SID' => $shift['SID'],
'style' => 'default', 'style' => 'default',
'start' => date('H:i', $shift['start']), 'start' => date('H:i', $shift['start']),
'end' => date('H:i', $shift['end']), 'end' => date('H:i', $shift['end']),
'duration' => round(($shift['end'] - $shift['start']) / 3600), 'duration' => round(($shift['end'] - $shift['start']) / 3600),
'shifttype_name' => $shifttype['name'], 'shifttype_name' => $shifttype['name'],
'title' => $shift['title'], 'title' => $shift['title'],
'room_name' => $room['Name'], 'room_name' => $room['Name'],
'needed_angels' => [] 'needed_angels' => []
]; ];
if (time() + 3 * 60 * 60 > $shift['start']) { if (time() + 3 * 60 * 60 > $shift['start']) {
@ -65,6 +68,7 @@ function public_dashboard_controller_free_shift($shift)
* Gathers information for needed angels on dashboard * Gathers information for needed angels on dashboard
* *
* @param array $needed_angels * @param array $needed_angels
* @return array
*/ */
function public_dashboard_needed_angels($needed_angels) function public_dashboard_needed_angels($needed_angels)
{ {
@ -75,7 +79,7 @@ function public_dashboard_needed_angels($needed_angels)
$angeltype = AngelType($needed_angel['TID']); $angeltype = AngelType($needed_angel['TID']);
if ($angeltype['show_on_dashboard']) { if ($angeltype['show_on_dashboard']) {
$result[] = [ $result[] = [
'need' => $need, 'need' => $need,
'angeltype_name' => $angeltype['name'] 'angeltype_name' => $angeltype['name']
]; ];
} }
@ -86,9 +90,10 @@ function public_dashboard_needed_angels($needed_angels)
/** /**
* Returns url to public dashboard * Returns url to public dashboard
*
* @return string
*/ */
function public_dashboard_link() function public_dashboard_link()
{ {
return page_link_to('public-dashboard'); return page_link_to('public-dashboard');
} }
?>

View File

@ -1,8 +1,11 @@
<?php <?php
use Engelsystem\ShiftSignupState; use Engelsystem\ShiftSignupState;
/** /**
* Route shift entry actions. * Route shift entry actions.
*
* @return array
*/ */
function shift_entries_controller() function shift_entries_controller()
{ {
@ -25,6 +28,8 @@ function shift_entries_controller()
/** /**
* Sign up for a shift. * Sign up for a shift.
*
* @return array
*/ */
function shift_entry_create_controller() function shift_entry_create_controller()
{ {
@ -63,6 +68,7 @@ function shift_entry_create_controller()
* *
* @param array $shift * @param array $shift
* @param array $angeltype * @param array $angeltype
* @return array
*/ */
function shift_entry_create_controller_admin($shift, $angeltype) function shift_entry_create_controller_admin($shift, $angeltype)
{ {
@ -73,16 +79,16 @@ function shift_entry_create_controller_admin($shift, $angeltype)
if ($request->has('user_id')) { if ($request->has('user_id')) {
$signup_user = User($request->input('user_id')); $signup_user = User($request->input('user_id'));
} }
if($signup_user == null) { if ($signup_user == null) {
redirect(shift_link($shift)); redirect(shift_link($shift));
} }
$angeltypes = AngelTypes(); $angeltypes = AngelTypes();
if($request->has('angeltype_id')) { if ($request->has('angeltype_id')) {
$angeltype = AngelType($request->input('angeltype_id')); $angeltype = AngelType($request->input('angeltype_id'));
} }
if($angeltype == null) { if ($angeltype == null) {
if(count($angeltypes) == 0) { if (count($angeltypes) == 0) {
redirect(shift_link($shift)); redirect(shift_link($shift));
} }
$angeltype = $angeltypes[0]; $angeltype = $angeltypes[0];
@ -90,11 +96,11 @@ function shift_entry_create_controller_admin($shift, $angeltype)
if ($request->has('submit')) { if ($request->has('submit')) {
ShiftEntry_create([ ShiftEntry_create([
'SID' => $shift['SID'], 'SID' => $shift['SID'],
'TID' => $angeltype['id'], 'TID' => $angeltype['id'],
'UID' => $signup_user['UID'], 'UID' => $signup_user['UID'],
'Comment' => '', 'Comment' => '',
'freeloaded' => false, 'freeloaded' => false,
'freeload_comment' => '' 'freeload_comment' => ''
]); ]);
@ -109,7 +115,7 @@ function shift_entry_create_controller_admin($shift, $angeltype)
} }
$angeltypes_select = []; $angeltypes_select = [];
foreach($angeltypes as $a) { foreach ($angeltypes as $a) {
$angeltypes_select[$a['id']] = $a['name']; $angeltypes_select[$a['id']] = $a['name'];
} }
@ -126,6 +132,7 @@ function shift_entry_create_controller_admin($shift, $angeltype)
* *
* @param array $shift * @param array $shift
* @param array $angeltype * @param array $angeltype
* @return array
*/ */
function shift_entry_create_controller_supporter($shift, $angeltype) function shift_entry_create_controller_supporter($shift, $angeltype)
{ {
@ -136,15 +143,23 @@ function shift_entry_create_controller_supporter($shift, $angeltype)
if ($request->has('user_id')) { if ($request->has('user_id')) {
$signup_user = User($request->input('user_id')); $signup_user = User($request->input('user_id'));
} }
if (! UserAngelType_exists($signup_user, $angeltype)) { if (!UserAngelType_exists($signup_user, $angeltype)) {
error(_('User is not in angeltype.')); error(_('User is not in angeltype.'));
redirect(shift_link($shift)); redirect(shift_link($shift));
} }
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype); $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
$shift_signup_state = Shift_signup_allowed($signup_user, $shift, $angeltype, null, null, $needed_angeltype, $shift_entries); $shift_signup_state = Shift_signup_allowed(
if (! $shift_signup_state->isSignupAllowed()) { $signup_user,
$shift,
$angeltype,
null,
null,
$needed_angeltype,
$shift_entries
);
if (!$shift_signup_state->isSignupAllowed()) {
if ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) { if ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) {
error(_('This shift is already occupied.')); error(_('This shift is already occupied.'));
} }
@ -153,11 +168,11 @@ function shift_entry_create_controller_supporter($shift, $angeltype)
if ($request->has('submit')) { if ($request->has('submit')) {
ShiftEntry_create([ ShiftEntry_create([
'SID' => $shift['SID'], 'SID' => $shift['SID'],
'TID' => $angeltype['id'], 'TID' => $angeltype['id'],
'UID' => $signup_user['UID'], 'UID' => $signup_user['UID'],
'Comment' => '', 'Comment' => '',
'freeloaded' => false, 'freeloaded' => false,
'freeload_comment' => '' 'freeload_comment' => ''
]); ]);
@ -180,9 +195,11 @@ function shift_entry_create_controller_supporter($shift, $angeltype)
/** /**
* Generates an error message for the given shift signup state. * Generates an error message for the given shift signup state.
*
* @param ShiftSignupState $shift_signup_state * @param ShiftSignupState $shift_signup_state
*/ */
function shift_entry_error_message(ShiftSignupState $shift_signup_state) { function shift_entry_error_message(ShiftSignupState $shift_signup_state)
{
if ($shift_signup_state->getState() == ShiftSignupState::ANGELTYPE) { if ($shift_signup_state->getState() == ShiftSignupState::ANGELTYPE) {
error(_('You need be accepted member of the angeltype.')); error(_('You need be accepted member of the angeltype.'));
} elseif ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) { } elseif ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) {
@ -204,6 +221,7 @@ function shift_entry_error_message(ShiftSignupState $shift_signup_state) {
* *
* @param array $shift * @param array $shift
* @param array $angeltype * @param array $angeltype
* @return array
*/ */
function shift_entry_create_controller_user($shift, $angeltype) function shift_entry_create_controller_user($shift, $angeltype)
{ {
@ -213,8 +231,16 @@ function shift_entry_create_controller_user($shift, $angeltype)
$signup_user = $user; $signup_user = $user;
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype); $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
$shift_signup_state = Shift_signup_allowed($signup_user, $shift, $angeltype, null, null, $needed_angeltype, $shift_entries); $shift_signup_state = Shift_signup_allowed(
if (! $shift_signup_state->isSignupAllowed()) { $signup_user,
$shift,
$angeltype,
null,
null,
$needed_angeltype,
$shift_entries
);
if (!$shift_signup_state->isSignupAllowed()) {
shift_entry_error_message($shift_signup_state); shift_entry_error_message($shift_signup_state);
redirect(shift_link($shift)); redirect(shift_link($shift));
} }
@ -223,15 +249,15 @@ function shift_entry_create_controller_user($shift, $angeltype)
if ($request->has('submit')) { if ($request->has('submit')) {
$comment = strip_request_item_nl('comment'); $comment = strip_request_item_nl('comment');
ShiftEntry_create([ ShiftEntry_create([
'SID' => $shift['SID'], 'SID' => $shift['SID'],
'TID' => $angeltype['id'], 'TID' => $angeltype['id'],
'UID' => $signup_user['UID'], 'UID' => $signup_user['UID'],
'Comment' => $comment, 'Comment' => $comment,
'freeloaded' => false, 'freeloaded' => false,
'freeload_comment' => '' 'freeload_comment' => ''
]); ]);
if ($angeltype['restricted'] == false && ! UserAngelType_exists($signup_user, $angeltype)) { if ($angeltype['restricted'] == false && !UserAngelType_exists($signup_user, $angeltype)) {
UserAngelType_create($signup_user, $angeltype); UserAngelType_create($signup_user, $angeltype);
} }
@ -249,13 +275,16 @@ function shift_entry_create_controller_user($shift, $angeltype)
/** /**
* Link to create a shift entry. * Link to create a shift entry.
* *
* @param array $shift
* @param array $angeltype
* @param array $params
* @return string URL * @return string URL
*/ */
function shift_entry_create_link($shift, $angeltype, $params = []) function shift_entry_create_link($shift, $angeltype, $params = [])
{ {
$params = array_merge([ $params = array_merge([
'action' => 'create', 'action' => 'create',
'shift_id' => $shift['SID'], 'shift_id' => $shift['SID'],
'angeltype_id' => $angeltype['id'] 'angeltype_id' => $angeltype['id']
], $params); ], $params);
return page_link_to('shift_entries', $params); return page_link_to('shift_entries', $params);
@ -264,12 +293,14 @@ function shift_entry_create_link($shift, $angeltype, $params = [])
/** /**
* Link to create a shift entry as admin. * Link to create a shift entry as admin.
* *
* @param array $shift
* @param array $params
* @return string URL * @return string URL
*/ */
function shift_entry_create_link_admin($shift, $params = []) function shift_entry_create_link_admin($shift, $params = [])
{ {
$params = array_merge([ $params = array_merge([
'action' => 'create', 'action' => 'create',
'shift_id' => $shift['SID'] 'shift_id' => $shift['SID']
], $params); ], $params);
return page_link_to('shift_entries', $params); return page_link_to('shift_entries', $params);
@ -277,12 +308,14 @@ function shift_entry_create_link_admin($shift, $params = [])
/** /**
* Load a shift entry from get parameter shift_entry_id. * Load a shift entry from get parameter shift_entry_id.
*
* @return array
*/ */
function shift_entry_load() function shift_entry_load()
{ {
$request = request(); $request = request();
if (! $request->has('shift_entry_id') || ! test_request_int('shift_entry_id')) { if (!$request->has('shift_entry_id') || !test_request_int('shift_entry_id')) {
redirect(page_link_to('user_shifts')); redirect(page_link_to('user_shifts'));
} }
$shiftEntry = ShiftEntry($request->input('shift_entry_id')); $shiftEntry = ShiftEntry($request->input('shift_entry_id'));
@ -296,6 +329,8 @@ function shift_entry_load()
/** /**
* Remove somebody from a shift. * Remove somebody from a shift.
*
* @return array
*/ */
function shift_entry_delete_controller() function shift_entry_delete_controller()
{ {
@ -334,13 +369,13 @@ function shift_entry_delete_controller()
* Link to delete a shift entry. * Link to delete a shift entry.
* *
* @param array $shiftEntry * @param array $shiftEntry
* * @param array $params
* @return string URL * @return string URL
*/ */
function shift_entry_delete_link($shiftEntry, $params = []) function shift_entry_delete_link($shiftEntry, $params = [])
{ {
$params = array_merge([ $params = array_merge([
'action' => 'delete', 'action' => 'delete',
'shift_entry_id' => $shiftEntry['id'] 'shift_entry_id' => $shiftEntry['id']
], $params); ], $params);
return page_link_to('shift_entries', $params); return page_link_to('shift_entries', $params);

View File

@ -45,7 +45,6 @@ function shift_edit_controller()
{ {
global $privileges; global $privileges;
// Schicht bearbeiten
$msg = ''; $msg = '';
$valid = true; $valid = true;
$request = request(); $request = request();
@ -65,7 +64,11 @@ function shift_edit_controller()
$angeltypes = select_array(AngelTypes(), 'id', 'name'); $angeltypes = select_array(AngelTypes(), 'id', 'name');
$shifttypes = select_array(ShiftTypes(), 'id', 'name'); $shifttypes = select_array(ShiftTypes(), 'id', 'name');
$needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'angel_type_id', 'count'); $needed_angel_types = select_array(
NeededAngelTypes_by_shift($shift_id),
'angel_type_id',
'count'
);
foreach (array_keys($angeltypes) as $angeltype_id) { foreach (array_keys($angeltypes) as $angeltype_id) {
if (!isset($needed_angel_types[$angeltype_id])) { if (!isset($needed_angel_types[$angeltype_id])) {
$needed_angel_types[$angeltype_id] = 0; $needed_angel_types[$angeltype_id] = 0;
@ -149,7 +152,7 @@ function shift_edit_controller()
$needed_angel_types_info = []; $needed_angel_types_info = [];
foreach ($needed_angel_types as $type_id => $count) { foreach ($needed_angel_types as $type_id => $count) {
NeededAngelType_add($shift_id, $type_id, null, $count); NeededAngelType_add($shift_id, $type_id, null, $count);
if($count > 0) { if ($count > 0) {
$needed_angel_types_info[] = $angeltypes[$type_id] . ': ' . $count; $needed_angel_types_info[] = $angeltypes[$type_id] . ': ' . $count;
} }
} }
@ -178,7 +181,9 @@ function shift_edit_controller()
shifts_title(), shifts_title(),
[ [
msg(), msg(),
'<noscript>' . info(_('This page is much more comfortable with javascript.'), true) . '</noscript>', '<noscript>'
. info(_('This page is much more comfortable with javascript.'), true)
. '</noscript>',
form([ form([
form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
form_text('title', _('Title'), $title), form_text('title', _('Title'), $title),
@ -310,8 +315,9 @@ function shifts_controller()
switch ($request->input('action')) { switch ($request->input('action')) {
case 'view': case 'view':
return shift_controller(); return shift_controller();
/** @noinspection PhpMissingBreakStatementInspection */
case 'next': case 'next':
return shift_next_controller(); shift_next_controller();
default: default:
redirect(page_link_to('/')); redirect(page_link_to('/'));
} }

View File

@ -273,7 +273,10 @@ function user_angeltype_update_controller()
UserAngelType_update($user_angeltype['id'], $supporter); UserAngelType_update($user_angeltype['id'], $supporter);
$success_message = sprintf( $success_message = sprintf(
$supporter ? _('Added supporter rights for %s to %s.') : _('Removed supporter rights for %s from %s.'), $supporter
? _('Added supporter rights for %s to %s.')
: _('Removed supporter rights for %s from %s.')
,
AngelType_name_render($angeltype), AngelType_name_render($angeltype),
User_Nick_render($user_source) User_Nick_render($user_source)
); );
@ -291,6 +294,8 @@ function user_angeltype_update_controller()
/** /**
* User joining an Angeltype (Or supporter doing this for him). * User joining an Angeltype (Or supporter doing this for him).
*
* @return array
*/ */
function user_angeltype_add_controller() function user_angeltype_add_controller()
{ {
@ -364,7 +369,11 @@ function user_angeltype_join_controller($angeltype)
$user_angeltype_id = UserAngelType_create($user, $angeltype); $user_angeltype_id = UserAngelType_create($user, $angeltype);
$success_message = sprintf(_('You joined %s.'), $angeltype['name']); $success_message = sprintf(_('You joined %s.'), $angeltype['name']);
engelsystem_log(sprintf('User %s joined %s.', User_Nick_render($user), AngelType_name_render($angeltype))); engelsystem_log(sprintf(
'User %s joined %s.',
User_Nick_render($user),
AngelType_name_render($angeltype)
));
success($success_message); success($success_message);
if (in_array('admin_user_angeltypes', $privileges)) { if (in_array('admin_user_angeltypes', $privileges)) {

View File

@ -271,7 +271,7 @@ function users_list_controller()
User_arrived_count(), User_arrived_count(),
User_active_count(), User_active_count(),
User_force_active_count(), User_force_active_count(),
ShiftEntries_freeleaded_count(), ShiftEntries_freeloaded_count(),
User_tshirts_count(), User_tshirts_count(),
User_got_voucher_count() User_got_voucher_count()
) )
@ -464,7 +464,10 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter)
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) { if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) {
$filtered_shifts[] = $shift; $filtered_shifts[] = $shift;
} }
if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) { if (
in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())
&& $taken >= $needed_angels_count
) {
$filtered_shifts[] = $shift; $filtered_shifts[] = $shift;
} }
} }

View File

@ -39,7 +39,10 @@ function engelsystem_email($address, $title, $message)
$address, $address,
$title, $title,
$message, $message,
sprintf("Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <%s>", config('no_reply_email')) sprintf(
"Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <%s>",
config('no_reply_email')
)
); );
if ($result === false) { if ($result === false) {

View File

@ -84,6 +84,7 @@ $includeFiles = [
__DIR__ . '/../includes/pages/user_settings.php', __DIR__ . '/../includes/pages/user_settings.php',
__DIR__ . '/../includes/pages/user_shifts.php', __DIR__ . '/../includes/pages/user_shifts.php',
]; ];
foreach ($includeFiles as $file) { foreach ($includeFiles as $file) {
require_once realpath($file); require_once realpath($file);
} }

View File

@ -63,7 +63,12 @@ function mail_shift_change($old_shift, $new_shift)
foreach ($users as $user) { foreach ($users as $user) {
if ($user['email_shiftinfo']) { if ($user['email_shiftinfo']) {
engelsystem_email_to_user($user, '[engelsystem] ' . _('Your Shift has changed'), $message, true); engelsystem_email_to_user(
$user,
'[engelsystem] ' . _('Your Shift has changed'),
$message,
true
);
} }
} }
} }
@ -111,6 +116,10 @@ function mail_shift_assign($user, $shift)
engelsystem_email_to_user($user, '[engelsystem] ' . _('Assigned to Shift'), $message, true); engelsystem_email_to_user($user, '[engelsystem] ' . _('Assigned to Shift'), $message, true);
} }
/**
* @param array $user
* @param array $shift
*/
function mail_shift_removed($user, $shift) function mail_shift_removed($user, $shift)
{ {
if (!$user['email_shiftinfo']) { if (!$user['email_shiftinfo']) {

View File

@ -26,10 +26,11 @@ function AngelType_new()
/** /**
* Checks if the angeltype has any contact information. * Checks if the angeltype has any contact information.
* *
* @param Angeltype $angeltype * @param array $angeltype Angeltype
* @return bool * @return bool
*/ */
function AngelType_has_contact_info($angeltype) { function AngelType_has_contact_info($angeltype)
{
return !empty($angeltype['contact_name']) return !empty($angeltype['contact_name'])
|| !empty($angeltype['contact_dect']) || !empty($angeltype['contact_dect'])
|| !empty($angeltype['contact_email']); || !empty($angeltype['contact_email']);
@ -139,6 +140,7 @@ function AngelType_create($angeltype)
. $angeltype['contact_email'] . ', ' . $angeltype['contact_email'] . ', '
. $angeltype['show_on_dashboard'] . $angeltype['show_on_dashboard']
); );
return $angeltype; return $angeltype;
} }
@ -172,6 +174,7 @@ function AngelType_validate_name($name, $angeltype)
FROM `AngelTypes` FROM `AngelTypes`
WHERE `name`=? WHERE `name`=?
LIMIT 1', [$name])) == 0); LIMIT 1', [$name])) == 0);
return new ValidationResult($valid, $name); return new ValidationResult($valid, $name);
} }

View File

@ -60,7 +60,8 @@ function NeededAngelTypes_delete_by_room($room_id)
* @param int $room_id * @param int $room_id
* @return array * @return array
*/ */
function NeededAngelTypes_by_room($room_id) { function NeededAngelTypes_by_room($room_id)
{
return DB::select( return DB::select(
'SELECT `angel_type_id`, `count` FROM `NeededAngelTypes` WHERE `room_id`=?', 'SELECT `angel_type_id`, `count` FROM `NeededAngelTypes` WHERE `room_id`=?',
[$room_id] [$room_id]
@ -76,7 +77,12 @@ function NeededAngelTypes_by_room($room_id) {
function NeededAngelTypes_by_shift($shiftId) function NeededAngelTypes_by_shift($shiftId)
{ {
$needed_angeltypes_source = DB::select(' $needed_angeltypes_source = DB::select('
SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` SELECT
`NeededAngelTypes`.*,
`AngelTypes`.`id`,
`AngelTypes`.`name`,
`AngelTypes`.`restricted`,
`AngelTypes`.`no_self_signup`
FROM `NeededAngelTypes` FROM `NeededAngelTypes`
JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id`
WHERE `shift_id` = ? WHERE `shift_id` = ?

View File

@ -1,14 +1,13 @@
<?php <?php
use Engelsystem\Database\DB; use Engelsystem\Database\DB;
use Engelsystem\ValidationResult; use Engelsystem\ValidationResult;
/** /**
* Validate a name for a room. * Validate a name for a room.
* *
* @param string $name * @param string $name The new name
* The new name * @param int $room_id The room id
* @param int $room_id
* The room id
* @return ValidationResult * @return ValidationResult
*/ */
function Room_validate_name($name, $room_id) function Room_validate_name($name, $room_id)
@ -17,10 +16,11 @@ function Room_validate_name($name, $room_id)
if (empty($name)) { if (empty($name)) {
$valid = false; $valid = false;
} }
if (count(DB::select('SELECT RID FROM `Room` WHERE `Name`=? AND NOT `RID`=?', [ if (count(DB::select('SELECT RID FROM `Room` WHERE `Name`=? AND NOT `RID`=?', [
$name, $name,
$room_id $room_id
])) > 0) { ])) > 0) {
$valid = false; $valid = false;
} }
return new ValidationResult($valid, $name); return new ValidationResult($valid, $name);
@ -77,14 +77,10 @@ function Room_delete_by_name($name)
/** /**
* Create a new room * Create a new room
* *
* @param string $name * @param string $name Name of the room
* Name of the room * @param boolean $from_frab Is this a frab imported room?
* @param boolean $from_frab * @param string $map_url URL to a map tha can be displayed in an iframe
* Is this a frab imported room? * @param string description Markdown description
* @param string $map_url
* URL to a map tha can be displayed in an iframe
* @param
* description markdown description
* @return false|int * @return false|int
*/ */
function Room_create($name, $from_frab, $map_url, $description) function Room_create($name, $from_frab, $map_url, $description)
@ -94,7 +90,7 @@ function Room_create($name, $from_frab, $map_url, $description)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)
', [ ', [
$name, $name,
(int) $from_frab, (int)$from_frab,
$map_url, $map_url,
$description $description
]); ]);
@ -113,14 +109,12 @@ function Room_create($name, $from_frab, $map_url, $description)
/** /**
* update a room * update a room
* *
* @param string $name * @param int $room_id The rooms id
* Name of the room * @param string $name Name of the room
* @param boolean $from_frab * @param boolean $from_frab Is this a frab imported room?
* Is this a frab imported room? * @param string $map_url URL to a map tha can be displayed in an iframe
* @param string $map_url * @param string $description Markdown description
* URL to a map tha can be displayed in an iframe * @return int
* @param
* description markdown description
*/ */
function Room_update($room_id, $name, $from_frab, $map_url, $description) function Room_update($room_id, $name, $from_frab, $map_url, $description)
{ {
@ -134,7 +128,7 @@ function Room_update($room_id, $name, $from_frab, $map_url, $description)
WHERE `RID`=? WHERE `RID`=?
LIMIT 1', [ LIMIT 1', [
$name, $name,
(int) $from_frab, (int)$from_frab,
$map_url, $map_url,
$description, $description,
$room_id $room_id
@ -153,9 +147,7 @@ function Room_update($room_id, $name, $from_frab, $map_url, $description)
/** /**
* Returns room by id. * Returns room by id.
* *
* @param int $room_id * @param int $room_id RID
* RID
* @param bool $onlyVisible
* @return array|false * @return array|false
*/ */
function Room($room_id) function Room($room_id)

View File

@ -26,7 +26,7 @@ function ShiftEntry_new()
* *
* @return int * @return int
*/ */
function ShiftEntries_freeleaded_count() function ShiftEntries_freeloaded_count()
{ {
$result = DB::selectOne('SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1'); $result = DB::selectOne('SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1');
@ -38,7 +38,7 @@ function ShiftEntries_freeleaded_count()
} }
/** /**
* List users subsribed to a given shift. * List users subscribed to a given shift.
* *
* @param int $shift_id * @param int $shift_id
* @return array * @return array
@ -102,7 +102,8 @@ function ShiftEntry_create($shift_entry)
. ' signed up for shift ' . $shift['name'] . ' signed up for shift ' . $shift['name']
. ' from ' . date('Y-m-d H:i', $shift['start']) . ' from ' . date('Y-m-d H:i', $shift['start'])
. ' to ' . date('Y-m-d H:i', $shift['end']) . ' to ' . date('Y-m-d H:i', $shift['end'])
); );
return $result; return $result;
} }
@ -157,12 +158,12 @@ function ShiftEntry_delete($shiftEntry)
$angeltype = AngelType($shiftEntry['TID']); $angeltype = AngelType($shiftEntry['TID']);
engelsystem_log( engelsystem_log(
'Shift signout: '. User_Nick_render($signout_user) . ' from shift ' . $shifttype['name'] 'Shift signout: ' . User_Nick_render($signout_user) . ' from shift ' . $shifttype['name']
. ' at ' . $room['Name'] . ' at ' . $room['Name']
. ' from ' . date('Y-m-d H:i', $shift['start']) . ' from ' . date('Y-m-d H:i', $shift['start'])
. ' to ' . date('Y-m-d H:i', $shift['end']) . ' to ' . date('Y-m-d H:i', $shift['end'])
. ' as ' . $angeltype['name'] . ' as ' . $angeltype['name']
); );
} }
/** /**

View File

@ -69,8 +69,7 @@ class ShiftSignupState
/** /**
* Combine this state with another state from the same shift. * Combine this state with another state from the same shift.
* *
* @param ShiftSignupState $shiftSignupState * @param ShiftSignupState $shiftSignupState The other state to combine
* The other state to combine
*/ */
public function combineWith(ShiftSignupState $shiftSignupState) public function combineWith(ShiftSignupState $shiftSignupState)
{ {
@ -122,6 +121,7 @@ class ShiftSignupState
case ShiftSignupState::ADMIN: case ShiftSignupState::ADMIN:
return true; return true;
} }
return false; return false;
} }

View File

@ -76,7 +76,7 @@ function ShiftType($shifttype_id)
/** /**
* Get all shift types. * Get all shift types.
* *
* @return array * @return array[]
*/ */
function ShiftTypes() function ShiftTypes()
{ {

View File

@ -50,7 +50,6 @@ class ShiftsFilter
*/ */
public function __construct($user_shifts_admin, $rooms, $types) public function __construct($user_shifts_admin, $rooms, $types)
{ {
$this->user_shifts_admin = $user_shifts_admin;
$this->rooms = $rooms; $this->rooms = $rooms;
$this->types = $types; $this->types = $types;

View File

@ -8,7 +8,8 @@ use Engelsystem\ShiftSignupState;
* @param array $angeltype * @param array $angeltype
* @return array * @return array
*/ */
function Shifts_by_angeltype($angeltype) { function Shifts_by_angeltype($angeltype)
{
return DB::select(' return DB::select('
SELECT DISTINCT `Shifts`.* FROM `Shifts` SELECT DISTINCT `Shifts`.* FROM `Shifts`
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id` = `Shifts`.`SID` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id` = `Shifts`.`SID`
@ -28,6 +29,10 @@ function Shifts_by_angeltype($angeltype) {
/** /**
* Returns every shift with needed angels in the given time range. * Returns every shift with needed angels in the given time range.
*
* @param int $start timestamp
* @param int $end timestamp
* @return array
*/ */
function Shifts_free($start, $end) function Shifts_free($start, $end)
{ {
@ -48,14 +53,14 @@ function Shifts_free($start, $end)
AND (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`) AND (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
> (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) > (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
AND NOT `Shifts`.`PSID` IS NULL AND NOT `Shifts`.`PSID` IS NULL
) as `tmp` ) AS `tmp`
ORDER BY `tmp`.`start` ORDER BY `tmp`.`start`
", [ ", [
$start, $start,
$end, $end,
$start, $start,
$end $end
]); ]);
$free_shifts = []; $free_shifts = [];
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
$free_shifts[] = Shift($shift['SID']); $free_shifts[] = Shift($shift['SID']);
@ -65,14 +70,17 @@ function Shifts_free($start, $end)
/** /**
* Returns all shifts with a PSID (from frab import) * Returns all shifts with a PSID (from frab import)
*
* @return array[]
*/ */
function Shifts_from_frab() { function Shifts_from_frab()
{
return DB::select('SELECT * FROM `Shifts` WHERE `PSID` IS NOT NULL ORDER BY `start`'); return DB::select('SELECT * FROM `Shifts` WHERE `PSID` IS NOT NULL ORDER BY `start`');
} }
/** /**
* @param array $room * @param array $room
* @return array * @return array[]
*/ */
function Shifts_by_room($room) function Shifts_by_room($room)
{ {
@ -220,7 +228,7 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
/** /**
* @param ShiftsFilter $shiftsFilter * @param ShiftsFilter $shiftsFilter
* @return array * @return array[]
*/ */
function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
{ {
@ -405,13 +413,13 @@ function Shift_signup_allowed_admin($needed_angeltype, $shift_entries)
/** /**
* Check if an angel can signout from a shift. * Check if an angel can signout from a shift.
* *
* @param $shift The shift * @param array $shift The shift
* @param $angeltype The angeltype * @param array $angeltype The angeltype
* @param $signout_user The user that was signed up for the shift * @param array $signout_user The user that was signed up for the shift
*
* @return bool * @return bool
*/ */
function Shift_signout_allowed($shift, $angeltype, $signout_user) { function Shift_signout_allowed($shift, $angeltype, $signout_user)
{
global $user, $privileges; global $user, $privileges;
// user shifts admin can sign out any user at any time // user shifts admin can sign out any user at any time
@ -423,11 +431,11 @@ function Shift_signout_allowed($shift, $angeltype, $signout_user) {
if ( if (
in_array('shiftentry_edit_angeltype_supporter', $privileges) in_array('shiftentry_edit_angeltype_supporter', $privileges)
&& User_is_AngelType_supporter($user, $angeltype) && User_is_AngelType_supporter($user, $angeltype)
) { ) {
return true; return true;
} }
if($signout_user['UID'] == $user['UID'] && $shift['start'] > time() + config('last_unsubscribe') * 3600) { if ($signout_user['UID'] == $user['UID'] && $shift['start'] > time() + config('last_unsubscribe') * 3600) {
return true; return true;
} }
@ -496,9 +504,8 @@ function Shift_delete_by_psid($shift_psid)
*/ */
function Shift_delete($shift_id) function Shift_delete($shift_id)
{ {
mail_shift_delete(Shift($shift_id));
DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]); DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]);
mail_shift_delete(Shift($shift_id));
} }
/** /**
@ -606,15 +613,23 @@ function Shift_create($shift)
* *
* @param array $user * @param array $user
* @param bool $include_freeload_comments * @param bool $include_freeload_comments
* @return array * @return array[]
*/ */
function Shifts_by_user($user, $include_freeload_comments = false) function Shifts_by_user($user, $include_freeload_comments = false)
{ {
return DB::select(' return DB::select('
SELECT `ShiftTypes`.`id` AS `shifttype_id`, `ShiftTypes`.`name`, SELECT
`ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`, `ShiftTypes`.`id` AS `shifttype_id`,
' . ($include_freeload_comments ? '`ShiftEntry`.`freeload_comment`, ' : '') . ' `ShiftTypes`.`name`,
`Shifts`.*, `Room`.* `ShiftEntry`.`id`,
`ShiftEntry`.`SID`,
`ShiftEntry`.`TID`,
`ShiftEntry`.`UID`,
`ShiftEntry`.`freeloaded`,
`ShiftEntry`.`Comment`,
' . ($include_freeload_comments ? '`ShiftEntry`.`freeload_comment`, ' : '') . '
`Shifts`.*,
`Room`.*
FROM `ShiftEntry` FROM `ShiftEntry`
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)

View File

@ -1,36 +1,43 @@
<?php <?php
use Engelsystem\Database\Db; use Engelsystem\Database\Db;
/** /**
* Returns the number of angels currently working. * Returns the number of angels currently working.
*
* @return int|string
*/ */
function stats_currently_working() function stats_currently_working()
{ {
$result = Db::selectOne(" $result = Db::selectOne("
SELECT SUM( SELECT SUM(
(SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
) as `count` ) AS `count`
FROM `Shifts` FROM `Shifts`
WHERE (`end` >= ? AND `start` <= ?)", [ WHERE (`end` >= ? AND `start` <= ?)", [
time(), time(),
time() time()
]); ]);
if (empty($result['count'])) { if (empty($result['count'])) {
return '-'; return '-';
} }
return $result['count']; return $result['count'];
} }
/** /**
* Return the number of hours still to work. * Return the number of hours still to work.
*
* @return int|string
*/ */
function stats_hours_to_work() function stats_hours_to_work()
{ {
$result = Db::selectOne(" $result = Db::selectOne("
SELECT ROUND(SUM(`count`)) as `count` FROM ( SELECT ROUND(SUM(`count`)) AS `count` FROM (
SELECT SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`) (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
* (`Shifts`.`end` - `Shifts`.`start`)/3600 as `count` * (`Shifts`.`end` - `Shifts`.`start`)/3600 AS `count`
FROM `Shifts` FROM `Shifts`
WHERE `end` >= ? WHERE `end` >= ?
AND `Shifts`.`PSID` IS NULL AND `Shifts`.`PSID` IS NULL
@ -39,11 +46,11 @@ function stats_hours_to_work()
SELECT SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`) (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
* (`Shifts`.`end` - `Shifts`.`start`)/3600 as `count` * (`Shifts`.`end` - `Shifts`.`start`)/3600 AS `count`
FROM `Shifts` FROM `Shifts`
WHERE `end` >= ? WHERE `end` >= ?
AND NOT `Shifts`.`PSID` IS NULL AND NOT `Shifts`.`PSID` IS NULL
) as `tmp` ) AS `tmp`
", [ ", [
time(), time(),
time() time()
@ -56,17 +63,19 @@ function stats_hours_to_work()
/** /**
* Returns the number of needed angels in the next 3 hours * Returns the number of needed angels in the next 3 hours
*
* @return int|string
*/ */
function stats_angels_needed_three_hours() function stats_angels_needed_three_hours()
{ {
$now = time(); $now = time();
$in3hours = $now + 3 * 60 * 60; $in3hours = $now + 3 * 60 * 60;
$result = Db::selectOne(" $result = Db::selectOne("
SELECT SUM(`count`) as `count` FROM ( SELECT SUM(`count`) AS `count` FROM (
SELECT SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`) (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) - (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
as `count` AS `count`
FROM `Shifts` FROM `Shifts`
WHERE `end` > ? AND `start` < ? WHERE `end` > ? AND `start` < ?
AND `Shifts`.`PSID` IS NULL AND `Shifts`.`PSID` IS NULL
@ -76,11 +85,11 @@ function stats_angels_needed_three_hours()
SELECT SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`) (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) - (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
as `count` AS `count`
FROM `Shifts` FROM `Shifts`
WHERE `end` > ? AND `start` < ? WHERE `end` > ? AND `start` < ?
AND NOT `Shifts`.`PSID` IS NULL AND NOT `Shifts`.`PSID` IS NULL
) as `tmp`", [ ) AS `tmp`", [
$now, $now,
$in3hours, $in3hours,
$now, $now,
@ -94,17 +103,22 @@ function stats_angels_needed_three_hours()
/** /**
* Returns the number of needed angels for nightshifts (between 2 and 8) * Returns the number of needed angels for nightshifts (between 2 and 8)
*
* @return int|string
*/ */
function stats_angels_needed_for_nightshifts() function stats_angels_needed_for_nightshifts()
{ {
$night_start = parse_date('Y-m-d H:i', date('Y-m-d', time() + 12 * 60 * 60) . ' 02:00'); $night_start = parse_date(
'Y-m-d H:i',
date('Y-m-d', time() + 12 * 60 * 60) . ' 02:00'
);
$night_end = $night_start + 6 * 60 * 60; $night_end = $night_start + 6 * 60 * 60;
$result = Db::selectOne(" $result = Db::selectOne("
SELECT SUM(`count`) as `count` FROM ( SELECT SUM(`count`) AS `count` FROM (
SELECT SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`) (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) - (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
as `count` AS `count`
FROM `Shifts` FROM `Shifts`
WHERE `end` > ? AND `start` < ? WHERE `end` > ? AND `start` < ?
AND `Shifts`.`PSID` IS NULL AND `Shifts`.`PSID` IS NULL
@ -114,11 +128,11 @@ function stats_angels_needed_for_nightshifts()
SELECT SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`) (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) - (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
as `count` AS `count`
FROM `Shifts` FROM `Shifts`
WHERE `end` > ? AND `start` < ? WHERE `end` > ? AND `start` < ?
AND NOT `Shifts`.`PSID` IS NULL AND NOT `Shifts`.`PSID` IS NULL
) as `tmp`", [ ) AS `tmp`", [
$night_start, $night_start,
$night_end, $night_end,
$night_start, $night_start,
@ -129,5 +143,3 @@ function stats_angels_needed_for_nightshifts()
} }
return $result['count']; return $result['count'];
} }
?>

View File

@ -27,7 +27,7 @@ function UserAngelType_exists($user, $angeltype)
* List users angeltypes. * List users angeltypes.
* *
* @param array $user * @param array $user
* @return array * @return array[]
*/ */
function User_angeltypes($user) function User_angeltypes($user)
{ {
@ -43,7 +43,7 @@ function User_angeltypes($user)
* Gets unconfirmed user angeltypes for angeltypes of which the given user is a supporter. * Gets unconfirmed user angeltypes for angeltypes of which the given user is a supporter.
* *
* @param array $user * @param array $user
* @return array * @return array[]
*/ */
function User_unconfirmed_AngelTypes($user) function User_unconfirmed_AngelTypes($user)
{ {
@ -76,6 +76,7 @@ function User_is_AngelType_supporter(&$user, $angeltype)
if (!isset($user['privileges'])) { if (!isset($user['privileges'])) {
$user['privileges'] = privileges_for_user($user['UID']); $user['privileges'] = privileges_for_user($user['UID']);
} }
return (count(DB::select(' return (count(DB::select('
SELECT `id` SELECT `id`
FROM `UserAngelTypes` FROM `UserAngelTypes`
@ -105,7 +106,7 @@ function UserAngelType_update($user_angeltype_id, $supporter)
SET `supporter`=? SET `supporter`=?
WHERE `id`=? WHERE `id`=?
LIMIT 1 LIMIT 1
', [(int) $supporter, $user_angeltype_id]); ', [(int)$supporter, $user_angeltype_id]);
} }
/** /**
@ -143,7 +144,6 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user)
* *
* @param int $user_angeltype_id * @param int $user_angeltype_id
* @param array $confirm_user * @param array $confirm_user
* @return bool
*/ */
function UserAngelType_confirm($user_angeltype_id, $confirm_user) function UserAngelType_confirm($user_angeltype_id, $confirm_user)
{ {

View File

@ -6,7 +6,7 @@ use Engelsystem\Database\DB;
* Returns users groups * Returns users groups
* *
* @param array $user * @param array $user
* @return array * @return array[]
*/ */
function User_groups($user) function User_groups($user)
{ {

View File

@ -209,7 +209,7 @@ function User_is_freeloader($user)
* Returns all users that are not member of given angeltype. * Returns all users that are not member of given angeltype.
* *
* @param array $angeltype Angeltype * @param array $angeltype Angeltype
* @return array * @return array[]
*/ */
function Users_by_angeltype_inverted($angeltype) function Users_by_angeltype_inverted($angeltype)
{ {
@ -231,7 +231,7 @@ function Users_by_angeltype_inverted($angeltype)
* Returns all members of given angeltype. * Returns all members of given angeltype.
* *
* @param array $angeltype * @param array $angeltype
* @return array * @return array[]
*/ */
function Users_by_angeltype($angeltype) function Users_by_angeltype($angeltype)
{ {
@ -258,7 +258,7 @@ function Users_by_angeltype($angeltype)
/** /**
* Returns User id array * Returns User id array
* *
* @return array * @return array[]
*/ */
function User_ids() function User_ids()
{ {
@ -268,6 +268,7 @@ function User_ids()
/** /**
* Strip unwanted characters from a users nick. Allowed are letters, numbers, connecting punctuation and simple space. * Strip unwanted characters from a users nick. Allowed are letters, numbers, connecting punctuation and simple space.
* Nick is trimmed. * Nick is trimmed.
*
* @param string $nick * @param string $nick
* @return string * @return string
*/ */
@ -279,8 +280,7 @@ function User_validate_Nick($nick)
/** /**
* Validate user email address. * Validate user email address.
* *
* @param string $mail * @param string $mail The email address to validate
* The email address to validate
* @return ValidationResult * @return ValidationResult
*/ */
function User_validate_mail($mail) function User_validate_mail($mail)
@ -292,8 +292,7 @@ function User_validate_mail($mail)
/** /**
* Validate user jabber address * Validate user jabber address
* *
* @param string $jabber * @param string $jabber Jabber-ID to validate
* Jabber-ID to validate
* @return ValidationResult * @return ValidationResult
*/ */
function User_validate_jabber($jabber) function User_validate_jabber($jabber)
@ -337,10 +336,8 @@ function User_validate_planned_arrival_date($planned_arrival_date)
/** /**
* Validate the planned departure date * Validate the planned departure date
* *
* @param int $planned_arrival_date * @param int $planned_arrival_date Unix timestamp
* Unix timestamp * @param int $planned_departure_date Unix timestamp
* @param int $planned_departure_date
* Unix timestamp
* @return ValidationResult * @return ValidationResult
*/ */
function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date) function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date)
@ -383,8 +380,7 @@ function User($user_id)
/** /**
* Returns User by api_key. * Returns User by api_key.
* *
* @param string $api_key * @param string $api_key User api key
* User api key
* @return array|null Matching user, null if not found * @return array|null Matching user, null if not found
*/ */
function User_by_api_key($api_key) function User_by_api_key($api_key)
@ -396,7 +392,7 @@ function User_by_api_key($api_key)
* Returns User by email. * Returns User by email.
* *
* @param string $email * @param string $email
* @return array|null Matching user, null or false on error * @return array|null Matching user, null on error
*/ */
function User_by_email($email) function User_by_email($email)
{ {
@ -460,7 +456,9 @@ function User_generate_password_recovery_token(&$user)
$user['UID'], $user['UID'],
] ]
); );
engelsystem_log('Password recovery for ' . User_Nick_render($user) . ' started.'); engelsystem_log('Password recovery for ' . User_Nick_render($user) . ' started.');
return $user['password_recovery_token']; return $user['password_recovery_token'];
} }
@ -474,10 +472,10 @@ function User_get_eligable_voucher_count(&$user)
$shifts_done = count(ShiftEntries_finished_by_user($user)); $shifts_done = count(ShiftEntries_finished_by_user($user));
$earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers']; $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];
$elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers; $eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
if ($elegible_vouchers < 0) { if ($eligable_vouchers < 0) {
return 0; return 0;
} }
return $elegible_vouchers; return $eligable_vouchers;
} }

View File

@ -173,7 +173,8 @@ function admin_active()
} }
$usr['nick'] = User_Nick_render($usr); $usr['nick'] = User_Nick_render($usr);
$usr['shirt_size'] = $tshirt_sizes[$usr['Size']]; $usr['shirt_size'] = $tshirt_sizes[$usr['Size']];
$usr['work_time'] = round($usr['shift_length'] / 60) . ' min (' . round($usr['shift_length'] / 3600) . ' h)'; $usr['work_time'] = round($usr['shift_length'] / 60)
. ' min (' . round($usr['shift_length'] / 3600) . ' h)';
$usr['active'] = glyph_bool($usr['Aktiv'] == 1); $usr['active'] = glyph_bool($usr['Aktiv'] == 1);
$usr['force_active'] = glyph_bool($usr['force_active'] == 1); $usr['force_active'] = glyph_bool($usr['force_active'] == 1);
$usr['tshirt'] = glyph_bool($usr['Tshirt'] == 1); $usr['tshirt'] = glyph_bool($usr['Tshirt'] == 1);

View File

@ -85,7 +85,11 @@ function admin_groups()
'privilege-' . $privilege['name'] 'privilege-' . $privilege['name']
); );
$privileges_html .= sprintf( $privileges_html .= sprintf(
'<tr><td><input type="checkbox" name="privileges[]" value="%s" %s /></td> <td>%s</td> <td>%s</td></tr>', '<tr>'
. '<td><input type="checkbox" name="privileges[]" value="%s" %s /></td>'
. '<td>%s</td>'
. '<td>%s</td>'
. '</tr>',
$privilege['id'], $privilege['id'],
($privilege['group_id'] != '' ? 'checked="checked"' : ''), ($privilege['group_id'] != '' ? 'checked="checked"' : ''),
$privilege['name'], $privilege['name'],

View File

@ -34,7 +34,7 @@ function admin_import()
$test_handle = @fopen($import_dir . '/tmp', 'w'); $test_handle = @fopen($import_dir . '/tmp', 'w');
fclose($test_handle); fclose($test_handle);
@unlink($import_dir . '/tmp'); @unlink($import_dir . '/tmp');
} catch(Exception $e) { } catch (Exception $e) {
error(_('Webserver has no write-permission on import directory.')); error(_('Webserver has no write-permission on import directory.'));
} }
@ -63,8 +63,9 @@ function admin_import()
error(_('Please select a shift type.')); error(_('Please select a shift type.'));
} }
if ($request->has('add_minutes_start') && is_numeric(trim($request->input('add_minutes_start')))) { $minutes_start = trim($request->input('add_minutes_start'));
$add_minutes_start = trim($request->input('add_minutes_start')); if ($request->has('add_minutes_start') && is_numeric($minutes_start)) {
$add_minutes_start = $minutes_start;
} else { } else {
$valid = false; $valid = false;
error(_('Please enter an amount of minutes to add to a talk\'s begin.')); error(_('Please enter an amount of minutes to add to a talk\'s begin.'));
@ -106,7 +107,11 @@ function admin_import()
); );
} else { } else {
$html .= div('well well-sm text-center', [ $html .= div('well well-sm text-center', [
_('File Upload') . mute(glyph('arrow-right')) . mute(_('Validation')) . mute(glyph('arrow-right')) . mute(_('Import')) _('File Upload')
. mute(glyph('arrow-right'))
. mute(_('Validation'))
. mute(glyph('arrow-right'))
. mute(_('Import'))
]) . div('row', [ ]) . div('row', [
div('col-md-offset-3 col-md-6', [ div('col-md-offset-3 col-md-6', [
form([ form([
@ -164,7 +169,10 @@ function admin_import()
'well well-sm text-center', 'well well-sm text-center',
[ [
'<span class="text-success">' . _('File Upload') . glyph('ok-circle') . '</span>' '<span class="text-success">' . _('File Upload') . glyph('ok-circle') . '</span>'
. mute(glyph('arrow-right')) . _('Validation') . mute(glyph('arrow-right')) . mute(_('Import')) . mute(glyph('arrow-right'))
. _('Validation')
. mute(glyph('arrow-right'))
. mute(_('Import'))
] ]
) )
. form( . form(
@ -315,7 +323,7 @@ function prepare_rooms($file)
// Contains all rooms from db and frab // Contains all rooms from db and frab
$rooms_import = []; $rooms_import = [];
foreach ($rooms as $room) { foreach ($rooms as $room) {
if($room['from_frab']) { if ($room['from_frab']) {
$rooms_db[] = $room['Name']; $rooms_db[] = $room['Name'];
} }
$rooms_db_all[] = $room['Name']; $rooms_db_all[] = $room['Name'];

View File

@ -24,7 +24,9 @@ function admin_new_questions()
$new_messages = count(DB::select('SELECT `QID` FROM `Questions` WHERE `AID` IS NULL')); $new_messages = count(DB::select('SELECT `QID` FROM `Questions` WHERE `AID` IS NULL'));
if ($new_messages > 0) { if ($new_messages > 0) {
return '<a href="' . page_link_to('admin_questions') . '">' . _('There are unanswered questions!') . '</a>'; return '<a href="' . page_link_to('admin_questions') . '">'
. _('There are unanswered questions!')
. '</a>';
} }
} }
} }

View File

@ -18,17 +18,25 @@ function admin_rooms()
foreach ($rooms_source as $room) { foreach ($rooms_source as $room) {
$rooms[] = [ $rooms[] = [
'name' => Room_name_render($room), 'name' => Room_name_render($room),
'from_frab' => glyph_bool($room['from_frab']), 'from_frab' => glyph_bool($room['from_frab']),
'map_url' => glyph_bool(!empty($room['map_url'])), 'map_url' => glyph_bool(!empty($room['map_url'])),
'actions' => table_buttons([ 'actions' => table_buttons([
button(page_link_to('admin_rooms', ['show' => 'edit', 'id' => $room['RID']]), _('edit'), 'btn-xs'), button(
button(page_link_to('admin_rooms', ['show' => 'delete', 'id' => $room['RID']]), _('delete'), 'btn-xs') 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'
)
]) ])
]; ];
} }
$room = null;
$room = null;
if ($request->has('show')) { if ($request->has('show')) {
$msg = ''; $msg = '';
$name = ''; $name = '';
@ -69,7 +77,7 @@ function admin_rooms()
if ($request->has('name') && strlen(strip_request_item('name')) > 0) { if ($request->has('name') && strlen(strip_request_item('name')) > 0) {
$result = Room_validate_name(strip_request_item('name'), $room_id); $result = Room_validate_name(strip_request_item('name'), $room_id);
if(!$result->isValid()) { if (!$result->isValid()) {
$valid = false; $valid = false;
$msg .= error(_('This name is already in use.'), true); $msg .= error(_('This name is already in use.'), true);
} else { } else {
@ -87,7 +95,7 @@ function admin_rooms()
} }
if ($request->has('description')) { if ($request->has('description')) {
$description= strip_request_item_nl('description'); $description = strip_request_item_nl('description');
} }
foreach ($angeltypes as $angeltype_id => $angeltype) { foreach ($angeltypes as $angeltype_id => $angeltype) {
@ -101,7 +109,10 @@ function admin_rooms()
$angeltypes_count[$angeltype_id] = $request->input($queryKey); $angeltypes_count[$angeltype_id] = $request->input($queryKey);
} else { } else {
$valid = false; $valid = false;
$msg .= error(sprintf(_('Please enter needed angels for type %s.'), $angeltype), true); $msg .= error(sprintf(
_('Please enter needed angels for type %s.'),
$angeltype
), true);
} }
} }
@ -118,7 +129,7 @@ function admin_rooms()
$angeltype = AngelType($angeltype_id); $angeltype = AngelType($angeltype_id);
if ($angeltype != null) { if ($angeltype != null) {
NeededAngelType_add(null, $angeltype_id, $room_id, $angeltype_count); NeededAngelType_add(null, $angeltype_id, $room_id, $angeltype_count);
if($angeltype_count > 0) { if ($angeltype_count > 0) {
$needed_angeltype_info[] = $angeltype['name'] . ': ' . $angeltype_count; $needed_angeltype_info[] = $angeltype['name'] . ': ' . $angeltype_count;
} }
} }
@ -197,10 +208,10 @@ function admin_rooms()
]), ]),
msg(), msg(),
table([ table([
'name' => _('Name'), 'name' => _('Name'),
'from_frab' => _('Frab import'), 'from_frab' => _('Frab import'),
'map_url' => _('Map'), 'map_url' => _('Map'),
'actions' => '' 'actions' => ''
], $rooms) ], $rooms)
]); ]);
} }

View File

@ -113,10 +113,16 @@ function admin_shifts()
} elseif ($request->input('mode') == 'variable') { } elseif ($request->input('mode') == 'variable') {
if ( if (
$request->has('change_hours') $request->has('change_hours')
&& preg_match('/^(\d{2}(,|$))/', trim(str_replace(' ', '', $request->input('change_hours')))) && preg_match(
'/^(\d{2}(,|$))/',
trim(str_replace(' ', '', $request->input('change_hours')))
)
) { ) {
$mode = 'variable'; $mode = 'variable';
$change_hours = array_map('trim', explode(',', $request->input('change_hours'))); $change_hours = array_map(
'trim',
explode(',', $request->input('change_hours'))
);
} else { } else {
$valid = false; $valid = false;
error(_('Please split the shift-change hours by colons.')); error(_('Please split the shift-change hours by colons.'));
@ -264,7 +270,8 @@ function admin_shifts()
]; ];
foreach ($types as $type) { foreach ($types as $type) {
if (isset($needed_angel_types[$type['id']]) && $needed_angel_types[$type['id']] > 0) { if (isset($needed_angel_types[$type['id']]) && $needed_angel_types[$type['id']] > 0) {
$shifts_table_entry['needed_angels'] .= '<b>' . AngelType_name_render($type) . ':</b> ' . $needed_angel_types[$type['id']] . '<br />'; $shifts_table_entry['needed_angels'] .= '<b>' . AngelType_name_render($type) . ':</b> '
. $needed_angel_types[$type['id']] . '<br />';
} }
} }
$shifts_table[] = $shifts_table_entry; $shifts_table[] = $shifts_table_entry;
@ -327,6 +334,7 @@ function admin_shifts()
FROM `AngelTypes` FROM `AngelTypes`
WHERE `id` = ? WHERE `id` = ?
LIMIT 1', [$type_id]); LIMIT 1', [$type_id]);
if (!empty($angel_type_source)) { if (!empty($angel_type_source)) {
DB::insert(' DB::insert('
INSERT INTO `NeededAngelTypes` (`shift_id`, `angel_type_id`, `count`) INSERT INTO `NeededAngelTypes` (`shift_id`, `angel_type_id`, `count`)
@ -338,7 +346,8 @@ function admin_shifts()
$count $count
] ]
); );
if($count > 0) {
if ($count > 0) {
$needed_angel_types_info[] = $angel_type_source['name'] . ': ' . $count; $needed_angel_types_info[] = $angel_type_source['name'] . ': ' . $count;
} }
} }
@ -380,7 +389,13 @@ function admin_shifts()
form_info(_('Mode'), ''), form_info(_('Mode'), ''),
form_radio('mode', _('Create one shift'), $mode == 'single', 'single'), form_radio('mode', _('Create one shift'), $mode == 'single', 'single'),
form_radio('mode', _('Create multiple shifts'), $mode == 'multi', 'multi'), form_radio('mode', _('Create multiple shifts'), $mode == 'multi', 'multi'),
form_text('length', _('Length'), $request->has('length') ? $request->input('length') : '120'), form_text(
'length',
_('Length'),
$request->has('length')
? $request->input('length')
: '120'
),
form_radio( form_radio(
'mode', 'mode',
_('Create multiple shifts with variable length'), _('Create multiple shifts with variable length'),
@ -390,7 +405,9 @@ function admin_shifts()
form_text( form_text(
'change_hours', 'change_hours',
_('Shift change hours'), _('Shift change hours'),
$request->has('change_hours') ? $request->input('input') : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22' $request->has('change_hours')
? $request->input('input')
: '00, 04, 08, 10, 12, 14, 16, 18, 20, 22'
) )
]), ]),
div('col-md-6', [ div('col-md-6', [
@ -401,7 +418,12 @@ function admin_shifts()
$angelmode == 'location', $angelmode == 'location',
'location' 'location'
), ),
form_radio('angelmode', _('The following angels are needed'), $angelmode == 'manually', 'manually'), form_radio(
'angelmode',
_('The following angels are needed'),
$angelmode == 'manually',
'manually'
),
div('row', [ div('row', [
$angel_types $angel_types
]) ])

View File

@ -235,7 +235,8 @@ function admin_user()
} }
$user_source = User($user_id); $user_source = User($user_id);
engelsystem_log( engelsystem_log(
'Set groups of ' . User_Nick_render($user_source) . ' to: ' . join(', ', $user_groups_info) 'Set groups of ' . User_Nick_render($user_source) . ' to: '
. join(', ', $user_groups_info)
); );
$html .= success('Benutzergruppen gespeichert.', true); $html .= success('Benutzergruppen gespeichert.', true);
} else { } else {
@ -261,7 +262,9 @@ function admin_user()
`Handy` = ?, `Handy` = ?,
`Alter` =?, `Alter` =?,
`DECT` = ?, `DECT` = ?,
' . ($user_source['email_by_human_allowed'] ? '`email` = ' . DB::getPdo()->quote($request->postData('eemail')) . ',' : '') . ' ' . ($user_source['email_by_human_allowed']
? '`email` = ' . DB::getPdo()->quote($request->postData('eemail')) . ','
: '') . '
`jabber` = ?, `jabber` = ?,
`Size` = ?, `Size` = ?,
`Gekommen`= ?, `Gekommen`= ?,
@ -298,13 +301,19 @@ function admin_user()
break; break;
case 'change_pw': case 'change_pw':
if ($request->postData('new_pw') != '' && $request->postData('new_pw') == $request->postData('new_pw2')) { if (
$request->postData('new_pw') != ''
&& $request->postData('new_pw') == $request->postData('new_pw2')
) {
set_password($user_id, $request->postData('new_pw')); set_password($user_id, $request->postData('new_pw'));
$user_source = User($user_id); $user_source = User($user_id);
engelsystem_log('Set new password for ' . User_Nick_render($user_source)); engelsystem_log('Set new password for ' . User_Nick_render($user_source));
$html .= success('Passwort neu gesetzt.', true); $html .= success('Passwort neu gesetzt.', true);
} else { } else {
$html .= error('Die Eingaben müssen übereinstimmen und dürfen nicht leer sein!', true); $html .= error(
'Die Eingaben müssen übereinstimmen und dürfen nicht leer sein!',
true
);
} }
break; break;
} }

View File

@ -183,7 +183,7 @@ function guest_register()
$tel = strip_request_item('tel'); $tel = strip_request_item('tel');
} }
if ($request->has('dect')) { if ($request->has('dect')) {
if(strlen(strip_request_item('dect')) <= 5) { if (strlen(strip_request_item('dect')) <= 5) {
$dect = strip_request_item('dect'); $dect = strip_request_item('dect');
} else { } else {
$valid = false; $valid = false;
@ -392,7 +392,6 @@ function guest_register()
form_info(entry_required() . ' = ' . _('Entry required!')) form_info(entry_required() . ' = ' . _('Entry required!'))
]) ])
]), ]),
// form_textarea('comment', _('Did you help at former CCC events and which tasks have you performed then?'), $comment),
form_submit('submit', _('Register')) form_submit('submit', _('Register'))
]) ])
]); ]);

View File

@ -14,7 +14,11 @@ function guest_stats()
list($user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User`'); list($user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User`');
$stats['user_count'] = $user_count['user_count']; $stats['user_count'] = $user_count['user_count'];
list($arrived_user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User` WHERE `Gekommen`=1'); list($arrived_user_count) = DB::select('
SELECT count(*) AS `user_count`
FROM `User`
WHERE `Gekommen`=1
');
$stats['arrived_user_count'] = $arrived_user_count['user_count']; $stats['arrived_user_count'] = $arrived_user_count['user_count'];
$done_shifts_seconds = DB::selectOne(' $done_shifts_seconds = DB::selectOne('

View File

@ -63,13 +63,21 @@ function make_atom_entries_from_news($news_entries)
return $html; return $html;
} }
/**
* @param array $news_entry
* @return string
*/
function make_atom_entry_from_news($news_entry) function make_atom_entry_from_news($news_entry)
{ {
return ' return '
<entry> <entry>
<title>' . htmlspecialchars($news_entry['Betreff']) . '</title> <title>' . htmlspecialchars($news_entry['Betreff']) . '</title>
<link href="' . page_link_to('news_comments', ['nid' => $news_entry['ID']]) . '"/> <link href="' . page_link_to('news_comments', ['nid' => $news_entry['ID']]) . '"/>
<id>' . preg_replace('#^https?://#', '', page_link_to('news_comments', ['nid' => $news_entry['ID']])) . '</id> <id>' . preg_replace(
'#^https?://#',
'',
page_link_to('news_comments', ['nid' => $news_entry['ID']])
) . '</id>
<updated>' . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . '</updated> <updated>' . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . '</updated>
<summary>' . htmlspecialchars($news_entry['Text']) . '</summary> <summary>' . htmlspecialchars($news_entry['Text']) . '</summary>
</entry>' . "\n"; </entry>' . "\n";

View File

@ -30,7 +30,7 @@ function user_ical()
/** /**
* Renders an ical calendar from given shifts array. * Renders an ical calendar from given shifts array.
* *
* @param array <Shift> $shifts * @param array $shifts Shift
*/ */
function send_ical_from_shifts($shifts) function send_ical_from_shifts($shifts)
{ {

View File

@ -77,7 +77,8 @@ function user_meetings()
* @param array $news * @param array $news
* @return string HTML * @return string HTML
*/ */
function news_text($news) { function news_text($news)
{
$text = ReplaceSmilies($news['Text']); $text = ReplaceSmilies($news['Text']);
$text = preg_replace("/\r\n\r\n/m", '<br><br>', $text); $text = preg_replace("/\r\n\r\n/m", '<br><br>', $text);
return $text; return $text;
@ -101,7 +102,11 @@ function display_news($news)
$html .= '<div class="panel-footer text-muted">'; $html .= '<div class="panel-footer text-muted">';
if (in_array('admin_news', $privileges)) { if (in_array('admin_news', $privileges)) {
$html .= '<div class="pull-right">' $html .= '<div class="pull-right">'
. button_glyph(page_link_to('admin_news', ['action' => 'edit', 'id' => $news['ID']]), 'edit', 'btn-xs') . button_glyph(
page_link_to('admin_news', ['action' => 'edit', 'id' => $news['ID']]),
'edit',
'btn-xs'
)
. '</div>'; . '</div>';
} }
$html .= '<span class="glyphicon glyphicon-time"></span> ' . date('Y-m-d H:i', $news['Datum']) . '&emsp;'; $html .= '<span class="glyphicon glyphicon-time"></span> ' . date('Y-m-d H:i', $news['Datum']) . '&emsp;';
@ -140,7 +145,11 @@ function user_news_comments()
$nid = $request->input('nid'); $nid = $request->input('nid');
$news = DB::selectOne('SELECT * FROM `News` WHERE `ID`=? LIMIT 1', [$nid]); $news = DB::selectOne('SELECT * FROM `News` WHERE `ID`=? LIMIT 1', [$nid]);
if ($request->has('text')) { if ($request->has('text')) {
$text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($request->input('text'))); $text = preg_replace(
"/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui",
'',
strip_tags($request->input('text'))
);
DB::insert(' DB::insert('
INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`) INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)

View File

@ -78,7 +78,7 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
$user_source['Vorname'] = strip_request_item('prename', $user_source['Vorname']); $user_source['Vorname'] = strip_request_item('prename', $user_source['Vorname']);
$user_source['Alter'] = strip_request_item('age', $user_source['Alter']); $user_source['Alter'] = strip_request_item('age', $user_source['Alter']);
$user_source['Telefon'] = strip_request_item('tel', $user_source['Telefon']); $user_source['Telefon'] = strip_request_item('tel', $user_source['Telefon']);
if(strlen(strip_request_item('dect')) <= 5) { if (strlen(strip_request_item('dect')) <= 5) {
$user_source['DECT'] = strip_request_item('dect', $user_source['DECT']); $user_source['DECT'] = strip_request_item('dect', $user_source['DECT']);
} else { } else {
$valid = false; $valid = false;
@ -126,7 +126,7 @@ function user_settings_password($user_source)
* *
* @param array $user_source The user * @param array $user_source The user
* @param array $themes List of available themes * @param array $themes List of available themes
* @return mixed * @return array
*/ */
function user_settings_theme($user_source, $themes) function user_settings_theme($user_source, $themes)
{ {

View File

@ -56,8 +56,18 @@ function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days)
$end_time = $start_time + 24 * 60 * 60; $end_time = $start_time + 24 * 60 * 60;
} }
$shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, $start_time)); $shiftsFilter->setStartTime(check_request_datetime(
$shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, $end_time)); 'start_day',
'start_time',
$days,
$start_time
));
$shiftsFilter->setEndTime(check_request_datetime(
'end_day',
'end_time',
$days,
$end_time
));
if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) { if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) {
$shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60); $shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60);
@ -115,7 +125,7 @@ function load_days()
} }
/** /**
* @return array|false * @return array[]|false
*/ */
function load_types() function load_types()
{ {
@ -210,9 +220,19 @@ function view_user_shifts()
view(__DIR__ . '/../../templates/user_shifts.html', [ view(__DIR__ . '/../../templates/user_shifts.html', [
'title' => shifts_title(), 'title' => shifts_title(),
'room_select' => make_select($rooms, $shiftsFilter->getRooms(), 'rooms', _('Rooms')), '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_select' => html_select_key(
'start_day',
'start_day',
array_combine($days, $days),
$start_day
),
'start_time' => $start_time, 'start_time' => $start_time,
'end_select' => html_select_key('end_day', 'end_day', array_combine($days, $days), $end_day), 'end_select' => html_select_key(
'end_day',
'end_day',
array_combine($days, $days),
$end_day
),
'end_time' => $end_time, 'end_time' => $end_time,
'type_select' => make_select( 'type_select' => make_select(
$types, $types,
@ -242,7 +262,10 @@ function view_user_shifts()
'set_last_4h' => _('last 4h'), 'set_last_4h' => _('last 4h'),
'set_next_4h' => _('next 4h'), 'set_next_4h' => _('next 4h'),
'set_next_8h' => _('next 8h'), 'set_next_8h' => _('next 8h'),
'buttons' => button(public_dashboard_link(), glyph('dashboard') . _('Public Dashboard')) 'buttons' => button(
public_dashboard_link(),
glyph('dashboard') . _('Public Dashboard')
)
]) ])
]) ])
]); ]);

View File

@ -87,18 +87,22 @@ function verify_password($password, $salt, $uid = null)
{ {
$crypt_alg = config('crypt_alg'); $crypt_alg = config('crypt_alg');
$correct = false; $correct = false;
if (substr($salt, 0, 1) == '$') { // new-style crypt() if (substr($salt, 0, 1) == '$') {
// new-style crypt()
$correct = crypt($password, $salt) == $salt; $correct = crypt($password, $salt) == $salt;
} elseif (substr($salt, 0, 7) == '{crypt}') { // old-style crypt() with DES and static salt - not used anymore } elseif (substr($salt, 0, 7) == '{crypt}') {
// old-style crypt() with DES and static salt - not used anymore
$correct = crypt($password, '77') == $salt; $correct = crypt($password, '77') == $salt;
} elseif (strlen($salt) == 32) { // old-style md5 without salt - not used anymore } elseif (strlen($salt) == 32) {
// old-style md5 without salt - not used anymore
$correct = md5($password) == $salt; $correct = md5($password) == $salt;
} }
if ($correct && substr($salt, 0, strlen($crypt_alg)) != $crypt_alg && intval($uid)) { if ($correct && substr($salt, 0, strlen($crypt_alg)) != $crypt_alg && intval($uid)) {
// this password is stored in another format than we want it to be. // this password is stored in another format than we want it to be.
// let's update it! // let's update it!
// we duplicate the query from the above set_password() function to have the extra safety of checking the old hash // we duplicate the query from the above set_password() function to have the extra safety of checking
// the old hash
DB::update(' DB::update('
UPDATE `User` UPDATE `User`
SET `Passwort` = ? SET `Passwort` = ?

View File

@ -23,9 +23,11 @@ function form_hidden($name, $value)
*/ */
function form_spinner($name, $label, $value) function form_spinner($name, $label, $value)
{ {
$value = htmlspecialchars($value);
return form_element($label, ' return form_element($label, '
<div class="input-group"> <div class="input-group">
<input id="spinner-' . $name . '" class="form-control" name="' . $name . '" value="' . htmlspecialchars($value) . '" /> <input id="spinner-' . $name . '" class="form-control" name="' . $name . '" value="' . $value . '" />
<div class="input-group-btn"> <div class="input-group-btn">
<button id="spinner-' . $name . '-down" class="btn btn-default" type="button"> <button id="spinner-' . $name . '-down" class="btn btn-default" type="button">
<span class="glyphicon glyphicon-minus"></span> <span class="glyphicon glyphicon-minus"></span>
@ -130,7 +132,13 @@ function form_multi_checkboxes($names, $label, $items, $selected, $disabled = []
$sel .= ' disabled="disabled"'; $sel .= ' disabled="disabled"';
} }
$html .= '<td style="text-align: center;">' $html .= '<td style="text-align: center;">'
. '<input type="checkbox" id="' . $dom_id . '" name="' . $name . '[]" value="' . $key . '" ' . $sel . ' />' . sprintf(
'<input type="checkbox" id="%s" name="%s[]" value="%s" %s />',
$dom_id,
$name,
$key,
$sel
)
. '</td>'; . '</td>';
} }
$html .= '<td><label for="' . $dom_id . '">' . $item . '</label></td></tr>'; $html .= '<td><label for="' . $dom_id . '">' . $item . '</label></td></tr>';
@ -281,7 +289,11 @@ function form_email($name, $label, $value, $disabled = false)
*/ */
function form_file($name, $label) function form_file($name, $label)
{ {
return form_element($label, '<input id="form_' . $name . '" type="file" name="' . $name . '" />', 'form_' . $name); return form_element(
$label,
sprintf('<input id="form_%1$s" type="file" name="%1$s" />', $name),
'form_' . $name
);
} }
/** /**
@ -297,7 +309,11 @@ function form_password($name, $label, $disabled = false)
$disabled = $disabled ? ' disabled="disabled"' : ''; $disabled = $disabled ? ' disabled="disabled"' : '';
return form_element( return form_element(
$label, $label,
'<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" ' . $disabled . '/>', sprintf(
'<input class="form-control" id="form_%1$s" type="password" name="%1$s" value=""%s/>',
$name,
$disabled
),
'form_' . $name 'form_' . $name
); );
} }

View File

@ -60,15 +60,29 @@ function header_toolbar()
} }
if (!isset($user) && in_array('register', $privileges) && config('registration_enabled')) { if (!isset($user) && in_array('register', $privileges) && config('registration_enabled')) {
$toolbar_items[] = toolbar_item_link(page_link_to('register'), 'plus', register_title(), $page == 'register'); $toolbar_items[] = toolbar_item_link(
page_link_to('register'),
'plus',
register_title(),
$page == 'register'
);
} }
if (in_array('login', $privileges)) { if (in_array('login', $privileges)) {
$toolbar_items[] = toolbar_item_link(page_link_to('login'), 'log-in', login_title(), $page == 'login'); $toolbar_items[] = toolbar_item_link(
page_link_to('login'),
'log-in',
login_title(),
$page == 'login'
);
} }
if (isset($user) && in_array('user_messages', $privileges)) { if (isset($user) && in_array('user_messages', $privileges)) {
$toolbar_items[] = toolbar_item_link(page_link_to('user_messages'), 'envelope', user_unread_messages()); $toolbar_items[] = toolbar_item_link(
page_link_to('user_messages'),
'envelope',
user_unread_messages()
);
} }
$toolbar_items[] = header_render_hints(); $toolbar_items[] = header_render_hints();
@ -112,7 +126,12 @@ function make_user_submenu()
} }
if (in_array('logout', $privileges)) { if (in_array('logout', $privileges)) {
$user_submenu[] = toolbar_item_link(page_link_to('logout'), 'log-out', logout_title(), $page == 'logout'); $user_submenu[] = toolbar_item_link(
page_link_to('logout'),
'log-out',
logout_title(),
$page == 'logout'
);
} }
return $user_submenu; return $user_submenu;
@ -160,7 +179,12 @@ function make_navigation()
foreach ($admin_pages as $menu_page => $title) { foreach ($admin_pages as $menu_page => $title) {
if (in_array($menu_page, $privileges)) { if (in_array($menu_page, $privileges)) {
$admin_menu[] = toolbar_item_link(page_link_to($menu_page), '', $title, $menu_page == $page); $admin_menu[] = toolbar_item_link(
page_link_to($menu_page),
'',
$title,
$menu_page == $page
);
} }
} }

View File

@ -7,11 +7,12 @@
* @param string $label * @param string $label
* @param string $number * @param string $number
* @param string $style default, warning, danger or success. Optional. * @param string $style default, warning, danger or success. Optional.
* @return string
*/ */
function stats($label, $number, $style = null) function stats($label, $number, $style = null)
{ {
if(empty($style)) { if (empty($style)) {
if($number > 0) { if ($number > 0) {
$style = 'danger'; $style = 'danger';
} else { } else {
$style = 'success'; $style = 'success';
@ -29,22 +30,24 @@ function stats($label, $number, $style = null)
* Renders tabs from the array. Array key is tab name, array value is tab content. * Renders tabs from the array. Array key is tab name, array value is tab content.
* *
* @param array $tabs * @param array $tabs
* @param int $selected The selected tab, default 0 * @param int $selected The selected tab, default 0
* @return string HTML * @return string HTML
*/ */
function tabs($tabs, $selected = 0) function tabs($tabs, $selected = 0)
{ {
$tab_header = []; $tab_header = [];
$tab_content = []; $tab_content = [];
foreach($tabs as $header => $content) { foreach ($tabs as $header => $content) {
$class = ''; $class = '';
if(count($tab_header) == $selected) { if (count($tab_header) == $selected) {
$class = 'active'; $class = 'active';
} }
$tab_header[] = '<li role="presentation" class="' . $class . '"> $tab_header[] = '<li role="presentation" class="' . $class . '">
<a href="#' . $header . '" aria-controls="' . $header . '" role="tab" data-toggle="tab">' <a href="#' . $header . '" aria-controls="' . $header . '" role="tab" data-toggle="tab">'
. $header . '</a></li>'; . $header . '</a></li>';
$tab_content[] = '<div role="tabpanel" class="tab-pane ' . $class . '" id="' . $header . '">' . $content . '</div>'; $tab_content[] = '<div role="tabpanel" class="tab-pane ' . $class . '" id="' . $header . '">'
. $content
. '</div>';
} }
return div('', [ return div('', [
'<ul class="nav nav-tabs" role="tablist">' . join($tab_header) . '</ul>', '<ul class="nav nav-tabs" role="tablist">' . join($tab_header) . '</ul>',
@ -114,7 +117,9 @@ function glyph($glyph_name)
*/ */
function glyph_bool($boolean) function glyph_bool($boolean)
{ {
return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>'; return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">'
. glyph($boolean ? 'ok' : 'remove')
. '</span>';
} }
/** /**
@ -265,12 +270,15 @@ function page_with_title($title, $elements)
/** /**
* Renders a description based on the data arrays key and values as label an description. * Renders a description based on the data arrays key and values as label an description.
*
* @param array $data * @param array $data
* @return string
*/ */
function description($data) { function description($data)
{
$elements = []; $elements = [];
foreach($data as $label => $description) { foreach ($data as $label => $description) {
if(!empty($label) && !empty($description)) { if (!empty($label) && !empty($description)) {
$elements[] = '<dt>' . $label . '</dt><dd>' . $description . '</dd>'; $elements[] = '<dt>' . $label . '</dt><dd>' . $description . '</dd>';
} }
} }

View File

@ -1,7 +1,8 @@
<?php <?php
use Engelsystem\ShiftsFilterRenderer;
use Engelsystem\ShiftCalendarRenderer; use Engelsystem\ShiftCalendarRenderer;
use Engelsystem\ShiftsFilterRenderer;
/** /**
* AngelTypes * AngelTypes
*/ */
@ -14,7 +15,9 @@ use Engelsystem\ShiftCalendarRenderer;
*/ */
function AngelType_name_render($angeltype) function AngelType_name_render($angeltype)
{ {
return '<a href="' . angeltype_link($angeltype['id']) . '">' . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . '</a>'; return '<a href="' . angeltype_link($angeltype['id']) . '">'
. ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name']
. '</a>';
} }
/** /**
@ -92,7 +95,10 @@ function AngelType_edit_view($angeltype, $supporter_mode)
? form_info(_('No Self Sign Up'), $angeltype['no_self_signup'] ? _('Yes') : _('No')) ? form_info(_('No Self Sign Up'), $angeltype['no_self_signup'] ? _('Yes') : _('No'))
: form_checkbox('no_self_signup', _('No Self Sign Up'), $angeltype['no_self_signup']), : form_checkbox('no_self_signup', _('No Self Sign Up'), $angeltype['no_self_signup']),
$supporter_mode $supporter_mode
? form_info(_('Requires driver license'), $angeltype['requires_driver_license'] ? _('Yes') : _('No')) ? form_info(_('Requires driver license'),
$angeltype['requires_driver_license']
? _('Yes')
: _('No'))
: form_checkbox( : form_checkbox(
'requires_driver_license', 'requires_driver_license',
_('Requires driver license'), _('Requires driver license'),
@ -133,7 +139,10 @@ function AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes,
]; ];
if ($angeltype['requires_driver_license']) { if ($angeltype['requires_driver_license']) {
$buttons[] = button(user_driver_license_edit_link($user), glyph('road') . _('my driving license')); $buttons[] = button(
user_driver_license_edit_link($user),
glyph('road') . _('my driving license')
);
} }
if ($user_angeltype == null) { if ($user_angeltype == null) {
@ -336,32 +345,32 @@ function AngelType_view(
AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user), AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user),
msg(), msg(),
tabs([ tabs([
_('Info') => AngelType_view_info( _('Info') => AngelType_view_info(
$angeltype, $angeltype,
$members, $members,
$admin_user_angeltypes, $admin_user_angeltypes,
$admin_angeltypes, $admin_angeltypes,
$supporter $supporter
), ),
_('Shifts') => AngelType_view_shifts( _('Shifts') => AngelType_view_shifts(
$angeltype, $angeltype,
$shiftsFilterRenderer, $shiftsFilterRenderer,
$shiftCalendarRenderer $shiftCalendarRenderer
) )
], $tab) ], $tab)
]); ]);
} }
/** /**
* @param Angeltype $angeltype * @param array $angeltype
* @param ShiftsFilterRenderer $shiftsFilterRenderer * @param ShiftsFilterRenderer $shiftsFilterRenderer
* @param ShiftCalendarRenderer $shiftCalendarRenderer * @param ShiftCalendarRenderer $shiftCalendarRenderer
* @return string HTML * @return string HTML
*/ */
function AngelType_view_shifts($angeltype, $shiftsFilterRenderer, $shiftCalendarRenderer) function AngelType_view_shifts($angeltype, $shiftsFilterRenderer, $shiftCalendarRenderer)
{ {
$shifts = $shiftsFilterRenderer->render(page_link_to('angeltypes', [ $shifts = $shiftsFilterRenderer->render(page_link_to('angeltypes', [
'action' => 'view', 'action' => 'view',
'angeltype_id' => $angeltype['id'] 'angeltype_id' => $angeltype['id']
])); ]));
$shifts .= $shiftCalendarRenderer->render(); $shifts .= $shiftCalendarRenderer->render();
@ -370,11 +379,11 @@ function AngelType_view_shifts($angeltype, $shiftsFilterRenderer, $shiftCalendar
} }
/** /**
* @param Angeltype $angeltype * @param array $angeltype
* @param array $members * @param array $members
* @param bool $admin_user_angeltypes * @param bool $admin_user_angeltypes
* @param bool $admin_angeltypes * @param bool $admin_angeltypes
* @param bool $supporter * @param bool $supporter
* @return string HTML * @return string HTML
*/ */
function AngelType_view_info( function AngelType_view_info(
@ -385,7 +394,7 @@ function AngelType_view_info(
$supporter $supporter
) { ) {
$info = []; $info = [];
if(AngelType_has_contact_info($angeltype)) { if (AngelType_has_contact_info($angeltype)) {
$info[] = AngelTypes_render_contact_info($angeltype); $info[] = AngelTypes_render_contact_info($angeltype);
} }
@ -400,7 +409,7 @@ function AngelType_view_info(
$members, $members,
$admin_user_angeltypes, $admin_user_angeltypes,
$admin_angeltypes $admin_angeltypes
); );
$table_headers = AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes); $table_headers = AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes);
if (count($supporters) > 0) { if (count($supporters) > 0) {
@ -431,10 +440,10 @@ function AngelType_view_info(
page_link_to( page_link_to(
'user_angeltypes', 'user_angeltypes',
['action' => 'add', 'angeltype_id' => $angeltype['id']] ['action' => 'add', 'angeltype_id' => $angeltype['id']]
), ),
_('Add'), _('Add'),
'add' 'add'
) )
]); ]);
} }
$info[] = table($table_headers, $members_confirmed); $info[] = table($table_headers, $members_confirmed);
@ -445,11 +454,11 @@ function AngelType_view_info(
button( button(
page_link_to('user_angeltypes', ['action' => 'confirm_all', 'angeltype_id' => $angeltype['id']]), page_link_to('user_angeltypes', ['action' => 'confirm_all', 'angeltype_id' => $angeltype['id']]),
glyph('ok') . _('confirm all') glyph('ok') . _('confirm all')
), ),
button( button(
page_link_to('user_angeltypes', ['action' => 'delete_all', 'angeltype_id' => $angeltype['id']]), page_link_to('user_angeltypes', ['action' => 'delete_all', 'angeltype_id' => $angeltype['id']]),
glyph('remove') . _('deny all') glyph('remove') . _('deny all')
) )
]); ]);
$info[] = table($table_headers, $members_unconfirmed); $info[] = table($table_headers, $members_unconfirmed);
} }
@ -460,16 +469,16 @@ function AngelType_view_info(
/** /**
* Renders the contact info * Renders the contact info
* *
* @param Anteltype $angeltype * @param array $angeltype
* @return string HTML * @return string HTML
*/ */
function AngelTypes_render_contact_info($angeltype) function AngelTypes_render_contact_info($angeltype)
{ {
return heading(_('Contact'), 3) . description([ return heading(_('Contact'), 3) . description([
_('Name') => $angeltype['contact_name'], _('Name') => $angeltype['contact_name'],
_('DECT') => $angeltype['contact_dect'], _('DECT') => $angeltype['contact_dect'],
_('E-Mail') => $angeltype['contact_email'] _('E-Mail') => $angeltype['contact_email']
]); ]);
} }
/** /**
@ -511,7 +520,7 @@ function AngelTypes_about_view_angeltype($angeltype)
$html = '<h2>' . $angeltype['name'] . '</h2>'; $html = '<h2>' . $angeltype['name'] . '</h2>';
if(AngelType_has_contact_info($angeltype)) { if (AngelType_has_contact_info($angeltype)) {
$html .= AngelTypes_render_contact_info($angeltype); $html .= AngelTypes_render_contact_info($angeltype);
} }

View File

@ -73,7 +73,11 @@ function EventConfig_info($event_config)
} }
// Event name, start+end date are set // Event name, start+end date are set
if ($event_config['event_name'] != null && $event_config['event_start_date'] != null && $event_config['event_end_date'] != null) { if (
$event_config['event_name'] != null
&& $event_config['event_start_date'] != null
&& $event_config['event_end_date'] != null
) {
return sprintf( return sprintf(
_('%s, from %s to %s'), _('%s, from %s to %s'),
$event_config['event_name'], $event_config['event_name'],
@ -134,7 +138,10 @@ function EventConfig_edit_view(
form_text('event_name', _('Event Name'), $event_name), form_text('event_name', _('Event Name'), $event_name),
form_info('', _('Event Name is shown on the start page.')), form_info('', _('Event Name is shown on the start page.')),
form_textarea('event_welcome_msg', _('Event Welcome Message'), $event_welcome_msg), form_textarea('event_welcome_msg', _('Event Welcome Message'), $event_welcome_msg),
form_info('', _('Welcome message is shown after successful registration. You can use markdown.')) form_info(
'',
_('Welcome message is shown after successful registration. You can use markdown.')
)
]), ]),
div('col-md-3 col-xs-6', [ div('col-md-3 col-xs-6', [
form_date('buildup_start_date', _('Buildup date'), $buildup_start_date), form_date('buildup_start_date', _('Buildup date'), $buildup_start_date),

View File

@ -2,6 +2,10 @@
/** /**
* Public dashboard (formerly known as angel news hub) * Public dashboard (formerly known as angel news hub)
*
* @param array $stats
* @param array[] $free_shifts
* @return string
*/ */
function public_dashboard_view($stats, $free_shifts) function public_dashboard_view($stats, $free_shifts)
{ {
@ -9,7 +13,7 @@ function public_dashboard_view($stats, $free_shifts)
if (count($free_shifts) > 0) { if (count($free_shifts) > 0) {
$shift_panels = []; $shift_panels = [];
foreach ($free_shifts as $shift) { foreach ($free_shifts as $shift) {
$shift_panels[] = public_dashborad_shift_render($shift); $shift_panels[] = public_dashboard_shift_render($shift);
} }
$needed_angels = div('first', [ $needed_angels = div('first', [
div('col-md-12', [ div('col-md-12', [
@ -18,6 +22,7 @@ function public_dashboard_view($stats, $free_shifts)
join($shift_panels) join($shift_panels)
]); ]);
} }
return page([ return page([
div('public-dashboard', [ div('public-dashboard', [
div('first', [ div('first', [
@ -48,21 +53,27 @@ function public_dashboard_view($stats, $free_shifts)
/** /**
* Renders a single shift panel for a dashboard shift with needed angels * Renders a single shift panel for a dashboard shift with needed angels
*
* @param array $shift
* @return string
*/ */
function public_dashborad_shift_render($shift) function public_dashboard_shift_render($shift)
{ {
$panel_body = glyph('time') . $shift['start'] . ' - ' . $shift['end']; $panel_body = glyph('time') . $shift['start'] . ' - ' . $shift['end'];
$panel_body .= ' (' . $shift['duration'] . ' h)'; $panel_body .= ' (' . $shift['duration'] . ' h)';
$panel_body .= '<br>' . glyph('tasks') . $shift['shifttype_name']; $panel_body .= '<br>' . glyph('tasks') . $shift['shifttype_name'];
if (! empty($shift['title'])) { if (!empty($shift['title'])) {
$panel_body .= ' (' . $shift['title'] . ')'; $panel_body .= ' (' . $shift['title'] . ')';
} }
$panel_body .= '<br>' . glyph('map-marker') . $shift['room_name']; $panel_body .= '<br>' . glyph('map-marker') . $shift['room_name'];
foreach ($shift['needed_angels'] as $needed_angels) { foreach ($shift['needed_angels'] as $needed_angels) {
$panel_body .= '<br>' . glyph('user') . '<span class="text-' . $shift['style'] . '">' . $needed_angels['need'] . ' &times; ' . $needed_angels['angeltype_name'] . '</span>'; $panel_body .= '<br>' . glyph('user')
. '<span class="text-' . $shift['style'] . '">'
. $needed_angels['need'] . ' &times; ' . $needed_angels['angeltype_name']
. '</span>';
} }
return div('col-md-3', [ return div('col-md-3', [
@ -74,4 +85,3 @@ function public_dashborad_shift_render($shift)
]) ])
]); ]);
} }
?>

View File

@ -1,11 +1,12 @@
<?php <?php
use Engelsystem\ShiftCalendarRenderer; use Engelsystem\ShiftCalendarRenderer;
use Engelsystem\ShiftsFilterRenderer; use Engelsystem\ShiftsFilterRenderer;
/** /**
* *
* @param array $room * @param array $room
* @param ShiftsFilterRenderer $shiftsFilterRenderer * @param ShiftsFilterRenderer $shiftsFilterRenderer
* @param ShiftCalendarRenderer $shiftCalendarRenderer * @param ShiftCalendarRenderer $shiftCalendarRenderer
* @return string * @return string
*/ */
@ -14,25 +15,30 @@ function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalen
global $user; global $user;
$assignNotice = ''; $assignNotice = '';
if (config('signup_requires_arrival') && ! $user['Gekommen']) { if (config('signup_requires_arrival') && !$user['Gekommen']) {
$assignNotice = info(render_user_arrived_hint(), true); $assignNotice = info(render_user_arrived_hint(), true);
} }
$description = ''; $description = '';
if (! empty($room['description'])) { if (!empty($room['description'])) {
$description = '<h3>' . _('Description') . '</h3>'; $description = '<h3>' . _('Description') . '</h3>';
$parsedown = new Parsedown(); $parsedown = new Parsedown();
$description .= '<div class="well">' . $parsedown->parse($room['description']) . '</div>'; $description .= '<div class="well">' . $parsedown->parse($room['description']) . '</div>';
} }
$tabs = []; $tabs = [];
if (! empty($room['map_url'])) { if (!empty($room['map_url'])) {
$tabs[_('Map')] = '<div class="map"><iframe style="width: 100%; min-height: 400px; border: 0px none;" src="' . $room['map_url'] . '"></iframe></div>'; $tabs[_('Map')] = sprintf(
'<div class="map">'
. '<iframe style="width: 100%; min-height: 400px; border: 0 none;" src="%s"></iframe>'
. '</div>',
$room['map_url']
);
} }
$tabs[_('Shifts')] = div('first', [ $tabs[_('Shifts')] = div('first', [
$shiftsFilterRenderer->render(page_link_to('rooms', [ $shiftsFilterRenderer->render(page_link_to('rooms', [
'action' => 'view', 'action' => 'view',
'room_id' => $room['RID'] 'room_id' => $room['RID']
])), ])),
$shiftCalendarRenderer->render() $shiftCalendarRenderer->render()
@ -59,8 +65,10 @@ function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalen
function Room_name_render($room) function Room_name_render($room)
{ {
global $privileges; global $privileges;
if (in_array('view_rooms', $privileges)) { if (in_array('view_rooms', $privileges)) {
return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>'; return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>';
} }
return glyph('map-marker') . $room['Name']; return glyph('map-marker') . $room['Name'];
} }

View File

@ -48,6 +48,7 @@ class ShiftCalendarLane
$this->shifts[] = $shift; $this->shifts[] = $shift;
return; return;
} }
throw new Exception('Unable to add shift to shift calendar lane.'); throw new Exception('Unable to add shift to shift calendar lane.');
} }
@ -65,6 +66,7 @@ class ShiftCalendarLane
return false; return false;
} }
} }
return true; return true;
} }

View File

@ -267,7 +267,10 @@ class ShiftCalendarRenderer
$start_time = $shift['start']; $start_time = $shift['start'];
} }
} }
return ShiftCalendarRenderer::SECONDS_PER_ROW * floor(($start_time - ShiftCalendarRenderer::TIME_MARGIN) / ShiftCalendarRenderer::SECONDS_PER_ROW); return ShiftCalendarRenderer::SECONDS_PER_ROW * floor(
($start_time - ShiftCalendarRenderer::TIME_MARGIN)
/ ShiftCalendarRenderer::SECONDS_PER_ROW
);
} }
/** /**
@ -282,7 +285,11 @@ class ShiftCalendarRenderer
$end_time = $shift['end']; $end_time = $shift['end'];
} }
} }
return ShiftCalendarRenderer::SECONDS_PER_ROW * ceil(($end_time + ShiftCalendarRenderer::TIME_MARGIN) / ShiftCalendarRenderer::SECONDS_PER_ROW);
return ShiftCalendarRenderer::SECONDS_PER_ROW * ceil(
($end_time + ShiftCalendarRenderer::TIME_MARGIN)
/ ShiftCalendarRenderer::SECONDS_PER_ROW
);
} }
/** /**
@ -290,7 +297,10 @@ class ShiftCalendarRenderer
*/ */
private function calcBlocksPerSlot() private function calcBlocksPerSlot()
{ {
return ceil(($this->getLastBlockEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW); return ceil(
($this->getLastBlockEndTime() - $this->getFirstBlockStartTime())
/ ShiftCalendarRenderer::SECONDS_PER_ROW
);
} }
/** /**

View File

@ -33,10 +33,14 @@ class ShiftCalendarShiftRenderer
$blocks = ceil(($shift['end'] - $shift['start']) / ShiftCalendarRenderer::SECONDS_PER_ROW); $blocks = ceil(($shift['end'] - $shift['start']) / ShiftCalendarRenderer::SECONDS_PER_ROW);
$blocks = max(1, $blocks); $blocks = max(1, $blocks);
return [ return [
$blocks, $blocks,
div( div(
'shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', 'shift panel panel-' . $class . '" '
. 'style="height: '
. ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN)
. 'px"',
[ [
$this->renderShiftHead($shift), $this->renderShiftHead($shift),
div('panel-body', [ div('panel-body', [
@ -127,9 +131,9 @@ class ShiftCalendarShiftRenderer
if (in_array('user_shifts_admin', $privileges)) { if (in_array('user_shifts_admin', $privileges)) {
$html .= '<li class="list-group-item">'; $html .= '<li class="list-group-item">';
$html .= button(shift_entry_create_link_admin($shift), $html .= button(shift_entry_create_link_admin($shift),
glyph('plus') . _('Add more angels'), glyph('plus') . _('Add more angels'),
'btn-xs' 'btn-xs'
); );
$html .= '</li>'; $html .= '</li>';
} }
if ($html != '') { if ($html != '') {
@ -138,6 +142,7 @@ class ShiftCalendarShiftRenderer
'<ul class="list-group">' . $html . '</ul>' '<ul class="list-group">' . $html . '</ul>'
]; ];
} }
return [ return [
$shift_signup_state, $shift_signup_state,
'' ''
@ -161,7 +166,15 @@ class ShiftCalendarShiftRenderer
$style = $entry['freeloaded'] ? ' text-decoration: line-through;' : ''; $style = $entry['freeloaded'] ? ' text-decoration: line-through;' : '';
$entry_list[] = '<span style="' . $style . '">' . User_Nick_render($entry) . '</span>'; $entry_list[] = '<span style="' . $style . '">' . User_Nick_render($entry) . '</span>';
} }
$shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, null, $angeltype, $shift_entries); $shift_signup_state = Shift_signup_allowed(
$user,
$shift,
$angeltype,
null,
null,
$angeltype,
$shift_entries
);
$inner_text = sprintf( $inner_text = sprintf(
ngettext('%d helper needed', '%d helpers needed', $shift_signup_state->getFreeEntries()), ngettext('%d helper needed', '%d helpers needed', $shift_signup_state->getFreeEntries()),
$shift_signup_state->getFreeEntries() $shift_signup_state->getFreeEntries()
@ -200,7 +213,10 @@ class ShiftCalendarShiftRenderer
// Add link to join the angeltype first // Add link to join the angeltype first
$entry_list[] = $inner_text . '<br />' $entry_list[] = $inner_text . '<br />'
. button( . button(
page_link_to('user_angeltypes', ['action' => 'add', 'angeltype_id' => $angeltype['id']]), page_link_to(
'user_angeltypes',
['action' => 'add', 'angeltype_id' => $angeltype['id']]
),
sprintf(_('Become %s'), $angeltype['name']), sprintf(_('Become %s'), $angeltype['name']),
'btn-xs' 'btn-xs'
); );
@ -241,8 +257,16 @@ class ShiftCalendarShiftRenderer
$header_buttons = ''; $header_buttons = '';
if (in_array('admin_shifts', $privileges)) { if (in_array('admin_shifts', $privileges)) {
$header_buttons = '<div class="pull-right">' . table_buttons([ $header_buttons = '<div class="pull-right">' . table_buttons([
button(page_link_to('user_shifts', ['edit_shift' => $shift['SID']]), glyph('edit'), 'btn-xs'), button(
button(page_link_to('user_shifts', ['delete_shift' => $shift['SID']]), glyph('trash'), 'btn-xs') 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>'; ]) . '</div>';
} }
$shift_heading = date('H:i', $shift['start']) . ' &dash; ' $shift_heading = date('H:i', $shift['start']) . ' &dash; '

View File

@ -13,7 +13,14 @@
function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_user) function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_user)
{ {
return page_with_title(ShiftEntry_delete_title(), [ return page_with_title(ShiftEntry_delete_title(), [
info(sprintf(_('Do you want to sign off %s from shift %s from %s to %s as %s?'), User_Nick_render($signoff_user), $shift['name'], date('Y-m-d H:i', $shift['start']), date('Y-m-d H:i', $shift['end']), $angeltype['name']), true), info(sprintf(
_('Do you want to sign off %s from shift %s from %s to %s as %s?'),
User_Nick_render($signoff_user),
$shift['name'],
date('Y-m-d H:i', $shift['start']),
date('Y-m-d H:i', $shift['end']),
$angeltype['name']
), true),
buttons([ buttons([
button(user_link($signoff_user), glyph('remove') . _('cancel')), button(user_link($signoff_user), glyph('remove') . _('cancel')),
button(shift_entry_delete_link($shiftEntry, [ button(shift_entry_delete_link($shiftEntry, [
@ -36,7 +43,13 @@ function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_
function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user) function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user)
{ {
return page_with_title(ShiftEntry_delete_title(), [ return page_with_title(ShiftEntry_delete_title(), [
info(sprintf(_('Do you want to sign off from your shift %s from %s to %s as %s?'), $shift['name'], date('Y-m-d H:i', $shift['start']), date('Y-m-d H:i', $shift['end']), $angeltype['name']), true), info(sprintf(
_('Do you want to sign off from your shift %s from %s to %s as %s?'),
$shift['name'],
date('Y-m-d H:i', $shift['start']),
date('Y-m-d H:i', $shift['end']),
$angeltype['name']
), true),
buttons([ buttons([
button(user_link($signoff_user), glyph('remove') . _('cancel')), button(user_link($signoff_user), glyph('remove') . _('cancel')),
button(shift_entry_delete_link($shiftEntry, [ button(shift_entry_delete_link($shiftEntry, [
@ -63,18 +76,22 @@ function ShiftEntry_delete_title()
* @param array $angeltypes_select * @param array $angeltypes_select
* @param array $signup_user * @param array $signup_user
* @param array $users_select * @param array $users_select
* @return string
*/ */
function ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_select, $signup_user, $users_select) function ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_select, $signup_user, $users_select)
{ {
return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [ return page_with_title(
Shift_view_header($shift, $room), ShiftEntry_create_title() . ': ' . $shift['name']
info(_('Do you want to sign up the following user for this shift?'), true), . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
form([ [
form_select('angeltype_id', _('Angeltype'), $angeltypes_select, $angeltype['id']), Shift_view_header($shift, $room),
form_select('user_id', _('User'), $users_select, $signup_user['UID']), info(_('Do you want to sign up the following user for this shift?'), true),
form_submit('submit', glyph('ok') . _('Save')) form([
]) form_select('angeltype_id', _('Angeltype'), $angeltypes_select, $angeltype['id']),
]); form_select('user_id', _('User'), $users_select, $signup_user['UID']),
form_submit('submit', glyph('ok') . _('Save'))
])
]);
} }
/** /**
@ -85,37 +102,44 @@ function ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_sel
* @param array $angeltype * @param array $angeltype
* @param array $signup_user * @param array $signup_user
* @param array $users_select * @param array $users_select
* @return string
*/ */
function ShiftEntry_create_view_supporter($shift, $room, $angeltype, $signup_user, $users_select) function ShiftEntry_create_view_supporter($shift, $room, $angeltype, $signup_user, $users_select)
{ {
return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [ return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name']
Shift_view_header($shift, $room), . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
info(sprintf(_('Do you want to sign up the following user for this shift as %s?'), AngelType_name_render($angeltype)), true), [
form([ Shift_view_header($shift, $room),
form_select('user_id', _('User'), $users_select, $signup_user['UID']), info(sprintf(_('Do you want to sign up the following user for this shift as %s?'),
form_submit('submit', glyph('ok') . _('Save')) AngelType_name_render($angeltype)), true),
]) form([
]); form_select('user_id', _('User'), $users_select, $signup_user['UID']),
form_submit('submit', glyph('ok') . _('Save'))
])
]);
} }
/** /**
* User joining a shift. * User joining a shift.
* *
* @param array $shift * @param array $shift
* @param array $room * @param array $room
* @param array $angeltype * @param array $angeltype
* @param string $comment * @param string $comment
* @return string
*/ */
function ShiftEntry_create_view_user($shift, $room, $angeltype, $comment) function ShiftEntry_create_view_user($shift, $room, $angeltype, $comment)
{ {
return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [ return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name']
Shift_view_header($shift, $room), . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
info(sprintf(_('Do you want to sign up for this shift as %s?'), AngelType_name_render($angeltype)), true), [
form([ Shift_view_header($shift, $room),
form_textarea('comment', _('Comment (for your eyes only):'), $comment), info(sprintf(_('Do you want to sign up for this shift as %s?'), AngelType_name_render($angeltype)), true),
form_submit('submit', glyph('ok') . _('Save')) form([
]) form_textarea('comment', _('Comment (for your eyes only):'), $comment),
]); form_submit('submit', glyph('ok') . _('Save'))
])
]);
} }
/** /**
@ -135,18 +159,31 @@ function ShiftEntry_create_title()
* @param string $title * @param string $title
* @param string $type * @param string $type
* @param string $comment * @param string $comment
* @param bool $freeloaded * @param bool $freeloaded
* @param string $freeload_comment * @param string $freeload_comment
* @param bool $user_admin_shifts * @param bool $user_admin_shifts
* @return string * @return string
*/ */
function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment, $freeloaded, $freeload_comment, $user_admin_shifts = false) function ShiftEntry_edit_view(
{ $angel,
$date,
$location,
$title,
$type,
$comment,
$freeloaded,
$freeload_comment,
$user_admin_shifts = false
) {
$freeload_form = []; $freeload_form = [];
if ($user_admin_shifts) { if ($user_admin_shifts) {
$freeload_form = [ $freeload_form = [
form_checkbox('freeloaded', _('Freeloaded'), $freeloaded), form_checkbox('freeloaded', _('Freeloaded'), $freeloaded),
form_textarea('freeload_comment', _('Freeload comment (Only for shift coordination):'), $freeload_comment) form_textarea(
'freeload_comment',
_('Freeload comment (Only for shift coordination):'),
$freeload_comment
)
]; ];
} }
return page_with_title(_('Edit shift entry'), [ return page_with_title(_('Edit shift entry'), [

View File

@ -7,14 +7,18 @@ use Engelsystem\ShiftSignupState;
* *
* @param array $shift * @param array $shift
* @param array $room * @param array $room
*
* @return string HTML * @return string HTML
*/ */
function Shift_view_header($shift, $room) { function Shift_view_header($shift, $room)
{
return div('row', [ return div('row', [
div('col-sm-3 col-xs-6', [ div('col-sm-3 col-xs-6', [
'<h4>' . _('Title') . '</h4>', '<h4>' . _('Title') . '</h4>',
'<p class="lead">' . ($shift['URL'] != '' ? '<a href="' . $shift['URL'] . '">' . $shift['title'] . '</a>' : $shift['title']) . '</p>' '<p class="lead">'
. ($shift['URL'] != ''
? '<a href="' . $shift['URL'] . '">' . $shift['title'] . '</a>'
: $shift['title'])
. '</p>'
]), ]),
div('col-sm-3 col-xs-6', [ div('col-sm-3 col-xs-6', [
'<h4>' . _('Start') . '</h4>', '<h4>' . _('Start') . '</h4>',
@ -237,6 +241,11 @@ function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angelty
function shift_length($shift) function shift_length($shift)
{ {
$length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ':'; $length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ':';
$length .= str_pad((($shift['end'] - $shift['start']) % (60 * 60)) / 60, 2, '0', STR_PAD_LEFT) . 'h'; $length .= str_pad(
(($shift['end'] - $shift['start']) % (60 * 60)) / 60,
2,
'0',
STR_PAD_LEFT
) . 'h';
return $length; return $length;
} }

View File

@ -97,7 +97,11 @@ function UserAngelType_confirm_view($user_angeltype, $user, $angeltype)
{ {
return page_with_title(_('Confirm angeltype for user'), [ return page_with_title(_('Confirm angeltype for user'), [
msg(), msg(),
info(sprintf(_('Do you really want to confirm %s for %s?'), User_Nick_render($user), $angeltype['name']), true), info(sprintf(
_('Do you really want to confirm %s for %s?'),
User_Nick_render($user),
$angeltype['name']
), true),
buttons([ buttons([
button(angeltype_link($angeltype['id']), glyph('remove') . _('cancel')), button(angeltype_link($angeltype['id']), glyph('remove') . _('cancel')),
button( button(
@ -122,7 +126,11 @@ function UserAngelType_delete_view($user_angeltype, $user, $angeltype)
{ {
return page_with_title(_('Remove angeltype'), [ return page_with_title(_('Remove angeltype'), [
msg(), msg(),
info(sprintf(_('Do you really want to delete %s from %s?'), User_Nick_render($user), $angeltype['name']), true), info(sprintf(
_('Do you really want to delete %s from %s?'),
User_Nick_render($user),
$angeltype['name']
), true),
buttons([ buttons([
button(angeltype_link($angeltype['id']), glyph('remove') . _('cancel')), button(angeltype_link($angeltype['id']), glyph('remove') . _('cancel')),
button( button(
@ -174,7 +182,11 @@ function UserAngelType_join_view($user, $angeltype)
{ {
return page_with_title(sprintf(_('Become a %s'), $angeltype['name']), [ return page_with_title(sprintf(_('Become a %s'), $angeltype['name']), [
msg(), msg(),
info(sprintf(_('Do you really want to add %s to %s?'), User_Nick_render($user), $angeltype['name']), true), info(sprintf(
_('Do you really want to add %s to %s?'),
User_Nick_render($user),
$angeltype['name']
), true),
buttons([ buttons([
button(angeltype_link($angeltype['id']), glyph('remove') . _('cancel')), button(angeltype_link($angeltype['id']), glyph('remove') . _('cancel')),
button( button(

View File

@ -42,7 +42,11 @@ function UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver
_('Truck 12,5t'), _('Truck 12,5t'),
$user_driver_license['has_license_12_5t_truck'] $user_driver_license['has_license_12_5t_truck']
), ),
form_checkbox('has_license_forklift', _('Forklift'), $user_driver_license['has_license_forklift']) form_checkbox(
'has_license_forklift',
_('Forklift'),
$user_driver_license['has_license_forklift']
)
]) ])
], 'driving_license'), ], 'driving_license'),
form_submit('submit', _('Save')) form_submit('submit', _('Save'))

View File

@ -20,7 +20,9 @@ class UserHintsRenderer
$hint_class = $this->important ? 'danger' : 'info'; $hint_class = $this->important ? 'danger' : 'info';
$glyphicon = $this->important ? 'warning-sign' : 'info-sign'; $glyphicon = $this->important ? 'warning-sign' : 'info-sign';
return toolbar_popover($glyphicon . ' text-' . $hint_class, '', $this->hints, 'bg-' . $hint_class); return toolbar_popover(
$glyphicon . ' text-' . $hint_class, '', $this->hints, 'bg-' . $hint_class
);
} }
return ''; return '';

View File

@ -105,6 +105,7 @@ function User_registration_success_view($event_welcome_message)
{ {
$parsedown = new Parsedown(); $parsedown = new Parsedown();
$event_welcome_message = $parsedown->text($event_welcome_message); $event_welcome_message = $parsedown->text($event_welcome_message);
return page_with_title(_('Registration successful'), [ return page_with_title(_('Registration successful'), [
msg(), msg(),
div('row', [ div('row', [
@ -171,7 +172,10 @@ function User_edit_vouchers_view($user)
buttons([ buttons([
button(user_link($user), glyph('chevron-left') . _('back')) button(user_link($user), glyph('chevron-left') . _('back'))
]), ]),
info(sprintf(_('Angel should receive at least %d vouchers.'), User_get_eligable_voucher_count($user)), true), info(sprintf(
_('Angel should receive at least %d vouchers.'),
User_get_eligable_voucher_count($user)
), true),
form( form(
[ [
form_spinner('vouchers', _('Number of vouchers given out'), $user['got_voucher']), form_spinner('vouchers', _('Number of vouchers given out'), $user['got_voucher']),
@ -269,7 +273,7 @@ function Users_table_header_link($column, $label, $order_by)
*/ */
function User_shift_state_render($user) function User_shift_state_render($user)
{ {
if(!$user['Gekommen']) { if (!$user['Gekommen']) {
return ''; return '';
} }
@ -283,16 +287,25 @@ function User_shift_state_render($user)
if ($nextShift['start'] > time()) { if ($nextShift['start'] > time()) {
if ($nextShift['start'] - time() > 3600) { if ($nextShift['start'] - time() > 3600) {
return '<span class="text-success moment-countdown" data-timestamp="' . $nextShift['start'] . '">' . _('Next shift %c') . '</span>'; return '<span class="text-success moment-countdown" data-timestamp="' . $nextShift['start'] . '">'
. _('Next shift %c')
. '</span>';
} }
return '<span class="text-warning moment-countdown" data-timestamp="' . $nextShift['start'] . '">' . _('Next shift %c') . '</span>'; return '<span class="text-warning moment-countdown" data-timestamp="' . $nextShift['start'] . '">'
. _('Next shift %c')
. '</span>';
} }
$halfway = ($nextShift['start'] + $nextShift['end']) / 2; $halfway = ($nextShift['start'] + $nextShift['end']) / 2;
if (time() < $halfway) { if (time() < $halfway) {
return '<span class="text-danger moment-countdown" data-timestamp="' . $nextShift['start'] . '">' . _('Shift starts %c') . '</span>'; return '<span class="text-danger moment-countdown" data-timestamp="' . $nextShift['start'] . '">'
. _('Shift starts %c')
. '</span>';
} }
return '<span class="text-danger moment-countdown" data-timestamp="' . $nextShift['end'] . '">' . _('Shift ends %c') . '</span>';
return '<span class="text-danger moment-countdown" data-timestamp="' . $nextShift['end'] . '">'
. _('Shift ends %c')
. '</span>';
} }
/** /**
@ -345,13 +358,14 @@ function User_view_myshift($shift, $user_source, $its_me)
'comment' => '' 'comment' => ''
]; ];
if($its_me) { if ($its_me) {
$myshift['comment'] = $shift['Comment']; $myshift['comment'] = $shift['Comment'];
} }
if ($shift['freeloaded']) { if ($shift['freeloaded']) {
if (in_array('user_shifts_admin', $privileges)) { if (in_array('user_shifts_admin', $privileges)) {
$myshift['comment'] .= '<br /><p class="error">' . _('Freeloaded') . ': ' . $shift['freeload_comment'] . '</p>'; $myshift['comment'] .= '<br />'
. '<p class="error">' . _('Freeloaded') . ': ' . $shift['freeload_comment'] . '</p>';
} else { } else {
$myshift['comment'] .= '<br /><p class="error">' . _('Freeloaded') . '</p>'; $myshift['comment'] .= '<br /><p class="error">' . _('Freeloaded') . '</p>';
} }
@ -432,7 +446,9 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
$myshifts_table = User_view_myshifts($shifts, $user_source, $its_me); $myshifts_table = User_view_myshifts($shifts, $user_source, $its_me);
return page_with_title( return page_with_title(
'<span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . ' <small>' . $user_name . '</small>', '<span class="icon-icon_angel"></span> '
. htmlspecialchars($user_source['Nick'])
. ' <small>' . $user_name . '</small>',
[ [
msg(), msg(),
div('row space-top', [ div('row space-top', [
@ -451,10 +467,16 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
_('arrived') _('arrived')
) : '', ) : '',
$admin_user_privilege ? button( $admin_user_privilege ? button(
page_link_to('users', ['action' => 'edit_vouchers', 'user_id' => $user_source['UID']]), page_link_to(
'users',
['action' => 'edit_vouchers', 'user_id' => $user_source['UID']]
),
glyph('cutlery') . _('Edit vouchers') glyph('cutlery') . _('Edit vouchers')
) : '', ) : '',
$its_me ? button(page_link_to('user_settings'), glyph('list-alt') . _('Settings')) : '', $its_me ? button(
page_link_to('user_settings'),
glyph('list-alt') . _('Settings')
) : '',
$its_me ? button( $its_me ? button(
page_link_to('ical', ['key' => $user_source['api_key']]), page_link_to('ical', ['key' => $user_source['api_key']]),
glyph('calendar') . _('iCal Export') glyph('calendar') . _('iCal Export')
@ -487,7 +509,10 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
'comment' => _('Comment'), 'comment' => _('Comment'),
'actions' => _('Action') 'actions' => _('Action')
], $myshifts_table) : '', ], $myshifts_table) : '',
$its_me ? info(glyph('info-sign') . _('Your night shifts between 2 and 8 am count twice.'), true) : '', $its_me ? info(
glyph('info-sign') . _('Your night shifts between 2 and 8 am count twice.'),
true
) : '',
$its_me && count($shifts) == 0 $its_me && count($shifts) == 0
? error(sprintf( ? error(sprintf(
_('Go to the <a href="%s">shifts table</a> to sign yourself up for some shifts.'), _('Go to the <a href="%s">shifts table</a> to sign yourself up for some shifts.'),
@ -499,10 +524,16 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
} }
/** /**
* Render the state section of user view. * Render the state section of user view
*
* @param bool $admin_user_privilege
* @param bool $freeloader
* @param array $user_source
* @return string
*/ */
function User_view_state($admin_user_privilege, $freeloader, $user_source) { function User_view_state($admin_user_privilege, $freeloader, $user_source)
if($admin_user_privilege) { {
if ($admin_user_privilege) {
$state = User_view_state_admin($freeloader, $user_source); $state = User_view_state_admin($freeloader, $user_source);
} else { } else {
$state = User_view_state_user($user_source); $state = User_view_state_user($user_source);
@ -516,13 +547,17 @@ function User_view_state($admin_user_privilege, $freeloader, $user_source) {
/** /**
* Render the state section of user view for users. * Render the state section of user view for users.
*
* @param array $user_source
* @return array
*/ */
function User_view_state_user($user_source) { function User_view_state_user($user_source)
{
$state = [ $state = [
User_shift_state_render($user_source) User_shift_state_render($user_source)
]; ];
if($user_source['Gekommen']) { if ($user_source['Gekommen']) {
$state[] = '<span class="text-success">' . glyph('home') . _('Arrived') . '</span>'; $state[] = '<span class="text-success">' . glyph('home') . _('Arrived') . '</span>';
} else { } else {
$state[] = '<span class="text-danger">' . _('Not arrived') . '</span>'; $state[] = '<span class="text-danger">' . _('Not arrived') . '</span>';
@ -534,27 +569,32 @@ function User_view_state_user($user_source) {
/** /**
* Render the state section of user view for admins. * Render the state section of user view for admins.
*
* @param bool $freeloader
* @param array $user_source
* @return array
*/ */
function User_view_state_admin($freeloader, $user_source) { function User_view_state_admin($freeloader, $user_source)
{
$state = []; $state = [];
if($freeloader) { if ($freeloader) {
$state[] = '<span class="text-danger">' . glyph('exclamation-sign') . _('Freeloader') . '</span>'; $state[] = '<span class="text-danger">' . glyph('exclamation-sign') . _('Freeloader') . '</span>';
} }
$state[] = User_shift_state_render($user_source); $state[] = User_shift_state_render($user_source);
if($user_source['Gekommen']) { if ($user_source['Gekommen']) {
$state[] = '<span class="text-success">' . glyph('home') $state[] = '<span class="text-success">' . glyph('home')
. sprintf(_('Arrived at %s'), date('Y-m-d', $user_source['arrival_date'])) . sprintf(_('Arrived at %s'), date('Y-m-d', $user_source['arrival_date']))
. '</span>'; . '</span>';
if($user_source['force_active']) { if ($user_source['force_active']) {
$state[] = '<span class="text-success">' . _('Active (forced)') . '</span>'; $state[] = '<span class="text-success">' . _('Active (forced)') . '</span>';
} elseif($user_source['Aktiv']) { } elseif ($user_source['Aktiv']) {
$state[] = '<span class="text-success">' . _('Active') . '</span>'; $state[] = '<span class="text-success">' . _('Active') . '</span>';
} }
if($user_source['Tshirt']) { if ($user_source['Tshirt']) {
$state[] = '<span class="text-success">' . _('T-Shirt') . '</span>'; $state[] = '<span class="text-success">' . _('T-Shirt') . '</span>';
} }
} else { } else {
@ -563,14 +603,14 @@ function User_view_state_admin($freeloader, $user_source) {
. '</span>'; . '</span>';
} }
if($user_source['got_voucher'] > 0) { if ($user_source['got_voucher'] > 0) {
$state[] = '<span class="text-success">' $state[] = '<span class="text-success">'
. glyph('cutlery') . glyph('cutlery')
. sprintf( . sprintf(
ngettext('Got %s voucher', 'Got %s vouchers', $user_source['got_voucher']), ngettext('Got %s voucher', 'Got %s vouchers', $user_source['got_voucher']),
$user_source['got_voucher'] $user_source['got_voucher']
) )
. '</span>'; . '</span>';
} else { } else {
$state[] = '<span class="text-danger">' . _('Got no vouchers') . '</span>'; $state[] = '<span class="text-danger">' . _('Got no vouchers') . '</span>';
} }
@ -731,7 +771,7 @@ function render_user_arrived_hint()
if ($user['Gekommen'] == 0) { if ($user['Gekommen'] == 0) {
$event_config = EventConfig(); $event_config = EventConfig();
if(!is_null($event_config) if (!is_null($event_config)
&& !is_null($event_config['buildup_start_date']) && !is_null($event_config['buildup_start_date'])
&& time() > $event_config['buildup_start_date']) { && time() > $event_config['buildup_start_date']) {
return _('You are not marked as arrived. Please go to heaven\'s desk, get your angel badge and/or tell them that you arrived already.'); return _('You are not marked as arrived. Please go to heaven\'s desk, get your angel badge and/or tell them that you arrived already.');

View File

@ -12,7 +12,9 @@ class DatabaseServiceProvider extends ServiceProvider
{ {
$config = $this->app->get('config'); $config = $this->app->get('config');
Db::connect( Db::connect(
'mysql:host=' . $config->get('database')['host'] . ';dbname=' . $config->get('database')['db'] . ';charset=utf8', 'mysql:host=' . $config->get('database')['host']
. ';dbname=' . $config->get('database')['db']
. ';charset=utf8',
$config->get('database')['user'], $config->get('database')['user'],
$config->get('database')['pw'] $config->get('database')['pw']
) || $this->exitOnError(); ) || $this->exitOnError();

View File

@ -71,7 +71,7 @@ class Db
* *
* @param string $query * @param string $query
* @param array $bindings * @param array $bindings
* @return array * @return array[]
*/ */
public static function select($query, array $bindings = []) public static function select($query, array $bindings = [])
{ {

View File

@ -15,7 +15,6 @@ interface HandlerInterface
/** /**
* @param Throwable $e * @param Throwable $e
* @return
*/ */
public function report(Throwable $e); public function report(Throwable $e);
} }

View File

@ -15,6 +15,11 @@ class Whoops extends Legacy implements HandlerInterface
/** @var Application */ /** @var Application */
protected $app; protected $app;
/**
* Whoops constructor.
*
* @param Container $app
*/
public function __construct(Container $app) public function __construct(Container $app)
{ {
$this->app = $app; $this->app = $app;