group MDL-19798 Updated print_header and build_navigation to OUTPUT and PAGE equivalents
[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
19// Make sure course is OK and user has access to manage groups
20if (!$course = $DB->get_record('course', array('id' => $courseid))) {
60e40dda 21 print_error('invalidcourseid');
f6eece19 22}
23require_login($course);
24$context = get_context_instance(CONTEXT_COURSE, $course->id);
25require_capability('moodle/course:managegroups', $context);
26
27// Make sure all groups are OK and belong to course
28$groupidarray = explode(',',$groupids);
29$groupnames = array();
30foreach($groupidarray as $groupid) {
31 if (!$group = $DB->get_record('groups', array('id' => $groupid))) {
60e40dda 32 print_error('invalidgroupid');
f6eece19 33 }
34 if ($courseid != $group->courseid) {
60e40dda 35 print_error('groupunknown', '', '', $group->courseid);
f6eece19 36 }
37 $groupnames[] = format_string($group->name);
38}
39
40$returnurl='index.php?id='.$course->id;
41
42if(count($groupidarray)==0) {
43 print_error('errorselectsome','group',$returnurl);
44}
45
46if ($confirm && data_submitted()) {
47 if (!confirm_sesskey() ) {
48 print_error('confirmsesskeybad','error',$returnurl);
49 }
50 $DB->begin_sql();
51 foreach($groupidarray as $groupid) {
5e2f308b 52 groups_delete_group($groupid);
f6eece19 53 }
54 $DB->commit_sql();
55 redirect($returnurl);
56} else {
b87573d7 57 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
58 $PAGE->set_heading(get_string('deleteselectedgroup', 'group'));
59 echo $OUTPUT->header();
f6eece19 60 $optionsyes = array('courseid'=>$courseid, 'groups'=>$groupids, 'sesskey'=>sesskey(), 'confirm'=>1);
61 $optionsno = array('id'=>$courseid);
62 if(count($groupnames)==1) {
63 $message=get_string('deletegroupconfirm', 'group', $groupnames[0]);
64 } else {
65 $message=get_string('deletegroupsconfirm', 'group').'<ul>';
66 foreach($groupnames as $groupname) {
67 $message.='<li>'.$groupname.'</li>';
68 }
69 $message.='</ul>';
70 }
768cefa0 71 $formcontinue = html_form::make_button('delete.php', $optionsyes, get_string('yes'), 'post');
72 $formcancel = html_form::make_button('index.php', $optionsno, get_string('no'), 'get');
73 echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
653468d4 74 echo $OUTPUT->footer();
f6eece19 75}
76?>