weekly release 2.4dev
[moodle.git] / group / members.php
CommitLineData
4ca6cfbf 1<?php
4d8e2417
AG
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17
62d63838 18/**
19 * Add/remove members from group.
20 *
4d8e2417
AG
21 * @copyright 2006 The Open University and others, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk and others
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package core_group
62d63838 24 */
97873016 25require_once(dirname(__FILE__) . '/../config.php');
26require_once(dirname(__FILE__) . '/lib.php');
27require_once($CFG->dirroot . '/user/selector/lib.php');
558fce9c 28require_once($CFG->dirroot . '/course/lib.php');
99d19c13 29require_once($CFG->libdir . '/filelib.php');
62d63838 30
aa9671c9 31$groupid = required_param('group', PARAM_INT);
4f0c2d00 32$cancel = optional_param('cancel', false, PARAM_BOOL);
62d63838 33
4f0c2d00
PS
34$group = $DB->get_record('groups', array('id'=>$groupid), '*', MUST_EXIST);
35$course = $DB->get_record('course', array('id'=>$group->courseid), '*', MUST_EXIST);
62d63838 36
0ac9d19a 37$PAGE->set_url('/group/members.php', array('group'=>$groupid));
c1fbff27 38$PAGE->set_pagelayout('standard');
849185ce 39
62d63838 40require_login($course);
bf0f06b1 41$context = context_course::instance($course->id);
62d63838 42require_capability('moodle/course:managegroups', $context);
43
4f0c2d00 44$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$group->id;
62d63838 45
4f0c2d00 46if ($cancel) {
97873016 47 redirect($returnurl);
48}
62d63838 49
4f0c2d00 50$groupmembersselector = new group_members_selector('removeselect', array('groupid' => $groupid, 'courseid' => $course->id));
4f0c2d00 51$potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id));
6f5e0852 52
97873016 53if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
54 $userstoadd = $potentialmembersselector->get_selected_users();
55 if (!empty($userstoadd)) {
56 foreach ($userstoadd as $user) {
57 if (!groups_add_member($groupid, $user->id)) {
62d63838 58 print_error('erroraddremoveuser', 'group', $returnurl);
59 }
97873016 60 $groupmembersselector->invalidate_selected_users();
61 $potentialmembersselector->invalidate_selected_users();
62d63838 62 }
62d63838 63 }
62d63838 64}
65
97873016 66if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
67 $userstoremove = $groupmembersselector->get_selected_users();
68 if (!empty($userstoremove)) {
69 foreach ($userstoremove as $user) {
70 if (!groups_remove_member($groupid, $user->id)) {
71 print_error('erroraddremoveuser', 'group', $returnurl);
e254aa34 72 }
97873016 73 $groupmembersselector->invalidate_selected_users();
74 $potentialmembersselector->invalidate_selected_users();
62d63838 75 }
62d63838 76 }
77}
78
79// Print the page and form
80$strgroups = get_string('groups');
81$strparticipants = get_string('participants');
0be6f678 82$stradduserstogroup = get_string('adduserstogroup', 'group');
acf000b0 83$strusergroupmembership = get_string('usergroupmembership', 'group');
62d63838 84
85$groupname = format_string($group->name);
86
9dec75db 87$PAGE->requires->js('/group/clientlib.js');
4f0c2d00
PS
88$PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$course->id)));
89$PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$course->id)));
b87573d7 90$PAGE->navbar->add($stradduserstogroup);
91
92/// Print header
93$PAGE->set_title("$course->shortname: $strgroups");
94$PAGE->set_heading($course->fullname);
b87573d7 95echo $OUTPUT->header();
74feb96a
MD
96echo $OUTPUT->heading(get_string('adduserstogroup', 'group').": $groupname", 3);
97
98/// Print group info - TODO: remove tables for layout here
99$groupinfotable = new html_table();
100$groupinfotable->attributes['class'] = 'groupinfobox';
101$picturecell = new html_table_cell();
102$picturecell->attributes['class'] = 'left side picture';
103$picturecell->text = print_group_picture($group, $course->id, true, true, false);
104
105$contentcell = new html_table_cell();
106$contentcell->attributes['class'] = 'content';
107
108$group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group', 'description', $group->id);
109if (!isset($group->descriptionformat)) {
110 $group->descriptionformat = FORMAT_MOODLE;
111}
367a75fa
SH
112$options = new stdClass;
113$options->overflowdiv = true;
114$contentcell->text = format_text($group->description, $group->descriptionformat, $options);
74feb96a
MD
115$groupinfotable->data[] = new html_table_row(array($picturecell, $contentcell));
116echo html_writer::table($groupinfotable);
117
118/// Print the editing form
62d63838 119?>
acf000b0 120
62d63838 121<div id="addmembersform">
aa9671c9 122 <form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
62d63838 123 <div>
124 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
62d63838 125
97873016 126 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
62d63838 127 <tr>
6cab02ac 128 <td id='existingcell'>
acf000b0 129 <p>
97873016 130 <label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
acf000b0 131 </p>
97873016 132 <?php $groupmembersselector->display(); ?>
133 </td>
134 <td id='buttonscell'>
62d63838 135 <p class="arrow_button">
92e01ab7
PS
136 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
137 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
62d63838 138 </p>
139 </td>
6cab02ac 140 <td id='potentialcell'>
acf000b0 141 <p>
97873016 142 <label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
acf000b0 143 </p>
97873016 144 <?php $potentialmembersselector->display(); ?>
145 </td>
bf1ac6d9
AD
146 <td>
147 <p><?php echo($strusergroupmembership) ?></p>
148 <div id="group-usersummary"></div>
149 </td>
62d63838 150 </tr>
97873016 151 <tr><td colspan="3" id='backcell'>
62d63838 152 <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
153 </td></tr>
154 </table>
155 </div>
156 </form>
157</div>
158
159<?php
bf1ac6d9
AD
160 //outputs the JS array used to display the other groups users are in
161 $potentialmembersselector->print_user_summaries($course->id);
162
4c459d6c 163 //this must be after calling display() on the selectors so their setup JS executes first
f19497f2 164 $PAGE->requires->js_init_call('init_add_remove_members_page', null, false, $potentialmembersselector->get_js_module());
4c459d6c 165
653468d4 166 echo $OUTPUT->footer();