diff --git a/course/deletesection.php b/course/deletesection.php
new file mode 100644
index 0000000..e112b38
--- /dev/null
+++ b/course/deletesection.php
@@ -0,0 +1,82 @@
+<?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("lib.php");
+    require('deletesectionlib.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!");
+    }
+
+    if ( $section->section == 0) {
+        error("Course section 0 (main) could not be deleted");
+    }
+
+    require_login($course->id);
+
+    require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
+
+    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');
+    }
+
+    // OK checks done
+
+    // delete all modules if they exist
+    if (!empty($section->sequence) ) {
+        $modids = split(',', $section->sequence);
+        foreach($modids AS $modid) {
+            deletesection_delete_module($modid);
+        }
+    }
+
+    // remove the section and update the course.numsections and sections order
+    deletesection_delete_and_reorder($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);
+?>
diff --git a/course/deletesectionlib.php b/course/deletesectionlib.php
new file mode 100644
index 0000000..02fb988
--- /dev/null
+++ b/course/deletesectionlib.php
@@ -0,0 +1,65 @@
+<?php
+
+function deletesection_delete_module($modid, $course) {
+    global $CFG;
+
+    if (! $cm = get_record("course_modules", "id", $modid)) {
+        error("This course module doesn't exist");
+    }
+
+    $mod->instance = $cm->instance;
+    $mod->coursemodule = $cm->id;
+    $mod->course = $course->id;
+    $mod->section = $section->id;
+
+    $sql = "SELECT md.name
+              FROM {$CFG->prefix}course_modules cm
+              JOIN {$CFG->prefix}modules md
+                ON md.id = cm.module
+             WHERE cm.id = '{$cm->id}'";
+
+    if (!$modname = get_field_sql($sql)){
+        error('Invalid course module id!');
+    }
+
+    $mod->modulename = clean_param($modname, PARAM_SAFEDIR);  // For safety
+    $modlib = "$CFG->dirroot/mod/$mod->modulename/lib.php";
+
+    if (file_exists($modlib)) {
+        include_once($modlib);
+    } else {
+        error("This module is missing important code! ($modlib)");
+    }
+
+    $deleteinstancefunction = $mod->modulename."_delete_instance";
+    if (! $deleteinstancefunction($mod->instance)) {
+        notify("Could not delete the $mod->modulename (instance)");
+    }
+    if (! delete_course_module($mod->coursemodule)) {
+        notify("Could not delete the $mod->modulename (coursemodule)");
+    }
+    if (! delete_mod_from_section($mod->coursemodule, "$mod->section")) {
+        notify("Could not delete the $mod->modulename from that section");
+    }
+}
+
+function deletesection_delete_and_reorder($section, $course) {
+    global $CFG;
+
+    if (!delete_records("course_sections", "id", $section->id)) {
+        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);
+
+    add_to_log($course->id, "course", "deletesection", "deletesection.php?id=$section->id", "$section->section");
+}
+
+?>
diff --git a/course/format/topics/format.php b/course/format/topics/format.php
index 62ca069..193ced8 100644
--- a/course/format/topics/format.php
+++ b/course/format/topics/format.php
@@ -54,6 +54,7 @@
     $strtopic         = get_string('topic');
     $strgroups        = get_string('groups');
     $strgroupmy       = get_string('groupmy');
+    $strdeletesection = get_string('deletesection');
     $editing          = $PAGE->user_is_editing();
 
     if ($editing) {
@@ -219,6 +220,7 @@
             echo '</td>';
 
             echo '<td class="right side">';
+
             if ($displaysection == $section) {      // Show the zoom boxes
                 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
                      '<img src="'.$CFG->pixpath.'/i/all.gif" alt="'.$strshowalltopics.'" /></a><br />';
@@ -255,6 +257,9 @@
                          '<img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strmovedown.'" /></a><br />';
                 }
 
+                echo '<a class="delete_section" href="deletesection.php?id='.$thissection->id.
+                     '&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strdeletesection.'">'.
+                     '<img src="'.$CFG->pixpath.'/t/delete.gif" alt="'.$strdeletesection.'" /></a><br />';
             }
 
             echo '</td></tr>';
diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php
index 64f3f77..2b0dd08 100644
--- a/course/format/weeks/format.php
+++ b/course/format/weeks/format.php
@@ -40,6 +40,7 @@
     $strweek         = get_string('week');
     $strgroups       = get_string('groups');
     $strgroupmy      = get_string('groupmy');
+    $strdeletesection = get_string('deletesection');
     $editing         = $PAGE->user_is_editing();
 
     if ($editing) {
@@ -244,6 +245,10 @@
                     echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.$USER->sesskey.'#section-'.($section+1).'" title="'.$strmovedown.'">'.
                          '<img src="'.$CFG->pixpath.'/t/down.gif" class="iconsmall down" alt="'.$strmovedown.'" /></a><br />';
                 }
+
+                echo '<a class="delete_section" href="deletesection.php?id='.$thissection->id.
+                     '&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strdeletesection.'">'.
+                     '<img src="'.$CFG->pixpath.'/t/delete.gif" alt="'.$strdeletesection.'" /></a><br />';
             }
 
             echo '</td></tr>';
diff --git a/course/rest.php b/course/rest.php
index e7e08a6..8a85449 100644
--- a/course/rest.php
+++ b/course/rest.php
@@ -193,6 +193,26 @@ switch($_SERVER['REQUEST_METHOD']) {
                            "view.php?id=$courseid",
                            "$mod->name $cm->instance", $cm->id);
                 break;
+             case 'section':
+                require('deletesectionlib.php'); 
+
+                if (!$section = get_record('course_sections','course',$course->id,'section',$sectionid)) {
+                    error_log('AJAX commands.php: Bad section ID '.$sectionid);
+                    die;
+                }
+
+                // delete all modules if they exist
+                if (!empty($section->sequence) ) {
+                    $modids = split(',', $section->sequence);
+                    foreach($modids AS $modid) {
+                        deletesection_delete_module($modid);
+                    }
+                }
+
+                // remove the section and update the course.numsections and sections order
+                deletesection_delete_and_reorder($section, $course);
+
+                rebuild_course_cache($course->id);
         }
         break;
 }
diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php
index d2a44e7..2b8545a 100644
--- a/lang/en_utf8/moodle.php
+++ b/lang/en_utf8/moodle.php
@@ -406,10 +406,13 @@ $string['deletedactivity'] = 'Deleted $a';
 $string['deletedcourse'] = '$a has been completely deleted';
 $string['deletednot'] = 'Could not delete $a !';
 $string['deletelogs'] = 'Delete logs';
+$string['deletesection'] = 'Delete section';
+$string['deletesectioncheck'] = 'Are you sure you want to delete section $a? All activities and resources within this section will be deleted. This operation cannot be undone.';
 $string['deleteselected'] = 'Delete selected';
 $string['deleteselectedkey'] = 'Delete selected key';
 $string['deletingcourse'] = 'Deleting $a';
 $string['deletingexistingcoursedata'] = 'Deleting existing course data';
+$string['deletingsection'] = 'Deleting section';
 $string['deletingolddata'] = 'Deleting old data';
 $string['department'] = 'Department';
 $string['desc'] = 'Descending';
