prohibit inline control structures on model and view

This commit is contained in:
msquare 2016-09-29 11:18:17 +02:00
parent 91dafb19ec
commit e965f8d041
19 changed files with 371 additions and 279 deletions

View File

@ -47,8 +47,9 @@ function AngelType_create($name, $restricted, $description, $requires_driver_lic
`restricted`=" . sql_bool($restricted) . ", `restricted`=" . sql_bool($restricted) . ",
`description`='" . sql_escape($description) . "', `description`='" . sql_escape($description) . "',
`requires_driver_license`=" . sql_bool($requires_driver_license)); `requires_driver_license`=" . sql_bool($requires_driver_license));
if ($result === false) if ($result === false) {
return false; return false;
}
return sql_id(); return sql_id();
} }
@ -61,13 +62,14 @@ function AngelType_create($name, $restricted, $description, $requires_driver_lic
*/ */
function AngelType_validate_name($name, $angeltype) { function AngelType_validate_name($name, $angeltype) {
$name = strip_item($name); $name = strip_item($name);
if ($name == "") if ($name == "") {
return array( return [
false, false,
$name $name
); ];
if (isset($angeltype) && isset($angeltype['id'])) }
return array( if (isset($angeltype) && isset($angeltype['id'])) {
return [
sql_num_query(" sql_num_query("
SELECT * SELECT *
FROM `AngelTypes` FROM `AngelTypes`
@ -75,16 +77,16 @@ function AngelType_validate_name($name, $angeltype) {
AND NOT `id`='" . sql_escape($angeltype['id']) . "' AND NOT `id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1") == 0, LIMIT 1") == 0,
$name $name
); ];
else }
return array( return [
sql_num_query(" sql_num_query("
SELECT `id` SELECT `id`
FROM `AngelTypes` FROM `AngelTypes`
WHERE `name`='" . sql_escape($name) . "' WHERE `name`='" . sql_escape($name) . "'
LIMIT 1") == 0, LIMIT 1") == 0,
$name $name
); ];
} }
/** /**
@ -119,10 +121,12 @@ function AngelTypes() {
*/ */
function AngelType_ids() { function AngelType_ids() {
$angelType_source = sql_select("SELECT `id` FROM `AngelTypes`"); $angelType_source = sql_select("SELECT `id` FROM `AngelTypes`");
if ($angelType_source === false) if ($angelType_source === false) {
return false; return false;
if (count($angelType_source) > 0) }
if (count($angelType_source) > 0) {
return $angelType_source; return $angelType_source;
}
return null; return null;
} }
@ -134,10 +138,12 @@ function AngelType_ids() {
*/ */
function AngelType($id) { function AngelType($id) {
$angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($id) . "' LIMIT 1"); $angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($id) . "' LIMIT 1");
if ($angelType_source === false) if ($angelType_source === false) {
return false; return false;
if (count($angelType_source) > 0) }
if (count($angelType_source) > 0) {
return $angelType_source[0]; return $angelType_source[0];
}
return null; return null;
} }

View File

@ -5,10 +5,12 @@
*/ */
function EventConfig() { function EventConfig() {
$event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1"); $event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1");
if ($event_config === false) if ($event_config === false) {
return false; return false;
if (count($event_config) > 0) }
if (count($event_config) > 0) {
return $event_config[0]; return $event_config[0];
}
return null; return null;
} }

View File

@ -15,10 +15,12 @@ function Message_ids() {
*/ */
function Message($id) { function Message($id) {
$message_source = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($id) . "' LIMIT 1"); $message_source = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($id) . "' LIMIT 1");
if ($message_source === false) if ($message_source === false) {
return false; return false;
if (count($message_source) > 0) }
if (count($message_source) > 0) {
return $message_source[0]; return $message_source[0];
}
return null; return null;
} }

View File

@ -14,10 +14,11 @@ function NeededAngelTypes_by_shift($shiftId) {
AND `count` > 0 AND `count` > 0
ORDER BY `room_id` DESC ORDER BY `room_id` DESC
"); ");
if ($needed_angeltypes_source === false) if ($needed_angeltypes_source === false) {
return false; return false;
}
// Use settings from room // Use settings from room
if (count($needed_angeltypes_source) == 0) { if (count($needed_angeltypes_source) == 0) {
$needed_angeltypes_source = sql_select(" $needed_angeltypes_source = sql_select("
SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted` SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted`
@ -28,15 +29,17 @@ function NeededAngelTypes_by_shift($shiftId) {
AND `count` > 0 AND `count` > 0
ORDER BY `room_id` DESC ORDER BY `room_id` DESC
"); ");
if ($needed_angeltypes_source === false) if ($needed_angeltypes_source === false) {
return false; return false;
}
} }
$needed_angeltypes = array(); $needed_angeltypes = [];
foreach ($needed_angeltypes_source as $angeltype) { foreach ($needed_angeltypes_source as $angeltype) {
$shift_entries = ShiftEntries_by_shift_and_angeltype($shiftId, $angeltype['angel_type_id']); $shift_entries = ShiftEntries_by_shift_and_angeltype($shiftId, $angeltype['angel_type_id']);
if ($shift_entries === false) if ($shift_entries === false) {
return false; return false;
}
$angeltype['taken'] = count($shift_entries); $angeltype['taken'] = count($shift_entries);
$needed_angeltypes[] = $angeltype; $needed_angeltypes[] = $angeltype;

View File

@ -25,8 +25,9 @@ function Room_create($name, $from_frab, $public) {
`FromPentabarf`='" . sql_escape($from_frab ? 'Y' : '') . "', `FromPentabarf`='" . sql_escape($from_frab ? 'Y' : '') . "',
`show`='" . sql_escape($public ? 'Y' : '') . "', `show`='" . sql_escape($public ? 'Y' : '') . "',
`Number`=0"); `Number`=0");
if ($result === false) if ($result === false) {
return false; return false;
}
return sql_id(); return sql_id();
} }
@ -38,10 +39,12 @@ function Room_create($name, $from_frab, $public) {
function Room($id) { function Room($id) {
$room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($id) . "' AND `show` = 'Y'"); $room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($id) . "' AND `show` = 'Y'");
if ($room_source === false) if ($room_source === false) {
return false; return false;
if (count($room_source) > 0) }
if (count($room_source) > 0) {
return $room_source[0]; return $room_source[0];
}
return null; return null;
} }

View File

@ -51,10 +51,12 @@ function ShiftEntry_update($shift_entry) {
*/ */
function ShiftEntry($shift_entry_id) { function ShiftEntry($shift_entry_id) {
$shift_entry = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'"); $shift_entry = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'");
if ($shift_entry === false) if ($shift_entry === false) {
return false; return false;
if (count($shift_entry) == 0) }
if (count($shift_entry) == 0) {
return null; return null;
}
return $shift_entry[0]; return $shift_entry[0];
} }
@ -89,8 +91,8 @@ function ShiftEntries_upcoming_for_user($user) {
* *
* @param User $user * @param User $user
*/ */
function ShiftEntries_finished_by_user($user){ function ShiftEntries_finished_by_user($user) {
return sql_select(" return sql_select("
SELECT * SELECT *
FROM `ShiftEntry` FROM `ShiftEntry`
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`) JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)

View File

@ -37,8 +37,9 @@ function ShiftType_create($name, $angeltype_id, $description) {
`name`='" . sql_escape($name) . "', `name`='" . sql_escape($name) . "',
`angeltype_id`=" . sql_null($angeltype_id) . ", `angeltype_id`=" . sql_null($angeltype_id) . ",
`description`='" . sql_escape($description) . "'"); `description`='" . sql_escape($description) . "'");
if ($result === false) if ($result === false) {
return false; return false;
}
return sql_id(); return sql_id();
} }
@ -49,10 +50,12 @@ function ShiftType_create($name, $angeltype_id, $description) {
*/ */
function ShiftType($shifttype_id) { function ShiftType($shifttype_id) {
$shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'"); $shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
if ($shifttype === false) if ($shifttype === false) {
return false; return false;
if ($shifttype == null) }
if ($shifttype == null) {
return null; return null;
}
return $shifttype[0]; return $shifttype[0];
} }

View File

@ -6,10 +6,13 @@
* @param array<Shift> $shifts * @param array<Shift> $shifts
*/ */
function Shift_collides($shift, $shifts) { function Shift_collides($shift, $shifts) {
foreach ($shifts as $other_shift) foreach ($shifts as $other_shift) {
if ($shift['SID'] != $other_shift['SID']) if ($shift['SID'] != $other_shift['SID']) {
if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) {
return true; return true;
}
}
}
return false; return false;
} }
@ -25,41 +28,46 @@ function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_
if ($user_shifts == null) { if ($user_shifts == null) {
$user_shifts = Shifts_by_user($user); $user_shifts = Shifts_by_user($user);
if ($user_shifts === false) if ($user_shifts === false) {
engelsystem_error('Unable to load users shifts.'); engelsystem_error('Unable to load users shifts.');
}
} }
$collides = Shift_collides($shift, $user_shifts); $collides = Shift_collides($shift, $user_shifts);
if ($user_angeltype == null) { if ($user_angeltype == null) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false) if ($user_angeltype === false) {
engelsystem_error('Unable to load user angeltype.'); engelsystem_error('Unable to load user angeltype.');
}
} }
$signed_up = false; $signed_up = false;
foreach ($user_shifts as $user_shift) foreach ($user_shifts as $user_shift) {
if ($user_shift['SID'] == $shift['SID']) { if ($user_shift['SID'] == $shift['SID']) {
$signed_up = true; $signed_up = true;
break; break;
} }
}
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']); $needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
if ($needed_angeltypes === false) if ($needed_angeltypes === false) {
engelsystem_error('Unable to load needed angel types.'); engelsystem_error('Unable to load needed angel types.');
}
// is the shift still running or alternatively is the user shift admin? // is the shift still running or alternatively is the user shift admin?
$user_may_join_shift = true; $user_may_join_shift = true;
// you canot join if shift is full // you canot join if shift is full
foreach ($needed_angeltypes as $needed_angeltype) foreach ($needed_angeltypes as $needed_angeltype) {
if ($needed_angeltype['angel_type_id'] == $angeltype['id']) { if ($needed_angeltype['angel_type_id'] == $angeltype['id']) {
if ($needed_angeltype['taken'] >= $needed_angeltype['count']) if ($needed_angeltype['taken'] >= $needed_angeltype['count'])
$user_may_join_shift = false; $user_may_join_shift = false;
break; break;
} }
}
// you cannot join if user alread joined a parallel or this shift // you cannot join if user alread joined a parallel or this shift
$user_may_join_shift &= ! $collides; $user_may_join_shift &= ! $collides;
// you cannot join if you already singed up for this shift // you cannot join if you already singed up for this shift
@ -69,10 +77,11 @@ function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_
$user_may_join_shift &= $user_angeltype != null; $user_may_join_shift &= $user_angeltype != null;
// you cannot join if you are not confirmed // you cannot join if you are not confirmed
if ($angeltype['restricted'] == 1 && $user_angeltype != null) if ($angeltype['restricted'] == 1 && $user_angeltype != null) {
$user_may_join_shift &= isset($user_angeltype['confirm_user_id']); $user_may_join_shift &= isset($user_angeltype['confirm_user_id']);
}
// you can only join if the shift is in future // you can only join if the shift is in future
$user_may_join_shift &= time() < $shift['start']; $user_may_join_shift &= time() < $shift['start'];
// User shift admins may join anybody in every shift // User shift admins may join anybody in every shift
@ -123,10 +132,12 @@ function Shift_update($shift) {
*/ */
function Shift_update_by_psid($shift) { function Shift_update_by_psid($shift) {
$shift_source = sql_select("SELECT `SID` FROM `Shifts` WHERE `PSID`=" . $shift['PSID']); $shift_source = sql_select("SELECT `SID` FROM `Shifts` WHERE `PSID`=" . $shift['PSID']);
if ($shift_source === false) if ($shift_source === false) {
return false; return false;
if (count($shift_source) == 0) }
if (count($shift_source) == 0) {
return null; return null;
}
$shift['SID'] = $shift_source[0]['SID']; $shift['SID'] = $shift_source[0]['SID'];
return Shift_update($shift); return Shift_update($shift);
} }
@ -148,8 +159,9 @@ function Shift_create($shift) {
`PSID`=" . sql_null($shift['PSID']) . ", `PSID`=" . sql_null($shift['PSID']) . ",
`created_by_user_id`='" . sql_escape($user['UID']) . "', `created_by_user_id`='" . sql_escape($user['UID']) . "',
`created_at_timestamp`=" . time()); `created_at_timestamp`=" . time());
if ($result === false) if ($result === false) {
return false; return false;
}
return sql_id(); return sql_id();
} }
@ -205,8 +217,9 @@ function Shifts_filtered() {
// real request // real request
$shifts_source = sql_select("SELECT `SID` FROM `Shifts`" . $filter); $shifts_source = sql_select("SELECT `SID` FROM `Shifts`" . $filter);
if ($shifts_source === false) if ($shifts_source === false) {
return false; return false;
}
if (count($shifts_source) > 0) { if (count($shifts_source) > 0) {
return $shifts_source; return $shifts_source;
} }
@ -227,8 +240,9 @@ function Shift($id) {
WHERE `SID`='" . sql_escape($id) . "'"); WHERE `SID`='" . sql_escape($id) . "'");
$shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($id) . "'"); $shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($id) . "'");
if ($shifts_source === false) if ($shifts_source === false) {
return false; return false;
}
if (count($shifts_source) > 0) { if (count($shifts_source) > 0) {
$result = $shifts_source[0]; $result = $shifts_source[0];
@ -260,13 +274,15 @@ function Shifts() {
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID` JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
"); ");
if ($shifts_source === false) if ($shifts_source === false) {
return false; return false;
}
foreach ($shifts_source as &$shift) { foreach ($shifts_source as &$shift) {
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']); $needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
if ($needed_angeltypes === false) if ($needed_angeltypes === false) {
return false; return false;
}
$shift['angeltypes'] = $needed_angeltypes; $shift['angeltypes'] = $needed_angeltypes;
} }

View File

@ -133,8 +133,9 @@ function UserAngelType_create($user, $angeltype) {
INSERT INTO `UserAngelTypes` SET INSERT INTO `UserAngelTypes` SET
`user_id`='" . sql_escape($user['UID']) . "', `user_id`='" . sql_escape($user['UID']) . "',
`angeltype_id`='" . sql_escape($angeltype['id']) . "'"); `angeltype_id`='" . sql_escape($angeltype['id']) . "'");
if ($result === false) if ($result === false) {
return false; return false;
}
return sql_id(); return sql_id();
} }
@ -149,10 +150,12 @@ function UserAngelType($user_angeltype_id) {
FROM `UserAngelTypes` FROM `UserAngelTypes`
WHERE `id`='" . sql_escape($user_angeltype_id) . "' WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1"); LIMIT 1");
if ($angeltype === false) if ($angeltype === false) {
return false; return false;
if (count($angeltype) == 0) }
if (count($angeltype) == 0) {
return null; return null;
}
return $angeltype[0]; return $angeltype[0];
} }
@ -169,10 +172,12 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) {
WHERE `user_id`='" . sql_escape($user['UID']) . "' WHERE `user_id`='" . sql_escape($user['UID']) . "'
AND `angeltype_id`='" . sql_escape($angeltype['id']) . "' AND `angeltype_id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1"); LIMIT 1");
if ($angeltype === false) if ($angeltype === false) {
return false; return false;
if (count($angeltype) == 0) }
if (count($angeltype) == 0) {
return null; return null;
}
return $angeltype[0]; return $angeltype[0];
} }
?> ?>

