2009-11-01 12:00:47 +00:00
|
|
|
<?php
|
2012-01-05 09:29:55 +08:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle 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.
|
|
|
|
//
|
|
|
|
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2007-08-16 09:28:18 +00:00
|
|
|
/**
|
|
|
|
* Add/remove members from group.
|
|
|
|
*
|
2012-01-05 09:29:55 +08:00
|
|
|
* @copyright 2006 The Open University and others, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk and others
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
* @package core_group
|
2007-08-16 09:28:18 +00:00
|
|
|
*/
|
2016-02-26 17:47:58 +11:00
|
|
|
require_once(__DIR__ . '/../config.php');
|
|
|
|
require_once(__DIR__ . '/lib.php');
|
2008-10-29 08:18:24 +00:00
|
|
|
require_once($CFG->dirroot . '/user/selector/lib.php');
|
2009-06-08 05:54:18 +00:00
|
|
|
require_once($CFG->dirroot . '/course/lib.php');
|
2011-01-23 18:34:41 +01:00
|
|
|
require_once($CFG->libdir . '/filelib.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);
|
2013-08-21 13:42:30 +08:00
|
|
|
$course = $DB->get_record('course', array('id'=>$group->courseid), '*', MUST_EXIST);
|
2007-08-16 09:28:18 +00:00
|
|
|
|
2012-03-16 20:11:23 +01:00
|
|
|
$PAGE->set_url('/group/members.php', array('group'=>$groupid));
|
2012-10-03 14:40:22 +08:00
|
|
|
$PAGE->set_pagelayout('admin');
|
2009-09-21 08:22:52 +00:00
|
|
|
|
2007-08-16 09:28:18 +00:00
|
|
|
require_login($course);
|
2012-08-02 11:20:48 +08:00
|
|
|
$context = context_course::instance($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));
|
|
|
|
$potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id));
|
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)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('erroraddremoveuser', 'group', $returnurl);
|
2007-08-16 09:28:18 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2012-03-20 17:41:33 +00:00
|
|
|
if (!groups_remove_member_allowed($groupid, $user->id)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('errorremovenotpermitted', 'group', $returnurl,
|
2012-03-20 17:41:33 +00:00
|
|
|
$user->fullname);
|
|
|
|
}
|
2008-10-29 08:18:24 +00:00
|
|
|
if (!groups_remove_member($groupid, $user->id)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('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-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();
|
2010-07-19 04:09:13 +00:00
|
|
|
echo $OUTPUT->heading(get_string('adduserstogroup', 'group').": $groupname", 3);
|
|
|
|
|
2013-10-30 17:24:48 +08:00
|
|
|
// Store the rows we want to display in the group info.
|
|
|
|
$groupinforow = array();
|
|
|
|
|
|
|
|
// Check if there is a description to display.
|
|
|
|
if (!empty($group->description)) {
|
2017-10-23 08:04:09 +08:00
|
|
|
$grouprenderer = $PAGE->get_renderer('core_group');
|
|
|
|
$groupdetailpage = new \core_group\output\group_details($groupid);
|
|
|
|
echo $grouprenderer->group_details($groupdetailpage);
|
2010-07-19 04:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Print the editing form
|
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">
|
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">
|
2017-05-15 09:55:02 +05:30
|
|
|
<input class="btn btn-secondary" name="add" id="add"
|
|
|
|
type="submit" value="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>"
|
|
|
|
title="<?php print_string('add'); ?>" /><br />
|
|
|
|
<input class="btn btn-secondary" 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'>
|
2017-05-15 09:55:02 +05:30
|
|
|
<input class="btn btn-secondary" type="submit" name="cancel"
|
|
|
|
value="<?php print_string('backtogroups', 'group'); ?>" />
|
2007-08-16 09:28:18 +00:00
|
|
|
</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
|
2010-07-23 04:19:42 +00:00
|
|
|
$PAGE->requires->js_init_call('init_add_remove_members_page', null, false, $potentialmembersselector->get_js_module());
|
2009-11-30 05:28:55 +00:00
|
|
|
|
2009-08-06 14:10:09 +00:00
|
|
|
echo $OUTPUT->footer();
|