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
|
2007-08-15 23:51:07 +00:00
|
|
|
* @author J.White AT open.ac.uk
|
2007-01-04 13:15:04 +13:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package groups
|
|
|
|
*/
|
|
|
|
require_once('../config.php');
|
|
|
|
require_once('lib.php');
|
2007-08-15 23:51:07 +00:00
|
|
|
require_once('grouping_form.php');
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
/// get url variables
|
2007-08-16 09:28:18 +00:00
|
|
|
$courseid = optional_param('courseid', 0, PARAM_INT);
|
|
|
|
$id = optional_param('id', 0, PARAM_INT);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_BOOL);
|
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
if ($id) {
|
|
|
|
if (!$grouping = get_record('groupings', 'id', $id)) {
|
|
|
|
error('Group ID was incorrect');
|
|
|
|
}
|
2008-01-18 10:16:39 +00:00
|
|
|
$grouping->description = clean_text($grouping->description);
|
2007-08-15 23:51:07 +00:00
|
|
|
if (empty($courseid)) {
|
2007-08-16 09:28:18 +00:00
|
|
|
$courseid = $grouping->courseid;
|
2007-02-06 15:34:09 +00:00
|
|
|
|
2007-08-16 09:28:18 +00:00
|
|
|
} else if ($courseid != $grouping->courseid) {
|
2007-08-15 23:51:07 +00:00
|
|
|
error('Course ID was incorrect');
|
|
|
|
}
|
2007-07-07 14:18:30 +12:00
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
if (!$course = get_record('course', 'id', $courseid)) {
|
|
|
|
error('Course ID was incorrect');
|
|
|
|
}
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
} else {
|
|
|
|
if (!$course = get_record('course', 'id', $courseid)) {
|
|
|
|
error('Course ID was incorrect');
|
|
|
|
}
|
|
|
|
$grouping = new object();
|
|
|
|
$grouping->courseid = $course->id;
|
2007-03-30 05:14:29 +00:00
|
|
|
}
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
require_login($course);
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
require_capability('moodle/course:managegroups', $context);
|
2007-01-04 13:15:04 +13:00
|
|
|
|
2007-08-16 09:28:18 +00:00
|
|
|
$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id;
|
2007-08-15 23:51:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
if ($id and $delete) {
|
|
|
|
if (!$confirm) {
|
|
|
|
print_header(get_string('deleteselectedgrouping', 'group'), get_string('deleteselectedgroup', 'group'));
|
|
|
|
$optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
|
|
|
|
$optionsno = array('id'=>$courseid);
|
2007-08-16 09:28:18 +00:00
|
|
|
notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get');
|
2007-08-15 23:51:07 +00:00
|
|
|
print_footer();
|
|
|
|
die;
|
|
|
|
|
|
|
|
} else if (confirm_sesskey()){
|
|
|
|
if (groups_delete_grouping($id)) {
|
|
|
|
// MDL-9983
|
|
|
|
$eventdata = new object();
|
|
|
|
$eventdata->group = $id;
|
|
|
|
$eventdata->course = $courseid;
|
|
|
|
events_trigger('grouping_deleted', $eventdata);
|
2007-08-16 09:28:18 +00:00
|
|
|
redirect($returnurl);
|
2007-08-15 23:51:07 +00:00
|
|
|
} else {
|
|
|
|
print_error('erroreditgrouping', 'group', $returnurl);
|
|
|
|
}
|
2007-04-03 06:41:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
/// First create the form
|
|
|
|
$editform = new grouping_form();
|
|
|
|
$editform->set_data($grouping);
|
|
|
|
|
2007-03-30 05:14:29 +00:00
|
|
|
if ($editform->is_cancelled()) {
|
2007-08-15 23:51:07 +00:00
|
|
|
redirect($returnurl);
|
|
|
|
|
2007-03-30 05:14:29 +00:00
|
|
|
} elseif ($data = $editform->get_data()) {
|
|
|
|
$success = true;
|
2007-08-15 23:51:07 +00:00
|
|
|
|
|
|
|
if ($data->id) {
|
2007-11-19 20:31:57 +00:00
|
|
|
if (!groups_update_grouping($data)) {
|
|
|
|
error('Error updating grouping');
|
2007-01-04 13:15:04 +13:00
|
|
|
}
|
2007-03-30 05:14:29 +00:00
|
|
|
|
|
|
|
} else {
|
2007-11-19 20:31:57 +00:00
|
|
|
if (!groups_create_grouping($data)) {
|
|
|
|
error('Error creating grouping');
|
2007-08-15 23:51:07 +00:00
|
|
|
}
|
2007-02-06 15:34:09 +00:00
|
|
|
}
|
2007-08-15 23:51:07 +00:00
|
|
|
|
|
|
|
redirect($returnurl);
|
|
|
|
|
2007-01-04 13:15:04 +13:00
|
|
|
}
|
2007-08-15 23:51:07 +00:00
|
|
|
|
2007-08-16 09:28:18 +00:00
|
|
|
$strgroupings = get_string('groupings', 'group');
|
2007-08-15 23:51:07 +00:00
|
|
|
$strparticipants = get_string('participants');
|
|
|
|
|
|
|
|
if ($id) {
|
|
|
|
$strheading = get_string('editgroupingsettings', 'group');
|
|
|
|
} else {
|
|
|
|
$strheading = get_string('creategrouping', 'group');
|
|
|
|
}
|
|
|
|
|
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'=>$strgroupings, 'link'=>$CFG->wwwroot.'/group/groupings.php?id='.$courseid, 'type'=>'misc'),
|
|
|
|
array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
|
|
|
|
$navigation = build_navigation($navlinks);
|
|
|
|
|
|
|
|
/// Print header
|
|
|
|
print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
|
|
|
|
|
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
print_heading($strheading);
|
|
|
|
$editform->display();
|
|
|
|
print_footer($course);
|
|
|
|
|
2007-01-04 13:15:04 +13:00
|
|
|
?>
|