]> git.mjollnir.org Git - moodle.git/commitdiff
Part of "contributions" overhaul in course/user.php
authormartin <martin>
Tue, 23 Jul 2002 16:24:12 +0000 (16:24 +0000)
committermartin <martin>
Tue, 23 Jul 2002 16:24:12 +0000 (16:24 +0000)
course/lib.php
course/topics.php
course/user.php
course/view.php
course/weeks.php
lang/en/strings.php
mod/journal/user.php

index 492edc49338aa3e3e30a6dbf06228576f096dd8f..88d3061a784abe81b617cf16dfde52e7b8176b6b 100644 (file)
@@ -397,4 +397,31 @@ function enrol_student_in_course($user, $course) {
        }
 }
 
+function get_all_mods($courseid, &$mods, &$modtype) {
+
+    $mods = NULL;
+    $modtype = NULL;
+
+    if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname
+                                   FROM modules m, course_modules cm
+                                   WHERE cm.course = '$courseid' 
+                                     AND cm.deleted = '0'
+                                     AND cm.module = m.id") ) {
+        foreach($rawmods as $mod) {    // Index the mods
+            $mods[$mod->id] = $mod;
+            $modtype[$mod->modname] = $mod->modfullname;
+        }
+        ksort($modtype);
+    }
+
+}
+
+function get_all_sections($courseid) {
+    
+    return get_records_sql("SELECT section, id, course, summary, sequence
+                            FROM course_sections 
+                            WHERE course = '$courseid' 
+                            ORDER BY section");
+}
+
 ?>
index 7863037505e91b5260bd7968a55b2881acdc84a9..ba4df90bd122b2411c37e3bcb8fcd0e350b4feed 100644 (file)
@@ -8,19 +8,15 @@
 
     include("../mod/forum/lib.php");
 
-    if (! $rawsections = get_records("course_sections", "course", $course->id) ) {
+    if (! $sections = get_all_sections($course->id) ) {
         $section->course = $course->id;   // Create a default section.
         $section->section = 0;
         $section->id = insert_record("course_sections", $section);
-        if (! $rawsections = get_records("course_sections", "course", $course->id) ) {
+        if (! $sections = get_all_sections($course->id) ) {
             error("Error finding or creating section structures for this course");
         }
     }
     
-    foreach($rawsections as $cw) {  //Index the sections
-        $sections[$cw->section] = $cw;
-    }
-
     if (isset($topic)) {
         if ($topic == "all") {
             unset($USER->topic);
index 86f89c77f62b9bfc2fd547035f93b084680d328a..0cdb92572ad92875640661223da5b95aec691cc7 100644 (file)
@@ -1,9 +1,11 @@
 <?PHP // $Id$
 
     require("../config.php");
+    require("lib.php");
 
     require_variable($id);       // course id
     require_variable($user);     // user id
+    optional_variable($mode, "complete");
 
     if (! $course = get_record("course", "id", $id)) {
         error("Course id is incorrect.");
                   <A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> -> 
                   Full Report", "");
 
-    if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname
-                                   FROM modules m, course_modules cm
-                                   WHERE cm.course = '$course->id' 
-                                     AND cm.deleted = '0'
-                                     AND cm.module = m.id") ) {
+    get_all_mods($course->id, $mods, $modtype);
 
-        foreach($rawmods as $mod) {    // Index the mods
-            $mods[$mod->id] = $mod;
-            $modtype[$mod->modname] = $mod->modfullname;
-        }
-    }
+    switch ($mode) {
+        case "summary" :
+            echo "<P>Not supported yet</P>";
+            break;
 
+        case "outline" :
+        case "complete" :
+        default:
+            $sections = get_all_sections($course->id);
 
-    // Replace all the following with a better log-based method.
-    if ($course->format == "weeks") {
-        if ($sections = get_records_sql("SELECT * FROM course_sections WHERE course = '$course->id' ORDER BY section")) {
-            foreach ($sections as $www) {
-                $section = (object)$www;
-                echo "<H2>Week $section->section</H2>";
-                if ($section->sequence) {
-                    $sectionmods = explode(",", $section->sequence);
-                    foreach ($sectionmods as $sectionmod) {
-                        $mod = $mods[$sectionmod];
-                        $instance = get_record("$mod->modname", "id", "$mod->instance");
-                        $userfile = "$CFG->dirroot/mod/$mod->name/user.php";
-                        include($userfile);
-                    }
+            for ($i=0; $i<=$course->numsections; $i++) {
+
+                if (isset($sections[$i])) {   // should always be true
+
+                    $section = $sections[$i];
+        
+                    if ($section->sequence) {
+                        echo "<HR>";
+                        echo "<H2>";
+                        switch ($course->format) {
+                            case "weeks": print_string("week"); break;
+                            case "topics": print_string("topic"); break;
+                            default: print_string("section"); break;
+                        }
+                        echo " $i</H2>";
+
+                        echo "<UL>";
+
+                        if ($mode == "outline") {
+                            echo "<TABLE CELLPADDING=4 CELLSPACING=0>";
+                        }
+
+                        $sectionmods = explode(",", $section->sequence);
+                        foreach ($sectionmods as $sectionmod) {
+                            $mod = $mods[$sectionmod];
+                            $instance = get_record("$mod->modname", "id", "$mod->instance");
+                            $userfile = "$CFG->dirroot/mod/$mod->modname/user.php";
+                            if (file_exists($userfile)) {
+                                if ($mode == "outline") {
+                                    $output = include($userfile);
+                                    print_outline_row($mod, $instance, $output);
+                                } else {
+                                    include($userfile);
+                                }
+                            }
+                        }
+
+                        if ($mode == "outline") {
+                            echo "</TABLE>";
+                            print_simple_box_end();
+                        }
+                        echo "</UL>";
                     
-                } else {
-                    echo "<P>No modules</P>";
+                    }
                 }
             }
-        }
-    } else { 
-        echo "<P>Not implemented yet</P>";
+            break;
     }
 
+
     print_footer($course);
 
+
+function print_outline_row($mod, $instance, $info) {
+    $image = "<IMG SRC=\"../mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
+    echo "<TR><TD ALIGN=right>$image</TD>";
+    echo "<TD align=left width=200>";
+    echo "<A TITLE=\"$mod->modfullname\"";
+    echo "   HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instance->name</A></TD>";
+    echo "<TD>&nbsp;&nbsp;&nbsp;</TD>";
+    echo "<TD BGCOLOR=white>$info</TD></TR>";
+}
+
 ?>
 
index a3f0fa69d8dab835269eea20fbb1ab33d871765c..47380fadfa7fc69c387be4f88f56b5eacdb5b7ad 100644 (file)
         error("No modules are installed!");
     }
 
-    if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname
-                                   FROM modules m, course_modules cm
-                                   WHERE cm.course = '$course->id' 
-                                     AND cm.deleted = '0'
-                                     AND cm.module = m.id") ) {
-
-        foreach($rawmods as $mod) {    // Index the mods
-            $mods[$mod->id] = $mod;
-            $modtype[$mod->modname] = $mod->modfullname;
-        }
-        if (isset($modtype["forum"]) and isset($modtype["discuss"])) {
-            // We only need one of them
-            unset($modtype["discuss"]);
-        }
-        ksort($modtype);
+    get_all_mods($course->id, $mods, $modtype);
+
+    if (isset($modtype["forum"]) and isset($modtype["discuss"])) {  // Only need to display one
+        unset($modtype["discuss"]);
     }
 
     switch ($course->format) {
index 00a0d556215610e14edbd5d09dcf2411089ce5f1..2fb3834d032781a410a116430e72772455b6f612 100644 (file)
@@ -4,18 +4,14 @@
 
     include("../mod/forum/lib.php");
 
-    if (! $rawsections = get_records("course_sections", "course", $course->id) ) {
+    if (! $sections = get_all_sections($course->id, $course->numsections) ) {
         $section->course = $course->id;   // Create a default section.
         $section->section = 0;
         $section->id = insert_record("course_sections", $section);
-        if (! $rawsections = get_records("course_sections", "course", $course->id) ) {
+        if (! $sections = get_all_sections($course->id, $course->numsections) ) {
             error("Error finding or creating section structures for this course");
         }
     }
-    
-    foreach($rawsections as $cw) {  //Index the sections
-        $sections[$cw->section] = $cw;
-    }
 
     if (isset($week)) {
         if ($week == "all") {
@@ -26,7 +22,6 @@
     }
 
 
-
     // Layout the whole page as three big columns.
     echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
     echo "<TR VALIGN=top><TD VALIGN=top WIDTH=180>";
index ae05a28a6ddecfdd00a8f068bc0a65eebb4a36f8..535e4dbe9621411e0117c2ba2e020f5df5045d39 100644 (file)
@@ -160,6 +160,7 @@ $string[passwordsenttext] = "
 $string[personalprofile] = "Personal profile";
 $string[phone] = "Phone";
 $string[returningtosite] = "Returning to this web site?";
+$string[section] = "Section";
 $string[selectacountry] = "Select a country";
 $string[senddetails] = "Send my details via email";
 $string[serverlocaltime] = "Server's local time";
@@ -177,6 +178,7 @@ $string[textformat] = "Plain text format";
 $string[timezone] = "Timezone";
 $string[thanks] = "Thanks";
 $string[todaylogs] = "Today's logs";
+$string[topic] = "Topic";
 $string[unenrol] = "Unenrol";
 $string[unenrolme] = "Unenrol me from \$a";
 $string[update] = "Update";
@@ -187,6 +189,7 @@ $string[username] = "Username";
 $string[usernameexists] = "This username already exists, choose another";
 $string[userprofilefor] = "User profile for \$a";
 $string[webpage] = "Web page";
+$string[week] = "Week";
 $string[welcometocourse] = "Welcome to \$a";
 $string[welcometocoursetext] = "Welcome to \$a->coursename!
 
index 51c4928f08ef0c2f81aacbf73e4fff88dd398186..84a37f6e1d229721aa809fdd2a0b4f3b17f34b66 100644 (file)
@@ -1,70 +1,81 @@
 <?PHP // $Id$
 
-// Code fragment to list all the journals in a course by a particular user.
-// Assumes $course, $user and $mod are all defined (see /course/user.php)
+// Code fragment to list entries in a journal by a particular user.
+// Assumes $mode is defined as a selector for the type of report.
+// $course, $user, $mod and $instance are all objects (see /course/user.php)
 
-    include("$CFG->dirroot/mod/journal/lib.php");
+require_once("$CFG->dirroot/mod/journal/lib.php");
 
-    if (! $journals = get_all_instances_in_course("journal", $course->id)) {
-        notify("There are no journals");
-        die;
-    }
+switch ($mode) {
+    case "summary":
+        return user_journal_summary($course, $user, $mod, $instance);
+        break;
+    case "outline":
+        return user_journal_outline($course, $user, $mod, $instance);
+        break;
+    case "complete":
+        return user_journal_complete($course, $user, $mod, $instance);
+        break;
+}
+
+function user_journal_summary($course, $user, $mod, $journal) {
+    global $CFG;
+}
+
+
+function user_journal_outline($course, $user, $mod, $journal) {
+    if ($entry = get_record_sql("SELECT * FROM journal_entries 
+                                 WHERE user='$user->id' AND journal='$journal->id'")) {
 
-    if (! $teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t 
-                                       WHERE t.course = '$course->id' AND t.user = u.id
-                                       ORDER BY u.lastaccess DESC")) {
-        notify("No teachers");
-        die;
+        $numwords = count(preg_split("/\w\b/", $entry->text)) - 1;
+
+        return "$numwords words, last edited ".userdate($entry->modified);
+
+    } else {
+        return "No entry";
     }
+}
 
-    $timenow = time();
 
-    echo "<TABLE BORDER=1 CELLSPACING=0 valign=top align=center cellpadding=10>";
-    echo "<TR><TH>Week<TH>Journal</TR>";
-    foreach ($journals as $journal) {
+function user_journal_complete($course, $user, $mod, $journal) {
+    global $CFG, $THEME;
 
-        $journal->timestart  = $course->startdate + (($journal->section - 1) * 608400);
-        if ($journal->daysopen) {
-            $journal->timefinish = $journal->timestart + (3600 * 24 * $journal->daysopen);
-        } else {
-            $journal->timefinish = 9999999999;
-        }
+    echo "<H3>Journal: <A HREF=\"$CFG->wwwroot/mod/journal/view.php?id=$mod->id\">$journal->name</A></H3>";
+    echo "<UL>";
 
-        $entry = get_record_sql("SELECT * FROM journal_entries 
-                                 WHERE user='$user->id' AND journal='$journal->id'");
+    if ($entry = get_record_sql("SELECT * FROM journal_entries 
+                             WHERE user='$user->id' AND journal='$journal->id'")) {
 
+        print_simple_box_start();
+        if ($entry->modified) {
+            echo "<P><FONT SIZE=1>Last edited: ".userdate($entry->modified)."</FONT></P>";
+        }
         if ($entry->text) {
-            echo "<TR VALIGN=TOP>";
-            $journalopen = ($journal->timestart < $timenow && $timenow < $journal->timefinish);
-            if ($journalopen) {
-                echo "<TD BGCOLOR=\"$THEME->cellheading2\">";
-            } else {
-                echo "<TD BGCOLOR=\"$THEME->cellheading\">";
-            }
-            echo "$journal->section</TD>";
-            echo "<TD BGCOLOR=\"$THEME->cellcontent\">";
-            echo "<P><A HREF=\"$CFG->wwwroot/mod/journal/view.php?id=$journal->coursemodule\">$journal->name</A></P>";
-            if ($entry->modified) {
-                echo "<P><FONT SIZE=1>Last edited: ".userdate($entry->modified)."</FONT></P>";
-            }
             echo text_to_html($entry->text);
-            if ($entry->teacher) {
-                echo "\n<BR CLEAR=ALL><TABLE><TR>";
-                echo "<TD WIDTH=35 VALIGN=TOP>";
-                print_user_picture($entry->teacher, $course->id, $teachers[$entry->teacher]->picture);
-                echo "<TD BGCOLOR=\"$THEME->cellheading\">".$RATING[$entry->rating];
-                if ($entry->timemarked) {
-                    echo "&nbsp;&nbsp;<FONT SIZE=1>".userdate($entry->timemarked)."</FONT>";
-                }
-                echo "<BR><FONT COLOR=#000055>";
-                echo text_to_html($entry->comment);
-                echo "</FONT><BR>";
-                echo "</TD></TR></TABLE>";
+        }
+        if ($entry->teacher) {
+            $teacher = get_record("user", "id", $entry->teacher);
+    
+            echo "\n<BR CLEAR=ALL>";
+            echo "<TABLE><TR>";
+            echo "<TD WIDTH=35 VALIGN=TOP>";
+            print_user_picture($entry->teacher, $course->id, $teacher->picture);
+            echo "<TD BGCOLOR=\"$THEME->cellheading\">".$RATING[$entry->rating];
+            if ($entry->timemarked) {
+                echo "&nbsp;&nbsp;<FONT SIZE=1>".userdate($entry->timemarked)."</FONT>";
             }
-            echo "</TD></TR>";
+            echo "<BR><FONT COLOR=#000055>";
+            echo text_to_html($entry->comment);
+            echo "</FONT><BR>";
+            echo "</TD></TR></TABLE>";
         }
+        print_simple_box_end();
+
+    } else {
+        echo "No entry";
     }
-    echo "</TABLE>";
+    echo "</UL>";
+}
+
 ?>