View File

@ -6,10 +6,12 @@
*/ */
function UserDriverLicense($user_id) { function UserDriverLicense($user_id) {
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'"); $user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
if ($user_driver_license === false) if ($user_driver_license === false) {
return false; return false;
if (count($user_driver_license) > 0) }
if (count($user_driver_license) > 0) {
return $user_driver_license[0]; return $user_driver_license[0];
}
return null; return null;
} }

View File

@ -164,10 +164,12 @@ function User_validate_Nick($nick) {
*/ */
function User($id) { function User($id) {
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1"); $user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
if ($user_source === false) if ($user_source === false) {
return false; return false;
if (count($user_source) > 0) }
if (count($user_source) > 0) {
return $user_source[0]; return $user_source[0];
}
return null; return null;
} }
@ -179,10 +181,12 @@ function User($id) {
*/ */
function mUser_Limit($id) { function mUser_Limit($id) {
$user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber` FROM `User` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1"); $user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber` FROM `User` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
if ($user_source === false) if ($user_source === false) {
return false; return false;
if (count($user_source) > 0) }
if (count($user_source) > 0) {
return $user_source[0]; return $user_source[0];
}
return null; return null;
} }
@ -195,10 +199,12 @@ function mUser_Limit($id) {
*/ */
function User_by_api_key($api_key) { function User_by_api_key($api_key) {
$user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1"); $user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1");
if ($user === false) if ($user === false) {
return false; return false;
if (count($user) == 0) }
if (count($user) == 0) {
return null; return null;
}
return $user[0]; return $user[0];
} }
@ -210,10 +216,12 @@ function User_by_api_key($api_key) {
*/ */
function User_by_email($email) { function User_by_email($email) {
$user = sql_select("SELECT * FROM `User` WHERE `email`='" . sql_escape($email) . "' LIMIT 1"); $user = sql_select("SELECT * FROM `User` WHERE `email`='" . sql_escape($email) . "' LIMIT 1");
if ($user === false) if ($user === false) {
return false; return false;
if (count($user) == 0) }
if (count($user) == 0) {
return null; return null;
}
return $user[0]; return $user[0];
} }
@ -225,10 +233,12 @@ function User_by_email($email) {
*/ */
function User_by_password_recovery_token($token) { function User_by_password_recovery_token($token) {
$user = sql_select("SELECT * FROM `User` WHERE `password_recovery_token`='" . sql_escape($token) . "' LIMIT 1"); $user = sql_select("SELECT * FROM `User` WHERE `password_recovery_token`='" . sql_escape($token) . "' LIMIT 1");
if ($user === false) if ($user === false) {
return false; return false;
if (count($user) == 0) }
if (count($user) == 0) {
return null; return null;
}
return $user[0]; return $user[0];
} }
@ -240,10 +250,12 @@ function User_by_password_recovery_token($token) {
function User_reset_api_key(&$user, $log = true) { function User_reset_api_key(&$user, $log = true) {
$user['api_key'] = md5($user['Nick'] . time() . rand()); $user['api_key'] = md5($user['Nick'] . time() . rand());
$result = sql_query("UPDATE `User` SET `api_key`='" . sql_escape($user['api_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1"); $result = sql_query("UPDATE `User` SET `api_key`='" . sql_escape($user['api_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
if ($result === false) if ($result === false) {
return false; return false;
if ($log) }
if ($log) {
engelsystem_log(sprintf("API key resetted (%s).", User_Nick_render($user))); engelsystem_log(sprintf("API key resetted (%s).", User_Nick_render($user)));
}
} }
/** /**
@ -254,25 +266,25 @@ function User_reset_api_key(&$user, $log = true) {
function User_generate_password_recovery_token(&$user) { function User_generate_password_recovery_token(&$user) {
$user['password_recovery_token'] = md5($user['Nick'] . time() . rand()); $user['password_recovery_token'] = md5($user['Nick'] . time() . rand());
$result = sql_query("UPDATE `User` SET `password_recovery_token`='" . sql_escape($user['password_recovery_token']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1"); $result = sql_query("UPDATE `User` SET `password_recovery_token`='" . sql_escape($user['password_recovery_token']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
if ($result === false) if ($result === false) {
return false; return false;
}
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'];
} }
function User_get_eligable_voucher_count(&$user) { function User_get_eligable_voucher_count(&$user) {
global $voucher_settings; global $voucher_settings;
$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; $elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
if ( $elegible_vouchers < 0) { if ($elegible_vouchers < 0) {
return 0; return 0;
} }
return $elegible_vouchers; return $elegible_vouchers;
} }
?> ?>

View File

@ -21,42 +21,39 @@ function AngelType_name_render($angeltype) {
* @return string * @return string
*/ */
function AngelType_render_membership($user_angeltype) { function AngelType_render_membership($user_angeltype) {
$membership = "";
if ($user_angeltype['user_angeltype_id'] != null) { if ($user_angeltype['user_angeltype_id'] != null) {
if ($user_angeltype['restricted']) { if ($user_angeltype['restricted']) {
if ($user_angeltype['confirm_user_id'] == null) if ($user_angeltype['confirm_user_id'] == null) {
$membership = glyph('lock') . _("Unconfirmed"); return glyph('lock') . _("Unconfirmed");
elseif ($user_angeltype['coordinator']) } elseif ($user_angeltype['coordinator']) {
$membership = glyph_bool(true) . _("Coordinator"); return glyph_bool(true) . _("Coordinator");
else }
$membership = glyph_bool(true) . _("Member"); return glyph_bool(true) . _("Member");
} elseif ($user_angeltype['coordinator']) } elseif ($user_angeltype['coordinator']) {
$membership = glyph_bool(true) . _("Coordinator"); return glyph_bool(true) . _("Coordinator");
else }
$membership = glyph_bool(true) . _("Member"); return glyph_bool(true) . _("Member");
} else {
$membership = glyph_bool(false);
} }
return $membership; return glyph_bool(false);
} }
function AngelType_delete_view($angeltype) { function AngelType_delete_view($angeltype) {
return page_with_title(sprintf(_("Delete angeltype %s"), $angeltype['name']), array( return page_with_title(sprintf(_("Delete angeltype %s"), $angeltype['name']), array(
info(sprintf(_("Do you want to delete angeltype %s?"), $angeltype['name']), true), info(sprintf(_("Do you want to delete angeltype %s?"), $angeltype['name']), true),
buttons(array( buttons([
button(page_link_to('angeltypes'), _("cancel"), 'cancel'), button(page_link_to('angeltypes'), _("cancel"), 'cancel'),
button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'] . '&confirmed', _("delete"), 'ok') button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'] . '&confirmed', _("delete"), 'ok')
)) ])
)); ));
} }
function AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license) { function AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license) {
return page_with_title(sprintf(_("Edit %s"), $name), array( return page_with_title(sprintf(_("Edit %s"), $name), array(
buttons(array( buttons([
button(page_link_to('angeltypes'), _("Angeltypes"), 'back') button(page_link_to('angeltypes'), _("Angeltypes"), 'back')
)), ]),
msg(), msg(),
form(array( form([
$coordinator_mode ? form_info(_("Name"), $name) : form_text('name', _("Name"), $name), $coordinator_mode ? form_info(_("Name"), $name) : form_text('name', _("Name"), $name),
$coordinator_mode ? form_info(_("Restricted"), $restricted ? _("Yes") : _("No")) : form_checkbox('restricted', _("Restricted"), $restricted), $coordinator_mode ? form_info(_("Restricted"), $restricted ? _("Yes") : _("No")) : form_checkbox('restricted', _("Restricted"), $restricted),
$coordinator_mode ? form_info(_("Requires driver license"), $requires_driver_license ? _("Yes") : _("No")) : form_checkbox('requires_driver_license', _("Requires driver license"), $requires_driver_license), $coordinator_mode ? form_info(_("Requires driver license"), $requires_driver_license ? _("Yes") : _("No")) : form_checkbox('requires_driver_license', _("Requires driver license"), $requires_driver_license),
@ -64,7 +61,7 @@ function AngelType_edit_view($name, $restricted, $description, $coordinator_mode
form_textarea('description', _("Description"), $description), form_textarea('description', _("Description"), $description),
form_info("", _("Please use markdown for the description.")), form_info("", _("Please use markdown for the description.")),
form_submit('submit', _("Save")) form_submit('submit', _("Save"))
)) ])
)); ));
} }
@ -73,38 +70,44 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
button(page_link_to('angeltypes'), _("Angeltypes"), 'back') button(page_link_to('angeltypes'), _("Angeltypes"), 'back')
]; ];
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) {
$buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add'); $buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
else { } else {
if ($angeltype['requires_driver_license'] && $user_driver_license == null) if ($angeltype['requires_driver_license'] && $user_driver_license == null) {
error(_("This angeltype requires a driver license. Please enter your driver license information!")); error(_("This angeltype requires a driver license. Please enter your driver license information!"));
}
if ($angeltype['restricted'] && $user_angeltype['confirm_user_id'] == null) if ($angeltype['restricted'] && $user_angeltype['confirm_user_id'] == null) {
error(sprintf(_("You are unconfirmed for this angeltype. Please go to the introduction for %s to get confirmed."), $angeltype['name'])); error(sprintf(_("You are unconfirmed for this angeltype. Please go to the introduction for %s to get confirmed."), $angeltype['name']));
}
$buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'], _("leave"), 'cancel'); $buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'], _("leave"), 'cancel');
} }
if ($admin_angeltypes || $coordinator) if ($admin_angeltypes || $coordinator) {
$buttons[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), 'edit'); $buttons[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), 'edit');
if ($admin_angeltypes) }
if ($admin_angeltypes) {
$buttons[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), 'delete'); $buttons[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), 'delete');
}
$page = array( $page = [
msg(), msg(),
buttons($buttons) buttons($buttons)
); ];
$page[] = '<h3>' . _("Description") . '</h3>'; $page[] = '<h3>' . _("Description") . '</h3>';
$parsedown = new Parsedown(); $parsedown = new Parsedown();
if ($angeltype['description'] != "") if ($angeltype['description'] != "") {
$page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>'; $page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
}
$coordinators = array(); $coordinators = [];
$members_confirmed = array(); $members_confirmed = [];
$members_unconfirmed = array(); $members_unconfirmed = [];
foreach ($members as $member) { foreach ($members as $member) {
$member['Nick'] = User_Nick_render($member); $member['Nick'] = User_Nick_render($member);
@ -125,19 +128,21 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
]); ]);
$members_unconfirmed[] = $member; $members_unconfirmed[] = $member;
} elseif ($member['coordinator']) { } elseif ($member['coordinator']) {
if ($admin_angeltypes) if ($admin_angeltypes) {
$member['actions'] = table_buttons([ $member['actions'] = table_buttons([
button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&coordinator=0', _("Remove coordinator rights"), 'btn-xs') button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&coordinator=0', _("Remove coordinator rights"), 'btn-xs')
]); ]);
else } else {
$member['actions'] = ''; $member['actions'] = '';
}
$coordinators[] = $member; $coordinators[] = $member;
} else { } else {
if ($admin_user_angeltypes) if ($admin_user_angeltypes) {
$member['actions'] = table_buttons([ $member['actions'] = table_buttons([
$admin_angeltypes ? button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&coordinator=1', _("Add coordinator rights"), 'btn-xs') : '', $admin_angeltypes ? button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&coordinator=1', _("Add coordinator rights"), 'btn-xs') : '',
button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $member['user_angeltype_id'], _("remove"), 'btn-xs') button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $member['user_angeltype_id'], _("remove"), 'btn-xs')
]); ]);
}
$members_confirmed[] = $member; $members_confirmed[] = $member;
} }
} }
@ -167,25 +172,28 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
$page[] = table($table_headers, $coordinators); $page[] = table($table_headers, $coordinators);
} }
if (count($members_confirmed) > 0) if (count($members_confirmed) > 0) {
$members_confirmed[] = [ $members_confirmed[] = [
'Nick' => _('Sum'), 'Nick' => _('Sum'),
'DECT' => count($members_confirmed), 'DECT' => count($members_confirmed),
'actions' => '' 'actions' => ''
]; ];
}
if (count($members_unconfirmed) > 0) if (count($members_unconfirmed) > 0) {
$members_unconfirmed[] = [ $members_unconfirmed[] = [
'Nick' => _('Sum'), 'Nick' => _('Sum'),
'DECT' => count($members_unconfirmed), 'DECT' => count($members_unconfirmed),
'actions' => '' 'actions' => ''
]; ];
}
$page[] = '<h3>' . _("Members") . '</h3>'; $page[] = '<h3>' . _("Members") . '</h3>';
if ($admin_user_angeltypes) if ($admin_user_angeltypes) {
$page[] = buttons([ $page[] = buttons([
button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("Add"), 'add') button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("Add"), 'add')
]); ]);
}
$page[] = table($table_headers, $members_confirmed); $page[] = table($table_headers, $members_confirmed);
if ($admin_user_angeltypes && $angeltype['restricted'] && count($members_unconfirmed) > 0) { if ($admin_user_angeltypes && $angeltype['restricted'] && count($members_unconfirmed) > 0) {
@ -206,51 +214,54 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
* @param array $angeltypes * @param array $angeltypes
*/ */
function AngelTypes_list_view($angeltypes, $admin_angeltypes) { function AngelTypes_list_view($angeltypes, $admin_angeltypes) {
return page_with_title(angeltypes_title(), array( return page_with_title(angeltypes_title(), [
msg(), msg(),
buttons(array( buttons([
$admin_angeltypes ? button(page_link_to('angeltypes') . '&action=edit', _("New angeltype"), 'add') : '', $admin_angeltypes ? button(page_link_to('angeltypes') . '&action=edit', _("New angeltype"), 'add') : '',
button(page_link_to('angeltypes') . '&action=about', _("Teams/Job description")) button(page_link_to('angeltypes') . '&action=about', _("Teams/Job description"))
)), ]),
table(array( table([
'name' => _("Name"), 'name' => _("Name"),
'restricted' => glyph('lock') . _("Restricted"), 'restricted' => glyph('lock') . _("Restricted"),
'membership' => _("Membership"), 'membership' => _("Membership"),
'actions' => "" 'actions' => ""
), $angeltypes) ], $angeltypes)
)); ]);
} }
function AngelTypes_about_view($angeltypes, $user_logged_in) { function AngelTypes_about_view($angeltypes, $user_logged_in) {
global $faq_url; global $faq_url;
$content = array( $content = [
buttons(array( buttons([
! $user_logged_in ? button(page_link_to('register'), register_title()) : '', ! $user_logged_in ? button(page_link_to('register'), register_title()) : '',
! $user_logged_in ? button(page_link_to('login'), login_title()) : '', ! $user_logged_in ? button(page_link_to('login'), login_title()) : '',
$user_logged_in ? button(page_link_to('angeltypes'), angeltypes_title(), 'back') : '', $user_logged_in ? button(page_link_to('angeltypes'), angeltypes_title(), 'back') : '',
button($faq_url, _("FAQ"), "btn-primary") button($faq_url, _("FAQ"), "btn-primary")
)), ]),
'<p>' . _("Here is the list of teams and their tasks. If you have questions, read the FAQ.") . '</p>', '<p>' . _("Here is the list of teams and their tasks. If you have questions, read the FAQ.") . '</p>',
'<hr />' '<hr />'
); ];
$parsedown = new Parsedown(); $parsedown = new Parsedown();
foreach ($angeltypes as $angeltype) { foreach ($angeltypes as $angeltype) {
$content[] = '<h2>' . $angeltype['name'] . '</h2>'; $content[] = '<h2>' . $angeltype['name'] . '</h2>';
if (isset($angeltype['user_angeltype_id'])) { if (isset($angeltype['user_angeltype_id'])) {
$buttons = array(); $buttons = [];
if ($angeltype['user_angeltype_id'] != null) if ($angeltype['user_angeltype_id'] != null) {
$buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), 'cancel'); $buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), 'cancel');
else } else {
$buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add'); $buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
}
$content[] = buttons($buttons); $content[] = buttons($buttons);
} }
if ($angeltype['restricted']) if ($angeltype['restricted']) {
$content[] = info(_("This angeltype is restricted by double-opt-in by a team coordinator. Please show up at the according introduction meetings."), true); $content[] = info(_("This angeltype is restricted by double-opt-in by a team coordinator. Please show up at the according introduction meetings."), true);
if ($angeltype['description'] != "") }
if ($angeltype['description'] != "") {
$content[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>'; $content[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
}
$content[] = '<hr />'; $content[] = '<hr />';
} }

View File

@ -12,26 +12,26 @@ function Questions_view($open_questions, $answered_questions, $ask_action) {
$question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>'; $question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>';
} }
return page_with_title(questions_title(), array( return page_with_title(questions_title(), [
msg(), msg(),
'<h2>' . _("Open questions") . '</h2>', heading(_("Open questions"), 2),
table(array( table([
'Question' => _("Question"), 'Question' => _("Question"),
'actions' => "" 'actions' => ""
), $open_questions), ], $open_questions),
'<h2>' . _("Answered questions") . '</h2>', heading(_("Answered questions"), 2),
table(array( table([
'Question' => _("Question"), 'Question' => _("Question"),
'answer_user' => _("Answered by"), 'answer_user' => _("Answered by"),
'Answer' => _("Answer"), 'Answer' => _("Answer"),
'actions' => "" 'actions' => ""
), $answered_questions), ], $answered_questions),
'<h2>' . _("Ask an archangel") . '</h2>', heading(_("Ask an archangel"), 2),
form(array( form([
form_textarea('question', _("Your Question:"), ""), form_textarea('question', _("Your Question:"), ""),
form_submit('submit', _("Save")) form_submit('submit', _("Save"))
), $ask_action) ], $ask_action)
)); ]);
} }
?> ?>

