Merge branch 'm24_MDL-38545_PHP_Strict_error' of https://github.com/scara/moodle...
[moodle.git] / group / delete.php
blobb58bb0c0420dc7aec43028a553b15ea9483ce606
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));
36 // Make sure course is OK and user has access to manage groups
37 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
38 print_error('invalidcourseid');
40 require_login($course);
41 $context = context_course::instance($course->id);
42 require_capability('moodle/course:managegroups', $context);
43 $changeidnumber = has_capability('moodle/course:changeidnumber', $context);
45 // Make sure all groups are OK and belong to course
46 $groupidarray = explode(',',$groupids);
47 $groupnames = array();
48 foreach($groupidarray as $groupid) {
49 if (!$group = $DB->get_record('groups', array('id' => $groupid))) {
50 print_error('invalidgroupid');
52 if (!empty($group->idnumber) && !$changeidnumber) {
53 print_error('grouphasidnumber', '', '', $group->name);
55 if ($courseid != $group->courseid) {
56 print_error('groupunknown', '', '', $group->courseid);
58 $groupnames[] = format_string($group->name);
61 $returnurl='index.php?id='.$course->id;
63 if(count($groupidarray)==0) {
64 print_error('errorselectsome','group',$returnurl);
67 if ($confirm && data_submitted()) {
68 if (!confirm_sesskey() ) {
69 print_error('confirmsesskeybad','error',$returnurl);
72 foreach($groupidarray as $groupid) {
73 groups_delete_group($groupid);
76 redirect($returnurl);
77 } else {
78 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
79 $PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
80 echo $OUTPUT->header();
81 $optionsyes = array('courseid'=>$courseid, 'groups'=>$groupids, 'sesskey'=>sesskey(), 'confirm'=>1);
82 $optionsno = array('id'=>$courseid);
83 if(count($groupnames)==1) {
84 $message=get_string('deletegroupconfirm', 'group', $groupnames[0]);
85 } else {
86 $message=get_string('deletegroupsconfirm', 'group').'<ul>';
87 foreach($groupnames as $groupname) {
88 $message.='<li>'.$groupname.'</li>';
90 $message.='</ul>';
92 $formcontinue = new single_button(new moodle_url('delete.php', $optionsyes), get_string('yes'), 'post');
93 $formcancel = new single_button(new moodle_url('index.php', $optionsno), get_string('no'), 'get');
94 echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
95 echo $OUTPUT->footer();