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
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
require_once($CFG->libdir.'/completionlib.php');
|
2001-11-22 06:23:56 +00:00
|
|
|
|
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
|
2007-12-19 17:35:20 +00:00
|
|
|
define('FRONTPAGENEWS', '0');
|
|
|
|
define('FRONTPAGECOURSELIST', '1');
|
|
|
|
define('FRONTPAGECATEGORYNAMES', '2');
|
|
|
|
define('FRONTPAGETOPICONLY', '3');
|
|
|
|
define('FRONTPAGECATEGORYCOMBO', '4');
|
2006-07-19 12:10:07 +00:00
|
|
|
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);
|
|
|
|
|
2009-08-07 07:18:01 +00:00
|
|
|
if (!defined('MAX_MODINFO_CACHE_SIZE')) {
|
2009-04-06 09:48:39 +00:00
|
|
|
define('MAX_MODINFO_CACHE_SIZE', 10);
|
|
|
|
}
|
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 'course':
|
|
|
|
case 'file':
|
|
|
|
case 'login':
|
|
|
|
case 'lib':
|
|
|
|
case 'admin':
|
|
|
|
case 'calendar':
|
2007-08-06 18:19:15 +00:00
|
|
|
case 'mnet course':
|
2009-01-07 23:00:59 +00:00
|
|
|
if (strpos($url, '../') === 0) {
|
|
|
|
$url = ltrim($url, '.');
|
|
|
|
} else {
|
|
|
|
$url = "/course/$url";
|
|
|
|
}
|
2007-08-06 18:19:15 +00:00
|
|
|
break;
|
2008-03-19 22:48:13 +00:00
|
|
|
case 'user':
|
2006-05-01 06:04:22 +00:00
|
|
|
case 'blog':
|
2009-01-07 23:00:59 +00:00
|
|
|
$url = "/$module/$url";
|
2002-05-31 09:34:50 +00:00
|
|
|
break;
|
2006-05-01 06:04:22 +00:00
|
|
|
case 'upload':
|
2009-01-07 23:00:59 +00:00
|
|
|
$url = $url;
|
2004-09-17 00:10:53 +00:00
|
|
|
break;
|
2008-06-30 09:04:07 +00:00
|
|
|
case 'coursetags':
|
2009-01-07 23:00:59 +00:00
|
|
|
$url = '/'.$url;
|
2008-06-30 09:04:07 +00:00
|
|
|
break;
|
2006-05-01 06:04:22 +00:00
|
|
|
case 'library':
|
|
|
|
case '':
|
2009-01-07 23:00:59 +00:00
|
|
|
$url = '/';
|
2004-08-17 14:26:47 +00:00
|
|
|
break;
|
2008-01-09 10:12:31 +00:00
|
|
|
case 'message':
|
2009-01-07 23:00:59 +00:00
|
|
|
$url = "/message/$url";
|
|
|
|
break;
|
|
|
|
case 'notes':
|
|
|
|
$url = "/notes/$url";
|
2008-01-09 10:12:31 +00:00
|
|
|
break;
|
2002-05-31 09:34:50 +00:00
|
|
|
default:
|
2009-01-07 23:00:59 +00:00
|
|
|
$url = "/mod/$module/$url";
|
2002-05-31 09:34:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-01-07 23:00:59 +00:00
|
|
|
|
|
|
|
//now let's sanitise urls - there might be some ugly nasties:-(
|
|
|
|
$parts = explode('?', $url);
|
|
|
|
$script = array_shift($parts);
|
|
|
|
if (strpos($script, 'http') === 0) {
|
|
|
|
$script = clean_param($script, PARAM_URL);
|
|
|
|
} else {
|
|
|
|
$script = clean_param($script, PARAM_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = '';
|
|
|
|
if ($parts) {
|
|
|
|
$query = implode('', $parts);
|
|
|
|
$query = str_replace('&', '&', $query); // both & and & are stored in db :-|
|
|
|
|
$parts = explode('&', $query);
|
|
|
|
$eq = urlencode('=');
|
|
|
|
foreach ($parts as $key=>$part) {
|
|
|
|
$part = urlencode(urldecode($part));
|
|
|
|
$part = str_replace($eq, '=', $part);
|
|
|
|
$parts[$key] = $part;
|
|
|
|
}
|
|
|
|
$query = '?'.implode('&', $parts);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $script.$query;
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $CFG, $DB;
|
2007-01-04 03:22:51 +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.
|
|
|
|
|
|
|
|
/// Setup for group handling.
|
2008-06-04 06:38:03 +00:00
|
|
|
|
|
|
|
// TODO: I don't understand group/context/etc. enough to be able to do
|
2007-01-04 03:22:51 +00:00
|
|
|
// something interesting with it here
|
|
|
|
// What is the context of a remote course?
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-01-04 03:22: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.
|
|
|
|
//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;
|
|
|
|
//}
|
2008-06-01 19:05:07 +00:00
|
|
|
|
|
|
|
$ILIKE = $DB->sql_ilike();
|
|
|
|
|
2007-01-04 03:22:51 +00:00
|
|
|
$groupid = 0;
|
|
|
|
|
|
|
|
$joins = array();
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
$qry = "SELECT l.*, u.firstname, u.lastname, u.picture
|
|
|
|
FROM {mnet_log} l
|
|
|
|
LEFT JOIN {user} u ON l.userid = u.id
|
|
|
|
WHERE ";
|
|
|
|
$params = array();
|
|
|
|
|
|
|
|
$where .= "l.hostid = :hostid";
|
|
|
|
$params['hostid'] = $hostid;
|
2007-01-04 03:22:51 +00:00
|
|
|
|
|
|
|
// TODO: Is 1 really a magic number referring to the sitename?
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($course != SITEID || $modid != 0) {
|
|
|
|
$where .= " AND l.course=:courseid";
|
|
|
|
$params['courseid'] = $course;
|
2007-01-04 03:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($modname) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$where .= " AND l.module = :modname";
|
|
|
|
$params['modname'] = $modname;
|
2007-01-04 03:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ('site_errors' === $modid) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$where .= " AND ( l.action='error' OR l.action='infected' )";
|
2007-01-04 03:22:51 +00:00
|
|
|
} else if ($modid) {
|
2008-06-04 06:38:03 +00:00
|
|
|
//TODO: This assumes that modids are the same across sites... probably
|
2007-01-04 03:22:51 +00:00
|
|
|
//not true
|
2008-06-01 19:05:07 +00:00
|
|
|
$where .= " AND l.cmid = :modid";
|
|
|
|
$params['modid'] = $modid;
|
2007-01-04 03:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($modaction) {
|
|
|
|
$firstletter = substr($modaction, 0, 1);
|
2008-04-24 06:40:26 +00:00
|
|
|
if (preg_match('/[[:alpha:]]/', $firstletter)) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$where .= " AND lower(l.action) $ILIKE :modaction";
|
|
|
|
$params['modaction'] = "%$modaction%";
|
2007-01-04 03:22:51 +00:00
|
|
|
} else if ($firstletter == '-') {
|
2008-06-01 19:05:07 +00:00
|
|
|
$where .= " AND lower(l.action) NOT $ILIKE :modaction";
|
|
|
|
$params['modaction'] = "%$modaction%";
|
2007-01-04 03:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$where .= " AND l.userid = :user";
|
|
|
|
$params['user'] = $user;
|
2007-01-04 03:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($date) {
|
|
|
|
$enddate = $date + 86400;
|
2008-06-01 19:05:07 +00:00
|
|
|
$where .= " AND l.time > :date AND l.time < :enddate";
|
|
|
|
$params['date'] = $date;
|
|
|
|
$params['enddate'] = $enddate;
|
2007-01-04 03:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$result = array();
|
2008-06-01 19:05:07 +00:00
|
|
|
$result['totalcount'] = $DB->count_records_sql("SELECT COUNT('x') FROM {mnet_log} l WHERE $where", $params);
|
2007-01-04 03:22:51 +00:00
|
|
|
if(!empty($result['totalcount'])) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$where .= " ORDER BY $order";
|
|
|
|
$result['logs'] = $DB->get_records_sql("$qry $where", $params, $limitfrom, $limitnum);
|
2007-01-04 03:22:51 +00:00
|
|
|
} 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) {
|
2008-05-30 16:47:21 +00:00
|
|
|
global $DB;
|
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();
|
2008-05-30 16:47:21 +00:00
|
|
|
$oarams = array();
|
2002-08-08 16:22:44 +00:00
|
|
|
|
2006-04-21 05:39:20 +00:00
|
|
|
if ($course->id != SITEID || $modid != 0) {
|
2008-05-30 16:47:21 +00:00
|
|
|
$joins[] = "l.course = :courseid";
|
|
|
|
$params['courseid'] = $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) {
|
2008-05-30 16:47:21 +00:00
|
|
|
$joins[] = "l.module = :modname";
|
2008-06-04 06:38:03 +00:00
|
|
|
$params['modname'] = $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) {
|
2008-05-30 16:47:21 +00:00
|
|
|
$joins[] = "l.cmid = :modid";
|
|
|
|
$params['modid'] = $modid;
|
2004-01-31 14:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($modaction) {
|
2008-05-30 16:47:21 +00:00
|
|
|
$ILIKE = $DB->sql_ilike();
|
2006-03-28 17:33:40 +00:00
|
|
|
$firstletter = substr($modaction, 0, 1);
|
2008-04-24 06:40:26 +00:00
|
|
|
if (preg_match('/[[:alpha:]]/', $firstletter)) {
|
2008-05-30 16:47:21 +00:00
|
|
|
$joins[] = "l.action $ILIKE :modaction";
|
|
|
|
$params['modaction'] = '%'.$modaction.'%';
|
2006-03-28 17:33:40 +00:00
|
|
|
} else if ($firstletter == '-') {
|
2008-05-30 16:47:21 +00:00
|
|
|
$joins[] = "l.action NOT $ILIKE :modaction";
|
|
|
|
$params['modaction'] = '%'.substr($modaction, 1).'%';
|
2006-03-28 17:33:40 +00:00
|
|
|
}
|
2004-01-15 07:17:12 +00:00
|
|
|
}
|
|
|
|
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2004-07-28 15:52:51 +00:00
|
|
|
/// Getting all members of a group.
|
|
|
|
if ($groupid and !$user) {
|
2007-08-16 09:28:18 +00:00
|
|
|
if ($gusers = groups_get_members($groupid)) {
|
|
|
|
$gusers = array_keys($gusers);
|
2007-06-07 16:04:23 +00:00
|
|
|
$joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
|
|
|
|
} else {
|
2007-10-05 04:24:42 +00:00
|
|
|
$joins[] = 'l.userid = 0'; // No users in groups, so we want something that will always be false.
|
2004-07-28 15:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($user) {
|
2008-05-30 16:47:21 +00:00
|
|
|
$joins[] = "l.userid = :userid";
|
|
|
|
$params['userid'] = $user;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($date) {
|
|
|
|
$enddate = $date + 86400;
|
2008-05-30 16:47:21 +00:00
|
|
|
$joins[] = "l.time > :date AND l.time < :enddate";
|
|
|
|
$params['date'] = $date;
|
|
|
|
$params['enddate'] = $enddate;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2007-06-07 16:04:23 +00:00
|
|
|
$selector = implode(' AND ', $joins);
|
2004-07-25 14:00:29 +00:00
|
|
|
|
2003-08-28 11:57:21 +00:00
|
|
|
$totalcount = 0; // Initialise
|
2006-05-15 05:01:00 +00:00
|
|
|
$result = array();
|
2008-05-30 16:47:21 +00:00
|
|
|
$result['logs'] = get_logs($selector, $params, $order, $limitfrom, $limitnum, $totalcount);
|
2006-05-15 05:01:00 +00:00
|
|
|
$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
|
|
|
|
2009-08-06 14:10:33 +00:00
|
|
|
global $CFG, $DB, $OUTPUT;
|
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!");
|
2009-08-06 14:10:33 +00:00
|
|
|
echo $OUTPUT->footer();
|
2001-11-22 06:23:56 +00:00
|
|
|
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] = '';
|
2008-05-07 18:28:59 +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) {
|
2008-05-07 18:28:59 +00:00
|
|
|
$courses[$cc->id] = $cc->shortname;
|
2006-05-15 05:01:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-21 10:58:18 +00:00
|
|
|
} else {
|
2008-05-07 18:28:59 +00:00
|
|
|
$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");
|
|
|
|
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<div class=\"info\">\n";
|
2003-08-22 06:07:18 +00:00
|
|
|
print_string("displayingrecords", "", $totalcount);
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "</div>\n";
|
2003-01-01 08:21:19 +00:00
|
|
|
|
2009-08-07 00:27:42 +00:00
|
|
|
echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, "$url&perpage=$perpage"));
|
2003-08-22 06:07:18 +00:00
|
|
|
|
2008-10-09 10:51:57 +00:00
|
|
|
echo '<table class="logtable generalbox boxaligncenter" summary="">'."\n";
|
2007-02-04 20:11:05 +00:00
|
|
|
// echo "<table class=\"logtable\" cellpadding=\"3\" cellspacing=\"0\" summary=\"\">\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";
|
2008-03-19 08:49:23 +00:00
|
|
|
echo "<th class=\"c3 header\" scope=\"col\">".get_string('fullnamecourse')."</th>\n";
|
2006-12-13 03:03:43 +00:00
|
|
|
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
|
|
|
|
2007-06-07 16:04:23 +00:00
|
|
|
// Make sure that the logs array is an array, even it is empty, to avoid warnings from the foreach.
|
2006-09-27 07:41:38 +00:00
|
|
|
if (empty($logs['logs'])) {
|
2007-06-07 16:04:23 +00:00
|
|
|
$logs['logs'] = array();
|
2006-09-27 07:41:38 +00:00
|
|
|
}
|
2008-06-04 06:38:03 +00:00
|
|
|
|
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 {
|
2008-06-01 19:05:07 +00:00
|
|
|
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
|
2004-07-29 18:01:32 +00:00
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
2007-06-07 15:33:56 +00:00
|
|
|
if ($ld && is_numeric($log->info)) {
|
2005-01-16 17:27:40 +00:00
|
|
|
// ugly hack to make sure fullname is shown correctly
|
2008-06-01 19:05:07 +00:00
|
|
|
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
|
|
|
|
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
|
2005-01-16 17:27:40 +00:00
|
|
|
} else {
|
2008-06-01 19:05:07 +00:00
|
|
|
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
|
2005-01-16 17:27:40 +00:00
|
|
|
}
|
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);
|
|
|
|
|
2008-03-13 15:32:08 +00:00
|
|
|
// If $log->url has been trimmed short by the db size restriction
|
|
|
|
// code in add_to_log, keep a note so we don't add a link to a broken url
|
|
|
|
$tl=textlib_get_instance();
|
|
|
|
$brokenurl=($tl->strlen($log->url)==100 && $tl->substr($log->url,97)=='...');
|
|
|
|
|
2005-05-12 08:04:47 +00:00
|
|
|
echo '<tr class="r'.$row.'">';
|
|
|
|
if ($course->id == SITEID) {
|
2007-02-04 20:11:05 +00:00
|
|
|
echo "<td class=\"cell c0\">\n";
|
2007-08-06 18:19:15 +00:00
|
|
|
if (empty($log->course)) {
|
2007-10-05 04:24:42 +00:00
|
|
|
echo get_string('site') . "\n";
|
2007-08-06 18:19:15 +00:00
|
|
|
} else {
|
2008-05-07 18:28:59 +00:00
|
|
|
echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">". format_string($courses[$log->course])."</a>\n";
|
2007-08-06 18:19:15 +00:00
|
|
|
}
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</td>\n";
|
2002-06-12 04:22:41 +00:00
|
|
|
}
|
2007-02-04 20:11:05 +00:00
|
|
|
echo "<td class=\"cell c1\" align=\"right\">".userdate($log->time, '%a').
|
2005-06-13 11:19:19 +00:00
|
|
|
' '.userdate($log->time, $strftimedatetime)."</td>\n";
|
2007-02-04 20:11:05 +00:00
|
|
|
echo "<td class=\"cell c2\">\n";
|
2008-01-02 16:47:57 +00:00
|
|
|
link_to_popup_window("/iplookup/index.php?ip=$log->ip&user=$log->userid", 'iplookup',$log->ip, 440, 700);
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</td>\n";
|
2008-05-07 18:28:59 +00:00
|
|
|
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
|
2007-02-04 20:11:05 +00:00
|
|
|
echo "<td class=\"cell c3\">\n";
|
2008-05-07 18:28:59 +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";
|
2007-02-04 20:11:05 +00:00
|
|
|
echo "<td class=\"cell c4\">\n";
|
2008-03-13 15:32:08 +00:00
|
|
|
$displayaction="$log->module $log->action";
|
|
|
|
if($brokenurl) {
|
|
|
|
echo $displayaction;
|
|
|
|
} else {
|
|
|
|
link_to_popup_window( make_log_url($log->module,$log->url), 'fromloglive',$displayaction, 440, 700);
|
|
|
|
}
|
2005-06-13 11:19:19 +00:00
|
|
|
echo "</td>\n";;
|
2007-02-04 20:11:05 +00:00
|
|
|
echo "<td class=\"cell c5\">{$log->info}</td>\n";
|
2005-06-13 11:19:19 +00:00
|
|
|
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
|
|
|
|
2009-08-07 00:27:42 +00:00
|
|
|
echo $OUTPUT->paging_bar(moodle_paging_bar::make($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) {
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2009-08-06 14:10:33 +00:00
|
|
|
global $CFG, $DB, $OUTPUT;
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-01-04 03:22:51 +00:00
|
|
|
if (!$logs = build_mnet_logs_array($hostid, $course, $user, $date, $order, $page*$perpage, $perpage,
|
|
|
|
$modname, $modid, $modaction, $groupid)) {
|
|
|
|
notify("No logs found!");
|
2009-08-06 14:10:33 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-01-04 03:22:51 +00:00
|
|
|
exit;
|
|
|
|
}
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-01-04 03:22:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-01-04 03:22:51 +00:00
|
|
|
$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");
|
|
|
|
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<div class=\"info\">\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
print_string("displayingrecords", "", $totalcount);
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "</div>\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
|
2009-08-07 00:27:42 +00:00
|
|
|
echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, "$url&perpage=$perpage"));
|
2007-01-04 03:22:51 +00:00
|
|
|
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<table class=\"logtable\" 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";
|
2008-03-19 08:49:23 +00:00
|
|
|
echo "<th class=\"c3 header\">".get_string('fullnamecourse')."</th>\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
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) {
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-01-04 03:22:51 +00:00
|
|
|
$log->info = $log->coursename;
|
|
|
|
$row = ($row + 1) % 2;
|
|
|
|
|
|
|
|
if (isset($ldcache[$log->module][$log->action])) {
|
|
|
|
$ld = $ldcache[$log->module][$log->action];
|
|
|
|
} else {
|
2008-06-02 08:13:24 +00:00
|
|
|
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
|
2007-01-04 03:22:51 +00:00
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
|
|
|
if (0 && $ld && !empty($log->info)) {
|
|
|
|
// ugly hack to make sure fullname is shown correctly
|
2008-06-01 19:05:07 +00:00
|
|
|
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
|
|
|
|
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
|
2007-01-04 03:22:51 +00:00
|
|
|
} else {
|
2008-06-01 19:05:07 +00:00
|
|
|
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
|
2007-01-04 03:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-04 06:38:03 +00:00
|
|
|
//Filter log->info
|
2007-01-04 03:22:51 +00:00
|
|
|
$log->info = format_string($log->info);
|
|
|
|
|
|
|
|
echo '<tr class="r'.$row.'">';
|
|
|
|
if ($course->id == SITEID) {
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<td class=\"r$row c0\" >\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courses[$log->course]."</a>\n";
|
|
|
|
echo "</td>\n";
|
|
|
|
}
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<td class=\"r$row c1\" align=\"right\">".userdate($log->time, '%a').
|
2007-01-04 03:22:51 +00:00
|
|
|
' '.userdate($log->time, $strftimedatetime)."</td>\n";
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<td class=\"r$row c2\" >\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
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)));
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<td class=\"r$row c3\" >\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
echo " <a href=\"$CFG->wwwroot/user/view.php?id={$log->userid}\">$fullname</a>\n";
|
|
|
|
echo "</td>\n";
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<td class=\"r$row c4\">\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
echo $log->action .': '.$log->module;
|
|
|
|
echo "</td>\n";;
|
2007-01-15 21:28:25 +00:00
|
|
|
echo "<td class=\"r$row c5\">{$log->info}</td>\n";
|
2007-01-04 03:22:51 +00:00
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
echo "</table>\n";
|
|
|
|
|
2009-08-07 00:27:42 +00:00
|
|
|
echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, "$url&perpage=$perpage"));
|
2007-01-04 03:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-15 05:01:00 +00:00
|
|
|
function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
|
|
|
|
$modid, $modaction, $groupid) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
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".
|
2008-03-19 08:49:23 +00:00
|
|
|
get_string('fullnamecourse')."\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 {
|
2008-06-02 08:13:24 +00:00
|
|
|
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
|
2006-08-25 07:09:28 +00:00
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
|
|
|
if ($ld && !empty($log->info)) {
|
|
|
|
// ugly hack to make sure fullname is shown correctly
|
2008-06-01 19:05:07 +00:00
|
|
|
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
|
|
|
|
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
|
2006-08-25 07:09:28 +00:00
|
|
|
} else {
|
2008-06-01 19:05:07 +00:00
|
|
|
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
|
2006-08-25 07:09:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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->info = strip_tags(urldecode($log->info)); // Some XSS protection
|
|
|
|
|
|
|
|
$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
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
global $CFG, $DB;
|
2006-05-15 05:01:00 +00:00
|
|
|
|
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'),
|
2008-03-19 08:49:23 +00:00
|
|
|
get_string('fullnamecourse'), 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++) {
|
2008-04-11 05:47:20 +00:00
|
|
|
$sheettitle = get_string('logs').' '.$wsnumber.'-'.$nroPages;
|
2006-08-25 07:09:28 +00:00
|
|
|
$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 {
|
2008-06-01 19:05:07 +00:00
|
|
|
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
|
2006-08-25 07:09:28 +00:00
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
|
|
|
if ($ld && !empty($log->info)) {
|
|
|
|
// ugly hack to make sure fullname is shown correctly
|
2008-06-01 19:05:07 +00:00
|
|
|
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
|
|
|
|
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
|
2006-08-25 07:09:28 +00:00
|
|
|
} else {
|
2008-06-01 19:05:07 +00:00
|
|
|
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
|
2006-08-25 07:09:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
global $CFG, $DB;
|
2006-12-21 10:58:18 +00:00
|
|
|
|
|
|
|
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'),
|
2008-03-19 08:49:23 +00:00
|
|
|
get_string('fullnamecourse'), get_string('action'), get_string('info'));
|
2006-12-21 10:58:18 +00:00
|
|
|
|
|
|
|
// Creating worksheets
|
|
|
|
for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
|
2008-04-11 05:47:20 +00:00
|
|
|
$sheettitle = get_string('logs').' '.$wsnumber.'-'.$nroPages;
|
2006-12-21 10:58:18 +00:00
|
|
|
$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 {
|
2008-06-01 19:05:07 +00:00
|
|
|
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
|
2006-12-21 10:58:18 +00:00
|
|
|
$ldcache[$log->module][$log->action] = $ld;
|
|
|
|
}
|
|
|
|
if ($ld && !empty($log->info)) {
|
|
|
|
// ugly hack to make sure fullname is shown correctly
|
2008-06-02 21:56:06 +00:00
|
|
|
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
|
2006-12-21 10:58:18 +00:00
|
|
|
} else {
|
2008-06-01 19:05:07 +00:00
|
|
|
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
|
2006-12-21 10:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2007-08-28 07:04:41 +00:00
|
|
|
global $CFG, $USER;
|
2003-07-30 13:02:45 +00:00
|
|
|
if (empty($CFG->gdversion)) {
|
|
|
|
echo "(".get_string("gdneed").")";
|
2002-06-10 05:19:03 +00:00
|
|
|
} else {
|
2007-08-28 07:04:41 +00:00
|
|
|
// MDL-10818, do not display broken graph when user has no permission to view graph
|
2008-11-29 14:22:10 +00:00
|
|
|
if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_COURSE, $course->id)) ||
|
2007-08-28 07:04:41 +00:00
|
|
|
($course->showreports and $USER->id == $userid)) {
|
|
|
|
echo '<img src="'.$CFG->wwwroot.'/course/report/log/graph.php?id='.$course->id.
|
|
|
|
'&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) {
|
2009-08-06 08:15:43 +00:00
|
|
|
global $CFG, $USER, $DB, $OUTPUT;
|
2005-08-16 00:25:39 +00:00
|
|
|
|
2006-01-17 20:49:43 +00:00
|
|
|
$htmlarray = array();
|
2008-06-02 08:13:24 +00:00
|
|
|
if ($modules = $DB->get_records('modules')) {
|
2005-09-05 01:31:08 +00:00
|
|
|
foreach ($modules as $mod) {
|
|
|
|
if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
|
2008-01-24 02:20:25 +00:00
|
|
|
include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
|
2005-09-05 01:31:08 +00:00
|
|
|
$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"';
|
|
|
|
}
|
2009-08-06 08:15:43 +00:00
|
|
|
echo $OUTPUT->heading('<a title="'. format_string($course->fullname).'" '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'. format_string($course->fullname).'</a>');
|
2006-01-17 20:49:43 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* This function trawls through the logs looking for
|
|
|
|
* anything new since the user's last login
|
|
|
|
*/
|
2002-05-31 09:34:50 +00:00
|
|
|
function print_recent_activity($course) {
|
|
|
|
// $course is an object
|
2009-08-06 01:38:17 +00:00
|
|
|
global $CFG, $USER, $SESSION, $DB, $OUTPUT;
|
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
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
|
|
|
|
|
|
|
$timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
|
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
|
|
|
$content = false;
|
2003-04-26 15:08:34 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
/// Firstly, have there been any new enrolments?
|
|
|
|
|
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">';
|
2009-08-06 01:38:17 +00:00
|
|
|
echo $OUTPUT->heading(get_string("newusers").':', 3);
|
2008-01-24 20:33:50 +00:00
|
|
|
$content = true;
|
2006-05-16 10:59:27 +00:00
|
|
|
echo "<ol class=\"list\">\n";
|
2003-08-17 01:46:00 +00:00
|
|
|
foreach ($users as $user) {
|
2008-01-24 20:33:50 +00:00
|
|
|
$fullname = fullname($user, $viewfullnames);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
/// Next, have there been any modifications to the course structure?
|
|
|
|
|
|
|
|
$modinfo =& get_fast_modinfo($course);
|
|
|
|
|
|
|
|
$changelist = array();
|
2003-04-26 15:08:34 +00:00
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
$logs = $DB->get_records_select('log', "time > ? AND course = ? AND
|
|
|
|
module = 'course' AND
|
|
|
|
(action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
|
|
|
|
array($timestart, $course->id), "id ASC");
|
2003-04-26 15:08:34 +00:00
|
|
|
|
|
|
|
if ($logs) {
|
2008-01-24 20:33:50 +00:00
|
|
|
$actions = array('add mod', 'update mod', 'delete mod');
|
|
|
|
$newgones = array(); // added and later deleted items
|
2003-04-26 15:08:34 +00:00
|
|
|
foreach ($logs as $key => $log) {
|
2008-01-24 20:33:50 +00:00
|
|
|
if (!in_array($log->action, $actions)) {
|
|
|
|
continue;
|
|
|
|
}
|
2005-03-10 14:09:45 +00:00
|
|
|
$info = split(' ', $log->info);
|
2003-09-14 12:25:16 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($info[0] == 'label') { // Labels are ignored in recent activity
|
2003-09-14 12:25:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (count($info) != 2) {
|
|
|
|
debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$modname = $info[0];
|
|
|
|
$instanceid = $info[1];
|
|
|
|
|
|
|
|
if ($log->action == 'delete mod') {
|
|
|
|
// unfortunately we do not know if the mod was visible
|
|
|
|
if (!array_key_exists($log->info, $newgones)) {
|
|
|
|
$strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
|
|
|
|
$changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!isset($modinfo->instances[$modname][$instanceid])) {
|
|
|
|
if ($log->action == 'add mod') {
|
|
|
|
// do not display added and later deleted activities
|
|
|
|
$newgones[$log->info] = true;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$cm = $modinfo->instances[$modname][$instanceid];
|
|
|
|
if (!$cm->uservisible) {
|
2008-07-05 13:20:21 +00:00
|
|
|
continue;
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($log->action == 'add mod') {
|
|
|
|
$stradded = get_string('added', 'moodle', get_string('modulename', $modname));
|
|
|
|
$changelist[$log->info] = array('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
|
|
|
|
|
|
|
|
} else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
|
|
|
|
$strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
|
|
|
|
$changelist[$log->info] = array('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
|
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)) {
|
2009-08-06 01:38:17 +00:00
|
|
|
echo $OUTPUT->heading(get_string("courseupdates").':', 3);
|
2008-01-24 20:33:50 +00:00
|
|
|
$content = true;
|
2002-06-01 09:23:37 +00:00
|
|
|
foreach ($changelist as $changeinfo => $change) {
|
2008-01-24 20:33:50 +00:00
|
|
|
echo '<p class="activity">'.$change['text'].'</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
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
/// Now display new things from each module
|
2003-11-21 12:54:09 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$usedmodules = array();
|
|
|
|
foreach($modinfo->cms as $cm) {
|
|
|
|
if (isset($usedmodules[$cm->modname])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!$cm->uservisible) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$usedmodules[$cm->modname] = $cm->modname;
|
|
|
|
}
|
2006-10-24 14:37:04 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
|
|
|
|
if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
|
|
|
|
include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
|
|
|
|
$print_recent_activity = $modname.'_print_recent_activity';
|
2007-12-28 16:04:30 +00:00
|
|
|
if (function_exists($print_recent_activity)) {
|
2008-01-24 20:33:50 +00:00
|
|
|
// NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
|
|
|
|
$content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
2007-12-28 16:04:30 +00:00
|
|
|
} else {
|
2008-06-04 06:38:03 +00:00
|
|
|
debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* For a given course, returns an array of course activity objects
|
|
|
|
* Each item in the array contains he following properties:
|
|
|
|
*/
|
2002-11-10 07:37:15 +00:00
|
|
|
function get_array_of_activities($courseid) {
|
|
|
|
// 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
|
2007-08-20 10:52:59 +00:00
|
|
|
// groupingid - grouping id
|
|
|
|
// groupmembersonly - is this instance visible to group members only
|
2003-07-20 13:53:31 +00:00
|
|
|
// extra - contains extra string to include in any link
|
2008-06-01 19:05:07 +00:00
|
|
|
global $CFG, $DB;
|
2008-12-17 16:37:35 +00:00
|
|
|
if(!empty($CFG->enableavailability)) {
|
|
|
|
require_once($CFG->libdir.'/conditionlib.php');
|
|
|
|
}
|
2003-10-22 13:14:56 +00:00
|
|
|
|
2009-04-02 06:59:14 +00:00
|
|
|
$course = $DB->get_record('course', array('id'=>$courseid));
|
|
|
|
|
|
|
|
if (empty($course)) {
|
|
|
|
throw new moodle_exception('courseidnotfound');
|
|
|
|
}
|
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
$mod = array();
|
|
|
|
|
2009-04-02 06:59:14 +00:00
|
|
|
$rawmods = get_course_mods($courseid);
|
|
|
|
if (empty($rawmods)) {
|
2008-01-24 20:33:50 +00:00
|
|
|
return $mod; // always return array
|
2002-11-10 07:37:15 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($sections = $DB->get_records("course_sections", array("course"=>$courseid), "section ASC")) {
|
2002-11-10 07:37:15 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
$mod[$seq]->id = $rawmods[$seq]->instance;
|
|
|
|
$mod[$seq]->cm = $rawmods[$seq]->id;
|
|
|
|
$mod[$seq]->mod = $rawmods[$seq]->modname;
|
|
|
|
$mod[$seq]->section = $section->section;
|
|
|
|
$mod[$seq]->visible = $rawmods[$seq]->visible;
|
|
|
|
$mod[$seq]->groupmode = $rawmods[$seq]->groupmode;
|
|
|
|
$mod[$seq]->groupingid = $rawmods[$seq]->groupingid;
|
2007-08-20 10:52:59 +00:00
|
|
|
$mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly;
|
2008-12-17 16:37:35 +00:00
|
|
|
$mod[$seq]->indent = $rawmods[$seq]->indent;
|
|
|
|
$mod[$seq]->completion = $rawmods[$seq]->completion;
|
2008-01-24 20:33:50 +00:00
|
|
|
$mod[$seq]->extra = "";
|
2008-12-17 16:37:35 +00:00
|
|
|
if(!empty($CFG->enableavailability)) {
|
|
|
|
condition_info::fill_availability_conditions($rawmods[$seq]);
|
|
|
|
$mod[$seq]->availablefrom = $rawmods[$seq]->availablefrom;
|
|
|
|
$mod[$seq]->availableuntil = $rawmods[$seq]->availableuntil;
|
|
|
|
$mod[$seq]->showavailability = $rawmods[$seq]->showavailability;
|
|
|
|
$mod[$seq]->conditionscompletion = $rawmods[$seq]->conditionscompletion;
|
|
|
|
$mod[$seq]->conditionsgrade = $rawmods[$seq]->conditionsgrade;
|
|
|
|
}
|
2003-10-22 13:14:56 +00:00
|
|
|
|
|
|
|
$modname = $mod[$seq]->mod;
|
|
|
|
$functionname = $modname."_get_coursemodule_info";
|
|
|
|
|
2008-04-30 12:24:54 +00:00
|
|
|
if (!file_exists("$CFG->dirroot/mod/$modname/lib.php")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-10-22 13:14:56 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-02-01 08:15:38 +00:00
|
|
|
if (!empty($info->name)) {
|
|
|
|
$mod[$seq]->name = urlencode($info->name);
|
|
|
|
}
|
2003-09-14 12:25:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-01 08:15:38 +00:00
|
|
|
if (!isset($mod[$seq]->name)) {
|
2008-06-02 21:39:23 +00:00
|
|
|
$mod[$seq]->name = urlencode($DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance)));
|
2008-02-01 08:15:38 +00:00
|
|
|
}
|
2002-11-10 07:37:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Returns a number of useful structures for course displays
|
|
|
|
*/
|
2002-08-02 17:38:18 +00:00
|
|
|
function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
|
2008-12-17 16:37:35 +00:00
|
|
|
global $DB,$COURSE;
|
2002-07-23 16:24:12 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$mods = array(); // course modules indexed by id
|
|
|
|
$modnames = array(); // all course module names (except resource!)
|
|
|
|
$modnamesplural= array(); // all course module names (plural form)
|
|
|
|
$modnamesused = array(); // course module names used
|
2002-07-23 16:24:12 +00:00
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($allmods = $DB->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
|
|
|
}
|
2007-12-21 15:37:47 +00:00
|
|
|
asort($modnames, SORT_LOCALE_STRING);
|
2002-08-02 17:38:18 +00:00
|
|
|
} else {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("nomodules", 'debug');
|
2002-08-02 17:38:18 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 16:37:35 +00:00
|
|
|
$course = ($courseid==$COURSE->id) ? $COURSE : $DB->get_record('course',array('id'=>$courseid));
|
|
|
|
$modinfo = get_fast_modinfo($course);
|
|
|
|
|
|
|
|
if ($rawmods=$modinfo->cms) {
|
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;
|
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
$mods[$mod->id] = $mod;
|
|
|
|
$mods[$mod->id]->modfullname = $modnames[$mod->modname];
|
|
|
|
if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-08-20 10:52:59 +00:00
|
|
|
// Check groupings
|
|
|
|
if (!groups_course_module_visible($mod)) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
$modnamesused[$mod->modname] = $modnames[$mod->modname];
|
2002-07-23 16:24:12 +00:00
|
|
|
}
|
2003-04-22 20:46:12 +00:00
|
|
|
if ($modnamesused) {
|
2008-01-07 16:46:35 +00:00
|
|
|
asort($modnamesused, SORT_LOCALE_STRING);
|
2003-04-22 20:46:12 +00:00
|
|
|
}
|
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) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
|
|
|
return $DB->get_records("course_sections", array("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) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $USER, $DB;
|
2003-04-28 13:29:26 +00:00
|
|
|
|
|
|
|
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
|
2008-06-04 06:38:03 +00:00
|
|
|
} else if ($DB->record_exists("course_display", array("userid" => $USER->id, "course"=>$courseid))) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$DB->set_field("course_display", "display", $display, array("userid"=>$USER->id, "course"=>$courseid));
|
2003-04-28 13:29:26 +00:00
|
|
|
} else {
|
2008-01-24 20:33:50 +00:00
|
|
|
$record = new object();
|
2003-04-28 13:29:26 +00:00
|
|
|
$record->userid = $USER->id;
|
|
|
|
$record->course = $courseid;
|
|
|
|
$record->display = $display;
|
2009-06-13 18:34:43 +00:00
|
|
|
$DB->insert_record("course_display", $record);
|
2003-04-28 13:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $USER->display[$courseid] = $display; // Note: = not ==
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* For a given course section, markes it visible or hidden,
|
|
|
|
* and does the same for every activity in that section
|
|
|
|
*/
|
2003-05-04 07:59:46 +00:00
|
|
|
function set_section_visible($courseid, $sectionnumber, $visibility) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2003-05-04 07:59:46 +00:00
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($section = $DB->get_record("course_sections", array("course"=>$courseid, "section"=>$sectionnumber))) {
|
|
|
|
$DB->set_field("course_sections", "visible", "$visibility", array("id"=>$section->id));
|
2003-05-04 07:59:46 +00:00
|
|
|
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
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Prints a section full of activity modules
|
|
|
|
*/
|
2008-07-28 12:31:29 +00:00
|
|
|
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false) {
|
2009-07-02 12:07:58 +00:00
|
|
|
global $CFG, $USER, $DB, $PAGE, $OUTPUT;
|
2003-07-14 13:08:38 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
static $initialised;
|
|
|
|
|
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 $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;
|
2005-04-26 15:44:39 +00:00
|
|
|
static $usetracking;
|
2008-01-24 20:33:50 +00:00
|
|
|
static $groupings;
|
2009-07-14 14:00:34 +00:00
|
|
|
static $shownhelp=false;
|
|
|
|
static $hiddenhelp=false;
|
2005-04-24 13:41:46 +00:00
|
|
|
|
2004-02-15 03:20:51 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (!isset($initialised)) {
|
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);
|
2009-05-06 08:59:29 +00:00
|
|
|
$isediting = $PAGE->user_is_editing();
|
2008-01-24 20:33:50 +00:00
|
|
|
$ismoving = $isediting && ismoving($course->id);
|
2004-01-31 08:40:38 +00:00
|
|
|
if ($ismoving) {
|
2008-01-24 20:33:50 +00:00
|
|
|
$strmovehere = get_string("movehere");
|
|
|
|
$strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
|
2004-01-31 08:40:38 +00:00
|
|
|
}
|
2005-04-26 16:34:49 +00:00
|
|
|
include_once($CFG->dirroot.'/mod/forum/lib.php');
|
|
|
|
if ($usetracking = forum_tp_can_track_forums()) {
|
2008-01-24 20:33:50 +00:00
|
|
|
$strunreadpostsone = get_string('unreadpostsone', 'forum');
|
2005-04-26 15:44:39 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
$initialised = true;
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
|
|
|
|
$labelformatoptions = new object();
|
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
|
2008-01-24 20:33:50 +00:00
|
|
|
$modinfo = get_fast_modinfo($course);
|
2009-07-15 14:19:24 +00:00
|
|
|
$completioninfo = new completion_info($course);
|
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\".
|
2007-09-25 15:15:07 +00:00
|
|
|
echo "<ul class=\"section img-text\">\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;
|
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
|
2002-08-03 08:16:31 +00:00
|
|
|
$mod = $mods[$modnumber];
|
2003-09-14 12:25:16 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($ismoving and $mod->id == $USER->activitycopy) {
|
|
|
|
// do not display moving mod
|
|
|
|
continue;
|
|
|
|
}
|
2003-09-14 12:25:16 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (isset($modinfo->cms[$modnumber])) {
|
2008-12-19 10:51:33 +00:00
|
|
|
// We can continue (because it will not be displayed at all)
|
|
|
|
// if:
|
|
|
|
// 1) The activity is not visible to users
|
|
|
|
// and
|
|
|
|
// 2a) The 'showavailability' option is not set (if that is set,
|
2009-08-07 07:18:01 +00:00
|
|
|
// we need to display the activity so we can show
|
2008-12-19 10:51:33 +00:00
|
|
|
// availability info)
|
|
|
|
// or
|
2009-08-07 07:18:01 +00:00
|
|
|
// 2b) The 'availableinfo' is empty, i.e. the activity was
|
|
|
|
// hidden in a way that leaves no info, such as using the
|
2008-12-19 10:51:33 +00:00
|
|
|
// eye icon.
|
2008-12-17 16:37:35 +00:00
|
|
|
if (!$modinfo->cms[$modnumber]->uservisible &&
|
2008-12-19 10:51:33 +00:00
|
|
|
(empty($modinfo->cms[$modnumber]->showavailability) ||
|
|
|
|
empty($modinfo->cms[$modnumber]->availableinfo))) {
|
2008-01-24 20:33:50 +00:00
|
|
|
// visibility shortcut
|
|
|
|
continue;
|
2003-07-20 13:53:31 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
} else {
|
2008-04-30 12:39:31 +00:00
|
|
|
if (!file_exists("$CFG->dirroot/mod/$mod->modname/lib.php")) {
|
|
|
|
// module not installed
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-17 16:37:35 +00:00
|
|
|
if (!coursemodule_visible_for_user($mod) &&
|
|
|
|
empty($mod->showavailability)) {
|
2008-01-24 20:33:50 +00:00
|
|
|
// full visibility check
|
|
|
|
continue;
|
2004-04-26 15:31:22 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
|
|
|
|
2009-08-07 07:18:01 +00:00
|
|
|
// In some cases the activity is visible to user, but it is
|
2009-04-17 11:07:59 +00:00
|
|
|
// dimmed. This is done if viewhiddenactivities is true and if:
|
|
|
|
// 1. the activity is not visible, or
|
|
|
|
// 2. the activity has dates set which do not include current, or
|
|
|
|
// 3. the activity has any other conditions set (regardless of whether
|
|
|
|
// current user meets them)
|
|
|
|
$canviewhidden = has_capability(
|
|
|
|
'moodle/course:viewhiddenactivities',
|
|
|
|
get_context_instance(CONTEXT_MODULE, $mod->id));
|
|
|
|
$accessiblebutdim = false;
|
|
|
|
if ($canviewhidden) {
|
|
|
|
$accessiblebutdim = !$mod->visible;
|
|
|
|
if (!empty($CFG->enableavailability)) {
|
|
|
|
$accessiblebutdim = $accessiblebutdim ||
|
|
|
|
$mod->availablefrom > time() ||
|
|
|
|
($mod->availableuntil && $mod->availableuntil < time()) ||
|
2009-08-07 07:18:01 +00:00
|
|
|
count($mod->conditionsgrade) > 0 ||
|
2009-04-17 11:07:59 +00:00
|
|
|
count($mod->conditionscompletion) > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
echo '<li class="activity '.$mod->modname.'" id="module-'.$modnumber.'">'; // Unique ID
|
|
|
|
if ($ismoving) {
|
|
|
|
echo '<a title="'.$strmovefull.'"'.
|
2009-01-02 10:36:25 +00:00
|
|
|
' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&sesskey='.sesskey().'">'.
|
2009-07-02 12:07:58 +00:00
|
|
|
'<img class="movetarget" src="'.$OUTPUT->old_icon_url('movehere') . '" '.
|
2008-01-24 20:33:50 +00:00
|
|
|
' alt="'.$strmovehere.'" /></a><br />
|
|
|
|
';
|
|
|
|
}
|
2004-04-26 15:31:22 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($mod->indent) {
|
2009-08-06 02:24:31 +00:00
|
|
|
$spacer = new html_image();
|
|
|
|
$spacer->height = 12;
|
|
|
|
$spacer->width = 20 * $mod->indent;
|
|
|
|
echo $OUTPUT->spacer($spacer);
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
|
|
|
|
2008-07-10 08:50:43 +00:00
|
|
|
$extra = '';
|
|
|
|
if (!empty($modinfo->cms[$modnumber]->extra)) {
|
2008-12-17 16:37:35 +00:00
|
|
|
$extra = $modinfo->cms[$modnumber]->extra;
|
2008-07-10 08:50:43 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
|
|
|
|
if ($mod->modname == "label") {
|
2009-04-17 11:07:59 +00:00
|
|
|
if ($accessiblebutdim || !$mod->uservisible) {
|
2008-12-19 10:51:33 +00:00
|
|
|
echo '<div class="dimmed_text"><span class="accesshide">'.
|
2008-12-19 10:59:36 +00:00
|
|
|
get_string('hiddenfromstudents').'</span>';
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
|
|
|
echo format_text($extra, FORMAT_HTML, $labelformatoptions);
|
2009-04-17 11:07:59 +00:00
|
|
|
if ($accessiblebutdim || !$mod->uservisible) {
|
2008-07-26 11:36:35 +00:00
|
|
|
echo "</div>";
|
2003-09-14 16:31:33 +00:00
|
|
|
}
|
2008-02-24 10:32:59 +00:00
|
|
|
if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
|
|
|
if (!isset($groupings)) {
|
|
|
|
$groupings = groups_get_all_groupings($course->id);
|
|
|
|
}
|
2008-02-28 03:40:06 +00:00
|
|
|
echo " <span class=\"groupinglabel\">(".format_string($groupings[$mod->groupingid]->name).')</span>';
|
2008-02-24 10:32:59 +00:00
|
|
|
}
|
2003-09-14 16:31:33 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
} else { // Normal activity
|
|
|
|
$instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id);
|
2003-09-14 12:25:16 +00:00
|
|
|
|
2009-04-03 01:13:42 +00:00
|
|
|
$customicon = $modinfo->cms[$modnumber]->icon;
|
|
|
|
if (!empty($customicon)) {
|
|
|
|
if (substr($customicon, 0, 4) === 'mod/') {
|
2009-07-02 12:25:19 +00:00
|
|
|
list($modname, $iconname) = explode('/', substr($customicon, 4), 2);
|
2009-07-08 01:52:16 +00:00
|
|
|
$icon = $OUTPUT->mod_icon_url(str_replace(array('.gif', '.png'), '', $customicon), $modname);
|
2009-04-03 01:13:42 +00:00
|
|
|
} else {
|
2009-07-08 01:52:16 +00:00
|
|
|
$icon = $OUTPUT->old_icon_url(str_replace(array('.gif', '.png'), '', $customicon));
|
2009-04-03 01:13:42 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
} else {
|
2009-07-02 12:07:58 +00:00
|
|
|
$icon = "" . $OUTPUT->mod_icon_url('icon', $mod->modname) . "";
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
2007-09-24 17:26:40 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
//Accessibility: for files get description via icon.
|
|
|
|
$altname = '';
|
|
|
|
if ('resource'==$mod->modname) {
|
2009-04-03 01:13:42 +00:00
|
|
|
if (!empty($customicon)) {
|
|
|
|
$possaltname = $customicon;
|
2007-09-25 15:15:07 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$mimetype = mimeinfo_from_icon('type', $possaltname);
|
|
|
|
$altname = get_mimetype_description($mimetype);
|
2007-09-25 15:15:07 +00:00
|
|
|
} else {
|
|
|
|
$altname = $mod->modfullname;
|
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
} else {
|
|
|
|
$altname = $mod->modfullname;
|
|
|
|
}
|
|
|
|
// Avoid unnecessary duplication.
|
|
|
|
if (false!==stripos($instancename, $altname)) {
|
|
|
|
$altname = '';
|
|
|
|
}
|
|
|
|
// File type after name, for alphabetic lists (screen reader).
|
|
|
|
if ($altname) {
|
|
|
|
$altname = get_accesshide(' '.$altname);
|
|
|
|
}
|
2007-09-25 15:15:07 +00:00
|
|
|
|
2008-12-17 16:37:35 +00:00
|
|
|
// We may be displaying this just in order to show information
|
|
|
|
// about visibility, without the actual link
|
2009-04-17 10:20:44 +00:00
|
|
|
if ($mod->uservisible) {
|
2008-12-17 16:37:35 +00:00
|
|
|
// Display normal module link
|
2009-04-17 11:07:59 +00:00
|
|
|
if (!$accessiblebutdim) {
|
2009-04-17 10:20:44 +00:00
|
|
|
$linkcss = '';
|
|
|
|
$accesstext ='';
|
2008-12-19 10:51:33 +00:00
|
|
|
} else {
|
|
|
|
$linkcss = ' class="dimmed" ';
|
2009-04-17 10:20:44 +00:00
|
|
|
$accesstext = '<span class="accesshide">'.
|
2008-12-19 10:51:33 +00:00
|
|
|
get_string('hiddenfromstudents').': </span>';
|
|
|
|
}
|
2009-04-17 10:20:44 +00:00
|
|
|
|
2008-12-19 10:51:33 +00:00
|
|
|
echo '<a '.$linkcss.' '.$extra.
|
2009-08-07 07:18:01 +00:00
|
|
|
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
|
2008-12-19 10:51:33 +00:00
|
|
|
'<img src="'.$icon.'" class="activityicon" alt="" /> '.
|
|
|
|
$accesstext.'<span>'.$instancename.$altname.'</span></a>';
|
2008-12-17 16:37:35 +00:00
|
|
|
|
|
|
|
if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
|
|
|
if (!isset($groupings)) {
|
|
|
|
$groupings = groups_get_all_groupings($course->id);
|
|
|
|
}
|
|
|
|
echo " <span class=\"groupinglabel\">(".format_string($groupings[$mod->groupingid]->name).')</span>';
|
2007-09-24 21:55:15 +00:00
|
|
|
}
|
2008-12-17 16:37:35 +00:00
|
|
|
} else {
|
|
|
|
// Display greyed-out text of link
|
2008-12-19 10:51:33 +00:00
|
|
|
echo '<span class="dimmed_text" '.$extra.' ><span class="accesshide">'.
|
|
|
|
get_string('notavailableyet','condition').': </span>'.
|
|
|
|
'<img src="'.$icon.'" class="activityicon" alt="" /> <span>'.
|
|
|
|
$instancename.$altname.'</span></span>';
|
2003-09-14 12:25:16 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
|
|
|
if ($usetracking && $mod->modname == 'forum') {
|
2008-04-13 19:15:02 +00:00
|
|
|
if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) {
|
|
|
|
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);
|
2005-01-29 09:56:42 +00:00
|
|
|
}
|
2008-04-13 19:15:02 +00:00
|
|
|
echo '</a></span>';
|
2005-01-29 09:49:42 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
2005-01-29 09:49:42 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($isediting) {
|
|
|
|
// TODO: we must define this as mod property!
|
|
|
|
if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
|
|
|
|
if (! $mod->groupmodelink = $groupbuttonslink) {
|
|
|
|
$mod->groupmode = $course->groupmode;
|
2004-01-31 08:40:38 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$mod->groupmode = false;
|
2003-09-14 12:25:16 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
echo ' ';
|
|
|
|
echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
|
2002-08-03 08:16:31 +00:00
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// Completion
|
2009-04-17 10:22:56 +00:00
|
|
|
$completion = $hidecompletion
|
2008-07-28 12:31:29 +00:00
|
|
|
? COMPLETION_TRACKING_NONE
|
|
|
|
: $completioninfo->is_enabled($mod);
|
2009-08-07 07:18:01 +00:00
|
|
|
if ($completion!=COMPLETION_TRACKING_NONE && isloggedin() &&
|
2008-12-17 16:37:35 +00:00
|
|
|
!isguestuser() && $mod->uservisible) {
|
2009-04-17 10:22:56 +00:00
|
|
|
$completiondata = $completioninfo->get_data($mod,true);
|
|
|
|
$completionicon = '';
|
|
|
|
if ($isediting) {
|
|
|
|
switch ($completion) {
|
2008-10-08 12:22:04 +00:00
|
|
|
case COMPLETION_TRACKING_MANUAL :
|
2009-04-17 10:22:56 +00:00
|
|
|
$completionicon = 'manual-enabled'; break;
|
2008-10-08 12:22:04 +00:00
|
|
|
case COMPLETION_TRACKING_AUTOMATIC :
|
2009-04-17 10:22:56 +00:00
|
|
|
$completionicon = 'auto-enabled'; break;
|
2008-07-28 12:31:29 +00:00
|
|
|
default: // wtf
|
|
|
|
}
|
2009-04-17 10:22:56 +00:00
|
|
|
} else if ($completion==COMPLETION_TRACKING_MANUAL) {
|
2008-07-28 12:31:29 +00:00
|
|
|
switch($completiondata->completionstate) {
|
|
|
|
case COMPLETION_INCOMPLETE:
|
2009-04-17 10:22:56 +00:00
|
|
|
$completionicon = 'manual-n'; break;
|
2008-07-28 12:31:29 +00:00
|
|
|
case COMPLETION_COMPLETE:
|
2009-04-17 10:22:56 +00:00
|
|
|
$completionicon = 'manual-y'; break;
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
} else { // Automatic
|
|
|
|
switch($completiondata->completionstate) {
|
|
|
|
case COMPLETION_INCOMPLETE:
|
2009-04-17 10:22:56 +00:00
|
|
|
$completionicon = 'auto-n'; break;
|
2008-07-28 12:31:29 +00:00
|
|
|
case COMPLETION_COMPLETE:
|
2009-04-17 10:22:56 +00:00
|
|
|
$completionicon = 'auto-y'; break;
|
2008-07-28 12:31:29 +00:00
|
|
|
case COMPLETION_COMPLETE_PASS:
|
2009-04-17 10:22:56 +00:00
|
|
|
$completionicon = 'auto-pass'; break;
|
2008-07-28 12:31:29 +00:00
|
|
|
case COMPLETION_COMPLETE_FAIL:
|
2009-04-17 10:22:56 +00:00
|
|
|
$completionicon = 'auto-fail'; break;
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-17 10:22:56 +00:00
|
|
|
if ($completionicon) {
|
2009-07-03 04:23:05 +00:00
|
|
|
$imgsrc = $OUTPUT->old_icon_url('i/completion-'.$completionicon);
|
2009-04-17 10:22:56 +00:00
|
|
|
$imgalt = get_string('completion-alt-'.$completionicon,'completion');
|
|
|
|
if ($completion==COMPLETION_TRACKING_MANUAL && !$isediting) {
|
|
|
|
$imgtitle = get_string('completion-title-'.$completionicon,'completion');
|
|
|
|
$newstate =
|
2008-07-28 12:31:29 +00:00
|
|
|
$completiondata->completionstate==COMPLETION_COMPLETE
|
2008-10-08 12:22:04 +00:00
|
|
|
? COMPLETION_INCOMPLETE
|
|
|
|
: COMPLETION_COMPLETE;
|
2009-01-15 17:09:02 +00:00
|
|
|
// In manual mode the icon is a toggle form...
|
|
|
|
|
|
|
|
// If this completion state is used by the
|
|
|
|
// conditional activities system, we need to turn
|
|
|
|
// off the JS.
|
2009-08-07 07:18:01 +00:00
|
|
|
if (!empty($CFG->enableavailability) &&
|
2009-01-15 17:09:02 +00:00
|
|
|
condition_info::completion_value_used_as_condition(
|
|
|
|
$course, $mod)) {
|
|
|
|
$extraclass = ' preventjs';
|
|
|
|
} else {
|
|
|
|
$extraclass = '';
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
echo "
|
2009-01-15 17:09:02 +00:00
|
|
|
<form class='togglecompletion$extraclass' method='post' action='togglecompletion.php'><div>";
|
2008-08-22 11:51:24 +00:00
|
|
|
echo "
|
2008-07-28 12:31:29 +00:00
|
|
|
<input type='hidden' name='id' value='{$mod->id}' />
|
|
|
|
<input type='hidden' name='completionstate' value='$newstate' />
|
|
|
|
<input type='image' src='$imgsrc' alt='$imgalt' title='$imgtitle' />
|
|
|
|
</div></form>";
|
|
|
|
} else {
|
|
|
|
// In auto mode, or when editing, the icon is just an image
|
2008-08-22 11:51:24 +00:00
|
|
|
echo "<span class='autocompletion'>";
|
|
|
|
echo "<img src='$imgsrc' alt='$imgalt' title='$imgalt' /></span>";
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
2009-07-14 14:00:34 +00:00
|
|
|
if (!$shownhelp && !$isediting) {
|
|
|
|
$PAGE->requires->js_function_call('completion_set_progressicon_visibility', array('completionprogressid', 'show'));
|
|
|
|
$shownhelp=true;
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-07 07:18:01 +00:00
|
|
|
// Show availability information (for someone who isn't allowed to
|
2008-12-17 16:37:35 +00:00
|
|
|
// see the activity itself, or for staff)
|
2009-04-17 10:22:56 +00:00
|
|
|
if (!$mod->uservisible) {
|
2008-12-17 16:37:35 +00:00
|
|
|
echo '<div class="availabilityinfo">'.$mod->availableinfo.'</div>';
|
2009-04-17 11:07:59 +00:00
|
|
|
} else if ($canviewhidden && !empty($CFG->enableavailability)) {
|
2008-12-17 16:37:35 +00:00
|
|
|
$ci = new condition_info($mod);
|
2009-04-17 10:22:56 +00:00
|
|
|
$fullinfo = $ci->get_full_information();
|
2008-12-17 16:37:35 +00:00
|
|
|
if($fullinfo) {
|
2009-08-07 07:18:01 +00:00
|
|
|
echo '<div class="availabilityinfo">'.get_string($mod->showavailability
|
2008-12-17 16:37:35 +00:00
|
|
|
? 'userrestriction_visible'
|
|
|
|
: 'userrestriction_hidden','condition',
|
|
|
|
$fullinfo).'</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
echo "</li>\n";
|
2002-08-03 08:16:31 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +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
|
|
|
}
|
2008-01-24 20:33:50 +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.'"'.
|
2009-01-02 10:36:25 +00:00
|
|
|
' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&sesskey='.sesskey().'">'.
|
2009-07-02 12:07:58 +00:00
|
|
|
'<img class="movetarget" src="'.$OUTPUT->old_icon_url('movehere') . '" '.
|
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";
|
|
|
|
}
|
2009-07-14 14:00:34 +00:00
|
|
|
|
|
|
|
//use javascript to hide the progress help button when no progress tick boxes have been displayed
|
2009-07-15 14:19:24 +00:00
|
|
|
if (!$shownhelp && !$hiddenhelp && $completioninfo->is_enabled()&& !$isediting && isloggedin() && !isguestuser()) {
|
2009-07-14 14:00:34 +00:00
|
|
|
$PAGE->requires->js_function_call('completion_set_progressicon_visibility', array('completionprogressid', 'hide'));
|
|
|
|
$hiddenhelp = true;
|
|
|
|
}
|
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-02-16 07:57:19 +00:00
|
|
|
// check to see if user can add menus
|
|
|
|
if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
2007-02-23 06:03:09 +00:00
|
|
|
return false;
|
2007-02-16 07:57:19 +00:00
|
|
|
}
|
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
static $resources = false;
|
|
|
|
static $activities = false;
|
2004-07-25 14:00:29 +00:00
|
|
|
|
2008-06-04 06:38:03 +00:00
|
|
|
if ($resources === false) {
|
2007-01-02 09:33:07 +00:00
|
|
|
$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
|
|
|
|
2008-02-15 10:39:47 +00:00
|
|
|
$libfile = "$CFG->dirroot/mod/$modname/lib.php";
|
|
|
|
if (!file_exists($libfile)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
include_once($libfile);
|
2007-01-02 09:33:07 +00:00
|
|
|
$gettypesfunc = $modname.'_get_types';
|
|
|
|
if (function_exists($gettypesfunc)) {
|
|
|
|
$types = $gettypesfunc();
|
|
|
|
foreach($types as $type) {
|
2008-02-13 17:03:25 +00:00
|
|
|
if (!isset($type->modclass) or !isset($type->typestr)) {
|
2008-02-21 15:17:41 +00:00
|
|
|
debugging('Incorrect activity type in '.$modname);
|
2008-02-13 17:03:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-01-02 09:33:07 +00:00
|
|
|
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)) {
|
2009-07-30 06:09:45 +00:00
|
|
|
$output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id§ion=$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 .= ' ';
|
2009-07-30 06:09:45 +00:00
|
|
|
$output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id§ion=$section&sesskey=".sesskey()."&add=",
|
2007-01-02 09:33:07 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
/**
|
|
|
|
* Return the course category context for the category with id $categoryid, except
|
|
|
|
* that if $categoryid is 0, return the system context.
|
|
|
|
*
|
|
|
|
* @param integer $categoryid a category id or 0.
|
|
|
|
* @return object the corresponding context
|
|
|
|
*/
|
|
|
|
function get_category_or_system_context($categoryid) {
|
|
|
|
if ($categoryid) {
|
|
|
|
return get_context_instance(CONTEXT_COURSECAT, $categoryid);
|
|
|
|
} else {
|
|
|
|
return get_context_instance(CONTEXT_SYSTEM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-01 07:48:26 +00:00
|
|
|
/**
|
|
|
|
* Rebuilds the cached list of course activities stored in the database
|
|
|
|
* @param int $courseid - id of course to rebuil, empty means all
|
|
|
|
* @param boolean $clearonly - only clear the modinfo fields, gets rebuild automatically on the fly
|
|
|
|
*/
|
|
|
|
function rebuild_course_cache($courseid=0, $clearonly=false) {
|
2008-05-15 21:40:00 +00:00
|
|
|
global $COURSE, $DB;
|
2008-02-01 07:48:26 +00:00
|
|
|
|
|
|
|
if ($clearonly) {
|
2008-06-01 16:14:59 +00:00
|
|
|
if (empty($courseid)) {
|
|
|
|
$courseselect = array();
|
|
|
|
} else {
|
|
|
|
$courseselect = array('id'=>$courseid);
|
|
|
|
}
|
|
|
|
$DB->set_field('course', 'modinfo', null, $courseselect);
|
2008-02-01 07:48:26 +00:00
|
|
|
// update cached global COURSE too ;-)
|
2009-07-03 09:59:00 +00:00
|
|
|
if ($courseid == $COURSE->id or empty($courseid)) {
|
2008-06-04 06:38:03 +00:00
|
|
|
$COURSE->modinfo = null;
|
2008-02-01 07:48:26 +00:00
|
|
|
}
|
|
|
|
// reset the fast modinfo cache
|
|
|
|
$reset = 'reset';
|
|
|
|
get_fast_modinfo($reset);
|
|
|
|
return;
|
|
|
|
}
|
2003-05-09 17:24:17 +00:00
|
|
|
|
|
|
|
if ($courseid) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$select = array('id'=>$courseid);
|
2003-05-09 17:24:17 +00:00
|
|
|
} else {
|
2008-06-01 19:05:07 +00:00
|
|
|
$select = array();
|
2007-08-23 05:46:07 +00:00
|
|
|
@set_time_limit(0); // this could take a while! MDL-10954
|
2003-05-09 17:24:17 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($rs = $DB->get_recordset("course", $select,'','id,fullname')) {
|
|
|
|
foreach ($rs as $course) {
|
2003-05-09 17:24:17 +00:00
|
|
|
$modinfo = serialize(get_array_of_activities($course->id));
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$DB->set_field("course", "modinfo", $modinfo, array("id"=>$course->id))) {
|
2007-02-28 06:25:22 +00:00
|
|
|
notify("Could not cache module information for course '" . format_string($course->fullname) . "'!");
|
2003-05-09 17:24:17 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
// update cached global COURSE too ;-)
|
|
|
|
if ($course->id == $COURSE->id) {
|
2008-06-04 06:38:03 +00:00
|
|
|
$COURSE->modinfo = $modinfo;
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
2003-05-09 17:24:17 +00:00
|
|
|
}
|
2008-06-01 19:05:07 +00:00
|
|
|
$rs->close();
|
2003-05-09 17:24:17 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
// reset the fast modinfo cache
|
2008-01-25 09:39:32 +00:00
|
|
|
$reset = 'reset';
|
|
|
|
get_fast_modinfo($reset);
|
2003-05-09 17:24:17 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
* Gets the child categories of a given coures category. Uses a static cache
|
|
|
|
* to make repeat calls efficient.
|
|
|
|
*
|
|
|
|
* @param unknown_type $parentid the id of a course category.
|
|
|
|
* @return array all the child course categories.
|
2008-06-01 19:05:07 +00:00
|
|
|
*/
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
function get_child_categories($parentid) {
|
2007-12-17 04:49:27 +00:00
|
|
|
static $allcategories = null;
|
|
|
|
|
|
|
|
// only fill in this variable the first time
|
|
|
|
if (null == $allcategories) {
|
|
|
|
$allcategories = array();
|
|
|
|
|
|
|
|
$categories = get_categories();
|
|
|
|
foreach ($categories as $category) {
|
|
|
|
if (empty($allcategories[$category->parent])) {
|
|
|
|
$allcategories[$category->parent] = array();
|
|
|
|
}
|
|
|
|
$allcategories[$category->parent][] = $category;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
if (empty($allcategories[$parentid])) {
|
2007-12-17 04:49:27 +00:00
|
|
|
return array();
|
|
|
|
} else {
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
return $allcategories[$parentid];
|
2007-12-17 04:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
* This function recursively travels the categories, building up a nice list
|
|
|
|
* for display. It also makes an array that list all the parents for each
|
|
|
|
* category.
|
|
|
|
*
|
|
|
|
* For example, if you have a tree of categories like:
|
|
|
|
* Miscellaneous (id = 1)
|
|
|
|
* Subcategory (id = 2)
|
|
|
|
* Sub-subcategory (id = 4)
|
|
|
|
* Other category (id = 3)
|
|
|
|
* Then after calling this function you will have
|
|
|
|
* $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
|
|
|
|
* 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
|
|
|
|
* 3 => 'Other category');
|
|
|
|
* $parents = array(2 => array(1), 4 => array(1, 2));
|
|
|
|
*
|
|
|
|
* If you specify $requiredcapability, then only categories where the current
|
|
|
|
* user has that capability will be added to $list, although all categories
|
|
|
|
* will still be added to $parents, and if you only have $requiredcapability
|
|
|
|
* in a child category, not the parent, then the child catgegory will still be
|
|
|
|
* included.
|
|
|
|
*
|
|
|
|
* If you specify the option $excluded, then that category, and all its children,
|
|
|
|
* are omitted from the tree. This is useful when you are doing something like
|
|
|
|
* moving categories, where you do not want to allow people to move a category
|
|
|
|
* to be the child of itself.
|
|
|
|
*
|
|
|
|
* @param array $list For output, accumulates an array categoryid => full category path name
|
|
|
|
* @param array $parents For output, accumulates an array categoryid => list of parent category ids.
|
2008-12-08 07:28:19 +00:00
|
|
|
* @param string/array $requiredcapability if given, only categories where the current
|
|
|
|
* user has this capability will be added to $list. Can also be an array of capabilities,
|
|
|
|
* in which case they are all required.
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
* @param integer $excludeid Omit this category and its children from the lists built.
|
|
|
|
* @param object $category Build the tree starting at this category - otherwise starts at the top level.
|
|
|
|
* @param string $path For internal use, as part of recursive calls.
|
2008-06-01 19:05:07 +00:00
|
|
|
*/
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
function make_categories_list(&$list, &$parents, $requiredcapability = '',
|
|
|
|
$excludeid = 0, $category = NULL, $path = "") {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
if (empty($category)) {
|
|
|
|
// Start at the top level.
|
|
|
|
$category = new stdClass;
|
|
|
|
$category->id = 0;
|
|
|
|
} else {
|
|
|
|
// This is the excluded category, don't include it.
|
|
|
|
if ($excludeid > 0 && $excludeid == $category->id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update $path.
|
2003-07-30 13:02:45 +00:00
|
|
|
if ($path) {
|
2007-02-28 06:25:22 +00:00
|
|
|
$path = $path.' / '.format_string($category->name);
|
2003-07-30 13:02:45 +00:00
|
|
|
} else {
|
2007-02-28 06:25:22 +00:00
|
|
|
$path = format_string($category->name);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
|
|
|
|
// Add this category to $list, if the permissions check out.
|
2008-12-09 16:25:38 +00:00
|
|
|
if (empty($requiredcapability)) {
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
$list[$category->id] = $path;
|
2008-12-09 16:25:38 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
ensure_context_subobj_present($category, CONTEXT_COURSECAT);
|
|
|
|
$requiredcapability = (array)$requiredcapability;
|
|
|
|
if (has_all_capabilities($requiredcapability, $category->context)) {
|
|
|
|
$list[$category->id] = $path;
|
|
|
|
}
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
// Add all the children recursively, while updating the parents array.
|
|
|
|
if ($categories = get_child_categories($category->id)) {
|
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;
|
|
|
|
}
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
make_categories_list($list, $parents, $requiredcapability, $excludeid, $cat, $path);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Recursive function to print out all the categories in a nice format
|
|
|
|
* with or without courses included
|
|
|
|
*/
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true) {
|
2004-04-05 03:13:10 +00:00
|
|
|
global $CFG;
|
2005-01-11 07:56:45 +00:00
|
|
|
|
2009-01-14 04:48:22 +00:00
|
|
|
// maxcategorydepth == 0 meant no limit
|
|
|
|
if (!empty($CFG->maxcategorydepth) && $depth >= $CFG->maxcategorydepth) {
|
2005-01-11 07:56:45 +00:00
|
|
|
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) {
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
if ($category->visible or has_capability('moodle/category:viewhiddencategories', get_context_instance(CONTEXT_SYSTEM))) {
|
|
|
|
print_category_info($category, $depth, $showcourses);
|
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";
|
|
|
|
}
|
|
|
|
|
2007-12-17 04:49:27 +00:00
|
|
|
if ($categories = get_child_categories($category->id)) { // Print all the children recursively
|
2003-07-30 13:02:45 +00:00
|
|
|
$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;
|
|
|
|
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1, $showcourses);
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* This function will return $options array for choose_from_menu, with whitespace to denote nesting.
|
|
|
|
*/
|
2005-08-16 06:15:49 +00:00
|
|
|
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
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Prints the category info in indented fashion
|
|
|
|
* This function is only used by print_whole_category_list() above
|
|
|
|
*/
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
function print_category_info($category, $depth, $showcourses = false) {
|
2009-07-02 10:53:31 +00:00
|
|
|
global $CFG, $DB, $OUTPUT;
|
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
|
|
|
|
2009-05-14 06:04:35 +00:00
|
|
|
static $coursecount = null;
|
|
|
|
if (null === $coursecount) {
|
|
|
|
// only need to check this once
|
|
|
|
$coursecount = $DB->count_records('course') <= FRONTPAGECOURSELIMIT;
|
|
|
|
}
|
|
|
|
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
if ($showcourses and $coursecount) {
|
2009-07-02 10:53:31 +00:00
|
|
|
$catimage = '<img src="'.$OUTPUT->old_icon_url('i/course') . '" 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
|
|
|
|
2008-01-10 15:43:24 +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');
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
if ($showcourses and $coursecount) {
|
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;
|
2008-09-08 18:16:39 +00:00
|
|
|
echo '<td class="category indentation" rowspan="'.$rows.'" valign="top">';
|
2009-08-06 02:24:31 +00:00
|
|
|
$spacer = new html_image();
|
|
|
|
$spacer->height = 10;
|
|
|
|
$spacer->width = $indent;
|
|
|
|
echo $OUTPUT->spacer($spacer) . '<br />';
|
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
|
|
|
|
2007-02-23 08:21:38 +00:00
|
|
|
echo '<td valign="top" class="category image">'.$catimage.'</td>';
|
2007-01-05 14:13:26 +00:00
|
|
|
echo '<td valign="top" class="category name">';
|
2007-02-28 06:25:22 +00:00
|
|
|
echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'. format_string($category->name).'</a>';
|
2005-01-11 07:56:45 +00:00
|
|
|
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
|
|
|
|
2009-01-14 04:48:22 +00:00
|
|
|
// does the depth exceed maxcategorydepth
|
|
|
|
// maxcategorydepth == 0 or unset meant no limit
|
|
|
|
|
|
|
|
$limit = !(isset($CFG->maxcategorydepth) && ($depth >= $CFG->maxcategorydepth-1));
|
|
|
|
|
|
|
|
if ($courses && ($limit || $CFG->maxcategorydepth == 0)) {
|
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">';
|
2007-02-28 06:25:22 +00:00
|
|
|
echo '<a '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'. format_string($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.'">';
|
2009-07-02 10:53:31 +00:00
|
|
|
echo '<img alt="'.$strallowguests.'" src="'.$OUTPUT->old_icon_url('i/guest') . '" /></a>';
|
2003-09-10 08:53:43 +00:00
|
|
|
} else {
|
2009-07-02 12:07:58 +00:00
|
|
|
echo '<img alt="" style="width:18px;height:16px;" src="'.$OUTPUT->old_icon_url('spacer') . '" />';
|
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.'">';
|
2009-07-02 10:53:31 +00:00
|
|
|
echo '<img alt="'.$strrequireskey.'" src="'.$OUTPUT->old_icon_url('i/key') . '" /></a>';
|
2003-09-10 08:53:43 +00:00
|
|
|
} else {
|
2009-07-02 12:07:58 +00:00
|
|
|
echo '<img alt="" style="width:18px;height:16px;" src="'.$OUTPUT->old_icon_url('spacer') . '" />';
|
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',
|
2009-07-02 10:53:31 +00:00
|
|
|
'<img alt="'.$strsummary.'" src="'.$OUTPUT->old_icon_url('i/info') . '" />',
|
2003-09-03 12:13:08 +00:00
|
|
|
400, 500, $strsummary);
|
2003-09-10 08:53:43 +00:00
|
|
|
} else {
|
2009-07-02 12:07:58 +00:00
|
|
|
echo '<img alt="" style="width:18px;height:16px;" src="'.$OUTPUT->old_icon_url('spacer') . '" />';
|
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;
|
2008-09-08 18:16:39 +00:00
|
|
|
echo '<td class="category indentation" valign="top">';
|
2009-08-06 02:24:31 +00:00
|
|
|
$spacer = new html_image();
|
|
|
|
$spacer->height = 10;
|
|
|
|
$spacer->width = $indent;
|
|
|
|
echo $OUTPUT->spacer($spacer) . '<br />';
|
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">';
|
2007-02-28 06:25:22 +00:00
|
|
|
echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'. format_string($category->name).'</a>';
|
2005-01-11 07:56:45 +00:00
|
|
|
echo '</td>';
|
2005-03-28 06:47:54 +00:00
|
|
|
echo '<td valign="top" class="category number">';
|
2008-01-10 15:43:24 +00:00
|
|
|
if (count($courses)) {
|
|
|
|
echo count($courses);
|
2005-01-11 07:56:45 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-12-05 08:56:54 +00:00
|
|
|
/**
|
|
|
|
* Print the buttons relating to course requests.
|
|
|
|
*
|
|
|
|
* @param object $systemcontext the system context.
|
|
|
|
*/
|
|
|
|
function print_course_request_buttons($systemcontext) {
|
|
|
|
global $CFG, $DB;
|
|
|
|
if (empty($CFG->enablecourserequests)) {
|
|
|
|
return;
|
|
|
|
}
|
2008-12-10 02:57:41 +00:00
|
|
|
if (isloggedin() && !isguestuser() && !has_capability('moodle/course:create', $systemcontext) && has_capability('moodle/course:request', $systemcontext)) {
|
2008-12-05 08:56:54 +00:00
|
|
|
/// Print a button to request a new course
|
|
|
|
print_single_button('request.php', NULL, get_string('requestcourse'), 'get');
|
|
|
|
}
|
|
|
|
/// Print a button to manage pending requests
|
|
|
|
if (has_capability('moodle/site:approvecourse', $systemcontext)) {
|
|
|
|
print_single_button('pending.php', NULL, get_string('coursespending'), 'get', '_self', false, '', !$DB->record_exists('course_request', array()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-28 03:03:35 +00:00
|
|
|
/**
|
|
|
|
* Does the user have permission to edit things in this category?
|
|
|
|
*
|
|
|
|
* @param integer $categoryid The id of the category we are showing, or 0 for system context.
|
|
|
|
* @return boolean has_any_capability(array(...), ...); in the appropriate context.
|
|
|
|
*/
|
|
|
|
function can_edit_in_category($categoryid = 0) {
|
|
|
|
$context = get_category_or_system_context($categoryid);
|
|
|
|
return has_any_capability(array('moodle/category:manage', 'moodle/course:create'), $context);
|
|
|
|
}
|
|
|
|
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
/**
|
|
|
|
* Prints the turn editing on/off button on course/index.php or course/category.php.
|
|
|
|
*
|
|
|
|
* @param integer $categoryid The id of the category we are showing, or 0 for system context.
|
|
|
|
* @return string HTML of the editing button, or empty string, if this user is not allowed
|
|
|
|
* to see it.
|
|
|
|
*/
|
|
|
|
function update_category_button($categoryid = 0) {
|
2009-05-06 08:59:29 +00:00
|
|
|
global $CFG, $PAGE;
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
|
|
|
|
// Check permissions.
|
2009-07-28 03:03:35 +00:00
|
|
|
if (!can_edit_in_category($categoryid)) {
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work out the appropriate action.
|
2009-05-06 08:59:29 +00:00
|
|
|
if ($PAGE->user_is_editing()) {
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
$label = get_string('turneditingoff');
|
|
|
|
$edit = 'off';
|
|
|
|
} else {
|
|
|
|
$label = get_string('turneditingon');
|
|
|
|
$edit = 'on';
|
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
// Generate the button HTML.
|
|
|
|
$options = array('categoryedit' => $edit, 'sesskey' => sesskey());
|
|
|
|
if ($categoryid) {
|
|
|
|
$options['id'] = $categoryid;
|
|
|
|
$page = 'category.php';
|
|
|
|
} else {
|
|
|
|
$page = 'index.php';
|
|
|
|
}
|
2009-07-28 02:45:13 +00:00
|
|
|
return print_single_button($CFG->wwwroot . '/course/' . $page, $options, $label, 'get', '', true);
|
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
|
|
|
}
|
2007-09-24 17:26:40 +00:00
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Category is 0 (for all courses) or an object
|
|
|
|
*/
|
2007-09-19 07:50:41 +00:00
|
|
|
function print_courses($category) {
|
2009-08-07 07:18:01 +00:00
|
|
|
global $CFG, $OUTPUT;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2007-09-19 07:26:54 +00:00
|
|
|
if (!is_object($category) && $category==0) {
|
2007-12-17 04:49:27 +00:00
|
|
|
$categories = get_child_categories(0); // Parent = 0 ie top-level categories only
|
2007-09-19 07:26:54 +00:00
|
|
|
if (is_array($categories) && count($categories) == 1) {
|
2003-07-30 13:56:17 +00:00
|
|
|
$category = array_shift($categories);
|
2008-06-04 06:38:03 +00:00
|
|
|
$courses = get_courses_wmanagers($category->id,
|
|
|
|
'c.sortorder ASC',
|
2007-09-19 07:26:54 +00:00
|
|
|
array('password','summary','currency'));
|
2003-07-30 13:56:17 +00:00
|
|
|
} else {
|
2008-06-04 06:38:03 +00:00
|
|
|
$courses = get_courses_wmanagers('all',
|
|
|
|
'c.sortorder ASC',
|
2007-09-19 07:26:54 +00:00
|
|
|
array('password','summary','currency'));
|
2003-07-30 13:56:17 +00:00
|
|
|
}
|
|
|
|
unset($categories);
|
2003-01-05 06:45:20 +00:00
|
|
|
} else {
|
2008-06-04 06:38:03 +00:00
|
|
|
$courses = get_courses_wmanagers($category->id,
|
|
|
|
'c.sortorder ASC',
|
2007-09-19 07:26:54 +00:00
|
|
|
array('password','summary','currency'));
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
2007-09-19 07:50:28 +00:00
|
|
|
if ($courses) {
|
2007-11-16 16:47:54 +00:00
|
|
|
echo '<ul class="unlist">';
|
2003-07-30 13:02:45 +00:00
|
|
|
foreach ($courses as $course) {
|
2007-09-19 07:26:54 +00:00
|
|
|
if ($course->visible == 1
|
2008-01-08 15:17:02 +00:00
|
|
|
|| has_capability('moodle/course:viewhiddencourses',$course->context)) {
|
2007-11-16 16:47:54 +00:00
|
|
|
echo '<li>';
|
2007-09-19 07:26:54 +00:00
|
|
|
print_course($course);
|
2007-11-16 16:47:54 +00:00
|
|
|
echo "</li>\n";
|
2007-09-19 07:26:54 +00:00
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
2007-11-16 16:47:54 +00:00
|
|
|
echo "</ul>\n";
|
2003-07-30 13:02:45 +00:00
|
|
|
} else {
|
2009-08-06 08:15:43 +00:00
|
|
|
echo $OUTPUT->heading(get_string("nocoursesyet"));
|
2008-04-24 08:39:47 +00:00
|
|
|
$context = get_context_instance(CONTEXT_SYSTEM);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-11 10:47:48 +00:00
|
|
|
/**
|
|
|
|
* Print a description of a course, suitable for browsing in a list.
|
|
|
|
*
|
|
|
|
* @param object $course the course object.
|
|
|
|
* @param string $highlightterms (optional) some search terms that should be highlighted in the display.
|
|
|
|
*/
|
|
|
|
function print_course($course, $highlightterms = '') {
|
2009-07-03 04:23:05 +00:00
|
|
|
global $CFG, $USER, $DB, $OUTPUT;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2007-09-19 07:26:54 +00:00
|
|
|
if (isset($course->context)) {
|
|
|
|
$context = $course->context;
|
|
|
|
} else {
|
|
|
|
$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-11-16 07:29:14 +00:00
|
|
|
echo '<div class="coursebox clearfix">';
|
2007-01-04 15:53:05 +00:00
|
|
|
echo '<div class="info">';
|
2007-12-16 13:41:16 +00:00
|
|
|
echo '<div class="name"><a title="'.get_string('entercourse').'"'.
|
2009-08-03 07:35:41 +00:00
|
|
|
$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
|
2008-12-11 10:47:48 +00:00
|
|
|
highlight($highlightterms, format_string($course->fullname)).'</a></div>';
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2006-11-17 08:57:50 +00:00
|
|
|
/// first find all roles that are supposed to be displayed
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-09-19 07:52:27 +00:00
|
|
|
if (!empty($CFG->coursemanager)) {
|
|
|
|
$managerroles = split(',', $CFG->coursemanager);
|
2007-09-19 07:09:24 +00:00
|
|
|
$canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
|
2007-09-19 07:26:54 +00:00
|
|
|
$namesarray = array();
|
|
|
|
if (isset($course->managers)) {
|
|
|
|
if (count($course->managers)) {
|
|
|
|
$rusers = $course->managers;
|
|
|
|
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-11-27 01:56:21 +00:00
|
|
|
/// Rename some of the role names if needed
|
|
|
|
if (isset($context)) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$aliasnames = $DB->get_records('role_names', array('contextid'=>$context->id), '', 'roleid,contextid,name');
|
2007-11-27 01:56:21 +00:00
|
|
|
}
|
|
|
|
|
2008-05-21 12:03:22 +00:00
|
|
|
// keep a note of users displayed to eliminate duplicates
|
|
|
|
$usersshown = array();
|
2007-09-19 07:26:54 +00:00
|
|
|
foreach ($rusers as $ra) {
|
2008-05-21 12:03:22 +00:00
|
|
|
|
|
|
|
// if we've already displayed user don't again
|
|
|
|
if (in_array($ra->user->id,$usersshown)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$usersshown[] = $ra->user->id;
|
|
|
|
|
2007-09-19 07:26:54 +00:00
|
|
|
if ($ra->hidden == 0 || $canseehidden) {
|
2008-06-04 06:38:03 +00:00
|
|
|
$fullname = fullname($ra->user, $canviewfullnames);
|
2008-04-10 03:35:17 +00:00
|
|
|
if ($ra->hidden == 1) {
|
2009-07-03 04:23:05 +00:00
|
|
|
$status = " <img src=\"" . $OUTPUT->old_icon_url('t/show') . "\" title=\"".get_string('userhashiddenassignments', 'role')."\" alt=\"".get_string('hiddenassign')."\" class=\"hide-show-image\"/>";
|
2008-04-10 03:35:17 +00:00
|
|
|
} else {
|
|
|
|
$status = '';
|
2008-04-04 06:41:54 +00:00
|
|
|
}
|
2007-11-27 01:56:21 +00:00
|
|
|
|
|
|
|
if (isset($aliasnames[$ra->roleid])) {
|
2008-02-29 08:44:23 +00:00
|
|
|
$ra->rolename = $aliasnames[$ra->roleid]->name;
|
2007-11-27 01:56:21 +00:00
|
|
|
}
|
|
|
|
|
2008-06-04 06:38:03 +00:00
|
|
|
$namesarray[] = format_string($ra->rolename)
|
2007-09-19 07:26:54 +00:00
|
|
|
. ': <a href="'.$CFG->wwwroot.'/user/view.php?id='.$ra->user->id.'&course='.SITEID.'">'
|
2008-06-04 06:38:03 +00:00
|
|
|
. $fullname . '</a>' . $status;
|
2007-09-19 07:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2008-06-04 06:38:03 +00:00
|
|
|
$rusers = get_role_users($managerroles, $context,
|
2007-09-19 07:26:54 +00:00
|
|
|
true, '', 'r.sortorder ASC, u.lastname ASC', $canseehidden);
|
|
|
|
if (is_array($rusers) && count($rusers)) {
|
|
|
|
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
2008-09-18 15:16:02 +00:00
|
|
|
|
|
|
|
/// Rename some of the role names if needed
|
|
|
|
if (isset($context)) {
|
|
|
|
$aliasnames = $DB->get_records('role_names', array('contextid'=>$context->id), '', 'roleid,contextid,name');
|
|
|
|
}
|
|
|
|
|
2007-09-19 07:26:54 +00:00
|
|
|
foreach ($rusers as $teacher) {
|
2008-06-04 06:38:03 +00:00
|
|
|
$fullname = fullname($teacher, $canviewfullnames);
|
2008-09-18 15:16:02 +00:00
|
|
|
|
|
|
|
/// Apply role names
|
|
|
|
if (isset($aliasnames[$teacher->roleid])) {
|
|
|
|
$teacher->rolename = $aliasnames[$teacher->roleid]->name;
|
|
|
|
}
|
|
|
|
|
2008-06-04 06:38:03 +00:00
|
|
|
$namesarray[] = format_string($teacher->rolename)
|
2007-09-19 07:26:54 +00:00
|
|
|
. ': <a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.'&course='.SITEID.'">'
|
2008-06-04 06:38:03 +00:00
|
|
|
. $fullname . '</a>';
|
2007-09-19 07:26:54 +00:00
|
|
|
}
|
2007-09-19 07:26:27 +00:00
|
|
|
}
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
2007-09-19 07:26:27 +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
|
|
|
}
|
2008-06-04 06:38:03 +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;
|
2008-12-11 10:47:48 +00:00
|
|
|
echo highlight($highlightterms, format_text($course->summary, FORMAT_MOODLE, $options, $course->id));
|
2007-01-04 15:53:05 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Prints custom user information on the home page.
|
|
|
|
* Over time this can include all sorts of information
|
|
|
|
*/
|
2003-07-30 13:02:45 +00:00
|
|
|
function print_my_moodle() {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $USER, $CFG, $DB;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2006-09-02 11:44:04 +00:00
|
|
|
if (empty($USER->id)) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error('nopermissions', '', '', 'See My Moodle');
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
2007-09-19 07:51:50 +00:00
|
|
|
$courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary'));
|
2009-08-03 07:35:41 +00:00
|
|
|
$rhosts = array();
|
|
|
|
$rcourses = array();
|
|
|
|
if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode==='strict') {
|
|
|
|
$rcourses = get_my_remotecourses($USER->id);
|
|
|
|
$rhosts = get_my_remotehosts();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) {
|
|
|
|
|
|
|
|
if (!empty($courses)) {
|
|
|
|
echo '<ul class="unlist">';
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
if ($course->id == SITEID) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
echo '<li>';
|
|
|
|
print_course($course);
|
|
|
|
echo "</li>\n";
|
2007-01-19 09:23:47 +00:00
|
|
|
}
|
2009-08-03 07:35:41 +00:00
|
|
|
echo "</ul>\n";
|
2007-01-19 09:23:47 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 07:35:41 +00:00
|
|
|
// MNET
|
|
|
|
if (!empty($rcourses)) {
|
|
|
|
// at the IDP, we know of all the remote courses
|
|
|
|
foreach ($rcourses as $course) {
|
|
|
|
print_remote_course($course, "100%");
|
|
|
|
}
|
|
|
|
} elseif (!empty($rhosts)) {
|
|
|
|
// non-IDP, we know of all the remote servers, but not courses
|
|
|
|
foreach ($rhosts as $host) {
|
|
|
|
print_remote_host($host, "100%");
|
|
|
|
}
|
|
|
|
}
|
2007-01-19 09:23:47 +00:00
|
|
|
unset($course);
|
2009-08-03 07:35:41 +00:00
|
|
|
unset($host);
|
2003-08-11 09:45:50 +00:00
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($DB->count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed
|
2003-10-21 02:25:22 +00:00
|
|
|
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";
|
|
|
|
}
|
2007-01-19 09:23:47 +00:00
|
|
|
|
2003-08-07 16:41:33 +00:00
|
|
|
} else {
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($DB->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 {
|
2007-02-14 04:56:26 +00:00
|
|
|
print_courses(0);
|
2003-08-07 16:41:33 +00:00
|
|
|
}
|
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;
|
2007-02-05 07:58:29 +00:00
|
|
|
static $count = 0;
|
|
|
|
|
|
|
|
$count++;
|
|
|
|
|
|
|
|
$id = 'coursesearch';
|
|
|
|
|
|
|
|
if ($count > 1) {
|
|
|
|
$id .= $count;
|
|
|
|
}
|
2003-08-11 09:45:50 +00:00
|
|
|
|
|
|
|
$strsearchcourses= get_string("searchcourses");
|
|
|
|
|
2004-09-08 19:24:38 +00:00
|
|
|
if ($format == 'plain') {
|
2007-02-05 07:58:29 +00:00
|
|
|
$output = '<form id="'.$id.'" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
|
2007-01-05 14:13:26 +00:00
|
|
|
$output .= '<fieldset class="coursesearchbox invisiblefieldset">';
|
2007-06-19 03:22:58 +00:00
|
|
|
$output .= '<label for="coursesearchbox">'.$strsearchcourses.': </label>';
|
2008-06-01 19:05:07 +00:00
|
|
|
$output .= '<input type="text" id="coursesearchbox" size="30" name="search" value="'.s($value).'" />';
|
2007-06-19 03:22:58 +00:00
|
|
|
$output .= '<input type="submit" value="'.get_string('go').'" />';
|
2007-01-05 14:13:26 +00:00
|
|
|
$output .= '</fieldset></form>';
|
2004-09-08 19:24:38 +00:00
|
|
|
} else if ($format == 'short') {
|
2007-02-05 07:58:29 +00:00
|
|
|
$output = '<form id="'.$id.'" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
|
2007-01-05 14:13:26 +00:00
|
|
|
$output .= '<fieldset class="coursesearchbox invisiblefieldset">';
|
2008-03-25 01:25:54 +00:00
|
|
|
$output .= '<label for="shortsearchbox">'.$strsearchcourses.': </label>';
|
2008-06-01 19:05:07 +00:00
|
|
|
$output .= '<input type="text" id="shortsearchbox" size="12" name="search" alt="'.s($strsearchcourses).'" value="'.s($value).'" />';
|
2007-06-19 03:22:58 +00:00
|
|
|
$output .= '<input type="submit" value="'.get_string('go').'" />';
|
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">';
|
2008-03-25 01:25:54 +00:00
|
|
|
$output .= '<label for="navsearchbox">'.$strsearchcourses.': </label>';
|
2008-06-01 19:05:07 +00:00
|
|
|
$output .= '<input type="text" id="navsearchbox" size="20" name="search" alt="'.s($strsearchcourses).'" value="'.s($value).'" />';
|
2007-06-19 03:22:58 +00:00
|
|
|
$output .= '<input type="submit" value="'.get_string('go').'" />';
|
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
|
|
|
|
2007-01-19 09:23:47 +00:00
|
|
|
function print_remote_course($course, $width="100%") {
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
$linkcss = '';
|
|
|
|
|
|
|
|
$url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}";
|
|
|
|
|
2007-11-16 07:29:14 +00:00
|
|
|
echo '<div class="coursebox remotecoursebox clearfix">';
|
2007-01-19 09:23:47 +00:00
|
|
|
echo '<div class="info">';
|
|
|
|
echo '<div class="name"><a title="'.get_string('entercourse').'"'.
|
|
|
|
$linkcss.' href="'.$url.'">'
|
2007-02-28 06:25:22 +00:00
|
|
|
. format_string($course->fullname) .'</a><br />'
|
|
|
|
. format_string($course->hostname) . ' : '
|
2008-06-04 06:38:03 +00:00
|
|
|
. format_string($course->cat_name) . ' : '
|
|
|
|
. format_string($course->shortname). '</div>';
|
2007-01-19 09:23:47 +00:00
|
|
|
echo '</div><div class="summary">';
|
|
|
|
$options = NULL;
|
|
|
|
$options->noclean = true;
|
|
|
|
$options->para = false;
|
|
|
|
echo format_text($course->summary, FORMAT_MOODLE, $options);
|
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
|
2007-01-19 09:36:40 +00:00
|
|
|
function print_remote_host($host, $width="100%") {
|
2009-07-02 10:53:31 +00:00
|
|
|
global $OUTPUT;
|
2007-01-19 09:36:40 +00:00
|
|
|
|
|
|
|
$linkcss = '';
|
|
|
|
|
2007-11-16 07:29:14 +00:00
|
|
|
echo '<div class="coursebox clearfix">';
|
2007-01-19 09:36:40 +00:00
|
|
|
echo '<div class="info">';
|
|
|
|
echo '<div class="name">';
|
2009-07-02 10:53:31 +00:00
|
|
|
echo '<img src="'.$OUTPUT->old_icon_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
|
2007-01-19 09:36:40 +00:00
|
|
|
echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
|
|
|
|
. s($host['name']).'</a> - ';
|
2007-01-19 09:37:28 +00:00
|
|
|
echo $host['count'] . ' ' . get_string('courses');
|
2007-01-19 09:36:40 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
2007-01-22 01:57:05 +00:00
|
|
|
echo '</div>';
|
2007-01-19 09:36:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-19 09:23:47 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function add_course_module($mod) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2002-08-01 03:50:27 +00:00
|
|
|
|
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
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
return $DB->insert_record("course_modules", $mod);
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
|
2007-08-26 15:30:51 +00:00
|
|
|
/**
|
|
|
|
* Returns course section - creates new if does not exist yet.
|
|
|
|
* @param int $relative section number
|
|
|
|
* @param int $courseid
|
|
|
|
* @return object $course_section object
|
|
|
|
*/
|
|
|
|
function get_course_section($section, $courseid) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
|
2007-08-26 15:30:51 +00:00
|
|
|
return $cw;
|
|
|
|
}
|
|
|
|
$cw = new object();
|
2008-06-01 19:05:07 +00:00
|
|
|
$cw->course = $courseid;
|
|
|
|
$cw->section = $section;
|
|
|
|
$cw->summary = "";
|
2007-08-26 15:30:51 +00:00
|
|
|
$cw->sequence = "";
|
2008-06-01 19:05:07 +00:00
|
|
|
$id = $DB->insert_record("course_sections", $cw);
|
2008-06-04 23:45:31 +00:00
|
|
|
return $DB->get_record("course_sections", array("id"=>$id));
|
2007-08-26 15:30:51 +00:00
|
|
|
}
|
2007-10-03 12:22:25 +00:00
|
|
|
/**
|
|
|
|
* Given a full mod object with section and course already defined, adds this module to that section.
|
|
|
|
*
|
|
|
|
* @param object $mod
|
|
|
|
* @param int $beforemod An existing ID which we will insert the new module before
|
|
|
|
* @return int The course_sections ID where the mod is inserted
|
|
|
|
*/
|
2003-07-14 13:08:38 +00:00
|
|
|
function add_mod_to_section($mod, $beforemod=NULL) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($section = $DB->get_record("course_sections", array("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);
|
|
|
|
|
2008-08-27 16:33:50 +00:00
|
|
|
if ($key = array_keys($modarray, $beforemod->id)) {
|
2003-07-14 13:08:38 +00:00
|
|
|
$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
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($DB->set_field("course_sections", "sequence", $newsequence, array("id"=>$section->id))) {
|
2002-10-21 03:00:40 +00:00
|
|
|
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
|
2008-06-01 19:05:07 +00:00
|
|
|
$section->course = $mod->course;
|
|
|
|
$section->section = $mod->section;
|
|
|
|
$section->summary = "";
|
2002-10-21 03:00:40 +00:00
|
|
|
$section->sequence = $mod->coursemodule;
|
2008-06-01 19:05:07 +00:00
|
|
|
return $DB->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) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2008-06-02 21:39:23 +00:00
|
|
|
return $DB->set_field("course_modules", "groupmode", $groupmode, array("id"=>$id));
|
2004-01-31 08:40:38 +00:00
|
|
|
}
|
|
|
|
|
2007-04-11 09:19:24 +00:00
|
|
|
function set_coursemodule_idnumber($id, $idnumber) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2008-06-04 06:38:03 +00:00
|
|
|
return $DB->set_field("course_modules", "idnumber", $idnumber, array("id"=>$id));
|
2007-04-11 09:19:24 +00:00
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
|
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) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
|
|
|
if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
|
2006-09-24 06:06:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module))) {
|
2006-09-24 06:06:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
|
2004-05-05 07:07:56 +00:00
|
|
|
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.
|
2008-06-01 19:05:07 +00:00
|
|
|
$DB->set_field('course_modules', 'visibleold', $cm->visible, array('id'=>$id));
|
2006-04-12 03:11:34 +00:00
|
|
|
} else {
|
|
|
|
// Get the previous saved visible states.
|
2008-06-01 19:05:07 +00:00
|
|
|
return $DB->set_field('course_modules', 'visible', $cm->visibleold, array('id'=>$id));
|
2006-04-12 03:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-01 19:05:07 +00:00
|
|
|
return $DB->set_field("course_modules", "visible", $visible, array("id"=>$id));
|
2003-04-14 15:11:09 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +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) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $CFG, $DB;
|
2007-08-03 19:25:22 +00:00
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
|
2005-03-28 06:47:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-06-01 19:05:07 +00:00
|
|
|
$modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
|
2007-08-03 19:25:22 +00:00
|
|
|
//delete events from calendar
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
|
2004-05-05 07:07:56 +00:00
|
|
|
foreach($events as $event) {
|
2007-07-27 18:39:54 +00:00
|
|
|
delete_event($event->id);
|
2004-05-05 07:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-03 19:25:22 +00:00
|
|
|
//delete grade items, outcome items and grades attached to modules
|
|
|
|
if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
|
|
|
|
'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
|
|
|
|
foreach ($grade_items as $grade_item) {
|
|
|
|
$grade_item->delete('moddelete');
|
|
|
|
}
|
|
|
|
}
|
2009-01-09 05:32:08 +00:00
|
|
|
|
|
|
|
delete_context(CONTEXT_MODULE, $cm->id);
|
2008-06-01 19:05:07 +00:00
|
|
|
return $DB->delete_records('course_modules', array('id'=>$cm->id));
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete_mod_from_section($mod, $section) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($section = $DB->get_record("course_sections", array("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);
|
2008-06-01 19:05:07 +00:00
|
|
|
return $DB->set_field("course_sections", "sequence", $newsequence, array("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
|
|
|
}
|
|
|
|
|
2008-08-08 05:25:54 +00:00
|
|
|
/**
|
|
|
|
* Moves a section up or down by 1. CANNOT BE USED DIRECTLY BY AJAX!
|
|
|
|
*
|
|
|
|
* @param object $course
|
|
|
|
* @param int $section
|
|
|
|
* @param int $move (-1 or 1)
|
|
|
|
*/
|
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
|
2008-06-01 19:05:07 +00:00
|
|
|
global $USER, $DB;
|
2003-06-10 15:27:09 +00:00
|
|
|
|
|
|
|
if (!$move) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sectiondest = $section + $move;
|
|
|
|
|
|
|
|
if ($sectiondest > $course->numsections or $sectiondest < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$sectionrecord = $DB->get_record("course_sections", array("course"=>$course->id, "section"=>$section))) {
|
2003-06-10 15:27:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$sectiondestrecord = $DB->get_record("course_sections", array("course"=>$course->id, "section"=>$sectiondest))) {
|
2003-06-10 15:27:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$DB->set_field("course_sections", "section", $sectiondest, array("id"=>$sectionrecord->id))) {
|
2003-06-10 15:27:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$DB->set_field("course_sections", "section", $section, array("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.
|
2008-06-01 19:05:07 +00:00
|
|
|
$sections = $DB->get_records('course_sections', array('course'=>$course->id), 'section ASC');
|
2006-07-19 12:30:39 +00:00
|
|
|
$n = 0;
|
|
|
|
foreach ($sections as $section) {
|
|
|
|
if ($section->section != $n) {
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$DB->set_field('course_sections', 'section', $n, array('id'=>$section->id))) {
|
2005-10-14 03:12:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-08-08 05:25:54 +00:00
|
|
|
/**
|
|
|
|
* Moves a section within a course, from a position to another.
|
|
|
|
* Be very careful: $section and $destination refer to section number,
|
|
|
|
* not id!.
|
|
|
|
*
|
|
|
|
* @param object $course
|
|
|
|
* @param int $section Section number (not id!!!)
|
|
|
|
* @param int $destination
|
|
|
|
* @return boolean Result
|
|
|
|
*/
|
|
|
|
function move_section_to($course, $section, $destination) {
|
|
|
|
/// Moves a whole course section up and down within the course
|
|
|
|
global $USER, $DB;
|
|
|
|
|
2008-10-08 12:22:04 +00:00
|
|
|
if (!$destination && $destination != 0) {
|
2008-08-08 05:25:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-08 12:22:04 +00:00
|
|
|
if ($destination > $course->numsections) {
|
2008-08-08 05:25:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all sections for this course and re-order them (2 of them should now share the same section number)
|
|
|
|
if (!$sections = $DB->get_records_menu('course_sections', array('course' => $course->id),
|
|
|
|
'section ASC, id ASC', 'id, section')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sections = reorder_sections($sections, $section, $destination);
|
|
|
|
|
|
|
|
// Update all sections
|
|
|
|
foreach ($sections as $id => $position) {
|
|
|
|
$DB->set_field('course_sections', 'section', $position, array('id' => $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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, $destination);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reordering algorithm for course sections. Given an array of section->section indexed by section->id,
|
|
|
|
* an original position number and a target position number, rebuilds the array so that the
|
|
|
|
* move is made without any duplication of section positions.
|
|
|
|
* Note: The target_position is the position AFTER WHICH the moved section will be inserted. If you want to
|
|
|
|
* insert a section before the first one, you must give 0 as the target (section 0 can never be moved).
|
|
|
|
*
|
|
|
|
* @param array $sections
|
|
|
|
* @param int $origin_position
|
|
|
|
* @param int $target_position
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function reorder_sections($sections, $origin_position, $target_position) {
|
|
|
|
if (!is_array($sections)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can't move section position 0
|
|
|
|
if ($origin_position < 1) {
|
|
|
|
echo "We can't move section position 0";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Locate origin section in sections array
|
|
|
|
if (!$origin_key = array_search($origin_position, $sections)) {
|
|
|
|
echo "searched position not in sections array";
|
|
|
|
return false; // searched position not in sections array
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract origin section
|
|
|
|
$origin_section = $sections[$origin_key];
|
|
|
|
unset($sections[$origin_key]);
|
|
|
|
|
|
|
|
// Find offset of target position (stupid PHP's array_splice requires offset instead of key index!)
|
|
|
|
$found = false;
|
|
|
|
$append_array = array();
|
|
|
|
foreach ($sections as $id => $position) {
|
|
|
|
if ($found) {
|
|
|
|
$append_array[$id] = $position;
|
|
|
|
unset($sections[$id]);
|
|
|
|
}
|
|
|
|
if ($position == $target_position) {
|
|
|
|
$found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append moved section
|
|
|
|
$sections[$origin_key] = $origin_section;
|
|
|
|
|
|
|
|
// Append rest of array (if applicable)
|
|
|
|
if (!empty($append_array)) {
|
|
|
|
foreach ($append_array as $id => $position) {
|
|
|
|
$sections[$id] = $position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Renumber positions
|
|
|
|
$position = 0;
|
|
|
|
foreach ($sections as $id => $p) {
|
|
|
|
$sections[$id] = $position;
|
|
|
|
$position++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sections;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Move the module object $mod to the specified $section
|
|
|
|
* If $beforemod exists then that is the module
|
|
|
|
* before which $modid should be inserted
|
|
|
|
* All parameters are objects
|
|
|
|
*/
|
2003-07-14 13:08:38 +00:00
|
|
|
function moveto_module($mod, $section, $beforemod=NULL) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2003-07-14 13:08:38 +00:00
|
|
|
|
|
|
|
/// 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;
|
2009-06-13 17:17:10 +00:00
|
|
|
$DB->update_record("course_modules", $mod);
|
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) {
|
2009-07-02 10:53:31 +00:00
|
|
|
global $CFG, $USER, $DB, $OUTPUT;
|
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
|
|
|
|
2007-02-16 07:57:19 +00:00
|
|
|
$modcontext = get_context_instance(CONTEXT_MODULE, $mod->id);
|
|
|
|
// no permission to edit
|
|
|
|
if (!has_capability('moodle/course:manageactivities', $modcontext)) {
|
2007-02-23 06:03:09 +00:00
|
|
|
return false;
|
2007-02-16 07:57:19 +00:00
|
|
|
}
|
|
|
|
|
2004-01-31 08:40:38 +00:00
|
|
|
if (!isset($str)) {
|
2008-04-17 06:41:00 +00:00
|
|
|
$str->assign = get_string("assignroles", 'role');
|
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
|
|
|
}
|
2007-02-16 07:57:19 +00:00
|
|
|
if (has_capability('moodle/course:activityvisibility', $modcontext)) {
|
|
|
|
if ($mod->visible) {
|
|
|
|
$hideshow = '<a class="editing_hide" title="'.$str->hide.'" href="'.$path.'/mod.php?hide='.$mod->id.
|
|
|
|
'&sesskey='.$sesskey.$section.'"><img'.
|
2009-07-02 10:53:31 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url('t/hide') . '" class="iconsmall" '.
|
2007-02-16 07:57:19 +00:00
|
|
|
' alt="'.$str->hide.'" /></a>'."\n";
|
|
|
|
} else {
|
|
|
|
$hideshow = '<a class="editing_show" title="'.$str->show.'" href="'.$path.'/mod.php?show='.$mod->id.
|
|
|
|
'&sesskey='.$sesskey.$section.'"><img'.
|
2009-07-02 10:53:31 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url('t/show') . '" class="iconsmall" '.
|
2007-02-16 07:57:19 +00:00
|
|
|
' alt="'.$str->show.'" /></a>'."\n";
|
|
|
|
}
|
2008-04-25 14:03:17 +00:00
|
|
|
} else {
|
|
|
|
$hideshow = '';
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2008-04-25 14:03:17 +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;
|
2007-03-22 07:16:57 +00:00
|
|
|
$groupclass = 'editing_groupsseparate';
|
2009-07-02 10:53:31 +00:00
|
|
|
$groupimage = $OUTPUT->old_icon_url('t/groups') . '';
|
2005-03-14 19:05:39 +00:00
|
|
|
$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;
|
2007-03-22 07:16:57 +00:00
|
|
|
$groupclass = 'editing_groupsvisible';
|
2009-07-02 10:53:31 +00:00
|
|
|
$groupimage = $OUTPUT->old_icon_url('t/groupv') . '';
|
2005-03-14 19:05:39 +00:00
|
|
|
$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';
|
2009-07-02 10:53:31 +00:00
|
|
|
$groupimage = $OUTPUT->old_icon_url('t/groupn') . '';
|
2005-03-14 19:05:39 +00:00
|
|
|
$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 = "";
|
|
|
|
}
|
2007-02-23 06:03:09 +00:00
|
|
|
|
2007-02-16 07:57:19 +00:00
|
|
|
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $mod->course))) {
|
|
|
|
if ($moveselect) {
|
|
|
|
$move = '<a class="editing_move" title="'.$str->move.'" href="'.$path.'/mod.php?copy='.$mod->id.
|
|
|
|
'&sesskey='.$sesskey.$section.'"><img'.
|
2009-07-02 10:53:31 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url('t/move') . '" class="iconsmall" '.
|
2007-02-16 07:57:19 +00:00
|
|
|
' alt="'.$str->move.'" /></a>'."\n";
|
|
|
|
} else {
|
|
|
|
$move = '<a class="editing_moveup" title="'.$str->moveup.'" href="'.$path.'/mod.php?id='.$mod->id.
|
|
|
|
'&move=-1&sesskey='.$sesskey.$section.'"><img'.
|
2009-07-02 10:53:31 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url('t/up') . '" class="iconsmall" '.
|
2007-02-16 07:57:19 +00:00
|
|
|
' alt="'.$str->moveup.'" /></a>'."\n".
|
|
|
|
'<a class="editing_movedown" title="'.$str->movedown.'" href="'.$path.'/mod.php?id='.$mod->id.
|
|
|
|
'&move=1&sesskey='.$sesskey.$section.'"><img'.
|
2009-07-02 10:53:31 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url('t/down') . '" class="iconsmall" '.
|
2007-02-16 07:57:19 +00:00
|
|
|
' alt="'.$str->movedown.'" /></a>'."\n";
|
|
|
|
}
|
2007-03-26 03:06:39 +00:00
|
|
|
} else {
|
2008-06-04 06:38:03 +00:00
|
|
|
$move = '';
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
2007-08-09 07:50:21 +00:00
|
|
|
$leftright = '';
|
2007-02-16 07:57:19 +00:00
|
|
|
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $mod->course))) {
|
2007-08-09 07:50:21 +00:00
|
|
|
|
2007-08-09 08:41:08 +00:00
|
|
|
if (right_to_left()) { // Exchange arrows on RTL
|
2009-07-03 09:59:00 +00:00
|
|
|
$rightarrow = 't/left';
|
|
|
|
$leftarrow = 't/right';
|
2007-08-09 07:50:21 +00:00
|
|
|
} else {
|
2009-07-03 09:59:00 +00:00
|
|
|
$rightarrow = 't/right';
|
|
|
|
$leftarrow = 't/left';
|
2007-08-09 07:50:21 +00:00
|
|
|
}
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-02-16 07:57:19 +00:00
|
|
|
if ($indent > 0) {
|
|
|
|
$leftright .= '<a class="editing_moveleft" title="'.$str->moveleft.'" href="'.$path.'/mod.php?id='.$mod->id.
|
|
|
|
'&indent=-1&sesskey='.$sesskey.$section.'"><img'.
|
2009-07-03 04:23:05 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url($leftarrow).'" class="iconsmall" '.
|
2007-02-16 07:57:19 +00:00
|
|
|
' alt="'.$str->moveleft.'" /></a>'."\n";
|
|
|
|
}
|
|
|
|
if ($indent >= 0) {
|
|
|
|
$leftright .= '<a class="editing_moveright" title="'.$str->moveright.'" href="'.$path.'/mod.php?id='.$mod->id.
|
|
|
|
'&indent=1&sesskey='.$sesskey.$section.'"><img'.
|
2009-07-03 04:23:05 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url($rightarrow).'" class="iconsmall" '.
|
2007-02-16 07:57:19 +00:00
|
|
|
' alt="'.$str->moveright.'" /></a>'."\n";
|
|
|
|
}
|
2005-03-14 19:05:39 +00:00
|
|
|
}
|
2008-04-17 06:41:00 +00:00
|
|
|
if (has_capability('moodle/course:managegroups', $modcontext)){
|
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $mod->id);
|
2009-01-01 14:25:29 +00:00
|
|
|
$assign = '<a class="editing_assign" title="'.$str->assign.'" href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.
|
2009-07-02 10:53:31 +00:00
|
|
|
$context->id.'"><img src="'.$OUTPUT->old_icon_url('i/roles') . '" alt="'.$str->assign.'" class="iconsmall"/></a>';
|
2008-04-25 14:03:44 +00:00
|
|
|
} else {
|
|
|
|
$assign = '';
|
2008-04-17 06:41:00 +00:00
|
|
|
}
|
2008-04-25 14:03:44 +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'.
|
2009-07-02 10:53:31 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url('t/edit') . '" 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'.
|
2009-07-02 10:53:31 +00:00
|
|
|
' src="'.$OUTPUT->old_icon_url('t/delete') . '" class="iconsmall" '.
|
2008-04-17 06:41:00 +00:00
|
|
|
' alt="'.$str->delete.'" /></a>'."\n".$hideshow.$groupmode."\n".$assign.'</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
|
|
|
|
2007-02-28 06:25:22 +00:00
|
|
|
$str = $course->shortname.': '. $course->fullname;
|
2005-01-24 22:21:28 +00:00
|
|
|
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) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
|
|
|
return $DB->record_exists("course_meta", array("child_course"=>$course->id));
|
2005-01-24 22:21:28 +00:00
|
|
|
}
|
|
|
|
|
2005-02-12 21:41:22 +00:00
|
|
|
|
|
|
|
/**
|
2008-06-01 19:09:13 +00:00
|
|
|
* Print standard form elements on module setup forms in mod/.../mod_form.php
|
2005-02-12 21:41:22 +00:00
|
|
|
*/
|
2007-09-06 01:35:37 +00:00
|
|
|
function print_standard_coursemodule_settings($form, $features=null) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$form->course))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("invalidcourseid");
|
2005-02-13 06:07:06 +00:00
|
|
|
}
|
|
|
|
print_groupmode_setting($form, $course);
|
2007-09-06 01:35:37 +00:00
|
|
|
if (!empty($features->groupings)) {
|
|
|
|
print_grouping_settings($form, $course);
|
|
|
|
}
|
2005-02-13 06:07:06 +00:00
|
|
|
print_visible_setting($form, $course);
|
2005-02-12 21:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-01 19:09:13 +00:00
|
|
|
* Print groupmode form element on module setup forms in mod/.../mod_form.php
|
2005-02-12 21:41:22 +00:00
|
|
|
*/
|
2005-02-13 06:31:01 +00:00
|
|
|
function print_groupmode_setting($form, $course=NULL) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2005-02-12 21:41:22 +00:00
|
|
|
|
2005-02-13 06:31:01 +00:00
|
|
|
if (empty($course)) {
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$form->course))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("invalidcourseid");
|
2005-02-13 06:31:01 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-12 21:41:22 +00:00
|
|
|
if ($form->coursemodule) {
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$cm = $DB->get_record('course_modules', array('id'=>$form->coursemodule))) {
|
2008-08-27 16:33:50 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2005-02-12 21:41:22 +00:00
|
|
|
}
|
2007-09-08 20:53:05 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
2005-02-12 21:41:22 +00:00
|
|
|
} else {
|
|
|
|
$cm = null;
|
2007-09-08 20:53:05 +00:00
|
|
|
$groupmode = groups_get_course_groupmode($course);
|
2005-02-12 21:41:22 +00:00
|
|
|
}
|
|
|
|
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">';
|
2007-09-08 20:53:05 +00:00
|
|
|
$choices = array();
|
2005-02-12 21:41:22 +00:00
|
|
|
$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>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-06 01:35:37 +00:00
|
|
|
/**
|
2008-06-01 19:09:13 +00:00
|
|
|
* Print groupmode form element on module setup forms in mod/.../mod_form.php
|
2007-09-06 01:35:37 +00:00
|
|
|
*/
|
|
|
|
function print_grouping_settings($form, $course=NULL) {
|
2008-05-15 21:40:00 +00:00
|
|
|
global $DB;
|
2007-09-06 01:35:37 +00:00
|
|
|
|
|
|
|
if (empty($course)) {
|
2008-06-01 19:05:07 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id'=>$form->course))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("invalidcourseid");
|
2007-09-06 01:35:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($form->coursemodule) {
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$cm = $DB->get_record('course_modules', array('id'=>$form->coursemodule))) {
|
2008-08-27 16:33:50 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2007-09-06 01:35:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$cm = null;
|
|
|
|
}
|
|
|
|
|
2008-05-15 21:40:00 +00:00
|
|
|
$groupings = $DB->get_records_menu('groupings', array('courseid'=>$course->id), 'name', 'id, name');
|
2007-09-06 01:35:37 +00:00
|
|
|
if (!empty($groupings)) {
|
|
|
|
echo '<tr valign="top">';
|
|
|
|
echo '<td align="right"><b>'.get_string('grouping', 'group').':</b></td>';
|
|
|
|
echo '<td align="left">';
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-09-06 01:35:37 +00:00
|
|
|
$groupingid = isset($cm->groupingid) ? $cm->groupingid : 0;
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-09-06 01:35:37 +00:00
|
|
|
choose_from_menu($groupings, 'groupingid', $groupingid, get_string('none'), '', 0, false);
|
|
|
|
echo '</td></tr>';
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2007-09-06 01:35:37 +00:00
|
|
|
$checked = empty($cm->groupmembersonly) ? '':'checked="checked"';
|
|
|
|
echo '<tr valign="top">';
|
|
|
|
echo '<td align="right"><b>'.get_string('groupmembersonly', 'group').':</b></td>';
|
|
|
|
echo '<td align="left">';
|
|
|
|
echo "<input type=\"checkbox\" name=\"groupmembersonly\" value=\"1\" $checked />";
|
|
|
|
echo '</td></tr>';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-12 21:41:22 +00:00
|
|
|
/**
|
2008-06-01 19:09:13 +00:00
|
|
|
* Print visibility setting form element on module setup forms in mod/.../mod_form.php
|
2005-02-12 21:41:22 +00:00
|
|
|
*/
|
2005-02-13 06:31:01 +00:00
|
|
|
function print_visible_setting($form, $course=NULL) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2005-02-17 19:19:21 +00:00
|
|
|
if (empty($course)) {
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$form->course))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("invalidcourseid");
|
2005-02-17 19:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-12 21:41:22 +00:00
|
|
|
if ($form->coursemodule) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$visible = $DB->get_field('course_modules', 'visible', array('id'=>$form->coursemodule));
|
2005-02-12 21:41:22 +00:00
|
|
|
} else {
|
|
|
|
$visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($form->mode == 'add') { // in this case $form->section is the section number, not the id
|
2008-06-01 19:05:07 +00:00
|
|
|
$hiddensection = !$DB->get_field('course_sections', 'visible', array('section'=>$form->section, 'course'=>$form->course));
|
2005-02-12 21:41:22 +00:00
|
|
|
} else {
|
2008-06-01 19:05:07 +00:00
|
|
|
$hiddensection = !$DB->get_field('course_sections', 'visible', array('id'=>$form->section));
|
2005-02-12 21:41:22 +00:00
|
|
|
}
|
|
|
|
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">';
|
2008-01-24 20:33:50 +00:00
|
|
|
$choices = array(1 => get_string('show'), 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
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
function update_restricted_mods($course, $mods) {
|
|
|
|
global $DB;
|
2008-02-21 15:17:41 +00:00
|
|
|
|
|
|
|
/// Delete all the current restricted list
|
2008-06-01 19:05:07 +00:00
|
|
|
$DB->delete_records('course_allowed_modules', array('course'=>$course->id));
|
2008-02-21 15:17:41 +00:00
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
if (empty($course->restrictmodules)) {
|
2008-02-21 15:17:41 +00:00
|
|
|
return; // We're done
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
2008-02-21 15:17:41 +00:00
|
|
|
|
|
|
|
/// Insert the new list of restricted mods
|
|
|
|
foreach ($mods as $mod) {
|
|
|
|
if ($mod == 0) {
|
|
|
|
continue; // this is the 'allow none' option
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
2008-02-21 15:17:41 +00:00
|
|
|
$am = new object();
|
|
|
|
$am->course = $course->id;
|
|
|
|
$am->module = $mod;
|
2008-06-01 19:05:07 +00:00
|
|
|
$DB->insert_record('course_allowed_modules',$am);
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $DB;
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
if (empty($course->restrictmodules)) {
|
|
|
|
return true;
|
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2008-02-21 15:17:41 +00:00
|
|
|
// Admins and admin-like people who can edit everything can also add anything.
|
|
|
|
// This is a bit wierd, really. I debated taking it out but it's enshrined in help for the setting.
|
2008-04-24 08:39:47 +00:00
|
|
|
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM))) {
|
2005-08-16 06:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-02-21 15:17:41 +00:00
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
if (is_numeric($mod)) {
|
|
|
|
$modid = $mod;
|
|
|
|
} else if (is_string($mod)) {
|
2008-06-01 19:05:07 +00:00
|
|
|
$modid = $DB->get_field('modules', 'id', array('name'=>$mod));
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
|
|
|
if (empty($modid)) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
return $DB->record_exists('course_allowed_modules', array('course'=>$course->id, 'module'=>$modid));
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 21:52:38 +00:00
|
|
|
/**
|
|
|
|
* Recursively delete category including all subcategories and courses.
|
2009-04-16 07:48:34 +00:00
|
|
|
* @param object $category
|
|
|
|
* @param boolean $showfeedback display some notices
|
|
|
|
* @return array return deleted courses
|
2008-05-13 21:52:38 +00:00
|
|
|
*/
|
|
|
|
function category_delete_full($category, $showfeedback=true) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $CFG, $DB;
|
2008-05-13 21:52:38 +00:00
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
require_once($CFG->libdir.'/questionlib.php');
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($children = $DB->get_records('course_categories', array('parent'=>$category->id), 'sortorder ASC')) {
|
2008-05-13 21:52:38 +00:00
|
|
|
foreach ($children as $childcat) {
|
2009-04-16 07:48:34 +00:00
|
|
|
category_delete_full($childcat, $showfeedback);
|
2008-05-13 21:52:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 07:48:34 +00:00
|
|
|
$deletedcourses = array();
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($courses = $DB->get_records('course', array('category'=>$category->id), 'sortorder ASC')) {
|
2008-05-13 21:52:38 +00:00
|
|
|
foreach ($courses as $course) {
|
2008-07-06 17:57:06 +00:00
|
|
|
if (!delete_course($course, false)) {
|
2009-04-16 07:48:34 +00:00
|
|
|
throw new moodle_exception('cannotdeletecategorycourse','','',$course->shortname);
|
2008-05-13 21:52:38 +00:00
|
|
|
}
|
2009-04-16 07:48:34 +00:00
|
|
|
$deletedcourses[] = $course;
|
2008-05-13 21:52:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now delete anything that may depend on course category context
|
|
|
|
grade_course_category_delete($category->id, 0, $showfeedback);
|
|
|
|
if (!question_delete_course_category($category, 0, $showfeedback)) {
|
2009-04-16 07:48:34 +00:00
|
|
|
throw new moodle_exception('cannotdeletecategoryquestions','','',$category->name);
|
2008-05-13 21:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// finally delete the category and it's context
|
2008-06-01 19:05:07 +00:00
|
|
|
$DB->delete_records('course_categories', array('id'=>$category->id));
|
2008-05-13 21:52:38 +00:00
|
|
|
delete_context(CONTEXT_COURSECAT, $category->id);
|
|
|
|
|
2008-07-06 17:57:06 +00:00
|
|
|
events_trigger('course_category_deleted', $category);
|
2008-05-13 21:52:38 +00:00
|
|
|
|
2009-08-07 07:18:01 +00:00
|
|
|
return $deletedcourses;
|
2008-05-13 21:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete category, but move contents to another category.
|
|
|
|
* @param object $ccategory
|
|
|
|
* @param int $newparentid category id
|
|
|
|
* @return bool status
|
|
|
|
*/
|
|
|
|
function category_delete_move($category, $newparentid, $showfeedback=true) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $CFG, $DB;
|
2008-05-13 21:52:38 +00:00
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
require_once($CFG->libdir.'/questionlib.php');
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if (!$newparentcat = $DB->get_record('course_categories', array('id'=>$newparentid))) {
|
2008-05-13 21:52:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($children = $DB->get_records('course_categories', array('parent'=>$category->id), 'sortorder ASC')) {
|
2008-05-13 21:52:38 +00:00
|
|
|
foreach ($children as $childcat) {
|
2009-02-17 16:33:32 +00:00
|
|
|
move_category($childcat, $newparentcat);
|
2008-05-13 21:52:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
if ($courses = $DB->get_records('course', array('category'=>$category->id), 'sortorder ASC', 'id')) {
|
2008-05-13 21:52:38 +00:00
|
|
|
if (!move_courses(array_keys($courses), $newparentid)) {
|
2008-06-04 06:38:03 +00:00
|
|
|
notify("Error moving courses");
|
2008-05-13 21:52:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-06-04 06:38:03 +00:00
|
|
|
notify(get_string('coursesmovedout', '', format_string($category->name)), 'notifysuccess');
|
2008-05-13 21:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now delete anything that may depend on course category context
|
|
|
|
grade_course_category_delete($category->id, $newparentid, $showfeedback);
|
|
|
|
if (!question_delete_course_category($category, $newparentcat, $showfeedback)) {
|
2008-06-04 06:38:03 +00:00
|
|
|
notify(get_string('errordeletingquestionsfromcategory', 'question', $category), 'notifysuccess');
|
2008-05-13 21:52:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally delete the category and it's context
|
2008-06-01 19:05:07 +00:00
|
|
|
$DB->delete_records('course_categories', array('id'=>$category->id));
|
2008-05-13 21:52:38 +00:00
|
|
|
delete_context(CONTEXT_COURSECAT, $category->id);
|
|
|
|
|
2008-07-06 17:57:06 +00:00
|
|
|
events_trigger('course_category_deleted', $category);
|
2008-05-13 21:52:38 +00:00
|
|
|
|
2008-06-04 06:38:03 +00:00
|
|
|
notify(get_string('coursecategorydeleted', '', format_string($category->name)), 'notifysuccess');
|
2008-05-13 21:52:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Efficiently moves many courses around while maintaining
|
|
|
|
* sortorder in order.
|
|
|
|
*
|
|
|
|
* @param $courseids is an array of course ids
|
|
|
|
*/
|
|
|
|
function move_courses($courseids, $categoryid) {
|
|
|
|
global $CFG, $DB;
|
2005-09-01 04:48:22 +00:00
|
|
|
|
2008-06-16 14:25:53 +00:00
|
|
|
if (!empty($courseids) and $category = $DB->get_record('course_categories', array('id'=>$categoryid))) {
|
|
|
|
$courseids = array_reverse($courseids);
|
|
|
|
$i = 1;
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2008-06-16 14:25:53 +00:00
|
|
|
foreach ($courseids as $courseid) {
|
|
|
|
if (!$course = $DB->get_record("course", array("id"=>$courseid))) {
|
|
|
|
notify("Error finding course $courseid");
|
|
|
|
} else {
|
|
|
|
$course->category = $categoryid;
|
|
|
|
$course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - $i++;
|
2007-09-19 07:14:23 +00:00
|
|
|
|
2009-06-13 17:17:10 +00:00
|
|
|
$DB->update_record('course', $course);
|
2008-06-16 14:25:53 +00:00
|
|
|
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
$newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
|
|
|
|
context_moved($context, $newparent);
|
2005-09-01 04:48:22 +00:00
|
|
|
}
|
2006-11-09 18:25:58 +00:00
|
|
|
}
|
2008-06-16 14:25:53 +00:00
|
|
|
fix_course_sortorder();
|
|
|
|
}
|
2005-09-01 04:48:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-01 19:05:07 +00:00
|
|
|
/**
|
|
|
|
* Efficiently moves a category - NOTE that this can have
|
|
|
|
* a huge impact access-control-wise...
|
|
|
|
*/
|
2009-02-17 16:33:32 +00:00
|
|
|
function move_category($category, $newparentcat) {
|
2008-06-01 19:05:07 +00:00
|
|
|
global $CFG, $DB;
|
2007-09-19 07:14:23 +00:00
|
|
|
|
2007-10-02 22:34:12 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSECAT, $category->id);
|
|
|
|
|
|
|
|
if (empty($newparentcat->id)) {
|
2009-02-17 16:33:32 +00:00
|
|
|
$DB->set_field('course_categories', 'parent', 0, array('id'=>$category->id));
|
2008-06-16 14:25:53 +00:00
|
|
|
|
2007-10-02 22:34:12 +00:00
|
|
|
$newparent = get_context_instance(CONTEXT_SYSTEM);
|
2008-06-16 14:25:53 +00:00
|
|
|
|
2007-10-02 22:34:12 +00:00
|
|
|
} else {
|
2009-02-17 16:33:32 +00:00
|
|
|
$DB->set_field('course_categories', 'parent', $newparentcat->id, array('id'=>$category->id));
|
2007-10-02 22:34:12 +00:00
|
|
|
$newparent = get_context_instance(CONTEXT_COURSECAT, $newparentcat->id);
|
2007-09-19 07:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
context_moved($context, $newparent);
|
|
|
|
|
2008-08-08 05:25:54 +00:00
|
|
|
// now make it last in new category
|
2008-06-16 14:25:53 +00:00
|
|
|
$DB->set_field('course_categories', 'sortorder', MAX_COURSES_IN_CATEGORY*MAX_COURSE_CATEGORIES, array('id'=>$category->id));
|
|
|
|
|
|
|
|
// and fix the sortorders
|
2007-09-19 07:14:23 +00:00
|
|
|
fix_course_sortorder();
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
2007-05-08 15:07:25 +00:00
|
|
|
return $sectionname;
|
2006-12-11 15:47:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-16 08:46:55 +00:00
|
|
|
/**
|
|
|
|
* Can the current user delete this course?
|
2009-05-04 19:56:32 +00:00
|
|
|
* Course creators have exception,
|
|
|
|
* 1 day after the creation they can sill delete the course.
|
2007-02-16 08:46:55 +00:00
|
|
|
* @param int $courseid
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function can_delete_course($courseid) {
|
2009-05-04 19:56:32 +00:00
|
|
|
global $USER, $DB;
|
2007-02-16 08:46:55 +00:00
|
|
|
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
|
|
|
|
2009-05-04 19:56:32 +00:00
|
|
|
if (has_capability('moodle/course:delete', $context)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hack: now try to find out if creator created this course recently (1 day)
|
|
|
|
if (!has_capability('moodle/course:create', $context)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$since = time() - 60*60*24;
|
|
|
|
|
|
|
|
$params = array('userid'=>$USER->id, 'url'=>"view.php?id=$courseid", 'since'=>$since);
|
|
|
|
$select = "module = 'course' AND action = 'new' AND userid = :userid AND url = :url AND time > :since";
|
|
|
|
|
|
|
|
return $DB->record_exists_select('log', $select, $params);
|
2007-02-16 08:46:55 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 08:11:10 +00:00
|
|
|
/**
|
|
|
|
* Save the Your name for 'Some role' strings.
|
|
|
|
*
|
|
|
|
* @param integer $courseid the id of this course.
|
|
|
|
* @param array $data the data that came from the course settings form.
|
|
|
|
*/
|
|
|
|
function save_local_role_names($courseid, $data) {
|
|
|
|
global $DB;
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
|
|
|
|
|
|
|
foreach ($data as $fieldname => $value) {
|
|
|
|
if (!strstr($fieldname, 'role_')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list($ignored, $roleid) = explode('_', $fieldname);
|
|
|
|
|
|
|
|
// make up our mind whether we want to delete, update or insert
|
|
|
|
if (!$value) {
|
|
|
|
$DB->delete_records('role_names', array('contextid' => $context->id, 'roleid' => $roleid));
|
|
|
|
|
|
|
|
} else if ($rolename = $DB->get_record('role_names', array('contextid' => $context->id, 'roleid' => $roleid))) {
|
|
|
|
$rolename->name = $value;
|
|
|
|
$DB->update_record('role_names', $rolename);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$rolename = new stdClass;
|
|
|
|
$rolename->contextid = $context->id;
|
|
|
|
$rolename->roleid = $roleid;
|
|
|
|
$rolename->name = $value;
|
|
|
|
$DB->insert_record('role_names', $rolename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-16 08:46:55 +00:00
|
|
|
|
2008-05-30 16:47:21 +00:00
|
|
|
/**
|
2007-03-23 02:29:05 +00:00
|
|
|
* Create a course and either return a $course object or false
|
|
|
|
*
|
|
|
|
* @param object $data - all the data needed for an entry in the 'course' table
|
|
|
|
*/
|
|
|
|
function create_course($data) {
|
2008-05-30 16:47:21 +00:00
|
|
|
global $CFG, $USER, $DB;
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2009-03-20 06:53:03 +00:00
|
|
|
//check the categoryid
|
|
|
|
if (!empty($data->category) && !$data->category==0) {
|
|
|
|
$category = $DB->get_record('course_categories', array('id'=>$data->category));
|
|
|
|
if (empty($category)) {
|
|
|
|
throw new moodle_exception('noexistingcategory');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//check if the shortname already exist
|
|
|
|
if(!empty($data->shortname)) {
|
|
|
|
$course = $DB->get_record('course', array('shortname' => $data->shortname));
|
|
|
|
if (!empty($course)) {
|
|
|
|
throw new moodle_exception('shortnametaken');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//check if the id number already exist
|
|
|
|
if(!empty($data->idnumber)) {
|
|
|
|
$course = $DB->get_record('course', array('idnumber' => $data->idnumber));
|
|
|
|
if (!empty($course)) {
|
|
|
|
throw new moodle_exception('idnumbertaken');
|
|
|
|
}
|
|
|
|
}
|
2009-08-07 07:18:01 +00:00
|
|
|
|
2009-03-20 06:53:03 +00:00
|
|
|
|
2007-03-23 02:29:05 +00:00
|
|
|
// preprocess allowed mods
|
|
|
|
$allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
|
|
|
|
unset($data->allowedmods);
|
2008-02-21 15:17:41 +00:00
|
|
|
if ($CFG->restrictmodulesfor == 'all') {
|
|
|
|
$data->restrictmodules = 1;
|
2009-05-08 14:24:56 +00:00
|
|
|
|
|
|
|
// if the user is not an admin, get the default allowed modules because
|
|
|
|
// there are no modules passed by the form
|
|
|
|
if(!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
|
|
|
if(!$allowedmods && $CFG->defaultallowedmodules) {
|
|
|
|
$allowedmods = explode(',', $CFG->defaultallowedmodules);
|
|
|
|
}
|
|
|
|
}
|
2008-02-21 15:17:41 +00:00
|
|
|
} else {
|
|
|
|
$data->restrictmodules = 0;
|
2007-03-23 02:29:05 +00:00
|
|
|
}
|
2007-02-16 08:46:55 +00:00
|
|
|
|
2007-03-23 02:29:05 +00:00
|
|
|
$data->timecreated = time();
|
|
|
|
|
2008-06-16 14:25:53 +00:00
|
|
|
// place at beginning of any category
|
|
|
|
$data->sortorder = 0;
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2008-05-30 16:47:21 +00:00
|
|
|
if ($newcourseid = $DB->insert_record('course', $data)) { // Set up new course
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2008-05-30 16:47:21 +00:00
|
|
|
$course = $DB->get_record('course', array('id'=>$newcourseid));
|
2007-03-23 02:29:05 +00:00
|
|
|
|
|
|
|
// Setup the blocks
|
2009-05-08 03:11:24 +00:00
|
|
|
blocks_add_default_course_blocks($course);
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2008-02-21 15:17:41 +00:00
|
|
|
update_restricted_mods($course, $allowedmods);
|
2007-03-23 02:29:05 +00:00
|
|
|
|
|
|
|
$section = new object();
|
2008-06-01 19:05:07 +00:00
|
|
|
$section->course = $course->id; // Create a default section.
|
2007-03-23 02:29:05 +00:00
|
|
|
$section->section = 0;
|
2008-05-30 16:47:21 +00:00
|
|
|
$section->id = $DB->insert_record('course_sections', $section);
|
2007-03-23 02:29:05 +00:00
|
|
|
|
|
|
|
fix_course_sortorder();
|
|
|
|
|
|
|
|
add_to_log(SITEID, 'course', 'new', 'view.php?id='.$course->id, $data->fullname.' (ID '.$course->id.')');
|
|
|
|
|
2008-11-13 08:11:10 +00:00
|
|
|
// Save any custom role names.
|
|
|
|
save_local_role_names($course->id, $data);
|
|
|
|
|
|
|
|
// Trigger events
|
2008-07-06 17:57:06 +00:00
|
|
|
events_trigger('course_created', $course);
|
|
|
|
|
2007-03-23 02:29:05 +00:00
|
|
|
return $course;
|
2008-06-04 06:38:03 +00:00
|
|
|
}
|
2007-03-23 02:29:05 +00:00
|
|
|
|
|
|
|
return false; // error
|
|
|
|
}
|
|
|
|
|
2008-05-30 16:47:21 +00:00
|
|
|
/**
|
2007-03-23 02:29:05 +00:00
|
|
|
* Update a course and return true or false
|
|
|
|
*
|
|
|
|
* @param object $data - all the data needed for an entry in the 'course' table
|
|
|
|
*/
|
|
|
|
function update_course($data) {
|
2008-05-30 16:47:21 +00:00
|
|
|
global $USER, $CFG, $DB;
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2008-02-21 15:17:41 +00:00
|
|
|
// Preprocess allowed mods
|
2007-03-23 02:29:05 +00:00
|
|
|
$allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
|
|
|
|
unset($data->allowedmods);
|
2008-02-21 15:17:41 +00:00
|
|
|
|
|
|
|
// Normal teachers can't change setting
|
2007-03-23 02:29:05 +00:00
|
|
|
if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
|
|
|
unset($data->restrictmodules);
|
|
|
|
}
|
|
|
|
|
2007-09-19 07:13:57 +00:00
|
|
|
$movecat = false;
|
2008-05-30 16:47:21 +00:00
|
|
|
$oldcourse = $DB->get_record('course', array('id'=>$data->id)); // should not fail, already tested above
|
2009-03-20 06:53:03 +00:00
|
|
|
// check that course id exist
|
|
|
|
if (empty($oldcourse)) {
|
|
|
|
throw new moodle_exception('courseidnotfound');
|
|
|
|
}
|
|
|
|
|
2007-03-23 02:29:05 +00:00
|
|
|
if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category))
|
|
|
|
or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
|
|
|
|
// can not move to new category, keep the old one
|
|
|
|
unset($data->category);
|
2008-05-30 16:47:21 +00:00
|
|
|
|
2007-09-19 07:13:57 +00:00
|
|
|
} elseif ($oldcourse->category != $data->category) {
|
|
|
|
$movecat = true;
|
2007-03-23 02:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update with the new data
|
2008-05-30 16:47:21 +00:00
|
|
|
if ($DB->update_record('course', $data)) {
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2008-05-30 16:47:21 +00:00
|
|
|
$course = $DB->get_record('course', array('id'=>$data->id));
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2007-06-07 15:40:08 +00:00
|
|
|
add_to_log($course->id, "course", "update", "edit.php?id=$course->id", $course->id);
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2008-02-21 15:17:41 +00:00
|
|
|
// "Admins" can change allowed mods for a course
|
2007-03-23 02:29:05 +00:00
|
|
|
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
|
|
|
update_restricted_mods($course, $allowedmods);
|
|
|
|
}
|
|
|
|
|
2007-09-19 07:13:57 +00:00
|
|
|
if ($movecat) {
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
$newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
|
|
|
|
context_moved($context, $newparent);
|
|
|
|
}
|
|
|
|
|
2007-03-23 02:29:05 +00:00
|
|
|
fix_course_sortorder();
|
|
|
|
|
|
|
|
// Test for and remove blocks which aren't appropriate anymore
|
2009-06-12 11:56:30 +00:00
|
|
|
blocks_remove_inappropriate($course);
|
2007-03-23 02:29:05 +00:00
|
|
|
|
2008-11-13 08:11:10 +00:00
|
|
|
// Save any custom role names.
|
|
|
|
save_local_role_names($course->id, $data);
|
2008-06-04 06:38:03 +00:00
|
|
|
|
2008-11-13 08:11:10 +00:00
|
|
|
// Trigger events
|
2008-07-06 17:57:06 +00:00
|
|
|
events_trigger('course_updated', $course);
|
2007-03-23 02:29:05 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-16 08:46:55 +00:00
|
|
|
|
2009-03-13 06:51:30 +00:00
|
|
|
/**
|
|
|
|
* Return all course participant for a given course
|
|
|
|
* @global object $DB
|
|
|
|
* @param integer $courseid
|
|
|
|
* @return array of user
|
|
|
|
*/
|
|
|
|
function get_course_participants ($courseid) {
|
|
|
|
global $DB;
|
|
|
|
$users = get_users_by_capability(
|
|
|
|
get_context_instance(CONTEXT_COURSE, $courseid),
|
|
|
|
'moodle/course:view');
|
|
|
|
return $users;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the user is a participant for a given course
|
|
|
|
* @global object $DB
|
|
|
|
* @param integer $userid
|
|
|
|
* @param integer $courseid
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function is_course_participant ($userid, $courseid) {
|
|
|
|
global $DB;
|
|
|
|
$users = get_users_by_capability(
|
|
|
|
get_context_instance(CONTEXT_COURSE, $courseid),
|
|
|
|
'moodle/course:view','u.id');
|
2009-08-07 07:18:01 +00:00
|
|
|
|
2009-03-13 06:51:30 +00:00
|
|
|
foreach($users as $user) {
|
|
|
|
if ($user->id == $userid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-08-07 07:18:01 +00:00
|
|
|
|
2009-03-13 06:51:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-20 06:53:03 +00:00
|
|
|
function get_course_by_id ($id) {
|
|
|
|
global $DB;
|
|
|
|
return $DB->get_record('course', array('id' => $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_course_by_shortname ($shortname) {
|
|
|
|
global $DB;
|
|
|
|
return $DB->get_record('course', array('shortname' => $shortname));
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_course_by_idnumber ($idnumber) {
|
|
|
|
global $DB;
|
|
|
|
return $DB->get_record('course', array('idnumber' => $idnumber));
|
|
|
|
}
|
|
|
|
|
2007-12-16 13:41:16 +00:00
|
|
|
?>
|