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)) {
65 print_error('erroreditgrouping', 'group', $returnurl);
70 /// First create the form
71 $editform = new grouping_form();
72 $editform->set_data($grouping);
74 if ($editform->is_cancelled()) {
77 } elseif ($data = $editform->get_data()) {
81 if (!groups_update_grouping($data)) {
82 error('Error updating grouping');
86 if (!groups_create_grouping($data)) {
87 error('Error creating grouping');
95 $strgroupings = get_string('groupings', 'group');
96 $strparticipants = get_string('participants');
99 $strheading = get_string('editgroupingsettings', 'group');
101 $strheading = get_string('creategrouping', 'group');
104 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot
.'/user/index.php?id='.$courseid, 'type'=>'misc'),
105 array('name'=>$strgroupings, 'link'=>$CFG->wwwroot
.'/group/groupings.php?id='.$courseid, 'type'=>'misc'),
106 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
107 $navigation = build_navigation($navlinks);
110 print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
113 print_heading($strheading);
114 $editform->display();
115 print_footer($course);