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 $grouping->description
= clean_text($grouping->description
);
26 if (empty($courseid)) {
27 $courseid = $grouping->courseid
;
29 } else if ($courseid != $grouping->courseid
) {
30 error('Course ID was incorrect');
33 if (!$course = get_record('course', 'id', $courseid)) {
34 error('Course ID was incorrect');
38 if (!$course = get_record('course', 'id', $courseid)) {
39 error('Course ID was incorrect');
41 $grouping = new object();
42 $grouping->courseid
= $course->id
;
45 require_login($course);
46 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
47 require_capability('moodle/course:managegroups', $context);
49 $returnurl = $CFG->wwwroot
.'/group/groupings.php?id='.$course->id
;
52 if ($id and $delete) {
54 print_header(get_string('deletegrouping', 'group'), get_string('deletegrouping', 'group'));
55 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
56 $optionsno = array('id'=>$courseid);
57 notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name
), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get');
61 } else if (confirm_sesskey()){
62 if (groups_delete_grouping($id)) {
64 $eventdata = new object();
65 $eventdata->group
= $id;
66 $eventdata->course
= $courseid;
67 events_trigger('grouping_deleted', $eventdata);
70 print_error('erroreditgrouping', 'group', $returnurl);
75 /// First create the form
76 $editform = new grouping_form();
77 $editform->set_data($grouping);
79 if ($editform->is_cancelled()) {
82 } elseif ($data = $editform->get_data()) {
86 if (!groups_update_grouping($data)) {
87 error('Error updating grouping');
91 if (!groups_create_grouping($data)) {
92 error('Error creating grouping');
100 $strgroupings = get_string('groupings', 'group');
101 $strparticipants = get_string('participants');
104 $strheading = get_string('editgroupingsettings', 'group');
106 $strheading = get_string('creategrouping', 'group');
109 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot
.'/user/index.php?id='.$courseid, 'type'=>'misc'),
110 array('name'=>$strgroupings, 'link'=>$CFG->wwwroot
.'/group/groupings.php?id='.$courseid, 'type'=>'misc'),
111 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
112 $navigation = build_navigation($navlinks);
115 print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
118 print_heading($strheading);
119 $editform->display();
120 print_footer($course);