add page heading
[moodle.git] / group / delete.php
CommitLineData
f6eece19 1<?php
2/**
3 * Delete group
4 *
5 * @copyright &copy; 2008 The Open University
6 * @author s.marshall AT open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package groups
9 */
10
11require_once('../config.php');
12require_once('lib.php');
13
14// Get and check parameters
15$courseid = required_param('courseid', PARAM_INT);
16$groupids = required_param('groups', PARAM_SEQUENCE);
17$confirm = optional_param('confirm', 0, PARAM_BOOL);
18
a6855934 19$PAGE->set_url('/group/delete.php', array('courseid'=>$courseid,'groups'=>$groupids));
bbe0bd98 20
f6eece19 21// Make sure course is OK and user has access to manage groups
22if (!$course = $DB->get_record('course', array('id' => $courseid))) {
60e40dda 23 print_error('invalidcourseid');
f6eece19 24}
25require_login($course);
26$context = get_context_instance(CONTEXT_COURSE, $course->id);
27require_capability('moodle/course:managegroups', $context);
28
29// Make sure all groups are OK and belong to course
30$groupidarray = explode(',',$groupids);
31$groupnames = array();
32foreach($groupidarray as $groupid) {
33 if (!$group = $DB->get_record('groups', array('id' => $groupid))) {
60e40dda 34 print_error('invalidgroupid');
f6eece19 35 }
36 if ($courseid != $group->courseid) {
60e40dda 37 print_error('groupunknown', '', '', $group->courseid);
f6eece19 38 }
39 $groupnames[] = format_string($group->name);
40}
41
42$returnurl='index.php?id='.$course->id;
43
44if(count($groupidarray)==0) {
45 print_error('errorselectsome','group',$returnurl);
46}
47
48if ($confirm && data_submitted()) {
49 if (!confirm_sesskey() ) {
50 print_error('confirmsesskeybad','error',$returnurl);
51 }
d5a8d9aa 52
f6eece19 53 foreach($groupidarray as $groupid) {
5e2f308b 54 groups_delete_group($groupid);
f6eece19 55 }
d5a8d9aa 56
f6eece19 57 redirect($returnurl);
58} else {
b87573d7 59 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
bd08a24a 60 $PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
b87573d7 61 echo $OUTPUT->header();
f6eece19 62 $optionsyes = array('courseid'=>$courseid, 'groups'=>$groupids, 'sesskey'=>sesskey(), 'confirm'=>1);
63 $optionsno = array('id'=>$courseid);
64 if(count($groupnames)==1) {
65 $message=get_string('deletegroupconfirm', 'group', $groupnames[0]);
66 } else {
67 $message=get_string('deletegroupsconfirm', 'group').'<ul>';
68 foreach($groupnames as $groupname) {
69 $message.='<li>'.$groupname.'</li>';
70 }
71 $message.='</ul>';
72 }
dc6896ef
PS
73 $formcontinue = new single_button(new moodle_url('delete.php', $optionsyes), get_string('yes'), 'post');
74 $formcancel = new single_button(new moodle_url('index.php', $optionsno), get_string('no'), 'get');
768cefa0 75 echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
653468d4 76 echo $OUTPUT->footer();
f6eece19 77}