define("FRONTPAGECOURSELIST", 1);
define("FRONTPAGECATEGORYNAMES", 2);
-function print_recent_selector_form($course, $selecteduser=0, $selecteddate="today",
- $mod="", $modid=0, $modaction="") {
+function print_recent_selector_form($course, $selecteduser=0, $selecteddate="lastlogin",
+ $mod="", $modid="activity/All", $modaction="", $selectedgroup="", $selectedsort="default") {
global $USER, $CFG;
-
$isteacher = isteacher($course->id);
// Get all the possible users
$users = array();
-
+
if ($course->category) {
$courseusers = get_course_users($course->id);
} else {
$courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname");
- }
-
+ }
+
if ($courseusers) {
foreach ($courseusers as $courseuser) {
$users[$courseuser->id] = fullname($courseuser, $isteacher);
}
- }
+ }
if ($guest = get_guest()) {
$users[$guest->id] = fullname($guest);
}
-
+
if (isadmin()) {
if ($ccc = get_records("course", "", "", "fullname")) {
foreach ($ccc as $cc) {
$courses["$cc->id"] = "$cc->fullname";
} else {
$courses["$cc->id"] = " $cc->fullname (Site)";
- }
+ }
}
- }
+ }
asort($courses);
}
$activities = array();
- $selectedactivity = "";
+
+ $selectedactivity = $modid;
if ($modinfo = unserialize($course->modinfo)) {
$section = 0;
- if ($course->format == 'weeks') { // Bodgy
+ if ($course->format == 'weeks') { // Body
$strsection = get_string("week");
} else {
$strsection = get_string("topic");
}
+
+ $activities["activity/All"] = "All activities";
+ $activities["activity/Assignments"] = "All assignments";
+ $activities["activity/Chats"] = "All chats";
+ $activities["activity/Forums"] = "All forums";
+ $activities["activity/Quizzes"] = "All quizzes";
+ $activities["activity/Workshops"] = "All workshops";
+
+ $activities["section/individual"] = "------------- Individual Activities --------------";
+
foreach ($modinfo as $mod) {
if ($mod->mod == "label") {
continue;
- }
+ }
if ($mod->section > 0 and $section <> $mod->section) {
$activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------";
}
// What day is it now for the user, and when is midnight that day (in GMT).
$timemidnight = $today = usergetmidnight($timenow);
- // Put today up the top of the list
- $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) );
+ $dates = array();
+ $dates["$USER->lastlogin"] = get_string("lastlogin").", ".userdate($USER->lastlogin, $strftimedate);
+ $dates["$timemidnight"] = get_string("today").", ".userdate($timenow, $strftimedate);
if (!$course->startdate or ($course->startdate > $timenow)) {
$course->startdate = $course->timecreated;
$numdates++;
}
- if ($selecteddate == "today") {
- $selecteddate = $today;
+ if ($selecteddate == "lastlogin") {
+ $selecteddate = $USER->lastlogin;
}
- echo '<center>';
echo '<form action="recent.php" method="get">';
echo '<input type=hidden name=chooserecent value="1">';
+ echo "<center>";
+ echo "<table>";
+
if (isadmin()) {
+ echo "<tr><td><b>" . get_string("courses") . "</b></td><td>";
choose_from_menu ($courses, "id", $course->id, "");
+ echo "</td></tr>";
} else {
echo "<input type=hidden name=id value=\"$course->id\">";
}
+
+ $sortfields = array("default" => "By course order","dateasc" => "Date - Most recent last", "datedesc" => "Date - Most recent first");
+
+ echo "<tr><td><b>" . get_string("participants") . "</b></td><td>";
choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") );
+ echo "</td>";
+
+ echo "<td align='right'><b>" . get_string("since") . "</b></td><td>";
choose_from_menu ($dates, "date", $selecteddate, get_string("alldays"));
- choose_from_menu ($activities, "modid", $selectedactivity, get_string("allactivities"), "", "");
+ echo "</td></tr>";
+
+ echo "<tr><td><b>" . get_string("activities") . "</b></td><td>";
+ choose_from_menu ($activities, "modid", $selectedactivity, "");
+ echo "</td>";
+
+ echo "<td align='right'><b>" . get_string("sortby") . "</b></td><td>";
+ choose_from_menu ($sortfields, "sortby", $selectedsort, "");
+ echo "</td></tr>";
+
+ echo '<tr>';
+
+ $groupmode = groupmode($course);
+
+ if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+ if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
+ echo '<td><b>';
+ if ($groupmode == VISIBLEGROUPS) {
+ print_string('groupsvisible');
+ } else {
+ print_string('groupsseparate');
+ }
+ echo ':</b></td><td>';
+ choose_from_menu($groups, "selectedgroup", $selectedgroup, get_string("allgroups"), "", "");
+ echo '</td>';
+ }
+ }
+
+
+ echo "<td colspan='2' align='right'>";
echo "<input type=submit value=\"".get_string("showrecent")."\">";
- echo "</form>";
+ echo "</td></tr>";
+
+ echo "</table>";
echo "</center>";
+ echo "</form>";
}
function print_log_selector_form($course, $selecteduser=0, $selecteddate="today",
}
print_heading("$course->fullname: $userinfo, $dateinfo (".usertimezone().")");
- print_recent_selector_form($course, $user, $date, $modname, $modid, $modaction);
+ print_recent_selector_form($course, $user, $date, $modname, $modid, $modaction, $selectedgroup, $sortby);
} else {
}
- get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
+ $tmpmodid = $modid;
- $sections = get_all_sections($course->id);
+ switch ($tmpmodid) {
+ case "activity/Assignments" : $filter = "assignment"; break;
+ case "activity/Chats" : $filter = "chat"; break;
+ case "activity/Forums" : $filter = "forum"; break;
+ case "activity/Quizzes" : $filter = "quiz"; break;
+ case "activity/Workshops" : $filter = "workshop"; break;
+ default : $filter = "";
+ }
- for ($i=0; $i<=$course->numsections; $i++) {
+ if (!empty($filter)) {
+ $activityfilter = "AND m.name = '$filter'";
+ } else {
+ $activityfilter = "";
+ }
- if (isset($sections[$i]) && $sections[$i]->visible) {
+ $activities = array();
+ $sections = array();
- $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>";
+ $index = 0;
- echo "<ul>";
+ if (is_numeric($modid)) { // you chose a single activity
- $sectionmods = explode(",", $section->sequence);
+ $sections[0]->sequence = "$modid";
- foreach ($sectionmods as $sectionmod) {
- if (empty($mods[$sectionmod])) {
- continue;
- }
- $mod = $mods[$sectionmod];
-
- $instance = get_record("$mod->modname", "id", "$mod->instance");
- $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
-
- if (file_exists($libfile)) {
- require_once($libfile);
- $print_recent_instance_activity = $mod->modname."_print_recent_instance_activity";
-
- // fix modid if a section (or week) is selected, may want to enhance to get all mods from section (or week)
- if (!is_numeric($modid))
- $modid = "";
-
- if (function_exists($print_recent_instance_activity) && (($mod->id == $modid) || (empty($modid)))) {
- $image = "<img src=\"$CFG->modpixpath/$mod->modname/icon.gif\" ".
- "height=16 width=16 alt=\"$mod->modfullname\">";
- echo "<h4>$image $mod->modfullname: ".
- "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
- "$instance->name</a></h4>";
- echo "<ul>";
- $print_recent_instance_activity($instance, $date, $user);
- echo "</ul>";
- }
+ } else { // you chose a group of activities
+
+ $sections = get_records_sql("SELECT cs.id, cs.section, cs.sequence
+ FROM {$CFG->prefix}course_sections cs
+ WHERE course = '$course->id'
+ AND cs.visible = '1'
+ AND sequence != ''
+ ORDER by section");
+ }
+
+ if (!empty($sections)) {
+
+ echo "<hr>";
+
+ foreach ($sections as $section) {
+ $sectionmods = explode(",", $section->sequence);
+
+ foreach ($sectionmods as $sectionmod) {
+ $coursemod = get_record_sql("SELECT m.id, m.name, cm.groupmode
+ FROM {$CFG->prefix}course_modules cm,
+ {$CFG->prefix}modules m
+ WHERE course = '$course->id'
+ AND m.id = cm.module $activityfilter
+ AND cm.id = '$sectionmod'");
+
+ $groupmode = groupmode($course, $coursemod);
+ switch ($groupmode) {
+ case SEPARATEGROUPS : $groupid = mygroupid($course->id); break;
+ case VISIBLEGROUPS :
+ if ($selectedgroup == "allgroups") {
+ $groupid == "";
+ } else {
+ $groupid = $selectedgroup;
+ }
+ break;
+ case NOGROUPS :
+ default : $groupid = "";
+ }
+
+ $libfile = "$CFG->dirroot/mod/$coursemod->name/lib.php";
+
+ if (file_exists($libfile)) {
+ require_once($libfile);
+ $get_recent_mod_activity = $coursemod->name."_get_recent_mod_activity";
+
+ if (function_exists($get_recent_mod_activity)) {
+ $get_recent_mod_activity($activities, $index, $date, $course->id, $sectionmod, $user, $groupid);
}
}
+ }
+ }
+ }
+
+ $detail = true;
+
+ switch ($sortby) {
+ case "datedesc" : usort($activities, "compare_activities_by_time_desc"); break;
+ case "dateasc" : usort($activities, "compare_activities_by_time_asc"); break;
+ case "default" :
+ default : $detail = false; $sortby = "default";
+
+ }
+
+ if (!empty($activities)) {
+
+ echo "<ul>";
+ $newsection = true;
+ $lastsection = "";
+ $newinstance = true;
+ $lastinstance = "";
+
+ switch ($course->format) {
+ case "weeks": $sectiontitle = get_string("week"); break;
+ case "topics": $sectiontitle = get_string("topic"); break;
+ default: $sectiontitle = get_string("section"); break;
+ }
+
+ echo "<hr>";
+ foreach ($activities as $activity) {
+
+ if ($sortby == "default") {
+ if ($lastsection != $activity->section) {
+ $lastsection = $activity->section;
+ $newsection = true;
+ }
+ if ($newsection) {
+// echo "<h2>$sectiontitle: $activity->section</h2>";
+ $newsection = false;
+ }
+ if ($lastinstance != $activity->instance) {
+ $lastinstance = $activity->instance;
+ $newinstance = true;
+ }
+ if ($newinstance) {
+ $image = "<img src=\"$CFG->modpixpath/$activity->type/icon.gif\" ".
+ "height=16 width=16 alt=\"$activity->type\">";
+ echo "<h4>$image " . $activity->name . "</h4>";
+
+ $newinstance = false;
+ }
+
+ }
+
+ $print_recent_mod_activity = $activity->type."_print_recent_mod_activity";
+
+ if (function_exists($print_recent_mod_activity)) {
+ echo "<ul>";
+ $print_recent_mod_activity($activity, $course->id, $detail);
echo "</ul>";
}
}
+ echo "</ul>";
+ } else {
+ echo "<h4><center>" . get_string("norecentactivity") . "</center></h2>";
}
+// fix modid for selection form
+ $modid =$tmpmodid;
+
print_footer($course);
+function compare_activities_by_time_desc($a, $b) {
+ if ($a->timestamp == $b->timestamp)
+ return 0;
+ return ($a->timestamp > $b->timestamp) ? -1 : 1;
+}
+
+function compare_activities_by_time_asc($a, $b) {
+ if ($a->timestamp == $b->timestamp)
+ return 0;
+ return ($a->timestamp < $b->timestamp) ? -1 : 1;
+}
?>