2003-09-09 08:37:48 +00:00
|
|
|
<?php // $Id$
|
2002-08-11 15:41:54 +00:00
|
|
|
// Library of useful functions
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
|
2003-04-26 12:17:30 +00:00
|
|
|
if (defined('COURSE_MAX_LOG_DISPLAY')) { // Being included again - should never happen!!
|
2003-01-13 14:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
define('COURSE_MAX_LOG_DISPLAY', 150); // days
|
|
|
|
define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records
|
|
|
|
define('COURSE_LIVELOG_REFRESH', 60); // Seconds
|
|
|
|
define('COURSE_MAX_RECENT_PERIOD', 172800); // Two days, in seconds
|
|
|
|
define('COURSE_MAX_SUMMARIES_PER_PAGE', 10); // courses
|
2006-01-16 03:15:48 +00:00
|
|
|
define('COURSE_MAX_COURSES_PER_DROPDOWN',1000); // max courses in log dropdown before switching to optional
|
2006-05-15 05:01:00 +00:00
|
|
|
define('COURSE_MAX_USERS_PER_DROPDOWN',1000); // max users in log dropdown before switching to optional
|
|
|
|
define('FRONTPAGENEWS', 0);
|
2006-07-19 12:10:07 +00:00
|
|
|
define('FRONTPAGECOURSELIST', 1);
|
|
|
|
define('FRONTPAGECATEGORYNAMES', 2);
|
|
|
|
define('FRONTPAGETOPICONLY', 3);
|
|
|
|
define('FRONTPAGECATEGORYCOMBO', 4);
|
|
|
|
define('FRONTPAGECOURSELIMIT', 200); // maximum number of courses displayed on the frontpage
|
|
|
|
define('EXCELROWS', 65535);
|
|
|
|
define('FIRSTUSEDEXCELROW', 3);
|
2004-11-23 00:16:24 +00:00
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
define('MOD_CLASS_ACTIVITY', 0);
|
|
|
|
define('MOD_CLASS_RESOURCE', 1);
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, $selecteddate="lastlogin",
|
2004-02-15 06:11:15 +00:00
|
|
|
$mod="", $modid="activity/All", $modaction="", $selectedgroup="", $selectedsort="default") {
|
2004-02-05 20:30:26 +00:00
|
|
|
|
|
|
|
global $USER, $CFG;
|
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
if ($advancedfilter) {
|
|
|
|
|
|
|
|
// Get all the possible users
|
|
|
|
$users = array();
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2004-09-08 15:46:43 +00:00
|
|
|
if ($courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname')) {
|
2004-02-20 21:38:42 +00:00
|
|
|
foreach ($courseusers as $courseuser) {
|
2006-09-11 08:56:23 +00:00
|
|
|
$users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
|
2004-02-20 21:38:42 +00:00
|
|
|
}
|
2004-02-05 20:30:26 +00:00
|
|
|
}
|
2004-02-20 21:38:42 +00:00
|
|
|
if ($guest = get_guest()) {
|
|
|
|
$users[$guest->id] = fullname($guest);
|
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2006-09-08 08:46:26 +00:00
|
|
|
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
2004-02-20 21:38:42 +00:00
|
|
|
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)";
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
2004-02-20 21:38:42 +00:00
|
|
|
}
|
2004-02-05 20:30:26 +00:00
|
|
|
}
|
2004-02-20 21:38:42 +00:00
|
|
|
asort($courses);
|
|
|
|
}
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$activities = array();
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$selectedactivity = $modid;
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2006-09-04 21:12:37 +00:00
|
|
|
/// Casting $course->modinfo to string prevents one notice when the field is null
|
|
|
|
if ($modinfo = unserialize((string)$course->modinfo)) {
|
2004-02-20 21:38:42 +00:00
|
|
|
$section = 0;
|
|
|
|
if ($course->format == 'weeks') { // Body
|
|
|
|
$strsection = get_string("week");
|
|
|
|
} else {
|
|
|
|
$strsection = get_string("topic");
|
2004-02-05 20:30:26 +00:00
|
|
|
}
|
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$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;
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
2006-09-05 08:50:23 +00:00
|
|
|
if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities',get_context_instance(CONTEXT_MODULE, $mod->cm))) {
|
2004-03-10 13:38:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
if ($mod->section > 0 and $section <> $mod->section) {
|
|
|
|
$activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------";
|
|
|
|
}
|
|
|
|
$section = $mod->section;
|
2005-04-02 10:10:07 +00:00
|
|
|
$mod->name = strip_tags(format_string(urldecode($mod->name),true));
|
2004-02-20 21:38:42 +00:00
|
|
|
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";
|
|
|
|
}
|
2004-02-05 20:30:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$strftimedate = get_string("strftimedate");
|
|
|
|
$strftimedaydate = get_string("strftimedaydate");
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
asort($users);
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
// 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
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$timenow = time(); // GMT
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
// What day is it now for the user, and when is midnight that day (in GMT).
|
|
|
|
$timemidnight = $today = usergetmidnight($timenow);
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$dates = array();
|
|
|
|
$dates["$USER->lastlogin"] = get_string("lastlogin").", ".userdate($USER->lastlogin, $strftimedate);
|
|
|
|
$dates["$timemidnight"] = get_string("today").", ".userdate($timenow, $strftimedate);
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
if (!$course->startdate or ($course->startdate > $timenow)) {
|
|
|
|
$course->startdate = $course->timecreated;
|
|
|
|
}
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$numdates = 1;
|
|
|
|
while ($timemidnight > $course->startdate and $numdates < 365) {
|
|
|
|
$timemidnight = $timemidnight - 86400;
|
|
|
|
$timenow = $timenow - 86400;
|
|
|
|
$dates["$timemidnight"] = userdate($timenow, $strftimedaydate);
|
|
|
|
$numdates++;
|
|
|
|
}
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2005-06-13 19:06:28 +00:00
|
|
|
if ($selecteddate === "lastlogin") {
|
2004-02-20 21:38:42 +00:00
|
|
|
$selecteddate = $USER->lastlogin;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<form action="recent.php" method="get">';
|
2004-09-08 19:24:38 +00:00
|
|
|
echo '<input type="hidden" name="chooserecent" value="1" />';
|
2004-02-20 21:38:42 +00:00
|
|
|
echo "<center>";
|
|
|
|
echo "<table>";
|
|
|
|
|
2006-09-08 08:46:26 +00:00
|
|
|
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
2004-02-20 21:38:42 +00:00
|
|
|
echo "<tr><td><b>" . get_string("courses") . "</b></td><td>";
|
|
|
|
choose_from_menu ($courses, "id", $course->id, "");
|
|
|
|
echo "</td></tr>";
|
|
|
|
} else {
|
2004-09-08 19:24:38 +00:00
|
|
|
echo '<input type="hidden" name="id" value="'.$course->id.'" />';
|
2004-02-20 21:38:42 +00:00
|
|
|
}
|
2004-02-05 20:30:26 +00:00
|
|
|
|
2004-02-20 22:16:28 +00:00
|
|
|
$sortfields = array("default" => get_string("bycourseorder"),"dateasc" => get_string("datemostrecentlast"), "datedesc" => get_string("datemostrecentfirst"));
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
echo "<tr><td><b>" . get_string("participants") . "</b></td><td>";
|
|
|
|
choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") );
|
|
|
|
echo "</td>";
|
|
|
|
|
2004-09-08 19:24:38 +00:00
|
|
|
echo '<td align="right"><b>' . get_string("since") . '</b></td><td>';
|
2004-02-20 21:38:42 +00:00
|
|
|
choose_from_menu ($dates, "date", $selecteddate, get_string("alldays"));
|
2004-02-15 06:11:15 +00:00
|
|
|
echo "</td></tr>";
|
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
echo "<tr><td><b>" . get_string("activities") . "</b></td><td>";
|
|
|
|
choose_from_menu ($activities, "modid", $selectedactivity, "");
|
|
|
|
echo "</td>";
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2004-09-08 19:24:38 +00:00
|
|
|
echo '<td align="right"><b>' . get_string("sortby") . "</b></td><td>";
|
2004-02-20 21:38:42 +00:00
|
|
|
choose_from_menu ($sortfields, "sortby", $selectedsort, "");
|
|
|
|
echo "</td></tr>";
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
echo '<tr>';
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$groupmode = groupmode($course);
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2006-09-05 08:50:23 +00:00
|
|
|
if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
|
2007-01-04 13:15:04 +13:00
|
|
|
if ($groups_names = groups_get_groups_names($course->id)) { //TODO:check.
|
2004-02-15 06:11:15 +00:00
|
|
|
echo '<td><b>';
|
2004-02-20 21:38:42 +00:00
|
|
|
if ($groupmode == VISIBLEGROUPS) {
|
|
|
|
print_string('groupsvisible');
|
|
|
|
} else {
|
|
|
|
print_string('groupsseparate');
|
|
|
|
}
|
|
|
|
echo ':</b></td><td>';
|
2007-01-04 13:15:04 +13:00
|
|
|
choose_from_menu($groups_names, "selectedgroup", $selectedgroup, get_string("allgroups"), "", "");
|
2004-02-20 21:38:42 +00:00
|
|
|
echo '</td>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-08 19:24:38 +00:00
|
|
|
echo '<td colspan="2" align="right">';
|
|
|
|
echo '<input type="submit" value="'.get_string('showrecent').'" />';
|
2004-02-20 21:38:42 +00:00
|
|
|
echo "</td></tr>";
|
|
|
|
|
|
|
|
echo "</table>";
|
|
|
|
|
2004-09-16 17:13:57 +00:00
|
|
|
$advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&advancedfilter=0\">" . get_string("normalfilter") . "</a>";
|
2004-02-20 21:38:42 +00:00
|
|
|
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;
|
2004-02-15 06:11:15 +00:00
|
|
|
} else {
|
2004-02-20 21:38:42 +00:00
|
|
|
$day = $strdays;
|
2004-02-15 06:11:15 +00:00
|
|
|
}
|
2004-02-23 21:17:03 +00:00
|
|
|
$tmpdate = time() - ($count * 3600 * 24);
|
2004-02-20 21:38:42 +00:00
|
|
|
$heading = $heading .
|
2004-09-16 17:13:57 +00:00
|
|
|
"<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&date=$tmpdate\"> $count $day</a> | ";
|
2004-02-15 06:11:15 +00:00
|
|
|
}
|
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
$heading = $strsince . ": <a href=\"$CFG->wwwroot/course/recent.php?id=$course->id\">$strlastlogin</a>" . " | " . $heading;
|
|
|
|
print_heading($heading);
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2004-09-16 17:13:57 +00:00
|
|
|
$advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&advancedfilter=1\">" . get_string("advancedfilter") . "</a>";
|
2004-02-20 21:38:42 +00:00
|
|
|
print_heading($advancedlink);
|
|
|
|
|
|
|
|
}
|
2004-02-15 06:11:15 +00:00
|
|
|
|
2004-02-05 20:30:26 +00:00
|
|
|
}
|
2003-01-13 14:11:05 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-05-31 09:34:50 +00:00
|
|
|
function make_log_url($module, $url) {
|
|
|
|
switch ($module) {
|
2006-05-01 06:04:22 +00:00
|
|
|
case 'user':
|
|
|
|
case 'course':
|
|
|
|
case 'file':
|
|
|
|
case 'login':
|
|
|
|
case 'lib':
|
|
|
|
case 'admin':
|
|
|
|
case 'message':
|
|
|
|
case 'calendar':
|
|
|
|
case 'blog':
|
2002-05-31 09:34:50 +00:00
|
|
|
return "/$module/$url";
|
|
|
|
break;
|
2006-05-01 06:04:22 +00:00
|
|
|
case 'upload':
|
|
|
|
return $url;
|
2004-09-17 00:10:53 +00:00
|
|
|
break;
|
2006-05-01 06:04:22 +00:00
|
|
|
case 'library':
|
|
|
|
case '':
|
|
|
|
return '/';
|
2004-08-17 14:26:47 +00:00
|
|
|
break;
|
2002-05-31 09:34:50 +00:00
|
|
|
default:
|
|
|
|
return "/mod/$module/$url";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
|
2007-01-04 03:22:51 +00:00
|
|
|
function build_mnet_logs_array($hostid, $course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',
|
|
|
|
$modname="", $modid=0, $modaction="", $groupid=0) {
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
// It is assumed that $date is the GMT time of midnight for that day,
|
|
|
|
// and so the next 86400 seconds worth of logs are printed.
|
|
|
|
|
|
|
|
/// Setup for group handling.
|
|
|
|
|
|
|
|
// TODO: I don't understand group/context/etc. enough to be able to do
|
|
|
|
// something interesting with it here
|
|
|
|
// What is the context of a remote course?
|
|
|
|
|
|
|
|
/// If the group mode is separate, and this user does not have editing privileges,
|
|
|
|
/// then only the user's group can be viewed.
|
|
|
|
//if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
|
|
|
// $groupid = get_current_group($course->id);
|
|
|
|
//}
|
|
|
|
/// If this course doesn't have groups, no groupid can be specified.
|
|
|
|
//else if (!$course->groupmode) {
|
|
|
|
// $groupid = 0;
|
|
|
|
//}
|
|
|
|
$groupid = 0;
|
|
|
|
|
|
|
|
$joins = array();
|
|
|
|
|
|
|
|
$qry = "
|
|
|
|
SELECT
|
|
|
|
l.*,
|
|
|
|
u.firstname,
|
|
|
|
u.lastname,
|
|
|
|
u.picture
|
|
|
|
FROM
|
|
|
|
{$CFG->prefix}mnet_log l
|
|
|
|
LEFT JOIN
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
ON
|
|
|
|
l.userid = u.id
|
|
|
|
WHERE
|
|
|
|
";
|
|
|
|
|
|
|
|
$where .= "l.hostid = '$hostid'";
|
|
|
|
|
|
|
|
// TODO: Is 1 really a magic number referring to the sitename?
|
|
|
|
if ($course != 1 || $modid != 0) {
|
|
|
|
$where .= " AND\n l.course='$course'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($modname) {
|
|
|
|
$where .= " AND\n l.module = '$modname'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('site_errors' === $modid) {
|
|
|
|
$where .= " AND\n ( l.action='error' OR l.action='infected' )";
|
|
|
|
} else if ($modid) {
|
|
|
|
//TODO: This assumes that modids are the same across sites... probably
|
|
|
|
//not true
|
|
|
|
$where .= " AND\n l.cmid = '$modid'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($modaction) {
|
|
|
|
$firstletter = substr($modaction, 0, 1);
|
|
|
|
if (ctype_alpha($firstletter)) {
|
|
|
|
$where .= " AND\n lower(l.action) LIKE '%" . strtolower($modaction) . "%'";
|
|
|
|
} else if ($firstletter == '-') {
|
|
|
|
$where .= " AND\n lower(l.action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
$where .= " AND\n l.userid = '$user'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($date) {
|
|
|
|
$enddate = $date + 86400;
|
|
|
|
$where .= " AND\n l.time > '$date' AND l.time < '$enddate'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
$result['totalcount'] = count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}mnet_log l WHERE $where");
|
|
|
|
if(!empty($result['totalcount'])) {
|
|
|
|
$where .= "\n ORDER BY\n $order";
|
|
|
|
$result['logs'] = get_records_sql($qry.$where, $limitfrom, $limitnum);
|
|
|
|
} else {
|
|
|
|
$result['logs'] = array();
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',
|
|
|
|
$modname="", $modid=0, $modaction="", $groupid=0) {
|
2004-01-15 07:17:12 +00:00
|
|
|
|
2004-07-25 14:00:29 +00:00
|
|
|
// It is assumed that $date is the GMT time of midnight for that day,
|
|
|
|
// and so the next 86400 seconds worth of logs are printed.
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-07-28 15:52:51 +00:00
|
|
|
/// Setup for group handling.
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2004-07-28 15:52:51 +00:00
|
|
|
/// If the group mode is separate, and this user does not have editing privileges,
|
|
|
|
/// then only the user's group can be viewed.
|
2006-09-05 08:50:23 +00:00
|
|
|
if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
2004-07-28 15:52:51 +00:00
|
|
|
$groupid = get_current_group($course->id);
|
|
|
|
}
|
|
|
|
/// If this course doesn't have groups, no groupid can be specified.
|
|
|
|
else if (!$course->groupmode) {
|
|
|
|
$groupid = 0;
|
|
|
|
}
|
|
|
|
|
2004-07-25 14:00:29 +00:00
|
|
|
$joins = array();
|
2002-08-08 16:22:44 +00:00
|
|
|
|
2006-04-21 05:39:20 +00:00
|
|
|
if ($course->id != SITEID || $modid != 0) {
|
2004-09-21 11:41:58 +00:00
|
|
|
$joins[] = "l.course='$course->id'";
|
2006-04-21 05:39:20 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-02-14 02:44:35 +00:00
|
|
|
if ($modname) {
|
2004-07-25 14:00:29 +00:00
|
|
|
$joins[] = "l.module = '$modname'";
|
2004-01-15 07:17:12 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 09:55:12 +00:00
|
|
|
if ('site_errors' === $modid) {
|
2004-12-09 21:35:20 +00:00
|
|
|
$joins[] = "( l.action='error' OR l.action='infected' )";
|
2004-08-12 09:55:12 +00:00
|
|
|
} else if ($modid) {
|
|
|
|
$joins[] = "l.cmid = '$modid'";
|
2004-01-31 14:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($modaction) {
|
2006-03-28 17:33:40 +00:00
|
|
|
$firstletter = substr($modaction, 0, 1);
|
|
|
|
if (ctype_alpha($firstletter)) {
|
|
|
|
$joins[] = "lower(l.action) LIKE '%" . strtolower($modaction) . "%'";
|
|
|
|
} else if ($firstletter == '-') {
|
|
|
|
$joins[] = "lower(l.action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'";
|
|
|
|
}
|
2004-01-15 07:17:12 +00:00
|
|
|
}
|
|
|
|
|
2004-07-28 15:52:51 +00:00
|
|
|
/// Getting all members of a group.
|
|
|
|
if ($groupid and !$user) {
|
2007-01-04 13:15:04 +13:00
|
|
|
if ($gusers = groups_get_members($groupid)) { //TODO:check.
|
2004-07-28 15:52:51 +00:00
|
|
|
$first = true;
|
|
|
|
foreach($gusers as $guser) {
|
|
|
|
if ($first) {
|
|
|
|
$gselect = '(l.userid='.$guser->userid;
|
|
|
|
$first = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$gselect .= ' OR l.userid='.$guser->userid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$first) $gselect .= ')';
|
|
|
|
$joins[] = $gselect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($user) {
|
2004-07-25 14:00:29 +00:00
|
|
|
$joins[] = "l.userid = '$user'";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($date) {
|
|
|
|
$enddate = $date + 86400;
|
2004-07-25 14:00:29 +00:00
|
|
|
$joins[] = "l.time > '$date' AND l.time < '$enddate'";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 13:12:16 +00:00
|
|
|
$selector = '';
|
2004-07-25 14:00:29 +00:00
|
|
|
for ($i = 0; $i < count($joins); $i++) {
|
|
|
|
$selector .= $joins[$i] . (($i == count($joins)-1) ? " " : " AND ");
|
|
|
|
}
|
|
|
|
|
2003-08-28 11:57:21 +00:00
|
|
|
$totalcount = 0; // Initialise
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
$result = array();
|
|
|
|
$result['logs'] = get_logs($selector, $order, $limitfrom, $limitnum, $totalcount);
|
|
|
|
$result['totalcount'] = $totalcount;
|
|
|
|
return $result;
|
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
|
|
|
|
$url="", $modname="", $modid=0, $modaction="", $groupid=0) {
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
global $CFG;
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
if (!$logs = build_logs_array($course, $user, $date, $order, $page*$perpage, $perpage,
|
|
|
|
$modname, $modid, $modaction, $groupid)) {
|
2001-11-22 06:23:56 +00:00
|
|
|
notify("No logs found!");
|
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-12-21 10:58:18 +00:00
|
|
|
$courses = array();
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
if ($course->id == SITEID) {
|
|
|
|
$courses[0] = '';
|
2006-12-21 10:58:18 +00:00
|
|
|
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
|
2006-05-15 05:01:00 +00:00
|
|
|
foreach ($ccc as $cc) {
|
|
|
|
$courses[$cc->id] = $cc->shortname;
|
|
|
|
}
|
|
|
|
}
|
2006-12-21 10:58:18 +00:00
|
|
|
} else {
|
|
|
|
$courses[$course->id] = $course->shortname;
|
2006-05-15 05:01:00 +00:00
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
$totalcount = $logs['totalcount'];
|
2001-11-22 06:23:56 +00:00
|
|
|
$count=0;
|
2004-07-29 18:01:32 +00:00
|
|
|
$ldcache = array();
|
2001-11-22 06:23:56 +00:00
|
|
|
$tt = getdate(time());
|
|
|
|
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
|
2003-01-01 08:21:19 +00:00
|
|
|
|
2003-01-15 10:55:54 +00:00
|
|
|
$strftimedatetime = get_string("strftimedatetime");
|
|
|
|
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "<p align=\"center\">\n";
|
2003-08-22 06:07:18 +00:00
|
|
|
print_string("displayingrecords", "", $totalcount);
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</p>\n";
|
2003-01-01 08:21:19 +00:00
|
|
|
|
2004-09-21 11:41:58 +00:00
|
|
|
print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&");
|
2003-08-22 06:07:18 +00:00
|
|
|
|
2007-01-05 14:13:26 +00:00
|
|
|
echo "<table class=\"logtable\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\">\n";
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "<tr>";
|
2005-05-12 08:04:47 +00:00
|
|
|
if ($course->id == SITEID) {
|
2006-12-13 03:03:43 +00:00
|
|
|
echo "<th class=\"c0 header\" scope=\"col\">".get_string('course')."</th>\n";
|
2005-05-12 08:04:47 +00:00
|
|
|
}
|
2006-12-13 03:03:43 +00:00
|
|
|
echo "<th class=\"c1 header\" scope=\"col\">".get_string('time')."</th>\n";
|
|
|
|
echo "<th class=\"c2 header\" scope=\"col\">".get_string('ip_address')."</th>\n";
|
|
|
|
echo "<th class=\"c3 header\" scope=\"col\">".get_string('fullname')."</th>\n";
|
|
|
|
echo "<th class=\"c4 header\" scope=\"col\">".get_string('action')."</th>\n";
|
|
|
|
echo "<th class=\"c5 header\" scope=\"col\">".get_string('info')."</th>\n";
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</tr>\n";
|
2005-05-12 08:04:47 +00:00
|
|
|
|
2006-09-27 07:41:38 +00:00
|
|
|
if (empty($logs['logs'])) {
|
|
|
|
echo "</table>\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-05-12 08:04:47 +00:00
|
|
|
$row = 1;
|
2006-05-15 05:01:00 +00:00
|
|
|
foreach ($logs['logs'] as $log) {
|
2002-05-31 09:34:50 +00:00
|
|
|
|
2005-05-12 08:04:47 +00:00
|
|
|
$row = ($row + 1) % 2;
|
|
|
|
|
2004-07-29 18:01:32 +00:00
|
|
|
if (isset($ldcache[$log->module][$log->action])) {
|
|
|
|
$ld = $ldcache[$log->module][$log->action];
|
|
|
|
} else {
|
2005-05-12 08:04:47 +00:00
|
|
|
$ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
|
2004-07-29 18:01:32 +00:00
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
2004-11-23 23:27:18 +00:00
|
|
|
if ($ld && !empty($log->info)) {
|
2005-01-16 17:27:40 +00:00
|
|
|
// ugly hack to make sure fullname is shown correctly
|
2006-09-26 05:03:46 +00:00
|
|
|
if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
|
2005-01-16 17:27:40 +00:00
|
|
|
$log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
|
|
|
|
} else {
|
|
|
|
$log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
|
|
|
|
}
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
|
2006-11-09 18:25:58 +00:00
|
|
|
//Filter log->info
|
2005-03-27 22:31:54 +00:00
|
|
|
$log->info = format_string($log->info);
|
|
|
|
|
2004-08-29 04:47:13 +00:00
|
|
|
$log->url = strip_tags(urldecode($log->url)); // Some XSS protection
|
|
|
|
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
|
2004-10-08 14:43:35 +00:00
|
|
|
$log->url = str_replace('&', '&', $log->url); /// XHTML compatibility
|
2004-08-29 04:47:13 +00:00
|
|
|
|
2005-05-12 08:04:47 +00:00
|
|
|
echo '<tr class="r'.$row.'">';
|
|
|
|
if ($course->id == SITEID) {
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "<td class=\"r$row c0\" nowrap=\"nowrap\">\n";
|
2006-07-04 05:27:18 +00:00
|
|
|
echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courses[$log->course]."</a>\n";
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</td>\n";
|
2002-06-12 04:22:41 +00:00
|
|
|
}
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "<td class=\"r$row c1\" nowrap=\"nowrap\" align=\"right\">".userdate($log->time, '%a').
|
|
|
|
' '.userdate($log->time, $strftimedatetime)."</td>\n";
|
|
|
|
echo "<td class=\"r$row c2\" nowrap=\"nowrap\">\n";
|
2005-07-18 08:07:00 +00:00
|
|
|
link_to_popup_window("/iplookup/index.php?ip=$log->ip&user=$log->userid", 'iplookup',$log->ip, 400, 700);
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</td>\n";
|
2006-09-11 08:56:23 +00:00
|
|
|
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "<td class=\"r$row c3\" nowrap=\"nowrap\">\n";
|
2006-04-19 12:54:34 +00:00
|
|
|
echo " <a href=\"$CFG->wwwroot/user/view.php?id={$log->userid}&course={$log->course}\">$fullname</a>\n";
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</td>\n";
|
|
|
|
echo "<td class=\"r$row c4\" nowrap=\"nowrap\">\n";
|
2004-07-29 18:01:32 +00:00
|
|
|
link_to_popup_window( make_log_url($log->module,$log->url), 'fromloglive',"$log->module $log->action", 400, 600);
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</td>\n";;
|
|
|
|
echo "<td class=\"r$row c5\" nowrap=\"nowrap\">{$log->info}</td>\n";
|
|
|
|
echo "</tr>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</table>\n";
|
2003-08-22 06:07:18 +00:00
|
|
|
|
2004-09-21 11:41:58 +00:00
|
|
|
print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-04 03:22:51 +00:00
|
|
|
function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
|
|
|
|
$url="", $modname="", $modid=0, $modaction="", $groupid=0) {
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (!$logs = build_mnet_logs_array($hostid, $course, $user, $date, $order, $page*$perpage, $perpage,
|
|
|
|
$modname, $modid, $modaction, $groupid)) {
|
|
|
|
notify("No logs found!");
|
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($course->id == SITEID) {
|
|
|
|
$courses[0] = '';
|
|
|
|
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.visible')) {
|
|
|
|
foreach ($ccc as $cc) {
|
|
|
|
$courses[$cc->id] = $cc->shortname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$totalcount = $logs['totalcount'];
|
|
|
|
$count=0;
|
|
|
|
$ldcache = array();
|
|
|
|
$tt = getdate(time());
|
|
|
|
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
|
|
|
|
|
|
|
|
$strftimedatetime = get_string("strftimedatetime");
|
|
|
|
|
|
|
|
echo "<p align=\"center\">\n";
|
|
|
|
print_string("displayingrecords", "", $totalcount);
|
|
|
|
echo "</p>\n";
|
|
|
|
|
|
|
|
print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&");
|
|
|
|
|
2007-01-05 14:13:26 +00:00
|
|
|
echo "<table class=\"logtable\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\">\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
echo "<tr>";
|
|
|
|
if ($course->id == SITEID) {
|
|
|
|
echo "<th class=\"c0 header\">".get_string('course')."</th>\n";
|
|
|
|
}
|
|
|
|
echo "<th class=\"c1 header\">".get_string('time')."</th>\n";
|
|
|
|
echo "<th class=\"c2 header\">".get_string('ip_address')."</th>\n";
|
|
|
|
echo "<th class=\"c3 header\">".get_string('fullname')."</th>\n";
|
|
|
|
echo "<th class=\"c4 header\">".get_string('action')."</th>\n";
|
|
|
|
echo "<th class=\"c5 header\">".get_string('info')."</th>\n";
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
if (empty($logs['logs'])) {
|
|
|
|
echo "</table>\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$row = 1;
|
|
|
|
foreach ($logs['logs'] as $log) {
|
|
|
|
|
|
|
|
$log->info = $log->coursename;
|
|
|
|
$row = ($row + 1) % 2;
|
|
|
|
|
|
|
|
if (isset($ldcache[$log->module][$log->action])) {
|
|
|
|
$ld = $ldcache[$log->module][$log->action];
|
|
|
|
} else {
|
|
|
|
$ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
|
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
|
|
|
if (0 && $ld && !empty($log->info)) {
|
|
|
|
// ugly hack to make sure fullname is shown correctly
|
|
|
|
if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
|
|
|
|
$log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
|
|
|
|
} else {
|
|
|
|
$log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Filter log->info
|
|
|
|
$log->info = format_string($log->info);
|
|
|
|
|
|
|
|
$log->url = strip_tags(urldecode($log->url)); // Some XSS protection
|
|
|
|
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
|
|
|
|
$log->url = str_replace('&', '&', $log->url); /// XHTML compatibility
|
|
|
|
|
|
|
|
echo '<tr class="r'.$row.'">';
|
|
|
|
if ($course->id == SITEID) {
|
|
|
|
echo "<td class=\"r$row c0\" nowrap=\"nowrap\">\n";
|
|
|
|
echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courses[$log->course]."</a>\n";
|
|
|
|
echo "</td>\n";
|
|
|
|
}
|
|
|
|
echo "<td class=\"r$row c1\" nowrap=\"nowrap\" align=\"right\">".userdate($log->time, '%a').
|
|
|
|
' '.userdate($log->time, $strftimedatetime)."</td>\n";
|
|
|
|
echo "<td class=\"r$row c2\" nowrap=\"nowrap\">\n";
|
|
|
|
link_to_popup_window("/iplookup/index.php?ip=$log->ip&user=$log->userid", 'iplookup',$log->ip, 400, 700);
|
|
|
|
echo "</td>\n";
|
|
|
|
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
|
|
|
|
echo "<td class=\"r$row c3\" nowrap=\"nowrap\">\n";
|
|
|
|
echo " <a href=\"$CFG->wwwroot/user/view.php?id={$log->userid}\">$fullname</a>\n";
|
|
|
|
echo "</td>\n";
|
|
|
|
echo "<td class=\"r$row c4\" nowrap=\"nowrap\">\n";
|
|
|
|
echo $log->action .': '.$log->module;
|
|
|
|
echo "</td>\n";;
|
|
|
|
echo "<td class=\"r$row c5\" nowrap=\"nowrap\">{$log->info}</td>\n";
|
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
echo "</table>\n";
|
|
|
|
|
|
|
|
print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
|
|
|
|
$modid, $modaction, $groupid) {
|
2006-09-26 05:03:46 +00:00
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
$text = get_string('course')."\t".get_string('time')."\t".get_string('ip_address')."\t".
|
|
|
|
get_string('fullname')."\t".get_string('action')."\t".get_string('info');
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
|
2006-05-15 05:01:00 +00:00
|
|
|
$modname, $modid, $modaction, $groupid)) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-12-21 10:58:18 +00:00
|
|
|
$courses = array();
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
if ($course->id == SITEID) {
|
|
|
|
$courses[0] = '';
|
|
|
|
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
|
|
|
|
foreach ($ccc as $cc) {
|
|
|
|
$courses[$cc->id] = $cc->shortname;
|
|
|
|
}
|
|
|
|
}
|
2006-12-21 10:58:18 +00:00
|
|
|
} else {
|
|
|
|
$courses[$course->id] = $course->shortname;
|
2006-05-15 05:01:00 +00:00
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
$count=0;
|
|
|
|
$ldcache = array();
|
|
|
|
$tt = getdate(time());
|
|
|
|
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
|
|
|
|
|
|
|
|
$strftimedatetime = get_string("strftimedatetime");
|
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
$filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
|
|
|
|
$filename .= '.txt';
|
2006-11-09 18:25:58 +00:00
|
|
|
header("Content-Type: application/download\n");
|
2006-08-25 07:09:28 +00:00
|
|
|
header("Content-Disposition: attachment; filename=$filename");
|
|
|
|
header("Expires: 0");
|
|
|
|
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
|
|
|
|
header("Pragma: public");
|
|
|
|
|
|
|
|
echo get_string('savedat').userdate(time(), $strftimedatetime)."\n";
|
|
|
|
echo $text;
|
|
|
|
|
2006-09-27 07:41:38 +00:00
|
|
|
if (empty($logs['logs'])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
foreach ($logs['logs'] as $log) {
|
|
|
|
if (isset($ldcache[$log->module][$log->action])) {
|
|
|
|
$ld = $ldcache[$log->module][$log->action];
|
|
|
|
} else {
|
|
|
|
$ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
|
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
|
|
|
if ($ld && !empty($log->info)) {
|
|
|
|
// ugly hack to make sure fullname is shown correctly
|
2006-09-26 05:03:46 +00:00
|
|
|
if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
|
2006-08-25 07:09:28 +00:00
|
|
|
$log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
|
|
|
|
} else {
|
|
|
|
$log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-09 18:25:58 +00:00
|
|
|
//Filter log->info
|
2006-08-25 07:09:28 +00:00
|
|
|
$log->info = format_string($log->info);
|
|
|
|
|
|
|
|
$log->url = strip_tags(urldecode($log->url)); // Some XSS protection
|
|
|
|
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
|
|
|
|
$log->url = str_replace('&', '&', $log->url); // XHTML compatibility
|
|
|
|
|
|
|
|
$firstField = $courses[$log->course];
|
2006-09-11 08:56:23 +00:00
|
|
|
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
|
2006-08-25 07:09:28 +00:00
|
|
|
$row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
|
|
|
|
$text = implode("\t", $row);
|
|
|
|
echo $text." \n";
|
|
|
|
}
|
|
|
|
return true;
|
2006-05-15 05:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_log_xls($course, $user, $date, $order='l.time DESC', $modname,
|
|
|
|
$modid, $modaction, $groupid) {
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
require_once("$CFG->libdir/excellib.class.php");
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
|
2006-05-15 05:01:00 +00:00
|
|
|
$modname, $modid, $modaction, $groupid)) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-12-21 10:58:18 +00:00
|
|
|
$courses = array();
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
if ($course->id == SITEID) {
|
|
|
|
$courses[0] = '';
|
|
|
|
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
|
|
|
|
foreach ($ccc as $cc) {
|
|
|
|
$courses[$cc->id] = $cc->shortname;
|
|
|
|
}
|
|
|
|
}
|
2006-12-21 10:58:18 +00:00
|
|
|
} else {
|
|
|
|
$courses[$course->id] = $course->shortname;
|
2006-05-15 05:01:00 +00:00
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
$count=0;
|
|
|
|
$ldcache = array();
|
|
|
|
$tt = getdate(time());
|
|
|
|
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
|
|
|
|
|
|
|
|
$strftimedatetime = get_string("strftimedatetime");
|
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
$nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1));
|
|
|
|
$filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
|
|
|
|
$filename .= '.xls';
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
$workbook = new MoodleExcelWorkbook('-');
|
|
|
|
$workbook->send($filename);
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
$worksheet = array();
|
|
|
|
$headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
|
|
|
|
get_string('fullname'), get_string('action'), get_string('info'));
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
// Creating worksheets
|
|
|
|
for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
|
|
|
|
$sheettitle = get_string('excel_sheettitle', 'logs', $wsnumber).$nroPages;
|
|
|
|
$worksheet[$wsnumber] =& $workbook->add_worksheet($sheettitle);
|
|
|
|
$worksheet[$wsnumber]->set_column(1, 1, 30);
|
|
|
|
$worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
|
|
|
|
userdate(time(), $strftimedatetime));
|
|
|
|
$col = 0;
|
|
|
|
foreach ($headers as $item) {
|
|
|
|
$worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW-1,$col,$item,'');
|
|
|
|
$col++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-27 07:41:38 +00:00
|
|
|
if (empty($logs['logs'])) {
|
|
|
|
$workbook->close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
$formatDate =& $workbook->add_format();
|
|
|
|
$formatDate->set_num_format(get_string('log_excel_date_format'));
|
|
|
|
|
|
|
|
$row = FIRSTUSEDEXCELROW;
|
|
|
|
$wsnumber = 1;
|
|
|
|
$myxls =& $worksheet[$wsnumber];
|
|
|
|
foreach ($logs['logs'] as $log) {
|
|
|
|
if (isset($ldcache[$log->module][$log->action])) {
|
|
|
|
$ld = $ldcache[$log->module][$log->action];
|
|
|
|
} else {
|
|
|
|
$ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
|
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
|
|
|
if ($ld && !empty($log->info)) {
|
|
|
|
// ugly hack to make sure fullname is shown correctly
|
2006-09-26 05:03:46 +00:00
|
|
|
if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
|
2006-08-25 07:09:28 +00:00
|
|
|
$log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
|
|
|
|
} else {
|
|
|
|
$log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter log->info
|
|
|
|
$log->info = format_string($log->info);
|
|
|
|
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
|
|
|
|
|
|
|
|
if ($nroPages>1) {
|
|
|
|
if ($row > EXCELROWS) {
|
|
|
|
$wsnumber++;
|
|
|
|
$myxls =& $worksheet[$wsnumber];
|
|
|
|
$row = FIRSTUSEDEXCELROW;
|
|
|
|
}
|
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
$myxls->write($row, 0, $courses[$log->course], '');
|
|
|
|
// Excel counts from 1/1/1900
|
|
|
|
$excelTime=25569+$log->time/(3600*24);
|
|
|
|
$myxls->write($row, 1, $excelTime, $formatDate);
|
|
|
|
$myxls->write($row, 2, $log->ip, '');
|
2006-09-11 08:56:23 +00:00
|
|
|
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
|
2006-08-25 07:09:28 +00:00
|
|
|
$myxls->write($row, 3, $fullname, '');
|
|
|
|
$myxls->write($row, 4, $log->module.' '.$log->action, '');
|
|
|
|
$myxls->write($row, 5, $log->info, '');
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-08-25 07:09:28 +00:00
|
|
|
$row++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$workbook->close();
|
2006-12-21 10:58:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_log_ods($course, $user, $date, $order='l.time DESC', $modname,
|
|
|
|
$modid, $modaction, $groupid) {
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
require_once("$CFG->libdir/odslib.class.php");
|
|
|
|
|
|
|
|
if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
|
|
|
|
$modname, $modid, $modaction, $groupid)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$courses = array();
|
|
|
|
|
|
|
|
if ($course->id == SITEID) {
|
|
|
|
$courses[0] = '';
|
|
|
|
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
|
|
|
|
foreach ($ccc as $cc) {
|
|
|
|
$courses[$cc->id] = $cc->shortname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$courses[$course->id] = $course->shortname;
|
|
|
|
}
|
|
|
|
|
|
|
|
$count=0;
|
|
|
|
$ldcache = array();
|
|
|
|
$tt = getdate(time());
|
|
|
|
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
|
|
|
|
|
|
|
|
$strftimedatetime = get_string("strftimedatetime");
|
|
|
|
|
|
|
|
$nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1));
|
|
|
|
$filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
|
|
|
|
$filename .= '.ods';
|
|
|
|
|
|
|
|
$workbook = new MoodleODSWorkbook('-');
|
|
|
|
$workbook->send($filename);
|
|
|
|
|
|
|
|
$worksheet = array();
|
|
|
|
$headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
|
|
|
|
get_string('fullname'), get_string('action'), get_string('info'));
|
|
|
|
|
|
|
|
// Creating worksheets
|
|
|
|
for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
|
|
|
|
$sheettitle = get_string('excel_sheettitle', 'logs', $wsnumber).$nroPages;
|
|
|
|
$worksheet[$wsnumber] =& $workbook->add_worksheet($sheettitle);
|
|
|
|
$worksheet[$wsnumber]->set_column(1, 1, 30);
|
|
|
|
$worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
|
|
|
|
userdate(time(), $strftimedatetime));
|
|
|
|
$col = 0;
|
|
|
|
foreach ($headers as $item) {
|
|
|
|
$worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW-1,$col,$item,'');
|
|
|
|
$col++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($logs['logs'])) {
|
|
|
|
$workbook->close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$formatDate =& $workbook->add_format();
|
|
|
|
$formatDate->set_num_format(get_string('log_excel_date_format'));
|
|
|
|
|
|
|
|
$row = FIRSTUSEDEXCELROW;
|
|
|
|
$wsnumber = 1;
|
|
|
|
$myxls =& $worksheet[$wsnumber];
|
|
|
|
foreach ($logs['logs'] as $log) {
|
|
|
|
if (isset($ldcache[$log->module][$log->action])) {
|
|
|
|
$ld = $ldcache[$log->module][$log->action];
|
|
|
|
} else {
|
|
|
|
$ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
|
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
|
|
|
if ($ld && !empty($log->info)) {
|
|
|
|
// ugly hack to make sure fullname is shown correctly
|
|
|
|
if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
|
|
|
|
$log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
|
|
|
|
} else {
|
|
|
|
$log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter log->info
|
|
|
|
$log->info = format_string($log->info);
|
|
|
|
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
|
|
|
|
|
|
|
|
if ($nroPages>1) {
|
|
|
|
if ($row > EXCELROWS) {
|
|
|
|
$wsnumber++;
|
|
|
|
$myxls =& $worksheet[$wsnumber];
|
|
|
|
$row = FIRSTUSEDEXCELROW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-21 19:46:29 +00:00
|
|
|
$myxls->write_string($row, 0, $courses[$log->course]);
|
|
|
|
$myxls->write_date($row, 1, $log->time);
|
|
|
|
$myxls->write_string($row, 2, $log->ip);
|
2006-12-21 10:58:18 +00:00
|
|
|
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
|
2006-12-21 19:46:29 +00:00
|
|
|
$myxls->write_string($row, 3, $fullname);
|
|
|
|
$myxls->write_string($row, 4, $log->module.' '.$log->action);
|
|
|
|
$myxls->write_string($row, 5, $log->info);
|
2006-12-21 10:58:18 +00:00
|
|
|
|
|
|
|
$row++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$workbook->close();
|
2006-08-25 07:09:28 +00:00
|
|
|
return true;
|
2006-05-15 05:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
|
|
|
|
global $CFG;
|
|
|
|
if (empty($CFG->gdversion)) {
|
|
|
|
echo "(".get_string("gdneed").")";
|
2002-06-10 05:19:03 +00:00
|
|
|
} else {
|
2006-04-05 03:17:20 +00:00
|
|
|
echo '<img src="'.$CFG->wwwroot.'/course/report/log/graph.php?id='.$course->id.
|
2005-04-20 00:44:02 +00:00
|
|
|
'&user='.$userid.'&type='.$type.'&date='.$date.'" alt="" />';
|
2002-06-10 05:19:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-17 20:49:43 +00:00
|
|
|
function print_overview($courses) {
|
2005-08-16 00:25:39 +00:00
|
|
|
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
2006-01-17 20:49:43 +00:00
|
|
|
$htmlarray = array();
|
2005-09-05 01:31:08 +00:00
|
|
|
if ($modules = get_records('modules')) {
|
|
|
|
foreach ($modules as $mod) {
|
|
|
|
if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
|
|
|
|
require_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
|
|
|
|
$fname = $mod->name.'_print_overview';
|
2005-08-16 00:25:39 +00:00
|
|
|
if (function_exists($fname)) {
|
2006-01-17 20:49:43 +00:00
|
|
|
$fname($courses,$htmlarray);
|
2005-08-16 00:25:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-17 20:49:43 +00:00
|
|
|
foreach ($courses as $course) {
|
2006-03-15 09:59:28 +00:00
|
|
|
print_simple_box_start('center', '100%', '', 5, "coursebox");
|
2006-01-17 20:49:43 +00:00
|
|
|
$linkcss = '';
|
|
|
|
if (empty($course->visible)) {
|
|
|
|
$linkcss = 'class="dimmed"';
|
|
|
|
}
|
|
|
|
print_heading('<a title="'.$course->fullname.'" '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a>');
|
|
|
|
if (array_key_exists($course->id,$htmlarray)) {
|
|
|
|
foreach ($htmlarray[$course->id] as $modname => $html) {
|
|
|
|
echo $html;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_simple_box_end();
|
|
|
|
}
|
2005-08-16 00:25:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-31 09:34:50 +00:00
|
|
|
function print_recent_activity($course) {
|
|
|
|
// $course is an object
|
2004-05-28 10:53:54 +00:00
|
|
|
// This function trawls through the logs looking for
|
2002-05-31 09:34:50 +00:00
|
|
|
// anything new since the user's last login
|
|
|
|
|
2005-01-25 14:03:43 +00:00
|
|
|
global $CFG, $USER, $SESSION;
|
2002-05-31 09:34:50 +00:00
|
|
|
|
2006-10-24 14:37:04 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
2003-11-19 16:30:09 +00:00
|
|
|
|
2004-05-16 10:34:17 +00:00
|
|
|
$timestart = time() - COURSE_MAX_RECENT_PERIOD;
|
2004-02-23 18:05:59 +00:00
|
|
|
|
2006-10-24 14:37:04 +00:00
|
|
|
if (!has_capability('moodle/legacy:guest', $context, NULL, false)) {
|
|
|
|
if (!empty($USER->lastcourseaccess[$course->id])) {
|
|
|
|
if ($USER->lastcourseaccess[$course->id] > $timestart) {
|
|
|
|
$timestart = $USER->lastcourseaccess[$course->id];
|
|
|
|
}
|
2004-05-15 14:58:12 +00:00
|
|
|
}
|
2003-04-26 12:17:30 +00:00
|
|
|
}
|
2004-02-23 18:05:59 +00:00
|
|
|
|
2004-10-08 13:34:48 +00:00
|
|
|
echo '<div class="activitydate">';
|
2005-03-10 14:09:45 +00:00
|
|
|
echo get_string('activitysince', '', userdate($timestart));
|
2004-10-08 13:34:48 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '<div class="activityhead">';
|
2004-02-23 18:05:59 +00:00
|
|
|
|
2004-10-08 13:34:48 +00:00
|
|
|
echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
|
2004-02-23 18:05:59 +00:00
|
|
|
|
2006-05-16 10:59:27 +00:00
|
|
|
echo "</div>\n";
|
2004-02-23 18:05:59 +00:00
|
|
|
|
2002-05-31 09:34:50 +00:00
|
|
|
|
|
|
|
// Firstly, have there been any new enrolments?
|
|
|
|
|
|
|
|
$heading = false;
|
|
|
|
$content = false;
|
2003-04-26 15:08:34 +00:00
|
|
|
|
2003-08-17 01:46:00 +00:00
|
|
|
$users = get_recent_enrolments($course->id, $timestart);
|
2003-04-26 15:08:34 +00:00
|
|
|
|
2006-05-16 10:59:27 +00:00
|
|
|
//Accessibility: new users now appear in an <OL> list.
|
2003-08-17 01:46:00 +00:00
|
|
|
if ($users) {
|
2005-03-10 14:09:45 +00:00
|
|
|
echo '<div class="newusers">';
|
2006-05-16 10:59:27 +00:00
|
|
|
if (! $heading) {
|
2006-11-09 18:25:58 +00:00
|
|
|
print_headline(get_string("newusers").':', 3);
|
2006-05-16 10:59:27 +00:00
|
|
|
$heading = true;
|
|
|
|
$content = true;
|
|
|
|
}
|
|
|
|
echo "<ol class=\"list\">\n";
|
2003-08-17 01:46:00 +00:00
|
|
|
foreach ($users as $user) {
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-09-11 08:56:23 +00:00
|
|
|
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
|
2006-05-16 10:59:27 +00:00
|
|
|
echo '<li class="name"><a href="'.$CFG->wwwroot."/user/view.php?id=$user->id&course=$course->id\">$fullname</a></li>\n";
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
2006-05-16 10:59:27 +00:00
|
|
|
echo "</ol>\n</div>\n";
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
|
2003-04-26 15:08:34 +00:00
|
|
|
// Next, have there been any modifications to the course structure?
|
|
|
|
|
2005-03-10 14:09:45 +00:00
|
|
|
$logs = get_records_select('log', "time > '$timestart' AND course = '$course->id' AND
|
2003-04-26 15:08:34 +00:00
|
|
|
module = 'course' AND action LIKE '% mod'", "time ASC");
|
|
|
|
|
|
|
|
if ($logs) {
|
|
|
|
foreach ($logs as $key => $log) {
|
2005-03-10 14:09:45 +00:00
|
|
|
$info = split(' ', $log->info);
|
2003-09-14 12:25:16 +00:00
|
|
|
|
2005-03-10 14:09:45 +00:00
|
|
|
if ($info[0] == 'label') { // Labels are special activities
|
2003-09-14 12:25:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-03-10 14:09:45 +00:00
|
|
|
$modname = get_field($info[0], 'name', 'id', $info[1]);
|
2003-04-26 15:08:34 +00:00
|
|
|
//Create a temp valid module structure (course,id)
|
|
|
|
$tempmod->course = $log->course;
|
|
|
|
$tempmod->id = $info[1];
|
|
|
|
//Obtain the visible property from the instance
|
|
|
|
$modvisible = instance_is_visible($info[0],$tempmod);
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2003-04-26 15:08:34 +00:00
|
|
|
//Only if the mod is visible
|
|
|
|
if ($modvisible) {
|
|
|
|
switch ($log->action) {
|
2005-03-10 14:09:45 +00:00
|
|
|
case 'add mod':
|
|
|
|
$stradded = get_string('added', 'moodle', get_string('modulename', $info[0]));
|
2005-03-26 11:49:01 +00:00
|
|
|
$changelist[$log->info] = array ('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/course/$log->url\">".format_string($modname,true)."</a>");
|
2003-04-26 15:08:34 +00:00
|
|
|
break;
|
2005-03-10 14:09:45 +00:00
|
|
|
case 'update mod':
|
|
|
|
$strupdated = get_string('updated', 'moodle', get_string('modulename', $info[0]));
|
|
|
|
if (empty($changelist[$log->info])) {
|
2005-03-26 11:49:01 +00:00
|
|
|
$changelist[$log->info] = array ('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/course/$log->url\">".format_string($modname,true)."</a>");
|
2003-04-26 15:08:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-03-10 14:09:45 +00:00
|
|
|
case 'delete mod':
|
|
|
|
if (!empty($changelist[$log->info]['operation']) and
|
|
|
|
$changelist[$log->info]['operation'] == 'add') {
|
|
|
|
$changelist[$log->info] = NULL;
|
2003-04-26 15:08:34 +00:00
|
|
|
} else {
|
2005-03-10 14:09:45 +00:00
|
|
|
$strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $info[0]));
|
|
|
|
$changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
|
2003-04-26 15:08:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
2002-06-01 09:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-29 17:32:32 +00:00
|
|
|
if (!empty($changelist)) {
|
2002-06-01 09:23:37 +00:00
|
|
|
foreach ($changelist as $changeinfo => $change) {
|
|
|
|
if ($change) {
|
|
|
|
$changes[$changeinfo] = $change;
|
|
|
|
}
|
|
|
|
}
|
2003-10-22 16:19:21 +00:00
|
|
|
if (isset($changes)){
|
|
|
|
if (count($changes) > 0) {
|
2005-03-10 14:09:45 +00:00
|
|
|
print_headline(get_string('courseupdates').':', 3);
|
2003-10-22 16:19:21 +00:00
|
|
|
$content = true;
|
|
|
|
foreach ($changes as $changeinfo => $change) {
|
2005-03-10 14:09:45 +00:00
|
|
|
echo '<p class="activity">'.$change['text'].'</p>';
|
2003-10-22 16:19:21 +00:00
|
|
|
}
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
2003-08-26 18:45:54 +00:00
|
|
|
|
2002-09-21 17:11:08 +00:00
|
|
|
// Now display new things from each module
|
2002-05-31 09:34:50 +00:00
|
|
|
|
2005-03-10 14:09:45 +00:00
|
|
|
$mods = get_records('modules', 'visible', '1', 'name', 'id, name');
|
2003-11-21 12:54:09 +00:00
|
|
|
|
2006-10-24 14:37:04 +00:00
|
|
|
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
|
|
|
|
2003-04-26 15:08:34 +00:00
|
|
|
foreach ($mods as $mod) { // Each module gets it's own logs and prints them
|
2005-03-10 14:09:45 +00:00
|
|
|
include_once($CFG->dirroot.'/mod/'.$mod->name.'/lib.php');
|
|
|
|
$print_recent_activity = $mod->name.'_print_recent_activity';
|
2003-04-26 15:08:34 +00:00
|
|
|
if (function_exists($print_recent_activity)) {
|
2006-09-22 09:11:46 +00:00
|
|
|
//
|
|
|
|
// NOTE:
|
2006-10-24 14:37:04 +00:00
|
|
|
// $isteacher (second parameter below) is to be deprecated!
|
2006-09-22 09:11:46 +00:00
|
|
|
//
|
|
|
|
// TODO:
|
2006-09-24 14:03:34 +00:00
|
|
|
// 1) Make sure that all _print_recent_activity functions are
|
|
|
|
// not using the $isteacher value.
|
|
|
|
// 2) Eventually, remove the $isteacher parameter from the
|
|
|
|
// function calls.
|
2006-09-22 09:11:46 +00:00
|
|
|
//
|
2006-10-24 14:37:04 +00:00
|
|
|
$modcontent = $print_recent_activity($course, $viewfullnames, $timestart);
|
2002-09-21 17:11:08 +00:00
|
|
|
if ($modcontent) {
|
|
|
|
$content = true;
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $content) {
|
2005-03-10 14:09:45 +00:00
|
|
|
echo '<p class="message">'.get_string('nothingnew').'</p>';
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-04 06:30:51 +00:00
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
function get_array_of_activities($courseid) {
|
2004-05-28 10:53:54 +00:00
|
|
|
// For a given course, returns an array of course activity objects
|
2002-11-10 07:37:15 +00:00
|
|
|
// 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
|
2003-05-09 17:24:17 +00:00
|
|
|
// visible - is the instance visible or not
|
2003-07-20 13:53:31 +00:00
|
|
|
// extra - contains extra string to include in any link
|
2002-11-10 07:37:15 +00:00
|
|
|
|
2003-10-22 13:14:56 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
$mod = array();
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if (!$rawmods = get_course_mods($courseid)) {
|
2002-11-10 07:37:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) {
|
|
|
|
foreach ($sections as $section) {
|
2003-03-21 04:53:08 +00:00
|
|
|
if (!empty($section->sequence)) {
|
2002-11-10 07:37:15 +00:00
|
|
|
$sequence = explode(",", $section->sequence);
|
|
|
|
foreach ($sequence as $seq) {
|
2003-01-14 14:56:57 +00:00
|
|
|
if (empty($rawmods[$seq])) {
|
|
|
|
continue;
|
|
|
|
}
|
2002-11-10 07:37:15 +00:00
|
|
|
$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));
|
2003-04-23 16:37:37 +00:00
|
|
|
$mod[$seq]->visible = $rawmods[$seq]->visible;
|
2003-07-20 13:53:31 +00:00
|
|
|
$mod[$seq]->extra = "";
|
2003-10-22 13:14:56 +00:00
|
|
|
|
|
|
|
$modname = $mod[$seq]->mod;
|
|
|
|
$functionname = $modname."_get_coursemodule_info";
|
|
|
|
|
|
|
|
include_once("$CFG->dirroot/mod/$modname/lib.php");
|
|
|
|
|
|
|
|
if (function_exists($functionname)) {
|
2004-04-26 15:31:22 +00:00
|
|
|
if ($info = $functionname($rawmods[$seq])) {
|
|
|
|
if (!empty($info->extra)) {
|
|
|
|
$mod[$seq]->extra = $info->extra;
|
|
|
|
}
|
|
|
|
if (!empty($info->icon)) {
|
|
|
|
$mod[$seq]->icon = $info->icon;
|
|
|
|
}
|
2003-09-14 12:25:16 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-10 07:37:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-04 06:30:51 +00:00
|
|
|
|
2002-08-02 17:38:18 +00:00
|
|
|
function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
|
|
|
|
// Returns a number of useful structures for course displays
|
2002-07-23 16:24:12 +00:00
|
|
|
|
2002-08-02 17:38:18 +00:00
|
|
|
$mods = NULL; // course modules indexed by id
|
2004-07-25 14:00:29 +00:00
|
|
|
$modnames = NULL; // all course module names (except resource!)
|
2002-08-03 08:16:31 +00:00
|
|
|
$modnamesplural= NULL; // all course module names (plural form)
|
2002-08-02 17:38:18 +00:00
|
|
|
$modnamesused = NULL; // course module names used
|
2002-07-23 16:24:12 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($allmods = get_records("modules")) {
|
2002-08-02 17:38:18 +00:00
|
|
|
foreach ($allmods as $mod) {
|
2003-05-09 17:24:17 +00:00
|
|
|
if ($mod->visible) {
|
|
|
|
$modnames[$mod->name] = get_string("modulename", "$mod->name");
|
|
|
|
$modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name");
|
|
|
|
}
|
2002-08-02 17:38:18 +00:00
|
|
|
}
|
|
|
|
asort($modnames);
|
|
|
|
} else {
|
|
|
|
error("No modules are installed!");
|
|
|
|
}
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($rawmods = get_course_mods($courseid)) {
|
2002-07-23 16:24:12 +00:00
|
|
|
foreach($rawmods as $mod) { // Index the mods
|
2005-04-19 12:40:00 +00:00
|
|
|
if (empty($modnames[$mod->modname])) {
|
|
|
|
continue;
|
|
|
|
}
|
2002-07-23 16:24:12 +00:00
|
|
|
$mods[$mod->id] = $mod;
|
2005-04-19 12:40:00 +00:00
|
|
|
$mods[$mod->id]->modfullname = $modnames[$mod->modname];
|
2006-09-05 08:50:23 +00:00
|
|
|
if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
|
2005-04-19 12:40:00 +00:00
|
|
|
$modnamesused[$mod->modname] = $modnames[$mod->modname];
|
2003-04-14 15:11:09 +00:00
|
|
|
}
|
2002-07-23 16:24:12 +00:00
|
|
|
}
|
2003-04-22 20:46:12 +00:00
|
|
|
if ($modnamesused) {
|
|
|
|
asort($modnamesused);
|
|
|
|
}
|
2002-07-23 16:24:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2002-07-23 16:24:12 +00:00
|
|
|
function get_all_sections($courseid) {
|
2004-05-28 10:53:54 +00:00
|
|
|
|
|
|
|
return get_records("course_sections", "course", "$courseid", "section",
|
2003-05-04 07:59:46 +00:00
|
|
|
"section, id, course, summary, sequence, visible");
|
2002-07-23 16:24:12 +00:00
|
|
|
}
|
|
|
|
|
2003-04-28 13:29:26 +00:00
|
|
|
function course_set_display($courseid, $display=0) {
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
if ($display == "all" or empty($display)) {
|
|
|
|
$display = 0;
|
|
|
|
}
|
|
|
|
|
2006-12-04 09:02:17 +00:00
|
|
|
if (empty($USER->id) or $USER->username == 'guest') {
|
|
|
|
//do not store settings in db for guests
|
|
|
|
} else if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) {
|
2003-04-28 13:29:26 +00:00
|
|
|
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 ==
|
|
|
|
}
|
|
|
|
|
2003-05-04 07:59:46 +00:00
|
|
|
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) {
|
2006-04-12 03:11:34 +00:00
|
|
|
set_coursemodule_visible($moduleid, $visibility, true);
|
2003-05-04 07:59:46 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-09 17:24:17 +00:00
|
|
|
rebuild_course_cache($courseid);
|
2003-05-04 07:59:46 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-09 11:48:11 +00:00
|
|
|
|
2002-12-09 07:35:40 +00:00
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") {
|
2003-07-12 06:52:26 +00:00
|
|
|
/// Prints a section full of activity modules
|
2003-07-14 13:08:38 +00:00
|
|
|
global $CFG, $USER;
|
|
|
|
|
2004-01-31 08:40:38 +00:00
|
|
|
static $groupbuttons;
|
2004-02-15 04:13:25 +00:00
|
|
|
static $groupbuttonslink;
|
2003-07-12 06:52:26 +00:00
|
|
|
static $isteacher;
|
|
|
|
static $isediting;
|
2003-07-14 13:08:38 +00:00
|
|
|
static $ismoving;
|
|
|
|
static $strmovehere;
|
|
|
|
static $strmovefull;
|
2005-01-29 09:56:42 +00:00
|
|
|
static $strunreadpostsone;
|
2003-07-12 06:52:26 +00:00
|
|
|
|
2005-04-24 13:41:46 +00:00
|
|
|
static $untracked;
|
2005-04-26 15:44:39 +00:00
|
|
|
static $usetracking;
|
2005-04-24 13:41:46 +00:00
|
|
|
|
2004-09-06 07:55:29 +00:00
|
|
|
$labelformatoptions = New stdClass;
|
2004-02-15 03:20:51 +00:00
|
|
|
|
2003-07-12 06:52:26 +00:00
|
|
|
if (!isset($isteacher)) {
|
2004-08-12 11:23:47 +00:00
|
|
|
$groupbuttons = ($course->groupmode or (!$course->groupmodeforce));
|
2004-02-15 04:13:25 +00:00
|
|
|
$groupbuttonslink = (!$course->groupmodeforce);
|
2003-07-12 06:52:26 +00:00
|
|
|
$isediting = isediting($course->id);
|
2005-02-12 12:49:46 +00:00
|
|
|
$ismoving = $isediting && ismoving($course->id);
|
2004-01-31 08:40:38 +00:00
|
|
|
if ($ismoving) {
|
|
|
|
$strmovehere = get_string("movehere");
|
|
|
|
$strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
|
|
|
|
}
|
2005-04-26 16:34:49 +00:00
|
|
|
include_once($CFG->dirroot.'/mod/forum/lib.php');
|
|
|
|
if ($usetracking = forum_tp_can_track_forums()) {
|
2005-04-26 15:44:39 +00:00
|
|
|
$strunreadpostsone = get_string('unreadpostsone', 'forum');
|
2005-04-26 16:34:49 +00:00
|
|
|
$untracked = forum_tp_get_untracked_forums($USER->id, $course->id);
|
2005-04-26 15:44:39 +00:00
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2004-10-20 23:26:49 +00:00
|
|
|
$labelformatoptions->noclean = true;
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2006-09-04 21:12:37 +00:00
|
|
|
/// Casting $course->modinfo to string prevents one notice when the field is null
|
|
|
|
$modinfo = unserialize((string)$course->modinfo);
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2006-03-27 16:21:56 +00:00
|
|
|
//Acccessibility: replace table with list <ul>, but don't output empty list.
|
2003-03-21 04:53:08 +00:00
|
|
|
if (!empty($section->sequence)) {
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2006-04-13 16:07:12 +00:00
|
|
|
// Fix bug #5027, don't want style=\"width:$width\".
|
|
|
|
echo "<ul class=\"section\">\n";
|
2002-08-03 08:16:31 +00:00
|
|
|
$sectionmods = explode(",", $section->sequence);
|
|
|
|
|
|
|
|
foreach ($sectionmods as $modnumber) {
|
2003-01-13 14:11:05 +00:00
|
|
|
if (empty($mods[$modnumber])) {
|
|
|
|
continue;
|
|
|
|
}
|
2002-08-03 08:16:31 +00:00
|
|
|
$mod = $mods[$modnumber];
|
2003-09-14 12:25:16 +00:00
|
|
|
|
2006-09-05 08:50:23 +00:00
|
|
|
if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
2006-08-25 07:09:28 +00:00
|
|
|
echo '<li class="activity '.$mod->modname.'" id="module-'.$modnumber.'">'; // Unique ID
|
2003-07-14 13:08:38 +00:00
|
|
|
if ($ismoving) {
|
|
|
|
if ($mod->id == $USER->activitycopy) {
|
|
|
|
continue;
|
|
|
|
}
|
2004-09-08 19:24:38 +00:00
|
|
|
echo '<a title="'.$strmovefull.'"'.
|
2004-10-09 17:23:28 +00:00
|
|
|
' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&sesskey='.$USER->sesskey.'">'.
|
2005-02-12 12:40:04 +00:00
|
|
|
'<img class="movetarget" src="'.$CFG->pixpath.'/movehere.gif" '.
|
|
|
|
' alt="'.$strmovehere.'" /></a><br />
|
2004-09-08 19:24:38 +00:00
|
|
|
';
|
2003-04-14 15:11:09 +00:00
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
$instancename = urldecode($modinfo[$modnumber]->name);
|
2006-08-25 07:09:28 +00:00
|
|
|
$instancename = format_string($instancename, true, $course->id);
|
2003-09-14 12:25:16 +00:00
|
|
|
|
2003-07-20 13:53:31 +00:00
|
|
|
if (!empty($modinfo[$modnumber]->extra)) {
|
|
|
|
$extra = urldecode($modinfo[$modnumber]->extra);
|
|
|
|
} else {
|
|
|
|
$extra = "";
|
|
|
|
}
|
2003-09-14 12:25:16 +00:00
|
|
|
|
2004-04-26 15:31:22 +00:00
|
|
|
if (!empty($modinfo[$modnumber]->icon)) {
|
|
|
|
$icon = "$CFG->pixpath/".urldecode($modinfo[$modnumber]->icon);
|
|
|
|
} else {
|
|
|
|
$icon = "$CFG->modpixpath/$mod->modname/icon.gif";
|
|
|
|
}
|
|
|
|
|
2003-09-14 16:31:33 +00:00
|
|
|
if ($mod->indent) {
|
|
|
|
print_spacer(12, 20 * $mod->indent, false);
|
|
|
|
}
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
if ($mod->modname == "label") {
|
2003-09-14 16:31:33 +00:00
|
|
|
if (!$mod->visible) {
|
|
|
|
echo "<span class=\"dimmed_text\">";
|
|
|
|
}
|
2004-09-03 12:44:11 +00:00
|
|
|
echo format_text($extra, FORMAT_HTML, $labelformatoptions);
|
2003-09-14 16:31:33 +00:00
|
|
|
if (!$mod->visible) {
|
|
|
|
echo "</span>";
|
|
|
|
}
|
2003-09-14 12:25:16 +00:00
|
|
|
|
|
|
|
} else { // Normal activity
|
2006-11-28 02:22:17 +00:00
|
|
|
|
2007-01-04 21:39:47 +00:00
|
|
|
if (!empty($USER->screenreader)) {
|
2006-11-28 02:22:17 +00:00
|
|
|
$typestring = '('.get_string('modulename',$mod->modname).') ';
|
|
|
|
} else {
|
|
|
|
$typestring = '';
|
|
|
|
}
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
$linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
|
2004-09-08 19:24:38 +00:00
|
|
|
echo '<img src="'.$icon.'"'.
|
2005-02-12 12:40:04 +00:00
|
|
|
' class="activityicon" alt="'.$mod->modfullname.'" />'.
|
|
|
|
' <a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
|
2004-09-08 19:24:38 +00:00
|
|
|
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
|
2006-11-28 02:22:17 +00:00
|
|
|
$typestring.$instancename.'</a>';
|
2003-09-14 12:25:16 +00:00
|
|
|
}
|
2005-04-26 15:44:39 +00:00
|
|
|
if ($usetracking && $mod->modname == 'forum') {
|
2005-01-29 09:49:42 +00:00
|
|
|
$groupmode = groupmode($course, $mod);
|
2006-09-05 08:50:23 +00:00
|
|
|
$groupid = ($groupmode == SEPARATEGROUPS && !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) ?
|
2005-04-26 15:44:39 +00:00
|
|
|
get_current_group($course->id) : false;
|
2005-04-24 13:41:46 +00:00
|
|
|
|
2005-04-26 16:34:49 +00:00
|
|
|
if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) {
|
2005-04-24 13:41:46 +00:00
|
|
|
$unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid);
|
|
|
|
if ($unread) {
|
|
|
|
echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">';
|
|
|
|
if ($unread == 1) {
|
|
|
|
echo $strunreadpostsone;
|
|
|
|
} else {
|
|
|
|
print_string('unreadpostsnumber', 'forum', $unread);
|
|
|
|
}
|
|
|
|
echo '</a> </span>';
|
2005-01-30 04:47:09 +00:00
|
|
|
}
|
2005-01-29 09:56:42 +00:00
|
|
|
}
|
2005-01-29 09:49:42 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
if ($isediting) {
|
2005-02-16 12:50:11 +00:00
|
|
|
if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource') {
|
2004-02-15 04:13:25 +00:00
|
|
|
if (! $mod->groupmodelink = $groupbuttonslink) {
|
|
|
|
$mod->groupmode = $course->groupmode;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2004-01-31 08:40:38 +00:00
|
|
|
$mod->groupmode = false;
|
|
|
|
}
|
2005-03-14 19:05:39 +00:00
|
|
|
echo ' ';
|
2005-03-05 05:19:26 +00:00
|
|
|
echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
|
2003-09-14 12:25:16 +00:00
|
|
|
}
|
2006-03-27 16:21:56 +00:00
|
|
|
echo "</li>\n";
|
2002-08-03 08:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-13 16:07:12 +00:00
|
|
|
} elseif ($ismoving) {
|
|
|
|
echo "<ul class=\"section\">\n";
|
2006-11-09 18:25:58 +00:00
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
if ($ismoving) {
|
2006-04-13 09:44:33 +00:00
|
|
|
echo '<li><a title="'.$strmovefull.'"'.
|
2004-10-09 17:23:28 +00:00
|
|
|
' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&sesskey='.$USER->sesskey.'">'.
|
2005-02-12 12:40:04 +00:00
|
|
|
'<img class="movetarget" src="'.$CFG->pixpath.'/movehere.gif" '.
|
2006-03-27 16:21:56 +00:00
|
|
|
' alt="'.$strmovehere.'" /></a></li>
|
2004-09-08 19:24:38 +00:00
|
|
|
';
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2006-03-27 16:21:56 +00:00
|
|
|
if (!empty($section->sequence) || $ismoving) {
|
|
|
|
echo "</ul><!--class='section'-->\n\n";
|
|
|
|
}
|
2002-08-04 13:25:53 +00:00
|
|
|
}
|
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
/**
|
|
|
|
* Prints the menus to add activities and resources.
|
|
|
|
*/
|
2004-07-26 16:05:09 +00:00
|
|
|
function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false) {
|
2007-01-02 09:33:07 +00:00
|
|
|
global $CFG;
|
2004-07-25 14:00:29 +00:00
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
static $resources = false;
|
|
|
|
static $activities = false;
|
2004-07-25 14:00:29 +00:00
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
if ($resources === false) {
|
|
|
|
$resources = array();
|
|
|
|
$activities = array();
|
2004-08-02 19:11:15 +00:00
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
foreach($modnames as $modname=>$modnamestr) {
|
|
|
|
if (!course_allowed_module($course, $modname)) {
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-02 19:11:15 +00:00
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
require_once("$CFG->dirroot/mod/$modname/lib.php");
|
|
|
|
$gettypesfunc = $modname.'_get_types';
|
|
|
|
if (function_exists($gettypesfunc)) {
|
|
|
|
$types = $gettypesfunc();
|
|
|
|
foreach($types as $type) {
|
|
|
|
if ($type->modclass == MOD_CLASS_RESOURCE) {
|
|
|
|
$resources[$type->type] = $type->typestr;
|
|
|
|
} else {
|
|
|
|
$activities[$type->type] = $type->typestr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// all mods without type are considered activity
|
|
|
|
$activities[$modname] = $modnamestr;
|
|
|
|
}
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
2004-07-25 14:00:29 +00:00
|
|
|
}
|
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
$straddactivity = get_string('addactivity');
|
|
|
|
$straddresource = get_string('addresource');
|
|
|
|
|
2007-01-04 12:44:58 +00:00
|
|
|
$output = '<div class="section_add_menus">';
|
|
|
|
|
|
|
|
if (!$vertical) {
|
|
|
|
$output .= '<div class="horizontal">';
|
|
|
|
}
|
2007-01-02 09:33:07 +00:00
|
|
|
|
|
|
|
if (!empty($resources)) {
|
|
|
|
$output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=".sesskey()."&add=",
|
2005-08-16 06:15:49 +00:00
|
|
|
$resources, "ressection$section", "", $straddresource, 'resource/types', $straddresource, true);
|
|
|
|
}
|
2004-07-26 16:05:09 +00:00
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
if (!empty($activities)) {
|
|
|
|
$output .= ' ';
|
|
|
|
$output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=".sesskey()."&add=",
|
|
|
|
$activities, "section$section", "", $straddactivity, 'mods', $straddactivity, true);
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
|
|
|
|
2007-01-04 12:44:58 +00:00
|
|
|
if (!$vertical) {
|
2005-05-10 00:31:32 +00:00
|
|
|
$output .= '</div>';
|
|
|
|
}
|
|
|
|
|
2004-07-26 16:05:09 +00:00
|
|
|
$output .= '</div>';
|
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
2004-07-25 14:00:29 +00:00
|
|
|
}
|
|
|
|
|
2003-05-09 17:24:17 +00:00
|
|
|
function rebuild_course_cache($courseid=0) {
|
|
|
|
// Rebuilds the cached list of course activities stored in the database
|
|
|
|
// If a courseid is not specified, then all are rebuilt
|
|
|
|
|
|
|
|
if ($courseid) {
|
|
|
|
$select = "id = '$courseid'";
|
|
|
|
} else {
|
|
|
|
$select = "";
|
|
|
|
}
|
|
|
|
|
2004-11-22 05:46:18 +00:00
|
|
|
if ($courses = get_records_select("course", $select,'','id,fullname')) {
|
2003-05-09 17:24:17 +00:00
|
|
|
foreach ($courses as $course) {
|
|
|
|
$modinfo = serialize(get_array_of_activities($course->id));
|
|
|
|
if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
|
|
|
|
notify("Could not cache module information for course '$course->fullname'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
function make_categories_list(&$list, &$parents, $category=NULL, $path="") {
|
2004-05-28 10:53:54 +00:00
|
|
|
/// Given an empty array, this function recursively travels the
|
2003-07-30 13:02:45 +00:00
|
|
|
/// categories, building up a nice list for display. It also makes
|
|
|
|
/// an array that list all the parents for each category.
|
|
|
|
|
2005-09-06 22:29:16 +00:00
|
|
|
// initialize the arrays if needed
|
|
|
|
if (!is_array($list)) {
|
2006-11-09 18:25:58 +00:00
|
|
|
$list = array();
|
2005-09-06 22:29:16 +00:00
|
|
|
}
|
|
|
|
if (!is_array($parents)) {
|
2006-11-09 18:25:58 +00:00
|
|
|
$parents = array();
|
2005-09-06 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
if ($category) {
|
|
|
|
if ($path) {
|
2005-01-11 07:56:45 +00:00
|
|
|
$path = $path.' / '.$category->name;
|
2003-07-30 13:02:45 +00:00
|
|
|
} else {
|
2005-01-11 07:56:45 +00:00
|
|
|
$path = $category->name;
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
$list[$category->id] = $path;
|
|
|
|
} else {
|
|
|
|
$category->id = 0;
|
|
|
|
}
|
|
|
|
|
2005-01-11 07:56:45 +00:00
|
|
|
if ($categories = get_categories($category->id)) { // Print all the children recursively
|
2003-07-30 13:02:45 +00:00
|
|
|
foreach ($categories as $cat) {
|
|
|
|
if (!empty($category->id)) {
|
2003-09-20 17:33:55 +00:00
|
|
|
if (isset($parents[$category->id])) {
|
2003-09-20 17:08:45 +00:00
|
|
|
$parents[$cat->id] = $parents[$category->id];
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
$parents[$cat->id][] = $category->id;
|
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
make_categories_list($list, $parents, $cat, $path);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-19 13:16:57 +00:00
|
|
|
function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $files = true) {
|
2004-05-28 10:53:54 +00:00
|
|
|
/// Recursive function to print out all the categories in a nice format
|
2003-07-30 13:02:45 +00:00
|
|
|
/// with or without courses included
|
2004-04-05 03:13:10 +00:00
|
|
|
global $CFG;
|
2005-01-11 07:56:45 +00:00
|
|
|
|
|
|
|
if (isset($CFG->max_category_depth) && ($depth >= $CFG->max_category_depth)) {
|
|
|
|
return;
|
2004-04-05 03:13:10 +00:00
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
if (!$displaylist) {
|
2003-07-31 12:23:49 +00:00
|
|
|
make_categories_list($displaylist, $parentslist);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($category) {
|
2006-09-07 08:57:56 +00:00
|
|
|
if ($category->visible or has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
2006-07-19 12:10:07 +00:00
|
|
|
print_category_info($category, $depth, $files);
|
2003-07-30 13:02:45 +00:00
|
|
|
} else {
|
|
|
|
return; // Don't bother printing children of invisible categories
|
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
} 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;
|
|
|
|
|
2006-07-19 12:10:07 +00:00
|
|
|
print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1, $files);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
// this function will return $options array for choose_from_menu, with whitespace to denote nesting.
|
|
|
|
|
|
|
|
function make_categories_options() {
|
|
|
|
make_categories_list($cats,$parents);
|
|
|
|
foreach ($cats as $key => $value) {
|
|
|
|
if (array_key_exists($key,$parents)) {
|
|
|
|
if ($indent = count($parents[$key])) {
|
|
|
|
for ($i = 0; $i < $indent; $i++) {
|
|
|
|
$cats[$key] = ' '.$cats[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $cats;
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2006-07-19 12:10:07 +00:00
|
|
|
function print_category_info($category, $depth, $files = false) {
|
2003-08-07 16:01:31 +00:00
|
|
|
/// Prints the category info in indented fashion
|
|
|
|
/// This function is only used by print_whole_category_list() above
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
global $CFG;
|
2003-09-03 12:13:08 +00:00
|
|
|
static $strallowguests, $strrequireskey, $strsummary;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-09-03 12:13:08 +00:00
|
|
|
if (empty($strsummary)) {
|
2005-01-11 07:56:45 +00:00
|
|
|
$strallowguests = get_string('allowguests');
|
|
|
|
$strrequireskey = get_string('requireskey');
|
|
|
|
$strsummary = get_string('summary');
|
2003-09-03 12:13:08 +00:00
|
|
|
}
|
2002-09-09 11:48:11 +00:00
|
|
|
|
2005-01-11 07:56:45 +00:00
|
|
|
$catlinkcss = $category->visible ? '' : ' class="dimmed" ';
|
2003-08-29 01:31:41 +00:00
|
|
|
|
2006-07-19 12:10:07 +00:00
|
|
|
$coursecount = count_records('course') <= FRONTPAGECOURSELIMIT;
|
|
|
|
if ($files and $coursecount) {
|
2007-01-05 14:13:26 +00:00
|
|
|
$catimage = '<img src="'.$CFG->pixpath.'/i/course.gif" alt="" />';
|
2003-09-03 12:13:08 +00:00
|
|
|
} else {
|
2006-01-16 03:01:28 +00:00
|
|
|
$catimage = " ";
|
2003-08-21 09:33:07 +00:00
|
|
|
}
|
2003-09-03 12:13:08 +00:00
|
|
|
|
2007-01-05 14:13:26 +00:00
|
|
|
echo "\n\n".'<table class="categorylist">';
|
2003-08-07 16:01:31 +00:00
|
|
|
|
2006-07-19 12:10:07 +00:00
|
|
|
if ($files and $coursecount) {
|
2005-08-09 15:09:29 +00:00
|
|
|
$courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.guest,c.cost,c.currency');
|
2003-09-03 12:13:08 +00:00
|
|
|
|
2006-09-24 06:06:24 +00:00
|
|
|
echo '<tr>';
|
2003-09-03 12:13:08 +00:00
|
|
|
|
|
|
|
if ($depth) {
|
|
|
|
$indent = $depth*30;
|
|
|
|
$rows = count($courses) + 1;
|
2004-09-08 19:24:38 +00:00
|
|
|
echo '<td rowspan="'.$rows.'" valign="top" width="'.$indent.'">';
|
2003-09-03 12:13:08 +00:00
|
|
|
print_spacer(10, $indent);
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '</td>';
|
2003-09-03 12:13:08 +00:00
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '<td valign="top">'.$catimage.'</td>';
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<td valign="top" class="category name">';
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.$category->name.'</a>';
|
|
|
|
echo '</td>';
|
2005-03-28 06:47:54 +00:00
|
|
|
echo '<td class="category info"> </td>';
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '</tr>';
|
2003-09-03 12:13:08 +00:00
|
|
|
|
2004-04-05 03:13:10 +00:00
|
|
|
if ($courses && !(isset($CFG->max_category_depth)&&($depth>=$CFG->max_category_depth-1))) {
|
2003-07-30 13:02:45 +00:00
|
|
|
foreach ($courses as $course) {
|
2005-01-11 07:56:45 +00:00
|
|
|
$linkcss = $course->visible ? '' : ' class="dimmed" ';
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<tr><td valign="top"> ';
|
|
|
|
echo '</td><td valign="top" class="course name">';
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '<a '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a>';
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '</td><td align="right" valign="top" class="course info">';
|
2003-07-30 13:02:45 +00:00
|
|
|
if ($course->guest ) {
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '<a title="'.$strallowguests.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">';
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<img alt="'.$strallowguests.'" src="'.$CFG->pixpath.'/i/guest.gif" /></a>';
|
2003-09-10 08:53:43 +00:00
|
|
|
} else {
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<img alt="" style="width:18px;height:16px;" src="'.$CFG->pixpath.'/spacer.gif" />';
|
2002-09-10 13:47:56 +00:00
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
if ($course->password) {
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '<a title="'.$strrequireskey.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">';
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<img alt="'.$strrequireskey.'" src="'.$CFG->pixpath.'/i/key.gif" /></a>';
|
2003-09-10 08:53:43 +00:00
|
|
|
} else {
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<img alt="" style="width:18px;height:16px;" src="'.$CFG->pixpath.'/spacer.gif" />';
|
2003-09-03 12:13:08 +00:00
|
|
|
}
|
|
|
|
if ($course->summary) {
|
2005-01-11 07:56:45 +00:00
|
|
|
link_to_popup_window ('/course/info.php?id='.$course->id, 'courseinfo',
|
2007-01-05 14:13:26 +00:00
|
|
|
'<img alt="'.$strsummary.'" src="'.$CFG->pixpath.'/i/info.gif" />',
|
2003-09-03 12:13:08 +00:00
|
|
|
400, 500, $strsummary);
|
2003-09-10 08:53:43 +00:00
|
|
|
} else {
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<img alt="" style="width:18px;height:16px;" src="'.$CFG->pixpath.'/spacer.gif" />';
|
2002-09-10 13:47:56 +00:00
|
|
|
}
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '</td></tr>';
|
2002-09-10 13:47:56 +00:00
|
|
|
}
|
2002-09-09 11:48:11 +00:00
|
|
|
}
|
2003-08-07 16:01:31 +00:00
|
|
|
} else {
|
2003-09-03 12:13:08 +00:00
|
|
|
|
2006-01-30 22:54:12 +00:00
|
|
|
echo '<tr>';
|
|
|
|
|
2003-09-03 12:13:08 +00:00
|
|
|
if ($depth) {
|
|
|
|
$indent = $depth*20;
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '<td valign="top" width="'.$indent.'">';
|
2003-09-03 12:13:08 +00:00
|
|
|
print_spacer(10, $indent);
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '</td>';
|
2003-08-07 16:01:31 +00:00
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<td valign="top" class="category name">';
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.$category->name.'</a>';
|
|
|
|
echo '</td>';
|
2005-03-28 06:47:54 +00:00
|
|
|
echo '<td valign="top" class="category number">';
|
2005-01-11 07:56:45 +00:00
|
|
|
if ($category->coursecount) {
|
|
|
|
echo $category->coursecount;
|
|
|
|
}
|
|
|
|
echo '</td></tr>';
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '</table>';
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-07 01:13:27 +00:00
|
|
|
function print_courses($category, $width="100%", $hidesitecourse = false) {
|
2003-07-30 13:02:45 +00:00
|
|
|
/// Category is 0 (for all courses) or an object
|
|
|
|
|
2005-01-25 14:03:43 +00:00
|
|
|
global $CFG;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
|
|
|
if (empty($category)) {
|
2003-07-30 13:56:17 +00:00
|
|
|
$categories = get_categories(0); // Parent = 0 ie top-level categories only
|
|
|
|
if (count($categories) == 1) {
|
|
|
|
$category = array_shift($categories);
|
2006-09-12 14:02:15 +00:00
|
|
|
$courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.category,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency,c.enrol,c.guest');
|
2003-07-30 13:56:17 +00:00
|
|
|
} else {
|
2006-09-12 14:02:15 +00:00
|
|
|
$courses = get_courses('all', 'c.sortorder ASC', 'c.id,c.category,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency,c.enrol,c.guest');
|
2003-07-30 13:56:17 +00:00
|
|
|
}
|
|
|
|
unset($categories);
|
2003-01-05 06:45:20 +00:00
|
|
|
} else {
|
2003-07-30 13:02:45 +00:00
|
|
|
$categories = get_categories($category->id); // sub categories
|
2006-09-12 14:02:15 +00:00
|
|
|
$courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.category,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency,c.enrol,c.guest');
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($courses) {
|
|
|
|
foreach ($courses as $course) {
|
2006-11-12 08:55:13 +00:00
|
|
|
if ($hidesitecourse and ($course->id == SITEID)) {
|
2006-02-07 01:13:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
print_course($course, $width);
|
|
|
|
}
|
|
|
|
} else {
|
2006-03-09 02:48:29 +00:00
|
|
|
print_heading(get_string("nocoursesyet"));
|
2006-08-25 07:09:28 +00:00
|
|
|
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('moodle/course:create', $context)) {
|
2006-04-10 15:41:57 +00:00
|
|
|
$options = array();
|
|
|
|
$options['category'] = $category->id;
|
2007-01-09 06:07:35 +00:00
|
|
|
echo '<div class="addcoursebutton">';
|
2006-04-10 15:41:57 +00:00
|
|
|
print_single_button($CFG->wwwroot.'/course/edit.php', $options, get_string("addnewcourse"));
|
|
|
|
echo '</div>';
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_course($course, $width="100%") {
|
|
|
|
|
2005-09-01 04:48:22 +00:00
|
|
|
global $CFG, $USER;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2006-09-16 15:23:41 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2006-09-16 15:23:41 +00:00
|
|
|
$linkcss = $course->visible ? '' : ' class="dimmed" ';
|
2003-08-21 17:30:39 +00:00
|
|
|
|
2007-01-04 15:53:05 +00:00
|
|
|
echo '<div class="coursebox">';
|
|
|
|
echo '<div class="info">';
|
|
|
|
echo '<div class="name"><a title="'.get_string('entercourse').'"'.
|
2004-09-08 21:25:33 +00:00
|
|
|
$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
|
2007-01-04 15:53:05 +00:00
|
|
|
$course->fullname.'</a></div>';
|
2006-11-16 08:29:25 +00:00
|
|
|
|
2006-11-17 08:57:50 +00:00
|
|
|
/// first find all roles that are supposed to be displayed
|
|
|
|
if ($managerroles = get_config('', 'coursemanager')) {
|
|
|
|
$coursemanagerroles = split(',', $managerroles->value);
|
|
|
|
foreach ($coursemanagerroles as $roleid) {
|
|
|
|
$role = get_record('role','id',$roleid);
|
|
|
|
if ($users = get_role_users($roleid, $context, true, '', 'u.lastname ASC', true)) {
|
|
|
|
foreach ($users as $teacher) {
|
|
|
|
$fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
|
|
|
|
$namesarray[] = format_string($role->name).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
|
2006-11-16 08:29:25 +00:00
|
|
|
$teacher->id.'&course='.SITEID.'">'.$fullname.'</a>';
|
2006-11-17 08:57:50 +00:00
|
|
|
}
|
2006-11-16 08:29:25 +00:00
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
2006-11-17 08:57:50 +00:00
|
|
|
|
|
|
|
if (!empty($namesarray)) {
|
2006-09-16 15:23:41 +00:00
|
|
|
echo "<ul class=\"teachers\">\n<li>";
|
|
|
|
echo implode('</li><li>', $namesarray);
|
|
|
|
echo "</li></ul>";
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
2006-11-17 08:57:50 +00:00
|
|
|
|
2006-09-16 15:23:41 +00:00
|
|
|
require_once("$CFG->dirroot/enrol/enrol.class.php");
|
|
|
|
$enrol = enrolment_factory::factory($course->enrol);
|
2004-06-26 09:51:13 +00:00
|
|
|
echo $enrol->get_access_icons($course);
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2007-01-04 15:53:05 +00:00
|
|
|
echo '</div><div class="summary">';
|
2004-09-30 06:46:26 +00:00
|
|
|
$options = NULL;
|
|
|
|
$options->noclean = true;
|
2004-09-30 08:42:34 +00:00
|
|
|
$options->para = false;
|
2004-09-30 06:46:26 +00:00
|
|
|
echo format_text($course->summary, FORMAT_MOODLE, $options, $course->id);
|
2007-01-04 15:53:05 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
|
|
|
echo '<div class="clearer"></div>';
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_my_moodle() {
|
|
|
|
/// Prints custom user information on the home page.
|
|
|
|
/// Over time this can include all sorts of information
|
|
|
|
|
|
|
|
global $USER, $CFG;
|
|
|
|
|
2006-09-02 11:44:04 +00:00
|
|
|
if (empty($USER->id)) {
|
2003-07-30 13:02:45 +00:00
|
|
|
error("It shouldn't be possible to see My Moodle without being logged in.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($courses = get_my_courses($USER->id)) {
|
|
|
|
foreach ($courses as $course) {
|
2006-11-12 08:55:13 +00:00
|
|
|
if ($course->id == SITEID) {
|
2003-08-26 15:55:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
print_course($course, "100%");
|
|
|
|
}
|
2003-08-11 09:45:50 +00:00
|
|
|
|
2003-10-21 02:25:22 +00:00
|
|
|
if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed
|
|
|
|
echo "<table width=\"100%\"><tr><td align=\"center\">";
|
|
|
|
print_course_search("", false, "short");
|
|
|
|
echo "</td><td align=\"center\">";
|
|
|
|
print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
|
|
|
|
echo "</td></tr></table>\n";
|
|
|
|
}
|
2003-08-07 16:41:33 +00:00
|
|
|
} else {
|
|
|
|
if (count_records("course_categories") > 1) {
|
2003-09-03 15:25:08 +00:00
|
|
|
print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox");
|
2003-08-07 16:41:33 +00:00
|
|
|
print_whole_category_list();
|
|
|
|
print_simple_box_end();
|
|
|
|
} else {
|
|
|
|
print_courses(0, "100%");
|
|
|
|
}
|
2003-01-05 06:45:20 +00:00
|
|
|
}
|
2002-07-27 09:44:01 +00:00
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2003-08-19 05:32:20 +00:00
|
|
|
function print_course_search($value="", $return=false, $format="plain") {
|
2003-08-11 09:45:50 +00:00
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$strsearchcourses= get_string("searchcourses");
|
|
|
|
|
2004-09-08 19:24:38 +00:00
|
|
|
if ($format == 'plain') {
|
2007-01-04 21:32:36 +00:00
|
|
|
$output = '<form id="coursesearch" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
|
2007-01-05 14:13:26 +00:00
|
|
|
$output .= '<fieldset class="coursesearchbox invisiblefieldset">';
|
2006-04-14 08:02:32 +00:00
|
|
|
$output .= '<input type="text" size="30" name="search" alt="'.s($strsearchcourses).'" value="'.s($value, true).'" />';
|
2005-11-02 15:36:57 +00:00
|
|
|
$output .= '<input type="submit" value="'.s($strsearchcourses).'" />';
|
2007-01-05 14:13:26 +00:00
|
|
|
$output .= '</fieldset></form>';
|
2004-09-08 19:24:38 +00:00
|
|
|
} else if ($format == 'short') {
|
2007-01-04 21:32:36 +00:00
|
|
|
$output = '<form id="coursesearch" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
|
2007-01-05 14:13:26 +00:00
|
|
|
$output .= '<fieldset class="coursesearchbox invisiblefieldset">';
|
2006-04-14 08:02:32 +00:00
|
|
|
$output .= '<input type="text" size="12" name="search" alt="'.s($strsearchcourses).'" value="'.s($value, true).'" />';
|
2005-11-02 15:36:57 +00:00
|
|
|
$output .= '<input type="submit" value="'.s($strsearchcourses).'" />';
|
2007-01-05 14:13:26 +00:00
|
|
|
$output .= '</fieldset></form>';
|
2004-09-08 19:24:38 +00:00
|
|
|
} else if ($format == 'navbar') {
|
2007-01-05 14:13:26 +00:00
|
|
|
$output = '<form id="coursesearchnavbar" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
|
|
|
|
$output .= '<fieldset class="coursesearchbox invisiblefieldset">';
|
2006-04-14 08:02:32 +00:00
|
|
|
$output .= '<input type="text" size="20" name="search" alt="'.s($strsearchcourses).'" value="'.s($value, true).'" />';
|
2005-11-02 15:36:57 +00:00
|
|
|
$output .= '<input type="submit" value="'.s($strsearchcourses).'" />';
|
2007-01-05 14:13:26 +00:00
|
|
|
$output .= '</fieldset></form>';
|
2003-08-19 05:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
echo $output;
|
2003-08-11 09:45:50 +00:00
|
|
|
}
|
2002-08-01 03:50:27 +00:00
|
|
|
|
|
|
|
/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function add_course_module($mod) {
|
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
$mod->added = time();
|
2004-08-08 15:14:25 +00:00
|
|
|
unset($mod->id);
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
return insert_record("course_modules", $mod);
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 13:08:38 +00:00
|
|
|
function add_mod_to_section($mod, $beforemod=NULL) {
|
|
|
|
/// Given a full mod object with section and course already defined
|
|
|
|
/// If $before is specified, then this is an existing ID which we
|
|
|
|
/// will insert the new module before
|
|
|
|
///
|
|
|
|
/// Returns the course_sections ID where the mod is inserted
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) {
|
2003-07-14 13:08:38 +00:00
|
|
|
|
|
|
|
$section->sequence = trim($section->sequence);
|
|
|
|
|
|
|
|
if (empty($section->sequence)) {
|
2002-08-01 03:50:27 +00:00
|
|
|
$newsequence = "$mod->coursemodule";
|
2003-07-14 13:08:38 +00:00
|
|
|
|
|
|
|
} else if ($beforemod) {
|
|
|
|
$modarray = explode(",", $section->sequence);
|
|
|
|
|
|
|
|
if ($key = array_keys ($modarray, $beforemod->id)) {
|
|
|
|
$insertarray = array($mod->id, $beforemod->id);
|
|
|
|
array_splice($modarray, $key[0], 1, $insertarray);
|
|
|
|
$newsequence = implode(",", $modarray);
|
|
|
|
|
|
|
|
} else { // Just tack it on the end anyway
|
|
|
|
$newsequence = "$section->sequence,$mod->coursemodule";
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$newsequence = "$section->sequence,$mod->coursemodule";
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) {
|
|
|
|
return $section->id; // Return course_sections ID that was used.
|
2002-08-01 03:50:27 +00:00
|
|
|
} else {
|
2002-10-21 03:00:40 +00:00
|
|
|
return 0;
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
} else { // Insert a new record
|
2002-10-21 03:00:40 +00:00
|
|
|
$section->course = $mod->course;
|
|
|
|
$section->section = $mod->section;
|
|
|
|
$section->summary = "";
|
|
|
|
$section->sequence = $mod->coursemodule;
|
|
|
|
return insert_record("course_sections", $section);
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-12 21:41:22 +00:00
|
|
|
function set_coursemodule_groupmode($id, $groupmode) {
|
2004-01-31 08:40:38 +00:00
|
|
|
return set_field("course_modules", "groupmode", $groupmode, "id", $id);
|
|
|
|
}
|
|
|
|
|
2006-04-12 03:11:34 +00:00
|
|
|
/**
|
|
|
|
* $prevstateoverrides = true will set the visibility of the course module
|
|
|
|
* to what is defined in visibleold. This enables us to remember the current
|
|
|
|
* visibility when making a whole section hidden, so that when we toggle
|
|
|
|
* that section back to visible, we are able to return the visibility of
|
|
|
|
* the course module back to what it was originally.
|
|
|
|
*/
|
|
|
|
function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) {
|
2006-09-24 06:06:24 +00:00
|
|
|
if (!$cm = get_record('course_modules', 'id', $id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!$modulename = get_field('modules', 'name', 'id', $cm->module)) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-05-05 07:07:56 +00:00
|
|
|
if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
|
|
|
|
foreach($events as $event) {
|
2005-02-12 21:41:22 +00:00
|
|
|
if ($visible) {
|
|
|
|
show_event($event);
|
|
|
|
} else {
|
|
|
|
hide_event($event);
|
|
|
|
}
|
2004-05-05 07:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-12 03:11:34 +00:00
|
|
|
if ($prevstateoverrides) {
|
|
|
|
if ($visible == '0') {
|
|
|
|
// Remember the current visible state so we can toggle this back.
|
|
|
|
set_field('course_modules', 'visibleold', $cm->visible, 'id', $id);
|
|
|
|
} else {
|
|
|
|
// Get the previous saved visible states.
|
|
|
|
return set_field('course_modules', 'visible', $cm->visibleold, 'id', $id);
|
|
|
|
}
|
|
|
|
}
|
2005-02-12 21:41:22 +00:00
|
|
|
return set_field("course_modules", "visible", $visible, "id", $id);
|
2003-04-14 15:11:09 +00:00
|
|
|
}
|
|
|
|
|
2005-03-28 06:47:54 +00:00
|
|
|
/*
|
|
|
|
* Delete a course module and any associated data at the course level (events)
|
2006-11-09 18:25:58 +00:00
|
|
|
* Until 1.5 this function simply marked a deleted flag ... now it
|
2005-03-28 06:47:54 +00:00
|
|
|
* deletes it completely.
|
|
|
|
*
|
|
|
|
*/
|
2005-02-12 21:41:22 +00:00
|
|
|
function delete_course_module($id) {
|
2005-03-28 06:47:54 +00:00
|
|
|
if (!$cm = get_record('course_modules', 'id', $id)) {
|
|
|
|
return true;
|
|
|
|
}
|
2004-05-05 07:07:56 +00:00
|
|
|
$modulename = get_field('modules', 'name', 'id', $cm->module);
|
|
|
|
if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
|
|
|
|
foreach($events as $event) {
|
2005-02-12 21:41:22 +00:00
|
|
|
delete_event($event);
|
2004-05-05 07:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-28 06:47:54 +00:00
|
|
|
return delete_records('course_modules', 'id', $cm->id);
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete_mod_from_section($mod, $section) {
|
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
if ($section = get_record("course_sections", "id", "$section") ) {
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
$modarray = explode(",", $section->sequence);
|
2002-08-01 03:50:27 +00:00
|
|
|
|
|
|
|
if ($key = array_keys ($modarray, $mod)) {
|
|
|
|
array_splice($modarray, $key[0], 1);
|
|
|
|
$newsequence = implode(",", $modarray);
|
2002-10-21 03:00:40 +00:00
|
|
|
return set_field("course_sections", "sequence", $newsequence, "id", $section->id);
|
2002-08-01 03:50:27 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
return false;
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
|
2003-06-10 15:27:09 +00:00
|
|
|
function move_section($course, $section, $move) {
|
|
|
|
/// Moves a whole course section up and down within the course
|
2005-01-16 17:54:34 +00:00
|
|
|
global $USER;
|
2003-06-10 15:27:09 +00:00
|
|
|
|
|
|
|
if (!$move) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sectiondest = $section + $move;
|
|
|
|
|
|
|
|
if ($sectiondest > $course->numsections or $sectiondest < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$sectionrecord = get_record("course_sections", "course", $course->id, "section", $section)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-08-21 15:06:32 +00:00
|
|
|
if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) {
|
2003-06-10 15:27:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-08-21 15:06:32 +00:00
|
|
|
if (!set_field("course_sections", "section", $section, "id", $sectiondestrecord->id)) {
|
2003-06-10 15:27:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-01-16 17:54:34 +00:00
|
|
|
// if the focus is on the section that is being moved, then move the focus along
|
|
|
|
if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) {
|
|
|
|
course_set_display($course->id, $sectiondest);
|
|
|
|
}
|
2005-10-14 03:12:41 +00:00
|
|
|
|
2006-07-19 12:30:39 +00:00
|
|
|
// Check for duplicates and fix order if needed.
|
2005-10-14 03:12:41 +00:00
|
|
|
// There is a very rare case that some sections in the same course have the same section id.
|
2006-07-19 12:30:39 +00:00
|
|
|
$sections = get_records_select('course_sections', "course = $course->id", 'section ASC');
|
|
|
|
$n = 0;
|
|
|
|
foreach ($sections as $section) {
|
|
|
|
if ($section->section != $n) {
|
2005-10-14 03:12:41 +00:00
|
|
|
if (!set_field('course_sections', 'section', $n, 'id', $section->id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-07-19 12:30:39 +00:00
|
|
|
$n++;
|
2005-10-14 03:12:41 +00:00
|
|
|
}
|
2003-06-10 15:27:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-14 13:08:38 +00:00
|
|
|
function moveto_module($mod, $section, $beforemod=NULL) {
|
|
|
|
/// All parameters are objects
|
|
|
|
/// Move the module object $mod to the specified $section
|
|
|
|
/// If $beforemod exists then that is the module
|
|
|
|
/// before which $modid should be inserted
|
|
|
|
|
|
|
|
/// Remove original module from original section
|
|
|
|
|
|
|
|
if (! delete_mod_from_section($mod->id, $mod->section)) {
|
|
|
|
notify("Could not delete module from existing section");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Update module itself if necessary
|
|
|
|
|
|
|
|
if ($mod->section != $section->id) {
|
2004-05-28 10:53:54 +00:00
|
|
|
$mod->section = $section->id;
|
2003-07-14 13:08:38 +00:00
|
|
|
if (!update_record("course_modules", $mod)) {
|
|
|
|
return false;
|
|
|
|
}
|
2005-02-12 21:41:22 +00:00
|
|
|
// if moving to a hidden section then hide module
|
|
|
|
if (!$section->visible) {
|
|
|
|
set_coursemodule_visible($mod->id, 0);
|
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Add the module into the new section
|
|
|
|
|
|
|
|
$mod->course = $section->course;
|
|
|
|
$mod->section = $section->section; // need relative reference
|
|
|
|
$mod->coursemodule = $mod->id;
|
|
|
|
|
|
|
|
if (! add_mod_to_section($mod, $beforemod)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-03-05 05:19:26 +00:00
|
|
|
function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-1, $section=-1) {
|
2005-01-25 14:03:43 +00:00
|
|
|
global $CFG, $USER;
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2004-01-31 08:40:38 +00:00
|
|
|
static $str;
|
2005-03-14 19:05:39 +00:00
|
|
|
static $sesskey;
|
2004-01-31 08:40:38 +00:00
|
|
|
|
|
|
|
if (!isset($str)) {
|
2006-11-21 04:19:01 +00:00
|
|
|
$str->delete = get_string("delete");
|
|
|
|
$str->move = get_string("move");
|
|
|
|
$str->moveup = get_string("moveup");
|
|
|
|
$str->movedown = get_string("movedown");
|
|
|
|
$str->moveright = get_string("moveright");
|
|
|
|
$str->moveleft = get_string("moveleft");
|
|
|
|
$str->update = get_string("update");
|
|
|
|
$str->duplicate = get_string("duplicate");
|
|
|
|
$str->hide = get_string("hide");
|
|
|
|
$str->show = get_string("show");
|
2004-01-31 08:40:38 +00:00
|
|
|
$str->clicktochange = get_string("clicktochange");
|
2004-02-15 04:13:25 +00:00
|
|
|
$str->forcedmode = get_string("forcedmode");
|
2004-01-31 08:40:38 +00:00
|
|
|
$str->groupsnone = get_string("groupsnone");
|
|
|
|
$str->groupsseparate = get_string("groupsseparate");
|
|
|
|
$str->groupsvisible = get_string("groupsvisible");
|
2005-03-14 19:05:39 +00:00
|
|
|
$sesskey = sesskey();
|
2003-04-14 15:11:09 +00:00
|
|
|
}
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2005-03-05 05:19:26 +00:00
|
|
|
if ($section >= 0) {
|
2005-04-01 22:59:30 +00:00
|
|
|
$section = '&sr='.$section; // Section return
|
2005-03-05 05:19:26 +00:00
|
|
|
} else {
|
|
|
|
$section = '';
|
|
|
|
}
|
|
|
|
|
2002-08-03 08:16:31 +00:00
|
|
|
if ($absolute) {
|
2005-03-14 19:05:39 +00:00
|
|
|
$path = $CFG->wwwroot.'/course';
|
2003-04-28 04:32:55 +00:00
|
|
|
} else {
|
2005-03-14 19:05:39 +00:00
|
|
|
$path = '.';
|
2003-04-28 04:32:55 +00:00
|
|
|
}
|
|
|
|
|
2004-01-31 08:40:38 +00:00
|
|
|
if ($mod->visible) {
|
2006-11-21 04:19:01 +00:00
|
|
|
$hideshow = '<a class="editing_hide" title="'.$str->hide.'" href="'.$path.'/mod.php?hide='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" '.
|
|
|
|
' alt="'.$str->hide.'" /></a>'."\n";
|
2003-04-14 15:11:09 +00:00
|
|
|
} else {
|
2006-11-21 04:19:01 +00:00
|
|
|
$hideshow = '<a class="editing_show" title="'.$str->show.'" href="'.$path.'/mod.php?show='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" '.
|
|
|
|
' alt="'.$str->show.'" /></a>'."\n";
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2004-01-31 08:40:38 +00:00
|
|
|
if ($mod->groupmode !== false) {
|
|
|
|
if ($mod->groupmode == SEPARATEGROUPS) {
|
2004-02-15 04:13:25 +00:00
|
|
|
$grouptitle = $str->groupsseparate;
|
2006-11-21 04:19:01 +00:00
|
|
|
$groupclass = 'editing_groupseparate';
|
2005-03-14 19:05:39 +00:00
|
|
|
$groupimage = $CFG->pixpath.'/t/groups.gif';
|
|
|
|
$grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=0&sesskey='.$sesskey;
|
2004-01-31 08:40:38 +00:00
|
|
|
} else if ($mod->groupmode == VISIBLEGROUPS) {
|
2004-02-15 04:13:25 +00:00
|
|
|
$grouptitle = $str->groupsvisible;
|
2006-11-21 04:19:01 +00:00
|
|
|
$groupclass = 'editing_groupvisible';
|
2005-03-14 19:05:39 +00:00
|
|
|
$groupimage = $CFG->pixpath.'/t/groupv.gif';
|
|
|
|
$grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=1&sesskey='.$sesskey;
|
2004-02-15 04:13:25 +00:00
|
|
|
} else {
|
|
|
|
$grouptitle = $str->groupsnone;
|
2006-11-21 04:19:01 +00:00
|
|
|
$groupclass = 'editing_groupsnone';
|
2005-03-14 19:05:39 +00:00
|
|
|
$groupimage = $CFG->pixpath.'/t/groupn.gif';
|
|
|
|
$grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=2&sesskey='.$sesskey;
|
2004-02-15 04:13:25 +00:00
|
|
|
}
|
|
|
|
if ($mod->groupmodelink) {
|
2006-11-21 04:19:01 +00:00
|
|
|
$groupmode = '<a class="'.$groupclass.'" title="'.$grouptitle.' ('.$str->clicktochange.')" href="'.$grouplink.'">'.
|
2007-01-08 09:14:05 +00:00
|
|
|
'<img src="'.$groupimage.'" class="iconsmall" '.
|
|
|
|
'alt="'.$grouptitle.'" /></a>';
|
2004-01-31 08:40:38 +00:00
|
|
|
} else {
|
2005-03-14 19:05:39 +00:00
|
|
|
$groupmode = '<img title="'.$grouptitle.' ('.$str->forcedmode.')" '.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$groupimage.'" class="iconsmall" '.
|
|
|
|
'alt="'.$grouptitle.'" />';
|
2004-01-31 08:40:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$groupmode = "";
|
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
|
|
|
|
if ($moveselect) {
|
2006-11-21 04:19:01 +00:00
|
|
|
$move = '<a class="editing_move" title="'.$str->move.'" href="'.$path.'/mod.php?copy='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" '.
|
|
|
|
' alt="'.$str->move.'" /></a>'."\n";
|
2003-07-14 16:22:42 +00:00
|
|
|
} else {
|
2006-11-21 04:19:01 +00:00
|
|
|
$move = '<a class="editing_moveup" title="'.$str->moveup.'" href="'.$path.'/mod.php?id='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&move=-1&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/up.gif" class="iconsmall" '.
|
|
|
|
' alt="'.$str->moveup.'" /></a>'."\n".
|
2006-11-21 04:19:01 +00:00
|
|
|
'<a class="editing_movedown" title="'.$str->movedown.'" href="'.$path.'/mod.php?id='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&move=1&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/down.gif" class="iconsmall" '.
|
|
|
|
' alt="'.$str->movedown.'" /></a>'."\n";
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 16:31:33 +00:00
|
|
|
$leftright = "";
|
|
|
|
if ($indent > 0) {
|
2006-11-21 04:19:01 +00:00
|
|
|
$leftright .= '<a class="editing_moveleft" title="'.$str->moveleft.'" href="'.$path.'/mod.php?id='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&indent=-1&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/left.gif" class="iconsmall" '.
|
|
|
|
' alt="'.$str->moveleft.'" /></a>'."\n";
|
2003-09-14 16:31:33 +00:00
|
|
|
}
|
|
|
|
if ($indent >= 0) {
|
2006-11-21 04:19:01 +00:00
|
|
|
$leftright .= '<a class="editing_moveright" title="'.$str->moveright.'" href="'.$path.'/mod.php?id='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&indent=1&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/right.gif" class="iconsmall" '.
|
|
|
|
' alt="'.$str->moveright.'" /></a>'."\n";
|
2005-03-14 19:05:39 +00:00
|
|
|
}
|
|
|
|
|
2006-11-21 04:19:01 +00:00
|
|
|
return '<span class="commands">'."\n".$leftright.$move.
|
|
|
|
'<a class="editing_update" title="'.$str->update.'" href="'.$path.'/mod.php?update='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" '.
|
2006-11-21 04:19:01 +00:00
|
|
|
' alt="'.$str->update.'" /></a>'."\n".
|
|
|
|
'<a class="editing_delete" title="'.$str->delete.'" href="'.$path.'/mod.php?delete='.$mod->id.
|
2005-03-14 19:05:39 +00:00
|
|
|
'&sesskey='.$sesskey.$section.'"><img'.
|
2007-01-08 09:14:05 +00:00
|
|
|
' src="'.$CFG->pixpath.'/t/delete.gif" class="iconsmall" '.
|
2006-11-21 04:19:01 +00:00
|
|
|
' alt="'.$str->delete.'" /></a>'."\n".$hideshow.$groupmode."\n".'</span>';
|
2002-08-02 17:38:18 +00:00
|
|
|
}
|
|
|
|
|
2005-01-24 22:21:28 +00:00
|
|
|
/**
|
2006-11-09 18:25:58 +00:00
|
|
|
* given a course object with shortname & fullname, this function will
|
2005-01-24 22:21:28 +00:00
|
|
|
* truncate the the number of chars allowed and add ... if it was too long
|
|
|
|
*/
|
|
|
|
function course_format_name ($course,$max=100) {
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2005-01-24 22:21:28 +00:00
|
|
|
$str = $course->shortname.': '.$course->fullname;
|
|
|
|
if (strlen($str) <= $max) {
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return substr($str,0,$max-3).'...';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will return true if the given course is a child course at all
|
|
|
|
*/
|
|
|
|
function course_in_meta ($course) {
|
2005-01-25 04:33:02 +00:00
|
|
|
return record_exists("course_meta","child_course",$course->id);
|
2005-01-24 22:21:28 +00:00
|
|
|
}
|
|
|
|
|
2005-02-12 21:41:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print standard form elements on module setup forms in mod/.../mod.html
|
|
|
|
*/
|
|
|
|
function print_standard_coursemodule_settings($form) {
|
2005-02-13 06:07:06 +00:00
|
|
|
if (! $course = get_record('course', 'id', $form->course)) {
|
|
|
|
error("This course doesn't exist");
|
|
|
|
}
|
|
|
|
print_groupmode_setting($form, $course);
|
|
|
|
print_visible_setting($form, $course);
|
2005-02-12 21:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print groupmode form element on module setup forms in mod/.../mod.html
|
|
|
|
*/
|
2005-02-13 06:31:01 +00:00
|
|
|
function print_groupmode_setting($form, $course=NULL) {
|
2005-02-12 21:41:22 +00:00
|
|
|
|
2005-02-13 06:31:01 +00:00
|
|
|
if (empty($course)) {
|
|
|
|
if (! $course = get_record('course', 'id', $form->course)) {
|
|
|
|
error("This course doesn't exist");
|
|
|
|
}
|
|
|
|
}
|
2005-02-12 21:41:22 +00:00
|
|
|
if ($form->coursemodule) {
|
|
|
|
if (! $cm = get_record('course_modules', 'id', $form->coursemodule)) {
|
|
|
|
error("This course module doesn't exist");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$cm = null;
|
|
|
|
}
|
|
|
|
$groupmode = groupmode($course, $cm);
|
|
|
|
if ($course->groupmode or (!$course->groupmodeforce)) {
|
|
|
|
echo '<tr valign="top">';
|
|
|
|
echo '<td align="right"><b>'.get_string('groupmode').':</b></td>';
|
2005-06-04 09:58:35 +00:00
|
|
|
echo '<td align="left">';
|
2005-02-12 21:41:22 +00:00
|
|
|
unset($choices);
|
|
|
|
$choices[NOGROUPS] = get_string('groupsnone');
|
|
|
|
$choices[SEPARATEGROUPS] = get_string('groupsseparate');
|
|
|
|
$choices[VISIBLEGROUPS] = get_string('groupsvisible');
|
|
|
|
choose_from_menu($choices, 'groupmode', $groupmode, '', '', 0, false, $course->groupmodeforce);
|
|
|
|
helpbutton('groupmode', get_string('groupmode'));
|
|
|
|
echo '</td></tr>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print visibility setting form element on module setup forms in mod/.../mod.html
|
|
|
|
*/
|
2005-02-13 06:31:01 +00:00
|
|
|
function print_visible_setting($form, $course=NULL) {
|
2005-02-17 19:19:21 +00:00
|
|
|
if (empty($course)) {
|
|
|
|
if (! $course = get_record('course', 'id', $form->course)) {
|
|
|
|
error("This course doesn't exist");
|
|
|
|
}
|
|
|
|
}
|
2005-02-12 21:41:22 +00:00
|
|
|
if ($form->coursemodule) {
|
|
|
|
$visible = get_field('course_modules', 'visible', 'id', $form->coursemodule);
|
|
|
|
} else {
|
|
|
|
$visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($form->mode == 'add') { // in this case $form->section is the section number, not the id
|
|
|
|
$hiddensection = !get_field('course_sections', 'visible', 'section', $form->section, 'course', $form->course);
|
|
|
|
} else {
|
|
|
|
$hiddensection = !get_field('course_sections', 'visible', 'id', $form->section);
|
|
|
|
}
|
|
|
|
if ($hiddensection) {
|
|
|
|
$visible = false;
|
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2005-02-12 21:41:22 +00:00
|
|
|
echo '<tr valign="top">';
|
2006-10-16 02:53:45 +00:00
|
|
|
echo '<td align="right"><b>'.get_string('visible', '').':</b></td>';
|
2005-06-04 09:58:35 +00:00
|
|
|
echo '<td align="left">';
|
2005-02-12 21:41:22 +00:00
|
|
|
unset($choices);
|
2005-02-13 06:15:12 +00:00
|
|
|
$choices[1] = get_string('show');
|
|
|
|
$choices[0] = get_string('hide');
|
2005-02-12 21:41:22 +00:00
|
|
|
choose_from_menu($choices, 'visible', $visible, '', '', 0, false, $hiddensection);
|
|
|
|
echo '</td></tr>';
|
2006-11-09 18:25:58 +00:00
|
|
|
}
|
2005-02-12 21:41:22 +00:00
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
function update_restricted_mods($course,$mods) {
|
|
|
|
delete_records("course_allowed_modules","course",$course->id);
|
|
|
|
if (empty($course->restrictmodules)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($mods as $mod) {
|
|
|
|
if ($mod == 0)
|
|
|
|
continue; // this is the 'allow none' option
|
|
|
|
$am->course = $course->id;
|
|
|
|
$am->module = $mod;
|
|
|
|
insert_record("course_allowed_modules",$am);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will take an int (module id) or a string (module name)
|
|
|
|
* and return true or false, whether it's allowed in the given course (object)
|
2006-11-09 18:25:58 +00:00
|
|
|
* $mod is not allowed to be an object, as the field for the module id is inconsistent
|
2005-08-16 06:15:49 +00:00
|
|
|
* depending on where in the code it's called from (sometimes $mod->id, sometimes $mod->module)
|
|
|
|
*/
|
|
|
|
|
|
|
|
function course_allowed_module($course,$mod) {
|
|
|
|
if (empty($course->restrictmodules)) {
|
|
|
|
return true;
|
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2006-09-08 08:46:26 +00:00
|
|
|
// i am not sure this capability is correct
|
|
|
|
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
2005-08-16 06:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (is_numeric($mod)) {
|
|
|
|
$modid = $mod;
|
|
|
|
} else if (is_string($mod)) {
|
2006-06-01 19:52:38 +00:00
|
|
|
if ($mod = get_field("modules","id","name",$mod))
|
2005-08-16 06:15:49 +00:00
|
|
|
$modid = $mod;
|
|
|
|
}
|
|
|
|
if (empty($modid)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (record_exists("course_allowed_modules","course",$course->id,"module",$modid));
|
|
|
|
}
|
|
|
|
|
2005-09-01 04:48:22 +00:00
|
|
|
/***
|
|
|
|
*** Efficiently moves many courses around while maintaining
|
|
|
|
*** sortorder in order.
|
2006-11-09 18:25:58 +00:00
|
|
|
***
|
2005-09-01 04:48:22 +00:00
|
|
|
*** $courseids is an array of course ids
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
|
|
|
function move_courses ($courseids, $categoryid) {
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (!empty($courseids)) {
|
2006-11-09 18:25:58 +00:00
|
|
|
|
|
|
|
$courseids = array_reverse($courseids);
|
2005-09-01 04:48:22 +00:00
|
|
|
|
|
|
|
foreach ($courseids as $courseid) {
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2005-09-01 04:48:22 +00:00
|
|
|
if (! $course = get_record("course", "id", $courseid)) {
|
|
|
|
notify("Error finding course $courseid");
|
|
|
|
} else {
|
|
|
|
// figure out a sortorder that we can use in the destination category
|
|
|
|
$sortorder = get_field_sql('SELECT MIN(sortorder)-1 AS min
|
|
|
|
FROM ' . $CFG->prefix . 'course WHERE category=' . $categoryid);
|
|
|
|
if ($sortorder === false) {
|
|
|
|
// the category is empty
|
|
|
|
// rather than let the db default to 0
|
2006-11-09 18:25:58 +00:00
|
|
|
// set it to > 100 and avoid extra work in fix_coursesortorder()
|
2005-09-01 04:48:22 +00:00
|
|
|
$sortorder = 200;
|
|
|
|
} else if ($sortorder < 10) {
|
|
|
|
fix_course_sortorder($categoryid);
|
|
|
|
}
|
|
|
|
|
|
|
|
$course->category = $categoryid;
|
|
|
|
$course->sortorder = $sortorder;
|
|
|
|
$course->fullname = addslashes($course->fullname);
|
|
|
|
$course->shortname = addslashes($course->shortname);
|
|
|
|
$course->summary = addslashes($course->summary);
|
|
|
|
$course->password = addslashes($course->password);
|
|
|
|
$course->teacher = addslashes($course->teacher);
|
|
|
|
$course->teachers = addslashes($course->teachers);
|
|
|
|
$course->student = addslashes($course->student);
|
|
|
|
$course->students = addslashes($course->students);
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2005-09-01 04:48:22 +00:00
|
|
|
if (!update_record('course', $course)) {
|
|
|
|
notify("An error occurred - course not moved!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fix_course_sortorder();
|
2006-11-09 18:25:58 +00:00
|
|
|
}
|
2005-09-01 04:48:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-12-11 15:47:23 +00:00
|
|
|
/**
|
|
|
|
* @param string $format Course format ID e.g. 'weeks'
|
|
|
|
* @return Name that the course format prefers for sections
|
|
|
|
*/
|
|
|
|
function get_section_name($format) {
|
|
|
|
$sectionname = get_string("name$format","format_$format");
|
|
|
|
if($sectionname == "[[name$format]]") {
|
|
|
|
$sectionname = get_string("name$format");
|
|
|
|
}
|
|
|
|
return $sectionname;
|
|
|
|
}
|
|
|
|
|
2006-08-13 13:17:38 +00:00
|
|
|
?>
|