MDL-11328 Added the missing variable
[moodle-pu.git] / group / grouping.php
blobdc5ad1b482381fab50bc1f6bbccbdf01082402b6
1 <?php
2 /**
3 * Create grouping OR edit grouping settings.
5 * @copyright &copy; 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
9 * @package groups
11 require_once('../config.php');
12 require_once('lib.php');
13 require_once('grouping_form.php');
15 /// get url variables
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);
21 if ($id) {
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');
36 } else {
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) {
52 if (!$confirm) {
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');
57 print_footer();
58 die;
60 } else if (confirm_sesskey()){
61 if (groups_delete_grouping($id)) {
62 // MDL-9983
63 $eventdata = new object();
64 $eventdata->group = $id;
65 $eventdata->course = $courseid;
66 events_trigger('grouping_deleted', $eventdata);
67 redirect($returnurl);
68 } else {
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()) {
79 redirect($returnurl);
81 } elseif ($data = $editform->get_data()) {
82 $success = true;
84 if ($data->id) {
85 $data->timemodified = time();
86 if (!update_record('groupings', $data)) {
87 error('Error updating group');
90 } else {
91 $data->timecreated = time();
92 $data->timemodified = $data->timecreated;
93 if (!$data->id = insert_record('groupings', $data)) {
94 error('Error updating grouping');
98 redirect($returnurl);
102 $strgroupings = get_string('groupings', 'group');
103 $strparticipants = get_string('participants');
105 if ($id) {
106 $strheading = get_string('editgroupingsettings', 'group');
107 } else {
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);
116 /// Print header
117 print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
120 print_heading($strheading);
121 $editform->display();
122 print_footer($course);