3 * Add/remove members from group.
5 * @copyright © 2006 The Open University and others
6 * @author N.D.Freear AT open.ac.uk
7 * @author J.White AT open.ac.uk and others
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 require_once(dirname(__FILE__
) . '/../config.php');
12 require_once(dirname(__FILE__
) . '/lib.php');
13 require_once($CFG->dirroot
. '/user/selector/lib.php');
14 require_once($CFG->dirroot
. '/course/lib.php');
15 require_once($CFG->libdir
. '/filelib.php');
17 $groupid = required_param('group', PARAM_INT
);
18 $cancel = optional_param('cancel', false, PARAM_BOOL
);
20 $group = $DB->get_record('groups', array('id'=>$groupid), '*', MUST_EXIST
);
21 $course = $DB->get_record('course', array('id'=>$group->courseid
), '*', MUST_EXIST
);
23 $PAGE->set_url('/group/members.php', array('group'=>$groupid));
24 $PAGE->set_pagelayout('standard');
26 require_login($course);
27 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
28 require_capability('moodle/course:managegroups', $context);
30 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$group->id
;
36 $groupmembersselector = new group_members_selector('removeselect', array('groupid' => $groupid, 'courseid' => $course->id
));
37 $potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id
));
39 if (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
)) {
44 print_error('erroraddremoveuser', 'group', $returnurl);
46 $groupmembersselector->invalidate_selected_users();
47 $potentialmembersselector->invalidate_selected_users();
52 if (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);
59 $groupmembersselector->invalidate_selected_users();
60 $potentialmembersselector->invalidate_selected_users();
65 // Print the page and form
66 $strgroups = get_string('groups');
67 $strparticipants = get_string('participants');
68 $stradduserstogroup = get_string('adduserstogroup', 'group');
69 $strusergroupmembership = get_string('usergroupmembership', 'group');
71 $groupname = format_string($group->name
);
73 $PAGE->requires
->yui2_lib('connection');
74 $PAGE->requires
->js('/group/clientlib.js');
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
)));
77 $PAGE->navbar
->add($stradduserstogroup);
80 $PAGE->set_title("$course->shortname: $strgroups");
81 $PAGE->set_heading($course->fullname
);
82 echo $OUTPUT->header();
83 echo $OUTPUT->heading(get_string('adduserstogroup', 'group').": $groupname", 3);
85 /// Print group info - TODO: remove tables for layout here
86 $groupinfotable = new html_table();
87 $groupinfotable->attributes
['class'] = 'groupinfobox';
88 $picturecell = new html_table_cell();
89 $picturecell->attributes
['class'] = 'left side picture';
90 $picturecell->text
= print_group_picture($group, $course->id
, true, true, false);
92 $contentcell = new html_table_cell();
93 $contentcell->attributes
['class'] = 'content';
95 $group->description
= file_rewrite_pluginfile_urls($group->description
, 'pluginfile.php', $context->id
, 'group', 'description', $group->id
);
96 if (!isset($group->descriptionformat
)) {
97 $group->descriptionformat
= FORMAT_MOODLE
;
99 $options = new stdClass
;
100 $options->overflowdiv
= true;
101 $contentcell->text
= format_text($group->description
, $group->descriptionformat
, $options);
102 $groupinfotable->data
[] = new html_table_row(array($picturecell, $contentcell));
103 echo html_writer
::table($groupinfotable);
105 /// Print the editing form
108 <div id
="addmembersform">
109 <form id
="assignform" method
="post" action
="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
111 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
113 <table
class="generaltable generalbox groupmanagementtable boxaligncenter" summary
="">
115 <td id
='existingcell'>
117 <label
for="removeselect"><?php
print_string('groupmembers', 'group'); ?
></label
>
119 <?php
$groupmembersselector->display(); ?
>
121 <td id
='buttonscell'>
122 <p
class="arrow_button">
123 <input name
="add" id
="add" type
="submit" value
="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" title
="<?php print_string('add'); ?>" /><br
/>
124 <input name
="remove" id
="remove" type
="submit" value
="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" title
="<?php print_string('remove'); ?>" />
127 <td id
='potentialcell'>
129 <label
for="addselect"><?php
print_string('potentialmembs', 'group'); ?
></label
>
131 <?php
$potentialmembersselector->display(); ?
>
134 <p
><?php
echo($strusergroupmembership) ?
></p
>
135 <div id
="group-usersummary"></div
>
138 <tr
><td colspan
="3" id
='backcell'>
139 <input type
="submit" name
="cancel" value
="<?php print_string('backtogroups', 'group'); ?>" />
147 //outputs the JS array used to display the other groups users are in
148 $potentialmembersselector->print_user_summaries($course->id
);
150 //this must be after calling display() on the selectors so their setup JS executes first
151 $PAGE->requires
->js_init_call('init_add_remove_members_page', null, false, $potentialmembersselector->get_js_module());
153 echo $OUTPUT->footer();