]> git.mjollnir.org Git - moodle.git/commitdiff
Changes to course display on front page when there is more than one category
authormartin <martin>
Tue, 10 Sep 2002 13:47:56 +0000 (13:47 +0000)
committermartin <martin>
Tue, 10 Sep 2002 13:47:56 +0000 (13:47 +0000)
course/lib.php
index.php
lang/en/moodle.php

index 552e091b25620e2d8e9c25b872c40dd88d56c0d9..6fa7e0bc5b33aa80ba4bec69ac39a08f037c8064 100644 (file)
@@ -597,19 +597,62 @@ function print_course_admin_links($course, $width=180) {
 function print_course_categories($categories, $selected="none", $width=180) {
     global $CFG, $THEME, $USER;
 
-    foreach ($categories as $cat) {
-        $caticon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/course.gif\" HEIGHT=16 WIDTH=16>";
-        if ($cat->id == $selected) {
-            $catdata[]="$cat->name";
-        } else {
-            $catdata[]="<A HREF=\"$CFG->wwwroot/course/index.php?category=$cat->id\">$cat->name</A>";
+    if ($selected == "index") {  // Print comprehensive index of categories with courses
+        if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0 ORDER BY shortname")) {
+            if (isset($USER->id) and !isadmin()) {
+                print_simple_box_start("LEFT", "100%");
+                print_heading("<A HREF=\"course/index.php?category=my\">".get_string("mycourses")."</A>", "LEFT");
+                $some = false;
+                echo "<UL>";
+                foreach ($courses as $key => $course) {
+                    if (isteacher($course->id) or isstudent($course->id)) {
+                        echo "<IMG SRC=\"$CFG->wwwroot/pix/i/course.gif\" HEIGHT=16 WIDTH=16>&nbsp;<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> &nbsp; ";
+                        $some = true;
+                    }
+                }
+                if (!$some) {
+                    print_string("nocoursesyet");
+                }
+                echo "</UL>";
+                print_simple_box_end();
+                print_spacer(8,1);
+            }
+            foreach ($categories as $category) {
+                print_simple_box_start("LEFT", "100%");
+                print_heading("<A HREF=\"course/index.php?category=my\">$category->name</A>", "LEFT");
+                $some = false;
+                echo "<UL>";
+                foreach ($courses as $key => $course) {
+                    if ($course->category == $category->id) {
+                        echo "<IMG SRC=\"$CFG->wwwroot/pix/i/course.gif\" HEIGHT=16 WIDTH=16>&nbsp;<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> &nbsp; ";
+                        unset($courses[$key]);
+                        $some = true;
+                    }
+                }
+                if (!$some) {
+                    print_string("nocoursesyet");
+                }
+                echo "</UL>";
+                print_simple_box_end();
+                print_spacer(8,1);
+            }
         }
+
+    } else {                    // Print short list of categories only 
+        foreach ($categories as $cat) {
+            $caticon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/course.gif\" HEIGHT=16 WIDTH=16>";
+            if ($cat->id == $selected) {
+                $catdata[]="$cat->name";
+            } else {
+                $catdata[]="<A HREF=\"$CFG->wwwroot/course/index.php?category=$cat->id\">$cat->name</A>";
+            }
+        }
+        $catdata[] = "<A HREF=\"$CFG->wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."</A>";
+        if (isset($USER->id)) {
+            $catdata[] = "<A HREF=\"$CFG->wwwroot/course/index.php?category=my\">".get_string("mycourses")."</A>";
+        }
+        print_side_block("", $catdata, $showall.$mine, $caticon, $width);
     }
-    $catdata[] = "<A HREF=\"$CFG->wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."</A>";
-    if (isset($USER->id)) {
-        $catdata[] = "<A HREF=\"$CFG->wwwroot/course/index.php?category=my\">".get_string("mycourses")."</A>";
-    }
-    print_side_block("", $catdata, $showall.$mine, $caticon, $width);
 }
 
 function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
index 0303e12b991b2df1b5d618222b83133f153b9ca5..c6b397e4995e15814b4decc4aa9af402715cb8da 100644 (file)
--- a/index.php
+++ b/index.php
      if ($site->newsitems == 0 ) {
          print_simple_box(get_string("availablecourses"), "CENTER", "100%", "$THEME->cellheading");
          print_spacer(8,1);
-         print_all_courses("all");
+         $categories = get_all_categories();
+         if (count($categories) > 1) {
+             print_course_categories($categories, "index");
+         } else {
+             print_all_courses("all");
+         }
 
      } else {
          if (! $newsforum = forum_get_course_forum($site->id, "news")) {
index 395a019ad17aa4b4eade9ca5ddd4b1966c1c00fb..d39a966a4417dcc4d1b82d6ddf1eecb37c90c75b 100644 (file)
@@ -288,7 +288,7 @@ $string[newsitems] = "news items";
 $string[newsitemsnumber] = "News items to show";
 $string[never] = "Never";
 $string[no] = "No";
-$string[nocoursesyet] = "There are no courses yet";
+$string[nocoursesyet] = "No courses in this category";
 $string[noexistingteachers] = "No existing teachers";
 $string[nograde] = "No grade";
 $string[nopotentialteachers] = "No potential teachers";