5 * @copyright © 2008 The Open University
6 * @author s.marshall AT open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 require_once('../config.php');
12 require_once('lib.php');
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
);
19 $PAGE->set_url('/group/delete.php', array('courseid'=>$courseid,'groups'=>$groupids));
21 // Make sure course is OK and user has access to manage groups
22 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
23 print_error('invalidcourseid');
25 require_login($course);
26 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
27 require_capability('moodle/course:managegroups', $context);
29 // Make sure all groups are OK and belong to course
30 $groupidarray = explode(',',$groupids);
31 $groupnames = array();
32 foreach($groupidarray as $groupid) {
33 if (!$group = $DB->get_record('groups', array('id' => $groupid))) {
34 print_error('invalidgroupid');
36 if ($courseid != $group->courseid
) {
37 print_error('groupunknown', '', '', $group->courseid
);
39 $groupnames[] = format_string($group->name
);
42 $returnurl='index.php?id='.$course->id
;
44 if(count($groupidarray)==0) {
45 print_error('errorselectsome','group',$returnurl);
48 if ($confirm && data_submitted()) {
49 if (!confirm_sesskey() ) {
50 print_error('confirmsesskeybad','error',$returnurl);
53 foreach($groupidarray as $groupid) {
54 groups_delete_group($groupid);
59 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
60 $PAGE->set_heading($course->fullname
. ': '. get_string('deleteselectedgroup', 'group'));
61 echo $OUTPUT->header();
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]);
67 $message=get_string('deletegroupsconfirm', 'group').'<ul>';
68 foreach($groupnames as $groupname) {
69 $message.='<li>'.$groupname.'</li>';
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');
75 echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
76 echo $OUTPUT->footer();