View File

@ -2,8 +2,9 @@
function Room_name_render($room) { function Room_name_render($room) {
global $privileges; global $privileges;
if (in_array('admin_rooms', $privileges)) if (in_array('admin_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

@ -13,16 +13,16 @@
*/ */
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) {
if ($user_admin_shifts) { if ($user_admin_shifts) {
$freeload_form = array( $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)
); ];
} else { } else {
$freeload_form = array(); $freeload_form = [];
} }
return page_with_title(_("Edit shift entry"), array( return page_with_title(_("Edit shift entry"), [
msg(), msg(),
form(array( form([
form_info(_("Angel:"), $angel), form_info(_("Angel:"), $angel),
form_info(_("Date, Duration:"), $date), form_info(_("Date, Duration:"), $date),
form_info(_("Location:"), $location), form_info(_("Location:"), $location),
@ -31,8 +31,8 @@ function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment,
form_textarea('comment', _("Comment (for your eyes only):"), $comment), form_textarea('comment', _("Comment (for your eyes only):"), $comment),
join("", $freeload_form), join("", $freeload_form),
form_submit('submit', _("Save")) form_submit('submit', _("Save"))
)) ])
)); ]);
} }
?> ?>

View File

@ -2,27 +2,29 @@
function ShiftType_name_render($shifttype) { function ShiftType_name_render($shifttype) {
global $privileges; global $privileges;
if (in_array('shifttypes', $privileges)) if (in_array('shifttypes', $privileges)) {
return '<a href="' . shifttype_link($shifttype) . '">' . $shifttype['name'] . '</a>'; return '<a href="' . shifttype_link($shifttype) . '">' . $shifttype['name'] . '</a>';
}
return $shifttype['name']; return $shifttype['name'];
} }
function ShiftType_delete_view($shifttype) { function ShiftType_delete_view($shifttype) {
return page_with_title(sprintf(_("Delete shifttype %s"), $shifttype['name']), array( return page_with_title(sprintf(_("Delete shifttype %s"), $shifttype['name']), [
info(sprintf(_("Do you want to delete shifttype %s?"), $shifttype['name']), true), info(sprintf(_("Do you want to delete shifttype %s?"), $shifttype['name']), true),
buttons(array( buttons([
button(page_link_to('shifttypes'), _("cancel"), 'cancel'), button(page_link_to('shifttypes'), _("cancel"), 'cancel'),
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'] . '&confirmed', _("delete"), 'ok') button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'] . '&confirmed', _("delete"), 'ok')
)) ])
)); ]);
} }
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) { function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) {
$angeltypes_select = [ $angeltypes_select = [
'' => _('All') '' => _('All')
]; ];
foreach ($angeltypes as $angeltype) foreach ($angeltypes as $angeltype) {
$angeltypes_select[$angeltype['id']] = $angeltype['name']; $angeltypes_select[$angeltype['id']] = $angeltype['name'];
}
return page_with_title($shifttype_id ? _('Edit shifttype') : _('Create shifttype'), [ return page_with_title($shifttype_id ? _('Edit shifttype') : _('Create shifttype'), [
msg(), msg(),
@ -42,8 +44,9 @@ function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $s
function ShiftType_view($shifttype, $angeltype) { function ShiftType_view($shifttype, $angeltype) {
$parsedown = new Parsedown(); $parsedown = new Parsedown();
$title = $shifttype['name']; $title = $shifttype['name'];
if ($angeltype) if ($angeltype) {
$title .= ' <small>' . sprintf(_('for team %s'), $angeltype['name']) . '</small>'; $title .= ' <small>' . sprintf(_('for team %s'), $angeltype['name']) . '</small>';
}
return page_with_title($title, [ return page_with_title($title, [
msg(), msg(),
buttons([ buttons([

View File

@ -2,10 +2,12 @@
function Shift_editor_info_render($shift) { function Shift_editor_info_render($shift) {
$info = []; $info = [];
if ($shift['created_by_user_id'] != null) if ($shift['created_by_user_id'] != null) {
$info[] = sprintf(glyph('plus') . _("created at %s by %s"), date('Y-m-d H:i', $shift['created_at_timestamp']), User_Nick_render(User($shift['created_by_user_id']))); $info[] = sprintf(glyph('plus') . _("created at %s by %s"), date('Y-m-d H:i', $shift['created_at_timestamp']), User_Nick_render(User($shift['created_by_user_id'])));
if ($shift['edited_by_user_id'] != null) }
if ($shift['edited_by_user_id'] != null) {
$info[] = sprintf(glyph('pencil') . _("edited at %s by %s"), date('Y-m-d H:i', $shift['edited_at_timestamp']), User_Nick_render(User($shift['edited_by_user_id']))); $info[] = sprintf(glyph('pencil') . _("edited at %s by %s"), date('Y-m-d H:i', $shift['edited_at_timestamp']), User_Nick_render(User($shift['edited_by_user_id'])));
}
return join('<br />', $info); return join('<br />', $info);
} }
@ -14,32 +16,36 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null,
if ($user_angeltype == null) { if ($user_angeltype == null) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false) if ($user_angeltype === false) {
engelsystem_error('Unable to load user angeltype.'); engelsystem_error('Unable to load user angeltype.');
}
} }
if (Shift_signup_allowed($shift, $angeltype, $user_angeltype, $user_shifts)) if (Shift_signup_allowed($shift, $angeltype, $user_angeltype, $user_shifts)) {
return button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up')); return button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'));
elseif ($user_angeltype == null) } elseif ($user_angeltype == null) {
return button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name'])); return button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']));
else }
return ''; return '';
} }
function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $user_shift_admin, $admin_rooms, $admin_shifttypes, $user_shifts, $signed_up) { function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $user_shift_admin, $admin_rooms, $admin_shifttypes, $user_shifts, $signed_up) {
$parsedown = new Parsedown(); $parsedown = new Parsedown();
$angeltypes = []; $angeltypes = [];
foreach ($angeltypes_source as $angeltype) foreach ($angeltypes_source as $angeltype) {
$angeltypes[$angeltype['id']] = $angeltype; $angeltypes[$angeltype['id']] = $angeltype;
}
$needed_angels = ''; $needed_angels = '';
foreach ($shift['NeedAngels'] as $needed_angeltype) { foreach ($shift['NeedAngels'] as $needed_angeltype) {
$class = 'progress-bar-warning'; $class = 'progress-bar-warning';
if ($needed_angeltype['taken'] == 0) if ($needed_angeltype['taken'] == 0) {
$class = 'progress-bar-danger'; $class = 'progress-bar-danger';
if ($needed_angeltype['taken'] >= $needed_angeltype['count']) }
if ($needed_angeltype['taken'] >= $needed_angeltype['count']) {
$class = 'progress-bar-success'; $class = 'progress-bar-success';
}
$needed_angels .= '<div class="list-group-item">'; $needed_angels .= '<div class="list-group-item">';
$needed_angels .= '<div class="pull-right">' . Shift_signup_button_render($shift, $angeltypes[$needed_angeltype['TID']]) . '</div>'; $needed_angels .= '<div class="pull-right">' . Shift_signup_button_render($shift, $angeltypes[$needed_angeltype['TID']]) . '</div>';
@ -51,8 +57,9 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source,
foreach ($shift['ShiftEntry'] as $shift_entry) { foreach ($shift['ShiftEntry'] as $shift_entry) {
if ($shift_entry['TID'] == $needed_angeltype['TID']) { if ($shift_entry['TID'] == $needed_angeltype['TID']) {
$entry = User_Nick_render(User($shift_entry['UID'])); $entry = User_Nick_render(User($shift_entry['UID']));
if ($shift_entry['freeloaded']) if ($shift_entry['freeloaded']) {
$entry = '<strike>' . $entry . '</strike>'; $entry = '<strike>' . $entry . '</strike>';
}
if ($user_shift_admin) { if ($user_shift_admin) {
$entry .= ' <div class="btn-group">'; $entry .= ' <div class="btn-group">';
$entry .= button_glyph(page_link_to('user_myshifts') . '&edit=' . $shift_entry['id'] . '&id=' . $shift_entry['UID'], 'pencil', 'btn-xs'); $entry .= button_glyph(page_link_to('user_myshifts') . '&edit=' . $shift_entry['id'] . '&id=' . $shift_entry['UID'], 'pencil', 'btn-xs');
@ -69,7 +76,6 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source,
} }
return page_with_title($shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [ return page_with_title($shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
msg(), msg(),
Shift_collides($shift, $user_shifts) ? info(_('This shift collides with one of your shifts.'), true) : '', Shift_collides($shift, $user_shifts) ? info(_('This shift collides with one of your shifts.'), true) : '',
$signed_up ? info(_('You are signed up for this shift.'), true) : '', $signed_up ? info(_('You are signed up for this shift.'), true) : '',

View File

@ -1,86 +1,88 @@
<?php <?php
function UserAngelType_update_view($user_angeltype, $user, $angeltype, $coordinator) { function UserAngelType_update_view($user_angeltype, $user, $angeltype, $coordinator) {
return page_with_title($coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"), array( return page_with_title($coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"), [
msg(), msg(),
info(sprintf($coordinator ? _("Do you really want to add coordinator rights for %s to %s?") : _("Do you really want to remove coordinator rights for %s from %s?"), $angeltype['name'], User_Nick_render($user)), true), info(sprintf($coordinator ? _("Do you really want to add coordinator rights for %s to %s?") : _("Do you really want to remove coordinator rights for %s from %s?"), $angeltype['name'], User_Nick_render($user)), true),
buttons(array( buttons([
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'), button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $user_angeltype['id'] . '&coordinator=' . ($coordinator ? '1' : '0') . '&confirmed', _("yes"), 'ok') button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $user_angeltype['id'] . '&coordinator=' . ($coordinator ? '1' : '0') . '&confirmed', _("yes"), 'ok')
)) ])
)); ]);
} }
function UserAngelTypes_delete_all_view($angeltype) { function UserAngelTypes_delete_all_view($angeltype) {
return page_with_title(_("Deny all users"), array( return page_with_title(_("Deny all users"), [
msg(), msg(),
info(sprintf(_("Do you really want to deny all users for %s?"), $angeltype['name']), true), info(sprintf(_("Do you really want to deny all users for %s?"), $angeltype['name']), true),
buttons(array( buttons([
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'), button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'] . '&confirmed', _("yes"), 'ok') button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'] . '&confirmed', _("yes"), 'ok')
)) ])
)); ]);
} }
function UserAngelTypes_confirm_all_view($angeltype) { function UserAngelTypes_confirm_all_view($angeltype) {
return page_with_title(_("Confirm all users"), array( return page_with_title(_("Confirm all users"), [
msg(), msg(),
info(sprintf(_("Do you really want to confirm all users for %s?"), $angeltype['name']), true), info(sprintf(_("Do you really want to confirm all users for %s?"), $angeltype['name']), true),
buttons(array( buttons([
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'), button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
button(page_link_to('user_angeltypes') . '&action=confirm_all&angeltype_id=' . $angeltype['id'] . '&confirmed', _("yes"), 'ok') button(page_link_to('user_angeltypes') . '&action=confirm_all&angeltype_id=' . $angeltype['id'] . '&confirmed', _("yes"), 'ok')
)) ])
)); ]);
} }
function UserAngelType_confirm_view($user_angeltype, $user, $angeltype) { function UserAngelType_confirm_view($user_angeltype, $user, $angeltype) {
return page_with_title(_("Confirm angeltype for user"), array( 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(array( buttons([
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'), button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
button(page_link_to('user_angeltypes') . '&action=confirm&user_angeltype_id=' . $user_angeltype['id'] . '&confirmed', _("yes"), 'ok') button(page_link_to('user_angeltypes') . '&action=confirm&user_angeltype_id=' . $user_angeltype['id'] . '&confirmed', _("yes"), 'ok')
)) ])
)); ]);
} }
function UserAngelType_delete_view($user_angeltype, $user, $angeltype) { function UserAngelType_delete_view($user_angeltype, $user, $angeltype) {
return page_with_title(_("Remove angeltype"), array( 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(array( buttons([
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'), button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'] . '&confirmed', _("yes"), 'ok') button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'] . '&confirmed', _("yes"), 'ok')
)) ])
)); ]);
} }
function UserAngelType_add_view($angeltype, $users_source, $user_id) { function UserAngelType_add_view($angeltype, $users_source, $user_id) {
$users = array(); $users = [];
foreach ($users_source as $user_source) foreach ($users_source as $user_source) {
$users[$user_source['UID']] = User_Nick_render($user_source); $users[$user_source['UID']] = User_Nick_render($user_source);
}
return page_with_title(_("Add user to angeltype"), array( return page_with_title(_("Add user to angeltype"), [
msg(), msg(),
buttons(array( buttons([
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("back"), 'back') button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("back"), 'back')
)), ]),
form(array( form([
form_info(_("Angeltype"), $angeltype['name']), form_info(_("Angeltype"), $angeltype['name']),
form_select('user_id', _("User"), $users, $user_id), form_select('user_id', _("User"), $users, $user_id),
form_submit('submit', _("Add")) form_submit('submit', _("Add"))
)) ])
)); ]);
} }
function UserAngelType_join_view($user, $angeltype) { function UserAngelType_join_view($user, $angeltype) {
return page_with_title(sprintf(_("Become a %s"), $angeltype['name']), array( 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(array( buttons([
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'), button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("cancel"), 'cancel'),
button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'] . '&user_id=' . $user['UID'] . '&confirmed', _("save"), 'ok') button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'] . '&user_id=' . $user['UID'] . '&confirmed', _("save"), 'ok')
)) ])
)); ]);
} }
?> ?>

