Part of "contributions" overhaul in course/user.php

This commit is contained in:
martin
2002-07-23 16:24:12 +00:00
parent 65cf9fc390
commit 7468bf014f
7 changed files with 169 additions and 110 deletions
+27
View 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");
}
?>
+2 -6
View 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);
+67 -29
View 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.");
@@ -27,44 +29,80 @@
<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>";
}
?>
+3 -14
View File
@@ -40,21 +40,10 @@
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") ) {
get_all_mods($course->id, $mods, $modtype);
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);
if (isset($modtype["forum"]) and isset($modtype["discuss"])) { // Only need to display one
unset($modtype["discuss"]);
}
switch ($course->format) {
+2 -7
View 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>";
+3
View 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!
+65 -54
View 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'")) {
$numwords = count(preg_split("/\w\b/", $entry->text)) - 1;
return "$numwords words, last edited ".userdate($entry->modified);
} else {
return "No entry";
}
}
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;
}
$timenow = time();
function user_journal_complete($course, $user, $mod, $journal) {
global $CFG, $THEME;
echo "<TABLE BORDER=1 CELLSPACING=0 valign=top align=center cellpadding=10>";
echo "<TR><TH>Week<TH>Journal</TR>";
foreach ($journals as $journal) {
echo "<H3>Journal: <A HREF=\"$CFG->wwwroot/mod/journal/view.php?id=$mod->id\">$journal->name</A></H3>";
echo "<UL>";
$journal->timestart = $course->startdate + (($journal->section - 1) * 608400);
if ($journal->daysopen) {
$journal->timefinish = $journal->timestart + (3600 * 24 * $journal->daysopen);
} else {
$journal->timefinish = 9999999999;
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>";
}
$entry = get_record_sql("SELECT * FROM journal_entries
WHERE user='$user->id' AND journal='$journal->id'");
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>";
}
echo "</TD></TR>";
}
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 "<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>";
}
?>