make angeltype names clickable

main
Philip Häusler 9 years ago
parent facc32f133
commit 2cb44fe517

@ -13,7 +13,7 @@ function angeltypes_title() {
function angeltypes_controller() { function angeltypes_controller() {
if (! isset($_REQUEST['action'])) if (! isset($_REQUEST['action']))
$_REQUEST['action'] = 'list'; $_REQUEST['action'] = 'list';
switch ($_REQUEST['action']) { switch ($_REQUEST['action']) {
default: default:
case 'list': case 'list':
@ -29,22 +29,31 @@ function angeltypes_controller() {
} }
} }
/**
* Path to angeltype view.
*
* @param AngelType $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) * Job description for all angeltypes (public to everyone)
*/ */
function angeltypes_about_controller() { function angeltypes_about_controller() {
global $privileges, $user; global $privileges, $user;
if (isset($user)) if (isset($user))
$angeltypes = AngelTypes_with_user($user); $angeltypes = AngelTypes_with_user($user);
else else
$angeltypes = AngelTypes(); $angeltypes = AngelTypes();
if ($angeltypes === false) if ($angeltypes === false)
engelsystem_error("Unable to load angeltypes."); engelsystem_error("Unable to load angeltypes.");
return array( return array(
_("Teams/Job description"), _("Teams/Job description"),
AngelTypes_about_view($angeltypes, isset($user)) AngelTypes_about_view($angeltypes, isset($user))
); );
} }
@ -53,29 +62,29 @@ function angeltypes_about_controller() {
*/ */
function angeltype_delete_controller() { function angeltype_delete_controller() {
global $privileges, $user; global $privileges, $user;
if (! in_array('admin_angel_types', $privileges)) if (! in_array('admin_angel_types', $privileges))
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) if ($angeltype === false)
engelsystem_error("Unable to load angeltype."); engelsystem_error("Unable to load angeltype.");
if ($angeltype == null) if ($angeltype == null)
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
if (isset($_REQUEST['confirmed'])) { if (isset($_REQUEST['confirmed'])) {
$result = AngelType_delete($angeltype); $result = AngelType_delete($angeltype);
if ($result === false) if ($result === false)
engelsystem_error("Unable to delete angeltype."); engelsystem_error("Unable to delete angeltype.");
engelsystem_log("Deleted angeltype: " . $angeltype['name']); engelsystem_log("Deleted angeltype: " . AngelType_name_render($angeltype));
success(sprintf(_("Angeltype %s deleted."), $angeltype['name'])); success(sprintf(_("Angeltype %s deleted."), AngelType_name_render($angeltype)));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
return array( return array(
sprintf(_("Delete angeltype %s"), $angeltype['name']), sprintf(_("Delete angeltype %s"), $angeltype['name']),
AngelType_delete_view($angeltype) AngelType_delete_view($angeltype)
); );
} }
@ -84,35 +93,35 @@ function angeltype_delete_controller() {
*/ */
function angeltype_edit_controller() { function angeltype_edit_controller() {
global $privileges, $user; global $privileges, $user;
$name = ""; $name = "";
$restricted = false; $restricted = false;
$description = ""; $description = "";
if (isset($_REQUEST['angeltype_id'])) { if (isset($_REQUEST['angeltype_id'])) {
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) if ($angeltype === false)
engelsystem_error("Unable to load angeltype."); engelsystem_error("Unable to load angeltype.");
if ($angeltype == null) if ($angeltype == null)
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
$name = $angeltype['name']; $name = $angeltype['name'];
$restricted = $angeltype['restricted']; $restricted = $angeltype['restricted'];
$description = $angeltype['description']; $description = $angeltype['description'];
if (! User_is_AngelType_coordinator($user, $angeltype)) if (! User_is_AngelType_coordinator($user, $angeltype))
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} else { } else {
if (! in_array('admin_angel_types', $privileges)) if (! in_array('admin_angel_types', $privileges))
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
// In coordinator mode only allow to modify description // In coordinator mode only allow to modify description
$coordinator_mode = ! in_array('admin_angel_types', $privileges); $coordinator_mode = ! in_array('admin_angel_types', $privileges);
if (isset($_REQUEST['submit'])) { if (isset($_REQUEST['submit'])) {
$ok = true; $ok = true;
if (! $coordinator_mode) { if (! $coordinator_mode) {
if (isset($_REQUEST['name'])) { if (isset($_REQUEST['name'])) {
list($valid, $name) = AngelType_validate_name($_REQUEST['name'], $angeltype); list($valid, $name) = AngelType_validate_name($_REQUEST['name'], $angeltype);
@ -121,13 +130,13 @@ function angeltype_edit_controller() {
error(_("Please check the name. Maybe it already exists.")); error(_("Please check the name. Maybe it already exists."));
} }
} }
$restricted = isset($_REQUEST['restricted']); $restricted = isset($_REQUEST['restricted']);
} }
if (isset($_REQUEST['description'])) if (isset($_REQUEST['description']))
$description = strip_request_item_nl('description'); $description = strip_request_item_nl('description');
if ($ok) { if ($ok) {
$restricted = $restricted ? 1 : 0; $restricted = $restricted ? 1 : 0;
if (isset($angeltype)) { if (isset($angeltype)) {
@ -142,15 +151,15 @@ function angeltype_edit_controller() {
engelsystem_error("Unable to create angeltype."); engelsystem_error("Unable to create angeltype.");
engelsystem_log("Created angeltype: " . $name . ", restricted: " . $restricted); engelsystem_log("Created angeltype: " . $name . ", restricted: " . $restricted);
} }
success("Angel type saved."); success("Angel type saved.");
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id); redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id);
} }
} }
return array( return array(
sprintf(_("Edit %s"), $name), sprintf(_("Edit %s"), $name),
AngelType_edit_view($name, $restricted, $description, $coordinator_mode) AngelType_edit_view($name, $restricted, $description, $coordinator_mode)
); );
} }
@ -159,30 +168,30 @@ function angeltype_edit_controller() {
*/ */
function angeltype_controller() { function angeltype_controller() {
global $privileges, $user; global $privileges, $user;
if (! in_array('angeltypes', $privileges)) if (! in_array('angeltypes', $privileges))
redirect('?'); redirect('?');
if (! isset($_REQUEST['angeltype_id'])) if (! isset($_REQUEST['angeltype_id']))
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) if ($angeltype === false)
engelsystem_error("Unable to load angeltype."); engelsystem_error("Unable to load angeltype.");
if ($angeltype == null) if ($angeltype == null)
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false) if ($user_angeltype === false)
engelsystem_error("Unable to load user angeltype."); engelsystem_error("Unable to load user angeltype.");
$members = Users_by_angeltype($angeltype); $members = Users_by_angeltype($angeltype);
if ($members === false) if ($members === false)
engelsystem_error("Unable to load members."); engelsystem_error("Unable to load members.");
return array( return array(
sprintf(_("Team %s"), $angeltype['name']), sprintf(_("Team %s"), $angeltype['name']),
AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator']) AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator'])
); );
} }
@ -191,40 +200,40 @@ function angeltype_controller() {
*/ */
function angeltypes_list_controller() { function angeltypes_list_controller() {
global $privileges, $user; global $privileges, $user;
if (! in_array('angeltypes', $privileges)) if (! in_array('angeltypes', $privileges))
redirect('?'); redirect('?');
$angeltypes = AngelTypes_with_user($user); $angeltypes = AngelTypes_with_user($user);
if ($angeltypes === false) if ($angeltypes === false)
engelsystem_error("Unable to load angeltypes."); engelsystem_error("Unable to load angeltypes.");
foreach ($angeltypes as &$angeltype) { foreach ($angeltypes as &$angeltype) {
$actions = array( $actions = array(
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'],_("view"),"btn-xs") button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("view"), "btn-xs")
); );
if (in_array('admin_angel_types', $privileges)) { 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=edit&angeltype_id=' . $angeltype['id'], _("edit"), "btn-xs");
$actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs"); $actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs");
} }
$angeltype['membership'] = AngelType_render_membership($angeltype); $angeltype['membership'] = AngelType_render_membership($angeltype);
if ($angeltype['user_angeltype_id'] != null) { 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"); $actions[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), "btn-xs");
} else { } else {
$actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs"); $actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs");
} }
$angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : ''; $angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : '';
$angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>'; $angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>';
$angeltype['actions'] = table_buttons($actions); $angeltype['actions'] = table_buttons($actions);
} }
return array( return array(
angeltypes_title(), angeltypes_title(),
AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges)) AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges))
); );
} }
?> ?>

