2007-01-03 08:17:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The main group management user interface.
|
|
|
|
*
|
|
|
|
* @copyright © 2006 The Open University
|
|
|
|
* @author N.D.Freear AT open.ac.uk
|
2007-08-14 00:50:00 +00:00
|
|
|
* @author J.White AT open.ac.uk
|
2007-01-03 08:17:56 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package groups
|
|
|
|
*/
|
|
|
|
require_once('../config.php');
|
|
|
|
require_once('lib.php');
|
2007-01-22 06:06:08 +00:00
|
|
|
require_once($CFG->libdir.'/json/JSON.php');
|
2007-01-19 04:57:46 +00:00
|
|
|
|
2008-09-25 06:40:52 +00:00
|
|
|
require_js(array('yui_yahoo', 'yui_dom', 'yui_utilities', 'yui_connection'));
|
|
|
|
require_js('group/clientlib.js');
|
2007-02-02 06:36:34 +00:00
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
$courseid = required_param('id', PARAM_INT);
|
|
|
|
$groupid = optional_param('group', false, PARAM_INT);
|
|
|
|
$userid = optional_param('user', false, PARAM_INT);
|
|
|
|
$action = groups_param_action();
|
2007-01-24 03:03:10 +00:00
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid;
|
2007-01-24 03:03:10 +00:00
|
|
|
|
2007-01-03 08:17:56 +00:00
|
|
|
// Get the course information so we can print the header and
|
|
|
|
// check the course id is valid
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2008-05-15 21:40:00 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
|
2007-01-03 08:17:56 +00:00
|
|
|
$success = false;
|
2007-01-17 13:56:09 +00:00
|
|
|
print_error('invalidcourse'); //'The course ID is invalid'
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
// Make sure that the user has permissions to manage groups.
|
|
|
|
require_login($course);
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
$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
|
|
|
|
}
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
switch ($action) {
|
|
|
|
case false: //OK, display form.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ajax_getmembersingroup':
|
2008-01-17 11:28:54 +00:00
|
|
|
$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;
|
2007-01-19 04:57:46 +00:00
|
|
|
}
|
2007-08-16 21:14:03 +00:00
|
|
|
}
|
2008-01-17 11:28:54 +00:00
|
|
|
$json = new Services_JSON();
|
|
|
|
echo $json->encode($roles);
|
2007-08-16 21:14:03 +00:00
|
|
|
die; // Client side JavaScript takes it from here.
|
2007-01-19 04:57:46 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
case 'deletegroup':
|
|
|
|
redirect('group.php?delete=1&courseid='.$courseid.'&id='.$groupid);
|
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
case 'showcreateorphangroupform':
|
|
|
|
redirect('group.php?courseid='.$courseid);
|
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-09-24 21:55:15 +00:00
|
|
|
case 'showautocreategroupsform':
|
|
|
|
redirect('autogroup.php?courseid='.$courseid);
|
2007-11-19 20:31:57 +00:00
|
|
|
break;
|
2007-09-24 21:55:15 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
case 'showgroupsettingsform':
|
|
|
|
redirect('group.php?courseid='.$courseid.'&id='.$groupid);
|
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
case 'updategroups': //Currently reloading.
|
|
|
|
break;
|
2007-01-19 04:57:46 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
case 'removemembers':
|
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
case 'showaddmembersform':
|
|
|
|
redirect('members.php?group='.$groupid);
|
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
case 'updatemembers': //Currently reloading.
|
|
|
|
break;
|
2007-02-19 16:38:18 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
default: //ERROR.
|
|
|
|
if (debugging()) {
|
2008-05-14 06:15:56 +00:00
|
|
|
print_error('unknowaction', '', $returnurl);
|
2007-08-16 21:14:03 +00:00
|
|
|
break;
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
2007-08-16 21:14:03 +00:00
|
|
|
}
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
// Print the page and form
|
|
|
|
$strgroups = get_string('groups');
|
|
|
|
$strparticipants = get_string('participants');
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
$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);
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
/// Print header
|
|
|
|
print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
|
2007-11-19 20:31:57 +00:00
|
|
|
// Add tabs
|
|
|
|
$currenttab = 'groups';
|
|
|
|
require('tabs.php');
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
$disabled = 'disabled="disabled"';
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
$showeditgroupsettingsform_disabled = $disabled;
|
|
|
|
$deletegroup_disabled = $disabled;
|
|
|
|
$showcreategroupform_disabled = $disabled;
|
2007-03-26 06:42:38 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
if (!empty($groupid)) {
|
|
|
|
$showaddmembersform_disabled = '';
|
|
|
|
$showeditgroupsettingsform_disabled = '';
|
|
|
|
$deletegroup_disabled = '';
|
|
|
|
} else {
|
|
|
|
$deletegroup_disabled = $disabled;
|
|
|
|
$showeditgroupsettingsform_disabled = $disabled;
|
|
|
|
$showaddmembersform_disabled = $disabled;
|
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
|
|
|
|
echo '<form id="groupeditform" action="index.php" method="post">'."\n";
|
|
|
|
echo '<div>'."\n";
|
|
|
|
echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n";
|
|
|
|
echo '<tr>'."\n";
|
2007-08-16 11:06:48 +00:00
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
echo "<td>\n";
|
|
|
|
echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping"> </span></label></p>'."\n";
|
2007-08-03 03:03:05 +00:00
|
|
|
|
2007-09-20 07:20:15 +00:00
|
|
|
if (ajaxenabled()) {
|
|
|
|
$onchange = 'membersCombo.refreshMembers(this.options[this.selectedIndex].value);';
|
|
|
|
} else {
|
2007-11-19 20:31:57 +00:00
|
|
|
$onchange = '';
|
2007-09-20 07:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
echo '<select name="group" id="groups" size="15" class="select" onchange="'.$onchange.'"'."\n";
|
2007-08-16 21:14:03 +00:00
|
|
|
echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
|
2007-07-07 14:18:30 +12:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
$groups = groups_get_all_groups($courseid);
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
$sel_groupid = 0;
|
2007-08-16 09:28:18 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
if ($groups) {
|
|
|
|
// Print out the HTML
|
|
|
|
foreach ($groups as $group) {
|
|
|
|
$select = '';
|
|
|
|
if ($groupid == $group->id) {
|
|
|
|
$select = ' selected="selected"';
|
|
|
|
$sel_groupid = $group->id;
|
2007-08-16 09:28:18 +00:00
|
|
|
}
|
2008-05-15 21:40:00 +00:00
|
|
|
$usercount = $DB->count_records('groups_members', array('groupid'=>$group->id));
|
2007-08-16 21:14:03 +00:00
|
|
|
$groupname = format_string($group->name).' ('.$usercount.')';
|
|
|
|
|
|
|
|
echo "<option value=\"{$group->id}\"$select title=\"$groupname\">$groupname</option>\n";
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
2007-08-16 21:14:03 +00:00
|
|
|
} else {
|
|
|
|
// Print an empty option to avoid the XHTML error of having an empty select element
|
|
|
|
echo '<option> </option>';
|
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
echo '</select>'."\n";
|
|
|
|
echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
|
|
|
|
. get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
|
|
|
|
echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
|
|
|
|
. get_string('editgroupsettings', 'group') . '" /></p>'."\n";
|
|
|
|
echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
|
|
|
|
. get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
|
|
|
|
|
|
|
|
echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
|
|
|
|
. get_string('creategroup', 'group') . '" /></p>'."\n";
|
2007-11-19 20:31:57 +00:00
|
|
|
|
2007-09-24 21:55:15 +00:00
|
|
|
echo '<p><input type="submit" name="act_showautocreategroupsform" id="showautocreategroupsform" value="'
|
|
|
|
. get_string('autocreategroups', 'group') . '" /></p>'."\n";
|
2007-08-16 21:14:03 +00:00
|
|
|
|
|
|
|
echo '</td>'."\n";
|
|
|
|
echo '<td>'."\n";
|
|
|
|
echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup"> </span></label></p>'."\n";
|
|
|
|
//NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick.
|
|
|
|
echo '<select name="user" id="members" size="15" class="select"'."\n";
|
|
|
|
echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
|
|
|
|
|
|
|
|
$member_names = array();
|
|
|
|
|
2008-01-17 11:28:54 +00:00
|
|
|
$atleastonemember = false;
|
2007-08-16 21:14:03 +00:00
|
|
|
if ($sel_groupid) {
|
2008-01-17 11:28:54 +00:00
|
|
|
|
|
|
|
if ($groupmemberroles = groups_get_members_by_role($groupid,$courseid,'u.id,u.firstname,u.lastname')) {
|
|
|
|
foreach($groupmemberroles as $roleid=>$roledata) {
|
2008-06-01 13:09:04 +00:00
|
|
|
echo '<optgroup label="'.s($roledata->name).'">';
|
2008-01-17 11:28:54 +00:00
|
|
|
foreach($roledata->users as $member) {
|
|
|
|
echo '<option value="'.$member->id.'">'.fullname($member, true).'</option>';
|
|
|
|
$atleastonemember = true;
|
|
|
|
}
|
|
|
|
echo '</optgroup>';
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
2008-01-17 11:28:54 +00:00
|
|
|
}
|
2007-08-16 21:14:03 +00:00
|
|
|
}
|
2008-01-17 11:28:54 +00:00
|
|
|
|
|
|
|
if (!$atleastonemember) {
|
2007-08-16 21:14:03 +00:00
|
|
|
// Print an empty option to avoid the XHTML error of having an empty select element
|
|
|
|
echo '<option> </option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</select>'."\n";
|
2007-03-26 06:42:38 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
|
|
|
|
. 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
|
|
|
|
echo '</td>'."\n";
|
|
|
|
echo '</tr>'."\n";
|
|
|
|
echo '</table>'."\n";
|
2007-03-26 06:42:38 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
//<input type="hidden" name="rand" value="om" />
|
|
|
|
echo '</div>'."\n";
|
|
|
|
echo '</form>'."\n";
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-09-04 07:28:14 +00:00
|
|
|
if (ajaxenabled()) {
|
|
|
|
echo '<script type="text/javascript">'."\n";
|
|
|
|
echo '//<![CDATA['."\n";
|
|
|
|
echo 'var groupsCombo = new UpdatableGroupsCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
|
|
|
|
echo 'var membersCombo = new UpdatableMembersCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
|
|
|
|
echo '//]]>'."\n";
|
|
|
|
echo '</script>'."\n";
|
|
|
|
}
|
2007-01-19 04:57:46 +00:00
|
|
|
|
2007-08-16 21:14:03 +00:00
|
|
|
print_footer($course);
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-08-15 20:21:01 +00:00
|
|
|
/**
|
|
|
|
* 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) {
|
2007-08-15 23:51:07 +00:00
|
|
|
$form_vars = $_GET;
|
2007-08-15 20:21:01 +00:00
|
|
|
}
|
|
|
|
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;
|
2008-05-14 06:15:56 +00:00
|
|
|
print_error('unknowaction');
|
2007-08-15 20:21:01 +00:00
|
|
|
}
|
|
|
|
///if (debugging()) echo 'Debug: '.$action;
|
|
|
|
return $action;
|
|
|
|
}
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-09-04 07:28:14 +00:00
|
|
|
?>
|