MDL-39846 fix forgotten object event property
[moodle.git] / group / grouping.php
blobbdfe58acd203fbf4dabb24181c072cf0e1881898
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Create grouping OR edit grouping settings.
21 * @copyright 2006 The Open University, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package core_group
25 require_once('../config.php');
26 require_once('lib.php');
27 require_once('grouping_form.php');
29 /// get url variables
30 $courseid = optional_param('courseid', 0, PARAM_INT);
31 $id = optional_param('id', 0, PARAM_INT);
32 $delete = optional_param('delete', 0, PARAM_BOOL);
33 $confirm = optional_param('confirm', 0, PARAM_BOOL);
35 $url = new moodle_url('/group/grouping.php');
36 if ($id) {
37 $url->param('id', $id);
38 if (!$grouping = $DB->get_record('groupings', array('id'=>$id))) {
39 print_error('invalidgroupid');
41 $grouping->description = clean_text($grouping->description);
42 if (empty($courseid)) {
43 $courseid = $grouping->courseid;
44 } else if ($courseid != $grouping->courseid) {
45 print_error('invalidcourseid');
46 } else {
47 $url->param('courseid', $courseid);
50 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
51 print_error('invalidcourseid');
54 } else {
55 $url->param('courseid', $courseid);
56 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
57 print_error('invalidcourseid');
59 $grouping = new stdClass();
60 $grouping->courseid = $course->id;
63 $PAGE->set_url($url);
65 require_login($course);
66 $context = context_course::instance($course->id);
67 require_capability('moodle/course:managegroups', $context);
69 $returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id;
72 if ($id and $delete) {
73 if (!empty($grouping->idnumber) && !has_capability('moodle/course:changeidnumber', $context)) {
74 print_error('groupinghasidnumber', '', '', $grouping->name);
76 if (!$confirm) {
77 $PAGE->set_title(get_string('deletegrouping', 'group'));
78 $PAGE->set_heading($course->fullname. ': '. get_string('deletegrouping', 'group'));
79 echo $OUTPUT->header();
80 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
81 $optionsno = array('id'=>$courseid);
82 $formcontinue = new single_button(new moodle_url('grouping.php', $optionsyes), get_string('yes'), 'get');
83 $formcancel = new single_button(new moodle_url('groupings.php', $optionsno), get_string('no'), 'get');
84 echo $OUTPUT->confirm(get_string('deletegroupingconfirm', 'group', $grouping->name), $formcontinue, $formcancel);
85 echo $OUTPUT->footer();
86 die;
88 } else if (confirm_sesskey()){
89 if (groups_delete_grouping($id)) {
90 redirect($returnurl);
91 } else {
92 print_error('erroreditgrouping', 'group', $returnurl);
97 // Prepare the description editor: We do support files for grouping descriptions
98 $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>true, 'context'=>$context, 'noclean'=>true);
99 if (!empty($grouping->id)) {
100 $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'grouping', 'description', $grouping->id);
101 } else {
102 $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'grouping', 'description', null);
105 /// First create the form
106 $editform = new grouping_form(null, compact('editoroptions'));
107 $editform->set_data($grouping);
109 if ($editform->is_cancelled()) {
110 redirect($returnurl);
112 } elseif ($data = $editform->get_data()) {
113 $success = true;
114 if (!has_capability('moodle/course:changeidnumber', $context)) {
115 // Remove the idnumber if the user doesn't have permission to modify it
116 unset($data->idnumber);
119 if ($data->id) {
120 groups_update_grouping($data, $editoroptions);
121 } else {
122 groups_create_grouping($data, $editoroptions);
125 redirect($returnurl);
129 $strgroupings = get_string('groupings', 'group');
130 $strparticipants = get_string('participants');
132 if ($id) {
133 $strheading = get_string('editgroupingsettings', 'group');
134 } else {
135 $strheading = get_string('creategrouping', 'group');
138 $PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
139 $PAGE->navbar->add($strgroupings, new moodle_url('/group/groupings.php', array('id'=>$courseid)));
140 $PAGE->navbar->add($strheading);
142 /// Print header
143 $PAGE->set_title($strgroupings);
144 $PAGE->set_heading($course->fullname. ': '.$strgroupings);
145 echo $OUTPUT->header();
146 echo $OUTPUT->heading($strheading);
147 $editform->display();
148 echo $OUTPUT->footer();