]> git.mjollnir.org Git - moodle.git/commitdiff
Cleaned up the admin pages (and moved some files) and added ability to completely...
authormartin <martin>
Sat, 3 Aug 2002 04:44:35 +0000 (04:44 +0000)
committermartin <martin>
Sat, 3 Aug 2002 04:44:35 +0000 (04:44 +0000)
admin/index.php
course/delete.php [new file with mode: 0644]
course/teacher.php [moved from admin/teacher.php with 91% similarity]
lang/en/moodle.php

index ea63d3e963daafc70eb1ff41af5172f3a6f7457b..548574a5f95ed1ec7594a1cfddce1ba7a47443fb 100644 (file)
 
     print_header("$site->fullname: Administration Page","$site->fullname: Administration Page", "Admin");
 
-    echo "<UL>";
-    echo "<LI><B><A HREF=\"site.php\">Site settings</A></B>";
-    echo "<LI><B><A HREF=\"../course/edit.php\">Create a new course</A></B>";
-    echo "<LI><B><A HREF=\"user.php\">Edit a user's account</A></B>";
-    echo "<LI><B><A HREF=\"teacher.php\">Assign teachers to courses</A></B>";
-    echo "<LI><B>Delete a course</B>";
-    echo "<LI><B><A HREF=\"../course/log.php?id=$site->id\">Site Logs</A></B>";
-    echo "</UL>";
+    $table->head  = array ("Site Management", "Course Setup", "Other");
+    $table->align = array ("CENTER", "CENTER", "CENTER");
+    $table->data[0][0] = "<P><A HREF=\"site.php\">Site settings</A></P>".
+                         "<P><A HREF=\"../course/log.php?id=$site->id\">Site Logs</A></P>";
+    $table->data[0][1] = "<P><A HREF=\"../course/edit.php\">Create a new course</A></P>".
+                         "<P><A HREF=\"../course/teacher.php\">Assign teachers to a course</A></P>".
+                         "<P><A HREF=\"../course/delete.php\">Delete a course</A></P>";
+    $table->data[0][2] = "<P><A HREF=\"user.php\">Edit a user's account</A></P>";
+
+    print_table($table);
 
     print_footer();
 ?>
