Index: lib/db/install.xml
===================================================================
RCS file: /globalcvs/ou-moodle/lib/db/install.xml,v
retrieving revision 1.15
diff -u -r1.15 install.xml
--- lib/db/install.xml 5 Nov 2007 08:19:05 -0000 1.15
+++ lib/db/install.xml 4 Feb 2008 15:19:27 -0000
@@ -819,7 +819,8 @@
-
+
+
Index: lib/db/upgrade.php
===================================================================
RCS file: /globalcvs/ou-moodle/lib/db/upgrade.php,v
retrieving revision 1.15
diff -u -r1.15 upgrade.php
--- lib/db/upgrade.php 5 Nov 2007 08:19:05 -0000 1.15
+++ lib/db/upgrade.php 4 Feb 2008 15:19:27 -0000
@@ -2675,6 +2675,23 @@
}
}
+ if ($result && $oldversion < 20071015xx.xx) {
+
+ /// 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, 2007101501);
+ }
return $result;
}
Index: admin/cron.php
===================================================================
RCS file: /globalcvs/ou-moodle/admin/cron.php,v
retrieving revision 1.22.2.4
diff -u -r1.22.2.4 cron.php
--- admin/cron.php 15 Jan 2008 15:27:25 -0000 1.22.2.4
+++ admin/cron.php 4 Feb 2008 15:19:27 -0000
@@ -231,6 +231,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.');
Index: lib/accesslib.php
===================================================================
RCS file: /globalcvs/ou-moodle/lib/accesslib.php,v
retrieving revision 1.57.2.4
diff -u -r1.57.2.4 accesslib.php
--- lib/accesslib.php 13 Dec 2007 19:22:26 -0000 1.57.2.4
+++ lib/accesslib.php 4 Feb 2008 15:19:27 -0000
@@ -458,6 +458,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";
@@ -920,7 +921,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
@@ -1171,6 +1172,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);
//
@@ -1270,6 +1272,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";
@@ -1342,6 +1345,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);
@@ -2883,6 +2887,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;
@@ -2897,6 +2906,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;
@@ -4092,6 +4106,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;
static $lastquery,$lastresult;
@@ -4535,6 +4550,35 @@
WHERE ra.roleid = r.id
AND ra.contextid = $context->id");
+}
+
+/**
+ * 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
}
/**
Index: lang/en_utf8/moodle.php
===================================================================
RCS file: /globalcvs/ou-moodle/lang/en_utf8/moodle.php,v
retrieving revision 1.35.2.1
diff -u -r1.35.2.1 moodle.php
--- lang/en_utf8/moodle.php 10 Dec 2007 10:38:03 -0000 1.35.2.1
+++ lang/en_utf8/moodle.php 4 Feb 2008 15:19:27 -0000
@@ -288,6 +288,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/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: 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 = 2007101509; // YYYYMMDD = date
+ $version = 20071015xx.xx; // YYYYMMDD = date
// XY = increments within a single day
$release = '2.0 dev'; // Human-friendly version name