View File

@ -3,7 +3,7 @@
/** /**
* Available T-Shirt sizes * Available T-Shirt sizes
*/ */
$tshirt_sizes = array( $tshirt_sizes = [
'' => _("Please select..."), '' => _("Please select..."),
'S' => "S", 'S' => "S",
'M' => "M", 'M' => "M",
@ -17,7 +17,7 @@ $tshirt_sizes = array(
'M-G' => "M Girl", 'M-G' => "M Girl",
'L-G' => "L Girl", 'L-G' => "L Girl",
'XL-G' => "XL Girl" 'XL-G' => "XL Girl"
); ];
/** /**
* Displays the welcome message to the user and shows a login form. * Displays the welcome message to the user and shows a login form.
@ -112,12 +112,12 @@ function Users_view($users, $order_by, $arrived_count, $active_count, $force_act
'actions' => '<strong>' . count($users) . '</strong>' 'actions' => '<strong>' . count($users) . '</strong>'
); );
return page_with_title(_('All users'), array( return page_with_title(_('All users'), [
msg(), msg(),
buttons(array( buttons([
button(page_link_to('register'), glyph('plus') . _('New user')) button(page_link_to('register'), glyph('plus') . _('New user'))
)), ]),
table(array( table([
'Nick' => Users_table_header_link('Nick', _('Nick'), $order_by), 'Nick' => Users_table_header_link('Nick', _('Nick'), $order_by),
'Vorname' => Users_table_header_link('Vorname', _('Prename'), $order_by), 'Vorname' => Users_table_header_link('Vorname', _('Prename'), $order_by),
'Name' => Users_table_header_link('Name', _('Name'), $order_by), 'Name' => Users_table_header_link('Name', _('Name'), $order_by),
@ -131,8 +131,8 @@ function Users_view($users, $order_by, $arrived_count, $active_count, $force_act
'Size' => Users_table_header_link('Size', _('Size'), $order_by), 'Size' => Users_table_header_link('Size', _('Size'), $order_by),
'lastLogIn' => Users_table_header_link('lastLogIn', _('Last login'), $order_by), 'lastLogIn' => Users_table_header_link('lastLogIn', _('Last login'), $order_by),
'actions' => '' 'actions' => ''
), $users) ], $users)
)); ]);
} }
function Users_table_header_link($column, $label, $order_by) { function Users_table_header_link($column, $label, $order_by) {
@ -141,24 +141,28 @@ function Users_table_header_link($column, $label, $order_by) {
function User_shift_state_render($user) { function User_shift_state_render($user) {
$upcoming_shifts = ShiftEntries_upcoming_for_user($user); $upcoming_shifts = ShiftEntries_upcoming_for_user($user);
if ($upcoming_shifts === false) if ($upcoming_shifts === false) {
return false; return false;
}
if (count($upcoming_shifts) == 0) if (count($upcoming_shifts) == 0) {
return '<span class="text-success">' . _("Free") . '</span>'; return '<span class="text-success">' . _("Free") . '</span>';
}
if ($upcoming_shifts[0]['start'] > time()) if ($upcoming_shifts[0]['start'] > time()) {
if ($upcoming_shifts[0]['start'] - time() > 3600) if ($upcoming_shifts[0]['start'] - time() > 3600) {
return '<span class="text-success moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>'; return '<span class="text-success moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>';
else } else {
return '<span class="text-warning moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>'; return '<span class="text-warning moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>';
}
}
$halfway = ($upcoming_shifts[0]['start'] + $upcoming_shifts[0]['end']) / 2; $halfway = ($upcoming_shifts[0]['start'] + $upcoming_shifts[0]['end']) / 2;
if (time() < $halfway) if (time() < $halfway) {
return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Shift starts %c") . '</span>'; return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Shift starts %c") . '</span>';
else } else {
return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['end'] . '">' . _("Shift ends %c") . '</span>'; return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['end'] . '">' . _("Shift ends %c") . '</span>';
}
} }
function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) { function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) {
@ -166,76 +170,83 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
$user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']); $user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']);
$myshifts_table = array(); $myshifts_table = [];
$timesum = 0; $timesum = 0;
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
$shift_info = '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>'; $shift_info = '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>';
if ($shift['title']) if ($shift['title']) {
$shift_info .= '<br /><a href="' . shift_link($shift) . '">' . $shift['title'] . '</a>'; $shift_info .= '<br /><a href="' . shift_link($shift) . '">' . $shift['title'] . '</a>';
}
foreach ($shift['needed_angeltypes'] as $needed_angel_type) { foreach ($shift['needed_angeltypes'] as $needed_angel_type) {
$shift_info .= '<br><b>' . $needed_angel_type['name'] . ':</b> '; $shift_info .= '<br><b>' . $needed_angel_type['name'] . ':</b> ';
$shift_entries = array(); $shift_entries = [];
foreach ($needed_angel_type['users'] as $user_shift) { foreach ($needed_angel_type['users'] as $user_shift) {
$member = User_Nick_render($user_shift); $member = User_Nick_render($user_shift);
if ($user_shift['freeloaded']) if ($user_shift['freeloaded']) {
$member = '<strike>' . $member . '</strike>'; $member = '<strike>' . $member . '</strike>';
}
$shift_entries[] = $member; $shift_entries[] = $member;
} }
$shift_info .= join(", ", $shift_entries); $shift_info .= join(", ", $shift_entries);
} }
$myshift = array( $myshift = [
'date' => date("Y-m-d", $shift['start']), 'date' => date("Y-m-d", $shift['start']),
'time' => date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']), 'time' => date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']),
'room' => $shift['Name'], 'room' => $shift['Name'],
'shift_info' => $shift_info, 'shift_info' => $shift_info,
'comment' => $shift['Comment'] '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>';
}
} }
$myshift['actions'] = [ $myshift['actions'] = [
button(shift_link($shift), glyph('eye-open') . _('view'), 'btn-xs') button(shift_link($shift), glyph('eye-open') . _('view'), 'btn-xs')
]; ];
if ($its_me || in_array('user_shifts_admin', $privileges)) if ($its_me || in_array('user_shifts_admin', $privileges)) {
$myshift['actions'][] = button(page_link_to('user_myshifts') . '&edit=' . $shift['id'] . '&id=' . $user_source['UID'], glyph('edit') . _('edit'), 'btn-xs'); $myshift['actions'][] = button(page_link_to('user_myshifts') . '&edit=' . $shift['id'] . '&id=' . $user_source['UID'], glyph('edit') . _('edit'), 'btn-xs');
if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) }
if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) {
$myshift['actions'][] = button(page_link_to('user_myshifts') . ((! $its_me) ? '&id=' . $user_source['UID'] : '') . '&cancel=' . $shift['id'], glyph('trash') . _('sign off'), 'btn-xs'); $myshift['actions'][] = button(page_link_to('user_myshifts') . ((! $its_me) ? '&id=' . $user_source['UID'] : '') . '&cancel=' . $shift['id'], glyph('trash') . _('sign off'), 'btn-xs');
}
$myshift['actions'] = table_buttons($myshift['actions']); $myshift['actions'] = table_buttons($myshift['actions']);
if ($shift['freeloaded']) if ($shift['freeloaded']) {
$timesum += (- 2 * ($shift['end'] - $shift['start'])); $timesum += (- 2 * ($shift['end'] - $shift['start']));
else } else {
$timesum += ($shift['end'] - $shift['start']); $timesum += ($shift['end'] - $shift['start']);
}
$myshifts_table[] = $myshift; $myshifts_table[] = $myshift;
} }
if (count($myshifts_table) > 0) if (count($myshifts_table) > 0) {
$myshifts_table[] = array( $myshifts_table[] = [
'date' => '<b>' . _("Sum:") . '</b>', 'date' => '<b>' . _("Sum:") . '</b>',
'time' => "<b>" . round($timesum / 3600, 1) . " h</b>", 'time' => "<b>" . round($timesum / 3600, 1) . " h</b>",
'room' => "", 'room' => "",
'shift_info' => "", 'shift_info' => "",
'comment' => "", 'comment' => "",
'actions' => "" 'actions' => ""
); ];
}
return page_with_title('<span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . ' <small>' . $user_name . '</small>', array( return page_with_title('<span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . ' <small>' . $user_name . '</small>', [
msg(), msg(),
div('row', array( div('row', [
div('col-md-3', array( div('col-md-3', [
'<h1>', '<h1>',
'<span class="glyphicon glyphicon-phone"></span>', '<span class="glyphicon glyphicon-phone"></span>',
$user_source['DECT'], $user_source['DECT'],
'</h1>' '</h1>'
)), ]),
div('col-md-3', array( div('col-md-3', [
'<h4>' . _("User state") . '</h4>', '<h4>' . _("User state") . '</h4>',
($admin_user_privilege && $freeloader) ? '<span class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> ' . _("Freeloader") . '</span><br />' : '', ($admin_user_privilege && $freeloader) ? '<span class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> ' . _("Freeloader") . '</span><br />' : '',
$user_source['Gekommen'] ? User_shift_state_render($user_source) . '<br />' : '', $user_source['Gekommen'] ? User_shift_state_render($user_source) . '<br />' : '',
@ -243,19 +254,19 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
$admin_user_privilege ? ($user_source['got_voucher'] > 0 ? '<br /><span class="text-success">' . glyph('cutlery') . sprintf(ngettext("Got %s voucher", "Got %s vouchers", $user_source['got_voucher']), $user_source['got_voucher']) . '</span><br />' : '<br /><span class="text-danger">' . _("Got no vouchers") . '</span><br />') : '', $admin_user_privilege ? ($user_source['got_voucher'] > 0 ? '<br /><span class="text-success">' . glyph('cutlery') . sprintf(ngettext("Got %s voucher", "Got %s vouchers", $user_source['got_voucher']), $user_source['got_voucher']) . '</span><br />' : '<br /><span class="text-danger">' . _("Got no vouchers") . '</span><br />') : '',
($user_source['Gekommen'] && $admin_user_privilege && $user_source['Aktiv']) ? ' <span class="text-success">' . _("Active") . '</span>' : '', ($user_source['Gekommen'] && $admin_user_privilege && $user_source['Aktiv']) ? ' <span class="text-success">' . _("Active") . '</span>' : '',
($user_source['Gekommen'] && $admin_user_privilege && $user_source['Tshirt']) ? ' <span class="text-success">' . _("T-Shirt") . '</span>' : '' ($user_source['Gekommen'] && $admin_user_privilege && $user_source['Tshirt']) ? ' <span class="text-success">' . _("T-Shirt") . '</span>' : ''
)), ]),
div('col-md-3', array( div('col-md-3', [
'<h4>' . _("Angeltypes") . '</h4>', '<h4>' . _("Angeltypes") . '</h4>',
User_angeltypes_render($user_angeltypes) User_angeltypes_render($user_angeltypes)
)), ]),
div('col-md-3', array( div('col-md-3', [
'<h4>' . _("Rights") . '</h4>', '<h4>' . _("Rights") . '</h4>',
User_groups_render($user_groups) User_groups_render($user_groups)
)) ])
)), ]),
div('row space-top', array( div('row space-top', [
div('col-md-12', array( div('col-md-12', [
buttons(array( buttons([
$admin_user_privilege ? button(page_link_to('admin_user') . '&id=' . $user_source['UID'], glyph("edit") . _("edit")) : '', $admin_user_privilege ? button(page_link_to('admin_user') . '&id=' . $user_source['UID'], glyph("edit") . _("edit")) : '',
$admin_user_privilege ? button(user_driver_license_edit_link($user_source), glyph("road") . _("driving license")) : '', $admin_user_privilege ? button(user_driver_license_edit_link($user_source), glyph("road") . _("driving license")) : '',
($admin_user_privilege && ! $user_source['Gekommen']) ? button(page_link_to('admin_arrive') . '&arrived=' . $user_source['UID'], _("arrived")) : '', ($admin_user_privilege && ! $user_source['Gekommen']) ? button(page_link_to('admin_arrive') . '&arrived=' . $user_source['UID'], _("arrived")) : '',
@ -264,63 +275,65 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
$its_me ? button(page_link_to('ical') . '&key=' . $user_source['api_key'], glyph('calendar') . _("iCal Export")) : '', $its_me ? button(page_link_to('ical') . '&key=' . $user_source['api_key'], glyph('calendar') . _("iCal Export")) : '',
$its_me ? button(page_link_to('shifts_json_export') . '&key=' . $user_source['api_key'], glyph('export') . _("JSON Export")) : '', $its_me ? button(page_link_to('shifts_json_export') . '&key=' . $user_source['api_key'], glyph('export') . _("JSON Export")) : '',
$its_me ? button(page_link_to('user_myshifts') . '&reset', glyph('repeat') . _('Reset API key')) : '' $its_me ? button(page_link_to('user_myshifts') . '&reset', glyph('repeat') . _('Reset API key')) : ''
)) ])
)) ])
)), ]),
($its_me || $admin_user_privilege) ? '<h2>' . _("Shifts") . '</h2>' : '', ($its_me || $admin_user_privilege) ? '<h2>' . _("Shifts") . '</h2>' : '',
($its_me || $admin_user_privilege) ? table(array( ($its_me || $admin_user_privilege) ? table([
'date' => _("Day"), 'date' => _("Day"),
'time' => _("Time"), 'time' => _("Time"),
'room' => _("Location"), 'room' => _("Location"),
'shift_info' => _("Name &amp; workmates"), 'shift_info' => _("Name &amp; workmates"),
'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 ? error(sprintf(_("Go to the <a href=\"%s\">shifts table</a> to sign yourself up for some shifts."), page_link_to('user_shifts')), true) : '' $its_me && count($shifts) == 0 ? error(sprintf(_("Go to the <a href=\"%s\">shifts table</a> to sign yourself up for some shifts."), page_link_to('user_shifts')), true) : ''
)); ]);
} }
/** /**
* View for password recovery step 1: E-Mail * View for password recovery step 1: E-Mail
*/ */
function User_password_recovery_view() { function User_password_recovery_view() {
return page_with_title(user_password_recovery_title(), array( return page_with_title(user_password_recovery_title(), [
msg(), msg(),
_("We will send you an e-mail with a password recovery link. Please use the email address you used for registration."), _("We will send you an e-mail with a password recovery link. Please use the email address you used for registration."),
form(array( form([
form_text('email', _("E-Mail"), ""), form_text('email', _("E-Mail"), ""),
form_submit('submit', _("Recover")) form_submit('submit', _("Recover"))
)) ])
)); ]);
} }
/** /**
* View for password recovery step 2: New password * View for password recovery step 2: New password
*/ */
function User_password_set_view() { function User_password_set_view() {
return page_with_title(user_password_recovery_title(), array( return page_with_title(user_password_recovery_title(), [
msg(), msg(),
_("Please enter a new password."), _("Please enter a new password."),
form(array( form([
form_password('password', _("Password")), form_password('password', _("Password")),
form_password('password2', _("Confirm password")), form_password('password2', _("Confirm password")),
form_submit('submit', _("Save")) form_submit('submit', _("Save"))
)) ])
)); ]);
} }
function User_angeltypes_render($user_angeltypes) { function User_angeltypes_render($user_angeltypes) {
$output = array(); $output = [];
foreach ($user_angeltypes as $angeltype) { foreach ($user_angeltypes as $angeltype) {
$class = ""; $class = "";
if ($angeltype['restricted'] == 1) if ($angeltype['restricted'] == 1) {
if ($angeltype['confirm_user_id'] != null) if ($angeltype['confirm_user_id'] != null) {
$class = 'text-success'; $class = 'text-success';
else } else {
$class = 'text-warning'; $class = 'text-warning';
else }
} else {
$class = 'text-success'; $class = 'text-success';
}
$output[] = '<a href="' . angeltype_link($angeltype['id']) . '" class="' . $class . '">' . ($angeltype['coordinator'] ? glyph('education') : '') . $angeltype['name'] . '</a>'; $output[] = '<a href="' . angeltype_link($angeltype['id']) . '" class="' . $class . '">' . ($angeltype['coordinator'] ? glyph('education') : '') . $angeltype['name'] . '</a>';
} }
return join('<br />', $output); return join('<br />', $output);