MDL-23281 Include course completion library
[moodle.git] / group / members.php
CommitLineData
4ca6cfbf 1<?php
62d63838 2/**
3 * Add/remove members from group.
4 *
97873016 5 * @copyright &copy; 2006 The Open University and others
62d63838 6 * @author N.D.Freear AT open.ac.uk
97873016 7 * @author J.White AT open.ac.uk and others
62d63838 8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package groups
10 */
97873016 11require_once(dirname(__FILE__) . '/../config.php');
12require_once(dirname(__FILE__) . '/lib.php');
13require_once($CFG->dirroot . '/user/selector/lib.php');
558fce9c 14require_once($CFG->dirroot . '/course/lib.php');
62d63838 15
aa9671c9 16$groupid = required_param('group', PARAM_INT);
4f0c2d00 17$cancel = optional_param('cancel', false, PARAM_BOOL);
62d63838 18
4f0c2d00
PS
19$group = $DB->get_record('groups', array('id'=>$groupid), '*', MUST_EXIST);
20$course = $DB->get_record('course', array('id'=>$group->courseid), '*', MUST_EXIST);
62d63838 21
a6855934 22$PAGE->set_url('/groups/members.php', array('id'=>$groupid));
849185ce 23
62d63838 24require_login($course);
4f0c2d00 25$context = get_context_instance(CONTEXT_COURSE, $course->id);
62d63838 26require_capability('moodle/course:managegroups', $context);
27
4f0c2d00 28$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$group->id;
62d63838 29
4f0c2d00 30if ($cancel) {
97873016 31 redirect($returnurl);
32}
62d63838 33
4f0c2d00 34$groupmembersselector = new group_members_selector('removeselect', array('groupid' => $groupid, 'courseid' => $course->id));
97873016 35$groupmembersselector->set_extra_fields(array());
4f0c2d00 36$potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id));
97873016 37$potentialmembersselector->set_extra_fields(array());
6f5e0852 38
97873016 39if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
40 $userstoadd = $potentialmembersselector->get_selected_users();
41 if (!empty($userstoadd)) {
42 foreach ($userstoadd as $user) {
43 if (!groups_add_member($groupid, $user->id)) {
62d63838 44 print_error('erroraddremoveuser', 'group', $returnurl);
45 }
97873016 46 $groupmembersselector->invalidate_selected_users();
47 $potentialmembersselector->invalidate_selected_users();
62d63838 48 }
62d63838 49 }
62d63838 50}
51
97873016 52if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
53 $userstoremove = $groupmembersselector->get_selected_users();
54 if (!empty($userstoremove)) {
55 foreach ($userstoremove as $user) {
56 if (!groups_remove_member($groupid, $user->id)) {
57 print_error('erroraddremoveuser', 'group', $returnurl);
e254aa34 58 }
97873016 59 $groupmembersselector->invalidate_selected_users();
60 $potentialmembersselector->invalidate_selected_users();
62d63838 61 }
62d63838 62 }
63}
64
65// Print the page and form
66$strgroups = get_string('groups');
67$strparticipants = get_string('participants');
0be6f678 68$stradduserstogroup = get_string('adduserstogroup', 'group');
acf000b0 69$strusergroupmembership = get_string('usergroupmembership', 'group');
62d63838 70
71$groupname = format_string($group->name);
72
3244d9cc 73$PAGE->requires->yui2_lib('connection');
9dec75db 74$PAGE->requires->js('/group/clientlib.js');
4f0c2d00
PS
75$PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$course->id)));
76$PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$course->id)));
b87573d7 77$PAGE->navbar->add($stradduserstogroup);
78
79/// Print header
80$PAGE->set_title("$course->shortname: $strgroups");
81$PAGE->set_heading($course->fullname);
b87573d7 82echo $OUTPUT->header();
62d63838 83?>
acf000b0 84
62d63838 85<div id="addmembersform">
86 <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
87
aa9671c9 88 <form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
62d63838 89 <div>
90 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
62d63838 91
97873016 92 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
62d63838 93 <tr>
6cab02ac 94 <td id='existingcell'>
acf000b0 95 <p>
97873016 96 <label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
acf000b0 97 </p>
97873016 98 <?php $groupmembersselector->display(); ?>
99 </td>
100 <td id='buttonscell'>
62d63838 101 <p class="arrow_button">
92e01ab7
PS
102 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
103 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
62d63838 104 </p>
105 </td>
6cab02ac 106 <td id='potentialcell'>
acf000b0 107 <p>
97873016 108 <label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
acf000b0 109 </p>
97873016 110 <?php $potentialmembersselector->display(); ?>
111 </td>
bf1ac6d9
AD
112 <td>
113 <p><?php echo($strusergroupmembership) ?></p>
114 <div id="group-usersummary"></div>
115 </td>
62d63838 116 </tr>
97873016 117 <tr><td colspan="3" id='backcell'>
62d63838 118 <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
119 </td></tr>
120 </table>
121 </div>
122 </form>
123</div>
124
125<?php
bf1ac6d9
AD
126 //outputs the JS array used to display the other groups users are in
127 $potentialmembersselector->print_user_summaries($course->id);
128
4c459d6c
AD
129 //this must be after calling display() on the selectors so their setup JS executes first
130 $PAGE->requires->js_function_call('init_add_remove_members_page');
131
653468d4 132 echo $OUTPUT->footer();