Index: group/assign.php
===================================================================
--- group/assign.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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: admin/mnet/enr_hosts.php
===================================================================
--- admin/mnet/enr_hosts.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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: enrol/authorize/db/upgrade.php
===================================================================
--- enrol/authorize/db/upgrade.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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/manual/lang/en/enrol_manual.php
===================================================================
--- enrol/manual/lang/en/enrol_manual.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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/database/enrol.php
===================================================================
--- enrol/database/enrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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/self/locallib.php
===================================================================
--- enrol/self/locallib.php (revision )
+++ enrol/self/locallib.php (revision )
@@ -0,0 +1,81 @@
+.
+
+/**
+ * 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;
+
+ if ($instance->password) {
+ $heading = empty($instance->name) ? get_string('pluginname', 'enrol_self') : format_string($instance->name);
+ $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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lib/moodlelib.php (revision )
@@ -2106,86 +2106,91 @@
* case they are automatically logged in as guests.
* If $courseid is given and the user is not enrolled in that course then the
* user is redirected to the course enrolment page.
- * If $cm is given and the coursemodule is hidden and the user is not a teacher
+ * If $cm is given and the course module is hidden and the user is not a teacher
* in the course then the user is redirected to the course home page.
*
* 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
@@ -2204,154 +2209,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);
- }
+}
-}
/**
@@ -2390,26 +2476,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.
@@ -2420,6 +2508,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 {
@@ -2437,7 +2528,7 @@
} else {
// course login always required
- require_login($courseorid, $autologinguest, $cm, $setwantsurltome);
+ require_login($courseorid, $autologinguest, $cm, $setwantsurltome, $preventredirect);
}
}
@@ -2707,25 +2798,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).
*
@@ -2922,157 +2994,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
*
@@ -3450,13 +3371,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);
@@ -3468,9 +3389,9 @@
$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 assingments in user context and context itself
+ // now do a final accesslib cleanup - removes all role assignments in user context and context itself
delete_context(CONTEXT_USER, $user->id);
require_once($CFG->dirroot.'/tag/lib.php');
@@ -4125,26 +4046,6 @@
}
}
-
-/// 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);
@@ -4270,7 +4171,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);
@@ -4283,7 +4184,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;
}
@@ -5038,54 +4939,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;
- $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 /////////////////////////////////////////////
/**
@@ -6916,6 +6769,7 @@
'dock' => NULL,
'editor' => 'lib/editor',
'edufields' => NULL,
+ 'enrol' => 'enrol',
'error' => NULL,
'filepicker' => NULL,
'filters' => NULL,
@@ -9223,23 +9077,6 @@
}
/**
- * 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 prefereed languages, setting Moodle
* to use the best one available if $SESSION->lang is undefined
*
@@ -9454,7 +9291,7 @@
}
}
- /**
+/**
* Returns the site identifier
*
* @global object
Index: admin/settings/appearance.php
===================================================================
--- admin/settings/appearance.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ admin/settings/appearance.php (revision )
@@ -128,9 +128,9 @@
$temp->add(new admin_setting_configtext('mycoursesperpage', get_string('mycoursesperpage', 'admin'), get_string('configmycoursesperpage', 'admin'), 21, PARAM_INT));
$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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ course/unenrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
@@ -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: tag/coursetagslib.php
===================================================================
--- tag/coursetagslib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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/roles/assign.php
===================================================================
--- admin/roles/assign.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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();
@@ -288,16 +204,6 @@
-
-
-
-
-
-
-
-
-
@@ -350,11 +256,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: admin/generator.php
===================================================================
--- admin/generator.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ admin/generator.php (revision )
@@ -710,25 +710,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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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: auth/mnet/auth.php
===================================================================
--- auth/mnet/auth.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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,411 @@
+.
+
+/**
+ * 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;
+ $header = empty($instance->name) ? get_string('pluginname', 'enrol_self') : $instance->name;
+ $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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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: admin/mnet/enr_course_enrol.php
===================================================================
--- admin/mnet/enr_course_enrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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/flatfile/enrol.php
===================================================================
--- enrol/flatfile/enrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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: enrol/guest/lib.php
===================================================================
--- enrol/guest/lib.php (revision )
+++ enrol/guest/lib.php (revision )
@@ -0,0 +1,276 @@
+.
+
+/**
+ * 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;
+ $header = empty($instance->name) ? get_string('pluginname', 'enrol_guest') : $instance->name;
+ $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: enrol/paypal/return.php
===================================================================
--- enrol/paypal/return.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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: admin/bloglevelupgrade.php
===================================================================
--- admin/bloglevelupgrade.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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/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: 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: lib/navigationlib.php
===================================================================
--- lib/navigationlib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lib/navigationlib.php (revision )
@@ -829,7 +829,7 @@
$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');
// Fetch all of the users courses.
- $this->mycourses = get_my_courses($USER->id);
+ $this->mycourses = enrol_get_my_courses();
// Check if any courses were returned.
if (count($this->mycourses) > 0) {
// Add all of the users courses to the navigation
@@ -1401,7 +1401,7 @@
}
$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;
}
@@ -2307,6 +2307,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));
@@ -2356,17 +2361,6 @@
$coursenode->add(get_string('outcomes', 'grades'), $url, self::TYPE_SETTING, null, null, 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));
@@ -2437,7 +2431,8 @@
$coursenode->add(get_string('files'), $url, self::TYPE_SETTING, null, null, 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));
@@ -2449,21 +2444,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[]='';
}
}
@@ -2650,7 +2645,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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ course/lib.php (revision )
@@ -1950,7 +1950,7 @@
echo "\n\n".'
';
@@ -2108,17 +2108,17 @@
$category = array_shift($categories);
$courses = get_courses_wmanagers($category->id,
'c.sortorder ASC',
- array('password','summary','summaryformat','currency'));
+ array('summary','summaryformat'));
} else {
$courses = get_courses_wmanagers('all',
'c.sortorder ASC',
- array('password','summary','summaryformat','currency'));
+ array('summary','summaryformat'));
}
unset($categories);
} else {
$courses = get_courses_wmanagers($category->id,
'c.sortorder ASC',
- array('password','summary','summaryformat','currency'));
+ array('summary','summaryformat'));
}
if ($courses) {
@@ -2169,8 +2169,8 @@
/// first find all roles that are supposed to be displayed
- if (!empty($CFG->coursemanager)) {
- $managerroles = split(',', $CFG->coursemanager);
+ if (!empty($CFG->coursecontact)) {
+ $managerroles = split(',', $CFG->coursecontact);
$namesarray = array();
if (isset($course->managers)) {
if (count($course->managers)) {
@@ -2236,9 +2236,7 @@
}
}
- require_once("$CFG->dirroot/enrol/enrol.class.php");
- $enrol = enrolment_factory::factory($course->enrol);
- echo $enrol->get_access_icons($course);
+ // TODO: print some enrol icons
echo '
';
$options = NULL;
@@ -2263,7 +2261,7 @@
print_error('nopermissions', '', '', 'See My Moodle');
}
- $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary'));
+ $courses = enrol_get_my_courses('summary', 'visible DESC,sortorder ASC');
$rhosts = array();
$rcourses = array();
if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode==='strict') {
@@ -2952,15 +2950,6 @@
}
}
-/**
- * This function will return true if the given course is a child course at all
- */
-function course_in_meta ($course) {
- global $DB;
- return $DB->record_exists("course_meta", array("child_course"=>$course->id));
-}
-
-
function update_restricted_mods($course, $mods) {
global $DB;
@@ -3220,7 +3209,7 @@
$context = get_context_instance(CONTEXT_COURSE, $courseid);
foreach ($data as $fieldname => $value) {
- if (!strstr($fieldname, 'role_')) {
+ if (strpos($fieldname, 'role_') !== 0) {
continue;
}
list($ignored, $roleid) = explode('_', $fieldname);
@@ -3247,35 +3236,32 @@
* Create a course and either return a $course object or false
*
* @param object $data - all the data needed for an entry in the 'course' table
+ * @param array $editoroptions course description editor options
+ * @param bool $fixcreator add default enrolment for creator role
+ * @return object new course record
*/
-function create_course($data) {
- global $CFG, $USER, $DB;
+function create_course($data, $editoroptions=null, $fixcreator=false) {
+ global $CFG, $DB, $USER;
//check the categoryid
if (!empty($data->category) && !$data->category==0) {
- $category = $DB->get_record('course_categories', array('id'=>$data->category));
- if (empty($category)) {
- throw new moodle_exception('noexistingcategory');
+ $category = $DB->get_record('course_categories', array('id'=>$data->category), '*', MUST_EXIST);
- }
+ }
- }
//check if the shortname already exist
- if(!empty($data->shortname)) {
+ if (!empty($data->shortname)) {
- $course = $DB->get_record('course', array('shortname' => $data->shortname));
- if (!empty($course)) {
+ if ($DB->record_exists('course', array('shortname' => $data->shortname))) {
throw new moodle_exception('shortnametaken');
}
}
//check if the id number already exist
- if(!empty($data->idnumber)) {
+ if (!empty($data->idnumber)) {
- $course = $DB->get_record('course', array('idnumber' => $data->idnumber));
- if (!empty($course)) {
+ if ($DB->record_exists('course', array('idnumber' => $data->idnumber))) {
throw new moodle_exception('idnumbertaken');
}
}
-
// preprocess allowed mods
$allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
unset($data->allowedmods);
@@ -3298,43 +3284,68 @@
// place at beginning of any category
$data->sortorder = 0;
- if ($newcourseid = $DB->insert_record('course', $data)) { // Set up new course
+ // Set up new course
+ $course->id = $DB->insert_record('course', $data);
+ $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
- $course = $DB->get_record('course', array('id'=>$newcourseid));
+ if ($editoroptions) {
+ // 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);
+ }
+ $course = $DB->get_record('course', array('id'=>$course->id));
+
+ // new context created - btter mark it as dirty
+ mark_context_dirty($context->path);
+
+ // this is a chicken-egg problem - we need to set up enrolment instances first,
+ // only then we can enrol course creator who may not have right to manage course :-(
+ enrol_course_updated(true, $course, $data);
+
+ // in case this is executed by creator enrol him/her into course using manual enrol with default role
+ if ($fixcreator) {
+ if (!is_viewing($context, NULL, 'moodle/role:assign') and !is_enrolled($context, NULL, 'moodle/role:assign')) {
+ //TODO: do some real enrolment here
+ role_assign($CFG->creatornewroleid, $USER->id, $context->id);
+ }
+ }
+
- // Setup the blocks
- blocks_add_default_course_blocks($course);
+ // Setup the blocks
+ blocks_add_default_course_blocks($course);
- update_restricted_mods($course, $allowedmods);
+ update_restricted_mods($course, $allowedmods);
- $section = new object();
- $section->course = $course->id; // Create a default section.
- $section->section = 0;
+ $section = new object();
+ $section->course = $course->id; // Create a default section.
+ $section->section = 0;
- $section->id = $DB->insert_record('course_sections', $section);
+ $section->id = $DB->insert_record('course_sections', $section);
- fix_course_sortorder();
+ fix_course_sortorder();
- add_to_log(SITEID, 'course', 'new', 'view.php?id='.$course->id, $data->fullname.' (ID '.$course->id.')');
+ add_to_log(SITEID, 'course', 'new', 'view.php?id='.$course->id, $data->fullname.' (ID '.$course->id.')');
- // Save any custom role names.
- save_local_role_names($course->id, $data);
+ // Save any custom role names.
+ save_local_role_names($course->id, $data);
- // Trigger events
- events_trigger('course_created', $course);
+ // Trigger events
+ events_trigger('course_created', $course);
- return $course;
- }
+ return $course;
+}
- return false; // error
-}
-
/**
* Update a course and return true or false
*
* @param object $data - all the data needed for an entry in the 'course' table
+ * @param array $editoroptions course description editor options
+ * @return void
*/
-function update_course($data) {
- global $USER, $CFG, $DB;
+function update_course($data, $editoroptions) {
+ global $CFG, $DB;
// Preprocess allowed mods
$allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
@@ -3346,11 +3357,7 @@
}
$movecat = false;
- $oldcourse = $DB->get_record('course', array('id'=>$data->id)); // should not fail, already tested above
- // check that course id exist
- if (empty($oldcourse)) {
- throw new moodle_exception('courseidnotfound');
- }
+ $oldcourse = $DB->get_record('course', array('id'=>$data->id), '*', MUST_EXIST);
if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category))
or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
@@ -3361,42 +3368,40 @@
$movecat = true;
}
+ $context = get_context_instance(CONTEXT_COURSE, $data->id, MUST_EXIST);
+ $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course_summary', $data->id);
+
// Update with the new data
- if ($DB->update_record('course', $data)) {
+ $DB->update_record('course', $data);
- $course = $DB->get_record('course', array('id'=>$data->id));
+ $course = $DB->get_record('course', array('id'=>$data->id));
+ enrol_course_updated(false, $course, $data);
+
- add_to_log($course->id, "course", "update", "edit.php?id=$course->id", $course->id);
+ add_to_log($course->id, "course", "update", "edit.php?id=$course->id", $course->id);
- // "Admins" can change allowed mods for a course
- if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
- update_restricted_mods($course, $allowedmods);
- }
+ // "Admins" can change allowed mods for a course
+ if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
+ update_restricted_mods($course, $allowedmods);
+ }
- if ($movecat) {
+ if ($movecat) {
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
- context_moved($context, $newparent);
- }
+ $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
+ context_moved($context, $newparent);
+ }
- fix_course_sortorder();
+ fix_course_sortorder();
- // Test for and remove blocks which aren't appropriate anymore
- blocks_remove_inappropriate($course);
+ // Test for and remove blocks which aren't appropriate anymore
+ blocks_remove_inappropriate($course);
- // Save any custom role names.
- save_local_role_names($course->id, $data);
+ // Save any custom role names.
+ save_local_role_names($course->id, $data);
- // Trigger events
- events_trigger('course_updated', $course);
+ // Trigger events
+ events_trigger('course_updated', $course);
-
- return true;
-
- }
+}
- return false;
-}
-
function get_course_by_id ($id) {
global $DB;
return $DB->get_record('course', array('id' => $id));
@@ -3738,7 +3743,8 @@
$course = $DB->get_record('course', array('id' => $course->id));
blocks_add_default_course_blocks($course);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
- role_assign($CFG->creatornewroleid, $this->properties->requester, 0, $coursecontext->id); // assing teacher role
+ // TODO: do some real enrolment here
+ role_assign($CFG->creatornewroleid, $this->properties->requester, $coursecontext->id); // assing teacher role
if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
// if we're all or requested we're ok.
$allowedmods = explode(',',$CFG->defaultallowedmodules);
Index: admin/report/security/lib.php
===================================================================
--- admin/report/security/lib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ admin/report/security/lib.php (revision )
@@ -587,9 +587,6 @@
$riskycount = $DB->count_records_sql($sql, $params);
- // default role can not have view cap in all courses - this would break moodle badly
- $viewcap = $DB->record_exists('role_capabilities', array('roleid'=>$default_role->id, 'permission'=>CAP_ALLOW, 'capability'=>'moodle/course:participate'));
-
// it may have either none or 'user' archetype - nothing else, or else it would break during upgrades badly
if ($default_role->archetype === '' or $default_role->archetype === 'user') {
$legacyok = true;
@@ -597,7 +594,7 @@
$legacyok = false;
}
- if ($riskycount or $viewcap or !$legacyok) {
+ if ($riskycount or !$legacyok) {
$result->status = REPORT_SECURITY_CRITICAL;
$result->info = get_string('check_defaultuserrole_error', 'report_security', format_string($default_role->name));
Index: backup/moodle2/backup_course_task.class.php
===================================================================
--- backup/moodle2/backup_course_task.class.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ backup/moodle2/backup_course_task.class.php (revision )
@@ -69,7 +69,7 @@
$this->add_step(new create_taskbasepath_directory('create_course_directory'));
// Create the course.xml file with course & category information
- // annotating some bits, metacourse info, tags and module restrictions
+ // annotating some bits, tags and module restrictions
$this->add_step(new backup_course_structure_step('course_info', 'course.xml'));
// Annotate the groups used in already annotated groupings
Index: enrol/manual/enrol.php
===================================================================
--- enrol/manual/enrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ enrol/manual/enrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
@@ -1,455 +0,0 @@
-dirroot.'/group/lib.php');
-require_once($CFG->libdir.'/eventslib.php');
-
-/**
-* enrolment_plugin_manual is the default enrolment plugin
-*
-* This class provides all the functionality for an enrolment plugin
-* In fact it includes all the code for the default, "manual" method
-* so that other plugins can override these as necessary.
-*/
-
-class enrolment_plugin_manual {
-
-var $errormsg;
-
-/**
-* Prints the entry form/page for this enrolment
-*
-* This is only called from course/enrol.php
-* Most plugins will probably override this to print payment
-* forms etc, or even just a notice to say that manual enrolment
-* is disabled
-*
-* @param course current course object
-*/
-function print_entry($course) {
- global $CFG, $USER, $SESSION, $OUTPUT, $PAGE;
-
- $strloginto = get_string('loginto', '', $course->shortname);
- $strcourses = get_string('courses');
-
-/// Automatically enrol into courses without password
-
- $context = get_context_instance(CONTEXT_SYSTEM);
-
- $PAGE->navbar->add($strcourses);
- $PAGE->navbar->add($strloginto);
-
- if ($course->password == '') { // no password, so enrol
-
- if (isguestuser()) {
- add_to_log($course->id, 'course', 'guest', 'view.php?id='.$course->id, getremoteaddr());
-
- } else if (empty($_GET['confirm']) && empty($_GET['cancel'])) {
- $PAGE->set_title($strloginto);
- $PAGE->set_heading($course->fullname);
- echo $OUTPUT->header();
- echo ' ';
- echo $OUTPUT->confirm(get_string('enrolmentconfirmation'), "enrol.php?id=$course->id&confirm=1&sesskey=".sesskey(), "enrol.php?id=$course->id&cancel=1");
- echo $OUTPUT->footer();
- exit;
-
- } else if (!empty($_GET['confirm']) and confirm_sesskey()) {
-
- if (!enrol_into_course($course, $USER, 'manual')) {
- print_error('couldnotassignrole');
- }
- // force a refresh of mycourses
- unset($USER->mycourses);
-
- if (!empty($SESSION->wantsurl)) {
- $destination = $SESSION->wantsurl;
- unset($SESSION->wantsurl);
- } else {
- $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
- }
-
- redirect($destination);
-
- } else if (!empty($_GET['cancel'])) {
- unset($SESSION->wantsurl);
- if (!empty($SESSION->enrolcancel)) {
- $destination = $SESSION->enrolcancel;
- unset($SESSION->enrolcancel);
- } else {
- $destination = $CFG->wwwroot;
- }
- redirect($destination);
- }
- }
-
- // if we get here we are going to display the form asking for the enrolment key
- // and (hopefully) provide information about who to ask for it.
- if (!isset($password)) {
- $password = '';
- }
-
- $PAGE->set_title($strloginto);
- $PAGE->set_heading($course->fullname);
- $PAGE->set_focuscontrol('form.password');
- echo $OUTPUT->header();
-
- print_course($course, "80%");
-
- include("$CFG->dirroot/enrol/manual/enrol.html");
-
- echo $OUTPUT->footer();
-
-}
-
-
-
-/**
-* The other half to print_entry, this checks the form data
-*
-* This function checks that the user has completed the task on the
-* enrolment entry page and then enrolls them.
-*
-* @param form the form data submitted, as an object
-* @param course the current course, as an object
-*/
-function check_entry($form, $course) {
- global $CFG, $USER, $SESSION;
-
- if (empty($form->password)) {
- $form->password = '';
- }
-
- if (empty($course->password) or !confirm_sesskey()) {
- // do not allow entry when no course password set
- // automatic login when manual primary, no login when secondary at all!!
- print_error('invalidenrol');
- }
-
- $groupid = $this->check_group_entry($course->id, $form->password);
-
- if (($form->password == $course->password) or ($groupid !== false) ) {
-
- if (isguestuser()) { // only real user guest, do not use this for users with guest role
- $USER->enrolkey[$course->id] = true;
- add_to_log($course->id, 'course', 'guest', 'view.php?id='.$course->id, getremoteaddr());
-
- } else { /// Update or add new enrolment
- if (enrol_into_course($course, $USER, 'manual')) {
- // force a refresh of mycourses
- unset($USER->mycourses);
- if ($groupid !== false) {
- if (!groups_add_member($groupid, $USER->id)) {
- print_error('couldnotassigngroup');
- }
- }
- } else {
- print_error('couldnotassignrole');
- }
- }
-
- if ($SESSION->wantsurl) {
- $destination = $SESSION->wantsurl;
- unset($SESSION->wantsurl);
- } else {
- $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
- }
-
- redirect($destination);
-
- } else if (!isset($CFG->enrol_manual_showhint) or $CFG->enrol_manual_showhint) {
- $this->errormsg = get_string('enrolmentkeyhint', '', substr($course->password, 0, 1));
-
- } else {
- $this->errormsg = get_string('enrolmentkeyerror', 'enrol_manual');
- }
-}
-
-
-/**
-* Check if the given enrolment key matches a group enrolment key for the given course
-*
-* @param courseid the current course id
-* @param password the submitted enrolment key
-*/
-function check_group_entry ($courseid, $password) {
-
- if ($groups = groups_get_all_groups($courseid)) {
- foreach ($groups as $group) {
- if ( !empty($group->enrolmentkey) and ($password == $group->enrolmentkey) ) {
- return $group->id;
- }
- }
- }
-
- return false;
-}
-
-
-/**
-* Prints a form for configuring the current enrolment plugin
-*
-* This function is called from admin/enrol.php, and outputs a
-* full page with a form for defining the current enrolment plugin.
-*
-* @param frm an object containing all the data for this page
-*/
-function config_form($frm) {
- global $CFG, $OUTPUT;
-
- if (!isset( $frm->enrol_manual_keyholderrole )) {
- $frm->enrol_manual_keyholderrole = '';
- }
-
- if (!isset($frm->enrol_manual_showhint)) {
- $frm->enrol_manual_showhint = 1;
- }
-
- if (!isset($frm->enrol_manual_usepasswordpolicy)) {
- $frm->enrol_manual_usepasswordpolicy = 0;
- }
-
- if (!isset($frm->enrol_manual_requirekey)) {
- $frm->enrol_manual_requirekey = 0;
- }
-
- include ("$CFG->dirroot/enrol/manual/config.html");
-}
-
-
-/**
-* Processes and stored configuration data for the enrolment plugin
-*
-* @param config all the configuration data as entered by the admin
-*/
-function process_config($config) {
- foreach ($config as $name => $value) {
- set_config($name, $value);
- }
-
- return true;
-}
-
-
-/**
-* Notify users about enrolments that are going to expire soon!
-* This function is run by admin/cron.php
-* @return void
-*/
-function cron() {
- global $CFG, $USER, $SITE, $DB;
-
- if (!isset($CFG->lastexpirynotify)) {
- set_config('lastexpirynotify', 0);
- }
-
- // notify once a day only - TODO: add some tz handling here, maybe use timestamps
- if ($CFG->lastexpirynotify == date('Ymd')) {
- return;
- }
-
- if ($rs = $DB->get_recordset_select('course', 'enrolperiod > 0 AND expirynotify > 0 AND expirythreshold > 0')) {
- $admin = get_admin();
-
- foreach ($rs as $course) {
- $a = new object();
- $a->coursename = $course->shortname .'/'. $course->fullname; // must be processed by format_string later
- $a->threshold = $course->expirythreshold / 86400;
- $a->extendurl = $CFG->wwwroot . '/user/index.php?id=' . $course->id;
- $a->current = array();
- $a->past = array();
-
- $expiry = time() + $course->expirythreshold;
- $cname = $course->fullname;
-
- /// Get all the manual role assignments for this course that have expired.
-
- if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
- continue;
- }
-
- if ($oldenrolments = $DB->get_records_sql("
- SELECT u.*, ra.timeend
- FROM {user} u
- JOIN {role_assignments} ra ON (ra.userid = u.id)
- WHERE ra.contextid = $context->id
- AND ra.timeend > 0 AND ra.timeend <= $expiry
- AND ra.enrol = 'manual'")) {
-
- // inform user who can assign roles or admin
- if ($teachers = get_users_by_capability($context, 'moodle/role:assign', '', '', '', '', '', '', false)) {
- $teachers = sort_by_roleassignment_authority($teachers, $context);
- $teacher = reset($teachers);
- } else {
- $teachers = array($admin);
- $teacher = $admin;
- }
-
- $a->teacherstr = fullname($teacher, true);
-
- foreach ($oldenrolments as $user) { /// Email all users about to expire
- $a->studentstr = fullname($user, true);
- if ($user->timeend < ($expiry - 86400)) {
- $a->past[] = fullname($user) . " <$user->email>";
- } else {
- $a->current[] = fullname($user) . " <$user->email>";
- if ($course->notifystudents) { // Send this guy notice
- // setup global $COURSE properly - needed for languages
- cron_setup_user($user, $course);
- $a->coursename = format_string($cname);
- $a->course = $a->coursename;
- $strexpirynotifystudentsemail = get_string('expirynotifystudentsemail', '', $a);
- $strexpirynotify = get_string('expirynotify');
-
- $eventdata = new object();
- $eventdata->modulename = 'moodle';
- $eventdata->userfrom = $teacher;
- $eventdata->userto = $user;
- $eventdata->subject = format_string($SITE->fullname) .' '. $strexpirynotify;
- $eventdata->fullmessage = $strexpirynotifystudentsemail;
- $eventdata->fullmessageformat = FORMAT_PLAIN;
- $eventdata->fullmessagehtml = '';
- $eventdata->smallmessage = '';
- message_send($eventdata);
- }
- }
- }
-
- $a->current = implode("\n", $a->current);
- $a->past = implode("\n", $a->past);
-
- if ($a->current || $a->past) {
- foreach ($teachers as $teacher) {
- // setup global $COURSE properly - needed for languages
- cron_setup_user($teacher, $course);
- $a->coursename = format_string($cname);
- $strexpirynotifyemail = get_string('expirynotifyemail', '', $a);
- $strexpirynotify = get_string('expirynotify');
-
- $eventdata = new object();
- $eventdata->modulename = 'moodle';
- $eventdata->userfrom = $admin;
- $eventdata->userto = $teacher;
- $eventdata->subject = $a->coursename .' '. $strexpirynotify;
- $eventdata->fullmessage = $strexpirynotifyemail;
- $eventdata->fullmessageformat = FORMAT_PLAIN;
- $eventdata->fullmessagehtml = '';
- $eventdata->smallmessage = '';
- message_send($eventdata);
- }
- }
- }
- }
- $rs->close();
- cron_setup_user();
- }
-
- set_config('lastexpirynotify', date('Ymd'));
-}
-
-
-/**
-* Returns the relevant icons for a course
-*
-* @param course the current course, as an object
-*/
-function get_access_icons($course) {
- global $CFG, $OUTPUT;
-
- global $strallowguests;
- global $strrequireskey;
-
- if (empty($strallowguests)) {
- $strallowguests = get_string('allowguests');
- $strrequireskey = get_string('requireskey');
- }
-
- $str = '';
-
- if (!empty($course->guest)) {
- $str .= '';
- $str .= ' ';
- }
- if (!empty($course->password)) {
- $str .= '';
- $str .= '';
- }
-
- return $str;
-}
-
-/**
- * Prints the message telling you were to get the enrolment key
- * appropriate for the prevailing circumstances
- * A bit clunky because I didn't want to change the standard strings
- */
-function print_enrolmentkeyfrom($course) {
- global $CFG, $USER;
-
- $context = get_context_instance(CONTEXT_SYSTEM);
-
- // if a keyholder role is defined we list teachers in that role (if any exist)
- $contactslisted = false;
- if (!empty($CFG->enrol_manual_keyholderrole)) {
- if ($contacts = get_role_users($CFG->enrol_manual_keyholderrole, get_context_instance(CONTEXT_COURSE, $course->id),true,'','u.lastname ASC')) {
- // guest user has a slightly different message
- if (isguestuser()) {
- print_string('enrolmentkeyfromguest', '', ': ' );
- }
- else {
- print_string('enrolmentkeyfrom', '', ': ');
- }
- foreach ($contacts as $contact) {
- $contactname = "id&course=".SITEID."\">".fullname($contact).".";
- echo "$contactname ";
- }
- $contactslisted = true;
- }
- }
-
- // if no keyholder role is defined OR nobody is in that role we do this the 'old' way
- // (show the first person with update rights)
- if (!$contactslisted) {
- if ($teachers = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'moodle/course:update',
- 'u.*', 'u.id ASC', 0, 1, '', '', false, true)) {
- $teacher = array_shift($teachers);
- }
- if (!empty($teacher)) {
- $teachername = "id&course=".SITEID."\">".fullname($teacher).".";
- } else {
- $teachername = strtolower( get_string('defaultcourseteacher') );
- }
-
- // guest user has a slightly different message
- if (isguestuser()) {
- print_string('enrolmentkeyfromguest', '', $teachername );
- }
- else {
- print_string('enrolmentkeyfrom', '', $teachername);
- }
- }
-}
-
-} /// end of class
-
-
Index: calendar/view.php
===================================================================
--- calendar/view.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ calendar/view.php (revision )
@@ -636,7 +636,7 @@
if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
$courses = get_courses('all', 'c.shortname','c.id,c.shortname');
} else {
- $courses = get_my_courses($USER->id, 'shortname');
+ $courses = enrol_get_my_courses();
}
unset($courses[SITEID]);
Index: enrol/authorize/enrol.php
===================================================================
--- enrol/authorize/enrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ enrol/authorize/enrol.php (revision )
@@ -1,6 +1,5 @@
dirroot.'/enrol/enrol.class.php');
require_once($CFG->dirroot.'/enrol/authorize/const.php');
require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php');
require_once($CFG->dirroot.'/enrol/authorize/authorizenet.class.php');
@@ -49,7 +48,7 @@
print_error('httpsrequired', 'enrol_authorize');
} else {
$wwwsroot = str_replace('http:','https:', $CFG->wwwroot);
- redirect("$wwwsroot/course/enrol.php?id=$course->id");
+ redirect("$wwwsroot/enrol/index.php?id=$course->id");
exit;
}
}
@@ -685,7 +684,8 @@
$timeend = $order->settletime + $course->enrolperiod;
}
$user = $DB->get_record('user', array('id'=>$order->userid));
- if (role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, 'authorize')) {
+ // TODO: do some real enrolment here
+ if (role_assign($role->id, $user->id, $context->id, 'enrol_authorize')) {
$this->log .= "User($user->id) has been enrolled to course($course->id).\n";
if (!empty($CFG->enrol_mailstudents)) {
$sendem[] = $order->id;
Index: user/view.php
===================================================================
--- user/view.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ user/view.php (revision )
@@ -121,7 +121,7 @@
if ($isfrontpage) {
// Reduce possibility of "browsing" userbase at site level
- if (!empty($CFG->forceloginforprofiles) and !has_capability('moodle/user:viewdetails', $usercontext) and !has_coursemanager_role($user->id)) {
+ if (!empty($CFG->forceloginforprofiles) and !has_capability('moodle/user:viewdetails', $usercontext) and !has_coursecontact_role($user->id)) {
// Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
$PAGE->navbar->add($struser);
echo $OUTPUT->header();
@@ -364,24 +364,26 @@
if (!isset($hiddenfields['mycourses'])) {
- if ($mycourses = get_my_courses($user->id, 'visible DESC,sortorder ASC', null, false, 21)) {
+ if ($hiscourses = enrol_get_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC')) {
$shown=0;
$courselisting = '';
- foreach ($mycourses as $mycourse) {
- if ($mycourse->category) {
- if ($mycourse->id != $course->id){
+ foreach ($hiscourses as $hiscourse) {
+ if ($hiscourse->category) {
+ if ($hiscourse->id != $course->id){
$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
+ if ($hiscourse->visible == 0) {
+ $ccontext = get_context_instance(CONTEXT_COURSE, $hiscourse->id, MUST_EXIST);
+ if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
+ // filter our courses I am not allowed to see
+ continue;
+ }
$class = 'class="dimmed"';
}
- $courselisting .= "wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >"
- . format_string($mycourse->fullname) . ", ";
+ $courselisting .= "wwwroot}/user/view.php?id={$user->id}&course={$hiscourse->id}\" $class >"
+ . format_string($hiscourse->fullname) . ", ";
}
else {
- $courselisting .= format_string($mycourse->fullname) . ", ";
+ $courselisting .= format_string($hiscourse->fullname) . ", ";
}
}
$shown++;
@@ -488,11 +490,12 @@
echo "";
}
-if (!$isfrontpage && empty($course->metacourse)) { // Mostly only useful at course level
+if (!$isfrontpage) { // Mostly only useful at course level
if ($currentuser) {
- if (is_enrolled($coursecontext, NULL, 'moodle/role:unassignself')) {
- echo '';
}
+ */
} else {
if (is_enrolled($coursecontext, $user->id, 'moodle/role:assign')) { // I can unassign roles
// add some button to unenroll user
Index: enrol/manual/db/install.php
===================================================================
--- enrol/manual/db/install.php (revision )
+++ enrol/manual/db/install.php (revision )
@@ -0,0 +1,24 @@
+enrol_manual_usepasswordpolicy)) {
+ set_config('usepasswordpolicy', $CFG->enrol_manual_usepasswordpolicy, 'enrol_guest');
+ set_config('usepasswordpolicy', $CFG->enrol_manual_usepasswordpolicy, 'enrol_self');
+ unset_config('enrol_manual_usepasswordpolicy');
+ }
+ if (isset($CFG->enrol_manual_requirekey)) {
+ set_config('requirepassword', $CFG->enrol_manual_requirekey, 'enrol_guest');
+ set_config('requirepassword', $CFG->enrol_manual_requirekey, 'enrol_self');
+ unset_config('enrol_manual_requirekey');
+ }
+ if (isset($CFG->enrol_manual_showhint)) {
+ set_config('showhint', $CFG->enrol_manual_showhint, 'enrol_guest');
+ set_config('showhint', $CFG->enrol_manual_showhint, 'enrol_self');
+ unset_config('enrol_manual_showhint');
+ }
+}
+
Index: enrol/paypal/enrol.php
===================================================================
--- enrol/paypal/enrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ enrol/paypal/enrol.php (revision )
@@ -1,9 +1,6 @@
dirroot/enrol/enrol.class.php");
-
-
class enrolment_plugin_paypal {
Index: enrol/meta/lib.php
===================================================================
--- enrol/meta/lib.php (revision )
+++ enrol/meta/lib.php (revision )
@@ -0,0 +1,34 @@
+.
+
+/**
+ * Meta course enrolment plugin.
+ *
+ * @package enrol_meta
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+//TODO:
+// * sync in cron or upon request
+
+
+class enrol_meta_plugin extends enrol_plugin {
+
+}
+
Index: enrol/ldap/enrol_ldap_sync.php
===================================================================
--- enrol/ldap/enrol_ldap_sync.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ enrol/ldap/enrol_ldap_sync.php (revision )
@@ -27,9 +27,4 @@
$enrol->sync_enrolments($role->shortname, true);
}
- // sync metacourses
- if (function_exists('sync_metacourses')) {
- sync_metacourses();
- }
-
Index: course/external.php
===================================================================
--- course/external.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ course/external.php (revision )
@@ -51,16 +51,7 @@
* @subreturn integer $return:course->showgrades
* @subreturn string $return:course->modinfo
* @subreturn string $return:course->newsitems
- * @subreturn string $return:course->guest
- * @subreturn integer $return:course->metacourse
- * @subreturn string $return:course->password
- * @subreturn integer $return:course->enrolperiod
- * @subreturn integer $return:course->defaultrole
- * @subreturn integer $return:course->enrollable
* @subreturn integer $return:course->numsections
- * @subreturn integer $return:course->expirynotify
- * @subreturn integer $return:course->notifystudents
- * @subreturn integer $return:course->expirythreshold
* @subreturn integer $return:course->marker
* @subreturn integer $return:course->maxbytes
* @subreturn integer $return:course->showreports
@@ -71,20 +62,15 @@
* @subreturn integer $return:course->defaultgroupingid
* @subreturn string $return:course->lang
* @subreturn string $return:course->theme
- * @subreturn string $return:course->cost
- * @subreturn string $return:course->currency
* @subreturn integer $return:course->timecreated
* @subreturn integer $return:course->timemodified
* @subreturn integer $return:course->requested
* @subreturn integer $return:course->restrictmodules
- * @subreturn integer $return:course->enrolstartdate
- * @subreturn integer $return:course->enrolenddate
- * @subreturn string $return:course->enrol
* @subreturn integer $return:course->enablecompletion
*/
static function get_courses($params) {
global $USER;
- if (has_capability('moodle/course:participate', get_context_instance(CONTEXT_SYSTEM))) {
+ if (has_capability('moodle/course:view', get_context_instance(CONTEXT_SYSTEM))) {
$courses = array();
foreach ($params as $param) {
$course = new stdClass();
@@ -111,12 +97,9 @@
$returnedcourse->startdate = $course->startdate;
$returnedcourse->category = $course->category;
$returnedcourse->sortorder = $course->sortorder;
- $returnedcourse->password = $course->password ;
$returnedcourse->showgrades = $course->showgrades;
$returnedcourse->modinfo = $course->modinfo;
$returnedcourse->newsitems = $course->newsitems;
- $returnedcourse->guest = $course->guest;
- $returnedcourse->enrolperiod = $course->enrolperiod;
$returnedcourse->marker = $course->marker;
$returnedcourse->maxbytes = $course->maxbytes;
$returnedcourse->showreports = $course->showreports;
@@ -127,21 +110,10 @@
$returnedcourse->defaultgroupingid = $course->defaultgroupingid;
$returnedcourse->lang = $course->lang;
$returnedcourse->theme = $course->theme;
- $returnedcourse->cost = $course->cost;
- $returnedcourse->currency = $course->currency;
$returnedcourse->timecreated = $course->timecreated;
$returnedcourse->timemodified = $course->timemodified;
- $returnedcourse->metacourse = $course->metacourse;
$returnedcourse->requested = $course->requested;
$returnedcourse->restrictmodules = $course->restrictmodules;
- $returnedcourse->expirynotify = $course->expirynotify;
- $returnedcourse->expirythreshold = $course->expirythreshold;
- $returnedcourse->notifystudents = $course->notifystudents;
- $returnedcourse->enrollable = $course->enrollable;
- $returnedcourse->enrolstartdate = $course->enrolstartdate;
- $returnedcourse->enrolenddate = $course->enrolenddate;
- $returnedcourse->enrol = $course->enrol;
- $returnedcourse->defaultrole = $course->defaultrole;
$returnedcourse->enablecompletion = $course->enablecompletion;
$courses[] = $returnedcourse;
@@ -168,16 +140,7 @@
* @subparam integer $params:course->showgrades
* @subparam string $params:course->modinfo
* @subparam string $params:course->newsitems
- * @subparam string $params:course->guest
- * @subparam integer $params:course->metacourse
- * @subparam string $params:course->password
- * @subparam integer $params:course->enrolperiod
- * @subparam integer $params:course->defaultrole
- * @subparam integer $params:course->enrollable
* @subparam integer $params:course->numsections
- * @subparam integer $params:course->expirynotify
- * @subparam integer $params:course->notifystudents
- * @subparam integer $params:course->expirythreshold
* @subparam integer $params:course->marker
* @subparam integer $params:course->maxbytes
* @subparam integer $params:course->showreports
@@ -188,15 +151,10 @@
* @subparam integer $params:course->defaultgroupingid
* @subparam string $params:course->lang
* @subparam string $params:course->theme
- * @subparam string $params:course->cost
- * @subparam string $params:course->currency
* @subparam integer $params:course->timecreated
* @subparam integer $params:course->timemodified
* @subparam integer $params:course->requested
* @subparam integer $params:course->restrictmodules
- * @subparam integer $params:course->enrolstartdate
- * @subparam integer $params:course->enrolenddate
- * @subparam string $params:course->enrol
* @subparam integer $params:course->enablecompletion
* @return array $return ids of new courses
* @subreturn integer $return:id course id
@@ -236,7 +194,6 @@
$course->startdate = clean_param($courseparams['startdate'], PARAM_INT);
}
-
if (array_key_exists('sortorder', $courseparams)) {
$course->sortorder = clean_param($courseparams['sortorder'], PARAM_INT);
}
@@ -253,46 +210,10 @@
$course->newsitems = clean_param($courseparams['newsitems'], PARAM_ALPHANUMEXT);
}
- if (array_key_exists('guest', $courseparams)) {
- $course->guest = clean_param($courseparams['guest'], PARAM_ALPHANUMEXT);
- }
-
- if (array_key_exists('metacourse', $courseparams)) {
- $course->metacourse = clean_param($courseparams['metacourse'], PARAM_INT);
- }
-
- if (array_key_exists('password', $courseparams)) {
- $course->password = clean_param($courseparams['password'], PARAM_ALPHANUMEXT);
- }
-
- if (array_key_exists('enrolperiod', $courseparams)) {
- $course->enrolperiod = clean_param($courseparams['enrolperiod'], PARAM_INT);
- }
-
- if (array_key_exists('defaultrole', $courseparams)) {
- $course->defaultrole = clean_param($courseparams['defaultrole'], PARAM_INT);
- }
-
- if (array_key_exists('enrollable', $courseparams)) {
- $course->enrollable = clean_param($courseparams['enrollable'], PARAM_INT);
- }
-
if (array_key_exists('numsections', $courseparams)) {
$course->numsections = clean_param($courseparams['numsections'], PARAM_INT);
}
- if (array_key_exists('expirynotify', $courseparams)) {
- $course->expirynotify = clean_param($courseparams['expirynotify'], PARAM_INT);
- }
-
- if (array_key_exists('notifystudents', $courseparams)) {
- $course->notifystudents = clean_param($courseparams['notifystudents'], PARAM_INT);
- }
-
- if (array_key_exists('expirythreshold', $courseparams)) {
- $course->expirythreshold = clean_param($courseparams['expirythreshold'], PARAM_INT);
- }
-
if (array_key_exists('marker', $courseparams)) {
$course->marker = clean_param($courseparams['marker'], PARAM_INT);
}
@@ -313,7 +234,6 @@
$course->hiddensections = clean_param($courseparams['hiddensections'], PARAM_INT);
}
-
if (array_key_exists('groupmode', $courseparams)) {
$course->groupmode = clean_param($courseparams['groupmode'], PARAM_INT);
}
@@ -334,14 +254,6 @@
$course->theme = clean_param($courseparams['theme'], PARAM_ALPHANUMEXT);
}
- if (array_key_exists('cost', $courseparams)) {
- $course->cost = clean_param($courseparams['cost'], PARAM_ALPHANUMEXT);
- }
-
- if (array_key_exists('currency', $courseparams)) {
- $course->currency = clean_param($courseparams['currency'], PARAM_ALPHANUMEXT);
- }
-
if (array_key_exists('timecreated', $courseparams)) {
$course->timecreated = clean_param($courseparams['timecreated'], PARAM_INT);
}
@@ -358,18 +270,6 @@
$course->restrictmodules = clean_param($courseparams['restrictmodules'], PARAM_INT);
}
- if (array_key_exists('enrolstartdate', $courseparams)) {
- $course->enrolstartdate = clean_param($courseparams['enrolstartdate'], PARAM_INT);
- }
-
- if (array_key_exists('enrolenddate', $courseparams)) {
- $course->enrolenddate = clean_param($courseparams['enrolenddate'], PARAM_INT);
- }
-
- if (array_key_exists('enrol', $courseparams)) {
- $course->enrol = clean_param($courseparams['enrol'], PARAM_ALPHANUMEXT);
- }
-
if (array_key_exists('enablecompletion', $courseparams)) {
$course->enablecompletion = clean_param($courseparams['enablecompletion'], PARAM_INT);
}
@@ -445,16 +345,7 @@
* @subparam integer $params:course->showgrades
* @subparam string $params:course->modinfo
* @subparam string $params:course->newsitems
- * @subparam string $params:course->guest
- * @subparam integer $params:course->metacourse
- * @subparam string $params:course->password
- * @subparam integer $params:course->enrolperiod
- * @subparam integer $params:course->defaultrole
- * @subparam integer $params:course->enrollable
* @subparam integer $params:course->numsections
- * @subparam integer $params:course->expirynotify
- * @subparam integer $params:course->notifystudents
- * @subparam integer $params:course->expirythreshold
* @subparam integer $params:course->marker
* @subparam integer $params:course->maxbytes
* @subparam integer $params:course->showreports
@@ -465,15 +356,10 @@
* @subparam integer $params:course->defaultgroupingid
* @subparam string $params:course->lang
* @subparam string $params:course->theme
- * @subparam string $params:course->cost
- * @subparam string $params:course->currency
* @subparam integer $params:course->timecreated
* @subparam integer $params:course->timemodified
* @subparam integer $params:course->requested
* @subparam integer $params:course->restrictmodules
- * @subparam integer $params:course->enrolstartdate
- * @subparam integer $params:course->enrolenddate
- * @subparam string $params:course->enrol
* @subparam integer $params:course->enablecompletion
* @return boolean result true if success
*/
@@ -515,7 +401,6 @@
$course->startdate = clean_param($courseparams['startdate'], PARAM_INT);
}
-
if (array_key_exists('sortorder', $courseparams)) {
$course->sortorder = clean_param($courseparams['sortorder'], PARAM_INT);
}
@@ -532,46 +417,10 @@
$course->newsitems = clean_param($courseparams['newsitems'], PARAM_ALPHANUMEXT);
}
- if (array_key_exists('guest', $courseparams)) {
- $course->guest = clean_param($courseparams['guest'], PARAM_ALPHANUMEXT);
- }
-
- if (array_key_exists('metacourse', $courseparams)) {
- $course->metacourse = clean_param($courseparams['metacourse'], PARAM_INT);
- }
-
- if (array_key_exists('password', $courseparams)) {
- $course->password = clean_param($courseparams['password'], PARAM_ALPHANUMEXT);
- }
-
- if (array_key_exists('enrolperiod', $courseparams)) {
- $course->enrolperiod = clean_param($courseparams['enrolperiod'], PARAM_INT);
- }
-
- if (array_key_exists('defaultrole', $courseparams)) {
- $course->defaultrole = clean_param($courseparams['defaultrole'], PARAM_INT);
- }
-
- if (array_key_exists('enrollable', $courseparams)) {
- $course->enrollable = clean_param($courseparams['enrollable'], PARAM_INT);
- }
-
if (array_key_exists('numsections', $courseparams)) {
$course->numsections = clean_param($courseparams['numsections'], PARAM_INT);
}
- if (array_key_exists('expirynotify', $courseparams)) {
- $course->expirynotify = clean_param($courseparams['expirynotify'], PARAM_INT);
- }
-
- if (array_key_exists('notifystudents', $courseparams)) {
- $course->notifystudents = clean_param($courseparams['notifystudents'], PARAM_INT);
- }
-
- if (array_key_exists('expirythreshold', $courseparams)) {
- $course->expirythreshold = clean_param($courseparams['expirythreshold'], PARAM_INT);
- }
-
if (array_key_exists('marker', $courseparams)) {
$course->marker = clean_param($courseparams['marker'], PARAM_INT);
}
@@ -612,14 +461,6 @@
$course->theme = clean_param($courseparams['theme'], PARAM_ALPHANUMEXT);
}
- if (array_key_exists('cost', $courseparams)) {
- $course->cost = clean_param($courseparams['cost'], PARAM_ALPHANUMEXT);
- }
-
- if (array_key_exists('currency', $courseparams)) {
- $course->currency = clean_param($courseparams['currency'], PARAM_ALPHANUMEXT);
- }
-
if (array_key_exists('timecreated', $courseparams)) {
$course->timecreated = clean_param($courseparams['timecreated'], PARAM_INT);
}
@@ -636,18 +477,6 @@
$course->restrictmodules = clean_param($courseparams['restrictmodules'], PARAM_INT);
}
- if (array_key_exists('enrolstartdate', $courseparams)) {
- $course->enrolstartdate = clean_param($courseparams['enrolstartdate'], PARAM_INT);
- }
-
- if (array_key_exists('enrolenddate', $courseparams)) {
- $course->enrolenddate = clean_param($courseparams['enrolenddate'], PARAM_INT);
- }
-
- if (array_key_exists('enrol', $courseparams)) {
- $course->enrol = clean_param($courseparams['enrol'], PARAM_ALPHANUMEXT);
- }
-
if (array_key_exists('enablecompletion', $courseparams)) {
$course->enablecompletion = clean_param($courseparams['enablecompletion'], PARAM_INT);
}
@@ -681,7 +510,7 @@
*/
static function get_course_modules($params, $type=null) {
global $DB;
- if (has_capability('moodle/course:participate', get_context_instance(CONTEXT_SYSTEM))) {
+ if (has_capability('moodle/course:view', get_context_instance(CONTEXT_SYSTEM))) {
$modules = array();
foreach ($params as $courseparams) {
if (array_key_exists('id', $courseparams)) {
Index: message/lib.php
===================================================================
--- message/lib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ message/lib.php (revision )
@@ -319,7 +319,7 @@
if (optional_param('mycourses', 0, PARAM_BOOL)) {
$users = array();
- $mycourses = get_my_courses($USER->id);
+ $mycourses = enrol_get_my_courses();
foreach ($mycourses as $mycourse) {
if (is_array($susers = message_search_users($mycourse->id, $frm->name))) {
foreach ($susers as $suser) $users[$suser->id] = $suser;
Index: grade/querylib.php
===================================================================
--- grade/querylib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ grade/querylib.php (revision )
@@ -128,7 +128,7 @@
if (!is_array($courseid_or_ids)) {
if (empty($courseid_or_ids)) {
- if (!$courses = get_my_courses($userid, $sort='visible DESC,sortorder ASC', 'id')) {
+ if (!$courses = enrol_get_users_courses($userid)) {
return false;
}
$courseids = array_keys($courses);
Index: auth/cas/auth.php
===================================================================
--- auth/cas/auth.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ auth/cas/auth.php (revision )
@@ -824,9 +824,9 @@
// update course creators if needed
if ($creatorrole !== false) {
if ($this->iscreator($user->username)) {
- role_assign($creatorrole->id, $user->id, 0, $sitecontext->id, 0, 0, 0, 'cas');
+ role_assign($creatorrole->id, $user->id, $sitecontext->id, 'auth_cas');
} else {
- role_unassign($creatorrole->id, $user->id, 0, $sitecontext->id, 'cas');
+ role_unassign($creatorrole->id, $user->id, $sitecontext->id, 'auth_cas');
}
}
}
@@ -884,7 +884,7 @@
// add course creators if needed
if ($creatorrole !== false and $this->iscreator($user->username)) {
- role_assign($creatorrole->id, $user->id, 0, $sitecontext->id, 0, 0, 0, 'cas');
+ role_assign($creatorrole->id, $user->id, $sitecontext->id, 'auth_cas');
}
}
$transaction->allow_commit();
@@ -1128,10 +1128,10 @@
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if ($iscreator) { // Following calls will not create duplicates
- role_assign($creatorrole->id, $user->id, 0, $systemcontext->id, 0, 0, 0, 'cas');
+ role_assign($creatorrole->id, $user->id, $systemcontext->id, 'auth_cas');
} else {
//unassign only if previously assigned by this plugin!
- role_unassign($creatorrole->id, $user->id, 0, $systemcontext->id, 'cas');
+ role_unassign($creatorrole->id, $user->id, $systemcontext->id, 'auth_cas');
}
}
}
Index: repository/lib.php
===================================================================
--- repository/lib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ repository/lib.php (revision )
@@ -549,7 +549,7 @@
$level = $context->contextlevel;
if ($level == CONTEXT_COURSE) {
- if (!has_capability('moodle/course:participate', $context)) {
+ if (!is_enrolled($context)) { //TODO: this looks a bit too simple, verify!
return false;
} else {
return true;
Index: lib/db/install.php
===================================================================
--- lib/db/install.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lib/db/install.php (revision )
@@ -46,7 +46,7 @@
'auth' => 'email',
'auth_pop3mailbox' => 'INBOX',
'enrol' => 'manual',
- 'enrol_plugins_enabled' => 'manual',
+ 'enrol_plugins_enabled' => 'manual,guest,self,cohort',
'style' => 'default',
'template' => 'default',
'theme' => theme_config::DEFAULT_THEME,
Index: lang/en/help/courseenrollable2.html
===================================================================
--- lang/en/help/courseenrollable2.html (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lang/en/help/courseenrollable2.html (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
@@ -1,2 +0,0 @@
-
This setting determines whether students are able to enrol themselves using the default interactive enrolment plugin (e.g. Internal enrolment) for the course, or whether they obtain the message "This course is not enrollable at the moment."
-
This setting has no effect on non-interactive enrolment plugins (e.g. External database enrolment). Also, users can always be assigned the role of student via the Assign roles link in the course administration block.
\ No newline at end of file
Index: enrol/self/db/access.php
===================================================================
--- enrol/self/db/access.php (revision )
+++ enrol/self/db/access.php (revision )
@@ -0,0 +1,25 @@
+ array(
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW,
+ )
+ ),
+
+);
+
+
Index: admin/uploaduser.php
===================================================================
--- admin/uploaduser.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ admin/uploaduser.php (revision )
@@ -658,12 +658,10 @@
$a = new object();
$a->course = $shortname;
$a->role = $rolecache[$rid]->name;
- if (role_assign($rid, $user->id, 0, $coursecontext->id, $timestart, $timeend)) {
+ //TODO: use real manual enrolments here!
+ role_assign($rid, $user->id, $coursecontext->id);
- $upt->track('enrolments', get_string('enrolledincourserole', '', $a));
+ $upt->track('enrolments', get_string('enrolledincourserole', '', $a));
- } else {
- $upt->track('enrolments', get_string('enrolledincoursenotrole', '', $a), 'error');
- }
+ }
- }
// find group to add to
if (!empty($user->{'group'.$i})) {
Index: enrol/index.php
===================================================================
--- enrol/index.php (revision )
+++ enrol/index.php (revision )
@@ -0,0 +1,99 @@
+.
+
+/**
+ * This page shows all course enrolment options for current user.
+ *
+ * @package core
+ * @subpackage course
+ * @copyright 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->libdir/formslib.php");
+
+$id = required_param('id', PARAM_INT);
+
+if (!isloggedin()) {
+ // do not use require_login here because we are usually coming from it,
+ // it would also mess up the SESSION->wantsurl
+ redirect(get_login_url());
+}
+
+$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
+$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
+
+// Everybody is enrolled on the frontpage
+if ($course->id == SITEID) {
+ redirect("$CFG->wwwroot/");
+}
+
+$PAGE->set_url('/enrol/index.php', array('id'=>$course->id));
+
+// do not allow enrols when in login-as session
+if (session_is_loggedinas() and $USER->loginascontext->contextlevel == CONTEXT_COURSE) {
+ print_error('loginasnoenrol', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid);
+}
+
+// get all enrol forms available in this course
+$enrols = enrol_get_plugins(true);
+$enrolinstances = enrol_get_instances($course->id, true);
+$forms = array();
+foreach($enrolinstances as $instance) {
+ if (!isset($enrols[$instance->enrol])) {
+ continue;
+ }
+ $form = $enrols[$instance->enrol]->enrol_page_hook($instance);
+ if ($form) {
+ $forms[$instance->id] = $form;
+ }
+}
+
+// Check if user already enrolled
+if (is_enrolled($context, $USER, '', true)) {
+ if (!empty($SESSION->wantsurl)) {
+ $destination = $SESSION->wantsurl;
+ unset($SESSION->wantsurl);
+ } else {
+ $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
+ }
+ redirect($destination); // Bye!
+}
+
+$PAGE->set_title($course->shortname);
+$PAGE->set_heading($course->fullname);
+$PAGE->navbar->add($course->fullname);
+
+
+echo $OUTPUT->header();
+
+//TODO: find if future enrolments present and display some info
+
+foreach ($forms as $form) {
+ echo $form;
+}
+
+if (!$forms) {
+ notice(get_string('notenrollable'), "$CFG->wwwroot/index.php");
+}
+
+if (isguestuser()) {
+ //TODO: print login link + some info
+}
+
+echo $OUTPUT->footer();
Index: course/info.php
===================================================================
--- course/info.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ course/info.php (revision )
@@ -29,7 +29,7 @@
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
- if ((!course_parent_visible($course) || (! $course->visible)) && !has_capability('moodle/course:viewhiddencourses', $context)) {
+ if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
print_error('coursehidden', '', $CFG->wwwroot .'/');
}
@@ -61,9 +61,9 @@
$course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course_summary', $course->id);
echo format_text($course->summary, $course->summaryformat, NULL, $course->id);
- if (!empty($CFG->coursemanager)) {
- $coursemanagerroles = explode(',', $CFG->coursemanager);
- foreach ($coursemanagerroles as $roleid) {
+ if (!empty($CFG->coursecontact)) {
+ $coursecontactroles = explode(',', $CFG->coursecontact);
+ foreach ($coursecontactroles as $roleid) {
$role = $DB->get_record('role', array('id'=>$roleid));
$roleid = (int) $roleid;
if ($users = get_role_users($roleid, $context, true)) {
@@ -82,9 +82,7 @@
}
}
- require_once("$CFG->dirroot/enrol/enrol.class.php");
- $enrol = enrolment_factory::factory($course->enrol);
- echo $enrol->get_access_icons($course);
+// TODO: print some enrol icons
echo $OUTPUT->box_end();
Index: enrol/imsenterprise/enrol.php
===================================================================
--- enrol/imsenterprise/enrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ enrol/imsenterprise/enrol.php (revision )
@@ -761,7 +761,8 @@
// Enrol unsing the generic role_assign() function
- if ((!role_assign($moodleroleid, $memberstoreobj->userid, 0, $rolecontext, $timeframe->begin, $timeframe->end, 0, 'imsenterprise')) && (trim($memberstoreobj->userid)!='')) {
+ //TODO: some real enrolment here
+ if ((!role_assign($moodleroleid, $memberstoreobj->userid, $rolecontext, 'enrol_imsenterprise')) && (trim($memberstoreobj->userid)!='')) {
$this->log_line("Error enrolling user #$memberstoreobj->userid ($member->idnumber) to role $member->roletype in course $memberstoreobj->course");
}else{
$this->log_line("Enrolled user #$memberstoreobj->userid ($member->idnumber) to role $member->roletype in course $memberstoreobj->course");
@@ -798,13 +799,10 @@
}elseif($CFG->enrol_imsunenrol){
// Unenrol
- if (! role_unassign($moodleroleid, $memberstoreobj->userid, 0, $rolecontext, 'imsenterprise')) {
- $this->log_line("Error unenrolling $memberstoreobj->userid from role $moodleroleid in course");
- }else{
+ role_unassign($moodleroleid, $memberstoreobj->userid, 0, $rolecontext, 'imsenterprise');
- $membersuntally++;
- $this->log_line("Unenrolled $member->idnumber from role $moodleroleid in course");
- }
+ $membersuntally++;
+ $this->log_line("Unenrolled $member->idnumber from role $moodleroleid in course");
+ }
- }
}
}
Index: lib/sessionlib.php
===================================================================
--- lib/sessionlib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lib/sessionlib.php (revision )
@@ -74,7 +74,7 @@
* @return void
*/
public function write_close();
-
+
/**
* Check for existing session with id $sid
* @param unknown_type $sid
@@ -159,7 +159,7 @@
} catch (Exception $ignored) {
// probably install/upgrade - ignore this problem
}
-
+
if (NO_MOODLE_COOKIES) {
return;
}
@@ -372,7 +372,7 @@
$sessionfile = clean_param("$CFG->dataroot/sessions/sess_$sid", PARAM_FILE);
return file_exists($sessionfile);
}
-
+
}
@@ -401,20 +401,20 @@
}
}
}
-
+
public function session_exists($sid){
global $CFG;
try {
$sql = "SELECT * FROM {sessions} WHERE timemodified < ? AND sid=? AND state=?";
$params = array(time() + $CFG->sessiontimeout, $sid, 0);
-
+
return $this->database->record_exists_sql($sql, $params);
} catch (dml_exception $ex) {
error_log('Error checking existance of database session');
return false;
}
}
-
+
protected function init_session_storage() {
global $CFG;
@@ -878,7 +878,7 @@
unset($_SESSION['USER']->description); // conserve memory
if (!isset($_SESSION['USER']->access)) {
// check enrolments and load caps only once
- check_enrolment_plugins($_SESSION['USER']);
+ enrol_check_plugins($_SESSION['USER']);
load_all_capabilities();
}
sesskey(); // init session key
Index: lib/setup.php
===================================================================
--- lib/setup.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lib/setup.php (revision )
@@ -289,6 +289,7 @@
require_once($CFG->libdir .'/accesslib.php'); // Access control functions
require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
+require_once($CFG->libdir .'/enrollib.php'); // Enrolment related functions
require_once($CFG->libdir .'/pagelib.php'); // Library that defines the moodle_page class, used for $PAGE
require_once($CFG->libdir .'/blocklib.php'); // Library for controlling blocks
require_once($CFG->libdir .'/eventslib.php'); // Events functions
Index: lib/simpletest/broken_testfilelib.php
===================================================================
--- lib/simpletest/broken_testfilelib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lib/simpletest/broken_testfilelib.php (revision )
@@ -135,7 +135,7 @@
$this->user->id = create_user($this->user);
// Assign user to course
- // role_assign(5, $this->user->id, 0, get_context_instance(CONTEXT_COURSE, $this->course->id)->id);
+ // role_assign(5, $this->user->id, get_context_instance(CONTEXT_COURSE, $this->course->id)->id);
// Create a module
$module = new stdClass();
Index: admin/settings/users.php
===================================================================
--- admin/settings/users.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ admin/settings/users.php (revision )
@@ -155,6 +155,7 @@
$temp->add(new admin_setting_configcheckbox('nodefaultuserrolelists', get_string('nodefaultuserrolelists', 'admin'), get_string('confignodefaultuserrolelists', 'admin'), 0));
if (!during_initial_install()) {
+ //TODO? remove defaultcourseroleid because it was replaced by default roles in each enrol plugin
$temp->add(new admin_setting_configselect('defaultcourseroleid', get_string('defaultcourseroleid', 'admin'),
get_string('configdefaultcourseroleid', 'admin'), $defaultstudentid, $allroles));
$temp->add(new admin_setting_configselect('creatornewroleid', get_string('creatornewroleid', 'admin'),
@@ -163,11 +164,6 @@
$temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0));
- if (!during_initial_install()) {
- $temp->add(new admin_setting_configmultiselect('nonmetacoursesyncroleids', get_string('nonmetacoursesyncroleids', 'admin'),
- get_string('confignonmetacoursesyncroleids', 'admin'), array(), $allroles));
- }
-
$temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('hiddenuserfields', 'admin'),
get_string('confighiddenuserfields', 'admin'), array(),
array('description' => get_string('description'),
Index: admin/settings/courses.php
===================================================================
--- admin/settings/courses.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ admin/settings/courses.php (revision )
@@ -11,8 +11,6 @@
$ADMIN->add('courses', new admin_externalpage('coursemgmt', get_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on',
array('moodle/category:manage', 'moodle/course:create')));
- $ADMIN->add('courses', new admin_enrolment_page());
-
/// Course Default Settings Page
/// NOTE: these settings must be applied after all other settings because they depend on them
///main course settings
@@ -41,46 +39,7 @@
$choices = get_max_upload_sizes();
}
$temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices), $choices));
- $temp->add(new admin_setting_configselect('moodlecourse/metacourse', get_string('metacourse'), get_string('coursehelpmetacourse'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
- ///enrolement course settings
- $temp->add(new admin_setting_heading('enrolhdr', get_string('enrolments'), ''));
- require_once($CFG->dirroot.'/enrol/enrol.class.php');
- $choices = array();
- $modules = explode(',', $CFG->enrol_plugins_enabled);
- foreach ($modules as $module) {
- $name = get_string('enrolname', "enrol_$module");
- $plugin = enrolment_factory::factory($module);
- if (method_exists($plugin, 'print_entry')) {
- $choices[$name] = $module;
- }
- }
- asort($choices);
- $choices = array_flip($choices);
- $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices);
- $temp->add(new admin_setting_configselect('moodlecourse/enrol', get_string('enrolmentplugins'), get_string('coursehelpenrolmentplugins'), key($choices),$choices));
- $choices = array(0 => get_string('no'), 1 => get_string('yes'), 2 => get_string('enroldate'));
- $temp->add(new admin_setting_configselect('moodlecourse/enrollable', get_string('enrollable'), get_string('coursehelpenrollable'), 1,$choices));
- $periodmenu=array();
- $periodmenu[0] = get_string('unlimited');
- for ($i=1; $i<=365; $i++) {
- $seconds = $i * 86400;
- $periodmenu[$seconds] = get_string('numdays', '', $i);
- }
- $temp->add(new admin_setting_configselect('moodlecourse/enrolperiod', get_string('enrolperiod'), '', 0,$periodmenu));
-
- ///
- $temp->add(new admin_setting_heading('expirynotifyhdr', get_string('expirynotify'), ''));
- $temp->add(new admin_setting_configselect('moodlecourse/expirynotify', get_string('notify'), get_string('coursehelpnotify'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
- $temp->add(new admin_setting_configselect('moodlecourse/notifystudents', get_string('expirynotifystudents'), get_string('coursehelpexpirynotifystudents'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
- $thresholdmenu=array();
- for ($i=1; $i<=30; $i++) {
- $seconds = $i * 86400;
- $thresholdmenu[$seconds] = get_string('numdays', '', $i);
- }
- $temp->add(new admin_setting_configselect('moodlecourse/expirythreshold', get_string('expirythreshold'), get_string('coursehelpexpirythreshold'), 10 * 86400,$thresholdmenu));
-
-
$temp->add(new admin_setting_heading('groups', get_string('groups', 'group'), ''));
$choices = array();
$choices[NOGROUPS] = get_string('groupsnone', 'group');
@@ -95,12 +54,6 @@
$choices['0'] = get_string('courseavailablenot');
$choices['1'] = get_string('courseavailable');
$temp->add(new admin_setting_configselect('moodlecourse/visible', get_string('visible'), '', 1,$choices));
- $temp->add(new admin_setting_configpasswordunmask('moodlecourse/enrolpassword', get_string('enrolmentkey'), get_string('coursehelpenrolmentkey'),''));
- $choices = array();
- $choices['0'] = get_string('guestsno');
- $choices['1'] = get_string('guestsyes');
- $choices['2'] = get_string('guestskey');
- $temp->add(new admin_setting_configselect('moodlecourse/guest', get_string('opentoguests'), '', 0,$choices));
$temp->add(new admin_setting_heading('language', get_string('language'), ''));
@@ -133,7 +86,6 @@
$temp = new admin_settingpage('backups', get_string('backups','admin'), 'moodle/backup:backupcourse');
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_modules', get_string('includemodules'), get_string('backupincludemoduleshelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_withuserdata', get_string('includemoduleuserdata'), get_string('backupincludemoduleuserdatahelp'), 0));
- $temp->add(new admin_setting_configcheckbox('backup/backup_sche_metacourse', get_string('metacourse'), get_string('backupmetacoursehelp'), 0));
$temp->add(new admin_setting_configselect('backup/backup_sche_users', get_string('users'), get_string('backupusershelp'),
0, array(0 => get_string('all'), 1 => get_string('course'))));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_logs', get_string('logs'), get_string('backuplogshelp'), 0));
Index: pluginfile.php
===================================================================
--- pluginfile.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ pluginfile.php (revision )
@@ -220,7 +220,7 @@
if ($USER->id !== $userid) {
$usercontext = get_context_instance(CONTEXT_USER, $userid);
// The browsing user is not the current user
- if (!has_coursemanager_role($userid) && !has_capability('moodle/user:viewdetails', $usercontext)) {
+ if (!has_coursecontact_role($userid) && !has_capability('moodle/user:viewdetails', $usercontext)) {
send_file_not_found();
}
@@ -228,7 +228,7 @@
if (has_capability('moodle/user:viewdetails', $usercontext)) {
$canview = true;
} else {
- $courses = get_my_courses($USER->id);
+ $courses = enrol_get_my_courses();
}
while (!$canview && count($courses) > 0) {
@@ -423,7 +423,7 @@
print_error('noguest');
}
- if (!has_coursemanager_role($userid) and !has_capability('moodle/user:viewdetails', $usercontext)) {
+ if (!has_coursecontact_role($userid) and !has_capability('moodle/user:viewdetails', $usercontext)) {
print_error('usernotavailable');
}
if (!has_capability('moodle/user:viewdetails', $context) &&
Index: enrol/cohort/lang/en/enrol_cohort.php
===================================================================
--- enrol/cohort/lang/en/enrol_cohort.php (revision )
+++ enrol/cohort/lang/en/enrol_cohort.php (revision )
@@ -0,0 +1,26 @@
+.
+
+/**
+ * Strings for component 'enrol_cohort', language 'en', branch 'MOODLE_20_STABLE'
+ *
+ * @package enrol_cohort
+ * @copyright 2010 onwards Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['pluginname'] = 'Cohort synchronisation';
Index: search/querylib.php
===================================================================
--- search/querylib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ search/querylib.php (revision )
@@ -398,7 +398,7 @@
}
// first check course compatibility against user : enrolled users to that course can see.
- $myCourses = get_my_courses($user->id);
+ $myCourses = enrol_get_users_courses($user->id, true);
$unenroled = !in_array($course_id, array_keys($myCourses));
// if guests are allowed, logged guest can see
Index: admin/cron.php
===================================================================
--- admin/cron.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ admin/cron.php (revision )
@@ -205,34 +205,6 @@
}
mtrace('Finished admin reports');
- mtrace('Removing expired enrolments ...', ''); // See MDL-8785
- $timenow = time();
- $somefound = false;
- // The preferred way saves memory, datablib
- // find courses where limited enrolment is enabled
- $sql = "SELECT ra.roleid, ra.userid, ra.contextid
- FROM {course} c
- JOIN {context} cx ON cx.instanceid = c.id
- JOIN {role_assignments} ra ON ra.contextid = cx.id
- WHERE cx.contextlevel = '".CONTEXT_COURSE."'
- AND ra.timeend > 0
- AND ra.timeend < ?
- AND c.enrolperiod > 0";
- if ($rs = $DB->get_recordset_sql($sql, array($timenow))) {
- foreach ($rs as $oldenrolment) {
- role_unassign($oldenrolment->roleid, $oldenrolment->userid, 0, $oldenrolment->contextid);
- $somefound = true;
- }
- $rs->close();
- }
- if ($somefound) {
- mtrace('Done');
- } else {
- mtrace('none found');
- }
-
-
-
mtrace('Starting main gradebook job ...');
grade_cron();
mtrace('done.');
@@ -270,41 +242,9 @@
if ($random100 < 20) { // Approximately 20% of the time.
mtrace("Running clean-up tasks...");
- /// Unenrol users who haven't logged in for $CFG->longtimenosee
+ /// TODO: Unenrol users who haven't logged in for $CFG->longtimenosee
- if ($CFG->longtimenosee) { // value in days
- $cuttime = $timenow - ($CFG->longtimenosee * 3600 * 24);
- $rs = $DB->get_recordset_sql ("SELECT id, userid, courseid
- FROM {user_lastaccess}
- WHERE courseid != ".SITEID."
- AND timeaccess < ?", array($cuttime));
- foreach ($rs as $assign) {
- if ($context = get_context_instance(CONTEXT_COURSE, $assign->courseid)) {
- if (role_unassign(0, $assign->userid, 0, $context->id)) {
- mtrace("removing user $assign->userid from course $assign->courseid as they have not accessed the course for over $CFG->longtimenosee days");
- }
- }
- }
- $rs->close();
- /// Execute the same query again, looking for remaining records and deleting them
- /// if the user hasn't moodle/course:participate in the CONTEXT_COURSE context (orphan records)
- $rs = $DB->get_recordset_sql ("SELECT id, userid, courseid
- FROM {user_lastaccess}
- WHERE courseid != ".SITEID."
- AND timeaccess < ?", array($cuttime));
- foreach ($rs as $assign) {
- if ($context = get_context_instance(CONTEXT_COURSE, $assign->courseid)) {
- if (!is_enrolled($context, $assign->userid) and !is_viewing($context, $assign->userid)) {
- $DB->delete_records('user_lastaccess', array('userid'=>$assign->userid, 'courseid'=>$assign->courseid));
- mtrace("Deleted orphan user_lastaccess for user $assign->userid from course $assign->courseid");
- }
- }
- }
- $rs->close();
- }
- flush();
-
/// Delete users who haven't confirmed within required period
if (!empty($CFG->deleteunconfirmed)) {
@@ -370,9 +310,6 @@
}
flush();
- sync_metacourses();
- mtrace('Synchronised metacourses');
-
//
// generate new password emails for users
//
@@ -464,21 +401,16 @@
unset($authplugin);
}
-/// Run the enrolment cron, if any
- if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
- $plugins = array($CFG->enrol);
+ mtrace("Running enrol crons if required...");
+ $enrols = enrol_get_plugins(true);
+ foreach($enrols as $ename=>$enrol) {
+ if (!$enrol->is_cron_required()) {
+ continue;
- }
+ }
- require_once($CFG->dirroot .'/enrol/enrol.class.php');
- foreach ($plugins as $p) {
- $enrol = enrolment_factory::factory($p);
- if (method_exists($enrol, 'cron')) {
+ mtrace("Running cron for enrol_$ename...");
- $enrol->cron();
+ $enrol->cron();
+ $enrol->set_config('lastcron', time());
- }
+ }
- if (!empty($enrol->log)) {
- mtrace($enrol->log);
- }
- unset($enrol);
- }
if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {
require_once($CFG->dirroot.'/lib/statslib.php');
Index: enrol/manual/db/access.php
===================================================================
--- enrol/manual/db/access.php (revision )
+++ enrol/manual/db/access.php (revision )
@@ -0,0 +1,58 @@
+.
+
+/**
+ * Capabilities for manual enrolment plugin.
+ *
+ * @package enrol_manual
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+$capabilities = array(
+
+ 'enrol/manual:config' => array(
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'manager' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ )
+ ),
+
+ 'enrol/manual:manage' => array(
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'manager' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ )
+ ),
+
+ 'enrol/manual:unenrolself' => array(
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ )
+ ),
+
+);
+
Index: search/documents/resource_document.php
===================================================================
--- search/documents/resource_document.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ search/documents/resource_document.php (revision )
@@ -326,7 +326,7 @@
}
//check if user is registered in course or course is open to guests
- if (!$course->guest && !has_capability('moodle/course:participate', $course_context)) {
+ if (!is_enrolled($course_context) and !is_viewing($course_context)) { //TODO: guest course access is gone, this needs a different solution
return false;
}
Index: enrol/review.php
===================================================================
--- enrol/review.php (revision )
+++ enrol/review.php (revision )
@@ -0,0 +1,239 @@
+.
+
+/**
+ * Main course enrolment management UI.
+ *
+ * @package core
+ * @subpackage enrol
+ * @copyright 2010 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require('../config.php');
+
+$id = required_param('id', PARAM_INT); // course id
+$action = optional_param('action', '', PARAM_ACTION);
+$instanceid = optional_param('instance', 0, PARAM_INT);
+$confirm = optional_param('confirm', 0, PARAM_BOOL);
+$add = optional_param('add', '', PARAM_SAFEDIR); // name of enrol plugin to be added to course
+
+$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('moodle/course:enrolreview', $context);
+
+$canconfig = has_capability('moodle/course:enrolconfig', $context);
+
+$PAGE->set_url('/enrol/review.php', array('id'=>$course->id));
+
+$instances = enrol_get_instances($course->id, false);
+$plugins = enrol_get_plugins(false);
+
+if ($canconfig and $action and confirm_sesskey()) {
+ if (isset($instances[$instanceid]) and isset($plugins[$instances[$instanceid]->enrol])) {
+ if ($action === 'up') {
+ $order = array_keys($instances);
+ $order = array_flip($order);
+ $pos = $order[$instanceid];
+ if ($pos > 0) {
+ $switch = $pos - 1;
+ $resorted = array_values($instances);
+ $temp = $resorted[$pos];
+ $resorted[$pos] = $resorted[$switch];
+ $resorted[$switch] = $temp;
+ // now update db sortorder
+ foreach ($resorted as $sortorder=>$instance) {
+ if ($instance->sortorder != $sortorder) {
+ $instance->sortorder = $sortorder;
+ $DB->update_record('enrol', $instance);
+ }
+ }
+ }
+ redirect($PAGE->url);
+
+ } else if ($action === 'down') {
+ $order = array_keys($instances);
+ $order = array_flip($order);
+ $pos = $order[$instanceid];
+ if ($pos < count($instances) - 1) {
+ $switch = $pos + 1;
+ $resorted = array_values($instances);
+ $temp = $resorted[$pos];
+ $resorted[$pos] = $resorted[$switch];
+ $resorted[$switch] = $temp;
+ // now update db sortorder
+ foreach ($resorted as $sortorder=>$instance) {
+ if ($instance->sortorder != $sortorder) {
+ $instance->sortorder = $sortorder;
+ $DB->update_record('enrol', $instance);
+ }
+ }
+ }
+ redirect($PAGE->url);
+
+ } else if ($action === 'delete') {
+ $instance = $instances[$instanceid];
+ $plugin = $plugins[$instance->enrol];
+
+ if ($confirm) {
+ $plugin->delete_instance($instance);
+ redirect($PAGE->url);
+ }
+
+ echo $OUTPUT->header();
+ $yesurl = new moodle_url('/enrol/review.php', array('id'=>$course->id, 'action'=>'delete', 'instance'=>$instance->id, 'confirm'=>1,'sesskey'=>sesskey()));
+ $displayname = empty($instance->name) ? get_string('pluginname', 'enrol_'.$instance->enrol) : format_string($instance->name);
+ $users = $DB->count_records('course_participants', array('enrolid'=>$instance->id));
+ $message = get_string('deleteinstanceconfirm', 'enrol', array('name'=>$displayname, 'users'=>$users));
+ echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
+ echo $OUTPUT->footer();
+ die();
+
+ } else if ($action === 'disable') {
+ $instance = $instances[$instanceid];
+ if ($instance->status == ENROL_STATUS_ENABLED) {
+ $instance->status = ENROL_STATUS_DISABLED;
+ $DB->update_record('enrol', $instance);
+ redirect($PAGE->url);
+ }
+
+ } else if ($action === 'enable') {
+ $instance = $instances[$instanceid];
+ if ($instance->status == ENROL_STATUS_DISABLED) {
+ $instance->status = ENROL_STATUS_ENABLED;
+ $DB->update_record('enrol', $instance);
+ redirect($PAGE->url);
+ }
+ }
+ }
+ if ($action === 'add') {
+ $candidates = enrol_get_instance_candidates($course->id);
+
+ if (isset($plugins[$add]) and isset($candidates[$add])) {
+ $plugins[$add]->add_default_instance($course);
+ redirect($PAGE->url);
+ }
+ }
+
+}
+
+
+echo $OUTPUT->header();
+
+$currenttab = 'review';
+require('tabs.php');
+
+echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
+
+// display strings
+$strup = get_string('up');
+$strdown = get_string('down');
+$strdelete = get_string('delete');
+$strenable = get_string('enable');
+$strdisable = get_string('disable');
+
+$table = new html_table();
+if ($canconfig) {
+ $table->head = array(get_string('name'), get_string('users'), $strup.'/'.$strdown, get_string('edit'));
+ $table->align = array('left', 'center', 'center', 'center');
+} else {
+ $table->head = array(get_string('name'), get_string('users'));
+ $table->align = array('left', 'center');
+}
+$table->width = '100%';
+$table->data = array();
+
+// iterate through enrol plugins and add to the display table
+$updowncount = 1;
+$icount = count($instances);
+$url = new moodle_url('/enrol/review.php', array('sesskey'=>sesskey(), 'id'=>$course->id));
+foreach ($instances as $instance) {
+ if (!isset($plugins[$instance->enrol])) {
+ continue;
+ }
+ $plugin = $plugins[$instance->enrol];
+
+ $displayname = empty($instance->name) ? get_string('pluginname', 'enrol_'.$instance->enrol) : format_string($instance->name);
+ if (enrol_is_enabled($instance->enrol)) {
+ //TODO: why is dimmed_text not dimming text???
+ $displayname = html_writer::tag('span', $displayname, array('class'=>'dimmed_text'));
+ } else if ($instance->status != ENROL_STATUS_ENABLED) {
+ //TODO: why is dimmed_text not dimming text???
+ $displayname = html_writer::tag('span', $displayname, array('class'=>'dimmed_text'));
+ }
+
+ $users = $DB->count_records('course_participants', array('enrolid'=>$instance->id));
+
+ if ($canconfig) {
+ // up/down link
+ $updown = '';
+ if ($updowncount > 1) {
+ $aurl = new moodle_url($url, array('action'=>'up', 'instance'=>$instance->id));
+ $updown .= "pix_url('t/up') . "\" alt=\"$strup\" /> ";
+ } else {
+ $updown .= "pix_url('spacer.gif') . "\" class=\"icon\" alt=\"\" /> ";
+ }
+ if ($updowncount < $icount) {
+ $aurl = new moodle_url($url, array('action'=>'down', 'instance'=>$instance->id));
+ $updown .= "pix_url('t/down') . "\" alt=\"$strdown\" />";
+ } else {
+ $updown .= "pix_url('spacer.gif') . "\" class=\"icon\" alt=\"\" />";
+ }
+ ++$updowncount;
+
+ // edit links
+ $aurl = new moodle_url($url, array('action'=>'delete', 'instance'=>$instance->id));
+ $edit = "pix_url('t/delete') . "\" alt=\"$strdelete\" /> ";
+
+ if (enrol_is_enabled($instance->enrol)) {
+ if ($instance->status == ENROL_STATUS_ENABLED) {
+ $aurl = new moodle_url($url, array('action'=>'disable', 'instance'=>$instance->id));
+ $edit .= "pix_url('t/show') . "\" alt=\"$strdisable\" /> ";
+ } else if ($instance->status == ENROL_STATUS_DISABLED) {
+ $aurl = new moodle_url($url, array('action'=>'enable', 'instance'=>$instance->id));
+ $edit .= "pix_url('t/hide') . "\" alt=\"$strenable\" /> ";
+ } else {
+ // plugin specific state - do not mess with it!
+ $edit .= "pix_url('t/hide') . "\" alt=\"\" />";
+ }
+
+ }
+
+ // add a row to the table
+ $table->data[] = array($displayname, $users, $updown, $edit);
+
+ } else {
+ // add a row to the table
+ $table->data[] = array($displayname, $users);
+ }
+
+}
+echo html_writer::table($table);
+
+if ($canconfig) {
+ if ($candidates = enrol_get_instance_candidates($course->id)) {
+ $addurl = new moodle_url('/enrol/review.php', array('id'=>$course->id, 'action'=>'add', 'sesskey'=>sesskey()));
+ $select = new single_select($addurl, 'add', $candidates);
+ $select->set_label(get_string('addinstance', 'enrol'));
+ echo $OUTPUT->render($select);
+ }
+}
+
+echo $OUTPUT->box_end();
+
+echo $OUTPUT->footer();
Index: lib/externallib.php
===================================================================
--- lib/externallib.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lib/externallib.php (revision )
@@ -307,28 +307,10 @@
if ($context->contextlevel >= CONTEXT_COURSE) {
list($context, $course, $cm) = get_context_info_array($context->id);
- // must be enrolled or viewing
- if (!is_enrolled($context) and !is_viewing($context)) {
- throw new invalid_parameter_exception('Must be enrolled in course or be allowed to inspect it.');
+ require_login($course, false, $cm, false, true);
- }
+ }
- // make sure the course is actually visible
- if (!($course->visible && course_parent_visible($COURSE)) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
- throw new invalid_parameter_exception('Invalid course.');
- }
+ }
- // make sure the activity is actually visible
- if ($cm && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
- throw new invalid_parameter_exception('Invalid activity.');
- }
+}
- // verify group memebers
- if (!empty($CFG->enablegroupmembersonly) and $cm and $cm->groupmembersonly and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
- if (!groups_has_membership($cm)) {
- throw new invalid_parameter_exception('Must be member of at least one group.');
- }
- }
- //TODO: verify course completion
- }
- }
-}
/**
* Common ancestor of all parameter description classes
@@ -468,7 +450,7 @@
return $newtoken->token;
}
/**
- * Create and return a session linked token. Token to be used for html embedded client apps that want to communicate
+ * Create and return a session linked token. Token to be used for html embedded client apps that want to communicate
* with the Moodle server through web services. The token is linked to the current session for the current page request.
* It is expected this will be called in the script generating the html page that is embedding the client app and that the
* returned token will be somehow passed into the client app being embedded in the page.
Index: enrol/manual/enrol.html
===================================================================
--- enrol/manual/enrol.html (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ enrol/manual/enrol.html (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
@@ -1,47 +0,0 @@
-password != '' and !(isguestuser() and !empty($USER->enrolkey[$course->id]))) { // password
- echo $OUTPUT->box_start('generalbox centerpara');
- echo '
\n";
-
-echo $OUTPUT->footer();
-
Index: lib/db/access.php
===================================================================
--- lib/db/access.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ lib/db/access.php (revision )
@@ -551,19 +551,6 @@
)
),
- 'moodle/role:unassignself' => array(
-
- 'captype' => 'write',
- 'contextlevel' => CONTEXT_COURSE,
- 'legacy' => 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,
@@ -682,6 +669,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(
@@ -703,6 +691,32 @@
)
),
+ /* review course enrolments */
+ 'moodle/course:enrolreview' => array(
+
+ 'riskbitmask' => RISK_PERSONAL,
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW,
+ )
+ ),
+
+ /* config enrol instances */
+ 'moodle/course:enrolconfig' => array(
+
+ 'riskbitmask' => RISK_PERSONAL,
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW,
+ )
+ ),
+
'moodle/course:bulkmessaging' => array(
'riskbitmask' => RISK_SPAM,
@@ -774,18 +788,6 @@
)
),
- 'moodle/course:managemetacourse' => array(
-
- 'riskbitmask' => RISK_XSS | RISK_PERSONAL,
-
- 'captype' => 'write',
- 'contextlevel' => CONTEXT_COURSE,
- 'legacy' => 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 access 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: user/index.php
===================================================================
--- user/index.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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
@@ -194,7 +193,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) {
@@ -268,27 +267,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();
@@ -345,22 +325,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');
@@ -398,7 +362,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();
@@ -423,17 +387,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');
@@ -490,17 +444,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 '
';
@@ -705,7 +648,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)) {
@@ -735,14 +678,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
@@ -789,13 +724,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'];
@@ -809,12 +737,7 @@
} else {
$rastring .= $rolename;
}
- if ($showenrolplugin) {
- $rastring .= ' ';
- } else {
- $rastring .= ' ('. $ra['enrolplugin'] .') ';
- }
+ }
- }
$data[] = $rastring;
if ($groupmode != 0) {
// htmlescape with s() and implode the array
@@ -846,11 +769,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'));
@@ -940,7 +858,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
@@ -974,11 +891,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;
@@ -1002,8 +914,7 @@
'ctxlevel' => $rec->ctxlevel,
'ctxinstanceid' => $rec->ctxinstanceid,
'ccname' => $rec->ccname,
- 'roleid' => $rec->roleid,
- 'enrolplugin' => $rec->enrolplugin);
+ 'roleid' => $rec->roleid);
}
}
Index: admin/settings/frontpage.php
===================================================================
--- admin/settings/frontpage.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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: lang/en/error.php
===================================================================
--- lang/en/error.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ course/importstudents.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
@@ -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: course/user.php
===================================================================
--- course/user.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ course/user.php (revision )
@@ -54,7 +54,7 @@
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
require_login();
-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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ 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 de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
+++ user/groupextendenrol.php (revision de4bf1ff9d6a12d5f77c47362c2de3b6496f026a)
@@ -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 '