Index: lang/en_utf8/moodle.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v retrieving revision 1.141.2.44 diff -u -r1.141.2.44 moodle.php --- lang/en_utf8/moodle.php 8 Oct 2008 09:21:14 -0000 1.141.2.44 +++ lang/en_utf8/moodle.php 5 Nov 2008 10:41:40 -0000 @@ -296,6 +296,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['coursesmovedout'] = 'Courses moved out from $a'; Index: admin/cron.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/cron.php,v retrieving revision 1.126.2.14 diff -u -r1.126.2.14 cron.php --- admin/cron.php 13 Oct 2008 21:45:24 -0000 1.126.2.14 +++ admin/cron.php 5 Nov 2008 10:41:39 -0000 @@ -219,6 +219,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/db/upgrade.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/db/upgrade.php,v retrieving revision 1.154.2.42 diff -u -r1.154.2.42 upgrade.php --- lib/db/upgrade.php 13 Oct 2008 21:45:24 -0000 1.154.2.42 +++ lib/db/upgrade.php 5 Nov 2008 10:41:50 -0000 @@ -3073,6 +3073,20 @@ } } + if ($result && $oldversion < 2007101531) { + + /// 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, 2007101530); + } + return $result; } Index: lib/db/install.xml =================================================================== RCS file: /cvsroot/moodle/moodle/lib/db/install.xml,v retrieving revision 1.135.2.15 diff -u -r1.135.2.15 install.xml --- lib/db/install.xml 10 Oct 2008 17:48:19 -0000 1.135.2.15 +++ lib/db/install.xml 5 Nov 2008 10:41:48 -0000 @@ -820,7 +820,8 @@ - + + Index: lib/accesslib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v retrieving revision 1.421.2.79 diff -u -r1.421.2.79 accesslib.php --- lib/accesslib.php 20 Oct 2008 13:43:13 -0000 1.421.2.79 +++ lib/accesslib.php 5 Nov 2008 10:41:43 -0000 @@ -526,6 +526,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"; @@ -1023,7 +1024,7 @@ JOIN {$CFG->prefix}context ctx ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") 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) UNION SELECT c.id, ctx.id AS ctxid, ctx.path AS ctxpath, @@ -1136,6 +1137,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, ra.roleid"; $rs = get_recordset_sql($sql); // @@ -1235,6 +1237,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"; @@ -1308,6 +1311,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, ra.roleid"; $rs = get_recordset_sql($sql); @@ -2852,6 +2856,11 @@ /// by repeating queries with the same exact parameters in a 100 secs time window $ra->timestart = round($timestart, -2); $ra->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()) { + $ra->active = 0; + } $ra->timemodified = $timemodified; $ra->modifierid = empty($USER->id) ? 0 : $USER->id; @@ -2867,6 +2876,11 @@ /// by repeating queries with the same exact parameters in a 100 secs time window $ra->timestart = round($timestart, -2); $ra->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; + } $ra->timemodified = $timemodified; $ra->modifierid = empty($USER->id) ? 0 : $USER->id; @@ -4043,6 +4057,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(); @@ -5033,6 +5048,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: lib/moodlelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v retrieving revision 1.960.2.103 diff -u -r1.960.2.103 moodlelib.php --- lib/moodlelib.php 3 Nov 2008 05:21:45 -0000 1.960.2.103 +++ lib/moodlelib.php 5 Nov 2008 10:41:46 -0000 @@ -1992,9 +1992,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.563.2.297 diff -u -r1.563.2.297 version.php --- version.php 4 Nov 2008 02:07:28 -0000 1.563.2.297 +++ version.php 5 Nov 2008 10:41:39 -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 = 2007101530; // YYYYMMDD = date of the 1.9 branch (don't change) + $version = 2007101531; // YYYYMMDD = date of the 1.9 branch (don't change) // X = release number 1.9.[0,1,2,3...] // Y.YY = micro-increments between releases