libdir.'/json/JSON.php'); require_js('yui_yahoo'); require_js('yui_dom'); require_js('yui_utilities'); require_js('yui_connection'); require_js($CFG->wwwroot.'/group/clientlib.js'); $courseid = required_param('id', PARAM_INT); $groupid = optional_param('group', false, PARAM_INT); $userid = optional_param('user', false, PARAM_INT); $action = groups_param_action(); $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 if (!$course = get_record('course', 'id',$courseid)) { $success = false; print_error('invalidcourse'); //'The course ID is invalid' } // Make sure that the user has permissions to manage groups. require_login($course); $context = get_context_instance(CONTEXT_COURSE, $courseid); if (! has_capability('moodle/course:managegroups', $context)) { redirect(); //"group.php?id=$course->id"); // Not allowed to see all groups } switch ($action) { case false: //OK, display form. break; case 'ajax_getmembersingroup': $roles = array(); if ($groupmemberroles = groups_get_members_by_role($groupid,$courseid,'u.id,u.firstname,u.lastname')) { 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; } } $json = new Services_JSON(); echo $json->encode($roles); die; // Client side JavaScript takes it from here. case 'deletegroup': redirect('group.php?delete=1&courseid='.$courseid.'&id='.$groupid); break; case 'showcreateorphangroupform': redirect('group.php?courseid='.$courseid); break; case 'showautocreategroupsform': redirect('autogroup.php?courseid='.$courseid); break; case 'showgroupsettingsform': redirect('group.php?courseid='.$courseid.'&id='.$groupid); break; case 'updategroups': //Currently reloading. break; case 'removemembers': break; case 'showaddmembersform': redirect('members.php?group='.$groupid); break; case 'updatemembers': //Currently reloading. break; default: //ERROR. if (debugging()) { error('Error, unknown button/action. Probably a user-interface bug!', $returnurl); break; } } // Print the page and form $strgroups = get_string('groups'); $strparticipants = get_string('participants'); $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'), array('name'=>$strgroups, 'link'=>'', 'type'=>'misc')); $navigation = build_navigation($navlinks); /// Print header print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course)); // Add tabs $currenttab = 'groups'; require('tabs.php'); $disabled = 'disabled="disabled"'; $showeditgroupsettingsform_disabled = $disabled; $deletegroup_disabled = $disabled; $showcreategroupform_disabled = $disabled; if (!empty($groupid)) { $showaddmembersform_disabled = ''; $showeditgroupsettingsform_disabled = ''; $deletegroup_disabled = ''; } else { $deletegroup_disabled = $disabled; $showeditgroupsettingsform_disabled = $disabled; $showaddmembersform_disabled = $disabled; } print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3); echo '
'."\n"; echo '
'."\n"; echo ''."\n"; echo ''."\n"; echo ''."\n"; echo "'."\n"; echo ''."\n"; echo ''."\n"; echo '
\n"; // NO GROUPINGS YET! echo '

'."\n"; if (ajaxenabled()) { $onchange = 'membersCombo.refreshMembers(this.options[this.selectedIndex].value);'; } else { $onchange = ''; } echo ''."\n"; echo '

'."\n"; echo '

'."\n"; echo '

'."\n"; echo '

'."\n"; echo '

'."\n"; echo '
'."\n"; echo '

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

'."\n"; echo '
'."\n"; // echo '
'."\n"; echo '
'."\n"; if (ajaxenabled()) { echo ''."\n"; } print_footer($course); /** * 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 $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; error('Action had wrong type.'); } ///if (debugging()) echo 'Debug: '.$action; return $action; } ?>