From 033af4b7baecac61367c0e54f7a2da77ec3be863 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Thu, 3 Nov 2011 08:30:26 +0100 Subject: [PATCH] MDL-29030 migrate and cleanup log report AMOS BEGIN MOV [log:view,coursereport_log],[log:view,report_log] MOV [log:viewtoday,coursereport_log],[log:viewtoday,report_log] AMOS END --- course/lib.php | 10 +- course/report/log/db/access.php | 68 ------- course/report/log/index.php | 169 ---------------- course/report/log/indexlive.php | 44 ----- course/report/log/live.php | 43 ----- course/report/log/mod.php | 23 --- course/report/log/version.php | 29 --- report/log/db/access.php | 55 ++++++ .../log/db/install.php | 24 +-- {course/report => report}/log/graph.php | 16 +- report/log/index.php | 182 ++++++++++++++++++ report/log/lang/en/report_log.php | 7 +- report/log/lib.php | 57 ++++++ .../log/lib.php => report/log/locallib.php | 73 +++---- report/log/settings.php | 26 ++- report/log/version.php | 30 +++ 16 files changed, 405 insertions(+), 451 deletions(-) delete mode 100644 course/report/log/db/access.php delete mode 100644 course/report/log/index.php delete mode 100644 course/report/log/indexlive.php delete mode 100644 course/report/log/live.php delete mode 100644 course/report/log/mod.php delete mode 100644 course/report/log/version.php create mode 100644 report/log/db/access.php rename course/report/log/lang/en/coursereport_log.php => report/log/db/install.php (57%) rename {course/report => report}/log/graph.php (93%) create mode 100644 report/log/index.php create mode 100644 report/log/lib.php rename course/report/log/lib.php => report/log/locallib.php (86%) create mode 100644 report/log/version.php diff --git a/course/lib.php b/course/lib.php index f9c4d87d34c..e545270d700 100644 --- a/course/lib.php +++ b/course/lib.php @@ -831,13 +831,19 @@ function print_log_ods($course, $user, $date, $order='l.time DESC', $modname, function print_log_graph($course, $userid=0, $type="course.png", $date=0) { global $CFG, $USER; + + // note: this is a hack - we should not use plugins from core + if (!file_exists($CFG->dirroot.'/report/log/graph.php')) { + return; + } + if (empty($CFG->gdversion)) { echo "(".get_string("gdneed").")"; } else { // MDL-10818, do not display broken graph when user has no permission to view graph - if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_COURSE, $course->id)) || + if (has_capability('report/log:view', get_context_instance(CONTEXT_COURSE, $course->id)) || ($course->showreports and $USER->id == $userid)) { - echo 'wwwroot.'/report/log/graph.php?id='.$course->id. '&user='.$userid.'&type='.$type.'&date='.$date.'" alt="" />'; } } diff --git a/course/report/log/db/access.php b/course/report/log/db/access.php deleted file mode 100644 index 7a4021becef..00000000000 --- a/course/report/log/db/access.php +++ /dev/null @@ -1,68 +0,0 @@ - array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'read', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - - 'clonepermissionsfrom' => 'moodle/site:viewreports', - ), - - 'coursereport/log:viewlive' => array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'read', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - - 'clonepermissionsfrom' => 'moodle/site:viewreports', - ), - - 'coursereport/log:viewtoday' => array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'read', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - - 'clonepermissionsfrom' => 'moodle/site:viewreports', - ) -); - - diff --git a/course/report/log/index.php b/course/report/log/index.php deleted file mode 100644 index 015d17d2db4..00000000000 --- a/course/report/log/index.php +++ /dev/null @@ -1,169 +0,0 @@ -libdir.'/adminlib.php'); - - $id = optional_param('id', 0, PARAM_INT);// Course ID - - $host_course = optional_param('host_course', '', PARAM_PATH);// Course ID - - if (empty($host_course)) { - $hostid = $CFG->mnet_localhost_id; - if (empty($id)) { - $site = get_site(); - $id = $site->id; - } - } else { - list($hostid, $id) = explode('/', $host_course); - } - - $group = optional_param('group', 0, PARAM_INT); // Group to display - $user = optional_param('user', 0, PARAM_INT); // User to display - $date = optional_param('date', 0, PARAM_FILE); // Date to display - number or some string - $modname = optional_param('modname', '', PARAM_PLUGIN); // course_module->id - $modid = optional_param('modid', 0, PARAM_FILE); // number or 'site_errors' - $modaction = optional_param('modaction', '', PARAM_PATH); // an action as recorded in the logs - $page = optional_param('page', '0', PARAM_INT); // which page to show - $perpage = optional_param('perpage', '100', PARAM_INT); // how many per page - $showcourses = optional_param('showcourses', 0, PARAM_INT); // whether to show courses if we're over our limit. - $showusers = optional_param('showusers', 0, PARAM_INT); // whether to show users if we're over our limit. - $chooselog = optional_param('chooselog', 0, PARAM_INT); - $logformat = optional_param('logformat', 'showashtml', PARAM_ALPHA); - - $params = array(); - if ($id !== 0) $params['id'] = $id; - if ($host_course !== '') $params['host_course'] = $host_course; - if ($group !== 0) $params['group'] = $group; - if ($user !== 0) $params['user'] = $user; - if ($date !== 0) $params['date'] = $date; - if ($modname !== '') $params['modname'] = $modname; - if ($modid !== 0) $params['modid'] = $modid; - if ($modaction !== '') $params['modaction'] = $modaction; - if ($page !== '0') $params['page'] = $page; - if ($perpage !== '100') $params['perpage'] = $perpage; - if ($showcourses !== 0) $params['showcourses'] = $showcourses; - if ($showusers !== 0) $params['showusers'] = $showusers; - if ($chooselog !== 0) $params['chooselog'] = $chooselog; - if ($logformat !== 'showashtml') $params['logformat'] = $logformat; - $PAGE->set_url('/course/report/log/index.php', $params); - $PAGE->set_pagelayout('report'); - - if ($hostid == $CFG->mnet_localhost_id) { - if (!$course = $DB->get_record('course', array('id'=>$id))) { - print_error('That\'s an invalid course id'.$id); - } - } else { - $course_stub = $DB->get_record('mnet_log', array('hostid'=>$hostid, 'course'=>$id), '*', true); - $course->id = $id; - $course->shortname = $course_stub->coursename; - $course->fullname = $course_stub->coursename; - } - - require_login($course); - - $context = get_context_instance(CONTEXT_COURSE, $course->id); - - require_capability('coursereport/log:view', $context); - - add_to_log($course->id, "course", "report log", "report/log/index.php?id=$course->id", $course->id); - - $strlogs = get_string('logs'); - $stradministration = get_string('administration'); - $strreports = get_string('reports'); - - session_get_instance()->write_close(); - - $navlinks = array(); - - if (!empty($chooselog)) { - $userinfo = get_string('allparticipants'); - $dateinfo = get_string('alldays'); - - if ($user) { - if (!$u = $DB->get_record('user', array('id'=>$user))) { - print_error('That\'s an invalid user!'); - } - $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context)); - } - if ($date) { - $dateinfo = userdate($date, get_string('strftimedaydate')); - } - - switch ($logformat) { - case 'showashtml': - if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) { - admin_externalpage_setup('reportlog'); - echo $OUTPUT->header(); - - } else { - $PAGE->set_title($course->shortname .': '. $strlogs); - $PAGE->set_heading($course->fullname); - $PAGE->navbar->add($strreports, new moodle_url('/course/report.php', array('id'=>$course->id))); - $PAGE->navbar->add($strlogs, new moodle_url('/course/report/log/index.php', array('id'=>$course->id))); - $PAGE->navbar->add("$userinfo, $dateinfo"); - echo $OUTPUT->header(); - } - - echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")"); - print_mnet_log_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat); - - if($hostid == $CFG->mnet_localhost_id) { - print_log($course, $user, $date, 'l.time DESC', $page, $perpage, - "index.php?id=$course->id&chooselog=1&user=$user&date=$date&modid=$modid&modaction=$modaction&group=$group", - $modname, $modid, $modaction, $group); - } else { - print_mnet_log($hostid, $id, $user, $date, 'l.time DESC', $page, $perpage, "", $modname, $modid, $modaction, $group); - } - break; - case 'downloadascsv': - if (!print_log_csv($course, $user, $date, 'l.time DESC', $modname, - $modid, $modaction, $group)) { - echo $OUTPUT->notification("No logs found!"); - echo $OUTPUT->footer(); - } - exit; - case 'downloadasods': - if (!print_log_ods($course, $user, $date, 'l.time DESC', $modname, - $modid, $modaction, $group)) { - echo $OUTPUT->notification("No logs found!"); - echo $OUTPUT->footer(); - } - exit; - case 'downloadasexcel': - if (!print_log_xls($course, $user, $date, 'l.time DESC', $modname, - $modid, $modaction, $group)) { - echo $OUTPUT->notification("No logs found!"); - echo $OUTPUT->footer(); - } - exit; - } - - - } else { - if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) { - admin_externalpage_setup('reportlog'); - echo $OUTPUT->header(); - } else { - $PAGE->set_title($course->shortname .': '. $strlogs); - $PAGE->set_heading($course->fullname); - echo $OUTPUT->header(); - } - - echo $OUTPUT->heading(get_string('chooselogs') .':'); - - print_log_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat); - - $livelogs = get_string('livelogs'); - $url = new moodle_url('/course/report/log/live.php', array('id'=>$course->id)); - $link = new action_link($url, $livelogs, new popup_action('click', $url, 'livelog', array('height' => 500, 'width' => 800))); - - echo $OUTPUT->render($link); - } - - echo $OUTPUT->footer(); - - exit; - diff --git a/course/report/log/indexlive.php b/course/report/log/indexlive.php deleted file mode 100644 index 09978b98e84..00000000000 --- a/course/report/log/indexlive.php +++ /dev/null @@ -1,44 +0,0 @@ -libdir.'/adminlib.php'); - - $id = optional_param('id', 0, PARAM_INT);// Course ID - - if (!$course = $DB->get_record('course', array('id'=>$id)) ) { - print_error('invalidcourseid'); - } - - require_login($course); - $context = get_context_instance(CONTEXT_COURSE, $course->id); - - require_capability('coursereport/log:viewlive', $context); - - $strlogs = get_string('logs'); - $strreports = get_string('reports'); - - if ($course->id == SITEID) { - admin_externalpage_setup('reportloglive'); - echo $OUTPUT->header(); - - } else { - $PAGE->set_title($course->shortname .': '. $strlogs); - $PAGE->set_heading($course->fullname); - $PAGE->navbar->add($strreports, new moodle_url('/course/report.php', array('id'=>$course->id)), navigation_node::TYPE_CUSTOM); - $PAGE->navbar->add($strlogs); - echo $OUTPUT->header(); - } - - echo $OUTPUT->heading(get_string('loglive', 'coursereport_log')); - - echo $OUTPUT->container_start('info'); - $link = new moodle_url('/course/report/log/live.php?id='. $course->id); - echo $OUTPUT->action_link($link, get_string('livelogs'), new popup_action('click', $link, 'livelog', array('height' => 500, 'width' => 800))); - echo $OUTPUT->container_end(); - - echo $OUTPUT->footer(); - - diff --git a/course/report/log/live.php b/course/report/log/live.php deleted file mode 100644 index 30622333a62..00000000000 --- a/course/report/log/live.php +++ /dev/null @@ -1,43 +0,0 @@ -get_record("course", array("id"=>$id))) { - print_error('invalidcourseid'); - } - - require_login($course); - - $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('coursereport/log:viewlive', $context); - - add_to_log($course->id, "course", "report live", "report/log/live.php?id=$course->id", $course->id); - - session_get_instance()->write_close(); - - $strlivelogs = get_string("livelogs"); - $strupdatesevery = get_string("updatesevery", "moodle", COURSE_LIVELOG_REFRESH); - - $PAGE->set_url('/course/report/log/live.php', array('id'=>$course->id)); - $PAGE->set_pagelayout('popup'); - $PAGE->set_title("$strlivelogs ($strupdatesevery)"); - $PAGE->set_periodic_refresh_delay(COURSE_LIVELOG_REFRESH); - $PAGE->set_heading($strlivelogs); - echo $OUTPUT->header(); - - $user=0; - $date=time() - 3600; - - print_log($course, $user, $date, "l.time DESC", $page, 500, - "live.php?id=$course->id&user=$user&date=$date"); - - echo $OUTPUT->footer(); - - exit; - - diff --git a/course/report/log/mod.php b/course/report/log/mod.php deleted file mode 100644 index 3c278a63be0..00000000000 --- a/course/report/log/mod.php +++ /dev/null @@ -1,23 +0,0 @@ -dirroot.'/course/lib.php'); - require_once($CFG->dirroot.'/course/report/log/lib.php'); - - if (has_capability('coursereport/log:view', $context)) { - echo $OUTPUT->heading(get_string('chooselogs') .':'); - - print_log_selector_form($course); - } - - if (has_capability('coursereport/log:viewlive', $context)) { - echo $OUTPUT->heading(get_string('chooselivelogs') .':'); - echo '

'; - $link = new moodle_url('/course/report/log/live.php?id='. $course->id); - echo $OUTPUT->action_link($link, get_string('livelogs'), new popup_action('click', $link, 'livelog', array('height' => 500, 'width' => 800))); - echo '

'; - } - diff --git a/course/report/log/version.php b/course/report/log/version.php deleted file mode 100644 index 819c2f13db1..00000000000 --- a/course/report/log/version.php +++ /dev/null @@ -1,29 +0,0 @@ -version = 2010090501; -$plugin->requires = 2010090501; - - diff --git a/report/log/db/access.php b/report/log/db/access.php new file mode 100644 index 00000000000..212af735b74 --- /dev/null +++ b/report/log/db/access.php @@ -0,0 +1,55 @@ +. + +/** + * Capabilities + * + * @package report + * @subpackage log + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$capabilities = array( + + 'report/log:view' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'coursereport/log:view', + ), + + 'report/log:viewtoday' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'coursereport/log:viewtoday', + ) +); + + diff --git a/course/report/log/lang/en/coursereport_log.php b/report/log/db/install.php similarity index 57% rename from course/report/log/lang/en/coursereport_log.php rename to report/log/db/install.php index 1a59f3f43bd..71e64986134 100644 --- a/course/report/log/lang/en/coursereport_log.php +++ b/report/log/db/install.php @@ -1,5 +1,4 @@ . /** - * Strings for component 'coursereport_log', language 'en', branch 'MOODLE_20_STABLE' + * Post installation and migration code. * - * @package coursereport_log - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package report + * @subpackage log + * @copyright 2011 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['loglive'] = 'Live logs'; -$string['log:view'] = 'View course logs'; -$string['log:viewlive'] = 'View live logs'; -$string['log:viewtoday'] = 'View today\'s logs'; -$string['pluginpagetype'] = 'Logs course report'; -$string['pluginname'] = 'Logs'; +defined('MOODLE_INTERNAL') || die; + +function xmldb_report_log_install() { + // this is a hack which is needed for cleanup of original coursereport_log stuff + unset_all_config_for_plugin('coursereport_log'); + capabilities_cleanup('coursereport_log'); +} + diff --git a/course/report/log/graph.php b/report/log/graph.php similarity index 93% rename from course/report/log/graph.php rename to report/log/graph.php index cf13b2cae97..579baf998f7 100644 --- a/course/report/log/graph.php +++ b/report/log/graph.php @@ -1,5 +1,4 @@ dirroot/course/lib.php"); require_once("$CFG->libdir/graphlib.php"); $id = required_param('id', PARAM_INT); // Course ID @@ -32,7 +32,7 @@ $type = required_param('type', PARAM_FILE); // Graph Type $user = optional_param('user', 0, PARAM_INT); // Student ID $date = optional_param('date', 0, PARAM_INT); // A time of a day (in GMT) -$url = new moodle_url('/course/report/log/graph.php', array('id'=>$id,'type'=>$type)); +$url = new moodle_url('/report/log/graph.php', array('id'=>$id,'type'=>$type)); if ($user !== 0) { $url->param('user', $user); } @@ -49,7 +49,7 @@ require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); if (!$course->showreports or $USER->id != $user) { - require_capability('coursereport/log:view', $context); + require_capability('report/log:view', $context); } if ($user) { diff --git a/report/log/index.php b/report/log/index.php new file mode 100644 index 00000000000..3b21a194587 --- /dev/null +++ b/report/log/index.php @@ -0,0 +1,182 @@ +. + +/** + * Displays different views of the logs. + * + * @package report + * @subpackage log + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require('../../config.php'); +require_once($CFG->dirroot.'/course/lib.php'); +require_once($CFG->dirroot.'/report/log/locallib.php'); +require_once($CFG->libdir.'/adminlib.php'); + +$id = optional_param('id', 0, PARAM_INT);// Course ID +$host_course = optional_param('host_course', '', PARAM_PATH);// Course ID + +if (empty($host_course)) { + $hostid = $CFG->mnet_localhost_id; + if (empty($id)) { + $site = get_site(); + $id = $site->id; + } +} else { + list($hostid, $id) = explode('/', $host_course); +} + +$group = optional_param('group', 0, PARAM_INT); // Group to display +$user = optional_param('user', 0, PARAM_INT); // User to display +$date = optional_param('date', 0, PARAM_FILE); // Date to display - number or some string +$modname = optional_param('modname', '', PARAM_PLUGIN); // course_module->id +$modid = optional_param('modid', 0, PARAM_FILE); // number or 'site_errors' +$modaction = optional_param('modaction', '', PARAM_PATH); // an action as recorded in the logs +$page = optional_param('page', '0', PARAM_INT); // which page to show +$perpage = optional_param('perpage', '100', PARAM_INT); // how many per page +$showcourses = optional_param('showcourses', 0, PARAM_INT); // whether to show courses if we're over our limit. +$showusers = optional_param('showusers', 0, PARAM_INT); // whether to show users if we're over our limit. +$chooselog = optional_param('chooselog', 0, PARAM_INT); +$logformat = optional_param('logformat', 'showashtml', PARAM_ALPHA); + +$params = array(); +if ($id !== 0) $params['id'] = $id; +if ($host_course !== '') $params['host_course'] = $host_course; +if ($group !== 0) $params['group'] = $group; +if ($user !== 0) $params['user'] = $user; +if ($date !== 0) $params['date'] = $date; +if ($modname !== '') $params['modname'] = $modname; +if ($modid !== 0) $params['modid'] = $modid; +if ($modaction !== '') $params['modaction'] = $modaction; +if ($page !== '0') $params['page'] = $page; +if ($perpage !== '100') $params['perpage'] = $perpage; +if ($showcourses !== 0) $params['showcourses'] = $showcourses; +if ($showusers !== 0) $params['showusers'] = $showusers; +if ($chooselog !== 0) $params['chooselog'] = $chooselog; +if ($logformat !== 'showashtml') $params['logformat'] = $logformat; +$PAGE->set_url('/report/log/index.php', $params); +$PAGE->set_pagelayout('report'); + +if ($hostid == $CFG->mnet_localhost_id) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error('That\'s an invalid course id'.$id); + } +} else { + $course_stub = $DB->get_record('mnet_log', array('hostid'=>$hostid, 'course'=>$id), '*', true); + $course->id = $id; + $course->shortname = $course_stub->coursename; + $course->fullname = $course_stub->coursename; +} + +require_login($course); + +$context = get_context_instance(CONTEXT_COURSE, $course->id); + +require_capability('report/log:view', $context); + +add_to_log($course->id, "course", "report log", "report/log/index.php?id=$course->id", $course->id); + +$strlogs = get_string('logs'); +$stradministration = get_string('administration'); +$strreports = get_string('reports'); + +session_get_instance()->write_close(); + +$navlinks = array(); + +if (!empty($chooselog)) { + $userinfo = get_string('allparticipants'); + $dateinfo = get_string('alldays'); + + if ($user) { + if (!$u = $DB->get_record('user', array('id'=>$user))) { + print_error('That\'s an invalid user!'); + } + $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context)); + } + if ($date) { + $dateinfo = userdate($date, get_string('strftimedaydate')); + } + + switch ($logformat) { + case 'showashtml': + if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) { + admin_externalpage_setup('reportlog'); + echo $OUTPUT->header(); + + } else { + $PAGE->set_title($course->shortname .': '. $strlogs); + $PAGE->set_heading($course->fullname); + $PAGE->navbar->add("$userinfo, $dateinfo"); + echo $OUTPUT->header(); + } + + echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")"); + print_mnet_log_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat); + + if($hostid == $CFG->mnet_localhost_id) { + print_log($course, $user, $date, 'l.time DESC', $page, $perpage, + "index.php?id=$course->id&chooselog=1&user=$user&date=$date&modid=$modid&modaction=$modaction&group=$group", + $modname, $modid, $modaction, $group); + } else { + print_mnet_log($hostid, $id, $user, $date, 'l.time DESC', $page, $perpage, "", $modname, $modid, $modaction, $group); + } + break; + case 'downloadascsv': + if (!print_log_csv($course, $user, $date, 'l.time DESC', $modname, + $modid, $modaction, $group)) { + echo $OUTPUT->notification("No logs found!"); + echo $OUTPUT->footer(); + } + exit; + case 'downloadasods': + if (!print_log_ods($course, $user, $date, 'l.time DESC', $modname, + $modid, $modaction, $group)) { + echo $OUTPUT->notification("No logs found!"); + echo $OUTPUT->footer(); + } + exit; + case 'downloadasexcel': + if (!print_log_xls($course, $user, $date, 'l.time DESC', $modname, + $modid, $modaction, $group)) { + echo $OUTPUT->notification("No logs found!"); + echo $OUTPUT->footer(); + } + exit; + } + + +} else { + if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) { + admin_externalpage_setup('reportlog'); + echo $OUTPUT->header(); + } else { + $PAGE->set_title($course->shortname .': '. $strlogs); + $PAGE->set_heading($course->fullname); + echo $OUTPUT->header(); + } + + echo $OUTPUT->heading(get_string('chooselogs') .':'); + + print_log_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat); +} + +echo $OUTPUT->footer(); + +exit; + diff --git a/report/log/lang/en/report_log.php b/report/log/lang/en/report_log.php index 9a447d9202c..a8ae48e0d96 100644 --- a/report/log/lang/en/report_log.php +++ b/report/log/lang/en/report_log.php @@ -15,12 +15,15 @@ // along with Moodle. If not, see . /** - * Strings for component 'report_log' + * Lang strings. * * @package report * @subpackage log - * @copyright 2011 Petr Skoda (http://skodak.org) + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['log:view'] = 'View course logs'; +$string['log:viewtoday'] = 'View today\'s logs'; +$string['pluginpagetype'] = 'Logs course report'; $string['pluginname'] = 'Logs'; diff --git a/report/log/lib.php b/report/log/lib.php new file mode 100644 index 00000000000..3caa391af7b --- /dev/null +++ b/report/log/lib.php @@ -0,0 +1,57 @@ +. + +/** + * Libs + * + * @package report + * @subpackage log + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +/** + * This function extends the navigation with the report items + * + * @param navigation_node $navigation The navigation node to extend + * @param stdClass $course The course to object for the report + * @param stdClass $context The context of the course + */ +function report_log_extend_navigation_course($navigation, $course, $context) { + global $CFG, $OUTPUT; + if (has_capability('report/log:view', $context)) { + $url = new moodle_url('/report/log/index.php', array('id'=>$course->id)); + $navigation->add(get_string('pluginname', 'report_log'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); + } +} + +/** + * Return a list of page types + * @param string $pagetype current page type + * @param stdClass $parentcontext Block's parent context + * @param stdClass $currentcontext Current context of block + * @return array + */ +function report_log_page_type_list($pagetype, $parentcontext, $currentcontext) { + $array = array( + '*' => get_string('page-x', 'pagetype'), + 'course-report-*' => get_string('page-course-report-x', 'pagetype'), + 'course-report-log-index' => get_string('pluginpagetype', 'report_log') + ); + return $array; +} \ No newline at end of file diff --git a/course/report/log/lib.php b/report/log/locallib.php similarity index 86% rename from course/report/log/lib.php rename to report/log/locallib.php index eca683b5742..97314e244d0 100644 --- a/course/report/log/lib.php +++ b/report/log/locallib.php @@ -1,5 +1,4 @@ mnet_localhost_id == $hostid) { - if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { + if (has_capability('report/log:view', $sitecontext) && $showcourses) { if ($ccc = $DB->get_records("course", null, "fullname","id,fullname,category")) { foreach ($ccc as $cc) { if ($cc->id == SITEID) { @@ -146,7 +150,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select } } } else { - if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { + if (has_capability('report/log:view', $sitecontext) && $showcourses) { $sql = "SELECT DISTINCT course, coursename FROM {mnet_log} where hostid = ?"; if ($ccc = $DB->get_records_sql($sql, array($hostid))) { foreach ($ccc as $cc) { @@ -195,7 +199,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select } } - if (has_capability('coursereport/log:view', $sitecontext) && !$course->category) { + if (has_capability('report/log:view', $sitecontext) && !$course->category) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; @@ -244,21 +248,21 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select $selecteddate = $today; } - echo "
wwwroot/course/report/log/index.php\" method=\"get\">\n"; + echo "wwwroot/report/log/index.php\" method=\"get\">\n"; echo "
\n";//invisible fieldset here breaks wrapping echo "\n"; echo "\n"; echo "\n"; - if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { + if (has_capability('report/log:view', $sitecontext) && $showcourses) { $cid = empty($course->id)? '1' : $course->id; echo html_writer::select($dropdown, "host_course", $hostid.'/'.$cid); } else { $courses = array(); $courses[$course->id] = $course->fullname . ((empty($course->category)) ? ' ('.get_string('site').') ' : ''); echo html_writer::select($courses,"id",$course->id, false); - if (has_capability('coursereport/log:view', $sitecontext)) { + if (has_capability('report/log:view', $sitecontext)) { $a = new stdClass(); - $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" + $a->url = "$CFG->wwwroot/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; print_string('logtoomanycourses','moodle',$a); } @@ -289,7 +293,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select $users[0] = get_string('allparticipants'); } echo html_writer::select($users, "user", $selecteduser, false); - $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" + $a->url = "$CFG->wwwroot/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showusers=1&showcourses=$showcourses"; print_string('logtoomanyusers','moodle',$a); } @@ -365,7 +369,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' $users[$CFG->siteguest] = get_string('guestuser'); } - if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { + if (has_capability('report/log:view', $sitecontext) && $showcourses) { if ($ccc = $DB->get_records("course", null, "fullname", "id,fullname,category")) { foreach ($ccc as $cc) { if ($cc->category) { @@ -408,7 +412,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' } } - if (has_capability('coursereport/log:view', $sitecontext) && ($course->id == SITEID)) { + if (has_capability('report/log:view', $sitecontext) && ($course->id == SITEID)) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; @@ -457,21 +461,21 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' $selecteddate = $today; } - echo "wwwroot/course/report/log/index.php\" method=\"get\">\n"; + echo "wwwroot/report/log/index.php\" method=\"get\">\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; - if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { + if (has_capability('report/log:view', $sitecontext) && $showcourses) { echo html_writer::select($courses, "id", $course->id, false); } else { // echo ''; $courses = array(); $courses[$course->id] = $course->fullname . (($course->id == SITEID) ? ' ('.get_string('site').') ' : ''); echo html_writer::select($courses,"id",$course->id, false); - if (has_capability('coursereport/log:view', $sitecontext)) { + if (has_capability('report/log:view', $sitecontext)) { $a = new stdClass(); - $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" + $a->url = "$CFG->wwwroot/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; print_string('logtoomanycourses','moodle',$a); } @@ -503,7 +507,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' } echo html_writer::select($users, "user", $selecteduser, false); $a = new stdClass(); - $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" + $a->url = "$CFG->wwwroot/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showusers=1&showcourses=$showcourses"; print_string('logtoomanyusers','moodle',$a); } @@ -522,34 +526,3 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' echo '
'; echo ''; } - -/** - * This function extends the navigation with the report items - * - * @param navigation_node $navigation The navigation node to extend - * @param stdClass $course The course to object for the report - * @param stdClass $context The context of the course - */ -function log_report_extend_navigation($navigation, $course, $context) { - global $CFG, $OUTPUT; - if (has_capability('coursereport/log:view', $context)) { - $url = new moodle_url('/course/report/log/index.php', array('id'=>$course->id)); - $navigation->add(get_string('pluginname', 'coursereport_log'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); - } -} - -/** - * Return a list of page types - * @param string $pagetype current page type - * @param stdClass $parentcontext Block's parent context - * @param stdClass $currentcontext Current context of block - */ -function log_page_type_list($pagetype, $parentcontext, $currentcontext) { - $array = array( - '*' => get_string('page-x', 'pagetype'), - 'course-report-*' => get_string('page-course-report-x', 'pagetype'), - 'course-report-log-index' => get_string('pluginpagetype', 'coursereport_log') - //course-report-log-live not included as theres no blocks on the live log page - ); - return $array; -} \ No newline at end of file diff --git a/report/log/settings.php b/report/log/settings.php index d879feb10f3..22fb79450ee 100644 --- a/report/log/settings.php +++ b/report/log/settings.php @@ -1,10 +1,32 @@ . + +/** + * Links and settings + * + * @package report + * @subpackage log + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ defined('MOODLE_INTERNAL') || die; // just a link to course report -$ADMIN->add('reports', new admin_externalpage('reportlog', get_string('log', 'admin'), "$CFG->wwwroot/course/report/log/index.php?id=".SITEID, 'coursereport/log:view')); -$ADMIN->add('reports', new admin_externalpage('reportloglive', get_string('loglive', 'coursereport_log'), "$CFG->wwwroot/course/report/log/indexlive.php?id=".SITEID, 'coursereport/log:viewlive')); +$ADMIN->add('reports', new admin_externalpage('reportlog', get_string('log', 'admin'), "$CFG->wwwroot/report/log/index.php?id=".SITEID, 'report/log:view')); // no report settings $settings = null; diff --git a/report/log/version.php b/report/log/version.php new file mode 100644 index 00000000000..29af7026f52 --- /dev/null +++ b/report/log/version.php @@ -0,0 +1,30 @@ +. + +/** + * Version info + * + * @package report + * @subpackage log + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +$plugin->version = 2011110202; // The current plugin version (Date: YYYYMMDDXX) +$plugin->requires = 2011102700.01; // Requires this Moodle version +$plugin->component = 'report_log'; // Full name of the plugin (used for diagnostics)