}
require_login($course->id);
-
- add_to_log("Edit week", $course->id);
if (!isteacher($course->id)) {
error("Only teachers can edit this!");
if (! set_field("course_weeks", "summary", $summary, "id", $week->id)) {
error("Could not update the summary!");
}
+
+ add_to_log($course->id, "course", "editweek", "editweek.php?id=$week->id", "$week->week");
redirect("view.php?id=$course->id");
exit;
$link = "$CFG->wwwroot/course/view.php?id=$course->id";
+ //XXXX The following function is now wrong - needs fixing
+ //if (! email_to_course($USER, $course, true, $subject, $message, "$link")) {
+ // error("An error occurred while trying to send mail!");
+ //}
- if (! email_to_course($USER, $course, true, $subject, $message, "$link")) {
- error("An error occurred while trying to send mail!");
- }
-
- add_to_log("Sent mail to everyone", $course->id);
+ add_to_log($course->id, "course", "email", "email.php?id=$course->id", "");
redirect("view.php?id=$course->id", "Email sent", 1);
exit;
echo "</CENTER>";
}
+function make_log_url($module, $url) {
+ switch ($module) {
+ case "course":
+ case "user":
+ case "file":
+ case "login":
+ case "lib":
+ case "admin":
+ return "/$module/$url";
+ break;
+ default:
+ return "/mod/$module/$url";
+ break;
+ }
+}
+
+
function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
$selector = "WHERE l.course='$course->id' AND l.user = u.id";
}
if (!$logs = get_records_sql("SELECT l.*, u.firstname, u.lastname, u.picture
- FROM logs l, user u $selector $order")){
+ FROM log l, user u $selector $order")){
notify("No logs found!");
print_footer($course);
exit;
echo "<P ALIGN=CENTER>Displaying ".count($logs)." records</P>";
echo "<TABLE BORDER=0 ALIGN=center CELLPADDING=3 CELLSPACING=3>";
foreach ($logs as $log) {
- $count++;
-
+
+ if ($ld = get_record_sql("SELECT * FROM log_display WHERE module='$log->module' AND action='$log->action'")) {
+ $log->info = get_field($ld->table, $ld->field, "id", $log->info);
+ }
+
echo "<TR>";
echo "<TD ALIGN=right><FONT SIZE=2>".date("l", $log->time)."</TD>";
echo "<TD><FONT SIZE=2>".date("j M Y, h:i A", $log->time)."</TD>";
echo "<TD><FONT SIZE=2><B>$log->firstname $log->lastname</B></TD>";
echo "<TD><FONT SIZE=2>";
- $log->message = addslashes($log->message);
- link_to_popup_window("$log->url","popup","$log->message", 400, 600);
+ link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600);
echo "</TD>";
+ echo "<TD><FONT SIZE=2>$log->info</TD>";
echo "</TR>";
}
echo "</TABLE>";
print_simple_box_end();
}
+function print_headline($text, $size=2) {
+ echo "<B><FONT SIZE=\"$size\">$text</FONT></B><BR>\n";
+}
+
+function print_recent_activity($course) {
+ // $course is an object
+ // This function trawls through the logs looking for
+ // anything new since the user's last login
+
+ global $CFG, $USER;
+
+ if (! $USER->lastlogin ) {
+ echo "<P>Welcome to the course! Here you will find a list of what's new since your last login.</P>";
+ return;
+ }
+
+ if (! $logs = get_records_sql("SELECT * FROM log WHERE time > '$USER->lastlogin' AND course = '$course->id' ORDER BY time ASC")) {
+ return;
+ }
+
+
+ // Firstly, have there been any new enrolments?
+
+ $heading = false;
+ $content = false;
+ foreach ($logs as $log) {
+ if ($log->module == "course" and $log->action == "enrol") {
+ if (! $heading) {
+ print_headline("New users");
+ $heading = true;
+ $content = true;
+ }
+ $user = get_record("user", "id", $log->info);
+ echo "<LI><FONT SIZE=1><A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A></FONT></LI>";
+ }
+ }
+
+ // Next, have there been any changes to the course structure?
+
+ if ($heading) {
+ echo "<BR>";
+ $heading = false;
+ }
+ foreach ($logs as $log) {
+ if ($log->module == "course") {
+ if ($log->action == "add mod" or $log->action == "update mod" or $log->action == "delete mod") {
+ if (! $heading) {
+ print_headline("Changes");
+ $heading = true;
+ $content = true;
+ }
+ $info = split(" ", $log->info);
+ $modname = get_field($info[0], "name", "id", $info[1]);
+
+ if ($info[0] == "discuss") {
+ $info[0] == "discussion"; // nasty hack, really.
+ }
+
+ echo "<LI><FONT SIZE=1>";
+ switch ($log->action) {
+ case "add mod":
+ echo "Added a ".$info[0].": $modname";
+ break;
+ case "update mod":
+ echo "Updated the ".$info[0].": <A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>";
+ break;
+ case "delete mod":
+ echo "Deleted a ".$info[0];
+ break;
+ }
+ echo "</FONT></LI>";
+ }
+ }
+ }
+
+
+ // Now all we need to know are the new posts.
+
+ if ($heading) {
+ echo "<BR>";
+ $heading = false;
+ $content = true;
+ }
+ foreach ($logs as $log) {
+
+ if ($log->module == "discuss") {
+ $post = NULL;
+
+ if ($log->action == "add post") {
+ $post = get_record_sql("SELECT p.*, u.firstname, u.lastname,
+ u.email, u.picture, u.id as userid
+ FROM discuss_posts p, user u
+ WHERE p.id = '$log->info' AND p.user = u.id");
+
+ } else if ($log->action == "add") {
+ $post = get_record_sql("SELECT p.*, u.firstname, u.lastname,
+ u.email, u.picture, u.id as userid
+ FROM discuss d, discuss_posts p, user u
+ WHERE d.id = '$log->info' AND d.firstpost = p.id AND p.user = u.id");
+ }
+
+ if ($post) {
+ if (! $heading) {
+ print_headline("Discussion Posts");
+ $heading = true;
+ $content = true;
+ }
+ if ($log->action == "add") {
+ echo "<LI><FONT SIZE=1>\"<A HREF=\"$CFG->wwwroot/mod/discuss/$log->url\"><B>$post->subject</B></A>\" by $post->firstname $post->lastname</FONT></LI>";
+ } else {
+ echo "<LI><FONT SIZE=1>\"<A HREF=\"$CFG->wwwroot/mod/discuss/$log->url\">$post->subject</A>\" by $post->firstname $post->lastname</FONT></LI>";
+ }
+ }
+
+ }
+ }
+
+ if (! $content) {
+ echo "<FONT SIZE=2>Nothing new since your last login</FONT>";
+ }
+
+}
+
?>
require_login();
require_variable($id);
+ if (! $course = get_record("course", "id", $id) ) {
+ error("That's an invalid course id");
+ }
if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
- $actual_password = get_field("course", "password", "id", $id);
-
- if ($password == $actual_password) {
+ if ($password == $course->password) {
- enrol_student_in_course($USER->id, $id);
- add_to_log("Enrolled in course", $id);
+ if (! enrol_student_in_course($USER->id, $course->id)) {
+ error("An error occurred while trying to enrol you.");
+ }
+ add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
$USER->student["$id"] = true;
}
}
- if (! $course = get_record("course", "id", $id) ) {
- error("That's an invalid course id");
- }
if (! $site = get_record("course", "category", "0") ) {
error("Could not find a site!");
error("An error occurred while trying to enrol you.");
}
- add_to_log("Enrolled in course", $id);
+ add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
$USER->student["$id"] = true;
$student_name = "$USER->firstname $USER->lastname";
- add_to_log("$teacher_name logged in as $student_name", $course->id);
+ add_to_log($course->id, "course", "loginas", "loginas.php?id=$course->id&user=$user", "$teacher_name");
notice("You are now logged in as $student_name", "$CFG->wwwroot/course/view.php?id=$course->id");
- die;
-
?>
require_login($course->id);
- add_to_log("View Whats New", $course->id);
+ add_to_log($course->id, "course", "view new", "new.php?id=$course->id", "");
print_header("$course->shortname: What's new", "$course->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> What's new");
print_simple_box("Readings", $align="CENTER", $width="100%", $color="$THEME->cellheading");
if ($readings = list_all_readings($course->id, "timemodified ASC", 0, true)) {
- foreach ($readings as $reading) {
- $readingdata[] = $reading;
- $readingicon[] = "<IMG SRC=\"../mod/reading/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Reading\">";
- }
- if ($USER->editing) {
- $readingdata[] = "<A HREF=\"mod.php?id=$course->id&week=0&add=reading\">Add reading...</A>";
- $readingicon[] = " ";
- }
+ foreach ($readings as $reading) {
+ $readingdata[] = $reading;
+ $readingicon[] = "<IMG SRC=\"../mod/reading/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Reading\">";
+ }
+ }
+ if ($USER->editing) {
+ $readingdata[] = "<A HREF=\"mod.php?id=$course->id&week=0&add=reading\">Add reading...</A>";
+ $readingicon[] = " ";
}
print_side_block("", $readingdata, "", $readingicon);
- if (isteacher($USER->id)) {
+ // Print all the recent activity
+ print_simple_box("Recent Activity", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+ echo "<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
+ print_recent_activity($course);
+ echo "</TD></TR></TABLE>";
+
+ // Print Admin links for teachers and admin.
+ if (isteacher($USER->id) || isadmin()) {
print_simple_box("Admin", $align="CENTER", $width="100%", $color="$THEME->cellheading");
$adminicon[]="<IMG SRC=\"../pix/i/edit.gif\" HEIGHT=16 WIDTH=16 ALT=\"Edit\">";
if ($USER->editing) {
error("User ID is incorrect");
}
- add_to_log("View total report of $user->firstname $user->lastname", $course->id);
+ add_to_log($course->id, "course", "user record", "user.php?id=$course->id&user=$user->id", "$user->id");
print_header("$course->shortname: Report", "$course->fullname",
"<A HREF=\"../course/view.php?id=$course->id\">$course->shortname</A> ->
<A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> ->
Full Report", "");
- if ($mods = get_records_sql("SELECT * FROM modules ORDER BY fullname")) {
- foreach ($mods as $mod) {
- $userfile = "$CFG->dirroot/mod/$mod->name/user.php";
- if (file_exists($userfile)) {
- echo "<H2>".$mod->fullname."s</H2>";
- echo "<BLOCKQUOTE>";
- include($userfile);
- echo "</BLOCKQUOTE>";
- echo "<HR WIDTH=100%>";
+ 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;
+ }
+ }
+
+
+ // Replace all the following with a better log-based method.
+ if ($course->format == 1) {
+ if ($weeks = get_records_sql("SELECT * FROM course_weeks WHERE course = '$course->id' ORDER BY week")) {
+ foreach ($weeks as $www) {
+ $week = (object)$www;
+ echo "<H2>Week $week->week</H2>";
+ if ($week->sequence) {
+ $weekmods = explode(",", $week->sequence);
+ foreach ($weekmods as $weekmod) {
+ $mod = $mods[$weekmod];
+ $instance = get_record("$mod->modname", "id", "$mod->instance");
+ $userfile = "$CFG->dirroot/mod/$mod->name/user.php";
+ include($userfile);
+ }
+
+ } else {
+ echo "<P>No modules</P>";
+ }
}
}
+ } else {
+ echo "<P>Not implemented yet</P>";
}
print_footer($course);
error("That's an invalid course id");
}
- add_to_log("View course: $course->shortname", $id);
+ add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
if ( isteacher($course->id) ) {
if ($edit == "on") {
<?PHP // $Id$
+ // Display the whole course as "weeks" made of of modules
+ // Included from "view.php"
-// Display the whole course as "weeks" made of of modules
-// Included from "view.php"
+ include("../mod/discuss/lib.php");
if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
$week->course = $course->id; // Create a default week.
$weeks[$cw->week] = $cw;
}
+ if (isset($week)) {
+ if ($week == "all") {
+ unset($USER->week);
+ } else {
+ $USER->week = $week;
+ }
+ }
+
+
+
// Layout the whole page as three big columns.
- echo "<TABLE BORDER=0 CELLPADDING=4>";
+ echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
echo "<TR VALIGN=top><TD VALIGN=top WIDTH=180>";
- echo "<IMG ALT=\"\" SRC=\"../pix/spacer.gif\" WIDTH=180 HEIGHT=1><BR>";
// Layout the left column
$moddata[]="<A HREF=\"../user/view.php?id=$USER->id&course=$course->id\">Edit my info</A>";
$modicon[]="<IMG SRC=\"../user/user.gif\" HEIGHT=16 WIDTH=16 ALT=\"Me\">";
- print_side_block("Activities", $moddata, "", $modicon);
+ print_simple_box("Activities", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+ print_side_block("", $moddata, "", $modicon);
// Admin links and controls
$admindata[]="<A HREF=\"../files/index.php?id=$course->id\">Files...</A>";
$adminicon[]="<IMG SRC=\"../files/pix/files.gif\" HEIGHT=16 WIDTH=16 ALT=\"Files\">";
- print_side_block("Administration", $admindata, "", $adminicon);
+ print_simple_box("Administration", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+ print_side_block("", $admindata, "", $adminicon);
}
// Start main column
echo "</TD><TD WIDTH=\"*\">";
- echo "<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=0><TR><TD>";
- echo "<P><IMG ALT=\"\" SRC=\"../pix/spacer.gif\" WIDTH=100% HEIGHT=3><BR>";
- echo "<B><FONT SIZE=2>Weekly Outline</FONT></B>\n";
+ print_simple_box("Weekly Outline", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+ echo "<IMG SRC=\"../pix/spacer.gif\" HEIGHT=6 WIDTH=1><BR>";
- echo "</FONT>";
- echo "</TD></TR></TABLE>";
-
// Now all the weekly modules
$timenow = time();
$weekdate = $course->startdate; // this should be 0:00 Monday of that week
echo "<TABLE BORDER=0 CELLPADDING=8 CELLSPACING=0 WIDTH=100%>";
while ($weekdate < $course->enddate) {
- echo "<TR>";
$nextweekdate = $weekdate + ($weekofseconds);
+
+ if (isset($USER->week)) { // Just display a single week
+ if ($USER->week != $week) {
+ $week++;
+ $weekdate = $nextweekdate;
+ continue;
+ }
+ }
+
$thisweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
$weekday = date("j F", $weekdate);
$highlightcolor = $THEME->cellheading;
}
+ echo "<TR>";
echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top>";
echo "<P ALIGN=CENTER><FONT SIZE=3><B>$week</B></FONT></P>";
echo "</TD>";
}
echo "</TD>";
- echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top> </TD>";
+ echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top ALIGN=CENTER>";
+ echo "<FONT SIZE=1>";
+ if (isset($USER->week)) {
+ echo "<A HREF=\"view.php?id=$course->id&week=all\" TITLE=\"Show all weeks\"><IMG SRC=../pix/i/allweeks.gif BORDER=0></A></FONT>";
+ } else {
+ echo "<A HREF=\"view.php?id=$course->id&week=$week\" TITLE=\"Show only week $week\"><IMG SRC=../pix/i/oneweek.gif BORDER=0></A></FONT>";
+ }
+ echo "</TD>";
echo "</TR>";
- echo "<TR><TD COLSPAN=3><IMG ALT=\"\" SRC=\"../pix/spacer.gif\" WIDTH=1 HEIGHT=1></TD></TR>";
+ echo "<TR><TD COLSPAN=3><IMG SRC=\"../pix/spacer.gif\" WIDTH=1 HEIGHT=1></TD></TR>";
$week++;
$weekdate = $nextweekdate;
echo "</TD><TD WIDTH=180>";
- // Print What's New
-
- print_side_block("<A HREF=\"new.php?id=$course->id\">What's New!</A>",
- "", "<FONT SIZE=1>...since your last login</FONT>");
-
- // Then, print all the news items.
+ // Print all the news items.
- include("../mod/discuss/lib.php");
if ($news = get_course_news_forum($course->id)) {
- echo "<P><B><FONT SIZE=2>Latest News</FONT></B><BR>";
- print_simple_box_start("CENTER", "100%", "#FFFFFF", 3);
+ print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+ print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
echo "<FONT SIZE=1>";
forum_latest_topics($news->id, 5, "minimal", "DESC", false);
echo "</FONT>";
print_simple_box_end();
}
+ echo "<BR>";
+
+ // Print all the recent activity
+ print_simple_box("Recent Activity", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+ print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
+ print_recent_activity($course);
+ print_simple_box_end();
echo "</TD></TR></TABLE>\n";