2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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 throw new \
moodle_exception('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 throw new \
moodle_exception('invalidgroupid');
53 if (!empty($group->idnumber
) && !$changeidnumber) {
54 throw new \
moodle_exception('grouphasidnumber', '', '', $group->name
);
56 if ($courseid != $group->courseid
) {
57 throw new \
moodle_exception('groupunknown', '', '', $group->courseid
);
59 $groupnames[] = format_string($group->name
);
62 $returnurl='index.php?id='.$course->id
;
64 if(count($groupidarray)==0) {
65 throw new \
moodle_exception('errorselectsome', 'group', $returnurl);
68 if ($confirm && data_submitted()) {
69 if (!confirm_sesskey() ) {
70 throw new \
moodle_exception('confirmsesskeybad', 'error', $returnurl);
73 foreach($groupidarray as $groupid) {
74 groups_delete_group($groupid);
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]);
87 $message=get_string('deletegroupsconfirm', 'group').'<ul>';
88 foreach($groupnames as $groupname) {
89 $message.='<li>'.$groupname.'</li>';
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();