Search moodle.org's
Developer Documentation


/course/ -> delete.php (source)
   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  /**
  18   * Admin-only code to delete a course utterly.
  19   *
  20   * @package core_course
  21   * @copyright 2002 onwards Martin Dougiamas (http://dougiamas.com)
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(dirname(__FILE__) . '/../config.php');
  26  require_once($CFG->dirroot . '/course/lib.php');
  27  
  28  $id = required_param('id', PARAM_INT); // Course ID.
  29  $delete = optional_param('delete', '', PARAM_ALPHANUM); // Confirmation hash.
  30  
  31  $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
  32  $coursecontext = context_course::instance($course->id);
  33  
  34  require_login();
  35  
  36  if ($SITE->id == $course->id || !can_delete_course($id)) {
  37      // Can not delete frontpage or don't have permission to delete the course.
  38      print_error('cannotdeletecourse');
  39  }
  40  
  41  $categorycontext = context_coursecat::instance($course->category);
  42  $PAGE->set_url('/course/delete.php', array('id' => $id));
  43  $PAGE->set_context($categorycontext);
  44  $PAGE->set_pagelayout('admin');
  45  navigation_node::override_active_url(new moodle_url('/course/management.php', array('categoryid'=>$course->category)));
  46  
  47  $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
  48  $coursefullname = format_string($course->fullname, true, array('context' => $coursecontext));
  49  $categoryurl = new moodle_url('/course/management.php', array('categoryid' => $course->category));
  50  
  51  // Check if we've got confirmation.
  52  if ($delete === md5($course->timemodified)) {
  53      // We do - time to delete the course.
  54      require_sesskey();
  55  
  56      $strdeletingcourse = get_string("deletingcourse", "", $courseshortname);
  57  
  58      $PAGE->navbar->add($strdeletingcourse);
  59      $PAGE->set_title("$SITE->shortname: $strdeletingcourse");
  60      $PAGE->set_heading($SITE->fullname);
  61  
  62      echo $OUTPUT->header();
  63      echo $OUTPUT->heading($strdeletingcourse);
  64      // We do this here because it spits out feedback as it goes.
  65      delete_course($course);
  66      echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
  67      // Update course count in categories.
  68      fix_course_sortorder();
  69      echo $OUTPUT->continue_button($categoryurl);
  70      echo $OUTPUT->footer();
  71      exit; // We must exit here!!!
  72  }
  73  
  74  $strdeletecheck = get_string("deletecheck", "", $courseshortname);
  75  $strdeletecoursecheck = get_string("deletecoursecheck");
  76  $message = "{$strdeletecoursecheck}<br /><br />{$coursefullname} ({$courseshortname})";
  77  
  78  $continueurl = new moodle_url('/course/delete.php', array('id' => $course->id, 'delete' => md5($course->timemodified)));
  79  $continuebutton = new single_button($continueurl, get_string('delete'), 'post');
  80  
  81  $PAGE->navbar->add($strdeletecheck);
  82  $PAGE->set_title("$SITE->shortname: $strdeletecheck");
  83  $PAGE->set_heading($SITE->fullname);
  84  echo $OUTPUT->header();
  85  echo $OUTPUT->confirm($message, $continuebutton, $categoryurl);
  86  echo $OUTPUT->footer();
  87  exit;

Search This Site: