MDL-55019 webservice: Course summary text should not be cleaned
[moodle.git] / group / delete.php
blob88430a54ead9ee8d8ba171ea07ef7cbae4365784
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 * Delete group
21 * @package core_group
22 * @copyright 2008 The Open University, s.marshall AT open.ac.uk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../config.php');
27 require_once('lib.php');
29 // Get and check parameters
30 $courseid = required_param('courseid', PARAM_INT);
31 $groupids = required_param('groups', PARAM_SEQUENCE);
32 $confirm = optional_param('confirm', 0, PARAM_BOOL);
34 $PAGE->set_url('/group/delete.php', array('courseid'=>$courseid,'groups'=>$groupids));
35 $PAGE->set_pagelayout('standard');
37 // Make sure course is OK and user has access to manage groups
38 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
39 print_error('invalidcourseid');
41 require_login($course);
42 $context = context_course::instance($course->id);
43 require_capability('moodle/course:managegroups', $context);
44 $changeidnumber = has_capability('moodle/course:changeidnumber', $context);
46 // Make sure all groups are OK and belong to course
47 $groupidarray = explode(',',$groupids);
48 $groupnames = array();
49 foreach($groupidarray as $groupid) {
50 if (!$group = $DB->get_record('groups', array('id' => $groupid))) {
51 print_error('invalidgroupid');
53 if (!empty($group->idnumber) && !$changeidnumber) {
54 print_error('grouphasidnumber', '', '', $group->name);
56 if ($courseid != $group->courseid) {
57 print_error('groupunknown', '', '', $group->courseid);
59 $groupnames[] = format_string($group->name);
62 $returnurl='index.php?id='.$course->id;
64 if(count($groupidarray)==0) {
65 print_error('errorselectsome','group',$returnurl);
68 if ($confirm && data_submitted()) {
69 if (!confirm_sesskey() ) {
70 print_error('confirmsesskeybad','error',$returnurl);
73 foreach($groupidarray as $groupid) {
74 groups_delete_group($groupid);
77 redirect($returnurl);
78 } else {
79 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
80 $PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
81 echo $OUTPUT->header();
82 $optionsyes = array('courseid'=>$courseid, 'groups'=>$groupids, 'sesskey'=>sesskey(), 'confirm'=>1);
83 $optionsno = array('id'=>$courseid);
84 if(count($groupnames)==1) {
85 $message=get_string('deletegroupconfirm', 'group', $groupnames[0]);
86 } else {
87 $message=get_string('deletegroupsconfirm', 'group').'<ul>';
88 foreach($groupnames as $groupname) {
89 $message.='<li>'.$groupname.'</li>';
91 $message.='</ul>';
93 $formcontinue = new single_button(new moodle_url('delete.php', $optionsyes), get_string('yes'), 'post');
94 $formcancel = new single_button(new moodle_url('index.php', $optionsno), get_string('no'), 'get');
95 echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
96 echo $OUTPUT->footer();