Commit 509a5c5f authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow updating of user roles by group admins

parent c494e7d8
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('group.php');
require_once(get_config('docroot') . 'interaction/lib.php');
$groupid = param_integer('group');
$userid = param_integer('user');
$newrole = param_alpha('role', null);
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException("Couldn't find group with id $groupid");
}
if (!$user = get_record('usr', 'id', $userid, 'deleted', 0)) {
throw new UserNotFoundException("Couldn't find user with id $userid");
}
$userrole = group_user_access($groupid, $userid);
if (!$userrole) {
throw new UserNotFoundException("Couldn't find user with id $userid in group $groupid");
}
$role = group_user_access($groupid);
if ($role != 'admin') {
throw new AccessDeniedException();
}
if ($newrole && $newrole != $userrole) {
set_field('group_member', 'role', $newrole, 'group', $groupid, 'member', $userid);
$SESSION->add_ok_msg(get_string('rolechanged', 'group'));
redirect('/group/members.php?id='.$groupid);
}
define('TITLE', $group->name . ' - ' . get_string('Changerole', 'group'));
$roleinfo = group_get_role_info($groupid);
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($groupid, $role))));
$smarty->assign('group', $group);
$smarty->assign('groupid', $groupid);
$smarty->assign('userid', $userid);
$smarty->assign('userrole', $userrole);
$smarty->assign('subtitle', get_string('changeroleofuseringroup', 'group', display_name($user), $group->name));
$smarty->assign('roles', $roleinfo);
$smarty->display('group/changerole.tpl');
?>
......@@ -36,7 +36,7 @@ $offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
list($html, $pagination, $count, $offset) = group_get_membersearch_data($id, $query, $offset, $limit);
log_debug($USER);
json_reply(false, array(
'message' => null,
'data' => array(
......
......@@ -248,4 +248,9 @@ $string['interactiondeleted'] = '%s deleted successfully';
$string['addnewinteraction'] = 'Add new %s';
$string['title'] = 'Title';
$string['Role'] = 'Role';
$string['changerole'] = 'Change role';
$string['changeroleofuseringroup'] = 'Change role of %s in %s';
$string['currentrole'] = 'Current role';
$string['changeroleto'] = 'Change role to';
$string['rolechanged'] = 'Role changed';
?>
......@@ -438,6 +438,8 @@ function group_get_membersearch_data($group, $query, $offset, $limit) {
$smarty->assign_by_ref('results', $results);
$smarty->assign('searchurl', $searchurl);
$smarty->assign('pagebaseurl', $searchurl);
$smarty->assign('caneditroles', group_user_access($group) == 'admin');
$smarty->assign('group', $group);
$html = $smarty->fetch('group/membersearchresults.tpl');
$pagination = build_pagination(array(
......
......@@ -1891,7 +1891,7 @@ span.viewicon {
margin-top: 0;
}
#membersearchresults {
width: 56em;
width: 48em;
border-top: 1px solid #95a8b7;
border-bottom: 1px solid #95a8b7;
}
......
{include file="header.tpl"}
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
<h2>{$group->name|escape}</h2>
{include file="group/tabstart.tpl" current="members"}
<div class="group-info-para"><h3>{$subtitle}</h3></div>
<div class="group-info-para">{str tag=currentrole section=group}: {$roles[$userrole]->display}</div>
<div class="group-info-para">
<form method="post">
<input type="hidden" name="userid" value="{$userid|escape}" />
<input type="hidden" name="groupid" value="{$groupid|escape}" />
{str tag=changeroleto section=group}
<select name="role">
{foreach from=$roles item=role}
<option value="{$role->role}"{if ($role->role == $userrole)} selected{/if}>{$role->display}</option>
{/foreach}
</select>
<input type="submit" value="{str tag=submit}" />
</form>
</div><br />
{include file="group/tabend.tpl"}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
......@@ -5,7 +5,7 @@
<td>
<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>
<p>{$results.roles[$r.role]->display}</p>
<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>
<p><strong>Joined:</strong> {$r.jointime}</p>
<p>{$r.introduction|str_shorten:80:true}</p>
</td>
......
Markdown is supported
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