has('confirmed')) { AngelType_delete($angeltype); success(sprintf(_('Angeltype %s deleted.'), AngelType_name_render($angeltype))); redirect(page_link_to('angeltypes')); } return [ sprintf(_('Delete angeltype %s'), $angeltype['name']), AngelType_delete_view($angeltype) ]; } /** * Change an Angeltype. * * @return array */ function angeltype_edit_controller() { global $privileges, $user; // In supporter mode only allow to modify description $supporter_mode = !in_array('admin_angel_types', $privileges); $request = request(); if ($request->has('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 ($request->has('submit')) { $valid = true; if (!$supporter_mode) { if ($request->has('name')) { $result = AngelType_validate_name($request->input('name'), $angeltype); $angeltype['name'] = $result->getValue(); if (!$result->isValid()) { $valid = false; error(_('Please check the name. Maybe it already exists.')); } } $angeltype['restricted'] = $request->has('restricted'); $angeltype['no_self_signup'] = $request->has('no_self_signup'); $angeltype['requires_driver_license'] = $request->has('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 [ sprintf(_('Edit %s'), $angeltype['name']), AngelType_edit_view($angeltype, $supporter_mode) ]; } /** * View details of a given angeltype. * * @return array */ function angeltype_controller() { global $privileges, $user; 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); 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 ) ]; } /** * View a list of all angeltypes. * * @return array */ function angeltypes_list_controller() { global $privileges, $user; if (!in_array('angeltypes', $privileges)) { redirect('?'); } $angeltypes = AngelTypes_with_user($user); 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' ); } $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'] = '' . $angeltype['name'] . ''; $angeltype['actions'] = table_buttons($actions); } return [ angeltypes_title(), AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges)) ]; } /** * Loads an angeltype from given angeltype_id request param. * * @return array */ function load_angeltype() { $request = request(); if (!$request->has('angeltype_id')) { redirect(page_link_to('angeltypes')); } $angeltype = AngelType($request->input('angeltype_id')); if ($angeltype == null) { error(_('Angeltype doesn\'t exist . ')); redirect(page_link_to('angeltypes')); } return $angeltype; }