diff --git a/course/lib.php b/course/lib.php index 79ccf916c22..f9c4d87d34c 100644 --- a/course/lib.php +++ b/course/lib.php @@ -31,7 +31,6 @@ require_once($CFG->libdir.'/filelib.php'); 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 define('COURSE_MAX_COURSES_PER_DROPDOWN',1000); // max courses in log dropdown before switching to optional diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 446e8d706f5..113e0374b3b 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -902,7 +902,6 @@ $string['liketologin'] = 'Would you like to log in now with a full user account? $string['list'] = 'List'; $string['listfiles'] = 'List of files in {$a}'; $string['listofallpeople'] = 'List of all people'; -$string['livelogs'] = 'Live logs from the past hour'; $string['local'] = 'Local'; $string['localplugindeleteconfirm'] = 'You are about to completely delete the local plugin \'{$a}\'. This will completely delete everything in the database associated with this plugin. Are you SURE you want to continue?'; $string['localplugins'] = 'Local plugins'; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 1fc85b29ab2..5f3520cff49 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -304,7 +304,7 @@ class plugin_manager { ), 'coursereport' => array( - 'log', 'stats' + 'stats' ), 'datafield' => array( @@ -407,7 +407,7 @@ class plugin_manager { 'report' => array( 'backups', 'completion', 'configlog', 'courseoverview', - 'log', 'outline', 'participation', 'progress', 'questioninstances', 'security', 'stats' + 'log', 'loglive', 'outline', 'participation', 'progress', 'questioninstances', 'security', 'stats' ), 'repository' => array( diff --git a/report/loglive/db/access.php b/report/loglive/db/access.php new file mode 100644 index 00000000000..a97cd3a2c10 --- /dev/null +++ b/report/loglive/db/access.php @@ -0,0 +1,40 @@ +. + +/** + * Capabilities + * + * @package report + * @subpackage loglive + * @copyright 2011 Petr Skoda + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$capabilities = array( + + 'report/loglive:view' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + ), +); + + diff --git a/report/loglive/index.php b/report/loglive/index.php new file mode 100644 index 00000000000..ba9fc30709a --- /dev/null +++ b/report/loglive/index.php @@ -0,0 +1,92 @@ +. + +/** + * Displays live view of recent logs + * + * @package report + * @subpackage loglive + * @copyright 2011 Petr Skoda + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require('../../config.php'); +require_once($CFG->libdir.'/adminlib.php'); +require_once($CFG->dirroot.'/course/lib.php'); + +if (!defined('REPORT_LOGLIVE_REFRESH')) { + define('REPORT_LOGLIVE_REFRESH', 60); // Seconds +} + +$id = optional_param('id', $SITE->id, PARAM_INT); +$page = optional_param('page', 0, PARAM_INT); +$inpopup = optional_param('inpopup', 0, PARAM_BOOL); + +$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); + +require_login($course); + +$context = context_course::instance($course->id); +require_capability('report/loglive:view', $context); + +$strlivelogs = get_string('livelogs', 'report_loglive'); + +if ($inpopup) { + session_get_instance()->write_close(); + + add_to_log($course->id, 'course', 'report live', "report/loglive/index.php?id=$course->id", $course->id); + + $date = time() - 3600; + + $url = new moodle_url('/report/loglive/index.php', array('id'=>$course->id, 'user'=>0, 'date'=>$date, 'inpopup'=>1)); + + $strupdatesevery = get_string('updatesevery', 'moodle', REPORT_LOGLIVE_REFRESH); + + $coursename = format_string($course->fullname, true, array('context'=>$context)); + + $PAGE->set_url($url); + $PAGE->set_pagelayout('popup'); + $PAGE->set_title("$coursename: $strlivelogs ($strupdatesevery)"); + $PAGE->set_periodic_refresh_delay(REPORT_LOGLIVE_REFRESH); + $PAGE->set_heading($strlivelogs); + echo $OUTPUT->header(); + + print_log($course, 0, $date, "l.time DESC", $page, 500, $url); + + echo $OUTPUT->footer(); + exit; +} + + +if ($course->id == SITEID) { + admin_externalpage_setup('reportloglive'); + echo $OUTPUT->header(); + +} else { + $PAGE->set_url('/report/log/live.php', array('id'=>$course->id)); + $PAGE->set_title($course->shortname .': '. $strlogs); + $PAGE->set_heading($course->fullname); + echo $OUTPUT->header(); +} + +echo $OUTPUT->heading(get_string('pluginname', 'report_loglive')); + +echo $OUTPUT->container_start('info'); +$link = new moodle_url('/report/loglive/index.php', array('id'=>$course->id, 'inpopup'=>1)); +echo $OUTPUT->action_link($link, $strlivelogs, new popup_action('click', $link, 'livelog', array('height' => 500, 'width' => 800))); +echo $OUTPUT->container_end(); + +echo $OUTPUT->footer(); diff --git a/report/loglive/lang/en/report_loglive.php b/report/loglive/lang/en/report_loglive.php new file mode 100644 index 00000000000..6d5cc0a76f9 --- /dev/null +++ b/report/loglive/lang/en/report_loglive.php @@ -0,0 +1,28 @@ +. + +/** + * Lang strings. + * + * @package report + * @subpackage loglive + * @copyright 2011 Petr Skoda + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['loglive:view'] = 'View live logs'; +$string['pluginname'] = 'Live logs'; +$string['livelogs'] = 'Live logs from the past hour'; diff --git a/report/loglive/lib.php b/report/loglive/lib.php new file mode 100644 index 00000000000..9d059367580 --- /dev/null +++ b/report/loglive/lib.php @@ -0,0 +1,44 @@ +. + +/** + * Libs, public API. + * + * NOTE: page type not included because there can not be any blocks in popups + * + * @package report + * @subpackage loglive + * @copyright 2011 Petr Skoda + * @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_loglive_extend_navigation_course($navigation, $course, $context) { + global $CFG, $OUTPUT; + if (has_capability('report/loglive:view', $context)) { + $url = new moodle_url('/report/loglive/index.php', array('id'=>$course->id, 'inpopup'=>1)); + $action = new action_link($url, get_string('pluginname', 'report_loglive'), new popup_action('click', $url)); + $navigation->add('', $action, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); + } +} diff --git a/report/loglive/settings.php b/report/loglive/settings.php new file mode 100644 index 00000000000..13de346c107 --- /dev/null +++ b/report/loglive/settings.php @@ -0,0 +1,32 @@ +. + +/** + * Links and settings + * + * @package report + * @subpackage loglive + * @copyright 2011 Petr Skoda + * @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('reportloglive', get_string('pluginname', 'report_loglive'), "$CFG->wwwroot/report/loglive/index.php", 'report/loglive:view')); + +// no report settings +$settings = null; diff --git a/report/loglive/version.php b/report/loglive/version.php new file mode 100644 index 00000000000..85ef9d0b251 --- /dev/null +++ b/report/loglive/version.php @@ -0,0 +1,30 @@ +. + +/** + * Version info + * + * @package report + * @subpackage loglive + * @copyright 2011 Petr Skoda + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +$plugin->version = 2011110200; // The current plugin version (Date: YYYYMMDDXX) +$plugin->requires = 2011102700.01; // Requires this Moodle version +$plugin->component = 'report_loglive'; // Full name of the plugin (used for diagnostics)