weekly release 2.3dev
[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');
99d19c13 15require_once($CFG->libdir . '/filelib.php');
62d63838 16
aa9671c9 17$groupid = required_param('group', PARAM_INT);
4f0c2d00 18$cancel = optional_param('cancel', false, PARAM_BOOL);
62d63838 19
4f0c2d00
PS
20$group = $DB->get_record('groups', array('id'=>$groupid), '*', MUST_EXIST);
21$course = $DB->get_record('course', array('id'=>$group->courseid), '*', MUST_EXIST);
62d63838 22
a6855934 23$PAGE->set_url('/groups/members.php', array('id'=>$groupid));
c1fbff27 24$PAGE->set_pagelayout('standard');
849185ce 25
62d63838 26require_login($course);
4f0c2d00 27$context = get_context_instance(CONTEXT_COURSE, $course->id);
62d63838 28require_capability('moodle/course:managegroups', $context);
29
4f0c2d00 30$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$group->id;
62d63838 31
4f0c2d00 32if ($cancel) {
97873016 33 redirect($returnurl);
34}
62d63838 35
4f0c2d00 36$groupmembersselector = new group_members_selector('removeselect', array('groupid' => $groupid, 'courseid' => $course->id));
4f0c2d00 37$potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id));
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();
74feb96a
MD
83echo $OUTPUT->heading(get_string('adduserstogroup', 'group').": $groupname", 3);
84
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);
91
92$contentcell = new html_table_cell();
93$contentcell->attributes['class'] = 'content';
94
95$group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group', 'description', $group->id);
96if (!isset($group->descriptionformat)) {
97 $group->descriptionformat = FORMAT_MOODLE;
98}
367a75fa
SH
99$options = new stdClass;
100$options->overflowdiv = true;
101$contentcell->text = format_text($group->description, $group->descriptionformat, $options);
74feb96a
MD
102$groupinfotable->data[] = new html_table_row(array($picturecell, $contentcell));
103echo html_writer::table($groupinfotable);
104
105/// Print the editing form
62d63838 106?>
acf000b0 107
62d63838 108<div id="addmembersform">
aa9671c9 109 <form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
62d63838 110 <div>
111 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
62d63838 112
97873016 113 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
62d63838 114 <tr>
6cab02ac 115 <td id='existingcell'>
acf000b0 116 <p>
97873016 117 <label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
acf000b0 118 </p>
97873016 119 <?php $groupmembersselector->display(); ?>
120 </td>
121 <td id='buttonscell'>
62d63838 122 <p class="arrow_button">
92e01ab7
PS
123 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
124 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
62d63838 125 </p>
126 </td>
6cab02ac 127 <td id='potentialcell'>
acf000b0 128 <p>
97873016 129 <label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
acf000b0 130 </p>
97873016 131 <?php $potentialmembersselector->display(); ?>
132 </td>
bf1ac6d9
AD
133 <td>
134 <p><?php echo($strusergroupmembership) ?></p>
135 <div id="group-usersummary"></div>
136 </td>
62d63838 137 </tr>
97873016 138 <tr><td colspan="3" id='backcell'>
62d63838 139 <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
140 </td></tr>
141 </table>
142 </div>
143 </form>
144</div>
145
146<?php
bf1ac6d9
AD
147 //outputs the JS array used to display the other groups users are in
148 $potentialmembersselector->print_user_summaries($course->id);
149
4c459d6c 150 //this must be after calling display() on the selectors so their setup JS executes first
f19497f2 151 $PAGE->requires->js_init_call('init_add_remove_members_page', null, false, $potentialmembersselector->get_js_module());
4c459d6c 152
653468d4 153 echo $OUTPUT->footer();