2009-11-01 12:00:47 +00:00
|
|
|
<?php
|
2007-08-16 09:28:18 +00:00
|
|
|
/**
|
|
|
|
* Add/remove members from group.
|
|
|
|
*
|
2008-10-29 08:18:24 +00:00
|
|
|
* @copyright © 2006 The Open University and others
|
2007-08-16 09:28:18 +00:00
|
|
|
* @author N.D.Freear AT open.ac.uk
|
2008-10-29 08:18:24 +00:00
|
|
|
* @author J.White AT open.ac.uk and others
|
2007-08-16 09:28:18 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package groups
|
|
|
|
*/
|
2008-10-29 08:18:24 +00:00
|
|
|
require_once(dirname(__FILE__) . '/../config.php');
|
|
|
|
require_once(dirname(__FILE__) . '/lib.php');
|
|
|
|
require_once($CFG->dirroot . '/user/selector/lib.php');
|
2009-06-08 05:54:18 +00:00
|
|
|
require_once($CFG->dirroot . '/course/lib.php');
|
2007-08-16 09:28:18 +00:00
|
|
|
|
2008-10-29 09:10:41 +00:00
|
|
|
$groupid = required_param('group', PARAM_INT);
|
2010-03-31 07:41:31 +00:00
|
|
|
$cancel = optional_param('cancel', false, PARAM_BOOL);
|
2007-08-16 09:28:18 +00:00
|
|
|
|
2010-03-31 07:41:31 +00:00
|
|
|
$group = $DB->get_record('groups', array('id'=>$groupid), '*', MUST_EXIST);
|
|
|
|
$course = $DB->get_record('course', array('id'=>$group->courseid), '*', MUST_EXIST);
|
2007-08-16 09:28:18 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/groups/members.php', array('id'=>$groupid));
|
2009-09-21 08:22:52 +00:00
|
|
|
|
2007-08-16 09:28:18 +00:00
|
|
|
require_login($course);
|
2010-03-31 07:41:31 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
2007-08-16 09:28:18 +00:00
|
|
|
require_capability('moodle/course:managegroups', $context);
|
|
|
|
|
2010-03-31 07:41:31 +00:00
|
|
|
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$group->id;
|
2007-08-16 09:28:18 +00:00
|
|
|
|
2010-03-31 07:41:31 +00:00
|
|
|
if ($cancel) {
|
2008-10-29 08:18:24 +00:00
|
|
|
redirect($returnurl);
|
|
|
|
}
|
2007-08-16 09:28:18 +00:00
|
|
|
|
2010-03-31 07:41:31 +00:00
|
|
|
$groupmembersselector = new group_members_selector('removeselect', array('groupid' => $groupid, 'courseid' => $course->id));
|
2008-10-29 08:18:24 +00:00
|
|
|
$groupmembersselector->set_extra_fields(array());
|
2010-03-31 07:41:31 +00:00
|
|
|
$potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id));
|
2008-10-29 08:18:24 +00:00
|
|
|
$potentialmembersselector->set_extra_fields(array());
|
2009-11-01 16:48:45 +00:00
|
|
|
|
2008-10-29 08:18:24 +00:00
|
|
|
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
|
|
|
|
$userstoadd = $potentialmembersselector->get_selected_users();
|
|
|
|
if (!empty($userstoadd)) {
|
|
|
|
foreach ($userstoadd as $user) {
|
|
|
|
if (!groups_add_member($groupid, $user->id)) {
|
2007-08-16 09:28:18 +00:00
|
|
|
print_error('erroraddremoveuser', 'group', $returnurl);
|
|
|
|
}
|
2008-10-29 08:18:24 +00:00
|
|
|
$groupmembersselector->invalidate_selected_users();
|
|
|
|
$potentialmembersselector->invalidate_selected_users();
|
2007-08-16 09:28:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-29 08:18:24 +00:00
|
|
|
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
|
|
|
|
$userstoremove = $groupmembersselector->get_selected_users();
|
|
|
|
if (!empty($userstoremove)) {
|
|
|
|
foreach ($userstoremove as $user) {
|
|
|
|
if (!groups_remove_member($groupid, $user->id)) {
|
|
|
|
print_error('erroraddremoveuser', 'group', $returnurl);
|
2008-01-17 11:28:54 +00:00
|
|
|
}
|
2008-10-29 08:18:24 +00:00
|
|
|
$groupmembersselector->invalidate_selected_users();
|
|
|
|
$potentialmembersselector->invalidate_selected_users();
|
2007-08-16 09:28:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print the page and form
|
|
|
|
$strgroups = get_string('groups');
|
|
|
|
$strparticipants = get_string('participants');
|
2007-08-17 19:09:11 +00:00
|
|
|
$stradduserstogroup = get_string('adduserstogroup', 'group');
|
2007-09-24 21:55:15 +00:00
|
|
|
$strusergroupmembership = get_string('usergroupmembership', 'group');
|
2007-08-16 09:28:18 +00:00
|
|
|
|
|
|
|
$groupname = format_string($group->name);
|
|
|
|
|
2010-02-06 15:26:47 +00:00
|
|
|
$PAGE->requires->yui2_lib('connection');
|
2010-01-18 20:57:32 +00:00
|
|
|
$PAGE->requires->js('/group/clientlib.js');
|
2010-03-31 07:41:31 +00:00
|
|
|
$PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$course->id)));
|
|
|
|
$PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$course->id)));
|
2009-09-07 06:43:02 +00:00
|
|
|
$PAGE->navbar->add($stradduserstogroup);
|
|
|
|
|
|
|
|
/// Print header
|
|
|
|
$PAGE->set_title("$course->shortname: $strgroups");
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
echo $OUTPUT->header();
|
2007-08-16 09:28:18 +00:00
|
|
|
?>
|
2007-09-24 21:55:15 +00:00
|
|
|
|
2007-08-16 09:28:18 +00:00
|
|
|
<div id="addmembersform">
|
|
|
|
<h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
|
|
|
|
|
2008-10-29 09:10:41 +00:00
|
|
|
<form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
|
2007-08-16 09:28:18 +00:00
|
|
|
<div>
|
|
|
|
<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
|
|
|
|
|
2008-10-29 08:18:24 +00:00
|
|
|
<table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
|
2007-08-16 09:28:18 +00:00
|
|
|
<tr>
|
2008-10-30 10:49:15 +00:00
|
|
|
<td id='existingcell'>
|
2007-09-24 21:55:15 +00:00
|
|
|
<p>
|
2008-10-29 08:18:24 +00:00
|
|
|
<label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
|
2007-09-24 21:55:15 +00:00
|
|
|
</p>
|
2008-10-29 08:18:24 +00:00
|
|
|
<?php $groupmembersselector->display(); ?>
|
|
|
|
</td>
|
|
|
|
<td id='buttonscell'>
|
2007-08-16 09:28:18 +00:00
|
|
|
<p class="arrow_button">
|
2009-12-23 17:44:17 +00:00
|
|
|
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
|
|
|
|
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
|
2007-08-16 09:28:18 +00:00
|
|
|
</p>
|
|
|
|
</td>
|
2008-10-30 10:49:15 +00:00
|
|
|
<td id='potentialcell'>
|
2007-09-24 21:55:15 +00:00
|
|
|
<p>
|
2008-10-29 08:18:24 +00:00
|
|
|
<label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
|
2007-09-24 21:55:15 +00:00
|
|
|
</p>
|
2008-10-29 08:18:24 +00:00
|
|
|
<?php $potentialmembersselector->display(); ?>
|
|
|
|
</td>
|
2009-12-21 08:13:50 +00:00
|
|
|
<td>
|
|
|
|
<p><?php echo($strusergroupmembership) ?></p>
|
|
|
|
<div id="group-usersummary"></div>
|
|
|
|
</td>
|
2007-08-16 09:28:18 +00:00
|
|
|
</tr>
|
2008-10-29 08:18:24 +00:00
|
|
|
<tr><td colspan="3" id='backcell'>
|
2007-08-16 09:28:18 +00:00
|
|
|
<input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
|
|
|
|
</td></tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
2009-12-21 08:13:50 +00:00
|
|
|
//outputs the JS array used to display the other groups users are in
|
|
|
|
$potentialmembersselector->print_user_summaries($course->id);
|
|
|
|
|
2009-11-30 05:28:55 +00:00
|
|
|
//this must be after calling display() on the selectors so their setup JS executes first
|
|
|
|
$PAGE->requires->js_function_call('init_add_remove_members_page');
|
|
|
|
|
2009-08-06 14:10:09 +00:00
|
|
|
echo $OUTPUT->footer();
|