diff --git a/course/delete.php b/course/delete.php
new file mode 100644 (file)
index 0000000..6089d21
--- /dev/null
@@ -0,0 +1,117 @@
+<?PHP // $Id$
+
+       require("../config.php");
+
+    optional_variable($id);       // course id
+    optional_variable($delete);   // delete confirmation
+
+    require_login();
+
+    if (!isadmin()) {
+        error("You must be an administrator to use this page.");
+    }
+
+    if (!$id) {
+           print_header("Delete a course", "Delete a course", 
+                     "<A HREF=\"$CFG->wwwroot/admin\">Admin</A> -> Delete a course");
+        if ($courses = get_records_sql("SELECT * from course WHERE category > 0 ORDER BY fullname")) {
+            print_heading("Choose a course to delete");
+            print_simple_box_start("CENTER");
+            foreach ($courses as $course) {
+                echo "<A HREF=\"delete.php?id=$course->id\">$course->fullname</A><BR>";
+            }
+            print_simple_box_end();
+        } else {
+            print_heading(get_string("nocoursesyet"));
+            print_continue("$CFG->wwwroot/admin/");
+        }
+        print_footer();
+        exit;
+    }
+
+    if (! $course = get_record("course", "id", $id)) {
+        error("Course ID was incorrect (can't find it)");
+    }
+
+    if (! $delete) {
+           print_header("Delete $course->shortname ?", "Delete $course->shortname ?", 
+                     "<A HREF=\"$CFG->wwwroot/admin\">Admin</A> -> Delete $course->shortname ?");
+        notice_yesno("Are you absolutely sure you want to completely delete this course and all the data it contains?<BR><BR>$course->fullname", "delete.php?id=$course->id&delete=".md5($course->timemodified), "delete.php");
+        exit;
+    }
+
+    if ($delete != md5($course->timemodified)) {
+        error("The check variable was wrong - try again");
+    }
+
+    // OK checks done, delete the course now.
+       print_header("Deleting $course->shortname", "Deleting $course->shortname", 
+                 "<A HREF=\"$CFG->wwwroot/admin\">Admin</A> -> Deleting $course->shortname");
+    print_heading("Deleting $course->fullname");
+
+    // First delete every instance of every module
+
+    if ($allmods = get_records_sql("SELECT * FROM modules") ) {
+        foreach ($allmods as $mod) {
+            $modname = $mod->name;
+            $modfile = "../mod/$modname/lib.php";
+            $moddelete = $modname."_delete_instance";
+            $count=0;
+            if (file_exists($modfile)) {
+                include_once($modfile);
+                if (function_exists($moddelete)) {
+                    if ($instances = get_records($modname, "course", $course->id)) {
+                        foreach ($instances as $instance) {
+                            if ($moddelete($instance->id)) {
+                                $count++;
+                            } else {
+                                notify("Could not delete $modname instance $instance->id ($instance->name)");
+                            }
+                        }
+                    }
+                } else {
+                    notify("Function $moddelete() doesn't exist!");
+                }
+
+            }
+            notify("Deleted $count instances of $modname");
+        } 
+    } else {
+        error("No modules are installed!");
+    } 
+
+    // Delete any user stuff
+
+    if (delete_records("user_students", "course", $course->id)) {
+        notify("Deleted student enrolments");
+    }
+
+    if (delete_records("user_teachers", "course", $course->id)) {
+        notify("Deleted teachers");
+    }
+
+    // Delete logs
+
+    if (delete_records("log", "course", $course->id)) {
+        notify("Deleted logs");
+    }
+
+    // Delete any course stuff
+
+    if (delete_records("course_sections", "course", $course->id)) {
+        notify("Deleted course sections");
+    }
+    if (delete_records("course_modules", "course", $course->id)) {
+        notify("Deleted course modules");
+    }
+    if (delete_records("course", "id", $course->id)) {
+        notify("Deleted the main course record");
+    }
+
+    print_heading("$course->shortname has been completely deleted");
+
+    print_continue("delete.php");
+
+    print_footer();
+
+?>
similarity index 91%
rename from admin/teacher.php
rename to course/teacher.php
index 8355f4271a16ddf7c3c490dfb2f31ef275a87421..a74af31ac60659992697c90b87d61722cba4cec2 100644 (file)
     }
 
     if (!$id) {
-        $courses = get_records_sql("SELECT * from course WHERE category > 0 ORDER BY fullname");
-
            print_header("Add teachers to a course", "Add teachers to a course", "<A HREF=\"$CFG->wwwroot/admin\">Admin</A> -> Add teachers", "");
-        print_heading("Choose a course to add teachers to");
-        print_simple_box_start("CENTER");
-        foreach ($courses as $course) {
-            echo "<A HREF=\"teacher.php?id=$course->id\">$course->fullname</A><BR>";
+        if ($courses = get_records_sql("SELECT * from course WHERE category > 0 ORDER BY fullname")) {
+
+            print_heading("Choose a course to add teachers to");
+            print_simple_box_start("CENTER");
+            foreach ($courses as $course) {
+                echo "<A HREF=\"teacher.php?id=$course->id\">$course->fullname</A><BR>";
+            }
+            print_simple_box_end();
+        } else {
+            print_heading(get_string("nocoursesyet"));
+            print_continue("$CFG->wwwroot/admin/");
         }
-        print_simple_box_end();
         print_footer();
         exit;
     }
index 72772493238a071f5c86156676a9dc9dbe0e7f8f..fa7102efe918643e8926659ec7e50de569705d89 100644 (file)
@@ -23,6 +23,7 @@ $string[changedpassword] = "Changed password";
 $string[changessaved] = "Changes saved";
 $string[city] = "City/town";
 $string[confirmed] = "Your registration has been confirmed";
+$string["continue"] = "Continue";
 $string[country] = "Country";
 $string[course] = "Course";
 $string[courses] = "Courses";
@@ -121,6 +122,7 @@ $string[missingusername] = "Missing username";
 $string[movedown] = "Move down";
 $string[moveup] = "Move up";
 $string[mustconfirm] = "You need to confirm your login";
+$string[nocoursesyet] = "There are no courses yet";
 $string[newaccount] = "New account";
 $string[newpassword] = "New password";
 $string[newpasswordtext] = "Hi \$a->firstname,