diff --git a/enrol/cohort/locallib.php b/enrol/cohort/locallib.php index 1cbe91129af..100c7e9e703 100644 --- a/enrol/cohort/locallib.php +++ b/enrol/cohort/locallib.php @@ -219,13 +219,13 @@ function enrol_cohort_enrol_all_users(course_enrolment_manager $manager, $cohort return false; } $sql = "SELECT com.userid - FROM {cohort_members} com - LEFT JOIN ( + FROM {cohort_members} com + LEFT JOIN ( SELECT * FROM {user_enrolments} ue WHERE ue.enrolid = :enrolid - ) ue ON ue.userid=com.userid - WHERE com.cohortid = :cohortid AND ue.id IS NULL"; + ) ue ON ue.userid=com.userid + WHERE com.cohortid = :cohortid AND ue.id IS NULL"; $params = array('cohortid' => $cohortid, 'enrolid' => $instance->id); $rs = $DB->get_recordset_sql($sql, $params); $count = 0; diff --git a/enrol/locallib.php b/enrol/locallib.php index f117910b897..9c1077fdf83 100644 --- a/enrol/locallib.php +++ b/enrol/locallib.php @@ -160,18 +160,17 @@ class course_enrolment_manager { list($ctxcondition, $params) = $DB->get_in_or_equal(get_parent_contexts($this->context, true), SQL_PARAMS_NAMED, 'ctx'); $params['courseid'] = $this->course->id; $sql = "SELECT COUNT(DISTINCT u.id) - FROM {role_assignments} ra - JOIN {user} u ON u.id = ra.userid - JOIN {context} ctx ON ra.contextid = ctx.id - LEFT JOIN ( - SELECT ue.id, ue.userid - FROM {user_enrolments} ue + FROM {role_assignments} ra + JOIN {user} u ON u.id = ra.userid + JOIN {context} ctx ON ra.contextid = ctx.id + LEFT JOIN ( + SELECT ue.id, ue.userid + FROM {user_enrolments} ue LEFT JOIN {enrol} e ON e.id=ue.enrolid - WHERE e.courseid = :courseid - ) ue ON ue.userid=u.id - WHERE - ctx.id $ctxcondition AND - ue.id IS NULL"; + WHERE e.courseid = :courseid + ) ue ON ue.userid=u.id + WHERE ctx.id $ctxcondition AND + ue.id IS NULL"; $this->totalotherusers = (int)$DB->count_records_sql($sql, $params); } return $this->totalotherusers; @@ -245,17 +244,16 @@ class course_enrolment_manager { FROM {role_assignments} ra JOIN {user} u ON u.id = ra.userid JOIN {context} ctx ON ra.contextid = ctx.id - LEFT JOIN ( - SELECT ue.id, ue.userid, ul.timeaccess AS lastseen - FROM {user_enrolments} ue - LEFT JOIN {enrol} e ON e.id=ue.enrolid - LEFT JOIN {user_lastaccess} ul ON (ul.courseid = e.courseid AND ul.userid = ue.userid) + LEFT JOIN ( + SELECT ue.id, ue.userid, ul.timeaccess AS lastseen + FROM {user_enrolments} ue + LEFT JOIN {enrol} e ON e.id=ue.enrolid + LEFT JOIN {user_lastaccess} ul ON (ul.courseid = e.courseid AND ul.userid = ue.userid) WHERE e.courseid = :courseid - ) ue ON ue.userid=u.id - WHERE - ctx.id $ctxcondition AND - ue.id IS NULL - ORDER BY u.$sort $direction, ctx.depth DESC"; + ) ue ON ue.userid=u.id + WHERE ctx.id $ctxcondition AND + ue.id IS NULL + ORDER BY u.$sort $direction, ctx.depth DESC"; $this->otherusers[$key] = $DB->get_records_sql($sql, $params, $page*$perpage, $perpage); } return $this->otherusers[$key]; @@ -351,11 +349,11 @@ class course_enrolment_manager { $countfields = 'SELECT COUNT(u.id)'; $sql = " FROM {user} u WHERE $wherecondition - AND u.id NOT IN ( + AND u.id NOT IN ( SELECT u.id FROM {role_assignments} r, {user} u - WHERE r.contextid = :contextid - AND u.id = r.userid)"; + WHERE r.contextid = :contextid AND + u.id = r.userid)"; $order = ' ORDER BY lastname ASC, firstname ASC'; $params['contextid'] = $this->context->id; diff --git a/enrol/manual/editenrolment.php b/enrol/manual/editenrolment.php index f22baa6b761..e749fab6cdf 100644 --- a/enrol/manual/editenrolment.php +++ b/enrol/manual/editenrolment.php @@ -84,9 +84,16 @@ if (!$plugin->allow_manage($instance) || $instance->enrol != 'manual' || !($plug $mform = new enrol_manual_user_enrolment_form($url, array('user'=>$user, 'course'=>$course, 'ue'=>$ue)); $mform->set_data($PAGE->url->params()); -$data = $mform->get_data(); -if ($mform->is_cancelled() || ($data && $manager->edit_enrolment($ue, $data))) { + +// Check the form hasn't been cancelled +if ($mform->is_cancelled()) { redirect($returnurl); +} else if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) { + // The forms been submit, validated and the sesskey has been checked ... edit the enrolment. + $data = $mform->get_data(); + if ($manager->edit_enrolment($ue, $data)) { + redirect($returnurl); + } } $fullname = fullname($user); diff --git a/enrol/manual/locallib.php b/enrol/manual/locallib.php index f10290d4293..2387b0517cb 100644 --- a/enrol/manual/locallib.php +++ b/enrol/manual/locallib.php @@ -53,11 +53,11 @@ class enrol_manual_potential_participant extends user_selector_base { $countfields = 'SELECT COUNT(1)'; $sql = " FROM {user} u - WHERE $wherecondition - AND u.id NOT IN (SELECT ue.userid - FROM {user_enrolments} ue - JOIN {enrol} e ON (e.id = ue.enrolid AND e.id = :enrolid))"; - + WHERE $wherecondition AND + u.id NOT IN ( + SELECT ue.userid + FROM {user_enrolments} ue + JOIN {enrol} e ON (e.id = ue.enrolid AND e.id = :enrolid))"; $order = ' ORDER BY u.lastname ASC, u.firstname ASC'; if (!$this->is_validating()) { diff --git a/enrol/manual/unenroluser.php b/enrol/manual/unenroluser.php index 5bfc12db1ec..4157ed984a5 100644 --- a/enrol/manual/unenroluser.php +++ b/enrol/manual/unenroluser.php @@ -75,7 +75,8 @@ if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'manual' || !($plu print_error('erroreditenrolment', 'enrol'); } -if ($confirm && $manager->unenrol_user($ue)) { +// If the unenrolment has been confirmed and the sesskey is valid unenrol the user. +if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) { redirect($returnurl); } diff --git a/enrol/self/editenrolment.php b/enrol/self/editenrolment.php index 3d87f74ec6f..4449d342c00 100644 --- a/enrol/self/editenrolment.php +++ b/enrol/self/editenrolment.php @@ -87,10 +87,16 @@ if (!$plugin->allow_manage($instance) || $instance->enrol != 'self' || !($plugin // Get the self enrolment edit form $mform = new enrol_self_user_enrolment_form($url, array('user'=>$user, 'course'=>$course, 'ue'=>$ue)); $mform->set_data($PAGE->url->params()); -$data = $mform->get_data(); -// Process the form and edit the enrolment if required. -if ($mform->is_cancelled() || ($data && $manager->edit_enrolment($ue, $data))) { + +// Check the form hasn't been cancelled +if ($mform->is_cancelled()) { redirect($returnurl); +} else if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) { + // The forms been submit, validated and the sesskey has been checked ... edit the enrolment. + $data = $mform->get_data(); + if ($manager->edit_enrolment($ue, $data)) { + redirect($returnurl); + } } $fullname = fullname($user); diff --git a/enrol/self/unenroluser.php b/enrol/self/unenroluser.php index 52c1b0354d2..a0c670409b0 100644 --- a/enrol/self/unenroluser.php +++ b/enrol/self/unenroluser.php @@ -80,7 +80,8 @@ if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'self' || !($plugi print_error('erroreditenrolment', 'enrol'); } -if ($confirm && $manager->unenrol_user($ue)) { +// If the unenrolment has been confirmed and the sesskey is valid unenrol the user. +if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) { redirect($returnurl); }