Index: admin/mnet/enr_hosts.php
===================================================================
--- admin/mnet/enr_hosts.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ admin/mnet/enr_hosts.php (revision )
@@ -8,10 +8,8 @@
admin_externalpage_setup('mnetenrol');
- require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
+ $enrolment = enrol_get_plugin('mnet');
- $enrolment = enrolment_factory::factory('mnet');
-
/// Otherwise fill and print the form.
/// get language strings
Index: group/assign.php
===================================================================
--- group/assign.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ group/assign.php (revision )
@@ -86,9 +86,9 @@
}
// Get course managers so they can be hilited in the list
- if ($managerroles = get_config('', 'coursemanager')) {
- $coursemanagerroles = split(',', $managerroles);
- foreach ($coursemanagerroles as $roleid) {
+ if ($managerroles = get_config('', 'coursecontact')) {
+ $coursecontactroles = split(',', $managerroles);
+ foreach ($coursecontactroles as $roleid) {
$role = $DB->get_record('role', array('id'=>$roleid));
$managers = get_role_users($roleid, $context, true, 'u.id', 'u.id ASC');
}
Index: enrol/authorize/db/upgrade.php
===================================================================
--- enrol/authorize/db/upgrade.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ enrol/authorize/db/upgrade.php (revision )
@@ -28,7 +28,7 @@
//===== 1.9.0 upgrade line ======//
- if ($result && $oldversion < 2008020500 && is_enabled_enrol('authorize')) {
+ if ($result && $oldversion < 2008020500 && enrol_is_enabled('authorize')) {
require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php');
if (!check_curl_available()) {
echo $OUTPUT->notification("You are using the authorize.net enrolment plugin for payment handling but cUrl is not available.
Index: enrol/database/enrol.php
===================================================================
--- enrol/database/enrol.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ enrol/database/enrol.php (revision )
@@ -1,7 +1,6 @@
libdir.'/adodb/adodb.inc.php');
-require_once($CFG->dirroot.'/enrol/enrol.class.php');
class enrolment_plugin_database {
@@ -146,7 +145,8 @@
}
//error_log('[ENROL_DB] Enrolling user in course '.$course->idnumber);
- role_assign($role->id, $user->id, 0, $context->id, 0, 0, 0, 'database');
+ //TODO: do some real enrolment here
+ role_assign($role->id, $user->id, $context->id, 'enrol_database');
}
} // We've processed all external courses found
@@ -157,7 +157,7 @@
foreach ($existing as $role_assignment) {
if ($role_assignment->enrol == 'database') {
//error_log('[ENROL_DB] Removing user from context '.$role_assignment->contextid);
- role_unassign($role_assignment->roleid, $user->id, '', $role_assignment->contextid);
+ role_unassign($role_assignment->roleid, $user->id, $role_assignment->contextid);
}
}
}
@@ -318,14 +318,11 @@
if ($to_prune) {
foreach ($to_prune as $role_assignment) {
- if (role_unassign($role->id, $role_assignment->userid, 0, $role_assignment->contextid)){
+ role_unassign($role->id, $role_assignment->userid, $role_assignment->contextid);
- error_log( "Unassigned {$role->shortname} assignment #{$role_assignment->id} for course {$course->id} (" . format_string($course->shortname) . "); user {$role_assignment->userid}");
+ error_log( "Unassigned {$role->shortname} assignment #{$role_assignment->id} for course {$course->id} (" . format_string($course->shortname) . "); user {$role_assignment->userid}");
- } else {
- error_log( "Failed to unassign {$role->shortname} assignment #{$role_assignment->id} for course {$course->id} (" . format_string($course->shortname) . "); user {$role_assignment->userid}");
- }
- }
- }
+ }
+ }
+ }
- }
//
// insert current enrolments
@@ -359,7 +356,8 @@
continue;
}
- if (role_assign($role->id, $userid, 0, $context->id, 0, 0, 0, 'database')){
+ //TODO: real enrolment here
+ if (role_assign($role->id, $userid, $context->id, 'enrol_database')){
error_log( "Assigned role {$role->shortname} to user {$userid} in course {$course->id} (" . format_string($course->shortname) . ")");
} else {
error_log( "Failed to assign role {$role->shortname} to user {$userid} in course {$course->id} (" . format_string($course->shortname) . ")");
@@ -409,12 +407,9 @@
$roleid = $user_obj->roleid;
$user = $user_obj->userid;
$contextid = $user_obj->contextid;
- if (role_unassign($roleid, $user, 0, $contextid)){
+ role_unassign($roleid, $user, $contextid);
- error_log( "Unassigned role {$roleid} from user $user in context $contextid");
+ error_log( "Unassigned role {$roleid} from user $user in context $contextid");
- } else {
- error_log( "Failed unassign role {$roleid} from user $user in context $contextid");
- }
+ }
- }
$ers->close(); // release the handle
}
Index: enrol/manual/lang/en/enrol_manual.php
===================================================================
--- enrol/manual/lang/en/enrol_manual.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ enrol/manual/lang/en/enrol_manual.php (revision )
@@ -23,16 +23,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-$string['description'] = 'This is the default form of enrolment. There are two main ways a student can be enrolled in a particular course.
-
-
A teacher or admin can enrol them manually using the link in the Course Administration menu
- within the course.
-
A course can have a password defined, known as an "enrolment key". Anyone who knows this key is
- able to add themselves to a course.
-
';
-$string['enrol_manual_requirekey'] = 'Require course enrolment keys in new courses and prevent removing of existing keys.';
-$string['enrol_manual_showhint'] = 'Enable this setting to reveal the first character of the enrolment key as a hint if one enters an incorrect key.';
-$string['enrol_manual_usepasswordpolicy'] = 'Use current user password policy for course enrolment keys.';
-$string['enrolmentkeyerror'] = 'That enrolment key was incorrect, please try again.';
-$string['enrolname'] = 'Internal Enrolment';
-$string['keyholderrole'] = 'The role of the user that holds the enrolment key for a course. Displayed to students attempting to enrol on the course.';
+$string['assignrole'] = 'Assignrole';
+$string['defaultperiod'] = 'Default enrolment period';
+$string['defaultperiod_desc'] = 'Default length of the default enrolment period setting (in seconds).'; //TODO: fixme
+$string['pluginname'] = 'Internal enrolments';
+$string['pluginname_desc'] = 'Internal enrolments is a basic enrolment plugin which allows simple user enrolments. It should be kept enabled in most cases. Some other plugins such as self enrolment may use this pugin internally.';
+$string['status'] = 'Enable internal enrolments';
+$string['status_desc'] = 'Allow course access of internally enrolled users. This should be kept enabled in most cases.';
+$string['statusenabled'] = 'Enabled';
+$string['statusdisabled'] = 'Disabled';
Index: enrol/self/locallib.php
===================================================================
--- enrol/self/locallib.php (revision )
+++ enrol/self/locallib.php (revision )
@@ -0,0 +1,82 @@
+.
+
+/**
+ * Selfenrol plugin implementation.
+ *
+ * @package enrol_self
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once("$CFG->libdir/formslib.php");
+
+class enrol_self_enrol_form extends moodleform {
+ protected $instance;
+
+ public function definition() {
+ $mform = $this->_form;
+ $instance = $this->_customdata;
+ $this->instance = $instance;
+ $plugin = enrol_get_plugin('self');
+
+ if ($instance->password) {
+ $heading = $plugin->get_instance_name($instance);
+ $mform->addElement('header', 'selfheader', $heading);
+ $mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_self'));
+ } else {
+ // nothing?
+ }
+
+ $this->add_action_buttons(false, get_string('enrolme', 'enrol_self'));
+
+ $mform->addElement('hidden', 'id');
+ $mform->setType('id', PARAM_INT);
+ $mform->setDefault('id', $instance->courseid);
+
+ $mform->addElement('hidden', 'instance');
+ $mform->setType('instance', PARAM_INT);
+ $mform->setDefault('instance', $instance->id);
+ }
+
+ public function validation($data, $files) {
+ global $DB, $CFG;
+
+ $errors = parent::validation($data, $files);
+ $instance = $this->instance;
+
+ if ($instance->password) {
+ if ($data['enrolpassword'] !== $instance->password) {
+ if ($instance->customint1) {
+ //TODO: check groups
+
+ } else {
+ $plugin = enrol_get_plugin('self');
+ if ($plugin->get_config('showhint')) {
+ $textlib = textlib_get_instance();
+ $hint = $textlib->substr($instance->password, 0, 1);
+ $errors['enrolpassword'] = get_string('passwordinvalidhint', 'enrol_self', $hint);
+ } else {
+ $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
+ }
+ }
+ }
+ }
+
+ return $errors;
+ }
+}
\ No newline at end of file
Index: enrol/authorize/locallib.php
===================================================================
--- enrol/authorize/locallib.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ enrol/authorize/locallib.php (revision )
@@ -358,7 +358,7 @@
}
else {
if (!empty($unenrol)) {
- role_unassign(0, $order->userid, 0, $coursecontext->id);
+ role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
}
redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid");
}
@@ -383,7 +383,7 @@
elseif (ORDER_DELETE == $do && in_array(ORDER_DELETE, $statusandactions->actions)) {
if ($confirm && confirm_sesskey()) {
if (!empty($unenrol)) {
- role_unassign(0, $order->userid, 0, $coursecontext->id);
+ role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
}
$DB->delete_records('enrol_authorize', array('id'=>$orderid));
redirect("$CFG->wwwroot/enrol/authorize/index.php");
@@ -436,7 +436,7 @@
if (AN_APPROVED == AuthorizeNet::process($suborder, $message, $extra, AN_ACTION_VOID)) {
if (empty($CFG->an_test)) {
if (!empty($unenrol)) {
- role_unassign(0, $order->userid, 0, $coursecontext->id);
+ role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true);
}
redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid");
}
Index: lib/moodlelib.php
===================================================================
--- lib/moodlelib.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ lib/moodlelib.php (revision )
@@ -2163,80 +2163,85 @@
* When $cm parameter specified, this function sets page layout to 'module'.
* You need to change it manually later if some other layout needed.
*
- * @global object
- * @global object
- * @global object
- * @global object
- * @global string
- * @global object
- * @global object
- * @global object
- * @uses SITEID Define
* @param mixed $courseorid id of the course or course object
* @param bool $autologinguest default true
* @param object $cm course module object
* @param bool $setwantsurltome Define if we want to set $SESSION->wantsurl, defaults to
* true. Used to avoid (=false) some scripts (file.php...) to set that variable,
* in order to keep redirects working properly. MDL-14495
+ * @param bool $preventredirect set to true in scripts that can not redirect (CLI, rss feeds, etc.), throws exceptions
* @return mixed Void, exit, and die depending on path
*/
-function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsurltome=true) {
- global $CFG, $SESSION, $USER, $COURSE, $FULLME, $PAGE, $SITE, $DB, $OUTPUT;
+function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $setwantsurltome = true, $preventredirect = false) {
+ global $CFG, $SESSION, $USER, $FULLME, $PAGE, $SITE, $DB, $OUTPUT;
-/// setup global $COURSE, themes, language and locale
+ // setup global $COURSE, themes, language and locale
if (!empty($courseorid)) {
if (is_object($courseorid)) {
$course = $courseorid;
} else if ($courseorid == SITEID) {
$course = clone($SITE);
} else {
- $course = $DB->get_record('course', array('id' => $courseorid));
- if (!$course) {
- throw new moodle_exception('invalidcourseid');
+ $course = $DB->get_record('course', array('id' => $courseorid), '*', MUST_EXIST);
- }
+ }
- }
if ($cm) {
+ if ($cm->course != $course->id) {
+ throw new coding_exception('course and cm parameters in require_login() call do not match!!');
+ }
$PAGE->set_cm($cm, $course); // set's up global $COURSE
$PAGE->set_pagelayout('incourse');
} else {
$PAGE->set_course($course); // set's up global $COURSE
}
} else {
- // do not touch global $COURSE via $PAGE->set_course() !!
+ // do not touch global $COURSE via $PAGE->set_course(),
+ // the reasons is we need to be able to call require_login() at any time!!
+ $course = $SITE;
+ if ($cm) {
+ throw new coding_exception('cm parameter in require_login() requires valid course parameter!');
- }
+ }
+ }
-/// If the user is not even logged in yet then make sure they are
+ // If the user is not even logged in yet then make sure they are
if (!isloggedin()) {
//NOTE: $USER->site check was obsoleted by session test cookie,
// $USER->confirmed test is in login/index.php
+ if ($preventredirect) {
+ throw new require_login_exception('You are not logged in');
+ }
+
if ($setwantsurltome) {
$SESSION->wantsurl = $FULLME;
}
if (!empty($_SERVER['HTTP_REFERER'])) {
$SESSION->fromurl = $_SERVER['HTTP_REFERER'];
}
- if ($autologinguest and !empty($CFG->guestloginbutton) and !empty($CFG->autologinguests) and ($COURSE->id == SITEID or $COURSE->guest) ) {
+ if ($autologinguest and !empty($CFG->guestloginbutton) and !empty($CFG->autologinguests)) {
+ if ($course->id == SITEID) {
- $loginguest = true;
- } else {
- $loginguest = false;
- }
+ $loginguest = true;
+ } else {
+ $loginguest = false;
+ }
+ } else {
+ $loginguest = false;
+ }
redirect(get_login_url($loginguest));
exit; // never reached
}
-/// loginas as redirection if needed
- if ($COURSE->id != SITEID and session_is_loggedinas()) {
+ // loginas as redirection if needed
+ if ($course->id != SITEID and session_is_loggedinas()) {
if ($USER->loginascontext->contextlevel == CONTEXT_COURSE) {
- if ($USER->loginascontext->instanceid != $COURSE->id) {
+ if ($USER->loginascontext->instanceid != $course->id) {
print_error('loginasonecourse', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid);
}
}
}
-/// check whether the user should be changing password (but only if it is REALLY them)
+ // check whether the user should be changing password (but only if it is REALLY them)
if (get_user_preferences('auth_forcepasswordchange') && !session_is_loggedinas()) {
$userauth = get_auth_plugin($USER->auth);
- if ($userauth->can_change_password()) {
+ if ($userauth->can_change_password() and !$preventredirect) {
$SESSION->wantsurl = $FULLME;
if ($changeurl = $userauth->change_password_url()) {
//use plugin custom url
@@ -2255,154 +2260,235 @@
}
}
-/// Check that the user account is properly set up
+ // Check that the user account is properly set up
if (user_not_fully_set_up($USER)) {
+ if ($preventredirect) {
+ throw new require_login_exception('User not fully set-up');
+ }
$SESSION->wantsurl = $FULLME;
redirect($CFG->wwwroot .'/user/edit.php?id='. $USER->id .'&course='. SITEID);
}
-/// Make sure the USER has a sesskey set up. Used for checking script parameters.
+ // Make sure the USER has a sesskey set up. Used for CSRF protection.
sesskey();
+ // Do not bother admins with any formalities, no last access updates either
+ if (is_siteadmin()) {
+ return;
+ }
+
// Check that the user has agreed to a site policy if there is one
if (!empty($CFG->sitepolicy)) {
+ if ($preventredirect) {
+ throw new require_login_exception('Policy not agreed');
+ }
if (!$USER->policyagreed) {
$SESSION->wantsurl = $FULLME;
redirect($CFG->wwwroot .'/user/policy.php');
}
}
- // Fetch the system context, we are going to use it a lot.
+ // Fetch the system context, the course context, and prefetch its child contexts
$sysctx = get_context_instance(CONTEXT_SYSTEM);
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
+ if ($cm) {
+ $cmcontext = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST);
+ } else {
+ $cmcontext = null;
+ }
-/// If the site is currently under maintenance, then print a message
+ // If the site is currently under maintenance, then print a message
if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', $sysctx)) {
+ if ($preventredirect) {
+ throw new require_login_exception('Maintenance in progress');
+ }
+
print_maintenance_message();
}
-/// groupmembersonly access control
- if (!empty($CFG->enablegroupmembersonly) and $cm and $cm->groupmembersonly and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
- if (isguestuser() or !groups_has_membership($cm)) {
- print_error('groupmembersonlyerror', 'group', $CFG->wwwroot.'/course/view.php?id='.$cm->course);
+ // make sure the course itself is not hidden
+ if ($course->id == SITEID) {
+ // frontpage can not be hidden
+ } else {
+ if (!empty($USER->access['rsw'][$coursecontext->path])) {
+ // when switching roles ignore the hidden flag - user had to be in course to do the switch
+ } else {
+ if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
+ // originally there was also test of parent category visibility,
+ // BUT is was very slow in complex queries involving "my courses"
+ // now it is also possible to simply hide all courses user is not enrolled in :-)
+ if ($preventredirect) {
+ throw new require_login_exception('Course is hidden');
- }
+ }
+ notice(get_string('coursehidden'), $CFG->wwwroot .'/');
- }
+ }
-
- // Fetch the course context, and prefetch its child contexts
- $coursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id, MUST_EXIST);
- if ($cm) {
- $cmcontext = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST);
- }
+ }
-
- // Conditional activity access control
- if (!empty($CFG->enableavailability) and $cm) {
- // We cache conditional access in session
- if (!isset($SESSION->conditionaccessok)) {
- $SESSION->conditionaccessok = array();
- }
+ }
- // If you have been allowed into the module once then you are allowed
- // in for rest of session, no need to do conditional checks
- if (!array_key_exists($cm->id, $SESSION->conditionaccessok)) {
- // Get condition info (does a query for the availability table)
- require_once($CFG->libdir.'/conditionlib.php');
- $ci = new condition_info($cm, CONDITION_MISSING_EXTRATABLE);
- // Check condition for user (this will do a query if the availability
- // information depends on grade or completion information)
- if ($ci->is_available($junk) || has_capability('moodle/course:viewhiddenactivities', $cmcontext)) {
- $SESSION->conditionaccessok[$cm->id] = true;
+
+ // is the user enrolled?
+ if ($course->id == SITEID) {
+ // everybody is enrolled on the frontpage
+
- } else {
+ } else {
- print_error('activityiscurrentlyhidden');
+ if (session_is_loggedinas()) {
+ // Make sure the REAL person can access this course first
+ $realuser = session_get_realuser();
+ if (!is_enrolled($coursecontext, $realuser->id, '', true) and !is_viewing($coursecontext, $realuser->id) and !is_siteadmin($realuser->id)) {
+ if ($preventredirect) {
+ throw new require_login_exception('Invalid course login-as access');
- }
+ }
+ echo $OUTPUT->header();
+ notice(get_string('studentnotallowed', '', fullname($USER, true)), $CFG->wwwroot .'/');
- }
- }
+ }
+ }
- if ($COURSE->id == SITEID) {
- /// Eliminate hidden site activities straight away
- if ($cm && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $cmcontext)) {
- redirect($CFG->wwwroot, get_string('activityiscurrentlyhidden'));
+ // very simple enrolment caching - changes in course setting are not reflected immediately
+ if (!isset($USER->enrol)) {
+ $USER->enrol = array();
+ $USER->enrol['enrolled'] = array();
+ $USER->enrol['tempguest'] = array();
}
- user_accesstime_log($COURSE->id); /// Access granted, update lastaccess times
- return;
- } else {
+ $access = false;
- /// Check if the user can be in a particular course
- if (empty($USER->access['rsw'][$coursecontext->path])) {
- //
- // MDL-13900 - If the course or the parent category are hidden
- // and the user hasn't the 'course:viewhiddencourses' capability, prevent access
- //
- if ( !($COURSE->visible && course_parent_visible($COURSE)) && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
- echo $OUTPUT->header();
- notice(get_string('coursehidden'), $CFG->wwwroot .'/');
+ if (is_viewing($coursecontext, $USER)) {
+ // ok, no need to mess with enrol
+ $access = true;
+
+ } else {
+ if (isset($USER->enrol['enrolled'][$course->id])) {
+ if ($USER->enrol['enrolled'][$course->id] == 0) {
+ $access = true;
+ } else if ($USER->enrol['enrolled'][$course->id] > time()) {
+ $access = true;
+ } else {
+ //expired
+ unset($USER->enrol['enrolled'][$course->id]);
- }
- }
+ }
+ }
-
- if (is_enrolled($coursecontext) or is_viewing($coursecontext)) {
- // Enrolled user or allowed to visit course (managers, inspectors, etc.)
- if (session_is_loggedinas()) { // Make sure the REAL person can also access this course
- $realuser = session_get_realuser();
- if (!is_enrolled($coursecontext, $realuser->id) and !is_viewing($coursecontext, $realuser->id) and !is_siteadmin($realuser->id)) {
- echo $OUTPUT->header();
- notice(get_string('studentnotallowed', '', fullname($USER, true)), $CFG->wwwroot .'/');
+ if (isset($USER->enrol['tempguest'][$course->id])) {
+ if ($USER->enrol['tempguest'][$course->id] == 0) {
+ $access = true;
+ } else if ($USER->enrol['tempguest'][$course->id] > time()) {
+ $access = true;
+ } else {
+ //expired
+ unset($USER->enrol['tempguest'][$course->id]);
+ $USER->access = remove_temp_roles($coursecontext, $USER->access);
}
}
- // Make sure they can read this activity too, if specified
- if ($cm && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $cmcontext)) {
- redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
+ if ($access) {
+ // cache ok
+ } else if (is_enrolled($coursecontext, $USER, '', true)) {
+ // active participants may always access
+ // TODO: refactor this into some new function
+ $now = time();
+ $sql = "SELECT MAX(cp.timeend)
+ FROM {course_participants} cp
+ JOIN {enrol} e ON (e.id = cp.enrolid AND e.courseid = :courseid)
+ JOIN {user} u ON u.id = cp.userid
+ WHERE cp.userid = :userid AND cp.status = :active AND e.status = :enabled AND u.deleted = 0
+ AND cp.timestart < :now1 AND (cp.timeend = 0 OR cp.timeend > :now2)";
+ $params = array('enabled'=>ENROL_STATUS_ENABLED, 'active'=>ENROL_PARTICIPATION_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_accesstime_log($COURSE->id); /// Access granted, update lastaccess times
- return; // User is allowed to see this course
+ $USER->enrol['enrolled'][$course->id] = $until;
+ $access = true;
+
+ // remove traces of previous temp guest access
+ $USER->access = remove_temp_roles($coursecontext, $USER->access);
+
- } else {
+ } else {
- // guest access
- switch ($COURSE->guest) { /// Check course policy about guest access
+ $instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'status'=>ENROL_STATUS_ENABLED), 'sortorder, id ASC');
+ $enrols = enrol_get_plugins(true);
+ // first ask all enabled enrol instances in course if they want to auto enrol user
+ foreach($instances as $instance) {
+ if (!isset($enrols[$instance->enrol])) {
+ continue;
+ }
+ $until = $enrols[$instance->enrol]->try_autoenrol($instance);
+ if ($until !== false) {
+ $USER->enrol['enrolled'][$course->id] = $until;
+ $USER->access = remove_temp_roles($coursecontext, $USER->access);
+ $access = true;
+ break;
+ }
+ }
+ // if not enrolled yet try to gain temporary guest access
+ if (!$access) {
+ foreach($instances as $instance) {
+ if (!isset($enrols[$instance->enrol])) {
+ continue;
+ }
+ $until = $enrols[$instance->enrol]->try_guestaccess($instance);
+ if ($until !== false) {
+ $USER->enrol['tempguest'][$course->id] = $until;
+ $access = true;
+ break;
+ }
+ }
+ }
+ }
+ }
- case 1: /// Guests always allowed
- if ($cm and !$cm->visible) { // Not allowed to see module, send to course page
- redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course,
- get_string('activityiscurrentlyhidden'));
+ if (!$access) {
+ if ($preventredirect) {
+ throw new require_login_exception('Not enrolled');
- }
+ }
+ $SESSION->wantsurl = $FULLME;
+ redirect($CFG->wwwroot .'/enrol/index.php?id='. $course->id);
+ }
+ }
- if ($USER->username != 'guest' and !empty($CFG->guestroleid)) {
- // Non-guests who don't currently have access, check if they can be allowed in as a guest
- // Temporarily assign them guest role for this context, if it fails later user is asked to enrol
- $USER->access = load_temp_role($coursecontext, $CFG->guestroleid, $USER->access);
+ // test visibility
+ if ($cm && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $cmcontext)) {
+ if ($preventredirect) {
+ throw new require_login_exception('Activity is hidden');
- }
+ }
+ redirect($CFG->wwwroot, get_string('activityiscurrentlyhidden'));
+ }
- user_accesstime_log($COURSE->id); /// Access granted, update lastaccess times
- return; // User is allowed to see this course
-
- case 2: /// Guests allowed with key
- if (!empty($USER->enrolkey[$COURSE->id])) { // Set by enrol/manual/enrol.php
- user_accesstime_log($COURSE->id); /// Access granted, update lastaccess times
- return true;
+ // groupmembersonly access control
+ if (!empty($CFG->enablegroupmembersonly) and $cm and $cm->groupmembersonly and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ if (isguestuser() or !groups_has_membership($cm)) {
+ if ($preventredirect) {
+ throw new require_login_exception('Not member of a group');
- }
+ }
- // otherwise drop through to logic below (--> enrol.php)
- break;
+ print_error('groupmembersonlyerror', 'group', $CFG->wwwroot.'/course/view.php?id='.$cm->course);
+ }
+ }
- default: /// Guests not allowed
- $strloggedinasguest = get_string('loggedinasguest');
- $PAGE->navbar->add($strloggedinasguest);
- echo $OUTPUT->header();
- if (empty($USER->access['rsw'][$coursecontext->path])) { // Normal guest
- notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), get_login_url());
+ // Conditional activity access control
+ if (!empty($CFG->enableavailability) and $cm) {
+ // TODO: this is going to work with login-as-user, sorry!
+ // We cache conditional access in session
+ if (!isset($SESSION->conditionaccessok)) {
+ $SESSION->conditionaccessok = array();
+ }
+ // If you have been allowed into the module once then you are allowed
+ // in for rest of session, no need to do conditional checks
+ if (!array_key_exists($cm->id, $SESSION->conditionaccessok)) {
+ // Get condition info (does a query for the availability table)
+ require_once($CFG->libdir.'/conditionlib.php');
+ $ci = new condition_info($cm, CONDITION_MISSING_EXTRATABLE);
+ // Check condition for user (this will do a query if the availability
+ // information depends on grade or completion information)
+ if ($ci->is_available($junk) || has_capability('moodle/course:viewhiddenactivities', $cmcontext)) {
+ $SESSION->conditionaccessok[$cm->id] = true;
- } else {
+ } else {
- echo $OUTPUT->notification(get_string('guestsnotallowed', '', format_string($COURSE->fullname)));
- echo '
'.switchroles_form($COURSE->id).'
';
- echo $OUTPUT->footer();
- exit;
+ print_error('activityiscurrentlyhidden');
- }
+ }
- break;
- }
- }
+ }
+ }
- // Currently not enrolled in the course, so see if they want to enrol
- $SESSION->wantsurl = $FULLME;
- redirect($CFG->wwwroot .'/course/enrol.php?id='. $COURSE->id);
- die;
+ // Finally access granted, update lastaccess times
+ user_accesstime_log($course->id);
- }
+}
-}
/**
@@ -2441,26 +2527,28 @@
* @param bool $setwantsurltome Define if we want to set $SESSION->wantsurl, defaults to
* true. Used to avoid (=false) some scripts (file.php...) to set that variable,
* in order to keep redirects working properly. MDL-14495
+ * @param bool $preventredirect set to true in scripts that can not redirect (CLI, rss feeds, etc.), throws exceptions
+ * @return void
*/
-function require_course_login($courseorid, $autologinguest=true, $cm=null, $setwantsurltome=true) {
+function require_course_login($courseorid, $autologinguest = true, $cm = NULL, $setwantsurltome = true, $preventredirect = false) {
global $CFG, $PAGE, $SITE;
if (!empty($CFG->forcelogin)) {
// login required for both SITE and courses
- require_login($courseorid, $autologinguest, $cm, $setwantsurltome);
+ require_login($courseorid, $autologinguest, $cm, $setwantsurltome, $preventredirect);
} else if (!empty($cm) and !$cm->visible) {
// always login for hidden activities
- require_login($courseorid, $autologinguest, $cm, $setwantsurltome);
+ require_login($courseorid, $autologinguest, $cm, $setwantsurltome, $preventredirect);
} else if ((is_object($courseorid) and $courseorid->id == SITEID)
or (!is_object($courseorid) and $courseorid == SITEID)) {
//login for SITE not required
if ($cm and empty($cm->visible)) {
// hidden activities are not accessible without login
- require_login($courseorid, $autologinguest, $cm, $setwantsurltome);
+ require_login($courseorid, $autologinguest, $cm, $setwantsurltome, $preventredirect);
} else if ($cm and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
// not-logged-in users do not have any group membership
- require_login($courseorid, $autologinguest, $cm, $setwantsurltome);
+ require_login($courseorid, $autologinguest, $cm, $setwantsurltome, $preventredirect);
} else {
// We still need to instatiate PAGE vars properly so that things
// that rely on it like navigation function correctly.
@@ -2471,6 +2559,9 @@
$course = clone($SITE);
}
if ($cm) {
+ if ($cm->course != $course->id) {
+ throw new coding_exception('course and cm parameters in require_course_login() call do not match!!');
+ }
$PAGE->set_cm($cm, $course);
$PAGE->set_pagelayout('incourse');
} else {
@@ -2488,7 +2579,7 @@
} else {
// course login always required
- require_login($courseorid, $autologinguest, $cm, $setwantsurltome);
+ require_login($courseorid, $autologinguest, $cm, $setwantsurltome, $preventredirect);
}
}
@@ -2771,25 +2862,6 @@
}
/**
- * Sync all meta courses
- * Goes through all enrolment records for the courses inside all metacourses and syncs with them.
- * @see sync_metacourse()
- *
- * @global object
- */
-function sync_metacourses() {
- global $DB;
-
- if (!$courses = $DB->get_records('course', array('metacourse'=>1))) {
- return;
- }
-
- foreach ($courses as $course) {
- sync_metacourse($course);
- }
-}
-
-/**
* Returns reference to full info about modules in course (including visibility).
* Cached and as fast as possible (0 or 1 db query).
*
@@ -2986,157 +3058,6 @@
}
/**
- * Goes through all enrolment records for the courses inside the metacourse and sync with them.
- *
- * @todo finish timeend and timestart maybe we could rely on cron
- * job to do the cleaning from time to time
- *
- * @global object
- * @global object
- * @uses CONTEXT_COURSE
- * @param mixed $course the metacourse to synch. Either the course object itself, or the courseid.
- * @return bool Success
- */
-function sync_metacourse($course) {
- global $CFG, $DB;
-
- // Check the course is valid.
- if (!is_object($course)) {
- if (!$course = $DB->get_record('course', array('id'=>$course))) {
- return false; // invalid course id
- }
- }
-
- // Check that we actually have a metacourse.
- if (empty($course->metacourse)) {
- return false;
- }
-
- // Get a list of roles that should not be synced.
- if (!empty($CFG->nonmetacoursesyncroleids)) {
- $roleexclusions = 'ra.roleid NOT IN (' . $CFG->nonmetacoursesyncroleids . ') AND';
- } else {
- $roleexclusions = '';
- }
-
- // Get the context of the metacourse.
- $context = get_context_instance(CONTEXT_COURSE, $course->id); // SITEID can not be a metacourse
-
- // We do not ever want to unassign the list of metacourse manager, so get a list of them.
- if ($users = get_users_by_capability($context, 'moodle/course:managemetacourse')) {
- $managers = array_keys($users);
- } else {
- $managers = array();
- }
-
- // Get assignments of a user to a role that exist in a child course, but
- // not in the meta coure. That is, get a list of the assignments that need to be made.
- if (!$assignments = $DB->get_records_sql("
- SELECT ra.id, ra.roleid, ra.userid
- FROM {role_assignments} ra, {context} con, {course_meta} cm
- WHERE ra.contextid = con.id AND
- con.contextlevel = ".CONTEXT_COURSE." AND
- con.instanceid = cm.child_course AND
- cm.parent_course = ? AND
- $roleexclusions
- NOT EXISTS (
- SELECT 1
- FROM {role_assignments} ra2
- WHERE ra2.userid = ra.userid AND
- ra2.roleid = ra.roleid AND
- ra2.contextid = ?
- )", array($course->id, $context->id))) {
- $assignments = array();
- }
-
- // Get assignments of a user to a role that exist in the meta course, but
- // not in any child courses. That is, get a list of the unassignments that need to be made.
- if (!$unassignments = $DB->get_records_sql("
- SELECT ra.id, ra.roleid, ra.userid
- FROM {role_assignments} ra
- WHERE ra.contextid = ? AND
- $roleexclusions
- NOT EXISTS (
- SELECT 1
- FROM {role_assignments} ra2, {context} con2, {course_meta} cm
- WHERE ra2.userid = ra.userid AND
- ra2.roleid = ra.roleid AND
- ra2.contextid = con2.id AND
- con2.contextlevel = " . CONTEXT_COURSE . " AND
- con2.instanceid = cm.child_course AND
- cm.parent_course = ?
- )", array($context->id, $course->id))) {
- $unassignments = array();
- }
-
- $success = true;
-
- // Make the unassignments, if they are not managers.
- foreach ($unassignments as $unassignment) {
- if (!in_array($unassignment->userid, $managers)) {
- $success = role_unassign($unassignment->roleid, $unassignment->userid, 0, $context->id) && $success;
- }
- }
-
- // Make the assignments.
- foreach ($assignments as $assignment) {
- $success = role_assign($assignment->roleid, $assignment->userid, 0, $context->id, 0, 0) && $success;
- }
-
- return $success;
-
-// TODO: finish timeend and timestart
-// maybe we could rely on cron job to do the cleaning from time to time
-}
-
-/**
- * Adds a record to the metacourse table and calls sync_metacoures
- *
- * @global object
- * @param int $metacourseid The Metacourse ID for the metacourse to add to
- * @param int $courseid The Course ID of the course to add
- * @return bool Success
- */
-function add_to_metacourse ($metacourseid, $courseid) {
- global $DB;
-
- if (!$metacourse = $DB->get_record("course", array("id"=>$metacourseid))) {
- return false;
- }
-
- if (!$course = $DB->get_record("course", array("id"=>$courseid))) {
- return false;
- }
-
- if (!$record = $DB->get_record("course_meta", array("parent_course"=>$metacourseid, "child_course"=>$courseid))) {
- $rec = new object();
- $rec->parent_course = $metacourseid;
- $rec->child_course = $courseid;
- $DB->insert_record('course_meta', $rec);
- return sync_metacourse($metacourseid);
- }
- return true;
-
-}
-
-/**
- * Removes the record from the metacourse table and calls sync_metacourse
- *
- * @global object
- * @param int $metacourseid The Metacourse ID for the metacourse to remove from
- * @param int $courseid The Course ID of the course to remove
- * @return bool Success
- */
-function remove_from_metacourse($metacourseid, $courseid) {
- global $DB;
-
- if ($DB->delete_records('course_meta', array('parent_course'=>$metacourseid, 'child_course'=>$courseid))) {
- return sync_metacourse($metacourseid);
- }
- return false;
-}
-
-/**
* Determines if the currently logged in user is in editing mode.
* Note: originally this function had $userid parameter - it was not usable anyway
*
@@ -3514,13 +3435,13 @@
require_once($CFG->libdir.'/grouplib.php');
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/message/lib.php');
-
- // delete all grades - backup is kept in grade_grades_history table
- if ($grades = grade_grade::fetch_all(array('userid'=>$user->id))) {
- foreach ($grades as $grade) {
- $grade->delete('userdelete');
- }
- }
+
+ // delete all grades - backup is kept in grade_grades_history table
+ if ($grades = grade_grade::fetch_all(array('userid'=>$user->id))) {
+ foreach ($grades as $grade) {
+ $grade->delete('userdelete');
+ }
+ }
//move unread messages from this user to read
message_move_userfrom_unread2read($user->id);
@@ -3532,7 +3453,7 @@
$DB->delete_records('groups_members', array('userid'=>$user->id));
// unenrol from all roles in all contexts
- role_unassign(0, $user->id); // this might be slow but it is really needed - modules might do some extra cleanup!
+ role_unassign_all(array('userid'=>$user->id)); // this might be slow but it is really needed - modules might do some extra cleanup!
// now do a final accesslib cleanup - removes all role assignments in user context and context itself
delete_context(CONTEXT_USER, $user->id);
@@ -4144,26 +4065,6 @@
$DB->delete_records($table, array($col=>$course->id));
}
-
-/// Clean up metacourse stuff
-
- if ($course->metacourse) {
- $DB->delete_records("course_meta", array("parent_course"=>$course->id));
- sync_metacourse($course->id); // have to do it here so the enrolments get nuked. sync_metacourses won't find it without the id.
- if ($showfeedback) {
- echo $OUTPUT->notification("$strdeleted course_meta");
- }
- } else {
- if ($parents = $DB->get_records("course_meta", array("child_course"=>$course->id))) {
- foreach ($parents as $parent) {
- remove_from_metacourse($parent->parent_course,$parent->child_course); // this will do the unenrolments as well.
- }
- if ($showfeedback) {
- echo $OUTPUT->notification("$strdeleted course_meta");
- }
- }
- }
-
/// Delete questions and question categories
question_delete_course($course, $showfeedback);
@@ -4295,7 +4196,7 @@
if (!empty($data->reset_roles_local)) {
$children = get_child_contexts($context);
foreach ($children as $child) {
- role_unassign(0, 0, 0, $child->id);
+ role_unassign_all(array('contextid'=>$child->id));
}
//force refresh for logged in users
mark_context_dirty($context->path);
@@ -4308,7 +4209,7 @@
foreach($data->reset_roles as $roleid) {
if ($users = get_role_users($roleid, $context, false, 'u.id', 'u.id ASC')) {
foreach ($users as $user) {
- role_unassign($roleid, $user->id, 0, $context->id);
+ role_unassign($roleid, $user->id, $context->id);
if (!is_enrolled($context, $user->id)) {
$data->unenrolled[$user->id] = $user->id;
}
@@ -5063,58 +4964,6 @@
return false;
}
-/**
- * Send welcome email to specified user
- *
- * @global object
- * @global object
- * @param object $course
- * @param user $user A {@link $USER} object
- * @return bool
- */
-function email_welcome_message_to_user($course, $user=NULL) {
- global $CFG, $USER;
-
- if (isset($CFG->sendcoursewelcomemessage) and !$CFG->sendcoursewelcomemessage) {
- return;
- }
-
- if (empty($user)) {
- if (!isloggedin()) {
- return false;
- }
- $user = $USER;
- }
-
- if (!empty($course->welcomemessage)) {
- $message = $course->welcomemessage;
- } else {
- $a = new object();
- $a->coursename = $course->fullname;
- if ($course->id == SITEID) {
- $a->profileurl = "$CFG->wwwroot/user/profile.php?id=$user->id";
- } else {
- $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id";
- }
- $message = get_string("welcometocoursetext", "", $a);
- }
-
- /// If you don't want a welcome message sent, then make the message string blank.
- if (!empty($message)) {
- $subject = get_string('welcometocourse', '', format_string($course->fullname));
-
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- // TODO: replace with $CFG->coursemanager test, 'moodle/course:update' is very wrong!!
- if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC','', '', '', '', false, true)) {
- $users = sort_by_roleassignment_authority($users, $context);
- $teacher = array_shift($users);
- } else {
- $teacher = get_admin();
- }
- email_to_user($user, $teacher, $subject, $message);
- }
-}
-
/// FILE HANDLING /////////////////////////////////////////////
/**
@@ -7027,6 +6876,7 @@
'dock' => NULL,
'editor' => 'lib/editor',
'edufields' => NULL,
+ 'enrol' => 'enrol',
'error' => NULL,
'filepicker' => NULL,
'filters' => NULL,
@@ -9352,24 +9202,7 @@
}
/**
- * Checks if a given plugin is in the list of enabled enrolment plugins.
- *
- * @global object
- * @param string $auth Enrolment plugin.
- * @return boolean Whether the plugin is enabled.
- */
-function is_enabled_enrol($enrol='') {
- global $CFG;
-
- // use the global default if not specified
- if ($enrol == '') {
- $enrol = $CFG->enrol;
- }
- return in_array($enrol, explode(',', $CFG->enrol_plugins_enabled));
-}
-
-/**
- * This function will search for browser preferred languages, setting Moodle
+ * This function will search for browser prefereed languages, setting Moodle
* to use the best one available if $SESSION->lang is undefined
*
* @global object
@@ -9583,7 +9416,7 @@
}
}
- /**
+/**
* Returns the site identifier
*
* @global object
Index: admin/settings/appearance.php
===================================================================
--- admin/settings/appearance.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ admin/settings/appearance.php (revision )
@@ -126,9 +126,9 @@
$temp = new admin_externalpage('profilepage', get_string('myprofile', 'admin'), $CFG->wwwroot . '/user/profilesys.php');
$ADMIN->add('appearance', $temp);
- // coursemanager is the person responsible for course - usually manages enrolments, receives notification, etc.
- $temp = new admin_settingpage('coursemanager', get_string('coursemanager', 'admin'));
- $temp->add(new admin_setting_special_coursemanager());
+ // coursecontact is the person responsible for course - usually manages enrolments, receives notification, etc.
+ $temp = new admin_settingpage('coursecontact', get_string('coursecontact', 'admin'));
+ $temp->add(new admin_setting_special_coursecontact());
$ADMIN->add('appearance', $temp);
$temp = new admin_settingpage('ajax', get_string('ajaxuse'));
Index: course/unenrol.php
===================================================================
--- course/unenrol.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ course/unenrol.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
@@ -1,123 +0,0 @@
-.
-
-/**
- * Remove oneself or someone else from a course, unassigning all roles one might have
- *
- * This will not delete any of their data from the course, but will remove them
- * from the participant list and prevent any course email being sent to them.
- *
- * @copyright 1999 Martin Dougiamas http://dougiamas.com
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @package course
- */
-
-require_once("../config.php");
-require_once("lib.php");
-
-$id = required_param('id', PARAM_INT); //course
-$userid = optional_param('user', 0, PARAM_INT); //course
-$confirm = optional_param('confirm', 0, PARAM_BOOL);
-
-$PAGE->set_url('/course/unenrol.php', array('id'=>$id));
-
-if($userid == $USER->id){
- // the rest of this code assumes $userid=0 means
- // you are unassigning yourself, so set this for the
- // correct capabiliy checks & language later
- $userid = 0;
-}
-
-if (!$course = $DB->get_record('course', array('id'=>$id))) {
- print_error('invalidcourseid');
-}
-
-if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
- print_error('invalidcontext');
-}
-
-require_login($course->id);
-
-if ($course->metacourse) {
- print_error('cantunenrollfrommetacourse', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
-}
-
-if ($userid) { // Unenrolling someone else
- require_capability('moodle/role:assign', $context, NULL, false);
-
- $roles = get_user_roles($context, $userid, false);
-
- // verify user may unassign all roles at course context
- foreach($roles as $role) {
- if (!user_can_assign($context, $role->roleid)) {
- print_error('cannotunassignrolefrom', '', '',
- $role->roleid);
- }
- }
-
-} else { // Unenrol yourself
- require_capability('moodle/role:unassignself', $context, NULL, false);
-}
-
-if (!empty($USER->access['rsw'][$context->path])) {
- print_error('cantunenrollinthisrole', '',
- $CFG->wwwroot.'/course/view.php?id='.$course->id);
-}
-
-if ($confirm and confirm_sesskey()) {
- if ($userid) {
- if (! role_unassign(0, $userid, 0, $context->id)) {
- print_error("unenrolerror");
- }
-
- add_to_log($course->id, 'course', 'unenrol',
- "view.php?id=$course->id", $course->id);
- redirect($CFG->wwwroot.'/user/index.php?id='.$course->id);
-
- } else {
- if (! role_unassign(0, $USER->id, 0, $context->id)) {
- print_error("unenrolerror");
- }
-
- // force a refresh of mycourses
- unset($USER->mycourses);
- add_to_log($course->id, 'course', 'unenrol',
- "view.php?id=$course->id", $course->id);
-
- redirect($CFG->wwwroot);
- }
-}
-
-
-$strunenrol = get_string('unenrol');
-$PAGE->navbar->add($strunenrol);
-$PAGE->set_title("$course->shortname: $strunenrol");
-$PAGE->set_heading($course->fullname);
-echo $OUTPUT->header();
-if ($userid) {
- if (!$user = $DB->get_record('user', array('id'=>$userid))) {
- print_error('nousers');
- }
- $strunenrolsure = get_string('unenrolsure', '', fullname($user, true));
- echo $OUTPUT->confirm($strunenrolsure, "unenrol.php?id=$id&user=$user->id&confirm=yes", $PAGE->url);
-} else {
- $strunenrolsure = get_string('unenrolsure', '', get_string("yourself"));
- echo $OUTPUT->confirm($strunenrolsure, "unenrol.php?id=$id&confirm=yes", $PAGE->url);
-}
-
-echo $OUTPUT->footer();
-
Index: blocks/course_overview/block_course_overview.php
===================================================================
--- blocks/course_overview/block_course_overview.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ blocks/course_overview/block_course_overview.php (revision )
@@ -65,7 +65,7 @@
$courses_limit = $courses_limit + 1;
}
- $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
+ $courses = enrol_get_my_courses(NULL, 'visible DESC,sortorder ASC', '*', $courses_limit);
$site = get_site();
$course = $site; //just in case we need the old global $course hack
Index: admin/roles/assign.php
===================================================================
--- admin/roles/assign.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ admin/roles/assign.php (revision )
@@ -31,8 +31,6 @@
$contextid = required_param('contextid',PARAM_INT);
$roleid = optional_param('roleid', 0, PARAM_INT);
-$extendperiod = optional_param('extendperiod', 0, PARAM_INT);
-$extendbase = optional_param('extendbase', 3, PARAM_INT);
list($context, $course, $cm) = get_context_info_array($contextid);
@@ -58,7 +56,6 @@
$contextname = print_context_name($context);
$courseid = $course->id;
-$inmeta = $course->metacourse;
$isfrontpage = ($course->id == SITEID);
// These are needed early because of tabs.php
@@ -87,40 +84,6 @@
}
}
-// Build the list of options for the enrolment period dropdown.
-$unlimitedperiod = get_string('unlimited');
-for ($i=1; $i<=365; $i++) {
- $seconds = $i * 86400;
- $periodmenu[$seconds] = get_string('numdays', '', $i);
-}
-// Work out the apropriate default setting.
-if ($extendperiod) {
- $defaultperiod = $extendperiod;
-} else {
- $defaultperiod = $course->enrolperiod;
-}
-
-// Build the list of options for the starting from dropdown.
-$timeformat = get_string('strftimedatefullshort');
-$today = time();
-$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
-
-// MDL-12420, preventing course start date showing up as an option at system context and front page roles.
-if ($course->startdate > 0) {
- $basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')';
-}
-if ($course->enrollable != 2 || ($course->enrolstartdate == 0 || $course->enrolstartdate <= $today) && ($course->enrolenddate == 0 || $course->enrolenddate > $today)) {
- $basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
-}
-if ($course->enrollable == 2) {
- if($course->enrolstartdate > 0) {
- $basemenu[4] = get_string('courseenrolstart') . ' (' . userdate($course->enrolstartdate, $timeformat) . ')';
- }
- if($course->enrolenddate > 0) {
- $basemenu[5] = get_string('courseenrolend') . ' (' . userdate($course->enrolenddate, $timeformat) . ')';
- }
-}
-
// Process any incoming role assignments before printing the header.
if ($roleid) {
@@ -138,48 +101,11 @@
foreach ($userstoassign as $adduser) {
$allow = true;
- if ($inmeta) {
- if (has_capability('moodle/course:managemetacourse', $context, $adduser->id)) {
- //ok
- } else {
- $managerroles = get_roles_with_capability('moodle/course:managemetacourse', CAP_ALLOW, $context);
- if (!empty($managerroles) and !array_key_exists($roleid, $managerroles)) {
- $erruser = $DB->get_record('user', array('id'=>$adduser->id), 'id, firstname, lastname');
- $errors[] = get_string('metaassignerror', 'role', fullname($erruser));
- $allow = false;
- }
- }
- }
if ($allow) {
- switch($extendbase) {
- case 2:
- $timestart = $course->startdate;
- break;
- case 3:
- $timestart = $today;
- break;
- case 4:
- $timestart = $course->enrolstartdate;
- break;
- case 5:
- $timestart = $course->enrolenddate;
- break;
+ role_assign($roleid, $adduser->id, $context->id);
- }
+ }
-
- if($extendperiod > 0) {
- $timeend = $timestart + $extendperiod;
- } else {
- $timeend = 0;
- }
+ }
- if (! role_assign($roleid, $adduser->id, 0, $context->id, $timestart, $timeend)) {
- $a = new stdClass;
- $a->role = $assignableroles[$roleid];
- $a->user = fullname($adduser);
- $errors[] = get_string('assignerror', 'role', $a);
- }
- }
- }
$potentialuserselector->invalidate_selected_users();
$currentuserselector->invalidate_selected_users();
@@ -197,19 +123,9 @@
if (!empty($userstounassign)) {
foreach ($userstounassign as $removeuser) {
- if (! role_unassign($roleid, $removeuser->id, 0, $context->id)) {
- $a = new stdClass;
- $a->role = $assignableroles[$roleid];
- $a->user = fullname($removeuser);
- $errors[] = get_string('unassignerror', 'role', $a);
- } else if ($inmeta) {
- sync_metacourse($courseid);
- $newroles = get_user_roles($context, $removeuser->id, false);
- if (empty($newroles) || array_key_exists($roleid, $newroles)) {
- $errors[] = get_string('metaunassignerror', 'role', fullname($removeuser));
+ //TODO: add some protection for role unsasignment from some enrol/auth plugins
+ role_unassign_all(array('roleid'=>$roleid, 'userid'=>$removeuser->id, 'contextid'=>$context->id));
- }
+ }
- }
- }
$potentialuserselector->invalidate_selected_users();
$currentuserselector->invalidate_selected_users();
@@ -290,16 +206,6 @@
-
-
-
-
-
-
-
-
-
@@ -352,11 +258,6 @@
// Print instruction
echo $OUTPUT->heading(get_string('chooseroletoassign', 'role'), 3);
- // sync metacourse enrolments if needed
- if ($inmeta) {
- sync_metacourse($course);
- }
-
// Get the names of role holders for roles with between 1 and MAX_USERS_TO_LIST_PER_ROLE users,
// and so determine whether to show the extra column.
$roleholdernames = array();
Index: tag/coursetagslib.php
===================================================================
--- tag/coursetagslib.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ tag/coursetagslib.php (revision )
@@ -399,7 +399,8 @@
//view, but arguably it is best that when clicking on a tag, the tagged course summary should
//be seen and then if the student clicks on that they will be given the opportunity to join
//note courses not visible should not have their tagid sent to this function
- //if (has_capability('moodle/course:participate', get_context_instance(CONTEXT_COURSE, $c->itemid))) {
+ // $context = get_context_instance(CONTEXT_COURSE, $c->itemid);
+ //if (is_enrolled($context) oe is_viewing($context)) {
$course = $DB->get_record('course', array('id'=>$c->itemid));
$courses[$c->itemid] = $course;
//}
Index: admin/generator.php
===================================================================
--- admin/generator.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ admin/generator.php (revision )
@@ -709,25 +709,18 @@
$context = get_context_instance(CONTEXT_COURSE, $courseid);
foreach ($users_to_assign as $random_user) {
- $success = role_assign(5, $random_user, 0, $context->id);
+ role_assign(5, $random_user, $context->id);
- if ($success) {
- $assigned_count++;
- $course_users[$courseid][] = $random_user;
- if (!isset($assigned_users[$random_user])) {
- $assigned_users[$random_user] = 1;
- } else {
- $assigned_users[$random_user]++;
- }
- $this->verbose("Student $random_user was assigned to course $courseid.");
+ $assigned_count++;
+ $course_users[$courseid][] = $random_user;
+ if (!isset($assigned_users[$random_user])) {
+ $assigned_users[$random_user] = 1;
+ } else {
+ $assigned_users[$random_user]++;
+ }
+ $this->verbose("Student $random_user was assigned to course $courseid.");
- } else {
- $this->verbose("Could not assign student $random_user to course $courseid!");
- if (!$this->get('ignore_errors')) {
- die();
- }
- }
+ }
+ }
- }
- }
if (!$this->get('quiet')) {
echo "$assigned_count user => course role assignments have been correctly performed.{$this->eolchar}";
Index: enrol/manual/manage.php
===================================================================
--- enrol/manual/manage.php (revision )
+++ enrol/manual/manage.php (revision )
@@ -0,0 +1,184 @@
+.
+
+/**
+ * Manual user enrolment UI.
+ *
+ * @package enrol_manual
+ * @copyright 2009 Tim Hunt, 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require('../../config.php');
+require_once($CFG->dirroot.'/enrol/manual/locallib.php');
+
+$id = required_param('id', PARAM_INT); // course id
+$enrolid = required_param('enrolid', PARAM_INT);
+$roleid = optional_param('roleid', -1, PARAM_INT);
+$extendperiod = optional_param('extendperiod', 0, PARAM_INT);
+$extendbase = optional_param('extendbase', 3, PARAM_INT);
+
+$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
+$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
+
+require_login($course);
+require_capability('enrol/manual:manage', $context);
+
+$instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST);
+if ($roleid < 0) {
+ $roleid = $instance->defaultrole;
+}
+$roles = get_assignable_roles($context);
+$roles = array('0'=>get_string('none')) + $roles;
+
+if (!isset($roles[$roleid])) {
+ // weird - security always first!
+ $roleid = 0;
+}
+
+if (!$enrol_manual = enrol_get_plugin('manual')) {
+ throw coding_error('Can not instantiate enrol_manual');
+}
+
+$PAGE->set_url('/enrol/manual/manage.php', array('id'=>$course->id, 'enrolid'=>$instance->id));
+
+// Create the user selector objects.
+$options = array('enrolid' => $enrolid);
+
+$potentialuserselector = new enrol_manual_potential_participant('addselect', $options);
+$currentuserselector = new enrol_manual_current_participant('removeselect', $options);
+
+// Build the list of options for the enrolment period dropdown.
+$unlimitedperiod = get_string('unlimited');
+$periodmenu = array();
+for ($i=1; $i<=365; $i++) {
+ $seconds = $i * 86400;
+ $periodmenu[$seconds] = get_string('numdays', '', $i);
+}
+// Work out the apropriate default setting.
+if ($extendperiod) {
+ $defaultperiod = $extendperiod;
+} else {
+ $defaultperiod = $instance->enrolperiod;
+}
+
+// Build the list of options for the starting from dropdown.
+$timeformat = get_string('strftimedatefullshort');
+$today = time();
+$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
+
+// enrolment start
+$basemenu = array();
+if ($course->startdate > 0) {
+ $basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')';
+}
+$basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
+
+// process add and removes
+if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
+ $userstoassign = $potentialuserselector->get_selected_users();
+ if (!empty($userstoassign)) {
+ foreach($userstoassign as $adduser) {
+ switch($extendbase) {
+ case 2:
+ $timestart = $course->startdate;
+ break;
+ case 3:
+ default:
+ $timestart = $today;
+ break;
+ }
+
+ if($extendperiod > 0) {
+ $timeend = $timestart + $extendperiod;
+ } else {
+ $timeend = 0;
+ }
+ $enrol_manual->enrol_user($instance, $adduser->id, $timestart, $timeend, $roleid);
+ }
+
+ $potentialuserselector->invalidate_selected_users();
+ $currentuserselector->invalidate_selected_users();
+
+ //TODO: log
+ }
+}
+
+// Process incoming role unassignments
+if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
+ $userstounassign = $currentuserselector->get_selected_users();
+ if (!empty($userstounassign)) {
+ foreach($userstounassign as $removeuser) {
+ $enrol_manual->unenrol_user($instance, $removeuser->id);
+ }
+
+ $potentialuserselector->invalidate_selected_users();
+ $currentuserselector->invalidate_selected_users();
+
+ //TODO: log
+ }
+}
+
+
+echo $OUTPUT->header();
+
+$currenttab = 'manual';
+require("$CFG->dirroot/enrol/tabs.php");
+
+
+?>
+
+footer();
\ No newline at end of file
Index: backup/moodle2/backup_stepslib.php
===================================================================
--- backup/moodle2/backup_stepslib.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ backup/moodle2/backup_stepslib.php (revision )
@@ -202,7 +202,7 @@
/**
* structure step that will generate the course.xml file for the course, including
- * course category reference, tags, metacourse, modules restriction information
+ * course category reference, tags, modules restriction information
* and some annotations (files & groupings)
*/
class backup_course_structure_step extends backup_structure_step {
@@ -219,7 +219,7 @@
'numsections', 'marker', 'maxbytes', 'showreports',
'visible', 'hiddensections', 'groupmode', 'groupmodeforce',
'defaultgroupingid', 'lang', 'theme', 'cost',
- 'currency', 'timecreated', 'timemodified', 'metacourse',
+ 'currency', 'timecreated', 'timemodified',
'requested', 'restrictmodules', 'expirynotify', 'expirythreshold',
'notifystudents', 'enrollable', 'enrolstartdate', 'enrolenddate',
'enrol', 'defaultrole', 'enablecompletion'));
@@ -307,8 +307,7 @@
$assignments = new backup_nested_element('role_assignments');
$assignment = new backup_nested_element('assignment', array('id'), array(
- 'roleid', 'userid', 'hidden', 'timestart',
- 'timeend', 'timemodified', 'modifierid', 'enrol',
+ 'roleid', 'userid', 'timemodified', 'modifierid', 'enrol',
'sortorder'));
// Build the tree
@@ -714,8 +713,7 @@
$assignments = new backup_nested_element('role_assignments');
$assignment = new backup_nested_element('assignment', array('id'), array(
- 'roleid', 'userid', 'hidden', 'timestart',
- 'timeend', 'timemodified', 'modifierid', 'enrol',
+ 'roleid', 'userid', 'timemodified', 'modifierid', 'enrol',
'sortorder'));
// Build the tree
Index: course/category.php
===================================================================
--- course/category.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ course/category.php (revision )
@@ -240,7 +240,7 @@
/// Print out all the courses
$courses = get_courses_page($category->id, 'c.sortorder ASC',
- 'c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible,c.guest,c.password',
+ 'c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible',
$totalcount, $page*$perpage, $perpage);
$numcourses = count($courses);
@@ -397,16 +397,7 @@
echo '
';
} else {
echo '
';
- if (!empty($acourse->guest)) {
- echo '';
- }
- if (!empty($acourse->password)) {
- echo '';
- }
+ //TODO: show some icons for plugins - such as guest, pasword, etc.
if (!empty($acourse->summary)) {
$link = new moodle_url("/course/info.php?id=$acourse->id");
echo $OUTPUT->action_link($link, '',
Index: auth/mnet/auth.php
===================================================================
--- auth/mnet/auth.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ auth/mnet/auth.php (revision )
@@ -87,7 +87,7 @@
}
$userdata['myhosts'] = array();
- if($courses = get_my_courses($user->id, 'id', 'id, visible')) {
+ if ($courses = enrol_get_users_courses($user->id, false)) {
$userdata['myhosts'][] = array('name'=> $SITE->shortname, 'url' => $CFG->wwwroot, 'count' => count($courses));
}
@@ -352,10 +352,10 @@
$mnetrequest->add_param($remoteuser->username);
$fields = 'id, category, sortorder, fullname, shortname, idnumber, summary,
startdate, cost, currency, defaultrole, visible';
- $courses = get_my_courses($localuser->id, 'visible DESC,sortorder ASC', $fields);
+ $courses = enrol_get_users_courses($localuser->id, false, $fields, 'visible DESC,sortorder ASC');
if (is_array($courses) && !empty($courses)) {
// Second request to do the JOINs that we'd have done
- // inside get_my_courses() if we had been allowed
+ // inside enrol_get_users_courses() if we had been allowed
$sql = "SELECT c.id,
cc.name AS cat_name, cc.description AS cat_description,
r.shortname as defaultrolename
Index: enrol/self/lib.php
===================================================================
--- enrol/self/lib.php (revision )
+++ enrol/self/lib.php (revision )
@@ -0,0 +1,412 @@
+.
+
+/**
+ * Self enrolment plugin.
+ *
+ * This plugin does not add entries to the course_participants table,
+ * instead it is relying on the manual enrolment plugin to do the actual
+ * work.
+ *
+ * @package enrol_self
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class enrol_self_plugin extends enrol_plugin {
+
+ public function enrol_user(stdClass $instance, $userid, $timestart = 0, $timeend = 0, $roleid = null) {
+ // nothing to do, we abuse the first instance of manual enrolment plugin
+ return;
+ }
+
+ public function unenrol_user(stdClass $instance, $userid) {
+ // nothing to do, we enrolled via some manual plugin
+ return;
+ }
+
+ /**
+ * Creates course enrol form, checks if form submitted
+ * and enrols user if necessary. It can also redirect.
+ *
+ * @param stdClass $instance
+ * @return string html text, usually a form in a text box
+ */
+ public function enrol_page_hook(stdClass $instance) {
+ global $CFG, $OUTPUT, $SESSION, $USER, $DB;
+
+ if (isguestuser()) {
+ // can not enrol guest!!
+ return null;
+ }
+
+ if (!$manuals = $DB->get_records('enrol', array('enrol'=>'manual', 'courseid'=>$instance->courseid), 'sortorder,id ASC')) {
+ // we can not self enrol if no manual enrol plugin present, sorry
+ return null;
+ }
+ $manual = reset($manuals);
+ if (!$manualplugin = enrol_get_plugin('manual')) {
+ // weird, somebody deleted manual plugin
+ return null;
+ }
+
+ if ($DB->record_exists('course_participants', array('userid'=>$USER->id, 'enrolid'=>$manual->id))) {
+ // user is already enrolled - does not matter if active, bad luck!
+ //TODO: maybe we should tell them they rea already enrolled, but can not access the course
+ return null;
+ }
+
+ if ($instance->enrolstartdate != 0 and $instance->enrolstartdate < time) {
+ //TODO: inform that we can not enrol yet
+ return null;
+ }
+
+ if ($instance->enrolenddate != 0 and $instance->enrolenddate > time) {
+ //TODO: inform that enrolment is not possible any more
+ return null;
+ }
+
+ require_once("$CFG->dirroot/enrol/self/locallib.php");
+ $form = new enrol_self_enrol_form(NULL, $instance);
+ $instanceid = optional_param('instance', 0, PARAM_INT);
+
+ if ($instance->id == $instanceid) {
+ if ($data = $form->get_data()) {
+ // clean caches
+ unset($USER->enrol['enrolled'][$instance->courseid]);
+ unset($USER->enrol['tempguest'][$instance->courseid]);
+
+ // remove any guest role
+ $context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
+ $USER->access = remove_temp_roles($context, $USER->access);
+
+ $enrol = enrol_get_plugin('self');
+ if ($instance->enrolperiod) {
+ $timestart = time();
+ $tineend = $timestart + $instance->enrolperiod;
+ } else {
+ $timestart = 0;
+ $tineend = 0;
+ }
+
+ // abuse the manual enrol plugin so that teachers may manually tweak the roles and enrolments later
+ $manualplugin->enrol_user($manual, $USER->id, $timestart, $tineend, $instance->defaultrole);
+ // send welcome
+ if ($this->get_config('sendcoursewelcomemessage')) {
+ $this->email_welcome_message($instance, $USER);
+ }
+ }
+ }
+
+ ob_start();
+ $form->display();
+ $output = ob_get_clean();
+
+ return $OUTPUT->box($output);
+ }
+
+ /**
+ * Adds enrol instance UI to course edit form
+ *
+ * @param object $instance enrol instance or null if does not exist yet
+ * @param MoodleQuickForm $mform
+ * @param object $data
+ * @param object $context context of existing course or parent category if course does not exist
+ * @return void
+ */
+ public function course_edit_form($instance, MoodleQuickForm $mform, $data, $context) {
+
+ $i = isset($instance->id) ? $instance->id : 0;
+ $plugin = enrol_get_plugin('self');
+ $header = $plugin->get_instance_name($instance);
+ $config = has_capability('enrol/self:config', $context);
+
+ $mform->addElement('header', 'enrol_self_header_'.$i, $header);
+
+
+ $options = array(ENROL_STATUS_ENABLED => get_string('yes'),
+ ENROL_STATUS_DISABLED => get_string('no'));
+ $mform->addElement('select', 'enrol_self_status_'.$i, get_string('status', 'enrol_self'), $options);
+ $mform->setDefault('enrol_self_status_'.$i, $this->get_config('status'));
+ $mform->setAdvanced('enrol_self_status_'.$i, $this->get_config('status_adv'));
+ if (!$config) {
+ $mform->hardFreeze('enrol_self_status_'.$i);
+ }
+
+
+ $mform->addElement('passwordunmask', 'enrol_self_password_'.$i, get_string('password', 'enrol_self'));
+ if (!$config) {
+ $mform->hardFreeze('enrol_self_password_'.$i);
+ } else {
+ $mform->disabledIf('enrol_self_password_'.$i, 'enrol_self_status_'.$i, 'noteq', ENROL_STATUS_ENABLED);
+ }
+
+
+ $options = array(1 => get_string('yes'),
+ 0 => get_string('no'));
+ $mform->addElement('select', 'enrol_self_customint1_'.$i, get_string('groupkey', 'enrol_self'), $options);
+ $mform->setDefault('enrol_self_customint1_'.$i, $this->get_config('groupkey'));
+ $mform->setAdvanced('enrol_self_customint1_'.$i, $this->get_config('groupkey_adv'));
+ if (!$config) {
+ $mform->hardFreeze('enrol_self_customint1_'.$i);
+ } else {
+ $mform->disabledIf('enrol_self_customint1_'.$i, 'enrol_self_status_'.$i, 'noteq', ENROL_STATUS_ENABLED);
+ }
+
+
+ if ($instance) {
+ $roles = get_default_enrol_roles($context, $instance->defaultrole);
+ } else {
+ $roles = get_default_enrol_roles($context, $this->get_config('defaultrole'));
+ }
+ $mform->addElement('select', 'enrol_self_defaultrole_'.$i, get_string('role', 'enrol_self'), $roles);
+ $mform->setDefault('enrol_self_defaultrole_'.$i, $this->get_config('role'));
+ $mform->setAdvanced('enrol_self_defaultrole_'.$i, $this->get_config('role_adv'));
+ if (!$config) {
+ $mform->hardFreeze('enrol_self_defaultrole_'.$i);
+ } else {
+ $mform->disabledIf('enrol_self_defaultrole_'.$i, 'enrol_self_status_'.$i, 'noteq', ENROL_STATUS_ENABLED);
+ }
+
+
+ $mform->addElement('duration', 'enrol_self_enrolperiod_'.$i, get_string('enrolperiod', 'enrol_self'), array('optional' => true, 'defaultunit' => 86400));
+ $mform->setDefault('enrol_self_enrolperiod_'.$i, $this->get_config('enrolperiod'));
+ $mform->setAdvanced('enrol_self_enrolperiod_'.$i, $this->get_config('enrolperiod_adv'));
+ if (!$config) {
+ $mform->hardFreeze('enrol_self_enrolperiod_'.$i);
+ } else {
+ $mform->disabledIf('enrol_self_enrolperiod_'.$i, 'enrol_self_status_'.$i, 'noteq', ENROL_STATUS_ENABLED);
+ }
+
+
+ $mform->addElement('date_selector', 'enrol_self_enrolstartdate_'.$i, get_string('enrolstartdate', 'enrol_self'), array('optional' => true));
+ $mform->setDefault('enrol_self_enrolstartdate_'.$i, 0);
+ $mform->setAdvanced('enrol_self_enrolstartdate_'.$i, 1);
+ if (!$config) {
+ $mform->hardFreeze('enrol_self_enrolstartdate_'.$i);
+ } else {
+ $mform->disabledIf('enrol_self_enrolstartdate_'.$i, 'enrol_self_status_'.$i, 'noteq', ENROL_STATUS_ENABLED);
+ }
+
+
+ $mform->addElement('date_selector', 'enrol_self_enrolenddate_'.$i, get_string('enrolenddate', 'enrol_self'), array('optional' => true));
+ $mform->setDefault('enrol_self_enrolenddate_'.$i, 0);
+ $mform->setAdvanced('enrol_self_enrolenddate_'.$i, 1);
+ if (!$config) {
+ $mform->hardFreeze('enrol_self_enrolenddate_'.$i);
+ } else {
+ $mform->disabledIf('enrol_self_enrolenddate_'.$i, 'enrol_self_status_'.$i, 'noteq', ENROL_STATUS_ENABLED);
+ }
+
+
+ // now add all values from enrol table
+ if ($instance) {
+ foreach($instance as $key=>$val) {
+ $data->{'enrol_self_'.$key.'_'.$i} = $val;
+ }
+ }
+ }
+
+
+ /**
+ * Validates course edit form data
+ *
+ * @param object $instance enrol instance or null if does not exist yet
+ * @param array $data
+ * @param object $context context of existing course or parent category if course does not exist
+ * @return array errors array
+ */
+ public function course_edit_validation($instance, array $data, $context) {
+ $errors = array();
+
+ if (!has_capability('enrol/self:config', $context)) {
+ // we are going to ignore the data later anyway, they would nto be able to fix the form anyway
+ return $errors;
+ }
+
+ $i = isset($instance->id) ? $instance->id : 0;
+
+ $password = empty($data['enrol_self_password_'.$i]) ? '' : $data['enrol_self_password_'.$i];
+ $checkpassword = false;
+
+ if ($instance) {
+ if ($data['enrol_self_status_'.$i] == ENROL_STATUS_ENABLED) {
+ if ($instance->password !== $password) {
+ $checkpassword = true;
+ }
+ }
+ } else {
+ if ($data['enrol_self_status_'.$i] == ENROL_STATUS_ENABLED) {
+ $checkpassword = true;
+ }
+ }
+
+ if ($checkpassword) {
+ $require = $this->get_config('requirepassword');
+ $policy = $this->get_config('usepasswordpolicy');
+ if ($require and empty($password)) {
+ $errors['enrol_self_password_'.$i] = get_string('required');
+ } else if ($policy) {
+ $errmsg = '';//prevent eclipse warning
+ if (!check_password_policy($password, $errmsg)) {
+ $errors['enrol_self_password_'.$i] = $errmsg;
+ }
+ }
+ }
+
+ if ($data['enrol_self_status_'.$i] == ENROL_STATUS_ENABLED) {
+ if (!empty($data['enrol_self_enrolenddate_'.$i]) and $data['enrol_self_enrolenddate_'.$i] < $data['enrol_self_enrolstartdate_'.$i]) {
+ $errors['enrol_self_enrolenddate_'.$i] = get_string('enrolenddaterror', 'enrol_self');
+ }
+ }
+
+ return $errors;
+ }
+
+
+ /**
+ * Called after updating/inserting course.
+ *
+ * @param object $instance enrol instance, null if does not exist yet
+ * @param object $course
+ * @param object $data form data
+ * @return void
+ */
+ public function course_updated($instance, $course, $data) {
+ global $DB;
+
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+ if (has_capability('enrol/self:config', $context)) {
+ if ($instance) {
+ $i = $instance->id;
+ } else {
+ $i = 0;
+ $instance = new object();
+ $instance->enrol = 'self';
+ $instance->courseid = $course->id;
+ }
+
+ $instance->status = $data->{'enrol_self_status_'.$i};
+ $instance->timemodified = time();
+
+ if ($instance->status == ENROL_STATUS_ENABLED) {
+ $instance->password = $data->{'enrol_self_password_'.$i};
+ $instance->customint1 = $data->{'enrol_self_customint1_'.$i};
+ $instance->defaultrole = $data->{'enrol_self_defaultrole_'.$i};
+ $instance->enrolperiod = $data->{'enrol_self_enrolperiod_'.$i};
+ $instance->enrolstartdate = $data->{'enrol_self_enrolstartdate_'.$i};
+ $instance->enrolenddate = $data->{'enrol_self_enrolenddate_'.$i};
+
+ } else if (empty($instance->id)) {
+ if ($this->get_config('requirepassword')) {
+ // make sure some password is set after enabling this plugin
+ $instance->password = generate_password(20);
+ }
+ $instance->customint1 = $this->get_config('groupkey');
+ $instance->defaultrole = $this->get_config('role');
+ $instance->enrolperiod = $this->get_config('enrolperiod');
+ $instance->enrolstartdate = 0;
+ $instance->enrolenddate = 0;
+ }
+
+ if (empty($instance->id)) {
+ $instance->timecreated = $instance->timemodified;
+ $instance->sortorder = $DB->get_field('enrol', 'COALESCE(MAX(sortorder), -1) + 1', array('courseid'=>$course->id));
+ $DB->insert_record('enrol', $instance);
+ } else {
+ $DB->update_record('enrol', $instance);
+ }
+
+ } else {
+ if ($instance) {
+ // bad luck, user can not change anything
+ } else {
+ $this->add_default_instance($course);
+ }
+ }
+ }
+
+ /**
+ * Add new instance of enrol plugin with default settings.
+ * @param object $course
+ * @return int id of new instance
+ */
+ public function add_default_instance($course) {
+ global $DB;
+
+ $instance = new object();
+ $instance->enrol = 'self';
+ $instance->status = $this->get_config('status');
+ $instance->courseid = $course->id;
+ $instance->customint1 = $this->get_config('groupkey');
+ $instance->defaultrole = $this->get_config('role');
+ $instance->enrolperiod = $this->get_config('enrolperiod');
+ $instance->enrolstartdate = 0;
+ $instance->enrolenddate = 0;
+ $instance->timemodified = time();
+ $instance->timecreated = $instance->timemodified;
+ $instance->sortorder = $DB->get_field('enrol', 'COALESCE(MAX(sortorder), -1) + 1', array('courseid'=>$course->id));
+
+ if ($this->get_config('requirepassword')) {
+ $instance->password = generate_password(20);
+ }
+
+ return $DB->insert_record('enrol', $instance);
+ }
+
+ /**
+ * Send welcome email to specified user
+ *
+ * @param object $instance
+ * @param object $user user record
+ * @return void
+ */
+ protected function email_welcome_message($instance, $user) {
+ global $CFG, $DB;
+
+ $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
+
+ if (!empty($instance->customtext1)) {
+ //note: there is no gui for this yet, do we really need it?
+ $message = formaat_string($instance->customtext1);
+ } else {
+ $a = new object();
+ $a->coursename = format_string($course->fullname);
+ $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id";
+ $message = get_string("welcometocoursetext", 'enrol_self', $a);
+ }
+
+ $subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname));
+
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $rusers = null;
+ if (!empty($CFG->coursecontact)) {
+ $croles = explode(',', $CFG->coursecontact);
+ $rusers = get_role_users($croles, $context, true, '', 'r.sortorder ASC, u.lastname ASC');
+ }
+ if ($rusers) {
+ $contact = reset($rusers);
+ } else {
+ $contact = get_admin();
+ }
+
+ email_to_user($user, $contact, $subject, $message);
+ }
+}
+
+
Index: lib/simpletest/testaccesslib.php
===================================================================
--- lib/simpletest/testaccesslib.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ lib/simpletest/testaccesslib.php (revision )
@@ -261,10 +261,6 @@
$context = $contexts['cou'];
$context->id = SYSCONTEXTID + 2;
- $this->load_test_data('capabilities',
- array('name'), array(
- array('moodle/course:participate')));
-
$roles = $this->load_test_data('role',
array( 'name', 'shortname', 'description', 'sortorder'), array(
'admin' => array('admin', 'admin', 'not null', 1),
@@ -274,14 +270,8 @@
$adminid = $roles['admin']->id;
$r1id = $roles['r1']->id;
$r2id = $roles['r2']->id;
- $funnyid = $roles['funny']->id; // strange role to test that roles with 'moodle/course:participate' are not returned.
+ $funnyid = $roles['funny']->id; // strange role
- $this->load_test_data('role_capabilities',
- array('roleid', 'capability', 'contextid', 'permission'), array(
- array( $r1id, 'moodle/course:participate', SYSCONTEXTID + 1, CAP_ALLOW),
- array( $r2id, 'moodle/course:participate', SYSCONTEXTID, CAP_ALLOW),
- array($funnyid, 'moodle/course:participate', SYSCONTEXTID, CAP_ALLOW)));
-
$this->load_test_data('role_assignments',
array('userid', 'contextid', 'roleid'), array(
array( 1, SYSCONTEXTID, $adminid),
@@ -295,13 +285,6 @@
array( $r2id , $r2id),
array( $r2id , $funnyid)));
- // Admin should be able to switch to any role with 'moodle/course:participate' in any context.
- $this->switch_global_user_id(1);
- accesslib_clear_all_caches_for_unit_testing();
- $this->assert(new ArraysHaveSameValuesExpectation(array($r2id)), array_keys(get_switchable_roles($syscontext)));
- $this->assert(new ArraysHaveSameValuesExpectation(array($r2id)), array_keys(get_switchable_roles($context)));
- $this->revert_global_user_id();
-
// r1 should be able to switch to r2, but this user only has r1 in $context, not $syscontext.
$this->switch_global_user_id(2);
accesslib_clear_all_caches_for_unit_testing();
@@ -316,21 +299,5 @@
$this->assert(new ArraysHaveSameValuesExpectation(array($r2id)), array_keys(get_switchable_roles($context)));
}
- function test_get_allowed_switchable_roles() {
- $this->create_test_table('role_capabilities', 'lib');
-
- $this->load_test_data('role_capabilities',
- array('roleid', 'capability', 'contextid', 'permission'), array(
- array( 1, 'moodle/forum:replypost', SYSCONTEXTID, CAP_ALLOW),
- array( 2, 'moodle/course:participate', SYSCONTEXTID, CAP_ALLOW),
- array( 4, 'moodle/course:participate', SYSCONTEXTID, CAP_ALLOW),
- array( 5, 'moodle/course:participate', SYSCONTEXTID, CAP_ALLOW),
- array( 6, 'moodle/course:participate', SYSCONTEXTID, CAP_PREVENT),
- ));
-
- $this->switch_to_test_db();
-
- $this->assert(new ArraysHaveSameValuesExpectation(array(2, 5)), array_keys(get_allowed_switchable_roles()));
- }
+}
-}
Index: admin/settings/plugins.php
===================================================================
--- admin/settings/plugins.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ admin/settings/plugins.php (revision )
@@ -51,6 +51,47 @@
}
+ // Enrolment plugins
+ $ADMIN->add('modules', new admin_category('enrolments', get_string('enrolments')));
+ $temp = new admin_settingpage('manageenrols', get_string('manageenrols', 'enrol'));
+ $temp->add(new admin_setting_manageenrols());
+ if (empty($CFG->enrol_plugins_enabled)) {
+ $enabled = array();
+ } else {
+ $enabled = explode(',', $CFG->enrol_plugins_enabled);
+ }
+ $enrols = get_plugin_list('enrol');
+ $options = array();
+ foreach($enrols as $enrol=>$enrolpath) {
+ if (!file_exists("$enrolpath/lib.php")) {
+ continue;
+ }
+ if (!in_array($enrol, $enabled)) {
+ continue;
+ }
+ $options[$enrol] = get_string('pluginname', 'enrol_'.$enrol);
+ }
+ if ($options) {
+ $temp->add(new admin_setting_configmultiselect('enrol_plugins_default', get_string('defaultenrols', 'enrol'), get_string('defaultenrols_desc', 'enrol'), array('manual', 'self', 'guest'), $options));
+ }
+ $ADMIN->add('enrolments', $temp);
+ foreach($enrols as $enrol=>$enrolpath) {
+ if (!file_exists("$enrolpath/settings.php")) {
+ continue;
+ }
+
+ $settings = new admin_settingpage('enrolsettings'.$enrol, get_string('pluginname', 'enrol_'.$enrol), 'moodle/site:config', !in_array($enrol, $enabled));
+ // settings.php may create a subcategory or unset the settings completely
+ include("$enrolpath/settings.php");
+ if ($settings) {
+ $ADMIN->add('enrolments', $settings);
+ }
+
+ }
+ unset($enabled);
+ unset($enrols);
+
+
/// Editor plugins
$ADMIN->add('modules', new admin_category('editorsettings', get_string('editors', 'editor')));
$temp = new admin_settingpage('manageeditors', get_string('editorsettings', 'editor'));
Index: enrol/self/version.php
===================================================================
--- enrol/self/version.php (revision )
+++ enrol/self/version.php (revision )
@@ -0,0 +1,25 @@
+.
+
+/**
+ * Self enrolment plugin.
+ *
+ * @package enrol_self
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$plugin->version = 2010042302;
Index: backup/restore_check.html
===================================================================
--- backup/restore_check.html (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ backup/restore_check.html (revision )
@@ -92,8 +92,6 @@
}
//restoreto
$restore_restoreto = required_param('restore_restoreto', PARAM_INT);
- //restore_metacourse
- $restore_metacourse = required_param('restore_metacourse', PARAM_INT);
//restore_users
$restore_users = required_param('restore_users', PARAM_INT);
@@ -140,7 +138,6 @@
}
}
$restore->restoreto=$restore_restoreto;
- $restore->metacourse=$restore_metacourse;
$restore->users=$restore_users;
$restore->groups=$restore_groups;
$restore->logs=$restore_logs;
@@ -220,15 +217,9 @@
//Check site
$site = get_site();
- // Non-cached - get accessinfo
- if (isset($USER->access)) {
- $accessinfo = $USER->access;
- } else {
- $accessinfo = get_user_access_sitewide($USER->id);
- }
-
// Get all the courses the user is able to restore to
- $mycourses = get_user_courses_bycap($USER->id, 'moodle/restore:restorecourse', $accessinfo, true, 'c.sortorder ASC', array('id', 'fullname', 'shortname', 'visible'));
+ //TODO: use better function which includes all courses for admins
+ $mycourses = get_user_courses_bycap($USER->id, 'moodle/restore:restorecourse');
// Calculate if the user can create courses
$cancreatecourses = user_can_create_courses();
Index: enrol/flatfile/enrol.php
===================================================================
--- enrol/flatfile/enrol.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ enrol/flatfile/enrol.php (revision )
@@ -187,9 +187,10 @@
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if ($fields[0] == 'add') {
- role_assign($roleid, $user->id, null, $context->id, $fields[4], $fields[5], 0, 'flatfile');
+ // TODO: real enrol, and maybe manual
+ role_assign($roleid, $user->id, $context->id, 'enrol_flatfile');
} else {
- role_unassign($roleid, $user->id, null, $context->id);
+ role_unassign($roleid, $user->id, $context->id);
}
Index: admin/mnet/enr_course_enrol.php
===================================================================
--- admin/mnet/enr_course_enrol.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ admin/mnet/enr_course_enrol.php (revision )
@@ -12,8 +12,7 @@
admin_externalpage_setup('mnetenrol');
- require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
- $enrolment = enrolment_factory::factory('mnet');
+ $enrolment = enrol_get_plugin('mnet');
$mnethostid = required_param('host', PARAM_INT);
$courseid = required_param('courseid', PARAM_INT);
@@ -278,7 +277,7 @@
/// Print the page
/// get language strings
-$str = get_strings(array('enrolmentplugins', 'configuration', 'users', 'administration'));
+$str = get_strings(array('configuration', 'users', 'administration'));
/// Get some language strings
$strpotentialusers = get_string('potentialusers', 'role');
Index: enrol/guest/lib.php
===================================================================
--- enrol/guest/lib.php (revision )
+++ enrol/guest/lib.php (revision )
@@ -0,0 +1,277 @@
+.
+
+/**
+ * Guest access plugin.
+ *
+ * This plugin does not add any entries into the course_participants table,
+ * the access control is granted on the fly via the tricks in require_login().
+ *
+ * @package enrol_guest
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class enrol_guest_plugin extends enrol_plugin {
+
+ public function enrol_user(stdClass $instance, $userid, $timestart = 0, $timeend = 0, $roleid = null) {
+ // no real enrolments here
+ return;
+ }
+
+ public function unenrol_user(stdClass $instance, $userid) {
+ // nothing to do, we never enrol here
+ return;
+ }
+
+ /**
+ * Attempt to automatically gain temporary guest access to course,
+ * 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)) {
+ // Temporarily assign them some guest role for this context
+ $context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
+ $USER->access = load_temp_role($context, $CFG->guestroleid, $USER->access);
+ return ENROL_REQUIRE_LOGIN_CACHE_PERIOD;
+ }
+
+ return false;
+ }
+
+ /**
+ * Creates course enrol form, checks if form submitted
+ * and enrols user if necessary. It can also redirect.
+ *
+ * @param stdClass $instance
+ * @return string html text, usually a form in a text box
+ */
+ public function enrol_page_hook(stdClass $instance) {
+ global $CFG, $OUTPUT, $SESSION, $USER;
+
+ if (empty($instance->password)) {
+ return null;
+ }
+
+ require_once("$CFG->dirroot/enrol/guest/locallib.php");
+ $form = new enrol_guest_enrol_form(NULL, $instance);
+ $instanceid = optional_param('instance', 0, PARAM_INT);
+
+ if ($instance->id == $instanceid) {
+ if ($data = $form->get_data()) {
+ // set up 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->access = load_temp_role($context, $CFG->guestroleid, $USER->access);
+
+ // go to the originally requested page
+ if (!empty($SESSION->wantsurl)) {
+ $destination = $SESSION->wantsurl;
+ unset($SESSION->wantsurl);
+ } else {
+ $destination = "$CFG->wwwroot/course/view.php?id=$instance->courseid";
+ }
+ redirect($destination);
+ }
+ }
+
+ ob_start();
+ $form->display();
+ $output = ob_get_clean();
+
+ return $OUTPUT->box($output, 'generalbox');
+ }
+
+ /**
+ * Adds enrol instance UI to course edit form
+ *
+ * @param object $instance enrol instance or null if does not exist yet
+ * @param MoodleQuickForm $mform
+ * @param object $data
+ * @param object $context context of existing course or parent category if course does not exist
+ * @return void
+ */
+ public function course_edit_form($instance, MoodleQuickForm $mform, $data, $context) {
+
+ $i = isset($instance->id) ? $instance->id : 0;
+ $plugin = enrol_get_plugin('guest');
+ $header = $plugin->get_instance_name($instance);
+ $config = has_capability('enrol/guest:config', $context);
+
+ $mform->addElement('header', 'enrol_guest_header_'.$i, $header);
+
+
+ $options = array(ENROL_STATUS_ENABLED => get_string('yes'),
+ ENROL_STATUS_DISABLED => get_string('no'));
+ $mform->addElement('select', 'enrol_guest_status_'.$i, get_string('status', 'enrol_guest'), $options);
+ $mform->setDefault('enrol_guest_status_'.$i, $this->get_config('status'));
+ $mform->setAdvanced('enrol_guest_status_'.$i, $this->get_config('status_adv'));
+ if (!$config) {
+ $mform->hardFreeze('enrol_guest_status_'.$i);
+ }
+
+ $mform->addElement('passwordunmask', 'enrol_guest_password_'.$i, get_string('password', 'enrol_guest'));
+ if (!$config) {
+ $mform->hardFreeze('enrol_guest_password_'.$i);
+ } else {
+ $mform->disabledIf('enrol_guest_password_'.$i, 'enrol_guest_status_'.$i, 'noteq', ENROL_STATUS_ENABLED);
+ }
+
+
+ // now add all values from enrol table
+ if ($instance) {
+ foreach($instance as $key=>$val) {
+ $data->{'enrol_guest_'.$key.'_'.$i} = $val;
+ }
+ }
+ }
+
+ /**
+ * Validates course edit form data
+ *
+ * @param object $instance enrol instance or null if does not exist yet
+ * @param array $data
+ * @param object $context context of existing course or parent category if course does not exist
+ * @return array errors array
+ */
+ public function course_edit_validation($instance, array $data, $context) {
+ $errors = array();
+
+ if (!has_capability('enrol/guest:config', $context)) {
+ // we are going to ignore the data later anyway, they would nto be able to fix the form anyway
+ return $errors;
+ }
+
+ $i = isset($instance->id) ? $instance->id : 0;
+
+ $password = empty($data['enrol_guest_password_'.$i]) ? '' : $data['enrol_guest_password_'.$i];
+ $checkpassword = false;
+
+ if ($instance) {
+ if ($data['enrol_guest_status_'.$i] == ENROL_STATUS_ENABLED) {
+ if ($instance->password !== $password) {
+ $checkpassword = true;
+ }
+ }
+ } else {
+ if ($data['enrol_guest_status_'.$i] == ENROL_STATUS_ENABLED) {
+ $checkpassword = true;
+ }
+ }
+
+ if ($checkpassword) {
+ $require = $this->get_config('requirepassword');
+ $policy = $this->get_config('usepasswordpolicy');
+ if ($require and empty($password)) {
+ $errors['enrol_guest_password_'.$i] = get_string('required');
+ } else if ($policy) {
+ $errmsg = '';//prevent eclipse warning
+ if (!check_password_policy($password, $errmsg)) {
+ $errors['enrol_guest_password_'.$i] = $errmsg;
+ }
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
+ * Called after updating/inserting course.
+ *
+ * @param object $instance enrol instance, null if does not exist yet
+ * @param object $course
+ * @param object $data form data
+ * @return void
+ */
+ public function course_updated($instance, $course, $data) {
+ global $DB;
+
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+ if (has_capability('enrol/guest:config', $context)) {
+ if ($instance) {
+ $i = $instance->id;
+ } else {
+ $i = 0;
+ $instance = new object();
+ $instance->enrol = 'guest';
+ $instance->courseid = $course->id;
+ }
+
+ $instance->status = $data->{'enrol_guest_status_'.$i};
+ $instance->timemodified = time();
+
+ if ($instance->status == ENROL_STATUS_ENABLED) {
+ $instance->password = $data->{'enrol_guest_password_'.$i};
+ } else if (empty($instance->id)) {
+ if ($this->get_config('requirepassword')) {
+ // make sure some password is set after enabling this plugin
+ $instance->password = generate_password(20);
+ }
+ }
+
+ if (empty($instance->id)) {
+ $instance->timecreated = $instance->timemodified;
+ $instance->sortorder = $DB->get_field('enrol', 'COALESCE(MAX(sortorder), -1) + 1', array('courseid'=>$course->id));
+ $DB->insert_record('enrol', $instance);
+ } else {
+ $DB->update_record('enrol', $instance);
+ }
+
+ } else {
+ if ($instance) {
+ // bad luck, user can not change anything
+ } else {
+ $this->add_default_instance($course);
+ }
+ }
+ }
+
+ /**
+ * Add new instance of enrol plugin with default settings.
+ * @param object $course
+ * @return int id of new instance
+ */
+ public function add_default_instance($course) {
+ global $DB;
+
+ $instance = new object();
+ $instance->enrol = 'guest';
+ $instance->status = $this->get_config('status');
+ $instance->courseid = $course->id;
+ $instance->timemodified = time();
+ $instance->timecreated = $instance->timemodified;
+ $instance->sortorder = $DB->get_field('enrol', 'COALESCE(MAX(sortorder), -1) + 1', array('courseid'=>$course->id));
+
+ if ($this->get_config('requirepassword')) {
+ $instance->password = generate_password(20);
+ }
+
+ return $DB->insert_record('enrol', $instance);
+ }
+
+}
+
Index: admin/bloglevelupgrade.php
===================================================================
--- admin/bloglevelupgrade.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ admin/bloglevelupgrade.php (revision )
@@ -48,7 +48,7 @@
$a->blogcount = 0;
foreach ($bloggers as $blogger) {
- $courses = get_my_courses($blogger->userid);
+ $courses = enrol_get_users_courses($blogger->userid, true, 'groupmode,groupmodeforce');
$blogentries = $DB->get_records('post', array('module' => 'blog', 'userid' => $blogger->userid));
foreach ($courses as $course) {
Index: enrol/paypal/return.php
===================================================================
--- enrol/paypal/return.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ enrol/paypal/return.php (revision )
@@ -25,7 +25,7 @@
$destination = "$CFG->wwwroot/course/view.php?id=$course->id";
}
- if (has_capability('moodle/course:participate', $context)) {
+ if (is_enrolled($context, NULL, '', true)) { // TODO: use real paypal check
redirect($destination, get_string('paymentthanks', '', $course->fullname));
} else { /// Somehow they aren't enrolled yet! :-(
Index: enrol/cohort/lib.php
===================================================================
--- enrol/cohort/lib.php (revision )
+++ enrol/cohort/lib.php (revision )
@@ -0,0 +1,30 @@
+.
+
+/**
+ * Cohort enrolment plugin.
+ *
+ * @package enrol_cohort
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+class enrol_cohort_plugin extends enrol_plugin {
+
+}
+
Index: enrol/guest/version.php
===================================================================
--- enrol/guest/version.php (revision )
+++ enrol/guest/version.php (revision )
@@ -0,0 +1,25 @@
+.
+
+/**
+ * Guest access plugin.
+ *
+ * @package enrol_guest
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$plugin->version = 2010042302;
Index: lib/navigationlib.php
===================================================================
--- lib/navigationlib.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ lib/navigationlib.php (revision )
@@ -932,7 +932,7 @@
$CFG->navshowcategories = false;
}
- $this->mycourses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', null, false, $limit);
+ $this->mycourses = enrol_get_my_courses(NULL, 'visible DESC,sortorder ASC', $limit);
$showallcourses = (count($this->mycourses) == 0 || !empty($CFG->navshowallcourses));
$showcategories = ($showallcourses && !empty($CFG->navshowcategories));
@@ -1645,7 +1645,7 @@
public function add_course(stdClass $course, $forcegeneric = false) {
global $CFG;
$canviewhidden = has_capability('moodle/course:viewhiddencourses', $this->page->context);
- if ($course->id !== SITEID && !$canviewhidden && (!$course->visible || !course_parent_visible($course))) {
+ if ($course->id !== SITEID && !$canviewhidden && !$course->visible) {
return false;
}
@@ -2661,6 +2661,11 @@
}
}
+ if (has_capability('moodle/course:enrolreview', $coursecontext)) {
+ $url = new moodle_url('/enrol/review.php', array('id'=>$course->id));
+ $coursenode->add(get_string('enrolments'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/roles', ''));
+ }
+
if (has_capability('moodle/role:assign', $coursecontext)) {
// Add assign or override roles if allowed
$url = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$coursecontext->id));
@@ -2710,17 +2715,6 @@
$coursenode->add(get_string('outcomes', 'grades'), $url, self::TYPE_SETTING, null, 'outcomes', new pix_icon('i/outcomes', ''));
}
- // Add meta course links
- if ($course->metacourse) {
- if (has_capability('moodle/course:managemetacourse', $coursecontext)) {
- $url = new moodle_url('/course/importstudents.php', array('id'=>$course->id));
- $coursenode->add(get_string('childcourses'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/course', ''));
- } else if (has_capability('moodle/role:assign', $coursecontext)) {
- $roleassign = $coursenode->add(get_string('childcourses'), null, self::TYPE_SETTING, null, null, new pix_icon('i/course', ''));
- $roleassign->hidden = true;
- }
- }
-
// Manage groups in this course
if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $coursecontext)) {
$url = new moodle_url('/group/index.php', array('id'=>$course->id));
@@ -2777,7 +2771,8 @@
$coursenode->add(get_string('files'), $url, self::TYPE_SETTING, null, 'coursefiles', new pix_icon('i/files', ''));
}
- // Authorize hooks
+ // TODO: rework enrol hooks!!!!
+ /*
if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize')) {
require_once($CFG->dirroot.'/enrol/authorize/const.php');
$url = new moodle_url('/enrol/authorize/index.php', array('course'=>$course->id));
@@ -2789,21 +2784,21 @@
$coursenode->add(get_string('paymentpending', 'moodle', $cnt), $url, self::TYPE_SETTING, null, null, new pix_icon('i/payment', ''));
}
}
- }
+ }*/
// Unenrol link
- if (empty($course->metacourse) && ($course->id!==SITEID)) {
+ if ($course->id!==SITEID) {
if (is_enrolled(get_context_instance(CONTEXT_COURSE, $course->id))) {
- if (has_capability('moodle/role:unassignself', $this->page->context, NULL, false) and get_user_roles($this->page->context, $USER->id, false)) { // Have some role
+ /*if (..detect if can unenrol somehow and probably cache it..) {
$this->content->items[]=''.get_string('unenrolme', '', format_string($course->shortname)).'';
$this->content->icons[]='';
- }
+ }*/
} else if (is_viewing(get_context_instance(CONTEXT_COURSE, $course->id))) {
// inspector, manager, etc. - do not show anything
} else {
// access because otherwise they would not get into this course at all
- $this->content->items[]=''.get_string('enrolme', '', format_string($course->shortname)).'';
+ $this->content->items[]=''.get_string('enrolme', '', format_string($course->shortname)).'';
$this->content->icons[]='';
}
}
@@ -3013,7 +3008,7 @@
// Check that the user can view the profile
$usercontext = get_context_instance(CONTEXT_USER, $user->id); // User context
if ($course->id==SITEID) {
- if ($CFG->forceloginforprofiles && !!has_coursemanager_role($user->id) && !has_capability('moodle/user:viewdetails', $usercontext)) { // Reduce possibility of "browsing" userbase at site level
+ if ($CFG->forceloginforprofiles && !!has_coursecontact_role($user->id) && !has_capability('moodle/user:viewdetails', $usercontext)) { // Reduce possibility of "browsing" userbase at site level
// Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
return false;
}
Index: course/lib.php
===================================================================
--- course/lib.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ course/lib.php (revision )
@@ -1950,7 +1950,7 @@
echo "\n\n".'
\n";
-
-echo $OUTPUT->footer();
-
Index: lib/db/access.php
===================================================================
--- lib/db/access.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ lib/db/access.php (revision )
@@ -596,19 +596,6 @@
)
),
- 'moodle/role:unassignself' => array(
-
- 'captype' => 'write',
- 'contextlevel' => CONTEXT_COURSE,
- 'archetypes' => array(
- 'student' => (empty($CFG->allowunenrol)) ? CAP_INHERIT : CAP_ALLOW,
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- )
- ),
-
'moodle/role:switchroles' => array(
'riskbitmask' => RISK_XSS | RISK_PERSONAL,
@@ -727,6 +714,7 @@
/* originally this capability was called moodle/course:view,
* but since 2.0 it is used for access to course without the enrolment
+ * TODO: remove when enrol migration finished!
*/
'moodle/course:participate' => array(
@@ -748,6 +736,32 @@
)
),
+ /* review course enrolments */
+ 'moodle/course:enrolreview' => array(
+
+ 'riskbitmask' => RISK_PERSONAL,
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW,
+ )
+ ),
+
+ /* config enrol instances */
+ 'moodle/course:enrolconfig' => array(
+
+ 'riskbitmask' => RISK_PERSONAL,
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW,
+ )
+ ),
+
'moodle/course:bulkmessaging' => array(
'riskbitmask' => RISK_SPAM,
@@ -819,18 +833,6 @@
)
),
- 'moodle/course:managemetacourse' => array(
-
- 'riskbitmask' => RISK_XSS | RISK_PERSONAL,
-
- 'captype' => 'write',
- 'contextlevel' => CONTEXT_COURSE,
- 'archetypes' => array(
- 'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- )
- ),
-
'moodle/course:activityvisibility' => array(
'captype' => 'write',
Index: enrol/self/lang/en/enrol_self.php
===================================================================
--- enrol/self/lang/en/enrol_self.php (revision )
+++ enrol/self/lang/en/enrol_self.php (revision )
@@ -0,0 +1,57 @@
+.
+
+/**
+ * Strings for component 'enrol_self', language 'en', branch 'MOODLE_20_STABLE'
+ *
+ * @package enrol_self
+ * @copyright 2010 onwards Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['enrolenddate'] = 'End date';
+$string['enrolenddaterror'] = 'Enrolment end date cannot be earlier than start date';
+$string['enrolme'] = 'Enrol me';
+$string['enrolperiod'] = 'Enrolment period';
+$string['enrolperiod_desc'] = 'Default length of the enrolment period (in seconds).'; //TODO: fixme
+$string['enrolstartdate'] = 'Start date';
+$string['groupkey'] = 'Use group enrolment keys';
+$string['groupkey_desc'] = 'Use group enrolment keys by default.';
+$string['password'] = 'Enrolment key';
+$string['passwordinvalid'] = 'Incorrect enrolment key, please try again';
+$string['passwordinvalidhint'] = 'That enrolment key was incorrect, please try again
+(Here\'s a hint - it starts with \'{$a}\')';
+$string['pluginname'] = 'Self enrolment';
+$string['pluginname_desc'] = 'The self enrolment plugin allows users to choose which courses they want to participate in. The courses may be protected by an enrolment key. Internally the enrolment is done via the manual enrolmnet plugin which has to be enabled in the same course.';
+$string['requirepassword'] = 'Require enrolment key';
+$string['requirepassword_desc'] = 'Require enrolment key in new courses and prevent prevent removing of enrolment key from existing courses.';
+$string['role'] = 'Assign role';
+$string['role_desc'] = 'Select role which should be assigned to users during self enrolment';
+$string['sendcoursewelcomemessage'] = 'Send course welcome message';
+$string['sendcoursewelcomemessage_desc'] = 'If enabled, users receive a welcome message via email when they self-enrol in a course.';
+$string['showhint'] = 'Show hint';
+$string['showhint_desc'] = 'Show first letter of the guest access key.';
+$string['status'] = 'Allow self enrolments';
+$string['status_desc'] = 'Allow users to self enrol into course by default.';
+$string['usepasswordpolicy'] = 'Use password policy';
+$string['usepasswordpolicy_desc'] = 'Use standard password policy for enrolment keys.';
+$string['welcometocourse'] = 'Welcome to {$a}';
+$string['welcometocoursetext'] = 'Welcome to {$a->coursename}!
+
+If you have not done so already, you should edit your profile page so that we can learn more about you:
+
+ {$a->profileurl}';
Index: admin/settings/frontpage.php
===================================================================
--- admin/settings/frontpage.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ admin/settings/frontpage.php (revision )
@@ -50,7 +50,6 @@
$temp->add(new admin_setting_configtext('commentsperpage', get_string('commentsperpage', 'admin'), '', 15, PARAM_INT));
$temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
- $temp->add(new admin_setting_configcheckbox('allowvisiblecoursesinhiddencategories', get_string('allowvisiblecoursesinhiddencategories', 'admin'), get_string('configvisiblecourses', 'admin'), 0));
// front page default role
$roleoptions = array(0=>get_string('none')); // roles to choose from
Index: user/index.php
===================================================================
--- user/index.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ user/index.php (revision )
@@ -11,7 +11,6 @@
define('SHOW_ALL_PAGE_SIZE', 5000);
define('MODE_BRIEF', 0);
define('MODE_USERDETAILS', 1);
- define('MODE_ENROLDETAILS', 2);
$page = optional_param('page', 0, PARAM_INT); // which page to show
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page
@@ -199,7 +198,7 @@
$controlstable->data[] = new html_table_row();
/// Print my course menus
- if ($mycourses = get_my_courses($USER->id)) {
+ if ($mycourses = enrol_get_my_courses()) {
$courselist = array();
$popupurl = new moodle_url('/user/index.php?roleid='.$roleid.'&sifirst=&silast=');
foreach ($mycourses as $mycourse) {
@@ -273,27 +272,8 @@
}
}
- // Decide wheteher we will fetch extra enrolment/groups data.
- //
- // MODE_ENROLDETAILS is expensive, and only suitable where the listing is small
- // (at or below DEFAULT_PAGE_SIZE) and $USER can enrol/unenrol
- // (will take 1 extra DB query - 2 on Oracle)
- //
- if (!$isfrontpage && ($perpage <= DEFAULT_PAGE_SIZE) && has_capability('moodle/role:assign',$context)) {
- $allowenroldetails = true;
- } else {
- $allowenroldetails = false;
- if ($mode === MODE_ENROLDETAILS) {
- // conditions haven't been met - reset
- $mode = MODE_BRIEF;
- }
- }
-
$formatmenu = array( '0' => get_string('brief'),
'1' => get_string('userdetails'));
- if ($allowenroldetails) {
- $formatmenu['2']= get_string('enroldetails');
- }
$select = new single_select($baseurl, 'mode', $formatmenu, $mode, null, 'formatmenu');
$select->set_label(get_string('userlist'));
$userlistcell = new html_table_cell();
@@ -350,22 +330,6 @@
$tableheaders[] = get_string('lastaccess');
}
- if ($course->enrolperiod and $roleid) {
- $tablecolumns[] = 'timeend';
- $tableheaders[] = get_string('enrolmentend');
- }
-
- if ($mode === MODE_ENROLDETAILS) {
- $tablecolumns[] = 'roles';
- $tableheaders[] = get_string('roles');
- if ($groupmode != 0) {
- $tablecolumns[] = 'groups';
- $tableheaders[] = get_string('groups');
- $tablecolumns[] = 'groupings';
- $tableheaders[] = get_string('groupings', 'group');
- }
- }
-
if ($bulkoperations) {
$tablecolumns[] = 'select';
$tableheaders[] = get_string('select');
@@ -403,7 +367,7 @@
// we are looking for all users with this role assigned in this context or higher
$contextlist = get_related_contexts_string($context);
- list($esql, $params) = get_enrolled_sql($context, NULL, $currentgroup, 'eu');
+ list($esql, $params) = get_enrolled_sql($context, NULL, $currentgroup);
$joins = array("FROM {user} u");
$wheres = array();
@@ -428,17 +392,7 @@
if ($accesssince) {
$wheres[] = get_course_lastaccess_sql($accesssince);
}
-
- if ($course->enrolperiod) {
- // note: this is extremely tricky now, we do not know which ra assignment
- // is the one causing enrolment - better show it onl when filtering by roles
-
- if ($roleid) {
- $select .= ", (SELECT MAX(rax.timeend) FROM {role_assignments} rax WHERE rax.userid = u.id AND rax.contextid $contextlist AND rax.roleid = :raxroleid) AS timeend";
- $params['raxroleid'] = $roleid;
- }
+ }
- }
- }
// performance hacks - we preload user contexts together with accounts
list($ccselect, $ccjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
@@ -495,17 +449,6 @@
// list of users at the current visible page - paging makes it relatively short
$userlist = $DB->get_recordset_sql("$select $from $where $sort", $params, $table->get_page_start(), $table->get_page_size());
- //
- // The SELECT behind get_participants_extra() is cheaper if we pass an array
- // if IDs. We could pass the SELECT we did before (with the limit bits - tricky!)
- // but this is much cheaper. And in any case, it is only doable with limited numbers
- // of rows anyway. On a large course it will explode badly...
- //
- if ($mode === MODE_ENROLDETAILS) {
- $userids = $DB->get_fieldset_sql("SELECT u.id $from $where", $params, $table->get_page_start(), $table->get_page_size());
- $userlist_extra = get_participants_extra($userids, $course, $context);
- }
-
/// If there are multiple Roles in the course, then show a drop down menu for switching
if (count($rolenames) > 1) {
echo '
';
@@ -710,7 +653,7 @@
}
if (has_capability('moodle/role:assign', $context) and get_user_roles($context, $user->id, false)) { // I can unassign and user has some role
- $links[] = html_writer::link(new moodle_url('/course/unenrol.php?id='. $course->id .'&user='. $user->id), get_string('unenrol'));
+ $links[] = html_writer::link(new moodle_url('/enrol/unenrol.php?id='. $course->id .'&user='. $user->id), get_string('unenrol'));
}
if ($USER->id != $user->id && !session_is_loggedinas() && has_capability('moodle/user:loginas', $context) && !is_siteadmin($user->id)) {
@@ -740,14 +683,6 @@
if ($userlist) {
- // only show the plugin if multiple enrolment plugins
- // are enabled...
- if (strpos($CFG->enrol_plugins_enabled, ',')=== false) {
- $showenrolplugin = true;
- } else {
- $showenrolplugin = false;
- }
-
$usersprinted = array();
foreach ($userlist as $user) {
if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
@@ -794,13 +729,6 @@
if (!isset($hiddenfields['lastaccess'])) {
$data[] = $lastaccess;
}
- if ($course->enrolperiod and $roleid) {
- if ($user->timeend) {
- $data[] = userdate($user->timeend, $timeformat);
- } else {
- $data[] = get_string('unlimited');
- }
- }
if (isset($userlist_extra) && isset($userlist_extra[$user->id])) {
$ras = $userlist_extra[$user->id]['ra'];
@@ -814,12 +742,7 @@
} else {
$rastring .= $rolename;
}
- if ($showenrolplugin) {
- $rastring .= ' ';
- } else {
- $rastring .= ' ('. $ra['enrolplugin'] .') ';
- }
+ }
- }
$data[] = $rastring;
if ($groupmode != 0) {
// htmlescape with s() and implode the array
@@ -851,11 +774,6 @@
$displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
}
- if ($context->id != $frontpagectx->id) {
- $displaylist['extendenrol.php'] = get_string('extendenrol');
- $displaylist['groupextendenrol.php'] = get_string('groupextendenrol');
- }
-
echo $OUTPUT->old_help_icon("participantswithselectedusers", get_string("withselectedusers"));
echo html_writer::tag('label', get_string("withselectedusers"), array('for'=>'formactionid'));
echo html_writer::select($displaylist, 'formaction', '', array(''=>'choosedots'), array('id'=>'formactionid'));
@@ -947,7 +865,6 @@
ctx.contextlevel AS ctxlevel, ctx.instanceid AS ctxinstanceid,
cc.name AS ccname,
ra.roleid AS roleid,
- ra.enrol AS enrolplugin,
g.id AS gid, g.name AS gname
$gpselect
FROM {role_assignments} ra
@@ -981,11 +898,6 @@
// ctxname => 'name' (categories only)
// ctxinstid =>
// roleid => $roleid
- // enrol => $pluginname
- //
- // Might be interesting to add to RA timestart, timeend, timemodified,
- // and modifierid (with an outer join to mdl_user!
- //
foreach ($rs as $rec) {
$userid = $rec->userid;
@@ -1009,8 +921,7 @@
'ctxlevel' => $rec->ctxlevel,
'ctxinstanceid' => $rec->ctxinstanceid,
'ccname' => $rec->ccname,
- 'roleid' => $rec->roleid,
- 'enrolplugin' => $rec->enrolplugin);
+ 'roleid' => $rec->roleid);
}
}
Index: lang/en/error.php
===================================================================
--- lang/en/error.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ lang/en/error.php (revision )
@@ -104,7 +104,6 @@
$string['cannotmanualctrack'] = 'Activity does not provide manual completion tracking';
$string['cannotmapfield'] = 'Mapping collision detected - two fields maps to the same grade item {$a}';
$string['cannotmarktopic'] = 'Could not mark that topic for this course';
-$string['cannotmetacourse'] = 'Cannot not add the selected course to this meta course!';
$string['cannotmigratedatacomments'] = 'Cannot migrate data module comments';
$string['cannotmodulename'] = 'Cannot get the module name in build navigation';
$string['cannotmoduletype'] = 'Cannot get the module type in build navigation';
@@ -160,8 +159,6 @@
$string['cannotusepage2'] = 'Sorry, you may not use this page';
$string['cannotviewprofile'] = 'You cannot view the profile of this user';
$string['cannotwritefile'] = 'Cannot write to file ({$a})';
-$string['cantunenrollfrommetacourse'] = 'You cannot unenrol from this meta course';
-$string['cantunenrollinthisrole'] = 'You cannot unenrol from this course while you are in your current role';
$string['commentmisconf'] = 'Comment ID is misconfigured';
$string['componentisuptodate'] = 'Component is up-to-date';
$string['confirmsesskeybad'] = 'Sorry, but your session key could not be confirmed to carry out this action. This security feature prevents against accidental or malicious execution of important functions in your name. Please make sure you really wanted to execute this function.';
@@ -270,7 +267,6 @@
$string['invalidcoursenameshort'] = 'Invalid short course name';
$string['invaliddata'] = 'Data submitted is invalid';
$string['invalidelementid'] = 'Incorrect element id!';
-$string['invalidenrol'] = 'Illegal enrolment attempted';
$string['invalidentry'] = 'This is not valid entry!';
$string['invalidevent'] = 'Invalid event';
$string['invalidfieldname'] = '"{$a}" is not a valid field name';
@@ -409,6 +405,7 @@
$string['remotedownloaderror'] = 'Download of component to your server failed, please verify proxy settings, PHP cURL extension is highly recommended.
You must download the {$a->url} file manually, copy it to "{$a->dest}" in your server and unzip it there.';
$string['remotedownloadnotallowed'] = 'Download of components to your server isn\'t allowed (allow_url_fopen is disabled).
You must download the {$a->url} file manually, copy it to "{$a->dest}" in your server and unzip it there.';
$string['reportnotavailable'] = 'This type of report is only available for the site course';
+$string['requireloginerror'] = 'Cource or activity not accessible.';
$string['restorechecksumfailed'] = 'Some problem happened with the restore information stored in your session. Please check your PHP memory/DB package size limits. Restore stopped.';
$string['restrictedcontextexception'] = 'Sorry, execution of external function violates context restriction.';
$string['restricteduser'] = 'Sorry, but your current account "{$a}" is restricted from doing that';
Index: course/importstudents.php
===================================================================
--- course/importstudents.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ course/importstudents.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
@@ -1,170 +0,0 @@
-.
-
-/**
- * Script to assign students to a meta course by selecting which courses the meta
- * course comprises. This is basically a hack of student.php that uses courses instead.
- *
- * @copyright 1999 Martin Dougiamas http://dougiamas.com
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @package course
- */
-
- require_once("../config.php");
- require_once("lib.php");
-
- define("MAX_COURSES_PER_PAGE", 1000);
-
- $id = required_param('id',PARAM_INT); // course id
- $add = optional_param('add', 0, PARAM_BOOL);
- $remove = optional_param('remove', 0, PARAM_BOOL);
- $showall = optional_param('showall', 0, PARAM_BOOL);
- $searchtext = optional_param('searchtext', '', PARAM_RAW); // search string
- $previoussearch = optional_param('previoussearch', 0, PARAM_BOOL);
- $previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0;
-
- $url = new moodle_url('/course/importstudents.php', array('id'=>$id));
- if ($add !== 0) {
- $url->param('add', $add);
- }
- if ($remove !== 0) {
- $url->param('remove', $remove);
- }
- if ($showall !== 0) {
- $url->param('showall', $showall);
- }
- if ($searchtext !== '') {
- $url->param('searchtext', $searchtext);
- }
- if ($previoussearch !== 0) {
- $url->param('previoussearch', $previoussearch);
- }
- $PAGE->set_url($url);
-
- $site = get_site();
-
- if (!$course = $DB->get_record('course', array('id'=>$id))) {
- print_error("invalidcourseid");
- }
-
- require_login($course->id);
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- require_capability('moodle/course:managemetacourse', $context);
-
- if (!$course->metacourse) {
- redirect("$CFG->wwwroot/course/view.php?id=$course->id");
- }
-
- $strassigncourses = get_string('metaassigncourses');
- $stralreadycourses = get_string('metaalreadycourses');
- $strnoalreadycourses = get_string('metanoalreadycourses');
- $strpotentialcourses = get_string('metapotentialcourses');
- $strnopotentialcourses = get_string('metanopotentialcourses');
- $straddcourses = get_string('metaaddcourse');
- $strremovecourse = get_string('metaremovecourse');
- $strsearch = get_string("search");
- $strsearchresults = get_string("searchresults");
- $strcourses = get_string("courses");
- $strshowall = get_string("showall");
-
- $PAGE->navbar->add($strassigncourses);
- $PAGE->set_title("$course->shortname: $strassigncourses");
- $PAGE->set_heading($site->fullname);
- $PAGE->set_focuscontrol("searchtext");
- echo $OUTPUT->header();
-
-/// Print a help notice about the need to use this page
-
- echo $OUTPUT->heading(get_string('childcourses'));
-
- if (!$frm = data_submitted()) {
- $note = get_string("importmetacoursenote");
- echo $OUTPUT->box($note);
-
-/// A form was submitted so process the input
-
- } else {
- if ($add and !empty($frm->addselect) and confirm_sesskey()) {
- $timestart = $timeend = 0;
- foreach ($frm->addselect as $addcourse) {
- $addcourse = clean_param($addcourse, PARAM_INT);
- set_time_limit(180);
- if (!add_to_metacourse($course->id,$addcourse)) {
- print_error("cannotmetacourse");
- }
- }
- } else if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
- foreach ($frm->removeselect as $removecourse) {
- set_time_limit(180);
- $removecourse = clean_param($removecourse, PARAM_INT);
- if (! remove_from_metacourse($course->id,$removecourse)) {
- print_error("cannotremovefrommeta");
- }
- }
- } else if ($showall and confirm_sesskey()) {
- $searchtext = '';
- $previoussearch = 0;
- }
- }
-
-
-/// Get all existing students and teachers for this course.
- if(! $alreadycourses = get_courses_in_metacourse($course->id)) {
- $alreadycourses = array();
- }
-
- $numcourses = 0;
-
-
-/// Get search results excluding any users already in this course
- if (($searchtext != '') and $previoussearch and confirm_sesskey()) {
- if ($searchcourses = get_courses_search(explode(" ",$searchtext),'fullname ASC',0,99999,$numcourses)) {
- foreach ($searchcourses as $tmp) {
- if (array_key_exists($tmp->id,$alreadycourses)) {
- unset($searchcourses[$tmp->id]);
- }
- if (!empty($tmp->metacourse)) {
- unset($searchcourses[$tmp->id]);
- }
- }
- if (array_key_exists($course->id,$searchcourses)) {
- unset($searchcourses[$course->id]);
- }
- $numcourses = count($searchcourses);
- }
- }
-
-/// If no search results then get potential students for this course excluding users already in course
- if (empty($searchcourses)) {
- $numcourses = count_courses_notin_metacourse($course->id);
-
- if ($numcourses > 0 and $numcourses <= MAX_COURSES_PER_PAGE) {
- $courses = get_courses_notin_metacourse($course->id);
- } else {
- $courses = array();
- }
- }
-
- echo $OUTPUT->box_start();
-
- include('importstudents.html');
-
- echo $OUTPUT->box_end();
-
- echo $OUTPUT->footer();
-
-
Index: user/profile.php
===================================================================
--- user/profile.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ user/profile.php (revision )
@@ -325,16 +325,17 @@
if (!isset($hiddenfields['mycourses'])) {
- if ($mycourses = get_my_courses($user->id, 'visible DESC,sortorder ASC', null, false, 21)) {
+ if ($mycourses = enrol_get_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC')) {
$shown=0;
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
$class = '';
if ($mycourse->visible == 0) {
- // get_my_courses will filter courses $USER cannot see
- // if we get one with visible 0 it just means it's hidden
- // ... but not from $USER
+ $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);
+ if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
+ continue;
+ }
$class = 'class="dimmed"';
}
$courselisting .= "wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >" . format_string($mycourse->fullname) . ", ";
Index: course/user.php
===================================================================
--- course/user.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ course/user.php (revision )
@@ -53,8 +53,9 @@
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
+require_login();
$PAGE->set_pagelayout('admin');
-if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !has_capability('moodle/course:participate', $coursecontext)) {
+if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !is_enrolled($coursecontext)) {
// do not require parents to be enrolled in courses ;-)
$PAGE->set_course($course);
} else {
Index: course/edit.php
===================================================================
--- course/edit.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ course/edit.php (revision )
@@ -1,165 +1,154 @@
.
+
+/**
+ * Edit course settings
+ *
+ * @package moodlecore
+ * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
- require_once('../config.php');
+require_once('../config.php');
- require_once($CFG->dirroot.'/enrol/enrol.class.php');
- require_once('lib.php');
- require_once('edit_form.php');
+require_once('lib.php');
+require_once('edit_form.php');
- $id = optional_param('id', 0, PARAM_INT); // course id
- $categoryid = optional_param('category', 0, PARAM_INT); // course category - can be changed in edit form
+$id = optional_param('id', 0, PARAM_INT); // course id
+$categoryid = optional_param('category', 0, PARAM_INT); // course category - can be changed in edit form
- $PAGE->set_pagelayout('admin');
+$PAGE->set_pagelayout('admin');
+$PAGE->set_url('/course/edit.php');
-/// basic access control checks
+// basic access control checks
- if ($id) { // editing course
+if ($id) { // editing course
-
- if($id == SITEID){
+ if ($id == SITEID){
- // don't allow editing of 'site course' using this from
- print_error('cannoteditsiteform');
- }
+ // don't allow editing of 'site course' using this from
+ print_error('cannoteditsiteform');
+ }
- if (!$course = $DB->get_record('course', array('id'=>$id))) {
- print_error('invalidcourseid');
- }
+ $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
- require_login($course->id);
+ require_login($course->id);
- $category = $DB->get_record('course_categories', array('id'=>$course->category));
+ $category = $DB->get_record('course_categories', array('id'=>$course->category), '*', MUST_EXIST);
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
- require_capability('moodle/course:update', $coursecontext);
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ require_capability('moodle/course:update', $coursecontext);
+ $PAGE->url->param('id',$id);
+
- } else if ($categoryid) { // creating new course in this category
- $course = null;
- require_login();
+} else if ($categoryid) { // creating new course in this category
+ $course = null;
+ require_login();
- if (!$category = $DB->get_record('course_categories', array('id'=>$categoryid))) {
- print_error('unknowcategory');
- }
+ $category = $DB->get_record('course_categories', array('id'=>$categoryid), '*', MUST_EXIST);
- require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id));
+ require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id));
+ $PAGE->url->param('category',$categoryid);
+
- } else {
- require_login();
- print_error('needcoursecategroyid');
- }
+} else {
+ require_login();
+ print_error('needcoursecategroyid');
+}
- $PAGE->set_url('/course/edit.php');
- if ($id !== 0) {
- $PAGE->url->param('id',$id);
- } else {
- $PAGE->url->param('category',$categoryid);
- }
-
- /// Prepare course and the editor
+// Prepare course and the editor
- $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
- if (!empty($course)) {
- $allowedmods = array();
+$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
+if (!empty($course)) {
+ $allowedmods = array();
- if (!empty($course)) {
- if ($am = $DB->get_records('course_allowed_modules', array('course'=>$course->id))) {
- foreach ($am as $m) {
- $allowedmods[] = $m->module;
- }
- } else {
- if (empty($course->restrictmodules)) {
- $allowedmods = explode(',',$CFG->defaultallowedmodules);
- } // it'll be greyed out but we want these by default anyway.
- }
- $course->allowedmods = $allowedmods;
+ if ($am = $DB->get_records('course_allowed_modules', array('course'=>$course->id))) {
+ foreach ($am as $m) {
+ $allowedmods[] = $m->module;
+ }
+ } else {
+ if (empty($course->restrictmodules)) {
+ $allowedmods = explode(',',$CFG->defaultallowedmodules);
+ } // it'll be greyed out but we want these by default anyway.
+ }
+ $course->allowedmods = $allowedmods;
- }
- $course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course_summary', $course->id);
+ $course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course_summary', $course->id);
+
- } else {
- $course = file_prepare_standard_editor($course, 'summary', $editoroptions, null, 'course_summary', null);
- }
+} else {
+ $course = file_prepare_standard_editor($course, 'summary', $editoroptions, null, 'course_summary', null);
+}
-/// first create the form
+// first create the form
- $editform = new course_edit_form('edit.php', compact('course', 'category', 'editoroptions'));
+$editform = new course_edit_form('edit.php', compact('course', 'category', 'editoroptions'));
+
- // now override defaults if course already exists
+// now override defaults if course already exists
- if (!empty($course->id)) {
- $course->enrolpassword = $course->password; // we need some other name for password field MDL-9929
- $editform->set_data($course);
- }
- if ($editform->is_cancelled()){
- if (empty($course)) {
+if ($editform->is_cancelled()){
+ if (empty($course)) {
- redirect($CFG->wwwroot);
+ redirect($CFG->wwwroot.'/');
- } else {
- redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
- }
+ } else {
+ redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
+ }
- } else if ($data = $editform->get_data()) {
+} else if ($data = $editform->get_data()) {
+ // process data if submitted
- $data->password = $data->enrolpassword; // we need some other name for password field MDL-9929
-/// process data if submitted
-
- //preprocess data
- $data->timemodified = time();
+ //preprocess data
+ $data->timemodified = time();
- if (empty($course->id)) {
- // In creating the course
+ if (empty($course->id)) {
+ // In creating the course
- if (!$course = create_course($data)) {
- print_error('coursenotcreated');
- }
+ $course = create_course($data, $editoroptions, true);
- // Get the context of the newly created course
+ // Get the context of the newly created course
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
- // Save the files used in the summary editor
- $editordata = new stdClass;
- $editordata->id = $course->id;
- $editordata->summary_editor = $data->summary_editor;
- $editordata = file_postupdate_standard_editor($editordata, 'summary', $editoroptions, $context, 'course_summary', $course->id);
- $DB->update_record('course', $editordata);
-
- // assign default role to creator if not already having permission to manage course assignments
- if (!is_viewing($context, NULL, 'moodle/role:assign') and !is_enrolled($context, NULL, 'moodle/role:assign')) {
- role_assign($CFG->creatornewroleid, $USER->id, 0, $context->id);
+ // Redirect to manual enrolment page if possible - this is a big hack, we should improve it in future
+ if ($manuals = $DB->get_records('enrol', array('enrol'=>'manual', 'status'=>ENROL_STATUS_ENABLED), 'sortorder,id ASC')) {
+ if (has_capability('enrol/manual:manage', $context)) {
+ $manual = reset($manuals);
+ redirect($CFG->wwwroot."/enrol/manual/manage.php?enrolid=$manual->id&id=$course->id");
}
-
- // ensure we can use the course right after creating it
- // this means trigger a reload of accessinfo...
- mark_context_dirty($context->path);
-
- if ($data->metacourse and has_capability('moodle/course:managemetacourse', $context)) {
- // Redirect users with metacourse capability to student import
- redirect($CFG->wwwroot."/course/importstudents.php?id=$course->id");
- } else {
- // Redirect to roles assignment
- redirect($CFG->wwwroot."/$CFG->admin/roles/assign.php?contextid=$context->id");
- }
+ }
+ redirect($CFG->wwwroot."/course/view.php?id=$course->id");
- } else {
- // Save any changes to the files used in the editor
+ } else {
+ // Save any changes to the files used in the editor
- $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $coursecontext, 'course_summary', $data->id);
- if (!update_course($data)) {
- print_error('coursenotupdated');
- }
+ update_course($data, $editoroptions);
- redirect($CFG->wwwroot."/course/view.php?id=$course->id");
- }
- }
+ redirect($CFG->wwwroot."/course/view.php?id=$course->id");
+ }
+}
-/// Print the form
+// Print the form
- $site = get_site();
+$site = get_site();
- $streditcoursesettings = get_string("editcoursesettings");
- $straddnewcourse = get_string("addnewcourse");
- $stradministration = get_string("administration");
- $strcategories = get_string("categories");
+$streditcoursesettings = get_string("editcoursesettings");
+$straddnewcourse = get_string("addnewcourse");
+$stradministration = get_string("administration");
+$strcategories = get_string("categories");
- if (!empty($course->id)) {
- $PAGE->navbar->add($streditcoursesettings);
- $title = $streditcoursesettings;
- $fullname = $course->fullname;
- } else {
- $PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php'));
- $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
- $PAGE->navbar->add($straddnewcourse);
- $title = "$site->shortname: $straddnewcourse";
- $fullname = $site->fullname;
- }
+if (!empty($course->id)) {
+ $PAGE->navbar->add($streditcoursesettings);
+ $title = $streditcoursesettings;
+ $fullname = $course->fullname;
+} else {
+ $PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php'));
+ $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
+ $PAGE->navbar->add($straddnewcourse);
+ $title = "$site->shortname: $straddnewcourse";
+ $fullname = $site->fullname;
+}
- $PAGE->set_title($title);
- $PAGE->set_heading($fullname);
- $PAGE->set_focuscontrol($editform->focus());
+$PAGE->set_title($title);
+$PAGE->set_heading($fullname);
+$PAGE->set_focuscontrol($editform->focus());
+
- echo $OUTPUT->header();
- echo $OUTPUT->heading($streditcoursesettings);
+echo $OUTPUT->header();
+echo $OUTPUT->heading($streditcoursesettings);
- $editform->display();
+$editform->display();
- echo $OUTPUT->footer();
+echo $OUTPUT->footer();
Index: grade/report/overview/lib.php
===================================================================
--- grade/report/overview/lib.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ grade/report/overview/lib.php (revision )
@@ -111,8 +111,8 @@
public function fill_table() {
global $CFG, $DB, $OUTPUT;
- // MDL-11679, only show 'mycourses' instead of all courses
- if ($courses = get_my_courses($this->user->id, 'c.sortorder ASC', 'id, shortname, showgrades')) {
+ // MDL-11679, only show user's courses instead of all courses
+ if ($courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades')) {
$numusers = $this->get_numusers(false);
foreach ($courses as $course) {
Index: user/groupextendenrol.php
===================================================================
--- user/groupextendenrol.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
+++ user/groupextendenrol.php (revision 6d5f80157d7f2b3c33f64ca31af5da9baa434333)
@@ -1,185 +0,0 @@
-.
-
-/**
- * This file is part of the User section Moodle
- *
- * @copyright 1999 Martin Dougiamas http://dougiamas.com
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @package user
- */
-
-require_once("../config.php");
-
-$id = required_param('id', PARAM_INT); // course id
-$users = optional_param('userid', array(), PARAM_INT); // array of user id
-
-$PAGE->set_url('/user/groupextendenrol.php', array('id'=>$id));
-
-if (! $course = $DB->get_record('course', array('id'=>$id))) {
- print_error('invalidcourseid');
-}
-
-$context = get_context_instance(CONTEXT_COURSE, $id);
-require_login($course->id);
-
-// to extend enrolments current user needs to be able to do role assignments
-require_capability('moodle/role:assign', $context);
-$today = time();
-$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
-
-if ((count($users) > 0) and ($form = data_submitted()) and confirm_sesskey()) {
-
- foreach ($form->userid as $k => $v) {
- // find all roles this student have in this course
- if ($students = $DB->get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
- FROM {role_assignments} ra
- WHERE userid = ?
- AND contextid = ?", array($v, $context->id))) {
- // enrol these users again, with time extension
- // not that this is not necessarily a student role
- foreach ($students as $student) {
- // only extend if the user can make role assignments on this role
- if (user_can_assign($context, $student->roleid)) {
- switch($form->extendperiod) {
- case 0: // No change (currently this option is not available in dropdown list, but it might be ...)
- break;
- case -1: // unlimited
- $student->timeend = 0;
- break;
- default: // extend
- switch($form->extendbase) {
- case 0: // course start date
- $student->timeend = $course->startdate + $form->extendperiod;
- break;
- case 1: // student enrolment start date
- // we check for student enrolment date because Moodle versions before 1.9 did not set this for
- // unlimited enrolment courses, so it might be 0
- if($student->timestart > 0) {
- $student->timeend = $student->timestart + $form->extendperiod;
- }
- break;
- case 2: // student enrolment start date
- // enrolment end equals 0 means Unlimited, so adding some time to that will still yield Unlimited
- if($student->timeend > 0) {
- $student->timeend = $student->timeend + $form->extendperiod;
- }
- break;
- case 3: // current date
- $student->timeend = $today + $form->extendperiod;
- break;
- case 4: // course enrolment start date
- if($course->enrolstartdate > 0) {
- $student->timeend = $course->enrolstartdate + $form->extendperiod;
- }
- break;
- case 5: // course enrolment end date
- if($course->enrolenddate > 0) {
- $student->timeend = $course->enrolenddate + $form->extendperiod;
- }
- break;
- }
- }
- role_assign($student->roleid, $v, 0, $context->id, $student->timestart, $student->timeend, 0);
- }
- }
- }
- }
-
- redirect("$CFG->wwwroot/user/index.php?id=$id", get_string('changessaved'));
-}
-
-$PAGE->navbar->add(get_string('extendenrol'));
-$PAGE->set_title("$course->shortname: ".get_string('extendenrol'));
-$PAGE->set_heading($course->fullname);
-
-/// Print headers
-echo $OUTPUT->header();
-
-$timeformat = get_string('strftimedate');
-$unlimited = get_string('unlimited');
-$periodmenu[-1] = $unlimited;
-for ($i=1; $i<=365; $i++) {
- $seconds = $i * 86400;
- $periodmenu[$seconds] = get_string('numdays', '', $i);
-}
-
-$basemenu[0] = get_string('startdate') . ' (' . userdate($course->startdate, $timeformat) . ')';
-$basemenu[1] = get_string('enrolmentstart');
-$basemenu[2] = get_string('enrolmentend');
-if($course->enrollable != 2 || ($course->enrolstartdate == 0 || $course->enrolstartdate <= $today) && ($course->enrolenddate == 0 || $course->enrolenddate > $today)) {
- $basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
-}
-if($course->enrollable == 2) {
- if($course->enrolstartdate > 0) {
- $basemenu[4] = get_string('courseenrolstartdate') . ' (' . userdate($course->enrolstartdate, $timeformat) . ')';
- }
- if($course->enrolenddate > 0) {
- $basemenu[5] = get_string('courseenrolenddate') . ' (' . userdate($course->enrolenddate, $timeformat) . ')';
- }
-}
-
-$title = get_string('groupextendenrol');
-echo $OUTPUT->heading($title . $OUTPUT->old_help_icon('groupextendenrol', $title));
-echo '