+ enrol_autocreate_category, "");
+ if (isset($err["enrol_autocreate_category"])) formerr($err["enrol_autocreate_category"]);
+ ?>
+
+
+
+
+
+
+
enrol_db_template:
@@ -214,9 +257,243 @@
-
-
-
+
enrol_coursetable:
+
+
+
+
+
+
+
+
+
+
enrol_coursefullname:
+
+
+
+
+
+
+
+
+
+
enrol_courseshortname:
+
+
+
+
+
+
+
+
+
+
enrol_courseid:
+
+
+
+
+
+
+
+
+
+
enrol_coursesummary:
+
+
+
+
+
+
+
+
+
+
enrol_coursecategory:
+
+
+
+
+
+
+
+
+
+
enrol_category_separator:
+
+
+
+
+
+
+
+
+
+
enrol_coursestartdate:
+
+
+
+
+
+
+
+
+
+
enrol_courseformat:
+
+
+
+
+
+
+
+
+
+
enrol_coursetheme:
+
+
+
+
+
+
+
+
+
+
enrol_coursepassword:
+
+
+
+
+
+
+
+
+
+
enrol_courseguest:
+
+
+
+
+
+
+
+
+
+
enrol_coursenumsections:
+
+
+
+
+
+
+
+
+
+
enrol_courseidnumber:
+
+
+
+
+
+
+
+
+
+
enrol_coursecost:
+
+
+
+
+
+
+
+
+
+
enrol_coursenewsitems:
+
+
+
+
+
+
+
+
+
+
enrol_courseshowgrades:
+
+
+
+
+
+
+
+
+
+
enrol_coursegroupmode:
+
+
+
+
+
+
+
+
+
+
enrol_coursegroupmodefoce:
+
+
+
+
+
+
+
+
+
+
enrol_coursevisible:
+
+
+
+
+
+
+
+
+
+
enrol_courseenrollable:
+
+
+
+
+
+
+
+
+
+
enrol_coursetemplate:
+
+
+
+
+
+
+
+
+
+
enrol_restore_coursetemplate:
+
+ enrol_restore_coursetemplate, ""); ?>
+
+
+
+
+
+
+
+
enrol_restore_usetemplate:
+
+ enrol_restore_usetemplate, ""); ?>
+
+
+
+
--- enrol/database/enrol.php 2008-09-10 13:38:36.000000000 -0700
+++ enrol/database/enrol.php 2009-02-04 11:12:51.000000000 -0800
@@ -6,6 +6,31 @@
var $log;
+ /**
+ * Courses with enrollments that
+ * have been processed during the
+ * sync_enrolments() method
+ *
+ * @var array
+ **/
+ var $processed = array();
+
+ /**
+ * Backup files created
+ *
+ * @var array
+ **/
+ var $backupfiles = array();
+
+/**
+ * Run any cleanup routines
+ *
+ * @return void
+ **/
+function __destruct() {
+ $this->delete_backup_files();
+}
+
/*
* For the given user, let's go out and look in an external database
* for an authoritative list of enrolments, and then adjust the
@@ -61,8 +86,10 @@
error_log('[ENROL_DB] Using config default for roles: '.$role->shortname);
}*/
- if ($rs = $enroldb->Execute("SELECT {$CFG->enrol_remotecoursefield} as enrolremotecoursefield
- FROM {$CFG->enrol_dbtable}
+ if ($rs = $enroldb->Execute("SELECT {$CFG->enrol_remotecoursefield} as enrolremotecoursefield".
+ (!empty($CFG->enrol_db_remotetimestartfield) ? ", $CFG->enrol_db_remotetimestartfield as timestart" : '').
+ (!empty($CFG->enrol_db_remotetimeendfield) ? ", $CFG->enrol_db_remotetimeendfield as timeend" : '').
+ " FROM {$CFG->enrol_dbtable}
WHERE {$CFG->enrol_remoteuserfield} = " . $useridfield .
(isset($remote_role_name, $remote_role_value) ? ' AND '.$remote_role_name.' = '.$remote_role_value : ''))) {
@@ -82,10 +109,21 @@
if (!$rs->EOF) { // We found some courses
//$count = 0;
- $courselist = array();
+ $courselist = $enroltimes = array();
while ($fields_obj = rs_fetch_next_record($rs)) { // Make a nice little array of courses to process
$fields_obj = (object)array_change_key_case((array)$fields_obj , CASE_LOWER);
$courselist[] = $fields_obj->enrolremotecoursefield;
+
+ if (isset($fields_obj->timestart)) {
+ $enroltimes[$fields_obj->enrolremotecoursefield]['timestart'] = $fields_obj->timestart;
+ } else {
+ $enroltimes[$fields_obj->enrolremotecoursefield]['timestart'] = 0;
+ }
+ if (isset($fields_obj->timeend)) {
+ $enroltimes[$fields_obj->enrolremotecoursefield]['timeend'] = $fields_obj->timeend;
+ } else {
+ $enroltimes[$fields_obj->enrolremotecoursefield]['timeend'] = 0;
+ }
//$count++;
}
rs_close($rs);
@@ -95,6 +133,12 @@
foreach ($courselist as $coursefield) { /// Check the list of courses against existing
$course = get_record('course', $CFG->enrol_localcoursefield, $coursefield);
if (!is_object($course)) {
+ if (!empty($CFG->enrol_restore_coursetemplate) and !empty($CFG->enrol_coursetemplate)) {
+ if (debugging('',DEBUG_ALL)) {
+ error_log( "Course $coursefield does not exist and restore is enabled, but not allowed on login, skipping") ;
+ }
+ continue; // next foreach course
+ }
if (empty($CFG->enrol_db_autocreate)) { // autocreation not allowed
if (debugging('',DEBUG_ALL)) {
error_log( "Course $coursefield does not exist, skipping") ;
@@ -102,16 +146,17 @@
continue; // next foreach course
}
// ok, now then let's create it!
- // prepare any course properties we actually have
- $course = new StdClass;
- $course->{$CFG->enrol_localcoursefield} = $coursefield;
- $course->fullname = $coursefield;
- $course->shortname = $coursefield;
- if (!($newcourseid = $this->create_course($course, true)
- and $course = get_record( 'course', 'id', $newcourseid))) {
- error_log( "Creating course $coursefield failed");
+ error_log("Creating Course $coursefield...");
+ if ($courseid = $this->create_course($enroldb, $coursefield, true)
+ and $course = get_record( 'course', 'id', $courseid)) {
+ // we are skipping fix_course_sortorder()
+ error_log("created.");
+ } else {
+ error_log("failed.");
continue; // nothing left to do...
}
+ } else if (!empty($CFG->enrol_db_autoupdate)) {
+ $this->update_course($enroldb, $course, $coursefield);
}
// if the course is hidden and we don't want to enrol in hidden courses
@@ -132,20 +177,37 @@
continue;
}
+ $times = $enroltimes[$coursefield];
+
// Search the role assignments to see if this user
// already has this role in this context. If it is, we
// skip to the next course.
foreach($existing as $key => $role_assignment) {
if ($role_assignment->roleid == $role->id
&& $role_assignment->contextid == $context->id) {
+
unset($existing[$key]);
- //error_log('[ENROL_DB] User is already enroled in course '.$course->idnumber);
- continue 2;
+
+ if (!$CFG->enrol_db_disableunenrol and $times['timeend'] != 0 and $times['timeend'] < time()) {
+ // Timeend expired, unenrol
+ role_unassign($role->id, $user->id, 0, $context->id);
+ continue 2;
+ }
+ if (round($times['timestart'], -2) == $role_assignment->timestart and $times['timeend'] == $role_assignment->timeend) {
+ // No updates needed, skip out of this one
+ //error_log('[ENROL_DB] User is already enroled in course '.$course->idnumber);
+ continue 2;
+ } else {
+ // Perform an update by performing the role_assign below
+ break;
+ }
}
}
//error_log('[ENROL_DB] Enrolling user in course '.$course->idnumber);
- role_assign($role->id, $user->id, 0, $context->id, 0, 0, 0, 'database');
+ if ($times['timeend'] == 0 or $times['timeend'] > time()) {
+ role_assign($role->id, $user->id, 0, $context->id, $times['timestart'], $times['timeend'], 0, 'database');
+ }
}
} // We've processed all external courses found
@@ -157,7 +219,7 @@
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);
- }
+ }
}
}
} else {
@@ -240,18 +302,24 @@
}
continue; // next foreach course
}
+ // Add to list - don't care if it fails
+ $this->processed[$extcourse] = $extcourse;
+
// ok, now then let's create it!
- // prepare any course properties we actually have
- $course = new StdClass;
- $course->{$CFG->enrol_localcoursefield} = $extcourse;
- $course->fullname = $extcourse;
- $course->shortname = $extcourse;
- if (!($newcourseid = $this->create_course($course, true)
- and $course = get_record( 'course', 'id', $newcourseid))) {
- error_log( "Creating course $extcourse failed");
+ error_log("Creating Course $extcourse...");
+ if ($courseid = $this->create_course($enroldb, $extcourse, true, true)
+ and $course = get_record( 'course', 'id', $courseid)) {
+ // we are skipping fix_course_sortorder()
+ print "created\n";
+ } else {
+ print "failed\n";
continue; // nothing left to do...
}
+ } else if (!empty($CFG->enrol_db_autoupdate)) {
+ $this->update_course($enroldb, $course, $extcourse);
+ // Course updated, add to list
+ $this->processed[$extcourse] = $extcourse;
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
@@ -265,7 +333,9 @@
// get a list of the student ids the are enrolled
// in the external db -- hopefully it'll fit in memory...
$extenrolments = array();
- $sql = "SELECT {$CFG->enrol_remoteuserfield} " .
+ $sql = "SELECT {$CFG->enrol_remoteuserfield}" .
+ (!empty($CFG->enrol_db_remotetimestartfield) ? ", $CFG->enrol_db_remotetimestartfield" : '').
+ (!empty($CFG->enrol_db_remotetimeendfield) ? ", $CFG->enrol_db_remotetimeendfield" : '').
" FROM {$CFG->enrol_dbtable} " .
" WHERE {$CFG->enrol_remotecoursefield} = " . $enroldb->quote($extcourse) .
($have_role ? ' AND '.$remote_role_name.' = '.$remote_role_value : '');
@@ -279,10 +349,25 @@
continue;
}
- // slurp results into an array
+ // slurp results into an arrays
+ $enroltimes = array();
while ($crs_obj = rs_fetch_next_record($crs)) {
$crs_obj = (object)array_change_key_case((array)$crs_obj , CASE_LOWER);
- array_push($extenrolments, $crs_obj->{strtolower($CFG->enrol_remoteuserfield)});
+ $extenrolment = $crs_obj->{strtolower($CFG->enrol_remoteuserfield)};
+ array_push($extenrolments, $extenrolment);
+
+ $enroltimes[$extenrolment] = array();
+
+ if (isset($crs_obj->{strtolower($CFG->enrol_db_remotetimestartfield)})) {
+ $enroltimes[$extenrolment]['timestart'] = $crs_obj->{strtolower($CFG->enrol_db_remotetimestartfield)};
+ } else {
+ $enroltimes[$extenrolment]['timestart'] = 0;
+ }
+ if (isset($crs_obj->{strtolower($CFG->enrol_db_remotetimeendfield)})) {
+ $enroltimes[$extenrolment]['timeend'] = $crs_obj->{strtolower($CFG->enrol_db_remotetimeendfield)};
+ } else {
+ $enroltimes[$extenrolment]['timeend'] = 0;
+ }
}
rs_close($crs); // release the handle
@@ -327,7 +412,7 @@
foreach ($extenrolments as $member) {
// Get the user id and whether is enrolled in one fell swoop
$sql = "
- SELECT u.id AS userid, ra.id AS enrolmentid
+ SELECT u.id AS userid, ra.id AS enrolmentid, ra.timestart, ra.timeend, ra.contextid
FROM {$CFG->prefix}user u
LEFT OUTER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
AND ra.roleid = {$role->id}
@@ -348,19 +433,36 @@
$user_obj = rs_fetch_record($ers);
$userid = $user_obj->userid;
$enrolmentid = $user_obj->enrolmentid;
+ $times = $enroltimes[$member];
rs_close($ers); // release the handle
- if ($enrolmentid) { // already enrolled - skip
+ if ($times['timeend'] != 0 and $times['timeend'] < time()) {
+ // Timeend expired - don't assign a role
+ if (!$CFG->enrol_db_disableunenrol and $enrolmentid) {
+ // Enrolled and timeend has expired - unenrol
+ if (role_unassign($role->id, $user_obj->userid, 0, $user_obj->contextid)){
+ error_log( "Unassigned {$role->shortname} assignment #$enrolmentid for course {$course->id} (" . format_string($course->shortname) . "); user {$user_obj->userid}");
+ } else {
+ error_log( "Failed to unassign {$role->shortname} assignment #$enrolmentid for course {$course->id} (" . format_string($course->shortname) . "); user {$user_obj->userid}");
+ }
+ }
+ continue;
+ }
+ if ($enrolmentid and round($times['timestart'], -2) == $user_obj->timestart and $times['timeend'] == $user_obj->timeend) {
+ // already enrolled and enrollment dates have not changed - skip (we round timestart because role_assign does)
continue;
}
- if (role_assign($role->id, $userid, 0, $context->id, 0, 0, 0, 'database')){
+ if (role_assign($role->id, $userid, 0, $context->id, $times['timestart'], $times['timeend'], 0, '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) . ")");
}
} // end foreach member
+
+ // Update cron time
+ $this->cron_set_start(false);
} // end while course records
rs_close($rs); //Close the main course recordset
@@ -404,6 +506,9 @@
} else {
error_log( "Failed unassign role {$roleid} from user $user in context $contextid");
}
+
+ // Update cron time
+ $this->cron_set_start(false);
}
rs_close($ers); // release the handle
}
@@ -415,6 +520,7 @@
fix_course_sortorder();
$this->enrol_disconnect($enroldb);
+ $this->delete_backup_files();
return true;
}
@@ -432,10 +538,24 @@
'enrol_localcoursefield', 'enrol_localuserfield',
'enrol_remotecoursefield', 'enrol_remoteuserfield',
'enrol_db_autocreate', 'enrol_db_category', 'enrol_db_template',
+ 'enrol_autocreate_category', 'enrol_category_separator',
'enrol_db_localrolefield', 'enrol_db_remoterolefield',
+ 'enrol_db_remotetimestartfield', 'enrol_db_remotetimeendfield',
'enrol_remotecoursefield', 'enrol_remoteuserfield',
+ 'enrol_coursetable', 'enrol_coursefullname',
+ 'enrol_courseshortname', 'enrol_courseid',
+ 'enrol_coursesummary', 'enrol_coursecategory',
+ 'enrol_coursetemplate', 'enrol_courseenrollable',
'enrol_db_ignorehiddencourse', 'enrol_db_defaultcourseroleid',
- 'enrol_db_disableunenrol');
+ 'enrol_db_disableunenrol', 'enrol_coursestartdate',
+ 'enrol_courseformat', 'enrol_coursetheme',
+ 'enrol_coursepassword', 'enrol_courseguest',
+ 'enrol_coursenumsections', 'enrol_courseidnumber',
+ 'enrol_coursecost', 'enrol_coursenewsitems',
+ 'enrol_courseshowgrades', 'enrol_coursegroupmode',
+ 'enrol_coursegroupmodefoce', 'enrol_coursevisible',
+ 'enrol_db_autoupdate', 'enrol_restore_coursetemplate',
+ 'enrol_restore_usetemplate');
foreach ($vars as $var) {
if (!isset($frm->$var)) {
@@ -503,16 +623,165 @@
}
set_config('enrol_db_autocreate', $config->enrol_db_autocreate);
+ if (!isset($config->enrol_db_autoupdate)) {
+ $config->enrol_db_autoupdate = 0;
+ }
+ set_config('enrol_db_autoupdate', $config->enrol_db_autoupdate);
+
if (!isset($config->enrol_db_category)) {
$config->enrol_db_category = '';
}
set_config('enrol_db_category', $config->enrol_db_category);
+ if (!isset($config->enrol_autocreate_category)) {
+ $config->enrol_autocreate_category = '';
+ }
+ set_config('enrol_autocreate_category', $config->enrol_autocreate_category);
+
+ if (!isset($config->enrol_category_separator)) {
+ $config->enrol_category_separator = '';
+ }
+ set_config('enrol_category_separator', $config->enrol_category_separator);
+
if (!isset($config->enrol_db_template)) {
$config->enrol_db_template = '';
}
set_config('enrol_db_template', $config->enrol_db_template);
+ if (!isset($config->enrol_coursetable)) {
+ $config->enrol_coursetable = '';
+ }
+ set_config('enrol_coursetable', $config->enrol_coursetable);
+
+ if (!isset($config->enrol_coursefullname)) {
+ $config->enrol_coursefullname = '';
+ }
+ set_config('enrol_coursefullname', $config->enrol_coursefullname);
+
+ if (!isset($config->enrol_courseshortname)) {
+ $config->enrol_courseshortname = '';
+ }
+ set_config('enrol_courseshortname',
+ $config->enrol_courseshortname);
+
+ if (!isset($config->enrol_courseid)) {
+ $config->enrol_courseid = '';
+ }
+ set_config('enrol_courseid',
+ $config->enrol_courseid);
+
+ if (!isset($config->enrol_coursesummary)) {
+ $config->enrol_coursesummary = '';
+ }
+ set_config('enrol_coursesummary',
+ $config->enrol_coursesummary);
+
+ if (!isset($config->enrol_coursecategory)) {
+ $config->enrol_coursecategory = '';
+ }
+ set_config('enrol_coursecategory',
+ $config->enrol_coursecategory);
+
+ if (!isset($config->enrol_coursestartdate)) {
+ $config->enrol_coursestartdate = '';
+ }
+ set_config('enrol_coursestartdate',
+ $config->enrol_coursestartdate);
+
+ if (!isset($config->enrol_courseformat)) {
+ $config->enrol_courseformat = '';
+ }
+ set_config('enrol_courseformat',
+ $config->enrol_courseformat);
+
+ if (!isset($config->enrol_coursetheme)) {
+ $config->enrol_coursetheme = '';
+ }
+ set_config('enrol_coursetheme',
+ $config->enrol_coursetheme);
+
+ if (!isset($config->enrol_coursepassword)) {
+ $config->enrol_coursepassword = '';
+ }
+ set_config('enrol_coursepassword',
+ $config->enrol_coursepassword);
+
+ if (!isset($config->enrol_courseguest)) {
+ $config->enrol_courseguest = '';
+ }
+ set_config('enrol_courseguest',
+ $config->enrol_courseguest);
+
+ if (!isset($config->enrol_coursenumsections)) {
+ $config->enrol_coursenumsections = '';
+ }
+ set_config('enrol_coursenumsections',
+ $config->enrol_coursenumsections);
+
+ if (!isset($config->enrol_courseidnumber)) {
+ $config->enrol_courseidnumber = '';
+ }
+ set_config('enrol_courseidnumber',
+ $config->enrol_courseidnumber);
+
+ if (!isset($config->enrol_coursecost)) {
+ $config->enrol_coursecost = '';
+ }
+ set_config('enrol_coursecost',
+ $config->enrol_coursecost);
+
+ if (!isset($config->enrol_coursenewsitems)) {
+ $config->enrol_coursenewsitems = '';
+ }
+ set_config('enrol_coursenewsitems',
+ $config->enrol_coursenewsitems);
+
+ if (!isset($config->enrol_courseshowgrades)) {
+ $config->enrol_courseshowgrades = '';
+ }
+ set_config('enrol_courseshowgrades',
+ $config->enrol_courseshowgrades);
+
+ if (!isset($config->enrol_coursegroupmode)) {
+ $config->enrol_coursegroupmode = '';
+ }
+ set_config('enrol_coursegroupmode',
+ $config->enrol_coursegroupmode);
+
+ if (!isset($config->enrol_coursegroupmodefoce)) {
+ $config->enrol_coursegroupmodefoce = '';
+ }
+ set_config('enrol_coursegroupmodefoce',
+ $config->enrol_coursegroupmodefoce);
+
+ if (!isset($config->enrol_coursevisible)) {
+ $config->enrol_coursevisible = '';
+ }
+ set_config('enrol_coursevisible',
+ $config->enrol_coursevisible);
+
+ if (!isset($config->enrol_courseenrollable)) {
+ $config->enrol_courseenrollable = '';
+ }
+ set_config('enrol_courseenrollable',
+ $config->enrol_courseenrollable);
+
+ if (!isset($config->enrol_coursetemplate)) {
+ $config->enrol_coursetemplate = '';
+ }
+ set_config('enrol_coursetemplate',
+ $config->enrol_coursetemplate);
+
+ if (!isset($config->enrol_restore_coursetemplate)) {
+ $config->enrol_restore_coursetemplate = '';
+ }
+ set_config('enrol_restore_coursetemplate', $config->enrol_restore_coursetemplate);
+
+ if (!isset($config->enrol_restore_usetemplate)) {
+ $config->enrol_restore_usetemplate = '';
+ }
+ set_config('enrol_restore_usetemplate', $config->enrol_restore_usetemplate);
+
if (!isset($config->enrol_db_defaultcourseroleid)) {
$config->enrol_db_defaultcourseroleid = '';
}
@@ -528,6 +797,16 @@
}
set_config('enrol_db_remoterolefield', $config->enrol_db_remoterolefield);
+ if (!isset($config->enrol_db_remotetimestartfield)) {
+ $config->enrol_db_remotetimestartfield = '';
+ }
+ set_config('enrol_db_remotetimestartfield', $config->enrol_db_remotetimestartfield);
+
+ if (!isset($config->enrol_db_remotetimeendfield)) {
+ $config->enrol_db_remotetimeendfield = '';
+ }
+ set_config('enrol_db_remotetimeendfield', $config->enrol_db_remotetimeendfield);
+
if (!isset($config->enrol_db_ignorehiddencourse)) {
$config->enrol_db_ignorehiddencourse = '';
}
@@ -546,14 +825,38 @@
// NOTE: if you pass true for $skip_fix_course_sortorder
// you will want to call fix_course_sortorder() after your are done
// with course creation
-function create_course ($course,$skip_fix_course_sortorder=0){
+function create_course($enroldb, $coursefield, $skip_fix_course_sortorder = 0, $enablerestore = false) {
global $CFG;
- // define a template
- if(!empty($CFG->enrol_db_template)){
- $template = get_record("course", 'shortname', $CFG->enrol_db_template);
- $template = (array)$template;
+ if (!empty($CFG->enrol_coursetable)) {
+ // Using external course information table
+ if (!$course = $this->get_course_details($enroldb, $coursefield)) {
+ return false;
+ }
} else {
+ // Using most basic data
+ $course = new StdClass;
+ $course->{$CFG->enrol_localcoursefield} = $coursefield;
+ $course->fullname = $coursefield;
+ $course->shortname = $coursefield;
+ }
+
+ // define a template
+ if (!empty($CFG->enrol_coursetemplate) and !empty($course->template)) {
+ // We stored the course template in $course->template in get_course_details()
+ // so use it and unset() it once we are done with it.
+ if ($template = get_record("course", 'shortname', addslashes($course->template))) {
+ $templatecourse = clone($template);
+ $template = (array)$template;
+ unset ($course->template);
+ }
+ }
+ if ((!empty($CFG->enrol_db_template) and (!$template))) {
+ if ($template = get_record("course", 'shortname', addslashes($CFG->enrol_db_template))) {
+ $template = (array)$template;
+ }
+ }
+ if (empty($template)) {
$site = get_site();
$template = array(
'startdate' => time() + 3600 * 24,
@@ -574,28 +877,38 @@
'teachers' => $site->teachers,
);
}
+
// overlay template
foreach (array_keys($template) AS $key) {
- if (empty($course->$key)) {
+ if (!isset($course->$key)) {
$course->$key = $template[$key];
}
}
- $course->category = 1; // the misc 'catch-all' category
- if (!empty($CFG->enrol_db_category)){ //category = 0 or undef will break moodle
- $course->category = $CFG->enrol_db_category;
+ // Only use default categories if the course doesn't already have one.
+ if (empty($course->category)) {
+ // the misc 'catch-all' category
+ $course->category = 1;
+
+ if (!empty($CFG->enrol_db_category)) {
+ //category = 0 or undef will break moodle
+ $course->category = $CFG->enrol_db_category;
+ }
}
// define the sortorder
$sort = get_field_sql('SELECT COALESCE(MAX(sortorder)+1, 100) AS max ' .
' FROM ' . $CFG->prefix . 'course ' .
' WHERE category=' . $course->category);
- $course->sortorder = $sort;
-
- // override with local data
- $course->startdate = time() + 3600 * 24;
+ $course->sortorder = $sort;
$course->timecreated = time();
- $course->visible = 1;
+
+ if (!isset($course->startdate)) {
+ $course->startdate = time() + 3600 * 24;
+ }
+ if (!isset($course->visible)) {
+ $course->visible = 1;
+ }
// clear out id just in case
unset($course->id);
@@ -606,12 +919,16 @@
// store it and log
if ($newcourseid = insert_record("course", addslashes_object($course))) { // Set up new course
- $section = NULL;
- $section->course = $newcourseid; // Create a default section.
- $section->section = 0;
- $section->id = insert_record("course_sections", $section);
- $page = page_create_object(PAGE_COURSE_VIEW, $newcourseid);
- blocks_repopulate_page($page); // Return value no
+ if ($enablerestore and !empty($CFG->enrol_restore_coursetemplate) and isset($templatecourse)) {
+ $this->backup_and_restore_into_course($templatecourse, $newcourseid);
+ } else {
+ $section = NULL;
+ $section->course = $newcourseid; // Create a default section.
+ $section->section = 0;
+ $section->id = insert_record("course_sections", $section);
+ $page = page_create_object(PAGE_COURSE_VIEW, $newcourseid);
+ blocks_repopulate_page($page); // Return value no
+ }
if(!$skip_fix_course_sortorder){
@@ -619,7 +936,7 @@
}
add_to_log($newcourseid, "course", "new", "view.php?id=$newcourseid", "enrol/database auto-creation");
} else {
- trigger_error("Could not create new course $extcourse from from database");
+ trigger_error("Could not create new course $extcourse from database");
notify("Serious Error! Could not create the new course!");
return false;
}
@@ -627,6 +944,112 @@
return $newcourseid;
}
+/**
+ * Update a Moodle course settings based
+ * on the external course settings.
+ *
+ * @param object $enroldb External database connection
+ * @param object $course Moodle course to update
+ * @param string $extcourseid External course id to sync the Moodle course to
+ * @return void
+ **/
+function update_course($enroldb, $course, $extcourseid) {
+ if ($extcourse = $this->get_course_details($enroldb, $extcourseid)) {
+ $update = false;
+ $record = new stdClass;
+ foreach ($extcourse as $key => $value) {
+ if ($key != 'id' and isset($course->$key) and $course->$key != $value) {
+ switch ($key) {
+ case 'idnumber':
+ case 'shortname':
+ $record->$key = substr($value, 0, 100);
+ break;
+ default:
+ $record->$key = $value;
+ break;
+ }
+ $update = true;
+ }
+ }
+
+ // Explicitly set
+ $record->id = $course->id;
+
+ if ($update) {
+ if (!update_record('course', addslashes_object($record))) {
+ error_log("Failed to update course with id = $course->id");
+ }
+ }
+ }
+}
+
+/**
+ * Processes courses that have no enrolments.
+ *
+ * Best to be called after {@link sync_enrolments()}
+ * as $this->processed is built so we can skip courses
+ * already processed via enrolments.
+ *
+ * @return boolean
+ **/
+function process_courses_without_enrolments() {
+ global $CFG;
+
+ // Check required config
+ if (!empty($CFG->enrol_courseid) and
+ !empty($CFG->enrol_coursetable) and
+ !empty($CFG->enrol_localcoursefield)) {
+
+ $enroldb = $this->enrol_connect();
+ if (!$enroldb) {
+ error_log('[ENROL_DB] Could not make a connection');
+ return;
+ }
+
+ begin_sql();
+
+ if ($rs = $enroldb->Execute("SELECT {$CFG->enrol_courseid} as enrolremotecoursefield
+ FROM {$CFG->enrol_coursetable}")) {
+
+ while ($fields_obj = rs_fetch_next_record($rs)) {
+ $fields_obj = (object)array_change_key_case((array)$fields_obj , CASE_LOWER);
+ $coursefield = $fields_obj->enrolremotecoursefield;
+
+ if (!in_array($coursefield, $this->processed)) {
+ $course = get_record('course', $CFG->enrol_localcoursefield, $coursefield);
+
+ if (!is_object($course)) {
+ if (empty($CFG->enrol_db_autocreate)) { // autocreation not allowed
+ if (debugging('', DEBUG_ALL)) {
+ error_log( "Course $extcourse does not exist, skipping");
+ }
+ continue; // next foreach course
+ }
+ // ok, now then let's create it!
+ error_log("Creating Course $coursefield...");
+ if ($this->create_course($enroldb, $coursefield, true, true)) {
+ // we are skipping fix_course_sortorder()
+ error_log("created.");
+ } else {
+ error_log("failed.");
+ continue; // nothing left to do...
+ }
+ } else if (!empty($CFG->enrol_db_autoupdate)) {
+ $this->update_course($enroldb, $course, $coursefield);
+ }
+ }
+ }
+ rs_close($rs);
+ }
+ commit_sql();
+ fix_course_sortorder();
+ $this->enrol_disconnect($enroldb);
+ $this->delete_backup_files();
+ }
+
+ return true;
+}
+
/// DB Connect
/// NOTE: You MUST remember to disconnect
/// when you stop using it -- as this call will
@@ -677,6 +1100,462 @@
return array($have_role, $remote_role_name, $remote_role_value);
}
+// get_course_details
+//
+// get_course_details Returns false if the course doesn't exist
+// or if there is more than one course with this courseid in the
+// enrolment database
+//
+// @param $enroldb
+// @param $courseid
+// @param $log_errors boolean (default 'true')
+function get_course_details($enroldb, $courseid, $log_errors = true){
+ global $CFG;
+
+ $columns = $CFG->enrol_courseshortname;
+ if (!empty($CFG->enrol_coursefullname)) {
+ $columns = $columns . "," . $CFG->enrol_coursefullname;
+ }
+ if (!empty($CFG->enrol_coursesummary)) {
+ $columns = $columns . "," . $CFG->enrol_coursesummary;
+ }
+ if (!empty($CFG->enrol_coursecategory)) {
+ $columns = $columns . "," . $CFG->enrol_coursecategory;
+ }
+ if (!empty($CFG->enrol_courseenrollable)) {
+ $columns = $columns . "," . $CFG->enrol_courseenrollable;
+ }
+ if (!empty($CFG->enrol_coursetemplate)) {
+ $columns = $columns . "," . $CFG->enrol_coursetemplate;
+ }
+ if (!empty($CFG->enrol_coursestartdate)) {
+ $columns = $columns . "," . $CFG->enrol_coursestartdate;
+ }
+ if (!empty($CFG->enrol_courseformat)) {
+ $columns = $columns . "," . $CFG->enrol_courseformat;
+ }
+ if (!empty($CFG->enrol_coursetheme)) {
+ $columns = $columns . "," . $CFG->enrol_coursetheme;
+ }
+ if (!empty($CFG->enrol_coursepassword)) {
+ $columns = $columns . "," . $CFG->enrol_coursepassword;
+ }
+ if (!empty($CFG->enrol_courseguest)) {
+ $columns = $columns . "," . $CFG->enrol_courseguest;
+ }
+ if (!empty($CFG->enrol_coursenumsections)) {
+ $columns = $columns . "," . $CFG->enrol_coursenumsections;
+ }
+ if (!empty($CFG->enrol_courseidnumber)) {
+ $columns = $columns . "," . $CFG->enrol_courseidnumber;
+ }
+ if (!empty($CFG->enrol_coursecost)) {
+ $columns = $columns . "," . $CFG->enrol_coursecost;
+ }
+ if (!empty($CFG->enrol_coursenewsitems)) {
+ $columns = $columns . "," . $CFG->enrol_coursenewsitems;
+ }
+ if (!empty($CFG->enrol_courseshowgrades)) {
+ $columns = $columns . "," . $CFG->enrol_courseshowgrades;
+ }
+ if (!empty($CFG->enrol_coursegroupmode)) {
+ $columns = $columns . "," . $CFG->enrol_coursegroupmode;
+ }
+ if (!empty($CFG->enrol_coursegroupmodefoce)) {
+ $columns = $columns . "," . $CFG->enrol_coursegroupmodefoce;
+ }
+ if (!empty($CFG->enrol_coursevisible)) {
+ $columns = $columns . "," . $CFG->enrol_coursevisible;
+ }
+
+ $courseid = addslashes($courseid);
+ $query = "SELECT $columns FROM {$CFG->enrol_coursetable} " .
+ "WHERE {$CFG->enrol_courseid} = '$courseid'";
+
+ if ($rs = $enroldb->Execute($query)) {
+ if ($rs->RecordCount() == 1) {
+ $course = new StdClass;
+ $course->shortname = $rs->fields[$CFG->enrol_courseshortname];
+ if (!empty($CFG->enrol_coursefullname)) {
+ $course->fullname = $rs->fields[$CFG->enrol_coursefullname];
+ }
+ if (!empty($CFG->enrol_coursesummary)) {
+ $course->summary = $rs->fields[$CFG->enrol_coursesummary];
+ }
+ if (!empty($CFG->enrol_coursestartdate)) {
+ $course->startdate = $rs->fields[$CFG->enrol_coursestartdate];
+ }
+ if (!empty($CFG->enrol_courseenrollable)) {
+ $course->enrollable = $rs->fields[$CFG->enrol_courseenrollable];
+ }
+ if (!empty($CFG->enrol_courseformat)) {
+ $course->format = $rs->fields[$CFG->enrol_courseformat];
+ }
+ if (!empty($CFG->enrol_coursetheme)) {
+ $course->theme = $rs->fields[$CFG->enrol_coursetheme];
+ }
+ if (!empty($CFG->enrol_coursepassword)) {
+ $course->password = $rs->fields[$CFG->enrol_coursepassword];
+ }
+ if (!empty($CFG->enrol_courseguest)) {
+ $course->guest = $rs->fields[$CFG->enrol_courseguest];
+ }
+ if (!empty($CFG->enrol_coursenumsections)) {
+ $course->numsections = $rs->fields[$CFG->enrol_coursenumsections];
+ }
+ if (!empty($CFG->enrol_courseidnumber)) {
+ $course->idnumber = $rs->fields[$CFG->enrol_courseidnumber];
+ }
+ if (!empty($CFG->enrol_coursecost)) {
+ $course->cost = $rs->fields[$CFG->enrol_coursecost];
+ }
+ if (!empty($CFG->enrol_coursenewsitems)) {
+ $course->newsitems = $rs->fields[$CFG->enrol_coursenewsitems];
+ }
+ if (!empty($CFG->enrol_courseshowgrades)) {
+ $course->showgrades = $rs->fields[$CFG->enrol_courseshowgrades];
+ }
+ if (!empty($CFG->enrol_coursegroupmode)) {
+ $course->groupmode = $rs->fields[$CFG->enrol_coursegroupmode];
+ }
+ if (!empty($CFG->enrol_coursegroupmodefoce)) {
+ $course->groupmodeforce = $rs->fields[$CFG->enrol_coursegroupmodefoce];
+ }
+ if (!empty($CFG->enrol_coursevisible)) {
+ $course->visible = $rs->fields[$CFG->enrol_coursevisible];
+ }
+ if (!empty($CFG->enrol_coursecategory)) {
+ $category = $rs->fields[$CFG->enrol_coursecategory];
+ if(!empty($category) and $categoryid = $this->get_category($category)) {
+ $course->category = $categoryid;
+ }
+ // If we don't find a categoryid, don't set the course
+ // category so it gets the default one.
+ }
+ if (!empty($CFG->enrol_coursetemplate)) {
+ // Don't forget to unset $course->template later before
+ // we do insert_record, as there is no 'template' field
+ // in prefix_course and the insert will fail.
+ $course->template = $rs->fields[$CFG->enrol_coursetemplate];
+ }
+
+ // Make this assignment last, in case the user chooses
+ // one of the above fields as $CFG->enrol_localcoursefield
+ $course->{$CFG->enrol_localcoursefield} = $courseid;
+ return $course;
+
+ } else if ($rs->RecordCount() > 1) {
+ // Woops! There is more than one course with this ID.
+ // We cannot tell which is the right one! Log this
+ // and return with error.
+ if ($log_errors) {
+ error_log("User enrolled to course $courseid, but there "
+ . "is more than one course with that value in "
+ . "the enrolment database (in field "
+ . "{$CFG->enrol_courseid}) \n");
+ }
+
+ } else {
+ // We didn't find the course in the external enrolment
+ // database. Log it and return with error.
+ if ($log_errors) {
+ error_log("User enrolled to a nonexistant course $courseid "
+ . "(course not found in enrolment database) ");
+ }
+ }
+ }
+ return false;
+}
+
+// get_category
+//
+// get_category returns the id of a given course category. If
+// $CFG->enrol_db_autocreate_category is set and the category doesn't
+// exist, it creates it and returns the new id. Otherwise it returns
+// false.
+//
+// if $CFG->enrol_category_separator is set, it can handle
+// subcategories of any depth. You just need to specify the 'path' of
+// the subcategory as the names of the categories separated by the
+// value of the separator. For example, if we use '/' as the
+// separator, we can specify 'category1/category2/category3' if we are
+// interested in a category called 'category3' that is inside a
+// category called 'category2' that is inside a category called
+// 'category1' that is a top level category.
+//
+// @param $category the name of the category
+// @return category id (int) or false.
+// @uses $CFG
+function get_category($category) {
+ global $CFG;
+
+ if(empty($CFG->enrol_category_separator)) {
+ if (empty($CFG->enrol_autocreate_category)) {
+ if ($id = get_field('course_categories', 'id', 'name', addslashes($category))) {
+ return $id;
+ }
+ error_log("Category '$category' not found (and not autocreating categories). " .
+ "Using default category");
+ return false;
+ } else {
+ $categories = array($category);
+ }
+ } else {
+ if ((strpos($category, $CFG->enrol_category_separator) === 0)
+ || (strrpos($category, $CFG->enrol_category_separator) === (strlen($category) - 1))) {
+ error_log('Category name syntax invalid (cannot start or end with category ' .
+ 'separator): '.$category);
+ return false;
+ }
+ $categories = explode($CFG->enrol_category_separator, $category);
+ }
+
+ // Start checking/creating categories at the top level.
+ $parentid = 0;
+ $parentpath = '';
+ foreach ($categories as $depth => $categoryname) {
+ if ($category = get_record('course_categories', 'name', addslashes($categoryname),
+ 'parent', $parentid)) {
+ $categoryid = $category->id;
+ $parentid = $category->id;
+ $parentpath = $category->path;
+ continue;
+ }
+ if (empty($CFG->enrol_autocreate_category)) {
+ error_log("Category '$categoryname' not found (and not autocreating categories). " .
+ "Using default category");
+ return false;
+ }
+ $newcategory = new stdClass();
+ $newcategory->name = addslashes($categoryname);
+ $newcategory->description = addslashes($categoryname);
+ $newcategory->sortorder = 999;
+ $newcategory->parent = $parentid;
+ $newcategory->depth = $depth + 1;
+ if (!$newcategory->id = insert_record('course_categories', $newcategory)) {
+ error_log("Could not create the new category: '$newcategory->name'");
+ return false;
+ } else {
+ $newcategory->path = $parentpath . '/' . $newcategory->id;
+ update_record ('course_categories', $newcategory);
+ $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
+ mark_context_dirty($newcategory->context->path);
+ $parentid = $newcategory->id;
+ $parentpath = $newcategory->path;
+ $categoryid = $newcategory->id;
+ }
+ }
+ return $categoryid;
+}
+
+/**
+ * Backups a course and then restores
+ * that backup into a destination course.
+ *
+ * @param object $fromcourse The course to backup and restore
+ * @param int $destcourseid The destination for the restore
+ * @return boolean
+ **/
+function backup_and_restore_into_course($fromcourse, $destcourseid) {
+ global $CFG, $USER;
+
+ require_once($CFG->libdir.'/adminlib.php');
+ require_once($CFG->libdir.'/blocklib.php');
+ require_once($CFG->libdir.'/wiki_to_markdown.php');
+ require_once($CFG->libdir.'/xmlize.php');
+ require_once($CFG->dirroot.'/course/lib.php');
+ require_once($CFG->dirroot.'/backup/lib.php');
+ require_once($CFG->dirroot.'/backup/backuplib.php');
+ require_once($CFG->dirroot.'/backup/restorelib.php');
+ require_once($CFG->dirroot.'/backup/bb/restore_bb.php');
+
+ // Same setup as in admin/cron.php
+ $USER = get_admin();
+ $USER->timezone = $CFG->timezone;
+ $USER->lang = '';
+ $USER->theme = '';
+
+ // Look in backupfiles for the backup file or generate a new one
+ if (array_key_exists($fromcourse->id, $this->backupfiles) and $this->backupfiles[$fromcourse->id] === false) {
+ error_log("Failed to restore course with id = $fromcourse->id into course with id = $destcourseid because backup has failed once already");
+ return false;
+
+ } else if (!array_key_exists($fromcourse->id, $this->backupfiles)) {
+ // Grab backup file (may actually trigger a backup)
+ if (!$this->backupfiles[$fromcourse->id] = $this->get_backup_file($fromcourse)) {
+ return false;
+ }
+ }
+
+ // Should have backup file now - import it into destination course
+ if (!@import_backup_file_silently($this->backupfiles[$fromcourse->id], $destcourseid, true, false)) {
+ error_log("Failed to restore course with id = $fromcourse->id into course with id = $destcourseid because import failed");
+ return false;
+ }
+
+ // Update the time since backup/restores can take a long time
+ $this->cron_set_start();
+
+ return true;
+}
+
+/**
+ * Look for a backup file in
+ * backupdata/template or create
+ * a new backup
+ *
+ * @param object $course Find a backup file for this course
+ * @return mixed
+ **/
+function get_backup_file($course) {
+ global $CFG;
+
+ $templatedir = "$CFG->dataroot/$course->id/backupdata/template";
+
+ // If we are using template dir, check there for a backup file first
+ if (!empty($CFG->enrol_restore_usetemplate) and is_dir($templatedir)) {
+ $files = get_directory_list($templatedir, '', false);
+ foreach ($files as $file) {
+ if (pathinfo($file, PATHINFO_EXTENSION) != 'zip') {
+ continue;
+ }
+ if (strpos(strtolower($file), strtolower($course->shortname)) !== false) {
+ // Found what we hope is a backup file
+ return "$templatedir/$file";
+ }
+ }
+ }
+
+ $errorstring = '';
+ $backupprefs = array();
+ if ($backupfile = @backup_course_silently($course->id, $backupprefs, $errorstring)) {
+ // If using templates dir, then save backup file to it
+ if (!empty($CFG->enrol_restore_usetemplate) and make_upload_directory("$course->id/backupdata/template", false)) {
+ $name = pathinfo($backupfile, PATHINFO_BASENAME);
+
+ if (rename($backupfile, "$templatedir/$name")) {
+ return "$templatedir/$name";
+ }
+ }
+ return $backupfile;
+ } else {
+ error_log("Failed to backup course with id = $course->id. Error string returned from backup: $errorstring");
+ return false;
+ }
+}
+
+/**
+ * Remove all backup files generated
+ * during execution except the ones
+ * stored in backupdata/template.
+ *
+ * @return boolean
+ **/
+function delete_backup_files() {
+ global $CFG;
+
+ require_once($CFG->libdir.'/filelib.php');
+
+ foreach ($this->backupfiles as $backupfile) {
+ if (strpos($backupfile, 'backupdata/template') === false) {
+ fulldelete($backupfile);
+ }
+ }
+ $this->backupfiles = array();
+
+ return true;
+}
+
+/**
+ * Cron hook
+ *
+ * @return void
+ **/
+function cron() {
+ global $CFG;
+
+ require_once($CFG->dirroot.'/course/lib.php');
+ require_once($CFG->dirroot.'/lib/blocklib.php');
+
+ if ($this->cron_running()) {
+ error_log("Cron is still running or has not expired yet. Will try again next cron.");
+ return;
+ }
+ $this->cron_set_start();
+
+ // If we have settings to handle roles individually, through each type of
+ // role and update it. Otherwise, just got through once (with no role
+ // specified).
+ $roles = !empty($CFG->enrol_db_remoterolefield) && !empty($CFG->enrol_db_localrolefield)
+ ? get_records('role')
+ : array(null);
+
+ foreach ($roles as $role) {
+ $this->sync_enrolments($role);
+ }
+
+ $this->process_courses_without_enrolments();
+
+ // sync metacourses
+ if (function_exists('sync_metacourses')) {
+ sync_metacourses();
+ }
+
+ $info = get_performance_info();
+ error_log('Performance info from enrol/database cron: '.$info['txt']);
+
+ $this->cron_set_end();
+}
+
+/**
+ * Determine if the cron is still running
+ *
+ * @return boolean
+ **/
+function cron_running() {
+ if ($started = get_config(NULL, 'enrol_db_cronstarted')) {
+ $timetocheck = time() - HOURSECS;
+
+ if ($started != 0 and $started > $timetocheck) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Set the time for the cronstarted
+ *
+ * If not forced, then will only actually
+ * set the config every 100 calls - this is
+ * nice for calling within loops.
+ *
+ * @return boolean
+ **/
+function cron_set_start($force = true) {
+ static $count = 1;
+
+ $return = true;
+
+ if (!$force) {
+ $count++;
+ }
+ if ($force or $count % 100 == 0) {
+ $return = set_config('enrol_db_cronstarted', time());
+ }
+ return $return;
+}
+
+/**
+ * End the cron time
+ *
+ * @return boolean
+ **/
+function cron_set_end() {
+ return unset_config('enrol_db_cronstarted');
+}
+
} // end of class
?>
--- enrol/database/enrol_database_sync.php 2008-02-16 12:03:06.000000000 -0800
+++ enrol/database/enrol_database_sync.php 2009-02-04 11:12:51.000000000 -0800
@@ -4,13 +4,11 @@
error_log("should not be called from apache!");
exit;
}
+
error_reporting(E_ALL);
-
- require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); // global moodle config file.
- require_once($CFG->dirroot . '/course/lib.php');
- require_once($CFG->dirroot . '/lib/blocklib.php');
- require_once($CFG->dirroot . "/enrol/database/enrol.php");
+ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); // global moodle config file.
+ require_once($CFG->dirroot.'/enrol/database/enrol.php');
// ensure errors are well explained
$CFG->debug=E_ALL;
@@ -19,24 +17,10 @@
error_log("Database enrol plugin not enabled!");
die;
}
+ set_time_limit(0);
+ @raise_memory_limit('128M');
- // update enrolments -- these handlers should autocreate courses if required
$enrol = new enrolment_plugin_database();
+ $enrol->cron();
- // If we have settings to handle roles individually, through each type of
- // role and update it. Otherwise, just got through once (with no role
- // specified).
- $roles = !empty($CFG->enrol_db_remoterolefield) && !empty($CFG->enrol_db_localrolefield)
- ? get_records('role')
- : array(null);
-
- foreach ($roles as $role) {
- $enrol->sync_enrolments($role);
- }
-
- // sync metacourses
- if (function_exists('sync_metacourses')) {
- sync_metacourses();
- }
-
?>
--- lang/en_utf8/enrol_database.php 2008-02-16 12:05:09.000000000 -0800
+++ lang/en_utf8/enrol_database.php 2009-01-29 12:03:30.000000000 -0800
@@ -3,18 +3,38 @@
$string['autocreate'] = 'Courses can be created automatically if there are enrolments to a course that doesn\'t yet exist in Moodle.';
+$string['autocreatecategory'] = 'If courses are automatically created and they belong to a category that doesn\'t yet exist in Moodle, those categories can be created automatically.';
$string['autocreation_settings'] = 'Autocreation Settings';
-$string['category'] = 'The category for auto-created courses.';
-$string['course_fullname'] = 'The name of the field where the course fullname is stored.';
-$string['course_id'] = 'The name of the field where the course ID is stored. The values of this field are used to match those in the \"enrol_db_l_coursefield\" field in Moodle\'s course table.';
-$string['course_shortname'] = 'The name of the field where the course shortname is stored.';
-$string['course_table'] = 'Then name of the table where we expect to find the course details in (short name, fullname, ID, etc.)';
-$string['dbtype'] = 'Database type';
+$string['autoupdate'] = 'Courses can be updated automatically if there are enrolments to a course that already exist in Moodle.';
+$string['category'] = 'The default category for auto-created courses (unless you use the enrol_coursecategory setting below.)';
+$string['categoryseparator'] = 'Leave this empty if you don\'t want to use subcategories in your external database. Otherwise, specify the character you are using as the category separator. You need to specify the \'path\' of the subcategory in the enrol_coursecategory field as the names of the categories separated by the category separator. For example, if we use \'/\' as the separator, we should have something like category1/category2 (i.e, category2 is inside category category1, which is a top level category.)';
+$string['coursecategory'] = 'Optional: The name of the field where the course category name is stored. If you want each course to be in a given category (rather than the default one) fill this in.';
+$string['coursecost'] = 'Optional: The name of the field where the course cost is stored.';
+$string['courseenrollable'] = 'Optional: The name of the field where the course enrollable flag is stored.';
+$string['courseformat'] = 'Optional: The name of the field where the course format is stored.';
+$string['coursefullname'] = 'Optional: The name of the field where the course fullname is stored.';
+$string['coursegroupmode'] = 'Optional: The name of the field where the course group mode is stored.';
+$string['coursegroupmodefoce'] = 'Optional: The name of the field where the course group mode forced is stored.';
+$string['courseguest'] = 'Optional: The name of the field where the course guest is stored.';
+$string['courseid'] = 'The name of the field where the course ID is stored. The values of this field are used to match those in the \"enrol_localcoursefield\" field in Moodle\'s course table.';
+$string['courseidnumber'] = 'Optional: The name of the field where the course idnumber is stored.';
+$string['coursenewsitems'] = 'Optional: The name of the field where the course number of news items is stored.';
+$string['coursenumsections'] = 'Optional: The name of the field where the course number of sections is stored.';
+$string['coursepassword'] = 'Optional: The name of the field where the course password is stored.';
+$string['courseshortname'] = 'The name of the field where the course shortname is stored.';
+$string['courseshowgrades'] = 'Optional: The name of the field where the course show grades is stored.';
+$string['coursestartdate'] = 'Optional: The name of the field where the course start date is stored.';
+$string['coursesummary'] = 'Optional: The name of the field where the course summary is stored.';
+$string['coursetable'] = 'Then name of the table where we expect to find the course details in (short name, fullname, ID, etc.)';
+$string['coursetemplate'] = 'Optional: The name of the field where the shortname of the template course is stored. If you want each course to have a given course as the template (rather than the default one) fill this in.';
+$string['coursetheme'] = 'Optional: The name of the field where the course theme is stored.';
+$string['coursevisible'] = 'Optional: The name of the field where the course visible is stored.';
$string['dbhost'] = 'Server IP name or number';
-$string['dbuser'] = 'Server user';
-$string['dbpass'] = 'Server password';
$string['dbname'] = 'Database name';
+$string['dbpass'] = 'Server password';
$string['dbtable'] = 'Database table';
+$string['dbtype'] = 'Database type';
+$string['dbuser'] = 'Server user';
$string['defaultcourseroleid'] = 'The role that will be assigned by default if no other role is specified.';
$string['description'] = 'You can use a external database (of nearly any kind) to control your enrolments. It is assumed your external database contains a field containing a course ID, and a field containing a user ID. These are compared against fields that you choose in the local course and user tables.';
$string['disableunenrol'] = 'If set to yes users previously enrolled by the external database plugin will not be unenrolled by the same plugin regardless of the database contents.';
@@ -29,10 +49,14 @@
$string['local_fields_mapping'] = 'Moodle (local) database fields';
$string['name'] = 'The specific database to use.';
$string['pass'] = 'Password to access the server.';
-$string['remote_fields_mapping'] = 'Enrolment (remote) database fields.';
$string['remotecoursefield'] = 'The name of the field in the remote table that we are using to match entries in the course table.';
$string['remoterolefield'] = 'The name of the field in the remote table that we are using to match entries in the roles table.';
+$string['remotetimeendfield'] = 'Optional: The name of the field in the remote table that we are using for enrollment end date.';
+$string['remotetimestartfield'] = 'Optional: The name of the field in the remote table that we are using for enrollment start date.';
$string['remoteuserfield'] = 'The name of the field in the remote table that we are using to match entries in the user table.';
+$string['remote_fields_mapping'] = 'Enrolment (remote) database fields.';
+$string['restore_coursetemplate'] = 'Backup and then restore the course that matches enrol_coursetemplate setting into the newly created course.';
+$string['restore_usetemplate'] = 'Use the course files backupdata/template directory. If a backup, using the default backup file name, is stored in the backupdata/template directory, then it will be used for the course restore for the enrol_restore_coursetemplate setting. If no backup is found in the backupdata/template directory, then a new backup will automatically be generated and permanently stored there.';
$string['server_settings'] = 'External Database Server Settings';
$string['student_coursefield'] = 'The name of the field in the student enrolment table that we expect to find the course ID in.';
$string['student_l_userfield'] = 'The name of the field in the local user table that we use to match the user to a remote record for students (eg idnumber).';