@ -48,8 +48,8 @@ function user_angeltypes_delete_all_controller() {
if ($result === false) if ($result === false)
engelsystem_error("Unable to confirm all users."); engelsystem_error("Unable to confirm all users.");
engelsystem_log(sprintf("Denied all users for angeltype %s", $angeltype['name'])); engelsystem_log(sprintf("Denied all users for angeltype %s", AngelType_name_render($angeltype)));
success(sprintf(_("Denied all users for angeltype %s."), $angeltype['name'])); success(sprintf(_("Denied all users for angeltype %s."), 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']);
} }
@ -96,8 +96,8 @@ function user_angeltypes_confirm_all_controller() {
if ($result === false) if ($result === false)
engelsystem_error("Unable to confirm all users."); engelsystem_error("Unable to confirm all users.");
engelsystem_log(sprintf("Confirmed all users for angeltype %s", $angeltype['name'])); engelsystem_log(sprintf("Confirmed all users for angeltype %s", AngelType_name_render($angeltype)));
success(sprintf(_("Confirmed all users for angeltype %s."), $angeltype['name'])); success(sprintf(_("Confirmed all users for angeltype %s."), 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']);
} }
@ -152,8 +152,8 @@ function user_angeltype_confirm_controller() {
if ($result === false) if ($result === false)
engelsystem_error("Unable to confirm user angeltype."); engelsystem_error("Unable to confirm user angeltype.");
engelsystem_log(sprintf("%s confirmed for angeltype %s", User_Nick_render($user_source), $angeltype['name'])); 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'])); 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']); redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
} }
@ -273,7 +273,7 @@ function user_angeltype_update_controller() {
if ($result === false) if ($result === false)
engelsystem_error("Unable to update coordinator rights."); engelsystem_error("Unable to update coordinator rights.");
$success_message = sprintf($coordinator ? _("Added coordinator rights for %s to %s.") : _("Removed coordinator rights for %s from %s."), $angeltype['name'], User_Nick_render($user_source)); $success_message = sprintf($coordinator ? _("Added coordinator rights for %s to %s.") : _("Removed coordinator rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source));
engelsystem_log($success_message); engelsystem_log($success_message);
success($success_message); success($success_message);
@ -332,13 +332,13 @@ function user_angeltype_add_controller() {
if ($user_angeltype_id === false) if ($user_angeltype_id === false)
engelsystem_error("Unable to create user angeltype."); engelsystem_error("Unable to create user angeltype.");
engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), $angeltype['name'])); 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'])); success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
$result = UserAngelType_confirm($user_angeltype_id, $user_source); $result = UserAngelType_confirm($user_angeltype_id, $user_source);
if ($result === false) if ($result === false)
engelsystem_error("Unable to confirm user angeltype."); engelsystem_error("Unable to confirm user angeltype.");
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), $angeltype['name'])); 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']);
} }
@ -365,14 +365,14 @@ function user_angeltype_add_controller() {
engelsystem_error("Unable to create user angeltype."); engelsystem_error("Unable to create user angeltype.");
$success_message = sprintf(_("You joined %s."), $angeltype['name']); $success_message = sprintf(_("You joined %s."), $angeltype['name']);
engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), $angeltype['name'])); engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
success($success_message); success($success_message);
if (in_array('admin_user_angeltypes', $privileges)) { if (in_array('admin_user_angeltypes', $privileges)) {
$result = UserAngelType_confirm($user_angeltype_id, $user); $result = UserAngelType_confirm($user_angeltype_id, $user);
if ($result === false) if ($result === false)
engelsystem_error("Unable to confirm user angeltype."); engelsystem_error("Unable to confirm user angeltype.");
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), $angeltype['name'])); 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']);

@ -10,7 +10,7 @@
* @param AngelType $angeltype * @param AngelType $angeltype
*/ */
function AngelType_name_render($angeltype) { function AngelType_name_render($angeltype) {
return '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . '</a>'; return '<a href="' . angeltype_link($angeltype['id']) . '">' . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . '</a>';
} }
/** /**

@ -269,7 +269,7 @@ function User_angeltypes_render($user_angeltypes) {
$class = 'text-warning'; $class = 'text-warning';
else else
$class = 'text-success'; $class = 'text-success';
$output[] = '<span class="' . $class . '">' . ($angeltype['coordinator'] ? glyph('education') : '') . $angeltype['name'] . '</span>'; $output[] = '<a href="' . angeltype_link($angeltype['id']) . '" class="' . $class . '">' . ($angeltype['coordinator'] ? glyph('education') : '') . $angeltype['name'] . '</a>';
} }
return join('<br />', $output); return join('<br />', $output);
} }

Loading…
Cancel
Save