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) { if ($cc->category) { $courses["$cc->id"] = "$cc->fullname"; } else { $courses["$cc->id"] = " $cc->fullname (Site)"; } } } asort($courses); } $activities = array(); $selectedactivity = ""; if ($modinfo = unserialize($course->modinfo)) { $section = 0; if ($course->format == 'weeks') { // Bodgy $strsection = get_string("week"); } else { $strsection = get_string("topic"); } 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"; } } } $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); // Put today up the top of the list $dates = array("$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 == "today") { $selecteddate = $today; } echo '
"; print_string("displayingrecords", "", $totalcount); echo "
"; print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&"); echo "course\">".$courses[$log->course]." | "; } echo "".userdate($log->time, "%a")." | "; echo "".userdate($log->time, $strftimedatetime)." | "; echo ""; link_to_popup_window("/lib/ipatlas/plot.php?address=$log->ip&user=$log->userid", "ipatlas","$log->ip", 400, 700); echo " | "; $fullname = fullname($log, $isteacher); echo "userid&course=$log->course\">$fullname | "; echo ""; link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600); echo " | "; echo "$log->info | "; echo "
"; print_string("welcometocourse", "", $course->shortname); echo "
"; return; } else { echo "";
echo get_string("yourlastlogin").":
";
echo userdate($USER->lastlogin, get_string("strftimerecentfull"));
echo "
";
foreach ($users as $user) {
if (! $heading) {
print_headline(get_string("newusers").":");
$heading = true;
$content = true;
}
$fullname = fullname($user, $isteacher);
echo "id&course=$course->id\">$fullname
";
}
echo "
".$change["text"]."
"; } } } } // If this site uses Library module, then print recent items if (!empty($CFG->librarypath)) { if (file_exists("$CFG->dirroot/$CFG->librarypath/librarylib.php")) { include_once("$CFG->dirroot/$CFG->librarypath/librarylib.php"); if (librarysummarize(5, '', date('YmdHis',$USER->lastlogin))) { $content = true; } } } // Now display new things from each module $mods = get_records("modules", "visible", "1", "name", "id, name"); foreach ($mods as $mod) { // Each module gets it's own logs and prints them include_once("$CFG->dirroot/mod/$mod->name/lib.php"); $print_recent_activity = $mod->name."_print_recent_activity"; if (function_exists($print_recent_activity)) { $modcontent = $print_recent_activity($course, $isteacher, $timestart); if ($modcontent) { $content = true; } } } if (! $content) { echo "".get_string("nothingnew").""; } } function get_array_of_activities($courseid) { // For a given course, returns an array of course activity objects // Each item in the array contains he following properties: // cm - course module id // mod - name of the module (eg forum) // section - the number of the section (eg week or topic) // name - the name of the instance // visible - is the instance visible or not // extra - contains extra string to include in any link global $CFG; $mod = array(); if (!$rawmods = get_course_mods($courseid)) { return NULL; } if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) { foreach ($sections as $section) { if (!empty($section->sequence)) { $sequence = explode(",", $section->sequence); foreach ($sequence as $seq) { if (empty($rawmods[$seq])) { continue; } $mod[$seq]->cm = $rawmods[$seq]->id; $mod[$seq]->mod = $rawmods[$seq]->modname; $mod[$seq]->section = $section->section; $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); $mod[$seq]->visible = $rawmods[$seq]->visible; $mod[$seq]->extra = ""; $modname = $mod[$seq]->mod; $functionname = $modname."_get_coursemodule_info"; include_once("$CFG->dirroot/mod/$modname/lib.php"); if (function_exists($functionname)) { if ($extra = $functionname($rawmods[$seq])) { $mod[$seq]->extra = $extra; } } } } } } return $mod; } function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { // Returns a number of useful structures for course displays $mods = NULL; // course modules indexed by id $modnames = NULL; // all course module names $modnamesplural= NULL; // all course module names (plural form) $modnamesused = NULL; // course module names used if ($allmods = get_records("modules")) { foreach ($allmods as $mod) { if ($mod->visible) { $modnames[$mod->name] = get_string("modulename", "$mod->name"); $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name"); } } asort($modnames); } else { error("No modules are installed!"); } if ($rawmods = get_course_mods($courseid)) { foreach($rawmods as $mod) { // Index the mods $mods[$mod->id] = $mod; $mods[$mod->id]->modfullname = $modnames[$mod->modname]; if ($mod->visible or isteacher($courseid)) { $modnamesused[$mod->modname] = $modnames[$mod->modname]; } } if ($modnamesused) { asort($modnamesused); } } } function get_all_sections($courseid) { return get_records("course_sections", "course", "$courseid", "section", "section, id, course, summary, sequence, visible"); } function course_set_display($courseid, $display=0) { global $USER; if (empty($USER)) { return false; } if ($display == "all" or empty($display)) { $display = 0; } if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) { set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid); } else { $record->userid = $USER->id; $record->course = $courseid; $record->display = $display; if (!insert_record("course_display", $record)) { notify("Could not save your course display!"); } } return $USER->display[$courseid] = $display; // Note: = not == } function set_section_visible($courseid, $sectionnumber, $visibility) { /// For a given course section, markes it visible or hidden, /// and does the same for every activity in that section if ($section = get_record("course_sections", "course", $courseid, "section", $sectionnumber)) { set_field("course_sections", "visible", "$visibility", "id", $section->id); if (!empty($section->sequence)) { $modules = explode(",", $section->sequence); foreach ($modules as $moduleid) { set_field("course_modules", "visible", "$visibility", "id", $moduleid); } } rebuild_course_cache($courseid); } } function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused, $absolute=true, $width="100%") { global $CFG, $USER, $THEME; static $groupbuttons; static $isteacher; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strcancel; static $stractivityclipboard; if (!isset($isteacher)) { $groupbuttons = $course->groupmode and !$course->groupmodeforce; $isteacher = isteacher($course->id); $isediting = isediting($course->id); $ismoving = ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); $strcancel= get_string("cancel"); $stractivityclipboard = $USER->activitycopyname; } } $modinfo = unserialize($course->modinfo); $moddata = array(); $modicon = array(); $editbuttons = ""; if ($ismoving) { $modicon[] = " pixpath/t/move.gif\" height=\"11\" width=\"11\">"; $moddata[] = "$USER->activitycopyname (wwwroot/course/mod.php?cancelcopy=true\">$strcancel)"; } if (!empty($section->sequence)) { $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($isediting and !$ismoving) { if (!$groupbuttons) { $mod->groupmode = false; } $editbuttons = "modname\">";
if ($ismoving) {
if ($mod->id == $USER->activitycopy) {
continue;
}
echo "id\">".
"pixpath/movehere.gif\" ".
" alt=\"$strmovehere\" border=\"0\"> \n"; } $instancename = urldecode($modinfo[$modnumber]->name); if (!empty($modinfo[$modnumber]->extra)) { $extra = urldecode($modinfo[$modnumber]->extra); } else { $extra = ""; } if ($mod->indent) { print_spacer(12, 20 * $mod->indent, false); } if ($mod->modname == "label") { if (!$mod->visible) { echo ""; } echo format_text($extra, FORMAT_HTML); if (!$mod->visible) { echo ""; } } else { // Normal activity $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; echo "modpixpath/$mod->modname/icon.gif\"". " height=16 width=16 alt=\"$mod->modfullname\">". " modfullname\" $linkcss $extra". " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename"; } if ($isediting) { if (!$groupbuttons) { $mod->groupmode = false; } echo " "; echo make_editing_buttons($mod, $absolute, true, $mod->indent); } echo " | ";
echo "
id\">". "pixpath/movehere.gif\" ". " alt=\"$strmovehere\" border=\"0\"> |
cellheading\" class=\"$class\">"; echo stripslashes($heading); echo " |
".$icons[$key]." | "; } echo "$string | "; echo "
"; } echo " | $footer | "; echo "
cellheading\">$heading | "; echo "
cellcontent2\">"; } function print_side_block_end() { echo " |
wwwroot/$CFG->admin/\">".get_string("admin")."...";
}
print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width);
echo "wwwroot/pix/spacer.gif\" width=\"$width\" height=1>
";
}
function print_course_admin_links($course, $width=180) {
global $USER, $CFG, $THEME;
if (isguest()) {
return true;
}
if (isteacher($course->id)) {
$isteacheredit = isteacheredit($course->id);
if ($isteacheredit) {
$adminicon[]="pixpath/i/edit.gif\" height=16 width=16 alt=\"\">";
if (isediting($course->id)) {
$admindata[]="id&edit=off\">".get_string("turneditingoff")."";
} else {
$admindata[]="id&edit=on\">".get_string("turneditingon")."";
}
$admindata[]="id\">".get_string("settings")."...";
$adminicon[]="pixpath/i/settings.gif\" height=16 width=16 alt=\"\">";
if (iscreator() or !empty($CFG->teacherassignteachers)) {
if (!$course->teachers) {
$course->teachers = get_string("defaultcourseteachers");
}
$admindata[]="id\">$course->teachers...";
$adminicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
}
}
if (!$course->students) {
$course->students = get_string("defaultcoursestudents");
}
$admindata[]="id\">$course->students...";
$adminicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
if ($isteacheredit) {
$admindata[]="wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."...";
$adminicon[]="pixpath/i/backup.gif\" height=16 width=16 alt=\"\">";
$admindata[]="wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."...";
$adminicon[]="pixpath/i/restore.gif\" height=16 width=16 alt=\"\">";
$admindata[]="id\">".get_string("scales")."...";
$adminicon[]="pixpath/i/scales.gif\" height=16 width=16 alt=\"\">";
}
$admindata[]="id\">".get_string("grades")."...";
$adminicon[]="pixpath/i/grades.gif\" height=16 width=16 alt=\"\">";
$admindata[]="id\">".get_string("logs")."...";
$adminicon[]="pixpath/i/log.gif\" height=16 width=16 alt=\"\">";
if ($isteacheredit) {
$admindata[]="wwwroot/files/index.php?id=$course->id\">".get_string("files")."...";
$adminicon[]="pixpath/i/files.gif\" height=16 width=16 alt=\"\">";
}
$admindata[]="wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...";
$adminicon[]="modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">";
if ($teacherforum = forum_get_course_forum($course->id, "teacher")) {
$admindata[]="wwwroot/mod/forum/view.php?f=$teacherforum->id\">$teacherforum->name";
$adminicon[]="modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">";
}
} else if (!isguest()) { // Students menu
if ($course->showgrades) {
$admindata[]="id\">".get_string("grades")."...";
$adminicon[]="pixpath/i/grades.gif\" height=16 width=16 alt=\"\">";
}
if ($course->showreports) {
$admindata[]="id&user=$USER->id\">".get_string("activityreport")."...";
$adminicon[]="pixpath/i/report.gif\" height=16 width=16 alt=\"\">";
}
if (is_internal_auth()) {
$admindata[]="wwwroot/login/change_password.php?id=$course->id\">".
get_string("changepassword")."...";
$adminicon[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
} else if ($CFG->changepassword) {
$admindata[]="changepassword\">".get_string("changepassword")."...";
$adminicon[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
}
if ($CFG->allowunenroll) {
$admindata[]="id\">".get_string("unenrolme", "", $course->shortname)."...";
$adminicon[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
}
}
if (!empty($admindata)) {
print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width);
}
}
function make_categories_list(&$list, &$parents, $category=NULL, $path="") {
/// Given an empty array, this function recursively travels the
/// categories, building up a nice list for display. It also makes
/// an array that list all the parents for each category.
if ($category) {
if ($path) {
$path = "$path / $category->name";
} else {
$path = "$category->name";
}
$list[$category->id] = $path;
} else {
$category->id = 0;
}
if ($categories = get_categories("$category->id")) { // Print all the children recursively
foreach ($categories as $cat) {
if (!empty($category->id)) {
if (isset($parents[$category->id])) {
$parents[$cat->id] = $parents[$category->id];
}
$parents[$cat->id][] = $category->id;
}
make_categories_list($list, $parents, $cat, $path);
}
}
}
function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1) {
/// Recursive function to print out all the categories in a nice format
/// with or without courses included
if (!$displaylist) {
make_categories_list($displaylist, $parentslist);
}
if ($category) {
if ($category->visible or iscreator()) {
print_category_info($category, $depth);
} else {
return; // Don't bother printing children of invisible categories
}
} else {
$category->id = "0";
}
if ($categories = get_categories($category->id)) { // Print all the children recursively
$countcats = count($categories);
$count = 0;
$first = true;
$last = false;
foreach ($categories as $cat) {
$count++;
if ($count == $countcats) {
$last = true;
}
$up = $first ? false : true;
$down = $last ? false : true;
$first = false;
print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1);
}
}
}
function print_category_info($category, $depth) {
/// Prints the category info in indented fashion
/// This function is only used by print_whole_category_list() above
global $CFG;
static $strallowguests, $strrequireskey, $strsummary;
if (empty($strsummary)) {
$strallowguests = get_string("allowguests");
$strrequireskey = get_string("requireskey");
$strsummary = get_string("summary");
}
$catlinkcss = $category->visible ? "" : " class=\"dimmed\" ";
if ($CFG->frontpage == FRONTPAGECOURSELIST) {
$catimage = "pixpath/i/course.gif\" width=16 height=16 border=0>";
} else {
$catimage = " ";
}
echo "\n\n
"; print_spacer(10, $indent); echo " | "; } echo "$catimage | "; echo ""; echo "wwwroot/course/category.php?id=$category->id\">$category->name"; echo " | "; echo ""; echo " |
"; echo " | \n"; echo "wwwroot/course/view.php?id=$course->id\">$course->fullname"; echo " | \n"; if ($course->guest ) { echo "wwwroot/course/view.php?id=$course->id\">"; echo "pixpath/i/guest.gif\">"; } else { echo "pixpath/spacer.gif\">"; } if ($course->password) { echo "wwwroot/course/view.php?id=$course->id\">"; echo "pixpath/i/key.gif\">"; } else { echo "pixpath/spacer.gif\">"; } if ($course->summary) { link_to_popup_window ("/course/info.php?id=$course->id", "courseinfo", "pixpath/i/info.gif\">", 400, 500, $strsummary); } else { echo "pixpath/spacer.gif\">"; } echo " | "; print_spacer(10, $indent); echo " | "; } echo ""; echo "wwwroot/course/category.php?id=$category->id\">$category->name"; echo " | "; echo "$category->coursecount | "; } echo "\n
wwwroot/course/index.php\">".get_string("fulllistofcourses")."..."; print_side_block( get_string("mycourses"), "", $moddata, $modicon, $fulllist, $width); return; } } $categories = get_categories("0"); // Parent = 0 ie top-level categories only if (count($categories) > 1) { // Just print top level category links foreach ($categories as $category) { $linkcss = $category->visible ? "" : " class=\"dimmed\" "; $moddata[]="wwwroot/course/category.php?id=$category->id\">$category->name"; $modicon[]=$icon; } $fulllist = "
wwwroot/course/\">".get_string("searchcourses")."..."; } else { // Just print course names of single category $category = array_shift($categories); $courses = get_courses($category->id); if ($courses) { foreach ($courses as $course) { $linkcss = $course->visible ? "" : " class=\"dimmed\" "; $moddata[]="shortname\" ". "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname"; $modicon[]=$icon; } $fulllist = "
wwwroot/course/index.php\">".get_string("fulllistofcourses")."...";
} else {
$moddata = array();
$modicon = array();
$fulllist = get_string("nocoursesyet");
}
}
print_side_block( get_string("courses"), "", $moddata, $modicon, $fulllist, $width);
}
function print_courses($category, $width="100%") {
/// Category is 0 (for all courses) or an object
global $CFG, $THEME;
if (empty($category)) {
$categories = get_categories(0); // Parent = 0 ie top-level categories only
if (count($categories) == 1) {
$category = array_shift($categories);
$courses = get_courses($category->id);
} else {
$courses = get_courses("all");
}
unset($categories);
} else {
$categories = get_categories($category->id); // sub categories
$courses = get_courses($category->id);
}
if ($courses) {
foreach ($courses as $course) {
print_course($course, $width);
echo "
\n";
}
} else {
print_heading(get_string("nocoursesyet"));
}
}
function print_course($course, $width="100%") {
global $CFG, $THEME;
if (! $site = get_site()) {
error("Could not find a site!");
}
print_simple_box_start("center", "$width", $THEME->cellcontent, 5, "coursebox");
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
echo "
";
echo " wwwroot/course/view.php?id=$course->id\">$course->fullname "; if ($teachers = get_course_teachers($course->id)) { echo "\n";
foreach ($teachers as $teacher) {
if ($teacher->authority > 0) {
if (!$teacher->role) {
$teacher->role = $course->teacher;
}
$fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course
echo "$teacher->role: wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$fullname | ";
echo " ".filter_text(text_to_html($course->summary), $course->id)." "; echo " |
"; print_course_search("", false, "short"); echo " | "; print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get"); echo " |
"; $output .= "
"; $output .= "
"; $output .= ""; $output .= " |