2007-01-04 13:15:04 +13:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Create grouping OR edit grouping settings.
|
|
|
|
*
|
|
|
|
* @copyright © 2006 The Open University
|
|
|
|
* @author N.D.Freear AT open.ac.uk
|
|
|
|
* @author J.White AT open.ac.uk
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package groups
|
|
|
|
*/
|
|
|
|
require_once('../config.php');
|
|
|
|
require_once('lib.php');
|
|
|
|
require_once($CFG->libdir.'/moodlelib.php');
|
2007-03-30 05:14:29 +00:00
|
|
|
require_once('grouping_edit_form.php');
|
2007-01-04 13:15:04 +13:00
|
|
|
|
|
|
|
$courseid = required_param('courseid', PARAM_INT);
|
2007-03-30 05:14:29 +00:00
|
|
|
$id = optional_param('id', false, PARAM_INT);
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-02-06 15:34:09 +00:00
|
|
|
$delete = optional_param('delete', false, PARAM_BOOL);
|
|
|
|
|
2007-01-04 13:15:04 +13:00
|
|
|
// Get the course information so we can print the header and
|
|
|
|
// check the course id is valid
|
|
|
|
$course = groups_get_course_info($courseid);
|
|
|
|
if (! $course) {
|
|
|
|
$success = false;
|
2007-01-17 13:56:09 +00:00
|
|
|
print_error('invalidcourse'); //'The course ID is invalid'
|
|
|
|
}
|
2007-03-30 05:14:29 +00:00
|
|
|
if (GROUP_NOT_IN_GROUPING == $id) {
|
2007-01-17 13:56:09 +00:00
|
|
|
print_error('errornotingroupingedit', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
|
2007-01-04 13:15:04 +13:00
|
|
|
}
|
|
|
|
|
2007-03-30 05:14:29 +00:00
|
|
|
/// basic access control checks
|
|
|
|
if ($id) {
|
|
|
|
if (!$grouping = get_record('groups_groupings', 'id', $id)) {
|
|
|
|
error('Grouping ID was incorrect');
|
|
|
|
}
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
require_capability('moodle/course:managegroups', $context);
|
|
|
|
}
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-03-30 05:14:29 +00:00
|
|
|
/// First create the form
|
|
|
|
$editform = new grouping_edit_form('grouping.php', compact('grouping', 'courseid'));
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-03-30 05:14:29 +00:00
|
|
|
/// Override defaults if group is set
|
|
|
|
if (!empty($grouping)) {
|
|
|
|
$editform->set_data($grouping);
|
|
|
|
}
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-03-30 05:14:29 +00:00
|
|
|
if ($editform->is_cancelled()) {
|
|
|
|
redirect(groups_home_url($courseid, false, $id, false));
|
|
|
|
} elseif ($data = $editform->get_data()) {
|
|
|
|
$success = true;
|
|
|
|
|
|
|
|
// preprocess data
|
|
|
|
if ($delete) {
|
|
|
|
if ($success = groups_delete_grouping($id)) {
|
|
|
|
redirect(groups_home_url($course->id));
|
|
|
|
} else {
|
|
|
|
print_error('erroreditgrouping', 'group', groups_home_url($course->id));
|
2007-02-06 15:34:09 +00:00
|
|
|
}
|
2007-03-30 05:14:29 +00:00
|
|
|
} elseif (empty($grouping)) { // New grouping
|
|
|
|
if (!$id = groups_create_grouping($course->id, $data)) {
|
|
|
|
print_error('erroreditgrouping');
|
|
|
|
} else {
|
|
|
|
$success = (bool)$id;
|
|
|
|
$data->id = $id;
|
2007-01-04 13:15:04 +13:00
|
|
|
}
|
2007-03-30 05:14:29 +00:00
|
|
|
} else { // Updating grouping
|
|
|
|
if (!groups_update_grouping($data, $course->id)) {
|
|
|
|
print_error('groupingnotupdated');
|
2007-01-04 13:15:04 +13:00
|
|
|
}
|
|
|
|
}
|
2007-03-30 05:14:29 +00:00
|
|
|
|
|
|
|
if ($success) {
|
|
|
|
redirect(groups_home_url($courseid, false, $id, false));
|
2007-01-04 13:15:04 +13:00
|
|
|
} else {
|
2007-03-30 05:14:29 +00:00
|
|
|
print_error('erroreditgrouping', 'group', groups_home_url($courseid));
|
2007-01-04 13:15:04 +13:00
|
|
|
}
|
2007-03-30 05:14:29 +00:00
|
|
|
|
|
|
|
} else { // Prepare and output form
|
2007-01-04 13:15:04 +13:00
|
|
|
$strgroups = get_string('groups');
|
|
|
|
$strparticipants = get_string('participants');
|
2007-03-30 05:14:29 +00:00
|
|
|
|
|
|
|
if ($id) {
|
|
|
|
$strheading = get_string('editgroupingsettings', 'group');
|
|
|
|
} else {
|
|
|
|
$strheading = get_string('creategrouping', 'group');
|
2007-02-06 15:34:09 +00:00
|
|
|
}
|
2007-03-30 05:14:29 +00:00
|
|
|
print_header("$course->shortname: ". $strheading,
|
2007-02-28 06:25:22 +00:00
|
|
|
$course->fullname,
|
2007-01-04 13:15:04 +13:00
|
|
|
"<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
|
|
|
|
"-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
|
2007-03-30 05:14:29 +00:00
|
|
|
'-> <a href="' .format_string(groups_home_url($courseid, false, $id, false)) . "\">$strgroups</a>".
|
|
|
|
"-> $strheading", '', '', true, '', user_login_string($course, $USER));
|
|
|
|
print_heading($strheading);
|
|
|
|
$editform->display();
|
2007-01-04 13:15:04 +13:00
|
|
|
print_footer($course);
|
|
|
|
}
|
|
|
|
?>
|