Index: lib/moodlelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v
retrieving revision 1.1043
diff -u -r1.1043 moodlelib.php
--- lib/moodlelib.php 8 May 2008 03:50:15 -0000 1.1043
+++ lib/moodlelib.php 8 May 2008 15:26:19 -0000
@@ -1981,9 +1981,17 @@
}
}
- /// Non-guests who don't currently have access, check if they can be allowed in as a guest
+ /// Non-guests who don't currently have access...
if ($USER->username != 'guest' and !has_capability('moodle/course:view', $COURSE->context)) {
+
+ /// Is it because they have a role which hasn't started yet?
+ if($inactive=get_inactive_role_on_context($COURSE->context->id)) {
+ /// Display info about the start date and stop
+ notice(get_string('courserolenotstarted','',userdate($inactive->timestart)), $CFG->wwwroot .'/');
+ }
+
+ /// Check if they can be allowed in as a guest
if ($COURSE->guest == 1) {
// Temporarily assign them guest role for this context, if it fails later user is asked to enrol
$USER->access = load_temp_role($COURSE->context, $CFG->guestroleid, $USER->access);
Index: lib/accesslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v
retrieving revision 1.482
diff -u -r1.482 accesslib.php
--- lib/accesslib.php 29 Apr 2008 06:53:19 -0000 1.482
+++ lib/accesslib.php 8 May 2008 15:26:18 -0000
@@ -525,6 +525,7 @@
ON ra.roleid=rc.roleid AND ra.contextid=ctx.id
WHERE ctx.contextlevel=10
AND ra.userid={$userid}
+ AND ra.active=1
AND rc.capability IN ('moodle/site:config', 'moodle/legacy:admin', 'moodle/site:doanything')
GROUP BY rc.capability
HAVING SUM(rc.permission) > 0";
@@ -1016,7 +1017,7 @@
JOIN {$CFG->prefix}context ctx
ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
LEFT OUTER JOIN {$CFG->prefix}role_assignments ra
- ON (ra.contextid=ctx.id AND ra.userid=$userid)
+ ON (ra.contextid=ctx.id AND ra.userid=$userid AND ra.active=1)
LEFT OUTER JOIN {$CFG->prefix}role_capabilities rc
ON (rc.contextid=ctx.id AND (rc.capability='$cap' $capany))
WHERE ra.id IS NOT NULL
@@ -1095,6 +1096,7 @@
LEFT OUTER JOIN {$CFG->prefix}role_capabilities rc
ON (rc.roleid=ra.roleid AND rc.contextid=ra.contextid)
WHERE ra.userid = $userid AND ctx.contextlevel <= ".CONTEXT_COURSE."
+ AND ra.active=1
ORDER BY ctx.depth, ctx.path";
$rs = get_recordset_sql($sql);
//
@@ -1194,6 +1196,7 @@
JOIN {$CFG->prefix}role_capabilities rco
ON (rco.roleid=ra.roleid AND rco.contextid=sctx.id)
WHERE ra.userid = $userid
+ AND ra.active = 1
AND sctx.contextlevel <= ".CONTEXT_COURSE."
ORDER BY sctx.depth, sctx.path, ra.roleid";
@@ -1266,6 +1269,7 @@
JOIN {$CFG->prefix}context ctx
ON ra.contextid=ctx.id
WHERE ra.userid = $userid
+ AND ra.active = 1
AND (ctx.path = '{$context->path}' OR ctx.path LIKE '{$context->path}/%')
ORDER BY ctx.depth, ctx.path";
$rs = get_recordset_sql($sql);
@@ -2805,6 +2809,11 @@
/// by repeating queries with the same exact parameters in a 100 secs time window
$newra->timestart = round($timestart, -2);
$newra->timeend = $timeend;
+ /// If timestart is in the future then the role must be set to not be active
+ /// (otherwise, database defaults to active=1); will be activated later in cron
+ if($timestart > time()) {
+ $newra->active = 0;
+ }
$newra->timemodified = $timemodified;
$newra->modifierid = empty($USER->id) ? 0 : $USER->id;
@@ -2819,6 +2828,11 @@
/// by repeating queries with the same exact parameters in a 100 secs time window
$newra->timestart = round($timestart, -2);
$newra->timeend = $timeend;
+ /// If timestart is in the future then the role must be set to not be active
+ /// (otherwise, database defaults to active=1); will be activated later in cron
+ if($timestart > time()) {
+ $newra->active = 0;
+ }
$newra->timemodified = $timemodified;
$newra->modifierid = empty($USER->id) ? 0 : $USER->id;
@@ -3975,6 +3989,7 @@
WHERE ra.userid = '.$userid.'
AND ra.roleid = r.id
AND ra.contextid = c.id
+ AND ra.active = 1
AND '.$contexts . $hiddensql .'
ORDER BY '.$order)) {
$return = array();
@@ -4960,6 +4975,35 @@
}
/**
+ * If the user has any role on the specified (exact) context which is not
+ * yet active, then we return the timestart of the role assignment.
+ * - If they have two such roles then we return the earliest timestart.
+ * - Note that they may have other active roles. This function is intended
+ * to be used after a has_capability fails, so that information can be
+ * displayed to the user about when they might have access again.
+ * @param int $contextid ID of context
+ * @param int $userid User ID, leave out for current user
+ * @return False if none, or an object containing fields from role_assignments
+ * (including timestart).
+ */
+function get_inactive_role_on_context($contextid,$userid=0) {
+ global $CFG,$USER;
+ if(!$userid) {
+ $userid=$USER->id;
+ }
+ $rs=get_recordset_sql("SELECT ra.*
+ FROM {$CFG->prefix}role_assignments ra
+ WHERE ra.userid=$userid
+ AND ra.contextid=$contextid
+ AND ra.active=0
+ AND ra.timestart<>0
+ ORDER BY ra.timestart");
+ $firstresult=rs_fetch_next_record($rs);
+ rs_close($rs);
+ return $firstresult; // False if no records, or the first record
+}
+
+/**
* Switches the current user to another role for the current session and only
* in the given context.
*
Index: version.php
===================================================================
RCS file: /cvsroot/moodle/moodle/version.php,v
retrieving revision 1.640
diff -u -r1.640 version.php
--- version.php 8 May 2008 01:53:35 -0000 1.640
+++ version.php 8 May 2008 15:26:16 -0000
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2008050700; // YYYYMMDD = date of the last version bump
+ $version = 2008050800; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20080508)'; // Human-friendly version name
Index: lang/en_utf8/moodle.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v
retrieving revision 1.180
diff -u -r1.180 moodle.php
--- lang/en_utf8/moodle.php 20 Apr 2008 01:18:44 -0000 1.180
+++ lang/en_utf8/moodle.php 8 May 2008 15:26:17 -0000
@@ -292,6 +292,7 @@
$string['courserequestreason'] = 'Reasons for wanting this course';
$string['courserequestsuccess'] = 'Successfully saved your course request. Expect an email within a few days with the outcome';
$string['courserestore'] = 'Course restore';
+$string['courserolenotstarted'] = 'You don\'t yet have access to this course. Your access should be enabled shortly after $a - please try again then.';
$string['courses'] = 'Courses';
$string['coursescategory'] = 'Courses in the same category';
$string['coursespending'] = 'Courses pending approval';
Index: lib/db/upgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/upgrade.php,v
retrieving revision 1.194
diff -u -r1.194 upgrade.php
--- lib/db/upgrade.php 7 May 2008 13:34:55 -0000 1.194
+++ lib/db/upgrade.php 8 May 2008 15:26:20 -0000
@@ -68,6 +68,20 @@
upgrade_main_savepoint($result, 2008050700);
}
+ if ($result && $oldversion < 2008050800) {
+
+ /// Define field active to be added to role_assignments
+ $table = new XMLDBTable('role_assignments');
+ $field = new XMLDBField('active');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'sortorder');
+
+ /// Launch add field active
+ $result = $result && add_field($table, $field);
+
+ /// Main savepoint reached
+ upgrade_main_savepoint($result, 2008050800);
+ }
+
return $result;
}
Index: lib/db/install.xml
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/install.xml,v
retrieving revision 1.147
diff -u -r1.147 install.xml
--- lib/db/install.xml 7 Mar 2008 13:23:38 -0000 1.147
+++ lib/db/install.xml 8 May 2008 15:26:20 -0000
@@ -820,7 +820,8 @@
-
+
+
Index: admin/cron.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/cron.php,v
retrieving revision 1.138
diff -u -r1.138 cron.php
--- admin/cron.php 1 May 2008 05:49:35 -0000 1.138
+++ admin/cron.php 8 May 2008 15:26:16 -0000
@@ -218,8 +218,10 @@
mtrace('none found');
}
-
-
+ mtrace('Activating any enrolments with start times ...');
+ execute_sql("UPDATE {$CFG->prefix}role_assignments SET active=1 WHERE active=0 AND timestart<".time(),false);
+ mtrace('done.');
+
mtrace('Starting main gradebook job ...');
grade_cron();
mtrace('done.');