diff --git a/course/lib.php b/course/lib.php
index 74ed316..510ddce 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -2467,6 +2485,50 @@ function delete_mod_from_section($mod, $section) {
     return false;
 }
 
+function delete_section($section, $course) {
+
+    if ( $section->section == 0) {
+        print_error("Course section 0 (main) could not be deleted");
+    }
+
+    // delete all modules if they exist
+    if (!empty($section->sequence) ) {
+        $modids = split(',', $section->sequence);
+        foreach($modids AS $modid) {
+            if ($cm = get_record("course_modules", "id", $modid)) {
+                if ($modulename = get_field('modules', 'name', 'id', $cm->module)) {
+
+                    $modlib = "{$CFG->dirroot}/mod/{$modulename}/lib.php";
+                    if (file_exists($modlib)) {
+                        include_once($modlib);
+                        $deleteinstancefunction = $modulename."_delete_instance";
+                        $deleteinstancefunction($cm->instance);
+                    }
+                }
+                delete_course_module($modid);
+            }
+        }
+    }
+    // remove the section and update the course.numsections and sections order
+    if (!delete_records("course_sections", "id", $section->id)) {
+        print_error("Could not delete Course section");
+    }
+
+    execute_sql("UPDATE {$CFG->prefix}course_sections
+                    SET section = section - 1
+                  WHERE course = {$course->id}
+                    AND section > {$section->section}", false);
+
+    execute_sql("UPDATE {$CFG->prefix}course
+                    SET numsections = numsections - 1
+                  WHERE id = {$course->id}", false);
+
+
+    rebuild_course_cache($course->id);
+
+    add_to_log($course->id, "course", "deletesection", "deletesection.php?id=$section->id", "$section->section");
+}
+
 /**
  * Moves a section up or down by 1. CANNOT BE USED DIRECTLY BY AJAX!
  *
diff --git a/course/deletesection.php b/course/deletesection.php
new file mode 100644
index 0000000..0094eaa
--- /dev/null
+++ b/course/deletesection.php
@@ -0,0 +1,69 @@
+<?php // $Id: editsection.php,v 1.25 2007/08/17 19:09:11 nicolasconnault Exp $
+      // Edit the introduction of a section
+
+require_once('../config.php');
+require_once($CFG->dirroot.'/course/lib.php');
+
+$id = required_param('id', PARAM_INT); // SECTION ID
+$delete = optional_param('delete', '', PARAM_ALPHANUM); // delete confirmation hash
+
+$site = get_site();
+
+if (! $section = get_record("course_sections", "id", $id)) {
+    error("Course section is incorrect");
+}
+
+if (! $course = get_record("course", "id", $section->course)) {
+    error("Could not find the course!");
+}
+
+require_login($course->id);
+
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+require_capability('moodle/course:manageactivities', $context);
+
+if (!$delete) {
+    $delete_section = get_string("deletesection");
+    $delete_section_check = get_string("deletesectioncheck", '', $section->section);
+
+    $navlinks[] = array('name' => $delete_section, 'link' => null, 'type' => 'misc');
+    $navigation = build_navigation($navlinks);
+
+    print_header("$course->shortname: $delete_section", $site->fullname, $navigation);
+
+    notice_yesno("{$delete_section_check}",
+                 "deletesection.php?id=$section->id&amp;delete=".md5($course->timemodified)."&amp;sesskey={$USER->sesskey}",
+                 "view.php?id={$course->id}");
+
+    print_footer($course);
+    exit;
+}
+
+if ($delete != md5($course->timemodified)) {
+    error("The check variable was wrong - try again");
+}
+
+if (!confirm_sesskey()) {
+    print_error('confirmsesskeybad', 'error');
+}
+
+delete_section($section, $course);
+
+$strdeletingsection= get_string("deletingsection", "", format_string($course->shortname));
+
+$navlinks[] = array('name' => $strdeletingsection, 'link' => null, 'type' => 'misc');
+$navigation = build_navigation($navlinks);
+
+print_header("$course->shortname: $strdeletingsection", $site->fullname, $navigation);
+
+print_heading($strdeletingsection);
+
+redirect("view.php?id=$course->id");
+
+print_heading( get_string("deletedsection") );
+
+print_continue("view.php?id=$course->id");
+
+print_footer($course);
+?>
