PSR-2 formatting
This commit is contained in:
parent
b839e40106
commit
7313e15ce8
|
@ -49,8 +49,8 @@ $shift_sum_formula = "SUM(
|
|||
|
||||
// voucher calculation
|
||||
$voucher_settings = [
|
||||
"initial_vouchers" => 2,
|
||||
"shifts_per_voucher" => 1
|
||||
"initial_vouchers" => 2,
|
||||
"shifts_per_voucher" => 1
|
||||
];
|
||||
|
||||
// weigh every shift the same
|
||||
|
@ -66,4 +66,3 @@ $config = [
|
|||
'pw' => "",
|
||||
'db' => "engelsystem"
|
||||
];
|
||||
?>
|
||||
|
|
|
@ -3,17 +3,19 @@
|
|||
/**
|
||||
* Text for Angeltype related links.
|
||||
*/
|
||||
function angeltypes_title() {
|
||||
return _("Angeltypes");
|
||||
function angeltypes_title()
|
||||
{
|
||||
return _("Angeltypes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Route angeltype actions.
|
||||
*/
|
||||
function angeltypes_controller() {
|
||||
$action = strip_request_item('action', 'list');
|
||||
function angeltypes_controller()
|
||||
{
|
||||
$action = strip_request_item('action', 'list');
|
||||
|
||||
switch ($action) {
|
||||
switch ($action) {
|
||||
default:
|
||||
case 'list':
|
||||
return angeltypes_list_controller();
|
||||
|
@ -33,23 +35,25 @@ function angeltypes_controller() {
|
|||
*
|
||||
* @param AngelType $angeltype_id
|
||||
*/
|
||||
function angeltype_link($angeltype_id) {
|
||||
return page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id;
|
||||
function angeltype_link($angeltype_id)
|
||||
{
|
||||
return page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Job description for all angeltypes (public to everyone)
|
||||
*/
|
||||
function angeltypes_about_controller() {
|
||||
global $user;
|
||||
function angeltypes_about_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (isset($user)) {
|
||||
$angeltypes = AngelTypes_with_user($user);
|
||||
} else {
|
||||
$angeltypes = AngelTypes();
|
||||
}
|
||||
if (isset($user)) {
|
||||
$angeltypes = AngelTypes_with_user($user);
|
||||
} else {
|
||||
$angeltypes = AngelTypes();
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
_("Teams/Job description"),
|
||||
AngelTypes_about_view($angeltypes, isset($user))
|
||||
];
|
||||
|
@ -58,22 +62,23 @@ function angeltypes_about_controller() {
|
|||
/**
|
||||
* Delete an Angeltype.
|
||||
*/
|
||||
function angeltype_delete_controller() {
|
||||
global $privileges;
|
||||
function angeltype_delete_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('admin_angel_types', $privileges)) {
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (! in_array('admin_angel_types', $privileges)) {
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$angeltype = load_angeltype();
|
||||
$angeltype = load_angeltype();
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
AngelType_delete($angeltype);
|
||||
success(sprintf(_("Angeltype %s deleted."), AngelType_name_render($angeltype)));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
AngelType_delete($angeltype);
|
||||
success(sprintf(_("Angeltype %s deleted."), AngelType_name_render($angeltype)));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
sprintf(_("Delete angeltype %s"), $angeltype['name']),
|
||||
AngelType_delete_view($angeltype)
|
||||
];
|
||||
|
@ -82,62 +87,63 @@ function angeltype_delete_controller() {
|
|||
/**
|
||||
* Change an Angeltype.
|
||||
*/
|
||||
function angeltype_edit_controller() {
|
||||
global $privileges, $user;
|
||||
function angeltype_edit_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
// In supporter mode only allow to modify description
|
||||
$supporter_mode = ! in_array('admin_angel_types', $privileges);
|
||||
|
||||
if (isset($_REQUEST['angeltype_id'])) {
|
||||
// Edit existing angeltype
|
||||
if (isset($_REQUEST['angeltype_id'])) {
|
||||
// Edit existing angeltype
|
||||
$angeltype = load_angeltype();
|
||||
|
||||
if (! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
} else {
|
||||
// New angeltype
|
||||
if ($supporter_mode) {
|
||||
// Supporters aren't allowed to create new angeltypes.
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$angeltype = AngelType_new();
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (! $supporter_mode) {
|
||||
if (isset($_REQUEST['name'])) {
|
||||
$result = AngelType_validate_name($_REQUEST['name'], $angeltype);
|
||||
$angeltype['name'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please check the name. Maybe it already exists."));
|
||||
if (! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
}
|
||||
|
||||
$angeltype['restricted'] = isset($_REQUEST['restricted']);
|
||||
$angeltype['no_self_signup'] = isset($_REQUEST['no_self_signup']);
|
||||
|
||||
$angeltype['requires_driver_license'] = isset($_REQUEST['requires_driver_license']);
|
||||
} else {
|
||||
// New angeltype
|
||||
if ($supporter_mode) {
|
||||
// Supporters aren't allowed to create new angeltypes.
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$angeltype = AngelType_new();
|
||||
}
|
||||
|
||||
$angeltype['description'] = strip_request_item_nl('description', $angeltype['description']);
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if ($valid) {
|
||||
if ($angeltype['id'] != null) {
|
||||
AngelType_update($angeltype);
|
||||
} else {
|
||||
$angeltype = AngelType_create($angeltype);
|
||||
}
|
||||
if (! $supporter_mode) {
|
||||
if (isset($_REQUEST['name'])) {
|
||||
$result = AngelType_validate_name($_REQUEST['name'], $angeltype);
|
||||
$angeltype['name'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please check the name. Maybe it already exists."));
|
||||
}
|
||||
}
|
||||
|
||||
success("Angel type saved.");
|
||||
redirect(angeltype_link($angeltype['id']));
|
||||
$angeltype['restricted'] = isset($_REQUEST['restricted']);
|
||||
$angeltype['no_self_signup'] = isset($_REQUEST['no_self_signup']);
|
||||
|
||||
$angeltype['requires_driver_license'] = isset($_REQUEST['requires_driver_license']);
|
||||
}
|
||||
|
||||
$angeltype['description'] = strip_request_item_nl('description', $angeltype['description']);
|
||||
|
||||
if ($valid) {
|
||||
if ($angeltype['id'] != null) {
|
||||
AngelType_update($angeltype);
|
||||
} else {
|
||||
$angeltype = AngelType_create($angeltype);
|
||||
}
|
||||
|
||||
success("Angel type saved.");
|
||||
redirect(angeltype_link($angeltype['id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
sprintf(_("Edit %s"), $angeltype['name']),
|
||||
AngelType_edit_view($angeltype, $supporter_mode)
|
||||
];
|
||||
|
@ -146,19 +152,20 @@ function angeltype_edit_controller() {
|
|||
/**
|
||||
* View details of a given angeltype.
|
||||
*/
|
||||
function angeltype_controller() {
|
||||
global $privileges, $user;
|
||||
function angeltype_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
if (! in_array('angeltypes', $privileges)) {
|
||||
redirect('?');
|
||||
}
|
||||
if (! in_array('angeltypes', $privileges)) {
|
||||
redirect('?');
|
||||
}
|
||||
|
||||
$angeltype = load_angeltype();
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
$user_driver_license = UserDriverLicense($user['UID']);
|
||||
$members = Users_by_angeltype($angeltype);
|
||||
$angeltype = load_angeltype();
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
$user_driver_license = UserDriverLicense($user['UID']);
|
||||
$members = Users_by_angeltype($angeltype);
|
||||
|
||||
return [
|
||||
return [
|
||||
sprintf(_("Team %s"), $angeltype['name']),
|
||||
AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['supporter'], in_array('admin_angel_types', $privileges), $user_angeltype['supporter'], $user_driver_license, $user)
|
||||
];
|
||||
|
@ -167,41 +174,42 @@ function angeltype_controller() {
|
|||
/**
|
||||
* View a list of all angeltypes.
|
||||
*/
|
||||
function angeltypes_list_controller() {
|
||||
global $privileges, $user;
|
||||
function angeltypes_list_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
if (! in_array('angeltypes', $privileges)) {
|
||||
redirect('?');
|
||||
}
|
||||
if (! in_array('angeltypes', $privileges)) {
|
||||
redirect('?');
|
||||
}
|
||||
|
||||
$angeltypes = AngelTypes_with_user($user);
|
||||
$angeltypes = AngelTypes_with_user($user);
|
||||
|
||||
foreach ($angeltypes as &$angeltype) {
|
||||
$actions = [
|
||||
foreach ($angeltypes as &$angeltype) {
|
||||
$actions = [
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("view"), "btn-xs")
|
||||
];
|
||||
|
||||
if (in_array('admin_angel_types', $privileges)) {
|
||||
$actions[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), "btn-xs");
|
||||
$actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs");
|
||||
if (in_array('admin_angel_types', $privileges)) {
|
||||
$actions[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), "btn-xs");
|
||||
$actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs");
|
||||
}
|
||||
|
||||
$angeltype['membership'] = AngelType_render_membership($angeltype);
|
||||
if ($angeltype['user_angeltype_id'] != null) {
|
||||
$actions[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), "btn-xs");
|
||||
} else {
|
||||
$actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs");
|
||||
}
|
||||
|
||||
$angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : '';
|
||||
$angeltype['no_self_signup'] = $angeltype['no_self_signup'] ? '' : glyph('share');
|
||||
|
||||
$angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>';
|
||||
|
||||
$angeltype['actions'] = table_buttons($actions);
|
||||
}
|
||||
|
||||
$angeltype['membership'] = AngelType_render_membership($angeltype);
|
||||
if ($angeltype['user_angeltype_id'] != null) {
|
||||
$actions[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), "btn-xs");
|
||||
} else {
|
||||
$actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs");
|
||||
}
|
||||
|
||||
$angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : '';
|
||||
$angeltype['no_self_signup'] = $angeltype['no_self_signup'] ? '' : glyph('share');
|
||||
|
||||
$angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>';
|
||||
|
||||
$angeltype['actions'] = table_buttons($actions);
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
angeltypes_title(),
|
||||
AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges))
|
||||
];
|
||||
|
@ -210,17 +218,17 @@ function angeltypes_list_controller() {
|
|||
/**
|
||||
* Loads an angeltype from given angeltype_id request param.
|
||||
*/
|
||||
function load_angeltype() {
|
||||
if (! isset($_REQUEST['angeltype_id'])) {
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
function load_angeltype()
|
||||
{
|
||||
if (! isset($_REQUEST['angeltype_id'])) {
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$angeltype = AngelType($_REQUEST['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$angeltype = AngelType($_REQUEST['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
return $angeltype;
|
||||
return $angeltype;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,103 +1,103 @@
|
|||
<?php
|
||||
|
||||
function event_config_title() {
|
||||
return _("Event config");
|
||||
function event_config_title()
|
||||
{
|
||||
return _("Event config");
|
||||
}
|
||||
|
||||
function event_config_edit_controller() {
|
||||
global $privileges;
|
||||
function event_config_edit_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('admin_event_config', $privileges)) {
|
||||
redirect('?');
|
||||
}
|
||||
|
||||
$event_name = null;
|
||||
$event_welcome_msg = null;
|
||||
$buildup_start_date = null;
|
||||
$event_start_date = null;
|
||||
$event_end_date = null;
|
||||
$teardown_end_date = null;
|
||||
|
||||
$event_config = EventConfig();
|
||||
if ($event_config != null) {
|
||||
$event_name = $event_config['event_name'];
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
$event_start_date = $event_config['event_start_date'];
|
||||
$event_end_date = $event_config['event_end_date'];
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
$event_welcome_msg = $event_config['event_welcome_msg'];
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['event_name'])) {
|
||||
$event_name = strip_request_item('event_name');
|
||||
}
|
||||
if ($event_name == '') {
|
||||
$event_name = null;
|
||||
if (! in_array('admin_event_config', $privileges)) {
|
||||
redirect('?');
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['event_welcome_msg'])) {
|
||||
$event_welcome_msg = strip_request_item_nl('event_welcome_msg');
|
||||
}
|
||||
if ($event_welcome_msg == '') {
|
||||
$event_welcome_msg = null;
|
||||
$event_name = null;
|
||||
$event_welcome_msg = null;
|
||||
$buildup_start_date = null;
|
||||
$event_start_date = null;
|
||||
$event_end_date = null;
|
||||
$teardown_end_date = null;
|
||||
|
||||
$event_config = EventConfig();
|
||||
if ($event_config != null) {
|
||||
$event_name = $event_config['event_name'];
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
$event_start_date = $event_config['event_start_date'];
|
||||
$event_end_date = $event_config['event_end_date'];
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
$event_welcome_msg = $event_config['event_welcome_msg'];
|
||||
}
|
||||
|
||||
$result = check_request_date('buildup_start_date', _("Please enter buildup start date."), true);
|
||||
$buildup_start_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
$result = check_request_date('event_start_date', _("Please enter event start date."), true);
|
||||
$event_start_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
if (isset($_REQUEST['event_name'])) {
|
||||
$event_name = strip_request_item('event_name');
|
||||
}
|
||||
if ($event_name == '') {
|
||||
$event_name = null;
|
||||
}
|
||||
|
||||
$result = check_request_date('event_end_date', _("Please enter event end date."), true);
|
||||
$event_end_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
if (isset($_REQUEST['event_welcome_msg'])) {
|
||||
$event_welcome_msg = strip_request_item_nl('event_welcome_msg');
|
||||
}
|
||||
if ($event_welcome_msg == '') {
|
||||
$event_welcome_msg = null;
|
||||
}
|
||||
|
||||
$result = check_request_date('teardown_end_date', _("Please enter teardown end date."), true);
|
||||
$teardown_end_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
$result = check_request_date('buildup_start_date', _("Please enter buildup start date."), true);
|
||||
$buildup_start_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) {
|
||||
$valid = false;
|
||||
error(_("The buildup start date has to be before the event start date."));
|
||||
$result = check_request_date('event_start_date', _("Please enter event start date."), true);
|
||||
$event_start_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
$result = check_request_date('event_end_date', _("Please enter event end date."), true);
|
||||
$event_end_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
$result = check_request_date('teardown_end_date', _("Please enter teardown end date."), true);
|
||||
$teardown_end_date = $result->getValue();
|
||||
$valid &= $result->isValid();
|
||||
|
||||
if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) {
|
||||
$valid = false;
|
||||
error(_("The buildup start date has to be before the event start date."));
|
||||
}
|
||||
|
||||
if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) {
|
||||
$valid = false;
|
||||
error(_("The event start date has to be before the event end date."));
|
||||
}
|
||||
|
||||
if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) {
|
||||
$valid = false;
|
||||
error(_("The event end date has to be before the teardown end date."));
|
||||
}
|
||||
|
||||
if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) {
|
||||
$valid = false;
|
||||
error(_("The buildup start date has to be before the teardown end date."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg);
|
||||
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update event config.");
|
||||
}
|
||||
|
||||
engelsystem_log("Changed event config: $event_name, $event_welcome_msg, " . date("Y-m-d", $buildup_start_date) . ", " . date("Y-m-d", $event_start_date) . ", " . date("Y-m-d", $event_end_date) . ", " . date("Y-m-d", $teardown_end_date));
|
||||
success(_("Settings saved."));
|
||||
redirect(page_link_to('admin_event_config'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) {
|
||||
$valid = false;
|
||||
error(_("The event start date has to be before the event end date."));
|
||||
}
|
||||
|
||||
if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) {
|
||||
$valid = false;
|
||||
error(_("The event end date has to be before the teardown end date."));
|
||||
}
|
||||
|
||||
if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) {
|
||||
$valid = false;
|
||||
error(_("The buildup start date has to be before the teardown end date."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg);
|
||||
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update event config.");
|
||||
}
|
||||
|
||||
engelsystem_log("Changed event config: $event_name, $event_welcome_msg, " . date("Y-m-d", $buildup_start_date) . ", " . date("Y-m-d", $event_start_date) . ", " . date("Y-m-d", $event_end_date) . ", " . date("Y-m-d", $teardown_end_date));
|
||||
success(_("Settings saved."));
|
||||
redirect(page_link_to('admin_event_config'));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
event_config_title(),
|
||||
EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date)
|
||||
];
|
||||
}
|
||||
|
||||
?>
|
|
@ -10,42 +10,43 @@ use Engelsystem\ShiftCalendarRenderer;
|
|||
/**
|
||||
* View a room with its shifts.
|
||||
*/
|
||||
function room_controller() {
|
||||
global $privileges;
|
||||
function room_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('view_rooms', $privileges)) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
$room = load_room();
|
||||
$all_shifts = Shifts_by_room($room);
|
||||
$days = [];
|
||||
foreach ($all_shifts as $shift) {
|
||||
$day = date("Y-m-d", $shift['start']);
|
||||
if (! in_array($day, $days)) {
|
||||
$days[] = $day;
|
||||
if (! in_array('view_rooms', $privileges)) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
}
|
||||
|
||||
$shiftsFilter = new ShiftsFilter(true, [
|
||||
$room = load_room();
|
||||
$all_shifts = Shifts_by_room($room);
|
||||
$days = [];
|
||||
foreach ($all_shifts as $shift) {
|
||||
$day = date("Y-m-d", $shift['start']);
|
||||
if (! in_array($day, $days)) {
|
||||
$days[] = $day;
|
||||
}
|
||||
}
|
||||
|
||||
$shiftsFilter = new ShiftsFilter(true, [
|
||||
$room['RID']
|
||||
], AngelType_ids());
|
||||
$selected_day = date("Y-m-d");
|
||||
if (! empty($days)) {
|
||||
$selected_day = $days[0];
|
||||
}
|
||||
if (isset($_REQUEST['shifts_filter_day'])) {
|
||||
$selected_day = $_REQUEST['shifts_filter_day'];
|
||||
}
|
||||
$shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $selected_day . ' 00:00'));
|
||||
$shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $selected_day . ' 23:59'));
|
||||
$selected_day = date("Y-m-d");
|
||||
if (! empty($days)) {
|
||||
$selected_day = $days[0];
|
||||
}
|
||||
if (isset($_REQUEST['shifts_filter_day'])) {
|
||||
$selected_day = $_REQUEST['shifts_filter_day'];
|
||||
}
|
||||
$shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $selected_day . ' 00:00'));
|
||||
$shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $selected_day . ' 23:59'));
|
||||
|
||||
$shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
|
||||
$shiftsFilterRenderer->enableDaySelection($days);
|
||||
$shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
|
||||
$shiftsFilterRenderer->enableDaySelection($days);
|
||||
|
||||
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
|
||||
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
|
||||
|
||||
return [
|
||||
return [
|
||||
$room['Name'],
|
||||
Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer)
|
||||
];
|
||||
|
@ -54,12 +55,13 @@ function room_controller() {
|
|||
/**
|
||||
* Dispatch different room actions.
|
||||
*/
|
||||
function rooms_controller() {
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$_REQUEST['action'] = 'list';
|
||||
}
|
||||
function rooms_controller()
|
||||
{
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$_REQUEST['action'] = 'list';
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
switch ($_REQUEST['action']) {
|
||||
default:
|
||||
case 'list':
|
||||
redirect(page_link_to('admin_rooms'));
|
||||
|
@ -68,28 +70,29 @@ function rooms_controller() {
|
|||
}
|
||||
}
|
||||
|
||||
function room_link($room) {
|
||||
return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
|
||||
function room_link($room)
|
||||
{
|
||||
return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
|
||||
}
|
||||
|
||||
function room_edit_link($room) {
|
||||
return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
|
||||
function room_edit_link($room)
|
||||
{
|
||||
return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads room by request param room_id
|
||||
*/
|
||||
function load_room() {
|
||||
if (! test_request_int('room_id')) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
function load_room()
|
||||
{
|
||||
if (! test_request_int('room_id')) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
$room = Room($_REQUEST['room_id']);
|
||||
if ($room == null) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
$room = Room($_REQUEST['room_id']);
|
||||
if ($room == null) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
return $room;
|
||||
return $room;
|
||||
}
|
||||
|
||||
?>
|
|
@ -3,86 +3,86 @@
|
|||
/**
|
||||
* Sign up for a shift.
|
||||
*/
|
||||
function shift_entry_add_controller() {
|
||||
global $privileges, $user;
|
||||
function shift_entry_add_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) {
|
||||
$shift_id = $_REQUEST['shift_id'];
|
||||
} else {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) {
|
||||
$shift_id = $_REQUEST['shift_id'];
|
||||
} else {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
// Locations laden
|
||||
$rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
||||
$room_array = [];
|
||||
foreach ($rooms as $room) {
|
||||
$room_array[$room['RID']] = $room['Name'];
|
||||
}
|
||||
$room_array = [];
|
||||
foreach ($rooms as $room) {
|
||||
$room_array[$room['RID']] = $room['Name'];
|
||||
}
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
$shift['Name'] = $room_array[$shift['RID']];
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id'])) {
|
||||
$type_id = $_REQUEST['type_id'];
|
||||
} else {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
$type = AngelType($type_id);
|
||||
} else {
|
||||
$type = sql_select("SELECT * FROM `UserAngelTypes` JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`) WHERE `AngelTypes`.`id` = '" . sql_escape($type_id) . "' AND (`AngelTypes`.`restricted` = 0 OR (`UserAngelTypes`.`user_id` = '" . sql_escape($user['UID']) . "' AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL))");
|
||||
$type = $type[0];
|
||||
}
|
||||
|
||||
if ($type == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id']) && (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges))) {
|
||||
$user_id = $_REQUEST['user_id'];
|
||||
} else {
|
||||
$user_id = $user['UID'];
|
||||
}
|
||||
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']);
|
||||
|
||||
$shift_signup_allowed = Shift_signup_allowed(User($user_id), $shift, $type, null, null, $needed_angeltype, $shift_entries);
|
||||
if (! $shift_signup_allowed->isSignupAllowed()) {
|
||||
error(_("You are not allowed to sign up for this shift. Maybe shift is full or already running."));
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$selected_type_id = $type_id;
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
|
||||
if (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1") == 0) {
|
||||
$shift = Shift($shift_id);
|
||||
$shift['Name'] = $room_array[$shift['RID']];
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['angeltype_id']) && test_request_int('angeltype_id') && sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($_REQUEST['angeltype_id']) . "' LIMIT 1") > 0) {
|
||||
$selected_type_id = $_REQUEST['angeltype_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'")) {
|
||||
return error("This angel does already have an entry for this shift.", true);
|
||||
if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id'])) {
|
||||
$type_id = $_REQUEST['type_id'];
|
||||
} else {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$freeloaded = $shift['freeloaded'];
|
||||
$freeload_comment = $shift['freeload_comment'];
|
||||
if (in_array("user_shifts_admin", $privileges)) {
|
||||
$freeloaded = isset($_REQUEST['freeloaded']);
|
||||
$freeload_comment = strip_request_item_nl('freeload_comment');
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
$type = AngelType($type_id);
|
||||
} else {
|
||||
$type = sql_select("SELECT * FROM `UserAngelTypes` JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`) WHERE `AngelTypes`.`id` = '" . sql_escape($type_id) . "' AND (`AngelTypes`.`restricted` = 0 OR (`UserAngelTypes`.`user_id` = '" . sql_escape($user['UID']) . "' AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL))");
|
||||
$type = $type[0];
|
||||
}
|
||||
|
||||
$comment = strip_request_item_nl('comment');
|
||||
$result = ShiftEntry_create([
|
||||
if ($type == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id']) && (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges))) {
|
||||
$user_id = $_REQUEST['user_id'];
|
||||
} else {
|
||||
$user_id = $user['UID'];
|
||||
}
|
||||
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']);
|
||||
|
||||
$shift_signup_allowed = Shift_signup_allowed(User($user_id), $shift, $type, null, null, $needed_angeltype, $shift_entries);
|
||||
if (! $shift_signup_allowed->isSignupAllowed()) {
|
||||
error(_("You are not allowed to sign up for this shift. Maybe shift is full or already running."));
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$selected_type_id = $type_id;
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
if (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1") == 0) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['angeltype_id']) && test_request_int('angeltype_id') && sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($_REQUEST['angeltype_id']) . "' LIMIT 1") > 0) {
|
||||
$selected_type_id = $_REQUEST['angeltype_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'")) {
|
||||
return error("This angel does already have an entry for this shift.", true);
|
||||
}
|
||||
|
||||
$freeloaded = $shift['freeloaded'];
|
||||
$freeload_comment = $shift['freeload_comment'];
|
||||
if (in_array("user_shifts_admin", $privileges)) {
|
||||
$freeloaded = isset($_REQUEST['freeloaded']);
|
||||
$freeload_comment = strip_request_item_nl('freeload_comment');
|
||||
}
|
||||
|
||||
$comment = strip_request_item_nl('comment');
|
||||
$result = ShiftEntry_create([
|
||||
'SID' => $shift_id,
|
||||
'TID' => $selected_type_id,
|
||||
'UID' => $user_id,
|
||||
|
@ -90,72 +90,73 @@ function shift_entry_add_controller() {
|
|||
'freeloaded' => $freeloaded,
|
||||
'freeload_comment' => $freeload_comment
|
||||
]);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create shift entry.');
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create shift entry.');
|
||||
}
|
||||
|
||||
if ($type['restricted'] == 0 && sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "'") == 0) {
|
||||
sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')");
|
||||
}
|
||||
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " signed up for shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
|
||||
success(_("You are subscribed. Thank you!") . ' <a href="' . page_link_to('user_myshifts') . '">' . _("My shifts") . ' »</a>');
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
if ($type['restricted'] == 0 && sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "'") == 0) {
|
||||
sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')");
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$users = sql_select("SELECT *, (SELECT count(*) FROM `ShiftEntry` WHERE `freeloaded`=1 AND `ShiftEntry`.`UID`=`User`.`UID`) AS `freeloaded` FROM `User` ORDER BY `Nick`");
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? "" : " (" . _("Freeloader") . ")");
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
} elseif (in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
$users = Users_by_angeltype($type);
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
if (! $type['restricted'] || $usr['confirm_user_id'] != null) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'];
|
||||
}
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = User_angeltypes($user);
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
if ($angeltype['supporter']) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
}
|
||||
} else {
|
||||
$user_text = User_Nick_render($user);
|
||||
$angeltype_select = $type['name'];
|
||||
}
|
||||
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " signed up for shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
|
||||
success(_("You are subscribed. Thank you!") . ' <a href="' . page_link_to('user_myshifts') . '">' . _("My shifts") . ' »</a>');
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$users = sql_select("SELECT *, (SELECT count(*) FROM `ShiftEntry` WHERE `freeloaded`=1 AND `ShiftEntry`.`UID`=`User`.`UID`) AS `freeloaded` FROM `User` ORDER BY `Nick`");
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? "" : " (" . _("Freeloader") . ")");
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
} elseif (in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
$users = Users_by_angeltype($type);
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
if (! $type['restricted'] || $usr['confirm_user_id'] != null) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'];
|
||||
}
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = User_angeltypes($user);
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
if ($angeltype['supporter']) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
}
|
||||
} else {
|
||||
$user_text = User_Nick_render($user);
|
||||
$angeltype_select = $type['name'];
|
||||
}
|
||||
|
||||
return ShiftEntry_edit_view($user_text, date("Y-m-d H:i", $shift['start']) . ' – ' . date('Y-m-d H:i', $shift['end']) . ' (' . shift_length($shift) . ')', $shift['Name'], $shift['name'], $angeltype_select, "", false, null, in_array('user_shifts_admin', $privileges));
|
||||
return ShiftEntry_edit_view($user_text, date("Y-m-d H:i", $shift['start']) . ' – ' . date('Y-m-d H:i', $shift['end']) . ' (' . shift_length($shift) . ')', $shift['Name'], $shift['name'], $angeltype_select, "", false, null, in_array('user_shifts_admin', $privileges));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove somebody from a shift.
|
||||
*/
|
||||
function shift_entry_delete_controller() {
|
||||
global $privileges, $user;
|
||||
function shift_entry_delete_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
if (! isset($_REQUEST['entry_id']) || ! test_request_int('entry_id')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$entry_id = $_REQUEST['entry_id'];
|
||||
if (! isset($_REQUEST['entry_id']) || ! test_request_int('entry_id')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$entry_id = $_REQUEST['entry_id'];
|
||||
|
||||
$shift_entry_source = sql_select("
|
||||
$shift_entry_source = sql_select("
|
||||
SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type`, `AngelTypes`.`id` as `angeltype_id`
|
||||
FROM `ShiftEntry`
|
||||
JOIN `User` ON (`User`.`UID`=`ShiftEntry`.`UID`)
|
||||
|
@ -164,24 +165,22 @@ function shift_entry_delete_controller() {
|
|||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
|
||||
WHERE `ShiftEntry`.`id`='" . sql_escape($entry_id) . "'");
|
||||
if (count($shift_entry_source) > 0) {
|
||||
$shift_entry_source = $shift_entry_source[0];
|
||||
if (count($shift_entry_source) > 0) {
|
||||
$shift_entry_source = $shift_entry_source[0];
|
||||
|
||||
if (!in_array('user_shifts_admin', $privileges) && (!in_array('shiftentry_edit_angeltype_supporter', $privileges) || !User_is_AngelType_supporter($user, AngelType($shift_entry_source['angeltype_id'])))) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
if (!in_array('user_shifts_admin', $privileges) && (!in_array('shiftentry_edit_angeltype_supporter', $privileges) || !User_is_AngelType_supporter($user, AngelType($shift_entry_source['angeltype_id'])))) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$result = ShiftEntry_delete($entry_id);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift entry.');
|
||||
}
|
||||
|
||||
engelsystem_log("Deleted " . User_Nick_render($shift_entry_source) . "'s shift: " . $shift_entry_source['name'] . " at " . $shift_entry_source['Name'] . " from " . date("Y-m-d H:i", $shift_entry_source['start']) . " to " . date("Y-m-d H:i", $shift_entry_source['end']) . " as " . $shift_entry_source['angel_type']);
|
||||
success(_("Shift entry deleted."));
|
||||
} else {
|
||||
error(_("Entry not found."));
|
||||
}
|
||||
|
||||
$result = ShiftEntry_delete($entry_id);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift entry.');
|
||||
}
|
||||
|
||||
engelsystem_log("Deleted " . User_Nick_render($shift_entry_source) . "'s shift: " . $shift_entry_source['name'] . " at " . $shift_entry_source['Name'] . " from " . date("Y-m-d H:i", $shift_entry_source['start']) . " to " . date("Y-m-d H:i", $shift_entry_source['end']) . " as " . $shift_entry_source['angel_type']);
|
||||
success(_("Shift entry deleted."));
|
||||
} else {
|
||||
error(_("Entry not found."));
|
||||
}
|
||||
redirect(shift_link($shift_entry_source));
|
||||
redirect(shift_link($shift_entry_source));
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,136 +1,140 @@
|
|||
<?php
|
||||
use Engelsystem\ShiftSignupState;
|
||||
|
||||
function shift_link($shift) {
|
||||
return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID'];
|
||||
function shift_link($shift)
|
||||
{
|
||||
return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID'];
|
||||
}
|
||||
|
||||
function shift_delete_link($shift) {
|
||||
return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'];
|
||||
function shift_delete_link($shift)
|
||||
{
|
||||
return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'];
|
||||
}
|
||||
|
||||
function shift_edit_link($shift) {
|
||||
return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'];
|
||||
function shift_edit_link($shift)
|
||||
{
|
||||
return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a single shift.
|
||||
*/
|
||||
function shift_edit_controller() {
|
||||
global $privileges;
|
||||
function shift_edit_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
// Schicht bearbeiten
|
||||
$msg = "";
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
|
||||
if (! in_array('admin_shifts', $privileges)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['edit_shift']) || ! test_request_int('edit_shift')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shift_id = $_REQUEST['edit_shift'];
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
|
||||
$room = select_array(Rooms(), 'RID', 'Name');
|
||||
$angeltypes = select_array(AngelTypes(), 'id', 'name');
|
||||
$shifttypes = select_array(ShiftTypes(), 'id', 'name');
|
||||
|
||||
$needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'id', 'count');
|
||||
foreach (array_keys($angeltypes) as $angeltype_id) {
|
||||
if (! isset($needed_angel_types[$angeltype_id])) {
|
||||
$needed_angel_types[$angeltype_id] = 0;
|
||||
if (! in_array('admin_shifts', $privileges)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
}
|
||||
|
||||
$shifttype_id = $shift['shifttype_id'];
|
||||
$title = $shift['title'];
|
||||
$rid = $shift['RID'];
|
||||
$start = $shift['start'];
|
||||
$end = $shift['end'];
|
||||
if (! isset($_REQUEST['edit_shift']) || ! test_request_int('edit_shift')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shift_id = $_REQUEST['edit_shift'];
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
// Name/Bezeichnung der Schicht, darf leer sein
|
||||
$shift = Shift($shift_id);
|
||||
|
||||
$room = select_array(Rooms(), 'RID', 'Name');
|
||||
$angeltypes = select_array(AngelTypes(), 'id', 'name');
|
||||
$shifttypes = select_array(ShiftTypes(), 'id', 'name');
|
||||
|
||||
$needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'id', 'count');
|
||||
foreach (array_keys($angeltypes) as $angeltype_id) {
|
||||
if (! isset($needed_angel_types[$angeltype_id])) {
|
||||
$needed_angel_types[$angeltype_id] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$shifttype_id = $shift['shifttype_id'];
|
||||
$title = $shift['title'];
|
||||
$rid = $shift['RID'];
|
||||
$start = $shift['start'];
|
||||
$end = $shift['end'];
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
// Name/Bezeichnung der Schicht, darf leer sein
|
||||
$title = strip_request_item('title');
|
||||
|
||||
// Auswahl der sichtbaren Locations für die Schichten
|
||||
if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room[$_REQUEST['rid']])) {
|
||||
$rid = $_REQUEST['rid'];
|
||||
$rid = $_REQUEST['rid'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please select a room."), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please select a shifttype.'), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
|
||||
$start = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a valid starting time for the shifts."), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
|
||||
$end = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a valid ending time for the shifts."), true);
|
||||
}
|
||||
|
||||
if ($start >= $end) {
|
||||
$valid = false;
|
||||
$msg .= error(_("The ending time has to be after the starting time."), true);
|
||||
}
|
||||
|
||||
foreach ($needed_angel_types as $needed_angeltype_id => $needed_angeltype_name) {
|
||||
if (isset($_REQUEST['type_' . $needed_angeltype_id]) && test_request_int('type_' . $needed_angeltype_id)) {
|
||||
$needed_angel_types[$needed_angeltype_id] = trim($_REQUEST['type_' . $needed_angeltype_id]);
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Please check your input for needed angels of type %s."), $needed_angeltype_name), true);
|
||||
}
|
||||
$msg .= error(_("Please select a room."), true);
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$shift['shifttype_id'] = $shifttype_id;
|
||||
$shift['title'] = $title;
|
||||
$shift['RID'] = $rid;
|
||||
$shift['start'] = $start;
|
||||
$shift['end'] = $end;
|
||||
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_('Please select a shifttype.'), true);
|
||||
}
|
||||
|
||||
$result = Shift_update($shift);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shift.');
|
||||
}
|
||||
NeededAngelTypes_delete_by_shift($shift_id);
|
||||
$needed_angel_types_info = [];
|
||||
foreach ($needed_angel_types as $type_id => $count) {
|
||||
NeededAngelType_add($shift_id, $type_id, null, $count);
|
||||
$needed_angel_types_info[] = $angeltypes[$type_id] . ": " . $count;
|
||||
}
|
||||
if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
|
||||
$start = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a valid starting time for the shifts."), true);
|
||||
}
|
||||
|
||||
engelsystem_log("Updated shift '" . $shifttypes[$shifttype_id] . ", " . $title . "' from " . date("Y-m-d H:i", $start) . " to " . date("Y-m-d H:i", $end) . " with angel types " . join(", ", $needed_angel_types_info));
|
||||
success(_("Shift updated."));
|
||||
if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
|
||||
$end = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a valid ending time for the shifts."), true);
|
||||
}
|
||||
|
||||
redirect(shift_link([
|
||||
if ($start >= $end) {
|
||||
$valid = false;
|
||||
$msg .= error(_("The ending time has to be after the starting time."), true);
|
||||
}
|
||||
|
||||
foreach ($needed_angel_types as $needed_angeltype_id => $needed_angeltype_name) {
|
||||
if (isset($_REQUEST['type_' . $needed_angeltype_id]) && test_request_int('type_' . $needed_angeltype_id)) {
|
||||
$needed_angel_types[$needed_angeltype_id] = trim($_REQUEST['type_' . $needed_angeltype_id]);
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Please check your input for needed angels of type %s."), $needed_angeltype_name), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$shift['shifttype_id'] = $shifttype_id;
|
||||
$shift['title'] = $title;
|
||||
$shift['RID'] = $rid;
|
||||
$shift['start'] = $start;
|
||||
$shift['end'] = $end;
|
||||
|
||||
$result = Shift_update($shift);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shift.');
|
||||
}
|
||||
NeededAngelTypes_delete_by_shift($shift_id);
|
||||
$needed_angel_types_info = [];
|
||||
foreach ($needed_angel_types as $type_id => $count) {
|
||||
NeededAngelType_add($shift_id, $type_id, null, $count);
|
||||
$needed_angel_types_info[] = $angeltypes[$type_id] . ": " . $count;
|
||||
}
|
||||
|
||||
engelsystem_log("Updated shift '" . $shifttypes[$shifttype_id] . ", " . $title . "' from " . date("Y-m-d H:i", $start) . " to " . date("Y-m-d H:i", $end) . " with angel types " . join(", ", $needed_angel_types_info));
|
||||
success(_("Shift updated."));
|
||||
|
||||
redirect(shift_link([
|
||||
'SID' => $shift_id
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$angel_types_spinner = "";
|
||||
foreach ($angeltypes as $angeltype_id => $angeltype_name) {
|
||||
$angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name, $needed_angel_types[$angeltype_id]);
|
||||
}
|
||||
$angel_types_spinner = "";
|
||||
foreach ($angeltypes as $angeltype_id => $angeltype_name) {
|
||||
$angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name, $needed_angel_types[$angeltype_id]);
|
||||
}
|
||||
|
||||
return page_with_title(shifts_title(), [
|
||||
return page_with_title(shifts_title(), [
|
||||
msg(),
|
||||
'<noscript>' . info(_("This page is much more comfortable with javascript."), true) . '</noscript>',
|
||||
form([
|
||||
|
@ -146,87 +150,90 @@ function shift_edit_controller() {
|
|||
]);
|
||||
}
|
||||
|
||||
function shift_delete_controller() {
|
||||
global $privileges;
|
||||
function shift_delete_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('user_shifts_admin', $privileges)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
if (! in_array('user_shifts_admin', $privileges)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
// Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
|
||||
if (! isset($_REQUEST['delete_shift']) || ! preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shift_id = $_REQUEST['delete_shift'];
|
||||
$shift_id = $_REQUEST['delete_shift'];
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shift = Shift($shift_id);
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
// Schicht löschen bestätigt
|
||||
if (isset($_REQUEST['delete'])) {
|
||||
Shift_delete($shift_id);
|
||||
Shift_delete($shift_id);
|
||||
|
||||
engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
|
||||
success(_("Shift deleted."));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
|
||||
success(_("Shift deleted."));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
return page_with_title(shifts_title(), [
|
||||
return page_with_title(shifts_title(), [
|
||||
error(sprintf(_("Do you want to delete the shift %s from %s to %s?"), $shift['name'], date("Y-m-d H:i", $shift['start']), date("H:i", $shift['end'])), true),
|
||||
'<a class="button" href="?p=user_shifts&delete_shift=' . $shift_id . '&delete">' . _("delete") . '</a>'
|
||||
]);
|
||||
}
|
||||
|
||||
function shift_controller() {
|
||||
global $user, $privileges;
|
||||
function shift_controller()
|
||||
{
|
||||
global $user, $privileges;
|
||||
|
||||
if (! in_array('user_shifts', $privileges)) {
|
||||
redirect(page_link_to('?'));
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['shift_id'])) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$shift = Shift($_REQUEST['shift_id']);
|
||||
if ($shift == null) {
|
||||
error(_("Shift could not be found."));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$shifttype = ShiftType($shift['shifttype_id']);
|
||||
$room = Room($shift['RID']);
|
||||
$angeltypes = AngelTypes();
|
||||
$user_shifts = Shifts_by_user($user);
|
||||
|
||||
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
|
||||
foreach ($angeltypes as &$angeltype) {
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
|
||||
|
||||
$angeltype_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, $user_shifts, $needed_angeltype, $shift_entries);
|
||||
if ($shift_signup_state == null) {
|
||||
$shift_signup_state = $angeltype_signup_state;
|
||||
} else {
|
||||
$shift_signup_state->combineWith($angeltype_signup_state);
|
||||
if (! in_array('user_shifts', $privileges)) {
|
||||
redirect(page_link_to('?'));
|
||||
}
|
||||
$angeltype['shift_signup_state'] = $angeltype_signup_state;
|
||||
}
|
||||
|
||||
return [
|
||||
if (! isset($_REQUEST['shift_id'])) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$shift = Shift($_REQUEST['shift_id']);
|
||||
if ($shift == null) {
|
||||
error(_("Shift could not be found."));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
$shifttype = ShiftType($shift['shifttype_id']);
|
||||
$room = Room($shift['RID']);
|
||||
$angeltypes = AngelTypes();
|
||||
$user_shifts = Shifts_by_user($user);
|
||||
|
||||
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
|
||||
foreach ($angeltypes as &$angeltype) {
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
|
||||
|
||||
$angeltype_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, $user_shifts, $needed_angeltype, $shift_entries);
|
||||
if ($shift_signup_state == null) {
|
||||
$shift_signup_state = $angeltype_signup_state;
|
||||
} else {
|
||||
$shift_signup_state->combineWith($angeltype_signup_state);
|
||||
}
|
||||
$angeltype['shift_signup_state'] = $angeltype_signup_state;
|
||||
}
|
||||
|
||||
return [
|
||||
$shift['name'],
|
||||
Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state)
|
||||
];
|
||||
}
|
||||
|
||||
function shifts_controller() {
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
function shifts_controller()
|
||||
{
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
switch ($_REQUEST['action']) {
|
||||
default:
|
||||
redirect(page_link_to('?'));
|
||||
case 'view':
|
||||
|
@ -239,86 +246,88 @@ function shifts_controller() {
|
|||
/**
|
||||
* Redirects the user to his next shift.
|
||||
*/
|
||||
function shift_next_controller() {
|
||||
global $user, $privileges;
|
||||
function shift_next_controller()
|
||||
{
|
||||
global $user, $privileges;
|
||||
|
||||
if (! in_array('user_shifts', $privileges)) {
|
||||
redirect(page_link_to('?'));
|
||||
}
|
||||
if (! in_array('user_shifts', $privileges)) {
|
||||
redirect(page_link_to('?'));
|
||||
}
|
||||
|
||||
$upcoming_shifts = ShiftEntries_upcoming_for_user($user);
|
||||
if ($upcoming_shifts === false) {
|
||||
return false;
|
||||
}
|
||||
$upcoming_shifts = ShiftEntries_upcoming_for_user($user);
|
||||
if ($upcoming_shifts === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($upcoming_shifts) > 0) {
|
||||
redirect(shift_link($upcoming_shifts[0]));
|
||||
}
|
||||
if (count($upcoming_shifts) > 0) {
|
||||
redirect(shift_link($upcoming_shifts[0]));
|
||||
}
|
||||
|
||||
redirect(page_link_to('user_shifts'));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Export all shifts using api-key.
|
||||
*/
|
||||
function shifts_json_export_all_controller() {
|
||||
global $api_key;
|
||||
function shifts_json_export_all_controller()
|
||||
{
|
||||
global $api_key;
|
||||
|
||||
if ($api_key == "") {
|
||||
engelsystem_error("Config contains empty apikey.");
|
||||
}
|
||||
if ($api_key == "") {
|
||||
engelsystem_error("Config contains empty apikey.");
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['api_key'])) {
|
||||
engelsystem_error("Missing parameter api_key.");
|
||||
}
|
||||
if (! isset($_REQUEST['api_key'])) {
|
||||
engelsystem_error("Missing parameter api_key.");
|
||||
}
|
||||
|
||||
if ($_REQUEST['api_key'] != $api_key) {
|
||||
engelsystem_error("Invalid api_key.");
|
||||
}
|
||||
if ($_REQUEST['api_key'] != $api_key) {
|
||||
engelsystem_error("Invalid api_key.");
|
||||
}
|
||||
|
||||
$shifts_source = Shifts();
|
||||
if ($shifts_source === false) {
|
||||
engelsystem_error("Unable to load shifts.");
|
||||
}
|
||||
$shifts_source = Shifts();
|
||||
if ($shifts_source === false) {
|
||||
engelsystem_error("Unable to load shifts.");
|
||||
}
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
raw_output(json_encode($shifts_source));
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
raw_output(json_encode($shifts_source));
|
||||
}
|
||||
|
||||
/**
|
||||
* Export filtered shifts via JSON.
|
||||
* (Like iCal Export or shifts view)
|
||||
*/
|
||||
function shifts_json_export_controller() {
|
||||
global $user;
|
||||
function shifts_json_export_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
engelsystem_error("Missing key.");
|
||||
}
|
||||
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
engelsystem_error("Missing key.");
|
||||
}
|
||||
|
||||
$key = $_REQUEST['key'];
|
||||
$key = $_REQUEST['key'];
|
||||
|
||||
$user = User_by_api_key($key);
|
||||
if ($user == null) {
|
||||
engelsystem_error("Key invalid.");
|
||||
}
|
||||
if (! in_array('shifts_json_export', privileges_for_user($user['UID']))) {
|
||||
engelsystem_error("No privilege for shifts_json_export.");
|
||||
}
|
||||
$user = User_by_api_key($key);
|
||||
if ($user == null) {
|
||||
engelsystem_error("Key invalid.");
|
||||
}
|
||||
if (! in_array('shifts_json_export', privileges_for_user($user['UID']))) {
|
||||
engelsystem_error("No privilege for shifts_json_export.");
|
||||
}
|
||||
|
||||
$shifts = load_ical_shifts();
|
||||
$shifts = load_ical_shifts();
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
raw_output(json_encode($shifts));
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
raw_output(json_encode($shifts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns users shifts to export.
|
||||
*/
|
||||
function load_ical_shifts() {
|
||||
global $user;
|
||||
function load_ical_shifts()
|
||||
{
|
||||
global $user;
|
||||
|
||||
return Shifts_by_user($user);
|
||||
return Shifts_by_user($user);
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,38 +1,40 @@
|
|||
<?php
|
||||
|
||||
function shifttype_link($shifttype) {
|
||||
return page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id'];
|
||||
function shifttype_link($shifttype)
|
||||
{
|
||||
return page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a shifttype.
|
||||
*/
|
||||
function shifttype_delete_controller() {
|
||||
if (! isset($_REQUEST['shifttype_id'])) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
|
||||
if ($shifttype == null) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$result = ShiftType_delete($shifttype['id']);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shifttype.');
|
||||
function shifttype_delete_controller()
|
||||
{
|
||||
if (! isset($_REQUEST['shifttype_id'])) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
engelsystem_log('Deleted shifttype ' . $shifttype['name']);
|
||||
success(sprintf(_('Shifttype %s deleted.'), $shifttype['name']));
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
|
||||
return [
|
||||
if ($shifttype == null) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$result = ShiftType_delete($shifttype['id']);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shifttype.');
|
||||
}
|
||||
|
||||
engelsystem_log('Deleted shifttype ' . $shifttype['name']);
|
||||
success(sprintf(_('Shifttype %s deleted.'), $shifttype['name']));
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_("Delete shifttype %s"), $shifttype['name']),
|
||||
ShiftType_delete_view($shifttype)
|
||||
];
|
||||
|
@ -41,93 +43,95 @@ function shifttype_delete_controller() {
|
|||
/**
|
||||
* Edit or create shift type.
|
||||
*/
|
||||
function shifttype_edit_controller() {
|
||||
$shifttype_id = null;
|
||||
$name = "";
|
||||
$angeltype_id = null;
|
||||
$description = "";
|
||||
function shifttype_edit_controller()
|
||||
{
|
||||
$shifttype_id = null;
|
||||
$name = "";
|
||||
$angeltype_id = null;
|
||||
$description = "";
|
||||
|
||||
$angeltypes = AngelTypes();
|
||||
$angeltypes = AngelTypes();
|
||||
|
||||
if (isset($_REQUEST['shifttype_id'])) {
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
error(_('Shifttype not found.'));
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
$shifttype_id = $shifttype['id'];
|
||||
$name = $shifttype['name'];
|
||||
$angeltype_id = $shifttype['angeltype_id'];
|
||||
$description = $shifttype['description'];
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
|
||||
$name = strip_request_item('name');
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter a name.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id'])) {
|
||||
$angeltype_id = $_REQUEST['angeltype_id'];
|
||||
} else {
|
||||
$angeltype_id = null;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['description'])) {
|
||||
$description = strip_request_item_nl('description');
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
if ($shifttype_id) {
|
||||
$result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shifttype.');
|
||||
if (isset($_REQUEST['shifttype_id'])) {
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
engelsystem_log('Updated shifttype ' . $name);
|
||||
success(_('Updated shifttype.'));
|
||||
} else {
|
||||
$shifttype_id = ShiftType_create($name, $angeltype_id, $description);
|
||||
if ($shifttype_id === false) {
|
||||
engelsystem_error('Unable to create shifttype.');
|
||||
if ($shifttype == null) {
|
||||
error(_('Shifttype not found.'));
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
engelsystem_log('Created shifttype ' . $name);
|
||||
success(_('Created shifttype.'));
|
||||
}
|
||||
redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id);
|
||||
$shifttype_id = $shifttype['id'];
|
||||
$name = $shifttype['name'];
|
||||
$angeltype_id = $shifttype['angeltype_id'];
|
||||
$description = $shifttype['description'];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
|
||||
$name = strip_request_item('name');
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter a name.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id'])) {
|
||||
$angeltype_id = $_REQUEST['angeltype_id'];
|
||||
} else {
|
||||
$angeltype_id = null;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['description'])) {
|
||||
$description = strip_request_item_nl('description');
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
if ($shifttype_id) {
|
||||
$result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shifttype.');
|
||||
}
|
||||
engelsystem_log('Updated shifttype ' . $name);
|
||||
success(_('Updated shifttype.'));
|
||||
} else {
|
||||
$shifttype_id = ShiftType_create($name, $angeltype_id, $description);
|
||||
if ($shifttype_id === false) {
|
||||
engelsystem_error('Unable to create shifttype.');
|
||||
}
|
||||
engelsystem_log('Created shifttype ' . $name);
|
||||
success(_('Created shifttype.'));
|
||||
}
|
||||
redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
shifttypes_title(),
|
||||
ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
|
||||
];
|
||||
}
|
||||
|
||||
function shifttype_controller() {
|
||||
if (! isset($_REQUEST['shifttype_id'])) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
function shifttype_controller()
|
||||
{
|
||||
if (! isset($_REQUEST['shifttype_id'])) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shifttype.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
$angeltype = null;
|
||||
if ($shifttype['angeltype_id'] != null) {
|
||||
$angeltype = AngelType($shifttype['angeltype_id']);
|
||||
}
|
||||
$angeltype = null;
|
||||
if ($shifttype['angeltype_id'] != null) {
|
||||
$angeltype = AngelType($shifttype['angeltype_id']);
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
$shifttype['name'],
|
||||
ShiftType_view($shifttype, $angeltype)
|
||||
];
|
||||
|
@ -136,13 +140,14 @@ function shifttype_controller() {
|
|||
/**
|
||||
* List all shift types.
|
||||
*/
|
||||
function shifttypes_list_controller() {
|
||||
$shifttypes = ShiftTypes();
|
||||
if ($shifttypes === false) {
|
||||
engelsystem_error("Unable to load shifttypes.");
|
||||
}
|
||||
function shifttypes_list_controller()
|
||||
{
|
||||
$shifttypes = ShiftTypes();
|
||||
if ($shifttypes === false) {
|
||||
engelsystem_error("Unable to load shifttypes.");
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
shifttypes_title(),
|
||||
ShiftTypes_list_view($shifttypes)
|
||||
];
|
||||
|
@ -151,19 +156,21 @@ function shifttypes_list_controller() {
|
|||
/**
|
||||
* Text for shift type related links.
|
||||
*/
|
||||
function shifttypes_title() {
|
||||
return _("Shifttypes");
|
||||
function shifttypes_title()
|
||||
{
|
||||
return _("Shifttypes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Route shift type actions
|
||||
*/
|
||||
function shifttypes_controller() {
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$_REQUEST['action'] = 'list';
|
||||
}
|
||||
function shifttypes_controller()
|
||||
{
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$_REQUEST['action'] = 'list';
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
switch ($_REQUEST['action']) {
|
||||
default:
|
||||
case 'list':
|
||||
return shifttypes_list_controller();
|
||||
|
@ -175,5 +182,3 @@ function shifttypes_controller() {
|
|||
return shifttype_delete_controller();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -3,53 +3,55 @@
|
|||
/**
|
||||
* Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype.
|
||||
*/
|
||||
function user_angeltypes_unconfirmed_hint() {
|
||||
global $user;
|
||||
function user_angeltypes_unconfirmed_hint()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user);
|
||||
if (count($unconfirmed_user_angeltypes) == 0) {
|
||||
return null;
|
||||
}
|
||||
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user);
|
||||
if (count($unconfirmed_user_angeltypes) == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$unconfirmed_links = [];
|
||||
foreach ($unconfirmed_user_angeltypes as $user_angeltype) {
|
||||
$unconfirmed_links[] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $user_angeltype['angeltype_id'] . '">' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . '</a>';
|
||||
}
|
||||
$unconfirmed_links = [];
|
||||
foreach ($unconfirmed_user_angeltypes as $user_angeltype) {
|
||||
$unconfirmed_links[] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $user_angeltype['angeltype_id'] . '">' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . '</a>';
|
||||
}
|
||||
|
||||
return sprintf(ngettext("There is %d unconfirmed angeltype.", "There are %d unconfirmed angeltypes.", count($unconfirmed_user_angeltypes)), count($unconfirmed_user_angeltypes)) . " " . _('Angel types which need approvals:') . ' ' . join(', ', $unconfirmed_links);
|
||||
return sprintf(ngettext("There is %d unconfirmed angeltype.", "There are %d unconfirmed angeltypes.", count($unconfirmed_user_angeltypes)), count($unconfirmed_user_angeltypes)) . " " . _('Angel types which need approvals:') . ' ' . join(', ', $unconfirmed_links);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all unconfirmed users from a specific angeltype.
|
||||
*/
|
||||
function user_angeltypes_delete_all_controller() {
|
||||
global $user;
|
||||
function user_angeltypes_delete_all_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['angeltype_id'])) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (! isset($_REQUEST['angeltype_id'])) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$angeltype = AngelType($_REQUEST['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$angeltype = AngelType($_REQUEST['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
error(_("You are not allowed to delete all users for this angeltype."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
error(_("You are not allowed to delete all users for this angeltype."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
UserAngelTypes_delete_all($angeltype['id']);
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
UserAngelTypes_delete_all($angeltype['id']);
|
||||
|
||||
engelsystem_log(sprintf("Denied all users for angeltype %s", AngelType_name_render($angeltype)));
|
||||
success(sprintf(_("Denied all users for angeltype %s."), AngelType_name_render($angeltype)));
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
engelsystem_log(sprintf("Denied all users for angeltype %s", AngelType_name_render($angeltype)));
|
||||
success(sprintf(_("Denied all users for angeltype %s."), AngelType_name_render($angeltype)));
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
_("Deny all users"),
|
||||
UserAngelTypes_delete_all_view($angeltype)
|
||||
];
|
||||
|
@ -58,40 +60,41 @@ function user_angeltypes_delete_all_controller() {
|
|||
/**
|
||||
* Confirm all unconfirmed users for an angeltype.
|
||||
*/
|
||||
function user_angeltypes_confirm_all_controller() {
|
||||
global $user, $privileges;
|
||||
function user_angeltypes_confirm_all_controller()
|
||||
{
|
||||
global $user, $privileges;
|
||||
|
||||
if (! isset($_REQUEST['angeltype_id'])) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (! isset($_REQUEST['angeltype_id'])) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$angeltype = AngelType($_REQUEST['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$angeltype = AngelType($_REQUEST['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
if ($user_angeltype == null) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
if ($user_angeltype == null) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (! in_array('admin_user_angeltypes', $privileges) && ! $user_angeltype['supporter']) {
|
||||
error(_("You are not allowed to confirm all users for this angeltype."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (! in_array('admin_user_angeltypes', $privileges) && ! $user_angeltype['supporter']) {
|
||||
error(_("You are not allowed to confirm all users for this angeltype."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
UserAngelTypes_confirm_all($angeltype['id'], $user);
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
UserAngelTypes_confirm_all($angeltype['id'], $user);
|
||||
|
||||
engelsystem_log(sprintf("Confirmed all users for angeltype %s", AngelType_name_render($angeltype)));
|
||||
success(sprintf(_("Confirmed all users for angeltype %s."), AngelType_name_render($angeltype)));
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
engelsystem_log(sprintf("Confirmed all users for angeltype %s", AngelType_name_render($angeltype)));
|
||||
success(sprintf(_("Confirmed all users for angeltype %s."), AngelType_name_render($angeltype)));
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
_("Confirm all users"),
|
||||
UserAngelTypes_confirm_all_view($angeltype)
|
||||
];
|
||||
|
@ -100,49 +103,50 @@ function user_angeltypes_confirm_all_controller() {
|
|||
/**
|
||||
* Confirm an user for an angeltype.
|
||||
*/
|
||||
function user_angeltype_confirm_controller() {
|
||||
global $user;
|
||||
function user_angeltype_confirm_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['user_angeltype_id'])) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
|
||||
if ($user_angeltype == null) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$angeltype = AngelType($user_angeltype['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
error(_("You are not allowed to confirm this users angeltype."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$user_source = User($user_angeltype['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$result = UserAngelType_confirm($user_angeltype['id'], $user);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to confirm user angeltype.");
|
||||
if (! isset($_REQUEST['user_angeltype_id'])) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
engelsystem_log(sprintf("%s confirmed for angeltype %s", User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
||||
success(sprintf(_("%s confirmed for angeltype %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
|
||||
if ($user_angeltype == null) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
return [
|
||||
$angeltype = AngelType($user_angeltype['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
error(_("You are not allowed to confirm this users angeltype."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$user_source = User($user_angeltype['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$result = UserAngelType_confirm($user_angeltype['id'], $user);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to confirm user angeltype.");
|
||||
}
|
||||
|
||||
engelsystem_log(sprintf("%s confirmed for angeltype %s", User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
||||
success(sprintf(_("%s confirmed for angeltype %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
|
||||
return [
|
||||
_("Confirm angeltype for user"),
|
||||
UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype)
|
||||
];
|
||||
|
@ -151,51 +155,52 @@ function user_angeltype_confirm_controller() {
|
|||
/**
|
||||
* Remove a user from an Angeltype.
|
||||
*/
|
||||
function user_angeltype_delete_controller() {
|
||||
global $user;
|
||||
function user_angeltype_delete_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['user_angeltype_id'])) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
|
||||
if ($user_angeltype == null) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$angeltype = AngelType($user_angeltype['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$user_source = User($user_angeltype['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
error(_("You are not allowed to delete this users angeltype."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$result = UserAngelType_delete($user_angeltype);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to delete user angeltype.");
|
||||
if (! isset($_REQUEST['user_angeltype_id'])) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$success_message = sprintf(_("User %s removed from %s."), User_Nick_render($user_source), $angeltype['name']);
|
||||
engelsystem_log($success_message);
|
||||
success($success_message);
|
||||
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
|
||||
if ($user_angeltype == null) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
$angeltype = AngelType($user_angeltype['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
return [
|
||||
$user_source = User($user_angeltype['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
error(_("You are not allowed to delete this users angeltype."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$result = UserAngelType_delete($user_angeltype);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to delete user angeltype.");
|
||||
}
|
||||
|
||||
$success_message = sprintf(_("User %s removed from %s."), User_Nick_render($user_source), $angeltype['name']);
|
||||
engelsystem_log($success_message);
|
||||
success($success_message);
|
||||
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
|
||||
return [
|
||||
_("Remove angeltype"),
|
||||
UserAngelType_delete_view($user_angeltype, $user_source, $angeltype)
|
||||
];
|
||||
|
@ -204,55 +209,56 @@ function user_angeltype_delete_controller() {
|
|||
/**
|
||||
* Update an UserAngelType.
|
||||
*/
|
||||
function user_angeltype_update_controller() {
|
||||
global $privileges;
|
||||
function user_angeltype_update_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('admin_angel_types', $privileges)) {
|
||||
error(_("You are not allowed to set supporter rights."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (! in_array('admin_angel_types', $privileges)) {
|
||||
error(_("You are not allowed to set supporter rights."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['user_angeltype_id'])) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (! isset($_REQUEST['user_angeltype_id'])) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['supporter']) && preg_match("/^[01]$/", $_REQUEST['supporter'])) {
|
||||
$supporter = $_REQUEST['supporter'] == "1";
|
||||
} else {
|
||||
error(_("No supporter update given."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
if (isset($_REQUEST['supporter']) && preg_match("/^[01]$/", $_REQUEST['supporter'])) {
|
||||
$supporter = $_REQUEST['supporter'] == "1";
|
||||
} else {
|
||||
error(_("No supporter update given."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
|
||||
if ($user_angeltype == null) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
|
||||
if ($user_angeltype == null) {
|
||||
error(_("User angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$angeltype = AngelType($user_angeltype['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$angeltype = AngelType($user_angeltype['angeltype_id']);
|
||||
if ($angeltype == null) {
|
||||
error(_("Angeltype doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
$user_source = User($user_angeltype['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
$user_source = User($user_angeltype['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
UserAngelType_update($user_angeltype['id'], $supporter);
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
UserAngelType_update($user_angeltype['id'], $supporter);
|
||||
|
||||
$success_message = sprintf($supporter ? _("Added supporter rights for %s to %s.") : _("Removed supporter rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source));
|
||||
engelsystem_log($success_message);
|
||||
success($success_message);
|
||||
$success_message = sprintf($supporter ? _("Added supporter rights for %s to %s.") : _("Removed supporter rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source));
|
||||
engelsystem_log($success_message);
|
||||
success($success_message);
|
||||
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
$supporter ? _("Add supporter rights") : _("Remove supporter rights"),
|
||||
UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter)
|
||||
];
|
||||
|
@ -261,14 +267,15 @@ function user_angeltype_update_controller() {
|
|||
/**
|
||||
* User joining an Angeltype (Or supporter doing this for him).
|
||||
*/
|
||||
function user_angeltype_add_controller() {
|
||||
global $user;
|
||||
function user_angeltype_add_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$angeltype = load_angeltype();
|
||||
$angeltype = load_angeltype();
|
||||
|
||||
// User is joining by itself
|
||||
if (! User_is_AngelType_supporter($user, $angeltype)) {
|
||||
return user_angeltype_join_controller($angeltype);
|
||||
return user_angeltype_join_controller($angeltype);
|
||||
}
|
||||
|
||||
// Allow to add any user
|
||||
|
@ -279,23 +286,23 @@ function user_angeltype_add_controller() {
|
|||
// Load possible users, that are not in the angeltype already
|
||||
$users_source = Users_by_angeltype_inverted($angeltype);
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$user_source = load_user();
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$user_source = load_user();
|
||||
|
||||
if (! UserAngelType_exists($user_source, $angeltype)) {
|
||||
$user_angeltype_id = UserAngelType_create($user_source, $angeltype);
|
||||
if (! UserAngelType_exists($user_source, $angeltype)) {
|
||||
$user_angeltype_id = UserAngelType_create($user_source, $angeltype);
|
||||
|
||||
engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
||||
success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
||||
engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
||||
success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
||||
|
||||
UserAngelType_confirm($user_angeltype_id, $user_source);
|
||||
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
|
||||
UserAngelType_confirm($user_angeltype_id, $user_source);
|
||||
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
|
||||
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
_("Add user to angeltype"),
|
||||
UserAngelType_add_view($angeltype, $users_source, $user_source['UID'])
|
||||
];
|
||||
|
@ -304,31 +311,32 @@ function user_angeltype_add_controller() {
|
|||
/**
|
||||
* A user joins an angeltype.
|
||||
*/
|
||||
function user_angeltype_join_controller($angeltype) {
|
||||
global $user, $privileges;
|
||||
function user_angeltype_join_controller($angeltype)
|
||||
{
|
||||
global $user, $privileges;
|
||||
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
if ($user_angeltype != null) {
|
||||
error(sprintf(_("You are already a %s."), $angeltype['name']));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$user_angeltype_id = UserAngelType_create($user, $angeltype);
|
||||
|
||||
$success_message = sprintf(_("You joined %s."), $angeltype['name']);
|
||||
engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
|
||||
success($success_message);
|
||||
|
||||
if (in_array('admin_user_angeltypes', $privileges)) {
|
||||
UserAngelType_confirm($user_angeltype_id, $user);
|
||||
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
if ($user_angeltype != null) {
|
||||
error(sprintf(_("You are already a %s."), $angeltype['name']));
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
if (isset($_REQUEST['confirmed'])) {
|
||||
$user_angeltype_id = UserAngelType_create($user, $angeltype);
|
||||
|
||||
return [
|
||||
$success_message = sprintf(_("You joined %s."), $angeltype['name']);
|
||||
engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
|
||||
success($success_message);
|
||||
|
||||
if (in_array('admin_user_angeltypes', $privileges)) {
|
||||
UserAngelType_confirm($user_angeltype_id, $user);
|
||||
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
|
||||
}
|
||||
|
||||
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_("Become a %s"), $angeltype['name']),
|
||||
UserAngelType_join_view($user, $angeltype)
|
||||
];
|
||||
|
@ -337,12 +345,13 @@ function user_angeltype_join_controller($angeltype) {
|
|||
/**
|
||||
* Route UserAngelType actions.
|
||||
*/
|
||||
function user_angeltypes_controller() {
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
function user_angeltypes_controller()
|
||||
{
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'delete_all':
|
||||
return user_angeltypes_delete_all_controller();
|
||||
case 'confirm_all':
|
||||
|
@ -359,5 +368,3 @@ function user_angeltypes_controller() {
|
|||
redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -3,39 +3,41 @@
|
|||
/**
|
||||
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license information provided.
|
||||
*/
|
||||
function user_driver_license_required_hint() {
|
||||
global $user;
|
||||
function user_driver_license_required_hint()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$angeltypes = User_angeltypes($user);
|
||||
$user_driver_license = UserDriverLicense($user['UID']);
|
||||
$angeltypes = User_angeltypes($user);
|
||||
$user_driver_license = UserDriverLicense($user['UID']);
|
||||
|
||||
// User has already entered data, no hint needed.
|
||||
if ($user_driver_license != null) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
if ($angeltype['requires_driver_license']) {
|
||||
return sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>');
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
if ($angeltype['requires_driver_license']) {
|
||||
return sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Route user driver licenses actions.
|
||||
*/
|
||||
function user_driver_licenses_controller() {
|
||||
global $user;
|
||||
function user_driver_licenses_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($user)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
if (! isset($user)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
$action = strip_request_item('action', 'edit');
|
||||
$action = strip_request_item('action', 'edit');
|
||||
|
||||
switch ($action) {
|
||||
switch ($action) {
|
||||
default:
|
||||
case 'edit':
|
||||
return user_driver_license_edit_controller();
|
||||
|
@ -47,86 +49,87 @@ function user_driver_licenses_controller() {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function user_driver_license_edit_link($user = null) {
|
||||
if ($user == null) {
|
||||
return page_link_to('user_driver_licenses');
|
||||
}
|
||||
return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID'];
|
||||
function user_driver_license_edit_link($user = null)
|
||||
{
|
||||
if ($user == null) {
|
||||
return page_link_to('user_driver_licenses');
|
||||
}
|
||||
return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the user for the driver license.
|
||||
*/
|
||||
function user_driver_license_load_user() {
|
||||
global $user;
|
||||
function user_driver_license_load_user()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user_source = $user;
|
||||
$user_source = $user;
|
||||
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
if ($user_source == null) {
|
||||
redirect(user_driver_license_edit_link());
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
if ($user_source == null) {
|
||||
redirect(user_driver_license_edit_link());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $user_source;
|
||||
return $user_source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a users driver license information.
|
||||
*/
|
||||
function user_driver_license_edit_controller() {
|
||||
global $privileges, $user;
|
||||
function user_driver_license_edit_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
$user_source = user_driver_license_load_user();
|
||||
$user_source = user_driver_license_load_user();
|
||||
|
||||
// only privilege admin_user can edit other users driver license information
|
||||
if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) {
|
||||
redirect(user_driver_license_edit_link());
|
||||
redirect(user_driver_license_edit_link());
|
||||
}
|
||||
|
||||
$user_driver_license = UserDriverLicense($user_source['UID']);
|
||||
if ($user_driver_license == null) {
|
||||
$wants_to_drive = false;
|
||||
$user_driver_license = UserDriverLicense_new();
|
||||
} else {
|
||||
$wants_to_drive = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$wants_to_drive = isset($_REQUEST['wants_to_drive']);
|
||||
if ($wants_to_drive) {
|
||||
$user_driver_license['has_car'] = isset($_REQUEST['has_car']);
|
||||
$user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']);
|
||||
$user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']);
|
||||
$user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']);
|
||||
$user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']);
|
||||
$user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']);
|
||||
|
||||
if (UserDriverLicense_valid($user_driver_license)) {
|
||||
if ($user_driver_license['user_id'] == null) {
|
||||
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user);
|
||||
} else {
|
||||
UserDriverLicenses_update($user_driver_license);
|
||||
}
|
||||
engelsystem_log("Driver license information updated.");
|
||||
success(_("Your driver license information has been saved."));
|
||||
redirect(user_link($user_source));
|
||||
} else {
|
||||
error(_("Please select at least one driving license."));
|
||||
}
|
||||
} elseif ($user_driver_license['id'] != null) {
|
||||
UserDriverLicenses_delete($user_source['UID']);
|
||||
engelsystem_log("Driver license information removed.");
|
||||
success(_("Your driver license information has been removed."));
|
||||
redirect(user_link($user_source));
|
||||
$user_driver_license = UserDriverLicense($user_source['UID']);
|
||||
if ($user_driver_license == null) {
|
||||
$wants_to_drive = false;
|
||||
$user_driver_license = UserDriverLicense_new();
|
||||
} else {
|
||||
$wants_to_drive = true;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$wants_to_drive = isset($_REQUEST['wants_to_drive']);
|
||||
if ($wants_to_drive) {
|
||||
$user_driver_license['has_car'] = isset($_REQUEST['has_car']);
|
||||
$user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']);
|
||||
$user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']);
|
||||
$user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']);
|
||||
$user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']);
|
||||
$user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']);
|
||||
|
||||
if (UserDriverLicense_valid($user_driver_license)) {
|
||||
if ($user_driver_license['user_id'] == null) {
|
||||
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user);
|
||||
} else {
|
||||
UserDriverLicenses_update($user_driver_license);
|
||||
}
|
||||
engelsystem_log("Driver license information updated.");
|
||||
success(_("Your driver license information has been saved."));
|
||||
redirect(user_link($user_source));
|
||||
} else {
|
||||
error(_("Please select at least one driving license."));
|
||||
}
|
||||
} elseif ($user_driver_license['id'] != null) {
|
||||
UserDriverLicenses_delete($user_source['UID']);
|
||||
engelsystem_log("Driver license information removed.");
|
||||
success(_("Your driver license information has been removed."));
|
||||
redirect(user_link($user_source));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_("Edit %s driving license information"), $user_source['Nick']),
|
||||
UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
|
||||
];
|
||||
}
|
||||
|
||||
?>
|
|
@ -5,18 +5,19 @@ use Engelsystem\ShiftCalendarRenderer;
|
|||
/**
|
||||
* Route user actions.
|
||||
*/
|
||||
function users_controller() {
|
||||
global $user;
|
||||
function users_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($user)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
if (! isset($user)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$_REQUEST['action'] = 'list';
|
||||
}
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$_REQUEST['action'] = 'list';
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
switch ($_REQUEST['action']) {
|
||||
default:
|
||||
case 'list':
|
||||
return users_list_controller();
|
||||
|
@ -34,144 +35,151 @@ function users_controller() {
|
|||
/**
|
||||
* Delete a user, requires to enter own password for reasons.
|
||||
*/
|
||||
function user_delete_controller() {
|
||||
global $privileges, $user;
|
||||
function user_delete_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
} else {
|
||||
$user_source = $user;
|
||||
}
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
} else {
|
||||
$user_source = $user;
|
||||
}
|
||||
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
// You cannot delete yourself
|
||||
if ($user['UID'] == $user_source['UID']) {
|
||||
error(_("You cannot delete yourself."));
|
||||
redirect(user_link($user));
|
||||
error(_("You cannot delete yourself."));
|
||||
redirect(user_link($user));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (! (isset($_REQUEST['password']) && verify_password($_REQUEST['password'], $user['Passwort'], $user['UID']))) {
|
||||
$valid = false;
|
||||
error(_("Your password is incorrect. Please try it again."));
|
||||
if (! (isset($_REQUEST['password']) && verify_password($_REQUEST['password'], $user['Passwort'], $user['UID']))) {
|
||||
$valid = false;
|
||||
error(_("Your password is incorrect. Please try it again."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$result = User_delete($user_source['UID']);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete user.');
|
||||
}
|
||||
|
||||
mail_user_delete($user_source);
|
||||
success(_("User deleted."));
|
||||
engelsystem_log(sprintf("Deleted %s", User_Nick_render($user_source)));
|
||||
|
||||
redirect(users_link());
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$result = User_delete($user_source['UID']);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete user.');
|
||||
}
|
||||
|
||||
mail_user_delete($user_source);
|
||||
success(_("User deleted."));
|
||||
engelsystem_log(sprintf("Deleted %s", User_Nick_render($user_source)));
|
||||
|
||||
redirect(users_link());
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
sprintf(_("Delete %s"), $user_source['Nick']),
|
||||
User_delete_view($user_source)
|
||||
];
|
||||
}
|
||||
|
||||
function users_link() {
|
||||
return page_link_to('users');
|
||||
function users_link()
|
||||
{
|
||||
return page_link_to('users');
|
||||
}
|
||||
|
||||
function user_edit_link($user) {
|
||||
return page_link_to('admin_user') . '&user_id=' . $user['UID'];
|
||||
function user_edit_link($user)
|
||||
{
|
||||
return page_link_to('admin_user') . '&user_id=' . $user['UID'];
|
||||
}
|
||||
|
||||
function user_delete_link($user) {
|
||||
return page_link_to('users') . '&action=delete&user_id=' . $user['UID'];
|
||||
function user_delete_link($user)
|
||||
{
|
||||
return page_link_to('users') . '&action=delete&user_id=' . $user['UID'];
|
||||
}
|
||||
|
||||
function user_link($user) {
|
||||
return page_link_to('users') . '&action=view&user_id=' . $user['UID'];
|
||||
function user_link($user)
|
||||
{
|
||||
return page_link_to('users') . '&action=view&user_id=' . $user['UID'];
|
||||
}
|
||||
|
||||
function user_edit_vouchers_controller() {
|
||||
global $privileges, $user;
|
||||
function user_edit_vouchers_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
} else {
|
||||
$user_source = $user;
|
||||
}
|
||||
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) {
|
||||
$vouchers = trim($_REQUEST['vouchers']);
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter a valid number of vouchers."));
|
||||
$user_source = $user;
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$user_source['got_voucher'] = $vouchers;
|
||||
|
||||
$result = User_update($user_source);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update user.');
|
||||
}
|
||||
|
||||
success(_("Saved the number of vouchers."));
|
||||
engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf("Got %s vouchers", $user_source['got_voucher']));
|
||||
|
||||
redirect(user_link($user_source));
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) {
|
||||
$vouchers = trim($_REQUEST['vouchers']);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter a valid number of vouchers."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$user_source['got_voucher'] = $vouchers;
|
||||
|
||||
$result = User_update($user_source);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update user.');
|
||||
}
|
||||
|
||||
success(_("Saved the number of vouchers."));
|
||||
engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf("Got %s vouchers", $user_source['got_voucher']));
|
||||
|
||||
redirect(user_link($user_source));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
sprintf(_("%s's vouchers"), $user_source['Nick']),
|
||||
User_edit_vouchers_view($user_source)
|
||||
];
|
||||
}
|
||||
|
||||
function user_controller() {
|
||||
global $privileges, $user;
|
||||
function user_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
$user_source = $user;
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User not found."));
|
||||
redirect('?');
|
||||
$user_source = $user;
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
if ($user_source == null) {
|
||||
error(_("User not found."));
|
||||
redirect('?');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$shifts = Shifts_by_user($user_source, in_array("user_shifts_admin", $privileges));
|
||||
foreach ($shifts as &$shift) {
|
||||
// TODO: Move queries to model
|
||||
$shifts = Shifts_by_user($user_source, in_array("user_shifts_admin", $privileges));
|
||||
foreach ($shifts as &$shift) {
|
||||
// TODO: Move queries to model
|
||||
$shift['needed_angeltypes'] = sql_select("SELECT DISTINCT `AngelTypes`.* FROM `ShiftEntry` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "' ORDER BY `AngelTypes`.`name`");
|
||||
foreach ($shift['needed_angeltypes'] as &$needed_angeltype) {
|
||||
$needed_angeltype['users'] = sql_select("
|
||||
foreach ($shift['needed_angeltypes'] as &$needed_angeltype) {
|
||||
$needed_angeltype['users'] = sql_select("
|
||||
SELECT `ShiftEntry`.`freeloaded`, `User`.*
|
||||
FROM `ShiftEntry`
|
||||
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
|
||||
WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "'
|
||||
AND `ShiftEntry`.`TID`='" . sql_escape($needed_angeltype['id']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($user_source['api_key'] == "") {
|
||||
User_reset_api_key($user_source, false);
|
||||
}
|
||||
if ($user_source['api_key'] == "") {
|
||||
User_reset_api_key($user_source, false);
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
$user_source['Nick'],
|
||||
User_view($user_source, in_array('admin_user', $privileges), User_is_freeloader($user_source), User_angeltypes($user_source), User_groups($user_source), $shifts, $user['UID'] == $user_source['UID'])
|
||||
];
|
||||
|
@ -180,28 +188,29 @@ function user_controller() {
|
|||
/**
|
||||
* List all users.
|
||||
*/
|
||||
function users_list_controller() {
|
||||
global $privileges;
|
||||
function users_list_controller()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
if (! in_array('admin_user', $privileges)) {
|
||||
redirect(page_link_to(''));
|
||||
}
|
||||
|
||||
$order_by = 'Nick';
|
||||
if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) {
|
||||
$order_by = $_REQUEST['OrderBy'];
|
||||
}
|
||||
$order_by = 'Nick';
|
||||
if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) {
|
||||
$order_by = $_REQUEST['OrderBy'];
|
||||
}
|
||||
|
||||
$users = Users($order_by);
|
||||
if ($users === false) {
|
||||
engelsystem_error('Unable to load users.');
|
||||
}
|
||||
$users = Users($order_by);
|
||||
if ($users === false) {
|
||||
engelsystem_error('Unable to load users.');
|
||||
}
|
||||
|
||||
foreach ($users as &$user) {
|
||||
$user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
|
||||
}
|
||||
foreach ($users as &$user) {
|
||||
$user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
_('All users'),
|
||||
Users_view($users, $order_by, User_arrived_count(), User_active_count(), User_force_active_count(), ShiftEntries_freeleaded_count(), User_tshirts_count(), User_got_voucher_count())
|
||||
];
|
||||
|
@ -210,162 +219,166 @@ function users_list_controller() {
|
|||
/**
|
||||
* Second step of password recovery: set a new password using the token link from email
|
||||
*/
|
||||
function user_password_recovery_set_new_controller() {
|
||||
global $min_password_length;
|
||||
$user_source = User_by_password_recovery_token($_REQUEST['token']);
|
||||
if ($user_source == null) {
|
||||
error(_("Token is not correct."));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) {
|
||||
if ($_REQUEST['password'] != $_REQUEST['password2']) {
|
||||
$valid = false;
|
||||
error(_("Your passwords don't match."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Your password is to short (please use at least 6 characters)."));
|
||||
function user_password_recovery_set_new_controller()
|
||||
{
|
||||
global $min_password_length;
|
||||
$user_source = User_by_password_recovery_token($_REQUEST['token']);
|
||||
if ($user_source == null) {
|
||||
error(_("Token is not correct."));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
set_password($user_source['UID'], $_REQUEST['password']);
|
||||
success(_("Password saved."));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
}
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
return User_password_set_view();
|
||||
if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) {
|
||||
if ($_REQUEST['password'] != $_REQUEST['password2']) {
|
||||
$valid = false;
|
||||
error(_("Your passwords don't match."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Your password is to short (please use at least 6 characters)."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
set_password($user_source['UID'], $_REQUEST['password']);
|
||||
success(_("Password saved."));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
}
|
||||
|
||||
return User_password_set_view();
|
||||
}
|
||||
|
||||
/**
|
||||
* First step of password recovery: display a form that asks for your email and send email with recovery link
|
||||
*/
|
||||
function user_password_recovery_start_controller() {
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
function user_password_recovery_start_controller()
|
||||
{
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['email']) && strlen(strip_request_item('email')) > 0) {
|
||||
$email = strip_request_item('email');
|
||||
if (check_email($email)) {
|
||||
$user_source = User_by_email($email);
|
||||
if ($user_source == null) {
|
||||
$valid = false;
|
||||
error(_("E-mail address is not correct."));
|
||||
if (isset($_REQUEST['email']) && strlen(strip_request_item('email')) > 0) {
|
||||
$email = strip_request_item('email');
|
||||
if (check_email($email)) {
|
||||
$user_source = User_by_email($email);
|
||||
if ($user_source == null) {
|
||||
$valid = false;
|
||||
error(_("E-mail address is not correct."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("E-mail address is not correct."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter your e-mail."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$token = User_generate_password_recovery_token($user_source);
|
||||
engelsystem_email_to_user($user_source, _("Password recovery"), sprintf(_("Please visit %s to recover your password."), page_link_to_absolute('user_password_recovery') . '&token=' . $token));
|
||||
success(_("We sent an email containing your password recovery link."));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("E-mail address is not correct."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter your e-mail."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$token = User_generate_password_recovery_token($user_source);
|
||||
engelsystem_email_to_user($user_source, _("Password recovery"), sprintf(_("Please visit %s to recover your password."), page_link_to_absolute('user_password_recovery') . '&token=' . $token));
|
||||
success(_("We sent an email containing your password recovery link."));
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
}
|
||||
|
||||
return User_password_recovery_view();
|
||||
return User_password_recovery_view();
|
||||
}
|
||||
|
||||
/**
|
||||
* User password recovery in 2 steps.
|
||||
* (By email)
|
||||
*/
|
||||
function user_password_recovery_controller() {
|
||||
if (isset($_REQUEST['token'])) {
|
||||
return user_password_recovery_set_new_controller();
|
||||
} else {
|
||||
return user_password_recovery_start_controller();
|
||||
}
|
||||
function user_password_recovery_controller()
|
||||
{
|
||||
if (isset($_REQUEST['token'])) {
|
||||
return user_password_recovery_set_new_controller();
|
||||
} else {
|
||||
return user_password_recovery_start_controller();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu title for password recovery.
|
||||
*/
|
||||
function user_password_recovery_title() {
|
||||
return _("Password recovery");
|
||||
function user_password_recovery_title()
|
||||
{
|
||||
return _("Password recovery");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a user from param user_id.
|
||||
*/
|
||||
function load_user() {
|
||||
if (! isset($_REQUEST['user_id'])) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
function load_user()
|
||||
{
|
||||
if (! isset($_REQUEST['user_id'])) {
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
$user = User($_REQUEST['user_id']);
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
$user = User($_REQUEST['user_id']);
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
|
||||
if ($user == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to());
|
||||
}
|
||||
if ($user == null) {
|
||||
error(_("User doesn't exist."));
|
||||
redirect(page_link_to());
|
||||
}
|
||||
|
||||
return $user;
|
||||
return $user;
|
||||
}
|
||||
|
||||
function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) {
|
||||
$shifts = Shifts_by_ShiftsFilter($shiftsFilter);
|
||||
$needed_angeltypes_source = NeededAngeltypes_by_ShiftsFilter($shiftsFilter);
|
||||
$shift_entries_source = ShiftEntries_by_ShiftsFilter($shiftsFilter);
|
||||
function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$shifts = Shifts_by_ShiftsFilter($shiftsFilter);
|
||||
$needed_angeltypes_source = NeededAngeltypes_by_ShiftsFilter($shiftsFilter);
|
||||
$shift_entries_source = ShiftEntries_by_ShiftsFilter($shiftsFilter);
|
||||
|
||||
$needed_angeltypes = [];
|
||||
$shift_entries = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$needed_angeltypes[$shift['SID']] = [];
|
||||
$shift_entries[$shift['SID']] = [];
|
||||
}
|
||||
foreach ($shift_entries_source as $shift_entry) {
|
||||
if (isset($shift_entries[$shift_entry['SID']])) {
|
||||
$shift_entries[$shift_entry['SID']][] = $shift_entry;
|
||||
$needed_angeltypes = [];
|
||||
$shift_entries = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$needed_angeltypes[$shift['SID']] = [];
|
||||
$shift_entries[$shift['SID']] = [];
|
||||
}
|
||||
}
|
||||
foreach ($needed_angeltypes_source as $needed_angeltype) {
|
||||
if (isset($needed_angeltypes[$needed_angeltype['SID']])) {
|
||||
$needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype;
|
||||
}
|
||||
}
|
||||
unset($needed_angeltypes_source);
|
||||
unset($shift_entries_source);
|
||||
|
||||
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())) {
|
||||
return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||
}
|
||||
|
||||
$filtered_shifts = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$needed_angels_count = 0;
|
||||
foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) {
|
||||
$taken = 0;
|
||||
foreach ($shift_entries[$shift['SID']] as $shift_entry) {
|
||||
if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) {
|
||||
$taken ++;
|
||||
foreach ($shift_entries_source as $shift_entry) {
|
||||
if (isset($shift_entries[$shift_entry['SID']])) {
|
||||
$shift_entries[$shift_entry['SID']][] = $shift_entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($needed_angeltypes_source as $needed_angeltype) {
|
||||
if (isset($needed_angeltypes[$needed_angeltype['SID']])) {
|
||||
$needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype;
|
||||
}
|
||||
}
|
||||
unset($needed_angeltypes_source);
|
||||
unset($shift_entries_source);
|
||||
|
||||
$needed_angels_count += max(0, $needed_angeltype['count'] - $taken);
|
||||
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())) {
|
||||
return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||
}
|
||||
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) {
|
||||
$filtered_shifts[] = $shift;
|
||||
}
|
||||
if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) {
|
||||
$filtered_shifts[] = $shift;
|
||||
}
|
||||
}
|
||||
|
||||
return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||
$filtered_shifts = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$needed_angels_count = 0;
|
||||
foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) {
|
||||
$taken = 0;
|
||||
foreach ($shift_entries[$shift['SID']] as $shift_entry) {
|
||||
if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) {
|
||||
$taken ++;
|
||||
}
|
||||
}
|
||||
|
||||
$needed_angels_count += max(0, $needed_angeltype['count'] - $taken);
|
||||
}
|
||||
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) {
|
||||
$filtered_shifts[] = $shift;
|
||||
}
|
||||
if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) {
|
||||
$filtered_shifts[] = $shift;
|
||||
}
|
||||
}
|
||||
|
||||
return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
/**
|
||||
* This file includes all needed functions, connects to the db etc.
|
||||
*/
|
||||
if(!is_readable(__DIR__ . '/../vendor/autoload.php')){
|
||||
die('Please run composer.phar install');
|
||||
if (!is_readable(__DIR__ . '/../vendor/autoload.php')) {
|
||||
die('Please run composer.phar install');
|
||||
}
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
|
@ -70,12 +70,12 @@ require_once realpath(__DIR__ . '/../includes/mailer/users_mailer.php');
|
|||
|
||||
require_once realpath(__DIR__ . '/../config/config.default.php');
|
||||
if (file_exists(realpath(__DIR__ . '/../config/config.php'))) {
|
||||
require_once realpath(__DIR__ . '/../config/config.php');
|
||||
require_once realpath(__DIR__ . '/../config/config.php');
|
||||
}
|
||||
|
||||
if ($maintenance_mode) {
|
||||
echo file_get_contents(__DIR__ . '/../public/maintenance.html');
|
||||
die();
|
||||
echo file_get_contents(__DIR__ . '/../public/maintenance.html');
|
||||
die();
|
||||
}
|
||||
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_active.php');
|
||||
|
@ -103,5 +103,3 @@ gettext_init();
|
|||
sql_connect($config['host'], $config['user'], $config['pw'], $config['db']);
|
||||
|
||||
load_auth();
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
<?php
|
||||
|
||||
function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false) {
|
||||
global $user;
|
||||
function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false)
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
|
||||
return true;
|
||||
}
|
||||
if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
gettext_locale($recipient_user['Sprache']);
|
||||
gettext_locale($recipient_user['Sprache']);
|
||||
|
||||
$message = sprintf(_("Hi %s,"), $recipient_user['Nick']) . "\n\n" . _("here is a message for you from the engelsystem:") . "\n\n" . $message . "\n\n" . _("This email is autogenerated and has not to be signed. You got this email because you are registered in the engelsystem.");
|
||||
$message = sprintf(_("Hi %s,"), $recipient_user['Nick']) . "\n\n" . _("here is a message for you from the engelsystem:") . "\n\n" . $message . "\n\n" . _("This email is autogenerated and has not to be signed. You got this email because you are registered in the engelsystem.");
|
||||
|
||||
gettext_locale();
|
||||
return engelsystem_email($recipient_user['email'], $title, $message);
|
||||
gettext_locale();
|
||||
return engelsystem_email($recipient_user['email'], $title, $message);
|
||||
}
|
||||
|
||||
function engelsystem_email($address, $title, $message) {
|
||||
$result = mail($address, $title, $message, "Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <noreply@engelsystem.de>");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to send email.');
|
||||
}
|
||||
function engelsystem_email($address, $title, $message)
|
||||
{
|
||||
$result = mail($address, $title, $message, "Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <noreply@engelsystem.de>");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to send email.');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
*
|
||||
* @param string $message
|
||||
*/
|
||||
function engelsystem_error($message) {
|
||||
raw_output($message);
|
||||
function engelsystem_error($message)
|
||||
{
|
||||
raw_output($message);
|
||||
}
|
||||
|
||||
?>
|
|
@ -7,26 +7,27 @@
|
|||
* @param unknown $colors colors for the data rows
|
||||
* @param unknown $data the data
|
||||
*/
|
||||
function bargraph($dom_id, $key, $row_names, $colors, $data) {
|
||||
$labels = [];
|
||||
foreach ($data as $dataset) {
|
||||
$labels[] = $dataset[$key];
|
||||
}
|
||||
|
||||
$datasets = [];
|
||||
foreach ($row_names as $row_key => $name) {
|
||||
$values = [];
|
||||
function bargraph($dom_id, $key, $row_names, $colors, $data)
|
||||
{
|
||||
$labels = [];
|
||||
foreach ($data as $dataset) {
|
||||
$values[] = $dataset[$row_key];
|
||||
$labels[] = $dataset[$key];
|
||||
}
|
||||
$datasets[] = [
|
||||
|
||||
$datasets = [];
|
||||
foreach ($row_names as $row_key => $name) {
|
||||
$values = [];
|
||||
foreach ($data as $dataset) {
|
||||
$values[] = $dataset[$row_key];
|
||||
}
|
||||
$datasets[] = [
|
||||
'label' => $name,
|
||||
'fillColor' => $colors[$row_key],
|
||||
'data' => $values
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return '<canvas id="' . $dom_id . '" style="width: 100%; height: 300px;"></canvas>
|
||||
return '<canvas id="' . $dom_id . '" style="width: 100%; height: 300px;"></canvas>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
var ctx = $("#' . $dom_id . '").get(0).getContext("2d");
|
||||
|
@ -37,5 +38,3 @@ function bargraph($dom_id, $key, $row_names, $colors, $data) {
|
|||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
?>
|
|
@ -9,33 +9,36 @@ $default_locale = 'en_US.UTF-8';
|
|||
/**
|
||||
* Return currently active locale
|
||||
*/
|
||||
function locale() {
|
||||
return $_SESSION['locale'];
|
||||
function locale()
|
||||
{
|
||||
return $_SESSION['locale'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns two letter language code from currently active locale
|
||||
*/
|
||||
function locale_short() {
|
||||
return substr(locale(), 0, 2);
|
||||
function locale_short()
|
||||
{
|
||||
return substr(locale(), 0, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes gettext for internationalization and updates the sessions locale to use for translation.
|
||||
*/
|
||||
function gettext_init() {
|
||||
global $locales, $default_locale;
|
||||
function gettext_init()
|
||||
{
|
||||
global $locales, $default_locale;
|
||||
|
||||
if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) {
|
||||
$_SESSION['locale'] = $_REQUEST['set_locale'];
|
||||
} elseif (! isset($_SESSION['locale'])) {
|
||||
$_SESSION['locale'] = $default_locale;
|
||||
}
|
||||
if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) {
|
||||
$_SESSION['locale'] = $_REQUEST['set_locale'];
|
||||
} elseif (! isset($_SESSION['locale'])) {
|
||||
$_SESSION['locale'] = $default_locale;
|
||||
}
|
||||
|
||||
gettext_locale();
|
||||
bindtextdomain('default', realpath(__DIR__ . '/../../locale'));
|
||||
bind_textdomain_codeset('default', 'UTF-8');
|
||||
textdomain('default');
|
||||
gettext_locale();
|
||||
bindtextdomain('default', realpath(__DIR__ . '/../../locale'));
|
||||
bind_textdomain_codeset('default', 'UTF-8');
|
||||
textdomain('default');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,13 +46,14 @@ function gettext_init() {
|
|||
*
|
||||
* @param string $locale
|
||||
*/
|
||||
function gettext_locale($locale = null) {
|
||||
if ($locale == null) {
|
||||
$locale = $_SESSION['locale'];
|
||||
}
|
||||
function gettext_locale($locale = null)
|
||||
{
|
||||
if ($locale == null) {
|
||||
$locale = $_SESSION['locale'];
|
||||
}
|
||||
|
||||
putenv('LC_ALL=' . $locale);
|
||||
setlocale(LC_ALL, $locale);
|
||||
putenv('LC_ALL=' . $locale);
|
||||
setlocale(LC_ALL, $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,15 +61,14 @@ function gettext_locale($locale = null) {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function make_langselect() {
|
||||
global $locales;
|
||||
$URL = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], "?") > 0 ? '&' : '?') . "set_locale=";
|
||||
function make_langselect()
|
||||
{
|
||||
global $locales;
|
||||
$URL = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], "?") > 0 ? '&' : '?') . "set_locale=";
|
||||
|
||||
$items = [];
|
||||
foreach ($locales as $locale => $name) {
|
||||
$items[] = toolbar_item_link(htmlspecialchars($URL) . $locale, '', '<img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"> ' . $name);
|
||||
}
|
||||
return $items;
|
||||
$items = [];
|
||||
foreach ($locales as $locale => $name) {
|
||||
$items[] = toolbar_item_link(htmlspecialchars($URL) . $locale, '', '<img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"> ' . $name);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
?>
|
|
@ -3,51 +3,54 @@
|
|||
/**
|
||||
* Gibt zwischengespeicherte Fehlermeldungen zurück und löscht den Zwischenspeicher
|
||||
*/
|
||||
function msg() {
|
||||
if (! isset($_SESSION['msg'])) {
|
||||
return "";
|
||||
}
|
||||
$msg = $_SESSION['msg'];
|
||||
$_SESSION['msg'] = "";
|
||||
return $msg;
|
||||
function msg()
|
||||
{
|
||||
if (! isset($_SESSION['msg'])) {
|
||||
return "";
|
||||
}
|
||||
$msg = $_SESSION['msg'];
|
||||
$_SESSION['msg'] = "";
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert eine Information
|
||||
*/
|
||||
function info($msg, $immediatly = false) {
|
||||
return alert('info', $msg, $immediatly);
|
||||
function info($msg, $immediatly = false)
|
||||
{
|
||||
return alert('info', $msg, $immediatly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert eine Fehlermeldung
|
||||
*/
|
||||
function error($msg, $immediatly = false) {
|
||||
return alert('danger', $msg, $immediatly);
|
||||
function error($msg, $immediatly = false)
|
||||
{
|
||||
return alert('danger', $msg, $immediatly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert eine Erfolgsmeldung
|
||||
*/
|
||||
function success($msg, $immediatly = false) {
|
||||
return alert('success', $msg, $immediatly);
|
||||
function success($msg, $immediatly = false)
|
||||
{
|
||||
return alert('success', $msg, $immediatly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an alert with given alert-* class.
|
||||
*/
|
||||
function alert($class, $msg, $immediatly = false) {
|
||||
if ($immediatly) {
|
||||
if ($msg == "") {
|
||||
return "";
|
||||
function alert($class, $msg, $immediatly = false)
|
||||
{
|
||||
if ($immediatly) {
|
||||
if ($msg == "") {
|
||||
return "";
|
||||
}
|
||||
return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
|
||||
}
|
||||
return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
|
||||
}
|
||||
|
||||
if (! isset($_SESSION['msg'])) {
|
||||
$_SESSION['msg'] = "";
|
||||
}
|
||||
$_SESSION['msg'] .= alert($class, $msg, true);
|
||||
if (! isset($_SESSION['msg'])) {
|
||||
$_SESSION['msg'] = "";
|
||||
}
|
||||
$_SESSION['msg'] .= alert($class, $msg, true);
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,104 +1,106 @@
|
|||
<?php
|
||||
|
||||
function mail_shift_change($old_shift, $new_shift) {
|
||||
$users = ShiftEntries_by_shift($old_shift["SID"]);
|
||||
$old_room = Room($old_shift["RID"]);
|
||||
$new_room = Room($new_shift["RID"]);
|
||||
function mail_shift_change($old_shift, $new_shift)
|
||||
{
|
||||
$users = ShiftEntries_by_shift($old_shift["SID"]);
|
||||
$old_room = Room($old_shift["RID"]);
|
||||
$new_room = Room($new_shift["RID"]);
|
||||
|
||||
$noticable_changes = false;
|
||||
$noticable_changes = false;
|
||||
|
||||
$message = _("A Shift you are registered on has changed:");
|
||||
$message .= "\n";
|
||||
$message = _("A Shift you are registered on has changed:");
|
||||
$message .= "\n";
|
||||
|
||||
if ($old_shift["name"] != $new_shift["name"]) {
|
||||
$message .= sprintf(_("* Shift type changed from %s to %s"), $old_shift["name"], $new_shift["name"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
if ($old_shift["name"] != $new_shift["name"]) {
|
||||
$message .= sprintf(_("* Shift type changed from %s to %s"), $old_shift["name"], $new_shift["name"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift["title"] != $new_shift["title"]) {
|
||||
$message .= sprintf(_("* Shift title changed from %s to %s"), $old_shift["title"], $new_shift["title"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
if ($old_shift["title"] != $new_shift["title"]) {
|
||||
$message .= sprintf(_("* Shift title changed from %s to %s"), $old_shift["title"], $new_shift["title"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift["start"] != $new_shift["start"]) {
|
||||
$message .= sprintf(_("* Shift Start changed from %s to %s"), date("Y-m-d H:i", $old_shift["start"]), date("Y-m-d H:i", $new_shift["start"])) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
if ($old_shift["start"] != $new_shift["start"]) {
|
||||
$message .= sprintf(_("* Shift Start changed from %s to %s"), date("Y-m-d H:i", $old_shift["start"]), date("Y-m-d H:i", $new_shift["start"])) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift["end"] != $new_shift["end"]) {
|
||||
$message .= sprintf(_("* Shift End changed from %s to %s"), date("Y-m-d H:i", $old_shift["end"]), date("Y-m-d H:i", $new_shift["end"])) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
if ($old_shift["end"] != $new_shift["end"]) {
|
||||
$message .= sprintf(_("* Shift End changed from %s to %s"), date("Y-m-d H:i", $old_shift["end"]), date("Y-m-d H:i", $new_shift["end"])) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if ($old_shift["RID"] != $new_shift["RID"]) {
|
||||
$message .= sprintf(_("* Shift Location changed from %s to %s"), $old_room["Name"], $new_room["Name"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
if ($old_shift["RID"] != $new_shift["RID"]) {
|
||||
$message .= sprintf(_("* Shift Location changed from %s to %s"), $old_room["Name"], $new_room["Name"]) . "\n";
|
||||
$noticable_changes = true;
|
||||
}
|
||||
|
||||
if (! $noticable_changes) {
|
||||
// There are no changes worth sending an E-Mail
|
||||
if (! $noticable_changes) {
|
||||
// There are no changes worth sending an E-Mail
|
||||
return;
|
||||
}
|
||||
|
||||
$message .= "\n";
|
||||
$message .= _("The updated Shift:") . "\n";
|
||||
|
||||
$message .= $new_shift["name"] . "\n";
|
||||
$message .= $new_shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $new_shift["start"]) . " - " . date("H:i", $new_shift["end"]) . "\n";
|
||||
$message .= $new_room["Name"] . "\n";
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift has changed"), $message, true);
|
||||
}
|
||||
}
|
||||
|
||||
$message .= "\n";
|
||||
$message .= _("The updated Shift:") . "\n";
|
||||
|
||||
$message .= $new_shift["name"] . "\n";
|
||||
$message .= $new_shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $new_shift["start"]) . " - " . date("H:i", $new_shift["end"]) . "\n";
|
||||
$message .= $new_room["Name"] . "\n";
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift has changed"), $message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mail_shift_delete($shift) {
|
||||
$users = ShiftEntries_by_shift($shift["SID"]);
|
||||
$room = Room($shift["RID"]);
|
||||
|
||||
$message = _("A Shift you are registered on was deleted:") . "\n";
|
||||
|
||||
$message .= $shift["name"] . "\n";
|
||||
$message .= $shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
|
||||
$message .= $room["Name"] . "\n";
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift was deleted"), $message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mail_shift_assign($user, $shift) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
function mail_shift_delete($shift)
|
||||
{
|
||||
$users = ShiftEntries_by_shift($shift["SID"]);
|
||||
$room = Room($shift["RID"]);
|
||||
|
||||
$message = _("You have been assigned to a Shift:") . "\n";
|
||||
$message = _("A Shift you are registered on was deleted:") . "\n";
|
||||
|
||||
$message .= $shift["name"] . "\n";
|
||||
$message .= $shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
|
||||
$message .= $room["Name"] . "\n";
|
||||
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Assigned to Shift"), $message, true);
|
||||
}
|
||||
foreach ($users as $user) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift was deleted"), $message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mail_shift_removed($user, $shift) {
|
||||
if ($user["email_shiftinfo"]) {
|
||||
$room = Room($shift["RID"]);
|
||||
function mail_shift_assign($user, $shift)
|
||||
{
|
||||
if ($user["email_shiftinfo"]) {
|
||||
$room = Room($shift["RID"]);
|
||||
|
||||
$message = _("You have been removed from a Shift:") . "\n";
|
||||
$message .= $shift["name"] . "\n";
|
||||
$message .= $shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
|
||||
$message .= $room["Name"] . "\n";
|
||||
$message = _("You have been assigned to a Shift:") . "\n";
|
||||
$message .= $shift["name"] . "\n";
|
||||
$message .= $shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
|
||||
$message .= $room["Name"] . "\n";
|
||||
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Removed from Shift"), $message, true);
|
||||
}
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Assigned to Shift"), $message, true);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
function mail_shift_removed($user, $shift)
|
||||
{
|
||||
if ($user["email_shiftinfo"]) {
|
||||
$room = Room($shift["RID"]);
|
||||
|
||||
$message = _("You have been removed from a Shift:") . "\n";
|
||||
$message .= $shift["name"] . "\n";
|
||||
$message .= $shift["title"] . "\n";
|
||||
$message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
|
||||
$message .= $room["Name"] . "\n";
|
||||
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Removed from Shift"), $message, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
/**
|
||||
* @param User $user_source
|
||||
*/
|
||||
function mail_user_delete($user) {
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your account has been deleted"), _("Your angelsystem account has been deleted. If you have any questions regarding your account deletion, please contact heaven."));
|
||||
function mail_user_delete($user)
|
||||
{
|
||||
engelsystem_email_to_user($user, '[engelsystem] ' . _("Your account has been deleted"), _("Your angelsystem account has been deleted. If you have any questions regarding your account deletion, please contact heaven."));
|
||||
}
|
||||
?>
|
|
@ -5,8 +5,9 @@ use Engelsystem\ValidationResult;
|
|||
* Returns an array containing the basic attributes of angeltypes.
|
||||
* FIXME! This is the big sign for needing entity objects
|
||||
*/
|
||||
function AngelType_new() {
|
||||
return [
|
||||
function AngelType_new()
|
||||
{
|
||||
return [
|
||||
'id' => null,
|
||||
'name' => "",
|
||||
'restricted' => false,
|
||||
|
@ -27,17 +28,18 @@ function AngelType_new() {
|
|||
* The angeltype
|
||||
* @return ValidationResult
|
||||
*/
|
||||
function AngelType_validate_contact_user_id($angeltype) {
|
||||
if (! isset($angeltype['contact_user_id'])) {
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
if (isset($angeltype['contact_name']) || isset($angeltype['contact_dect']) || isset($angeltype['contact_email'])) {
|
||||
return new ValidationResult(false, $angeltype['contact_user_id']);
|
||||
}
|
||||
if (User($angeltype['contact_user_id']) == null) {
|
||||
return new ValidationResult(false, $angeltype['contact_user_id']);
|
||||
}
|
||||
return new ValidationResult(true, $angeltype['contact_user_id']);
|
||||
function AngelType_validate_contact_user_id($angeltype)
|
||||
{
|
||||
if (! isset($angeltype['contact_user_id'])) {
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
if (isset($angeltype['contact_name']) || isset($angeltype['contact_dect']) || isset($angeltype['contact_email'])) {
|
||||
return new ValidationResult(false, $angeltype['contact_user_id']);
|
||||
}
|
||||
if (User($angeltype['contact_user_id']) == null) {
|
||||
return new ValidationResult(false, $angeltype['contact_user_id']);
|
||||
}
|
||||
return new ValidationResult(true, $angeltype['contact_user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,26 +48,27 @@ function AngelType_validate_contact_user_id($angeltype) {
|
|||
* @param Angeltype $angeltype
|
||||
* The angeltype
|
||||
*/
|
||||
function AngelType_contact_info($angeltype) {
|
||||
if (isset($angeltype['contact_user_id'])) {
|
||||
$contact_user = User($angeltype['contact_user_id']);
|
||||
$contact_data = [
|
||||
function AngelType_contact_info($angeltype)
|
||||
{
|
||||
if (isset($angeltype['contact_user_id'])) {
|
||||
$contact_user = User($angeltype['contact_user_id']);
|
||||
$contact_data = [
|
||||
'contact_name' => $contact_user['Nick'],
|
||||
'contact_dect' => $contact_user['DECT']
|
||||
];
|
||||
if ($contact_user['email_by_human_allowed']) {
|
||||
$contact_data['contact_email'] = $contact_user['email'];
|
||||
if ($contact_user['email_by_human_allowed']) {
|
||||
$contact_data['contact_email'] = $contact_user['email'];
|
||||
}
|
||||
return $contact_data;
|
||||
}
|
||||
return $contact_data;
|
||||
}
|
||||
if (isset($angeltype['contact_name'])) {
|
||||
return [
|
||||
if (isset($angeltype['contact_name'])) {
|
||||
return [
|
||||
'contact_name' => $angeltype['contact_name'],
|
||||
'contact_dect' => $angeltype['contact_dect'],
|
||||
'contact_email' => $angeltype['contact_email']
|
||||
];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,16 +76,17 @@ function AngelType_contact_info($angeltype) {
|
|||
*
|
||||
* @param Angeltype $angeltype
|
||||
*/
|
||||
function AngelType_delete($angeltype) {
|
||||
$result = sql_query("
|
||||
function AngelType_delete($angeltype)
|
||||
{
|
||||
$result = sql_query("
|
||||
DELETE FROM `AngelTypes`
|
||||
WHERE `id`='" . sql_escape($angeltype['id']) . "'
|
||||
LIMIT 1");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to delete angeltype.");
|
||||
}
|
||||
engelsystem_log("Deleted angeltype: " . AngelType_name_render($angeltype));
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to delete angeltype.");
|
||||
}
|
||||
engelsystem_log("Deleted angeltype: " . AngelType_name_render($angeltype));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,8 +95,9 @@ function AngelType_delete($angeltype) {
|
|||
* @param Angeltype $angeltype
|
||||
* The angeltype
|
||||
*/
|
||||
function AngelType_update($angeltype) {
|
||||
$result = sql_query("
|
||||
function AngelType_update($angeltype)
|
||||
{
|
||||
$result = sql_query("
|
||||
UPDATE `AngelTypes` SET
|
||||
`name`='" . sql_escape($angeltype['name']) . "',
|
||||
`restricted`=" . sql_bool($angeltype['restricted']) . ",
|
||||
|
@ -104,11 +109,11 @@ function AngelType_update($angeltype) {
|
|||
`contact_dect`=" . sql_null($angeltype['contact_dect']) . ",
|
||||
`contact_email`=" . sql_null($angeltype['contact_email']) . "
|
||||
WHERE `id`='" . sql_escape($angeltype['id']) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update angeltype.");
|
||||
}
|
||||
engelsystem_log("Updated angeltype: " . $angeltype['name'] . ($angeltype['restricted'] ? ", restricted" : "") . ($angeltype['no_self_signup'] ? ", no_self_signup" : "") . ($angeltype['requires_driver_license'] ? ", requires driver license" : ""));
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update angeltype.");
|
||||
}
|
||||
engelsystem_log("Updated angeltype: " . $angeltype['name'] . ($angeltype['restricted'] ? ", restricted" : "") . ($angeltype['no_self_signup'] ? ", no_self_signup" : "") . ($angeltype['requires_driver_license'] ? ", requires driver license" : ""));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,8 +123,9 @@ function AngelType_update($angeltype) {
|
|||
* The angeltype
|
||||
* @return the created angeltype
|
||||
*/
|
||||
function AngelType_create($angeltype) {
|
||||
$result = sql_query("
|
||||
function AngelType_create($angeltype)
|
||||
{
|
||||
$result = sql_query("
|
||||
INSERT INTO `AngelTypes` SET
|
||||
`name`='" . sql_escape($angeltype['name']) . "',
|
||||
`restricted`=" . sql_bool($angeltype['restricted']) . ",
|
||||
|
@ -130,12 +136,12 @@ function AngelType_create($angeltype) {
|
|||
`contact_name`=" . sql_null($angeltype['contact_name']) . ",
|
||||
`contact_dect`=" . sql_null($angeltype['contact_dect']) . ",
|
||||
`contact_email`=" . sql_null($angeltype['contact_email']));
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to create angeltype.");
|
||||
}
|
||||
$angeltype['id'] = sql_id();
|
||||
engelsystem_log("Created angeltype: " . $angeltype['name'] . ($angeltype['restricted'] ? ", restricted" : "") . ($angeltype['requires_driver_license'] ? ", requires driver license" : ""));
|
||||
return $angeltype;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to create angeltype.");
|
||||
}
|
||||
$angeltype['id'] = sql_id();
|
||||
engelsystem_log("Created angeltype: " . $angeltype['name'] . ($angeltype['restricted'] ? ", restricted" : "") . ($angeltype['requires_driver_license'] ? ", requires driver license" : ""));
|
||||
return $angeltype;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,26 +154,27 @@ function AngelType_create($angeltype) {
|
|||
* The angeltype the name is for
|
||||
* @return ValidationResult result and validated name
|
||||
*/
|
||||
function AngelType_validate_name($name, $angeltype) {
|
||||
$name = strip_item($name);
|
||||
if ($name == "") {
|
||||
return new ValidationResult(false, "");
|
||||
}
|
||||
if ($angeltype != null && isset($angeltype['id'])) {
|
||||
$valid = sql_num_query("
|
||||
function AngelType_validate_name($name, $angeltype)
|
||||
{
|
||||
$name = strip_item($name);
|
||||
if ($name == "") {
|
||||
return new ValidationResult(false, "");
|
||||
}
|
||||
if ($angeltype != null && isset($angeltype['id'])) {
|
||||
$valid = sql_num_query("
|
||||
SELECT *
|
||||
FROM `AngelTypes`
|
||||
WHERE `name`='" . sql_escape($name) . "'
|
||||
AND NOT `id`='" . sql_escape($angeltype['id']) . "'
|
||||
LIMIT 1") == 0;
|
||||
return new ValidationResult($valid, $name);
|
||||
}
|
||||
$valid = sql_num_query("
|
||||
return new ValidationResult($valid, $name);
|
||||
}
|
||||
$valid = sql_num_query("
|
||||
SELECT `id`
|
||||
FROM `AngelTypes`
|
||||
WHERE `name`='" . sql_escape($name) . "'
|
||||
LIMIT 1") == 0;
|
||||
return new ValidationResult($valid, $name);
|
||||
return new ValidationResult($valid, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,8 +182,9 @@ function AngelType_validate_name($name, $angeltype) {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function AngelTypes_with_user($user) {
|
||||
$result = sql_select("
|
||||
function AngelTypes_with_user($user)
|
||||
{
|
||||
$result = sql_select("
|
||||
SELECT `AngelTypes`.*,
|
||||
`UserAngelTypes`.`id` as `user_angeltype_id`,
|
||||
`UserAngelTypes`.`confirm_user_id`,
|
||||
|
@ -185,35 +193,37 @@ function AngelTypes_with_user($user) {
|
|||
LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id`
|
||||
AND `UserAngelTypes`.`user_id`=" . $user['UID'] . "
|
||||
ORDER BY `name`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load angeltypes.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load angeltypes.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all angeltypes.
|
||||
*/
|
||||
function AngelTypes() {
|
||||
$result = sql_select("
|
||||
function AngelTypes()
|
||||
{
|
||||
$result = sql_select("
|
||||
SELECT *
|
||||
FROM `AngelTypes`
|
||||
ORDER BY `name`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load angeltypes.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load angeltypes.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns AngelType id array
|
||||
*/
|
||||
function AngelType_ids() {
|
||||
$result = sql_select("SELECT `id` FROM `AngelTypes`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load angeltypes.");
|
||||
}
|
||||
return select_array($result, 'id', 'id');
|
||||
function AngelType_ids()
|
||||
{
|
||||
$result = sql_select("SELECT `id` FROM `AngelTypes`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load angeltypes.");
|
||||
}
|
||||
return select_array($result, 'id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,15 +232,14 @@ function AngelType_ids() {
|
|||
* @param $angeltype_id angelType
|
||||
* ID
|
||||
*/
|
||||
function AngelType($angeltype_id) {
|
||||
$angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "'");
|
||||
if ($angelType_source === false) {
|
||||
engelsystem_error("Unable to load angeltype.");
|
||||
}
|
||||
if (count($angelType_source) > 0) {
|
||||
return $angelType_source[0];
|
||||
}
|
||||
return null;
|
||||
function AngelType($angeltype_id)
|
||||
{
|
||||
$angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "'");
|
||||
if ($angelType_source === false) {
|
||||
engelsystem_error("Unable to load angeltype.");
|
||||
}
|
||||
if (count($angelType_source) > 0) {
|
||||
return $angelType_source[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
/**
|
||||
* Get event config.
|
||||
*/
|
||||
function EventConfig() {
|
||||
$event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1");
|
||||
if ($event_config === false) {
|
||||
engelsystem_error("Unable to load event config.");
|
||||
return false;
|
||||
}
|
||||
if (count($event_config) > 0) {
|
||||
return $event_config[0];
|
||||
}
|
||||
return null;
|
||||
function EventConfig()
|
||||
{
|
||||
$event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1");
|
||||
if ($event_config === false) {
|
||||
engelsystem_error("Unable to load event config.");
|
||||
return false;
|
||||
}
|
||||
if (count($event_config) > 0) {
|
||||
return $event_config[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,17 +26,18 @@ function EventConfig() {
|
|||
* @param int $teardown_end_date
|
||||
* @param string $event_welcome_msg
|
||||
*/
|
||||
function EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg) {
|
||||
if (EventConfig() == null) {
|
||||
return sql_query("INSERT INTO `EventConfig` SET
|
||||
function EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg)
|
||||
{
|
||||
if (EventConfig() == null) {
|
||||
return sql_query("INSERT INTO `EventConfig` SET
|
||||
`event_name`=" . sql_null($event_name) . ",
|
||||
`buildup_start_date`=" . sql_null($buildup_start_date) . ",
|
||||
`event_start_date`=" . sql_null($event_start_date) . ",
|
||||
`event_end_date`=" . sql_null($event_end_date) . ",
|
||||
`teardown_end_date`=" . sql_null($teardown_end_date) . ",
|
||||
`event_welcome_msg`=" . sql_null($event_welcome_msg));
|
||||
}
|
||||
return sql_query("UPDATE `EventConfig` SET
|
||||
}
|
||||
return sql_query("UPDATE `EventConfig` SET
|
||||
`event_name`=" . sql_null($event_name) . ",
|
||||
`buildup_start_date`=" . sql_null($buildup_start_date) . ",
|
||||
`event_start_date`=" . sql_null($event_start_date) . ",
|
||||
|
@ -43,4 +45,3 @@ function EventConfig_update($event_name, $buildup_start_date, $event_start_date,
|
|||
`teardown_end_date`=" . sql_null($teardown_end_date) . ",
|
||||
`event_welcome_msg`=" . sql_null($event_welcome_msg));
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -7,32 +7,34 @@
|
|||
* @param $message Log
|
||||
* Message
|
||||
*/
|
||||
function LogEntry_create($nick, $message) {
|
||||
return sql_query("INSERT INTO `LogEntries` SET `timestamp`='" . sql_escape(time()) . "', `nick`='" . sql_escape($nick) . "', `message`='" . sql_escape($message) . "'");
|
||||
function LogEntry_create($nick, $message)
|
||||
{
|
||||
return sql_query("INSERT INTO `LogEntries` SET `timestamp`='" . sql_escape(time()) . "', `nick`='" . sql_escape($nick) . "', `message`='" . sql_escape($message) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns log entries with maximum count of 10000.
|
||||
*/
|
||||
function LogEntries() {
|
||||
return sql_select("SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000");
|
||||
function LogEntries()
|
||||
{
|
||||
return sql_select("SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns log entries filtered by a keyword
|
||||
*/
|
||||
function LogEntries_filter($keyword) {
|
||||
if ($keyword == "") {
|
||||
return LogEntries();
|
||||
}
|
||||
return sql_select("SELECT * FROM `LogEntries` WHERE `nick` LIKE '%" . sql_escape($keyword) . "%' OR `message` LIKE '%" . sql_escape($keyword) . "%' ORDER BY `timestamp` DESC");
|
||||
function LogEntries_filter($keyword)
|
||||
{
|
||||
if ($keyword == "") {
|
||||
return LogEntries();
|
||||
}
|
||||
return sql_select("SELECT * FROM `LogEntries` WHERE `nick` LIKE '%" . sql_escape($keyword) . "%' OR `message` LIKE '%" . sql_escape($keyword) . "%' ORDER BY `timestamp` DESC");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all log entries.
|
||||
*/
|
||||
function LogEntries_clear_all() {
|
||||
return sql_query("TRUNCATE `LogEntries`");
|
||||
function LogEntries_clear_all()
|
||||
{
|
||||
return sql_query("TRUNCATE `LogEntries`");
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
/**
|
||||
* Returns Message id array
|
||||
*/
|
||||
function Message_ids() {
|
||||
return sql_select("SELECT `id` FROM `Messages`");
|
||||
function Message_ids()
|
||||
{
|
||||
return sql_select("SELECT `id` FROM `Messages`");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,15 +14,16 @@ function Message_ids() {
|
|||
* @param $message_id message
|
||||
* ID
|
||||
*/
|
||||
function Message($message_id) {
|
||||
$message_source = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
|
||||
if ($message_source === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($message_source) > 0) {
|
||||
return $message_source[0];
|
||||
}
|
||||
return null;
|
||||
function Message($message_id)
|
||||
{
|
||||
$message_source = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
|
||||
if ($message_source === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($message_source) > 0) {
|
||||
return $message_source[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,18 +36,17 @@ function Message($message_id) {
|
|||
* @param $text Text
|
||||
* of Message
|
||||
*/
|
||||
function Message_send($receiver_user_id, $text) {
|
||||
global $user;
|
||||
function Message_send($receiver_user_id, $text)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($text));
|
||||
$receiver_user_id = preg_replace("/([^0-9]{1,})/ui", '', strip_tags($receiver_user_id));
|
||||
$text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($text));
|
||||
$receiver_user_id = preg_replace("/([^0-9]{1,})/ui", '', strip_tags($receiver_user_id));
|
||||
|
||||
if (($text != "" && is_numeric($receiver_user_id)) && (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($receiver_user_id) . "' AND NOT `UID`='" . sql_escape($user['UID']) . "' LIMIT 1") > 0)) {
|
||||
sql_query("INSERT INTO `Messages` SET `Datum`='" . sql_escape(time()) . "', `SUID`='" . sql_escape($user['UID']) . "', `RUID`='" . sql_escape($receiver_user_id) . "', `Text`='" . sql_escape($text) . "'");
|
||||
return true;
|
||||
}
|
||||
if (($text != "" && is_numeric($receiver_user_id)) && (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($receiver_user_id) . "' AND NOT `UID`='" . sql_escape($user['UID']) . "' LIMIT 1") > 0)) {
|
||||
sql_query("INSERT INTO `Messages` SET `Datum`='" . sql_escape(time()) . "', `SUID`='" . sql_escape($user['UID']) . "', `RUID`='" . sql_escape($receiver_user_id) . "', `Text`='" . sql_escape($text) . "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
|
@ -16,17 +16,18 @@
|
|||
* @param int $count
|
||||
* How many angels are needed?
|
||||
*/
|
||||
function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count) {
|
||||
$result = sql_query("
|
||||
function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count)
|
||||
{
|
||||
$result = sql_query("
|
||||
INSERT INTO `NeededAngelTypes` SET
|
||||
`shift_id`=" . sql_null($shift_id) . ",
|
||||
`angel_type_id`='" . sql_escape($angeltype_id) . "',
|
||||
`room_id`=" . sql_null($room_id) . ",
|
||||
`count`='" . sql_escape($count) . "'");
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,8 +36,9 @@ function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count) {
|
|||
* @param int $shift_id
|
||||
* id of the shift
|
||||
*/
|
||||
function NeededAngelTypes_delete_by_shift($shift_id) {
|
||||
return sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`='" . sql_escape($shift_id) . "'");
|
||||
function NeededAngelTypes_delete_by_shift($shift_id)
|
||||
{
|
||||
return sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`='" . sql_escape($shift_id) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,8 +47,9 @@ function NeededAngelTypes_delete_by_shift($shift_id) {
|
|||
* @param int $room_id
|
||||
* id of the room
|
||||
*/
|
||||
function NeededAngelTypes_delete_by_room($room_id) {
|
||||
return sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
|
||||
function NeededAngelTypes_delete_by_room($room_id)
|
||||
{
|
||||
return sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,8 +58,9 @@ function NeededAngelTypes_delete_by_room($room_id) {
|
|||
* @param int $shiftID
|
||||
* id of shift
|
||||
*/
|
||||
function NeededAngelTypes_by_shift($shiftId) {
|
||||
$needed_angeltypes_source = sql_select("
|
||||
function NeededAngelTypes_by_shift($shiftId)
|
||||
{
|
||||
$needed_angeltypes_source = sql_select("
|
||||
SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
FROM `NeededAngelTypes`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id`
|
||||
|
@ -64,13 +68,13 @@ function NeededAngelTypes_by_shift($shiftId) {
|
|||
AND `count` > 0
|
||||
ORDER BY `room_id` DESC
|
||||
");
|
||||
if ($needed_angeltypes_source === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes.");
|
||||
}
|
||||
if ($needed_angeltypes_source === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes.");
|
||||
}
|
||||
|
||||
// Use settings from room
|
||||
if (count($needed_angeltypes_source) == 0) {
|
||||
$needed_angeltypes_source = sql_select("
|
||||
$needed_angeltypes_source = sql_select("
|
||||
SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted`
|
||||
FROM `NeededAngelTypes`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id`
|
||||
|
@ -79,27 +83,25 @@ function NeededAngelTypes_by_shift($shiftId) {
|
|||
AND `count` > 0
|
||||
ORDER BY `room_id` DESC
|
||||
");
|
||||
if ($needed_angeltypes_source === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes.");
|
||||
}
|
||||
}
|
||||
|
||||
$shift_entries = ShiftEntries_by_shift($shiftId);
|
||||
$needed_angeltypes = [];
|
||||
foreach ($needed_angeltypes_source as $angeltype) {
|
||||
$angeltype['shift_entries'] = [];
|
||||
$angeltype['taken'] = 0;
|
||||
foreach ($shift_entries as $shift_entry) {
|
||||
if ($shift_entry['TID'] == $angeltype['angel_type_id'] && $shift_entry['freeloaded'] == 0) {
|
||||
$angeltype['taken'] ++;
|
||||
$angeltype['shift_entries'][] = $shift_entry;
|
||||
if ($needed_angeltypes_source === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes.");
|
||||
}
|
||||
}
|
||||
|
||||
$needed_angeltypes[] = $angeltype;
|
||||
}
|
||||
|
||||
return $needed_angeltypes;
|
||||
}
|
||||
$shift_entries = ShiftEntries_by_shift($shiftId);
|
||||
$needed_angeltypes = [];
|
||||
foreach ($needed_angeltypes_source as $angeltype) {
|
||||
$angeltype['shift_entries'] = [];
|
||||
$angeltype['taken'] = 0;
|
||||
foreach ($shift_entries as $shift_entry) {
|
||||
if ($shift_entry['TID'] == $angeltype['angel_type_id'] && $shift_entry['freeloaded'] == 0) {
|
||||
$angeltype['taken'] ++;
|
||||
$angeltype['shift_entries'][] = $shift_entry;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
$needed_angeltypes[] = $angeltype;
|
||||
}
|
||||
|
||||
return $needed_angeltypes;
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
* returns a list of rooms.
|
||||
* @param boolean $show_all returns also hidden rooms when true
|
||||
*/
|
||||
function Rooms($show_all = false) {
|
||||
return sql_select("SELECT * FROM `Room`" . ($show_all ? "" : " WHERE `show`='Y'") . " ORDER BY `Name`");
|
||||
function Rooms($show_all = false)
|
||||
{
|
||||
return sql_select("SELECT * FROM `Room`" . ($show_all ? "" : " WHERE `show`='Y'") . " ORDER BY `Name`");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,8 +14,9 @@ function Rooms($show_all = false) {
|
|||
*
|
||||
* @param int $room_id
|
||||
*/
|
||||
function Room_delete($room_id) {
|
||||
return sql_query("DELETE FROM `Room` WHERE `RID`=" . sql_escape($room_id));
|
||||
function Room_delete($room_id)
|
||||
{
|
||||
return sql_query("DELETE FROM `Room` WHERE `RID`=" . sql_escape($room_id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,17 +29,18 @@ function Room_delete($room_id) {
|
|||
* @param boolean $public
|
||||
* Is the room visible for angels?
|
||||
*/
|
||||
function Room_create($name, $from_frab, $public) {
|
||||
$result = sql_query("
|
||||
function Room_create($name, $from_frab, $public)
|
||||
{
|
||||
$result = sql_query("
|
||||
INSERT INTO `Room` SET
|
||||
`Name`='" . sql_escape($name) . "',
|
||||
`FromPentabarf`='" . sql_escape($from_frab ? 'Y' : '') . "',
|
||||
`show`='" . sql_escape($public ? 'Y' : '') . "',
|
||||
`Number`=0");
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,16 +48,15 @@ function Room_create($name, $from_frab, $public) {
|
|||
*
|
||||
* @param $room_id RID
|
||||
*/
|
||||
function Room($room_id) {
|
||||
$room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($room_id) . "' AND `show` = 'Y'");
|
||||
function Room($room_id)
|
||||
{
|
||||
$room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($room_id) . "' AND `show` = 'Y'");
|
||||
|
||||
if ($room_source === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($room_source) > 0) {
|
||||
return $room_source[0];
|
||||
}
|
||||
return null;
|
||||
if ($room_source === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($room_source) > 0) {
|
||||
return $room_source[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
* Returns an array with the attributes of shift entries.
|
||||
* FIXME! Needs entity object.
|
||||
*/
|
||||
function ShiftEntry_new() {
|
||||
return [
|
||||
function ShiftEntry_new()
|
||||
{
|
||||
return [
|
||||
'id' => null,
|
||||
'SID' => null,
|
||||
'TID' => null,
|
||||
|
@ -19,15 +20,17 @@ function ShiftEntry_new() {
|
|||
/**
|
||||
* Counts all freeloaded shifts.
|
||||
*/
|
||||
function ShiftEntries_freeleaded_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
|
||||
function ShiftEntries_freeleaded_count()
|
||||
{
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
|
||||
}
|
||||
|
||||
/**
|
||||
* List users subsribed to a given shift.
|
||||
*/
|
||||
function ShiftEntries_by_shift($shift_id) {
|
||||
return sql_select("
|
||||
function ShiftEntries_by_shift($shift_id)
|
||||
{
|
||||
return sql_select("
|
||||
SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
|
||||
FROM `ShiftEntry`
|
||||
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
|
||||
|
@ -40,9 +43,10 @@ function ShiftEntries_by_shift($shift_id) {
|
|||
*
|
||||
* @param ShiftEntry $shift_entry
|
||||
*/
|
||||
function ShiftEntry_create($shift_entry) {
|
||||
mail_shift_assign(User($shift_entry['UID']), Shift($shift_entry['SID']));
|
||||
return sql_query("INSERT INTO `ShiftEntry` SET
|
||||
function ShiftEntry_create($shift_entry)
|
||||
{
|
||||
mail_shift_assign(User($shift_entry['UID']), Shift($shift_entry['SID']));
|
||||
return sql_query("INSERT INTO `ShiftEntry` SET
|
||||
`SID`='" . sql_escape($shift_entry['SID']) . "',
|
||||
`TID`='" . sql_escape($shift_entry['TID']) . "',
|
||||
`UID`='" . sql_escape($shift_entry['UID']) . "',
|
||||
|
@ -54,8 +58,9 @@ function ShiftEntry_create($shift_entry) {
|
|||
/**
|
||||
* Update a shift entry.
|
||||
*/
|
||||
function ShiftEntry_update($shift_entry) {
|
||||
return sql_query("UPDATE `ShiftEntry` SET
|
||||
function ShiftEntry_update($shift_entry)
|
||||
{
|
||||
return sql_query("UPDATE `ShiftEntry` SET
|
||||
`Comment`='" . sql_escape($shift_entry['Comment']) . "',
|
||||
`freeload_comment`='" . sql_escape($shift_entry['freeload_comment']) . "',
|
||||
`freeloaded`=" . sql_bool($shift_entry['freeloaded']) . "
|
||||
|
@ -65,24 +70,26 @@ function ShiftEntry_update($shift_entry) {
|
|||
/**
|
||||
* Get a shift entry.
|
||||
*/
|
||||
function ShiftEntry($shift_entry_id) {
|
||||
$shift_entry = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'");
|
||||
if ($shift_entry === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($shift_entry) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $shift_entry[0];
|
||||
function ShiftEntry($shift_entry_id)
|
||||
{
|
||||
$shift_entry = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'");
|
||||
if ($shift_entry === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($shift_entry) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $shift_entry[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a shift entry.
|
||||
*/
|
||||
function ShiftEntry_delete($shift_entry_id) {
|
||||
$shift_entry = ShiftEntry($shift_entry_id);
|
||||
mail_shift_removed(User($shift_entry['UID']), Shift($shift_entry['SID']));
|
||||
return sql_query("DELETE FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'");
|
||||
function ShiftEntry_delete($shift_entry_id)
|
||||
{
|
||||
$shift_entry = ShiftEntry($shift_entry_id);
|
||||
mail_shift_removed(User($shift_entry['UID']), Shift($shift_entry['SID']));
|
||||
return sql_query("DELETE FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,8 +97,9 @@ function ShiftEntry_delete($shift_entry_id) {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function ShiftEntries_upcoming_for_user($user) {
|
||||
return sql_select("
|
||||
function ShiftEntries_upcoming_for_user($user)
|
||||
{
|
||||
return sql_select("
|
||||
SELECT *
|
||||
FROM `ShiftEntry`
|
||||
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)
|
||||
|
@ -107,8 +115,9 @@ function ShiftEntries_upcoming_for_user($user) {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function ShiftEntries_finished_by_user($user) {
|
||||
return sql_select("
|
||||
function ShiftEntries_finished_by_user($user)
|
||||
{
|
||||
return sql_select("
|
||||
SELECT *
|
||||
FROM `ShiftEntry`
|
||||
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)
|
||||
|
@ -126,27 +135,27 @@ function ShiftEntries_finished_by_user($user) {
|
|||
* @param int $shift_id
|
||||
* @param int $angeltype_id
|
||||
*/
|
||||
function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) {
|
||||
$result = sql_select("
|
||||
function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id)
|
||||
{
|
||||
$result = sql_select("
|
||||
SELECT *
|
||||
FROM `ShiftEntry`
|
||||
WHERE `SID`=" . sql_escape($shift_id) . "
|
||||
AND `TID`=" . sql_escape($angeltype_id) . "
|
||||
");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shift entries.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shift entries.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all freeloaded shifts for given user.
|
||||
*/
|
||||
function ShiftEntries_freeloaded_by_user($user) {
|
||||
return sql_select("SELECT *
|
||||
function ShiftEntries_freeloaded_by_user($user)
|
||||
{
|
||||
return sql_select("SELECT *
|
||||
FROM `ShiftEntry`
|
||||
WHERE `freeloaded` = 1
|
||||
AND `UID`=" . sql_escape($user['UID']));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,7 +6,8 @@ namespace Engelsystem;
|
|||
* BO to represent if there are free slots on a shift for a given angeltype
|
||||
* and if signup for a given user is possible (or not, because of collisions, etc.)
|
||||
*/
|
||||
class ShiftSignupState {
|
||||
class ShiftSignupState
|
||||
{
|
||||
|
||||
/**
|
||||
* Shift has free places
|
||||
|
@ -43,14 +44,15 @@ class ShiftSignupState {
|
|||
*/
|
||||
const SIGNED_UP = 'SIGNED_UP';
|
||||
|
||||
private $state;
|
||||
private $state;
|
||||
|
||||
private $freeEntries;
|
||||
private $freeEntries;
|
||||
|
||||
public function __construct($state, $free_entries) {
|
||||
$this->state = $state;
|
||||
$this->freeEntries = $free_entries;
|
||||
}
|
||||
public function __construct($state, $free_entries)
|
||||
{
|
||||
$this->state = $state;
|
||||
$this->freeEntries = $free_entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine this state with another state from the same shift.
|
||||
|
@ -58,16 +60,18 @@ class ShiftSignupState {
|
|||
* @param ShiftSignupState $shiftSignupState
|
||||
* The other state to combine
|
||||
*/
|
||||
public function combineWith(ShiftSignupState $shiftSignupState) {
|
||||
$this->freeEntries += $shiftSignupState->getFreeEntries();
|
||||
public function combineWith(ShiftSignupState $shiftSignupState)
|
||||
{
|
||||
$this->freeEntries += $shiftSignupState->getFreeEntries();
|
||||
|
||||
if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) {
|
||||
$this->state = $shiftSignupState->state;
|
||||
}
|
||||
if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) {
|
||||
$this->state = $shiftSignupState->state;
|
||||
}
|
||||
}
|
||||
|
||||
private function valueForState($state) {
|
||||
switch ($state) {
|
||||
private function valueForState($state)
|
||||
{
|
||||
switch ($state) {
|
||||
case ShiftSignupState::SHIFT_ENDED:
|
||||
return 100;
|
||||
|
||||
|
@ -85,33 +89,34 @@ class ShiftSignupState {
|
|||
case ShiftSignupState::ADMIN:
|
||||
return 60;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if signup is allowed
|
||||
*/
|
||||
public function isSignupAllowed() {
|
||||
switch ($this->state) {
|
||||
public function isSignupAllowed()
|
||||
{
|
||||
switch ($this->state) {
|
||||
case ShiftSignupState::FREE:
|
||||
case ShiftSignupState::ADMIN:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shift signup state
|
||||
*/
|
||||
public function getState() {
|
||||
return $this->state;
|
||||
public function getState()
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many places are free in this shift for the angeltype?
|
||||
*/
|
||||
public function getFreeEntries() {
|
||||
return $this->freeEntries;
|
||||
public function getFreeEntries()
|
||||
{
|
||||
return $this->freeEntries;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -4,8 +4,9 @@
|
|||
* Delete a shift type.
|
||||
* @param int $shifttype_id
|
||||
*/
|
||||
function ShiftType_delete($shifttype_id) {
|
||||
return sql_query("DELETE FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
|
||||
function ShiftType_delete($shifttype_id)
|
||||
{
|
||||
return sql_query("DELETE FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,8 +17,9 @@ function ShiftType_delete($shifttype_id) {
|
|||
* @param int $angeltype_id
|
||||
* @param string $description
|
||||
*/
|
||||
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) {
|
||||
return sql_query("UPDATE `ShiftTypes` SET
|
||||
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
|
||||
{
|
||||
return sql_query("UPDATE `ShiftTypes` SET
|
||||
`name`='" . sql_escape($name) . "',
|
||||
`angeltype_id`=" . sql_null($angeltype_id) . ",
|
||||
`description`='" . sql_escape($description) . "'
|
||||
|
@ -32,15 +34,16 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) {
|
|||
* @param string $description
|
||||
* @return new shifttype id
|
||||
*/
|
||||
function ShiftType_create($name, $angeltype_id, $description) {
|
||||
$result = sql_query("INSERT INTO `ShiftTypes` SET
|
||||
function ShiftType_create($name, $angeltype_id, $description)
|
||||
{
|
||||
$result = sql_query("INSERT INTO `ShiftTypes` SET
|
||||
`name`='" . sql_escape($name) . "',
|
||||
`angeltype_id`=" . sql_null($angeltype_id) . ",
|
||||
`description`='" . sql_escape($description) . "'");
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,22 +51,22 @@ function ShiftType_create($name, $angeltype_id, $description) {
|
|||
*
|
||||
* @param int $shifttype_id
|
||||
*/
|
||||
function ShiftType($shifttype_id) {
|
||||
$shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shift type.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
return null;
|
||||
}
|
||||
return $shifttype[0];
|
||||
function ShiftType($shifttype_id)
|
||||
{
|
||||
$shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shift type.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
return null;
|
||||
}
|
||||
return $shifttype[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all shift types.
|
||||
*/
|
||||
function ShiftTypes() {
|
||||
return sql_select("SELECT * FROM `ShiftTypes` ORDER BY `name`");
|
||||
function ShiftTypes()
|
||||
{
|
||||
return sql_select("SELECT * FROM `ShiftTypes` ORDER BY `name`");
|
||||
}
|
||||
|
||||
?>
|
|
@ -7,7 +7,8 @@ namespace Engelsystem;
|
|||
*
|
||||
* @author msquare
|
||||
*/
|
||||
class ShiftsFilter {
|
||||
class ShiftsFilter
|
||||
{
|
||||
|
||||
/**
|
||||
* How long can the time interval be?
|
||||
|
@ -32,90 +33,101 @@ class ShiftsFilter {
|
|||
*/
|
||||
private $userShiftsAdmin;
|
||||
|
||||
private $filled = [];
|
||||
private $filled = [];
|
||||
|
||||
private $rooms = [];
|
||||
private $rooms = [];
|
||||
|
||||
private $types = [];
|
||||
private $types = [];
|
||||
|
||||
private $startTime = null;
|
||||
private $startTime = null;
|
||||
|
||||
private $endTime = null;
|
||||
private $endTime = null;
|
||||
|
||||
public function __construct($user_shifts_admin, $rooms, $types) {
|
||||
$this->user_shifts_admin = $user_shifts_admin;
|
||||
$this->rooms = $rooms;
|
||||
$this->types = $types;
|
||||
public function __construct($user_shifts_admin, $rooms, $types)
|
||||
{
|
||||
$this->user_shifts_admin = $user_shifts_admin;
|
||||
$this->rooms = $rooms;
|
||||
$this->types = $types;
|
||||
|
||||
$this->filled = [
|
||||
$this->filled = [
|
||||
ShiftsFilter::FILLED_FREE
|
||||
];
|
||||
|
||||
if ($user_shifts_admin) {
|
||||
$this->filled[] = ShiftsFilter::FILLED_FILLED;
|
||||
if ($user_shifts_admin) {
|
||||
$this->filled[] = ShiftsFilter::FILLED_FILLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getStartTime() {
|
||||
return $this->startTime;
|
||||
}
|
||||
|
||||
public function setStartTime($startTime) {
|
||||
$this->startTime = $startTime;
|
||||
}
|
||||
|
||||
public function getEndTime() {
|
||||
return $this->endTime;
|
||||
}
|
||||
|
||||
public function setEndTime($endTime) {
|
||||
if ($endTime - $this->startTime > ShiftsFilter::MAX_DURATION) {
|
||||
$endTime = $this->startTime + ShiftsFilter::MAX_DURATION;
|
||||
public function getStartTime()
|
||||
{
|
||||
return $this->startTime;
|
||||
}
|
||||
$this->endTime = $endTime;
|
||||
}
|
||||
|
||||
public function getTypes() {
|
||||
if (count($this->types) == 0) {
|
||||
return [
|
||||
public function setStartTime($startTime)
|
||||
{
|
||||
$this->startTime = $startTime;
|
||||
}
|
||||
|
||||
public function getEndTime()
|
||||
{
|
||||
return $this->endTime;
|
||||
}
|
||||
|
||||
public function setEndTime($endTime)
|
||||
{
|
||||
if ($endTime - $this->startTime > ShiftsFilter::MAX_DURATION) {
|
||||
$endTime = $this->startTime + ShiftsFilter::MAX_DURATION;
|
||||
}
|
||||
$this->endTime = $endTime;
|
||||
}
|
||||
|
||||
public function getTypes()
|
||||
{
|
||||
if (count($this->types) == 0) {
|
||||
return [
|
||||
0
|
||||
];
|
||||
}
|
||||
return $this->types;
|
||||
}
|
||||
return $this->types;
|
||||
}
|
||||
|
||||
public function setTypes($types) {
|
||||
$this->types = $types;
|
||||
}
|
||||
public function setTypes($types)
|
||||
{
|
||||
$this->types = $types;
|
||||
}
|
||||
|
||||
public function getRooms() {
|
||||
if (count($this->rooms) == 0) {
|
||||
return [
|
||||
public function getRooms()
|
||||
{
|
||||
if (count($this->rooms) == 0) {
|
||||
return [
|
||||
0
|
||||
];
|
||||
}
|
||||
return $this->rooms;
|
||||
}
|
||||
return $this->rooms;
|
||||
}
|
||||
|
||||
public function setRooms($rooms) {
|
||||
$this->rooms = $rooms;
|
||||
}
|
||||
public function setRooms($rooms)
|
||||
{
|
||||
$this->rooms = $rooms;
|
||||
}
|
||||
|
||||
public function isUserShiftsAdmin() {
|
||||
return $this->userShiftsAdmin;
|
||||
}
|
||||
public function isUserShiftsAdmin()
|
||||
{
|
||||
return $this->userShiftsAdmin;
|
||||
}
|
||||
|
||||
public function setUserShiftsAdmin($userShiftsAdmin) {
|
||||
$this->userShiftsAdmin = $userShiftsAdmin;
|
||||
}
|
||||
public function setUserShiftsAdmin($userShiftsAdmin)
|
||||
{
|
||||
$this->userShiftsAdmin = $userShiftsAdmin;
|
||||
}
|
||||
|
||||
public function getFilled() {
|
||||
return $this->filled;
|
||||
}
|
||||
public function getFilled()
|
||||
{
|
||||
return $this->filled;
|
||||
}
|
||||
|
||||
public function setFilled($filled) {
|
||||
$this->filled = $filled;
|
||||
}
|
||||
public function setFilled($filled)
|
||||
{
|
||||
$this->filled = $filled;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -2,16 +2,18 @@
|
|||
use Engelsystem\ShiftsFilter;
|
||||
use Engelsystem\ShiftSignupState;
|
||||
|
||||
function Shifts_by_room($room) {
|
||||
$result = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($room['RID']) . " ORDER BY `start`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shifts.");
|
||||
}
|
||||
return $result;
|
||||
function Shifts_by_room($room)
|
||||
{
|
||||
$result = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($room['RID']) . " ORDER BY `start`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shifts.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
||||
$SQL = "SELECT * FROM (
|
||||
function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$SQL = "SELECT * FROM (
|
||||
SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
|
||||
FROM `Shifts`
|
||||
JOIN `Room` USING (`RID`)
|
||||
|
@ -37,15 +39,16 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
|||
AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts
|
||||
|
||||
ORDER BY `start`";
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shifts by filter.");
|
||||
}
|
||||
return $result;
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shifts by filter.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
||||
$SQL = "SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$SQL = "SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
|
||||
|
@ -62,15 +65,16 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
|||
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
|
||||
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
|
||||
AND NOT `Shifts`.`PSID` IS NULL";
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes by filter.");
|
||||
}
|
||||
return $result;
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes by filter.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) {
|
||||
$result = sql_select("SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
|
||||
{
|
||||
$result = sql_select("SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
|
||||
FROM `Shifts`
|
||||
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
|
||||
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
|
||||
|
@ -87,28 +91,29 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) {
|
|||
WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . "
|
||||
AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . "
|
||||
AND NOT `Shifts`.`PSID` IS NULL");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes by filter.");
|
||||
}
|
||||
if (count($result) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $result[0];
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load needed angeltypes by filter.");
|
||||
}
|
||||
if (count($result) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
||||
$SQL = "SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
|
||||
function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$SQL = "SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
|
||||
FROM `Shifts`
|
||||
JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID`
|
||||
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
|
||||
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
|
||||
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
|
||||
ORDER BY `Shifts`.`start`";
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shift entries by filter.");
|
||||
}
|
||||
return $result;
|
||||
$result = sql_select($SQL);
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load shift entries by filter.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,28 +122,30 @@ function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
|||
* @param Shift $shift
|
||||
* @param array<Shift> $shifts
|
||||
*/
|
||||
function Shift_collides($shift, $shifts) {
|
||||
foreach ($shifts as $other_shift) {
|
||||
if ($shift['SID'] != $other_shift['SID']) {
|
||||
if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) {
|
||||
return true;
|
||||
}
|
||||
function Shift_collides($shift, $shifts)
|
||||
{
|
||||
foreach ($shifts as $other_shift) {
|
||||
if ($shift['SID'] != $other_shift['SID']) {
|
||||
if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of needed angels/free shift entries for an angeltype.
|
||||
*/
|
||||
function Shift_free_entries($needed_angeltype, $shift_entries) {
|
||||
$taken = 0;
|
||||
foreach ($shift_entries as $shift_entry) {
|
||||
if ($shift_entry['freeloaded'] == 0) {
|
||||
$taken ++;
|
||||
function Shift_free_entries($needed_angeltype, $shift_entries)
|
||||
{
|
||||
$taken = 0;
|
||||
foreach ($shift_entries as $shift_entry) {
|
||||
if ($shift_entry['freeloaded'] == 0) {
|
||||
$taken ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return max(0, $needed_angeltype['count'] - $taken);
|
||||
return max(0, $needed_angeltype['count'] - $taken);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,55 +160,56 @@ function Shift_free_entries($needed_angeltype, $shift_entries) {
|
|||
* @param boolean $angeltype_supporter
|
||||
* True, if the user has angeltype supporter rights for the angeltype, which enables him to sign somebody up for the shift.
|
||||
*/
|
||||
function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries) {
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries)
|
||||
{
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
|
||||
if ($user['Gekommen'] == 0) {
|
||||
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
|
||||
}
|
||||
|
||||
if ($user_shifts == null) {
|
||||
$user_shifts = Shifts_by_user($user);
|
||||
}
|
||||
|
||||
$signed_up = false;
|
||||
foreach ($user_shifts as $user_shift) {
|
||||
if ($user_shift['SID'] == $shift['SID']) {
|
||||
$signed_up = true;
|
||||
break;
|
||||
if ($user['Gekommen'] == 0) {
|
||||
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
|
||||
}
|
||||
}
|
||||
|
||||
if ($signed_up) {
|
||||
// you cannot join if you already singed up for this shift
|
||||
if ($user_shifts == null) {
|
||||
$user_shifts = Shifts_by_user($user);
|
||||
}
|
||||
|
||||
$signed_up = false;
|
||||
foreach ($user_shifts as $user_shift) {
|
||||
if ($user_shift['SID'] == $shift['SID']) {
|
||||
$signed_up = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($signed_up) {
|
||||
// you cannot join if you already singed up for this shift
|
||||
return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries);
|
||||
}
|
||||
}
|
||||
|
||||
if (time() > $shift['start']) {
|
||||
// you can only join if the shift is in future
|
||||
if (time() > $shift['start']) {
|
||||
// you can only join if the shift is in future
|
||||
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
|
||||
}
|
||||
if ($free_entries == 0) {
|
||||
// you cannot join if shift is full
|
||||
}
|
||||
if ($free_entries == 0) {
|
||||
// you cannot join if shift is full
|
||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user_angeltype == null) {
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
}
|
||||
if ($user_angeltype == null) {
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
}
|
||||
|
||||
if ($user_angeltype == null || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) || ($angeltype['restricted'] == 1 && $user_angeltype != null && ! isset($user_angeltype['confirm_user_id']))) {
|
||||
// you cannot join if user is not of this angel type
|
||||
if ($user_angeltype == null || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) || ($angeltype['restricted'] == 1 && $user_angeltype != null && ! isset($user_angeltype['confirm_user_id']))) {
|
||||
// you cannot join if user is not of this angel type
|
||||
// you cannot join if you are not confirmed
|
||||
// you cannot join if angeltype has no self signup
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries);
|
||||
}
|
||||
}
|
||||
|
||||
if (Shift_collides($shift, $user_shifts)) {
|
||||
// you cannot join if user alread joined a parallel or this shift
|
||||
if (Shift_collides($shift, $user_shifts)) {
|
||||
// you cannot join if user alread joined a parallel or this shift
|
||||
return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries);
|
||||
}
|
||||
}
|
||||
|
||||
// Hooray, shift is free for you!
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
|
@ -210,13 +218,14 @@ function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype,
|
|||
/**
|
||||
* Check if an angeltype supporter can sign up a user to a shift.
|
||||
*/
|
||||
function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries) {
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
if ($free_entries == 0) {
|
||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
||||
}
|
||||
function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries)
|
||||
{
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
if ($free_entries == 0) {
|
||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
||||
}
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,15 +236,16 @@ function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype,
|
|||
* @param AngelType $angeltype
|
||||
* The angeltype to which the user wants to sign up
|
||||
*/
|
||||
function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries) {
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries)
|
||||
{
|
||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||
|
||||
if ($free_entries == 0) {
|
||||
// User shift admins may join anybody in every shift
|
||||
if ($free_entries == 0) {
|
||||
// User shift admins may join anybody in every shift
|
||||
return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
|
||||
}
|
||||
}
|
||||
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,49 +258,53 @@ function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entrie
|
|||
* @param array<Shift> $user_shifts
|
||||
* List of the users shifts
|
||||
*/
|
||||
function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries) {
|
||||
global $user, $privileges;
|
||||
function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries)
|
||||
{
|
||||
global $user, $privileges;
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries);
|
||||
}
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries);
|
||||
}
|
||||
|
||||
if (in_array('shiftentry_edit_angeltype_supporter', $privileges) && User_is_AngelType_supporter($user, $angeltype)) {
|
||||
return Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries);
|
||||
}
|
||||
if (in_array('shiftentry_edit_angeltype_supporter', $privileges) && User_is_AngelType_supporter($user, $angeltype)) {
|
||||
return Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries);
|
||||
}
|
||||
|
||||
return Shift_signup_allowed_angel($signup_user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries);
|
||||
return Shift_signup_allowed_angel($signup_user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a shift by its external id.
|
||||
*/
|
||||
function Shift_delete_by_psid($shift_psid) {
|
||||
return sql_query("DELETE FROM `Shifts` WHERE `PSID`='" . sql_escape($shift_psid) . "'");
|
||||
function Shift_delete_by_psid($shift_psid)
|
||||
{
|
||||
return sql_query("DELETE FROM `Shifts` WHERE `PSID`='" . sql_escape($shift_psid) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a shift.
|
||||
*/
|
||||
function Shift_delete($shift_id) {
|
||||
mail_shift_delete(Shift($shift_id));
|
||||
function Shift_delete($shift_id)
|
||||
{
|
||||
mail_shift_delete(Shift($shift_id));
|
||||
|
||||
$result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift.');
|
||||
}
|
||||
return $result;
|
||||
$result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift.');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a shift.
|
||||
*/
|
||||
function Shift_update($shift) {
|
||||
global $user;
|
||||
$shift['name'] = ShiftType($shift['shifttype_id'])['name'];
|
||||
mail_shift_change(Shift($shift['SID']), $shift);
|
||||
function Shift_update($shift)
|
||||
{
|
||||
global $user;
|
||||
$shift['name'] = ShiftType($shift['shifttype_id'])['name'];
|
||||
mail_shift_change(Shift($shift['SID']), $shift);
|
||||
|
||||
return sql_query("UPDATE `Shifts` SET
|
||||
return sql_query("UPDATE `Shifts` SET
|
||||
`shifttype_id`='" . sql_escape($shift['shifttype_id']) . "',
|
||||
`start`='" . sql_escape($shift['start']) . "',
|
||||
`end`='" . sql_escape($shift['end']) . "',
|
||||
|
@ -306,16 +320,17 @@ function Shift_update($shift) {
|
|||
/**
|
||||
* Update a shift by its external id.
|
||||
*/
|
||||
function Shift_update_by_psid($shift) {
|
||||
$shift_source = sql_select("SELECT `SID` FROM `Shifts` WHERE `PSID`=" . $shift['PSID']);
|
||||
if ($shift_source === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($shift_source) == 0) {
|
||||
return null;
|
||||
}
|
||||
$shift['SID'] = $shift_source[0]['SID'];
|
||||
return Shift_update($shift);
|
||||
function Shift_update_by_psid($shift)
|
||||
{
|
||||
$shift_source = sql_select("SELECT `SID` FROM `Shifts` WHERE `PSID`=" . $shift['PSID']);
|
||||
if ($shift_source === false) {
|
||||
return false;
|
||||
}
|
||||
if (count($shift_source) == 0) {
|
||||
return null;
|
||||
}
|
||||
$shift['SID'] = $shift_source[0]['SID'];
|
||||
return Shift_update($shift);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -323,9 +338,10 @@ function Shift_update_by_psid($shift) {
|
|||
*
|
||||
* @return new shift id or false
|
||||
*/
|
||||
function Shift_create($shift) {
|
||||
global $user;
|
||||
$result = sql_query("INSERT INTO `Shifts` SET
|
||||
function Shift_create($shift)
|
||||
{
|
||||
global $user;
|
||||
$result = sql_query("INSERT INTO `Shifts` SET
|
||||
`shifttype_id`='" . sql_escape($shift['shifttype_id']) . "',
|
||||
`start`='" . sql_escape($shift['start']) . "',
|
||||
`end`='" . sql_escape($shift['end']) . "',
|
||||
|
@ -335,17 +351,18 @@ function Shift_create($shift) {
|
|||
`PSID`=" . sql_null($shift['PSID']) . ",
|
||||
`created_by_user_id`='" . sql_escape($user['UID']) . "',
|
||||
`created_at_timestamp`=" . time());
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return sql_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return users shifts.
|
||||
*/
|
||||
function Shifts_by_user($user, $include_freeload_comments = false) {
|
||||
$result = sql_select("
|
||||
function Shifts_by_user($user, $include_freeload_comments = false)
|
||||
{
|
||||
$result = sql_select("
|
||||
SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`,
|
||||
`ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`,
|
||||
" . ($include_freeload_comments ? "`ShiftEntry`.`freeload_comment`, " : "") . "
|
||||
|
@ -357,10 +374,10 @@ function Shifts_by_user($user, $include_freeload_comments = false) {
|
|||
WHERE `UID`='" . sql_escape($user['UID']) . "'
|
||||
ORDER BY `start`
|
||||
");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to load users shifts.');
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to load users shifts.');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -369,64 +386,64 @@ function Shifts_by_user($user, $include_freeload_comments = false) {
|
|||
* @param $shift_id Shift
|
||||
* ID
|
||||
*/
|
||||
function Shift($shift_id) {
|
||||
$shifts_source = sql_select("
|
||||
function Shift($shift_id)
|
||||
{
|
||||
$shifts_source = sql_select("
|
||||
SELECT `Shifts`.*, `ShiftTypes`.`name`
|
||||
FROM `Shifts`
|
||||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
WHERE `SID`='" . sql_escape($shift_id) . "'");
|
||||
$shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'");
|
||||
$shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'");
|
||||
|
||||
if ($shifts_source === false) {
|
||||
engelsystem_error('Unable to load shift.');
|
||||
}
|
||||
if ($shifts_source === false) {
|
||||
engelsystem_error('Unable to load shift.');
|
||||
}
|
||||
|
||||
if (empty($shifts_source)) {
|
||||
return null;
|
||||
}
|
||||
if (empty($shifts_source)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $shifts_source[0];
|
||||
$result = $shifts_source[0];
|
||||
|
||||
$result['ShiftEntry'] = $shiftsEntry_source;
|
||||
$result['NeedAngels'] = [];
|
||||
$result['ShiftEntry'] = $shiftsEntry_source;
|
||||
$result['NeedAngels'] = [];
|
||||
|
||||
$temp = NeededAngelTypes_by_shift($shift_id);
|
||||
foreach ($temp as $e) {
|
||||
$result['NeedAngels'][] = [
|
||||
$temp = NeededAngelTypes_by_shift($shift_id);
|
||||
foreach ($temp as $e) {
|
||||
$result['NeedAngels'][] = [
|
||||
'TID' => $e['angel_type_id'],
|
||||
'count' => $e['count'],
|
||||
'restricted' => $e['restricted'],
|
||||
'taken' => $e['taken']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all shifts with needed angeltypes and count of subscribed jobs.
|
||||
*/
|
||||
function Shifts() {
|
||||
$shifts_source = sql_select("
|
||||
function Shifts()
|
||||
{
|
||||
$shifts_source = sql_select("
|
||||
SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`RID`, `Room`.`Name` as `room_name`
|
||||
FROM `Shifts`
|
||||
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
||||
JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
|
||||
");
|
||||
if ($shifts_source === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($shifts_source as &$shift) {
|
||||
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
|
||||
if ($needed_angeltypes === false) {
|
||||
return false;
|
||||
if ($shifts_source === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$shift['angeltypes'] = $needed_angeltypes;
|
||||
}
|
||||
foreach ($shifts_source as &$shift) {
|
||||
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
|
||||
if ($needed_angeltypes === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $shifts_source;
|
||||
$shift['angeltypes'] = $needed_angeltypes;
|
||||
}
|
||||
|
||||
return $shifts_source;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -13,8 +13,9 @@
|
|||
* The angeltype to be checked
|
||||
* @return boolean
|
||||
*/
|
||||
function UserAngelType_exists($user, $angeltype) {
|
||||
return sql_num_query("
|
||||
function UserAngelType_exists($user, $angeltype)
|
||||
{
|
||||
return sql_num_query("
|
||||
SELECT `id`
|
||||
FROM `UserAngelTypes`
|
||||
WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "'
|
||||
|
@ -27,18 +28,19 @@ function UserAngelType_exists($user, $angeltype) {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function User_angeltypes($user) {
|
||||
$result = sql_select("
|
||||
function User_angeltypes($user)
|
||||
{
|
||||
$result = sql_select("
|
||||
SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter`
|
||||
FROM `UserAngelTypes`
|
||||
JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`
|
||||
WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "'
|
||||
");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load user angeltypes.");
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load user angeltypes.");
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,8 +48,9 @@ function User_angeltypes($user) {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function User_unconfirmed_AngelTypes($user) {
|
||||
$result = sql_select("
|
||||
function User_unconfirmed_AngelTypes($user)
|
||||
{
|
||||
$result = sql_select("
|
||||
SELECT
|
||||
`UserAngelTypes`.*,
|
||||
`AngelTypes`.`name`,
|
||||
|
@ -61,10 +64,10 @@ function User_unconfirmed_AngelTypes($user) {
|
|||
AND `UnconfirmedMembers`.`confirm_user_id` IS NULL
|
||||
GROUP BY `UserAngelTypes`.`angeltype_id`
|
||||
ORDER BY `AngelTypes`.`name`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load user angeltypes.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load user angeltypes.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,11 +76,12 @@ function User_unconfirmed_AngelTypes($user) {
|
|||
* @param User $user
|
||||
* @param AngelType $angeltype
|
||||
*/
|
||||
function User_is_AngelType_supporter(&$user, $angeltype) {
|
||||
if(!isset($user['privileges'])) {
|
||||
$user['privileges'] = privileges_for_user($user['UID']);
|
||||
}
|
||||
return (sql_num_query("
|
||||
function User_is_AngelType_supporter(&$user, $angeltype)
|
||||
{
|
||||
if (!isset($user['privileges'])) {
|
||||
$user['privileges'] = privileges_for_user($user['UID']);
|
||||
}
|
||||
return (sql_num_query("
|
||||
SELECT `id`
|
||||
FROM `UserAngelTypes`
|
||||
WHERE `user_id`='" . sql_escape($user['UID']) . "'
|
||||
|
@ -92,16 +96,17 @@ function User_is_AngelType_supporter(&$user, $angeltype) {
|
|||
* @param int $user_angeltype_id
|
||||
* @param bool $supporter
|
||||
*/
|
||||
function UserAngelType_update($user_angeltype_id, $supporter) {
|
||||
$result = sql_query("
|
||||
function UserAngelType_update($user_angeltype_id, $supporter)
|
||||
{
|
||||
$result = sql_query("
|
||||
UPDATE `UserAngelTypes`
|
||||
SET `supporter`=" . sql_bool($supporter) . "
|
||||
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
|
||||
LIMIT 1");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update supporter rights.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update supporter rights.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,15 +114,16 @@ function UserAngelType_update($user_angeltype_id, $supporter) {
|
|||
*
|
||||
* @param int $angeltype_id
|
||||
*/
|
||||
function UserAngelTypes_delete_all($angeltype_id) {
|
||||
$result = sql_query("
|
||||
function UserAngelTypes_delete_all($angeltype_id)
|
||||
{
|
||||
$result = sql_query("
|
||||
DELETE FROM `UserAngelTypes`
|
||||
WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "'
|
||||
AND `confirm_user_id` IS NULL");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to delete all unconfirmed users.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to delete all unconfirmed users.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,16 +132,17 @@ function UserAngelTypes_delete_all($angeltype_id) {
|
|||
* @param int $angeltype_id
|
||||
* @param User $confirm_user
|
||||
*/
|
||||
function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) {
|
||||
$result = sql_query("
|
||||
function UserAngelTypes_confirm_all($angeltype_id, $confirm_user)
|
||||
{
|
||||
$result = sql_query("
|
||||
UPDATE `UserAngelTypes`
|
||||
SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "'
|
||||
WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "'
|
||||
AND `confirm_user_id` IS NULL");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to confirm all users.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to confirm all users.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,16 +151,17 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) {
|
|||
* @param int $user_angeltype_id
|
||||
* @param User $confirm_user
|
||||
*/
|
||||
function UserAngelType_confirm($user_angeltype_id, $confirm_user) {
|
||||
$result = sql_query("
|
||||
function UserAngelType_confirm($user_angeltype_id, $confirm_user)
|
||||
{
|
||||
$result = sql_query("
|
||||
UPDATE `UserAngelTypes`
|
||||
SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "'
|
||||
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
|
||||
LIMIT 1");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to confirm user angeltype.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to confirm user angeltype.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,8 +169,9 @@ function UserAngelType_confirm($user_angeltype_id, $confirm_user) {
|
|||
*
|
||||
* @param UserAngelType $user_angeltype
|
||||
*/
|
||||
function UserAngelType_delete($user_angeltype) {
|
||||
return sql_query("
|
||||
function UserAngelType_delete($user_angeltype)
|
||||
{
|
||||
return sql_query("
|
||||
DELETE FROM `UserAngelTypes`
|
||||
WHERE `id`='" . sql_escape($user_angeltype['id']) . "'
|
||||
LIMIT 1");
|
||||
|
@ -174,15 +183,16 @@ function UserAngelType_delete($user_angeltype) {
|
|||
* @param User $user
|
||||
* @param Angeltype $angeltype
|
||||
*/
|
||||
function UserAngelType_create($user, $angeltype) {
|
||||
$result = sql_query("
|
||||
function UserAngelType_create($user, $angeltype)
|
||||
{
|
||||
$result = sql_query("
|
||||
INSERT INTO `UserAngelTypes` SET
|
||||
`user_id`='" . sql_escape($user['UID']) . "',
|
||||
`angeltype_id`='" . sql_escape($angeltype['id']) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to create user angeltype.");
|
||||
}
|
||||
return sql_id();
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to create user angeltype.");
|
||||
}
|
||||
return sql_id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,19 +200,20 @@ function UserAngelType_create($user, $angeltype) {
|
|||
*
|
||||
* @param int $user_angeltype_id
|
||||
*/
|
||||
function UserAngelType($user_angeltype_id) {
|
||||
$angeltype = sql_select("
|
||||
function UserAngelType($user_angeltype_id)
|
||||
{
|
||||
$angeltype = sql_select("
|
||||
SELECT *
|
||||
FROM `UserAngelTypes`
|
||||
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
|
||||
LIMIT 1");
|
||||
if ($angeltype === false) {
|
||||
engelsystem_error("Unable to load user angeltype.");
|
||||
}
|
||||
if (count($angeltype) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $angeltype[0];
|
||||
if ($angeltype === false) {
|
||||
engelsystem_error("Unable to load user angeltype.");
|
||||
}
|
||||
if (count($angeltype) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $angeltype[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,19 +222,19 @@ function UserAngelType($user_angeltype_id) {
|
|||
* @param User $user
|
||||
* @param Angeltype $angeltype
|
||||
*/
|
||||
function UserAngelType_by_User_and_AngelType($user, $angeltype) {
|
||||
$angeltype = sql_select("
|
||||
function UserAngelType_by_User_and_AngelType($user, $angeltype)
|
||||
{
|
||||
$angeltype = sql_select("
|
||||
SELECT *
|
||||
FROM `UserAngelTypes`
|
||||
WHERE `user_id`='" . sql_escape($user['UID']) . "'
|
||||
AND `angeltype_id`='" . sql_escape($angeltype['id']) . "'
|
||||
LIMIT 1");
|
||||
if ($angeltype === false) {
|
||||
engelsystem_error("Unable to load user angeltype.");
|
||||
}
|
||||
if (count($angeltype) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $angeltype[0];
|
||||
if ($angeltype === false) {
|
||||
engelsystem_error("Unable to load user angeltype.");
|
||||
}
|
||||
if (count($angeltype) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $angeltype[0];
|
||||
}
|
||||
?>
|
|
@ -4,8 +4,9 @@
|
|||
* Returns a new empty UserDriverLicense
|
||||
* FIXME entity object needed
|
||||
*/
|
||||
function UserDriverLicense_new() {
|
||||
return [
|
||||
function UserDriverLicense_new()
|
||||
{
|
||||
return [
|
||||
'user_id' => null,
|
||||
'has_car' => false,
|
||||
'has_license_car' => false,
|
||||
|
@ -23,8 +24,9 @@ function UserDriverLicense_new() {
|
|||
* The UserDriverLicense to check
|
||||
* @return boolean
|
||||
*/
|
||||
function UserDriverLicense_valid($user_driver_license) {
|
||||
return $user_driver_license['has_car'] || $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift'];
|
||||
function UserDriverLicense_valid($user_driver_license)
|
||||
{
|
||||
return $user_driver_license['has_car'] || $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,16 +35,17 @@ function UserDriverLicense_valid($user_driver_license) {
|
|||
* @param int $user_id
|
||||
* The users id
|
||||
*/
|
||||
function UserDriverLicense($user_id) {
|
||||
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
|
||||
if ($user_driver_license === false) {
|
||||
engelsystem_error('Unable to load user driver license.');
|
||||
return false;
|
||||
}
|
||||
if (count($user_driver_license) > 0) {
|
||||
return $user_driver_license[0];
|
||||
}
|
||||
return null;
|
||||
function UserDriverLicense($user_id)
|
||||
{
|
||||
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
|
||||
if ($user_driver_license === false) {
|
||||
engelsystem_error('Unable to load user driver license.');
|
||||
return false;
|
||||
}
|
||||
if (count($user_driver_license) > 0) {
|
||||
return $user_driver_license[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,9 +54,10 @@ function UserDriverLicense($user_id) {
|
|||
* @param UserDriverLicense $user_driver_license
|
||||
* The UserDriverLicense to create
|
||||
*/
|
||||
function UserDriverLicenses_create($user_driver_license, $user) {
|
||||
$user_driver_license['user_id'] = $user['UID'];
|
||||
$result = sql_query("
|
||||
function UserDriverLicenses_create($user_driver_license, $user)
|
||||
{
|
||||
$user_driver_license['user_id'] = $user['UID'];
|
||||
$result = sql_query("
|
||||
INSERT INTO `UserDriverLicenses` SET
|
||||
`user_id`=" . sql_escape($user_driver_license['user_id']) . ",
|
||||
`has_car`=" . sql_bool($user_driver_license['has_car']) . ",
|
||||
|
@ -62,10 +66,10 @@ function UserDriverLicenses_create($user_driver_license, $user) {
|
|||
`has_license_7_5t_truck`=" . sql_bool($user_driver_license['has_license_7_5t_truck']) . ",
|
||||
`has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
|
||||
`has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']));
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create user driver license');
|
||||
}
|
||||
return $user_driver_license;
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create user driver license');
|
||||
}
|
||||
return $user_driver_license;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,8 +78,9 @@ function UserDriverLicenses_create($user_driver_license, $user) {
|
|||
* @param UserDriverLicense $user_driver_license
|
||||
* The UserDriverLicense to update
|
||||
*/
|
||||
function UserDriverLicenses_update($user_driver_license) {
|
||||
$result = sql_query("UPDATE `UserDriverLicenses` SET
|
||||
function UserDriverLicenses_update($user_driver_license)
|
||||
{
|
||||
$result = sql_query("UPDATE `UserDriverLicenses` SET
|
||||
`has_car`=" . sql_bool($user_driver_license['has_car']) . ",
|
||||
`has_license_car`=" . sql_bool($user_driver_license['has_license_car']) . ",
|
||||
`has_license_3_5t_transporter`=" . sql_bool($user_driver_license['has_license_3_5t_transporter']) . ",
|
||||
|
@ -83,10 +88,10 @@ function UserDriverLicenses_update($user_driver_license) {
|
|||
`has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
|
||||
`has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']) . "
|
||||
WHERE `user_id`='" . sql_escape($user_driver_license['user_id']) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update user driver license information");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to update user driver license information");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,11 +99,11 @@ function UserDriverLicenses_update($user_driver_license) {
|
|||
*
|
||||
* @param int $user_id
|
||||
*/
|
||||
function UserDriverLicenses_delete($user_id) {
|
||||
$result = sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to remove user driver license information");
|
||||
}
|
||||
return $result;
|
||||
function UserDriverLicenses_delete($user_id)
|
||||
{
|
||||
$result = sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to remove user driver license information");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
?>
|
|
@ -4,8 +4,9 @@
|
|||
* Returns users groups
|
||||
* @param User $user
|
||||
*/
|
||||
function User_groups($user) {
|
||||
return sql_select("
|
||||
function User_groups($user)
|
||||
{
|
||||
return sql_select("
|
||||
SELECT `Groups`.*
|
||||
FROM `UserGroups`
|
||||
JOIN `Groups` ON `Groups`.`UID`=`UserGroups`.`group_id`
|
||||
|
@ -13,5 +14,3 @@ function User_groups($user) {
|
|||
ORDER BY `UserGroups`.`group_id`
|
||||
");
|
||||
}
|
||||
|
||||
?>
|
|
@ -10,8 +10,9 @@ use Engelsystem\ValidationResult;
|
|||
*
|
||||
* @param int $user_id
|
||||
*/
|
||||
function User_delete($user_id) {
|
||||
return sql_query("DELETE FROM `User` WHERE `UID`='" . sql_escape($user_id) . "'");
|
||||
function User_delete($user_id)
|
||||
{
|
||||
return sql_query("DELETE FROM `User` WHERE `UID`='" . sql_escape($user_id) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,8 +20,9 @@ function User_delete($user_id) {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function User_update($user) {
|
||||
return sql_query("UPDATE `User` SET
|
||||
function User_update($user)
|
||||
{
|
||||
return sql_query("UPDATE `User` SET
|
||||
`Nick`='" . sql_escape($user['Nick']) . "',
|
||||
`Name`='" . sql_escape($user['Name']) . "',
|
||||
`Vorname`='" . sql_escape($user['Vorname']) . "',
|
||||
|
@ -50,31 +52,37 @@ function User_update($user) {
|
|||
/**
|
||||
* Counts all forced active users.
|
||||
*/
|
||||
function User_force_active_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `force_active` = 1");
|
||||
function User_force_active_count()
|
||||
{
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `force_active` = 1");
|
||||
}
|
||||
|
||||
function User_active_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1");
|
||||
function User_active_count()
|
||||
{
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1");
|
||||
}
|
||||
|
||||
function User_got_voucher_count() {
|
||||
return sql_select_single_cell("SELECT SUM(`got_voucher`) FROM `User`");
|
||||
function User_got_voucher_count()
|
||||
{
|
||||
return sql_select_single_cell("SELECT SUM(`got_voucher`) FROM `User`");
|
||||
}
|
||||
|
||||
function User_arrived_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1");
|
||||
function User_arrived_count()
|
||||
{
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1");
|
||||
}
|
||||
|
||||
function User_tshirts_count() {
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1");
|
||||
function User_tshirts_count()
|
||||
{
|
||||
return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all column names for sorting in an array.
|
||||
*/
|
||||
function User_sortable_columns() {
|
||||
return [
|
||||
function User_sortable_columns()
|
||||
{
|
||||
return [
|
||||
'Nick',
|
||||
'Name',
|
||||
'Vorname',
|
||||
|
@ -95,8 +103,9 @@ function User_sortable_columns() {
|
|||
*
|
||||
* @param string $order_by
|
||||
*/
|
||||
function Users($order_by = 'Nick') {
|
||||
return sql_select("SELECT * FROM `User` ORDER BY `" . sql_escape($order_by) . "` ASC");
|
||||
function Users($order_by = 'Nick')
|
||||
{
|
||||
return sql_select("SELECT * FROM `User` ORDER BY `" . sql_escape($order_by) . "` ASC");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,10 +113,11 @@ function Users($order_by = 'Nick') {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function User_is_freeloader($user) {
|
||||
global $max_freeloadable_shifts, $user;
|
||||
function User_is_freeloader($user)
|
||||
{
|
||||
global $max_freeloadable_shifts, $user;
|
||||
|
||||
return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts;
|
||||
return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,17 +125,18 @@ function User_is_freeloader($user) {
|
|||
*
|
||||
* @param Angeltype $angeltype
|
||||
*/
|
||||
function Users_by_angeltype_inverted($angeltype) {
|
||||
$result = sql_select("
|
||||
function Users_by_angeltype_inverted($angeltype)
|
||||
{
|
||||
$result = sql_select("
|
||||
SELECT `User`.*
|
||||
FROM `User`
|
||||
LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "')
|
||||
WHERE `UserAngelTypes`.`id` IS NULL
|
||||
ORDER BY `Nick`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load users.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load users.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,8 +144,9 @@ function Users_by_angeltype_inverted($angeltype) {
|
|||
*
|
||||
* @param Angeltype $angeltype
|
||||
*/
|
||||
function Users_by_angeltype($angeltype) {
|
||||
$result = sql_select("
|
||||
function Users_by_angeltype($angeltype)
|
||||
{
|
||||
$result = sql_select("
|
||||
SELECT
|
||||
`User`.*,
|
||||
`UserAngelTypes`.`id` as `user_angeltype_id`,
|
||||
|
@ -146,17 +158,18 @@ function Users_by_angeltype($angeltype) {
|
|||
LEFT JOIN `UserDriverLicenses` ON `User`.`UID`=`UserDriverLicenses`.`user_id`
|
||||
WHERE `UserAngelTypes`.`angeltype_id`='" . sql_escape($angeltype['id']) . "'
|
||||
ORDER BY `Nick`");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load members.");
|
||||
}
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to load members.");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns User id array
|
||||
*/
|
||||
function User_ids() {
|
||||
return sql_select("SELECT `UID` FROM `User`");
|
||||
function User_ids()
|
||||
{
|
||||
return sql_select("SELECT `UID` FROM `User`");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -164,8 +177,9 @@ function User_ids() {
|
|||
*
|
||||
* @param string $nick
|
||||
*/
|
||||
function User_validate_Nick($nick) {
|
||||
return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick);
|
||||
function User_validate_Nick($nick)
|
||||
{
|
||||
return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,9 +189,10 @@ function User_validate_Nick($nick) {
|
|||
* The email address to validate
|
||||
* @return ValidationResult
|
||||
*/
|
||||
function User_validate_mail($mail) {
|
||||
$mail = strip_item($mail);
|
||||
return new ValidationResult(check_email($mail), $mail);
|
||||
function User_validate_mail($mail)
|
||||
{
|
||||
$mail = strip_item($mail);
|
||||
return new ValidationResult(check_email($mail), $mail);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,13 +202,14 @@ function User_validate_mail($mail) {
|
|||
* Jabber-ID to validate
|
||||
* @return ValidationResult
|
||||
*/
|
||||
function User_validate_jabber($jabber) {
|
||||
$jabber = strip_item($jabber);
|
||||
if ($jabber == '') {
|
||||
// Empty is ok
|
||||
function User_validate_jabber($jabber)
|
||||
{
|
||||
$jabber = strip_item($jabber);
|
||||
if ($jabber == '') {
|
||||
// Empty is ok
|
||||
return new ValidationResult(true, '');
|
||||
}
|
||||
return new ValidationResult(check_email($jabber), $jabber);
|
||||
}
|
||||
return new ValidationResult(check_email($jabber), $jabber);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,25 +219,26 @@ function User_validate_jabber($jabber) {
|
|||
* Unix timestamp
|
||||
* @return ValidationResult
|
||||
*/
|
||||
function User_validate_planned_arrival_date($planned_arrival_date) {
|
||||
if ($planned_arrival_date == null) {
|
||||
// null is not okay
|
||||
function User_validate_planned_arrival_date($planned_arrival_date)
|
||||
{
|
||||
if ($planned_arrival_date == null) {
|
||||
// null is not okay
|
||||
return new ValidationResult(false, time());
|
||||
}
|
||||
$event_config = EventConfig();
|
||||
if ($event_config == null) {
|
||||
// Nothing to validate against
|
||||
}
|
||||
$event_config = EventConfig();
|
||||
if ($event_config == null) {
|
||||
// Nothing to validate against
|
||||
return new ValidationResult(true, $planned_arrival_date);
|
||||
}
|
||||
if (isset($event_config['buildup_start_date']) && $planned_arrival_date < $event_config['buildup_start_date']) {
|
||||
// Planned arrival can not be before buildup start date
|
||||
}
|
||||
if (isset($event_config['buildup_start_date']) && $planned_arrival_date < $event_config['buildup_start_date']) {
|
||||
// Planned arrival can not be before buildup start date
|
||||
return new ValidationResult(false, $event_config['buildup_start_date']);
|
||||
}
|
||||
if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) {
|
||||
// Planned arrival can not be after teardown end date
|
||||
}
|
||||
if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) {
|
||||
// Planned arrival can not be after teardown end date
|
||||
return new ValidationResult(false, $event_config['teardown_end_date']);
|
||||
}
|
||||
return new ValidationResult(true, $planned_arrival_date);
|
||||
}
|
||||
return new ValidationResult(true, $planned_arrival_date);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,29 +250,30 @@ function User_validate_planned_arrival_date($planned_arrival_date) {
|
|||
* Unix timestamp
|
||||
* @return ValidationResult
|
||||
*/
|
||||
function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date) {
|
||||
if ($planned_departure_date == null) {
|
||||
// null is okay
|
||||
function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date)
|
||||
{
|
||||
if ($planned_departure_date == null) {
|
||||
// null is okay
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
if ($planned_arrival_date > $planned_departure_date) {
|
||||
// departure cannot be before arrival
|
||||
}
|
||||
if ($planned_arrival_date > $planned_departure_date) {
|
||||
// departure cannot be before arrival
|
||||
return new ValidationResult(false, $planned_arrival_date);
|
||||
}
|
||||
$event_config = EventConfig();
|
||||
if ($event_config == null) {
|
||||
// Nothing to validate against
|
||||
}
|
||||
$event_config = EventConfig();
|
||||
if ($event_config == null) {
|
||||
// Nothing to validate against
|
||||
return new ValidationResult(true, $planned_departure_date);
|
||||
}
|
||||
if (isset($event_config['buildup_start_date']) && $planned_departure_date < $event_config['buildup_start_date']) {
|
||||
// Planned arrival can not be before buildup start date
|
||||
}
|
||||
if (isset($event_config['buildup_start_date']) && $planned_departure_date < $event_config['buildup_start_date']) {
|
||||
// Planned arrival can not be before buildup start date
|
||||
return new ValidationResult(false, $event_config['buildup_start_date']);
|
||||
}
|
||||
if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) {
|
||||
// Planned arrival can not be after teardown end date
|
||||
}
|
||||
if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) {
|
||||
// Planned arrival can not be after teardown end date
|
||||
return new ValidationResult(false, $event_config['teardown_end_date']);
|
||||
}
|
||||
return new ValidationResult(true, $planned_departure_date);
|
||||
}
|
||||
return new ValidationResult(true, $planned_departure_date);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,15 +281,16 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de
|
|||
*
|
||||
* @param $user_id UID
|
||||
*/
|
||||
function User($user_id) {
|
||||
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
if ($user_source === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
if (count($user_source) > 0) {
|
||||
return $user_source[0];
|
||||
}
|
||||
return null;
|
||||
function User($user_id)
|
||||
{
|
||||
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
if ($user_source === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
if (count($user_source) > 0) {
|
||||
return $user_source[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -281,15 +300,16 @@ function User($user_id) {
|
|||
* User api key
|
||||
* @return Matching user, null or false on error
|
||||
*/
|
||||
function User_by_api_key($api_key) {
|
||||
$user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1");
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to find user by api key.");
|
||||
}
|
||||
if (count($user) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $user[0];
|
||||
function User_by_api_key($api_key)
|
||||
{
|
||||
$user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1");
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to find user by api key.");
|
||||
}
|
||||
if (count($user) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $user[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -298,15 +318,16 @@ function User_by_api_key($api_key) {
|
|||
* @param string $email
|
||||
* @return Matching user, null or false on error
|
||||
*/
|
||||
function User_by_email($email) {
|
||||
$user = sql_select("SELECT * FROM `User` WHERE `email`='" . sql_escape($email) . "' LIMIT 1");
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
if (count($user) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $user[0];
|
||||
function User_by_email($email)
|
||||
{
|
||||
$user = sql_select("SELECT * FROM `User` WHERE `email`='" . sql_escape($email) . "' LIMIT 1");
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
if (count($user) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $user[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,15 +336,16 @@ function User_by_email($email) {
|
|||
* @param string $token
|
||||
* @return Matching user, null or false on error
|
||||
*/
|
||||
function User_by_password_recovery_token($token) {
|
||||
$user = sql_select("SELECT * FROM `User` WHERE `password_recovery_token`='" . sql_escape($token) . "' LIMIT 1");
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
if (count($user) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $user[0];
|
||||
function User_by_password_recovery_token($token)
|
||||
{
|
||||
$user = sql_select("SELECT * FROM `User` WHERE `password_recovery_token`='" . sql_escape($token) . "' LIMIT 1");
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to load user.");
|
||||
}
|
||||
if (count($user) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $user[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -331,15 +353,16 @@ function User_by_password_recovery_token($token) {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function User_reset_api_key(&$user, $log = true) {
|
||||
$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");
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
if ($log) {
|
||||
engelsystem_log(sprintf("API key resetted (%s).", User_Nick_render($user)));
|
||||
}
|
||||
function User_reset_api_key(&$user, $log = true)
|
||||
{
|
||||
$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");
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
if ($log) {
|
||||
engelsystem_log(sprintf("API key resetted (%s).", User_Nick_render($user)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -347,28 +370,28 @@ function User_reset_api_key(&$user, $log = true) {
|
|||
*
|
||||
* @param User $user
|
||||
*/
|
||||
function User_generate_password_recovery_token(&$user) {
|
||||
$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");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to generate password recovery token.");
|
||||
}
|
||||
engelsystem_log("Password recovery for " . User_Nick_render($user) . " started.");
|
||||
return $user['password_recovery_token'];
|
||||
function User_generate_password_recovery_token(&$user)
|
||||
{
|
||||
$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");
|
||||
if ($result === false) {
|
||||
engelsystem_error("Unable to generate password recovery token.");
|
||||
}
|
||||
engelsystem_log("Password recovery for " . User_Nick_render($user) . " started.");
|
||||
return $user['password_recovery_token'];
|
||||
}
|
||||
|
||||
function User_get_eligable_voucher_count(&$user) {
|
||||
global $voucher_settings;
|
||||
function User_get_eligable_voucher_count(&$user)
|
||||
{
|
||||
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'];
|
||||
$elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
|
||||
if ($elegible_vouchers < 0) {
|
||||
return 0;
|
||||
}
|
||||
$earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];
|
||||
$elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
|
||||
if ($elegible_vouchers < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $elegible_vouchers;
|
||||
return $elegible_vouchers;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,11 +6,11 @@ namespace Engelsystem;
|
|||
* BO that represents the result of an entity attribute validation.
|
||||
* It contains the validated value and a bool for validation success.
|
||||
*/
|
||||
class ValidationResult {
|
||||
class ValidationResult
|
||||
{
|
||||
private $valid;
|
||||
|
||||
private $valid;
|
||||
|
||||
private $value;
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -20,23 +20,25 @@ class ValidationResult {
|
|||
* @param * $value
|
||||
* The validated value
|
||||
*/
|
||||
public function __construct($valid, $value) {
|
||||
$this->valid = $valid;
|
||||
$this->value = $value;
|
||||
public function __construct($valid, $value)
|
||||
{
|
||||
$this->valid = $valid;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the value valid?
|
||||
*/
|
||||
public function isValid() {
|
||||
return $this->valid;
|
||||
public function isValid()
|
||||
{
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* The parsed/validated value.
|
||||
*/
|
||||
public function getValue() {
|
||||
return $this->value;
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -3,56 +3,61 @@
|
|||
/**
|
||||
* Close connection.
|
||||
*/
|
||||
function sql_close() {
|
||||
global $sql_connection;
|
||||
function sql_close()
|
||||
{
|
||||
global $sql_connection;
|
||||
|
||||
return $sql_connection->close();
|
||||
return $sql_connection->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return NULL if given value is null.
|
||||
*/
|
||||
function sql_null($value = null) {
|
||||
return $value == null ? 'NULL' : ("'" . sql_escape($value) . "'");
|
||||
function sql_null($value = null)
|
||||
{
|
||||
return $value == null ? 'NULL' : ("'" . sql_escape($value) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Start new transaction.
|
||||
*/
|
||||
function sql_transaction_start() {
|
||||
global $sql_nested_transaction_level;
|
||||
function sql_transaction_start()
|
||||
{
|
||||
global $sql_nested_transaction_level;
|
||||
|
||||
if ($sql_nested_transaction_level ++ == 0) {
|
||||
return sql_query("BEGIN");
|
||||
}
|
||||
if ($sql_nested_transaction_level ++ == 0) {
|
||||
return sql_query("BEGIN");
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit transaction.
|
||||
*/
|
||||
function sql_transaction_commit() {
|
||||
global $sql_nested_transaction_level;
|
||||
function sql_transaction_commit()
|
||||
{
|
||||
global $sql_nested_transaction_level;
|
||||
|
||||
if (-- $sql_nested_transaction_level == 0) {
|
||||
return sql_query("COMMIT");
|
||||
}
|
||||
if (-- $sql_nested_transaction_level == 0) {
|
||||
return sql_query("COMMIT");
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop transaction, revert database.
|
||||
*/
|
||||
function sql_transaction_rollback() {
|
||||
global $sql_nested_transaction_level;
|
||||
function sql_transaction_rollback()
|
||||
{
|
||||
global $sql_nested_transaction_level;
|
||||
|
||||
if (-- $sql_nested_transaction_level == 0) {
|
||||
return sql_query("ROLLBACK");
|
||||
}
|
||||
if (-- $sql_nested_transaction_level == 0) {
|
||||
return sql_query("ROLLBACK");
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,15 +66,16 @@ function sql_transaction_rollback() {
|
|||
* @param string $message
|
||||
* @return false
|
||||
*/
|
||||
function sql_error($message) {
|
||||
sql_close();
|
||||
function sql_error($message)
|
||||
{
|
||||
sql_close();
|
||||
|
||||
$message = trim($message) . "\n";
|
||||
$message .= debug_string_backtrace() . "\n";
|
||||
$message = trim($message) . "\n";
|
||||
$message .= debug_string_backtrace() . "\n";
|
||||
|
||||
error_log('mysql_provider error: ' . $message);
|
||||
error_log('mysql_provider error: ' . $message);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,26 +91,27 @@ function sql_error($message) {
|
|||
* DB to select
|
||||
* @return mysqli The connection handler
|
||||
*/
|
||||
function sql_connect($host, $user, $pass, $db_name) {
|
||||
global $sql_connection;
|
||||
function sql_connect($host, $user, $pass, $db_name)
|
||||
{
|
||||
global $sql_connection;
|
||||
|
||||
$sql_connection = new mysqli($host, $user, $pass, $db_name);
|
||||
if ($sql_connection->connect_errno) {
|
||||
error("Unable to connect to MySQL: " . $sql_connection->connect_error);
|
||||
return sql_error("Unable to connect to MySQL: " . $sql_connection->connect_error);
|
||||
}
|
||||
$sql_connection = new mysqli($host, $user, $pass, $db_name);
|
||||
if ($sql_connection->connect_errno) {
|
||||
error("Unable to connect to MySQL: " . $sql_connection->connect_error);
|
||||
return sql_error("Unable to connect to MySQL: " . $sql_connection->connect_error);
|
||||
}
|
||||
|
||||
$result = $sql_connection->query("SET CHARACTER SET utf8;");
|
||||
if (! $result) {
|
||||
return sql_error("Unable to set utf8 character set (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
$result = $sql_connection->query("SET CHARACTER SET utf8;");
|
||||
if (! $result) {
|
||||
return sql_error("Unable to set utf8 character set (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
|
||||
$result = $sql_connection->set_charset('utf8');
|
||||
if (! $result) {
|
||||
return sql_error("Unable to set utf8 names (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
$result = $sql_connection->set_charset('utf8');
|
||||
if (! $result) {
|
||||
return sql_error("Unable to set utf8 names (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
|
||||
return $sql_connection;
|
||||
return $sql_connection;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,12 +121,13 @@ function sql_connect($host, $user, $pass, $db_name) {
|
|||
* $db_name
|
||||
* @return bool true on success, false on error
|
||||
*/
|
||||
function sql_select_db($db_name) {
|
||||
global $sql_connection;
|
||||
if (! $sql_connection->select_db($db_name)) {
|
||||
return sql_error("No database selected.");
|
||||
}
|
||||
return true;
|
||||
function sql_select_db($db_name)
|
||||
{
|
||||
global $sql_connection;
|
||||
if (! $sql_connection->select_db($db_name)) {
|
||||
return sql_error("No database selected.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,22 +136,23 @@ function sql_select_db($db_name) {
|
|||
* @param string $query
|
||||
* @return Result array or false on error
|
||||
*/
|
||||
function sql_select($query) {
|
||||
global $sql_connection;
|
||||
function sql_select($query)
|
||||
{
|
||||
global $sql_connection;
|
||||
|
||||
// echo $query . ";\n";
|
||||
// echo debug_string_backtrace() . "\n";
|
||||
|
||||
$result = $sql_connection->query($query);
|
||||
if ($result) {
|
||||
$data = [];
|
||||
while ($line = $result->fetch_assoc()) {
|
||||
array_push($data, $line);
|
||||
if ($result) {
|
||||
$data = [];
|
||||
while ($line = $result->fetch_assoc()) {
|
||||
array_push($data, $line);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
return sql_error("MySQL-query error: " . $query . " (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
return sql_error("MySQL-query error: " . $query . " (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,15 +161,16 @@ function sql_select($query) {
|
|||
* @param string $query
|
||||
* @return mysqli_result boolean resource or false on error
|
||||
*/
|
||||
function sql_query($query) {
|
||||
global $sql_connection;
|
||||
function sql_query($query)
|
||||
{
|
||||
global $sql_connection;
|
||||
|
||||
$result = $sql_connection->query($query);
|
||||
if ($result) {
|
||||
return $result;
|
||||
}
|
||||
$result = $sql_connection->query($query);
|
||||
if ($result) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return sql_error("MySQL-query error: " . $query . " (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
return sql_error("MySQL-query error: " . $query . " (" . $sql_connection->errno . ") " . $sql_connection->error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,9 +178,10 @@ function sql_query($query) {
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
function sql_id() {
|
||||
global $sql_connection;
|
||||
return $sql_connection->insert_id;
|
||||
function sql_id()
|
||||
{
|
||||
global $sql_connection;
|
||||
return $sql_connection->insert_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,9 +190,10 @@ function sql_id() {
|
|||
* @param string $query
|
||||
* @return string
|
||||
*/
|
||||
function sql_escape($query) {
|
||||
global $sql_connection;
|
||||
return $sql_connection->real_escape_string($query);
|
||||
function sql_escape($query)
|
||||
{
|
||||
global $sql_connection;
|
||||
return $sql_connection->real_escape_string($query);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,8 +202,9 @@ function sql_escape($query) {
|
|||
* @param boolean $boolean
|
||||
* @return string
|
||||
*/
|
||||
function sql_bool($boolean) {
|
||||
return $boolean == true ? 'TRUE' : 'FALSE';
|
||||
function sql_bool($boolean)
|
||||
{
|
||||
return $boolean == true ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,17 +213,18 @@ function sql_bool($boolean) {
|
|||
* @param string $query
|
||||
* @return int Count of result lines
|
||||
*/
|
||||
function sql_num_query($query) {
|
||||
return sql_query($query)->num_rows;
|
||||
function sql_num_query($query)
|
||||
{
|
||||
return sql_query($query)->num_rows;
|
||||
}
|
||||
|
||||
function sql_select_single_col($query) {
|
||||
$result = sql_select($query);
|
||||
return array_map('array_shift', $result);
|
||||
function sql_select_single_col($query)
|
||||
{
|
||||
$result = sql_select($query);
|
||||
return array_map('array_shift', $result);
|
||||
}
|
||||
|
||||
function sql_select_single_cell($query) {
|
||||
return array_shift(array_shift(sql_select($query)));
|
||||
function sql_select_single_cell($query)
|
||||
{
|
||||
return array_shift(array_shift(sql_select($query)));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,45 +1,47 @@
|
|||
<?php
|
||||
|
||||
function admin_active_title() {
|
||||
return _("Active angels");
|
||||
function admin_active_title()
|
||||
{
|
||||
return _("Active angels");
|
||||
}
|
||||
|
||||
function admin_active() {
|
||||
global $tshirt_sizes, $shift_sum_formula;
|
||||
function admin_active()
|
||||
{
|
||||
global $tshirt_sizes, $shift_sum_formula;
|
||||
|
||||
$msg = "";
|
||||
$search = "";
|
||||
$forced_count = sql_num_query("SELECT * FROM `User` WHERE `force_active`=1");
|
||||
$count = $forced_count;
|
||||
$limit = "";
|
||||
$set_active = "";
|
||||
$msg = "";
|
||||
$search = "";
|
||||
$forced_count = sql_num_query("SELECT * FROM `User` WHERE `force_active`=1");
|
||||
$count = $forced_count;
|
||||
$limit = "";
|
||||
$set_active = "";
|
||||
|
||||
if (isset($_REQUEST['search'])) {
|
||||
$search = strip_request_item('search');
|
||||
}
|
||||
|
||||
$show_all_shifts = isset($_REQUEST['show_all_shifts']);
|
||||
|
||||
if (isset($_REQUEST['set_active'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['count']) && preg_match("/^[0-9]+$/", $_REQUEST['count'])) {
|
||||
$count = strip_request_item('count');
|
||||
if ($count < $forced_count) {
|
||||
error(sprintf(_("At least %s angels are forced to be active. The number has to be greater."), $forced_count));
|
||||
redirect(page_link_to('admin_active'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a number of angels to be marked as active."), true);
|
||||
if (isset($_REQUEST['search'])) {
|
||||
$search = strip_request_item('search');
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$limit = " LIMIT " . $count;
|
||||
}
|
||||
if (isset($_REQUEST['ack'])) {
|
||||
sql_query("UPDATE `User` SET `Aktiv` = 0 WHERE `Tshirt` = 0");
|
||||
$users = sql_select("
|
||||
$show_all_shifts = isset($_REQUEST['show_all_shifts']);
|
||||
|
||||
if (isset($_REQUEST['set_active'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['count']) && preg_match("/^[0-9]+$/", $_REQUEST['count'])) {
|
||||
$count = strip_request_item('count');
|
||||
if ($count < $forced_count) {
|
||||
error(sprintf(_("At least %s angels are forced to be active. The number has to be greater."), $forced_count));
|
||||
redirect(page_link_to('admin_active'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a number of angels to be marked as active."), true);
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$limit = " LIMIT " . $count;
|
||||
}
|
||||
if (isset($_REQUEST['ack'])) {
|
||||
sql_query("UPDATE `User` SET `Aktiv` = 0 WHERE `Tshirt` = 0");
|
||||
$users = sql_select("
|
||||
SELECT `User`.*, COUNT(`ShiftEntry`.`id`) as `shift_count`, $shift_sum_formula as `shift_length`
|
||||
FROM `User`
|
||||
LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
|
||||
|
@ -47,130 +49,130 @@ function admin_active() {
|
|||
WHERE `User`.`Gekommen` = 1 AND `User`.`force_active`=0
|
||||
GROUP BY `User`.`UID`
|
||||
ORDER BY `force_active` DESC, `shift_length` DESC" . $limit);
|
||||
$user_nicks = [];
|
||||
foreach ($users as $usr) {
|
||||
sql_query("UPDATE `User` SET `Aktiv` = 1 WHERE `UID`='" . sql_escape($usr['UID']) . "'");
|
||||
$user_nicks[] = User_Nick_render($usr);
|
||||
}
|
||||
sql_query("UPDATE `User` SET `Aktiv`=1 WHERE `force_active`=TRUE");
|
||||
engelsystem_log("These angels are active now: " . join(", ", $user_nicks));
|
||||
$user_nicks = [];
|
||||
foreach ($users as $usr) {
|
||||
sql_query("UPDATE `User` SET `Aktiv` = 1 WHERE `UID`='" . sql_escape($usr['UID']) . "'");
|
||||
$user_nicks[] = User_Nick_render($usr);
|
||||
}
|
||||
sql_query("UPDATE `User` SET `Aktiv`=1 WHERE `force_active`=TRUE");
|
||||
engelsystem_log("These angels are active now: " . join(", ", $user_nicks));
|
||||
|
||||
$limit = "";
|
||||
$msg = success(_("Marked angels."), true);
|
||||
} else {
|
||||
$set_active = '<a href="' . page_link_to('admin_active') . '&serach=' . $search . '">« ' . _("back") . '</a> | <a href="' . page_link_to('admin_active') . '&search=' . $search . '&count=' . $count . '&set_active&ack">' . _("apply") . '</a>';
|
||||
$limit = "";
|
||||
$msg = success(_("Marked angels."), true);
|
||||
} else {
|
||||
$set_active = '<a href="' . page_link_to('admin_active') . '&serach=' . $search . '">« ' . _("back") . '</a> | <a href="' . page_link_to('admin_active') . '&search=' . $search . '&count=' . $count . '&set_active&ack">' . _("apply") . '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['active']) && preg_match("/^[0-9]+$/", $_REQUEST['active'])) {
|
||||
$user_id = $_REQUEST['active'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Aktiv`=1 WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " is active now.");
|
||||
$msg = success(_("Angel has been marked as active."), true);
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
if (isset($_REQUEST['active']) && preg_match("/^[0-9]+$/", $_REQUEST['active'])) {
|
||||
$user_id = $_REQUEST['active'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Aktiv`=1 WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " is active now.");
|
||||
$msg = success(_("Angel has been marked as active."), true);
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
}
|
||||
} elseif (isset($_REQUEST['not_active']) && preg_match("/^[0-9]+$/", $_REQUEST['not_active'])) {
|
||||
$user_id = $_REQUEST['not_active'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Aktiv`=0 WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " is NOT active now.");
|
||||
$msg = success(_("Angel has been marked as not active."), true);
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
}
|
||||
} elseif (isset($_REQUEST['tshirt']) && preg_match("/^[0-9]+$/", $_REQUEST['tshirt'])) {
|
||||
$user_id = $_REQUEST['tshirt'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Tshirt`=1 WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " has tshirt now.");
|
||||
$msg = success(_("Angel has got a t-shirt."), true);
|
||||
} else {
|
||||
$msg = error("Angel not found.", true);
|
||||
}
|
||||
} elseif (isset($_REQUEST['not_tshirt']) && preg_match("/^[0-9]+$/", $_REQUEST['not_tshirt'])) {
|
||||
$user_id = $_REQUEST['not_tshirt'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Tshirt`=0 WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " has NO tshirt.");
|
||||
$msg = success(_("Angel has got no t-shirt."), true);
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
}
|
||||
}
|
||||
} elseif (isset($_REQUEST['not_active']) && preg_match("/^[0-9]+$/", $_REQUEST['not_active'])) {
|
||||
$user_id = $_REQUEST['not_active'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Aktiv`=0 WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " is NOT active now.");
|
||||
$msg = success(_("Angel has been marked as not active."), true);
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
}
|
||||
} elseif (isset($_REQUEST['tshirt']) && preg_match("/^[0-9]+$/", $_REQUEST['tshirt'])) {
|
||||
$user_id = $_REQUEST['tshirt'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Tshirt`=1 WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " has tshirt now.");
|
||||
$msg = success(_("Angel has got a t-shirt."), true);
|
||||
} else {
|
||||
$msg = error("Angel not found.", true);
|
||||
}
|
||||
} elseif (isset($_REQUEST['not_tshirt']) && preg_match("/^[0-9]+$/", $_REQUEST['not_tshirt'])) {
|
||||
$user_id = $_REQUEST['not_tshirt'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Tshirt`=0 WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User " . User_Nick_render($user_source) . " has NO tshirt.");
|
||||
$msg = success(_("Angel has got no t-shirt."), true);
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
}
|
||||
}
|
||||
|
||||
$users = sql_select("
|
||||
$users = sql_select("
|
||||
SELECT `User`.*, COUNT(`ShiftEntry`.`id`) as `shift_count`, ${shift_sum_formula} as `shift_length`
|
||||
FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
|
||||
LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID` " . ($show_all_shifts ? "" : "AND (`Shifts`.`end` < " . time() . " OR `Shifts`.`end` IS NULL)") . "
|
||||
WHERE `User`.`Gekommen` = 1
|
||||
GROUP BY `User`.`UID`
|
||||
ORDER BY `force_active` DESC, `shift_length` DESC" . $limit);
|
||||
$matched_users = [];
|
||||
if ($search == "") {
|
||||
$tokens = [];
|
||||
} else {
|
||||
$tokens = explode(" ", $search);
|
||||
}
|
||||
foreach ($users as &$usr) {
|
||||
if (count($tokens) > 0) {
|
||||
$match = false;
|
||||
foreach ($tokens as $t) {
|
||||
if (stristr($usr['Nick'], trim($t))) {
|
||||
$match = true;
|
||||
break;
|
||||
$matched_users = [];
|
||||
if ($search == "") {
|
||||
$tokens = [];
|
||||
} else {
|
||||
$tokens = explode(" ", $search);
|
||||
}
|
||||
foreach ($users as &$usr) {
|
||||
if (count($tokens) > 0) {
|
||||
$match = false;
|
||||
foreach ($tokens as $t) {
|
||||
if (stristr($usr['Nick'], trim($t))) {
|
||||
$match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $match) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! $match) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$usr['nick'] = User_Nick_render($usr);
|
||||
$usr['shirt_size'] = $tshirt_sizes[$usr['Size']];
|
||||
$usr['work_time'] = round($usr['shift_length'] / 60) . ' min (' . round($usr['shift_length'] / 3600) . ' h)';
|
||||
$usr['active'] = glyph_bool($usr['Aktiv'] == 1);
|
||||
$usr['force_active'] = glyph_bool($usr['force_active'] == 1);
|
||||
$usr['tshirt'] = glyph_bool($usr['Tshirt'] == 1);
|
||||
$usr['nick'] = User_Nick_render($usr);
|
||||
$usr['shirt_size'] = $tshirt_sizes[$usr['Size']];
|
||||
$usr['work_time'] = round($usr['shift_length'] / 60) . ' min (' . round($usr['shift_length'] / 3600) . ' h)';
|
||||
$usr['active'] = glyph_bool($usr['Aktiv'] == 1);
|
||||
$usr['force_active'] = glyph_bool($usr['force_active'] == 1);
|
||||
$usr['tshirt'] = glyph_bool($usr['Tshirt'] == 1);
|
||||
|
||||
$actions = [];
|
||||
if ($usr['Aktiv'] == 0) {
|
||||
$actions[] = '<a href="' . page_link_to('admin_active') . '&active=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("set active") . '</a>';
|
||||
}
|
||||
if ($usr['Aktiv'] == 1 && $usr['Tshirt'] == 0) {
|
||||
$actions[] = '<a href="' . page_link_to('admin_active') . '&not_active=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("remove active") . '</a>';
|
||||
$actions[] = '<a href="' . page_link_to('admin_active') . '&tshirt=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("got t-shirt") . '</a>';
|
||||
}
|
||||
if ($usr['Tshirt'] == 1) {
|
||||
$actions[] = '<a href="' . page_link_to('admin_active') . '&not_tshirt=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("remove t-shirt") . '</a>';
|
||||
$actions = [];
|
||||
if ($usr['Aktiv'] == 0) {
|
||||
$actions[] = '<a href="' . page_link_to('admin_active') . '&active=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("set active") . '</a>';
|
||||
}
|
||||
if ($usr['Aktiv'] == 1 && $usr['Tshirt'] == 0) {
|
||||
$actions[] = '<a href="' . page_link_to('admin_active') . '&not_active=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("remove active") . '</a>';
|
||||
$actions[] = '<a href="' . page_link_to('admin_active') . '&tshirt=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("got t-shirt") . '</a>';
|
||||
}
|
||||
if ($usr['Tshirt'] == 1) {
|
||||
$actions[] = '<a href="' . page_link_to('admin_active') . '&not_tshirt=' . $usr['UID'] . ($show_all_shifts ? '&show_all_shifts=' : '') . '&search=' . $search . '">' . _("remove t-shirt") . '</a>';
|
||||
}
|
||||
|
||||
$usr['actions'] = join(' ', $actions);
|
||||
|
||||
$matched_users[] = $usr;
|
||||
}
|
||||
|
||||
$usr['actions'] = join(' ', $actions);
|
||||
|
||||
$matched_users[] = $usr;
|
||||
}
|
||||
|
||||
$shirt_statistics = [];
|
||||
foreach (array_keys($tshirt_sizes) as $size) {
|
||||
if ($size != '') {
|
||||
$shirt_statistics[] = [
|
||||
$shirt_statistics = [];
|
||||
foreach (array_keys($tshirt_sizes) as $size) {
|
||||
if ($size != '') {
|
||||
$shirt_statistics[] = [
|
||||
'size' => $size,
|
||||
'needed' => sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Size`='" . sql_escape($size) . "' AND `Gekommen`=1"),
|
||||
'given' => sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Size`='" . sql_escape($size) . "' AND `Tshirt`=1")
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$shirt_statistics[] = [
|
||||
$shirt_statistics[] = [
|
||||
'size' => '<b>' . _("Sum") . '</b>',
|
||||
'needed' => '<b>' . User_arrived_count() . '</b>',
|
||||
'given' => '<b>' . sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Tshirt`=1") . '</b>'
|
||||
];
|
||||
|
||||
return page_with_title(admin_active_title(), [
|
||||
return page_with_title(admin_active_title(), [
|
||||
form([
|
||||
form_text('search', _("Search angel:"), $search),
|
||||
form_checkbox('show_all_shifts', _("Show all shifts"), $show_all_shifts),
|
||||
|
@ -199,4 +201,3 @@ function admin_active() {
|
|||
], $shirt_statistics)
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,141 +1,143 @@
|
|||
<?php
|
||||
|
||||
function admin_arrive_title() {
|
||||
return _("Arrived angels");
|
||||
function admin_arrive_title()
|
||||
{
|
||||
return _("Arrived angels");
|
||||
}
|
||||
|
||||
function admin_arrive() {
|
||||
$msg = "";
|
||||
$search = "";
|
||||
if (isset($_REQUEST['search'])) {
|
||||
$search = strip_request_item('search');
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['reset']) && preg_match("/^[0-9]*$/", $_REQUEST['reset'])) {
|
||||
$user_id = $_REQUEST['reset'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Gekommen`=0, `arrival_date` = NULL WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User set to not arrived: " . User_Nick_render($user_source));
|
||||
success(_("Reset done. Angel has not arrived."));
|
||||
redirect(user_link($user_source));
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
function admin_arrive()
|
||||
{
|
||||
$msg = "";
|
||||
$search = "";
|
||||
if (isset($_REQUEST['search'])) {
|
||||
$search = strip_request_item('search');
|
||||
}
|
||||
} elseif (isset($_REQUEST['arrived']) && preg_match("/^[0-9]*$/", $_REQUEST['arrived'])) {
|
||||
$user_id = $_REQUEST['arrived'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Gekommen`=1, `arrival_date`='" . time() . "' WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User set has arrived: " . User_Nick_render($user_source));
|
||||
success(_("Angel has been marked as arrived."));
|
||||
redirect(user_link($user_source));
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
}
|
||||
}
|
||||
|
||||
$users = sql_select("SELECT * FROM `User` ORDER BY `Nick`");
|
||||
$arrival_count_at_day = [];
|
||||
$planned_arrival_count_at_day = [];
|
||||
$planned_departure_count_at_day = [];
|
||||
$users_matched = [];
|
||||
if ($search == "") {
|
||||
$tokens = [];
|
||||
} else {
|
||||
$tokens = explode(" ", $search);
|
||||
}
|
||||
foreach ($users as $usr) {
|
||||
if (count($tokens) > 0) {
|
||||
$match = false;
|
||||
$index = join(" ", $usr);
|
||||
foreach ($tokens as $t) {
|
||||
if (stristr($index, trim($t))) {
|
||||
$match = true;
|
||||
break;
|
||||
if (isset($_REQUEST['reset']) && preg_match("/^[0-9]*$/", $_REQUEST['reset'])) {
|
||||
$user_id = $_REQUEST['reset'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Gekommen`=0, `arrival_date` = NULL WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User set to not arrived: " . User_Nick_render($user_source));
|
||||
success(_("Reset done. Angel has not arrived."));
|
||||
redirect(user_link($user_source));
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
}
|
||||
} elseif (isset($_REQUEST['arrived']) && preg_match("/^[0-9]*$/", $_REQUEST['arrived'])) {
|
||||
$user_id = $_REQUEST['arrived'];
|
||||
$user_source = User($user_id);
|
||||
if ($user_source != null) {
|
||||
sql_query("UPDATE `User` SET `Gekommen`=1, `arrival_date`='" . time() . "' WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
engelsystem_log("User set has arrived: " . User_Nick_render($user_source));
|
||||
success(_("Angel has been marked as arrived."));
|
||||
redirect(user_link($user_source));
|
||||
} else {
|
||||
$msg = error(_("Angel not found."), true);
|
||||
}
|
||||
}
|
||||
if (! $match) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$usr['nick'] = User_Nick_render($usr);
|
||||
if ($usr['planned_departure_date'] != null) {
|
||||
$usr['rendered_planned_departure_date'] = date('Y-m-d', $usr['planned_departure_date']);
|
||||
$users = sql_select("SELECT * FROM `User` ORDER BY `Nick`");
|
||||
$arrival_count_at_day = [];
|
||||
$planned_arrival_count_at_day = [];
|
||||
$planned_departure_count_at_day = [];
|
||||
$users_matched = [];
|
||||
if ($search == "") {
|
||||
$tokens = [];
|
||||
} else {
|
||||
$usr['rendered_planned_departure_date'] = '-';
|
||||
$tokens = explode(" ", $search);
|
||||
}
|
||||
$usr['rendered_planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']);
|
||||
$usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-";
|
||||
$usr['arrived'] = $usr['Gekommen'] == 1 ? _("yes") : "";
|
||||
$usr['actions'] = $usr['Gekommen'] == 1 ? '<a href="' . page_link_to('admin_arrive') . '&reset=' . $usr['UID'] . '&search=' . $search . '">' . _("reset") . '</a>' : '<a href="' . page_link_to('admin_arrive') . '&arrived=' . $usr['UID'] . '&search=' . $search . '">' . _("arrived") . '</a>';
|
||||
foreach ($users as $usr) {
|
||||
if (count($tokens) > 0) {
|
||||
$match = false;
|
||||
$index = join(" ", $usr);
|
||||
foreach ($tokens as $t) {
|
||||
if (stristr($index, trim($t))) {
|
||||
$match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $match) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($usr['arrival_date'] > 0) {
|
||||
$day = date('Y-m-d', $usr['arrival_date']);
|
||||
if (! isset($arrival_count_at_day[$day])) {
|
||||
$arrival_count_at_day[$day] = 0;
|
||||
}
|
||||
$arrival_count_at_day[$day] ++;
|
||||
$usr['nick'] = User_Nick_render($usr);
|
||||
if ($usr['planned_departure_date'] != null) {
|
||||
$usr['rendered_planned_departure_date'] = date('Y-m-d', $usr['planned_departure_date']);
|
||||
} else {
|
||||
$usr['rendered_planned_departure_date'] = '-';
|
||||
}
|
||||
$usr['rendered_planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']);
|
||||
$usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-";
|
||||
$usr['arrived'] = $usr['Gekommen'] == 1 ? _("yes") : "";
|
||||
$usr['actions'] = $usr['Gekommen'] == 1 ? '<a href="' . page_link_to('admin_arrive') . '&reset=' . $usr['UID'] . '&search=' . $search . '">' . _("reset") . '</a>' : '<a href="' . page_link_to('admin_arrive') . '&arrived=' . $usr['UID'] . '&search=' . $search . '">' . _("arrived") . '</a>';
|
||||
|
||||
if ($usr['arrival_date'] > 0) {
|
||||
$day = date('Y-m-d', $usr['arrival_date']);
|
||||
if (! isset($arrival_count_at_day[$day])) {
|
||||
$arrival_count_at_day[$day] = 0;
|
||||
}
|
||||
$arrival_count_at_day[$day] ++;
|
||||
}
|
||||
|
||||
if ($usr['planned_arrival_date'] != null) {
|
||||
$day = date('Y-m-d', $usr['planned_arrival_date']);
|
||||
if (! isset($planned_arrival_count_at_day[$day])) {
|
||||
$planned_arrival_count_at_day[$day] = 0;
|
||||
}
|
||||
$planned_arrival_count_at_day[$day] ++;
|
||||
}
|
||||
|
||||
if ($usr['planned_departure_date'] != null && $usr['Gekommen'] == 1) {
|
||||
$day = date('Y-m-d', $usr['planned_departure_date']);
|
||||
if (! isset($planned_departure_count_at_day[$day])) {
|
||||
$planned_departure_count_at_day[$day] = 0;
|
||||
}
|
||||
$planned_departure_count_at_day[$day] ++;
|
||||
}
|
||||
|
||||
$users_matched[] = $usr;
|
||||
}
|
||||
|
||||
if ($usr['planned_arrival_date'] != null) {
|
||||
$day = date('Y-m-d', $usr['planned_arrival_date']);
|
||||
if (! isset($planned_arrival_count_at_day[$day])) {
|
||||
$planned_arrival_count_at_day[$day] = 0;
|
||||
}
|
||||
$planned_arrival_count_at_day[$day] ++;
|
||||
}
|
||||
ksort($arrival_count_at_day);
|
||||
ksort($planned_arrival_count_at_day);
|
||||
ksort($planned_departure_count_at_day);
|
||||
|
||||
if ($usr['planned_departure_date'] != null && $usr['Gekommen'] == 1) {
|
||||
$day = date('Y-m-d', $usr['planned_departure_date']);
|
||||
if (! isset($planned_departure_count_at_day[$day])) {
|
||||
$planned_departure_count_at_day[$day] = 0;
|
||||
}
|
||||
$planned_departure_count_at_day[$day] ++;
|
||||
}
|
||||
|
||||
$users_matched[] = $usr;
|
||||
}
|
||||
|
||||
ksort($arrival_count_at_day);
|
||||
ksort($planned_arrival_count_at_day);
|
||||
ksort($planned_departure_count_at_day);
|
||||
|
||||
$arrival_at_day = [];
|
||||
$arrival_sum = 0;
|
||||
foreach ($arrival_count_at_day as $day => $count) {
|
||||
$arrival_sum += $count;
|
||||
$arrival_at_day[$day] = [
|
||||
$arrival_at_day = [];
|
||||
$arrival_sum = 0;
|
||||
foreach ($arrival_count_at_day as $day => $count) {
|
||||
$arrival_sum += $count;
|
||||
$arrival_at_day[$day] = [
|
||||
'day' => $day,
|
||||
'count' => $count,
|
||||
'sum' => $arrival_sum
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$planned_arrival_at_day = [];
|
||||
$planned_arrival_sum = 0;
|
||||
foreach ($planned_arrival_count_at_day as $day => $count) {
|
||||
$planned_arrival_sum += $count;
|
||||
$planned_arrival_at_day[$day] = [
|
||||
$planned_arrival_at_day = [];
|
||||
$planned_arrival_sum = 0;
|
||||
foreach ($planned_arrival_count_at_day as $day => $count) {
|
||||
$planned_arrival_sum += $count;
|
||||
$planned_arrival_at_day[$day] = [
|
||||
'day' => $day,
|
||||
'count' => $count,
|
||||
'sum' => $planned_arrival_sum
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$planned_departure_at_day = [];
|
||||
$planned_departure_sum = 0;
|
||||
foreach ($planned_departure_count_at_day as $day => $count) {
|
||||
$planned_departure_sum += $count;
|
||||
$planned_departure_at_day[$day] = [
|
||||
$planned_departure_at_day = [];
|
||||
$planned_departure_sum = 0;
|
||||
foreach ($planned_departure_count_at_day as $day => $count) {
|
||||
$planned_departure_sum += $count;
|
||||
$planned_departure_at_day[$day] = [
|
||||
'day' => $day,
|
||||
'count' => $count,
|
||||
'sum' => $planned_departure_sum
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(admin_arrive_title(), [
|
||||
return page_with_title(admin_arrive_title(), [
|
||||
msg(),
|
||||
form([
|
||||
form_text('search', _("Search"), $search),
|
||||
|
@ -198,4 +200,3 @@ function admin_arrive() {
|
|||
])
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,37 +1,39 @@
|
|||
<?php
|
||||
|
||||
function admin_free_title() {
|
||||
return _("Free angels");
|
||||
function admin_free_title()
|
||||
{
|
||||
return _("Free angels");
|
||||
}
|
||||
|
||||
function admin_free() {
|
||||
global $privileges;
|
||||
function admin_free()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
$search = "";
|
||||
if (isset($_REQUEST['search'])) {
|
||||
$search = strip_request_item('search');
|
||||
}
|
||||
|
||||
$angeltypesearch = "";
|
||||
if (empty($_REQUEST['angeltype'])) {
|
||||
$_REQUEST['angeltype'] = '';
|
||||
} else {
|
||||
$angeltypesearch = " INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = '" . sql_escape($_REQUEST['angeltype']) . "' AND `UserAngelTypes`.`user_id` = `User`.`UID`";
|
||||
if (isset($_REQUEST['confirmed_only'])) {
|
||||
$angeltypesearch .= " AND `UserAngelTypes`.`confirm_user_id`";
|
||||
$search = "";
|
||||
if (isset($_REQUEST['search'])) {
|
||||
$search = strip_request_item('search');
|
||||
}
|
||||
$angeltypesearch .= ") ";
|
||||
}
|
||||
|
||||
$angel_types_source = sql_select("SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`");
|
||||
$angel_types = [
|
||||
$angeltypesearch = "";
|
||||
if (empty($_REQUEST['angeltype'])) {
|
||||
$_REQUEST['angeltype'] = '';
|
||||
} else {
|
||||
$angeltypesearch = " INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = '" . sql_escape($_REQUEST['angeltype']) . "' AND `UserAngelTypes`.`user_id` = `User`.`UID`";
|
||||
if (isset($_REQUEST['confirmed_only'])) {
|
||||
$angeltypesearch .= " AND `UserAngelTypes`.`confirm_user_id`";
|
||||
}
|
||||
$angeltypesearch .= ") ";
|
||||
}
|
||||
|
||||
$angel_types_source = sql_select("SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`");
|
||||
$angel_types = [
|
||||
'' => 'alle Typen'
|
||||
];
|
||||
foreach ($angel_types_source as $angel_type) {
|
||||
$angel_types[$angel_type['id']] = $angel_type['name'];
|
||||
}
|
||||
foreach ($angel_types_source as $angel_type) {
|
||||
$angel_types[$angel_type['id']] = $angel_type['name'];
|
||||
}
|
||||
|
||||
$users = sql_select("
|
||||
$users = sql_select("
|
||||
SELECT `User`.*
|
||||
FROM `User`
|
||||
${angeltypesearch}
|
||||
|
@ -41,28 +43,28 @@ function admin_free() {
|
|||
GROUP BY `User`.`UID`
|
||||
ORDER BY `Nick`");
|
||||
|
||||
$free_users_table = [];
|
||||
if ($search == "") {
|
||||
$tokens = [];
|
||||
} else {
|
||||
$tokens = explode(" ", $search);
|
||||
}
|
||||
foreach ($users as $usr) {
|
||||
if (count($tokens) > 0) {
|
||||
$match = false;
|
||||
$index = join("", $usr);
|
||||
foreach ($tokens as $t) {
|
||||
if (stristr($index, trim($t))) {
|
||||
$match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $match) {
|
||||
continue;
|
||||
}
|
||||
$free_users_table = [];
|
||||
if ($search == "") {
|
||||
$tokens = [];
|
||||
} else {
|
||||
$tokens = explode(" ", $search);
|
||||
}
|
||||
foreach ($users as $usr) {
|
||||
if (count($tokens) > 0) {
|
||||
$match = false;
|
||||
$index = join("", $usr);
|
||||
foreach ($tokens as $t) {
|
||||
if (stristr($index, trim($t))) {
|
||||
$match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $match) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$free_users_table[] = [
|
||||
$free_users_table[] = [
|
||||
'name' => User_Nick_render($usr),
|
||||
'shift_state' => User_shift_state_render($usr),
|
||||
'dect' => $usr['DECT'],
|
||||
|
@ -70,8 +72,8 @@ function admin_free() {
|
|||
'email' => $usr['email_by_human_allowed'] ? $usr['email'] : glyph('eye-close'),
|
||||
'actions' => in_array('admin_user', $privileges) ? button(page_link_to('admin_user') . '&id=' . $usr['UID'], _("edit"), 'btn-xs') : ''
|
||||
];
|
||||
}
|
||||
return page_with_title(admin_free_title(), [
|
||||
}
|
||||
return page_with_title(admin_free_title(), [
|
||||
form([
|
||||
div('row', [
|
||||
div('col-md-4', [
|
||||
|
@ -98,4 +100,3 @@ function admin_free() {
|
|||
], $free_users_table)
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,97 +1,98 @@
|
|||
<?php
|
||||
|
||||
function admin_groups_title() {
|
||||
return _("Grouprights");
|
||||
function admin_groups_title()
|
||||
{
|
||||
return _("Grouprights");
|
||||
}
|
||||
|
||||
function admin_groups() {
|
||||
$html = "";
|
||||
$groups = sql_select("SELECT * FROM `Groups` ORDER BY `Name`");
|
||||
if (! isset($_REQUEST["action"])) {
|
||||
$groups_table = [];
|
||||
foreach ($groups as $group) {
|
||||
$privileges = sql_select("SELECT * FROM `GroupPrivileges` JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) WHERE `group_id`='" . sql_escape($group['UID']) . "'");
|
||||
$privileges_html = [];
|
||||
function admin_groups()
|
||||
{
|
||||
$html = "";
|
||||
$groups = sql_select("SELECT * FROM `Groups` ORDER BY `Name`");
|
||||
if (! isset($_REQUEST["action"])) {
|
||||
$groups_table = [];
|
||||
foreach ($groups as $group) {
|
||||
$privileges = sql_select("SELECT * FROM `GroupPrivileges` JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) WHERE `group_id`='" . sql_escape($group['UID']) . "'");
|
||||
$privileges_html = [];
|
||||
|
||||
foreach ($privileges as $priv) {
|
||||
$privileges_html[] = $priv['name'];
|
||||
}
|
||||
foreach ($privileges as $priv) {
|
||||
$privileges_html[] = $priv['name'];
|
||||
}
|
||||
|
||||
$groups_table[] = [
|
||||
$groups_table[] = [
|
||||
'name' => $group['Name'],
|
||||
'privileges' => join(', ', $privileges_html),
|
||||
'actions' => button(page_link_to('admin_groups') . '&action=edit&id=' . $group['UID'], _("edit"), 'btn-xs')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(admin_groups_title(), [
|
||||
return page_with_title(admin_groups_title(), [
|
||||
table([
|
||||
'name' => _("Name"),
|
||||
'privileges' => _("Privileges"),
|
||||
'actions' => ''
|
||||
], $groups_table)
|
||||
]);
|
||||
} else {
|
||||
switch ($_REQUEST["action"]) {
|
||||
} else {
|
||||
switch ($_REQUEST["action"]) {
|
||||
case 'edit':
|
||||
if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$group_id = $_REQUEST['id'];
|
||||
$group_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error("Incomplete call, missing Groups ID.", true);
|
||||
return error("Incomplete call, missing Groups ID.", true);
|
||||
}
|
||||
|
||||
$group = sql_select("SELECT * FROM `Groups` WHERE `UID`='" . sql_escape($group_id) . "' LIMIT 1");
|
||||
if (count($group) > 0) {
|
||||
list($group) = $group;
|
||||
$privileges = sql_select("SELECT `Privileges`.*, `GroupPrivileges`.`group_id` FROM `Privileges` LEFT OUTER JOIN `GroupPrivileges` ON (`Privileges`.`id` = `GroupPrivileges`.`privilege_id` AND `GroupPrivileges`.`group_id`='" . sql_escape($group_id) . "') ORDER BY `Privileges`.`name`");
|
||||
$privileges_html = "";
|
||||
$privileges_form = [];
|
||||
foreach ($privileges as $priv) {
|
||||
$privileges_form[] = form_checkbox('privileges[]', $priv['desc'] . ' (' . $priv['name'] . ')', $priv['group_id'] != "", $priv['id']);
|
||||
$privileges_html .= sprintf('<tr><td><input type="checkbox" ' . 'name="privileges[]" value="%s" %s />' . '</td> <td>%s</td> <td>%s</td></tr>', $priv['id'], ($priv['group_id'] != "" ? 'checked="checked"' : ''), $priv['name'], $priv['desc']);
|
||||
}
|
||||
list($group) = $group;
|
||||
$privileges = sql_select("SELECT `Privileges`.*, `GroupPrivileges`.`group_id` FROM `Privileges` LEFT OUTER JOIN `GroupPrivileges` ON (`Privileges`.`id` = `GroupPrivileges`.`privilege_id` AND `GroupPrivileges`.`group_id`='" . sql_escape($group_id) . "') ORDER BY `Privileges`.`name`");
|
||||
$privileges_html = "";
|
||||
$privileges_form = [];
|
||||
foreach ($privileges as $priv) {
|
||||
$privileges_form[] = form_checkbox('privileges[]', $priv['desc'] . ' (' . $priv['name'] . ')', $priv['group_id'] != "", $priv['id']);
|
||||
$privileges_html .= sprintf('<tr><td><input type="checkbox" ' . 'name="privileges[]" value="%s" %s />' . '</td> <td>%s</td> <td>%s</td></tr>', $priv['id'], ($priv['group_id'] != "" ? 'checked="checked"' : ''), $priv['name'], $priv['desc']);
|
||||
}
|
||||
|
||||
$privileges_form[] = form_submit('submit', _("Save"));
|
||||
$html .= page_with_title(_("Edit group"), [
|
||||
$privileges_form[] = form_submit('submit', _("Save"));
|
||||
$html .= page_with_title(_("Edit group"), [
|
||||
form($privileges_form, page_link_to('admin_groups') . '&action=save&id=' . $group_id)
|
||||
]);
|
||||
} else {
|
||||
return error("No Group found.", true);
|
||||
return error("No Group found.", true);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$group_id = $_REQUEST['id'];
|
||||
$group_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error("Incomplete call, missing Groups ID.", true);
|
||||
return error("Incomplete call, missing Groups ID.", true);
|
||||
}
|
||||
|
||||
$group = sql_select("SELECT * FROM `Groups` WHERE `UID`='" . sql_escape($group_id) . "' LIMIT 1");
|
||||
if (! is_array($_REQUEST['privileges'])) {
|
||||
$_REQUEST['privileges'] = [];
|
||||
$_REQUEST['privileges'] = [];
|
||||
}
|
||||
if (count($group) > 0) {
|
||||
list($group) = $group;
|
||||
sql_query("DELETE FROM `GroupPrivileges` WHERE `group_id`='" . sql_escape($group_id) . "'");
|
||||
$privilege_names = [];
|
||||
foreach ($_REQUEST['privileges'] as $priv) {
|
||||
if (preg_match("/^[0-9]{1,}$/", $priv)) {
|
||||
$group_privileges_source = sql_select("SELECT * FROM `Privileges` WHERE `id`='" . sql_escape($priv) . "' LIMIT 1");
|
||||
if (count($group_privileges_source) > 0) {
|
||||
sql_query("INSERT INTO `GroupPrivileges` SET `group_id`='" . sql_escape($group_id) . "', `privilege_id`='" . sql_escape($priv) . "'");
|
||||
$privilege_names[] = $group_privileges_source[0]['name'];
|
||||
}
|
||||
list($group) = $group;
|
||||
sql_query("DELETE FROM `GroupPrivileges` WHERE `group_id`='" . sql_escape($group_id) . "'");
|
||||
$privilege_names = [];
|
||||
foreach ($_REQUEST['privileges'] as $priv) {
|
||||
if (preg_match("/^[0-9]{1,}$/", $priv)) {
|
||||
$group_privileges_source = sql_select("SELECT * FROM `Privileges` WHERE `id`='" . sql_escape($priv) . "' LIMIT 1");
|
||||
if (count($group_privileges_source) > 0) {
|
||||
sql_query("INSERT INTO `GroupPrivileges` SET `group_id`='" . sql_escape($group_id) . "', `privilege_id`='" . sql_escape($priv) . "'");
|
||||
$privilege_names[] = $group_privileges_source[0]['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
engelsystem_log("Group privileges of group " . $group['Name'] . " edited: " . join(", ", $privilege_names));
|
||||
redirect(page_link_to("admin_groups"));
|
||||
engelsystem_log("Group privileges of group " . $group['Name'] . " edited: " . join(", ", $privilege_names));
|
||||
redirect(page_link_to("admin_groups"));
|
||||
} else {
|
||||
return error("No Group found.", true);
|
||||
return error("No Group found.", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,95 +1,97 @@
|
|||
<?php
|
||||
|
||||
function admin_import_title() {
|
||||
return _("Frab import");
|
||||
function admin_import_title()
|
||||
{
|
||||
return _("Frab import");
|
||||
}
|
||||
|
||||
function admin_import() {
|
||||
global $rooms_import;
|
||||
global $user;
|
||||
$html = "";
|
||||
$import_dir = __DIR__ . '/../../import';
|
||||
function admin_import()
|
||||
{
|
||||
global $rooms_import;
|
||||
global $user;
|
||||
$html = "";
|
||||
$import_dir = __DIR__ . '/../../import';
|
||||
|
||||
$step = "input";
|
||||
if (isset($_REQUEST['step']) && in_array($step, [
|
||||
$step = "input";
|
||||
if (isset($_REQUEST['step']) && in_array($step, [
|
||||
'input',
|
||||
'check',
|
||||
'import'
|
||||
])) {
|
||||
$step = $_REQUEST['step'];
|
||||
}
|
||||
$step = $_REQUEST['step'];
|
||||
}
|
||||
|
||||
if ($test_handle = @fopen($import_dir . '/tmp', 'w')) {
|
||||
fclose($test_handle);
|
||||
@unlink($import_dir . '/tmp');
|
||||
} else {
|
||||
error(_('Webserver has no write-permission on import directory.'));
|
||||
}
|
||||
if ($test_handle = @fopen($import_dir . '/tmp', 'w')) {
|
||||
fclose($test_handle);
|
||||
@unlink($import_dir . '/tmp');
|
||||
} else {
|
||||
error(_('Webserver has no write-permission on import directory.'));
|
||||
}
|
||||
|
||||
$import_file = $import_dir . '/import_' . $user['UID'] . '.xml';
|
||||
$shifttype_id = null;
|
||||
$add_minutes_start = 15;
|
||||
$add_minutes_end = 15;
|
||||
$import_file = $import_dir . '/import_' . $user['UID'] . '.xml';
|
||||
$shifttype_id = null;
|
||||
$add_minutes_start = 15;
|
||||
$add_minutes_end = 15;
|
||||
|
||||
$shifttypes_source = ShiftTypes();
|
||||
if ($shifttypes_source === false) {
|
||||
engelsystem_error('Unable to load shifttypes.');
|
||||
}
|
||||
$shifttypes = [];
|
||||
foreach ($shifttypes_source as $shifttype) {
|
||||
$shifttypes[$shifttype['id']] = $shifttype['name'];
|
||||
}
|
||||
$shifttypes_source = ShiftTypes();
|
||||
if ($shifttypes_source === false) {
|
||||
engelsystem_error('Unable to load shifttypes.');
|
||||
}
|
||||
$shifttypes = [];
|
||||
foreach ($shifttypes_source as $shifttype) {
|
||||
$shifttypes[$shifttype['id']] = $shifttype['name'];
|
||||
}
|
||||
|
||||
switch ($step) {
|
||||
switch ($step) {
|
||||
case 'input':
|
||||
$valid = false;
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a shift type.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) {
|
||||
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter an amount of minutes to add to a talk's begin."));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) {
|
||||
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter an amount of minutes to add to a talk's end."));
|
||||
}
|
||||
|
||||
if (isset($_FILES['xcal_file']) && ($_FILES['xcal_file']['error'] == 0)) {
|
||||
if (move_uploaded_file($_FILES['xcal_file']['tmp_name'], $import_file)) {
|
||||
libxml_use_internal_errors(true);
|
||||
if (simplexml_load_file($import_file) === false) {
|
||||
$valid = false;
|
||||
error(_('No valid xml/xcal file provided.'));
|
||||
unlink($import_file);
|
||||
}
|
||||
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('File upload went wrong.'));
|
||||
$valid = false;
|
||||
error(_('Please select a shift type.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) {
|
||||
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter an amount of minutes to add to a talk's begin."));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) {
|
||||
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter an amount of minutes to add to a talk's end."));
|
||||
}
|
||||
|
||||
if (isset($_FILES['xcal_file']) && ($_FILES['xcal_file']['error'] == 0)) {
|
||||
if (move_uploaded_file($_FILES['xcal_file']['tmp_name'], $import_file)) {
|
||||
libxml_use_internal_errors(true);
|
||||
if (simplexml_load_file($import_file) === false) {
|
||||
$valid = false;
|
||||
error(_('No valid xml/xcal file provided.'));
|
||||
unlink($import_file);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('File upload went wrong.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please provide some data.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please provide some data.'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
redirect(page_link_to('admin_import') . "&step=check&shifttype_id=" . $shifttype_id . "&add_minutes_end=" . $add_minutes_end . "&add_minutes_start=" . $add_minutes_start);
|
||||
redirect(page_link_to('admin_import') . "&step=check&shifttype_id=" . $shifttype_id . "&add_minutes_end=" . $add_minutes_end . "&add_minutes_start=" . $add_minutes_start);
|
||||
} 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'))
|
||||
]) . div('row', [
|
||||
div('col-md-offset-3 col-md-6', [
|
||||
|
@ -108,29 +110,29 @@ function admin_import() {
|
|||
|
||||
case 'check':
|
||||
if (! file_exists($import_file)) {
|
||||
error(_('Missing import file.'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
error(_('Missing import file.'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
} else {
|
||||
error(_('Please select a shift type.'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
error(_('Please select a shift type.'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) {
|
||||
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
|
||||
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
|
||||
} else {
|
||||
error(_("Please enter an amount of minutes to add to a talk's begin."));
|
||||
redirect(page_link_to('admin_import'));
|
||||
error(_("Please enter an amount of minutes to add to a talk's begin."));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) {
|
||||
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
|
||||
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
|
||||
} else {
|
||||
error(_("Please enter an amount of minutes to add to a talk's end."));
|
||||
redirect(page_link_to('admin_import'));
|
||||
error(_("Please enter an amount of minutes to add to a talk's end."));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
list($rooms_new, $rooms_deleted) = prepare_rooms($import_file);
|
||||
|
@ -182,67 +184,67 @@ function admin_import() {
|
|||
|
||||
case 'import':
|
||||
if (! file_exists($import_file)) {
|
||||
error(_('Missing import file.'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
error(_('Missing import file.'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
if (! file_exists($import_file)) {
|
||||
redirect(page_link_to('admin_import'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
} else {
|
||||
error(_('Please select a shift type.'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
error(_('Please select a shift type.'));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) {
|
||||
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
|
||||
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
|
||||
} else {
|
||||
error(_("Please enter an amount of minutes to add to a talk's begin."));
|
||||
redirect(page_link_to('admin_import'));
|
||||
error(_("Please enter an amount of minutes to add to a talk's begin."));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) {
|
||||
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
|
||||
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
|
||||
} else {
|
||||
error(_("Please enter an amount of minutes to add to a talk's end."));
|
||||
redirect(page_link_to('admin_import'));
|
||||
error(_("Please enter an amount of minutes to add to a talk's end."));
|
||||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
list($rooms_new, $rooms_deleted) = prepare_rooms($import_file);
|
||||
foreach ($rooms_new as $room) {
|
||||
$result = Room_create($room, true, true);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create room.');
|
||||
}
|
||||
$rooms_import[trim($room)] = sql_id();
|
||||
$result = Room_create($room, true, true);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create room.');
|
||||
}
|
||||
$rooms_import[trim($room)] = sql_id();
|
||||
}
|
||||
foreach ($rooms_deleted as $room) {
|
||||
sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1");
|
||||
sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1");
|
||||
}
|
||||
|
||||
list($events_new, $events_updated, $events_deleted) = prepare_events($import_file, $shifttype_id, $add_minutes_start, $add_minutes_end);
|
||||
foreach ($events_new as $event) {
|
||||
$result = Shift_create($event);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create shift.');
|
||||
}
|
||||
$result = Shift_create($event);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to create shift.');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($events_updated as $event) {
|
||||
$result = Shift_update_by_psid($event);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shift.');
|
||||
}
|
||||
$result = Shift_update_by_psid($event);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shift.');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($events_deleted as $event) {
|
||||
$result = Shift_delete_by_psid($event['PSID']);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift.');
|
||||
}
|
||||
$result = Shift_delete_by_psid($event['PSID']);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift.');
|
||||
}
|
||||
}
|
||||
|
||||
engelsystem_log("Frab import done");
|
||||
|
@ -257,61 +259,63 @@ function admin_import() {
|
|||
redirect(page_link_to('admin_import'));
|
||||
}
|
||||
|
||||
return page_with_title(admin_import_title(), [
|
||||
return page_with_title(admin_import_title(), [
|
||||
msg(),
|
||||
$html
|
||||
]);
|
||||
}
|
||||
|
||||
function prepare_rooms($file) {
|
||||
global $rooms_import;
|
||||
$data = read_xml($file);
|
||||
function prepare_rooms($file)
|
||||
{
|
||||
global $rooms_import;
|
||||
$data = read_xml($file);
|
||||
|
||||
// Load rooms from db for compare with input
|
||||
$rooms = sql_select("SELECT * FROM `Room` WHERE `FromPentabarf`='Y'");
|
||||
$rooms_db = [];
|
||||
$rooms_import = [];
|
||||
foreach ($rooms as $room) {
|
||||
$rooms_db[] = (string) $room['Name'];
|
||||
$rooms_import[$room['Name']] = $room['RID'];
|
||||
}
|
||||
|
||||
$events = $data->vcalendar->vevent;
|
||||
$rooms_pb = [];
|
||||
foreach ($events as $event) {
|
||||
$rooms_pb[] = (string) $event->location;
|
||||
if (! isset($rooms_import[trim($event->location)])) {
|
||||
$rooms_import[trim($event->location)] = trim($event->location);
|
||||
$rooms_db = [];
|
||||
$rooms_import = [];
|
||||
foreach ($rooms as $room) {
|
||||
$rooms_db[] = (string) $room['Name'];
|
||||
$rooms_import[$room['Name']] = $room['RID'];
|
||||
}
|
||||
}
|
||||
$rooms_pb = array_unique($rooms_pb);
|
||||
|
||||
$rooms_new = array_diff($rooms_pb, $rooms_db);
|
||||
$rooms_deleted = array_diff($rooms_db, $rooms_pb);
|
||||
$events = $data->vcalendar->vevent;
|
||||
$rooms_pb = [];
|
||||
foreach ($events as $event) {
|
||||
$rooms_pb[] = (string) $event->location;
|
||||
if (! isset($rooms_import[trim($event->location)])) {
|
||||
$rooms_import[trim($event->location)] = trim($event->location);
|
||||
}
|
||||
}
|
||||
$rooms_pb = array_unique($rooms_pb);
|
||||
|
||||
return [
|
||||
$rooms_new = array_diff($rooms_pb, $rooms_db);
|
||||
$rooms_deleted = array_diff($rooms_db, $rooms_pb);
|
||||
|
||||
return [
|
||||
$rooms_new,
|
||||
$rooms_deleted
|
||||
];
|
||||
}
|
||||
|
||||
function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_end) {
|
||||
global $rooms_import;
|
||||
$data = read_xml($file);
|
||||
function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_end)
|
||||
{
|
||||
global $rooms_import;
|
||||
$data = read_xml($file);
|
||||
|
||||
$rooms = sql_select("SELECT * FROM `Room`");
|
||||
$rooms_db = [];
|
||||
foreach ($rooms as $room) {
|
||||
$rooms_db[$room['Name']] = $room['RID'];
|
||||
}
|
||||
$rooms = sql_select("SELECT * FROM `Room`");
|
||||
$rooms_db = [];
|
||||
foreach ($rooms as $room) {
|
||||
$rooms_db[$room['Name']] = $room['RID'];
|
||||
}
|
||||
|
||||
$events = $data->vcalendar->vevent;
|
||||
$shifts_pb = [];
|
||||
foreach ($events as $event) {
|
||||
$event_pb = $event->children("http://pentabarf.org");
|
||||
$event_id = trim($event_pb->{
|
||||
$events = $data->vcalendar->vevent;
|
||||
$shifts_pb = [];
|
||||
foreach ($events as $event) {
|
||||
$event_pb = $event->children("http://pentabarf.org");
|
||||
$event_id = trim($event_pb->{
|
||||
'event-id' });
|
||||
$shifts_pb[$event_id] = [
|
||||
$shifts_pb[$event_id] = [
|
||||
'shifttype_id' => $shifttype_id,
|
||||
'start' => parse_date("Ymd\THis", $event->dtstart) - $add_minutes_start * 60,
|
||||
'end' => parse_date("Ymd\THis", $event->dtend) + $add_minutes_end * 60,
|
||||
|
@ -320,58 +324,60 @@ function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_e
|
|||
'URL' => trim($event->url),
|
||||
'PSID' => $event_id
|
||||
];
|
||||
}
|
||||
|
||||
$shifts = sql_select("SELECT * FROM `Shifts` WHERE `PSID` IS NOT NULL ORDER BY `start`");
|
||||
$shifts_db = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$shifts_db[$shift['PSID']] = $shift;
|
||||
}
|
||||
|
||||
$shifts_new = [];
|
||||
$shifts_updated = [];
|
||||
foreach ($shifts_pb as $shift) {
|
||||
if (! isset($shifts_db[$shift['PSID']])) {
|
||||
$shifts_new[] = $shift;
|
||||
} else {
|
||||
$tmp = $shifts_db[$shift['PSID']];
|
||||
if ($shift['shifttype_id'] != $tmp['shifttype_id'] || $shift['title'] != $tmp['title'] || $shift['start'] != $tmp['start'] || $shift['end'] != $tmp['end'] || $shift['RID'] != $tmp['RID'] || $shift['URL'] != $tmp['URL']) {
|
||||
$shifts_updated[] = $shift;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$shifts_deleted = [];
|
||||
foreach ($shifts_db as $shift) {
|
||||
if (! isset($shifts_pb[$shift['PSID']])) {
|
||||
$shifts_deleted[] = $shift;
|
||||
$shifts = sql_select("SELECT * FROM `Shifts` WHERE `PSID` IS NOT NULL ORDER BY `start`");
|
||||
$shifts_db = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$shifts_db[$shift['PSID']] = $shift;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
$shifts_new = [];
|
||||
$shifts_updated = [];
|
||||
foreach ($shifts_pb as $shift) {
|
||||
if (! isset($shifts_db[$shift['PSID']])) {
|
||||
$shifts_new[] = $shift;
|
||||
} else {
|
||||
$tmp = $shifts_db[$shift['PSID']];
|
||||
if ($shift['shifttype_id'] != $tmp['shifttype_id'] || $shift['title'] != $tmp['title'] || $shift['start'] != $tmp['start'] || $shift['end'] != $tmp['end'] || $shift['RID'] != $tmp['RID'] || $shift['URL'] != $tmp['URL']) {
|
||||
$shifts_updated[] = $shift;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$shifts_deleted = [];
|
||||
foreach ($shifts_db as $shift) {
|
||||
if (! isset($shifts_pb[$shift['PSID']])) {
|
||||
$shifts_deleted[] = $shift;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
$shifts_new,
|
||||
$shifts_updated,
|
||||
$shifts_deleted
|
||||
];
|
||||
}
|
||||
|
||||
function read_xml($file) {
|
||||
global $xml_import;
|
||||
if (! isset($xml_import)) {
|
||||
$xml_import = simplexml_load_file($file);
|
||||
}
|
||||
return $xml_import;
|
||||
function read_xml($file)
|
||||
{
|
||||
global $xml_import;
|
||||
if (! isset($xml_import)) {
|
||||
$xml_import = simplexml_load_file($file);
|
||||
}
|
||||
return $xml_import;
|
||||
}
|
||||
|
||||
function shifts_printable($shifts, $shifttypes) {
|
||||
global $rooms_import;
|
||||
$rooms = array_flip($rooms_import);
|
||||
function shifts_printable($shifts, $shifttypes)
|
||||
{
|
||||
global $rooms_import;
|
||||
$rooms = array_flip($rooms_import);
|
||||
|
||||
uasort($shifts, 'shift_sort');
|
||||
uasort($shifts, 'shift_sort');
|
||||
|
||||
$shifts_printable = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$shifts_printable[] = [
|
||||
$shifts_printable = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$shifts_printable[] = [
|
||||
'day' => date("l, Y-m-d", $shift['start']),
|
||||
'start' => date("H:i", $shift['start']),
|
||||
'shifttype' => ShiftType_name_render([
|
||||
|
@ -382,11 +388,11 @@ function shifts_printable($shifts, $shifttypes) {
|
|||
'end' => date("H:i", $shift['end']),
|
||||
'room' => $rooms[$shift['RID']]
|
||||
];
|
||||
}
|
||||
return $shifts_printable;
|
||||
}
|
||||
return $shifts_printable;
|
||||
}
|
||||
|
||||
function shift_sort($shift_a, $shift_b) {
|
||||
return ($shift_a['start'] < $shift_b['start']) ? - 1 : 1;
|
||||
function shift_sort($shift_a, $shift_b)
|
||||
{
|
||||
return ($shift_a['start'] < $shift_b['start']) ? - 1 : 1;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
<?php
|
||||
|
||||
function admin_log_title() {
|
||||
return _("Log");
|
||||
function admin_log_title()
|
||||
{
|
||||
return _("Log");
|
||||
}
|
||||
|
||||
function admin_log() {
|
||||
$filter = "";
|
||||
if (isset($_REQUEST['keyword'])) {
|
||||
$filter = strip_request_item('keyword');
|
||||
}
|
||||
$log_entries_source = LogEntries_filter($filter);
|
||||
function admin_log()
|
||||
{
|
||||
$filter = "";
|
||||
if (isset($_REQUEST['keyword'])) {
|
||||
$filter = strip_request_item('keyword');
|
||||
}
|
||||
$log_entries_source = LogEntries_filter($filter);
|
||||
|
||||
$log_entries = [];
|
||||
foreach ($log_entries_source as $log_entry) {
|
||||
$log_entry['date'] = date("d.m.Y H:i", $log_entry['timestamp']);
|
||||
$log_entries[] = $log_entry;
|
||||
}
|
||||
$log_entries = [];
|
||||
foreach ($log_entries_source as $log_entry) {
|
||||
$log_entry['date'] = date("d.m.Y H:i", $log_entry['timestamp']);
|
||||
$log_entries[] = $log_entry;
|
||||
}
|
||||
|
||||
return page_with_title(admin_log_title(), [
|
||||
return page_with_title(admin_log_title(), [
|
||||
msg(),
|
||||
form([
|
||||
form_text('keyword', _("Search"), $filter),
|
||||
|
@ -30,4 +32,3 @@ function admin_log() {
|
|||
], $log_entries)
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
<?php
|
||||
|
||||
function admin_news() {
|
||||
global $user;
|
||||
function admin_news()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_GET["action"])) {
|
||||
redirect(page_link_to("news"));
|
||||
}
|
||||
if (! isset($_GET["action"])) {
|
||||
redirect(page_link_to("news"));
|
||||
}
|
||||
|
||||
$html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$news_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error("Incomplete call, missing News ID.", true);
|
||||
}
|
||||
$html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$news_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error("Incomplete call, missing News ID.", true);
|
||||
}
|
||||
|
||||
$news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
|
||||
if (empty($news)) {
|
||||
return error("No News found.", true);
|
||||
}
|
||||
switch ($_REQUEST["action"]) {
|
||||
$news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
|
||||
if (empty($news)) {
|
||||
return error("No News found.", true);
|
||||
}
|
||||
switch ($_REQUEST["action"]) {
|
||||
default:
|
||||
redirect(page_link_to('news'));
|
||||
case 'edit':
|
||||
|
@ -62,6 +63,5 @@ function admin_news() {
|
|||
redirect(page_link_to("news"));
|
||||
break;
|
||||
}
|
||||
return $html . '</div>';
|
||||
return $html . '</div>';
|
||||
}
|
||||
?>
|
|
@ -1,38 +1,41 @@
|
|||
<?php
|
||||
|
||||
function admin_questions_title() {
|
||||
return _("Answer questions");
|
||||
function admin_questions_title()
|
||||
{
|
||||
return _("Answer questions");
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a hint for new questions to answer.
|
||||
*/
|
||||
function admin_new_questions() {
|
||||
global $privileges, $page;
|
||||
function admin_new_questions()
|
||||
{
|
||||
global $privileges, $page;
|
||||
|
||||
if ($page != "admin_questions") {
|
||||
if (in_array("admin_questions", $privileges)) {
|
||||
$new_messages = sql_num_query("SELECT * FROM `Questions` WHERE `AID` IS NULL");
|
||||
if ($page != "admin_questions") {
|
||||
if (in_array("admin_questions", $privileges)) {
|
||||
$new_messages = sql_num_query("SELECT * FROM `Questions` WHERE `AID` IS NULL");
|
||||
|
||||
if ($new_messages > 0) {
|
||||
return '<a href="' . page_link_to("admin_questions") . '">' . _('There are unanswered questions!') . '</a>';
|
||||
}
|
||||
if ($new_messages > 0) {
|
||||
return '<a href="' . page_link_to("admin_questions") . '">' . _('There are unanswered questions!') . '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
function admin_questions() {
|
||||
global $user;
|
||||
function admin_questions()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$unanswered_questions_table = [];
|
||||
$questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL");
|
||||
foreach ($questions as $question) {
|
||||
$user_source = User($question['UID']);
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$unanswered_questions_table = [];
|
||||
$questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL");
|
||||
foreach ($questions as $question) {
|
||||
$user_source = User($question['UID']);
|
||||
|
||||
$unanswered_questions_table[] = [
|
||||
$unanswered_questions_table[] = [
|
||||
'from' => User_Nick_render($user_source),
|
||||
'question' => str_replace("\n", "<br />", $question['Question']),
|
||||
'answer' => form([
|
||||
|
@ -41,23 +44,23 @@ function admin_questions() {
|
|||
], page_link_to('admin_questions') . '&action=answer&id=' . $question['QID']),
|
||||
'actions' => button(page_link_to("admin_questions") . '&action=delete&id=' . $question['QID'], _("delete"), 'btn-xs')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$answered_questions_table = [];
|
||||
$questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL");
|
||||
foreach ($questions as $question) {
|
||||
$user_source = User($question['UID']);
|
||||
$answer_user_source = User($question['AID']);
|
||||
$answered_questions_table[] = [
|
||||
$answered_questions_table = [];
|
||||
$questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL");
|
||||
foreach ($questions as $question) {
|
||||
$user_source = User($question['UID']);
|
||||
$answer_user_source = User($question['AID']);
|
||||
$answered_questions_table[] = [
|
||||
'from' => User_Nick_render($user_source),
|
||||
'question' => str_replace("\n", "<br />", $question['Question']),
|
||||
'answered_by' => User_Nick_render($answer_user_source),
|
||||
'answer' => str_replace("\n", "<br />", $question['Answer']),
|
||||
'actions' => button(page_link_to("admin_questions") . '&action=delete&id=' . $question['QID'], _("delete"), 'btn-xs')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(admin_questions_title(), [
|
||||
return page_with_title(admin_questions_title(), [
|
||||
'<h2>' . _("Unanswered questions") . '</h2>',
|
||||
table([
|
||||
'from' => _("From"),
|
||||
|
@ -74,47 +77,46 @@ function admin_questions() {
|
|||
'actions' => ''
|
||||
], $answered_questions_table)
|
||||
]);
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'answer':
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$question_id = $_REQUEST['id'];
|
||||
$question_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error("Incomplete call, missing Question ID.", true);
|
||||
return error("Incomplete call, missing Question ID.", true);
|
||||
}
|
||||
|
||||
$question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
if (count($question) > 0 && $question[0]['AID'] == null) {
|
||||
$answer = trim(preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($_REQUEST['answer'])));
|
||||
$answer = trim(preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($_REQUEST['answer'])));
|
||||
|
||||
if ($answer != "") {
|
||||
sql_query("UPDATE `Questions` SET `AID`='" . sql_escape($user['UID']) . "', `Answer`='" . sql_escape($answer) . "' WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
engelsystem_log("Question " . $question[0]['Question'] . " answered: " . $answer);
|
||||
redirect(page_link_to("admin_questions"));
|
||||
} else {
|
||||
return error("Enter an answer!", true);
|
||||
}
|
||||
if ($answer != "") {
|
||||
sql_query("UPDATE `Questions` SET `AID`='" . sql_escape($user['UID']) . "', `Answer`='" . sql_escape($answer) . "' WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
engelsystem_log("Question " . $question[0]['Question'] . " answered: " . $answer);
|
||||
redirect(page_link_to("admin_questions"));
|
||||
} else {
|
||||
return error("Enter an answer!", true);
|
||||
}
|
||||
} else {
|
||||
return error("No question found.", true);
|
||||
return error("No question found.", true);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$question_id = $_REQUEST['id'];
|
||||
$question_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error("Incomplete call, missing Question ID.", true);
|
||||
return error("Incomplete call, missing Question ID.", true);
|
||||
}
|
||||
|
||||
$question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
if (count($question) > 0) {
|
||||
sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
engelsystem_log("Question deleted: " . $question[0]['Question']);
|
||||
redirect(page_link_to("admin_questions"));
|
||||
sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
engelsystem_log("Question deleted: " . $question[0]['Question']);
|
||||
redirect(page_link_to("admin_questions"));
|
||||
} else {
|
||||
return error("No question found.", true);
|
||||
return error("No question found.", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
|
||||
function admin_rooms_title() {
|
||||
return _("Rooms");
|
||||
function admin_rooms_title()
|
||||
{
|
||||
return _("Rooms");
|
||||
}
|
||||
|
||||
function admin_rooms() {
|
||||
$rooms_source = sql_select("SELECT * FROM `Room` ORDER BY `Name`");
|
||||
$rooms = [];
|
||||
foreach ($rooms_source as $room) {
|
||||
$rooms[] = [
|
||||
function admin_rooms()
|
||||
{
|
||||
$rooms_source = sql_select("SELECT * FROM `Room` ORDER BY `Name`");
|
||||
$rooms = [];
|
||||
foreach ($rooms_source as $room) {
|
||||
$rooms[] = [
|
||||
'name' => Room_name_render($room),
|
||||
'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '✓' : '',
|
||||
'public' => $room['show'] == 'Y' ? '✓' : '',
|
||||
|
@ -17,122 +19,122 @@ function admin_rooms() {
|
|||
button(page_link_to('admin_rooms') . '&show=delete&id=' . $room['RID'], _("delete"), 'btn-xs')
|
||||
])
|
||||
];
|
||||
}
|
||||
$room = null;
|
||||
|
||||
if (isset($_REQUEST['show'])) {
|
||||
$msg = "";
|
||||
$name = "";
|
||||
$from_pentabarf = "";
|
||||
$public = 'Y';
|
||||
$number = "";
|
||||
|
||||
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
||||
$angeltypes = [];
|
||||
$angeltypes_count = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
$angeltypes_count[$angeltype['id']] = 0;
|
||||
}
|
||||
$room = null;
|
||||
|
||||
if (test_request_int('id')) {
|
||||
$room = Room($_REQUEST['id']);
|
||||
if ($room === false) {
|
||||
engelsystem_error("Unable to load room.");
|
||||
}
|
||||
if ($room == null) {
|
||||
redirect(page_link_to('admin_rooms'));
|
||||
}
|
||||
if (isset($_REQUEST['show'])) {
|
||||
$msg = "";
|
||||
$name = "";
|
||||
$from_pentabarf = "";
|
||||
$public = 'Y';
|
||||
$number = "";
|
||||
|
||||
$room_id = $_REQUEST['id'];
|
||||
$name = $room['Name'];
|
||||
$from_pentabarf = $room['FromPentabarf'];
|
||||
$public = $room['show'];
|
||||
$number = $room['Number'];
|
||||
|
||||
$needed_angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
|
||||
foreach ($needed_angeltypes as $needed_angeltype) {
|
||||
$angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($_REQUEST['show'] == 'edit') {
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['name']) && strlen(strip_request_item('name')) > 0) {
|
||||
$name = strip_request_item('name');
|
||||
if (isset($room) && sql_num_query("SELECT * FROM `Room` WHERE `Name`='" . sql_escape($name) . "' AND NOT `RID`=" . sql_escape($room_id)) > 0) {
|
||||
$valid = false;
|
||||
$msg .= error(_("This name is already in use."), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a name."), true);
|
||||
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
||||
$angeltypes = [];
|
||||
$angeltypes_count = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
$angeltypes_count[$angeltype['id']] = 0;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['from_pentabarf'])) {
|
||||
$from_pentabarf = 'Y';
|
||||
} else {
|
||||
$from_pentabarf = '';
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['public'])) {
|
||||
$public = 'Y';
|
||||
} else {
|
||||
$public = '';
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['number'])) {
|
||||
$number = strip_request_item('number');
|
||||
} else {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
foreach ($angeltypes as $angeltype_id => $angeltype) {
|
||||
if (isset($_REQUEST['angeltype_count_' . $angeltype_id]) && preg_match("/^[0-9]{1,4}$/", $_REQUEST['angeltype_count_' . $angeltype_id])) {
|
||||
$angeltypes_count[$angeltype_id] = $_REQUEST['angeltype_count_' . $angeltype_id];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Please enter needed angels for type %s.", $angeltype)), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
if (isset($room_id)) {
|
||||
sql_query("UPDATE `Room` SET `Name`='" . sql_escape($name) . "', `FromPentabarf`='" . sql_escape($from_pentabarf) . "', `show`='" . sql_escape($public) . "', `Number`='" . sql_escape($number) . "' WHERE `RID`='" . sql_escape($room_id) . "' LIMIT 1");
|
||||
engelsystem_log("Room updated: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
|
||||
} else {
|
||||
$room_id = Room_create($name, $from_pentabarf, $public, $number);
|
||||
if ($room_id === false) {
|
||||
engelsystem_error("Unable to create room.");
|
||||
if (test_request_int('id')) {
|
||||
$room = Room($_REQUEST['id']);
|
||||
if ($room === false) {
|
||||
engelsystem_error("Unable to load room.");
|
||||
}
|
||||
engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
|
||||
}
|
||||
|
||||
NeededAngelTypes_delete_by_room($room_id);
|
||||
$needed_angeltype_info = [];
|
||||
foreach ($angeltypes_count as $angeltype_id => $angeltype_count) {
|
||||
$angeltype = AngelType($angeltype_id);
|
||||
if ($angeltype != null) {
|
||||
NeededAngelType_add(null, $angeltype_id, $room_id, $angeltype_count);
|
||||
$needed_angeltype_info[] = $angeltype['name'] . ": " . $angeltype_count;
|
||||
if ($room == null) {
|
||||
redirect(page_link_to('admin_rooms'));
|
||||
}
|
||||
}
|
||||
|
||||
engelsystem_log("Set needed angeltypes of room " . $name . " to: " . join(", ", $needed_angeltype_info));
|
||||
success(_("Room saved."));
|
||||
redirect(page_link_to("admin_rooms"));
|
||||
$room_id = $_REQUEST['id'];
|
||||
$name = $room['Name'];
|
||||
$from_pentabarf = $room['FromPentabarf'];
|
||||
$public = $room['show'];
|
||||
$number = $room['Number'];
|
||||
|
||||
$needed_angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
|
||||
foreach ($needed_angeltypes as $needed_angeltype) {
|
||||
$angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$angeltypes_count_form = [];
|
||||
foreach ($angeltypes as $angeltype_id => $angeltype) {
|
||||
$angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', [
|
||||
|
||||
if ($_REQUEST['show'] == 'edit') {
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['name']) && strlen(strip_request_item('name')) > 0) {
|
||||
$name = strip_request_item('name');
|
||||
if (isset($room) && sql_num_query("SELECT * FROM `Room` WHERE `Name`='" . sql_escape($name) . "' AND NOT `RID`=" . sql_escape($room_id)) > 0) {
|
||||
$valid = false;
|
||||
$msg .= error(_("This name is already in use."), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a name."), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['from_pentabarf'])) {
|
||||
$from_pentabarf = 'Y';
|
||||
} else {
|
||||
$from_pentabarf = '';
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['public'])) {
|
||||
$public = 'Y';
|
||||
} else {
|
||||
$public = '';
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['number'])) {
|
||||
$number = strip_request_item('number');
|
||||
} else {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
foreach ($angeltypes as $angeltype_id => $angeltype) {
|
||||
if (isset($_REQUEST['angeltype_count_' . $angeltype_id]) && preg_match("/^[0-9]{1,4}$/", $_REQUEST['angeltype_count_' . $angeltype_id])) {
|
||||
$angeltypes_count[$angeltype_id] = $_REQUEST['angeltype_count_' . $angeltype_id];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Please enter needed angels for type %s.", $angeltype)), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
if (isset($room_id)) {
|
||||
sql_query("UPDATE `Room` SET `Name`='" . sql_escape($name) . "', `FromPentabarf`='" . sql_escape($from_pentabarf) . "', `show`='" . sql_escape($public) . "', `Number`='" . sql_escape($number) . "' WHERE `RID`='" . sql_escape($room_id) . "' LIMIT 1");
|
||||
engelsystem_log("Room updated: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
|
||||
} else {
|
||||
$room_id = Room_create($name, $from_pentabarf, $public, $number);
|
||||
if ($room_id === false) {
|
||||
engelsystem_error("Unable to create room.");
|
||||
}
|
||||
engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
|
||||
}
|
||||
|
||||
NeededAngelTypes_delete_by_room($room_id);
|
||||
$needed_angeltype_info = [];
|
||||
foreach ($angeltypes_count as $angeltype_id => $angeltype_count) {
|
||||
$angeltype = AngelType($angeltype_id);
|
||||
if ($angeltype != null) {
|
||||
NeededAngelType_add(null, $angeltype_id, $room_id, $angeltype_count);
|
||||
$needed_angeltype_info[] = $angeltype['name'] . ": " . $angeltype_count;
|
||||
}
|
||||
}
|
||||
|
||||
engelsystem_log("Set needed angeltypes of room " . $name . " to: " . join(", ", $needed_angeltype_info));
|
||||
success(_("Room saved."));
|
||||
redirect(page_link_to("admin_rooms"));
|
||||
}
|
||||
}
|
||||
$angeltypes_count_form = [];
|
||||
foreach ($angeltypes as $angeltype_id => $angeltype) {
|
||||
$angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', [
|
||||
form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id])
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(admin_rooms_title(), [
|
||||
return page_with_title(admin_rooms_title(), [
|
||||
buttons([
|
||||
button(page_link_to('admin_rooms'), _("back"), 'back')
|
||||
]),
|
||||
|
@ -157,18 +159,18 @@ function admin_rooms() {
|
|||
form_submit('submit', _("Save"))
|
||||
])
|
||||
]);
|
||||
} elseif ($_REQUEST['show'] == 'delete') {
|
||||
if (isset($_REQUEST['ack'])) {
|
||||
if (! Room_delete($room_id)) {
|
||||
engelsystem_error("Unable to delete room.");
|
||||
}
|
||||
} elseif ($_REQUEST['show'] == 'delete') {
|
||||
if (isset($_REQUEST['ack'])) {
|
||||
if (! Room_delete($room_id)) {
|
||||
engelsystem_error("Unable to delete room.");
|
||||
}
|
||||
|
||||
engelsystem_log("Room deleted: " . $name);
|
||||
success(sprintf(_("Room %s deleted."), $name));
|
||||
redirect(page_link_to('admin_rooms'));
|
||||
}
|
||||
engelsystem_log("Room deleted: " . $name);
|
||||
success(sprintf(_("Room %s deleted."), $name));
|
||||
redirect(page_link_to('admin_rooms'));
|
||||
}
|
||||
|
||||
return page_with_title(admin_rooms_title(), [
|
||||
return page_with_title(admin_rooms_title(), [
|
||||
buttons([
|
||||
button(page_link_to('admin_rooms'), _("back"), 'back')
|
||||
]),
|
||||
|
@ -177,10 +179,10 @@ function admin_rooms() {
|
|||
button(page_link_to('admin_rooms') . '&show=delete&id=' . $room_id . '&ack', _("Delete"), 'delete')
|
||||
])
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(admin_rooms_title(), [
|
||||
return page_with_title(admin_rooms_title(), [
|
||||
buttons([
|
||||
button(page_link_to('admin_rooms') . '&show=edit', _("add"))
|
||||
]),
|
||||
|
@ -193,4 +195,3 @@ function admin_rooms() {
|
|||
], $rooms)
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,182 +1,184 @@
|
|||
<?php
|
||||
|
||||
function admin_shifts_title() {
|
||||
return _("Create shifts");
|
||||
function admin_shifts_title()
|
||||
{
|
||||
return _("Create shifts");
|
||||
}
|
||||
|
||||
// Assistent zum Anlegen mehrerer neuer Schichten
|
||||
function admin_shifts() {
|
||||
$valid = true;
|
||||
function admin_shifts()
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
$rid = 0;
|
||||
$start = parse_date("Y-m-d H:i", date("Y-m-d") . " 00:00");
|
||||
$end = $start;
|
||||
$mode = 'single';
|
||||
$angelmode = 'manually';
|
||||
$length = '';
|
||||
$change_hours = [];
|
||||
$title = "";
|
||||
$shifttype_id = null;
|
||||
$rid = 0;
|
||||
$start = parse_date("Y-m-d H:i", date("Y-m-d") . " 00:00");
|
||||
$end = $start;
|
||||
$mode = 'single';
|
||||
$angelmode = 'manually';
|
||||
$length = '';
|
||||
$change_hours = [];
|
||||
$title = "";
|
||||
$shifttype_id = null;
|
||||
|
||||
// Locations laden (auch unsichtbare - fuer Erzengel ist das ok)
|
||||
$rooms = sql_select("SELECT * FROM `Room` ORDER BY `Name`");
|
||||
$room_array = [];
|
||||
foreach ($rooms as $room) {
|
||||
$room_array[$room['RID']] = $room['Name'];
|
||||
}
|
||||
$room_array = [];
|
||||
foreach ($rooms as $room) {
|
||||
$room_array[$room['RID']] = $room['Name'];
|
||||
}
|
||||
|
||||
// Engeltypen laden
|
||||
$types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
||||
$needed_angel_types = [];
|
||||
foreach ($types as $type) {
|
||||
$needed_angel_types[$type['id']] = 0;
|
||||
}
|
||||
$needed_angel_types = [];
|
||||
foreach ($types as $type) {
|
||||
$needed_angel_types[$type['id']] = 0;
|
||||
}
|
||||
|
||||
// Load shift types
|
||||
$shifttypes_source = ShiftTypes();
|
||||
if ($shifttypes_source === false) {
|
||||
engelsystem_error('Unable to load shift types.');
|
||||
}
|
||||
$shifttypes = [];
|
||||
foreach ($shifttypes_source as $shifttype) {
|
||||
$shifttypes[$shifttype['id']] = $shifttype['name'];
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['preview']) || isset($_REQUEST['back'])) {
|
||||
if (isset($_REQUEST['shifttype_id'])) {
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shift type.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
$valid = false;
|
||||
error(_('Please select a shift type.'));
|
||||
} else {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a shift type.'));
|
||||
if ($shifttypes_source === false) {
|
||||
engelsystem_error('Unable to load shift types.');
|
||||
}
|
||||
$shifttypes = [];
|
||||
foreach ($shifttypes_source as $shifttype) {
|
||||
$shifttypes[$shifttype['id']] = $shifttype['name'];
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['preview']) || isset($_REQUEST['back'])) {
|
||||
if (isset($_REQUEST['shifttype_id'])) {
|
||||
$shifttype = ShiftType($_REQUEST['shifttype_id']);
|
||||
if ($shifttype === false) {
|
||||
engelsystem_error('Unable to load shift type.');
|
||||
}
|
||||
if ($shifttype == null) {
|
||||
$valid = false;
|
||||
error(_('Please select a shift type.'));
|
||||
} else {
|
||||
$shifttype_id = $_REQUEST['shifttype_id'];
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a shift type.'));
|
||||
}
|
||||
|
||||
// Name/Bezeichnung der Schicht, darf leer sein
|
||||
$title = strip_request_item('title');
|
||||
|
||||
// Auswahl der sichtbaren Locations für die Schichten
|
||||
if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room_array[$_REQUEST['rid']])) {
|
||||
$rid = $_REQUEST['rid'];
|
||||
$rid = $_REQUEST['rid'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$rid = $rooms[0]['RID'];
|
||||
error(_('Please select a location.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
|
||||
$start = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a start time.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
|
||||
$end = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select an end time.'));
|
||||
}
|
||||
|
||||
if ($start >= $end) {
|
||||
$valid = false;
|
||||
error(_('The shifts end has to be after its start.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['mode'])) {
|
||||
if ($_REQUEST['mode'] == 'single') {
|
||||
$mode = 'single';
|
||||
} elseif ($_REQUEST['mode'] == 'multi') {
|
||||
if (isset($_REQUEST['length']) && preg_match("/^[0-9]+$/", trim($_REQUEST['length']))) {
|
||||
$mode = 'multi';
|
||||
$length = trim($_REQUEST['length']);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter a shift duration in minutes.'));
|
||||
}
|
||||
} elseif ($_REQUEST['mode'] == 'variable') {
|
||||
if (isset($_REQUEST['change_hours']) && preg_match("/^([0-9]{2}(,|$))/", trim(str_replace(" ", "", $_REQUEST['change_hours'])))) {
|
||||
$mode = 'variable';
|
||||
$change_hours = array_map('trim', explode(",", $_REQUEST['change_hours']));
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please split the shift-change hours by colons.'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a mode.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['angelmode'])) {
|
||||
if ($_REQUEST['angelmode'] == 'location') {
|
||||
$angelmode = 'location';
|
||||
} elseif ($_REQUEST['angelmode'] == 'manually') {
|
||||
$angelmode = 'manually';
|
||||
foreach ($types as $type) {
|
||||
if (isset($_REQUEST['type_' . $type['id']]) && preg_match("/^[0-9]+$/", trim($_REQUEST['type_' . $type['id']]))) {
|
||||
$needed_angel_types[$type['id']] = trim($_REQUEST['type_' . $type['id']]);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(sprintf(_('Please check the needed angels for team %s.'), $type['name']));
|
||||
}
|
||||
}
|
||||
if (array_sum($needed_angel_types) == 0) {
|
||||
$valid = false;
|
||||
error(_('There are 0 angels needed. Please enter the amounts of needed angels.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a mode for needed angels.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select needed angels.'));
|
||||
$rid = $rooms[0]['RID'];
|
||||
error(_('Please select a location.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
|
||||
$start = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a start time.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
|
||||
$end = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select an end time.'));
|
||||
}
|
||||
|
||||
if ($start >= $end) {
|
||||
$valid = false;
|
||||
error(_('The shifts end has to be after its start.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['mode'])) {
|
||||
if ($_REQUEST['mode'] == 'single') {
|
||||
$mode = 'single';
|
||||
} elseif ($_REQUEST['mode'] == 'multi') {
|
||||
if (isset($_REQUEST['length']) && preg_match("/^[0-9]+$/", trim($_REQUEST['length']))) {
|
||||
$mode = 'multi';
|
||||
$length = trim($_REQUEST['length']);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please enter a shift duration in minutes.'));
|
||||
}
|
||||
} elseif ($_REQUEST['mode'] == 'variable') {
|
||||
if (isset($_REQUEST['change_hours']) && preg_match("/^([0-9]{2}(,|$))/", trim(str_replace(" ", "", $_REQUEST['change_hours'])))) {
|
||||
$mode = 'variable';
|
||||
$change_hours = array_map('trim', explode(",", $_REQUEST['change_hours']));
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please split the shift-change hours by colons.'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a mode.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['angelmode'])) {
|
||||
if ($_REQUEST['angelmode'] == 'location') {
|
||||
$angelmode = 'location';
|
||||
} elseif ($_REQUEST['angelmode'] == 'manually') {
|
||||
$angelmode = 'manually';
|
||||
foreach ($types as $type) {
|
||||
if (isset($_REQUEST['type_' . $type['id']]) && preg_match("/^[0-9]+$/", trim($_REQUEST['type_' . $type['id']]))) {
|
||||
$needed_angel_types[$type['id']] = trim($_REQUEST['type_' . $type['id']]);
|
||||
} else {
|
||||
$valid = false;
|
||||
error(sprintf(_('Please check the needed angels for team %s.'), $type['name']));
|
||||
}
|
||||
}
|
||||
if (array_sum($needed_angel_types) == 0) {
|
||||
$valid = false;
|
||||
error(_('There are 0 angels needed. Please enter the amounts of needed angels.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a mode for needed angels.'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select needed angels.'));
|
||||
}
|
||||
|
||||
// Beim Zurück-Knopf das Formular zeigen
|
||||
if (isset($_REQUEST['back'])) {
|
||||
$valid = false;
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
// Alle Eingaben in Ordnung
|
||||
if ($valid) {
|
||||
if ($angelmode == 'location') {
|
||||
$needed_angel_types = [];
|
||||
$needed_angel_types_location = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($rid) . "'");
|
||||
foreach ($needed_angel_types_location as $type) {
|
||||
$needed_angel_types[$type['angel_type_id']] = $type['count'];
|
||||
if ($angelmode == 'location') {
|
||||
$needed_angel_types = [];
|
||||
$needed_angel_types_location = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($rid) . "'");
|
||||
foreach ($needed_angel_types_location as $type) {
|
||||
$needed_angel_types[$type['angel_type_id']] = $type['count'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$shifts = [];
|
||||
if ($mode == 'single') {
|
||||
$shifts[] = [
|
||||
$shifts = [];
|
||||
if ($mode == 'single') {
|
||||
$shifts[] = [
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'RID' => $rid,
|
||||
'title' => $title,
|
||||
'shifttype_id' => $shifttype_id
|
||||
];
|
||||
} elseif ($mode == 'multi') {
|
||||
$shift_start = $start;
|
||||
do {
|
||||
$shift_end = $shift_start + $length * 60;
|
||||
} elseif ($mode == 'multi') {
|
||||
$shift_start = $start;
|
||||
do {
|
||||
$shift_end = $shift_start + $length * 60;
|
||||
|
||||
if ($shift_end > $end) {
|
||||
$shift_end = $end;
|
||||
}
|
||||
if ($shift_start >= $shift_end) {
|
||||
break;
|
||||
}
|
||||
if ($shift_end > $end) {
|
||||
$shift_end = $end;
|
||||
}
|
||||
if ($shift_start >= $shift_end) {
|
||||
break;
|
||||
}
|
||||
|
||||
$shifts[] = [
|
||||
$shifts[] = [
|
||||
'start' => $shift_start,
|
||||
'end' => $shift_end,
|
||||
'RID' => $rid,
|
||||
|
@ -184,38 +186,38 @@ function admin_shifts() {
|
|||
'shifttype_id' => $shifttype_id
|
||||
];
|
||||
|
||||
$shift_start = $shift_end;
|
||||
} while ($shift_end < $end);
|
||||
} elseif ($mode == 'variable') {
|
||||
rsort($change_hours);
|
||||
$day = parse_date("Y-m-d H:i", date("Y-m-d", $start) . " 00:00");
|
||||
$change_index = 0;
|
||||
$shift_start = $shift_end;
|
||||
} while ($shift_end < $end);
|
||||
} elseif ($mode == 'variable') {
|
||||
rsort($change_hours);
|
||||
$day = parse_date("Y-m-d H:i", date("Y-m-d", $start) . " 00:00");
|
||||
$change_index = 0;
|
||||
// Ersten/nächsten passenden Schichtwechsel suchen
|
||||
foreach ($change_hours as $i => $change_hour) {
|
||||
if ($start < $day + $change_hour * 60 * 60) {
|
||||
$change_index = $i;
|
||||
} elseif ($start == $day + $change_hour * 60 * 60) {
|
||||
// Start trifft Schichtwechsel
|
||||
if ($start < $day + $change_hour * 60 * 60) {
|
||||
$change_index = $i;
|
||||
} elseif ($start == $day + $change_hour * 60 * 60) {
|
||||
// Start trifft Schichtwechsel
|
||||
$change_index = ($i + count($change_hours) - 1) % count($change_hours);
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$shift_start = $start;
|
||||
do {
|
||||
$day = parse_date("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00");
|
||||
$shift_end = $day + $change_hours[$change_index] * 60 * 60;
|
||||
$shift_start = $start;
|
||||
do {
|
||||
$day = parse_date("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00");
|
||||
$shift_end = $day + $change_hours[$change_index] * 60 * 60;
|
||||
|
||||
if ($shift_end > $end) {
|
||||
$shift_end = $end;
|
||||
}
|
||||
if ($shift_start >= $shift_end) {
|
||||
$shift_end += 24 * 60 * 60;
|
||||
}
|
||||
if ($shift_end > $end) {
|
||||
$shift_end = $end;
|
||||
}
|
||||
if ($shift_start >= $shift_end) {
|
||||
$shift_end += 24 * 60 * 60;
|
||||
}
|
||||
|
||||
$shifts[] = [
|
||||
$shifts[] = [
|
||||
'start' => $shift_start,
|
||||
'end' => $shift_end,
|
||||
'RID' => $rid,
|
||||
|
@ -223,35 +225,35 @@ function admin_shifts() {
|
|||
'shifttype_id' => $shifttype_id
|
||||
];
|
||||
|
||||
$shift_start = $shift_end;
|
||||
$change_index = ($change_index + count($change_hours) - 1) % count($change_hours);
|
||||
} while ($shift_end < $end);
|
||||
}
|
||||
$shift_start = $shift_end;
|
||||
$change_index = ($change_index + count($change_hours) - 1) % count($change_hours);
|
||||
} while ($shift_end < $end);
|
||||
}
|
||||
|
||||
$shifts_table = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$shifts_table_entry = [
|
||||
$shifts_table = [];
|
||||
foreach ($shifts as $shift) {
|
||||
$shifts_table_entry = [
|
||||
'timeslot' => '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . '<br />' . Room_name_render(Room($shift['RID'])),
|
||||
'title' => ShiftType_name_render(ShiftType($shifttype_id)) . ($shift['title'] ? '<br />' . $shift['title'] : ''),
|
||||
'needed_angels' => ''
|
||||
];
|
||||
foreach ($types as $type) {
|
||||
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 />';
|
||||
}
|
||||
foreach ($types as $type) {
|
||||
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[] = $shifts_table_entry;
|
||||
}
|
||||
$shifts_table[] = $shifts_table_entry;
|
||||
}
|
||||
|
||||
// Fürs Anlegen zwischenspeichern:
|
||||
$_SESSION['admin_shifts_shifts'] = $shifts;
|
||||
$_SESSION['admin_shifts_types'] = $needed_angel_types;
|
||||
$_SESSION['admin_shifts_types'] = $needed_angel_types;
|
||||
|
||||
$hidden_types = "";
|
||||
foreach ($needed_angel_types as $type_id => $count) {
|
||||
$hidden_types .= form_hidden('type_' . $type_id, $count);
|
||||
}
|
||||
return page_with_title(_("Preview"), [
|
||||
$hidden_types = "";
|
||||
foreach ($needed_angel_types as $type_id => $count) {
|
||||
$hidden_types .= form_hidden('type_' . $type_id, $count);
|
||||
}
|
||||
return page_with_title(_("Preview"), [
|
||||
form([
|
||||
$hidden_types,
|
||||
form_hidden('shifttype_id', $shifttype_id),
|
||||
|
@ -273,47 +275,47 @@ function admin_shifts() {
|
|||
])
|
||||
]);
|
||||
}
|
||||
} elseif (isset($_REQUEST['submit'])) {
|
||||
if (! is_array($_SESSION['admin_shifts_shifts']) || ! is_array($_SESSION['admin_shifts_types'])) {
|
||||
redirect(page_link_to('admin_shifts'));
|
||||
}
|
||||
|
||||
foreach ($_SESSION['admin_shifts_shifts'] as $shift) {
|
||||
$shift['URL'] = null;
|
||||
$shift['PSID'] = null;
|
||||
$shift_id = Shift_create($shift);
|
||||
if ($shift_id === false) {
|
||||
engelsystem_error('Unable to create shift.');
|
||||
}
|
||||
|
||||
engelsystem_log("Shift created: " . $shifttypes[$shift['shifttype_id']] . " with title " . $shift['title'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
|
||||
$needed_angel_types_info = [];
|
||||
foreach ($_SESSION['admin_shifts_types'] as $type_id => $count) {
|
||||
$angel_type_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($type_id) . "' LIMIT 1");
|
||||
if (count($angel_type_source) > 0) {
|
||||
sql_query("INSERT INTO `NeededAngelTypes` SET `shift_id`='" . sql_escape($shift_id) . "', `angel_type_id`='" . sql_escape($type_id) . "', `count`='" . sql_escape($count) . "'");
|
||||
$needed_angel_types_info[] = $angel_type_source[0]['name'] . ": " . $count;
|
||||
} elseif (isset($_REQUEST['submit'])) {
|
||||
if (! is_array($_SESSION['admin_shifts_shifts']) || ! is_array($_SESSION['admin_shifts_types'])) {
|
||||
redirect(page_link_to('admin_shifts'));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($_SESSION['admin_shifts_shifts'] as $shift) {
|
||||
$shift['URL'] = null;
|
||||
$shift['PSID'] = null;
|
||||
$shift_id = Shift_create($shift);
|
||||
if ($shift_id === false) {
|
||||
engelsystem_error('Unable to create shift.');
|
||||
}
|
||||
|
||||
engelsystem_log("Shift created: " . $shifttypes[$shift['shifttype_id']] . " with title " . $shift['title'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
|
||||
$needed_angel_types_info = [];
|
||||
foreach ($_SESSION['admin_shifts_types'] as $type_id => $count) {
|
||||
$angel_type_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($type_id) . "' LIMIT 1");
|
||||
if (count($angel_type_source) > 0) {
|
||||
sql_query("INSERT INTO `NeededAngelTypes` SET `shift_id`='" . sql_escape($shift_id) . "', `angel_type_id`='" . sql_escape($type_id) . "', `count`='" . sql_escape($count) . "'");
|
||||
$needed_angel_types_info[] = $angel_type_source[0]['name'] . ": " . $count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
engelsystem_log("Shift needs following angel types: " . join(", ", $needed_angel_types_info));
|
||||
success("Schichten angelegt.");
|
||||
redirect(page_link_to('admin_shifts'));
|
||||
} else {
|
||||
unset($_SESSION['admin_shifts_shifts']);
|
||||
unset($_SESSION['admin_shifts_types']);
|
||||
}
|
||||
|
||||
engelsystem_log("Shift needs following angel types: " . join(", ", $needed_angel_types_info));
|
||||
success("Schichten angelegt.");
|
||||
redirect(page_link_to('admin_shifts'));
|
||||
} else {
|
||||
unset($_SESSION['admin_shifts_shifts']);
|
||||
unset($_SESSION['admin_shifts_types']);
|
||||
}
|
||||
if (! isset($_REQUEST['rid'])) {
|
||||
$_REQUEST['rid'] = null;
|
||||
}
|
||||
$angel_types = "";
|
||||
foreach ($types as $type) {
|
||||
$angel_types .= '<div class="col-md-4">' . form_spinner('type_' . $type['id'], $type['name'], $needed_angel_types[$type['id']]) . '</div>';
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['rid'])) {
|
||||
$_REQUEST['rid'] = null;
|
||||
}
|
||||
$angel_types = "";
|
||||
foreach ($types as $type) {
|
||||
$angel_types .= '<div class="col-md-4">' . form_spinner('type_' . $type['id'], $type['name'], $needed_angel_types[$type['id']]) . '</div>';
|
||||
}
|
||||
|
||||
return page_with_title(admin_shifts_title(), [
|
||||
return page_with_title(admin_shifts_title(), [
|
||||
msg(),
|
||||
form([
|
||||
form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
|
||||
|
@ -343,4 +345,3 @@ function admin_shifts() {
|
|||
])
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,169 +1,171 @@
|
|||
<?php
|
||||
|
||||
function admin_user_title() {
|
||||
return _("All Angels");
|
||||
function admin_user_title()
|
||||
{
|
||||
return _("All Angels");
|
||||
}
|
||||
|
||||
function admin_user() {
|
||||
global $user, $privileges, $tshirt_sizes, $privileges;
|
||||
function admin_user()
|
||||
{
|
||||
global $user, $privileges, $tshirt_sizes, $privileges;
|
||||
|
||||
$html = '';
|
||||
$html = '';
|
||||
|
||||
if (! isset($_REQUEST['id'])) {
|
||||
redirect(users_link());
|
||||
}
|
||||
|
||||
$user_id = $_REQUEST['id'];
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$user_source = User($user_id);
|
||||
if ($user_source == null) {
|
||||
error(_('This user does not exist.'));
|
||||
redirect(users_link());
|
||||
if (! isset($_REQUEST['id'])) {
|
||||
redirect(users_link());
|
||||
}
|
||||
|
||||
$html .= "Hallo,<br />" . "hier kannst du den Eintrag ändern. Unter dem Punkt 'Gekommen' " . "wird der Engel als anwesend markiert, ein Ja bei Aktiv bedeutet, " . "dass der Engel aktiv war und damit ein Anspruch auf ein T-Shirt hat. " . "Wenn T-Shirt ein 'Ja' enthält, bedeutet dies, dass der Engel " . "bereits sein T-Shirt erhalten hat.<br /><br />\n";
|
||||
$user_id = $_REQUEST['id'];
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$user_source = User($user_id);
|
||||
if ($user_source == null) {
|
||||
error(_('This user does not exist.'));
|
||||
redirect(users_link());
|
||||
}
|
||||
|
||||
$html .= "<form action=\"" . page_link_to("admin_user") . "&action=save&id=$user_id\" method=\"post\">\n";
|
||||
$html .= "<table border=\"0\">\n";
|
||||
$html .= "<input type=\"hidden\" name=\"Type\" value=\"Normal\">\n";
|
||||
$html .= "<tr><td>\n";
|
||||
$html .= "<table>\n";
|
||||
$html .= " <tr><td>Nick</td><td>" . "<input type=\"text\" size=\"40\" name=\"eNick\" value=\"" . $user_source['Nick'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>lastLogIn</td><td>" . date("Y-m-d H:i", $user_source['lastLogIn']) . "</td></tr>\n";
|
||||
$html .= " <tr><td>Name</td><td>" . "<input type=\"text\" size=\"40\" name=\"eName\" value=\"" . $user_source['Name'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Vorname</td><td>" . "<input type=\"text\" size=\"40\" name=\"eVorname\" value=\"" . $user_source['Vorname'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Alter</td><td>" . "<input type=\"text\" size=\"5\" name=\"eAlter\" value=\"" . $user_source['Alter'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Telefon</td><td>" . "<input type=\"text\" size=\"40\" name=\"eTelefon\" value=\"" . $user_source['Telefon'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Handy</td><td>" . "<input type=\"text\" size=\"40\" name=\"eHandy\" value=\"" . $user_source['Handy'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>DECT</td><td>" . "<input type=\"text\" size=\"4\" name=\"eDECT\" value=\"" . $user_source['DECT'] . "\"></td></tr>\n";
|
||||
if ($user_source['email_by_human_allowed']) {
|
||||
$html .= " <tr><td>email</td><td>" . "<input type=\"text\" size=\"40\" name=\"eemail\" value=\"" . $user_source['email'] . "\"></td></tr>\n";
|
||||
}
|
||||
$html .= " <tr><td>jabber</td><td>" . "<input type=\"text\" size=\"40\" name=\"ejabber\" value=\"" . $user_source['jabber'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Size</td><td>" . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size']) . "</td></tr>\n";
|
||||
$html .= "Hallo,<br />" . "hier kannst du den Eintrag ändern. Unter dem Punkt 'Gekommen' " . "wird der Engel als anwesend markiert, ein Ja bei Aktiv bedeutet, " . "dass der Engel aktiv war und damit ein Anspruch auf ein T-Shirt hat. " . "Wenn T-Shirt ein 'Ja' enthält, bedeutet dies, dass der Engel " . "bereits sein T-Shirt erhalten hat.<br /><br />\n";
|
||||
|
||||
$options = [
|
||||
$html .= "<form action=\"" . page_link_to("admin_user") . "&action=save&id=$user_id\" method=\"post\">\n";
|
||||
$html .= "<table border=\"0\">\n";
|
||||
$html .= "<input type=\"hidden\" name=\"Type\" value=\"Normal\">\n";
|
||||
$html .= "<tr><td>\n";
|
||||
$html .= "<table>\n";
|
||||
$html .= " <tr><td>Nick</td><td>" . "<input type=\"text\" size=\"40\" name=\"eNick\" value=\"" . $user_source['Nick'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>lastLogIn</td><td>" . date("Y-m-d H:i", $user_source['lastLogIn']) . "</td></tr>\n";
|
||||
$html .= " <tr><td>Name</td><td>" . "<input type=\"text\" size=\"40\" name=\"eName\" value=\"" . $user_source['Name'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Vorname</td><td>" . "<input type=\"text\" size=\"40\" name=\"eVorname\" value=\"" . $user_source['Vorname'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Alter</td><td>" . "<input type=\"text\" size=\"5\" name=\"eAlter\" value=\"" . $user_source['Alter'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Telefon</td><td>" . "<input type=\"text\" size=\"40\" name=\"eTelefon\" value=\"" . $user_source['Telefon'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Handy</td><td>" . "<input type=\"text\" size=\"40\" name=\"eHandy\" value=\"" . $user_source['Handy'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>DECT</td><td>" . "<input type=\"text\" size=\"4\" name=\"eDECT\" value=\"" . $user_source['DECT'] . "\"></td></tr>\n";
|
||||
if ($user_source['email_by_human_allowed']) {
|
||||
$html .= " <tr><td>email</td><td>" . "<input type=\"text\" size=\"40\" name=\"eemail\" value=\"" . $user_source['email'] . "\"></td></tr>\n";
|
||||
}
|
||||
$html .= " <tr><td>jabber</td><td>" . "<input type=\"text\" size=\"40\" name=\"ejabber\" value=\"" . $user_source['jabber'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Size</td><td>" . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size']) . "</td></tr>\n";
|
||||
|
||||
$options = [
|
||||
'1' => _("Yes"),
|
||||
'0' => _("No")
|
||||
];
|
||||
|
||||
// Gekommen?
|
||||
$html .= " <tr><td>Gekommen</td><td>\n";
|
||||
$html .= html_options('eGekommen', $options, $user_source['Gekommen']) . "</td></tr>\n";
|
||||
$html .= html_options('eGekommen', $options, $user_source['Gekommen']) . "</td></tr>\n";
|
||||
|
||||
// Aktiv?
|
||||
$html .= " <tr><td>Aktiv</td><td>\n";
|
||||
$html .= html_options('eAktiv', $options, $user_source['Aktiv']) . "</td></tr>\n";
|
||||
$html .= html_options('eAktiv', $options, $user_source['Aktiv']) . "</td></tr>\n";
|
||||
|
||||
// Aktiv erzwingen
|
||||
if (in_array('admin_active', $privileges)) {
|
||||
$html .= " <tr><td>" . _("Force active") . "</td><td>\n";
|
||||
$html .= html_options('force_active', $options, $user_source['force_active']) . "</td></tr>\n";
|
||||
$html .= " <tr><td>" . _("Force active") . "</td><td>\n";
|
||||
$html .= html_options('force_active', $options, $user_source['force_active']) . "</td></tr>\n";
|
||||
}
|
||||
|
||||
// T-Shirt bekommen?
|
||||
$html .= " <tr><td>T-Shirt</td><td>\n";
|
||||
$html .= html_options('eTshirt', $options, $user_source['Tshirt']) . "</td></tr>\n";
|
||||
$html .= html_options('eTshirt', $options, $user_source['Tshirt']) . "</td></tr>\n";
|
||||
|
||||
$html .= " <tr><td>Hometown</td><td>" . "<input type=\"text\" size=\"40\" name=\"Hometown\" value=\"" . $user_source['Hometown'] . "\"></td></tr>\n";
|
||||
$html .= " <tr><td>Hometown</td><td>" . "<input type=\"text\" size=\"40\" name=\"Hometown\" value=\"" . $user_source['Hometown'] . "\"></td></tr>\n";
|
||||
|
||||
$html .= "</table>\n</td><td valign=\"top\"></td></tr>";
|
||||
$html .= "</table>\n</td><td valign=\"top\"></td></tr>";
|
||||
|
||||
$html .= "</td></tr>\n";
|
||||
$html .= "</table>\n<br />\n";
|
||||
$html .= "<input type=\"submit\" value=\"Speichern\">\n";
|
||||
$html .= "</form>";
|
||||
$html .= "</td></tr>\n";
|
||||
$html .= "</table>\n<br />\n";
|
||||
$html .= "<input type=\"submit\" value=\"Speichern\">\n";
|
||||
$html .= "</form>";
|
||||
|
||||
$html .= "<hr />";
|
||||
$html .= "<hr />";
|
||||
|
||||
$html .= form_info('', _('Please visit the angeltypes page or the users profile to manage users angeltypes.'));
|
||||
$html .= form_info('', _('Please visit the angeltypes page or the users profile to manage users angeltypes.'));
|
||||
|
||||
$html .= "Hier kannst Du das Passwort dieses Engels neu setzen:<form action=\"" . page_link_to("admin_user") . "&action=change_pw&id=$user_id\" method=\"post\">\n";
|
||||
$html .= "<table>\n";
|
||||
$html .= " <tr><td>Passwort</td><td>" . "<input type=\"password\" size=\"40\" name=\"new_pw\" value=\"\"></td></tr>\n";
|
||||
$html .= " <tr><td>Wiederholung</td><td>" . "<input type=\"password\" size=\"40\" name=\"new_pw2\" value=\"\"></td></tr>\n";
|
||||
$html .= "Hier kannst Du das Passwort dieses Engels neu setzen:<form action=\"" . page_link_to("admin_user") . "&action=change_pw&id=$user_id\" method=\"post\">\n";
|
||||
$html .= "<table>\n";
|
||||
$html .= " <tr><td>Passwort</td><td>" . "<input type=\"password\" size=\"40\" name=\"new_pw\" value=\"\"></td></tr>\n";
|
||||
$html .= " <tr><td>Wiederholung</td><td>" . "<input type=\"password\" size=\"40\" name=\"new_pw2\" value=\"\"></td></tr>\n";
|
||||
|
||||
$html .= "</table>";
|
||||
$html .= "<input type=\"submit\" value=\"Speichern\">\n";
|
||||
$html .= "</form>";
|
||||
$html .= "</table>";
|
||||
$html .= "<input type=\"submit\" value=\"Speichern\">\n";
|
||||
$html .= "</form>";
|
||||
|
||||
$html .= "<hr />";
|
||||
$html .= "<hr />";
|
||||
|
||||
$my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id` LIMIT 1");
|
||||
if (count($my_highest_group) > 0) {
|
||||
$my_highest_group = $my_highest_group[0]['group_id'];
|
||||
}
|
||||
$my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id` LIMIT 1");
|
||||
if (count($my_highest_group) > 0) {
|
||||
$my_highest_group = $my_highest_group[0]['group_id'];
|
||||
}
|
||||
|
||||
$his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "' ORDER BY `group_id` LIMIT 1");
|
||||
if (count($his_highest_group) > 0) {
|
||||
$his_highest_group = $his_highest_group[0]['group_id'];
|
||||
}
|
||||
$his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "' ORDER BY `group_id` LIMIT 1");
|
||||
if (count($his_highest_group) > 0) {
|
||||
$his_highest_group = $his_highest_group[0]['group_id'];
|
||||
}
|
||||
|
||||
if ($user_id != $user['UID'] && $my_highest_group <= $his_highest_group) {
|
||||
$html .= "Hier kannst Du die Benutzergruppen des Engels festlegen:<form action=\"" . page_link_to("admin_user") . "&action=save_groups&id=" . $user_id . "\" method=\"post\">\n";
|
||||
$html .= '<table>';
|
||||
if ($user_id != $user['UID'] && $my_highest_group <= $his_highest_group) {
|
||||
$html .= "Hier kannst Du die Benutzergruppen des Engels festlegen:<form action=\"" . page_link_to("admin_user") . "&action=save_groups&id=" . $user_id . "\" method=\"post\">\n";
|
||||
$html .= '<table>';
|
||||
|
||||
$groups = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($user_id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group) . "' ORDER BY `Groups`.`Name`");
|
||||
foreach ($groups as $group) {
|
||||
$html .= '<tr><td><input type="checkbox" name="groups[]" value="' . $group['UID'] . '"' . ($group['group_id'] != "" ? ' checked="checked"' : '') . ' /></td><td>' . $group['Name'] . '</td></tr>';
|
||||
}
|
||||
$groups = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($user_id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group) . "' ORDER BY `Groups`.`Name`");
|
||||
foreach ($groups as $group) {
|
||||
$html .= '<tr><td><input type="checkbox" name="groups[]" value="' . $group['UID'] . '"' . ($group['group_id'] != "" ? ' checked="checked"' : '') . ' /></td><td>' . $group['Name'] . '</td></tr>';
|
||||
}
|
||||
|
||||
$html .= '</table>';
|
||||
$html .= '</table>';
|
||||
|
||||
$html .= "<input type=\"submit\" value=\"Speichern\">\n";
|
||||
$html .= "</form>";
|
||||
$html .= "<input type=\"submit\" value=\"Speichern\">\n";
|
||||
$html .= "</form>";
|
||||
|
||||
$html .= "<hr />";
|
||||
}
|
||||
$html .= "<hr />";
|
||||
}
|
||||
|
||||
$html .= buttons([
|
||||
$html .= buttons([
|
||||
button(user_delete_link($user_source), glyph('lock') . _("delete"), 'btn-danger')
|
||||
]);
|
||||
|
||||
$html .= "<hr />";
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
$html .= "<hr />";
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'save_groups':
|
||||
if ($user_id != $user['UID']) {
|
||||
$my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id`");
|
||||
$his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "' ORDER BY `group_id`");
|
||||
$my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id`");
|
||||
$his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "' ORDER BY `group_id`");
|
||||
|
||||
if (count($my_highest_group) > 0 && (count($his_highest_group) == 0 || ($my_highest_group[0]['group_id'] <= $his_highest_group[0]['group_id']))) {
|
||||
$groups_source = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($user_id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group[0]['group_id']) . "' ORDER BY `Groups`.`Name`");
|
||||
$groups = [];
|
||||
$grouplist = [];
|
||||
foreach ($groups_source as $group) {
|
||||
$groups[$group['UID']] = $group;
|
||||
$grouplist[] = $group['UID'];
|
||||
}
|
||||
if (count($my_highest_group) > 0 && (count($his_highest_group) == 0 || ($my_highest_group[0]['group_id'] <= $his_highest_group[0]['group_id']))) {
|
||||
$groups_source = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($user_id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group[0]['group_id']) . "' ORDER BY `Groups`.`Name`");
|
||||
$groups = [];
|
||||
$grouplist = [];
|
||||
foreach ($groups_source as $group) {
|
||||
$groups[$group['UID']] = $group;
|
||||
$grouplist[] = $group['UID'];
|
||||
}
|
||||
|
||||
if (! is_array($_REQUEST['groups'])) {
|
||||
$_REQUEST['groups'] = [];
|
||||
}
|
||||
if (! is_array($_REQUEST['groups'])) {
|
||||
$_REQUEST['groups'] = [];
|
||||
}
|
||||
|
||||
sql_query("DELETE FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "'");
|
||||
$user_groups_info = [];
|
||||
foreach ($_REQUEST['groups'] as $group) {
|
||||
if (in_array($group, $grouplist)) {
|
||||
sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($user_id) . "', `group_id`='" . sql_escape($group) . "'");
|
||||
$user_groups_info[] = $groups[$group]['Name'];
|
||||
}
|
||||
sql_query("DELETE FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "'");
|
||||
$user_groups_info = [];
|
||||
foreach ($_REQUEST['groups'] as $group) {
|
||||
if (in_array($group, $grouplist)) {
|
||||
sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($user_id) . "', `group_id`='" . sql_escape($group) . "'");
|
||||
$user_groups_info[] = $groups[$group]['Name'];
|
||||
}
|
||||
}
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log("Set groups of " . User_Nick_render($user_source) . " to: " . join(", ", $user_groups_info));
|
||||
$html .= success("Benutzergruppen gespeichert.", true);
|
||||
} else {
|
||||
$html .= error("Du kannst keine Engel mit mehr Rechten bearbeiten.", true);
|
||||
}
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log("Set groups of " . User_Nick_render($user_source) . " to: " . join(", ", $user_groups_info));
|
||||
$html .= success("Benutzergruppen gespeichert.", true);
|
||||
} else {
|
||||
$html .= error("Du kannst keine Engel mit mehr Rechten bearbeiten.", true);
|
||||
}
|
||||
} else {
|
||||
$html .= error("Du kannst Deine eigenen Rechte nicht bearbeiten.", true);
|
||||
$html .= error("Du kannst Deine eigenen Rechte nicht bearbeiten.", true);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
$force_active = $user['force_active'];
|
||||
if (in_array('admin_active', $privileges)) {
|
||||
$force_active = $_REQUEST['force_active'];
|
||||
$force_active = $_REQUEST['force_active'];
|
||||
}
|
||||
$SQL = "UPDATE `User` SET
|
||||
`Nick` = '" . sql_escape($_POST["eNick"]) . "',
|
||||
|
@ -190,19 +192,18 @@ function admin_user() {
|
|||
|
||||
case 'change_pw':
|
||||
if ($_REQUEST['new_pw'] != "" && $_REQUEST['new_pw'] == $_REQUEST['new_pw2']) {
|
||||
set_password($user_id, $_REQUEST['new_pw']);
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log("Set new password for " . User_Nick_render($user_source));
|
||||
$html .= success("Passwort neu gesetzt.", true);
|
||||
set_password($user_id, $_REQUEST['new_pw']);
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log("Set new password for " . User_Nick_render($user_source));
|
||||
$html .= success("Passwort neu gesetzt.", true);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(_("Edit user"), [
|
||||
return page_with_title(_("Edit user"), [
|
||||
$html
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
function credits_title() {
|
||||
return _("Credits");
|
||||
function credits_title()
|
||||
{
|
||||
return _("Credits");
|
||||
}
|
||||
|
||||
function guest_credits() {
|
||||
return template_render(__DIR__ . '/../../templates/guest_credits.html', []);
|
||||
function guest_credits()
|
||||
{
|
||||
return template_render(__DIR__ . '/../../templates/guest_credits.html', []);
|
||||
}
|
||||
?>
|
|
@ -1,156 +1,160 @@
|
|||
<?php
|
||||
|
||||
function login_title() {
|
||||
return _("Login");
|
||||
function login_title()
|
||||
{
|
||||
return _("Login");
|
||||
}
|
||||
|
||||
function register_title() {
|
||||
return _("Register");
|
||||
function register_title()
|
||||
{
|
||||
return _("Register");
|
||||
}
|
||||
|
||||
function logout_title() {
|
||||
return _("Logout");
|
||||
function logout_title()
|
||||
{
|
||||
return _("Logout");
|
||||
}
|
||||
|
||||
// Engel registrieren
|
||||
function guest_register() {
|
||||
global $tshirt_sizes, $enable_tshirt_size, $default_theme, $user, $min_password_length;
|
||||
function guest_register()
|
||||
{
|
||||
global $tshirt_sizes, $enable_tshirt_size, $default_theme, $user, $min_password_length;
|
||||
|
||||
$event_config = EventConfig();
|
||||
|
||||
$msg = "";
|
||||
$nick = "";
|
||||
$lastname = "";
|
||||
$prename = "";
|
||||
$age = "";
|
||||
$tel = "";
|
||||
$dect = "";
|
||||
$mobile = "";
|
||||
$mail = "";
|
||||
$email_shiftinfo = false;
|
||||
$email_by_human_allowed = false;
|
||||
$jabber = "";
|
||||
$hometown = "";
|
||||
$comment = "";
|
||||
$tshirt_size = '';
|
||||
$password_hash = "";
|
||||
$selected_angel_types = [];
|
||||
$planned_arrival_date = null;
|
||||
|
||||
$angel_types_source = AngelTypes();
|
||||
$angel_types = [];
|
||||
foreach ($angel_types_source as $angel_type) {
|
||||
$angel_types[$angel_type['id']] = $angel_type['name'] . ($angel_type['restricted'] ? " (restricted)" : "");
|
||||
if (! $angel_type['restricted']) {
|
||||
$selected_angel_types[] = $angel_type['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 1) {
|
||||
$nick = User_validate_Nick($_REQUEST['nick']);
|
||||
if (sql_num_query("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "' LIMIT 1") > 0) {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your nick "%s" already exists."), $nick), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your nick "%s" is too short (min. 2 characters)."), User_validate_Nick($_REQUEST['nick'])), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['mail']) && strlen(strip_request_item('mail')) > 0) {
|
||||
$mail = strip_request_item('mail');
|
||||
if (! check_email($mail)) {
|
||||
$valid = false;
|
||||
$msg .= error(_("E-mail address is not correct."), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter your e-mail."), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['email_shiftinfo'])) {
|
||||
$email_shiftinfo = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['email_by_human_allowed'])) {
|
||||
$email_by_human_allowed = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) {
|
||||
$jabber = strip_request_item('jabber');
|
||||
if (! check_email($jabber)) {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please check your jabber account information."), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($enable_tshirt_size) {
|
||||
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']]) && $_REQUEST['tshirt_size'] != '') {
|
||||
$tshirt_size = $_REQUEST['tshirt_size'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please select your shirt size."), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) {
|
||||
if ($_REQUEST['password'] != $_REQUEST['password2']) {
|
||||
$valid = false;
|
||||
$msg .= error(_("Your passwords don't match."), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), $min_password_length), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_arrival_date'])) {
|
||||
$tmp = parse_date("Y-m-d H:i", $_REQUEST['planned_arrival_date'] . " 00:00");
|
||||
$result = User_validate_planned_arrival_date($tmp);
|
||||
$planned_arrival_date = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date."));
|
||||
}
|
||||
}
|
||||
$event_config = EventConfig();
|
||||
|
||||
$msg = "";
|
||||
$nick = "";
|
||||
$lastname = "";
|
||||
$prename = "";
|
||||
$age = "";
|
||||
$tel = "";
|
||||
$dect = "";
|
||||
$mobile = "";
|
||||
$mail = "";
|
||||
$email_shiftinfo = false;
|
||||
$email_by_human_allowed = false;
|
||||
$jabber = "";
|
||||
$hometown = "";
|
||||
$comment = "";
|
||||
$tshirt_size = '';
|
||||
$password_hash = "";
|
||||
$selected_angel_types = [];
|
||||
foreach (array_keys($angel_types) as $angel_type_id) {
|
||||
if (isset($_REQUEST['angel_types_' . $angel_type_id])) {
|
||||
$selected_angel_types[] = $angel_type_id;
|
||||
}
|
||||
$planned_arrival_date = null;
|
||||
|
||||
$angel_types_source = AngelTypes();
|
||||
$angel_types = [];
|
||||
foreach ($angel_types_source as $angel_type) {
|
||||
$angel_types[$angel_type['id']] = $angel_type['name'] . ($angel_type['restricted'] ? " (restricted)" : "");
|
||||
if (! $angel_type['restricted']) {
|
||||
$selected_angel_types[] = $angel_type['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 1) {
|
||||
$nick = User_validate_Nick($_REQUEST['nick']);
|
||||
if (sql_num_query("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "' LIMIT 1") > 0) {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your nick "%s" already exists."), $nick), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your nick "%s" is too short (min. 2 characters)."), User_validate_Nick($_REQUEST['nick'])), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['mail']) && strlen(strip_request_item('mail')) > 0) {
|
||||
$mail = strip_request_item('mail');
|
||||
if (! check_email($mail)) {
|
||||
$valid = false;
|
||||
$msg .= error(_("E-mail address is not correct."), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter your e-mail."), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['email_shiftinfo'])) {
|
||||
$email_shiftinfo = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['email_by_human_allowed'])) {
|
||||
$email_by_human_allowed = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) {
|
||||
$jabber = strip_request_item('jabber');
|
||||
if (! check_email($jabber)) {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please check your jabber account information."), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($enable_tshirt_size) {
|
||||
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']]) && $_REQUEST['tshirt_size'] != '') {
|
||||
$tshirt_size = $_REQUEST['tshirt_size'];
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please select your shirt size."), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) {
|
||||
if ($_REQUEST['password'] != $_REQUEST['password2']) {
|
||||
$valid = false;
|
||||
$msg .= error(_("Your passwords don't match."), true);
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), $min_password_length), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_arrival_date'])) {
|
||||
$tmp = parse_date("Y-m-d H:i", $_REQUEST['planned_arrival_date'] . " 00:00");
|
||||
$result = User_validate_planned_arrival_date($tmp);
|
||||
$planned_arrival_date = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date."));
|
||||
}
|
||||
}
|
||||
|
||||
$selected_angel_types = [];
|
||||
foreach (array_keys($angel_types) as $angel_type_id) {
|
||||
if (isset($_REQUEST['angel_types_' . $angel_type_id])) {
|
||||
$selected_angel_types[] = $angel_type_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Trivia
|
||||
if (isset($_REQUEST['lastname'])) {
|
||||
$lastname = strip_request_item('lastname');
|
||||
}
|
||||
if (isset($_REQUEST['prename'])) {
|
||||
$prename = strip_request_item('prename');
|
||||
}
|
||||
if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age'])) {
|
||||
$age = strip_request_item('age');
|
||||
}
|
||||
if (isset($_REQUEST['tel'])) {
|
||||
$tel = strip_request_item('tel');
|
||||
}
|
||||
if (isset($_REQUEST['dect'])) {
|
||||
$dect = strip_request_item('dect');
|
||||
}
|
||||
if (isset($_REQUEST['mobile'])) {
|
||||
$mobile = strip_request_item('mobile');
|
||||
}
|
||||
if (isset($_REQUEST['hometown'])) {
|
||||
$hometown = strip_request_item('hometown');
|
||||
}
|
||||
if (isset($_REQUEST['comment'])) {
|
||||
$comment = strip_request_item_nl('comment');
|
||||
$lastname = strip_request_item('lastname');
|
||||
}
|
||||
if (isset($_REQUEST['prename'])) {
|
||||
$prename = strip_request_item('prename');
|
||||
}
|
||||
if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age'])) {
|
||||
$age = strip_request_item('age');
|
||||
}
|
||||
if (isset($_REQUEST['tel'])) {
|
||||
$tel = strip_request_item('tel');
|
||||
}
|
||||
if (isset($_REQUEST['dect'])) {
|
||||
$dect = strip_request_item('dect');
|
||||
}
|
||||
if (isset($_REQUEST['mobile'])) {
|
||||
$mobile = strip_request_item('mobile');
|
||||
}
|
||||
if (isset($_REQUEST['hometown'])) {
|
||||
$hometown = strip_request_item('hometown');
|
||||
}
|
||||
if (isset($_REQUEST['comment'])) {
|
||||
$comment = strip_request_item_nl('comment');
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
sql_query("
|
||||
if ($valid) {
|
||||
sql_query("
|
||||
INSERT INTO `User` SET
|
||||
`color`='" . sql_escape($default_theme) . "',
|
||||
`Nick`='" . sql_escape($nick) . "',
|
||||
|
@ -175,45 +179,45 @@ function guest_register() {
|
|||
|
||||
// Assign user-group and set password
|
||||
$user_id = sql_id();
|
||||
sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($user_id) . "', `group_id`=-2");
|
||||
set_password($user_id, $_REQUEST['password']);
|
||||
sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($user_id) . "', `group_id`=-2");
|
||||
set_password($user_id, $_REQUEST['password']);
|
||||
|
||||
// Assign angel-types
|
||||
$user_angel_types_info = [];
|
||||
foreach ($selected_angel_types as $selected_angel_type_id) {
|
||||
sql_query("INSERT INTO `UserAngelTypes` SET `user_id`='" . sql_escape($user_id) . "', `angeltype_id`='" . sql_escape($selected_angel_type_id) . "'");
|
||||
$user_angel_types_info[] = $angel_types[$selected_angel_type_id];
|
||||
}
|
||||
foreach ($selected_angel_types as $selected_angel_type_id) {
|
||||
sql_query("INSERT INTO `UserAngelTypes` SET `user_id`='" . sql_escape($user_id) . "', `angeltype_id`='" . sql_escape($selected_angel_type_id) . "'");
|
||||
$user_angel_types_info[] = $angel_types[$selected_angel_type_id];
|
||||
}
|
||||
|
||||
engelsystem_log("User " . User_Nick_render(User($user_id)) . " signed up as: " . join(", ", $user_angel_types_info));
|
||||
success(_("Angel registration successful!"));
|
||||
engelsystem_log("User " . User_Nick_render(User($user_id)) . " signed up as: " . join(", ", $user_angel_types_info));
|
||||
success(_("Angel registration successful!"));
|
||||
|
||||
// User is already logged in - that means a supporter has registered an angel. Return to register page.
|
||||
if (isset($user)) {
|
||||
redirect(page_link_to('register'));
|
||||
redirect(page_link_to('register'));
|
||||
}
|
||||
|
||||
// If a welcome message is present, display registration success page.
|
||||
if ($event_config != null && $event_config['event_welcome_msg'] != null) {
|
||||
return User_registration_success_view($event_config['event_welcome_msg']);
|
||||
return User_registration_success_view($event_config['event_welcome_msg']);
|
||||
}
|
||||
|
||||
redirect('?');
|
||||
redirect('?');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$buildup_start_date = time();
|
||||
$teardown_end_date = null;
|
||||
if ($event_config != null) {
|
||||
if (isset($event_config['buildup_start_date'])) {
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
$buildup_start_date = time();
|
||||
$teardown_end_date = null;
|
||||
if ($event_config != null) {
|
||||
if (isset($event_config['buildup_start_date'])) {
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
}
|
||||
if (isset($event_config['teardown_end_date'])) {
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
}
|
||||
}
|
||||
if(isset($event_config['teardown_end_date'])) {
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(register_title(), [
|
||||
return page_with_title(register_title(), [
|
||||
_("By completing this form you're registering as a Chaos-Angel. This script will create you an account in the angel task scheduler."),
|
||||
$msg,
|
||||
msg(),
|
||||
|
@ -287,57 +291,59 @@ function guest_register() {
|
|||
]);
|
||||
}
|
||||
|
||||
function entry_required() {
|
||||
return '<span class="text-info glyphicon glyphicon-warning-sign"></span>';
|
||||
function entry_required()
|
||||
{
|
||||
return '<span class="text-info glyphicon glyphicon-warning-sign"></span>';
|
||||
}
|
||||
|
||||
function guest_logout() {
|
||||
session_destroy();
|
||||
redirect(page_link_to("start"));
|
||||
function guest_logout()
|
||||
{
|
||||
session_destroy();
|
||||
redirect(page_link_to("start"));
|
||||
}
|
||||
|
||||
function guest_login() {
|
||||
$nick = "";
|
||||
function guest_login()
|
||||
{
|
||||
$nick = "";
|
||||
|
||||
unset($_SESSION['uid']);
|
||||
$valid = true;
|
||||
unset($_SESSION['uid']);
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
|
||||
if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 0) {
|
||||
$nick = User_validate_Nick($_REQUEST['nick']);
|
||||
$login_user = sql_select("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "'");
|
||||
if (count($login_user) > 0) {
|
||||
$login_user = $login_user[0];
|
||||
if (isset($_REQUEST['password'])) {
|
||||
if (! verify_password($_REQUEST['password'], $login_user['Passwort'], $login_user['UID'])) {
|
||||
$valid = false;
|
||||
error(_("Your password is incorrect. Please try it again."));
|
||||
}
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 0) {
|
||||
$nick = User_validate_Nick($_REQUEST['nick']);
|
||||
$login_user = sql_select("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "'");
|
||||
if (count($login_user) > 0) {
|
||||
$login_user = $login_user[0];
|
||||
if (isset($_REQUEST['password'])) {
|
||||
if (! verify_password($_REQUEST['password'], $login_user['Passwort'], $login_user['UID'])) {
|
||||
$valid = false;
|
||||
error(_("Your password is incorrect. Please try it again."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter a password."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("No user was found with that Nickname. Please try again. If you are still having problems, ask a Dispatcher."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter a password."));
|
||||
$valid = false;
|
||||
error(_("Please enter a nickname."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$_SESSION['uid'] = $login_user['UID'];
|
||||
$_SESSION['locale'] = $login_user['Sprache'];
|
||||
|
||||
redirect(page_link_to('news'));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("No user was found with that Nickname. Please try again. If you are still having problems, ask a Dispatcher."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter a nickname."));
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
$_SESSION['uid'] = $login_user['UID'];
|
||||
$_SESSION['locale'] = $login_user['Sprache'];
|
||||
$event_config = EventConfig();
|
||||
|
||||
redirect(page_link_to('news'));
|
||||
}
|
||||
}
|
||||
|
||||
$event_config = EventConfig();
|
||||
|
||||
return page([
|
||||
return page([
|
||||
div('col-md-12', [
|
||||
div('row', [
|
||||
EventConfig_countdown_page($event_config)
|
||||
|
@ -382,19 +388,19 @@ function guest_login() {
|
|||
]);
|
||||
}
|
||||
|
||||
function get_register_hint() {
|
||||
global $privileges;
|
||||
function get_register_hint()
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (in_array('register', $privileges)) {
|
||||
return join('', [
|
||||
if (in_array('register', $privileges)) {
|
||||
return join('', [
|
||||
'<p>' . _("Please sign up, if you want to help us!") . '</p>',
|
||||
buttons([
|
||||
button(page_link_to('register'), register_title() . ' »')
|
||||
])
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: return error(_("Registration is disabled."), true);
|
||||
return error("Registration is <a href='https://engelsystem.de/33c3/overwhelmed.html'>disabled</a>.", true);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
function guest_start() {
|
||||
redirect(page_link_to('login'));
|
||||
function guest_start()
|
||||
{
|
||||
redirect(page_link_to('login'));
|
||||
}
|
||||
?>
|
|
@ -1,35 +1,34 @@
|
|||
<?php
|
||||
|
||||
function guest_stats() {
|
||||
global $api_key;
|
||||
function guest_stats()
|
||||
{
|
||||
global $api_key;
|
||||
|
||||
if (isset($_REQUEST['api_key'])) {
|
||||
if ($_REQUEST['api_key'] == $api_key) {
|
||||
$stats = [];
|
||||
if (isset($_REQUEST['api_key'])) {
|
||||
if ($_REQUEST['api_key'] == $api_key) {
|
||||
$stats = [];
|
||||
|
||||
list($user_count) = sql_select("SELECT count(*) as `user_count` FROM `User`");
|
||||
$stats['user_count'] = $user_count['user_count'];
|
||||
list($user_count) = sql_select("SELECT count(*) as `user_count` FROM `User`");
|
||||
$stats['user_count'] = $user_count['user_count'];
|
||||
|
||||
list($arrived_user_count) = sql_select("SELECT count(*) as `user_count` FROM `User` WHERE `Gekommen`=1");
|
||||
$stats['arrived_user_count'] = $arrived_user_count['user_count'];
|
||||
list($arrived_user_count) = sql_select("SELECT count(*) as `user_count` FROM `User` WHERE `Gekommen`=1");
|
||||
$stats['arrived_user_count'] = $arrived_user_count['user_count'];
|
||||
|
||||
$done_shifts_seconds = sql_select_single_cell("SELECT SUM(`Shifts`.`end` - `Shifts`.`start`) FROM `ShiftEntry` JOIN `Shifts` USING (`SID`) WHERE `Shifts`.`end` < UNIX_TIMESTAMP()");
|
||||
$stats['done_work_hours'] = round($done_shifts_seconds / (60 * 60), 0);
|
||||
$done_shifts_seconds = sql_select_single_cell("SELECT SUM(`Shifts`.`end` - `Shifts`.`start`) FROM `ShiftEntry` JOIN `Shifts` USING (`SID`) WHERE `Shifts`.`end` < UNIX_TIMESTAMP()");
|
||||
$stats['done_work_hours'] = round($done_shifts_seconds / (60 * 60), 0);
|
||||
|
||||
$users_in_action = sql_select("SELECT `Shifts`.`start`, `Shifts`.`end` FROM `ShiftEntry` JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID` WHERE UNIX_TIMESTAMP() BETWEEN `Shifts`.`start` AND `Shifts`.`end`");
|
||||
$stats['users_in_action'] = count($users_in_action);
|
||||
$users_in_action = sql_select("SELECT `Shifts`.`start`, `Shifts`.`end` FROM `ShiftEntry` JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID` WHERE UNIX_TIMESTAMP() BETWEEN `Shifts`.`start` AND `Shifts`.`end`");
|
||||
$stats['users_in_action'] = count($users_in_action);
|
||||
|
||||
header("Content-Type: application/json");
|
||||
raw_output(json_encode($stats));
|
||||
return;
|
||||
}
|
||||
raw_output(json_encode([
|
||||
header("Content-Type: application/json");
|
||||
raw_output(json_encode($stats));
|
||||
return;
|
||||
}
|
||||
raw_output(json_encode([
|
||||
'error' => "Wrong api_key."
|
||||
]));
|
||||
}
|
||||
raw_output(json_encode([
|
||||
}
|
||||
raw_output(json_encode([
|
||||
'error' => "Missing parameter api_key."
|
||||
]));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,46 +1,49 @@
|
|||
<?php
|
||||
|
||||
// publically available page to feed the news to feedreaders
|
||||
function user_atom() {
|
||||
global $user, $DISPLAY_NEWS;
|
||||
function user_atom()
|
||||
{
|
||||
global $user, $DISPLAY_NEWS;
|
||||
|
||||
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
engelsystem_error("Missing key.");
|
||||
}
|
||||
$key = $_REQUEST['key'];
|
||||
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
engelsystem_error("Missing key.");
|
||||
}
|
||||
$key = $_REQUEST['key'];
|
||||
|
||||
$user = User_by_api_key($key);
|
||||
if ($user == null) {
|
||||
engelsystem_error("Key invalid.");
|
||||
}
|
||||
if (! in_array('atom', privileges_for_user($user['UID']))) {
|
||||
engelsystem_error("No privilege for atom.");
|
||||
}
|
||||
$user = User_by_api_key($key);
|
||||
if ($user == null) {
|
||||
engelsystem_error("Key invalid.");
|
||||
}
|
||||
if (! in_array('atom', privileges_for_user($user['UID']))) {
|
||||
engelsystem_error("No privilege for atom.");
|
||||
}
|
||||
|
||||
$news = sql_select("SELECT * FROM `News` " . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . "ORDER BY `ID` DESC LIMIT " . sql_escape($DISPLAY_NEWS));
|
||||
$news = sql_select("SELECT * FROM `News` " . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . "ORDER BY `ID` DESC LIMIT " . sql_escape($DISPLAY_NEWS));
|
||||
|
||||
$output = make_atom_entries_from_news($news);
|
||||
$output = make_atom_entries_from_news($news);
|
||||
|
||||
header('Content-Type: application/atom+xml; charset=utf-8');
|
||||
header("Content-Length: " . strlen($output));
|
||||
raw_output($output);
|
||||
header('Content-Type: application/atom+xml; charset=utf-8');
|
||||
header("Content-Length: " . strlen($output));
|
||||
raw_output($output);
|
||||
}
|
||||
|
||||
function make_atom_entries_from_news($news_entries) {
|
||||
$html = '<?xml version="1.0" encoding="utf-8"?>
|
||||
function make_atom_entries_from_news($news_entries)
|
||||
{
|
||||
$html = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>Engelsystem</title>
|
||||
<id>' . $_SERVER['HTTP_HOST'] . htmlspecialchars(preg_replace('#[&?]key=[a-f0-9]{32}#', '', $_SERVER['REQUEST_URI'])) . '</id>
|
||||
<updated>' . date('Y-m-d\TH:i:sP', $news_entries[0]['Datum']) . "</updated>\n";
|
||||
foreach ($news_entries as $news_entry) {
|
||||
$html .= make_atom_entry_from_news($news_entry);
|
||||
}
|
||||
$html .= "</feed>";
|
||||
return $html;
|
||||
foreach ($news_entries as $news_entry) {
|
||||
$html .= make_atom_entry_from_news($news_entry);
|
||||
}
|
||||
$html .= "</feed>";
|
||||
return $html;
|
||||
}
|
||||
|
||||
function make_atom_entry_from_news($news_entry) {
|
||||
return " <entry>
|
||||
function make_atom_entry_from_news($news_entry)
|
||||
{
|
||||
return " <entry>
|
||||
<title>" . htmlspecialchars($news_entry['Betreff']) . "</title>
|
||||
<link href=\"" . page_link_to_absolute("news_comments&nid=") . "${news_entry['ID']}\"/>
|
||||
<id>" . preg_replace('#^https?://#', '', page_link_to_absolute("news")) . "-${news_entry['ID']}</id>
|
||||
|
@ -48,4 +51,3 @@ function make_atom_entry_from_news($news_entry) {
|
|||
<summary type=\"html\">" . htmlspecialchars($news_entry['Text']) . "</summary>
|
||||
</entry>\n";
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,26 +3,27 @@
|
|||
/**
|
||||
* Controller for ical output of users own shifts or any user_shifts filter.
|
||||
*/
|
||||
function user_ical() {
|
||||
global $user;
|
||||
function user_ical()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
engelsystem_error("Missing key.");
|
||||
}
|
||||
$key = $_REQUEST['key'];
|
||||
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
engelsystem_error("Missing key.");
|
||||
}
|
||||
$key = $_REQUEST['key'];
|
||||
|
||||
$user = User_by_api_key($key);
|
||||
if ($user == null) {
|
||||
engelsystem_error("Key invalid.");
|
||||
}
|
||||
$user = User_by_api_key($key);
|
||||
if ($user == null) {
|
||||
engelsystem_error("Key invalid.");
|
||||
}
|
||||
|
||||
if (! in_array('ical', privileges_for_user($user['UID']))) {
|
||||
engelsystem_error("No privilege for ical.");
|
||||
}
|
||||
if (! in_array('ical', privileges_for_user($user['UID']))) {
|
||||
engelsystem_error("No privilege for ical.");
|
||||
}
|
||||
|
||||
$ical_shifts = load_ical_shifts();
|
||||
$ical_shifts = load_ical_shifts();
|
||||
|
||||
send_ical_from_shifts($ical_shifts);
|
||||
send_ical_from_shifts($ical_shifts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,16 +31,17 @@ function user_ical() {
|
|||
*
|
||||
* @param array<Shift> $shifts
|
||||
*/
|
||||
function send_ical_from_shifts($shifts) {
|
||||
header("Content-Type: text/calendar; charset=utf-8");
|
||||
$output = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//-//Engelsystem//DE\r\nCALSCALE:GREGORIAN\r\n";
|
||||
foreach ($shifts as $shift) {
|
||||
$output .= make_ical_entry_from_shift($shift);
|
||||
}
|
||||
$output .= "END:VCALENDAR\r\n";
|
||||
$output = trim($output, "\x0A");
|
||||
header("Content-Length: " . strlen($output));
|
||||
raw_output($output);
|
||||
function send_ical_from_shifts($shifts)
|
||||
{
|
||||
header("Content-Type: text/calendar; charset=utf-8");
|
||||
$output = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//-//Engelsystem//DE\r\nCALSCALE:GREGORIAN\r\n";
|
||||
foreach ($shifts as $shift) {
|
||||
$output .= make_ical_entry_from_shift($shift);
|
||||
}
|
||||
$output .= "END:VCALENDAR\r\n";
|
||||
$output = trim($output, "\x0A");
|
||||
header("Content-Length: " . strlen($output));
|
||||
raw_output($output);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,17 +49,17 @@ function send_ical_from_shifts($shifts) {
|
|||
*
|
||||
* @param Shift $shift
|
||||
*/
|
||||
function make_ical_entry_from_shift($shift) {
|
||||
$output = "BEGIN:VEVENT\r\n";
|
||||
$output .= "UID:" . md5($shift['start'] . $shift['end'] . $shift['name']) . "\r\n";
|
||||
$output .= "SUMMARY:" . str_replace("\n", "\\n", $shift['name']) . " (" . str_replace("\n", "\\n", $shift['title']) . ")\r\n";
|
||||
if (isset($shift['Comment'])) {
|
||||
$output .= "DESCRIPTION:" . str_replace("\n", "\\n", $shift['Comment']) . "\r\n";
|
||||
}
|
||||
$output .= "DTSTART;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['start']) . "\r\n";
|
||||
$output .= "DTEND;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['end']) . "\r\n";
|
||||
$output .= "LOCATION:" . $shift['Name'] . "\r\n";
|
||||
$output .= "END:VEVENT\r\n";
|
||||
return $output;
|
||||
function make_ical_entry_from_shift($shift)
|
||||
{
|
||||
$output = "BEGIN:VEVENT\r\n";
|
||||
$output .= "UID:" . md5($shift['start'] . $shift['end'] . $shift['name']) . "\r\n";
|
||||
$output .= "SUMMARY:" . str_replace("\n", "\\n", $shift['name']) . " (" . str_replace("\n", "\\n", $shift['title']) . ")\r\n";
|
||||
if (isset($shift['Comment'])) {
|
||||
$output .= "DESCRIPTION:" . str_replace("\n", "\\n", $shift['Comment']) . "\r\n";
|
||||
}
|
||||
$output .= "DTSTART;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['start']) . "\r\n";
|
||||
$output .= "DTEND;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['end']) . "\r\n";
|
||||
$output .= "LOCATION:" . $shift['Name'] . "\r\n";
|
||||
$output .= "END:VEVENT\r\n";
|
||||
return $output;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,40 +1,43 @@
|
|||
<?php
|
||||
|
||||
function messages_title() {
|
||||
return _("Messages");
|
||||
function messages_title()
|
||||
{
|
||||
return _("Messages");
|
||||
}
|
||||
|
||||
function user_unread_messages() {
|
||||
global $user;
|
||||
function user_unread_messages()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (isset($user)) {
|
||||
$new_messages = sql_num_query("SELECT * FROM `Messages` WHERE isRead='N' AND `RUID`='" . sql_escape($user['UID']) . "'");
|
||||
if ($new_messages > 0) {
|
||||
return ' <span class="badge danger">' . $new_messages . '</span>';
|
||||
if (isset($user)) {
|
||||
$new_messages = sql_num_query("SELECT * FROM `Messages` WHERE isRead='N' AND `RUID`='" . sql_escape($user['UID']) . "'");
|
||||
if ($new_messages > 0) {
|
||||
return ' <span class="badge danger">' . $new_messages . '</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
return '';
|
||||
}
|
||||
|
||||
function user_messages() {
|
||||
global $user;
|
||||
function user_messages()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$users = sql_select("SELECT * FROM `User` WHERE NOT `UID`='" . sql_escape($user['UID']) . "' ORDER BY `Nick`");
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$users = sql_select("SELECT * FROM `User` WHERE NOT `UID`='" . sql_escape($user['UID']) . "' ORDER BY `Nick`");
|
||||
|
||||
$to_select_data = [
|
||||
$to_select_data = [
|
||||
"" => _("Select recipient...")
|
||||
];
|
||||
|
||||
foreach ($users as $u) {
|
||||
$to_select_data[$u['UID']] = $u['Nick'];
|
||||
}
|
||||
foreach ($users as $u) {
|
||||
$to_select_data[$u['UID']] = $u['Nick'];
|
||||
}
|
||||
|
||||
$to_select = html_select_key('to', 'to', $to_select_data, '');
|
||||
$to_select = html_select_key('to', 'to', $to_select_data, '');
|
||||
|
||||
$messages = sql_select("SELECT * FROM `Messages` WHERE `SUID`='" . sql_escape($user['UID']) . "' OR `RUID`='" . sql_escape($user['UID']) . "' ORDER BY `isRead`,`Datum` DESC");
|
||||
$messages = sql_select("SELECT * FROM `Messages` WHERE `SUID`='" . sql_escape($user['UID']) . "' OR `RUID`='" . sql_escape($user['UID']) . "' ORDER BY `isRead`,`Datum` DESC");
|
||||
|
||||
$messages_table = [
|
||||
$messages_table = [
|
||||
[
|
||||
'news' => '',
|
||||
'timestamp' => date("Y-m-d H:i"),
|
||||
|
@ -45,11 +48,11 @@ function user_messages() {
|
|||
]
|
||||
];
|
||||
|
||||
foreach ($messages as $message) {
|
||||
$sender_user_source = User($message['SUID']);
|
||||
$receiver_user_source = User($message['RUID']);
|
||||
foreach ($messages as $message) {
|
||||
$sender_user_source = User($message['SUID']);
|
||||
$receiver_user_source = User($message['RUID']);
|
||||
|
||||
$messages_table_entry = [
|
||||
$messages_table_entry = [
|
||||
'new' => $message['isRead'] == 'N' ? '<span class="glyphicon glyphicon-envelope"></span>' : '',
|
||||
'timestamp' => date("Y-m-d H:i", $message['Datum']),
|
||||
'from' => User_Nick_render($sender_user_source),
|
||||
|
@ -57,17 +60,17 @@ function user_messages() {
|
|||
'text' => str_replace("\n", '<br />', $message['Text'])
|
||||
];
|
||||
|
||||
if ($message['RUID'] == $user['UID']) {
|
||||
if ($message['isRead'] == 'N') {
|
||||
$messages_table_entry['actions'] = button(page_link_to("user_messages") . '&action=read&id=' . $message['id'], _("mark as read"), 'btn-xs');
|
||||
if ($message['RUID'] == $user['UID']) {
|
||||
if ($message['isRead'] == 'N') {
|
||||
$messages_table_entry['actions'] = button(page_link_to("user_messages") . '&action=read&id=' . $message['id'], _("mark as read"), 'btn-xs');
|
||||
}
|
||||
} else {
|
||||
$messages_table_entry['actions'] = button(page_link_to("user_messages") . '&action=delete&id=' . $message['id'], _("delete message"), 'btn-xs');
|
||||
}
|
||||
$messages_table[] = $messages_table_entry;
|
||||
}
|
||||
} else {
|
||||
$messages_table_entry['actions'] = button(page_link_to("user_messages") . '&action=delete&id=' . $message['id'], _("delete message"), 'btn-xs');
|
||||
}
|
||||
$messages_table[] = $messages_table_entry;
|
||||
}
|
||||
|
||||
return page_with_title(messages_title(), [
|
||||
return page_with_title(messages_title(), [
|
||||
msg(),
|
||||
sprintf(_("Hello %s, here can you leave messages for other angels"), User_Nick_render($user)),
|
||||
form([
|
||||
|
@ -81,51 +84,50 @@ function user_messages() {
|
|||
], $messages_table)
|
||||
], page_link_to('user_messages') . '&action=send')
|
||||
]);
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
case "read":
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$message_id = $_REQUEST['id'];
|
||||
$message_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error(_("Incomplete call, missing Message ID."), true);
|
||||
return error(_("Incomplete call, missing Message ID."), true);
|
||||
}
|
||||
|
||||
$message = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
|
||||
if (count($message) > 0 && $message[0]['RUID'] == $user['UID']) {
|
||||
sql_query("UPDATE `Messages` SET `isRead`='Y' WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
|
||||
redirect(page_link_to("user_messages"));
|
||||
sql_query("UPDATE `Messages` SET `isRead`='Y' WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
|
||||
redirect(page_link_to("user_messages"));
|
||||
} else {
|
||||
return error(_("No Message found."), true);
|
||||
return error(_("No Message found."), true);
|
||||
}
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$message_id = $_REQUEST['id'];
|
||||
$message_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error(_("Incomplete call, missing Message ID."), true);
|
||||
return error(_("Incomplete call, missing Message ID."), true);
|
||||
}
|
||||
|
||||
$message = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
|
||||
if (count($message) > 0 && $message[0]['SUID'] == $user['UID']) {
|
||||
sql_query("DELETE FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
|
||||
redirect(page_link_to("user_messages"));
|
||||
sql_query("DELETE FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
|
||||
redirect(page_link_to("user_messages"));
|
||||
} else {
|
||||
return error(_("No Message found."), true);
|
||||
return error(_("No Message found."), true);
|
||||
}
|
||||
break;
|
||||
|
||||
case "send":
|
||||
if (Message_send($_REQUEST['to'], $_REQUEST['text']) === true) {
|
||||
redirect(page_link_to("user_messages"));
|
||||
redirect(page_link_to("user_messages"));
|
||||
} else {
|
||||
return error(_("Transmitting was terminated with an Error."), true);
|
||||
return error(_("Transmitting was terminated with an Error."), true);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return error(_("Wrong action."), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,35 +1,37 @@
|
|||
<?php
|
||||
|
||||
function myshifts_title() {
|
||||
return _("My shifts");
|
||||
function myshifts_title()
|
||||
{
|
||||
return _("My shifts");
|
||||
}
|
||||
|
||||
// Zeigt die Schichten an, die ein Benutzer belegt
|
||||
function user_myshifts() {
|
||||
global $LETZTES_AUSTRAGEN;
|
||||
global $user, $privileges;
|
||||
function user_myshifts()
|
||||
{
|
||||
global $LETZTES_AUSTRAGEN;
|
||||
global $user, $privileges;
|
||||
|
||||
if (isset($_REQUEST['id']) && in_array("user_shifts_admin", $privileges) && preg_match("/^[0-9]{1,}$/", $_REQUEST['id']) && sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($_REQUEST['id']) . "'") > 0) {
|
||||
$user_id = $_REQUEST['id'];
|
||||
} else {
|
||||
$user_id = $user['UID'];
|
||||
}
|
||||
|
||||
list($shifts_user) = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
|
||||
if (isset($_REQUEST['reset'])) {
|
||||
if ($_REQUEST['reset'] == "ack") {
|
||||
User_reset_api_key($user);
|
||||
success(_("Key changed."));
|
||||
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
|
||||
if (isset($_REQUEST['id']) && in_array("user_shifts_admin", $privileges) && preg_match("/^[0-9]{1,}$/", $_REQUEST['id']) && sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($_REQUEST['id']) . "'") > 0) {
|
||||
$user_id = $_REQUEST['id'];
|
||||
} else {
|
||||
$user_id = $user['UID'];
|
||||
}
|
||||
return page_with_title(_("Reset API key"), [
|
||||
|
||||
list($shifts_user) = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
|
||||
|
||||
if (isset($_REQUEST['reset'])) {
|
||||
if ($_REQUEST['reset'] == "ack") {
|
||||
User_reset_api_key($user);
|
||||
success(_("Key changed."));
|
||||
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
|
||||
}
|
||||
return page_with_title(_("Reset API key"), [
|
||||
error(_("If you reset the key, the url to your iCal- and JSON-export and your atom feed changes! You have to update it in every application using one of these exports."), true),
|
||||
button(page_link_to('user_myshifts') . '&reset=ack', _("Continue"), 'btn-danger')
|
||||
]);
|
||||
} elseif (isset($_REQUEST['edit']) && preg_match("/^[0-9]*$/", $_REQUEST['edit'])) {
|
||||
$user_id = $_REQUEST['edit'];
|
||||
$shift = sql_select("SELECT
|
||||
} elseif (isset($_REQUEST['edit']) && preg_match("/^[0-9]*$/", $_REQUEST['edit'])) {
|
||||
$user_id = $_REQUEST['edit'];
|
||||
$shift = sql_select("SELECT
|
||||
`ShiftEntry`.`freeloaded`,
|
||||
`ShiftEntry`.`freeload_comment`,
|
||||
`ShiftEntry`.`Comment`,
|
||||
|
@ -45,74 +47,73 @@ function user_myshifts() {
|
|||
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
|
||||
WHERE `ShiftEntry`.`id`='" . sql_escape($user_id) . "'
|
||||
AND `UID`='" . sql_escape($shifts_user['UID']) . "' LIMIT 1");
|
||||
if (count($shift) > 0) {
|
||||
$shift = $shift[0];
|
||||
$freeloaded = $shift['freeloaded'];
|
||||
$freeload_comment = $shift['freeload_comment'];
|
||||
if (count($shift) > 0) {
|
||||
$shift = $shift[0];
|
||||
$freeloaded = $shift['freeloaded'];
|
||||
$freeload_comment = $shift['freeload_comment'];
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
if (in_array("user_shifts_admin", $privileges)) {
|
||||
$freeloaded = isset($_REQUEST['freeloaded']);
|
||||
$freeload_comment = strip_request_item_nl('freeload_comment');
|
||||
if ($freeloaded && $freeload_comment == '') {
|
||||
$valid = false;
|
||||
error(_("Please enter a freeload comment!"));
|
||||
}
|
||||
}
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$valid = true;
|
||||
if (in_array("user_shifts_admin", $privileges)) {
|
||||
$freeloaded = isset($_REQUEST['freeloaded']);
|
||||
$freeload_comment = strip_request_item_nl('freeload_comment');
|
||||
if ($freeloaded && $freeload_comment == '') {
|
||||
$valid = false;
|
||||
error(_("Please enter a freeload comment!"));
|
||||
}
|
||||
}
|
||||
|
||||
$comment = strip_request_item_nl('comment');
|
||||
$user_source = User($shift['UID']);
|
||||
$comment = strip_request_item_nl('comment');
|
||||
$user_source = User($shift['UID']);
|
||||
|
||||
if ($valid) {
|
||||
$result = ShiftEntry_update([
|
||||
if ($valid) {
|
||||
$result = ShiftEntry_update([
|
||||
'id' => $user_id,
|
||||
'Comment' => $comment,
|
||||
'freeloaded' => $freeloaded,
|
||||
'freeload_comment' => $freeload_comment
|
||||
]);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shift entry.');
|
||||
}
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update shift entry.');
|
||||
}
|
||||
|
||||
engelsystem_log("Updated " . User_Nick_render($user_source) . "'s shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']) . " with comment " . $comment . ". Freeloaded: " . ($freeloaded ? "YES Comment: " . $freeload_comment : "NO"));
|
||||
success(_("Shift saved."));
|
||||
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
|
||||
engelsystem_log("Updated " . User_Nick_render($user_source) . "'s shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']) . " with comment " . $comment . ". Freeloaded: " . ($freeloaded ? "YES Comment: " . $freeload_comment : "NO"));
|
||||
success(_("Shift saved."));
|
||||
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
|
||||
}
|
||||
}
|
||||
|
||||
return ShiftEntry_edit_view(User_Nick_render($shifts_user), date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), $shift['Name'], $shift['name'], $shift['angel_type'], $shift['Comment'], $shift['freeloaded'], $shift['freeload_comment'], in_array("user_shifts_admin", $privileges));
|
||||
} else {
|
||||
redirect(page_link_to('user_myshifts'));
|
||||
}
|
||||
}
|
||||
|
||||
return ShiftEntry_edit_view(User_Nick_render($shifts_user), date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), $shift['Name'], $shift['name'], $shift['angel_type'], $shift['Comment'], $shift['freeloaded'], $shift['freeload_comment'], in_array("user_shifts_admin", $privileges));
|
||||
} else {
|
||||
redirect(page_link_to('user_myshifts'));
|
||||
}
|
||||
} elseif (isset($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) {
|
||||
$user_id = $_REQUEST['cancel'];
|
||||
$shift = sql_select("
|
||||
} elseif (isset($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) {
|
||||
$user_id = $_REQUEST['cancel'];
|
||||
$shift = sql_select("
|
||||
SELECT *
|
||||
FROM `Shifts`
|
||||
INNER JOIN `ShiftEntry` USING (`SID`)
|
||||
WHERE `ShiftEntry`.`id`='" . sql_escape($user_id) . "' AND `UID`='" . sql_escape($shifts_user['UID']) . "'");
|
||||
if (count($shift) > 0) {
|
||||
$shift = $shift[0];
|
||||
if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) {
|
||||
$result = ShiftEntry_delete($user_id);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift entry.');
|
||||
if (count($shift) > 0) {
|
||||
$shift = $shift[0];
|
||||
if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) {
|
||||
$result = ShiftEntry_delete($user_id);
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to delete shift entry.');
|
||||
}
|
||||
$room = Room($shift['RID']);
|
||||
$angeltype = AngelType($shift['TID']);
|
||||
$shifttype = ShiftType($shift['shifttype_id']);
|
||||
|
||||
engelsystem_log("Deleted own shift: " . $shifttype['name'] . " at " . $room['Name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']) . " as " . $angeltype['name']);
|
||||
success(_("Shift canceled."));
|
||||
} else {
|
||||
error(_("It's too late to sign yourself off the shift. If neccessary, ask the dispatcher to do so."));
|
||||
}
|
||||
} else {
|
||||
redirect(user_link($shifts_user));
|
||||
}
|
||||
$room = Room($shift['RID']);
|
||||
$angeltype = AngelType($shift['TID']);
|
||||
$shifttype = ShiftType($shift['shifttype_id']);
|
||||
|
||||
engelsystem_log("Deleted own shift: " . $shifttype['name'] . " at " . $room['Name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']) . " as " . $angeltype['name']);
|
||||
success(_("Shift canceled."));
|
||||
} else {
|
||||
error(_("It's too late to sign yourself off the shift. If neccessary, ask the dispatcher to do so."));
|
||||
}
|
||||
} else {
|
||||
redirect(user_link($shifts_user));
|
||||
}
|
||||
}
|
||||
|
||||
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
|
||||
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,169 +1,175 @@
|
|||
<?php
|
||||
|
||||
function user_news_comments_title() {
|
||||
return _("News comments");
|
||||
function user_news_comments_title()
|
||||
{
|
||||
return _("News comments");
|
||||
}
|
||||
|
||||
function news_title() {
|
||||
return _("News");
|
||||
function news_title()
|
||||
{
|
||||
return _("News");
|
||||
}
|
||||
|
||||
function meetings_title() {
|
||||
return _("Meetings");
|
||||
function meetings_title()
|
||||
{
|
||||
return _("Meetings");
|
||||
}
|
||||
|
||||
function user_meetings() {
|
||||
global $DISPLAY_NEWS;
|
||||
function user_meetings()
|
||||
{
|
||||
global $DISPLAY_NEWS;
|
||||
|
||||
$html = '<div class="col-md-12"><h1>' . meetings_title() . '</h1>' . msg();
|
||||
$html = '<div class="col-md-12"><h1>' . meetings_title() . '</h1>' . msg();
|
||||
|
||||
if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page'])) {
|
||||
$page = $_REQUEST['page'];
|
||||
} else {
|
||||
$page = 0;
|
||||
}
|
||||
|
||||
$news = sql_select("SELECT * FROM `News` WHERE `Treffen`=1 ORDER BY `Datum` DESC LIMIT " . sql_escape($page * $DISPLAY_NEWS) . ", " . sql_escape($DISPLAY_NEWS));
|
||||
foreach ($news as $entry) {
|
||||
$html .= display_news($entry);
|
||||
}
|
||||
|
||||
$dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $DISPLAY_NEWS);
|
||||
$html .= '<div class="text-center">' . '<ul class="pagination">';
|
||||
for ($i = 0; $i < $dis_rows; $i ++) {
|
||||
if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) {
|
||||
$html .= '<li class="active">';
|
||||
} elseif (! isset($_REQUEST['page']) && $i == 0) {
|
||||
$html .= '<li class="active">';
|
||||
if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page'])) {
|
||||
$page = $_REQUEST['page'];
|
||||
} else {
|
||||
$html .= '<li>';
|
||||
$page = 0;
|
||||
}
|
||||
$html .= '<a href="' . page_link_to("user_meetings") . '&page=' . $i . '">' . ($i + 1) . '</a></li>';
|
||||
}
|
||||
$html .= '</ul></div></div>';
|
||||
|
||||
return $html;
|
||||
$news = sql_select("SELECT * FROM `News` WHERE `Treffen`=1 ORDER BY `Datum` DESC LIMIT " . sql_escape($page * $DISPLAY_NEWS) . ", " . sql_escape($DISPLAY_NEWS));
|
||||
foreach ($news as $entry) {
|
||||
$html .= display_news($entry);
|
||||
}
|
||||
|
||||
$dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $DISPLAY_NEWS);
|
||||
$html .= '<div class="text-center">' . '<ul class="pagination">';
|
||||
for ($i = 0; $i < $dis_rows; $i ++) {
|
||||
if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) {
|
||||
$html .= '<li class="active">';
|
||||
} elseif (! isset($_REQUEST['page']) && $i == 0) {
|
||||
$html .= '<li class="active">';
|
||||
} else {
|
||||
$html .= '<li>';
|
||||
}
|
||||
$html .= '<a href="' . page_link_to("user_meetings") . '&page=' . $i . '">' . ($i + 1) . '</a></li>';
|
||||
}
|
||||
$html .= '</ul></div></div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function display_news($news) {
|
||||
global $privileges, $page;
|
||||
function display_news($news)
|
||||
{
|
||||
global $privileges, $page;
|
||||
|
||||
$html = '';
|
||||
$html .= '<div class="panel' . ($news['Treffen'] == 1 ? ' panel-info' : ' panel-default') . '">';
|
||||
$html .= '<div class="panel-heading">';
|
||||
$html .= '<h3 class="panel-title">' . ($news['Treffen'] == 1 ? '[Meeting] ' : '') . ReplaceSmilies($news['Betreff']) . '</h3>';
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="panel-body">' . ReplaceSmilies(nl2br($news['Text'])) . '</div>';
|
||||
$html = '';
|
||||
$html .= '<div class="panel' . ($news['Treffen'] == 1 ? ' panel-info' : ' panel-default') . '">';
|
||||
$html .= '<div class="panel-heading">';
|
||||
$html .= '<h3 class="panel-title">' . ($news['Treffen'] == 1 ? '[Meeting] ' : '') . ReplaceSmilies($news['Betreff']) . '</h3>';
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="panel-body">' . ReplaceSmilies(nl2br($news['Text'])) . '</div>';
|
||||
|
||||
$html .= '<div class="panel-footer text-muted">';
|
||||
if (in_array("admin_news", $privileges)) {
|
||||
$html .= '<div class="pull-right">' . button_glyph(page_link_to("admin_news") . '&action=edit&id=' . $news['ID'], 'edit', 'btn-xs') . '</div>';
|
||||
}
|
||||
$html .= '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $news['Datum']) . ' ';
|
||||
$html .= '<div class="panel-footer text-muted">';
|
||||
if (in_array("admin_news", $privileges)) {
|
||||
$html .= '<div class="pull-right">' . button_glyph(page_link_to("admin_news") . '&action=edit&id=' . $news['ID'], 'edit', 'btn-xs') . '</div>';
|
||||
}
|
||||
$html .= '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $news['Datum']) . ' ';
|
||||
|
||||
$user_source = User($news['UID']);
|
||||
$user_source = User($news['UID']);
|
||||
|
||||
$html .= User_Nick_render($user_source);
|
||||
if ($page != "news_comments") {
|
||||
$html .= ' <a href="' . page_link_to("news_comments") . '&nid=' . $news['ID'] . '"><span class="glyphicon glyphicon-comment"></span> ' . _("Comments") . ' »</a> <span class="badge">' . sql_num_query("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($news['ID']) . "'") . '</span>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
$html .= User_Nick_render($user_source);
|
||||
if ($page != "news_comments") {
|
||||
$html .= ' <a href="' . page_link_to("news_comments") . '&nid=' . $news['ID'] . '"><span class="glyphicon glyphicon-comment"></span> ' . _("Comments") . ' »</a> <span class="badge">' . sql_num_query("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($news['ID']) . "'") . '</span>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
function user_news_comments() {
|
||||
global $user;
|
||||
function user_news_comments()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$html = '<div class="col-md-12"><h1>' . user_news_comments_title() . '</h1>';
|
||||
if (isset($_REQUEST["nid"]) && preg_match("/^[0-9]{1,}$/", $_REQUEST['nid']) && sql_num_query("SELECT * FROM `News` WHERE `ID`='" . sql_escape($_REQUEST['nid']) . "' LIMIT 1") > 0) {
|
||||
$nid = $_REQUEST["nid"];
|
||||
list($news) = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($nid) . "' LIMIT 1");
|
||||
if (isset($_REQUEST["text"])) {
|
||||
$text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($_REQUEST['text']));
|
||||
sql_query("INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`) VALUES ('" . sql_escape($nid) . "', '" . date("Y-m-d H:i:s") . "', '" . sql_escape($text) . "', '" . sql_escape($user["UID"]) . "')");
|
||||
engelsystem_log("Created news_comment: " . $text);
|
||||
$html .= success(_("Entry saved."), true);
|
||||
}
|
||||
$html = '<div class="col-md-12"><h1>' . user_news_comments_title() . '</h1>';
|
||||
if (isset($_REQUEST["nid"]) && preg_match("/^[0-9]{1,}$/", $_REQUEST['nid']) && sql_num_query("SELECT * FROM `News` WHERE `ID`='" . sql_escape($_REQUEST['nid']) . "' LIMIT 1") > 0) {
|
||||
$nid = $_REQUEST["nid"];
|
||||
list($news) = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($nid) . "' LIMIT 1");
|
||||
if (isset($_REQUEST["text"])) {
|
||||
$text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($_REQUEST['text']));
|
||||
sql_query("INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`) VALUES ('" . sql_escape($nid) . "', '" . date("Y-m-d H:i:s") . "', '" . sql_escape($text) . "', '" . sql_escape($user["UID"]) . "')");
|
||||
engelsystem_log("Created news_comment: " . $text);
|
||||
$html .= success(_("Entry saved."), true);
|
||||
}
|
||||
|
||||
$html .= display_news($news);
|
||||
$html .= display_news($news);
|
||||
|
||||
$comments = sql_select("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($nid) . "' ORDER BY 'ID'");
|
||||
foreach ($comments as $comment) {
|
||||
$user_source = User($comment['UID']);
|
||||
$comments = sql_select("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($nid) . "' ORDER BY 'ID'");
|
||||
foreach ($comments as $comment) {
|
||||
$user_source = User($comment['UID']);
|
||||
|
||||
$html .= '<div class="panel panel-default">';
|
||||
$html .= '<div class="panel-body">' . nl2br($comment['Text']) . '</div>';
|
||||
$html .= '<div class="panel-footer text-muted">';
|
||||
$html .= '<span class="glyphicon glyphicon-time"></span> ' . $comment['Datum'] . ' ';
|
||||
$html .= User_Nick_render($user_source);
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
}
|
||||
$html .= '<div class="panel panel-default">';
|
||||
$html .= '<div class="panel-body">' . nl2br($comment['Text']) . '</div>';
|
||||
$html .= '<div class="panel-footer text-muted">';
|
||||
$html .= '<span class="glyphicon glyphicon-time"></span> ' . $comment['Datum'] . ' ';
|
||||
$html .= User_Nick_render($user_source);
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
$html .= '<hr /><h2>' . _("New Comment:") . '</h2>';
|
||||
$html .= form([
|
||||
$html .= '<hr /><h2>' . _("New Comment:") . '</h2>';
|
||||
$html .= form([
|
||||
form_textarea('text', _("Message"), ''),
|
||||
form_submit('submit', _("Save"))
|
||||
], page_link_to('news_comments') . '&nid=' . $news['ID']);
|
||||
} else {
|
||||
$html .= _("Invalid request.");
|
||||
}
|
||||
} else {
|
||||
$html .= _("Invalid request.");
|
||||
}
|
||||
|
||||
return $html . '</div>';
|
||||
return $html . '</div>';
|
||||
}
|
||||
|
||||
function user_news() {
|
||||
global $DISPLAY_NEWS, $privileges, $user;
|
||||
function user_news()
|
||||
{
|
||||
global $DISPLAY_NEWS, $privileges, $user;
|
||||
|
||||
$html = '<div class="col-md-12"><h1>' . news_title() . '</h1>' . msg();
|
||||
$html = '<div class="col-md-12"><h1>' . news_title() . '</h1>' . msg();
|
||||
|
||||
if (isset($_POST["text"]) && isset($_POST["betreff"]) && in_array("admin_news", $privileges)) {
|
||||
if (! isset($_POST["treffen"]) || ! in_array("admin_news", $privileges)) {
|
||||
$_POST["treffen"] = 0;
|
||||
if (isset($_POST["text"]) && isset($_POST["betreff"]) && in_array("admin_news", $privileges)) {
|
||||
if (! isset($_POST["treffen"]) || ! in_array("admin_news", $privileges)) {
|
||||
$_POST["treffen"] = 0;
|
||||
}
|
||||
sql_query("INSERT INTO `News` (`Datum`, `Betreff`, `Text`, `UID`, `Treffen`) " . "VALUES ('" . sql_escape(time()) . "', '" . sql_escape($_POST["betreff"]) . "', '" . sql_escape($_POST["text"]) . "', '" . sql_escape($user['UID']) . "', '" . sql_escape($_POST["treffen"]) . "');");
|
||||
engelsystem_log("Created news: " . $_POST["betreff"] . ", treffen: " . $_POST["treffen"]);
|
||||
success(_("Entry saved."));
|
||||
redirect(page_link_to('news'));
|
||||
}
|
||||
sql_query("INSERT INTO `News` (`Datum`, `Betreff`, `Text`, `UID`, `Treffen`) " . "VALUES ('" . sql_escape(time()) . "', '" . sql_escape($_POST["betreff"]) . "', '" . sql_escape($_POST["text"]) . "', '" . sql_escape($user['UID']) . "', '" . sql_escape($_POST["treffen"]) . "');");
|
||||
engelsystem_log("Created news: " . $_POST["betreff"] . ", treffen: " . $_POST["treffen"]);
|
||||
success(_("Entry saved."));
|
||||
redirect(page_link_to('news'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page'])) {
|
||||
$page = $_REQUEST['page'];
|
||||
} else {
|
||||
$page = 0;
|
||||
}
|
||||
|
||||
$news = sql_select("SELECT * FROM `News` ORDER BY `Datum` DESC LIMIT " . sql_escape($page * $DISPLAY_NEWS) . ", " . sql_escape($DISPLAY_NEWS));
|
||||
foreach ($news as $entry) {
|
||||
$html .= display_news($entry);
|
||||
}
|
||||
|
||||
$dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $DISPLAY_NEWS);
|
||||
$html .= '<div class="text-center">' . '<ul class="pagination">';
|
||||
for ($i = 0; $i < $dis_rows; $i ++) {
|
||||
if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) {
|
||||
$html .= '<li class="active">';
|
||||
} elseif (! isset($_REQUEST['page']) && $i == 0) {
|
||||
$html .= '<li class="active">';
|
||||
if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page'])) {
|
||||
$page = $_REQUEST['page'];
|
||||
} else {
|
||||
$html .= '<li>';
|
||||
$page = 0;
|
||||
}
|
||||
$html .= '<a href="' . page_link_to("news") . '&page=' . $i . '">' . ($i + 1) . '</a></li>';
|
||||
}
|
||||
$html .= '</ul></div>';
|
||||
|
||||
if (in_array("admin_news", $privileges)) {
|
||||
$html .= '<hr />';
|
||||
$html .= '<h2>' . _("Create news:") . '</h2>';
|
||||
$news = sql_select("SELECT * FROM `News` ORDER BY `Datum` DESC LIMIT " . sql_escape($page * $DISPLAY_NEWS) . ", " . sql_escape($DISPLAY_NEWS));
|
||||
foreach ($news as $entry) {
|
||||
$html .= display_news($entry);
|
||||
}
|
||||
|
||||
$html .= form([
|
||||
$dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $DISPLAY_NEWS);
|
||||
$html .= '<div class="text-center">' . '<ul class="pagination">';
|
||||
for ($i = 0; $i < $dis_rows; $i ++) {
|
||||
if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) {
|
||||
$html .= '<li class="active">';
|
||||
} elseif (! isset($_REQUEST['page']) && $i == 0) {
|
||||
$html .= '<li class="active">';
|
||||
} else {
|
||||
$html .= '<li>';
|
||||
}
|
||||
$html .= '<a href="' . page_link_to("news") . '&page=' . $i . '">' . ($i + 1) . '</a></li>';
|
||||
}
|
||||
$html .= '</ul></div>';
|
||||
|
||||
if (in_array("admin_news", $privileges)) {
|
||||
$html .= '<hr />';
|
||||
$html .= '<h2>' . _("Create news:") . '</h2>';
|
||||
|
||||
$html .= form([
|
||||
form_text('betreff', _("Subject"), ''),
|
||||
form_textarea('text', _("Message"), ''),
|
||||
form_checkbox('treffen', _("Meeting"), false, 1),
|
||||
form_submit('submit', _("Save"))
|
||||
]);
|
||||
}
|
||||
return $html . '</div>';
|
||||
}
|
||||
return $html . '</div>';
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,57 +1,58 @@
|
|||
<?php
|
||||
|
||||
function questions_title() {
|
||||
return _("Ask the Heaven");
|
||||
function questions_title()
|
||||
{
|
||||
return _("Ask the Heaven");
|
||||
}
|
||||
|
||||
function user_questions() {
|
||||
global $user;
|
||||
function user_questions()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$open_questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
|
||||
if (! isset($_REQUEST['action'])) {
|
||||
$open_questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
|
||||
|
||||
$answered_questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
|
||||
foreach ($answered_questions as &$question) {
|
||||
$answer_user_source = User($question['AID']);
|
||||
$question['answer_user'] = User_Nick_render($answer_user_source);
|
||||
}
|
||||
$answered_questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
|
||||
foreach ($answered_questions as &$question) {
|
||||
$answer_user_source = User($question['AID']);
|
||||
$question['answer_user'] = User_Nick_render($answer_user_source);
|
||||
}
|
||||
|
||||
return Questions_view($open_questions, $answered_questions, page_link_to("user_questions") . '&action=ask');
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
return Questions_view($open_questions, $answered_questions, page_link_to("user_questions") . '&action=ask');
|
||||
} else {
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'ask':
|
||||
$question = strip_request_item_nl('question');
|
||||
if ($question != "") {
|
||||
$result = sql_query("INSERT INTO `Questions` SET `UID`='" . sql_escape($user['UID']) . "', `Question`='" . sql_escape($question) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error(_("Unable to save question."));
|
||||
}
|
||||
success(_("You question was saved."));
|
||||
redirect(page_link_to("user_questions"));
|
||||
$result = sql_query("INSERT INTO `Questions` SET `UID`='" . sql_escape($user['UID']) . "', `Question`='" . sql_escape($question) . "'");
|
||||
if ($result === false) {
|
||||
engelsystem_error(_("Unable to save question."));
|
||||
}
|
||||
success(_("You question was saved."));
|
||||
redirect(page_link_to("user_questions"));
|
||||
} else {
|
||||
return page_with_title(questions_title(), [
|
||||
return page_with_title(questions_title(), [
|
||||
error(_("Please enter a question!"), true)
|
||||
]);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
|
||||
$question_id = $_REQUEST['id'];
|
||||
$question_id = $_REQUEST['id'];
|
||||
} else {
|
||||
return error(_("Incomplete call, missing Question ID."), true);
|
||||
return error(_("Incomplete call, missing Question ID."), true);
|
||||
}
|
||||
|
||||
$question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
if (count($question) > 0 && $question[0]['UID'] == $user['UID']) {
|
||||
sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
redirect(page_link_to("user_questions"));
|
||||
sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1");
|
||||
redirect(page_link_to("user_questions"));
|
||||
} else {
|
||||
return page_with_title(questions_title(), [
|
||||
return page_with_title(questions_title(), [
|
||||
error(_("No question found."), true)
|
||||
]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
function settings_title() {
|
||||
return _("Settings");
|
||||
function settings_title()
|
||||
{
|
||||
return _("Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,75 +11,76 @@ function settings_title() {
|
|||
* @param User $user_source
|
||||
* The user
|
||||
*/
|
||||
function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) {
|
||||
$valid = true;
|
||||
function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['mail'])) {
|
||||
$result = User_validate_mail($_REQUEST['mail']);
|
||||
$user_source['email'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("E-mail address is not correct."));
|
||||
if (isset($_REQUEST['mail'])) {
|
||||
$result = User_validate_mail($_REQUEST['mail']);
|
||||
$user_source['email'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("E-mail address is not correct."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter your e-mail."));
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_("Please enter your e-mail."));
|
||||
}
|
||||
|
||||
$user_source['email_shiftinfo'] = isset($_REQUEST['email_shiftinfo']);
|
||||
$user_source['email_by_human_allowed'] = isset($_REQUEST['email_by_human_allowed']);
|
||||
$user_source['email_shiftinfo'] = isset($_REQUEST['email_shiftinfo']);
|
||||
$user_source['email_by_human_allowed'] = isset($_REQUEST['email_by_human_allowed']);
|
||||
|
||||
if (isset($_REQUEST['jabber'])) {
|
||||
$result = User_validate_jabber($_REQUEST['jabber']);
|
||||
$user_source['jabber'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please check your jabber account information."));
|
||||
if (isset($_REQUEST['jabber'])) {
|
||||
$result = User_validate_jabber($_REQUEST['jabber']);
|
||||
$user_source['jabber'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please check your jabber account information."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']])) {
|
||||
$user_source['Size'] = $_REQUEST['tshirt_size'];
|
||||
} elseif ($enable_tshirt_size) {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_arrival_date'])) {
|
||||
$tmp = parse_date("Y-m-d H:i", $_REQUEST['planned_arrival_date'] . " 00:00");
|
||||
$result = User_validate_planned_arrival_date($tmp);
|
||||
$user_source['planned_arrival_date'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date."));
|
||||
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']])) {
|
||||
$user_source['Size'] = $_REQUEST['tshirt_size'];
|
||||
} elseif ($enable_tshirt_size) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_departure_date'])) {
|
||||
$tmp = parse_date("Y-m-d H:i", $_REQUEST['planned_departure_date'] . " 00:00");
|
||||
$result = User_validate_planned_departure_date($user_source['planned_arrival_date'], $tmp);
|
||||
$user_source['planned_departure_date'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please enter your planned date of departure. It should be after your planned arrival date and after buildup start date and before teardown end date."));
|
||||
if (isset($_REQUEST['planned_arrival_date'])) {
|
||||
$tmp = parse_date("Y-m-d H:i", $_REQUEST['planned_arrival_date'] . " 00:00");
|
||||
$result = User_validate_planned_arrival_date($tmp);
|
||||
$user_source['planned_arrival_date'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date."));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_departure_date'])) {
|
||||
$tmp = parse_date("Y-m-d H:i", $_REQUEST['planned_departure_date'] . " 00:00");
|
||||
$result = User_validate_planned_departure_date($user_source['planned_arrival_date'], $tmp);
|
||||
$user_source['planned_departure_date'] = $result->getValue();
|
||||
if (! $result->isValid()) {
|
||||
$valid = false;
|
||||
error(_("Please enter your planned date of departure. It should be after your planned arrival date and after buildup start date and before teardown end date."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Trivia
|
||||
$user_source['Name'] = strip_request_item('lastname', $user_source['Name']);
|
||||
$user_source['Vorname'] = strip_request_item('prename', $user_source['Vorname']);
|
||||
$user_source['Alter'] = strip_request_item('age', $user_source['Alter']);
|
||||
$user_source['Telefon'] = strip_request_item('tel', $user_source['Telefon']);
|
||||
$user_source['DECT'] = strip_request_item('dect', $user_source['DECT']);
|
||||
$user_source['Handy'] = strip_request_item('mobile', $user_source['Handy']);
|
||||
$user_source['Hometown'] = strip_request_item('hometown', $user_source['Hometown']);
|
||||
$user_source['Vorname'] = strip_request_item('prename', $user_source['Vorname']);
|
||||
$user_source['Alter'] = strip_request_item('age', $user_source['Alter']);
|
||||
$user_source['Telefon'] = strip_request_item('tel', $user_source['Telefon']);
|
||||
$user_source['DECT'] = strip_request_item('dect', $user_source['DECT']);
|
||||
$user_source['Handy'] = strip_request_item('mobile', $user_source['Handy']);
|
||||
$user_source['Hometown'] = strip_request_item('hometown', $user_source['Hometown']);
|
||||
|
||||
if ($valid) {
|
||||
User_update($user_source);
|
||||
success(_("Settings saved."));
|
||||
redirect(page_link_to('user_settings'));
|
||||
}
|
||||
if ($valid) {
|
||||
User_update($user_source);
|
||||
success(_("Settings saved."));
|
||||
redirect(page_link_to('user_settings'));
|
||||
}
|
||||
|
||||
return $user_source;
|
||||
return $user_source;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,20 +89,21 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) {
|
|||
* @param User $user_source
|
||||
* The user
|
||||
*/
|
||||
function user_settings_password($user_source) {
|
||||
global $min_password_length;
|
||||
if (! isset($_REQUEST['password']) || ! verify_password($_REQUEST['password'], $user_source['Passwort'], $user_source['UID'])) {
|
||||
error(_("-> not OK. Please try again."));
|
||||
} elseif (strlen($_REQUEST['new_password']) < $min_password_length) {
|
||||
error(_("Your password is to short (please use at least 6 characters)."));
|
||||
} elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2']) {
|
||||
error(_("Your passwords don't match."));
|
||||
} elseif (set_password($user_source['UID'], $_REQUEST['new_password'])) {
|
||||
success(_("Password saved."));
|
||||
} else {
|
||||
error(_("Failed setting password."));
|
||||
}
|
||||
redirect(page_link_to('user_settings'));
|
||||
function user_settings_password($user_source)
|
||||
{
|
||||
global $min_password_length;
|
||||
if (! isset($_REQUEST['password']) || ! verify_password($_REQUEST['password'], $user_source['Passwort'], $user_source['UID'])) {
|
||||
error(_("-> not OK. Please try again."));
|
||||
} elseif (strlen($_REQUEST['new_password']) < $min_password_length) {
|
||||
error(_("Your password is to short (please use at least 6 characters)."));
|
||||
} elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2']) {
|
||||
error(_("Your passwords don't match."));
|
||||
} elseif (set_password($user_source['UID'], $_REQUEST['new_password'])) {
|
||||
success(_("Password saved."));
|
||||
} else {
|
||||
error(_("Failed setting password."));
|
||||
}
|
||||
redirect(page_link_to('user_settings'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,23 +114,24 @@ function user_settings_password($user_source) {
|
|||
* @param array<String> $themes
|
||||
* List of available themes
|
||||
*/
|
||||
function user_settings_theme($user_source, $themes) {
|
||||
$valid = true;
|
||||
function user_settings_theme($user_source, $themes)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['theme']) && isset($themes[$_REQUEST['theme']])) {
|
||||
$user_source['color'] = $_REQUEST['theme'];
|
||||
} else {
|
||||
$valid = false;
|
||||
}
|
||||
if (isset($_REQUEST['theme']) && isset($themes[$_REQUEST['theme']])) {
|
||||
$user_source['color'] = $_REQUEST['theme'];
|
||||
} else {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
sql_query("UPDATE `User` SET `color`='" . sql_escape($user_source['color']) . "' WHERE `UID`='" . sql_escape($user_source['UID']) . "'");
|
||||
if ($valid) {
|
||||
sql_query("UPDATE `User` SET `color`='" . sql_escape($user_source['color']) . "' WHERE `UID`='" . sql_escape($user_source['UID']) . "'");
|
||||
|
||||
success(_("Theme changed."));
|
||||
redirect(page_link_to('user_settings'));
|
||||
}
|
||||
success(_("Theme changed."));
|
||||
redirect(page_link_to('user_settings'));
|
||||
}
|
||||
|
||||
return $user_source;
|
||||
return $user_source;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,57 +142,58 @@ function user_settings_theme($user_source, $themes) {
|
|||
* @param array<String> $locales
|
||||
* List of available locales
|
||||
*/
|
||||
function user_settings_locale($user_source, $locales) {
|
||||
$valid = true;
|
||||
function user_settings_locale($user_source, $locales)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
if (isset($_REQUEST['language']) && isset($locales[$_REQUEST['language']])) {
|
||||
$user_source['Sprache'] = $_REQUEST['language'];
|
||||
} else {
|
||||
$valid = false;
|
||||
}
|
||||
if (isset($_REQUEST['language']) && isset($locales[$_REQUEST['language']])) {
|
||||
$user_source['Sprache'] = $_REQUEST['language'];
|
||||
} else {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
sql_query("UPDATE `User` SET `Sprache`='" . sql_escape($user_source['Sprache']) . "' WHERE `UID`='" . sql_escape($user_source['UID']) . "'");
|
||||
$_SESSION['locale'] = $user_source['Sprache'];
|
||||
if ($valid) {
|
||||
sql_query("UPDATE `User` SET `Sprache`='" . sql_escape($user_source['Sprache']) . "' WHERE `UID`='" . sql_escape($user_source['UID']) . "'");
|
||||
$_SESSION['locale'] = $user_source['Sprache'];
|
||||
|
||||
success("Language changed.");
|
||||
redirect(page_link_to('user_settings'));
|
||||
}
|
||||
success("Language changed.");
|
||||
redirect(page_link_to('user_settings'));
|
||||
}
|
||||
|
||||
return $user_source;
|
||||
return $user_source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main user settings page/controller
|
||||
*/
|
||||
function user_settings() {
|
||||
global $enable_tshirt_size, $tshirt_sizes, $themes, $locales;
|
||||
global $user;
|
||||
function user_settings()
|
||||
{
|
||||
global $enable_tshirt_size, $tshirt_sizes, $themes, $locales;
|
||||
global $user;
|
||||
|
||||
$buildup_start_date = null;
|
||||
$teardown_end_date = null;
|
||||
$event_config = EventConfig();
|
||||
if ($event_config != null) {
|
||||
if (isset($event_config['buildup_start_date'])) {
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
$buildup_start_date = null;
|
||||
$teardown_end_date = null;
|
||||
$event_config = EventConfig();
|
||||
if ($event_config != null) {
|
||||
if (isset($event_config['buildup_start_date'])) {
|
||||
$buildup_start_date = $event_config['buildup_start_date'];
|
||||
}
|
||||
if (isset($event_config['teardown_end_date'])) {
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
}
|
||||
}
|
||||
if (isset($event_config['teardown_end_date'])) {
|
||||
$teardown_end_date = $event_config['teardown_end_date'];
|
||||
|
||||
$user_source = $user;
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$user_source = user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes);
|
||||
} elseif (isset($_REQUEST['submit_password'])) {
|
||||
user_settings_password($user_source);
|
||||
} elseif (isset($_REQUEST['submit_theme'])) {
|
||||
$user_source = user_settings_theme($user_source, $themes);
|
||||
} elseif (isset($_REQUEST['submit_language'])) {
|
||||
$user_source = user_settings_locale($user_source, $locales);
|
||||
}
|
||||
}
|
||||
|
||||
$user_source = $user;
|
||||
|
||||
if (isset($_REQUEST['submit'])) {
|
||||
$user_source = user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes);
|
||||
} elseif (isset($_REQUEST['submit_password'])) {
|
||||
user_settings_password($user_source);
|
||||
} elseif (isset($_REQUEST['submit_theme'])) {
|
||||
$user_source = user_settings_theme($user_source, $themes);
|
||||
} elseif (isset($_REQUEST['submit_language'])) {
|
||||
$user_source = user_settings_locale($user_source, $locales);
|
||||
}
|
||||
|
||||
return User_settings_view($user_source, $locales, $themes, $buildup_start_date, $teardown_end_date, $enable_tshirt_size, $tshirt_sizes);
|
||||
return User_settings_view($user_source, $locales, $themes, $buildup_start_date, $teardown_end_date, $enable_tshirt_size, $tshirt_sizes);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
use Engelsystem\ShiftsFilter;
|
||||
|
||||
function shifts_title() {
|
||||
return _("Shifts");
|
||||
function shifts_title()
|
||||
{
|
||||
return _("Shifts");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,24 +13,25 @@ function shifts_title() {
|
|||
* Split actions into shift edit, shift delete, shift entry edit, shift entry delete
|
||||
* Introduce simpler and beautiful actions for shift entry join/leave for users
|
||||
*/
|
||||
function user_shifts() {
|
||||
global $user;
|
||||
function user_shifts()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (User_is_freeloader($user)) {
|
||||
redirect(page_link_to('user_myshifts'));
|
||||
}
|
||||
if (User_is_freeloader($user)) {
|
||||
redirect(page_link_to('user_myshifts'));
|
||||
}
|
||||
|
||||
// Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins
|
||||
if (isset($_REQUEST['entry_id'])) {
|
||||
return shift_entry_delete_controller();
|
||||
return shift_entry_delete_controller();
|
||||
} elseif (isset($_REQUEST['edit_shift'])) {
|
||||
return shift_edit_controller();
|
||||
return shift_edit_controller();
|
||||
} elseif (isset($_REQUEST['delete_shift'])) {
|
||||
return shift_delete_controller();
|
||||
return shift_delete_controller();
|
||||
} elseif (isset($_REQUEST['shift_id'])) {
|
||||
return shift_entry_add_controller();
|
||||
return shift_entry_add_controller();
|
||||
}
|
||||
return view_user_shifts();
|
||||
return view_user_shifts();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,23 +41,24 @@ function user_shifts() {
|
|||
* @param ShiftsFilter $shiftsFilter
|
||||
* The shiftfilter to update.
|
||||
*/
|
||||
function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) {
|
||||
$start_time = $shiftsFilter->getStartTime();
|
||||
if ($start_time == null) {
|
||||
$start_time = time();
|
||||
}
|
||||
function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days)
|
||||
{
|
||||
$start_time = $shiftsFilter->getStartTime();
|
||||
if ($start_time == null) {
|
||||
$start_time = time();
|
||||
}
|
||||
|
||||
$end_time = $shiftsFilter->getEndTime();
|
||||
if ($end_time == null) {
|
||||
$end_time = $start_time + 24 * 60 * 60;
|
||||
}
|
||||
$end_time = $shiftsFilter->getEndTime();
|
||||
if ($end_time == null) {
|
||||
$end_time = $start_time + 24 * 60 * 60;
|
||||
}
|
||||
|
||||
$shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, $start_time));
|
||||
$shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, $end_time));
|
||||
$shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, $start_time));
|
||||
$shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, $end_time));
|
||||
|
||||
if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) {
|
||||
$shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60);
|
||||
}
|
||||
if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) {
|
||||
$shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,75 +71,80 @@ function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) {
|
|||
* @param string[] $days
|
||||
* An array of available filter days
|
||||
*/
|
||||
function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $days) {
|
||||
$shiftsFilter->setUserShiftsAdmin($user_shifts_admin);
|
||||
$shiftsFilter->setFilled(check_request_int_array('filled', $shiftsFilter->getFilled()));
|
||||
$shiftsFilter->setRooms(check_request_int_array('rooms', $shiftsFilter->getRooms()));
|
||||
$shiftsFilter->setTypes(check_request_int_array('types', $shiftsFilter->getTypes()));
|
||||
update_ShiftsFilter_timerange($shiftsFilter, $days);
|
||||
function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $days)
|
||||
{
|
||||
$shiftsFilter->setUserShiftsAdmin($user_shifts_admin);
|
||||
$shiftsFilter->setFilled(check_request_int_array('filled', $shiftsFilter->getFilled()));
|
||||
$shiftsFilter->setRooms(check_request_int_array('rooms', $shiftsFilter->getRooms()));
|
||||
$shiftsFilter->setTypes(check_request_int_array('types', $shiftsFilter->getTypes()));
|
||||
update_ShiftsFilter_timerange($shiftsFilter, $days);
|
||||
}
|
||||
|
||||
function load_rooms() {
|
||||
$rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
||||
if (count($rooms) == 0) {
|
||||
error(_("The administration has not configured any rooms yet."));
|
||||
redirect('?');
|
||||
}
|
||||
return $rooms;
|
||||
function load_rooms()
|
||||
{
|
||||
$rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
||||
if (count($rooms) == 0) {
|
||||
error(_("The administration has not configured any rooms yet."));
|
||||
redirect('?');
|
||||
}
|
||||
return $rooms;
|
||||
}
|
||||
|
||||
function load_days() {
|
||||
$days = sql_select_single_col("
|
||||
function load_days()
|
||||
{
|
||||
$days = sql_select_single_col("
|
||||
SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) AS `id`, DATE(FROM_UNIXTIME(`start`)) AS `name`
|
||||
FROM `Shifts`
|
||||
ORDER BY `start`");
|
||||
if (count($days) == 0) {
|
||||
error(_("The administration has not configured any shifts yet."));
|
||||
redirect('?');
|
||||
}
|
||||
return $days;
|
||||
if (count($days) == 0) {
|
||||
error(_("The administration has not configured any shifts yet."));
|
||||
redirect('?');
|
||||
}
|
||||
return $days;
|
||||
}
|
||||
|
||||
function load_types() {
|
||||
global $user;
|
||||
function load_types()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (sql_num_query("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0") == 0) {
|
||||
error(_("The administration has not configured any angeltypes yet - or you are not subscribed to any angeltype."));
|
||||
redirect('?');
|
||||
}
|
||||
$types = sql_select("SELECT `AngelTypes`.`id`, `AngelTypes`.`name`, (`AngelTypes`.`restricted`=0 OR (NOT `UserAngelTypes`.`confirm_user_id` IS NULL OR `UserAngelTypes`.`id` IS NULL)) as `enabled` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "') ORDER BY `AngelTypes`.`name`");
|
||||
if (empty($types)) {
|
||||
return sql_select("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0");
|
||||
}
|
||||
return $types;
|
||||
if (sql_num_query("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0") == 0) {
|
||||
error(_("The administration has not configured any angeltypes yet - or you are not subscribed to any angeltype."));
|
||||
redirect('?');
|
||||
}
|
||||
$types = sql_select("SELECT `AngelTypes`.`id`, `AngelTypes`.`name`, (`AngelTypes`.`restricted`=0 OR (NOT `UserAngelTypes`.`confirm_user_id` IS NULL OR `UserAngelTypes`.`id` IS NULL)) as `enabled` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "') ORDER BY `AngelTypes`.`name`");
|
||||
if (empty($types)) {
|
||||
return sql_select("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0");
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
function view_user_shifts() {
|
||||
global $user, $privileges;
|
||||
global $ical_shifts;
|
||||
function view_user_shifts()
|
||||
{
|
||||
global $user, $privileges;
|
||||
global $ical_shifts;
|
||||
|
||||
$ical_shifts = [];
|
||||
$days = load_days();
|
||||
$rooms = load_rooms();
|
||||
$types = load_types();
|
||||
$ical_shifts = [];
|
||||
$days = load_days();
|
||||
$rooms = load_rooms();
|
||||
$types = load_types();
|
||||
|
||||
if (! isset($_SESSION['ShiftsFilter'])) {
|
||||
$room_ids = [
|
||||
if (! isset($_SESSION['ShiftsFilter'])) {
|
||||
$room_ids = [
|
||||
$rooms[0]['id']
|
||||
];
|
||||
$type_ids = array_map('get_ids_from_array', $types);
|
||||
$_SESSION['ShiftsFilter'] = new ShiftsFilter(in_array('user_shifts_admin', $privileges), $room_ids, $type_ids);
|
||||
}
|
||||
update_ShiftsFilter($_SESSION['ShiftsFilter'], in_array('user_shifts_admin', $privileges), $days);
|
||||
$shiftsFilter = $_SESSION['ShiftsFilter'];
|
||||
$type_ids = array_map('get_ids_from_array', $types);
|
||||
$_SESSION['ShiftsFilter'] = new ShiftsFilter(in_array('user_shifts_admin', $privileges), $room_ids, $type_ids);
|
||||
}
|
||||
update_ShiftsFilter($_SESSION['ShiftsFilter'], in_array('user_shifts_admin', $privileges), $days);
|
||||
$shiftsFilter = $_SESSION['ShiftsFilter'];
|
||||
|
||||
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
|
||||
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
|
||||
|
||||
if ($user['api_key'] == "") {
|
||||
User_reset_api_key($user, false);
|
||||
}
|
||||
if ($user['api_key'] == "") {
|
||||
User_reset_api_key($user, false);
|
||||
}
|
||||
|
||||
$filled = [
|
||||
$filled = [
|
||||
[
|
||||
'id' => '1',
|
||||
'name' => _("occupied")
|
||||
|
@ -146,12 +154,12 @@ function view_user_shifts() {
|
|||
'name' => _("free")
|
||||
]
|
||||
];
|
||||
$start_day = date("Y-m-d", $shiftsFilter->getStartTime());
|
||||
$start_time = date("H:i", $shiftsFilter->getStartTime());
|
||||
$end_day = date("Y-m-d", $shiftsFilter->getEndTime());
|
||||
$end_time = date("H:i", $shiftsFilter->getEndTime());
|
||||
$start_day = date("Y-m-d", $shiftsFilter->getStartTime());
|
||||
$start_time = date("H:i", $shiftsFilter->getStartTime());
|
||||
$end_day = date("Y-m-d", $shiftsFilter->getEndTime());
|
||||
$end_time = date("H:i", $shiftsFilter->getEndTime());
|
||||
|
||||
return page([
|
||||
return page([
|
||||
div('col-md-12', [
|
||||
msg(),
|
||||
template_render(__DIR__ . '/../../templates/user_shifts.html', [
|
||||
|
@ -172,26 +180,27 @@ function view_user_shifts() {
|
|||
]);
|
||||
}
|
||||
|
||||
function get_ids_from_array($array) {
|
||||
return $array["id"];
|
||||
function get_ids_from_array($array)
|
||||
{
|
||||
return $array["id"];
|
||||
}
|
||||
|
||||
function make_select($items, $selected, $name, $title = null) {
|
||||
$html_items = [];
|
||||
if (isset($title)) {
|
||||
$html_items[] = '<h4>' . $title . '</h4>' . "\n";
|
||||
}
|
||||
function make_select($items, $selected, $name, $title = null)
|
||||
{
|
||||
$html_items = [];
|
||||
if (isset($title)) {
|
||||
$html_items[] = '<h4>' . $title . '</h4>' . "\n";
|
||||
}
|
||||
|
||||
foreach ($items as $i) {
|
||||
$html_items[] = '<div class="checkbox"><label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '"' . (in_array($i['id'], $selected) ? ' checked="checked"' : '') . '> ' . $i['name'] . '</label>' . (! isset($i['enabled']) || $i['enabled'] ? '' : glyph("lock")) . '</div><br />';
|
||||
}
|
||||
$html = '<div id="selection_' . $name . '" class="selection ' . $name . '">' . "\n";
|
||||
$html .= implode("\n", $html_items);
|
||||
$html .= buttons([
|
||||
foreach ($items as $i) {
|
||||
$html_items[] = '<div class="checkbox"><label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '"' . (in_array($i['id'], $selected) ? ' checked="checked"' : '') . '> ' . $i['name'] . '</label>' . (! isset($i['enabled']) || $i['enabled'] ? '' : glyph("lock")) . '</div><br />';
|
||||
}
|
||||
$html = '<div id="selection_' . $name . '" class="selection ' . $name . '">' . "\n";
|
||||
$html .= implode("\n", $html_items);
|
||||
$html .= buttons([
|
||||
button("javascript: checkAll('selection_" . $name . "', true)", _("All"), ""),
|
||||
button("javascript: checkAll('selection_" . $name . "', false)", _("None"), "")
|
||||
]);
|
||||
$html .= '</div>' . "\n";
|
||||
return $html;
|
||||
$html .= '</div>' . "\n";
|
||||
return $html;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,21 +3,22 @@
|
|||
/**
|
||||
* Testet ob ein User eingeloggt ist und lädt die entsprechenden Privilegien
|
||||
*/
|
||||
function load_auth() {
|
||||
global $user, $privileges;
|
||||
function load_auth()
|
||||
{
|
||||
global $user, $privileges;
|
||||
|
||||
$user = null;
|
||||
if (isset($_SESSION['uid'])) {
|
||||
$user = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($_SESSION['uid']) . "' LIMIT 1");
|
||||
if (count($user) > 0) {
|
||||
// User ist eingeloggt, Datensatz zur Verfügung stellen und Timestamp updaten
|
||||
$user = null;
|
||||
if (isset($_SESSION['uid'])) {
|
||||
$user = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($_SESSION['uid']) . "' LIMIT 1");
|
||||
if (count($user) > 0) {
|
||||
// User ist eingeloggt, Datensatz zur Verfügung stellen und Timestamp updaten
|
||||
list($user) = $user;
|
||||
sql_query("UPDATE `User` SET " . "`lastLogIn` = '" . time() . "'" . " WHERE `UID` = '" . sql_escape($_SESSION['uid']) . "' LIMIT 1;");
|
||||
$privileges = privileges_for_user($user['UID']);
|
||||
return;
|
||||
sql_query("UPDATE `User` SET " . "`lastLogIn` = '" . time() . "'" . " WHERE `UID` = '" . sql_escape($_SESSION['uid']) . "' LIMIT 1;");
|
||||
$privileges = privileges_for_user($user['UID']);
|
||||
return;
|
||||
}
|
||||
unset($_SESSION['uid']);
|
||||
}
|
||||
unset($_SESSION['uid']);
|
||||
}
|
||||
|
||||
// guest privileges
|
||||
$privileges = privileges_for_group(- 1);
|
||||
|
@ -26,66 +27,70 @@ function load_auth() {
|
|||
/**
|
||||
* generate a salt (random string) of arbitrary length suitable for the use with crypt()
|
||||
*/
|
||||
function generate_salt($length = 16) {
|
||||
$alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
$salt = "";
|
||||
for ($i = 0; $i < $length; $i ++) {
|
||||
$salt .= $alphabet[rand(0, strlen($alphabet) - 1)];
|
||||
}
|
||||
return $salt;
|
||||
function generate_salt($length = 16)
|
||||
{
|
||||
$alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
$salt = "";
|
||||
for ($i = 0; $i < $length; $i ++) {
|
||||
$salt .= $alphabet[rand(0, strlen($alphabet) - 1)];
|
||||
}
|
||||
return $salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the password of a user
|
||||
*/
|
||||
function set_password($uid, $password) {
|
||||
global $crypt_alg;
|
||||
$result = sql_query("UPDATE `User` SET `Passwort` = '" . sql_escape(crypt($password, $crypt_alg . '$' . generate_salt(16) . '$')) . "', `password_recovery_token`=NULL WHERE `UID` = " . intval($uid) . " LIMIT 1");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update password.');
|
||||
}
|
||||
return $result;
|
||||
function set_password($uid, $password)
|
||||
{
|
||||
global $crypt_alg;
|
||||
$result = sql_query("UPDATE `User` SET `Passwort` = '" . sql_escape(crypt($password, $crypt_alg . '$' . generate_salt(16) . '$')) . "', `password_recovery_token`=NULL WHERE `UID` = " . intval($uid) . " LIMIT 1");
|
||||
if ($result === false) {
|
||||
engelsystem_error('Unable to update password.');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* verify a password given a precomputed salt.
|
||||
* if $uid is given and $salt is an old-style salt (plain md5), we convert it automatically
|
||||
*/
|
||||
function verify_password($password, $salt, $uid = false) {
|
||||
global $crypt_alg;
|
||||
$correct = false;
|
||||
if (substr($salt, 0, 1) == '$') { // new-style crypt()
|
||||
function verify_password($password, $salt, $uid = false)
|
||||
{
|
||||
global $crypt_alg;
|
||||
$correct = false;
|
||||
if (substr($salt, 0, 1) == '$') { // new-style crypt()
|
||||
$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;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
if ($correct && substr($salt, 0, strlen($crypt_alg)) != $crypt_alg && $uid) {
|
||||
// this password is stored in another format than we want it to be.
|
||||
if ($correct && substr($salt, 0, strlen($crypt_alg)) != $crypt_alg && $uid) {
|
||||
// this password is stored in another format than we want it to be.
|
||||
// let's update it!
|
||||
// we duplicate the query from the above set_password() function to have the extra safety of checking the old hash
|
||||
sql_query("UPDATE `User` SET `Passwort` = '" . sql_escape(crypt($password, $crypt_alg . '$' . generate_salt() . '$')) . "' WHERE `UID` = " . intval($uid) . " AND `Passwort` = '" . sql_escape($salt) . "' LIMIT 1");
|
||||
}
|
||||
return $correct;
|
||||
}
|
||||
return $correct;
|
||||
}
|
||||
|
||||
function privileges_for_user($user_id) {
|
||||
$privileges = [];
|
||||
$user_privs = sql_select("SELECT `Privileges`.`name` FROM `User` JOIN `UserGroups` ON (`User`.`UID` = `UserGroups`.`uid`) JOIN `GroupPrivileges` ON (`UserGroups`.`group_id` = `GroupPrivileges`.`group_id`) JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) WHERE `User`.`UID`='" . sql_escape($user_id) . "'");
|
||||
foreach ($user_privs as $user_priv) {
|
||||
$privileges[] = $user_priv['name'];
|
||||
}
|
||||
return $privileges;
|
||||
function privileges_for_user($user_id)
|
||||
{
|
||||
$privileges = [];
|
||||
$user_privs = sql_select("SELECT `Privileges`.`name` FROM `User` JOIN `UserGroups` ON (`User`.`UID` = `UserGroups`.`uid`) JOIN `GroupPrivileges` ON (`UserGroups`.`group_id` = `GroupPrivileges`.`group_id`) JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) WHERE `User`.`UID`='" . sql_escape($user_id) . "'");
|
||||
foreach ($user_privs as $user_priv) {
|
||||
$privileges[] = $user_priv['name'];
|
||||
}
|
||||
return $privileges;
|
||||
}
|
||||
|
||||
function privileges_for_group($group_id) {
|
||||
$privileges = [];
|
||||
$groups_privs = sql_select("SELECT * FROM `GroupPrivileges` JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) WHERE `group_id`='" . sql_escape($group_id) . "'");
|
||||
foreach ($groups_privs as $guest_priv) {
|
||||
$privileges[] = $guest_priv['name'];
|
||||
}
|
||||
return $privileges;
|
||||
function privileges_for_group($group_id)
|
||||
{
|
||||
$privileges = [];
|
||||
$groups_privs = sql_select("SELECT * FROM `GroupPrivileges` JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) WHERE `group_id`='" . sql_escape($group_id) . "'");
|
||||
foreach ($groups_privs as $guest_priv) {
|
||||
$privileges[] = $guest_priv['name'];
|
||||
}
|
||||
return $privileges;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -10,15 +10,17 @@
|
|||
* The value
|
||||
* @return string rendered html
|
||||
*/
|
||||
function form_hidden($name, $value) {
|
||||
return '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
|
||||
function form_hidden($name, $value)
|
||||
{
|
||||
return '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Zahlenfeld mit Buttons zum verstellen
|
||||
*/
|
||||
function form_spinner($name, $label, $value) {
|
||||
return form_element($label, '
|
||||
function form_spinner($name, $label, $value)
|
||||
{
|
||||
return form_element($label, '
|
||||
<div class="input-group">
|
||||
<input id="spinner-' . $name . '" class="form-control" type="text" name="' . $name . '" value="' . $value . '" />
|
||||
<div class="input-group-btn">
|
||||
|
@ -54,12 +56,13 @@ function form_spinner($name, $label, $value) {
|
|||
* Earliest possible date
|
||||
* @return HTML
|
||||
*/
|
||||
function form_date($name, $label, $value, $start_date = '', $end_date = '') {
|
||||
$dom_id = $name . '-date';
|
||||
$value = is_numeric($value) ? date('Y-m-d', $value) : '';
|
||||
$start_date = is_numeric($start_date) ? date('Y-m-d', $start_date) : '';
|
||||
$end_date = is_numeric($end_date) ? date('Y-m-d', $end_date) : '';
|
||||
return form_element($label, '
|
||||
function form_date($name, $label, $value, $start_date = '', $end_date = '')
|
||||
{
|
||||
$dom_id = $name . '-date';
|
||||
$value = is_numeric($value) ? date('Y-m-d', $value) : '';
|
||||
$start_date = is_numeric($start_date) ? date('Y-m-d', $start_date) : '';
|
||||
$end_date = is_numeric($end_date) ? date('Y-m-d', $end_date) : '';
|
||||
return form_element($label, '
|
||||
<div class="input-group date" id="' . $dom_id . '">
|
||||
<input type="text" name="' . $name . '" class="form-control" value="' . $value . '"><span class="input-group-addon">' . glyph('th') . '</span>
|
||||
</div>
|
||||
|
@ -89,12 +92,13 @@ function form_date($name, $label, $value, $start_date = '', $end_date = '') {
|
|||
* @param
|
||||
* selected Array mit den Keys, die ausgewählt sind
|
||||
*/
|
||||
function form_checkboxes($name, $label, $items, $selected) {
|
||||
$html = form_element($label, '');
|
||||
foreach ($items as $key => $item) {
|
||||
$html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false);
|
||||
}
|
||||
return $html;
|
||||
function form_checkboxes($name, $label, $items, $selected)
|
||||
{
|
||||
$html = form_element($label, '');
|
||||
foreach ($items as $key => $item) {
|
||||
$html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,68 +115,74 @@ function form_checkboxes($name, $label, $items, $selected) {
|
|||
* @param
|
||||
* disabled Wie selected, nur dass die entsprechenden Checkboxen deaktiviert statt markiert sind
|
||||
*/
|
||||
function form_multi_checkboxes($names, $label, $items, $selected, $disabled = []) {
|
||||
$html = "<table><thead><tr>";
|
||||
foreach ($names as $title) {
|
||||
$html .= "<th>$title</th>";
|
||||
}
|
||||
$html .= "</tr></thead><tbody>";
|
||||
foreach ($items as $key => $item) {
|
||||
$html .= "<tr>";
|
||||
foreach ($names as $name => $title) {
|
||||
$dom_id = $name . '_' . $key;
|
||||
$sel = array_search($key, $selected[$name]) !== false ? ' checked="checked"' : "";
|
||||
if (! empty($disabled) && ! empty($disabled[$name]) && array_search($key, $disabled[$name]) !== false) {
|
||||
$sel .= ' disabled="disabled"';
|
||||
}
|
||||
$html .= '<td style="text-align: center;"><input type="checkbox" id="' . $dom_id . '" name="' . $name . '[]" value="' . $key . '"' . $sel . ' /></td>';
|
||||
function form_multi_checkboxes($names, $label, $items, $selected, $disabled = [])
|
||||
{
|
||||
$html = "<table><thead><tr>";
|
||||
foreach ($names as $title) {
|
||||
$html .= "<th>$title</th>";
|
||||
}
|
||||
$html .= '<td><label for="' . $dom_id . '">' . $item . '</label></td></tr>';
|
||||
}
|
||||
$html .= "</tbody></table>";
|
||||
return form_element($label, $html);
|
||||
$html .= "</tr></thead><tbody>";
|
||||
foreach ($items as $key => $item) {
|
||||
$html .= "<tr>";
|
||||
foreach ($names as $name => $title) {
|
||||
$dom_id = $name . '_' . $key;
|
||||
$sel = array_search($key, $selected[$name]) !== false ? ' checked="checked"' : "";
|
||||
if (! empty($disabled) && ! empty($disabled[$name]) && array_search($key, $disabled[$name]) !== false) {
|
||||
$sel .= ' disabled="disabled"';
|
||||
}
|
||||
$html .= '<td style="text-align: center;"><input type="checkbox" id="' . $dom_id . '" name="' . $name . '[]" value="' . $key . '"' . $sel . ' /></td>';
|
||||
}
|
||||
$html .= '<td><label for="' . $dom_id . '">' . $item . '</label></td></tr>';
|
||||
}
|
||||
$html .= "</tbody></table>";
|
||||
return form_element($label, $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert eine Checkbox
|
||||
*/
|
||||
function form_checkbox($name, $label, $selected, $value = 'checked') {
|
||||
return '<div class="checkbox"><label><input type="checkbox" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
|
||||
function form_checkbox($name, $label, $selected, $value = 'checked')
|
||||
{
|
||||
return '<div class="checkbox"><label><input type="checkbox" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert einen Radio
|
||||
*/
|
||||
function form_radio($name, $label, $selected, $value) {
|
||||
return '<div class="radio"><label><input type="radio" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
|
||||
function form_radio($name, $label, $selected, $value)
|
||||
{
|
||||
return '<div class="radio"><label><input type="radio" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert einen Infotext in das Formular
|
||||
*/
|
||||
function form_info($label, $text = "") {
|
||||
if ($label == "") {
|
||||
return '<span class="help-block">' . glyph('info-sign') . $text . '</span>';
|
||||
}
|
||||
if ($text == "") {
|
||||
return '<h4>' . $label . '</h4>';
|
||||
}
|
||||
return form_element($label, '<p class="form-control-static">' . $text . '</p>', '');
|
||||
function form_info($label, $text = "")
|
||||
{
|
||||
if ($label == "") {
|
||||
return '<span class="help-block">' . glyph('info-sign') . $text . '</span>';
|
||||
}
|
||||
if ($text == "") {
|
||||
return '<h4>' . $label . '</h4>';
|
||||
}
|
||||
return form_element($label, '<p class="form-control-static">' . $text . '</p>', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert den Absenden-Button eines Formulars
|
||||
*/
|
||||
function form_submit($name, $label) {
|
||||
return form_element('<input class="btn btn-primary" type="submit" name="' . $name . '" value="' . $label . '" />', "");
|
||||
function form_submit($name, $label)
|
||||
{
|
||||
return form_element('<input class="btn btn-primary" type="submit" name="' . $name . '" value="' . $label . '" />', "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Formular-Textfeld
|
||||
*/
|
||||
function form_text($name, $label, $value, $disabled = false) {
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element($label, '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
|
||||
function form_text($name, $label, $value, $disabled = false)
|
||||
{
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element($label, '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,95 +197,104 @@ function form_text($name, $label, $value, $disabled = false) {
|
|||
* @param Boolean $disabled
|
||||
* Is the field enabled?
|
||||
*/
|
||||
function form_text_placeholder($name, $placeholder, $value, $disabled = false) {
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element('', '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" placeholder="' . $placeholder . '" ' . $disabled . '/>');
|
||||
function form_text_placeholder($name, $placeholder, $value, $disabled = false)
|
||||
{
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element('', '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" placeholder="' . $placeholder . '" ' . $disabled . '/>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Formular-Emailfeld
|
||||
*/
|
||||
function form_email($name, $label, $value, $disabled = false) {
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element($label, '<input class="form-control" id="form_' . $name . '" type="email" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
|
||||
function form_email($name, $label, $value, $disabled = false)
|
||||
{
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element($label, '<input class="form-control" id="form_' . $name . '" type="email" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Formular-Dateifeld
|
||||
*/
|
||||
function form_file($name, $label) {
|
||||
return form_element($label, '<input id="form_' . $name . '" type="file" name="' . $name . '" />', 'form_' . $name);
|
||||
function form_file($name, $label)
|
||||
{
|
||||
return form_element($label, '<input id="form_' . $name . '" type="file" name="' . $name . '" />', 'form_' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Formular-Passwortfeld
|
||||
*/
|
||||
function form_password($name, $label, $disabled = false) {
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element($label, '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" ' . $disabled . '/>', 'form_' . $name);
|
||||
function form_password($name, $label, $disabled = false)
|
||||
{
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element($label, '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" ' . $disabled . '/>', 'form_' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a password input with placeholder instead of label.
|
||||
*/
|
||||
function form_password_placeholder($name, $placeholder, $disabled = false) {
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element('', '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" placeholder="' . $placeholder . '" ' . $disabled . '/>', 'form_' . $name);
|
||||
function form_password_placeholder($name, $placeholder, $disabled = false)
|
||||
{
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element('', '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" placeholder="' . $placeholder . '" ' . $disabled . '/>', 'form_' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Formular-Textfeld
|
||||
*/
|
||||
function form_textarea($name, $label, $value, $disabled = false) {
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element($label, '<textarea rows="5" class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" ' . $disabled . '>' . $value . '</textarea>', 'form_' . $name);
|
||||
function form_textarea($name, $label, $value, $disabled = false)
|
||||
{
|
||||
$disabled = $disabled ? ' disabled="disabled"' : '';
|
||||
return form_element($label, '<textarea rows="5" class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" ' . $disabled . '>' . $value . '</textarea>', 'form_' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Formular-Auswahlfeld
|
||||
*/
|
||||
function form_select($name, $label, $values, $selected) {
|
||||
return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name);
|
||||
function form_select($name, $label, $values, $selected)
|
||||
{
|
||||
return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Formular-Element
|
||||
*/
|
||||
function form_element($label, $input, $for = "") {
|
||||
if ($label == '') {
|
||||
return '<div class="form-group">' . $input . '</div>';
|
||||
}
|
||||
function form_element($label, $input, $for = "")
|
||||
{
|
||||
if ($label == '') {
|
||||
return '<div class="form-group">' . $input . '</div>';
|
||||
}
|
||||
|
||||
return '<div class="form-group">' . '<label for="' . $for . '">' . $label . '</label>' . $input . '</div>';
|
||||
return '<div class="form-group">' . '<label for="' . $for . '">' . $label . '</label>' . $input . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert ein Formular
|
||||
*/
|
||||
function form($elements, $action = "") {
|
||||
return '<form role="form" action="' . $action . '" enctype="multipart/form-data" method="post">' . join($elements) . '</form>';
|
||||
function form($elements, $action = "")
|
||||
{
|
||||
return '<form role="form" action="' . $action . '" enctype="multipart/form-data" method="post">' . join($elements) . '</form>';
|
||||
}
|
||||
|
||||
function html_options($name, $options, $selected = "") {
|
||||
$html = "";
|
||||
foreach ($options as $value => $label) {
|
||||
$html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function html_select_key($dom_id, $name, $rows, $selected) {
|
||||
$html = '<select class="form-control" id="' . $dom_id . '" name="' . $name . '">';
|
||||
foreach ($rows as $key => $row) {
|
||||
if (($key == $selected) || ($row == $selected)) {
|
||||
$html .= '<option value="' . $key . '" selected="selected">' . $row . '</option>';
|
||||
} else {
|
||||
$html .= '<option value="' . $key . '">' . $row . '</option>';
|
||||
function html_options($name, $options, $selected = "")
|
||||
{
|
||||
$html = "";
|
||||
foreach ($options as $value => $label) {
|
||||
$html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
|
||||
}
|
||||
}
|
||||
$html .= '</select>';
|
||||
return $html;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
?>
|
||||
function html_select_key($dom_id, $name, $rows, $selected)
|
||||
{
|
||||
$html = '<select class="form-control" id="' . $dom_id . '" name="' . $name . '">';
|
||||
foreach ($rows as $key => $row) {
|
||||
if (($key == $selected) || ($row == $selected)) {
|
||||
$html .= '<option value="' . $key . '" selected="selected">' . $row . '</option>';
|
||||
} else {
|
||||
$html .= '<option value="' . $key . '">' . $row . '</option>';
|
||||
}
|
||||
}
|
||||
$html .= '</select>';
|
||||
return $html;
|
||||
}
|
||||
|
|
|
@ -7,24 +7,26 @@
|
|||
* @param
|
||||
* $message
|
||||
*/
|
||||
function engelsystem_log($message) {
|
||||
global $user;
|
||||
function engelsystem_log($message)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$nick = "Guest";
|
||||
if (isset($user)) {
|
||||
$nick = User_Nick_render($user);
|
||||
}
|
||||
LogEntry_create($nick, $message);
|
||||
$nick = "Guest";
|
||||
if (isset($user)) {
|
||||
$nick = User_Nick_render($user);
|
||||
}
|
||||
LogEntry_create($nick, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a PHP Stacktrace.
|
||||
*/
|
||||
function debug_string_backtrace() {
|
||||
ob_start();
|
||||
debug_print_backtrace();
|
||||
$trace = ob_get_contents();
|
||||
ob_end_clean();
|
||||
function debug_string_backtrace()
|
||||
{
|
||||
ob_start();
|
||||
debug_print_backtrace();
|
||||
$trace = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// Remove first item from backtrace as it's this function which
|
||||
// is redundant.
|
||||
|
@ -35,5 +37,3 @@ function debug_string_backtrace() {
|
|||
|
||||
return $trace;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,103 +1,109 @@
|
|||
<?php
|
||||
use Engelsystem\UserHintsRenderer;
|
||||
|
||||
function page_link_to($page = "") {
|
||||
if ($page == "") {
|
||||
return '?';
|
||||
}
|
||||
return '?p=' . $page;
|
||||
function page_link_to($page = "")
|
||||
{
|
||||
if ($page == "") {
|
||||
return '?';
|
||||
}
|
||||
return '?p=' . $page;
|
||||
}
|
||||
|
||||
function page_link_to_absolute($page) {
|
||||
return (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . preg_replace("/\?.*$/", '', $_SERVER['REQUEST_URI']) . page_link_to($page);
|
||||
function page_link_to_absolute($page)
|
||||
{
|
||||
return (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . preg_replace("/\?.*$/", '', $_SERVER['REQUEST_URI']) . page_link_to($page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the user hints
|
||||
*/
|
||||
function header_render_hints() {
|
||||
global $user;
|
||||
function header_render_hints()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$hints_renderer = new UserHintsRenderer();
|
||||
$hints_renderer = new UserHintsRenderer();
|
||||
|
||||
if (isset($user)) {
|
||||
$hints_renderer->addHint(admin_new_questions());
|
||||
$hints_renderer->addHint(user_angeltypes_unconfirmed_hint());
|
||||
$hints_renderer->addHint(render_user_departure_date_hint());
|
||||
$hints_renderer->addHint(user_driver_license_required_hint());
|
||||
if (isset($user)) {
|
||||
$hints_renderer->addHint(admin_new_questions());
|
||||
$hints_renderer->addHint(user_angeltypes_unconfirmed_hint());
|
||||
$hints_renderer->addHint(render_user_departure_date_hint());
|
||||
$hints_renderer->addHint(user_driver_license_required_hint());
|
||||
|
||||
// Important hints:
|
||||
$hints_renderer->addHint(render_user_freeloader_hint(), true);
|
||||
$hints_renderer->addHint(render_user_arrived_hint(), true);
|
||||
$hints_renderer->addHint(render_user_tshirt_hint(), true);
|
||||
$hints_renderer->addHint(render_user_dect_hint(), true);
|
||||
}
|
||||
$hints_renderer->addHint(render_user_arrived_hint(), true);
|
||||
$hints_renderer->addHint(render_user_tshirt_hint(), true);
|
||||
$hints_renderer->addHint(render_user_dect_hint(), true);
|
||||
}
|
||||
|
||||
return $hints_renderer->render();
|
||||
return $hints_renderer->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the header toolbar containing search, login/logout, user and settings links.
|
||||
*/
|
||||
function header_toolbar() {
|
||||
global $page, $privileges, $user;
|
||||
function header_toolbar()
|
||||
{
|
||||
global $page, $privileges, $user;
|
||||
|
||||
$toolbar_items = [];
|
||||
$toolbar_items = [];
|
||||
|
||||
if (isset($user)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('shifts') . '&action=next', 'time', User_shift_state_render($user));
|
||||
}
|
||||
if (isset($user)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('shifts') . '&action=next', 'time', User_shift_state_render($user));
|
||||
}
|
||||
|
||||
if (! isset($user) && in_array('register', $privileges)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('register'), 'plus', register_title(), $page == 'register');
|
||||
}
|
||||
if (! isset($user) && in_array('register', $privileges)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('register'), 'plus', register_title(), $page == 'register');
|
||||
}
|
||||
|
||||
if (in_array('login', $privileges)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('login'), 'log-in', login_title(), $page == 'login');
|
||||
}
|
||||
if (in_array('login', $privileges)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('login'), 'log-in', login_title(), $page == 'login');
|
||||
}
|
||||
|
||||
if (isset($user) && in_array('user_messages', $privileges)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('user_messages'), 'envelope', user_unread_messages());
|
||||
}
|
||||
if (isset($user) && in_array('user_messages', $privileges)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('user_messages'), 'envelope', user_unread_messages());
|
||||
}
|
||||
|
||||
$toolbar_items[] = header_render_hints();
|
||||
if (in_array('user_myshifts', $privileges)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('users') . '&action=view', ' icon-icon_angel', $user['Nick'], $page == 'users');
|
||||
}
|
||||
$toolbar_items[] = header_render_hints();
|
||||
if (in_array('user_myshifts', $privileges)) {
|
||||
$toolbar_items[] = toolbar_item_link(page_link_to('users') . '&action=view', ' icon-icon_angel', $user['Nick'], $page == 'users');
|
||||
}
|
||||
|
||||
$user_submenu = make_user_submenu();
|
||||
if (count($user_submenu) > 0) {
|
||||
$toolbar_items[] = toolbar_dropdown('', '', $user_submenu);
|
||||
}
|
||||
$user_submenu = make_user_submenu();
|
||||
if (count($user_submenu) > 0) {
|
||||
$toolbar_items[] = toolbar_dropdown('', '', $user_submenu);
|
||||
}
|
||||
|
||||
return toolbar($toolbar_items, true);
|
||||
return toolbar($toolbar_items, true);
|
||||
}
|
||||
|
||||
function make_user_submenu() {
|
||||
global $privileges, $page;
|
||||
function make_user_submenu()
|
||||
{
|
||||
global $privileges, $page;
|
||||
|
||||
$user_submenu = make_langselect();
|
||||
$user_submenu = make_langselect();
|
||||
|
||||
if (in_array('user_settings', $privileges) || in_array('logout', $privileges)) {
|
||||
$user_submenu[] = toolbar_item_divider();
|
||||
}
|
||||
if (in_array('user_settings', $privileges) || in_array('logout', $privileges)) {
|
||||
$user_submenu[] = toolbar_item_divider();
|
||||
}
|
||||
|
||||
if (in_array('user_settings', $privileges)) {
|
||||
$user_submenu[] = toolbar_item_link(page_link_to('user_settings'), 'list-alt', settings_title(), $page == 'user_settings');
|
||||
}
|
||||
if (in_array('user_settings', $privileges)) {
|
||||
$user_submenu[] = toolbar_item_link(page_link_to('user_settings'), 'list-alt', settings_title(), $page == 'user_settings');
|
||||
}
|
||||
|
||||
if (in_array('logout', $privileges)) {
|
||||
$user_submenu[] = toolbar_item_link(page_link_to('logout'), 'log-out', logout_title(), $page == 'logout');
|
||||
}
|
||||
if (in_array('logout', $privileges)) {
|
||||
$user_submenu[] = toolbar_item_link(page_link_to('logout'), 'log-out', logout_title(), $page == 'logout');
|
||||
}
|
||||
|
||||
return $user_submenu;
|
||||
return $user_submenu;
|
||||
}
|
||||
|
||||
function make_navigation() {
|
||||
global $page, $privileges;
|
||||
function make_navigation()
|
||||
{
|
||||
global $page, $privileges;
|
||||
|
||||
$menu = [];
|
||||
$pages = [
|
||||
$menu = [];
|
||||
$pages = [
|
||||
"news" => news_title(),
|
||||
"user_meetings" => meetings_title(),
|
||||
"user_shifts" => shifts_title(),
|
||||
|
@ -105,16 +111,16 @@ function make_navigation() {
|
|||
"user_questions" => questions_title()
|
||||
];
|
||||
|
||||
foreach ($pages as $menu_page => $title) {
|
||||
if (in_array($menu_page, $privileges)) {
|
||||
$menu[] = toolbar_item_link(page_link_to($menu_page), '', $title, $menu_page == $page);
|
||||
foreach ($pages as $menu_page => $title) {
|
||||
if (in_array($menu_page, $privileges)) {
|
||||
$menu[] = toolbar_item_link(page_link_to($menu_page), '', $title, $menu_page == $page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$menu = make_room_navigation($menu);
|
||||
$menu = make_room_navigation($menu);
|
||||
|
||||
$admin_menu = [];
|
||||
$admin_pages = [
|
||||
$admin_menu = [];
|
||||
$admin_pages = [
|
||||
"admin_arrive" => admin_arrive_title(),
|
||||
"admin_active" => admin_active_title(),
|
||||
"admin_user" => admin_user_title(),
|
||||
|
@ -129,17 +135,17 @@ function make_navigation() {
|
|||
"admin_event_config" => event_config_title()
|
||||
];
|
||||
|
||||
foreach ($admin_pages as $menu_page => $title) {
|
||||
if (in_array($menu_page, $privileges)) {
|
||||
$admin_menu[] = toolbar_item_link(page_link_to($menu_page), '', $title, $menu_page == $page);
|
||||
foreach ($admin_pages as $menu_page => $title) {
|
||||
if (in_array($menu_page, $privileges)) {
|
||||
$admin_menu[] = toolbar_item_link(page_link_to($menu_page), '', $title, $menu_page == $page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($admin_menu) > 0) {
|
||||
$menu[] = toolbar_dropdown('', _("Admin"), $admin_menu);
|
||||
}
|
||||
if (count($admin_menu) > 0) {
|
||||
$menu[] = toolbar_dropdown('', _("Admin"), $admin_menu);
|
||||
}
|
||||
|
||||
return toolbar($menu);
|
||||
return toolbar($menu);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,32 +154,32 @@ function make_navigation() {
|
|||
* @param string[] $menu
|
||||
* Rendered menu
|
||||
*/
|
||||
function make_room_navigation($menu) {
|
||||
global $privileges;
|
||||
function make_room_navigation($menu)
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
if (! in_array('view_rooms', $privileges)) {
|
||||
if (! in_array('view_rooms', $privileges)) {
|
||||
return $menu;
|
||||
}
|
||||
|
||||
$rooms = Rooms();
|
||||
$room_menu = [];
|
||||
if (in_array('admin_rooms', $privileges)) {
|
||||
$room_menu[] = toolbar_item_link(page_link_to('admin_rooms'), 'list', _("Manage rooms"));
|
||||
}
|
||||
if (count($room_menu) > 0) {
|
||||
$room_menu[] = toolbar_item_divider();
|
||||
}
|
||||
foreach ($rooms as $room) {
|
||||
$room_menu[] = toolbar_item_link(room_link($room), 'map-marker', $room['Name']);
|
||||
}
|
||||
if (count($room_menu > 0)) {
|
||||
$menu[] = toolbar_dropdown('map-marker', _("Rooms"), $room_menu);
|
||||
}
|
||||
return $menu;
|
||||
}
|
||||
|
||||
$rooms = Rooms();
|
||||
$room_menu = [];
|
||||
if (in_array('admin_rooms', $privileges)) {
|
||||
$room_menu[] = toolbar_item_link(page_link_to('admin_rooms'), 'list', _("Manage rooms"));
|
||||
}
|
||||
if (count($room_menu) > 0) {
|
||||
$room_menu[] = toolbar_item_divider();
|
||||
}
|
||||
foreach ($rooms as $room) {
|
||||
$room_menu[] = toolbar_item_link(room_link($room), 'map-marker', $room['Name']);
|
||||
}
|
||||
if (count($room_menu > 0)) {
|
||||
$menu[] = toolbar_dropdown('map-marker', _("Rooms"), $room_menu);
|
||||
}
|
||||
return $menu;
|
||||
}
|
||||
|
||||
function make_menu() {
|
||||
return make_navigation();
|
||||
function make_menu()
|
||||
{
|
||||
return make_navigation();
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -17,18 +17,19 @@ use Engelsystem\ValidationResult;
|
|||
* @param int $default_value
|
||||
* Default value unix timestamp
|
||||
*/
|
||||
function check_request_datetime($date_name, $time_name, $allowed_days, $default_value) {
|
||||
$time = date("H:i", $default_value);
|
||||
$day = date("Y-m-d", $default_value);
|
||||
function check_request_datetime($date_name, $time_name, $allowed_days, $default_value)
|
||||
{
|
||||
$time = date("H:i", $default_value);
|
||||
$day = date("Y-m-d", $default_value);
|
||||
|
||||
if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) {
|
||||
$time = trim($_REQUEST[$time_name]);
|
||||
}
|
||||
if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) {
|
||||
$day = $_REQUEST[$date_name];
|
||||
}
|
||||
if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) {
|
||||
$time = trim($_REQUEST[$time_name]);
|
||||
}
|
||||
if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) {
|
||||
$day = $_REQUEST[$date_name];
|
||||
}
|
||||
|
||||
return parse_date("Y-m-d H:i", $day . " " . $time);
|
||||
return parse_date("Y-m-d H:i", $day . " " . $time);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,20 +41,22 @@ function check_request_datetime($date_name, $time_name, $allowed_days, $default_
|
|||
* The string to parse
|
||||
* @return The parsed unix timestamp
|
||||
*/
|
||||
function parse_date($pattern, $value) {
|
||||
$datetime = DateTime::createFromFormat($pattern, trim($value));
|
||||
if ($datetime == null) {
|
||||
return null;
|
||||
}
|
||||
return $datetime->getTimestamp();
|
||||
function parse_date($pattern, $value)
|
||||
{
|
||||
$datetime = DateTime::createFromFormat($pattern, trim($value));
|
||||
if ($datetime == null) {
|
||||
return null;
|
||||
}
|
||||
return $datetime->getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Leitet den Browser an die übergebene URL weiter und hält das Script an.
|
||||
*/
|
||||
function redirect($url) {
|
||||
header("Location: " . $url, true, 302);
|
||||
raw_output("");
|
||||
function redirect($url)
|
||||
{
|
||||
header("Location: " . $url, true, 302);
|
||||
raw_output("");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,9 +65,10 @@ function redirect($url) {
|
|||
* @param String $output
|
||||
* String to display
|
||||
*/
|
||||
function raw_output($output) {
|
||||
echo $output;
|
||||
die();
|
||||
function raw_output($output)
|
||||
{
|
||||
echo $output;
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,12 +81,13 @@ function raw_output($output) {
|
|||
* @param string $value_name
|
||||
* name of the column to use as displayed value
|
||||
*/
|
||||
function select_array($data, $key_name, $value_name) {
|
||||
$ret = [];
|
||||
foreach ($data as $value) {
|
||||
$ret[$value[$key_name]] = $value[$value_name];
|
||||
}
|
||||
return $ret;
|
||||
function select_array($data, $key_name, $value_name)
|
||||
{
|
||||
$ret = [];
|
||||
foreach ($data as $value) {
|
||||
$ret[$value[$key_name]] = $value[$value_name];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,11 +98,12 @@ function select_array($data, $key_name, $value_name) {
|
|||
* @param array<int> $default
|
||||
* Default return value, if param is not set
|
||||
*/
|
||||
function check_request_int_array($name, $default = []) {
|
||||
if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) {
|
||||
return array_filter($_REQUEST[$name], 'is_numeric');
|
||||
}
|
||||
return $default;
|
||||
function check_request_int_array($name, $default = [])
|
||||
{
|
||||
if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) {
|
||||
return array_filter($_REQUEST[$name], 'is_numeric');
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,11 +118,12 @@ function check_request_int_array($name, $default = []) {
|
|||
* is a null value allowed?
|
||||
* @return ValidationResult containing the parsed date
|
||||
*/
|
||||
function check_request_date($name, $error_message = null, $null_allowed = false) {
|
||||
if (! isset($_REQUEST[$name])) {
|
||||
return new ValidationResult($null_allowed, null);
|
||||
}
|
||||
return check_date($_REQUEST[$name], $error_message, $null_allowed);
|
||||
function check_request_date($name, $error_message = null, $null_allowed = false)
|
||||
{
|
||||
if (! isset($_REQUEST[$name])) {
|
||||
return new ValidationResult($null_allowed, null);
|
||||
}
|
||||
return check_date($_REQUEST[$name], $error_message, $null_allowed);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,61 +138,65 @@ function check_request_date($name, $error_message = null, $null_allowed = false)
|
|||
* is a null value allowed?
|
||||
* @return ValidationResult containing the parsed date
|
||||
*/
|
||||
function check_date($input, $error_message = null, $null_allowed = false) {
|
||||
if ($tmp = parse_date("Y-m-d H:i", trim($input) . " 00:00")) {
|
||||
return new ValidationResult(true, $tmp);
|
||||
}
|
||||
if ($null_allowed) {
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
function check_date($input, $error_message = null, $null_allowed = false)
|
||||
{
|
||||
if ($tmp = parse_date("Y-m-d H:i", trim($input) . " 00:00")) {
|
||||
return new ValidationResult(true, $tmp);
|
||||
}
|
||||
if ($null_allowed) {
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
|
||||
error($error_message);
|
||||
return new ValidationResult(false, null);
|
||||
error($error_message);
|
||||
return new ValidationResult(false, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns REQUEST value filtered or default value (null) if not set.
|
||||
*/
|
||||
function strip_request_item($name, $default_value = null) {
|
||||
if (isset($_REQUEST[$name])) {
|
||||
return strip_item($_REQUEST[$name]);
|
||||
}
|
||||
return $default_value;
|
||||
function strip_request_item($name, $default_value = null)
|
||||
{
|
||||
if (isset($_REQUEST[$name])) {
|
||||
return strip_item($_REQUEST[$name]);
|
||||
}
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet, ob der angegebene REQUEST Wert ein Integer ist, bzw.
|
||||
* eine ID sein könnte.
|
||||
*/
|
||||
function test_request_int($name) {
|
||||
if (isset($_REQUEST[$name])) {
|
||||
return preg_match("/^[0-9]*$/", $_REQUEST[$name]);
|
||||
}
|
||||
return false;
|
||||
function test_request_int($name)
|
||||
{
|
||||
if (isset($_REQUEST[$name])) {
|
||||
return preg_match("/^[0-9]*$/", $_REQUEST[$name]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den gefilterten REQUEST Wert mit Zeilenumbrüchen zurück
|
||||
*/
|
||||
function strip_request_item_nl($name, $default_value = null) {
|
||||
if (isset($_REQUEST[$name])) {
|
||||
return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($_REQUEST[$name]));
|
||||
}
|
||||
return $default_value;
|
||||
function strip_request_item_nl($name, $default_value = null)
|
||||
{
|
||||
if (isset($_REQUEST[$name])) {
|
||||
return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($_REQUEST[$name]));
|
||||
}
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entfernt unerwünschte Zeichen
|
||||
*/
|
||||
function strip_item($item) {
|
||||
return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]{1,})/ui", '', strip_tags($item));
|
||||
function strip_item($item)
|
||||
{
|
||||
return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]{1,})/ui", '', strip_tags($item));
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft eine E-Mail-Adresse.
|
||||
*/
|
||||
function check_email($email) {
|
||||
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
function check_email($email)
|
||||
{
|
||||
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -16,8 +16,9 @@ $themes = [
|
|||
*
|
||||
* @param string $text
|
||||
*/
|
||||
function mute($text) {
|
||||
return '<span class="text-muted">' . $text . '</span>';
|
||||
function mute($text)
|
||||
{
|
||||
return '<span class="text-muted">' . $text . '</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,12 +29,14 @@ function mute($text) {
|
|||
* @param string $class
|
||||
* default, primary, info, success, warning, danger
|
||||
*/
|
||||
function label($content, $class = 'default') {
|
||||
return '<span class="label label-' . $class . '">' . $content . '</span>';
|
||||
function label($content, $class = 'default')
|
||||
{
|
||||
return '<span class="label label-' . $class . '">' . $content . '</span>';
|
||||
}
|
||||
|
||||
function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '') {
|
||||
return '<div class="progress"><div class="progress-bar ' . $class . '" role="progressbar" aria-valuenow="' . $valuenow . '" aria-valuemin="' . $valuemin . '" aria-valuemax="' . $valuemax . '" style="width: ' . floor(($valuenow - $valuemin) * 100 / ($valuemax - $valuemin)) . '%">' . $content . '</div></div>';
|
||||
function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '')
|
||||
{
|
||||
return '<div class="progress"><div class="progress-bar ' . $class . '" role="progressbar" aria-valuenow="' . $valuenow . '" aria-valuemin="' . $valuemin . '" aria-valuemax="' . $valuemax . '" style="width: ' . floor(($valuenow - $valuemin) * 100 / ($valuemax - $valuemin)) . '%">' . $content . '</div></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,8 +44,9 @@ function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '
|
|||
*
|
||||
* @param string $glyph_name
|
||||
*/
|
||||
function glyph($glyph_name) {
|
||||
return ' <span class="glyphicon glyphicon-' . $glyph_name . '"></span> ';
|
||||
function glyph($glyph_name)
|
||||
{
|
||||
return ' <span class="glyphicon glyphicon-' . $glyph_name . '"></span> ';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,20 +54,23 @@ function glyph($glyph_name) {
|
|||
*
|
||||
* @param boolean $boolean
|
||||
*/
|
||||
function glyph_bool($boolean) {
|
||||
return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>';
|
||||
function glyph_bool($boolean)
|
||||
{
|
||||
return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>';
|
||||
}
|
||||
|
||||
function div($class, $content = [], $dom_id = "") {
|
||||
if (is_array($content)) {
|
||||
$content = join("\n", $content);
|
||||
}
|
||||
$dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : '';
|
||||
return '<div' . $dom_id . ' class="' . $class . '">' . $content . '</div>';
|
||||
function div($class, $content = [], $dom_id = "")
|
||||
{
|
||||
if (is_array($content)) {
|
||||
$content = join("\n", $content);
|
||||
}
|
||||
$dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : '';
|
||||
return '<div' . $dom_id . ' class="' . $class . '">' . $content . '</div>';
|
||||
}
|
||||
|
||||
function heading($content, $number = 1) {
|
||||
return "<h" . $number . ">" . $content . "</h" . $number . ">";
|
||||
function heading($content, $number = 1)
|
||||
{
|
||||
return "<h" . $number . ">" . $content . "</h" . $number . ">";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,12 +79,14 @@ function heading($content, $number = 1) {
|
|||
* @param array $items
|
||||
* @return string
|
||||
*/
|
||||
function toolbar($items = [], $right = false) {
|
||||
return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>';
|
||||
function toolbar($items = [], $right = false)
|
||||
{
|
||||
return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>';
|
||||
}
|
||||
|
||||
function toolbar_pills($items) {
|
||||
return '<ul class="nav nav-pills">' . join("\n", $items) . '</ul>';
|
||||
function toolbar_pills($items)
|
||||
{
|
||||
return '<ul class="nav nav-pills">' . join("\n", $items) . '</ul>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,23 +98,27 @@ function toolbar_pills($items) {
|
|||
* @param bool $selected
|
||||
* @return string
|
||||
*/
|
||||
function toolbar_item_link($href, $glyphicon, $label, $selected = false) {
|
||||
return '<li class="' . ($selected ? 'active' : '') . '"><a href="' . $href . '">' . ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '') . $label . '</a></li>';
|
||||
function toolbar_item_link($href, $glyphicon, $label, $selected = false)
|
||||
{
|
||||
return '<li class="' . ($selected ? 'active' : '') . '"><a href="' . $href . '">' . ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '') . $label . '</a></li>';
|
||||
}
|
||||
|
||||
function toolbar_item_divider() {
|
||||
return '<li class="divider"></li>';
|
||||
function toolbar_item_divider()
|
||||
{
|
||||
return '<li class="divider"></li>';
|
||||
}
|
||||
|
||||
function toolbar_dropdown($glyphicon, $label, $submenu, $class = '') {
|
||||
return '<li class="dropdown ' . $class . '">
|
||||
function toolbar_dropdown($glyphicon, $label, $submenu, $class = '')
|
||||
{
|
||||
return '<li class="dropdown ' . $class . '">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '') . $label . ' <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" role="menu">' . join("\n", $submenu) . '</ul></li>';
|
||||
}
|
||||
|
||||
function toolbar_popover($glyphicon, $label, $content, $class = '') {
|
||||
$dom_id = md5(microtime() . $glyphicon . $label);
|
||||
return '<li class="dropdown messages ' . $class . '">
|
||||
function toolbar_popover($glyphicon, $label, $content, $class = '')
|
||||
{
|
||||
$dom_id = md5(microtime() . $glyphicon . $label);
|
||||
return '<li class="dropdown messages ' . $class . '">
|
||||
<a id="' . $dom_id . '" href="#" tabindex="0">' . ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '') . $label . ' <span class="caret"></span></a>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
|
@ -125,154 +138,165 @@ function toolbar_popover($glyphicon, $label, $content, $class = '') {
|
|||
* Generiert HTML Code für eine "Seite".
|
||||
* Fügt dazu die übergebenen Elemente zusammen.
|
||||
*/
|
||||
function page($elements) {
|
||||
return join($elements);
|
||||
function page($elements)
|
||||
{
|
||||
return join($elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generiert HTML Code für eine "Seite" mit zentraler Überschrift
|
||||
* Fügt dazu die übergebenen Elemente zusammen.
|
||||
*/
|
||||
function page_with_title($title, $elements) {
|
||||
return '<div class="col-md-12"><h1>' . $title . '</h1>' . join($elements) . '</div>';
|
||||
function page_with_title($title, $elements)
|
||||
{
|
||||
return '<div class="col-md-12"><h1>' . $title . '</h1>' . join($elements) . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert eine Datentabelle
|
||||
*/
|
||||
function table($columns, $rows_raw, $data = true) {
|
||||
// If only one column is given
|
||||
function table($columns, $rows_raw, $data = true)
|
||||
{
|
||||
// If only one column is given
|
||||
if (! is_array($columns)) {
|
||||
$rows = [];
|
||||
foreach ($rows_raw as $row) {
|
||||
$rows[] = [
|
||||
$rows = [];
|
||||
foreach ($rows_raw as $row) {
|
||||
$rows[] = [
|
||||
'col' => $row
|
||||
];
|
||||
}
|
||||
return render_table([
|
||||
}
|
||||
return render_table([
|
||||
'col' => $columns
|
||||
], $rows, $data);
|
||||
}
|
||||
|
||||
return render_table($columns, $rows_raw, $data);
|
||||
return render_table($columns, $rows_raw, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for rendering a html-table.
|
||||
* use table()
|
||||
*/
|
||||
function render_table($columns, $rows, $data = true) {
|
||||
if (count($rows) == 0) {
|
||||
return info(_("No data found."), true);
|
||||
}
|
||||
|
||||
$html = '<table class="table table-striped' . ($data ? ' data' : '') . '">';
|
||||
$html .= '<thead><tr>';
|
||||
foreach ($columns as $key => $column) {
|
||||
$html .= '<th class="column_' . $key . '">' . $column . '</th>';
|
||||
}
|
||||
$html .= '</tr></thead>';
|
||||
$html .= '<tbody>';
|
||||
foreach ($rows as $row) {
|
||||
$html .= '<tr>';
|
||||
foreach ($columns as $key => $column) {
|
||||
$value = " ";
|
||||
if (isset($row[$key])) {
|
||||
$value = $row[$key];
|
||||
}
|
||||
$html .= '<td class="column_' . $key . '">' . $value . '</td>';
|
||||
function render_table($columns, $rows, $data = true)
|
||||
{
|
||||
if (count($rows) == 0) {
|
||||
return info(_("No data found."), true);
|
||||
}
|
||||
$html .= '</tr>';
|
||||
}
|
||||
$html .= '</tbody>';
|
||||
$html .= '</table>';
|
||||
return $html;
|
||||
|
||||
$html = '<table class="table table-striped' . ($data ? ' data' : '') . '">';
|
||||
$html .= '<thead><tr>';
|
||||
foreach ($columns as $key => $column) {
|
||||
$html .= '<th class="column_' . $key . '">' . $column . '</th>';
|
||||
}
|
||||
$html .= '</tr></thead>';
|
||||
$html .= '<tbody>';
|
||||
foreach ($rows as $row) {
|
||||
$html .= '<tr>';
|
||||
foreach ($columns as $key => $column) {
|
||||
$value = " ";
|
||||
if (isset($row[$key])) {
|
||||
$value = $row[$key];
|
||||
}
|
||||
$html .= '<td class="column_' . $key . '">' . $value . '</td>';
|
||||
}
|
||||
$html .= '</tr>';
|
||||
}
|
||||
$html .= '</tbody>';
|
||||
$html .= '</table>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert einen Knopf
|
||||
*/
|
||||
function button($href, $label, $class = "") {
|
||||
return '<a href="' . $href . '" class="btn btn-default ' . $class . '">' . $label . '</a>';
|
||||
function button($href, $label, $class = "")
|
||||
{
|
||||
return '<a href="' . $href . '" class="btn btn-default ' . $class . '">' . $label . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert einen Knopf mit Glyph
|
||||
*/
|
||||
function button_glyph($href, $glyph, $class = "") {
|
||||
return button($href, glyph($glyph), $class);
|
||||
function button_glyph($href, $glyph, $class = "")
|
||||
{
|
||||
return button($href, glyph($glyph), $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert eine Toolbar mit Knöpfen
|
||||
*/
|
||||
function buttons($buttons = []) {
|
||||
return '<div class="form-group">' . table_buttons($buttons) . '</div>';
|
||||
function buttons($buttons = [])
|
||||
{
|
||||
return '<div class="form-group">' . table_buttons($buttons) . '</div>';
|
||||
}
|
||||
|
||||
function table_buttons($buttons = []) {
|
||||
return '<div class="btn-group">' . join(' ', $buttons) . '</div>';
|
||||
function table_buttons($buttons = [])
|
||||
{
|
||||
return '<div class="btn-group">' . join(' ', $buttons) . '</div>';
|
||||
}
|
||||
|
||||
// Load and render template
|
||||
function template_render($file, $data) {
|
||||
if (file_exists($file)) {
|
||||
$template = file_get_contents($file);
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $name => $content) {
|
||||
$template = str_replace("%" . $name . "%", $content, $template);
|
||||
}
|
||||
function template_render($file, $data)
|
||||
{
|
||||
if (file_exists($file)) {
|
||||
$template = file_get_contents($file);
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $name => $content) {
|
||||
$template = str_replace("%" . $name . "%", $content, $template);
|
||||
}
|
||||
}
|
||||
return $template;
|
||||
}
|
||||
return $template;
|
||||
}
|
||||
engelsystem_error("Cannot find template file «" . $file . "».");
|
||||
engelsystem_error("Cannot find template file «" . $file . "».");
|
||||
}
|
||||
|
||||
function shorten($str, $length = 50) {
|
||||
if (strlen($str) < $length) {
|
||||
return $str;
|
||||
}
|
||||
return '<span title="' . htmlentities($str, ENT_COMPAT, 'UTF-8') . '">' . substr($str, 0, $length - 3) . '...</span>';
|
||||
}
|
||||
|
||||
function table_body($array) {
|
||||
$html = "";
|
||||
foreach ($array as $line) {
|
||||
$html .= "<tr>";
|
||||
if (is_array($line)) {
|
||||
foreach ($line as $td) {
|
||||
$html .= "<td>" . $td . "</td>";
|
||||
}
|
||||
} else {
|
||||
$html .= "<td>" . $line . "</td>";
|
||||
function shorten($str, $length = 50)
|
||||
{
|
||||
if (strlen($str) < $length) {
|
||||
return $str;
|
||||
}
|
||||
$html .= "</tr>";
|
||||
}
|
||||
return $html;
|
||||
return '<span title="' . htmlentities($str, ENT_COMPAT, 'UTF-8') . '">' . substr($str, 0, $length - 3) . '...</span>';
|
||||
}
|
||||
|
||||
function ReplaceSmilies($neueckig) {
|
||||
$neueckig = str_replace(";o))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":-))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";o)", "<img src=\"pic/smiles/icon_wind.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":)", "<img src=\"pic/smiles/icon_smile.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":-)", "<img src=\"pic/smiles/icon_smile.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":-(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":o(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":o)", "<img src=\"pic/smiles/icon_lol.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";o(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";-(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig);
|
||||
$neueckig = str_replace("8)", "<img src=\"pic/smiles/icon_rolleyes.gif\">", $neueckig);
|
||||
$neueckig = str_replace("8o)", "<img src=\"pic/smiles/icon_rolleyes.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":P", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":-P", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":oP", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";P", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";oP", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig);
|
||||
$neueckig = str_replace("?)", "<img src=\"pic/smiles/icon_question.gif\">", $neueckig);
|
||||
|
||||
return $neueckig;
|
||||
function table_body($array)
|
||||
{
|
||||
$html = "";
|
||||
foreach ($array as $line) {
|
||||
$html .= "<tr>";
|
||||
if (is_array($line)) {
|
||||
foreach ($line as $td) {
|
||||
$html .= "<td>" . $td . "</td>";
|
||||
}
|
||||
} else {
|
||||
$html .= "<td>" . $line . "</td>";
|
||||
}
|
||||
$html .= "</tr>";
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function ReplaceSmilies($neueckig)
|
||||
{
|
||||
$neueckig = str_replace(";o))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":-))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";o)", "<img src=\"pic/smiles/icon_wind.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":)", "<img src=\"pic/smiles/icon_smile.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":-)", "<img src=\"pic/smiles/icon_smile.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":-(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":o(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":o)", "<img src=\"pic/smiles/icon_lol.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";o(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";-(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig);
|
||||
$neueckig = str_replace("8)", "<img src=\"pic/smiles/icon_rolleyes.gif\">", $neueckig);
|
||||
$neueckig = str_replace("8o)", "<img src=\"pic/smiles/icon_rolleyes.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":P", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":-P", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig);
|
||||
$neueckig = str_replace(":oP", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";P", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig);
|
||||
$neueckig = str_replace(";oP", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig);
|
||||
$neueckig = str_replace("?)", "<img src=\"pic/smiles/icon_question.gif\">", $neueckig);
|
||||
|
||||
return $neueckig;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
*
|
||||
* @param AngelType $angeltype
|
||||
*/
|
||||
function AngelType_name_render($angeltype) {
|
||||
return '<a href="' . angeltype_link($angeltype['id']) . '">' . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . '</a>';
|
||||
function AngelType_name_render($angeltype)
|
||||
{
|
||||
return '<a href="' . angeltype_link($angeltype['id']) . '">' . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,25 +21,27 @@ function AngelType_name_render($angeltype) {
|
|||
* UserAngelType and AngelType
|
||||
* @return string
|
||||
*/
|
||||
function AngelType_render_membership($user_angeltype) {
|
||||
if ($user_angeltype['user_angeltype_id'] != null) {
|
||||
if ($user_angeltype['restricted']) {
|
||||
if ($user_angeltype['confirm_user_id'] == null) {
|
||||
return glyph('lock') . _("Unconfirmed");
|
||||
} elseif ($user_angeltype['supporter']) {
|
||||
return glyph_bool(true) . _("supporter");
|
||||
}
|
||||
return glyph_bool(true) . _("Member");
|
||||
} elseif ($user_angeltype['supporter']) {
|
||||
return glyph_bool(true) . _("supporter");
|
||||
function AngelType_render_membership($user_angeltype)
|
||||
{
|
||||
if ($user_angeltype['user_angeltype_id'] != null) {
|
||||
if ($user_angeltype['restricted']) {
|
||||
if ($user_angeltype['confirm_user_id'] == null) {
|
||||
return glyph('lock') . _("Unconfirmed");
|
||||
} elseif ($user_angeltype['supporter']) {
|
||||
return glyph_bool(true) . _("supporter");
|
||||
}
|
||||
return glyph_bool(true) . _("Member");
|
||||
} elseif ($user_angeltype['supporter']) {
|
||||
return glyph_bool(true) . _("supporter");
|
||||
}
|
||||
return glyph_bool(true) . _("Member");
|
||||
}
|
||||
return glyph_bool(true) . _("Member");
|
||||
}
|
||||
return glyph_bool(false);
|
||||
return glyph_bool(false);
|
||||
}
|
||||
|
||||
function AngelType_delete_view($angeltype) {
|
||||
return page_with_title(sprintf(_("Delete angeltype %s"), $angeltype['name']), [
|
||||
function AngelType_delete_view($angeltype)
|
||||
{
|
||||
return page_with_title(sprintf(_("Delete angeltype %s"), $angeltype['name']), [
|
||||
info(sprintf(_("Do you want to delete angeltype %s?"), $angeltype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes'), _("cancel"), 'cancel'),
|
||||
|
@ -55,9 +58,10 @@ function AngelType_delete_view($angeltype) {
|
|||
* @param boolean $supporter_mode
|
||||
* Is the user a supporter of this angeltype?
|
||||
*/
|
||||
function AngelType_edit_view($angeltype, $supporter_mode) {
|
||||
$contact_info = AngelType_contact_info($angeltype);
|
||||
return page_with_title(sprintf(_("Edit %s"), $angeltype['name']), [
|
||||
function AngelType_edit_view($angeltype, $supporter_mode)
|
||||
{
|
||||
$contact_info = AngelType_contact_info($angeltype);
|
||||
return page_with_title(sprintf(_("Edit %s"), $angeltype['name']), [
|
||||
buttons([
|
||||
button(page_link_to('angeltypes'), _("Angeltypes"), 'back')
|
||||
]),
|
||||
|
@ -81,36 +85,37 @@ function AngelType_edit_view($angeltype, $supporter_mode) {
|
|||
/**
|
||||
* Renders the buttons for the angeltype view.
|
||||
*/
|
||||
function AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user) {
|
||||
$buttons = [
|
||||
function AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user)
|
||||
{
|
||||
$buttons = [
|
||||
button(page_link_to('angeltypes'), _("Angeltypes"), 'back')
|
||||
];
|
||||
|
||||
if ($angeltype['requires_driver_license']) {
|
||||
$buttons[] = button(user_driver_license_edit_link($user), glyph("road") . _("my driving license"));
|
||||
}
|
||||
|
||||
if ($user_angeltype == null) {
|
||||
$buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
|
||||
} else {
|
||||
if ($angeltype['requires_driver_license'] && $user_driver_license == null) {
|
||||
error(_("This angeltype requires a driver license. Please enter your driver license information!"));
|
||||
if ($angeltype['requires_driver_license']) {
|
||||
$buttons[] = button(user_driver_license_edit_link($user), glyph("road") . _("my driving license"));
|
||||
}
|
||||
|
||||
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']));
|
||||
if ($user_angeltype == null) {
|
||||
$buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
|
||||
} else {
|
||||
if ($angeltype['requires_driver_license'] && $user_driver_license == null) {
|
||||
error(_("This angeltype requires a driver license. Please enter your driver license information!"));
|
||||
}
|
||||
|
||||
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']));
|
||||
}
|
||||
$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 || $supporter) {
|
||||
$buttons[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), 'edit');
|
||||
}
|
||||
if ($admin_angeltypes) {
|
||||
$buttons[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), 'delete');
|
||||
}
|
||||
if ($admin_angeltypes || $supporter) {
|
||||
$buttons[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), 'edit');
|
||||
}
|
||||
if ($admin_angeltypes) {
|
||||
$buttons[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), 'delete');
|
||||
}
|
||||
|
||||
return buttons($buttons);
|
||||
return buttons($buttons);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,50 +123,51 @@ function AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes,
|
|||
*
|
||||
* @return [supporters, members, unconfirmed members]
|
||||
*/
|
||||
function AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $admin_angeltypes) {
|
||||
$supporters = [];
|
||||
$members_confirmed = [];
|
||||
$members_unconfirmed = [];
|
||||
foreach ($members as $member) {
|
||||
$member['Nick'] = User_Nick_render($member);
|
||||
function AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $admin_angeltypes)
|
||||
{
|
||||
$supporters = [];
|
||||
$members_confirmed = [];
|
||||
$members_unconfirmed = [];
|
||||
foreach ($members as $member) {
|
||||
$member['Nick'] = User_Nick_render($member);
|
||||
|
||||
if ($angeltype['requires_driver_license']) {
|
||||
$member['wants_to_drive'] = glyph_bool($member['user_id']);
|
||||
$member['has_car'] = glyph_bool($member['has_car']);
|
||||
$member['has_license_car'] = glyph_bool($member['has_license_car']);
|
||||
$member['has_license_3_5t_transporter'] = glyph_bool($member['has_license_3_5t_transporter']);
|
||||
$member['has_license_7_5t_truck'] = glyph_bool($member['has_license_7_5t_truck']);
|
||||
$member['has_license_12_5t_truck'] = glyph_bool($member['has_license_12_5t_truck']);
|
||||
$member['has_license_forklift'] = glyph_bool($member['has_license_forklift']);
|
||||
}
|
||||
if ($angeltype['requires_driver_license']) {
|
||||
$member['wants_to_drive'] = glyph_bool($member['user_id']);
|
||||
$member['has_car'] = glyph_bool($member['has_car']);
|
||||
$member['has_license_car'] = glyph_bool($member['has_license_car']);
|
||||
$member['has_license_3_5t_transporter'] = glyph_bool($member['has_license_3_5t_transporter']);
|
||||
$member['has_license_7_5t_truck'] = glyph_bool($member['has_license_7_5t_truck']);
|
||||
$member['has_license_12_5t_truck'] = glyph_bool($member['has_license_12_5t_truck']);
|
||||
$member['has_license_forklift'] = glyph_bool($member['has_license_forklift']);
|
||||
}
|
||||
|
||||
if ($angeltype['restricted'] && $member['confirm_user_id'] == null) {
|
||||
$member['actions'] = table_buttons([
|
||||
if ($angeltype['restricted'] && $member['confirm_user_id'] == null) {
|
||||
$member['actions'] = table_buttons([
|
||||
button(page_link_to('user_angeltypes') . '&action=confirm&user_angeltype_id=' . $member['user_angeltype_id'], _("confirm"), 'btn-xs'),
|
||||
button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $member['user_angeltype_id'], _("deny"), 'btn-xs')
|
||||
]);
|
||||
$members_unconfirmed[] = $member;
|
||||
} elseif ($member['supporter']) {
|
||||
if ($admin_angeltypes) {
|
||||
$member['actions'] = table_buttons([
|
||||
$members_unconfirmed[] = $member;
|
||||
} elseif ($member['supporter']) {
|
||||
if ($admin_angeltypes) {
|
||||
$member['actions'] = table_buttons([
|
||||
button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&supporter=0', _("Remove supporter rights"), 'btn-xs')
|
||||
]);
|
||||
} else {
|
||||
$member['actions'] = '';
|
||||
}
|
||||
$supporters[] = $member;
|
||||
} else {
|
||||
if ($admin_user_angeltypes) {
|
||||
$member['actions'] = table_buttons([
|
||||
} else {
|
||||
$member['actions'] = '';
|
||||
}
|
||||
$supporters[] = $member;
|
||||
} else {
|
||||
if ($admin_user_angeltypes) {
|
||||
$member['actions'] = table_buttons([
|
||||
$admin_angeltypes ? button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&supporter=1', _("Add supporter rights"), 'btn-xs') : '',
|
||||
button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $member['user_angeltype_id'], _("remove"), 'btn-xs')
|
||||
]);
|
||||
}
|
||||
$members_confirmed[] = $member;
|
||||
}
|
||||
$members_confirmed[] = $member;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
return [
|
||||
$supporters,
|
||||
$members_confirmed,
|
||||
$members_unconfirmed
|
||||
|
@ -171,9 +177,10 @@ function AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $a
|
|||
/**
|
||||
* Creates the needed member table headers according to given rights and settings from the angeltype.
|
||||
*/
|
||||
function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes) {
|
||||
if ($angeltype['requires_driver_license'] && ($supporter || $admin_angeltypes)) {
|
||||
return [
|
||||
function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes)
|
||||
{
|
||||
if ($angeltype['requires_driver_license'] && ($supporter || $admin_angeltypes)) {
|
||||
return [
|
||||
'Nick' => _("Nick"),
|
||||
'DECT' => _("DECT"),
|
||||
'wants_to_drive' => _("Driver"),
|
||||
|
@ -185,8 +192,8 @@ function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes)
|
|||
'has_license_forklift' => _("Forklift"),
|
||||
'actions' => ''
|
||||
];
|
||||
}
|
||||
return [
|
||||
}
|
||||
return [
|
||||
'Nick' => _("Nick"),
|
||||
'DECT' => _("DECT"),
|
||||
'actions' => ''
|
||||
|
@ -196,60 +203,61 @@ function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes)
|
|||
/**
|
||||
* Render an angeltype page containing the member lists.
|
||||
*/
|
||||
function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angeltypes, $admin_angeltypes, $supporter, $user_driver_license, $user) {
|
||||
$page = [
|
||||
function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angeltypes, $admin_angeltypes, $supporter, $user_driver_license, $user)
|
||||
{
|
||||
$page = [
|
||||
AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user),
|
||||
msg()
|
||||
];
|
||||
|
||||
$page[] = '<h3>' . _("Description") . '</h3>';
|
||||
$parsedown = new Parsedown();
|
||||
if ($angeltype['description'] != "") {
|
||||
$page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
|
||||
}
|
||||
$page[] = '<h3>' . _("Description") . '</h3>';
|
||||
$parsedown = new Parsedown();
|
||||
if ($angeltype['description'] != "") {
|
||||
$page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
|
||||
}
|
||||
|
||||
list($supporters, $members_confirmed, $members_unconfirmed) = AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $admin_angeltypes);
|
||||
$table_headers = AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes);
|
||||
list($supporters, $members_confirmed, $members_unconfirmed) = AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $admin_angeltypes);
|
||||
$table_headers = AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes);
|
||||
|
||||
if (count($supporters) > 0) {
|
||||
$page[] = '<h3>' . _("supporters") . '</h3>';
|
||||
$page[] = table($table_headers, $supporters);
|
||||
}
|
||||
if (count($supporters) > 0) {
|
||||
$page[] = '<h3>' . _("supporters") . '</h3>';
|
||||
$page[] = table($table_headers, $supporters);
|
||||
}
|
||||
|
||||
if (count($members_confirmed) > 0) {
|
||||
$members_confirmed[] = [
|
||||
if (count($members_confirmed) > 0) {
|
||||
$members_confirmed[] = [
|
||||
'Nick' => _('Sum'),
|
||||
'DECT' => count($members_confirmed),
|
||||
'actions' => ''
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($members_unconfirmed) > 0) {
|
||||
$members_unconfirmed[] = [
|
||||
if (count($members_unconfirmed) > 0) {
|
||||
$members_unconfirmed[] = [
|
||||
'Nick' => _('Sum'),
|
||||
'DECT' => count($members_unconfirmed),
|
||||
'actions' => ''
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$page[] = '<h3>' . _("Members") . '</h3>';
|
||||
if ($admin_user_angeltypes) {
|
||||
$page[] = buttons([
|
||||
$page[] = '<h3>' . _("Members") . '</h3>';
|
||||
if ($admin_user_angeltypes) {
|
||||
$page[] = buttons([
|
||||
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) {
|
||||
$page[] = '<h3>' . _("Unconfirmed") . '</h3>';
|
||||
$page[] = buttons([
|
||||
if ($admin_user_angeltypes && $angeltype['restricted'] && count($members_unconfirmed) > 0) {
|
||||
$page[] = '<h3>' . _("Unconfirmed") . '</h3>';
|
||||
$page[] = buttons([
|
||||
button(page_link_to('user_angeltypes') . '&action=confirm_all&angeltype_id=' . $angeltype['id'], _("confirm all"), 'ok'),
|
||||
button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'], _("deny all"), 'cancel')
|
||||
]);
|
||||
$page[] = table($table_headers, $members_unconfirmed);
|
||||
}
|
||||
$page[] = table($table_headers, $members_unconfirmed);
|
||||
}
|
||||
|
||||
return page_with_title(sprintf(_("Team %s"), $angeltype['name']), $page);
|
||||
return page_with_title(sprintf(_("Team %s"), $angeltype['name']), $page);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,8 +265,9 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
|
|||
*
|
||||
* @param array $angeltypes
|
||||
*/
|
||||
function AngelTypes_list_view($angeltypes, $admin_angeltypes) {
|
||||
return page_with_title(angeltypes_title(), [
|
||||
function AngelTypes_list_view($angeltypes, $admin_angeltypes)
|
||||
{
|
||||
return page_with_title(angeltypes_title(), [
|
||||
msg(),
|
||||
buttons([
|
||||
$admin_angeltypes ? button(page_link_to('angeltypes') . '&action=edit', _("New angeltype"), 'add') : '',
|
||||
|
@ -277,39 +286,41 @@ function AngelTypes_list_view($angeltypes, $admin_angeltypes) {
|
|||
/**
|
||||
* Renders the about info for an angeltype.
|
||||
*/
|
||||
function AngelTypes_about_view_angeltype($angeltype) {
|
||||
$parsedown = new Parsedown();
|
||||
function AngelTypes_about_view_angeltype($angeltype)
|
||||
{
|
||||
$parsedown = new Parsedown();
|
||||
|
||||
$html = '<h2>' . $angeltype['name'] . '</h2>';
|
||||
$html = '<h2>' . $angeltype['name'] . '</h2>';
|
||||
|
||||
if (isset($angeltype['user_angeltype_id'])) {
|
||||
$buttons = [];
|
||||
if ($angeltype['user_angeltype_id'] != null) {
|
||||
$buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), 'cancel');
|
||||
} else {
|
||||
$buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
|
||||
if (isset($angeltype['user_angeltype_id'])) {
|
||||
$buttons = [];
|
||||
if ($angeltype['user_angeltype_id'] != null) {
|
||||
$buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), 'cancel');
|
||||
} else {
|
||||
$buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
|
||||
}
|
||||
$html .= buttons($buttons);
|
||||
}
|
||||
$html .= buttons($buttons);
|
||||
}
|
||||
|
||||
if ($angeltype['restricted']) {
|
||||
$html .= info(_("This angeltype is restricted by double-opt-in by a team supporter. Please show up at the according introduction meetings."), true);
|
||||
}
|
||||
if ($angeltype['description'] != "") {
|
||||
$html .= '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
|
||||
}
|
||||
$html .= '<hr />';
|
||||
if ($angeltype['restricted']) {
|
||||
$html .= info(_("This angeltype is restricted by double-opt-in by a team supporter. Please show up at the according introduction meetings."), true);
|
||||
}
|
||||
if ($angeltype['description'] != "") {
|
||||
$html .= '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
|
||||
}
|
||||
$html .= '<hr />';
|
||||
|
||||
return $html;
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a site that contains every angeltype and its description, basically as an overview of the needed help types.
|
||||
*/
|
||||
function AngelTypes_about_view($angeltypes, $user_logged_in) {
|
||||
global $faq_url;
|
||||
function AngelTypes_about_view($angeltypes, $user_logged_in)
|
||||
{
|
||||
global $faq_url;
|
||||
|
||||
$content = [
|
||||
$content = [
|
||||
buttons([
|
||||
! $user_logged_in ? button(page_link_to('register'), register_title()) : '',
|
||||
! $user_logged_in ? button(page_link_to('login'), login_title()) : '',
|
||||
|
@ -319,11 +330,9 @@ function AngelTypes_about_view($angeltypes, $user_logged_in) {
|
|||
'<p>' . _("Here is the list of teams and their tasks. If you have questions, read the FAQ.") . '</p>',
|
||||
'<hr />'
|
||||
];
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
$content[] = AngelTypes_about_view_angeltype($angeltype);
|
||||
}
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
$content[] = AngelTypes_about_view_angeltype($angeltype);
|
||||
}
|
||||
|
||||
return page_with_title(_("Teams/Job description"), $content);
|
||||
return page_with_title(_("Teams/Job description"), $content);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -4,85 +4,87 @@
|
|||
* Shows basic event infos and countdowns.
|
||||
* @param EventConfig $event_config The event configuration
|
||||
*/
|
||||
function EventConfig_countdown_page($event_config) {
|
||||
if ($event_config == null) {
|
||||
return div('col-md-12 text-center', [
|
||||
function EventConfig_countdown_page($event_config)
|
||||
{
|
||||
if ($event_config == null) {
|
||||
return div('col-md-12 text-center', [
|
||||
heading(sprintf(_("Welcome to the %s!"), '<span class="icon-icon_angel"></span> ENGELSYSTEM'), 2)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$elements = [];
|
||||
$elements = [];
|
||||
|
||||
if ($event_config['event_name'] != null) {
|
||||
$elements[] = div('col-sm-12 text-center', [
|
||||
if ($event_config['event_name'] != null) {
|
||||
$elements[] = div('col-sm-12 text-center', [
|
||||
heading(sprintf(_("Welcome to the %s!"), $event_config['event_name'] . ' <span class="icon-icon_angel"></span> ENGELSYSTEM'), 2)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($event_config['buildup_start_date'] != null && time() < $event_config['buildup_start_date']) {
|
||||
$elements[] = div('col-sm-3 text-center hidden-xs', [
|
||||
if ($event_config['buildup_start_date'] != null && time() < $event_config['buildup_start_date']) {
|
||||
$elements[] = div('col-sm-3 text-center hidden-xs', [
|
||||
heading(_("Buildup starts"), 4),
|
||||
'<span class="moment-countdown text-big" data-timestamp="' . $event_config['buildup_start_date'] . '">%c</span>',
|
||||
'<small>' . date(_("Y-m-d"), $event_config['buildup_start_date']) . '</small>'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($event_config['event_start_date'] != null && time() < $event_config['event_start_date']) {
|
||||
$elements[] = div('col-sm-3 text-center hidden-xs', [
|
||||
if ($event_config['event_start_date'] != null && time() < $event_config['event_start_date']) {
|
||||
$elements[] = div('col-sm-3 text-center hidden-xs', [
|
||||
heading(_("Event starts"), 4),
|
||||
'<span class="moment-countdown text-big" data-timestamp="' . $event_config['event_start_date'] . '">%c</span>',
|
||||
'<small>' . date(_("Y-m-d"), $event_config['event_start_date']) . '</small>'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($event_config['event_end_date'] != null && time() < $event_config['event_end_date']) {
|
||||
$elements[] = div('col-sm-3 text-center hidden-xs', [
|
||||
if ($event_config['event_end_date'] != null && time() < $event_config['event_end_date']) {
|
||||
$elements[] = div('col-sm-3 text-center hidden-xs', [
|
||||
heading(_("Event ends"), 4),
|
||||
'<span class="moment-countdown text-big" data-timestamp="' . $event_config['event_end_date'] . '">%c</span>',
|
||||
'<small>' . date(_("Y-m-d"), $event_config['event_end_date']) . '</small>'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($event_config['teardown_end_date'] != null && time() < $event_config['teardown_end_date']) {
|
||||
$elements[] = div('col-sm-3 text-center hidden-xs', [
|
||||
if ($event_config['teardown_end_date'] != null && time() < $event_config['teardown_end_date']) {
|
||||
$elements[] = div('col-sm-3 text-center hidden-xs', [
|
||||
heading(_("Teardown ends"), 4),
|
||||
'<span class="moment-countdown text-big" data-timestamp="' . $event_config['teardown_end_date'] . '">%c</span>',
|
||||
'<small>' . date(_("Y-m-d"), $event_config['teardown_end_date']) . '</small>'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return join("", $elements);
|
||||
return join("", $elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts event name and start+end date into a line of text.
|
||||
*/
|
||||
function EventConfig_info($event_config) {
|
||||
if ($event_config == null) {
|
||||
return "";
|
||||
}
|
||||
function EventConfig_info($event_config)
|
||||
{
|
||||
if ($event_config == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return sprintf(_("%s, from %s to %s"), $event_config['event_name'], date(_("Y-m-d"), $event_config['event_start_date']), date(_("Y-m-d"), $event_config['event_end_date']));
|
||||
return sprintf(_("%s, from %s to %s"), $event_config['event_name'], date(_("Y-m-d"), $event_config['event_start_date']), date(_("Y-m-d"), $event_config['event_end_date']));
|
||||
}
|
||||
|
||||
// Event name, start date are set
|
||||
if ($event_config['event_name'] != null && $event_config['event_start_date'] != null) {
|
||||
return sprintf(_("%s, starting %s"), $event_config['event_name'], date(_("Y-m-d"), $event_config['event_start_date']));
|
||||
return sprintf(_("%s, starting %s"), $event_config['event_name'], date(_("Y-m-d"), $event_config['event_start_date']));
|
||||
}
|
||||
|
||||
// Event start+end date are set
|
||||
if ($event_config['event_start_date'] != null && $event_config['event_end_date'] != null) {
|
||||
return sprintf(_("Event from %s to %s"), date(_("Y-m-d"), $event_config['event_start_date']), date(_("Y-m-d"), $event_config['event_end_date']));
|
||||
return sprintf(_("Event from %s to %s"), date(_("Y-m-d"), $event_config['event_start_date']), date(_("Y-m-d"), $event_config['event_end_date']));
|
||||
}
|
||||
|
||||
// Only event name is set
|
||||
if ($event_config['event_name'] != null) {
|
||||
return sprintf($event_config['event_name']);
|
||||
return sprintf($event_config['event_name']);
|
||||
}
|
||||
|
||||
return "";
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,8 +99,9 @@ function EventConfig_info($event_config) {
|
|||
* @param date $event_end_date
|
||||
* @param date $teardown_end_date
|
||||
*/
|
||||
function EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date) {
|
||||
return page_with_title(event_config_title(), [
|
||||
function EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date)
|
||||
{
|
||||
return page_with_title(event_config_title(), [
|
||||
msg(),
|
||||
form([
|
||||
div('row', [
|
||||
|
@ -125,5 +128,3 @@ function EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_d
|
|||
])
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,18 +1,19 @@
|
|||
<?php
|
||||
|
||||
function Questions_view($open_questions, $answered_questions, $ask_action) {
|
||||
foreach ($open_questions as &$question) {
|
||||
$question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>';
|
||||
$question['Question'] = str_replace("\n", '<br />', $question['Question']);
|
||||
}
|
||||
function Questions_view($open_questions, $answered_questions, $ask_action)
|
||||
{
|
||||
foreach ($open_questions as &$question) {
|
||||
$question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>';
|
||||
$question['Question'] = str_replace("\n", '<br />', $question['Question']);
|
||||
}
|
||||
|
||||
foreach ($answered_questions as &$question) {
|
||||
$question['Question'] = str_replace("\n", '<br />', $question['Question']);
|
||||
$question['Answer'] = str_replace("\n", '<br />', $question['Answer']);
|
||||
$question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>';
|
||||
}
|
||||
foreach ($answered_questions as &$question) {
|
||||
$question['Question'] = str_replace("\n", '<br />', $question['Question']);
|
||||
$question['Answer'] = str_replace("\n", '<br />', $question['Answer']);
|
||||
$question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>';
|
||||
}
|
||||
|
||||
return page_with_title(questions_title(), [
|
||||
return page_with_title(questions_title(), [
|
||||
msg(),
|
||||
heading(_("Open questions"), 2),
|
||||
table([
|
||||
|
@ -33,5 +34,3 @@ function Questions_view($open_questions, $answered_questions, $ask_action) {
|
|||
], $ask_action)
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
|
@ -2,19 +2,19 @@
|
|||
use Engelsystem\ShiftsFilterRenderer;
|
||||
use Engelsystem\ShiftCalendarRenderer;
|
||||
|
||||
function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalendarRenderer $shiftCalendarRenderer) {
|
||||
return page_with_title(glyph('map-marker') . $room['Name'], [
|
||||
function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalendarRenderer $shiftCalendarRenderer)
|
||||
{
|
||||
return page_with_title(glyph('map-marker') . $room['Name'], [
|
||||
$shiftsFilterRenderer->render(room_link($room)) ,
|
||||
$shiftCalendarRenderer->render()
|
||||
]);
|
||||
}
|
||||
|
||||
function Room_name_render($room) {
|
||||
global $privileges;
|
||||
if (in_array('view_rooms', $privileges)) {
|
||||
return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>';
|
||||
}
|
||||
return glyph('map-marker') . $room['Name'];
|
||||
function Room_name_render($room)
|
||||
{
|
||||
global $privileges;
|
||||
if (in_array('view_rooms', $privileges)) {
|
||||
return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>';
|
||||
}
|
||||
return glyph('map-marker') . $room['Name'];
|
||||
}
|
||||
|
||||
?>
|
|
@ -5,21 +5,22 @@ namespace Engelsystem;
|
|||
/**
|
||||
* Represents a single lane in a shifts calendar.
|
||||
*/
|
||||
class ShiftCalendarLane {
|
||||
class ShiftCalendarLane
|
||||
{
|
||||
private $firstBlockStartTime;
|
||||
|
||||
private $firstBlockStartTime;
|
||||
private $blockCount;
|
||||
|
||||
private $blockCount;
|
||||
private $header;
|
||||
|
||||
private $header;
|
||||
private $shifts = [];
|
||||
|
||||
private $shifts = [];
|
||||
|
||||
public function __construct($header, $firstBlockStartTime, $blockCount) {
|
||||
$this->header = $header;
|
||||
$this->firstBlockStartTime = $firstBlockStartTime;
|
||||
$this->blockCount = $blockCount;
|
||||
}
|
||||
public function __construct($header, $firstBlockStartTime, $blockCount)
|
||||
{
|
||||
$this->header = $header;
|
||||
$this->firstBlockStartTime = $firstBlockStartTime;
|
||||
$this->blockCount = $blockCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a shift to the lane, but only if it fits.
|
||||
|
@ -29,12 +30,13 @@ class ShiftCalendarLane {
|
|||
* The shift to add
|
||||
* @return boolean true on success
|
||||
*/
|
||||
public function addShift($shift) {
|
||||
if ($this->shiftFits($shift)) {
|
||||
$this->shifts[] = $shift;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public function addShift($shift)
|
||||
{
|
||||
if ($this->shiftFits($shift)) {
|
||||
$this->shifts[] = $shift;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,21 +45,23 @@ class ShiftCalendarLane {
|
|||
* @param Shift $shift
|
||||
* The shift to fit into this lane
|
||||
*/
|
||||
public function shiftFits($newShift) {
|
||||
foreach ($this->shifts as $laneShift) {
|
||||
if (! ($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) {
|
||||
return false;
|
||||
public function shiftFits($newShift)
|
||||
{
|
||||
foreach ($this->shifts as $laneShift) {
|
||||
if (! ($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHeader()
|
||||
{
|
||||
return $this->header;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHeader() {
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
public function getShifts() {
|
||||
return $this->shifts;
|
||||
}
|
||||
public function getShifts()
|
||||
{
|
||||
return $this->shifts;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace Engelsystem;
|
||||
|
||||
class ShiftCalendarRenderer {
|
||||
class ShiftCalendarRenderer
|
||||
{
|
||||
|
||||
/**
|
||||
* 15m * 60s/m = 900s
|
||||
|
@ -25,28 +26,29 @@ class ShiftCalendarRenderer {
|
|||
*/
|
||||
const TIME_MARGIN = 1800;
|
||||
|
||||
private $lanes;
|
||||
private $lanes;
|
||||
|
||||
private $shiftsFilter;
|
||||
private $shiftsFilter;
|
||||
|
||||
private $firstBlockStartTime = null;
|
||||
private $firstBlockStartTime = null;
|
||||
|
||||
private $lastBlockEndTime = null;
|
||||
private $lastBlockEndTime = null;
|
||||
|
||||
private $blocksPerSlot = null;
|
||||
private $blocksPerSlot = null;
|
||||
|
||||
private $needed_angeltypes = null;
|
||||
private $needed_angeltypes = null;
|
||||
|
||||
private $shift_entries = null;
|
||||
private $shift_entries = null;
|
||||
|
||||
public function __construct($shifts, $needed_angeltypes, $shift_entries, ShiftsFilter $shiftsFilter) {
|
||||
$this->shiftsFilter = $shiftsFilter;
|
||||
$this->firstBlockStartTime = $this->calcFirstBlockStartTime($shifts);
|
||||
$this->lastBlockEndTime = $this->calcLastBlockEndTime($shifts);
|
||||
$this->lanes = $this->assignShiftsToLanes($shifts);
|
||||
$this->needed_angeltypes = $needed_angeltypes;
|
||||
$this->shift_entries = $shift_entries;
|
||||
}
|
||||
public function __construct($shifts, $needed_angeltypes, $shift_entries, ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$this->shiftsFilter = $shiftsFilter;
|
||||
$this->firstBlockStartTime = $this->calcFirstBlockStartTime($shifts);
|
||||
$this->lastBlockEndTime = $this->calcLastBlockEndTime($shifts);
|
||||
$this->lanes = $this->assignShiftsToLanes($shifts);
|
||||
$this->needed_angeltypes = $needed_angeltypes;
|
||||
$this->shift_entries = $shift_entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the shifts to different lanes per room if they collide
|
||||
|
@ -56,68 +58,73 @@ class ShiftCalendarRenderer {
|
|||
*
|
||||
* @return Returns an array that assigns a room_id to an array of ShiftCalendarLane containing the shifts
|
||||
*/
|
||||
private function assignShiftsToLanes($shifts) {
|
||||
// array that assigns a room id to a list of lanes (per room)
|
||||
private function assignShiftsToLanes($shifts)
|
||||
{
|
||||
// array that assigns a room id to a list of lanes (per room)
|
||||
$lanes = [];
|
||||
|
||||
foreach ($shifts as $shift) {
|
||||
$room_id = $shift['RID'];
|
||||
$header = Room_name_render([
|
||||
foreach ($shifts as $shift) {
|
||||
$room_id = $shift['RID'];
|
||||
$header = Room_name_render([
|
||||
'RID' => $room_id,
|
||||
'Name' => $shift['room_name']
|
||||
]);
|
||||
if (! isset($lanes[$room_id])) {
|
||||
// initialize room with one lane
|
||||
if (! isset($lanes[$room_id])) {
|
||||
// initialize room with one lane
|
||||
$lanes[$room_id] = [
|
||||
new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot())
|
||||
];
|
||||
}
|
||||
}
|
||||
// Try to add the shift to the existing lanes for this room
|
||||
$shift_added = false;
|
||||
foreach ($lanes[$room_id] as $lane) {
|
||||
$shift_added = $lane->addShift($shift);
|
||||
if ($shift_added == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach ($lanes[$room_id] as $lane) {
|
||||
$shift_added = $lane->addShift($shift);
|
||||
if ($shift_added == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If all lanes for this room are busy, create a new lane and add shift to it
|
||||
if ($shift_added == false) {
|
||||
$newLane = new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot());
|
||||
if (! $newLane->addShift($shift)) {
|
||||
engelsystem_error("Unable to add shift to new lane.");
|
||||
}
|
||||
$lanes[$room_id][] = $newLane;
|
||||
$newLane = new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot());
|
||||
if (! $newLane->addShift($shift)) {
|
||||
engelsystem_error("Unable to add shift to new lane.");
|
||||
}
|
||||
$lanes[$room_id][] = $newLane;
|
||||
}
|
||||
}
|
||||
|
||||
return $lanes;
|
||||
}
|
||||
|
||||
public function getFirstBlockStartTime()
|
||||
{
|
||||
return $this->firstBlockStartTime;
|
||||
}
|
||||
|
||||
return $lanes;
|
||||
}
|
||||
|
||||
public function getFirstBlockStartTime() {
|
||||
return $this->firstBlockStartTime;
|
||||
}
|
||||
|
||||
public function getLastBlockEndTime() {
|
||||
return $this->lastBlockEndTime;
|
||||
}
|
||||
|
||||
public function getBlocksPerSlot() {
|
||||
if ($this->blocksPerSlot == null) {
|
||||
$this->blocksPerSlot = $this->calcBlocksPerSlot();
|
||||
public function getLastBlockEndTime()
|
||||
{
|
||||
return $this->lastBlockEndTime;
|
||||
}
|
||||
|
||||
public function getBlocksPerSlot()
|
||||
{
|
||||
if ($this->blocksPerSlot == null) {
|
||||
$this->blocksPerSlot = $this->calcBlocksPerSlot();
|
||||
}
|
||||
return $this->blocksPerSlot;
|
||||
}
|
||||
return $this->blocksPerSlot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the whole calendar
|
||||
*
|
||||
* @return the generated html
|
||||
*/
|
||||
public function render() {
|
||||
if (count($this->lanes) == 0) {
|
||||
return '';
|
||||
}
|
||||
return div('shift-calendar', [
|
||||
public function render()
|
||||
{
|
||||
if (count($this->lanes) == 0) {
|
||||
return '';
|
||||
}
|
||||
return div('shift-calendar', [
|
||||
$this->renderTimeLane(),
|
||||
$this->renderShiftLanes()
|
||||
]) . $this->renderLegend();
|
||||
|
@ -126,15 +133,16 @@ class ShiftCalendarRenderer {
|
|||
/**
|
||||
* Renders the lanes containing the shifts
|
||||
*/
|
||||
private function renderShiftLanes() {
|
||||
$html = "";
|
||||
foreach ($this->lanes as $room_lanes) {
|
||||
foreach ($room_lanes as $lane) {
|
||||
$html .= $this->renderLane($lane);
|
||||
private function renderShiftLanes()
|
||||
{
|
||||
$html = "";
|
||||
foreach ($this->lanes as $room_lanes) {
|
||||
foreach ($room_lanes as $lane) {
|
||||
$html .= $this->renderLane($lane);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,30 +151,31 @@ class ShiftCalendarRenderer {
|
|||
* @param ShiftCalendarLane $lane
|
||||
* The lane to render
|
||||
*/
|
||||
private function renderLane(ShiftCalendarLane $lane) {
|
||||
global $user;
|
||||
private function renderLane(ShiftCalendarLane $lane)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$shift_renderer = new ShiftCalendarShiftRenderer();
|
||||
$html = "";
|
||||
$rendered_until = $this->getFirstBlockStartTime();
|
||||
$shift_renderer = new ShiftCalendarShiftRenderer();
|
||||
$html = "";
|
||||
$rendered_until = $this->getFirstBlockStartTime();
|
||||
|
||||
foreach ($lane->getShifts() as $shift) {
|
||||
while ($rendered_until + ShiftCalendarRenderer::SECONDS_PER_ROW <= $shift['start']) {
|
||||
$html .= $this->renderTick($rendered_until);
|
||||
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
|
||||
foreach ($lane->getShifts() as $shift) {
|
||||
while ($rendered_until + ShiftCalendarRenderer::SECONDS_PER_ROW <= $shift['start']) {
|
||||
$html .= $this->renderTick($rendered_until);
|
||||
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
|
||||
}
|
||||
|
||||
list($shift_height, $shift_html) = $shift_renderer->render($shift, $this->needed_angeltypes[$shift['SID']], $this->shift_entries[$shift['SID']], $user);
|
||||
$html .= $shift_html;
|
||||
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
|
||||
}
|
||||
|
||||
list($shift_height, $shift_html) = $shift_renderer->render($shift, $this->needed_angeltypes[$shift['SID']], $this->shift_entries[$shift['SID']], $user);
|
||||
$html .= $shift_html;
|
||||
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
|
||||
}
|
||||
while ($rendered_until < $this->getLastBlockEndTime()) {
|
||||
$html .= $this->renderTick($rendered_until);
|
||||
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
|
||||
}
|
||||
|
||||
while ($rendered_until < $this->getLastBlockEndTime()) {
|
||||
$html .= $this->renderTick($rendered_until);
|
||||
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
|
||||
}
|
||||
|
||||
return div('lane', [
|
||||
return div('lane', [
|
||||
div('header', $lane->getHeader()),
|
||||
$html
|
||||
]);
|
||||
|
@ -181,70 +190,76 @@ class ShiftCalendarRenderer {
|
|||
* Should time labels be generated?
|
||||
* @return rendered tick html
|
||||
*/
|
||||
private function renderTick($time, $label = false) {
|
||||
if ($time % (24 * 60 * 60) == 23 * 60 * 60) {
|
||||
if (! $label) {
|
||||
return div('tick day');
|
||||
}
|
||||
return div('tick day', [
|
||||
private function renderTick($time, $label = false)
|
||||
{
|
||||
if ($time % (24 * 60 * 60) == 23 * 60 * 60) {
|
||||
if (! $label) {
|
||||
return div('tick day');
|
||||
}
|
||||
return div('tick day', [
|
||||
date('m-d<b\r />H:i', $time)
|
||||
]);
|
||||
} elseif ($time % (60 * 60) == 0) {
|
||||
if (! $label) {
|
||||
return div('tick hour');
|
||||
}
|
||||
return div('tick hour', [
|
||||
} elseif ($time % (60 * 60) == 0) {
|
||||
if (! $label) {
|
||||
return div('tick hour');
|
||||
}
|
||||
return div('tick hour', [
|
||||
date('m-d<b\r />H:i', $time)
|
||||
]);
|
||||
}
|
||||
return div('tick');
|
||||
}
|
||||
return div('tick');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the left time lane including hour/day ticks
|
||||
*/
|
||||
private function renderTimeLane() {
|
||||
$time_slot = [
|
||||
private function renderTimeLane()
|
||||
{
|
||||
$time_slot = [
|
||||
div('header', [
|
||||
_("Time")
|
||||
])
|
||||
];
|
||||
for ($block = 0; $block < $this->getBlocksPerSlot(); $block ++) {
|
||||
$thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
$time_slot[] = $this->renderTick($thistime, true);
|
||||
}
|
||||
return div('lane time', $time_slot);
|
||||
}
|
||||
|
||||
private function calcFirstBlockStartTime($shifts) {
|
||||
$start_time = $this->shiftsFilter->getEndTime();
|
||||
foreach ($shifts as $shift) {
|
||||
if ($shift['start'] < $start_time) {
|
||||
$start_time = $shift['start'];
|
||||
for ($block = 0; $block < $this->getBlocksPerSlot(); $block ++) {
|
||||
$thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
$time_slot[] = $this->renderTick($thistime, true);
|
||||
}
|
||||
}
|
||||
return ShiftCalendarRenderer::SECONDS_PER_ROW * floor(($start_time - ShiftCalendarRenderer::TIME_MARGIN) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
return div('lane time', $time_slot);
|
||||
}
|
||||
|
||||
private function calcLastBlockEndTime($shifts) {
|
||||
$end_time = $this->shiftsFilter->getStartTime();
|
||||
foreach ($shifts as $shift) {
|
||||
if ($shift['end'] > $end_time) {
|
||||
$end_time = $shift['end'];
|
||||
}
|
||||
private function calcFirstBlockStartTime($shifts)
|
||||
{
|
||||
$start_time = $this->shiftsFilter->getEndTime();
|
||||
foreach ($shifts as $shift) {
|
||||
if ($shift['start'] < $start_time) {
|
||||
$start_time = $shift['start'];
|
||||
}
|
||||
}
|
||||
return ShiftCalendarRenderer::SECONDS_PER_ROW * floor(($start_time - ShiftCalendarRenderer::TIME_MARGIN) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
}
|
||||
return ShiftCalendarRenderer::SECONDS_PER_ROW * ceil(($end_time + ShiftCalendarRenderer::TIME_MARGIN) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
}
|
||||
|
||||
private function calcBlocksPerSlot() {
|
||||
return ceil(($this->getLastBlockEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
}
|
||||
private function calcLastBlockEndTime($shifts)
|
||||
{
|
||||
$end_time = $this->shiftsFilter->getStartTime();
|
||||
foreach ($shifts as $shift) {
|
||||
if ($shift['end'] > $end_time) {
|
||||
$end_time = $shift['end'];
|
||||
}
|
||||
}
|
||||
return ShiftCalendarRenderer::SECONDS_PER_ROW * ceil(($end_time + ShiftCalendarRenderer::TIME_MARGIN) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
}
|
||||
|
||||
private function calcBlocksPerSlot()
|
||||
{
|
||||
return ceil(($this->getLastBlockEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a legend explaining the shift coloring
|
||||
*/
|
||||
private function renderLegend() {
|
||||
return div('legend', [
|
||||
private function renderLegend()
|
||||
{
|
||||
return div('legend', [
|
||||
label(_('Your shift'), 'primary'),
|
||||
label(_('Help needed'), 'danger'),
|
||||
label(_('Other angeltype needed / collides with my shifts'), 'warning'),
|
||||
|
@ -253,5 +268,3 @@ class ShiftCalendarRenderer {
|
|||
]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -5,7 +5,8 @@ namespace Engelsystem;
|
|||
/**
|
||||
* Renders a single shift for the shift calendar
|
||||
*/
|
||||
class ShiftCalendarShiftRenderer {
|
||||
class ShiftCalendarShiftRenderer
|
||||
{
|
||||
|
||||
/**
|
||||
* Renders a shift
|
||||
|
@ -15,18 +16,19 @@ class ShiftCalendarShiftRenderer {
|
|||
* @param User $user
|
||||
* The user who is viewing the shift calendar
|
||||
*/
|
||||
public function render($shift, $needed_angeltypes, $shift_entries, $user) {
|
||||
$info_text = "";
|
||||
if ($shift['title'] != '') {
|
||||
$info_text = glyph('info-sign') . $shift['title'] . '<br>';
|
||||
}
|
||||
list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user);
|
||||
public function render($shift, $needed_angeltypes, $shift_entries, $user)
|
||||
{
|
||||
$info_text = "";
|
||||
if ($shift['title'] != '') {
|
||||
$info_text = glyph('info-sign') . $shift['title'] . '<br>';
|
||||
}
|
||||
list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user);
|
||||
|
||||
$class = $this->classForSignupState($shift_signup_state);
|
||||
$class = $this->classForSignupState($shift_signup_state);
|
||||
|
||||
$blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
$blocks = max(1, $blocks);
|
||||
return [
|
||||
$blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||
$blocks = max(1, $blocks);
|
||||
return [
|
||||
$blocks,
|
||||
div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [
|
||||
$this->renderShiftHead($shift),
|
||||
|
@ -43,8 +45,9 @@ class ShiftCalendarShiftRenderer {
|
|||
];
|
||||
}
|
||||
|
||||
private function classForSignupState(ShiftSignupState $shiftSignupState) {
|
||||
switch ($shiftSignupState->getState()) {
|
||||
private function classForSignupState(ShiftSignupState $shiftSignupState)
|
||||
{
|
||||
switch ($shiftSignupState->getState()) {
|
||||
case ShiftSignupState::ADMIN:
|
||||
case ShiftSignupState::OCCUPIED:
|
||||
return 'success';
|
||||
|
@ -62,50 +65,51 @@ class ShiftCalendarShiftRenderer {
|
|||
case ShiftSignupState::FREE:
|
||||
return 'danger';
|
||||
}
|
||||
}
|
||||
|
||||
private function renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user) {
|
||||
global $privileges;
|
||||
|
||||
$shift_entries_filtered = [];
|
||||
foreach ($needed_angeltypes as $needed_angeltype) {
|
||||
$shift_entries_filtered[$needed_angeltype['id']] = [];
|
||||
}
|
||||
foreach ($shift_entries as $shift_entry) {
|
||||
$shift_entries_filtered[$shift_entry['TID']][] = $shift_entry;
|
||||
}
|
||||
|
||||
$html = "";
|
||||
$shift_signup_state = null;
|
||||
foreach ($needed_angeltypes as $angeltype) {
|
||||
if ($angeltype['count'] > 0 || count($shift_entries_filtered[$angeltype['id']]) > 0) {
|
||||
list($angeltype_signup_state, $angeltype_html) = $this->renderShiftNeededAngeltype($shift, $shift_entries_filtered[$angeltype['id']], $angeltype, $user);
|
||||
if ($shift_signup_state == null) {
|
||||
$shift_signup_state = $angeltype_signup_state;
|
||||
} else {
|
||||
$shift_signup_state->combineWith($angeltype_signup_state);
|
||||
private function renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user)
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
$shift_entries_filtered = [];
|
||||
foreach ($needed_angeltypes as $needed_angeltype) {
|
||||
$shift_entries_filtered[$needed_angeltype['id']] = [];
|
||||
}
|
||||
foreach ($shift_entries as $shift_entry) {
|
||||
$shift_entries_filtered[$shift_entry['TID']][] = $shift_entry;
|
||||
}
|
||||
$html .= $angeltype_html;
|
||||
}
|
||||
}
|
||||
if ($shift_signup_state == null) {
|
||||
$shift_signup_state = new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, 0);
|
||||
}
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$html .= '<li class="list-group-item">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'], _("Add more angels"), 'btn-xs') . '</li>';
|
||||
}
|
||||
if ($html != '') {
|
||||
return [
|
||||
$html = "";
|
||||
$shift_signup_state = null;
|
||||
foreach ($needed_angeltypes as $angeltype) {
|
||||
if ($angeltype['count'] > 0 || count($shift_entries_filtered[$angeltype['id']]) > 0) {
|
||||
list($angeltype_signup_state, $angeltype_html) = $this->renderShiftNeededAngeltype($shift, $shift_entries_filtered[$angeltype['id']], $angeltype, $user);
|
||||
if ($shift_signup_state == null) {
|
||||
$shift_signup_state = $angeltype_signup_state;
|
||||
} else {
|
||||
$shift_signup_state->combineWith($angeltype_signup_state);
|
||||
}
|
||||
$html .= $angeltype_html;
|
||||
}
|
||||
}
|
||||
if ($shift_signup_state == null) {
|
||||
$shift_signup_state = new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, 0);
|
||||
}
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$html .= '<li class="list-group-item">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'], _("Add more angels"), 'btn-xs') . '</li>';
|
||||
}
|
||||
if ($html != '') {
|
||||
return [
|
||||
$shift_signup_state,
|
||||
'<ul class="list-group">' . $html . '</ul>'
|
||||
];
|
||||
}
|
||||
return [
|
||||
}
|
||||
return [
|
||||
$shift_signup_state,
|
||||
""
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a list entry containing the needed angels for an angeltype
|
||||
|
@ -117,15 +121,16 @@ class ShiftCalendarShiftRenderer {
|
|||
* @param User $user
|
||||
* The user who is viewing the shift calendar
|
||||
*/
|
||||
private function renderShiftNeededAngeltype($shift, $shift_entries, $angeltype, $user) {
|
||||
$entry_list = [];
|
||||
foreach ($shift_entries as $entry) {
|
||||
$style = $entry['freeloaded'] ? " text-decoration: line-through;" : '';
|
||||
$entry_list[] = "<span style=\"$style\">" . User_Nick_render($entry) . "</span>";
|
||||
}
|
||||
$shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, null, $angeltype, $shift_entries);
|
||||
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $shift_signup_state->getFreeEntries()), $shift_signup_state->getFreeEntries());
|
||||
switch ($shift_signup_state->getState()) {
|
||||
private function renderShiftNeededAngeltype($shift, $shift_entries, $angeltype, $user)
|
||||
{
|
||||
$entry_list = [];
|
||||
foreach ($shift_entries as $entry) {
|
||||
$style = $entry['freeloaded'] ? " text-decoration: line-through;" : '';
|
||||
$entry_list[] = "<span style=\"$style\">" . User_Nick_render($entry) . "</span>";
|
||||
}
|
||||
$shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, null, $angeltype, $shift_entries);
|
||||
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $shift_signup_state->getFreeEntries()), $shift_signup_state->getFreeEntries());
|
||||
switch ($shift_signup_state->getState()) {
|
||||
case ShiftSignupState::ADMIN:
|
||||
case ShiftSignupState::FREE:
|
||||
// When admin or free display a link + button for sign up
|
||||
|
@ -139,10 +144,10 @@ class ShiftCalendarShiftRenderer {
|
|||
|
||||
case ShiftSignupState::ANGELTYPE:
|
||||
if ($angeltype['restricted'] == 1) {
|
||||
// User has to be confirmed on the angeltype first
|
||||
// User has to be confirmed on the angeltype first
|
||||
$entry_list[] = $inner_text . glyph('lock');
|
||||
} else {
|
||||
// Add link to join the angeltype first
|
||||
// Add link to join the angeltype first
|
||||
$entry_list[] = $inner_text . '<br />' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs');
|
||||
}
|
||||
break;
|
||||
|
@ -158,11 +163,11 @@ class ShiftCalendarShiftRenderer {
|
|||
break;
|
||||
}
|
||||
|
||||
$shifts_row = '<li class="list-group-item">';
|
||||
$shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> ';
|
||||
$shifts_row .= join(", ", $entry_list);
|
||||
$shifts_row .= '</li>';
|
||||
return [
|
||||
$shifts_row = '<li class="list-group-item">';
|
||||
$shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> ';
|
||||
$shifts_row .= join(", ", $entry_list);
|
||||
$shifts_row .= '</li>';
|
||||
return [
|
||||
$shift_signup_state,
|
||||
$shifts_row
|
||||
];
|
||||
|
@ -174,22 +179,21 @@ class ShiftCalendarShiftRenderer {
|
|||
* @param Shift $shift
|
||||
* The shift
|
||||
*/
|
||||
private function renderShiftHead($shift) {
|
||||
global $privileges;
|
||||
private function renderShiftHead($shift)
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
$header_buttons = "";
|
||||
if (in_array('admin_shifts', $privileges)) {
|
||||
$header_buttons = '<div class="pull-right">' . table_buttons([
|
||||
$header_buttons = "";
|
||||
if (in_array('admin_shifts', $privileges)) {
|
||||
$header_buttons = '<div class="pull-right">' . table_buttons([
|
||||
button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
|
||||
button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs')
|
||||
]) . '</div>';
|
||||
}
|
||||
$shift_heading = date('H:i', $shift['start']) . ' ‐ ' . date('H:i', $shift['end']) . ' — ' . $shift['name'];
|
||||
return div('panel-heading', [
|
||||
}
|
||||
$shift_heading = date('H:i', $shift['start']) . ' ‐ ' . date('H:i', $shift['end']) . ' — ' . $shift['name'];
|
||||
return div('panel-heading', [
|
||||
'<a href="' . shift_link($shift) . '">' . $shift_heading . '</a>',
|
||||
$header_buttons
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -11,15 +11,16 @@
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment, $freeloaded, $freeload_comment, $user_admin_shifts = false) {
|
||||
$freeload_form = [];
|
||||
if ($user_admin_shifts) {
|
||||
$freeload_form = [
|
||||
function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment, $freeloaded, $freeload_comment, $user_admin_shifts = false)
|
||||
{
|
||||
$freeload_form = [];
|
||||
if ($user_admin_shifts) {
|
||||
$freeload_form = [
|
||||
form_checkbox('freeloaded', _("Freeloaded"), $freeloaded),
|
||||
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"), [
|
||||
msg(),
|
||||
form([
|
||||
form_info(_("Angel:"), $angel),
|
||||
|
@ -33,5 +34,3 @@ function ShiftEntry_edit_view($angel, $date, $location, $title, $type, $comment,
|
|||
])
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,15 +1,17 @@
|
|||
<?php
|
||||
|
||||
function ShiftType_name_render($shifttype) {
|
||||
global $privileges;
|
||||
if (in_array('shifttypes', $privileges)) {
|
||||
return '<a href="' . shifttype_link($shifttype) . '">' . $shifttype['name'] . '</a>';
|
||||
}
|
||||
return $shifttype['name'];
|
||||
function ShiftType_name_render($shifttype)
|
||||
{
|
||||
global $privileges;
|
||||
if (in_array('shifttypes', $privileges)) {
|
||||
return '<a href="' . shifttype_link($shifttype) . '">' . $shifttype['name'] . '</a>';
|
||||
}
|
||||
return $shifttype['name'];
|
||||
}
|
||||
|
||||
function ShiftType_delete_view($shifttype) {
|
||||
return page_with_title(sprintf(_("Delete shifttype %s"), $shifttype['name']), [
|
||||
function ShiftType_delete_view($shifttype)
|
||||
{
|
||||
return page_with_title(sprintf(_("Delete shifttype %s"), $shifttype['name']), [
|
||||
info(sprintf(_("Do you want to delete shifttype %s?"), $shifttype['name']), true),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), _("cancel"), 'cancel'),
|
||||
|
@ -18,15 +20,16 @@ function ShiftType_delete_view($shifttype) {
|
|||
]);
|
||||
}
|
||||
|
||||
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) {
|
||||
$angeltypes_select = [
|
||||
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
|
||||
{
|
||||
$angeltypes_select = [
|
||||
'' => _('All')
|
||||
];
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
$angeltypes_select[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
$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(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), shifttypes_title(), 'back')
|
||||
|
@ -41,13 +44,14 @@ function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $s
|
|||
]);
|
||||
}
|
||||
|
||||
function ShiftType_view($shifttype, $angeltype) {
|
||||
$parsedown = new Parsedown();
|
||||
$title = $shifttype['name'];
|
||||
if ($angeltype) {
|
||||
$title .= ' <small>' . sprintf(_('for team %s'), $angeltype['name']) . '</small>';
|
||||
}
|
||||
return page_with_title($title, [
|
||||
function ShiftType_view($shifttype, $angeltype)
|
||||
{
|
||||
$parsedown = new Parsedown();
|
||||
$title = $shifttype['name'];
|
||||
if ($angeltype) {
|
||||
$title .= ' <small>' . sprintf(_('for team %s'), $angeltype['name']) . '</small>';
|
||||
}
|
||||
return page_with_title($title, [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), shifttypes_title(), 'back'),
|
||||
|
@ -60,16 +64,17 @@ function ShiftType_view($shifttype, $angeltype) {
|
|||
]);
|
||||
}
|
||||
|
||||
function ShiftTypes_list_view($shifttypes) {
|
||||
foreach ($shifttypes as &$shifttype) {
|
||||
$shifttype['name'] = '<a href="' . page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id'] . '">' . $shifttype['name'] . '</a>';
|
||||
$shifttype['actions'] = table_buttons([
|
||||
function ShiftTypes_list_view($shifttypes)
|
||||
{
|
||||
foreach ($shifttypes as &$shifttype) {
|
||||
$shifttype['name'] = '<a href="' . page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id'] . '">' . $shifttype['name'] . '</a>';
|
||||
$shifttype['actions'] = table_buttons([
|
||||
button(page_link_to('shifttypes') . '&action=edit&shifttype_id=' . $shifttype['id'], _('edit'), 'btn-xs'),
|
||||
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'], _('delete'), 'btn-xs')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return page_with_title(shifttypes_title(), [
|
||||
return page_with_title(shifttypes_title(), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes') . '&action=edit', _('New shifttype'), 'add')
|
||||
|
@ -80,5 +85,3 @@ function ShiftTypes_list_view($shifttypes) {
|
|||
], $shifttypes)
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace Engelsystem;
|
||||
|
||||
class ShiftsFilterRenderer {
|
||||
class ShiftsFilterRenderer
|
||||
{
|
||||
|
||||
/**
|
||||
* The shiftFilter to render.
|
||||
|
@ -26,26 +27,28 @@ class ShiftsFilterRenderer {
|
|||
*/
|
||||
private $days = [];
|
||||
|
||||
public function __construct(ShiftsFilter $shiftsFilter) {
|
||||
$this->shiftsFilter = $shiftsFilter;
|
||||
}
|
||||
public function __construct(ShiftsFilter $shiftsFilter)
|
||||
{
|
||||
$this->shiftsFilter = $shiftsFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the filter.
|
||||
*
|
||||
* @return Generated HTML
|
||||
*/
|
||||
public function render($link_base) {
|
||||
$toolbar = [];
|
||||
if ($this->daySelectionEnabled && ! empty($this->days)) {
|
||||
$selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
|
||||
$day_dropdown_items = [];
|
||||
foreach ($this->days as $day) {
|
||||
$day_dropdown_items[] = toolbar_item_link($link_base . '&shifts_filter_day=' . $day, '', $day);
|
||||
public function render($link_base)
|
||||
{
|
||||
$toolbar = [];
|
||||
if ($this->daySelectionEnabled && ! empty($this->days)) {
|
||||
$selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
|
||||
$day_dropdown_items = [];
|
||||
foreach ($this->days as $day) {
|
||||
$day_dropdown_items[] = toolbar_item_link($link_base . '&shifts_filter_day=' . $day, '', $day);
|
||||
}
|
||||
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
|
||||
}
|
||||
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
|
||||
}
|
||||
return div('form-group', [
|
||||
return div('form-group', [
|
||||
toolbar_pills($toolbar)
|
||||
]);
|
||||
}
|
||||
|
@ -53,17 +56,17 @@ class ShiftsFilterRenderer {
|
|||
/**
|
||||
* Should the filter display a day selection.
|
||||
*/
|
||||
public function enableDaySelection($days) {
|
||||
$this->daySelectionEnabled = true;
|
||||
$this->days = $days;
|
||||
public function enableDaySelection($days)
|
||||
{
|
||||
$this->daySelectionEnabled = true;
|
||||
$this->days = $days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the filter display a day selection.
|
||||
*/
|
||||
public function isDaySelectionEnabled() {
|
||||
return $this->daySelectionEnabled;
|
||||
public function isDaySelectionEnabled()
|
||||
{
|
||||
return $this->daySelectionEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,53 +1,56 @@
|
|||
<?php
|
||||
use Engelsystem\ShiftSignupState;
|
||||
|
||||
function Shift_editor_info_render($shift) {
|
||||
$info = [];
|
||||
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'])));
|
||||
}
|
||||
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'])));
|
||||
}
|
||||
return join('<br />', $info);
|
||||
function Shift_editor_info_render($shift)
|
||||
{
|
||||
$info = [];
|
||||
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'])));
|
||||
}
|
||||
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'])));
|
||||
}
|
||||
return join('<br />', $info);
|
||||
}
|
||||
|
||||
function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null) {
|
||||
global $user;
|
||||
function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null)
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ($user_angeltype == null) {
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
}
|
||||
if ($user_angeltype == null) {
|
||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
||||
}
|
||||
|
||||
if ($angeltype['shift_signup_state']->isSignupAllowed()) {
|
||||
return button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'));
|
||||
} elseif ($user_angeltype == null) {
|
||||
return button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']));
|
||||
}
|
||||
return '';
|
||||
if ($angeltype['shift_signup_state']->isSignupAllowed()) {
|
||||
return button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'));
|
||||
} elseif ($user_angeltype == null) {
|
||||
return button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupState $shift_signup_state) {
|
||||
global $privileges;
|
||||
function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupState $shift_signup_state)
|
||||
{
|
||||
global $privileges;
|
||||
|
||||
$shift_admin = in_array('admin_shifts', $privileges);
|
||||
$user_shift_admin = in_array('user_shifts_admin', $privileges);
|
||||
$admin_rooms = in_array('admin_rooms', $privileges);
|
||||
$admin_shifttypes = in_array('shifttypes', $privileges);
|
||||
$shift_admin = in_array('admin_shifts', $privileges);
|
||||
$user_shift_admin = in_array('user_shifts_admin', $privileges);
|
||||
$admin_rooms = in_array('admin_rooms', $privileges);
|
||||
$admin_shifttypes = in_array('shifttypes', $privileges);
|
||||
|
||||
$parsedown = new Parsedown();
|
||||
$parsedown = new Parsedown();
|
||||
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype;
|
||||
}
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype;
|
||||
}
|
||||
|
||||
$needed_angels = '';
|
||||
foreach ($shift['NeedAngels'] as $needed_angeltype) {
|
||||
$needed_angels .= Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin);
|
||||
}
|
||||
$needed_angels = '';
|
||||
foreach ($shift['NeedAngels'] as $needed_angeltype) {
|
||||
$needed_angels .= Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin);
|
||||
}
|
||||
|
||||
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(),
|
||||
$shift_signup_state->getState() == ShiftSignupState::COLLIDES ? info(_('This shift collides with one of your shifts.'), true) : '',
|
||||
$shift_signup_state->getState() == ShiftSignupState::SIGNED_UP ? info(_('You are signed up for this shift.'), true) : '',
|
||||
|
@ -97,57 +100,59 @@ function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupSt
|
|||
]);
|
||||
}
|
||||
|
||||
function Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin) {
|
||||
global $user;
|
||||
function Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$angeltype = $angeltypes[$needed_angeltype['TID']];
|
||||
$angeltype_supporter = User_is_AngelType_supporter($user, $angeltype);
|
||||
$angeltype = $angeltypes[$needed_angeltype['TID']];
|
||||
$angeltype_supporter = User_is_AngelType_supporter($user, $angeltype);
|
||||
|
||||
$needed_angels = '';
|
||||
$needed_angels = '';
|
||||
|
||||
$class = 'progress-bar-warning';
|
||||
if ($needed_angeltype['taken'] == 0) {
|
||||
$class = 'progress-bar-danger';
|
||||
}
|
||||
if ($needed_angeltype['taken'] >= $needed_angeltype['count']) {
|
||||
$class = 'progress-bar-success';
|
||||
}
|
||||
$needed_angels .= '<div class="list-group-item">';
|
||||
|
||||
$needed_angels .= '<div class="pull-right">' . Shift_signup_button_render($shift, $angeltype) . '</div>';
|
||||
|
||||
$needed_angels .= '<h3>' . AngelType_name_render($angeltype) . '</h3>';
|
||||
$bar_max = max($needed_angeltype['count'] * 10, $needed_angeltype['taken'] * 10, 10);
|
||||
$bar_value = max(1, $needed_angeltype['taken'] * 10);
|
||||
$needed_angels .= progress_bar(0, $bar_max, $bar_value, $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']);
|
||||
|
||||
$angels = [];
|
||||
foreach ($shift['ShiftEntry'] as $shift_entry) {
|
||||
if ($shift_entry['TID'] == $needed_angeltype['TID']) {
|
||||
$angels[] = Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angeltype_supporter);
|
||||
$class = 'progress-bar-warning';
|
||||
if ($needed_angeltype['taken'] == 0) {
|
||||
$class = 'progress-bar-danger';
|
||||
}
|
||||
}
|
||||
if ($needed_angeltype['taken'] >= $needed_angeltype['count']) {
|
||||
$class = 'progress-bar-success';
|
||||
}
|
||||
$needed_angels .= '<div class="list-group-item">';
|
||||
|
||||
$needed_angels .= join(', ', $angels);
|
||||
$needed_angels .= '</div>';
|
||||
$needed_angels .= '<div class="pull-right">' . Shift_signup_button_render($shift, $angeltype) . '</div>';
|
||||
|
||||
return $needed_angels;
|
||||
$needed_angels .= '<h3>' . AngelType_name_render($angeltype) . '</h3>';
|
||||
$bar_max = max($needed_angeltype['count'] * 10, $needed_angeltype['taken'] * 10, 10);
|
||||
$bar_value = max(1, $needed_angeltype['taken'] * 10);
|
||||
$needed_angels .= progress_bar(0, $bar_max, $bar_value, $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']);
|
||||
|
||||
$angels = [];
|
||||
foreach ($shift['ShiftEntry'] as $shift_entry) {
|
||||
if ($shift_entry['TID'] == $needed_angeltype['TID']) {
|
||||
$angels[] = Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angeltype_supporter);
|
||||
}
|
||||
}
|
||||
|
||||
$needed_angels .= join(', ', $angels);
|
||||
$needed_angels .= '</div>';
|
||||
|
||||
return $needed_angels;
|
||||
}
|
||||
|
||||
function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angeltype_supporter) {
|
||||
$entry = User_Nick_render(User($shift_entry['UID']));
|
||||
if ($shift_entry['freeloaded']) {
|
||||
$entry = '<strike>' . $entry . '</strike>';
|
||||
}
|
||||
if ($user_shift_admin || $angeltype_supporter) {
|
||||
$entry .= ' <div class="btn-group">';
|
||||
if ($user_shift_admin) {
|
||||
$entry .= button_glyph(page_link_to('user_myshifts') . '&edit=' . $shift_entry['id'] . '&id=' . $shift_entry['UID'], 'pencil', 'btn-xs');
|
||||
function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angeltype_supporter)
|
||||
{
|
||||
$entry = User_Nick_render(User($shift_entry['UID']));
|
||||
if ($shift_entry['freeloaded']) {
|
||||
$entry = '<strike>' . $entry . '</strike>';
|
||||
}
|
||||
$entry .= button_glyph(page_link_to('user_shifts') . '&entry_id=' . $shift_entry['id'], 'trash', 'btn-xs');
|
||||
$entry .= '</div>';
|
||||
}
|
||||
return $entry;
|
||||
if ($user_shift_admin || $angeltype_supporter) {
|
||||
$entry .= ' <div class="btn-group">';
|
||||
if ($user_shift_admin) {
|
||||
$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_shifts') . '&entry_id=' . $shift_entry['id'], 'trash', 'btn-xs');
|
||||
$entry .= '</div>';
|
||||
}
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,9 +160,9 @@ function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angelty
|
|||
*
|
||||
* @param Shift $shift
|
||||
*/
|
||||
function shift_length($shift) {
|
||||
$length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ":";
|
||||
$length .= str_pad((($shift['end'] - $shift['start']) % (60 * 60)) / 60, 2, "0", STR_PAD_LEFT) . "h";
|
||||
return $length;
|
||||
function shift_length($shift)
|
||||
{
|
||||
$length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ":";
|
||||
$length .= str_pad((($shift['end'] - $shift['start']) % (60 * 60)) / 60, 2, "0", STR_PAD_LEFT) . "h";
|
||||
return $length;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
function UserAngelType_update_view($user_angeltype, $user, $angeltype, $supporter) {
|
||||
return page_with_title($supporter ? _("Add supporter rights") : _("Remove supporter rights"), [
|
||||
function UserAngelType_update_view($user_angeltype, $user, $angeltype, $supporter)
|
||||
{
|
||||
return page_with_title($supporter ? _("Add supporter rights") : _("Remove supporter rights"), [
|
||||
msg(),
|
||||
info(sprintf($supporter ? _("Do you really want to add supporter rights for %s to %s?") : _("Do you really want to remove supporter rights for %s from %s?"), $angeltype['name'], User_Nick_render($user)), true),
|
||||
buttons([
|
||||
|
@ -11,8 +12,9 @@ function UserAngelType_update_view($user_angeltype, $user, $angeltype, $supporte
|
|||
]);
|
||||
}
|
||||
|
||||
function UserAngelTypes_delete_all_view($angeltype) {
|
||||
return page_with_title(_("Deny all users"), [
|
||||
function UserAngelTypes_delete_all_view($angeltype)
|
||||
{
|
||||
return page_with_title(_("Deny all users"), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to deny all users for %s?"), $angeltype['name']), true),
|
||||
buttons([
|
||||
|
@ -22,8 +24,9 @@ function UserAngelTypes_delete_all_view($angeltype) {
|
|||
]);
|
||||
}
|
||||
|
||||
function UserAngelTypes_confirm_all_view($angeltype) {
|
||||
return page_with_title(_("Confirm all users"), [
|
||||
function UserAngelTypes_confirm_all_view($angeltype)
|
||||
{
|
||||
return page_with_title(_("Confirm all users"), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to confirm all users for %s?"), $angeltype['name']), true),
|
||||
buttons([
|
||||
|
@ -33,8 +36,9 @@ function UserAngelTypes_confirm_all_view($angeltype) {
|
|||
]);
|
||||
}
|
||||
|
||||
function UserAngelType_confirm_view($user_angeltype, $user, $angeltype) {
|
||||
return page_with_title(_("Confirm angeltype for user"), [
|
||||
function UserAngelType_confirm_view($user_angeltype, $user, $angeltype)
|
||||
{
|
||||
return page_with_title(_("Confirm angeltype for user"), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to confirm %s for %s?"), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
|
@ -44,8 +48,9 @@ function UserAngelType_confirm_view($user_angeltype, $user, $angeltype) {
|
|||
]);
|
||||
}
|
||||
|
||||
function UserAngelType_delete_view($user_angeltype, $user, $angeltype) {
|
||||
return page_with_title(_("Remove angeltype"), [
|
||||
function UserAngelType_delete_view($user_angeltype, $user, $angeltype)
|
||||
{
|
||||
return page_with_title(_("Remove angeltype"), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to delete %s from %s?"), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
|
@ -55,13 +60,14 @@ function UserAngelType_delete_view($user_angeltype, $user, $angeltype) {
|
|||
]);
|
||||
}
|
||||
|
||||
function UserAngelType_add_view($angeltype, $users_source, $user_id) {
|
||||
$users = [];
|
||||
foreach ($users_source as $user_source) {
|
||||
$users[$user_source['UID']] = User_Nick_render($user_source);
|
||||
}
|
||||
function UserAngelType_add_view($angeltype, $users_source, $user_id)
|
||||
{
|
||||
$users = [];
|
||||
foreach ($users_source as $user_source) {
|
||||
$users[$user_source['UID']] = User_Nick_render($user_source);
|
||||
}
|
||||
|
||||
return page_with_title(_("Add user to angeltype"), [
|
||||
return page_with_title(_("Add user to angeltype"), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("back"), 'back')
|
||||
|
@ -74,8 +80,9 @@ function UserAngelType_add_view($angeltype, $users_source, $user_id) {
|
|||
]);
|
||||
}
|
||||
|
||||
function UserAngelType_join_view($user, $angeltype) {
|
||||
return page_with_title(sprintf(_("Become a %s"), $angeltype['name']), [
|
||||
function UserAngelType_join_view($user, $angeltype)
|
||||
{
|
||||
return page_with_title(sprintf(_("Become a %s"), $angeltype['name']), [
|
||||
msg(),
|
||||
info(sprintf(_("Do you really want to add %s to %s?"), User_Nick_render($user), $angeltype['name']), true),
|
||||
buttons([
|
||||
|
@ -84,5 +91,3 @@ function UserAngelType_join_view($user, $angeltype) {
|
|||
])
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
|
@ -11,8 +11,9 @@
|
|||
* The user driver license
|
||||
* @return string
|
||||
*/
|
||||
function UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license) {
|
||||
return page_with_title(sprintf(_("Edit %s driving license information"), User_Nick_render($user_source)), [
|
||||
function UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
|
||||
{
|
||||
return page_with_title(sprintf(_("Edit %s driving license information"), User_Nick_render($user_source)), [
|
||||
buttons([
|
||||
button(user_link($user_source), _("Back to profile"), 'back')
|
||||
]),
|
||||
|
@ -52,5 +53,3 @@ function UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver
|
|||
</script>'
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
|
@ -2,24 +2,25 @@
|
|||
|
||||
namespace Engelsystem;
|
||||
|
||||
class UserHintsRenderer {
|
||||
class UserHintsRenderer
|
||||
{
|
||||
private $hints = [];
|
||||
|
||||
private $hints = [];
|
||||
|
||||
private $important = false;
|
||||
private $important = false;
|
||||
|
||||
/**
|
||||
* Render the added hints to a popover for the toolbar.
|
||||
*/
|
||||
public function render() {
|
||||
if (count($this->hints) > 0) {
|
||||
$hint_class = $this->important ? 'danger' : 'info';
|
||||
$glyphicon = $this->important ? 'warning-sign' : 'info-sign';
|
||||
public function render()
|
||||
{
|
||||
if (count($this->hints) > 0) {
|
||||
$hint_class = $this->important ? 'danger' : 'info';
|
||||
$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 '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,30 +31,31 @@ class UserHintsRenderer {
|
|||
* @param boolean $important
|
||||
* Is the hint important?
|
||||
*/
|
||||
public function addHint($hint, $important = false) {
|
||||
if ($hint != null && $hint != '') {
|
||||
if ($important) {
|
||||
$this->important = true;
|
||||
$this->hints[] = error($hint, true);
|
||||
} else {
|
||||
$this->hints[] = info($hint, true);
|
||||
public function addHint($hint, $important = false)
|
||||
{
|
||||
if ($hint != null && $hint != '') {
|
||||
if ($important) {
|
||||
$this->important = true;
|
||||
$this->hints[] = error($hint, true);
|
||||
} else {
|
||||
$this->hints[] = info($hint, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all hints.
|
||||
*/
|
||||
public function getHints() {
|
||||
return $this->hints;
|
||||
public function getHints()
|
||||
{
|
||||
return $this->hints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are there important hints? This leads to a more intensive icon.
|
||||
*/
|
||||
public function isImportant() {
|
||||
return $this->important;
|
||||
public function isImportant()
|
||||
{
|
||||
return $this->important;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -29,8 +29,9 @@ $tshirt_sizes = [
|
|||
* @param array<String> $themes
|
||||
* Available themes
|
||||
*/
|
||||
function User_settings_view($user_source, $locales, $themes, $buildup_start_date, $teardown_end_date, $enable_tshirt_size, $tshirt_sizes) {
|
||||
return page_with_title(settings_title(), [
|
||||
function User_settings_view($user_source, $locales, $themes, $buildup_start_date, $teardown_end_date, $enable_tshirt_size, $tshirt_sizes)
|
||||
{
|
||||
return page_with_title(settings_title(), [
|
||||
msg(),
|
||||
div('row', [
|
||||
div('col-md-6', [
|
||||
|
@ -82,10 +83,11 @@ function User_settings_view($user_source, $locales, $themes, $buildup_start_date
|
|||
/**
|
||||
* Displays the welcome message to the user and shows a login form.
|
||||
*/
|
||||
function User_registration_success_view($event_welcome_message) {
|
||||
$parsedown = new Parsedown();
|
||||
$event_welcome_message = $parsedown->text($event_welcome_message);
|
||||
return page_with_title(_("Registration successful"), [
|
||||
function User_registration_success_view($event_welcome_message)
|
||||
{
|
||||
$parsedown = new Parsedown();
|
||||
$event_welcome_message = $parsedown->text($event_welcome_message);
|
||||
return page_with_title(_("Registration successful"), [
|
||||
msg(),
|
||||
div('row', [
|
||||
div('col-md-4', [
|
||||
|
@ -117,8 +119,9 @@ function User_registration_success_view($event_welcome_message) {
|
|||
/**
|
||||
* Gui for deleting user with password field.
|
||||
*/
|
||||
function User_delete_view($user) {
|
||||
return page_with_title(sprintf(_("Delete %s"), User_Nick_render($user)), [
|
||||
function User_delete_view($user)
|
||||
{
|
||||
return page_with_title(sprintf(_("Delete %s"), User_Nick_render($user)), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(user_edit_link($user), glyph('chevron-left') . _("back"))
|
||||
|
@ -134,8 +137,9 @@ function User_delete_view($user) {
|
|||
/**
|
||||
* View for editing the number of given vouchers
|
||||
*/
|
||||
function User_edit_vouchers_view($user) {
|
||||
return page_with_title(sprintf(_("%s's vouchers"), User_Nick_render($user)), [
|
||||
function User_edit_vouchers_view($user)
|
||||
{
|
||||
return page_with_title(sprintf(_("%s's vouchers"), User_Nick_render($user)), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(user_link($user), glyph('chevron-left') . _("back"))
|
||||
|
@ -148,20 +152,21 @@ function User_edit_vouchers_view($user) {
|
|||
]);
|
||||
}
|
||||
|
||||
function Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count, $voucher_count) {
|
||||
foreach ($users as &$user) {
|
||||
$user['Nick'] = User_Nick_render($user);
|
||||
$user['Gekommen'] = glyph_bool($user['Gekommen']);
|
||||
$user['got_voucher'] = $user['got_voucher'];
|
||||
$user['Aktiv'] = glyph_bool($user['Aktiv']);
|
||||
$user['force_active'] = glyph_bool($user['force_active']);
|
||||
$user['Tshirt'] = glyph_bool($user['Tshirt']);
|
||||
$user['lastLogIn'] = date(_('m/d/Y h:i a'), $user['lastLogIn']);
|
||||
$user['actions'] = table_buttons([
|
||||
function Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count, $voucher_count)
|
||||
{
|
||||
foreach ($users as &$user) {
|
||||
$user['Nick'] = User_Nick_render($user);
|
||||
$user['Gekommen'] = glyph_bool($user['Gekommen']);
|
||||
$user['got_voucher'] = $user['got_voucher'];
|
||||
$user['Aktiv'] = glyph_bool($user['Aktiv']);
|
||||
$user['force_active'] = glyph_bool($user['force_active']);
|
||||
$user['Tshirt'] = glyph_bool($user['Tshirt']);
|
||||
$user['lastLogIn'] = date(_('m/d/Y h:i a'), $user['lastLogIn']);
|
||||
$user['actions'] = table_buttons([
|
||||
button_glyph(page_link_to('admin_user') . '&id=' . $user['UID'], 'edit', 'btn-xs')
|
||||
]);
|
||||
}
|
||||
$users[] = [
|
||||
}
|
||||
$users[] = [
|
||||
'Nick' => '<strong>' . _('Sum') . '</strong>',
|
||||
'Gekommen' => $arrived_count,
|
||||
'got_voucher' => $voucher_count,
|
||||
|
@ -172,7 +177,7 @@ function Users_view($users, $order_by, $arrived_count, $active_count, $force_act
|
|||
'actions' => '<strong>' . count($users) . '</strong>'
|
||||
];
|
||||
|
||||
return page_with_title(_("All users"), [
|
||||
return page_with_title(_("All users"), [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('register'), glyph('plus') . _("New user"))
|
||||
|
@ -195,66 +200,70 @@ function Users_view($users, $order_by, $arrived_count, $active_count, $force_act
|
|||
]);
|
||||
}
|
||||
|
||||
function Users_table_header_link($column, $label, $order_by) {
|
||||
return '<a href="' . page_link_to('users') . '&OrderBy=' . $column . '">' . $label . ($order_by == $column ? ' <span class="caret"></span>' : '') . '</a>';
|
||||
function Users_table_header_link($column, $label, $order_by)
|
||||
{
|
||||
return '<a href="' . page_link_to('users') . '&OrderBy=' . $column . '">' . $label . ($order_by == $column ? ' <span class="caret"></span>' : '') . '</a>';
|
||||
}
|
||||
|
||||
function User_shift_state_render($user) {
|
||||
$upcoming_shifts = ShiftEntries_upcoming_for_user($user);
|
||||
if ($upcoming_shifts === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($upcoming_shifts) == 0) {
|
||||
return '<span class="text-success">' . _("Free") . '</span>';
|
||||
}
|
||||
|
||||
if ($upcoming_shifts[0]['start'] > time()) {
|
||||
if ($upcoming_shifts[0]['start'] - time() > 3600) {
|
||||
return '<span class="text-success moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>';
|
||||
function User_shift_state_render($user)
|
||||
{
|
||||
$upcoming_shifts = ShiftEntries_upcoming_for_user($user);
|
||||
if ($upcoming_shifts === false) {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
|
||||
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]['end'] . '">' . _("Shift ends %c") . '</span>';
|
||||
if (count($upcoming_shifts) == 0) {
|
||||
return '<span class="text-success">' . _("Free") . '</span>';
|
||||
}
|
||||
|
||||
if ($upcoming_shifts[0]['start'] > time()) {
|
||||
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-warning moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>';
|
||||
}
|
||||
$halfway = ($upcoming_shifts[0]['start'] + $upcoming_shifts[0]['end']) / 2;
|
||||
|
||||
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]['end'] . '">' . _("Shift ends %c") . '</span>';
|
||||
}
|
||||
|
||||
function User_view_shiftentries($needed_angel_type) {
|
||||
$shift_info = '<br><b>' . $needed_angel_type['name'] . ':</b> ';
|
||||
function User_view_shiftentries($needed_angel_type)
|
||||
{
|
||||
$shift_info = '<br><b>' . $needed_angel_type['name'] . ':</b> ';
|
||||
|
||||
$shift_entries = [];
|
||||
foreach ($needed_angel_type['users'] as $user_shift) {
|
||||
$member = User_Nick_render($user_shift);
|
||||
if ($user_shift['freeloaded']) {
|
||||
$member = '<strike>' . $member . '</strike>';
|
||||
$shift_entries = [];
|
||||
foreach ($needed_angel_type['users'] as $user_shift) {
|
||||
$member = User_Nick_render($user_shift);
|
||||
if ($user_shift['freeloaded']) {
|
||||
$member = '<strike>' . $member . '</strike>';
|
||||
}
|
||||
|
||||
$shift_entries[] = $member;
|
||||
}
|
||||
$shift_info .= join(", ", $shift_entries);
|
||||
|
||||
$shift_entries[] = $member;
|
||||
}
|
||||
$shift_info .= join(", ", $shift_entries);
|
||||
|
||||
return $shift_info;
|
||||
return $shift_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper that renders a shift line for user view
|
||||
*/
|
||||
function User_view_myshift($shift, $user_source, $its_me) {
|
||||
global $LETZTES_AUSTRAGEN, $privileges;
|
||||
function User_view_myshift($shift, $user_source, $its_me)
|
||||
{
|
||||
global $LETZTES_AUSTRAGEN, $privileges;
|
||||
|
||||
$shift_info = '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>';
|
||||
if ($shift['title']) {
|
||||
$shift_info .= '<br /><a href="' . shift_link($shift) . '">' . $shift['title'] . '</a>';
|
||||
}
|
||||
foreach ($shift['needed_angeltypes'] as $needed_angel_type) {
|
||||
$shift_info .= User_view_shiftentries($needed_angel_type);
|
||||
}
|
||||
$shift_info = '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>';
|
||||
if ($shift['title']) {
|
||||
$shift_info .= '<br /><a href="' . shift_link($shift) . '">' . $shift['title'] . '</a>';
|
||||
}
|
||||
foreach ($shift['needed_angeltypes'] as $needed_angel_type) {
|
||||
$shift_info .= User_view_shiftentries($needed_angel_type);
|
||||
}
|
||||
|
||||
$myshift = [
|
||||
$myshift = [
|
||||
'date' => date("Y-m-d", $shift['start']),
|
||||
'time' => date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']),
|
||||
'room' => $shift['Name'],
|
||||
|
@ -262,46 +271,47 @@ function User_view_myshift($shift, $user_source, $its_me) {
|
|||
'comment' => $shift['Comment']
|
||||
];
|
||||
|
||||
if ($shift['freeloaded']) {
|
||||
if (in_array("user_shifts_admin", $privileges)) {
|
||||
$myshift['comment'] .= '<br /><p class="error">' . _("Freeloaded") . ': ' . $shift['freeload_comment'] . '</p>';
|
||||
} else {
|
||||
$myshift['comment'] .= '<br /><p class="error">' . _("Freeloaded") . '</p>';
|
||||
if ($shift['freeloaded']) {
|
||||
if (in_array("user_shifts_admin", $privileges)) {
|
||||
$myshift['comment'] .= '<br /><p class="error">' . _("Freeloaded") . ': ' . $shift['freeload_comment'] . '</p>';
|
||||
} else {
|
||||
$myshift['comment'] .= '<br /><p class="error">' . _("Freeloaded") . '</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$myshift['actions'] = [
|
||||
$myshift['actions'] = [
|
||||
button(shift_link($shift), glyph('eye-open') . _('view'), 'btn-xs')
|
||||
];
|
||||
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');
|
||||
}
|
||||
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'] = table_buttons($myshift['actions']);
|
||||
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');
|
||||
}
|
||||
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'] = table_buttons($myshift['actions']);
|
||||
|
||||
return $myshift;
|
||||
return $myshift;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper that prepares the shift table for user view
|
||||
*/
|
||||
function User_view_myshifts($shifts, $user_source, $its_me) {
|
||||
$myshifts_table = [];
|
||||
$timesum = 0;
|
||||
foreach ($shifts as $shift) {
|
||||
$myshifts_table[] = User_view_myshift($shift, $user_source, $its_me);
|
||||
function User_view_myshifts($shifts, $user_source, $its_me)
|
||||
{
|
||||
$myshifts_table = [];
|
||||
$timesum = 0;
|
||||
foreach ($shifts as $shift) {
|
||||
$myshifts_table[] = User_view_myshift($shift, $user_source, $its_me);
|
||||
|
||||
if ($shift['freeloaded']) {
|
||||
$timesum += (- 2 * ($shift['end'] - $shift['start']));
|
||||
} else {
|
||||
$timesum += ($shift['end'] - $shift['start']);
|
||||
if ($shift['freeloaded']) {
|
||||
$timesum += (- 2 * ($shift['end'] - $shift['start']));
|
||||
} else {
|
||||
$timesum += ($shift['end'] - $shift['start']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($myshifts_table) > 0) {
|
||||
$myshifts_table[] = [
|
||||
if (count($myshifts_table) > 0) {
|
||||
$myshifts_table[] = [
|
||||
'date' => '<b>' . _("Sum:") . '</b>',
|
||||
'time' => "<b>" . round($timesum / 3600, 1) . " h</b>",
|
||||
'room' => "",
|
||||
|
@ -309,18 +319,19 @@ function User_view_myshifts($shifts, $user_source, $its_me) {
|
|||
'comment' => "",
|
||||
'actions' => ""
|
||||
];
|
||||
}
|
||||
return $myshifts_table;
|
||||
}
|
||||
return $myshifts_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders view for a single user
|
||||
*/
|
||||
function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) {
|
||||
$user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']);
|
||||
$myshifts_table = User_view_myshifts($shifts, $user_source, $its_me);
|
||||
function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me)
|
||||
{
|
||||
$user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']);
|
||||
$myshifts_table = User_view_myshifts($shifts, $user_source, $its_me);
|
||||
|
||||
return page_with_title('<span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . ' <small>' . $user_name . '</small>', [
|
||||
return page_with_title('<span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . ' <small>' . $user_name . '</small>', [
|
||||
msg(),
|
||||
div('row space-top', [
|
||||
div('col-md-12', [
|
||||
|
@ -378,8 +389,9 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
|
|||
/**
|
||||
* View for password recovery step 1: E-Mail
|
||||
*/
|
||||
function User_password_recovery_view() {
|
||||
return page_with_title(user_password_recovery_title(), [
|
||||
function User_password_recovery_view()
|
||||
{
|
||||
return page_with_title(user_password_recovery_title(), [
|
||||
msg(),
|
||||
_("We will send you an e-mail with a password recovery link. Please use the email address you used for registration."),
|
||||
form([
|
||||
|
@ -392,8 +404,9 @@ function User_password_recovery_view() {
|
|||
/**
|
||||
* View for password recovery step 2: New password
|
||||
*/
|
||||
function User_password_set_view() {
|
||||
return page_with_title(user_password_recovery_title(), [
|
||||
function User_password_set_view()
|
||||
{
|
||||
return page_with_title(user_password_recovery_title(), [
|
||||
msg(),
|
||||
_("Please enter a new password."),
|
||||
form([
|
||||
|
@ -404,30 +417,32 @@ function User_password_set_view() {
|
|||
]);
|
||||
}
|
||||
|
||||
function User_angeltypes_render($user_angeltypes) {
|
||||
$output = [];
|
||||
foreach ($user_angeltypes as $angeltype) {
|
||||
$class = "";
|
||||
if ($angeltype['restricted'] == 1) {
|
||||
if ($angeltype['confirm_user_id'] != null) {
|
||||
$class = 'text-success';
|
||||
} else {
|
||||
$class = 'text-warning';
|
||||
}
|
||||
} else {
|
||||
$class = 'text-success';
|
||||
function User_angeltypes_render($user_angeltypes)
|
||||
{
|
||||
$output = [];
|
||||
foreach ($user_angeltypes as $angeltype) {
|
||||
$class = "";
|
||||
if ($angeltype['restricted'] == 1) {
|
||||
if ($angeltype['confirm_user_id'] != null) {
|
||||
$class = 'text-success';
|
||||
} else {
|
||||
$class = 'text-warning';
|
||||
}
|
||||
} else {
|
||||
$class = 'text-success';
|
||||
}
|
||||
$output[] = '<a href="' . angeltype_link($angeltype['id']) . '" class="' . $class . '">' . ($angeltype['supporter'] ? glyph('education') : '') . $angeltype['name'] . '</a>';
|
||||
}
|
||||
$output[] = '<a href="' . angeltype_link($angeltype['id']) . '" class="' . $class . '">' . ($angeltype['supporter'] ? glyph('education') : '') . $angeltype['name'] . '</a>';
|
||||
}
|
||||
return join('<br />', $output);
|
||||
return join('<br />', $output);
|
||||
}
|
||||
|
||||
function User_groups_render($user_groups) {
|
||||
$output = [];
|
||||
foreach ($user_groups as $group) {
|
||||
$output[] = substr($group['Name'], 2);
|
||||
}
|
||||
return join('<br />', $output);
|
||||
function User_groups_render($user_groups)
|
||||
{
|
||||
$output = [];
|
||||
foreach ($user_groups as $group) {
|
||||
$output[] = substr($group['Name'], 2);
|
||||
}
|
||||
return join('<br />', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -436,59 +451,63 @@ function User_groups_render($user_groups) {
|
|||
* @param User $user_source
|
||||
* @return string
|
||||
*/
|
||||
function User_Nick_render($user_source) {
|
||||
return '<a class="' . ($user_source['Gekommen'] ? '' : 'text-muted') . '" href="' . page_link_to('users') . '&action=view&user_id=' . $user_source['UID'] . '"><span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . '</a>';
|
||||
function User_Nick_render($user_source)
|
||||
{
|
||||
return '<a class="' . ($user_source['Gekommen'] ? '' : 'text-muted') . '" href="' . page_link_to('users') . '&action=view&user_id=' . $user_source['UID'] . '"><span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . '</a>';
|
||||
}
|
||||
|
||||
function render_user_departure_date_hint() {
|
||||
global $user;
|
||||
function render_user_departure_date_hint()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (! isset($user['planned_departure_date']) || $user['planned_departure_date'] == null) {
|
||||
return _("Please enter your planned date of departure on your settings page to give us a feeling for teardown capacities.");
|
||||
}
|
||||
if (! isset($user['planned_departure_date']) || $user['planned_departure_date'] == null) {
|
||||
return _("Please enter your planned date of departure on your settings page to give us a feeling for teardown capacities.");
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
function render_user_freeloader_hint() {
|
||||
global $user, $max_freeloadable_shifts;
|
||||
function render_user_freeloader_hint()
|
||||
{
|
||||
global $user, $max_freeloadable_shifts;
|
||||
|
||||
if (User_is_freeloader($user)) {
|
||||
return sprintf(_("You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again."), $max_freeloadable_shifts);
|
||||
}
|
||||
if (User_is_freeloader($user)) {
|
||||
return sprintf(_("You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again."), $max_freeloadable_shifts);
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Hinweis für Engel, die noch nicht angekommen sind
|
||||
function render_user_arrived_hint() {
|
||||
global $user;
|
||||
function render_user_arrived_hint()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ($user['Gekommen'] == 0) {
|
||||
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.");
|
||||
}
|
||||
if ($user['Gekommen'] == 0) {
|
||||
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 null;
|
||||
return null;
|
||||
}
|
||||
|
||||
function render_user_tshirt_hint() {
|
||||
global $enable_tshirt_size, $user;
|
||||
function render_user_tshirt_hint()
|
||||
{
|
||||
global $enable_tshirt_size, $user;
|
||||
|
||||
if ($enable_tshirt_size && $user['Size'] == "") {
|
||||
return _("You need to specify a tshirt size in your settings!");
|
||||
}
|
||||
if ($enable_tshirt_size && $user['Size'] == "") {
|
||||
return _("You need to specify a tshirt size in your settings!");
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
function render_user_dect_hint() {
|
||||
global $user;
|
||||
function render_user_dect_hint()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ($user['DECT'] == "") {
|
||||
return _("You need to specify a DECT phone number in your settings! If you don't have a DECT phone, just enter \"-\".");
|
||||
}
|
||||
if ($user['DECT'] == "") {
|
||||
return _("You need to specify a DECT phone number in your settings! If you don't have a DECT phone, just enter \"-\".");
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
254
public/index.php
254
public/index.php
|
@ -22,140 +22,140 @@ $free_pages = [
|
|||
// Gewünschte Seite/Funktion
|
||||
$page = "";
|
||||
if (! isset($_REQUEST['p'])) {
|
||||
$_REQUEST['p'] = isset($user) ? "news" : "login";
|
||||
$_REQUEST['p'] = isset($user) ? "news" : "login";
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && (in_array($_REQUEST['p'], $free_pages) || in_array($_REQUEST['p'], $privileges))) {
|
||||
$page = $_REQUEST['p'];
|
||||
$page = $_REQUEST['p'];
|
||||
|
||||
$title = $page;
|
||||
$content = "";
|
||||
$title = $page;
|
||||
$content = "";
|
||||
|
||||
if ($page == "api") {
|
||||
require_once realpath(__DIR__ . '/../includes/controller/api.php');
|
||||
error("Api disabled temporily.");
|
||||
redirect(page_link_to('login'));
|
||||
api_controller();
|
||||
} elseif ($page == "ical") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_ical.php');
|
||||
user_ical();
|
||||
} elseif ($page == "atom") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_atom.php');
|
||||
user_atom();
|
||||
} elseif ($page == "shifts_json_export") {
|
||||
require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php');
|
||||
shifts_json_export_controller();
|
||||
} elseif ($page == "shifts_json_export_all") {
|
||||
require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php');
|
||||
shifts_json_export_all_controller();
|
||||
} elseif ($page == "stats") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/guest_stats.php');
|
||||
guest_stats();
|
||||
} elseif ($page == "user_password_recovery") {
|
||||
require_once realpath(__DIR__ . '/../includes/controller/users_controller.php');
|
||||
$title = user_password_recovery_title();
|
||||
$content = user_password_recovery_controller();
|
||||
} elseif ($page == "angeltypes") {
|
||||
list($title, $content) = angeltypes_controller();
|
||||
} elseif ($page == "shifts") {
|
||||
list($title, $content) = shifts_controller();
|
||||
} elseif ($page == "users") {
|
||||
list($title, $content) = users_controller();
|
||||
} elseif ($page == "user_angeltypes") {
|
||||
list($title, $content) = user_angeltypes_controller();
|
||||
} elseif ($page == "user_driver_licenses") {
|
||||
list($title, $content) = user_driver_licenses_controller();
|
||||
} elseif ($page == "shifttypes") {
|
||||
list($title, $content) = shifttypes_controller();
|
||||
} elseif ($page == "admin_event_config") {
|
||||
list($title, $content) = event_config_edit_controller();
|
||||
} elseif ($page == "rooms") {
|
||||
list($title, $content) = rooms_controller();
|
||||
} elseif ($page == "news") {
|
||||
$title = news_title();
|
||||
$content = user_news();
|
||||
} elseif ($page == "news_comments") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_news.php');
|
||||
$title = user_news_comments_title();
|
||||
$content = user_news_comments();
|
||||
} elseif ($page == "user_meetings") {
|
||||
$title = meetings_title();
|
||||
$content = user_meetings();
|
||||
} elseif ($page == "user_myshifts") {
|
||||
$title = myshifts_title();
|
||||
$content = user_myshifts();
|
||||
} elseif ($page == "user_shifts") {
|
||||
$title = shifts_title();
|
||||
$content = user_shifts();
|
||||
} elseif ($page == "user_messages") {
|
||||
$title = messages_title();
|
||||
$content = user_messages();
|
||||
} elseif ($page == "user_questions") {
|
||||
$title = questions_title();
|
||||
$content = user_questions();
|
||||
} elseif ($page == "user_settings") {
|
||||
$title = settings_title();
|
||||
$content = user_settings();
|
||||
} elseif ($page == "login") {
|
||||
$title = login_title();
|
||||
$content = guest_login();
|
||||
} elseif ($page == "register") {
|
||||
$title = register_title();
|
||||
$content = guest_register();
|
||||
} elseif ($page == "logout") {
|
||||
$title = logout_title();
|
||||
$content = guest_logout();
|
||||
} elseif ($page == "admin_questions") {
|
||||
$title = admin_questions_title();
|
||||
$content = admin_questions();
|
||||
} elseif ($page == "admin_user") {
|
||||
$title = admin_user_title();
|
||||
$content = admin_user();
|
||||
} elseif ($page == "admin_arrive") {
|
||||
$title = admin_arrive_title();
|
||||
$content = admin_arrive();
|
||||
} elseif ($page == "admin_active") {
|
||||
$title = admin_active_title();
|
||||
$content = admin_active();
|
||||
} elseif ($page == "admin_free") {
|
||||
$title = admin_free_title();
|
||||
$content = admin_free();
|
||||
} elseif ($page == "admin_news") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_news.php');
|
||||
$content = admin_news();
|
||||
} elseif ($page == "admin_rooms") {
|
||||
$title = admin_rooms_title();
|
||||
$content = admin_rooms();
|
||||
} elseif ($page == "admin_groups") {
|
||||
$title = admin_groups_title();
|
||||
$content = admin_groups();
|
||||
} elseif ($page == "admin_language") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_language.php');
|
||||
$content = admin_language();
|
||||
} elseif ($page == "admin_import") {
|
||||
$title = admin_import_title();
|
||||
$content = admin_import();
|
||||
} elseif ($page == "admin_shifts") {
|
||||
$title = admin_shifts_title();
|
||||
$content = admin_shifts();
|
||||
} elseif ($page == "admin_log") {
|
||||
$title = admin_log_title();
|
||||
$content = admin_log();
|
||||
} elseif ($page == "credits") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/guest_credits.php');
|
||||
$title = credits_title();
|
||||
$content = guest_credits();
|
||||
} else {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/guest_start.php');
|
||||
$content = guest_start();
|
||||
}
|
||||
if ($page == "api") {
|
||||
require_once realpath(__DIR__ . '/../includes/controller/api.php');
|
||||
error("Api disabled temporily.");
|
||||
redirect(page_link_to('login'));
|
||||
api_controller();
|
||||
} elseif ($page == "ical") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_ical.php');
|
||||
user_ical();
|
||||
} elseif ($page == "atom") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_atom.php');
|
||||
user_atom();
|
||||
} elseif ($page == "shifts_json_export") {
|
||||
require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php');
|
||||
shifts_json_export_controller();
|
||||
} elseif ($page == "shifts_json_export_all") {
|
||||
require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php');
|
||||
shifts_json_export_all_controller();
|
||||
} elseif ($page == "stats") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/guest_stats.php');
|
||||
guest_stats();
|
||||
} elseif ($page == "user_password_recovery") {
|
||||
require_once realpath(__DIR__ . '/../includes/controller/users_controller.php');
|
||||
$title = user_password_recovery_title();
|
||||
$content = user_password_recovery_controller();
|
||||
} elseif ($page == "angeltypes") {
|
||||
list($title, $content) = angeltypes_controller();
|
||||
} elseif ($page == "shifts") {
|
||||
list($title, $content) = shifts_controller();
|
||||
} elseif ($page == "users") {
|
||||
list($title, $content) = users_controller();
|
||||
} elseif ($page == "user_angeltypes") {
|
||||
list($title, $content) = user_angeltypes_controller();
|
||||
} elseif ($page == "user_driver_licenses") {
|
||||
list($title, $content) = user_driver_licenses_controller();
|
||||
} elseif ($page == "shifttypes") {
|
||||
list($title, $content) = shifttypes_controller();
|
||||
} elseif ($page == "admin_event_config") {
|
||||
list($title, $content) = event_config_edit_controller();
|
||||
} elseif ($page == "rooms") {
|
||||
list($title, $content) = rooms_controller();
|
||||
} elseif ($page == "news") {
|
||||
$title = news_title();
|
||||
$content = user_news();
|
||||
} elseif ($page == "news_comments") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/user_news.php');
|
||||
$title = user_news_comments_title();
|
||||
$content = user_news_comments();
|
||||
} elseif ($page == "user_meetings") {
|
||||
$title = meetings_title();
|
||||
$content = user_meetings();
|
||||
} elseif ($page == "user_myshifts") {
|
||||
$title = myshifts_title();
|
||||
$content = user_myshifts();
|
||||
} elseif ($page == "user_shifts") {
|
||||
$title = shifts_title();
|
||||
$content = user_shifts();
|
||||
} elseif ($page == "user_messages") {
|
||||
$title = messages_title();
|
||||
$content = user_messages();
|
||||
} elseif ($page == "user_questions") {
|
||||
$title = questions_title();
|
||||
$content = user_questions();
|
||||
} elseif ($page == "user_settings") {
|
||||
$title = settings_title();
|
||||
$content = user_settings();
|
||||
} elseif ($page == "login") {
|
||||
$title = login_title();
|
||||
$content = guest_login();
|
||||
} elseif ($page == "register") {
|
||||
$title = register_title();
|
||||
$content = guest_register();
|
||||
} elseif ($page == "logout") {
|
||||
$title = logout_title();
|
||||
$content = guest_logout();
|
||||
} elseif ($page == "admin_questions") {
|
||||
$title = admin_questions_title();
|
||||
$content = admin_questions();
|
||||
} elseif ($page == "admin_user") {
|
||||
$title = admin_user_title();
|
||||
$content = admin_user();
|
||||
} elseif ($page == "admin_arrive") {
|
||||
$title = admin_arrive_title();
|
||||
$content = admin_arrive();
|
||||
} elseif ($page == "admin_active") {
|
||||
$title = admin_active_title();
|
||||
$content = admin_active();
|
||||
} elseif ($page == "admin_free") {
|
||||
$title = admin_free_title();
|
||||
$content = admin_free();
|
||||
} elseif ($page == "admin_news") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_news.php');
|
||||
$content = admin_news();
|
||||
} elseif ($page == "admin_rooms") {
|
||||
$title = admin_rooms_title();
|
||||
$content = admin_rooms();
|
||||
} elseif ($page == "admin_groups") {
|
||||
$title = admin_groups_title();
|
||||
$content = admin_groups();
|
||||
} elseif ($page == "admin_language") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/admin_language.php');
|
||||
$content = admin_language();
|
||||
} elseif ($page == "admin_import") {
|
||||
$title = admin_import_title();
|
||||
$content = admin_import();
|
||||
} elseif ($page == "admin_shifts") {
|
||||
$title = admin_shifts_title();
|
||||
$content = admin_shifts();
|
||||
} elseif ($page == "admin_log") {
|
||||
$title = admin_log_title();
|
||||
$content = admin_log();
|
||||
} elseif ($page == "credits") {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/guest_credits.php');
|
||||
$title = credits_title();
|
||||
$content = guest_credits();
|
||||
} else {
|
||||
require_once realpath(__DIR__ . '/../includes/pages/guest_start.php');
|
||||
$content = guest_start();
|
||||
}
|
||||
} else {
|
||||
// Wenn schon eingeloggt, keine-Berechtigung-Seite anzeigen
|
||||
// Wenn schon eingeloggt, keine-Berechtigung-Seite anzeigen
|
||||
if (isset($user)) {
|
||||
$title = _("No Access");
|
||||
$content = _("You don't have permission to view this page. You probably have to sign in or register in order to gain access!");
|
||||
$title = _("No Access");
|
||||
$content = _("You don't have permission to view this page. You probably have to sign in or register in order to gain access!");
|
||||
} else {
|
||||
// Sonst zur Loginseite leiten
|
||||
// Sonst zur Loginseite leiten
|
||||
redirect(page_link_to("login"));
|
||||
}
|
||||
}
|
||||
|
@ -174,5 +174,3 @@ echo template_render(__DIR__ . '/../templates/layout.html', [
|
|||
'locale' => locale(),
|
||||
'event_info' => EventConfig_info($event_config) . '<br />'
|
||||
]);
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,33 +2,35 @@
|
|||
|
||||
namespace Engelsystem\Test;
|
||||
|
||||
class LogEntriesModelTest extends \PHPUnit_Framework_TestCase {
|
||||
class LogEntriesModelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function create_LogEntry()
|
||||
{
|
||||
LogEntry_create('test', 'test');
|
||||
}
|
||||
|
||||
public function create_LogEntry() {
|
||||
LogEntry_create('test', 'test');
|
||||
}
|
||||
|
||||
public function test_LogEntry_create() {
|
||||
$count = count(LogEntries());
|
||||
$this->assertNotFalse(LogEntry_create('test', 'test_LogEntry_create'));
|
||||
public function test_LogEntry_create()
|
||||
{
|
||||
$count = count(LogEntries());
|
||||
$this->assertNotFalse(LogEntry_create('test', 'test_LogEntry_create'));
|
||||
|
||||
// There should be one more log entry now
|
||||
$this->assertEquals(count(LogEntries()), $count + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_LogEntries_clear_all() {
|
||||
$this->create_LogEntry();
|
||||
$this->assertTrue(count(LogEntries()) > 0);
|
||||
$this->assertNotFalse(LogEntries_clear_all());
|
||||
$this->assertEquals(count(LogEntries()), 0);
|
||||
}
|
||||
public function test_LogEntries_clear_all()
|
||||
{
|
||||
$this->create_LogEntry();
|
||||
$this->assertTrue(count(LogEntries()) > 0);
|
||||
$this->assertNotFalse(LogEntries_clear_all());
|
||||
$this->assertEquals(count(LogEntries()), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @after
|
||||
*/
|
||||
public function teardown() {
|
||||
LogEntries_clear_all();
|
||||
public function teardown()
|
||||
{
|
||||
LogEntries_clear_all();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,34 +2,35 @@
|
|||
|
||||
namespace Engelsystem\Test;
|
||||
|
||||
class RoomModelTest extends \PHPUnit_Framework_TestCase {
|
||||
class RoomModelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $room_id = null;
|
||||
|
||||
private $room_id = null;
|
||||
public function create_Room()
|
||||
{
|
||||
$this->room_id = Room_create('test', false, true, '');
|
||||
}
|
||||
|
||||
public function create_Room() {
|
||||
$this->room_id = Room_create('test', false, true, '');
|
||||
}
|
||||
public function test_Room()
|
||||
{
|
||||
$this->create_Room();
|
||||
|
||||
public function test_Room() {
|
||||
$this->create_Room();
|
||||
$room = Room($this->room_id);
|
||||
|
||||
$room = Room($this->room_id);
|
||||
$this->assertNotFalse($room);
|
||||
$this->assertNotNull($room);
|
||||
$this->assertEquals($room['Name'], 'test');
|
||||
|
||||
$this->assertNotFalse($room);
|
||||
$this->assertNotNull($room);
|
||||
$this->assertEquals($room['Name'], 'test');
|
||||
|
||||
$this->assertNull(Room(- 1));
|
||||
}
|
||||
$this->assertNull(Room(- 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @after
|
||||
*/
|
||||
public function teardown() {
|
||||
if ($this->room_id != null) {
|
||||
Room_delete($this->room_id);
|
||||
}
|
||||
public function teardown()
|
||||
{
|
||||
if ($this->room_id != null) {
|
||||
Room_delete($this->room_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue