Exemplo n.º 1
0
 /**
  * Renders a course enrolment table
  *
  * @param course_enrolment_table $table
  * @return string
  */
 protected function render_course_enrolment_users_table(course_enrolment_users_table $table)
 {
     $table->initialise_javascript();
     $content = '';
     $enrolmentselector = $table->get_enrolment_selector();
     if ($enrolmentselector) {
         $content .= $this->output->render($enrolmentselector);
     }
     $cohortenroller = $table->get_cohort_enrolment_control();
     if ($cohortenroller) {
         $content .= $this->output->render($cohortenroller);
     }
     $content .= $this->output->render($table->get_enrolment_type_filter());
     $content .= $this->output->render($table->get_paging_bar());
     $content .= html_writer::table($table);
     $content .= $this->output->render($table->get_paging_bar());
     $enrolmentselector = $table->get_enrolment_selector();
     if ($enrolmentselector) {
         $content .= $this->output->render($enrolmentselector);
     }
     $cohortenroller = $table->get_cohort_enrolment_control();
     if ($cohortenroller) {
         $content .= $this->output->render($cohortenroller);
     }
     return $content;
 }
Exemplo n.º 2
0
    /**
     * Renders a course enrolment table
     *
     * @param course_enrolment_table $table
     * @return string
     */
    protected function render_course_enrolment_users_table(course_enrolment_users_table $table) {

        $table->initialise_javascript();

        $buttons = $table->get_manual_enrol_buttons();
        $buttonhtml = '';
        if (count($buttons) > 0) {
            $buttonhtml .= html_writer::start_tag('div', array('class' => 'enrol_user_buttons'));
            foreach ($buttons as $button) {
                $buttonhtml .= $this->render($button);
            }
            $buttonhtml .= html_writer::end_tag('div');
        }

        $content = '';
        if (!empty($buttonhtml)) {
            $content .= $buttonhtml;
        }
        $content .= $this->output->render($table->get_enrolment_type_filter());
        $content .= $this->output->render($table->get_paging_bar());

        // Check if the table has any bulk operations. If it does we want to wrap the table in a
        // form so that we can capture and perform any required bulk operations.
        if ($table->has_bulk_user_enrolment_operations()) {
            $content .= html_writer::start_tag('form', array('action' => new moodle_url('/enrol/bulkchange.php'), 'method' => 'post'));
            foreach ($table->get_combined_url_params() as $key => $value) {
                if ($key == 'action') {
                    continue;
                }
                $content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value));
            }
            $content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'bulkchange'));
            $content .= html_writer::table($table);
            $content .= html_writer::start_tag('div', array('class' => 'singleselect bulkuserop'));
            $content .= html_writer::start_tag('select', array('name' => 'bulkuserop'));
            $content .= html_writer::tag('option', get_string('withselectedusers', 'enrol'), array('value' => ''));
            $options = array('' => get_string('withselectedusers', 'enrol'));
            foreach ($table->get_bulk_user_enrolment_operations() as $operation) {
                $content .= html_writer::tag('option', $operation->get_title(), array('value' => $operation->get_identifier()));
            }
            $content .= html_writer::end_tag('select');
            $content .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
            $content .= html_writer::end_tag('div');

            $content .= html_writer::end_tag('form');
        } else {
            $content .= html_writer::table($table);
        }
        $content .= $this->output->render($table->get_paging_bar());
        if (!empty($buttonhtml)) {
            $content .= $buttonhtml;
        }
        return $content;
    }
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
// Get the user for whom the enrolment is
$user = $DB->get_record('user', array('id' => $ue->userid), '*', MUST_EXIST);
// Get the course the enrolment is to
list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
$sql = "SELECT c.* {$ctxsql}\n          FROM {course} c\n     LEFT JOIN {enrol} e ON e.courseid = c.id\n               {$ctxjoin}\n         WHERE e.id = :enrolid";
$params = array('enrolid' => $ue->enrolid);
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
context_instance_preload($course);
if ($course->id == SITEID) {
    redirect(new moodle_url('/'));
}
require_login($course);
require_capability("enrol/globalclassroom:unenrol", get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST));
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
// The URL of the enrolled users page for the course.
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
// The URl to return the user too after this screen.
$returnurl = new moodle_url($usersurl, $manager->get_url_params() + $table->get_url_params());
// The URL of this page
$url = new moodle_url('/enrol/globalclassroom/unenroluser.php', $returnurl->params());
$url->param('ue', $ueid);
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'globalclassroom' || !$plugin instanceof enrol_globalclassroom_plugin) {
    print_error('erroreditenrolment', 'enrol');
}
// If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
Exemplo n.º 4
0
$user = $DB->get_record('user', array('id' => $ue->userid), '*', MUST_EXIST);
$instance = $DB->get_record('enrol', array('id' => $ue->enrolid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
// set up PAGE url first!
$PAGE->set_url('/enrol/unenroluser.php', array('ue' => $ueid, 'ifilter' => $filter));
require_login($course);
if (!enrol_is_enabled($instance->enrol)) {
    print_error('erroreditenrolment', 'enrol');
}
$plugin = enrol_get_plugin($instance->enrol);
if (!$plugin->allow_unenrol_user($instance, $ue) or !has_capability("enrol/{$instance->enrol}:unenrol", $context)) {
    print_error('erroreditenrolment', 'enrol');
}
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
$returnurl = new moodle_url('/enrol/users.php', array('id' => $course->id) + $manager->get_url_params() + $table->get_url_params());
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
// If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
if ($confirm && confirm_sesskey()) {
    $plugin->unenrol_user($instance, $ue->userid);
    redirect($returnurl);
}
$yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unenrolconfirm', 'core_enrol', array('user' => fullname($user, true), 'course' => format_string($course->fullname)));
$fullname = fullname($user);
$title = get_string('unenrol', 'core_enrol');
$PAGE->set_title($title);
$PAGE->set_heading($title);
Exemplo n.º 5
0
$id = required_param('id', PARAM_INT);
// course id
$bulkuserop = required_param('bulkuserop', PARAM_ALPHANUMEXT);
$userids = required_param_array('bulkuser', PARAM_INT);
$action = optional_param('action', '', PARAM_ACTION);
$filter = optional_param('ifilter', 0, PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
if ($course->id == SITEID) {
    redirect(new moodle_url('/'));
}
require_login($course);
require_capability('moodle/course:enrolreview', $context);
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
$returnurl = new moodle_url('/enrol/users.php', $table->get_combined_url_params());
$actionurl = new moodle_url('/enrol/bulkchange.php', $table->get_combined_url_params() + array('bulkuserop' => $bulkuserop));
$PAGE->set_url($actionurl);
navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
$ops = $table->get_bulk_user_enrolment_operations();
if (!array_key_exists($bulkuserop, $ops)) {
    throw new moodle_exception('invalidbulkenrolop');
}
$operation = $ops[$bulkuserop];
// Prepare the properties of the form
$users = $manager->get_users_enrolments($userids);
// Get the form for the bulk operation
$mform = $operation->get_form($actionurl, array('users' => $users));
// If the mform is false then attempt an immediate process. This may be an immediate action that
// doesn't require user input OR confirmation.... who know what but maybe one day
Exemplo n.º 6
0
$status = optional_param('status', -1, PARAM_INT);
$newcourse = optional_param('newcourse', false, PARAM_BOOL);
// When users reset the form, redirect back to first page without other params.
if (optional_param('resetbutton', '', PARAM_RAW) !== '') {
    redirect('users.php?id=' . $id . '&newcourse=' . $newcourse);
}
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
if ($course->id == SITEID) {
    redirect(new moodle_url('/'));
}
require_login($course);
require_capability('moodle/course:enrolreview', $context);
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($PAGE, $course, $filter, $role, $search, $fgroup, $status);
$table = new course_enrolment_users_table($manager, $PAGE);
$PAGE->set_url('/enrol/users.php', $manager->get_url_params() + $table->get_url_params() + array('newcourse' => $newcourse));
navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
// Check if there is an action to take
if ($action) {
    // Check if the page is confirmed (and sesskey is correct)
    $confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
    $actiontaken = false;
    $pagetitle = '';
    $pageheading = '';
    $mform = null;
    $pagecontent = null;
    switch ($action) {
        /**
         * Removes a role from the user with this course
         */
Exemplo n.º 7
0
require_once "{$CFG->dirroot}/enrol/renderer.php";
require_once "{$CFG->dirroot}/group/lib.php";
$id = required_param('id', PARAM_INT);
// course id
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
$filter = optional_param('ifilter', 0, PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
if ($course->id == SITEID) {
    redirect(new moodle_url('/'));
}
require_login($course);
require_capability('moodle/course:enrolreview', $context);
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
$PAGE->set_url('/enrol/users.php', $manager->get_url_params() + $table->get_url_params());
navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
// Check if there is an action to take
if ($action) {
    // Check if the page is confirmed (and sesskey is correct)
    $confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
    $actiontaken = false;
    $pagetitle = '';
    $pageheading = '';
    $mform = null;
    $pagecontent = null;
    switch ($action) {
        /**
         * Removes a role from the user with this course
         */
Exemplo n.º 8
0
require_once "{$CFG->dirroot}/group/lib.php";
$id = required_param('id', PARAM_INT);
// course id
$action = optional_param('action', '', PARAM_ACTION);
$filter = optional_param('ifilter', 0, PARAM_INT);
$PAGE->set_url(new moodle_url('/enrol/users.php', array('id' => $id)));
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
if ($course->id == SITEID) {
    redirect(new moodle_url('/'));
}
require_login($course);
require_capability('moodle/course:enrolreview', $context);
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE->url);
$pageurl = new moodle_url($PAGE->url, $manager->get_url_params() + $table->get_url_params());
// Check if there is an action to take
if ($action) {
    // Check if the page is confirmed (and sesskey is correct)
    $confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
    $actiontaken = false;
    $pagetitle = '';
    $pageheading = '';
    $mform = null;
    $pagecontent = null;
    switch ($action) {
        /**
         * Unenrols a user from this course
         */
        case 'unenrol':