delete.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.
  13. //
  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/>.
  16. /**
  17. * Delete group
  18. *
  19. * @package core_group
  20. * @copyright 2008 The Open University, s.marshall AT open.ac.uk
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once('../config.php');
  24. require_once('lib.php');
  25. // Get and check parameters
  26. $courseid = required_param('courseid', PARAM_INT);
  27. $groupids = required_param('groups', PARAM_SEQUENCE);
  28. $confirm = optional_param('confirm', 0, PARAM_BOOL);
  29. $PAGE->set_url('/group/delete.php', array('courseid'=>$courseid,'groups'=>$groupids));
  30. $PAGE->set_pagelayout('standard');
  31. // Make sure course is OK and user has access to manage groups
  32. if (!$course = $DB->get_record('course', array('id' => $courseid))) {
  33. print_error('invalidcourseid');
  34. }
  35. require_login($course);
  36. $context = context_course::instance($course->id);
  37. require_capability('moodle/course:managegroups', $context);
  38. $changeidnumber = has_capability('moodle/course:changeidnumber', $context);
  39. // Make sure all groups are OK and belong to course
  40. $groupidarray = explode(',',$groupids);
  41. $groupnames = array();
  42. foreach($groupidarray as $groupid) {
  43. if (!$group = $DB->get_record('groups', array('id' => $groupid))) {
  44. print_error('invalidgroupid');
  45. }
  46. if (!empty($group->idnumber) && !$changeidnumber) {
  47. print_error('grouphasidnumber', '', '', $group->name);
  48. }
  49. if ($courseid != $group->courseid) {
  50. print_error('groupunknown', '', '', $group->courseid);
  51. }
  52. $groupnames[] = format_string($group->name);
  53. }
  54. $returnurl='index.php?id='.$course->id;
  55. if(count($groupidarray)==0) {
  56. print_error('errorselectsome','group',$returnurl);
  57. }
  58. if ($confirm && data_submitted()) {
  59. if (!confirm_sesskey() ) {
  60. print_error('confirmsesskeybad','error',$returnurl);
  61. }
  62. foreach($groupidarray as $groupid) {
  63. groups_delete_group($groupid);
  64. }
  65. redirect($returnurl);
  66. } else {
  67. $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
  68. $PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
  69. echo $OUTPUT->header();
  70. $optionsyes = array('courseid'=>$courseid, 'groups'=>$groupids, 'sesskey'=>sesskey(), 'confirm'=>1);
  71. $optionsno = array('id'=>$courseid);
  72. if(count($groupnames)==1) {
  73. $message=get_string('deletegroupconfirm', 'group', $groupnames[0]);
  74. } else {
  75. $message=get_string('deletegroupsconfirm', 'group').'<ul>';
  76. foreach($groupnames as $groupname) {
  77. $message.='<li>'.$groupname.'</li>';
  78. }
  79. $message.='</ul>';
  80. }
  81. $formcontinue = new single_button(new moodle_url('delete.php', $optionsyes), get_string('yes'), 'post');
  82. $formcancel = new single_button(new moodle_url('index.php', $optionsno), get_string('no'), 'get');
  83. echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
  84. echo $OUTPUT->footer();
  85. }