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 |
16 | $courseid = optional_param('courseid', 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)) { | |
26 | $courseid = $group->courseid; | |
5bca3fed | 27 | |
ddff2fa8 | 28 | } else if ($courseid != $group->courseid) { |
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 | |
ddff2fa8 | 48 | $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id; |
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); | |
56 | notice_yesno(get_string('deletegroupingconfirm', 'group', $group->name), 'grouping.php', 'index.php', $optionsyes, $optionsno, 'get', 'get'); | |
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); | |
67 | redirect('index.php?id='.$course->id); | |
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 | |
102 | $strgroups = get_string('groups'); | |
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 | ||
111 | print_header("$course->shortname: ". $strheading, | |
112 | $course->fullname, | |
113 | "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ". | |
114 | "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ". | |
115 | "-> <a href=\"$returnurl\">$strgroups</a>". | |
116 | "-> $strheading", '', '', true, '', user_login_string($course, $USER)); | |
117 | print_heading($strheading); | |
118 | $editform->display(); | |
119 | print_footer($course); | |
120 | ||
f3f7610c | 121 | ?> |