function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angeltypes, $admin_angeltypes, $coordinator, $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['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');
    }
    if ($admin_angeltypes || $coordinator) {
        $buttons[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), 'edit');
    }
    if ($admin_angeltypes) {
        $buttons[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), 'delete');
    }
    $page = array(msg(), buttons($buttons));
    $page[] = '<h3>' . _("Description") . '</h3>';
    $parsedown = new Parsedown();
    if ($angeltype['description'] != "") {
        $page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
    }
    $coordinators = array();
    $members_confirmed = array();
    $members_unconfirmed = array();
    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['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['coordinator']) {
            if ($admin_angeltypes) {
                $member['actions'] = table_buttons([button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&coordinator=0', _("Remove coordinator rights"), 'btn-xs')]);
            } else {
                $member['actions'] = '';
            }
            $coordinators[] = $member;
        } else {
            if ($admin_user_angeltypes) {
                $member['actions'] = table_buttons([$admin_angeltypes ? button(page_link_to('user_angeltypes') . '&action=update&user_angeltype_id=' . $member['user_angeltype_id'] . '&coordinator=1', _("Add coordinator rights"), 'btn-xs') : '', button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $member['user_angeltype_id'], _("remove"), 'btn-xs')]);
            }
            $members_confirmed[] = $member;
        }
    }
    $table_headers = ['Nick' => _("Nick"), 'DECT' => _("DECT"), 'actions' => ''];
    if ($angeltype['requires_driver_license'] && ($coordinator || $admin_angeltypes)) {
        $table_headers = ['Nick' => _("Nick"), 'DECT' => _("DECT"), 'wants_to_drive' => _("Driver"), 'has_car' => _("Has car"), 'has_license_car' => _("Car"), 'has_license_3_5t_transporter' => _("3,5t Transporter"), 'has_license_7_5t_truck' => _("7,5t Truck"), 'has_license_12_5t_truck' => _("12,5t Truck"), 'has_license_forklift' => _("Forklift"), 'actions' => ''];
    }
    if (count($coordinators) > 0) {
        $page[] = '<h3>' . _("Coordinators") . '</h3>';
        $page[] = table($table_headers, $coordinators);
    }
    if (count($members_confirmed) > 0) {
        $members_confirmed[] = ['Nick' => _('Sum'), 'DECT' => count($members_confirmed), 'actions' => ''];
    }
    if (count($members_unconfirmed) > 0) {
        $members_unconfirmed[] = ['Nick' => _('Sum'), 'DECT' => count($members_unconfirmed), 'actions' => ''];
    }
    $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);
    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);
    }
    return page_with_title(sprintf(_("Team %s"), $angeltype['name']), $page);
}
Beispiel #2
0
function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me)
{
    global $LETZTES_AUSTRAGEN, $privileges;
    $user_name = htmlspecialchars($user_source['Vorname']) . " " . htmlspecialchars($user_source['Name']);
    $myshifts_table = array();
    $html = "";
    $timesum = 0;
    foreach ($shifts as $shift) {
        $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 .= '<br><b>' . $needed_angel_type['name'] . ':</b> ';
            $shift_entries = array();
            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);
        }
        $myshift = array('date' => date("Y-m-d", $shift['start']), 'time' => date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']), 'room' => $shift['Name'], 'shift_info' => $shift_info, '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>';
            }
        }
        $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 ($shift['freeloaded']) {
            $timesum += -2 * ($shift['end'] - $shift['start']);
        } else {
            $timesum += $shift['end'] - $shift['start'];
        }
        $myshifts_table[] = $myshift;
    }
    if (count($myshifts_table) > 0) {
        $myshifts_table[] = array('date' => '<b>' . _("Sum:") . '</b>', 'time' => "<b>" . round($timesum / 3600, 1) . " h</b>", 'room' => "", 'shift_info' => "", 'comment' => "", 'actions' => "");
    }
    return page_with_title('<span class="icon-icon_angel"></span> ' . htmlspecialchars($user_source['Nick']) . ' <small>' . $user_name . '</small>', array(msg(), div('row', array(div('col-md-3', array('<h1>', '<span class="glyphicon glyphicon-phone"></span>', $user_source['DECT'], '</h1>')), div('col-md-3', array('<h4>' . _("User state") . '</h4>', $admin_user_privilege && $freeloader ? '<span class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> ' . _("Freeloader") . '</span><br />' : '', $user_source['Gekommen'] ? User_shift_state_render($user_source) . '<br />' : '', $admin_user_privilege || $its_me ? $user_source['Gekommen'] ? '<span class="text-success"><span class="glyphicon glyphicon-home"></span> ' . sprintf(_("Arrived at %s"), date('Y-m-d', $user_source['arrival_date'])) . '</span>' : '<span class="text-danger">' . sprintf(_("Not arrived (Planned: %s)"), date('Y-m-d', $user_source['planned_arrival_date'])) . '</span>' : ($user_source['Gekommen'] ? '<span class="text-success"><span class="glyphicon glyphicon-home"></span> ' . _("Arrived") . '</span>' : '<span class="text-danger">' . _("Not arrived") . '</span>'), $admin_user_privilege ? $user_source['got_voucher'] > 0 ? '<br /><span class="text-success">' . glyph('cutlery') . sprintf(ngettext("Got %s voucher", "Got %s vouchers", $user_source['got_voucher']), $user_source['got_voucher']) . '</span><br />' : '<br /><span class="text-danger">' . _("Got no vouchers") . '</span><br />' : '', $user_source['Gekommen'] && $admin_user_privilege && $user_source['Aktiv'] ? ' <span class="text-success">' . _("Active") . '</span>' : '', $user_source['Gekommen'] && $admin_user_privilege && $user_source['Tshirt'] ? ' <span class="text-success">' . _("T-Shirt") . '</span>' : '')), div('col-md-3', array('<h4>' . _("Angeltypes") . '</h4>', User_angeltypes_render($user_angeltypes))), div('col-md-3', array('<h4>' . _("Rights") . '</h4>', User_groups_render($user_groups))))), div('row space-top', array(div('col-md-12', array(buttons(array($admin_user_privilege ? button(page_link_to('admin_user') . '&id=' . $user_source['UID'], glyph("edit") . _("edit")) : '', $admin_user_privilege ? button(user_driver_license_edit_link($user_source), glyph("road") . _("driving license")) : '', $admin_user_privilege && !$user_source['Gekommen'] ? button(page_link_to('admin_arrive') . '&arrived=' . $user_source['UID'], _("arrived")) : '', $admin_user_privilege ? button(page_link_to('users') . '&action=edit_vouchers&user_id=' . $user_source['UID'], glyph('cutlery') . _('Edit vouchers')) : '', $its_me ? button(page_link_to('user_settings'), glyph('list-alt') . _("Settings")) : '', $its_me ? button(page_link_to('ical') . '&key=' . $user_source['api_key'], glyph('calendar') . _("iCal Export")) : '', $its_me ? button(page_link_to('shifts_json_export') . '&key=' . $user_source['api_key'], glyph('export') . _("JSON Export")) : '', $its_me ? button(page_link_to('user_myshifts') . '&reset', glyph('repeat') . _('Reset API key')) : '')))))), $its_me || $admin_user_privilege ? '<h2>' . _("Shifts") . '</h2>' : '', $its_me || $admin_user_privilege ? table(array('date' => _("Day"), 'time' => _("Time"), 'room' => _("Location"), 'shift_info' => _("Name &amp; workmates"), 'comment' => _("Comment"), 'actions' => _("Action")), $myshifts_table) : '', $its_me ? info(glyph('info-sign') . _("Your night shifts between 2 and 8 am count twice."), true) : '', $its_me && count($shifts) == 0 ? error(sprintf(_("Go to the <a href=\"%s\">shifts table</a> to sign yourself up for some shifts."), page_link_to('user_shifts')), true) : ''));
}
/**
 * Edit a users driver license information.
 */
