MDL-31328_master theme_sky_high: fixed report layout and related files + updated...
[moodle.git] / group / grouping.php
blob8ac9eb6b7e049f1de51697aebcac69425f58abe5
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 = get_context_instance(CONTEXT_COURSE, $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 (!$confirm) {
74 $PAGE->set_title(get_string('deletegrouping', 'group'));
75 $PAGE->set_heading($course->fullname. ': '. get_string('deletegrouping', 'group'));
76 echo $OUTPUT->header();
77 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
78 $optionsno = array('id'=>$courseid);
79 $formcontinue = new single_button(new moodle_url('grouping.php', $optionsyes), get_string('yes'), 'get');
80 $formcancel = new single_button(new moodle_url('groupings.php', $optionsno), get_string('no'), 'get');
81 echo $OUTPUT->confirm(get_string('deletegroupingconfirm', 'group', $grouping->name), $formcontinue, $formcancel);
82 echo $OUTPUT->footer();
83 die;
85 } else if (confirm_sesskey()){
86 if (groups_delete_grouping($id)) {
87 redirect($returnurl);
88 } else {
89 print_error('erroreditgrouping', 'group', $returnurl);
94 // Prepare the description editor: We do support files for grouping descriptions
95 $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>true, 'context'=>$context, 'noclean'=>true);
96 if (!empty($grouping->id)) {
97 $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'grouping', 'description', $grouping->id);
98 } else {
99 $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'grouping', 'description', null);
102 /// First create the form
103 $editform = new grouping_form(null, compact('editoroptions'));
104 $editform->set_data($grouping);
106 if ($editform->is_cancelled()) {
107 redirect($returnurl);
109 } elseif ($data = $editform->get_data()) {
110 $success = true;
112 if ($data->id) {
113 groups_update_grouping($data, $editoroptions);
114 } else {
115 groups_create_grouping($data, $editoroptions);
118 redirect($returnurl);
122 $strgroupings = get_string('groupings', 'group');
123 $strparticipants = get_string('participants');
125 if ($id) {
126 $strheading = get_string('editgroupingsettings', 'group');
127 } else {
128 $strheading = get_string('creategrouping', 'group');
131 $PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
132 $PAGE->navbar->add($strgroupings, new moodle_url('/group/groupings.php', array('id'=>$courseid)));
133 $PAGE->navbar->add($strheading);
135 /// Print header
136 $PAGE->set_title($strgroupings);
137 $PAGE->set_heading($course->fullname. ': '.$strgroupings);
138 echo $OUTPUT->header();
139 echo $OUTPUT->heading($strheading);
140 $editform->display();
141 echo $OUTPUT->footer();