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
|
|
|
|
2007-02-02 06:36:34 +00:00
|
|
|
require_js('yui_yahoo');
|
|
|
|
require_js('yui_dom');
|
2007-08-03 03:03:05 +00:00
|
|
|
require_js('yui_utilities');
|
2007-02-02 06:36:34 +00:00
|
|
|
require_js('yui_connection');
|
|
|
|
require_js($CFG->wwwroot.'/group/lib/clientlib.js');
|
|
|
|
|
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
|
|
|
|
|
|
|
if (!$course = groups_get_course_info($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
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that the user has permissions to manage groups.
|
2007-08-14 00:50:00 +00:00
|
|
|
require_login($course);
|
2007-01-03 08:17:56 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($action) {
|
2007-02-19 16:38:18 +00:00
|
|
|
case false: //OK, display form.
|
|
|
|
break;
|
|
|
|
|
2007-01-19 04:57:46 +00:00
|
|
|
case 'ajax_getmembersingroup':
|
|
|
|
$members = array();
|
|
|
|
|
2007-01-22 06:06:08 +00:00
|
|
|
if ($memberids = groups_get_members($groupid)) {
|
2007-02-09 16:04:50 +00:00
|
|
|
$member_names = groups_userids_to_user_names($memberids, $courseid);
|
2007-01-22 06:06:08 +00:00
|
|
|
$json = new Services_JSON();
|
2007-02-09 16:04:50 +00:00
|
|
|
echo $json->encode($member_names);
|
2007-01-19 04:57:46 +00:00
|
|
|
}
|
|
|
|
die; // Client side JavaScript takes it from here.
|
|
|
|
|
|
|
|
case 'deletegroup':
|
2007-08-15 20:33:17 +00:00
|
|
|
redirect('group.php?delete=1&courseid='.$courseid.'&id='.$groupid);
|
2007-01-19 04:57:46 +00:00
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-03-27 04:03:51 +00:00
|
|
|
case 'showcreateorphangroupform':
|
2007-08-15 20:33:17 +00:00
|
|
|
redirect('group.php?courseid='.$courseid);
|
2007-03-27 04:03:51 +00:00
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
|
|
|
case 'showgroupsettingsform':
|
2007-08-15 20:33:17 +00:00
|
|
|
redirect('group.php?courseid='.$courseid.'&id='.$groupid);
|
2007-01-19 04:57:46 +00:00
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-01-19 04:57:46 +00:00
|
|
|
case 'updategroups': //Currently reloading.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'removemembers':
|
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-01-19 04:57:46 +00:00
|
|
|
case 'showaddmembersform':
|
2007-08-14 00:50:00 +00:00
|
|
|
redirect('assign.php?group='.$groupid);
|
2007-01-19 04:57:46 +00:00
|
|
|
break;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-01-19 04:57:46 +00:00
|
|
|
case 'updatemembers': //Currently reloading.
|
|
|
|
break;
|
2007-02-19 16:38:18 +00:00
|
|
|
|
|
|
|
default: //ERROR.
|
|
|
|
if (debugging()) {
|
2007-08-14 00:50:00 +00:00
|
|
|
error('Error, unknown button/action. Probably a user-interface bug!', $returnurl);
|
2007-01-19 04:57:46 +00:00
|
|
|
break;
|
2007-02-19 16:38:18 +00:00
|
|
|
}
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print the page and form
|
|
|
|
$strgroups = get_string('groups');
|
|
|
|
$strparticipants = get_string('participants');
|
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
print_header("$course->shortname: $strgroups",
|
|
|
|
$course->fullname,
|
2007-01-03 08:17:56 +00:00
|
|
|
"<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
|
|
|
|
"-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
|
|
|
|
"-> $strgroups", '', '', true, '', user_login_string($course, $USER));
|
|
|
|
|
2007-03-27 04:03:51 +00:00
|
|
|
$disabled = 'disabled="disabled"';
|
2007-08-14 00:50:00 +00:00
|
|
|
|
|
|
|
$showeditgroupsettingsform_disabled = $disabled;
|
|
|
|
$deletegroup_disabled = $disabled;
|
|
|
|
$showcreategroupform_disabled = $disabled;
|
2007-03-30 05:14:29 +00:00
|
|
|
|
|
|
|
if (!empty($groupid)) {
|
2007-03-27 04:03:51 +00:00
|
|
|
$showaddmembersform_disabled = '';
|
2007-08-14 00:50:00 +00:00
|
|
|
$showeditgroupsettingsform_disabled = '';
|
2007-03-27 04:03:51 +00:00
|
|
|
$deletegroup_disabled = '';
|
|
|
|
} else {
|
|
|
|
$deletegroup_disabled = $disabled;
|
2007-08-14 00:50:00 +00:00
|
|
|
$showeditgroupsettingsform_disabled = $disabled;
|
|
|
|
$showaddmembersform_disabled = $disabled;
|
2007-03-27 04:03:51 +00:00
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-02-28 06:25:22 +00:00
|
|
|
print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
|
2007-03-26 06:42:38 +00:00
|
|
|
echo '<form id="groupeditform" action="index.php" method="post">'."\n";
|
|
|
|
echo '<div>'."\n";
|
|
|
|
echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-04-05 10:55:04 +00:00
|
|
|
echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n";
|
2007-03-26 06:42:38 +00:00
|
|
|
echo '<tr>'."\n";
|
2007-07-07 14:18:30 +12:00
|
|
|
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-07-07 14:18:30 +12:00
|
|
|
echo "<td>\n";
|
|
|
|
// NO GROUPINGS YET!
|
|
|
|
echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping"> </span></label></p>'."\n";
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-04-05 10:55:04 +00:00
|
|
|
echo '<select name="group" id="groups" size="15" class="select" onchange="membersCombo.refreshMembers(this.options[this.selectedIndex].value);"'."\n";
|
|
|
|
echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
|
2007-03-26 06:42:38 +00:00
|
|
|
|
2007-08-15 20:21:01 +00:00
|
|
|
if ($groups = groups_get_all_groups($courseid)) {
|
|
|
|
$groupids = array_keys($groups);
|
2007-01-03 08:17:56 +00:00
|
|
|
} else {
|
2007-08-14 00:50:00 +00:00
|
|
|
$groupids = false;
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
|
|
|
|
$sel_groupid = 0;
|
|
|
|
|
2007-01-03 08:17:56 +00:00
|
|
|
if ($groupids) {
|
2007-01-24 03:03:10 +00:00
|
|
|
// Put the groups into a hash and sort them
|
2007-02-09 16:04:50 +00:00
|
|
|
$group_names = groups_groupids_to_group_names($groupids);
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-01-03 08:17:56 +00:00
|
|
|
// Print out the HTML
|
|
|
|
$count = 1;
|
2007-02-09 16:04:50 +00:00
|
|
|
foreach ($group_names as $group) {
|
2007-01-03 08:17:56 +00:00
|
|
|
$select = '';
|
2007-02-09 16:04:50 +00:00
|
|
|
if ($groupid == $group->id) { //|| $count <= 1) ??
|
2007-01-03 08:17:56 +00:00
|
|
|
$select = ' selected="selected"';
|
2007-02-09 16:04:50 +00:00
|
|
|
$sel_groupid = $group->id;
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
2007-04-05 10:55:04 +00:00
|
|
|
echo "<option value=\"{$group->id}\"$select title=\"{$group->name}\">{$group->name}</option>\n";
|
2007-01-03 08:17:56 +00:00
|
|
|
$count++;
|
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
} else {
|
2007-03-26 06:42:38 +00:00
|
|
|
// Print an empty option to avoid the XHTML error of having an empty select element
|
|
|
|
echo '<option> </option>';
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-03-26 06:42:38 +00:00
|
|
|
echo '</select>'."\n";
|
|
|
|
echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
|
|
|
|
. get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
|
2007-03-27 04:03:51 +00:00
|
|
|
echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
|
2007-03-26 06:42:38 +00:00
|
|
|
. get_string('editgroupsettings', 'group') . '" /></p>'."\n";
|
2007-03-27 04:03:51 +00:00
|
|
|
echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
|
2007-03-26 06:42:38 +00:00
|
|
|
. get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
|
2007-08-03 03:03:05 +00:00
|
|
|
|
2007-07-07 14:18:30 +12:00
|
|
|
echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
|
|
|
|
. get_string('creategroup', 'group') . '" /></p>'."\n";
|
|
|
|
|
2007-03-26 06:42:38 +00:00
|
|
|
echo '</td>'."\n";
|
|
|
|
echo '<td>'."\n";
|
2007-07-07 14:18:30 +12:00
|
|
|
echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup"> </span></label></p>'."\n";
|
2007-04-05 10:55:04 +00:00
|
|
|
//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";
|
2007-08-14 00:50:00 +00:00
|
|
|
|
|
|
|
$userids = false;
|
|
|
|
if ($sel_groupid) {
|
2007-01-03 08:17:56 +00:00
|
|
|
$userids = groups_get_members($sel_groupid);
|
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
|
|
|
|
if ($userids) {
|
2007-01-03 08:17:56 +00:00
|
|
|
// Put the groupings into a hash and sort them
|
2007-02-19 16:38:18 +00:00
|
|
|
$user_names = groups_userids_to_user_names($userids, $courseid);
|
2007-03-30 06:32:10 +00:00
|
|
|
if(empty($user_names)) {
|
|
|
|
echo '<option> </option>';
|
|
|
|
} else {
|
|
|
|
foreach ($user_names as $user) {
|
2007-04-05 10:55:04 +00:00
|
|
|
echo "<option value=\"{$user->id}\" title=\"{$user->name}\">{$user->name}</option>\n";
|
2007-03-30 06:32:10 +00:00
|
|
|
}
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
} else {
|
2007-03-26 06:42:38 +00:00
|
|
|
// Print an empty option to avoid the XHTML error of having an empty select element
|
|
|
|
echo '<option> </option>';
|
2007-01-03 08:17:56 +00:00
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-03-26 06:42:38 +00:00
|
|
|
echo '</select>'."\n";
|
|
|
|
|
2007-03-27 04:03:51 +00:00
|
|
|
echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
|
2007-03-26 06:42:38 +00:00
|
|
|
. 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
|
|
|
|
echo '</td>'."\n";
|
|
|
|
echo '</tr>'."\n";
|
|
|
|
echo '</table>'."\n";
|
|
|
|
|
|
|
|
//<input type="hidden" name="rand" value="om" />
|
|
|
|
echo '</div>'."\n";
|
|
|
|
echo '</form>'."\n";
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-01-19 09:23:22 +00:00
|
|
|
echo '<script type="text/javascript">'."\n";
|
2007-01-19 04:57:46 +00:00
|
|
|
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-03 08:17:56 +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) {
|
|
|
|
$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;
|
|
|
|
}
|
2007-01-03 08:17:56 +00:00
|
|
|
|
2007-02-02 06:36:34 +00:00
|
|
|
?>
|