Commit 3ef17736 authored by Nigel McNie's avatar Nigel McNie
Browse files

Add a button to the members page for each member that removes them from the group.

This is done using a form, although it's styled like all the other delete links we have around the place.
parent edfbc41a
......@@ -309,6 +309,29 @@ function group_get_adduser_form($userid, $groupid) {
));
}
function group_get_removeuser_form($userid, $groupid) {
return pieform(array(
'name' => 'removeuser' . $userid,
'validatecallback' => 'group_removeuser_validate',
'successcallback' => 'group_removeuser_submit',
'renderer' => 'oneline',
'elements' => array(
'group' => array(
'type' => 'hidden',
'value' => $groupid,
),
'member' => array(
'type' => 'hidden',
'value' => $userid,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('removefromgroup', 'group'),
),
),
));
}
/**
* Sets up groups for display in mygroups.php and find.php
*
......@@ -380,6 +403,13 @@ function group_invite_submit(Pieform $form, $values) {
}
}
function group_removeuser_validate(Pieform $form, $values) {
global $user, $group, $SESSION;
if (!group_user_can_leave($values['group'], $values['member'])) {
$form->set_error('submit', get_string('usercantleavegroup', 'group'));
}
}
function group_adduser_submit(Pieform $form, $values) {
global $SESSION;
$group = (int)$values['group'];
......@@ -395,6 +425,18 @@ function group_adduser_submit(Pieform $form, $values) {
redirect('/group/members.php?id=' . $group);
}
function group_removeuser_submit(Pieform $form, $values) {
global $SESSION;
$group = (int)$values['group'];
if (group_user_access($group) != 'admin') {
$SESSION->add_error_msg(get_string('accessdenied', 'error'));
redirect('/group/members.php?id=' . $group);
}
group_remove_user($group, $values['member']);
$SESSION->add_ok_msg(get_string('userremoved', 'group'));
redirect('/group/members.php?id=' . $group);
}
function group_get_role_info($groupid) {
$roles = get_records_sql_assoc('SELECT role, edit_views, see_submitted_views, gr.grouptype FROM {grouptype_roles} gr
INNER JOIN {group} g ON g.grouptype = gr.grouptype
......@@ -421,6 +463,12 @@ function group_get_membersearch_data($group, $query, $offset, $limit, $membershi
$smarty = smarty_core();
foreach ($results['data'] as &$r) {
if (group_user_can_leave($group, $r['id'])) {
$r['removeform'] = group_get_removeuser_form($r['id'], $group);
}
}
if (!empty($membershiptype)) {
if ($membershiptype == 'request') {
foreach ($results['data'] as &$r) {
......
......@@ -1928,6 +1928,24 @@ span.viewicon {
#membersearchresults td {
width: 50%;
}
#membersearchresults .removeform {
padding: 0;
}
#membersearchresults .removeform form,
#membersearchresults .removeform form div {
display: inline;
padding: 0;
margin: 0;
}
#membersearchresults .removeform input {
background: url(../images/icon-delete.gif) no-repeat left 3px;
padding-left: 10px;
font-size: 11px;
border: none;
color: #7f9d16;
margin: 0 0 0 20px;
height: auto;
}
.group-info-para {
margin: 15px 0 0 10px;
}
......
......@@ -6,7 +6,10 @@
<div class="fl"><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=40&amp;id={$r.id|escape}" alt=""></div>
<h4><a href="{$WWWROOT}user/view.php?id={$r.id|escape}">{$r.name|escape}</a></h4>
{if $r.role}
<p>{$results.roles[$r.role]->display}{if $caneditroles} (<a href="{$WWWROOT}group/changerole.php?group={$group}&amp;user={$r.id}">{str tag=changerole section=group}</a>){/if}</p>
<div class="removeform">
{$results.roles[$r.role]->display}{if $caneditroles} (<a href="{$WWWROOT}group/changerole.php?group={$group}&amp;user={$r.id}">{str tag=changerole section=group}</a>){/if}
{$r.removeform}
</div>
<p><strong>Joined:</strong> {$r.jointime}</p>
<p>{$r.introduction|str_shorten:80:true}</p>
{elseif $membershiptype == 'request'}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment