3 * Create grouping OR edit grouping settings.
5 * @copyright © 2006 The Open University
6 * @author N.D.Freear AT open.ac.uk
7 * @author J.White AT open.ac.uk
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 require_once('../config.php');
12 require_once('lib.php');
13 require_once('grouping_form.php');
16 $courseid = optional_param('courseid', 0, PARAM_INT
);
17 $id = optional_param('id', 0, PARAM_INT
);
18 $delete = optional_param('delete', 0, PARAM_BOOL
);
19 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
22 if (!$grouping = get_record('groupings', 'id', $id)) {
23 error('Group ID was incorrect');
25 if (empty($courseid)) {
26 $courseid = $grouping->courseid
;
28 } else if ($courseid != $grouping->courseid
) {
29 error('Course ID was incorrect');
32 if (!$course = get_record('course', 'id', $courseid)) {
33 error('Course ID was incorrect');
37 if (!$course = get_record('course', 'id', $courseid)) {
38 error('Course ID was incorrect');
40 $grouping = new object();
41 $grouping->courseid
= $course->id
;
44 require_login($course);
45 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
46 require_capability('moodle/course:managegroups', $context);
48 $returnurl = $CFG->wwwroot
.'/group/groupings.php?id='.$course->id
;
51 if ($id and $delete) {
53 print_header(get_string('deleteselectedgrouping', 'group'), get_string('deleteselectedgroup', 'group'));
54 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
55 $optionsno = array('id'=>$courseid);
56 notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name
), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get');
60 } else if (confirm_sesskey()){
61 if (groups_delete_grouping($id)) {
63 $eventdata = new object();
64 $eventdata->group
= $id;
65 $eventdata->course
= $courseid;
66 events_trigger('grouping_deleted', $eventdata);
69 print_error('erroreditgrouping', 'group', $returnurl);
74 /// First create the form
75 $editform = new grouping_form();
76 $editform->set_data($grouping);
78 if ($editform->is_cancelled()) {
81 } elseif ($data = $editform->get_data()) {
85 $data->timemodified
= time();
86 if (!update_record('groupings', $data)) {
87 error('Error updating group');
91 $data->timecreated
= time();
92 $data->timemodified
= $data->timecreated
;
93 if (!$data->id
= insert_record('groupings', $data)) {
94 error('Error updating grouping');
102 $strgroupings = get_string('groupings', 'group');
103 $strparticipants = get_string('participants');
106 $strheading = get_string('editgroupingsettings', 'group');
108 $strheading = get_string('creategrouping', 'group');
111 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot
.'/user/index.php?id='.$courseid, 'type'=>'misc'),
112 array('name'=>$strgroupings, 'link'=>$CFG->wwwroot
.'/group/groupings.php?id='.$courseid, 'type'=>'misc'),
113 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
114 $navigation = build_navigation($navlinks);
117 print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
120 print_heading($strheading);
121 $editform->display();
122 print_footer($course);