$return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
+$syscontext = context_system::instance();
+
switch ($action) {
case 'disable':
unset($enabled[$enrol]);
set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
+ $syscontext->mark_dirty(); // resets all enrol caches
break;
case 'enable':
$enabled = array_keys($enabled);
$enabled[] = $enrol;
set_config('enrol_plugins_enabled', implode(',', $enabled));
+ $syscontext->mark_dirty(); // resets all enrol caches
break;
case 'up':
} else { // Delete everything!!
uninstall_plugin('enrol', $enrol);
+ $syscontext->mark_dirty(); // resets all enrol caches
$a->plugin = $strplugin;
$a->directory = "$CFG->dirroot/enrol/$enrol";
$strmnetedithost = get_string('reviewhostdetails', 'mnet');
$logurl = $CFG->wwwroot.
- '/course/report/log/index.php?chooselog=1&showusers=1&showcourses=1&host_course='.$mnet_peer->id.
+ '/report/log/index.php?chooselog=1&showusers=1&showcourses=1&host_course='.$mnet_peer->id.
'%2F1&user='.'0'.
'&date=0'.
'&modid=&modaction=0&logformat=showashtml';
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->libdir . '/adminlib.php');
+require_once($CFG->libdir . '/pluginlib.php');
require_once($CFG->libdir . '/tablelib.php');
// Check permissions.
$thispageurl = new moodle_url('/admin/qbehaviours.php');
$behaviours = get_plugin_list('qbehaviour');
+$pluginmanager = plugin_manager::instance();
// Get some data we will need - question counts and which types are needed.
$counts = $DB->get_records_sql_menu("
if (!array_key_exists($behaviour, $counts)) {
$counts[$behaviour] = 0;
}
- $needed[$behaviour] = $counts[$behaviour] > 0;
+ $needed[$behaviour] = ($counts[$behaviour] > 0) &&
+ $pluginmanager->other_plugins_that_require('qbehaviour_' . $behaviour);
$archetypal[$behaviour] = question_engine::is_behaviour_archetypal($behaviour);
}
-foreach ($behaviours as $behaviour => $notused) {
- foreach (question_engine::get_behaviour_required_behaviours($behaviour) as $reqbehaviour) {
- $needed[$reqbehaviour] = true;
- }
-}
foreach ($counts as $behaviour => $count) {
if (!array_key_exists($behaviour, $behaviours)) {
$counts['missingtype'] += $count;
}
// Other question types required by this one.
- $requiredbehaviours = question_engine::get_behaviour_required_behaviours($behaviour);
- if (!empty($requiredbehaviours)) {
- $strrequiredbehaviours = array();
- foreach ($requiredbehaviours as $required) {
- $strrequiredbehaviours[] = $sortedbehaviours[$required];
+ $plugin = $pluginmanager->get_plugin_info('qbehaviour_' . $behaviour);
+ $required = $plugin->get_other_required_plugins();
+ if (!empty($required)) {
+ $strrequired = array();
+ foreach ($required as $component => $notused) {
+ $strrequired[] = $pluginmanager->plugin_name($component);
}
- $row[] = implode(', ', $strrequiredbehaviours);
+ $row[] = implode(', ', $strrequired);
} else {
$row[] = '';
}
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->libdir . '/adminlib.php');
+require_once($CFG->libdir . '/pluginlib.php');
require_once($CFG->libdir . '/tablelib.php');
// Check permissions.
$thispageurl = new moodle_url('/admin/qtypes.php');
$qtypes = question_bank::get_all_qtypes();
+$pluginmanager = plugin_manager::instance();
// Get some data we will need - question counts and which types are needed.
$counts = $DB->get_records_sql("
$counts[$qtypename]->numquestions = 0;
$counts[$qtypename]->numhidden = 0;
}
- $needed[$qtypename] = $counts[$qtypename]->numquestions > 0;
+ $needed[$qtypename] = $counts[$qtypename]->numquestions > 0 &&
+ $pluginmanager->other_plugins_that_require($qtype->plugin_name());
$counts[$qtypename]->numquestions -= $counts[$qtypename]->numhidden;
}
$needed['missingtype'] = true; // The system needs the missing question type.
-foreach ($qtypes as $qtypename => $qtype) {
- foreach ($qtype->requires_qtypes() as $reqtype) {
- $needed[$reqtype] = true;
- }
-}
foreach ($counts as $qtypename => $count) {
if (!isset($qtypes[$qtypename])) {
$counts['missingtype']->numquestions += $count->numquestions - $count->numhidden;
}
// Other question types required by this one.
- $requiredtypes = $qtype->requires_qtypes();
+ $plugin = $pluginmanager->get_plugin_info($qtype->plugin_name());
+ $requiredtypes = $plugin->get_other_required_plugins();
$strtypes = array();
if (!empty($requiredtypes)) {
- foreach ($requiredtypes as $required) {
- $strtypes[] = $qtypes[$required]->local_name();
+ foreach ($requiredtypes as $required => $notused) {
+ $strtypes[] = $pluginmanager->plugin_name($required);
}
$row[] = implode(', ', $strtypes);
} else {
}
$uninstallurl = $plugin->get_uninstall_url();
+ $requriedby = $pluginman->other_plugins_that_require($plugin->component);
if (is_null($uninstallurl)) {
$uninstall = new html_table_cell('');
+ } else if ($requriedby) {
+ $uninstall = new html_table_cell(get_string('requiredby', 'core_plugin', implode(', ', $requriedby)));
+ $uninstall->attributes['class'] = 'requiredby';
} else {
$uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
$uninstall = new html_table_cell($uninstall);
+++ /dev/null
-<?php
-
-defined('MOODLE_INTERNAL') || die;
-
-$ADMIN->add('reports', new admin_externalpage('reportconfiglog', get_string('configlog', 'report_configlog'), "$CFG->wwwroot/$CFG->admin/report/configlog/index.php"));
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$capabilities = array(
-
- 'report/courseoverview:view' => array(
- 'riskbitmask' => RISK_PERSONAL,
- 'captype' => 'read',
- 'contextlevel' => CONTEXT_SYSTEM,
- 'archetypes' => array(
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- ),
-
- 'clonepermissionsfrom' => 'moodle/site:viewreports',
- )
-);
+++ /dev/null
-<?php
-
- require_once('../../../config.php');
- require_once($CFG->dirroot.'/lib/statslib.php');
- require_once($CFG->libdir.'/adminlib.php');
-
- $report = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT);
- $time = optional_param('time', 0, PARAM_INT);
- $numcourses = optional_param('numcourses', 20, PARAM_INT);
-
- if (empty($CFG->enablestats)) {
- if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
- redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
- } else {
- print_error('statsdisable');
- }
- }
-
- admin_externalpage_setup('reportcourseoverview');
- echo $OUTPUT->header();
-
- $course = get_site();
- stats_check_uptodate($course->id);
-
- $strreports = get_string('reports');
- $strcourseoverview = get_string('courseoverview');
-
- $reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED);
-
- $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
- $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
- $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');
-
- if (empty($earliestday)) $earliestday = time();
- if (empty($earliestweek)) $earliestweek = time();
- if (empty($earliestmonth)) $earliestmonth = time();
-
- $now = stats_get_base_daily();
- $lastweekend = stats_get_base_weekly();
- $lastmonthend = stats_get_base_monthly();
-
- $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
-
- if (empty($timeoptions)) {
- print_error('nostatstodisplay', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id);
- }
-
- echo '<form action="index.php" method="post">'."\n";
- echo '<div>';
-
- $table = new html_table();
- $table->width = '*';
- $table->align = array('left','left','left','left','left','left');
-
- $reporttypemenu = html_writer::select($reportoptions,'report',$report, false);
- $timeoptionsmenu = html_writer::select($timeoptions,'time',$time, false);
-
- $table->data[] = array(get_string('statsreporttype'),$reporttypemenu,
- get_string('statstimeperiod'),$timeoptionsmenu,
- '<input type="text" name="numcourses" size="3" maxlength="2" value="'.$numcourses.'" />',
- '<input type="submit" value="'.get_string('view').'" />') ;
-
- echo html_writer::table($table);
- echo '</div>';
- echo '</form>';
-
- echo $OUTPUT->heading($reportoptions[$report]);
-
-
- if (!empty($report) && !empty($time)) {
- $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
- if (!empty($param->sql)) {
- $sql = $param->sql;
- } else {
- $sql = "SELECT courseid,".$param->fields."
- FROM {".'stats_'.$param->table."}
- WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
- GROUP BY courseid
- $param->extras
- ORDER BY $param->orderby";
- }
-
- $courses = $DB->get_records_sql($sql, $param->params, 0, $numcourses);
-
- if (empty($courses)) {
- echo $OUTPUT->notification(get_string('statsnodata'));
- echo '</td></tr></table>';
-
- } else {
- if (empty($CFG->gdversion)) {
- echo '<div class="graph">(' . get_string("gdneed") .')</div>';
- } else {
- echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot.'/'.$CFG->admin.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
- }
-
- $table = new html_table();
- $table->align = array('left','center','center','center');
- $table->head = array(get_string('course'),$param->line1);
- if (!empty($param->line2)) {
- $table->head[] = $param->line2;
- }
- if (!empty($param->line3)) {
- $table->head[] = $param->line3;
- }
-
- foreach ($courses as $c) {
- $a = array();
- $a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid)).'</a>';
-
- $a[] = $c->line1;
- if (isset($c->line2)) {
- $a[] = $c->line2;
- }
- if (isset($c->line3)) {
- $a[] = round($c->line3,2);
- }
- $table->data[] = $a;
- }
- echo html_writer::table($table);
- }
- }
- echo $OUTPUT->footer();
+++ /dev/null
-<?php
-
- require_once('../../../config.php');
- require_once($CFG->dirroot.'/lib/statslib.php');
- require_once($CFG->dirroot.'/lib/graphlib.php');
-
- $report = required_param('report', PARAM_INT);
- $time = required_param('time', PARAM_INT);
- $numcourses = required_param('numcourses', PARAM_INT);
-
- require_login();
-
- require_capability('report/courseoverview:view', get_context_instance(CONTEXT_SYSTEM));
-
- stats_check_uptodate();
-
- $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
-
- if (!empty($param->sql)) {
- $sql = $param->sql;
- } else {
- $sql = "SELECT courseid, $param->fields
- FROM {".'stats_'.$param->table."}
- WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
- GROUP BY courseid
- $param->extras
- ORDER BY $param->orderby";
- }
-
- $courses = $DB->get_records_sql($sql, $param->params, 0, $numcourses);
-
- if (empty($courses)) {
- $PAGE->set_url('/admin/report/courseoverview/index.php');
- print_error('statsnodata', 'error', $PAGE->url->out());
- }
-
-
- $graph = new graph(750,400);
-
- $graph->parameter['legend'] = 'outside-right';
- $graph->parameter['legend_size'] = 10;
- $graph->parameter['x_axis_angle'] = 90;
- $graph->parameter['title'] = false; // moodle will do a nicer job.
- $graph->y_tick_labels = null;
- $graph->offset_relation = null;
- if ($report != STATS_REPORT_ACTIVE_COURSES) {
- $graph->parameter['y_decimal_left'] = 2;
- }
-
- foreach ($courses as $c) {
- $graph->x_data[] = $DB->get_field('course', 'shortname', array('id'=>$c->courseid));
- $graph->y_data['bar1'][] = $c->{$param->graphline};
- }
- $graph->y_order = array('bar1');
- $graph->y_format['bar1'] = array('colour' => 'blue','bar' => 'fill','legend' => $param->{$param->graphline});
-
- $graph->draw_stack();
+++ /dev/null
-<?php
-
-defined('MOODLE_INTERNAL') || die;
-
-$ADMIN->add('reports', new admin_externalpage('reportcourseoverview', get_string('pluginname', 'report_courseoverview'), "$CFG->wwwroot/$CFG->admin/report/courseoverview/index.php",'report/courseoverview:view'));
+++ /dev/null
-<?PHP
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
+++ /dev/null
-<?php
-
-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'));
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$capabilities = array(
-
- 'report/questioninstances:view' => array(
- 'captype' => 'read',
- 'contextlevel' => CONTEXT_SYSTEM,
- 'archetypes' => array(
- 'manager' => CAP_ALLOW
- ),
-
- 'clonepermissionsfrom' => 'moodle/site:config',
- )
-);
+++ /dev/null
-<?php
-
-defined('MOODLE_INTERNAL') || die;
-
-$ADMIN->add('reports', new admin_externalpage('reportquestioninstances', get_string('pluginname', 'report_questioninstances'), "$CFG->wwwroot/$CFG->admin/report/questioninstances/index.php", 'report/questioninstances:view'));
+++ /dev/null
-<?PHP
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$capabilities = array(
-
- 'report/security:view' => array(
- 'riskbitmask' => RISK_CONFIG,
- 'captype' => 'read',
- 'contextlevel' => CONTEXT_SYSTEM,
- 'archetypes' => array(
- 'manager' => CAP_ALLOW
- ),
- )
-);
+++ /dev/null
-<?php
-
-defined('MOODLE_INTERNAL') || die;
-
-$ADMIN->add('reports', new admin_externalpage('reportsecurity', get_string('pluginname', 'report_security'), "$CFG->wwwroot/$CFG->admin/report/security/index.php",'report/security:view'));
+++ /dev/null
-<?PHP
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
+++ /dev/null
-<?php
-
-defined('MOODLE_INTERNAL') || die;
-
-// just a link to course report
-$ADMIN->add('reports', new admin_externalpage('reportstats', get_string('stats', 'admin'), "$CFG->wwwroot/course/report/stats/index.php", 'coursereport/stats:view'));
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Provides an overview of installed reports
+ *
+ * Displays the list of found reports, their version (if found) and
+ * a link to delete the report.
+ *
+ * The code is based on admin/localplugins.php by David Mudrak.
+ *
+ * @package admin
+ * @copyright 2011 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->libdir.'/tablelib.php');
+
+admin_externalpage_setup('managereports');
+
+$delete = optional_param('delete', '', PARAM_PLUGIN);
+$confirm = optional_param('confirm', '', PARAM_BOOL);
+
+/// If data submitted, then process and store.
+
+if (!empty($delete) and confirm_sesskey()) {
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('reports'));
+
+ if (!$confirm) {
+ if (get_string_manager()->string_exists('pluginname', 'report_' . $delete)) {
+ $strpluginname = get_string('pluginname', 'report_' . $delete);
+ } else {
+ $strpluginname = $delete;
+ }
+ echo $OUTPUT->confirm(get_string('reportsdeleteconfirm', 'admin', $strpluginname),
+ new moodle_url($PAGE->url, array('delete' => $delete, 'confirm' => 1)),
+ $PAGE->url);
+ echo $OUTPUT->footer();
+ die();
+
+ } else {
+ uninstall_plugin('report', $delete);
+ $a = new stdclass();
+ $a->name = $delete;
+ $pluginlocation = get_plugin_types();
+ $a->directory = $pluginlocation['report'] . '/' . $delete;
+ echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess');
+ echo $OUTPUT->continue_button($PAGE->url);
+ echo $OUTPUT->footer();
+ die();
+ }
+}
+
+echo $OUTPUT->header();
+echo $OUTPUT->heading(get_string('reports'));
+
+/// Print the table of all installed report plugins
+
+$table = new flexible_table('reportplugins_administration_table');
+$table->define_columns(array('name', 'version', 'delete'));
+$table->define_headers(array(get_string('plugin'), get_string('version'), get_string('delete')));
+$table->define_baseurl($PAGE->url);
+$table->set_attribute('id', 'reportplugins');
+$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
+$table->setup();
+
+$plugins = array();
+foreach (get_plugin_list('report') as $plugin => $plugindir) {
+ if (get_string_manager()->string_exists('pluginname', 'report_' . $plugin)) {
+ $strpluginname = get_string('pluginname', 'report_' . $plugin);
+ } else {
+ $strpluginname = $plugin;
+ }
+ $plugins[$plugin] = $strpluginname;
+}
+collatorlib::asort($plugins);
+
+$like = $DB->sql_like('plugin', '?', true, true, false, '|');
+$params = array('report|_%');
+$installed = $DB->get_records_select('config_plugins', "$like AND name = 'version'", $params);
+$versions = array();
+foreach ($installed as $config) {
+ $name = preg_replace('/^report_/', '', $config->plugin);
+ $versions[$name] = $config->value;
+ if (!isset($plugins[$name])) {
+ $plugins[$name] = $name;
+ }
+}
+
+foreach ($plugins as $plugin => $name) {
+ $delete = new moodle_url($PAGE->url, array('delete' => $plugin, 'sesskey' => sesskey()));
+ $delete = html_writer::link($delete, get_string('delete'));
+
+ if (!isset($versions[$plugin])) {
+ if (file_exists("$CFG->dirroot/report/$plugin/version.php")) {
+ // not installed yet
+ $version = '?';
+ } else {
+ // no version info available
+ $version = '-';
+ }
+ } else {
+ $version = $versions[$plugin];
+ if (file_exists("$CFG->dirroot/report/$plugin")) {
+ $version = $versions[$plugin];
+ } else {
+ // somebody removed plugin without uninstall
+ $name = '<span class="notifyproblem">'.$name.' ('.get_string('missingfromdisk').')</span>';
+ $version = $versions[$plugin];
+ }
+ }
+
+ $table->add_data(array($name, $version, $delete));
+}
+
+$table->print_html();
+
+echo $OUTPUT->footer();
$ADMIN->add('coursereports', $page);
}
}
+ unset($pages);
}
// Now add reports
-foreach (get_plugin_list('report') as $plugin => $plugindir) {
+$pages = array();
+foreach (get_plugin_list('report') as $report => $plugindir) {
$settings_path = "$plugindir/settings.php";
if (file_exists($settings_path)) {
+ $settings = new admin_settingpage('report' . $report,
+ get_string('pluginname', 'report_' . $report), 'moodle/site:config');
include($settings_path);
- continue;
- }
-
- $index_path = "$plugindir/index.php";
- if (!file_exists($index_path)) {
- continue;
+ if ($settings) {
+ $pages[] = $settings;
+ }
}
- // old style 3rd party plugin without settings.php
- $www_path = "$CFG->wwwroot/$CFG->admin/report/$plugin/index.php";
- $reportname = get_string($plugin, 'report_' . $plugin);
- $ADMIN->add('reports', new admin_externalpage('report'.$plugin, $reportname, $www_path, 'moodle/site:viewreports'));
+}
+$ADMIN->add('modules', new admin_category('reportplugins', get_string('reports')));
+$ADMIN->add('reportplugins', new admin_externalpage('managereports', get_string('reportsmanage', 'admin'),
+ $CFG->wwwroot . '/' . $CFG->admin . '/reports.php'));
+foreach ($pages as $page) {
+ $ADMIN->add('reportplugins', $page);
}
// Now add various admin tools
global $CFG, $USER, $DB;
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
+ if (session_is_loggedinas()) {
+ print_error('notpermittedtojumpas', 'mnet');
+ }
+
// check remote login permissions
if (! has_capability('moodle/site:mnetlogintoremote', get_system_context())
or is_mnet_remote_user($USER)
This files describes API changes in /auth/* - plugins,
information provided here is intended especially for developers.
+
=== 2.2 ===
required changes in code:
* @param int $oldquestiontextformat
* @return array
*/
- protected function get_default_numerical_options($oldquestiontextformat) {
+ protected function get_default_numerical_options($oldquestiontextformat, $units) {
global $CFG;
// replay the upgrade step 2009100100 - new table
$options['instructionsformat'] = $oldquestiontextformat;
}
+ // Set a good default, depending on whether there are any units defined.
+ if (empty($units)) {
+ $options['showunits'] = 3;
+ }
+
return $options;
}
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php');
+require_once($CFG->dirroot . '/backup/moodle2/backup_report_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_subplugin.class.php');
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Base class for report backup plugins.
+ *
+ * NOTE: When you back up a course, it potentially may run backup for all
+ * reports. In order to control whether a particular report gets
+ * backed up, a report should make use of the second and third
+ * parameters in get_plugin_element().
+ *
+ * @package moodlecore
+ * @subpackage backup-moodle2
+ * @copyright 2011 Petr Skoda
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class backup_report_plugin extends backup_plugin {
+ // Use default parent behaviour
+}
// save course data (in case of user theme, legacy theme, etc)
$this->add_plugin_structure('theme', $course, true);
+ // attach general report plugin structure to $course element; multiple
+ // reports can save course data if required
+ $this->add_plugin_structure('report', $course, true);
+
// attach course report plugin structure to $course element; multiple
// course reports can save course data if required
$this->add_plugin_structure('coursereport', $course, true);
//grade_categories
$grade_categories = new backup_nested_element('grade_categories');
$grade_category = new backup_nested_element('grade_category', array('id'), array(
- //'courseid',
+ //'courseid',
'parent', 'depth', 'path', 'fullname', 'aggregation', 'keephigh',
'dropload', 'aggregateonlygraded', 'aggregateoutcomes', 'aggregatesubcats',
'timecreated', 'timemodified', 'hidden'));
require_once($CFG->dirroot . '/backup/moodle2/restore_qtype_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_format_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_theme_plugin.class.php');
+require_once($CFG->dirroot . '/backup/moodle2/restore_report_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_coursereport_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_plagiarism_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php');
+require_once($CFG->dirroot . '/backup/moodle2/backup_report_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php');
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Restore for plugin report.
+ *
+ * @package moodlecore
+ * @subpackage backup-moodle2
+ * @copyright 2011 Petr Skoda
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class restore_report_plugin extends restore_plugin {
+ // Use default parent behaviour
+}
// Apply for 'theme' plugins optional paths at course level
$this->add_plugin_structure('theme', $course);
+ // Apply for 'report' plugins optional paths at course level
+ $this->add_plugin_structure('report', $course);
+
// Apply for 'course report' plugins optional paths at course level
$this->add_plugin_structure('coursereport', $course);
$outcome = $restore->process();
if (!$restore->is_independent()) {
if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
- $restore->execute();
+ try {
+ $restore->execute();
+ } catch(Exception $e) {
+ $restore->cleanup();
+ throw new moodle_exception((string)$e);
+ }
} else {
$restore->save_controller();
}
* @return string
*/
public function course_selector(moodle_url $nextstageurl, $wholecourse = true, restore_category_search $categories = null, restore_course_search $courses=null, $currentcourse = null) {
- global $CFG;
+ global $CFG, $PAGE;
require_once($CFG->dirroot.'/course/lib.php');
$nextstageurl->param('sesskey', sesskey());
$html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
$html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
$html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories));
- $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
+ $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'), 'class'=>'newcoursecontinue')));
$html .= html_writer::end_tag('div');
$html .= html_writer::end_tag('form');
+ $config = new stdClass;
+ $config->title = get_string('confirmnewcoursecontinue', 'backup');
+ $config->question = get_string('confirmnewcoursecontinuequestion', 'backup');
+ $config->yesLabel = get_string('continue');
+ $config->noLabel = get_string('cancel');
+ $PAGE->requires->yui_module('moodle-backup-confirmcancel', 'M.core_backup.watch_newcoursecontinue_buttons', array($config));
}
if ($wholecourse && !empty($currentcourse)) {
$this->stage = new restore_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results());
return true;
}
+
+ /**
+ * Delete course which is created by restore process
+ */
+ public function cleanup() {
+ $courseid = $this->controller->get_courseid();
+ if ($this->is_temporary_course_created($courseid)) {
+ delete_course($courseid, false);
+ }
+ }
+
+ /**
+ * Checks if the course is not restored fully and current controller has created it.
+ * @param int $courseid id of the course which needs to be checked
+ * @return bool
+ */
+ protected function is_temporary_course_created($courseid) {
+ global $DB;
+ //Check if current controller instance has created new course.
+ if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) {
+ $results = $DB->record_exists_sql("SELECT bc.itemid
+ FROM {backup_controllers} bc, {course} c
+ WHERE bc.operation = 'restore'
+ AND bc.type = 'course'
+ AND bc.itemid = c.id
+ AND bc.itemid = ?",
+ array($courseid)
+ );
+ return $results;
+ }
+ return false;
+ }
+
/**
* Returns true if enforce_dependencies changed any settings
* @return bool
/**
* Cancels the current restore and redirects the user back to the relevant place
*/
- public function cancel_restore() {
- global $PAGE;
- // Determine the approriate URL to redirect the user to
- if ($PAGE->context->contextlevel == CONTEXT_MODULE && $PAGE->cm !== null) {
- $relevanturl = new moodle_url('/mod/'.$PAGE->cm->modname.'/view.php', array('id'=>$PAGE->cm->id));
- } else {
- $relevanturl = new moodle_url('/course/view.php', array('id'=>$PAGE->course->id));
+ public function cancel_process() {
+ //Delete temporary restore course if exists.
+ if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) {
+ $this->cleanup();
}
- redirect($relevanturl);
+ parent::cancel_process();
}
/**
* Gets an array of progress bar items that can be displayed through the restore renderer.
$form = $this->initialise_stage_form();
if ($form->is_cancelled()) {
- $this->ui->cancel_restore();
+ $this->ui->cancel_process();
}
$data = $form->get_data();
});
}
+M.core_backup.watch_newcoursecontinue_buttons = function(config) {
+ Y.all('.newcoursecontinue').each(function(){
+ this._confirmationListener = this._confirmationListener || this.on('click', function(e){
+ // Prevent the default event (sumbit) from firing
+ e.preventDefault();
+ // Create the confirm box
+ var confirm = new M.core.confirm(config);
+ // If the user clicks yes
+ confirm.on('complete-yes', function(e){
+ // Detach the listener for the confirm box so it doesn't fire again.
+ this._confirmationListener.detach();
+ // Simulate the original cancel button click
+ this.simulate('click');
+ }, this);
+ // Show the confirm box
+ confirm.show();
+ }, this);
+ });
+}
+
}, '@VERSION@', {'requires':['base','node','node-event-simulate','moodle-enrol-notification']});
\ No newline at end of file
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
/**
* Block for displayed logged in user's course completion status
*
- * @package moodlecore
- * @copyright 2009 Catalyst IT Ltd
- * @author Aaron Barnes <aaronb@catalyst.net.nz>
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package block
+ * @subpackage completion
+ * @copyright 2009 Catalyst IT Ltd
+ * @author Aaron Barnes <aaronb@catalyst.net.nz>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+
+defined('MOODLE_INTERNAL') || die();
+
+
require_once($CFG->libdir.'/completionlib.php');
/**
// Check this user is enroled
if (!$info->is_tracked_user($USER->id)) {
// If not enrolled, but are can view the report:
- if (has_capability('coursereport/completion:view', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
- $this->content->text = '<a href="'.$CFG->wwwroot.'/course/report/completion/index.php?course='.$COURSE->id.
+ if (has_capability('report/completion:view', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
+ $this->content->text = '<a href="'.$CFG->wwwroot.'/report/completion/index.php?course='.$COURSE->id.
'">'.get_string('viewcoursereport', 'completion').'</a>';
return $this->content;
}
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
/**
* Block for displayed logged in user's course completion status
*
- * @package moodlecore
- * @copyright 2009 Catalyst IT Ltd
- * @author Aaron Barnes <aaronb@catalyst.net.nz>
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package block
+ * @subpackage completion
+ * @copyright 2009 Catalyst IT Ltd
+ * @author Aaron Barnes <aaronb@catalyst.net.nz>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+
require_once('../../config.php');
require_once($CFG->libdir.'/completionlib.php');
$can_view = true;
} else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
$can_view = true;
-} else if (has_capability('coursereport/completion:view', $coursecontext)) {
+} else if (has_capability('report/completion:view', $coursecontext)) {
$can_view = true;
-} else if (has_capability('coursereport/completion:view', $personalcontext)) {
+} else if (has_capability('report/completion:view', $personalcontext)) {
$can_view = true;
}
echo '<th class="c2 header" scope="col">'.get_string('requirement', 'block_completionstatus').'</th>';
echo '<th class="c3 header" scope="col">'.get_string('status').'</th>';
echo '<th class="c4 header" scope="col">'.get_string('complete').'</th>';
-echo '<th class="c5 header" scope="col">'.get_string('completiondate', 'coursereport_completion').'</th>';
+echo '<th class="c5 header" scope="col">'.get_string('completiondate', 'report_completion').'</th>';
echo '</tr>';
// Save row data
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-$plugin->version = 2009072800;
+/**
+ * Version info
+ *
+ * @package block
+ * @subpackage completion
+ * @copyright 2009 Catalyst IT Ltd
+ * @author Aaron Barnes <aaronb@catalyst.net.nz>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version = 2011110300;
+$plugin->component = 'block_completionstatus';
+$plugin->dependencies = array('report_completion' => 2011110200);
\ No newline at end of file
return true;
}
+
+ /**
+ * The block should only be dockable when the title of the block is not empty
+ * and when parent allows docking.
+ *
+ * @return bool
+ */
+ public function instance_can_be_docked() {
+ return (!empty($this->config->title) && parent::instance_can_be_docked());
+ }
}
return false;
}
+ if (session_is_loggedinas()) {
+ $this->content = new stdClass();
+ $this->content->footer = html_writer::tag('span',
+ get_string('notpermittedtojumpas', 'mnet'));
+ return $this->content;
+ }
+
// according to start_jump_session,
// remote users can't on-jump
// so don't show this block to them
This files describes API changes in /blocks/* - activity modules,
information provided here is intended especially for developers.
+
=== 2.0 ===
required changes in code:
move all images into new blocks/xxx/pix/ directory and use new outputlib api
old global $THEME is fully replaced by $OUTPUT
* remove '_utf8' from language pack names, use new {$a} syntax in language packs
-* use 'pluginname' lang pack identifier instead of 'blockname'
+* use 'pluginname' lang pack identifier instead of 'blockname'
* move cron and version number into standard version.php
* removed support for old config_global.html, use settings.php
-optional - no changes needed in older code:
-*
-
-
-TODO: add links to docs
\ No newline at end of file
$day = optional_param('cal_d', 0, PARAM_INT);
$mon = optional_param('cal_m', 0, PARAM_INT);
$yr = optional_param('cal_y', 0, PARAM_INT);
+$generateurl = optional_param('generateurl', 0, PARAM_BOOL);
if ($courseid != SITEID && !empty($courseid)) {
$course = $DB->get_record('course', array('id' => $courseid));
$calendar->prepare_for_view($course, $courses);
$pagetitle = get_string('export', 'calendar');
+$now = usergetdate(time());
// Print title and header
if ($issite) {
if (isset($CFG->calendar_weekend)) {
$weekend = intval($CFG->calendar_weekend);
}
- $username = $USER->username;
- $authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
+
+ $authtoken = sha1($USER->id . $USER->password . $CFG->calendar_exportsalt);
// Let's populate some vars to let "common tasks" be somewhat smart...
// If today it's weekend, give the "next week" option
$allownextweek = $weekend & (1 << $now['wday']);
$allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < 7;
// If today it's weekend but tomorrow it isn't, do NOT give the "this week" option
$allowthisweek = !(($weekend & (1 << $now['wday'])) && !($weekend & (1 << (($now['wday'] + 1) % 7))));
- echo $renderer->basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken);
+ echo $renderer->basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $USER->id, $authtoken);
break;
}
+if (!empty($generateurl)) {
+ $params['userid'] = optional_param('userid', 0, PARAM_INT);
+ $params['authtoken'] = optional_param('authtoken', '', PARAM_ALPHANUM);
+ $params['preset_what'] = optional_param('preset_what', 'all', PARAM_ALPHA);
+ $params['preset_time'] = optional_param('preset_time', 'weeknow', PARAM_ALPHA);
+
+ $link = new moodle_url('/calendar/export_execute.php', $params);
+ print html_writer::tag('div', get_string('calendarurl', 'calendar', $link->out()), array('class' => 'generalbox calendarurl'));
+}
+
echo $renderer->complete_layout();
echo $OUTPUT->footer();
require_once($CFG->dirroot.'/calendar/lib.php');
require_once($CFG->libdir.'/bennu/bennu.inc.php');
-$username = required_param('username', PARAM_TEXT);
+$userid = optional_param('userid', 0, PARAM_INT);
+$username = optional_param('username', '', PARAM_TEXT);
$authtoken = required_param('authtoken', PARAM_ALPHANUM);
+$generateurl = optional_param('generateurl', '', PARAM_TEXT);
if (empty($CFG->enablecalendarexport)) {
die('no export');
}
//Fetch user information
-if (!$user = $DB->get_record('user', array('username' => $username), 'id,password')) {
- //No such user
+$checkuserid = !empty($userid) && $user = $DB->get_record('user', array('id' => $userid), 'id,password');
+//allowing for fallback check of old url - MDL-27542
+$checkusername = !empty($username) && $user = $DB->get_record('user', array('username' => $username), 'id,password');
+if (!$checkuserid && !$checkusername) {
+ //No such user
die('Invalid authentication');
}
//Check authentication token
-if ($authtoken != sha1($username . $user->password . $CFG->calendar_exportsalt)) {
+$authuserid = !empty($userid) && $authtoken == sha1($userid . $user->password . $CFG->calendar_exportsalt);
+//allowing for fallback check of old url - MDL-27542
+$authusername = !empty($username) && $authtoken == sha1($username . $user->password . $CFG->calendar_exportsalt);
+if (!$authuserid && !$authusername) {
die('Invalid authentication');
}
$allowed_what = array('all', 'courses');
$allowed_time = array('weeknow', 'weeknext', 'monthnow', 'monthnext', 'recentupcoming');
+if (!empty($generateurl)) {
+ $authtoken = sha1($user->id . $user->password . $CFG->calendar_exportsalt);
+ $params = array();
+ $params['preset_what'] = $what;
+ $params['preset_time'] = $time;
+ $params['userid'] = $userid;
+ $params['authtoken'] = $authtoken;
+ $params['generateurl'] = true;
+
+ $link = new moodle_url('/calendar/export.php', $params);
+ redirect($link->out());
+ die;
+}
+
if(!empty($what) && !empty($time)) {
if(in_array($what, $allowed_what) && in_array($time, $allowed_time)) {
$courses = enrol_get_users_courses($user->id, true, 'id, visible, shortname');
$group = $DB->get_record('groups', array('id'=>$data->groupid));
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
} else if (isset($data->userid) && $data->userid > 0 && $data->userid == $USER->id) {
- $context = get_context_instance(CONTEXT_USER);
+ $context = get_context_instance(CONTEXT_USER, $data->userid);
} else if (isset($data->userid) && $data->userid > 0 && $data->userid != $USER->id &&
isset($data->instance) && $data->instance > 0) {
$cm = get_coursemodule_from_instance($data->modulename, $data->instance, 0, false, MUST_EXIST);
* @param bool $allowthisweek
* @param bool $allownextweek
* @param bool $allownextmonth
- * @param string $username
+ * @param int $userid
* @param string $authtoken
* @return string
*/
- public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken) {
+ public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $userid, $authtoken) {
$output = html_writer::tag('div', get_string('export', 'calendar'), array('class'=>'header'));
$output .= html_writer::start_tag('fieldset');
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>''));
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>''));
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>''));
- $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'username', 'value'=>$username));
+ $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'userid', 'value'=>$userid));
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken));
- $output .= html_writer::empty_tag('input', array('type'=>'button', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar')));
+ $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name' => 'generateurl', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar')));
$output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('exportbutton', 'calendar')));
$output .= html_writer::end_tag('div');
$output .= html_writer::tag('div', '', array('id'=>'url', 'style'=>'overflow:scroll;width:650px;'));
$output .= html_writer::end_tag('div');
- $this->page->requires->yui_module('moodle-calendar-eventmanager', 'M.core_calendar.init_basic_export', array($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken));
-
return $output;
}
if (!empty($CFG->enablecalendarexport)) {
echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
if (isloggedin()) {
- $authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
- $link = new moodle_url('/calendar/export_execute.php', array('preset_what'=>'all', 'preset_time'=>'recentupcoming', 'username'=>$USER->username, 'authtoken'=>$authtoken));
+ $authtoken = sha1($USER->id . $USER->password . $CFG->calendar_exportsalt);
+ $link = new moodle_url('/calendar/export_execute.php', array('preset_what'=>'all', 'preset_time'=>'recentupcoming', 'userid' => $USER->id, 'authtoken'=>$authtoken));
$icon = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/ical'), 'height'=>'14', 'width'=>'36', 'alt'=>get_string('ical', 'calendar'), 'title'=>get_string('quickdownloadcalendar', 'calendar')));
echo html_writer::tag('a', $icon, array('href'=>$link));
}
var EVENTMANAGER = {
add_event : function(config) {
new EVENT(config);
- },
- init_basic_export : function(allowthisweek, allownextweek, allownextmonth, username, authtoken) {
- var params = {
- preset_what : (Y.one('#pw_course').get('checked'))?'courses':'all',
- preset_time : 'recentupcoming',
- username : username,
- authtoken : authtoken
-
- }
- if (allowthisweek && Y.one('#pt_wknow').get('checked')) {
- params.presettime = 'weeknow';
- } else if (allownextweek && Y.one('#pt_wknext').get('checked')) {
- params.presettime = 'weeknext';
- } else if (allownextmonth && Y.one('#pt_monnext').get('checked')) {
- params.presettime = 'monthnext';
- } else if (Y.one('#pt_monnow').get('checked')) {
- params.presettime = 'monthnow';
- }
- Y.one('#url').setContent(M.cfg.wwwroot+'/calendar/export_execute.php?'+build_querystring(params));
- Y.one('#urlbox').setStyle('display', 'block');
}
}
require_once($CFG->libdir.'/completionlib.php');
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
}
-function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
- global $CFG, $USER;
- 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)) ||
- ($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="" />';
- }
- }
-}
-
-
function print_overview($courses, array $remote_courses=array()) {
global $CFG, $USER, $DB, $OUTPUT;
if (!empty($info->extraclasses)) {
$mod[$seq]->extraclasses = $info->extraclasses;
}
+ if (!empty($info->iconurl)) {
+ $mod[$seq]->iconurl = $info->iconurl;
+ }
if (!empty($info->onclick)) {
$mod[$seq]->onclick = $info->onclick;
}
// Minimise the database size by unsetting default options when they are
// 'empty'. This list corresponds to code in the cm_info constructor.
foreach (array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly',
- 'indent', 'completion', 'extra', 'extraclasses', 'onclick', 'content',
+ 'indent', 'completion', 'extra', 'extraclasses', 'iconurl', 'onclick', 'content',
'icon', 'iconcomponent', 'customdata', 'showavailability', 'availablefrom',
'availableuntil', 'conditionscompletion', 'conditionsgrade',
'completionview', 'completionexpected', 'score', 'showdescription')
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$capabilities = array(
-
- 'coursereport/completion:view' => array(
- 'riskbitmask' => RISK_PERSONAL,
- 'captype' => 'read',
- 'contextlevel' => CONTEXT_COURSE,
- 'archetypes' => array(
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- ),
-
- 'clonepermissionsfrom' => 'moodle/site:viewreports',
- )
-);
+++ /dev/null
-<?php
-
-$string['completion:view'] = 'View course completion report';
-$string['completiondate']='Completion date';
-$string['pluginpagetype'] = 'Course completion report';
-$string['pluginname']='Course completion';
+++ /dev/null
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * This file contains functions used by the progress report
- *
- * @since 2.0
- * @package course-report
- * @copyright 2009 Sam Hemelryk
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-require_once($CFG->libdir.'/completionlib.php');
-
-/**
- * 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 completion_report_extend_navigation($navigation, $course, $context) {
- global $CFG, $OUTPUT;
-
- if (has_capability('coursereport/completion:view', $context)) {
- $completion = new completion_info($course);
- if ($completion->is_enabled() && $completion->has_criteria()) {
- $url = new moodle_url('/course/report/completion/index.php', array('course'=>$course->id));
- $navigation->add(get_string('pluginname','coursereport_completion'), $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 completion_page_type_list($pagetype, $parentcontext, $currentcontext) {
- $array = array(
- '*' => get_string('page-x', 'pagetype'),
- 'course-report-*' => get_string('page-course-report-x', 'pagetype'),
- 'course-report-completion-index' => get_string('pluginpagetype', 'coursereport_completion')
- );
- return $array;
-}
+++ /dev/null
-<?php
-
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
- }
-
- require_once($CFG->libdir.'/completionlib.php');
-
- if (has_capability('coursereport/completion:view', $context)) {
- $completion = new completion_info($course);
- if ($completion->is_enabled() && $completion->has_criteria()) {
- echo '<p>';
- echo '<a href="'.$CFG->wwwroot.'/course/report/completion/index.php?course='.$course->id.'">'.get_string('coursecompletion').'</a>';
- echo '</p>';
- }
- }
-
+++ /dev/null
-<?PHP
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$capabilities = array(
-
- 'coursereport/log:view' => 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',
- )
-);
-
-
+++ /dev/null
-<?php
- // Displays different views of the logs.
-
- require_once('../../../config.php');
- require_once('../../lib.php');
- require_once('lib.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('/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;
-
+++ /dev/null
-<?php
- // Display link to live logs in separate window
-
- require_once('../../../config.php');
- require_once('../../lib.php');
- require_once('lib.php');
- require_once($CFG->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();
-
-
+++ /dev/null
-<?php
- // Displays live view of recent logs
-
- require_once("../../../config.php");
- require_once("../../lib.php");
-
- $id = required_param('id', PARAM_INT);
- $page = optional_param('page', 0, PARAM_INT); // which page to show
-
- 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);
-
- 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;
-
-
+++ /dev/null
-<?php
-
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
- }
-
- require_once($CFG->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 '<p>';
- $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 '</p>';
- }
-
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
-
-
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$capabilities = array(
-
- 'coursereport/outline:view' => array(
- 'riskbitmask' => RISK_PERSONAL,
- 'captype' => 'read',
- 'contextlevel' => CONTEXT_COURSE,
- 'archetypes' => array(
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- ),
-
- 'clonepermissionsfrom' => 'moodle/site:viewreports',
- )
-);
-
-
+++ /dev/null
-<?php
-
-// Display user activity reports for a course (totals)
-
- require_once('../../../config.php');
- require_once($CFG->dirroot.'/course/lib.php');
-
- $id = required_param('id',PARAM_INT); // course id
-
- if (!$course = $DB->get_record('course', array('id'=>$id))) {
- print_error('invalidcourseid');
- }
-
- $PAGE->set_url('/course/report/outline/index.php', array('id'=>$id));
- $PAGE->set_pagelayout('report');
-
- require_login($course);
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- require_capability('coursereport/outline:view', $context);
-
- add_to_log($course->id, 'course', 'report outline', "report/outline/index.php?id=$course->id", $course->id);
-
- $showlastaccess = true;
- $hiddenfields = explode(',', $CFG->hiddenuserfields);
-
- if (array_search('lastaccess', $hiddenfields) and !has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
- $showlastaccess = false;
- }
-
- $stractivityreport = get_string('activityreport');
- $stractivity = get_string('activity');
- $strlast = get_string('lastaccess');
- $strreports = get_string('reports');
- $strviews = get_string('views');
- $strrelatedblogentries = get_string('relatedblogentries', 'blog');
-
- $PAGE->set_title($course->shortname .': '. $stractivityreport);
- $PAGE->set_heading($course->fullname);
- echo $OUTPUT->header();
- echo $OUTPUT->heading(format_string($course->fullname));
-
- if (!$logstart = $DB->get_field_sql("SELECT MIN(time) FROM {log}")) {
- print_error('logfilenotavailable');
- }
-
- echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($logstart)), 'loginfo');
-
- $outlinetable = new html_table();
- $outlinetable->attributes['class'] = 'generaltable boxaligncenter';
- $outlinetable->cellpadding = 5;
- $outlinetable->id = 'outlinetable';
- $outlinetable->head = array($stractivity, $strviews);
-
- if ($CFG->useblogassociations) {
- $outlinetable->head[] = $strrelatedblogentries;
- }
-
- if ($showlastaccess) {
- $outlinetable->head[] = $strlast;
- }
-
- $modinfo = get_fast_modinfo($course);
- $sections = get_all_sections($course->id);
-
- $sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime
- FROM {course_modules} cm
- JOIN {modules} m ON m.id = cm.module
- JOIN {log} l ON l.cmid = cm.id
- WHERE cm.course = ? AND l.action LIKE 'view%' AND m.visible = 1
- GROUP BY cm.id";
- $views = $DB->get_records_sql($sql, array($course->id));
-
- $prevsecctionnum = 0;
- foreach ($modinfo->sections as $sectionnum=>$section) {
- foreach ($section as $cmid) {
- $cm = $modinfo->cms[$cmid];
- if (!$cm->has_view()) {
- continue;
- }
- if (!$cm->uservisible) {
- continue;
- }
- if ($prevsecctionnum != $sectionnum) {
- $sectionrow = new html_table_row();
- $sectionrow->attributes['class'] = 'section';
- $sectioncell = new html_table_cell();
- $sectioncell->colspan = count($outlinetable->head);
-
- $sectiontitle = get_section_name($course, $sections[$sectionnum]);
-
- $sectioncell->text = $OUTPUT->heading($sectiontitle, 3);
- $sectionrow->cells[] = $sectioncell;
- $outlinetable->data[] = $sectionrow;
-
- $prevsecctionnum = $sectionnum;
- }
-
- $dimmed = $cm->visible ? '' : 'class="dimmed"';
- $modulename = get_string('modulename', $cm->modname);
-
- $reportrow = new html_table_row();
- $activitycell = new html_table_cell();
- $activitycell->attributes['class'] = 'activity';
-
- $activityicon = $OUTPUT->pix_icon('icon', $modulename, $cm->modname, array('class'=>'icon'));
-
- $attributes = array();
- if (!$cm->visible) {
- $attributes['class'] = 'dimmed';
- }
-
- $activitycell->text = $activityicon . html_writer::link("$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id", format_string($cm->name), $attributes);;
-
- $reportrow->cells[] = $activitycell;
-
- $numviewscell = new html_table_cell();
- $numviewscell->attributes['class'] = 'numviews';
-
- if (!empty($views[$cm->id]->numviews)) {
- $numviewscell->text = $views[$cm->id]->numviews;
- } else {
- $numviewscell->text = '-';
- }
-
- $reportrow->cells[] = $numviewscell;
-
- if ($CFG->useblogassociations) {
- require_once($CFG->dirroot.'/blog/lib.php');
- $blogcell = new html_table_cell();
- $blogcell->attributes['class'] = 'blog';
- if ($blogcount = blog_get_associated_count($course->id, $cm->id)) {
- $blogcell->text = html_writer::link('/blog/index.php?modid='.$cm->id, $blogcount);
- } else {
- $blogcell->text = '-';
- }
- $reportrow->cells[] = $blogcell;
- }
-
- if ($showlastaccess) {
- $lastaccesscell = new html_table_cell();
- $lastaccesscell->attributes['class'] = 'lastaccess';
-
- if (isset($views[$cm->id]->lasttime)) {
- $timeago = format_time(time() - $views[$cm->id]->lasttime);
- $lastaccesscell->text = userdate($views[$cm->id]->lasttime)." ($timeago)";
- }
- $reportrow->cells[] = $lastaccesscell;
- }
- $outlinetable->data[] = $reportrow;
- }
- }
- echo html_writer::table($outlinetable);
-
- echo $OUTPUT->footer();
-
-
-
+++ /dev/null
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * This file contains functions used by the outline report
- *
- * @since 2.0
- * @package course-report
- * @copyright 2009 Sam Hemelryk
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-/**
- * 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 outline_report_extend_navigation($navigation, $course, $context) {
- global $CFG, $OUTPUT;
- if (has_capability('coursereport/outline:view', $context)) {
- $url = new moodle_url('/course/report/outline/index.php', array('id'=>$course->id));
- $navigation->add(get_string( 'activityreport' ), $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 outline_page_type_list($pagetype, $parentcontext, $currentcontext) {
- $array = array(
- '*' => get_string('page-x', 'pagetype'),
- 'course-report-*' => get_string('page-course-report-x', 'pagetype'),
- 'course-report-outline-index' => get_string('pluginpagetype', 'coursereport_outline')
- );
- return $array;
-}
\ No newline at end of file
+++ /dev/null
-<?php
-
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
- }
-
- if (has_capability('coursereport/outline:view', $context)) {
- echo '<p>';
- $activityreport = get_string( 'activityreport' );
- echo "<a href=\"{$CFG->wwwroot}/course/report/outline/index.php?id={$course->id}\">";
- echo "$activityreport</a>\n";
- echo '</p>';
- }
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
-
-
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$capabilities = array(
-
- 'coursereport/participation:view' => array(
- 'riskbitmask' => RISK_PERSONAL,
- 'captype' => 'read',
- 'contextlevel' => CONTEXT_COURSE,
- 'archetypes' => array(
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- ),
-
- 'clonepermissionsfrom' => 'moodle/site:viewreports',
- )
-);
-
-
+++ /dev/null
-<?php
-
- require_once('../../../config.php');
- require_once($CFG->dirroot.'/lib/tablelib.php');
-
- define('DEFAULT_PAGE_SIZE', 20);
- define('SHOW_ALL_PAGE_SIZE', 5000);
-
- $id = required_param('id', PARAM_INT); // course id.
- $roleid = optional_param('roleid', 0, PARAM_INT); // which role to show
- $instanceid = optional_param('instanceid', 0, PARAM_INT); // instance we're looking at.
- $timefrom = optional_param('timefrom', 0, PARAM_INT); // how far back to look...
- $action = optional_param('action', '', PARAM_ALPHA);
- $page = optional_param('page', 0, PARAM_INT); // which page to show
- $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page
-
- $url = new moodle_url('/course/report/participation/index.php', array('id'=>$id));
- if ($roleid !== 0) $url->param('roleid');
- if ($instanceid !== 0) $url->param('instanceid');
- if ($timefrom !== 0) $url->param('timefrom');
- if ($action !== '') $url->param('action');
- if ($page !== 0) $url->param('page');
- if ($perpage !== DEFAULT_PAGE_SIZE) $url->param('perpage');
- $PAGE->set_url($url);
- $PAGE->set_pagelayout('admin');
-
- if ($action != 'view' and $action != 'post') {
- $action = ''; // default to all (don't restrict)
- }
-
- if (!$course = $DB->get_record('course', array('id'=>$id))) {
- print_error('invalidcourse');
- }
-
- if ($roleid != 0 and !$role = $DB->get_record('role', array('id'=>$roleid))) {
- print_error('invalidrole');
- }
-
- require_login($course);
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- require_capability('coursereport/participation:view', $context);
-
- add_to_log($course->id, "course", "report participation", "report/participation/index.php?id=$course->id", $course->id);
-
- $strparticipation = get_string('participationreport');
- $strviews = get_string('views');
- $strposts = get_string('posts');
- $strview = get_string('view');
- $strpost = get_string('post');
- $strallactions = get_string('allactions');
- $strreports = get_string('reports');
-
- $actionoptions = array('' => $strallactions,
- 'view' => $strview,
- 'post' => $strpost,);
- if (!array_key_exists($action, $actionoptions)) {
- $action = '';
- }
-
- $PAGE->set_title($course->shortname .': '. $strparticipation);
- $PAGE->set_heading($course->fullname);
- echo $OUTPUT->header();
-
- $modinfo = get_fast_modinfo($course);
-
- $modules = $DB->get_records_select('modules', "visible = 1", null, 'name ASC');
-
- $instanceoptions = array();
- foreach ($modules as $module) {
- if (empty($modinfo->instances[$module->name])) {
- continue;
- }
- $instances = array();
- foreach ($modinfo->instances[$module->name] as $cm) {
- // Skip modules such as label which do not actually have links;
- // this means there's nothing to participate in
- if (!$cm->has_view()) {
- continue;
- }
- $instances[$cm->id] = format_string($cm->name);
- }
- if (count($instances) == 0) {
- continue;
- }
- $instanceoptions[] = array(get_string('modulenameplural', $module->name)=>$instances);
- }
-
- $timeoptions = array();
- // get minimum log time for this course
- $minlog = $DB->get_field_sql('SELECT min(time) FROM {log} WHERE course = ?', array($course->id));
-
- $now = usergetmidnight(time());
-
- // days
- for ($i = 1; $i < 7; $i++) {
- if (strtotime('-'.$i.' days',$now) >= $minlog) {
- $timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i);
- }
- }
- // weeks
- for ($i = 1; $i < 10; $i++) {
- if (strtotime('-'.$i.' weeks',$now) >= $minlog) {
- $timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i);
- }
- }
- // months
- for ($i = 2; $i < 12; $i++) {
- if (strtotime('-'.$i.' months',$now) >= $minlog) {
- $timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i);
- }
- }
- // try a year
- if (strtotime('-1 year',$now) >= $minlog) {
- $timeoptions[strtotime('-1 year',$now)] = get_string('lastyear');
- }
-
- $roleoptions = array();
- // TODO: we need a new list of roles that are visible here
- if ($roles = get_roles_used_in_context($context)) {
- foreach ($roles as $r) {
- $roleoptions[$r->id] = $r->name;
- }
- }
- $guestrole = get_guest_role();
- if (empty($roleoptions[$guestrole->id])) {
- $roleoptions[$guestrole->id] = $guestrole->name;
- }
-
- $roleoptions = role_fix_names($roleoptions, $context);
-
- // print first controls.
- echo '<form class="participationselectform" action="index.php" method="get"><div>'."\n".
- '<input type="hidden" name="id" value="'.$course->id.'" />'."\n";
- echo '<label for="menuinstanceid">'.get_string('activitymodule').'</label>'."\n";
- echo html_writer::select($instanceoptions, 'instanceid', $instanceid);
- echo '<label for="menutimefrom">'.get_string('lookback').'</label>'."\n";
- echo html_writer::select($timeoptions,'timefrom',$timefrom);
- echo '<label for="menuroleid">'.get_string('showonly').'</label>'."\n";
- echo html_writer::select($roleoptions,'roleid',$roleid,false);
- echo '<label for="menuaction">'.get_string('showactions').'</label>'."\n";
- echo html_writer::select($actionoptions,'action',$action,false);
- echo '<input type="submit" value="'.get_string('go').'" />'."\n</div></form>\n";
-
- $baseurl = $CFG->wwwroot.'/course/report/participation/index.php?id='.$course->id.'&roleid='
- .$roleid.'&instanceid='.$instanceid.'&timefrom='.$timefrom.'&action='.$action.'&perpage='.$perpage;
-
- if (!empty($instanceid) && !empty($roleid)) {
- // from here assume we have at least the module we're using.
- $cm = $modinfo->cms[$instanceid];
- $modulename = get_string('modulename', $cm->modname);
-
- include_once($CFG->dirroot.'/mod/'.$cm->modname.'/lib.php');
-
- $viewfun = $cm->modname.'_get_view_actions';
- $postfun = $cm->modname.'_get_post_actions';
-
- if (!function_exists($viewfun) || !function_exists($postfun)) {
- print_error('modulemissingcode', 'error', $baseurl, $cm->modname);
- }
-
- $viewnames = $viewfun();
- $postnames = $postfun();
-
- $table = new flexible_table('course-participation-'.$course->id.'-'.$cm->id.'-'.$roleid);
- $table->course = $course;
-
- $table->define_columns(array('fullname','count','select'));
- $table->define_headers(array(get_string('user'),((!empty($action)) ? get_string($action) : get_string('allactions')),get_string('select')));
- $table->define_baseurl($baseurl);
-
- $table->set_attribute('cellpadding','5');
- $table->set_attribute('class', 'generaltable generalbox reporttable');
-
- $table->sortable(true,'lastname','ASC');
- $table->no_sorting('select');
-
- $table->set_control_variables(array(
- TABLE_VAR_SORT => 'ssort',
- TABLE_VAR_HIDE => 'shide',
- TABLE_VAR_SHOW => 'sshow',
- TABLE_VAR_IFIRST => 'sifirst',
- TABLE_VAR_ILAST => 'silast',
- TABLE_VAR_PAGE => 'spage'
- ));
- $table->setup();
-
- switch ($action) {
- case 'view':
- $actions = $viewnames;
- break;
- case 'post':
- $actions = $postnames;
- break;
- default:
- // some modules have stuff we want to hide, ie mail blocked etc so do actually need to limit here.
- $actions = array_merge($viewnames, $postnames);
- }
-
- list($actionsql, $params) = $DB->get_in_or_equal($actions, SQL_PARAMS_NAMED, 'action');
- $actionsql = "action $actionsql";
-
- $relatedcontexts = get_related_contexts_string($context);
-
- $sql = "SELECT ra.userid, u.firstname, u.lastname, u.idnumber, l.actioncount AS count
- FROM (SELECT * FROM {role_assignments} WHERE contextid $relatedcontexts AND roleid = :roleid ) ra
- JOIN {user} u ON u.id = ra.userid
- LEFT JOIN (
- SELECT userid, COUNT(action) AS actioncount FROM {log} WHERE cmid = :instanceid AND time > :timefrom AND $actionsql GROUP BY userid
- ) l ON (l.userid = ra.userid)";
- $params['roleid'] = $roleid;
- $params['instanceid'] = $instanceid;
- $params['timefrom'] = $timefrom;
-
- list($twhere, $tparams) = $table->get_sql_where();
- if ($twhere) {
- $sql .= ' WHERE '.$twhere; //initial bar
- $params = array_merge($params, $tparams);
- }
-
- if ($table->get_sql_sort()) {
- $sql .= ' ORDER BY '.$table->get_sql_sort();
- }
-
- $countsql = "SELECT COUNT(DISTINCT(ra.userid))
- FROM {role_assignments} ra
- WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid";
-
- $totalcount = $DB->count_records_sql($countsql, $params);
-
- if ($twhere) {
- $matchcount = $DB->count_records_sql($countsql.' AND '.$twhere, $params);
- } else {
- $matchcount = $totalcount;
- }
-
- echo '<div id="participationreport">' . "\n";
- echo '<p class="modulename">'.$modulename . ' ' . $strviews.': '.implode(', ',$viewnames).'<br />'."\n"
- . $modulename . ' ' . $strposts.': '.implode(', ',$postnames).'</p>'."\n";
-
- $table->initialbars($totalcount > $perpage);
- $table->pagesize($perpage, $matchcount);
-
- if (!$users = $DB->get_records_sql($sql, $params, $table->get_page_start(), $table->get_page_size())) {
- $users = array(); // tablelib will handle saying 'Nothing to display' for us.
- }
-
- $data = array();
-
- $a->count = $totalcount;
- $a->items = $role->name;
-
- if ($matchcount != $totalcount) {
- $a->count = $matchcount.'/'.$a->count;
- }
-
- echo '<h2>'.get_string('counteditems', '', $a).'</h2>'."\n";
-
- echo '<form action="'.$CFG->wwwroot.'/user/action_redir.php" method="post" id="studentsform">'."\n";
- echo '<div>'."\n";
- echo '<input type="hidden" name="id" value="'.$id.'" />'."\n";
- echo '<input type="hidden" name="returnto" value="'. s($FULLME) .'" />'."\n";
- echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'."\n";
-
- foreach ($users as $u) {
- $data = array('<a href="'.$CFG->wwwroot.'/user/view.php?id='.$u->userid.'&course='.$course->id.'">'.fullname($u,true).'</a>'."\n",
- ((!empty($u->count)) ? get_string('yes').' ('.$u->count.') ' : get_string('no')),
- '<input type="checkbox" class="usercheckbox" name="user'.$u->userid.'" value="'.$u->count.'" />'."\n",
- );
- $table->add_data($data);
- }
-
- $table->print_html();
-
- if ($perpage == SHOW_ALL_PAGE_SIZE) {
- echo '<div id="showall"><a href="'.$baseurl.'&perpage='.DEFAULT_PAGE_SIZE.'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>'."\n";
- }
- else if ($matchcount > 0 && $perpage < $matchcount) {
- echo '<div id="showall"><a href="'.$baseurl.'&perpage='.SHOW_ALL_PAGE_SIZE.'">'.get_string('showall', '', $matchcount).'</a></div>'."\n";
- }
-
- echo '<div class="selectbuttons">';
- echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> '."\n";
- echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> '."\n";
- if ($perpage >= $matchcount) {
- echo '<input type="button" id="checknos" value="'.get_string('selectnos').'" />'."\n";
- }
- echo '</div>';
- echo '<div>';
- echo '<label for="formaction">'.get_string('withselectedusers').'</label>';
- $displaylist['messageselect.php'] = get_string('messageselectadd');
- echo html_writer::select($displaylist, 'formaction', '', array(''=>'choosedots'), array('id'=>'formactionselect'));
- echo $OUTPUT->help_icon('withselectedusers');
- echo '<input type="submit" value="' . get_string('ok') . '" />'."\n";
- echo '</div>';
- echo '</div>'."\n";
- echo '</form>'."\n";
- echo '</div>'."\n";
-
- $PAGE->requires->js_init_call('M.coursereport_participation.init');
- }
-
- echo $OUTPUT->footer();
-
-
+++ /dev/null
-<?php
-
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
- }
-
- if (has_capability('coursereport/participation:view', $context)) {
- echo '<p>';
- $participationreport = get_string('participationreport');
- echo "<a href=\"{$CFG->wwwroot}/course/report/participation/index.php?id={$course->id}\">";
- echo "$participationreport</a>\n";
- echo '</p>';
- }
-
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
-
-
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$capabilities = array(
-
- 'coursereport/progress:view' => array(
- 'riskbitmask' => RISK_PERSONAL,
- 'captype' => 'read',
- 'contextlevel' => CONTEXT_COURSE,
- 'archetypes' => array(
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- ),
-
- 'clonepermissionsfrom' => 'moodle/site:viewreports',
- )
-);
-
-
+++ /dev/null
-<?php
-
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
- }
-
- require_once($CFG->libdir.'/completionlib.php');
-
- if (has_capability('coursereport/progress:view', $context)) {
- $completion = new completion_info($course);
- if ($completion->is_enabled()) {
- echo '<p>';
- echo '<a href="'.$CFG->wwwroot.'/course/report/progress/?course='.$course->id.'">'.get_string('activitycompletion', 'completion').'</a>';
- echo '</p>';
- }
- }
-
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
-
-
+++ /dev/null
-<?php
-
- require_once('../../../config.php');
- require_once($CFG->dirroot.'/lib/statslib.php');
- require_once($CFG->dirroot.'/course/report/stats/lib.php');
- require_once($CFG->libdir.'/adminlib.php');
-
- $courseid = optional_param('course', SITEID, PARAM_INT);
- $report = optional_param('report', 0, PARAM_INT);
- $time = optional_param('time', 0, PARAM_INT);
- $mode = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT);
- $userid = optional_param('userid', 0, PARAM_INT);
- $roleid = 0;
-
- if ($report > 50) {
- $roleid = substr($report,1);
- $report = 5;
- }
-
- if ($report == STATS_REPORT_USER_LOGINS) {
- $courseid = SITEID; //override
- }
-
- if ($mode == STATS_MODE_RANKED) {
- redirect($CFG->wwwroot.'/course/report/stats/index.php?time='.$time);
- }
-
- if (!$course = $DB->get_record("course", array("id"=>$courseid))) {
- print_error("invalidcourseid");
- }
-
- if (!empty($userid)) {
- if (!$user = $DB->get_record('user', array('id'=>$userid))) {
- print_error("nousers");
- }
- }
-
- require_login($course);
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- require_capability('coursereport/stats:view', $context);
-
- $PAGE->set_url(new moodle_url('/course/report/stats/index.php', array('course' => $course->id,
- 'report' => $report,
- 'time' => $time,
- 'mode' => $mode,
- 'userid' => $userid)));
-
- add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id);
- stats_check_uptodate($course->id);
-
- if ($course->id == SITEID) {
- admin_externalpage_setup('reportstats');
- echo $OUTPUT->header();
- } else {
- $strreports = get_string("reports");
- $strstats = get_string('stats');
-
- $PAGE->set_title("$course->shortname: $strstats");
- $PAGE->set_heading($course->fullname);
- $PAGE->set_pagelayout('report');
- $PAGE->set_headingmenu(report_stats_mode_menu($course, $mode, $time, "$CFG->wwwroot/course/report/stats/index.php"));
- echo $OUTPUT->header();
- }
-
- require($CFG->dirroot.'/course/report/stats/report.php');
-
- if (empty($CFG->enablestats)) {
- if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
- redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
- } else {
- print_error('statsdisable');
- }
- }
-
- echo $OUTPUT->footer();
-
-
+++ /dev/null
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * This file contains functions used by the log reports
- *
- * This file is also required by /admin/reports/stats/index.php.
- *
- * @package course-report
- * @copyright 1999 onwards Martin Dougiamas http://moodle.com
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-require_once($CFG->dirroot.'/lib/statslib.php');
-
-function report_stats_mode_menu($course, $mode, $time, $url) {
- global $CFG, $OUTPUT;
- /*
- $reportoptions = stats_get_report_options($course->id, $mode);
- $timeoptions = report_stats_timeoptions($mode);
- if (empty($timeoptions)) {
- print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
- }
- */
-
- $options = array();
- $options[STATS_MODE_GENERAL] = get_string('statsmodegeneral');
- $options[STATS_MODE_DETAILED] = get_string('statsmodedetailed');
- if (has_capability('coursereport/stats:view', get_context_instance(CONTEXT_SYSTEM))) {
- $options[STATS_MODE_RANKED] = get_string('reports');
- }
- $popupurl = $url."?course=$course->id&time=$time";
- $select = new single_select(new moodle_url($popupurl), 'mode', $options, $mode, null);
- $select->formid = 'switchmode';
- return $OUTPUT->render($select);
-}
-
-
-function report_stats_timeoptions($mode) {
- global $CFG, $DB;
-
- if ($mode == STATS_MODE_DETAILED) {
- $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_daily}');
- $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_weekly}');
- $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_monthly}');
- } else {
- $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
- $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
- $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');
- }
-
-
- if (empty($earliestday)) $earliestday = time();
- if (empty($earliestweek)) $earliestweek = time();
- if (empty($earliestmonth)) $earliestmonth = time();
-
- $now = stats_get_base_daily();
- $lastweekend = stats_get_base_weekly();
- $lastmonthend = stats_get_base_monthly();
-
- return stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
-}
-
-/**
- * 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 stats_report_extend_navigation($navigation, $course, $context) {
- global $CFG, $OUTPUT;
- if (has_capability('coursereport/stats:view', $context)) {
- if (!empty($CFG->enablestats)) {
- $url = new moodle_url('/course/report/stats/index.php', array('course'=>$course->id));
- $navigation->add(get_string('stats'), $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 stats_page_type_list($pagetype, $parentcontext, $currentcontext) {
- $array = array(
- '*' => get_string('page-x', 'pagetype'),
- 'course-report-*' => get_string('page-course-report-x', 'pagetype'),
- 'course-report-stats-index' => get_string('pluginpagetype', 'coursereport_stats')
- );
- return $array;
-}
\ No newline at end of file
+++ /dev/null
-<?php
-
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
- }
-
- if (has_capability('coursereport/stats:view', $context)) {
- if (!empty($CFG->enablestats)) {
- echo '<p>';
- echo '<a href="'.$CFG->wwwroot.'/course/report/stats/index.php?course='.$course->id.'">'.get_string('stats').'</a>';
- echo '</p>';
- } else {
- echo '<p>';
- echo get_string('statsoff');
- echo '</p>';
- }
- }
-
+++ /dev/null
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-$plugin->version = 2010090501;
-$plugin->requires = 2010090501;
-
-
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
require_once("../config.php");
require_once("lib.php");
-require_once($CFG->libdir.'/completionlib.php');
$id = required_param('id',PARAM_INT); // course id
$user = required_param('user',PARAM_INT); // user id
$mode = optional_param('mode', "todaylogs", PARAM_ALPHA);
-$page = optional_param('page', 0, PARAM_INT);
-$perpage = optional_param('perpage', 100, PARAM_INT);
$url = new moodle_url('/course/user.php', array('id'=>$id,'user'=>$user, 'mode'=>$mode));
-if ($page !== 0) {
- $url->param('page', $page);
+
+$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
+$user = $DB->get_record("user", array("id"=>$user, 'deleted'=>0), '*', MUST_EXIST);
+
+if ($mode === 'outline' or $mode === 'complete') {
+ $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode));
+ redirect($url);
}
-if ($perpage !== 100) {
- $url->param('perpage', $perpage);
+if ($mode === 'todaylogs' or $mode === 'alllogs') {
+ $logmode = ($mode === 'todaylogs') ? 'today' : 'all';
+ $url = new moodle_url('/report/log/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$logmode));
+ redirect($url);
}
-$PAGE->set_url($url);
-
-if (!$course = $DB->get_record('course', array('id'=>$id))) {
- print_error('invalidcourseid', 'error');
+if ($mode === 'stats') {
+ $url = new moodle_url('/report/stats/user.php', array('id'=>$user->id, 'course'=>$course->id));
+ redirect($url);
}
-
-if (! $user = $DB->get_record("user", array("id"=>$user))) {
- print_error('invaliduserid', 'error');
+if ($mode === 'coursecompletions' or $mode === 'coursecompletion') {
+ $url = new moodle_url('/report/completion/user.php', array('id'=>$user->id, 'course'=>$course->id));
+ redirect($url);
}
-require_login();
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
$modes = array();
-if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
- $modes[] = 'outline';
-}
-
-if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
- $modes[] = 'complete';
-}
-
-if ($myreports or $anyreport or has_capability('coursereport/log:viewtoday', $coursecontext)) {
- $modes[] = 'todaylogs';
-}
-
-if ($myreports or $anyreport or has_capability('coursereport/log:view', $coursecontext)) {
- $modes[] = 'alllogs';
-}
-
-if ($myreports or $anyreport or has_capability('coursereport/stats:view', $coursecontext)) {
- $modes[] = 'stats';
-}
-
if (has_capability('moodle/grade:viewall', $coursecontext)) {
//ok - can view all course grades
$modes[] = 'grade';
$modes[] = 'grade';
}
-// Course completion tab
-if (!empty($CFG->enablecompletion) && ($course->id == SITEID || !empty($course->enablecompletion)) && // completion enabled
- ($myreports || $anyreport || ($course->id == SITEID || has_capability('coursereport/completion:view', $coursecontext)))) { // permissions to view the report
-
- // Decide if singular or plural
- if ($course->id == SITEID) {
- $modes[] = 'coursecompletions';
- } else {
- $modes[] = 'coursecompletion';
- }
-}
-
-
if (empty($modes)) {
require_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
}
add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id");
$stractivityreport = get_string("activityreport");
-$strparticipants = get_string("participants");
-$stroutline = get_string("outline");
-$strcomplete = get_string("complete");
-$stralllogs = get_string("alllogs");
-$strtodaylogs = get_string("todaylogs");
-$strmode = get_string($mode);
-$fullname = fullname($user, true);
-
-$link = null;
-if ($course->id != SITEID && has_capability('moodle/course:viewparticipants', $coursecontext)) {
- $link = new moodle_url('/user/index.php', array('id'=>$course->id));
-}
$PAGE->navigation->extend_for_user($user);
$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
}
break;
- case "todaylogs" :
- echo '<div class="graph">';
- print_log_graph($course, $user->id, "userday.png");
- echo '</div>';
- print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage,
- "user.php?id=$course->id&user=$user->id&mode=$mode");
- break;
-
- case "alllogs" :
- echo '<div class="graph">';
- print_log_graph($course, $user->id, "usercourse.png");
- echo '</div>';
- print_log($course, $user->id, 0, "l.time DESC", $page, $perpage,
- "user.php?id=$course->id&user=$user->id&mode=$mode");
- break;
- case 'stats':
-
- if (empty($CFG->enablestats)) {
- print_error('statsdisable', 'error');
- }
-
- require_once($CFG->dirroot.'/lib/statslib.php');
-
- $statsstatus = stats_check_uptodate($course->id);
- if ($statsstatus !== NULL) {
- echo $OUTPUT->notification($statsstatus);
- }
-
- $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend');
- $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend');
- $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend');
-
- if (empty($earliestday)) $earliestday = time();
- if (empty($earliestweek)) $earliestweek = time();
- if (empty($earliestmonth)) $earliestmonth = time();
-
- $now = stats_get_base_daily();
- $lastweekend = stats_get_base_weekly();
- $lastmonthend = stats_get_base_monthly();
-
- $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
-
- if (empty($timeoptions)) {
- print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
- }
-
- // use the earliest.
- $time = array_pop(array_keys($timeoptions));
-
- $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED);
- $params = $param->params;
-
- $param->table = 'user_'.$param->table;
-
- $sql = 'SELECT timeend,'.$param->fields.' FROM {stats_'.$param->table.'} WHERE '
- .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
- .' userid = '.$user->id.' AND timeend >= '.$param->timeafter .$param->extras
- .' ORDER BY timeend DESC';
- $stats = $DB->get_records_sql($sql, $params); //TODO: improve these params!!
-
- if (empty($stats)) {
- print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
- }
-
- // MDL-10818, do not display broken graph when user has no permission to view graph
- if ($myreports or has_capability('coursereport/stats:view', $coursecontext)) {
- echo '<center><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" alt="'.get_string('statisticsgraph').'" /></center>';
- }
-
- // What the heck is this about? -- MD
- $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
-
- $table = new html_table();
- $table->align = array('left','center','center','center');
- $param->table = str_replace('user_','',$param->table);
- switch ($param->table) {
- case 'daily' : $period = get_string('day'); break;
- case 'weekly' : $period = get_string('week'); break;
- case 'monthly': $period = get_string('month', 'form'); break;
- default : $period = '';
- }
- $table->head = array(get_string('periodending','moodle',$period),$param->line1,$param->line2,$param->line3);
- foreach ($stats as $stat) {
- if (!empty($stat->zerofixed)) { // Don't know why this is necessary, see stats_fix_zeros above - MD
- continue;
- }
- $a = array(userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone),$stat->line1);
- $a[] = $stat->line2;
- $a[] = $stat->line3;
- $table->data[] = $a;
- }
- echo html_writer::table($table);
- break;
-
- case "outline" :
- case "complete" :
- get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
- $sections = get_all_sections($course->id);
- $itemsprinted = false;
-
- for ($i=0; $i<=$course->numsections; $i++) {
-
- if (isset($sections[$i])) { // should always be true
-
- $section = $sections[$i];
- $showsection = (has_capability('moodle/course:viewhiddensections', $coursecontext) or $section->visible or !$course->hiddensections);
-
- if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
- // Check the section has a sequence. This is the sequence of modules/resources.
- // If there is no sequence there is nothing to display.
- if ($section->sequence) {
- $itemsprinted = true;
- echo '<div class="section">';
- echo '<h2>';
- echo get_section_name($course, $section);
- echo "</h2>";
-
- echo '<div class="content">';
-
- if ($mode == "outline") {
- echo "<table cellpadding=\"4\" cellspacing=\"0\">";
- }
-
- $sectionmods = explode(",", $section->sequence);
- foreach ($sectionmods as $sectionmod) {
- if (empty($mods[$sectionmod])) {
- continue;
- }
- $mod = $mods[$sectionmod];
-
- if (empty($mod->visible)) {
- continue;
- }
-
- $instance = $DB->get_record("$mod->modname", array("id"=>$mod->instance));
- $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
-
- if (file_exists($libfile)) {
- require_once($libfile);
-
- switch ($mode) {
- case "outline":
- $user_outline = $mod->modname."_user_outline";
- if (function_exists($user_outline)) {
- $output = $user_outline($course, $user, $mod, $instance);
- print_outline_row($mod, $instance, $output);
- }
- break;
- case "complete":
- $user_complete = $mod->modname."_user_complete";
- if (function_exists($user_complete)) {
- $image = $OUTPUT->pix_icon('icon', $mod->modfullname, 'mod_'.$mod->modname, array('class'=>'icon'));
- echo "<h4>$image $mod->modfullname: ".
- "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
- format_string($instance->name,true)."</a></h4>";
-
- ob_start();
-
- echo "<ul>";
- $user_complete($course, $user, $mod, $instance);
- echo "</ul>";
-
- $output = ob_get_contents();
- ob_end_clean();
-
- if (str_replace(' ', '', $output) != '<ul></ul>') {
- echo $output;
- }
- }
- break;
- }
- }
- }
-
- if ($mode == "outline") {
- echo "</table>";
- }
- echo '</div>'; // content
- echo '</div>'; // section
- }
- }
- }
- }
-
- if (!$itemsprinted) {
- echo $OUTPUT->notification(get_string('nothingtodisplay'));
- }
-
- break;
- case "coursecompletion":
- case "coursecompletions":
-
- // Display course completion user report
-
- // Grab all courses the user is enrolled in and their completion status
- $sql = "
- SELECT DISTINCT
- c.id AS id
- FROM
- {course} c
- INNER JOIN
- {context} con
- ON con.instanceid = c.id
- INNER JOIN
- {role_assignments} ra
- ON ra.contextid = con.id
- INNER JOIN
- {enrol} e
- ON c.id = e.courseid
- INNER JOIN
- {user_enrolments} ue
- ON e.id = ue.enrolid AND ra.userid = ue.userid
- AND ra.userid = {$user->id}
- ";
-
- // Get roles that are tracked by course completion
- if ($roles = $CFG->gradebookroles) {
- $sql .= '
- AND ra.roleid IN ('.$roles.')
- ';
- }
-
- $sql .= '
- WHERE
- con.contextlevel = '.CONTEXT_COURSE.'
- AND c.enablecompletion = 1
- ';
-
-
- // If we are looking at a specific course
- if ($course->id != 1) {
- $sql .= '
- AND c.id = '.(int)$course->id.'
- ';
- }
-
- // Check if result is empty
- $rs = $DB->get_recordset_sql($sql);
- if (!$rs->valid()) {
-
- if ($course->id != 1) {
- $error = get_string('nocompletions', 'coursereport_completion');
- } else {
- $error = get_string('nocompletioncoursesenroled', 'coursereport_completion');
- }
-
- echo $OUTPUT->notification($error);
- $rs->close(); // not going to loop (but break), close rs
- break;
- }
-
- // Categorize courses by their status
- $courses = array(
- 'inprogress' => array(),
- 'complete' => array(),
- 'unstarted' => array()
- );
-
- // Sort courses by the user's status in each
- foreach ($rs as $course_completion) {
- $c_info = new completion_info((object)$course_completion);
-
- // Is course complete?
- $coursecomplete = $c_info->is_course_complete($user->id);
-
- // Has this user completed any criteria?
- $criteriacomplete = $c_info->count_course_user_data($user->id);
-
- if ($coursecomplete) {
- $courses['complete'][] = $c_info;
- } else if ($criteriacomplete) {
- $courses['inprogress'][] = $c_info;
- } else {
- $courses['unstarted'][] = $c_info;
- }
- }
- $rs->close(); // after loop, close rs
-
- // Loop through course status groups
- foreach ($courses as $type => $infos) {
-
- // If there are courses with this status
- if (!empty($infos)) {
-
- echo '<h1 align="center">'.get_string($type, 'coursereport_completion').'</h1>';
- echo '<table class="generalbox boxaligncenter">';
- echo '<tr class="ccheader">';
- echo '<th class="c0 header" scope="col">'.get_string('course').'</th>';
- echo '<th class="c1 header" scope="col">'.get_string('requiredcriteria', 'completion').'</th>';
- echo '<th class="c2 header" scope="col">'.get_string('status').'</th>';
- echo '<th class="c3 header" scope="col" width="15%">'.get_string('info').'</th>';
-
- if ($type === 'complete') {
- echo '<th class="c4 header" scope="col">'.get_string('completiondate', 'coursereport_completion').'</th>';
- }
-
- echo '</tr>';
-
- // For each course
- foreach ($infos as $c_info) {
-
- // Get course info
- $c_course = $DB->get_record('course', array('id' => $c_info->course_id));
- $course_context = get_context_instance(CONTEXT_COURSE, $c_course->id, MUST_EXIST);
- $course_name = format_string($c_course->fullname, true, array('context' => $course_context));
-
- // Get completions
- $completions = $c_info->get_completions($user->id);
-
- // Save row data
- $rows = array();
-
- // For aggregating activity completion
- $activities = array();
- $activities_complete = 0;
-
- // For aggregating prerequisites
- $prerequisites = array();
- $prerequisites_complete = 0;
-
- // Loop through course criteria
- foreach ($completions as $completion) {
- $criteria = $completion->get_criteria();
- $complete = $completion->is_complete();
-
- // Activities are a special case, so cache them and leave them till last
- if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
- $activities[$criteria->moduleinstance] = $complete;
-
- if ($complete) {
- $activities_complete++;
- }
-
- continue;
- }
-
- // Prerequisites are also a special case, so cache them and leave them till last
- if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
- $prerequisites[$criteria->courseinstance] = $complete;
-
- if ($complete) {
- $prerequisites_complete++;
- }
-
- continue;
- }
-
- $row = array();
- $row['title'] = $criteria->get_title();
- $row['status'] = $completion->get_status();
- $rows[] = $row;
- }
-
- // Aggregate activities
- if (!empty($activities)) {
-
- $row = array();
- $row['title'] = get_string('activitiescomplete', 'coursereport_completion');
- $row['status'] = $activities_complete.' of '.count($activities);
- $rows[] = $row;
- }
-
- // Aggregate prerequisites
- if (!empty($prerequisites)) {
-
- $row = array();
- $row['title'] = get_string('prerequisitescompleted', 'completion');
- $row['status'] = $prerequisites_complete.' of '.count($prerequisites);
- array_splice($rows, 0, 0, array($row));
- }
-
- $first_row = true;
-
- // Print table
- foreach ($rows as $row) {
-
- // Display course name on first row
- if ($first_row) {
- echo '<tr><td class="c0"><a href="'.$CFG->wwwroot.'/course/view.php?id='.$c_course->id.'">'.$course_name.'</a></td>';
- } else {
- echo '<tr><td class="c0"></td>';
- }
-
- echo '<td class="c1">';
- echo $row['title'];
- echo '</td><td class="c2">';
-
- switch ($row['status']) {
- case 'Yes':
- echo get_string('complete');
- break;
-
- case 'No':
- echo get_string('incomplete', 'coursereport_completion');
- break;
-
- default:
- echo $row['status'];
- }
-
- // Display link on first row
- echo '</td><td class="c3">';
- if ($first_row) {
- echo '<a href="'.$CFG->wwwroot.'/blocks/completionstatus/details.php?course='.$c_course->id.'&user='.$user->id.'">'.get_string('detailedview', 'coursereport_completion').'</a>';
- }
- echo '</td>';
-
- // Display completion date for completed courses on first row
- if ($type === 'complete' && $first_row) {
- $params = array(
- 'userid' => $user->id,
- 'course' => $c_course->id
- );
-
- $ccompletion = new completion_completion($params);
- echo '<td class="c4">'.userdate($ccompletion->timecompleted, '%e %B %G').'</td>';
- }
-
- $first_row = false;
- echo '</tr>';
- }
- }
-
- echo '</table>';
- }
-
- }
-
break;
default:
// can not be reached ;-)
echo $OUTPUT->footer();
-
-
-function print_outline_row($mod, $instance, $result) {
- global $OUTPUT;
-
- $image = "<img src=\"" . $OUTPUT->pix_url('icon', $mod->modname) . "\" class=\"icon\" alt=\"$mod->modfullname\" />";
-
- echo "<tr>";
- echo "<td valign=\"top\">$image</td>";
- echo "<td valign=\"top\" style=\"width:300\">";
- echo " <a title=\"$mod->modfullname\"";
- echo " href=\"../mod/$mod->modname/view.php?id=$mod->id\">".format_string($instance->name,true)."</a></td>";
- echo "<td> </td>";
- echo "<td valign=\"top\">";
- if (isset($result->info)) {
- echo "$result->info";
- } else {
- echo "<p style=\"text-align:center\">-</p>";
- }
- echo "</td>";
- echo "<td> </td>";
- if (!empty($result->time)) {
- $timeago = format_time(time() - $result->time);
- echo "<td valign=\"top\" style=\"white-space: nowrap\">".userdate($result->time)." ($timeago)</td>";
- }
- echo "</tr>";
-}
-
'name' => new external_value(PARAM_ALPHANUMEXT, 'option name'),
'value' => new external_value(PARAM_RAW, 'option value')
)
- ), 'method options'),
+ ), 'method options', VALUE_DEFAULT, array()),
)
);
}
require_once($CFG->dirroot . "/user/lib.php");
$params = self::validate_parameters(
- self::get_users_by_course_id_parameters(),
+ self::get_enrolled_users_parameters(),
array(
'courseid'=>$courseid,
'options'=>$options
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
*/
public function get_info_icons(array $instances) {
foreach ($instances as $instance) {
- if ($instance->password) {
+ if ($instance->password !== '') {
return array(new pix_icon('withpassword', get_string('pluginname', 'enrol_guest'), 'enrol_guest'));
} else {
return array(new pix_icon('withoutpassword', get_string('pluginname', 'enrol_guest'), 'enrol_guest'));
* calling code has to make sure the plugin and instance are active.
*
* @param stdClass $instance course enrol instance
- * @param stdClass $user record
* @return bool|int false means no guest access, integer means end of cached time
*/
public function try_guestaccess(stdClass $instance) {
global $USER, $CFG;
- if (empty($instance->password)) {
+ $allow = false;
+
+ if ($instance->password === '') {
+ $allow = true;
+
+ } else if (isset($USER->enrol_guest_passwords[$instance->id])) { // this is a hack, ideally we should not add stuff to $USER...
+ if ($USER->enrol_guest_passwords[$instance->id] === $instance->password) {
+ $allow = true;
+ }
+ }
+
+ if ($allow) {
// Temporarily assign them some guest role for this context
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
load_temp_course_role($context, $CFG->guestroleid);
- return ENROL_REQUIRE_LOGIN_CACHE_PERIOD + time();
+ return ENROL_MAX_TIMESTAMP;
}
return false;
public function enrol_page_hook(stdClass $instance) {
global $CFG, $OUTPUT, $SESSION, $USER;
- if (empty($instance->password)) {
+ if ($instance->password === '') {
+ return null;
+ }
+
+ if (isset($USER->enrol['tempguest'][$instance->courseid]) and $USER->enrol['tempguest'][$instance->courseid] > time()) {
+ // no need to show the guest access when user can already enter course as guest
return null;
}
if ($instance->id == $instanceid) {
if ($data = $form->get_data()) {
- // set up primitive require_login() caching
- unset($USER->enrol['enrolled'][$instance->courseid]);
- $USER->enrol['tempguest'][$instance->courseid] = time() + 60*60*8; // 8 hours access before asking for pw again
-
// add guest role
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
+ $USER->enrol_guest_passwords[$instance->id] = $data->guestpassword; // this is a hack, ideally we should not add stuff to $USER...
+ if (isset($USER->enrol['tempguest'][$instance->courseid])) {
+ remove_temp_course_roles($context);
+ }
load_temp_course_role($context, $CFG->guestroleid);
+ $USER->enrol['tempguest'][$instance->courseid] = ENROL_MAX_TIMESTAMP;
// go to the originally requested page
if (!empty($SESSION->wantsurl)) {
}
}
$this->add_instance($course, $fields);
+ } else {
+ if ($this->get_config('defaultenrol')) {
+ $this->add_default_instance($course);
+ }
}
} else {
$instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'enrol'=>'guest'));
$i = $instance->id;
if (isset($data->{'enrol_guest_status_'.$i})) {
+ $reset = ($instance->status != $data->{'enrol_guest_status_'.$i});
+
$instance->status = $data->{'enrol_guest_status_'.$i};
$instance->timemodified = time();
if ($instance->status == ENROL_INSTANCE_ENABLED) {
+ if ($instance->password !== $data->{'enrol_guest_password_'.$i}) {
+ $reset = true;
+ }
$instance->password = $data->{'enrol_guest_password_'.$i};
}
$DB->update_record('enrol', $instance);
+
+ if ($reset) {
+ $context->mark_dirty();
+ }
}
}
}
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
$errors = parent::validation($data, $files);
$instance = $this->instance;
- if ($instance->password) {
+ if ($instance->password !== '') {
if ($data['guestpassword'] !== $instance->password) {
$plugin = enrol_get_plugin('guest');
if ($plugin->get_config('showhint')) {
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2010081800;
+$plugin->version = 2011110600;
+$plugin->component = 'enrol_guest';
if ($confirm) {
$plugin->delete_instance($instance);
+ $context->mark_dirty(); // invalidate all enrol caches
redirect($PAGE->url);
}
if ($instance->status == ENROL_INSTANCE_ENABLED) {
$instance->status = ENROL_INSTANCE_DISABLED;
$DB->update_record('enrol', $instance);
+ $context->mark_dirty(); // invalidate all enrol caches
redirect($PAGE->url);
}
if ($instance->status == ENROL_INSTANCE_DISABLED) {
$instance->status = ENROL_INSTANCE_ENABLED;
$DB->update_record('enrol', $instance);
+ $context->mark_dirty(); // invalidate all enrol caches
redirect($PAGE->url);
}
}
} else if ($data = $mform->get_data()) {
if ($instance->id) {
+ $reset = ($instance->status != $data->status);
+
$instance->status = $data->status;
$instance->enrolperiod = $data->enrolperiod;
$instance->roleid = $data->roleid;
$instance->timemodified = time();
$DB->update_record('enrol', $instance);
+ if ($reset) {
+ $context->mark_dirty();
+ }
+
} else {
$fields = array('status'=>$data->status, 'enrolperiod'=>$data->enrolperiod, 'roleid'=>$data->roleid);
$plugin->add_instance($course, $fields);
} else if ($data = $mform->get_data()) {
if ($instance->id) {
+ $reset = ($instance->status != $data->status);
+
$instance->status = $data->status;
$instance->name = $data->name;
$instance->cost = $data->cost;
$instance->timemodified = time();
$DB->update_record('enrol', $instance);
+ if ($reset) {
+ $context->mark_dirty();
+ }
+
} else {
$fields = array('status'=>$data->status, 'name'=>$data->name, 'cost'=>$data->cost, 'currency'=>$data->currency, 'roleid'=>$data->roleid,
'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate);
} else if ($data = $mform->get_data()) {
if ($instance->id) {
+ $reset = ($instance->status != $data->status);
+
$instance->status = $data->status;
$instance->name = $data->name;
$instance->password = $data->password;
$instance->timemodified = time();
$DB->update_record('enrol', $instance);
+ if ($reset) {
+ $context->mark_dirty();
+ }
+
} else {
$fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2,
'customint3'=>$data->customint3, 'customint4'=>$data->customint4, 'customtext1'=>$data->customtext1,
This files describes API changes in /enrol/* - plugins,
information provided here is intended especially for developers.
+
=== 2.2 ===
required changes in code:
* load_temp_role() is deprecated, use load_temp_course_role() instead, temp role not loaded
* remove_temp_role() is deprecated, use remove_temp_course_roles() instead
* 'user_unenrol_modified' event was renamed to 'user_enrol_modified'
+
+
+=== 2.0 ===
+
+required changes in code:
+* enrolment plugins need to be rewritten to use new API - see inline phpdocs and official plugins
\ No newline at end of file
$string['releasenoteslink'] = 'For information about this version of Moodle, please see the online <a target="_blank" href="{$a}">Release Notes</a>';
$string['rememberusername'] = 'Remember username';
$string['rememberusername_desc'] = 'Enable if you want to store permanent cookies with usernames during user login. Permanent cookies may be considered a privacy issue if used without consent.';
+$string['reportsmanage'] = 'Manage reports';
+$string['reportsdeleteconfirm'] = 'You are about to completely delete the report \'{$a}\'. This will completely delete everything in the database associated with this plugin. Are you SURE you want to continue?';
$string['requiredentrieschanged'] = '<strong>IMPORTANT - PLEASE READ<br/>(This warning message will only be displayed during this upgrade)</strong><br/>Due to a bug fix, the behaviour of database activities using the \'Required entries\' and \'Required entries before viewing settings\' settings will change. A more detailed explanation of the changes can be read on <a href="http://moodle.org/mod/forum/discuss.php?d=110928" target="_blank">the database module forum</a>. The expected behavior of these settings can also be read on <a href="http://docs.moodle.org/en/Adding/editing_a_database#Required_entries" target="_blank">Moodle Docs</a>.
<br/><br/>This change affects the following databases in your system: (Please save this list now, and after the upgrade, check that these activities still work the way that the teacher intends.)<br/><strong>{$a->text}</strong><br/>';
$string['requiremodintro'] = 'Require activity description';
Any information you have entered will be lost.';
$string['confirmcancelyes'] = 'Cancel';
$string['confirmcancelno'] = 'Stay';
+$string['confirmnewcoursecontinue'] = 'New course warning';
+$string['confirmnewcoursecontinuequestion'] = 'A temporary (hidden) course will be created by the course restoration process. To abort restoration click cancel. Do not close the browser while restoring.';
$string['coursecategory'] = 'Category the course will be restored into';
$string['courseid'] = 'Original ID';
$string['coursesettings'] = 'Course settings';
$string['calendar'] = 'Calendar';
$string['calendarheading'] = '{$a} Calendar';
$string['calendarpreferences'] = 'Calendar preferences';
+$string['calendarurl'] = 'Calendar URL: {$a}';
$string['clickhide'] = 'click to hide';
$string['clickshow'] = 'click to show';
$string['commontasks'] = 'Options';
$string['notmoodleapplication'] = 'WARNING: This is not a Moodle application, so some of the inspection methods may not work properly.';
$string['notPEM'] = 'This key is not in PEM format. It will not work.';
$string['notpermittedtojump'] = 'You do not have permission to begin a remote session from this Moodle server.';
+$string['notpermittedtojumpas'] = 'You can\'t begin a remote session while you are logged in as another user.';
$string['notpermittedtoland'] = 'You do not have permission to begin a remote session.';
$string['off'] = 'Off';
$string['on'] = 'On';
$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';
$string['noticenewerbackup'] = 'This backup file has been created with Moodle {$a->backuprelease} ({$a->backupversion}) and it\'s newer than your currently installed Moodle {$a->serverrelease} ({$a->serverversion}). This could cause some inconsistencies because backwards compatibility of backup files cannot be guaranteed.';
$string['notifications'] = 'Notifications';
$string['notifyloginfailuresmessage'] = '{$a->time}, IP: {$a->ip}, User: {$a->info}';
-$string['notifyloginfailuresmessageend'] = 'You can view these logs at {$a}/course/report/log/index.php?id=1&chooselog=1&modid=site_errors.';
+$string['notifyloginfailuresmessageend'] = 'You can view these logs at {$a}/report/log/index.php?id=1&chooselog=1&modid=site_errors.';
$string['notifyloginfailuresmessagestart'] = 'Here is a list of failed login attempts at {$a} since you were last notified';
$string['notifyloginfailuressubject'] = '{$a} :: Failed logins notification';
$string['notincluded'] = 'Not included';
$string['page-mod-x'] = 'Any activity module page';
$string['page-mod-x-view'] = 'Any main activity module page';
$string['page-my-index'] = 'My home page';
+$string['page-report-x'] = 'Any report page';
$string['page-site-index'] = 'The front page only';
$string['page-site-x'] = 'Any top-level site page';
$string['page-user-view'] = 'Only user profile pages';
$string['plugindisabled'] = 'Disabled';
$string['pluginenable'] = 'Enable';
$string['pluginenabled'] = 'Enabled';
+$string['requiredby'] = 'Required by: {$a}';
$string['requires'] = 'Requires';
$string['rootdir'] = 'Directory';
$string['settings'] = 'Settings';
$string['type_qtype'] = 'Question type';
$string['type_qtype_plural'] = 'Question types';
$string['type_report'] = 'Site report';
-$string['type_report_plural'] = 'Site reports';
+$string['type_report_plural'] = 'Reports';
$string['type_repository'] = 'Repository';
$string['type_repository_plural'] = 'Repositories';
$string['type_theme'] = 'Theme';
// Clear to force a refresh
unset($USER->mycourses);
- unset($USER->enrol);
+
+ // init/reset internal enrol caches - active course enrolments and temp access
+ $USER->enrol = array('enrolled'=>array(), 'tempguest'=>array());
}
/**
* @return void
*/
function load_temp_course_role(context_course $coursecontext, $roleid) {
- global $USER;
-
- //TODO: this gets removed if there are any dirty contexts, we should probably store list of these temp roles somewhere (skodak)
+ global $USER, $SITE;
if (empty($roleid)) {
debugging('invalid role specified in load_temp_course_role()');
return;
}
+ if ($coursecontext->instanceid == $SITE->id) {
+ debugging('Can not use temp roles on the frontpage');
+ return;
+ }
+
if (!isset($USER->access)) {
load_all_capabilities();
}
* @return void
*/
function remove_temp_course_roles(context_course $coursecontext) {
- global $DB, $USER;
+ global $DB, $USER, $SITE;
+
+ if ($coursecontext->instanceid == $SITE->id) {
+ debugging('Can not use temp roles on the frontpage');
+ return;
+ }
if (empty($USER->access['ra'][$coursecontext->path])) {
//no roles here, weird
* Returns true if user is enrolled (is participating) in course
* this is intended for students and teachers.
*
+ * Since 2.2 the result for active enrolments and current user are cached.
+ *
* @param context $context
* @param int|stdClass $user, if null $USER is used, otherwise user object or id expected
* @param string $withcapability extra capability name
if ($coursecontext->instanceid == SITEID) {
// everybody participates on frontpage
} else {
- if ($onlyactive) {
- $sql = "SELECT ue.*
- FROM {user_enrolments} ue
- JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)
- JOIN {user} u ON u.id = ue.userid
- WHERE ue.userid = :userid AND ue.status = :active AND e.status = :enabled AND u.deleted = 0";
- $params = array('enabled'=>ENROL_INSTANCE_ENABLED, 'active'=>ENROL_USER_ACTIVE, 'userid'=>$userid, 'courseid'=>$coursecontext->instanceid);
- // this result should be very small, better not do the complex time checks in sql for now ;-)
- $enrolments = $DB->get_records_sql($sql, $params);
- $now = time();
- // make sure the enrol period is ok
- $result = false;
- foreach ($enrolments as $e) {
- if ($e->timestart > $now) {
- continue;
+ // try cached info first - the enrolled flag is set only when active enrolment present
+ if ($USER->id == $userid) {
+ $coursecontext->reload_if_dirty();
+ if (isset($USER->enrol['enrolled'][$coursecontext->instanceid])) {
+ if ($USER->enrol['enrolled'][$coursecontext->instanceid] > time()) {
+ return true;
}
- if ($e->timeend and $e->timeend < $now) {
- continue;
- }
- $result = true;
- break;
}
- if (!$result) {
+ }
+
+ if ($onlyactive) {
+ // look for active enrolments only
+ $until = enrol_get_enrolment_end($coursecontext->instanceid, $userid);
+
+ if ($until === false) {
return false;
}
+ if ($USER->id == $userid) {
+ if ($until == 0) {
+ $until = ENROL_MAX_TIMESTAMP;
+ }
+ $USER->enrol['enrolled'][$coursecontext->instanceid] = $until;
+ if (isset($USER->enrol['tempguest'][$coursecontext->instanceid])) {
+ unset($USER->enrol['tempguest'][$coursecontext->instanceid]);
+ remove_temp_course_roles($coursecontext);
+ }
+ }
+
} else {
// any enrolment is good for us here, even outdated, disabled or inactive
$sql = "SELECT 'x'
// === from here we deal only with $USER ===
- // verify our caches
- if (!isset($USER->enrol)) {
- /**
- * These flags within the $USER object should NEVER be used outside of this
- * function can_access_course and the function require_login.
- * Doing so WILL break future versions!!!!
- */
- $USER->enrol = array();
- $USER->enrol['enrolled'] = array();
- $USER->enrol['tempguest'] = array();
- }
+ $coursecontext->reload_if_dirty();
+
if (isset($USER->enrol['enrolled'][$course->id])) {
- if ($USER->enrol['enrolled'][$course->id] == 0) {
- return true;
- } else if ($USER->enrol['enrolled'][$course->id] > time()) {
+ if ($USER->enrol['enrolled'][$course->id] > time()) {
return true;
}
}
if (isset($USER->enrol['tempguest'][$course->id])) {
- if ($USER->enrol['tempguest'][$course->id] == 0) {
- return true;
- } else if ($USER->enrol['tempguest'][$course->id] > time()) {
+ if ($USER->enrol['tempguest'][$course->id] > time()) {
return true;
}
}
- if (is_enrolled($coursecontext, $USER, '', true)) {
- // active participants may always access
- // TODO: refactor this into some new function
- $now = time();
- $sql = "SELECT MAX(ue.timeend)
- FROM {user_enrolments} ue
- JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)
- JOIN {user} u ON u.id = ue.userid
- WHERE ue.userid = :userid AND ue.status = :active AND e.status = :enabled AND u.deleted = 0
- AND ue.timestart < :now1 AND (ue.timeend = 0 OR ue.timeend > :now2)";
- $params = array('enabled'=>ENROL_INSTANCE_ENABLED, 'active'=>ENROL_USER_ACTIVE,
- 'userid'=>$USER->id, 'courseid'=>$coursecontext->instanceid, 'now1'=>$now, 'now2'=>$now);
- $until = $DB->get_field_sql($sql, $params);
- if (!$until or $until > time() + ENROL_REQUIRE_LOGIN_CACHE_PERIOD) {
- $until = time() + ENROL_REQUIRE_LOGIN_CACHE_PERIOD;
- }
-
- $USER->enrol['enrolled'][$course->id] = $until;
-
- // remove traces of previous temp guest access
- remove_temp_course_roles($coursecontext);
-
+ if (is_enrolled($coursecontext, $USER, '', $onlyactive)) {
return true;
}
- unset($USER->enrol['enrolled'][$course->id]);
// if not enrolled try to gain temporary guest access
$instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'status'=>ENROL_INSTANCE_ENABLED), 'sortorder, id ASC');
if (!isset($enrols[$instance->enrol])) {
continue;
}
- // Get a duration for the guestaccess, a timestamp in the future or false.
+ // Get a duration for the guest access, a timestamp in the future, 0 (always) or false.
$until = $enrols[$instance->enrol]->try_guestaccess($instance);
- if ($until !== false) {
+ if ($until !== false and $until > time()) {
$USER->enrol['tempguest'][$course->id] = $until;
return true;
}
}
- unset($USER->enrol['tempguest'][$course->id]);
+ if (isset($USER->enrol['tempguest'][$course->id])) {
+ unset($USER->enrol['tempguest'][$course->id]);
+ remove_temp_course_roles($coursecontext);
+ }
return false;
}
$libfile = $directory.'/lib.php';
if (file_exists($libfile)) {
require_once($libfile);
- $function = $pluginname.'_page_type_list';
+ $function = $possiblecomponent.'_'.$pluginname.'_page_type_list';
+ if (!function_exists($function)) {
+ $function = $pluginname.'_page_type_list';
+ }
if (function_exists($function)) {
if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) {
break;
* @return string
*/
public function get_title() {
- return get_string('unenrol');
+ return get_string('unenrol', 'enrol');
}
/**
* @return string
*/
public function get_type_title() {
- return get_string('unenrol');
+ return get_string('unenrol', 'enrol');
}
/**
/** User participation in course is suspended (used in user_enrolments->status) */
define('ENROL_USER_SUSPENDED', 1);
-/** Enrol info is cached for this number of seconds in require_login() */
+/** @deprecated - enrol caching was reworked, use ENROL_MAX_TIMESTAMP instead */
define('ENROL_REQUIRE_LOGIN_CACHE_PERIOD', 1800);
+/** The timestamp indicating forever */
+define('ENROL_MAX_TIMESTAMP', 2147483647);
+
/** When user disappears from external source, the enrolment is completely removed */
define('ENROL_EXT_REMOVED_UNENROL', 0);
/**
* Returns instances of enrol plugins
- * @param bool $enable return enabled only
+ * @param bool $enabled return enabled only
* @return array of enrol plugins name=>instance
*/
function enrol_get_plugins($enabled) {
/**
* Called when course is about to be deleted.
- * @param stdClass $object
+ * @param stdClass $course
* @return void
*/
function enrol_course_delete($course) {
return $result;
}
+/**
+ * This function returns the end of current active user enrolment.
+ *
+ * It deals correctly with multiple overlapping user enrolments.
+ *
+ * @param int $courseid
+ * @param int $userid
+ * @return int|bool timestamp when active enrolment ends, false means no active enrolment now, 0 means never
+ */
+function enrol_get_enrolment_end($courseid, $userid) {
+ global $DB;
+
+ $sql = "SELECT ue.*
+ FROM {user_enrolments} ue
+ JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)
+ JOIN {user} u ON u.id = ue.userid
+ WHERE ue.userid = :userid AND ue.status = :active AND e.status = :enabled AND u.deleted = 0";
+ $params = array('enabled'=>ENROL_INSTANCE_ENABLED, 'active'=>ENROL_USER_ACTIVE, 'userid'=>$userid, 'courseid'=>$courseid);
+
+ if (!$enrolments = $DB->get_records_sql($sql, $params)) {
+ return false;
+ }
+
+ $changes = array();
+
+ foreach ($enrolments as $ue) {
+ $start = (int)$ue->timestart;
+ $end = (int)$ue->timeend;
+ if ($end != 0 and $end < $start) {
+ debugging('Invalid enrolment start or end in user_enrolment id:'.$ue->id);
+ continue;
+ }
+ if (isset($changes[$start])) {
+ $changes[$start] = $changes[$start] + 1;
+ } else {
+ $changes[$start] = 1;
+ }
+ if ($end === 0) {
+ // no end
+ } else if (isset($changes[$end])) {
+ $changes[$end] = $changes[$end] - 1;
+ } else {
+ $changes[$end] = -1;
+ }
+ }
+
+ // let's sort then enrolment starts&ends and go through them chronologically,
+ // looking for current status and the next future end of enrolment
+ ksort($changes);
+
+ $now = time();
+ $current = 0;
+ $present = null;
+
+ foreach ($changes as $time => $change) {
+ if ($time > $now) {
+ if ($present === null) {
+ // we have just went past current time
+ $present = $current;
+ if ($present < 1) {
+ // no enrolment active
+ return false;
+ }
+ }
+ if ($present !== null) {
+ // we are already in the future - look for possible end
+ if ($current + $change < 1) {
+ return $time;
+ }
+ }
+ }
+ $current += $change;
+ }
+
+ if ($current > 0) {
+ return 0;
+ } else {
+ return false;
+ }
+}
+
+
/**
* All enrol plugins should be based on this class,
* this is also the main source of documentation.
* This should return either a timestamp in the future or false.
*
* @param stdClass $instance course enrol instance
- * @param stdClass $user record
* @return bool|int false means not enrolled, integer means timeend
*/
public function try_autoenrol(stdClass $instance) {
* This should return either a timestamp in the future or false.
*
* @param stdClass $instance course enrol instance
- * @param stdClass $user record
* @return bool|int false means no guest access, integer means timeend
*/
public function try_guestaccess(stdClass $instance) {
$ue->courseid = $courseid;
$ue->enrol = $name;
events_trigger('user_enrol_modified', $ue);
+ // resets current enrolment caches
+ $context->mark_dirty();
}
if ($roleid) {
- // this must be done after the enrolment event so that the role_assigned event is trigerred aftwerwards
+ // this must be done after the enrolment event so that the role_assigned event is triggered afterwards
if ($this->roles_protected()) {
role_assign($roleid, $userid, $context->id, 'enrol_'.$name, $instance->id);
} else {
&