lesson MDL-19812 Updated print_header and build_navigation to OUTPUT and PAGE equivalents
[moodle.git] / group / members.php
CommitLineData
acf000b0 1<?php // $Id$
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');
62d63838 15
aa9671c9 16$groupid = required_param('group', PARAM_INT);
62d63838 17
dfdaabd6 18if (!$group = $DB->get_record('groups', array('id'=>$groupid))) {
b121a4ee 19 print_error('invalidgroupid');
62d63838 20}
21
dfdaabd6 22if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
62d63838 23 print_error('invalidcourse');
24}
25$courseid = $course->id;
26
27require_login($course);
28$context = get_context_instance(CONTEXT_COURSE, $courseid);
29require_capability('moodle/course:managegroups', $context);
30
62d63838 31$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid.'&group='.$group->id;
32
97873016 33if (optional_param('cancel', false, PARAM_BOOL)) {
34 redirect($returnurl);
35}
62d63838 36
97873016 37$groupmembersselector = new group_members_selector('removeselect',
38 array('groupid' => $groupid, 'courseid' => $course->id));
39$groupmembersselector->set_extra_fields(array());
40$potentialmembersselector = new group_non_members_selector('addselect',
41 array('groupid' => $groupid, 'courseid' => $course->id));
42$potentialmembersselector->set_extra_fields(array());
43
44if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
45 $userstoadd = $potentialmembersselector->get_selected_users();
46 if (!empty($userstoadd)) {
47 foreach ($userstoadd as $user) {
48 if (!groups_add_member($groupid, $user->id)) {
62d63838 49 print_error('erroraddremoveuser', 'group', $returnurl);
50 }
97873016 51 $groupmembersselector->invalidate_selected_users();
52 $potentialmembersselector->invalidate_selected_users();
62d63838 53 }
62d63838 54 }
62d63838 55}
56
97873016 57if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
58 $userstoremove = $groupmembersselector->get_selected_users();
59 if (!empty($userstoremove)) {
60 foreach ($userstoremove as $user) {
61 if (!groups_remove_member($groupid, $user->id)) {
62 print_error('erroraddremoveuser', 'group', $returnurl);
e254aa34 63 }
97873016 64 $groupmembersselector->invalidate_selected_users();
65 $potentialmembersselector->invalidate_selected_users();
62d63838 66 }
62d63838 67 }
68}
69
70// Print the page and form
71$strgroups = get_string('groups');
72$strparticipants = get_string('participants');
0be6f678 73$stradduserstogroup = get_string('adduserstogroup', 'group');
acf000b0 74$strusergroupmembership = get_string('usergroupmembership', 'group');
62d63838 75
76$groupname = format_string($group->name);
77
0be6f678 78$navlinks = array();
79$navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$courseid", 'type' => 'misc');
80$navlinks[] = array('name' => $strgroups, 'link' => "$CFG->wwwroot/group/index.php?id=$courseid", 'type' => 'misc');
81$navlinks[] = array('name' => $stradduserstogroup, 'link' => null, 'type' => 'misc');
82$navigation = build_navigation($navlinks);
83
cf615522 84$PAGE->requires->js('group/clientlib.js');
85$PAGE->requires->js_function_call('init_add_remove_members_page');
0be6f678 86print_header("$course->shortname: $strgroups", $course->fullname, $navigation, '', '', true, '', user_login_string($course, $USER));
97873016 87check_theme_arrows();
62d63838 88?>
acf000b0 89
62d63838 90<div id="addmembersform">
91 <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
92
aa9671c9 93 <form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
62d63838 94 <div>
95 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
62d63838 96
97873016 97 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
62d63838 98 <tr>
6cab02ac 99 <td id='existingcell'>
acf000b0 100 <p>
97873016 101 <label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
acf000b0 102 </p>
97873016 103 <?php $groupmembersselector->display(); ?>
104 </td>
105 <td id='buttonscell'>
62d63838 106 <p class="arrow_button">
d3789c64 107 <input name="add" id="add" type="submit" value="<?php echo $THEME->larrow.'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
108 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$THEME->rarrow; ?>" title="<?php print_string('remove'); ?>" />
62d63838 109 </p>
110 </td>
6cab02ac 111 <td id='potentialcell'>
acf000b0 112 <p>
97873016 113 <label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
acf000b0 114 </p>
97873016 115 <?php $potentialmembersselector->display(); ?>
116 </td>
62d63838 117 </tr>
97873016 118 <tr><td colspan="3" id='backcell'>
62d63838 119 <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
120 </td></tr>
121 </table>
122 </div>
123 </form>
124</div>
125
126<?php
653468d4 127 echo $OUTPUT->footer();
62d63838 128?>