. /** * The main group management user interface. * * @copyright 2006 The Open University, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package core_group */ require_once('../config.php'); require_once('lib.php'); $courseid = required_param('id', PARAM_INT); $groupid = optional_param('group', false, PARAM_INT); $userid = optional_param('user', false, PARAM_INT); $action = groups_param_action(); // Support either single group= parameter, or array groups[] if ($groupid) { $groupids = array($groupid); } else { $groupids = optional_param_array('groups', array(), PARAM_INT); } $singlegroup = (count($groupids) == 1); $returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid; // Get the course information so we can print the header and // check the course id is valid $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); $url = new moodle_url('/group/index.php', array('id'=>$courseid)); if ($userid) { $url->param('user', $userid); } if ($groupid) { $url->param('group', $groupid); } $PAGE->set_url($url); // Make sure that the user has permissions to manage groups. require_login($course); $context = context_course::instance($course->id); require_capability('moodle/course:managegroups', $context); $PAGE->requires->js('/group/clientlib.js'); // Check for multiple/no group errors if (!$singlegroup) { switch($action) { case 'ajax_getmembersingroup': case 'showgroupsettingsform': case 'showaddmembersform': case 'updatemembers': print_error('errorselectone', 'group', $returnurl); } } switch ($action) { case false: //OK, display form. break; case 'ajax_getmembersingroup': $roles = array(); if ($groupmemberroles = groups_get_members_by_role($groupids[0], $courseid, 'u.id, ' . get_all_user_name_fields(true, 'u'))) { foreach($groupmemberroles as $roleid=>$roledata) { $shortroledata = new stdClass(); $shortroledata->name = $roledata->name; $shortroledata->users = array(); foreach($roledata->users as $member) { $shortmember = new stdClass(); $shortmember->id = $member->id; $shortmember->name = fullname($member, true); $shortroledata->users[] = $shortmember; } $roles[] = $shortroledata; } } echo json_encode($roles); die; // Client side JavaScript takes it from here. case 'deletegroup': if (count($groupids) == 0) { print_error('errorselectsome','group',$returnurl); } $groupidlist = implode(',', $groupids); redirect(new moodle_url('/group/delete.php', array('courseid'=>$courseid, 'groups'=>$groupidlist))); break; case 'showcreateorphangroupform': redirect(new moodle_url('/group/group.php', array('courseid'=>$courseid))); break; case 'showautocreategroupsform': redirect(new moodle_url('/group/autogroup.php', array('courseid'=>$courseid))); break; case 'showimportgroups': redirect(new moodle_url('/group/import.php', array('id'=>$courseid))); break; case 'showgroupsettingsform': redirect(new moodle_url('/group/group.php', array('courseid'=>$courseid, 'id'=>$groupids[0]))); break; case 'updategroups': //Currently reloading. break; case 'removemembers': break; case 'showaddmembersform': redirect(new moodle_url('/group/members.php', array('group'=>$groupids[0]))); break; case 'updatemembers': //Currently reloading. break; default: //ERROR. print_error('unknowaction', '', $returnurl); break; } // Print the page and form $strgroups = get_string('groups'); $strparticipants = get_string('participants'); /// Print header $PAGE->set_title($strgroups); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('standard'); echo $OUTPUT->header(); // Add tabs $currenttab = 'groups'; require('tabs.php'); $disabled = 'disabled="disabled"'; // Some buttons are enabled if single group selected. $showaddmembersform_disabled = $singlegroup ? '' : $disabled; $showeditgroupsettingsform_disabled = $singlegroup ? '' : $disabled; $deletegroup_disabled = count($groupids) > 0 ? '' : $disabled; echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $context)) .' '.$strgroups, 3); echo '
'."\n"; echo '
'."\n"; echo ''."\n"; echo html_writer::start_tag('div', array('class' => 'groupmanagementtable boxaligncenter')); echo html_writer::start_tag('div', array('class' => 'groups')); echo '

'."\n"; $onchange = 'M.core_group.membersCombo.refreshMembers();'; echo ''."\n"; echo '

'."\n"; echo '

'."\n"; echo '

'."\n"; echo '

'."\n"; echo '

'."\n"; echo '

'."\n"; echo html_writer::end_tag('div'); echo html_writer::start_tag('div', array('class' => 'members')); echo '

'."\n"; //NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick. echo ''."\n"; echo '

'."\n"; echo html_writer::end_tag('div'); echo html_writer::end_tag('div'); // echo '
'."\n"; echo '
'."\n"; $PAGE->requires->js_init_call('M.core_group.init_index', array($CFG->wwwroot, $courseid)); $PAGE->requires->js_init_call('M.core_group.groupslist', array($preventgroupremoval)); echo $OUTPUT->footer(); /** * Returns the first button action with the given prefix, taken from * POST or GET, otherwise returns false. * @see /lib/moodlelib.php function optional_param(). * @param string $prefix 'act_' as in 'action'. * @return string The action without the prefix, or false if no action found. */ function groups_param_action($prefix = 'act_') { $action = false; //($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/ if ($_POST) { $form_vars = $_POST; } elseif ($_GET) { $form_vars = $_GET; } if ($form_vars) { foreach ($form_vars as $key => $value) { if (preg_match("/$prefix(.+)/", $key, $matches)) { $action = $matches[1]; break; } } } if ($action && !preg_match('/^\w+$/', $action)) { $action = false; print_error('unknowaction'); } ///if (debugging()) echo 'Debug: '.$action; return $action; }