function user_driver_license_edit_controller()
{
    global $privileges, $user;
    if (isset($_REQUEST['user_id'])) {
        $user_source = User($_REQUEST['user_id']);
        if ($user_source === false) {
            engelsystem_error('Unable to load angeltype.');
        }
        if ($user_source == null) {
            redirect(user_driver_license_edit_link());
        }
        // only privilege admin_user can edit other users driver license information
        if ($user['UID'] != $user_source['UID'] && !in_array('admin_user', $privileges)) {
            redirect(user_driver_license_edit_link());
        }
    } else {
        $user_source = $user;
    }
    $wants_to_drive = false;
    $has_car = false;
    $has_license_car = false;
    $has_license_3_5t_transporter = false;
    $has_license_7_5t_truck = false;
    $has_license_12_5t_truck = false;
    $has_license_forklift = false;
    $user_driver_license = UserDriverLicense($user_source['UID']);
    if ($user_driver_license === false) {
        engelsystem_error('Unable to load user driver license.');
    }
    if ($user_driver_license != null) {
        $wants_to_drive = true;
        $has_car = $user_driver_license['has_car'];
        $has_license_car = $user_driver_license['has_license_car'];
        $has_license_3_5t_transporter = $user_driver_license['has_license_3_5t_transporter'];
        $has_license_7_5t_truck = $user_driver_license['has_license_7_5t_truck'];
        $has_license_12_5t_truck = $user_driver_license['has_license_12_5t_truck'];
        $has_license_forklift = $user_driver_license['has_license_forklift'];
    }
    if (isset($_REQUEST['submit'])) {
        $ok = true;
        $wants_to_drive = isset($_REQUEST['wants_to_drive']);
        $has_car = isset($_REQUEST['has_car']);
        $has_license_car = isset($_REQUEST['has_license_car']);
        $has_license_3_5t_transporter = isset($_REQUEST['has_license_3_5t_transporter']);
        $has_license_7_5t_truck = isset($_REQUEST['has_license_7_5t_truck']);
        $has_license_12_5t_truck = isset($_REQUEST['has_license_12_5t_truck']);
        $has_license_forklift = isset($_REQUEST['has_license_forklift']);
        if ($wants_to_drive && !$has_license_car && !$has_license_3_5t_transporter && !$has_license_7_5t_truck && !$has_license_12_5t_truck && !$has_license_forklift) {
            $ok = false;
            error(_("Please select at least one driving license."));
        }
        if ($ok) {
            if (!$wants_to_drive && $user_driver_license != null) {
                $result = UserDriverLicenses_delete($user_source['UID']);
                if ($result === false) {
                    engelsystem_error("Unable to remove user driver license information");
                }
                engelsystem_log("Driver license information removed.");
                success(_("Your driver license information has been removed."));
            } else {
                if ($wants_to_drive) {
                    if ($user_driver_license == null) {
                        $result = UserDriverLicenses_create($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift);
                    } else {
                        $result = UserDriverLicenses_update($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift);
                    }
                    if ($result === false) {
                        engelsystem_error("Unable to save user driver license information.");
                    }
                    engelsystem_log("Driver license information updated.");
                }
                success(_("Your driver license information has been saved."));
            }
            redirect(user_link($user_source));
        }
    }
    return [sprintf(_("Edit %s driving license information"), $user_source['Nick']), UserDriverLicense_edit_view($user_source, $wants_to_drive, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift)];
}