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 $groupmembersselector->set_extra_fields(array());
38 $potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id
));
39 $potentialmembersselector->set_extra_fields(array());
41 if (optional_param('add', false, PARAM_BOOL
) && confirm_sesskey()) {
42 $userstoadd = $potentialmembersselector->get_selected_users();
43 if (!empty($userstoadd)) {
44 foreach ($userstoadd as $user) {
45 if (!groups_add_member($groupid, $user->id
)) {
46 print_error('erroraddremoveuser', 'group', $returnurl);
48 $groupmembersselector->invalidate_selected_users();
49 $potentialmembersselector->invalidate_selected_users();
54 if (optional_param('remove', false, PARAM_BOOL
) && confirm_sesskey()) {
55 $userstoremove = $groupmembersselector->get_selected_users();
56 if (!empty($userstoremove)) {
57 foreach ($userstoremove as $user) {
58 if (!groups_remove_member($groupid, $user->id
)) {
59 print_error('erroraddremoveuser', 'group', $returnurl);
61 $groupmembersselector->invalidate_selected_users();
62 $potentialmembersselector->invalidate_selected_users();
67 // Print the page and form
68 $strgroups = get_string('groups');
69 $strparticipants = get_string('participants');
70 $stradduserstogroup = get_string('adduserstogroup', 'group');
71 $strusergroupmembership = get_string('usergroupmembership', 'group');
73 $groupname = format_string($group->name
);
75 $PAGE->requires
->yui2_lib('connection');
76 $PAGE->requires
->js('/group/clientlib.js');
77 $PAGE->navbar
->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$course->id
)));
78 $PAGE->navbar
->add($strgroups, new moodle_url('/group/index.php', array('id'=>$course->id
)));
79 $PAGE->navbar
->add($stradduserstogroup);
82 $PAGE->set_title("$course->shortname: $strgroups");
83 $PAGE->set_heading($course->fullname
);
84 echo $OUTPUT->header();
85 echo $OUTPUT->heading(get_string('adduserstogroup', 'group').": $groupname", 3);
87 /// Print group info - TODO: remove tables for layout here
88 $groupinfotable = new html_table();
89 $groupinfotable->attributes
['class'] = 'groupinfobox';
90 $picturecell = new html_table_cell();
91 $picturecell->attributes
['class'] = 'left side picture';
92 $picturecell->text
= print_group_picture($group, $course->id
, true, true, false);
94 $contentcell = new html_table_cell();
95 $contentcell->attributes
['class'] = 'content';
97 $group->description
= file_rewrite_pluginfile_urls($group->description
, 'pluginfile.php', $context->id
, 'group', 'description', $group->id
);
98 if (!isset($group->descriptionformat
)) {
99 $group->descriptionformat
= FORMAT_MOODLE
;
101 $options = new stdClass
;
102 $options->overflowdiv
= true;
103 $contentcell->text
= format_text($group->description
, $group->descriptionformat
, $options);
104 $groupinfotable->data
[] = new html_table_row(array($picturecell, $contentcell));
105 echo html_writer
::table($groupinfotable);
107 /// Print the editing form
110 <div id
="addmembersform">
111 <form id
="assignform" method
="post" action
="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
113 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
115 <table
class="generaltable generalbox groupmanagementtable boxaligncenter" summary
="">
117 <td id
='existingcell'>
119 <label
for="removeselect"><?php
print_string('groupmembers', 'group'); ?
></label
>
121 <?php
$groupmembersselector->display(); ?
>
123 <td id
='buttonscell'>
124 <p
class="arrow_button">
125 <input name
="add" id
="add" type
="submit" value
="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" title
="<?php print_string('add'); ?>" /><br
/>
126 <input name
="remove" id
="remove" type
="submit" value
="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" title
="<?php print_string('remove'); ?>" />
129 <td id
='potentialcell'>
131 <label
for="addselect"><?php
print_string('potentialmembs', 'group'); ?
></label
>
133 <?php
$potentialmembersselector->display(); ?
>
136 <p
><?php
echo($strusergroupmembership) ?
></p
>
137 <div id
="group-usersummary"></div
>
140 <tr
><td colspan
="3" id
='backcell'>
141 <input type
="submit" name
="cancel" value
="<?php print_string('backtogroups', 'group'); ?>" />
149 //outputs the JS array used to display the other groups users are in
150 $potentialmembersselector->print_user_summaries($course->id
);
152 //this must be after calling display() on the selectors so their setup JS executes first
153 $PAGE->requires
->js_init_call('init_add_remove_members_page', null, false, $potentialmembersselector->get_js_module());
155 echo $OUTPUT->footer();