/**
 * Change an Angeltype.
 */
function angeltype_edit_controller()
{
    global $privileges, $user;
    $name = "";
    $restricted = false;
    $description = "";
    $requires_driver_license = false;
    if (isset($_REQUEST['angeltype_id'])) {
        $angeltype = AngelType($_REQUEST['angeltype_id']);
        if ($angeltype === false) {
            engelsystem_error("Unable to load angeltype.");
        }
        if ($angeltype == null) {
            redirect(page_link_to('angeltypes'));
        }
        $name = $angeltype['name'];
        $restricted = $angeltype['restricted'];
        $description = $angeltype['description'];
        $requires_driver_license = $angeltype['requires_driver_license'];
        if (!User_is_AngelType_coordinator($user, $angeltype)) {
            redirect(page_link_to('angeltypes'));
        }
    } else {
        if (!in_array('admin_angel_types', $privileges)) {
            redirect(page_link_to('angeltypes'));
        }
    }
    // In coordinator mode only allow to modify description
    $coordinator_mode = !in_array('admin_angel_types', $privileges);
    if (isset($_REQUEST['submit'])) {
        $ok = true;
        if (!$coordinator_mode) {
            if (isset($_REQUEST['name'])) {
                list($valid, $name) = AngelType_validate_name($_REQUEST['name'], $angeltype);
                if (!$valid) {
                    $ok = false;
                    error(_("Please check the name. Maybe it already exists."));
                }
            }
            $restricted = isset($_REQUEST['restricted']);
            $requires_driver_license = isset($_REQUEST['requires_driver_license']);
        }
        if (isset($_REQUEST['description'])) {
            $description = strip_request_item_nl('description');
        }
        if ($ok) {
            if (isset($angeltype)) {
                $result = AngelType_update($angeltype['id'], $name, $restricted, $description, $requires_driver_license);
                if ($result === false) {
                    engelsystem_error("Unable to update angeltype.");
                }
                engelsystem_log("Updated angeltype: " . $name . ($restricted ? ", restricted" : "") . ($requires_driver_license ? ", requires driver license" : ""));
                $angeltype_id = $angeltype['id'];
            } else {
                $angeltype_id = AngelType_create($name, $restricted, $description, $requires_driver_license);
                if ($angeltype_id === false) {
                    engelsystem_error("Unable to create angeltype.");
                }
                engelsystem_log("Created angeltype: " . $name . ($restricted ? ", restricted" : "") . ($requires_driver_license ? ", requires driver license" : ""));
            }
            success("Angel type saved.");
            redirect(angeltype_link($angeltype_id));
        }
    }
    return array(sprintf(_("Edit %s"), $name), AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license));
}
示例#2
0
function User_angeltypes_render($user_angeltypes)
{
    $output = array();
    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['coordinator'] ? glyph('education') : '') . $angeltype['name'] . '</a>';
    }
    return join('<br />', $output);
}
示例#3
0
/**
 * Renders the angeltypes name as link.
 *
 * @param AngelType $angeltype          
 */
function AngelType_name_render($angeltype)
{
    return '<a href="' . angeltype_link($angeltype['id']) . '">' . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . '</a>';
}