Merge branch 'install_21_STABLE' of git://git.moodle.cz/moodle-install into MOODLE_21...
[moodle.git] / group / members.php
blob3906e3d0f06ecbcb754f4e29e43e9c8030c38a0d
1 <?php
2 /**
3 * Add/remove members from group.
5 * @copyright &copy; 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
9 * @package groups
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;
32 if ($cancel) {
33 redirect($returnurl);
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);
81 /// Print header
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; ?>">
112 <div>
113 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
115 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
116 <tr>
117 <td id='existingcell'>
119 <label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
120 </p>
121 <?php $groupmembersselector->display(); ?>
122 </td>
123 <td id='buttonscell'>
124 <p class="arrow_button">
125 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
126 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
127 </p>
128 </td>
129 <td id='potentialcell'>
131 <label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
132 </p>
133 <?php $potentialmembersselector->display(); ?>
134 </td>
135 <td>
136 <p><?php echo($strusergroupmembership) ?></p>
137 <div id="group-usersummary"></div>
138 </td>
139 </tr>
140 <tr><td colspan="3" id='backcell'>
141 <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
142 </td></tr>
143 </table>
144 </div>
145 </form>
146 </div>
148 <?php
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();