weekly release 3.10.1+
[moodle.git] / group / delete.php
CommitLineData
f6eece19 1<?php
4d8e2417
AG
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.
13//
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/>.
16
17
f6eece19 18/**
19 * Delete group
20 *
4d8e2417
AG
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
f6eece19 24 */
25
26require_once('../config.php');
27require_once('lib.php');
28
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);
33
a6855934 34$PAGE->set_url('/group/delete.php', array('courseid'=>$courseid,'groups'=>$groupids));
f196f42c 35$PAGE->set_pagelayout('standard');
bbe0bd98 36
f6eece19 37// Make sure course is OK and user has access to manage groups
38if (!$course = $DB->get_record('course', array('id' => $courseid))) {
60e40dda 39 print_error('invalidcourseid');
f6eece19 40}
41require_login($course);
bf0f06b1 42$context = context_course::instance($course->id);
f6eece19 43require_capability('moodle/course:managegroups', $context);
74b714df 44$changeidnumber = has_capability('moodle/course:changeidnumber', $context);
f6eece19 45
46// Make sure all groups are OK and belong to course
47$groupidarray = explode(',',$groupids);
48$groupnames = array();
49foreach($groupidarray as $groupid) {
50 if (!$group = $DB->get_record('groups', array('id' => $groupid))) {
60e40dda 51 print_error('invalidgroupid');
f6eece19 52 }
74b714df
ARN
53 if (!empty($group->idnumber) && !$changeidnumber) {
54 print_error('grouphasidnumber', '', '', $group->name);
55 }
f6eece19 56 if ($courseid != $group->courseid) {
60e40dda 57 print_error('groupunknown', '', '', $group->courseid);
f6eece19 58 }
59 $groupnames[] = format_string($group->name);
60}
61
62$returnurl='index.php?id='.$course->id;
63
64if(count($groupidarray)==0) {
65 print_error('errorselectsome','group',$returnurl);
66}
67
68if ($confirm && data_submitted()) {
69 if (!confirm_sesskey() ) {
70 print_error('confirmsesskeybad','error',$returnurl);
71 }
d5a8d9aa 72
f6eece19 73 foreach($groupidarray as $groupid) {
5e2f308b 74 groups_delete_group($groupid);
f6eece19 75 }
d5a8d9aa 76
f6eece19 77 redirect($returnurl);
78} else {
b87573d7 79 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
bd08a24a 80 $PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
b87573d7 81 echo $OUTPUT->header();
f6eece19 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>';
90 }
91 $message.='</ul>';
92 }
dc6896ef
PS
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');
768cefa0 95 echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
653468d4 96 echo $OUTPUT->footer();
f6eece19 97}