changes to function print_recent_selector_form for normal/advanced filters in course/recent.php

This commit is contained in:
selliott
2004-02-20 21:38:42 +00:00
parent 08e2111bf8
commit 587510bec5
+192 -155
View File
@@ -20,178 +20,215 @@ define("FRONTPAGENEWS", 0);
define("FRONTPAGECOURSELIST", 1);
define("FRONTPAGECATEGORYNAMES", 2);
function print_recent_selector_form($course, $selecteduser=0, $selecteddate="lastlogin",
function print_recent_selector_form($course, $advancedfilter=0, $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 ($advancedfilter) {
// 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) {
if ($cc->category) {
$courses["$cc->id"] = "$cc->fullname";
} else {
$courses["$cc->id"] = " $cc->fullname (Site)";
}
}
}
asort($courses);
}
$activities = array();
$selectedactivity = $modid;
if ($modinfo = unserialize($course->modinfo)) {
$section = 0;
if ($course->format == 'weeks') { // Body
$strsection = get_string("week");
if ($course->category) {
$courseusers = get_course_users($course->id);
} 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 --------------";
}
$section = $mod->section;
$mod->name = urldecode($mod->name);
if (strlen($mod->name) > 55) {
$mod->name = substr($mod->name, 0, 50)."...";
}
if (!$mod->visible) {
$mod->name = "(".$mod->name.")";
}
$activities["$mod->cm"] = $mod->name;
if ($mod->cm == $modid) {
$selectedactivity = "$mod->cm";
$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) {
if ($cc->category) {
$courses["$cc->id"] = "$cc->fullname";
} else {
$courses["$cc->id"] = " $cc->fullname (Site)";
}
}
}
asort($courses);
}
$strftimedate = get_string("strftimedate");
$strftimedaydate = get_string("strftimedaydate");
$activities = array();
asort($users);
$selectedactivity = $modid;
// Get all the possible dates
// Note that we are keeping track of real (GMT) time and user time
// User time is only used in displays - all calcs and passing is GMT
$timenow = time(); // GMT
// What day is it now for the user, and when is midnight that day (in GMT).
$timemidnight = $today = usergetmidnight($timenow);
$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 = 1;
while ($timemidnight > $course->startdate and $numdates < 365) {
$timemidnight = $timemidnight - 86400;
$timenow = $timenow - 86400;
$dates["$timemidnight"] = userdate($timenow, $strftimedaydate);
$numdates++;
}
if ($selecteddate == "lastlogin") {
$selecteddate = $USER->lastlogin;
}
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"));
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');
if ($modinfo = unserialize($course->modinfo)) {
$section = 0;
if ($course->format == 'weeks') { // Body
$strsection = get_string("week");
} else {
print_string('groupsseparate');
$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 --------------";
}
$section = $mod->section;
$mod->name = urldecode($mod->name);
if (strlen($mod->name) > 55) {
$mod->name = substr($mod->name, 0, 50)."...";
}
if (!$mod->visible) {
$mod->name = "(".$mod->name.")";
}
$activities["$mod->cm"] = $mod->name;
if ($mod->cm == $modid) {
$selectedactivity = "$mod->cm";
}
}
echo ':</b></td><td>';
choose_from_menu($groups, "selectedgroup", $selectedgroup, get_string("allgroups"), "", "");
echo '</td>';
}
$strftimedate = get_string("strftimedate");
$strftimedaydate = get_string("strftimedaydate");
asort($users);
// Get all the possible dates
// Note that we are keeping track of real (GMT) time and user time
// User time is only used in displays - all calcs and passing is GMT
$timenow = time(); // GMT
// What day is it now for the user, and when is midnight that day (in GMT).
$timemidnight = $today = usergetmidnight($timenow);
$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 = 1;
while ($timemidnight > $course->startdate and $numdates < 365) {
$timemidnight = $timemidnight - 86400;
$timenow = $timenow - 86400;
$dates["$timemidnight"] = userdate($timenow, $strftimedaydate);
$numdates++;
}
if ($selecteddate == "lastlogin") {
$selecteddate = $USER->lastlogin;
}
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"));
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 "</td></tr>";
echo "</table>";
$advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&advancedfilter=0\">" . get_string("normalfilter") . "</a>";
print_heading($advancedlink);
echo "</center>";
echo "</form>";
} else {
$day_list = array("1","7","14","21","30");
$strsince = get_string("since");
$strlastlogin = get_string("lastlogin");
$strday = get_string("day");
$strdays = get_string("days");
$heading = "";
foreach ($day_list as $count) {
if ($count == "1") {
$day = $strday;
} else {
$day = $strdays;
}
$selecteddate = time() - ($count * 3600 * 24);
$heading = $heading .
"<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&date=$selecteddate\"> $count $day</a> | ";
}
$heading = $strsince . ": <a href=\"$CFG->wwwroot/course/recent.php?id=$course->id\">$strlastlogin</a>" . " | " . $heading;
print_heading($heading);
print_heading(get_string("activitysince", "", userdate($selecteddate)));
$advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&advancedfilter=1\">" . get_string("advancedfilter") . "</a>";
print_heading($advancedlink);
}
echo "<td colspan='2' align='right'>";
echo "<input type=submit value=\"".get_string("showrecent")."\">";
echo "</td></tr>";
echo "</table>";
echo "</center>";
echo "</form>";
}
function print_log_selector_form($course, $selecteduser=0, $selecteddate="today",