2009-11-04 08:11:02 +00:00
|
|
|
<?php
|
2014-02-18 10:12:42 +13:00
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists all the users within a given course.
|
|
|
|
*
|
|
|
|
* @copyright 1999 Martin Dougiamas http://dougiamas.com
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
* @package core_user
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('../config.php');
|
2015-03-30 12:04:42 +02:00
|
|
|
require_once($CFG->dirroot.'/user/lib.php');
|
2017-08-17 11:07:38 +08:00
|
|
|
require_once($CFG->dirroot.'/course/lib.php');
|
2017-11-07 10:32:51 +08:00
|
|
|
require_once($CFG->dirroot.'/notes/lib.php');
|
2014-02-18 10:12:42 +13:00
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
2017-06-28 10:25:45 +08:00
|
|
|
require_once($CFG->dirroot.'/enrol/locallib.php');
|
2014-02-18 10:12:42 +13:00
|
|
|
|
2020-03-04 11:39:24 +08:00
|
|
|
use core_table\local\filter\filter;
|
|
|
|
use core_table\local\filter\integer_filter;
|
|
|
|
use core_table\local\filter\string_filter;
|
|
|
|
|
2021-12-20 14:54:11 +01:00
|
|
|
$participantsperpage = intval(get_config('moodlecourse', 'participantsperpage'));
|
|
|
|
define('DEFAULT_PAGE_SIZE', (!empty($participantsperpage) ? $participantsperpage : 20));
|
2014-02-18 10:12:42 +13:00
|
|
|
|
|
|
|
$page = optional_param('page', 0, PARAM_INT); // Which page to show.
|
|
|
|
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // How many per page.
|
|
|
|
$contextid = optional_param('contextid', 0, PARAM_INT); // One of this or.
|
|
|
|
$courseid = optional_param('id', 0, PARAM_INT); // This are required.
|
2017-08-17 11:07:38 +08:00
|
|
|
$newcourse = optional_param('newcourse', false, PARAM_BOOL);
|
2017-09-11 12:42:26 +08:00
|
|
|
$roleid = optional_param('roleid', 0, PARAM_INT);
|
2020-05-06 18:39:55 +08:00
|
|
|
$urlgroupid = optional_param('group', 0, PARAM_INT);
|
2014-02-18 10:12:42 +13:00
|
|
|
|
|
|
|
$PAGE->set_url('/user/index.php', array(
|
|
|
|
'page' => $page,
|
|
|
|
'perpage' => $perpage,
|
|
|
|
'contextid' => $contextid,
|
2017-08-17 11:07:38 +08:00
|
|
|
'id' => $courseid,
|
|
|
|
'newcourse' => $newcourse));
|
2014-02-18 10:12:42 +13:00
|
|
|
|
|
|
|
if ($contextid) {
|
|
|
|
$context = context::instance_by_id($contextid, MUST_EXIST);
|
|
|
|
if ($context->contextlevel != CONTEXT_COURSE) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidcontext');
|
2014-02-18 10:12:42 +13:00
|
|
|
}
|
|
|
|
$course = $DB->get_record('course', array('id' => $context->instanceid), '*', MUST_EXIST);
|
|
|
|
} else {
|
|
|
|
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
|
|
|
|
$context = context_course::instance($course->id, MUST_EXIST);
|
|
|
|
}
|
|
|
|
// Not needed anymore.
|
|
|
|
unset($contextid);
|
|
|
|
unset($courseid);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
require_login($course);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
$systemcontext = context_system::instance();
|
|
|
|
$isfrontpage = ($course->id == SITEID);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
$frontpagectx = context_course::instance(SITEID);
|
2010-03-31 07:41:31 +00:00
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
if ($isfrontpage) {
|
|
|
|
$PAGE->set_pagelayout('admin');
|
2017-08-30 15:11:20 +08:00
|
|
|
course_require_view_participants($systemcontext);
|
2014-02-18 10:12:42 +13:00
|
|
|
} else {
|
|
|
|
$PAGE->set_pagelayout('incourse');
|
2017-08-30 15:11:20 +08:00
|
|
|
course_require_view_participants($context);
|
2014-02-18 10:12:42 +13:00
|
|
|
}
|
2007-03-05 20:13:16 +00:00
|
|
|
|
2015-03-30 12:04:42 +02:00
|
|
|
// Trigger events.
|
|
|
|
user_list_view($course, $context);
|
2014-02-18 10:12:42 +13:00
|
|
|
|
|
|
|
$PAGE->set_title("$course->shortname: ".get_string('participants'));
|
|
|
|
$PAGE->set_heading($course->fullname);
|
2021-08-31 19:05:08 +02:00
|
|
|
$PAGE->set_pagetype('course-view-participants');
|
2020-07-24 13:37:29 +02:00
|
|
|
$PAGE->set_docs_path('enrol/users');
|
2014-02-18 10:12:42 +13:00
|
|
|
$PAGE->add_body_class('path-user'); // So we can style it independently.
|
|
|
|
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
|
2004-01-31 04:08:10 +00:00
|
|
|
|
2017-08-17 13:36:07 +08:00
|
|
|
// Expand the users node in the settings navigation when it exists because those pages
|
|
|
|
// are related to this one.
|
|
|
|
$node = $PAGE->settingsnav->find('users', navigation_node::TYPE_CONTAINER);
|
|
|
|
if ($node) {
|
2017-08-29 15:06:43 +08:00
|
|
|
$node->force_open();
|
2017-08-17 13:36:07 +08:00
|
|
|
}
|
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
echo $OUTPUT->header();
|
2021-11-01 14:33:59 +08:00
|
|
|
|
|
|
|
$participanttable = new \core_user\table\participants("user-index-participants-{$course->id}");
|
|
|
|
|
|
|
|
// Manage enrolments.
|
|
|
|
$manager = new course_enrolment_manager($PAGE, $course);
|
|
|
|
$enrolbuttons = $manager->get_manual_enrol_buttons();
|
|
|
|
$enrolrenderer = $PAGE->get_renderer('core_enrol');
|
|
|
|
$enrolbuttonsout = '';
|
|
|
|
foreach ($enrolbuttons as $enrolbutton) {
|
|
|
|
$enrolbuttonsout .= $enrolrenderer->render($enrolbutton);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->render_participants_tertiary_nav($course, html_writer::div($enrolbuttonsout, '', [
|
|
|
|
'data-region' => 'wrapper',
|
|
|
|
'data-table-uniqueid' => $participanttable->uniqueid,
|
|
|
|
]));
|
|
|
|
|
2020-05-06 18:39:55 +08:00
|
|
|
$filterset = new \core_user\table\participants_filterset();
|
|
|
|
$filterset->add_filter(new integer_filter('courseid', filter::JOINTYPE_DEFAULT, [(int)$course->id]));
|
2017-09-11 12:42:26 +08:00
|
|
|
|
2017-07-20 13:33:02 +08:00
|
|
|
$canaccessallgroups = has_capability('moodle/site:accessallgroups', $context);
|
2020-05-06 18:39:55 +08:00
|
|
|
$filtergroupids = $urlgroupid ? [$urlgroupid] : [];
|
2020-03-04 11:39:24 +08:00
|
|
|
|
2020-05-06 18:39:55 +08:00
|
|
|
// Force group filtering if user should only see a subset of groups' users.
|
2020-06-09 15:52:37 +08:00
|
|
|
if ($course->groupmode != NOGROUPS && !$canaccessallgroups) {
|
|
|
|
if ($filtergroupids) {
|
|
|
|
$filtergroupids = array_intersect(
|
|
|
|
$filtergroupids,
|
|
|
|
array_keys(groups_get_all_groups($course->id, $USER->id))
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$filtergroupids = array_keys(groups_get_all_groups($course->id, $USER->id));
|
|
|
|
}
|
2010-05-16 08:21:12 +00:00
|
|
|
|
2020-05-06 18:39:55 +08:00
|
|
|
if (empty($filtergroupids)) {
|
2020-06-09 15:52:37 +08:00
|
|
|
if ($course->groupmode == SEPARATEGROUPS) {
|
|
|
|
// The user is not in a group so show message and exit.
|
|
|
|
echo $OUTPUT->notification(get_string('notingroup'));
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
exit();
|
|
|
|
} else {
|
|
|
|
$filtergroupids = [(int) groups_get_course_group($course, true)];
|
|
|
|
}
|
2017-07-20 13:33:02 +08:00
|
|
|
}
|
2014-02-18 10:12:42 +13:00
|
|
|
}
|
2020-05-06 18:39:55 +08:00
|
|
|
|
|
|
|
// Apply groups filter if included in URL or forced due to lack of capabilities.
|
|
|
|
if (!empty($filtergroupids)) {
|
|
|
|
$filterset->add_filter(new integer_filter('groups', filter::JOINTYPE_DEFAULT, $filtergroupids));
|
2015-11-03 10:51:49 +00:00
|
|
|
}
|
2014-02-18 10:12:42 +13:00
|
|
|
|
2020-05-06 18:39:55 +08:00
|
|
|
// Display single group information if requested in the URL.
|
|
|
|
if ($urlgroupid > 0 && ($course->groupmode != SEPARATEGROUPS || $canaccessallgroups)) {
|
2017-10-23 08:04:09 +08:00
|
|
|
$grouprenderer = $PAGE->get_renderer('core_group');
|
2020-05-06 18:39:55 +08:00
|
|
|
$groupdetailpage = new \core_group\output\group_details($urlgroupid);
|
2017-10-23 08:04:09 +08:00
|
|
|
echo $grouprenderer->group_details($groupdetailpage);
|
|
|
|
}
|
|
|
|
|
2020-05-06 18:39:55 +08:00
|
|
|
// Filter by role if passed via URL (used on profile page).
|
|
|
|
if ($roleid) {
|
|
|
|
$viewableroles = get_profile_roles($context);
|
2020-04-20 11:24:26 +08:00
|
|
|
|
2020-05-06 18:39:55 +08:00
|
|
|
// Apply filter if the user can view this role.
|
|
|
|
if (array_key_exists($roleid, $viewableroles)) {
|
|
|
|
$filterset->add_filter(new integer_filter('roles', filter::JOINTYPE_DEFAULT, [$roleid]));
|
|
|
|
}
|
|
|
|
}
|
2020-04-20 11:24:26 +08:00
|
|
|
|
2020-03-25 15:22:00 +08:00
|
|
|
// Render the user filters.
|
|
|
|
$userrenderer = $PAGE->get_renderer('core_user');
|
|
|
|
echo $userrenderer->participants_filter($context, $participanttable->uniqueid);
|
|
|
|
|
2018-02-07 18:31:43 +01:00
|
|
|
echo '<div class="userlist">';
|
|
|
|
|
2017-06-28 11:44:20 +08:00
|
|
|
// Do this so we can get the total number of rows.
|
|
|
|
ob_start();
|
2020-04-20 11:24:26 +08:00
|
|
|
$participanttable->set_filterset($filterset);
|
2017-06-28 11:44:20 +08:00
|
|
|
$participanttable->out($perpage, true);
|
|
|
|
$participanttablehtml = ob_get_contents();
|
|
|
|
ob_end_clean();
|
2006-09-28 06:04:39 +00:00
|
|
|
|
2020-06-11 12:13:09 +08:00
|
|
|
echo html_writer::start_tag('form', [
|
|
|
|
'action' => 'action_redir.php',
|
|
|
|
'method' => 'post',
|
|
|
|
'id' => 'participantsform',
|
|
|
|
'data-course-id' => $course->id,
|
|
|
|
'data-table-unique-id' => $participanttable->uniqueid,
|
|
|
|
]);
|
|
|
|
echo '<div>';
|
|
|
|
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
|
|
|
echo '<input type="hidden" name="returnto" value="'.s($PAGE->url->out(false)).'" />';
|
2006-09-28 06:41:07 +00:00
|
|
|
|
2020-04-24 12:33:36 +08:00
|
|
|
echo html_writer::tag(
|
|
|
|
'p',
|
|
|
|
get_string('countparticipantsfound', 'core_user', $participanttable->totalrows),
|
|
|
|
[
|
|
|
|
'data-region' => 'participant-count',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2017-06-28 11:44:20 +08:00
|
|
|
echo $participanttablehtml;
|
2017-06-27 12:51:31 +08:00
|
|
|
|
2020-06-11 12:13:09 +08:00
|
|
|
$bulkoptions = (object) [
|
|
|
|
'uniqueid' => $participanttable->uniqueid,
|
|
|
|
];
|
|
|
|
|
2023-12-13 15:41:47 +01:00
|
|
|
echo '<br /><div class="buttons"><div class="d-flex flex-wrap align-items-center">';
|
2021-09-17 11:38:45 +01:00
|
|
|
|
|
|
|
echo html_writer::start_tag('div', array('class' => 'btn-group'));
|
|
|
|
|
|
|
|
if ($participanttable->get_page_size() < $participanttable->totalrows) {
|
|
|
|
// Select all users, refresh table showing all users and mark them all selected.
|
|
|
|
$label = get_string('selectalluserswithcount', 'moodle', $participanttable->totalrows);
|
|
|
|
echo html_writer::empty_tag('input', [
|
|
|
|
'type' => 'button',
|
|
|
|
'id' => 'checkall',
|
|
|
|
'class' => 'btn btn-secondary',
|
|
|
|
'value' => $label,
|
|
|
|
'data-target-page-size' => TABLE_SHOW_ALL_PAGE_SIZE,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
echo html_writer::end_tag('div');
|
|
|
|
$displaylist = array();
|
|
|
|
if (!empty($CFG->messaging) && has_all_capabilities(['moodle/site:sendmessage', 'moodle/course:bulkmessaging'], $context)) {
|
|
|
|
$displaylist['#messageselect'] = get_string('messageselectadd');
|
|
|
|
}
|
|
|
|
if (!empty($CFG->enablenotes) && has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) {
|
|
|
|
$displaylist['#addgroupnote'] = get_string('addnewnote', 'notes');
|
|
|
|
}
|
|
|
|
|
|
|
|
$params = ['operation' => 'download_participants'];
|
|
|
|
|
|
|
|
$downloadoptions = [];
|
|
|
|
$formats = core_plugin_manager::instance()->get_plugins_of_type('dataformat');
|
|
|
|
foreach ($formats as $format) {
|
|
|
|
if ($format->is_enabled()) {
|
|
|
|
$params = ['operation' => 'download_participants', 'dataformat' => $format->name];
|
|
|
|
$url = new moodle_url('bulkchange.php', $params);
|
|
|
|
$downloadoptions[$url->out(false)] = get_string('dataformat', $format->component);
|
2014-02-18 10:12:42 +13:00
|
|
|
}
|
2021-09-17 11:38:45 +01:00
|
|
|
}
|
2014-02-18 10:12:42 +13:00
|
|
|
|
2021-09-17 11:38:45 +01:00
|
|
|
if (!empty($downloadoptions)) {
|
|
|
|
$displaylist[] = [get_string('downloadas', 'table') => $downloadoptions];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($context->id != $frontpagectx->id) {
|
|
|
|
$instances = $manager->get_enrolment_instances();
|
|
|
|
$plugins = $manager->get_enrolment_plugins(false);
|
|
|
|
foreach ($instances as $key => $instance) {
|
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
|
|
|
// Weird, some broken stuff in plugin.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$plugin = $plugins[$instance->enrol];
|
|
|
|
$bulkoperations = $plugin->get_bulk_operations($manager);
|
2018-08-10 11:14:50 +02:00
|
|
|
|
2021-09-17 11:38:45 +01:00
|
|
|
$pluginoptions = [];
|
|
|
|
foreach ($bulkoperations as $key => $bulkoperation) {
|
|
|
|
$params = ['plugin' => $plugin->get_name(), 'operation' => $key];
|
2018-08-10 11:14:50 +02:00
|
|
|
$url = new moodle_url('bulkchange.php', $params);
|
2021-09-17 11:38:45 +01:00
|
|
|
$pluginoptions[$url->out(false)] = $bulkoperation->get_title();
|
|
|
|
}
|
|
|
|
if (!empty($pluginoptions)) {
|
|
|
|
$name = get_string('pluginname', 'enrol_' . $plugin->get_name());
|
|
|
|
$displaylist[] = [$name => $pluginoptions];
|
2018-08-10 11:14:50 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-17 11:38:45 +01:00
|
|
|
}
|
2018-08-10 11:14:50 +02:00
|
|
|
|
2021-09-17 11:38:45 +01:00
|
|
|
$selectactionparams = array(
|
|
|
|
'id' => 'formactionid',
|
|
|
|
'class' => 'ml-2',
|
|
|
|
'data-action' => 'toggle',
|
|
|
|
'data-togglegroup' => 'participants-table',
|
|
|
|
'data-toggle' => 'action',
|
|
|
|
'disabled' => 'disabled'
|
|
|
|
);
|
|
|
|
$label = html_writer::tag('label', get_string("withselectedusers"),
|
|
|
|
['for' => 'formactionid', 'class' => 'col-form-label d-inline']);
|
|
|
|
$select = html_writer::select($displaylist, 'formaction', '', ['' => 'choosedots'], $selectactionparams);
|
|
|
|
echo html_writer::tag('div', $label . $select);
|
2018-08-10 11:14:50 +02:00
|
|
|
|
2021-09-17 11:38:45 +01:00
|
|
|
echo '<input type="hidden" name="id" value="' . $course->id . '" />';
|
|
|
|
echo '<div class="d-none" data-region="state-help-icon">' . $OUTPUT->help_icon('publishstate', 'notes') . '</div>';
|
|
|
|
echo '</div></div></div>';
|
|
|
|
|
|
|
|
$bulkoptions->noteStateNames = note_get_state_names();
|
2017-07-21 09:50:28 +08:00
|
|
|
|
2020-06-11 12:13:09 +08:00
|
|
|
echo '</form>';
|
2006-09-28 04:45:39 +00:00
|
|
|
|
2020-06-11 12:13:09 +08:00
|
|
|
$PAGE->requires->js_call_amd('core_user/participants', 'init', [$bulkoptions]);
|
2014-02-18 10:12:42 +13:00
|
|
|
echo '</div>'; // Userlist.
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2017-06-28 10:25:45 +08:00
|
|
|
$enrolrenderer = $PAGE->get_renderer('core_enrol');
|
2020-03-12 00:55:20 +11:00
|
|
|
// Need to re-generate the buttons to avoid having elements with duplicate ids on the page.
|
|
|
|
$enrolbuttons = $manager->get_manual_enrol_buttons();
|
2020-06-03 16:52:57 +08:00
|
|
|
$enrolbuttonsout = '';
|
2017-06-28 10:25:45 +08:00
|
|
|
foreach ($enrolbuttons as $enrolbutton) {
|
2020-06-03 16:52:57 +08:00
|
|
|
$enrolbuttonsout .= $enrolrenderer->render($enrolbutton);
|
2017-06-28 10:25:45 +08:00
|
|
|
}
|
2020-06-03 16:52:57 +08:00
|
|
|
echo html_writer::div($enrolbuttonsout, 'd-flex justify-content-end', [
|
|
|
|
'data-region' => 'wrapper',
|
|
|
|
'data-table-uniqueid' => $participanttable->uniqueid,
|
|
|
|
]);
|
2017-06-28 10:25:45 +08:00
|
|
|
|
2014-02-18 10:12:42 +13:00
|
|
|
echo $OUTPUT->footer();
|