Commit | Line | Data |
---|---|---|
f3f7610c ML |
1 | <?php |
2 | /** | |
3 | * Create grouping OR edit grouping settings. | |
4 | * | |
5 | * @copyright © 2006 The Open University | |
6 | * @author N.D.Freear AT open.ac.uk | |
ddff2fa8 | 7 | * @author J.White AT open.ac.uk |
f3f7610c ML |
8 | * @license http://www.gnu.org/copyleft/gpl.html GNU Public License |
9 | * @package groups | |
10 | */ | |
11 | require_once('../config.php'); | |
12 | require_once('lib.php'); | |
ddff2fa8 | 13 | require_once('grouping_form.php'); |
f3f7610c | 14 | |
ddff2fa8 | 15 | /// get url variables |
62d63838 | 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); | |
f3f7610c | 20 | |
ddff2fa8 | 21 | if ($id) { |
22 | if (!$grouping = get_record('groupings', 'id', $id)) { | |
23 | error('Group ID was incorrect'); | |
24 | } | |
25 | if (empty($courseid)) { | |
62d63838 | 26 | $courseid = $grouping->courseid; |
5bca3fed | 27 | |
62d63838 | 28 | } else if ($courseid != $grouping->courseid) { |
ddff2fa8 | 29 | error('Course ID was incorrect'); |
30 | } | |
08103c93 | 31 | |
ddff2fa8 | 32 | if (!$course = get_record('course', 'id', $courseid)) { |
33 | error('Course ID was incorrect'); | |
34 | } | |
f3f7610c | 35 | |
ddff2fa8 | 36 | } else { |
37 | if (!$course = get_record('course', 'id', $courseid)) { | |
38 | error('Course ID was incorrect'); | |
39 | } | |
40 | $grouping = new object(); | |
41 | $grouping->courseid = $course->id; | |
c7b0485f | 42 | } |
f3f7610c | 43 | |
ddff2fa8 | 44 | require_login($course); |
45 | $context = get_context_instance(CONTEXT_COURSE, $course->id); | |
46 | require_capability('moodle/course:managegroups', $context); | |
f3f7610c | 47 | |
62d63838 | 48 | $returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id; |
ddff2fa8 | 49 | |
50 | ||
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); | |
62d63838 | 56 | notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get'); |
ddff2fa8 | 57 | print_footer(); |
58 | die; | |
59 | ||
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); | |
62d63838 | 67 | redirect($returnurl); |
ddff2fa8 | 68 | } else { |
69 | print_error('erroreditgrouping', 'group', $returnurl); | |
70 | } | |
e4596a4a | 71 | } |
72 | } | |
73 | ||
ddff2fa8 | 74 | /// First create the form |
75 | $editform = new grouping_form(); | |
76 | $editform->set_data($grouping); | |
77 | ||
c7b0485f | 78 | if ($editform->is_cancelled()) { |
ddff2fa8 | 79 | redirect($returnurl); |
80 | ||
c7b0485f | 81 | } elseif ($data = $editform->get_data()) { |
82 | $success = true; | |
ddff2fa8 | 83 | |
84 | if ($data->id) { | |
85 | $data->timemodified = time(); | |
86 | if (!update_record('groupings', $data)) { | |
87 | error('Error updating group'); | |
f3f7610c | 88 | } |
c7b0485f | 89 | |
c7b0485f | 90 | } else { |
ddff2fa8 | 91 | $data->timecreated = time(); |
92 | $data->timemodified = $data->timecreated; | |
93 | if (!$data->id = insert_record('groupings', $data)) { | |
94 | error('Error updating grouping'); | |
95 | } | |
5bca3fed | 96 | } |
ddff2fa8 | 97 | |
98 | redirect($returnurl); | |
99 | ||
f3f7610c | 100 | } |
ddff2fa8 | 101 | |
62d63838 | 102 | $strgroupings = get_string('groupings', 'group'); |
ddff2fa8 | 103 | $strparticipants = get_string('participants'); |
104 | ||
105 | if ($id) { | |
106 | $strheading = get_string('editgroupingsettings', 'group'); | |
107 | } else { | |
108 | $strheading = get_string('creategrouping', 'group'); | |
109 | } | |
110 | ||
778918fd | 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); | |
115 | ||
116 | /// Print header | |
117 | print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course)); | |
118 | ||
119 | ||
ddff2fa8 | 120 | print_heading($strheading); |
121 | $editform->display(); | |
122 | print_footer($course); | |
123 | ||
f3f7610c | 124 | ?> |