Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
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 $userfieldsapi = \core_user\fields::for_identity($context)->with_userpic(); 85 [ 86 'selects' => $userfieldsselects, 87 'joins' => $userfieldsjoin, 88 'params' => $userfieldsparams 89 ] = (array)$userfieldsapi->get_sql('u', true, '', '', false); 90 $extrafields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]); 91 if ($groupmemberroles = groups_get_members_by_role($groupids[0], $courseid, 92 'u.id, ' . $userfieldsselects, null, '', $userfieldsparams, $userfieldsjoin)) { 93 94 $viewfullnames = has_capability('moodle/site:viewfullnames', $context); 95 96 foreach($groupmemberroles as $roleid=>$roledata) { 97 $shortroledata = new stdClass(); 98 $shortroledata->name = $roledata->name; 99 $shortroledata->users = array(); 100 foreach($roledata->users as $member) { 101 $shortmember = new stdClass(); 102 $shortmember->id = $member->id; 103 $shortmember->name = fullname($member, $viewfullnames); 104 if ($extrafields) { 105 $extrafieldsdisplay = []; 106 foreach ($extrafields as $field) { 107 // No escaping here, handled client side in response to AJAX request. 108 $extrafieldsdisplay[] = $member->{$field}; 109 } 110 $shortmember->name .= ' (' . implode(', ', $extrafieldsdisplay) . ')'; 111 } 112 113 $shortroledata->users[] = $shortmember; 114 } 115 $roles[] = $shortroledata; 116 } 117 } 118 echo json_encode($roles); 119 die; // Client side JavaScript takes it from here. 120 121 case 'deletegroup': 122 if (count($groupids) == 0) { 123 print_error('errorselectsome','group',$returnurl); 124 } 125 $groupidlist = implode(',', $groupids); 126 redirect(new moodle_url('/group/delete.php', array('courseid'=>$courseid, 'groups'=>$groupidlist))); 127 break; 128 129 case 'showcreateorphangroupform': 130 redirect(new moodle_url('/group/group.php', array('courseid'=>$courseid))); 131 break; 132 133 case 'showautocreategroupsform': 134 redirect(new moodle_url('/group/autogroup.php', array('courseid'=>$courseid))); 135 break; 136 137 case 'showimportgroups': 138 redirect(new moodle_url('/group/import.php', array('id'=>$courseid))); 139 break; 140 141 case 'showgroupsettingsform': 142 redirect(new moodle_url('/group/group.php', array('courseid'=>$courseid, 'id'=>$groupids[0]))); 143 break; 144 145 case 'updategroups': //Currently reloading. 146 break; 147 148 case 'removemembers': 149 break; 150 151 case 'showaddmembersform': 152 redirect(new moodle_url('/group/members.php', array('group'=>$groupids[0]))); 153 break; 154 155 case 'updatemembers': //Currently reloading. 156 break; 157 158 default: //ERROR. 159 print_error('unknowaction', '', $returnurl); 160 break; 161 } 162 163 // Print the page and form 164 $strgroups = get_string('groups'); 165 $strparticipants = get_string('participants'); 166 167 /// Print header 168 $PAGE->set_title($strgroups); 169 $PAGE->set_heading($course->fullname); 170 $PAGE->set_pagelayout('standard'); 171 echo $OUTPUT->header(); 172 173 // Add tabs 174 $currenttab = 'groups'; 175 require ('tabs.php'); 176 177 echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $context)) .' '.$strgroups, 3); 178 179 $groups = groups_get_all_groups($courseid); 180 $selectedname = null; 181 $preventgroupremoval = array(); 182 183 // Get list of groups to render. 184 $groupoptions = array(); 185 if ($groups) { 186 foreach ($groups as $group) { 187 $selected = false; 188 $usercount = $DB->count_records('groups_members', array('groupid' => $group->id)); 189 $groupname = format_string($group->name) . ' (' . $usercount . ')'; 190 if (in_array($group->id, $groupids)) { 191 $selected = true; 192 if ($singlegroup) { 193 // Only keep selected name if there is one group selected. 194 $selectedname = $groupname; 195 } 196 } 197 if (!empty($group->idnumber) && !has_capability('moodle/course:changeidnumber', $context)) { 198 $preventgroupremoval[$group->id] = true; 199 } 200 201 $groupoptions[] = (object) [ 202 'value' => $group->id, 203 'selected' => $selected, 204 'text' => s($groupname) 205 ]; 206 } 207 } 208 209 // Get list of group members to render if there is a single selected group. 210 $members = array(); 211 if ($singlegroup) { 212 $userfieldsapi = \core_user\fields::for_identity($context)->with_userpic(); 213 [ 214 'selects' => $userfieldsselects, 215 'joins' => $userfieldsjoin, 216 'params' => $userfieldsparams 217 ] = (array)$userfieldsapi->get_sql('u', true, '', '', false); 218 $extrafields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]); 219 if ($groupmemberroles = groups_get_members_by_role(reset($groupids), $courseid, 220 'u.id, ' . $userfieldsselects, null, '', $userfieldsparams, $userfieldsjoin)) { 221 222 $viewfullnames = has_capability('moodle/site:viewfullnames', $context); 223 224 foreach ($groupmemberroles as $roleid => $roledata) { 225 $users = array(); 226 foreach ($roledata->users as $member) { 227 $shortmember = new stdClass(); 228 $shortmember->value = $member->id; 229 $shortmember->text = fullname($member, $viewfullnames); 230 if ($extrafields) { 231 $extrafieldsdisplay = []; 232 foreach ($extrafields as $field) { 233 $extrafieldsdisplay[] = s($member->{$field}); 234 } 235 $shortmember->text .= ' (' . implode(', ', $extrafieldsdisplay) . ')'; 236 } 237 238 $users[] = $shortmember; 239 } 240 $members[] = (object)[ 241 'role' => s($roledata->name), 242 'rolemembers' => $users 243 ]; 244 } 245 } 246 } 247 248 $disableaddedit = !$singlegroup; 249 $disabledelete = !empty($groupids); 250 $renderable = new \core_group\output\index_page($courseid, $groupoptions, $selectedname, $members, $disableaddedit, $disabledelete, 251 $preventgroupremoval); 252 $output = $PAGE->get_renderer('core_group'); 253 echo $output->render($renderable); 254 255 echo $OUTPUT->footer(); 256 257 /** 258 * Returns the first button action with the given prefix, taken from 259 * POST or GET, otherwise returns false. 260 * @see /lib/moodlelib.php function optional_param(). 261 * @param string $prefix 'act_' as in 'action'. 262 * @return string The action without the prefix, or false if no action found. 263 */ 264 function groups_param_action($prefix = 'act_') { 265 $action = false; 266 //($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/ 267 268 if ($_POST) { 269 $form_vars = $_POST; 270 } 271 elseif ($_GET) { 272 $form_vars = $_GET; 273 } 274 if ($form_vars) { 275 foreach ($form_vars as $key => $value) { 276 if (preg_match("/$prefix(.+)/", $key, $matches)) { 277 $action = $matches[1]; 278 break; 279 } 280 } 281 } 282 if ($action && !preg_match('/^\w+$/', $action)) { 283 $action = false; 284 print_error('unknowaction'); 285 } 286 ///if (debugging()) echo 'Debug: '.$action; 287 return $action; 288 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body