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;
|
|
|
|
}
|
|
|
|
|
2003-04-26 12:17:30 +00:00
|
|
|
define('COURSE_MAX_LOG_DISPLAY', 150); // days
|
2002-06-25 07:56:26 +00:00
|
|
|
|
2003-04-26 12:17:30 +00:00
|
|
|
define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records
|
2003-01-01 08:21:19 +00:00
|
|
|
|
2003-04-26 12:17:30 +00:00
|
|
|
define('COURSE_LIVELOG_REFRESH', 60); // Seconds
|
2002-08-10 13:50:38 +00:00
|
|
|
|
2004-05-15 14:58:12 +00:00
|
|
|
define('COURSE_MAX_RECENT_PERIOD', 172800); // Two days, in seconds
|
2003-09-03 15:25:08 +00:00
|
|
|
|
|
|
|
define('COURSE_MAX_SUMMARIES_PER_PAGE', 10); // courses
|
2002-08-01 15:48:27 +00:00
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
define("FRONTPAGENEWS", 0);
|
|
|
|
define("FRONTPAGECOURSELIST", 1);
|
|
|
|
define("FRONTPAGECATEGORYNAMES", 2);
|
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;
|
|
|
|
|
|
|
|
$isteacher = isteacher($course->id);
|
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-02-20 21:38:42 +00:00
|
|
|
if ($course->category) {
|
|
|
|
$courseusers = get_course_users($course->id);
|
|
|
|
} else {
|
|
|
|
$courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname");
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
if ($courseusers) {
|
|
|
|
foreach ($courseusers as $courseuser) {
|
|
|
|
$users[$courseuser->id] = fullname($courseuser, $isteacher);
|
|
|
|
}
|
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
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
if (isadmin()) {
|
|
|
|
if ($ccc = get_records("course", "", "", "fullname")) {
|
|
|
|
foreach ($ccc as $cc) {
|
|
|
|
if ($cc->category) {
|
|
|
|
$courses["$cc->id"] = "$cc->fullname";
|
|
|
|
} else {
|
|
|
|
$courses["$cc->id"] = " $cc->fullname (Site)";
|
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
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
if ($modinfo = unserialize($course->modinfo)) {
|
|
|
|
$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
|
|
|
}
|
2004-03-10 13:38:08 +00:00
|
|
|
if (!$mod->visible and !$isteacher) {
|
|
|
|
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;
|
2004-04-03 04:50:30 +00:00
|
|
|
$mod->name = strip_tags(urldecode($mod->name));
|
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
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
if ($selecteddate == "lastlogin") {
|
|
|
|
$selecteddate = $USER->lastlogin;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<form action="recent.php" method="get">';
|
|
|
|
echo '<input type=hidden name=chooserecent value="1">';
|
|
|
|
echo "<center>";
|
|
|
|
echo "<table>";
|
|
|
|
|
|
|
|
if (isadmin()) {
|
|
|
|
echo "<tr><td><b>" . get_string("courses") . "</b></td><td>";
|
|
|
|
choose_from_menu ($courses, "id", $course->id, "");
|
|
|
|
echo "</td></tr>";
|
|
|
|
} else {
|
|
|
|
echo "<input type=hidden name=id value=\"$course->id\">";
|
|
|
|
}
|
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>";
|
|
|
|
|
|
|
|
echo "<td align='right'><b>" . get_string("since") . "</b></td><td>";
|
|
|
|
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-02-20 21:38:42 +00:00
|
|
|
echo "<td align='right'><b>" . get_string("sortby") . "</b></td><td>";
|
|
|
|
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
|
|
|
|
2004-02-20 21:38:42 +00:00
|
|
|
if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
|
|
|
|
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
|
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>';
|
|
|
|
choose_from_menu($groups, "selectedgroup", $selectedgroup, get_string("allgroups"), "", "");
|
|
|
|
echo '</td>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
echo "<td colspan='2' align='right'>";
|
|
|
|
echo "<input type=submit value=\"".get_string("showrecent")."\">";
|
|
|
|
echo "</td></tr>";
|
|
|
|
|
|
|
|
echo "</table>";
|
|
|
|
|
|
|
|
$advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&advancedfilter=0\">" . get_string("normalfilter") . "</a>";
|
|
|
|
print_heading($advancedlink);
|
|
|
|
echo "</center>";
|
|
|
|
echo "</form>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$day_list = array("1","7","14","21","30");
|
|
|
|
$strsince = get_string("since");
|
|
|
|
$strlastlogin = get_string("lastlogin");
|
|
|
|
$strday = get_string("day");
|
|
|
|
$strdays = get_string("days");
|
|
|
|
|
|
|
|
$heading = "";
|
|
|
|
foreach ($day_list as $count) {
|
|
|
|
if ($count == "1") {
|
|
|
|
$day = $strday;
|
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-02-23 21:17:03 +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-02-20 21:38:42 +00:00
|
|
|
$advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&advancedfilter=1\">" . get_string("advancedfilter") . "</a>";
|
|
|
|
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
|
|
|
|
2004-01-15 07:17:12 +00:00
|
|
|
function print_log_selector_form($course, $selecteduser=0, $selecteddate="today",
|
2004-07-28 15:52:51 +00:00
|
|
|
$modname="", $modid=0, $modaction="", $selectedgroup=-1) {
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-06-10 09:44:37 +00:00
|
|
|
global $USER, $CFG;
|
|
|
|
|
2004-07-28 15:52:51 +00:00
|
|
|
/// Setup for group handling.
|
2003-11-19 16:30:09 +00:00
|
|
|
$isteacher = isteacher($course->id);
|
2004-07-28 15:52:51 +00:00
|
|
|
$isteacheredit = isteacheredit($course->id);
|
|
|
|
if ($course->groupmode == SEPARATEGROUPS and !$isteacheredit) {
|
|
|
|
$selectedgroup = get_current_group($course->id);
|
|
|
|
$showgroups = false;
|
|
|
|
}
|
|
|
|
else if ($course->groupmode) {
|
|
|
|
$selectedgroup = ($selectedgroup == -1) ? get_current_group($course->id) : $selectedgroup;
|
|
|
|
$showgroups = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$selectedgroup = 0;
|
|
|
|
$showgroups = false;
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
// Get all the possible users
|
|
|
|
$users = array();
|
2002-06-12 04:22:41 +00:00
|
|
|
|
|
|
|
if ($course->category) {
|
2004-07-28 15:52:51 +00:00
|
|
|
/// If using a group, only get users in that group.
|
|
|
|
if ($selectedgroup) {
|
|
|
|
$sql = 'SELECT u.id as id, u.firstname, u.lastname, u.lastaccess '.
|
|
|
|
'FROM '.$CFG->prefix.'user u,'.$CFG->prefix.'user_students us,'.$CFG->prefix.'groups_members gm, '.
|
|
|
|
$CFG->prefix.'user_teachers ut '.
|
|
|
|
'WHERE us.course='.$course->id.' AND gm.groupid='.$selectedgroup.
|
|
|
|
' AND (gm.userid=us.userid OR gm.userid=ut.userid) AND gm.userid=u.id';
|
|
|
|
$courseusers = get_records_sql($sql);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$courseusers = get_course_users($course->id);
|
|
|
|
}
|
2003-08-23 06:19:05 +00:00
|
|
|
} else {
|
|
|
|
$courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($courseusers) {
|
|
|
|
foreach ($courseusers as $courseuser) {
|
2003-11-19 16:30:09 +00:00
|
|
|
$users[$courseuser->id] = fullname($courseuser, $isteacher);
|
2002-09-11 02:26:56 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2003-08-23 06:19:05 +00:00
|
|
|
if ($guest = get_guest()) {
|
2003-11-28 10:32:32 +00:00
|
|
|
$users[$guest->id] = fullname($guest);
|
2003-08-23 06:19:05 +00:00
|
|
|
}
|
2002-06-12 04:22:41 +00:00
|
|
|
|
|
|
|
if (isadmin()) {
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($ccc = get_records("course", "", "", "fullname")) {
|
2002-06-12 04:22:41 +00:00
|
|
|
foreach ($ccc as $cc) {
|
2002-06-12 04:29:03 +00:00
|
|
|
if ($cc->category) {
|
|
|
|
$courses["$cc->id"] = "$cc->fullname";
|
|
|
|
} else {
|
|
|
|
$courses["$cc->id"] = " $cc->fullname (Site)";
|
|
|
|
}
|
2002-06-12 04:22:41 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-06-12 04:29:03 +00:00
|
|
|
asort($courses);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-01-15 07:17:12 +00:00
|
|
|
$activities = array();
|
|
|
|
$selectedactivity = "";
|
|
|
|
|
|
|
|
if ($modinfo = unserialize($course->modinfo)) {
|
|
|
|
$section = 0;
|
|
|
|
if ($course->format == 'weeks') { // Bodgy
|
|
|
|
$strsection = get_string("week");
|
|
|
|
} else {
|
|
|
|
$strsection = get_string("topic");
|
|
|
|
}
|
|
|
|
foreach ($modinfo as $mod) {
|
|
|
|
if ($mod->mod == "label") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($mod->section > 0 and $section <> $mod->section) {
|
|
|
|
$activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------";
|
|
|
|
}
|
|
|
|
$section = $mod->section;
|
2004-07-28 15:52:51 +00:00
|
|
|
$mod->name = urldecode($mod->name);
|
2004-01-15 07:17:12 +00:00
|
|
|
if (strlen($mod->name) > 55) {
|
|
|
|
$mod->name = substr($mod->name, 0, 50)."...";
|
|
|
|
}
|
|
|
|
if (!$mod->visible) {
|
|
|
|
$mod->name = "(".$mod->name.")";
|
|
|
|
}
|
2004-01-31 14:47:57 +00:00
|
|
|
$activities["$mod->cm"] = $mod->name;
|
2004-01-15 07:17:12 +00:00
|
|
|
|
|
|
|
if ($mod->cm == $modid) {
|
2004-01-31 14:47:57 +00:00
|
|
|
$selectedactivity = "$mod->cm";
|
2004-01-15 07:17:12 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-28 15:52:51 +00:00
|
|
|
|
|
|
|
if (isadmin() && !$course->category) {
|
|
|
|
$activities["site_errors"] = get_string("siteerrors");
|
|
|
|
if ($modid === "site_errors") {
|
|
|
|
$selectedactivity = "site_errors";
|
|
|
|
}
|
|
|
|
}
|
2004-01-15 07:17:12 +00:00
|
|
|
}
|
2004-07-28 15:52:51 +00:00
|
|
|
|
2003-01-15 10:55:54 +00:00
|
|
|
|
|
|
|
$strftimedate = get_string("strftimedate");
|
|
|
|
$strftimedaydate = get_string("strftimedaydate");
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
asort($users);
|
|
|
|
|
|
|
|
// Get all the possible dates
|
2002-06-10 09:44:37 +00:00
|
|
|
// Note that we are keeping track of real (GMT) time and user time
|
|
|
|
// User time is only used in displays - all calcs and passing is GMT
|
|
|
|
|
|
|
|
$timenow = time(); // GMT
|
|
|
|
|
|
|
|
// What day is it now for the user, and when is midnight that day (in GMT).
|
2002-06-11 04:28:01 +00:00
|
|
|
$timemidnight = $today = usergetmidnight($timenow);
|
2002-06-10 09:44:37 +00:00
|
|
|
|
|
|
|
// Put today up the top of the list
|
2003-01-15 10:55:54 +00:00
|
|
|
$dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) );
|
2002-06-10 09:44:37 +00:00
|
|
|
|
2003-08-25 00:56:38 +00:00
|
|
|
if (!$course->startdate or ($course->startdate > $timenow)) {
|
2002-06-10 09:44:37 +00:00
|
|
|
$course->startdate = $course->timecreated;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-06-10 09:44:37 +00:00
|
|
|
$numdates = 1;
|
|
|
|
while ($timemidnight > $course->startdate and $numdates < 365) {
|
2001-11-22 06:23:56 +00:00
|
|
|
$timemidnight = $timemidnight - 86400;
|
2002-06-10 09:44:37 +00:00
|
|
|
$timenow = $timenow - 86400;
|
2003-01-15 10:55:54 +00:00
|
|
|
$dates["$timemidnight"] = userdate($timenow, $strftimedaydate);
|
2002-06-10 09:44:37 +00:00
|
|
|
$numdates++;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($selecteddate == "today") {
|
|
|
|
$selecteddate = $today;
|
|
|
|
}
|
|
|
|
|
2004-01-15 07:17:12 +00:00
|
|
|
echo '<center>';
|
|
|
|
echo '<form action="log.php" method="get">';
|
|
|
|
echo '<input type=hidden name=chooselog value="1">';
|
2002-06-12 04:22:41 +00:00
|
|
|
if (isadmin()) {
|
2002-06-12 04:31:08 +00:00
|
|
|
choose_from_menu ($courses, "id", $course->id, "");
|
2002-06-12 04:22:41 +00:00
|
|
|
} else {
|
2004-01-15 07:17:12 +00:00
|
|
|
echo "<input type=hidden name=id value=\"$course->id\">";
|
2002-06-12 04:22:41 +00:00
|
|
|
}
|
2004-07-28 15:52:51 +00:00
|
|
|
|
|
|
|
if ($showgroups) {
|
|
|
|
$cgroups = get_groups($course->id);
|
|
|
|
foreach ($cgroups as $cgroup) {
|
|
|
|
$groups[$cgroup->id] = $cgroup->name;
|
|
|
|
}
|
|
|
|
choose_from_menu ($groups, "group", $selectedgroup, get_string("allgroups") );
|
|
|
|
}
|
|
|
|
|
2003-08-23 06:19:05 +00:00
|
|
|
choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") );
|
2002-08-11 15:41:54 +00:00
|
|
|
choose_from_menu ($dates, "date", $selecteddate, get_string("alldays"));
|
2004-01-31 14:47:57 +00:00
|
|
|
choose_from_menu ($activities, "modid", $selectedactivity, get_string("allactivities"), "", "");
|
2004-01-15 07:17:12 +00:00
|
|
|
echo "<input type=submit value=\"".get_string("showtheselogs")."\">";
|
|
|
|
echo "</form>";
|
|
|
|
echo "</center>";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-05-31 09:34:50 +00:00
|
|
|
function make_log_url($module, $url) {
|
|
|
|
switch ($module) {
|
|
|
|
case "course":
|
|
|
|
case "user":
|
|
|
|
case "file":
|
|
|
|
case "login":
|
|
|
|
case "lib":
|
|
|
|
case "admin":
|
|
|
|
return "/$module/$url";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return "/mod/$module/$url";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-28 15:52:51 +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) {
|
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-01-15 07:17:12 +00:00
|
|
|
global $CFG, $db;
|
2002-12-30 05:13:43 +00:00
|
|
|
|
2004-07-28 15:52:51 +00:00
|
|
|
/// Setup for group handling.
|
|
|
|
$isteacher = isteacher($course->id);
|
|
|
|
$isteacheredit = isteacheredit($course->id);
|
|
|
|
|
|
|
|
/// 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 !$isteacheredit) {
|
|
|
|
$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
|
|
|
|
2004-07-25 14:00:29 +00:00
|
|
|
if ($course->category) {
|
|
|
|
$joins[] = "l.course='$course->id'";
|
2002-06-12 04:22:41 +00:00
|
|
|
} else {
|
2003-08-23 06:19:05 +00:00
|
|
|
if ($ccc = get_courses("all", "c.id ASC", "c.id,c.shortname")) {
|
2002-06-12 04:22:41 +00:00
|
|
|
foreach ($ccc as $cc) {
|
|
|
|
$courses[$cc->id] = "$cc->shortname";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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-07-25 14:00:29 +00:00
|
|
|
if ($modid && is_int($modid)) {
|
|
|
|
$joins[] = "l.cmid = '$modid'";
|
|
|
|
} else if ($modid == "site_errors") {
|
|
|
|
$joins[] = "l.action='error'";
|
2004-01-31 14:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($modaction) {
|
2004-07-25 14:00:29 +00:00
|
|
|
$joins[] = "l.action = '$modaction'";
|
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) {
|
|
|
|
if ($gusers = get_records('groups_members', 'groupid', $groupid)) {
|
|
|
|
$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-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
|
|
|
|
|
2003-08-22 06:07:18 +00:00
|
|
|
if (!$logs = get_logs($selector, $order, $page*$perpage, $perpage, $totalcount)) {
|
2001-11-22 06:23:56 +00:00
|
|
|
notify("No logs found!");
|
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$count=0;
|
|
|
|
$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");
|
2003-11-19 16:30:09 +00:00
|
|
|
$isteacher = isteacher($course->id);
|
2003-01-15 10:55:54 +00:00
|
|
|
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "<p align=center>";
|
2003-08-22 06:07:18 +00:00
|
|
|
print_string("displayingrecords", "", $totalcount);
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "</p>";
|
2003-01-01 08:21:19 +00:00
|
|
|
|
2003-08-22 06:07:18 +00:00
|
|
|
print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&");
|
|
|
|
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "<table border=0 align=center cellpadding=3 cellspacing=3>";
|
2001-11-22 06:23:56 +00:00
|
|
|
foreach ($logs as $log) {
|
2002-05-31 09:34:50 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($ld = get_record("log_display", "module", "$log->module", "action", "$log->action")) {
|
2002-08-04 02:08:43 +00:00
|
|
|
$log->info = get_field($ld->mtable, $ld->field, "id", $log->info);
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "<tr nowrap>";
|
2002-06-12 04:22:41 +00:00
|
|
|
if (! $course->category) {
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "<td nowrap><font size=2><a href=\"view.php?id=$log->course\">".$courses[$log->course]."</a></td>";
|
2002-06-12 04:22:41 +00:00
|
|
|
}
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "<td nowrap align=right><font size=2>".userdate($log->time, "%a")."</td>";
|
|
|
|
echo "<td nowrap><font size=2>".userdate($log->time, $strftimedatetime)."</td>";
|
2003-04-28 04:32:55 +00:00
|
|
|
echo "<td nowrap><font size=2>";
|
2002-12-30 05:13:43 +00:00
|
|
|
link_to_popup_window("/lib/ipatlas/plot.php?address=$log->ip&user=$log->userid", "ipatlas","$log->ip", 400, 700);
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "</td>";
|
2003-11-19 16:30:09 +00:00
|
|
|
$fullname = fullname($log, $isteacher);
|
|
|
|
echo "<td nowrap><font size=2><a href=\"../user/view.php?id=$log->userid&course=$log->course\"><b>$fullname</b></td>";
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "<td nowrap><font size=2>";
|
2002-05-31 09:34:50 +00:00
|
|
|
link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600);
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "</td>";
|
|
|
|
echo "<td nowrap><font size=2>$log->info</td>";
|
|
|
|
echo "</tr>";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2003-04-27 03:32:45 +00:00
|
|
|
echo "</table>";
|
2003-08-22 06:07:18 +00:00
|
|
|
|
|
|
|
print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&");
|
2001-11-22 06:23:56 +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 {
|
2003-07-30 13:02:45 +00:00
|
|
|
echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
|
2002-06-10 05:19:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-22 06:23:56 +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
|
|
|
|
|
2003-08-26 18:45:54 +00:00
|
|
|
global $CFG, $USER, $THEME, $SESSION;
|
2002-05-31 09:34:50 +00:00
|
|
|
|
2003-11-19 16:30:09 +00:00
|
|
|
$isteacher = isteacher($course->id);
|
|
|
|
|
2004-05-16 10:34:17 +00:00
|
|
|
$timestart = time() - COURSE_MAX_RECENT_PERIOD;
|
2004-02-23 18:05:59 +00:00
|
|
|
|
2004-05-15 14:58:12 +00:00
|
|
|
if (!empty($USER->timeaccess[$course->id])) {
|
2004-05-16 10:34:17 +00:00
|
|
|
if ($USER->timeaccess[$course->id] > $timestart) {
|
2004-05-15 14:58:12 +00:00
|
|
|
$timestart = $USER->timeaccess[$course->id];
|
|
|
|
}
|
2003-04-26 12:17:30 +00:00
|
|
|
}
|
2004-02-23 18:05:59 +00:00
|
|
|
|
|
|
|
echo '<center><font size="1">';
|
|
|
|
echo get_string("activitysince", "", userdate($timestart));
|
|
|
|
|
2004-05-30 11:22:06 +00:00
|
|
|
echo '<p><a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a></p>';
|
2004-02-23 18:05:59 +00:00
|
|
|
|
|
|
|
echo '</font></center>';
|
|
|
|
|
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
|
|
|
|
2003-08-17 01:46:00 +00:00
|
|
|
if ($users) {
|
2003-09-23 03:13:31 +00:00
|
|
|
echo "<p>";
|
2003-08-17 01:46:00 +00:00
|
|
|
foreach ($users as $user) {
|
2002-05-31 09:34:50 +00:00
|
|
|
if (! $heading) {
|
2002-08-10 14:27:14 +00:00
|
|
|
print_headline(get_string("newusers").":");
|
2002-05-31 09:34:50 +00:00
|
|
|
$heading = true;
|
|
|
|
$content = true;
|
|
|
|
}
|
2003-11-19 16:30:09 +00:00
|
|
|
$fullname = fullname($user, $isteacher);
|
2004-05-30 11:22:06 +00:00
|
|
|
echo '<font size=1><a href="'.$CFG->wwwroot."/user/view.php?id=$user->id&course=$course->id\">$fullname</a></font><br />";
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
2003-09-23 03:13:31 +00:00
|
|
|
echo "</p>";
|
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?
|
|
|
|
|
2004-05-28 10:53:54 +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) {
|
|
|
|
$info = split(" ", $log->info);
|
2003-09-14 12:25:16 +00:00
|
|
|
|
|
|
|
if ($info[0] == "label") { // Labels are special activities
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-04-26 15:08:34 +00:00
|
|
|
$modname = get_field($info[0], "name", "id", $info[1]);
|
|
|
|
//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) {
|
|
|
|
case "add mod":
|
|
|
|
$stradded = get_string("added", "moodle", get_string("modulename", $info[0]));
|
|
|
|
$changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
|
|
|
|
break;
|
|
|
|
case "update mod":
|
|
|
|
$strupdated = get_string("updated", "moodle", get_string("modulename", $info[0]));
|
|
|
|
if (empty($changelist["$log->info"])) {
|
|
|
|
$changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "delete mod":
|
2004-05-28 10:53:54 +00:00
|
|
|
if (!empty($changelist["$log->info"]["operation"]) and
|
2003-04-26 15:08:34 +00:00
|
|
|
$changelist["$log->info"]["operation"] == "add") {
|
|
|
|
$changelist["$log->info"] = NULL;
|
|
|
|
} else {
|
|
|
|
$strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0]));
|
|
|
|
$changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
print_headline(get_string("courseupdates").":");
|
|
|
|
$content = true;
|
|
|
|
foreach ($changes as $changeinfo => $change) {
|
|
|
|
echo "<p><font size=1>".$change["text"]."</font></p>";
|
|
|
|
}
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
2003-08-26 18:45:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
// If this site uses Library module, then print recent items
|
|
|
|
if (!empty($CFG->librarypath)) {
|
|
|
|
if (file_exists("$CFG->dirroot/$CFG->librarypath/librarylib.php")) {
|
|
|
|
include_once("$CFG->dirroot/$CFG->librarypath/librarylib.php");
|
|
|
|
if (librarysummarize(5, '', date('YmdHis',$USER->lastlogin))) {
|
|
|
|
$content = true;
|
|
|
|
}
|
|
|
|
}
|
2002-05-31 09:34:50 +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
|
|
|
|
2003-11-21 12:54:09 +00:00
|
|
|
$mods = get_records("modules", "visible", "1", "name", "id, name");
|
|
|
|
|
2003-04-26 15:08:34 +00:00
|
|
|
foreach ($mods as $mod) { // Each module gets it's own logs and prints them
|
2003-11-21 12:54:09 +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)) {
|
|
|
|
$modcontent = $print_recent_activity($course, $isteacher, $timestart);
|
2002-09-21 17:11:08 +00:00
|
|
|
if ($modcontent) {
|
|
|
|
$content = true;
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $content) {
|
2003-04-26 12:17:30 +00:00
|
|
|
echo "<font size=2>".get_string("nothingnew")."</font>";
|
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
|
|
|
|
$mods[$mod->id] = $mod;
|
2002-08-02 17:38:18 +00:00
|
|
|
$mods[$mod->id]->modfullname = $modnames[$mod->modname];
|
2003-04-14 15:11:09 +00:00
|
|
|
if ($mod->visible or isteacher($courseid)) {
|
|
|
|
$modnamesused[$mod->modname] = $modnames[$mod->modname];
|
|
|
|
}
|
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
|
|
|
}
|
2004-07-25 14:00:29 +00:00
|
|
|
|
|
|
|
unset($modnames['resource']);
|
|
|
|
unset($modnames['label']);
|
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 (empty($USER)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($display == "all" or empty($display)) {
|
|
|
|
$display = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) {
|
|
|
|
set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid);
|
|
|
|
} else {
|
|
|
|
$record->userid = $USER->id;
|
|
|
|
$record->course = $courseid;
|
|
|
|
$record->display = $display;
|
|
|
|
if (!insert_record("course_display", $record)) {
|
|
|
|
notify("Could not save your course display!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $USER->display[$courseid] = $display; // Note: = not ==
|
|
|
|
}
|
|
|
|
|
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) {
|
2004-05-05 07:07:56 +00:00
|
|
|
if ($visibility) {
|
|
|
|
show_course_module($moduleid);
|
|
|
|
} else {
|
|
|
|
hide_course_module($moduleid);
|
|
|
|
}
|
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;
|
2003-07-12 06:52:26 +00:00
|
|
|
|
2004-02-15 03:20:51 +00:00
|
|
|
|
2003-07-12 06:52:26 +00:00
|
|
|
if (!isset($isteacher)) {
|
2004-02-15 04:13:25 +00:00
|
|
|
$groupbuttons = $course->groupmode;
|
|
|
|
$groupbuttonslink = (!$course->groupmodeforce);
|
2003-07-12 06:52:26 +00:00
|
|
|
$isteacher = isteacher($course->id);
|
|
|
|
$isediting = isediting($course->id);
|
2003-07-14 13:08:38 +00:00
|
|
|
$ismoving = 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'"));
|
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2002-11-10 08:55:11 +00:00
|
|
|
$modinfo = unserialize($course->modinfo);
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2004-05-28 10:53:54 +00:00
|
|
|
echo '<table width="'.$width.'" cellpadding="1" cellspacing="0">';
|
2003-03-21 04:53:08 +00:00
|
|
|
if (!empty($section->sequence)) {
|
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
|
|
|
|
2003-07-12 06:52:26 +00:00
|
|
|
if ($mod->visible or $isteacher) {
|
2003-09-14 12:25:16 +00:00
|
|
|
echo "<tr><td class=\"activity$mod->modname\">";
|
2003-07-14 13:08:38 +00:00
|
|
|
if ($ismoving) {
|
|
|
|
if ($mod->id == $USER->activitycopy) {
|
|
|
|
continue;
|
|
|
|
}
|
2003-10-27 08:31:28 +00:00
|
|
|
echo "<a title=\"$strmovefull\"".
|
2004-07-02 09:32:17 +00:00
|
|
|
" href=\"$CFG->wwwroot/course/mod.php?moveto=$mod->id\">".
|
2003-10-27 08:31:28 +00:00
|
|
|
"<img height=\"16\" width=\"80\" src=\"$CFG->pixpath/movehere.gif\" ".
|
|
|
|
" alt=\"$strmovehere\" border=\"0\"></a><br />\n";
|
2003-04-14 15:11:09 +00:00
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
$instancename = urldecode($modinfo[$modnumber]->name);
|
2004-02-15 10:08:05 +00:00
|
|
|
if (!empty($CFG->filterall)) {
|
2004-03-22 16:16:49 +00:00
|
|
|
$instancename = filter_text("<nolink>$instancename</nolink>", $course->id);
|
2004-02-15 10:08:05 +00:00
|
|
|
}
|
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\">";
|
|
|
|
}
|
2003-09-14 12:25:16 +00:00
|
|
|
echo format_text($extra, FORMAT_HTML);
|
2003-09-14 16:31:33 +00:00
|
|
|
if (!$mod->visible) {
|
|
|
|
echo "</span>";
|
|
|
|
}
|
2003-09-14 12:25:16 +00:00
|
|
|
|
|
|
|
} else { // Normal activity
|
|
|
|
$linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
|
2004-04-26 15:31:22 +00:00
|
|
|
echo "<img src=\"$icon\"".
|
2003-09-14 12:25:16 +00:00
|
|
|
" height=16 width=16 alt=\"$mod->modfullname\">".
|
|
|
|
" <font size=2><a title=\"$mod->modfullname\" $linkcss $extra".
|
|
|
|
" href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a></font>";
|
|
|
|
}
|
|
|
|
if ($isediting) {
|
2004-02-15 04:13:25 +00:00
|
|
|
if ($groupbuttons) {
|
|
|
|
if (! $mod->groupmodelink = $groupbuttonslink) {
|
|
|
|
$mod->groupmode = $course->groupmode;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2004-01-31 08:40:38 +00:00
|
|
|
$mod->groupmode = false;
|
|
|
|
}
|
2003-09-16 05:48:09 +00:00
|
|
|
echo " ";
|
2004-01-31 08:40:38 +00:00
|
|
|
echo make_editing_buttons($mod, $absolute, true, $mod->indent);
|
2003-09-14 12:25:16 +00:00
|
|
|
}
|
2003-09-16 05:48:09 +00:00
|
|
|
echo "</td>";
|
2003-09-14 12:25:16 +00:00
|
|
|
echo "</tr>";
|
2002-08-03 08:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
if ($ismoving) {
|
2003-10-27 08:31:28 +00:00
|
|
|
echo "<tr><td><a title=\"$strmovefull\"".
|
|
|
|
" href=\"mod.php?movetosection=$section->id\">".
|
|
|
|
"<img height=\"16\" width=\"80\" src=\"$CFG->pixpath/movehere.gif\" ".
|
|
|
|
" alt=\"$strmovehere\" border=\"0\"></a></td></tr>\n";
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2003-09-14 12:25:16 +00:00
|
|
|
echo "</table>\n\n";
|
2002-08-04 13:25:53 +00:00
|
|
|
}
|
|
|
|
|
2003-05-09 17:24:17 +00:00
|
|
|
|
2004-07-26 16:05:09 +00:00
|
|
|
function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false) {
|
2004-07-25 14:00:29 +00:00
|
|
|
// Prints the menus to add activities and resources
|
|
|
|
|
2004-07-27 01:43:43 +00:00
|
|
|
global $CFG;
|
2004-07-25 14:00:29 +00:00
|
|
|
static $straddactivity, $straddresource, $resources;
|
|
|
|
|
|
|
|
if (!isset($straddactivity)) {
|
|
|
|
$straddactivity = get_string('addactivity');
|
|
|
|
$straddresource = get_string('addresource');
|
|
|
|
$resourcetypes = get_list_of_plugins('mod/resource/type');
|
|
|
|
foreach ($resourcetypes as $resourcetype) {
|
|
|
|
$resources["resource&type=$resourcetype"] = get_string("resourcetype$resourcetype", 'resource');
|
|
|
|
}
|
|
|
|
asort($resources);
|
|
|
|
$resources['label'] = get_string('resourcetypelabel', 'resource');
|
|
|
|
}
|
|
|
|
|
2004-07-26 16:05:09 +00:00
|
|
|
$output = '';
|
|
|
|
|
|
|
|
$output .= '<div align="right"><table align="right"><tr><td>';
|
|
|
|
$output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=",
|
|
|
|
$resources, "ressection$section", "", $straddresource, '', '', true);
|
|
|
|
$output .= '</td>';
|
|
|
|
|
|
|
|
if ($vertical) {
|
|
|
|
$output .= '</tr><tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '<td>';
|
|
|
|
$output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=",
|
|
|
|
$modnames, "section$section", "", $straddactivity, '', '', true);
|
|
|
|
$output .= '</td></tr></table>';
|
|
|
|
$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 = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($courses = get_records_select("course", $select)) {
|
|
|
|
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'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-09 13:36:55 +00:00
|
|
|
function print_heading_block($heading, $width="100%", $class="headingblock") {
|
2002-12-09 07:35:40 +00:00
|
|
|
global $THEME;
|
|
|
|
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";
|
|
|
|
echo "<tr><td bgcolor=\"$THEME->cellheading\" class=\"$class\">";
|
2002-12-09 07:35:40 +00:00
|
|
|
echo stripslashes($heading);
|
|
|
|
echo "</td></tr></table>";
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
if ($category) {
|
|
|
|
if ($path) {
|
|
|
|
$path = "$path / $category->name";
|
|
|
|
} else {
|
|
|
|
$path = "$category->name";
|
|
|
|
}
|
|
|
|
$list[$category->id] = $path;
|
|
|
|
} else {
|
|
|
|
$category->id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($categories = get_categories("$category->id")) { // Print all the children recursively
|
|
|
|
foreach ($categories as $cat) {
|
|
|
|
if (!empty($category->id)) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1) {
|
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;
|
|
|
|
if (isset($CFG->max_category_depth)&&($depth >= $CFG->max_category_depth)) {
|
|
|
|
return;
|
|
|
|
}
|
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) {
|
2003-09-03 08:29:05 +00:00
|
|
|
if ($category->visible or iscreator()) {
|
2003-08-07 16:01:31 +00:00
|
|
|
print_category_info($category, $depth);
|
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;
|
|
|
|
|
2004-05-28 10:53:54 +00:00
|
|
|
print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
function print_category_info($category, $depth) {
|
|
|
|
/// 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)) {
|
|
|
|
$strallowguests = get_string("allowguests");
|
|
|
|
$strrequireskey = get_string("requireskey");
|
|
|
|
$strsummary = get_string("summary");
|
|
|
|
}
|
2002-09-09 11:48:11 +00:00
|
|
|
|
2003-08-29 01:31:41 +00:00
|
|
|
$catlinkcss = $category->visible ? "" : " class=\"dimmed\" ";
|
|
|
|
|
2003-08-21 09:33:07 +00:00
|
|
|
if ($CFG->frontpage == FRONTPAGECOURSELIST) {
|
2003-09-14 12:25:16 +00:00
|
|
|
$catimage = "<img src=\"$CFG->pixpath/i/course.gif\" width=16 height=16 border=0>";
|
2003-09-03 12:13:08 +00:00
|
|
|
} else {
|
|
|
|
$catimage = " ";
|
2003-08-21 09:33:07 +00:00
|
|
|
}
|
2003-09-03 12:13:08 +00:00
|
|
|
|
|
|
|
echo "\n\n<table border=0 cellpadding=3 cellspacing=0 width=\"100%\"><tr>";
|
2003-08-07 16:01:31 +00:00
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
if ($CFG->frontpage == FRONTPAGECOURSELIST) {
|
2003-09-03 12:13:08 +00:00
|
|
|
$courses = get_courses($category->id);
|
|
|
|
|
|
|
|
echo "<tr>";
|
|
|
|
|
|
|
|
if ($depth) {
|
|
|
|
$indent = $depth*30;
|
|
|
|
$rows = count($courses) + 1;
|
|
|
|
echo "<td rowspan=\"$rows\" valign=\"top\" width=\"$indent\">";
|
|
|
|
print_spacer(10, $indent);
|
|
|
|
echo "</td>";
|
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2003-09-03 12:13:08 +00:00
|
|
|
echo "<td valign=\"top\">$catimage</td>";
|
2003-09-03 15:25:08 +00:00
|
|
|
echo "<td valign=\"top\" width=\"100%\" class=\"categoryname\">";
|
2003-09-03 12:13:08 +00:00
|
|
|
echo "<a $catlinkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>";
|
2003-09-03 15:25:08 +00:00
|
|
|
echo "</td>";
|
|
|
|
echo "<td class=\"categoryname\"> </td>";
|
2003-09-03 12:13:08 +00:00
|
|
|
echo "</tr>\n";
|
|
|
|
|
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) {
|
|
|
|
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
|
2003-09-03 12:13:08 +00:00
|
|
|
echo "<tr><td valign=\"top\" width=\"30\"> ";
|
2003-09-03 15:25:08 +00:00
|
|
|
echo "</td>\n<td valign=\"top\" width=\"100%\" class=\"coursename\">";
|
2003-07-30 13:57:39 +00:00
|
|
|
echo "<a $linkcss href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
|
2003-09-03 15:25:08 +00:00
|
|
|
echo "</td>\n<td align=\"right\" valign=\"top\" nowrap class=\"coursename\">";
|
2003-07-30 13:02:45 +00:00
|
|
|
if ($course->guest ) {
|
|
|
|
echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
2004-01-25 17:00:12 +00:00
|
|
|
echo "<img hspace=1 alt=\"$strallowguests\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/guest.gif\"></a>";
|
2003-09-10 08:53:43 +00:00
|
|
|
} else {
|
2003-09-14 12:25:16 +00:00
|
|
|
echo "<img alt=\"\" height=16 width=18 border=0 src=\"$CFG->pixpath/spacer.gif\">";
|
2002-09-10 13:47:56 +00:00
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
if ($course->password) {
|
|
|
|
echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
2004-01-25 17:00:12 +00:00
|
|
|
echo "<img hspace=1 alt=\"$strrequireskey\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/key.gif\"></a>";
|
2003-09-10 08:53:43 +00:00
|
|
|
} else {
|
2003-09-14 12:25:16 +00:00
|
|
|
echo "<img alt=\"\" height=16 width=18 border=0 src=\"$CFG->pixpath/spacer.gif\">";
|
2003-09-03 12:13:08 +00:00
|
|
|
}
|
|
|
|
if ($course->summary) {
|
2004-05-28 10:53:54 +00:00
|
|
|
link_to_popup_window ("/course/info.php?id=$course->id", "courseinfo",
|
|
|
|
"<img hspace=1 alt=\"$strsummary\" height=16 width=16 border=0 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 {
|
2003-09-14 12:25:16 +00:00
|
|
|
echo "<img alt=\"\" height=16 width=18 border=0 src=\"$CFG->pixpath/spacer.gif\">";
|
2002-09-10 13:47:56 +00:00
|
|
|
}
|
2003-09-03 12:13:08 +00:00
|
|
|
echo "</td></tr>\n";
|
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
|
|
|
|
|
|
|
if ($depth) {
|
|
|
|
$indent = $depth*20;
|
|
|
|
echo "<td valign=\"top\" width=\"$indent\">";
|
|
|
|
print_spacer(10, $indent);
|
|
|
|
echo "</td>";
|
2003-08-07 16:01:31 +00:00
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2003-09-03 15:25:08 +00:00
|
|
|
echo "<td valign=\"top\" width=\"100%\" class=\"categoryname\">";
|
2003-09-03 12:13:08 +00:00
|
|
|
echo "<a $catlinkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>";
|
2003-09-03 15:25:08 +00:00
|
|
|
echo "</td>";
|
2003-11-19 02:52:26 +00:00
|
|
|
echo "<td valign=\"top\" class=\"categorynumber\">$category->coursecount</td></tr>";
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
2003-09-03 12:13:08 +00:00
|
|
|
echo "\n</table>\n";
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_courses($category, $width="100%") {
|
|
|
|
/// Category is 0 (for all courses) or an object
|
|
|
|
|
|
|
|
global $CFG, $THEME;
|
|
|
|
|
|
|
|
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);
|
2003-08-07 16:01:31 +00:00
|
|
|
$courses = get_courses($category->id);
|
2003-07-30 13:56:17 +00:00
|
|
|
} else {
|
2003-08-07 16:01:31 +00:00
|
|
|
$courses = get_courses("all");
|
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
|
2003-08-07 16:01:31 +00:00
|
|
|
$courses = get_courses($category->id);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($courses) {
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
print_course($course, $width);
|
|
|
|
echo "<br />\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print_heading(get_string("nocoursesyet"));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_course($course, $width="100%") {
|
|
|
|
|
|
|
|
global $CFG, $THEME;
|
|
|
|
|
2004-06-26 09:51:13 +00:00
|
|
|
static $enrol;
|
|
|
|
|
|
|
|
if (empty($enrol)) {
|
|
|
|
require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php");
|
|
|
|
$enrol = new enrolment_plugin;
|
|
|
|
}
|
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
if (! $site = get_site()) {
|
|
|
|
error("Could not find a site!");
|
|
|
|
}
|
|
|
|
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2003-10-21 06:40:39 +00:00
|
|
|
print_simple_box_start("center", "$width", $THEME->cellcontent, 5, "coursebox");
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-21 17:30:39 +00:00
|
|
|
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
|
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
echo "<table width=\"100%\">";
|
|
|
|
echo "<tr valign=top>";
|
2003-10-21 06:40:39 +00:00
|
|
|
echo "<td valign=top width=\"50%\" class=\"courseboxinfo\">";
|
2004-05-28 10:53:54 +00:00
|
|
|
echo "<p><font size=3><b><a title=\"".get_string("entercourse")."\"
|
2003-08-21 17:30:39 +00:00
|
|
|
$linkcss href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a></b></font></p>";
|
2003-07-30 13:02:45 +00:00
|
|
|
if ($teachers = get_course_teachers($course->id)) {
|
|
|
|
echo "<p><font size=\"1\">\n";
|
|
|
|
foreach ($teachers as $teacher) {
|
|
|
|
if ($teacher->authority > 0) {
|
|
|
|
if (!$teacher->role) {
|
|
|
|
$teacher->role = $course->teacher;
|
|
|
|
}
|
2003-11-19 16:30:09 +00:00
|
|
|
$fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course
|
|
|
|
echo "$teacher->role: <a href=\"$CFG->wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$fullname</a><br />";
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "</font></p>";
|
|
|
|
}
|
|
|
|
|
2004-06-26 09:51:13 +00:00
|
|
|
echo $enrol->get_access_icons($course);
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-10-21 06:40:39 +00:00
|
|
|
echo "</td><td valign=top width=\"50%\" class=\"courseboxsummary\">";
|
2004-01-25 16:50:49 +00:00
|
|
|
echo "<p><font size=2>".filter_text(text_to_html($course->summary), $course->id)."</font></p>";
|
2003-07-30 13:02:45 +00:00
|
|
|
echo "</td></tr>";
|
|
|
|
echo "</table>";
|
|
|
|
|
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_my_moodle() {
|
|
|
|
/// Prints custom user information on the home page.
|
|
|
|
/// Over time this can include all sorts of information
|
|
|
|
|
|
|
|
global $USER, $CFG;
|
|
|
|
|
|
|
|
if (!isset($USER->id)) {
|
|
|
|
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) {
|
2003-08-26 15:55:03 +00:00
|
|
|
if (!$course->category) {
|
|
|
|
continue;
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
print_course($course, "100%");
|
|
|
|
echo "<br />\n";
|
|
|
|
}
|
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");
|
|
|
|
|
2003-08-19 05:32:20 +00:00
|
|
|
if ($format == "plain") {
|
|
|
|
$output = "<center><p align=\"center\" class=\"coursesearchbox\">";
|
|
|
|
$output .= "<form name=\"coursesearch\" action=\"$CFG->wwwroot/course/search.php\" method=\"get\">";
|
|
|
|
$output .= "<input type=\"text\" size=30 name=\"search\" value=\"$value\">";
|
|
|
|
$output .= "<input type=\"submit\" value=\"$strsearchcourses\">";
|
|
|
|
$output .= "</form></p></center>";
|
2003-09-09 08:37:48 +00:00
|
|
|
} else if ($format == "short") {
|
|
|
|
$output = "<center><p align=\"center\" class=\"coursesearchbox\">";
|
|
|
|
$output .= "<form name=\"coursesearch\" action=\"$CFG->wwwroot/course/search.php\" method=\"get\">";
|
|
|
|
$output .= "<input type=\"text\" size=12 name=\"search\" value=\"$value\">";
|
|
|
|
$output .= "<input type=\"submit\" value=\"$strsearchcourses\">";
|
|
|
|
$output .= "</form></p></center>";
|
2003-08-19 05:32:20 +00:00
|
|
|
} else if ($format == "navbar") {
|
|
|
|
$output = "<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>";
|
|
|
|
$output .= "<form name=\"coursesearch\" action=\"$CFG->wwwroot/course/search.php\" method=\"get\">";
|
|
|
|
$output .= "<input type=\"text\" size=20 name=\"search\" value=\"$value\">";
|
|
|
|
$output .= "<input type=\"submit\" value=\"$strsearchcourses\">";
|
|
|
|
$output .= "</form>";
|
|
|
|
$output .= "</td></tr></table>";
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-31 08:40:38 +00:00
|
|
|
function set_groupmode_for_module($id, $groupmode) {
|
|
|
|
return set_field("course_modules", "groupmode", $groupmode, "id", $id);
|
|
|
|
}
|
|
|
|
|
2003-04-14 15:11:09 +00:00
|
|
|
function hide_course_module($mod) {
|
2004-05-05 07:07:56 +00:00
|
|
|
$cm = get_record('course_modules', 'id', $mod);
|
|
|
|
$modulename = get_field('modules', 'name', 'id', $cm->module);
|
|
|
|
if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
|
|
|
|
foreach($events as $event) {
|
|
|
|
hide_event($event);
|
|
|
|
}
|
|
|
|
}
|
2003-04-14 15:11:09 +00:00
|
|
|
return set_field("course_modules", "visible", 0, "id", $mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_course_module($mod) {
|
2004-05-05 07:07:56 +00:00
|
|
|
$cm = get_record('course_modules', 'id', $mod);
|
|
|
|
$modulename = get_field('modules', 'name', 'id', $cm->module);
|
|
|
|
if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
|
|
|
|
foreach($events as $event) {
|
|
|
|
show_event($event);
|
|
|
|
}
|
|
|
|
}
|
2003-04-14 15:11:09 +00:00
|
|
|
return set_field("course_modules", "visible", 1, "id", $mod);
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function delete_course_module($mod) {
|
|
|
|
return set_field("course_modules", "deleted", 1, "id", $mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2002-11-10 14:45:11 +00:00
|
|
|
function move_module($cm, $move) {
|
2003-06-10 15:27:09 +00:00
|
|
|
/// Moves an activity module up and down within the course
|
2002-08-01 03:50:27 +00:00
|
|
|
|
|
|
|
if (!$move) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $thissection = get_record("course_sections", "id", $cm->section)) {
|
|
|
|
error("This course section doesn't exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
$mods = explode(",", $thissection->sequence);
|
|
|
|
|
|
|
|
$len = count($mods);
|
|
|
|
$pos = array_keys($mods, $cm->id);
|
|
|
|
$thepos = $pos[0];
|
|
|
|
|
|
|
|
if ($len == 0 || count($pos) == 0 ) {
|
|
|
|
error("Very strange. Could not find the required module in this section.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($len == 1) {
|
|
|
|
$first = true;
|
|
|
|
$last = true;
|
|
|
|
} else {
|
|
|
|
$first = ($thepos == 0);
|
|
|
|
$last = ($thepos == $len - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($move < 0) { // Moving the module up
|
|
|
|
|
|
|
|
if ($first) {
|
2003-06-10 13:26:26 +00:00
|
|
|
if ($thissection->section == 0) { // First section, do nothing
|
2002-08-01 03:50:27 +00:00
|
|
|
return true;
|
2003-06-10 13:26:26 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
} else { // Push onto end of previous section
|
|
|
|
$prevsectionnumber = $thissection->section - 1;
|
2004-05-28 10:53:54 +00:00
|
|
|
if (! $prevsection = get_record("course_sections", "course", "$thissection->course",
|
2002-12-20 14:44:14 +00:00
|
|
|
"section", "$prevsectionnumber")) {
|
2002-08-01 03:50:27 +00:00
|
|
|
error("Previous section ($prevsection->id) doesn't exist");
|
|
|
|
}
|
|
|
|
|
2003-03-21 04:53:08 +00:00
|
|
|
if (!empty($prevsection->sequence)) {
|
2002-08-01 03:50:27 +00:00
|
|
|
$newsequence = "$prevsection->sequence,$cm->id";
|
|
|
|
} else {
|
|
|
|
$newsequence = "$cm->id";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) {
|
|
|
|
error("Previous section could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) {
|
|
|
|
error("Module could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
array_splice($mods, 0, 1);
|
|
|
|
$newsequence = implode(",", $mods);
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
|
|
|
|
error("Module could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else { // move up within this section
|
|
|
|
$swap = $mods[$thepos-1];
|
|
|
|
$mods[$thepos-1] = $mods[$thepos];
|
|
|
|
$mods[$thepos] = $swap;
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
$newsequence = implode(",", $mods);
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
|
|
|
|
error("This section could not be updated");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // Moving the module down
|
|
|
|
|
|
|
|
if ($last) {
|
|
|
|
$nextsectionnumber = $thissection->section + 1;
|
2004-05-28 10:53:54 +00:00
|
|
|
if ($nextsection = get_record("course_sections", "course", "$thissection->course",
|
2002-12-20 14:44:14 +00:00
|
|
|
"section", "$nextsectionnumber")) {
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2003-03-21 04:53:08 +00:00
|
|
|
if (!empty($nextsection->sequence)) {
|
2002-08-01 03:50:27 +00:00
|
|
|
$newsequence = "$cm->id,$nextsection->sequence";
|
|
|
|
} else {
|
|
|
|
$newsequence = "$cm->id";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) {
|
|
|
|
error("Next section could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) {
|
|
|
|
error("Module could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
array_splice($mods, $thepos, 1);
|
|
|
|
$newsequence = implode(",", $mods);
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
|
|
|
|
error("This section could not be updated");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else { // There is no next section, so just return
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else { // move down within this section
|
|
|
|
$swap = $mods[$thepos+1];
|
|
|
|
$mods[$thepos+1] = $mods[$thepos];
|
|
|
|
$mods[$thepos] = $swap;
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
$newsequence = implode(",", $mods);
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
|
|
|
|
error("This section could not be updated");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-31 08:40:38 +00:00
|
|
|
function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-1) {
|
2003-04-28 04:32:55 +00:00
|
|
|
global $CFG, $THEME;
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2004-01-31 08:40:38 +00:00
|
|
|
static $str;
|
|
|
|
|
|
|
|
if (!isset($str)) {
|
|
|
|
$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");
|
2004-05-30 23:09:21 +00:00
|
|
|
$str->duplicate = get_string("duplicate");
|
2004-01-31 08:40:38 +00:00
|
|
|
$str->hide = get_string("hide");
|
|
|
|
$str->show = get_string("show");
|
|
|
|
$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");
|
2003-04-14 15:11:09 +00:00
|
|
|
}
|
2002-08-03 08:16:31 +00:00
|
|
|
|
|
|
|
if ($absolute) {
|
2003-04-28 04:32:55 +00:00
|
|
|
$path = "$CFG->wwwroot/course";
|
|
|
|
} else {
|
|
|
|
$path = ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($THEME->custompix)) {
|
|
|
|
$pixpath = "$path/../pix";
|
2002-08-03 08:16:31 +00:00
|
|
|
} else {
|
2003-04-28 04:32:55 +00:00
|
|
|
$pixpath = "$path/../theme/$CFG->theme/pix";
|
2002-08-03 08:16:31 +00:00
|
|
|
}
|
2003-04-14 15:11:09 +00:00
|
|
|
|
2004-01-31 08:40:38 +00:00
|
|
|
if ($mod->visible) {
|
|
|
|
$hideshow = "<a title=\"$str->hide\" href=\"$path/mod.php?hide=$mod->id\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/hide.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"$str->hide\"></a> ";
|
2003-04-14 15:11:09 +00:00
|
|
|
} else {
|
2004-01-31 08:40:38 +00:00
|
|
|
$hideshow = "<a title=\"$str->show\" href=\"$path/mod.php?show=$mod->id\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/show.gif\" hspace=\"2\" height=\"11\" width=\"11\" ".
|
|
|
|
"border=\"0\" alt=\"$str->show\"></a> ";
|
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;
|
|
|
|
$groupimage = "$pixpath/t/groups.gif";
|
|
|
|
$grouplink = "$path/mod.php?id=$mod->id&groupmode=0";
|
2004-01-31 08:40:38 +00:00
|
|
|
} else if ($mod->groupmode == VISIBLEGROUPS) {
|
2004-02-15 04:13:25 +00:00
|
|
|
$grouptitle = $str->groupsvisible;
|
|
|
|
$groupimage = "$pixpath/t/groupv.gif";
|
|
|
|
$grouplink = "$path/mod.php?id=$mod->id&groupmode=1";
|
|
|
|
} else {
|
|
|
|
$grouptitle = $str->groupsnone;
|
|
|
|
$groupimage = "$pixpath/t/groupn.gif";
|
|
|
|
$grouplink = "$path/mod.php?id=$mod->id&groupmode=2";
|
|
|
|
}
|
|
|
|
if ($mod->groupmodelink) {
|
|
|
|
$groupmode = "<a title=\"$grouptitle ($str->clicktochange)\" href=\"$grouplink\">".
|
2004-07-28 11:52:39 +00:00
|
|
|
"<img src=\"$groupimage\" hspace=\"2\" height=\"11\" width=\"11\" ".
|
|
|
|
"border=\"0\" alt=\"$grouptitle\"></a>";
|
2004-01-31 08:40:38 +00:00
|
|
|
} else {
|
2004-02-15 04:13:25 +00:00
|
|
|
$groupmode = "<img title=\"$grouptitle ($str->forcedmode)\" ".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$groupimage\" hspace=\"2\" height=\"11\" width=\"11\" ".
|
|
|
|
"border=\"0\" alt=\"$grouptitle\">";
|
2004-01-31 08:40:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$groupmode = "";
|
|
|
|
}
|
2003-07-14 13:08:38 +00:00
|
|
|
|
|
|
|
if ($moveselect) {
|
2004-01-31 08:40:38 +00:00
|
|
|
$move = "<a title=\"$str->move\" href=\"$path/mod.php?copy=$mod->id\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/move.gif\" hspace=\"2\" height=\"11\" width=\"11\" ".
|
|
|
|
" border=\"0\" alt=\"$str->move\"></a>";
|
2003-07-14 16:22:42 +00:00
|
|
|
} else {
|
2004-01-31 08:40:38 +00:00
|
|
|
$move = "<a title=\"$str->moveup\" href=\"$path/mod.php?id=$mod->id&move=-1\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/up.gif\" hspace=\"2\" height=\"11\" width=\"11\" ".
|
|
|
|
" border=\"0\" alt=\"$str->moveup\"></a>".
|
2004-01-31 08:40:38 +00:00
|
|
|
"<a title=\"$str->movedown\" href=\"$path/mod.php?id=$mod->id&move=1\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/down.gif\" hspace=\"2\" height=\"11\" width=\"11\" ".
|
|
|
|
" border=\"0\" alt=\"$str->movedown\"></a>";
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 16:31:33 +00:00
|
|
|
$leftright = "";
|
|
|
|
if ($indent > 0) {
|
2004-01-31 08:40:38 +00:00
|
|
|
$leftright .= "<a title=\"$str->moveleft\" href=\"$path/mod.php?id=$mod->id&indent=-1\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/left.gif\" hspace=\"2\" height=\"11\" width=\"11\" ".
|
|
|
|
" border=\"0\" alt=\"$str->moveleft\"></a>";
|
2003-09-14 16:31:33 +00:00
|
|
|
}
|
|
|
|
if ($indent >= 0) {
|
2004-01-31 08:40:38 +00:00
|
|
|
$leftright .= "<a title=\"$str->moveright\" href=\"$path/mod.php?id=$mod->id&indent=1\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/right.gif\" hspace=\"2\" height=\"11\" width=\"11\" ".
|
|
|
|
" border=\"0\" alt=\"$str->moveright\"></a>";
|
2003-09-14 16:31:33 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 16:43:10 +00:00
|
|
|
return "$leftright$move".
|
2004-01-31 08:40:38 +00:00
|
|
|
"<a title=\"$str->update\" href=\"$path/mod.php?update=$mod->id\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/edit.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" ".
|
|
|
|
" alt=\"$str->update\"></a>".
|
2004-06-21 14:51:43 +00:00
|
|
|
// Following line is commented out until this feature is more definite -- martin
|
|
|
|
// "<a title=\"$str->duplicate\" href=\"$path/mod.php?duplicate=$mod->id\"> 2 </a>".
|
2004-01-31 08:40:38 +00:00
|
|
|
"<a title=\"$str->delete\" href=\"$path/mod.php?delete=$mod->id\"><img".
|
2004-07-28 11:52:39 +00:00
|
|
|
" src=\"$pixpath/t/delete.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" ".
|
|
|
|
" alt=\"$str->delete\"></a>$hideshow$groupmode";
|
2002-08-02 17:38:18 +00:00
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
?>
|