Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
1 <?php 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 18 /** 19 * The main group management user interface. 20 * 21 * @copyright 2006 The Open University, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 * @package core_group 24 */ 25 require_once('../config.php'); 26 require_once ('lib.php'); 27 28 $courseid = required_param('id', PARAM_INT); 29 $groupid = optional_param('group', false, PARAM_INT); 30 $userid = optional_param('user', false, PARAM_INT); 31 $action = groups_param_action(); 32 // Support either single group= parameter, or array groups[] 33 if ($groupid) { 34 $groupids = array($groupid); 35 } else { 36 $groupids = optional_param_array('groups', array(), PARAM_INT); 37 } 38 $singlegroup = (count($groupids) == 1); 39 40 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid; 41 42 // Get the course information so we can print the header and 43 // check the course id is valid 44 45 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); 46 47 $url = new moodle_url('/group/index.php', array('id'=>$courseid)); 48 navigation_node::override_active_url($url); 49 if ($userid) { 50 $url->param('user', $userid); 51 } 52 if ($groupid) { 53 $url->param('group', $groupid); 54 } 55 $PAGE->set_url($url); 56 57 // Make sure that the user has permissions to manage groups. 58 require_login($course); 59 60 $context = context_course::instance($course->id); 61 require_capability('moodle/course:managegroups', $context); 62 63 $PAGE->requires->js('/group/clientlib.js', true); 64 $PAGE->requires->js('/group/module.js', true); 65 66 // Check for multiple/no group errors 67 if (!$singlegroup) { 68 switch($action) { 69 case 'ajax_getmembersingroup': 70 case 'showgroupsettingsform': 71 case 'showaddmembersform': 72 case 'updatemembers': 73 print_error('errorselectone', 'group', $returnurl); 74 } 75 } 76 77 switch ($action) { 78 case false: //OK, display form. 79 break; 80 81 case 'ajax_getmembersingroup': 82 $roles = array(); 83 84 $extrafields = get_extra_user_fields($context); 85 if ($groupmemberroles = groups_get_members_by_role($groupids[0], $courseid, 86 'u.id, ' . user_picture::fields('u', $extrafields))) { 87 88 $viewfullnames = has_capability('moodle/site:viewfullnames', $context); 89 90 foreach($groupmemberroles as $roleid=>$roledata) { 91 $shortroledata = new stdClass(); 92 $shortroledata->name = $roledata->name; 93 $shortroledata->users = array(); 94 foreach($roledata->users as $member) { 95 $shortmember = new stdClass(); 96 $shortmember->id = $member->id; 97 $shortmember->name = fullname($member, $viewfullnames); 98 if ($extrafields) { 99 $extrafieldsdisplay = []; 100 foreach ($extrafields as $field) { 101 // No escaping here, handled client side in response to AJAX request. 102 $extrafieldsdisplay[] = $member->{$field}; 103 } 104 $shortmember->name .= ' (' . implode(', ', $extrafieldsdisplay) . ')'; 105 } 106 107 $shortroledata->users[] = $shortmember; 108 } 109 $roles[] = $shortroledata; 110 } 111 } 112 echo json_encode($roles); 113 die; // Client side JavaScript takes it from here. 114 115 case 'deletegroup': 116 if (count($groupids) == 0) { 117 print_error('errorselectsome','group',$returnurl); 118 } 119 $groupidlist = implode(',', $groupids); 120 redirect(new moodle_url('/group/delete.php', array('courseid'=>$courseid, 'groups'=>$groupidlist))); 121 break; 122 123 case 'showcreateorphangroupform': 124 redirect(new moodle_url('/group/group.php', array('courseid'=>$courseid))); 125 break; 126 127 case 'showautocreategroupsform': 128 redirect(new moodle_url('/group/autogroup.php', array('courseid'=>$courseid))); 129 break; 130 131 case 'showimportgroups': 132 redirect(new moodle_url('/group/import.php', array('id'=>$courseid))); 133 break; 134 135 case 'showgroupsettingsform': 136 redirect(new moodle_url('/group/group.php', array('courseid'=>$courseid, 'id'=>$groupids[0]))); 137 break; 138 139 case 'updategroups': //Currently reloading. 140 break; 141 142 case 'removemembers': 143 break; 144 145 case 'showaddmembersform': 146 redirect(new moodle_url('/group/members.php', array('group'=>$groupids[0]))); 147 break; 148 149 case 'updatemembers': //Currently reloading. 150 break; 151 152 default: //ERROR. 153 print_error('unknowaction', '', $returnurl); 154 break; 155 } 156 157 // Print the page and form 158 $strgroups = get_string('groups'); 159 $strparticipants = get_string('participants'); 160 161 /// Print header 162 $PAGE->set_title($strgroups); 163 $PAGE->set_heading($course->fullname); 164 $PAGE->set_pagelayout('standard'); 165 echo $OUTPUT->header(); 166 167 // Add tabs 168 $currenttab = 'groups'; 169 require ('tabs.php'); 170 171 echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $context)) .' '.$strgroups, 3); 172 173 $groups = groups_get_all_groups($courseid); 174 $selectedname = null; 175 $preventgroupremoval = array(); 176 177 // Get list of groups to render. 178 $groupoptions = array(); 179 if ($groups) { 180 foreach ($groups as $group) { 181 $selected = false; 182 $usercount = $DB->count_records('groups_members', array('groupid' => $group->id)); 183 $groupname = format_string($group->name) . ' (' . $usercount . ')'; 184 if (in_array($group->id, $groupids)) { 185 $selected = true; 186 if ($singlegroup) { 187 // Only keep selected name if there is one group selected. 188 $selectedname = $groupname; 189 } 190 } 191 if (!empty($group->idnumber) && !has_capability('moodle/course:changeidnumber', $context)) { 192 $preventgroupremoval[$group->id] = true; 193 } 194 195 $groupoptions[] = (object) [ 196 'value' => $group->id, 197 'selected' => $selected, 198 'text' => s($groupname) 199 ]; 200 } 201 } 202 203 // Get list of group members to render if there is a single selected group. 204 $members = array(); 205 if ($singlegroup) { 206 $extrafields = get_extra_user_fields($context); 207 if ($groupmemberroles = groups_get_members_by_role(reset($groupids), $courseid, 208 'u.id, ' . user_picture::fields('u', $extrafields))) { 209 210 $viewfullnames = has_capability('moodle/site:viewfullnames', $context); 211 212 foreach ($groupmemberroles as $roleid => $roledata) { 213 $users = array(); 214 foreach ($roledata->users as $member) { 215 $shortmember = new stdClass(); 216 $shortmember->value = $member->id; 217 $shortmember->text = fullname($member, $viewfullnames); 218 if ($extrafields) { 219 $extrafieldsdisplay = []; 220 foreach ($extrafields as $field) { 221 $extrafieldsdisplay[] = s($member->{$field}); 222 } 223 $shortmember->text .= ' (' . implode(', ', $extrafieldsdisplay) . ')'; 224 } 225 226 $users[] = $shortmember; 227 } 228 $members[] = (object)[ 229 'role' => s($roledata->name), 230 'rolemembers' => $users 231 ]; 232 } 233 } 234 } 235 236 $disableaddedit = !$singlegroup; 237 $disabledelete = !empty($groupids); 238 $renderable = new \core_group\output\index_page($courseid, $groupoptions, $selectedname, $members, $disableaddedit, $disabledelete, 239 $preventgroupremoval); 240 $output = $PAGE->get_renderer('core_group'); 241 echo $output->render($renderable); 242 243 echo $OUTPUT->footer(); 244 245 /** 246 * Returns the first button action with the given prefix, taken from 247 * POST or GET, otherwise returns false. 248 * @see /lib/moodlelib.php function optional_param(). 249 * @param string $prefix 'act_' as in 'action'. 250 * @return string The action without the prefix, or false if no action found. 251 */ 252 function groups_param_action($prefix = 'act_') { 253 $action = false; 254 //($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/ 255 256 if ($_POST) { 257 $form_vars = $_POST; 258 } 259 elseif ($_GET) { 260 $form_vars = $_GET; 261 } 262 if ($form_vars) { 263 foreach ($form_vars as $key => $value) { 264 if (preg_match("/$prefix(.+)/", $key, $matches)) { 265 $action = $matches[1]; 266 break; 267 } 268 } 269 } 270 if ($action && !preg_match('/^\w+$/', $action)) { 271 $action = false; 272 print_error('unknowaction'); 273 } 274 ///if (debugging()) echo 'Debug: '.$action; 275 return $action; 276 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body