Index: lib/moodlelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v
retrieving revision 1.991
diff -u -r1.991 moodlelib.php
--- lib/moodlelib.php 26 Jan 2008 17:00:03 -0000 1.991
+++ lib/moodlelib.php 30 Jan 2008 17:51:39 -0000
@@ -1912,9 +1912,16 @@
}
}
- /// 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.464
diff -u -r1.464 accesslib.php
--- lib/accesslib.php 25 Jan 2008 00:53:01 -0000 1.464
+++ lib/accesslib.php 30 Jan 2008 17:51:38 -0000
@@ -501,6 +501,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";
@@ -992,7 +993,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
@@ -1247,6 +1248,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);
//
@@ -1346,6 +1348,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";
@@ -1418,6 +1421,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);
@@ -2908,6 +2912,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;
@@ -2922,6 +2931,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;
@@ -4070,6 +4084,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);
}
@@ -4994,6 +5009,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.575
diff -u -r1.575 version.php
--- version.php 29 Jan 2008 05:54:42 -0000 1.575
+++ version.php 30 Jan 2008 17:51:36 -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 = 2007101508; // YYYYMMDD = date
+ $version = 2008013000; // YYYYMMDD = date
// XY = increments within a single day
$release = '2.0 dev'; // Human-friendly version name
Index: lang/en_utf8/moodle.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v
retrieving revision 1.167
diff -u -r1.167 moodle.php
--- lang/en_utf8/moodle.php 30 Jan 2008 16:34:04 -0000 1.167
+++ lang/en_utf8/moodle.php 30 Jan 2008 17:51:37 -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.175
diff -u -r1.175 upgrade.php
--- lib/db/upgrade.php 29 Jan 2008 05:54:42 -0000 1.175
+++ lib/db/upgrade.php 30 Jan 2008 17:51:40 -0000
@@ -2694,6 +2694,19 @@
upgrade_main_savepoint($result, 2007101508);
}
+ if ($result && $oldversion < 2008013000) {
+
+ /// 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, 2008013000);
+ }
return $result;
}
Index: lib/db/install.xml
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/install.xml,v
retrieving revision 1.137
diff -u -r1.137 install.xml
--- lib/db/install.xml 15 Dec 2007 00:49:05 -0000 1.137
+++ lib/db/install.xml 30 Jan 2008 17:51:40 -0000
@@ -819,7 +819,8 @@
-
+
+
Index: admin/cron.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/cron.php,v
retrieving revision 1.131
diff -u -r1.131 cron.php
--- admin/cron.php 13 Jan 2008 18:46:55 -0000 1.131
+++ admin/cron.php 30 Jan 2008 17:51:36 -0000
@@ -189,6 +189,10 @@
}
+ 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.');