diff -Naur ./enrol.php enrol/database/enrol.php
--- ./enrol.php 2007-07-08 13:36:59.000000000 +1000
+++ enrol/database/enrol.php 2007-06-03 11:51:30.000000000 +1000
@@ -61,7 +61,8 @@
error_log('[ENROL_DB] Using config default for roles: '.$role->shortname);
}*/
- if ($rs = $enroldb->Execute("SELECT {$CFG->enrol_remotecoursefield} as enrolremotecoursefield
+ if ($rs = $enroldb->Execute("SELECT {$CFG->enrol_remotecoursefield} as enrolremotecoursefield,
+ {$CFG->enrol_db_remotetitlefield} as enrolremotetitlefield
FROM {$CFG->enrol_dbtable}
WHERE {$CFG->enrol_remoteuserfield} = " . $useridfield .
(isset($remote_role_name, $remote_role_value) ? ' AND '.$remote_role_name.' = '.$remote_role_value : ''))) {
@@ -85,14 +86,18 @@
$courselist = array();
while ($fields_obj = rs_fetch_next_record($rs)) { // Make a nice little array of courses to process
$courselist[] = $fields_obj->enrolremotecoursefield;
+ $coursetitles[] = $fields_obj->enrolremotetitlefield;
}
rs_close($rs);
+ $listCount=-1; //Allows autoincrement at start of foreach
+
foreach ($courselist as $coursefield) { /// Check the list of courses against existing
+ $listCount++;
$course = get_record('course', $CFG->enrol_localcoursefield, $coursefield);
if (!is_object($course)) {
if (empty($CFG->enrol_db_autocreate)) { // autocreation not allowed
- print "Course $coursefield does not exist, skipping\n";
+ print "Course $coursefield does not exist, skipping $coursetitles[$listCount];\n";
continue; // next foreach course
}
// ok, now then let's create it!
@@ -100,7 +105,7 @@
// prepare any course properties we actually have
$course = new StdClass;
$course->{$CFG->enrol_localcoursefield} = $coursefield;
- $course->fullname = $coursefield;
+ $course->fullname = $coursetitles[$listCount];
$course->shortname = $coursefield;
if ($newcourseid = $this->create_course($course, true)
and $course = get_record( 'course', 'id', $newcourseid)) {
@@ -196,6 +201,7 @@
// get enrolments per-course
$sql = "SELECT DISTINCT {$CFG->enrol_remotecoursefield} " .
+ ", {$CFG->enrol_db_remotetitlefield}" . // Line added for field title
" FROM {$CFG->enrol_dbtable} " .
" WHERE {$CFG->enrol_remoteuserfield} IS NOT NULL" .
(isset($remote_role_name, $remote_role_value) ? ' AND '.$remote_role_name.' = '.$remote_role_value : '');
@@ -214,6 +220,7 @@
while ($extcourse_obj = rs_fetch_next_record($rs)) { // there are more course records
$extcourse = $extcourse_obj->{$CFG->enrol_remotecoursefield};
array_push($extcourses, $extcourse);
+ $titlecourse = $extcourse_obj->{$CFG->enrol_db_remotetitlefield};
print "course $extcourse\n";
@@ -225,7 +232,7 @@
if (!is_object($course)) {
if (empty($CFG->enrol_db_autocreate)) { // autocreation not allowed
- print "Course $extcourse does not exist, skipping\n";
+ print "Course $extcourse does not exist, skipping $titlecourse\n";
continue; // next foreach course
}
// ok, now then let's create it!
@@ -233,7 +240,7 @@
// prepare any course properties we actually have
$course = new StdClass;
$course->{$CFG->enrol_localcoursefield} = $extcourse;
- $course->fullname = $extcourse;
+ $course->fullname = $titlecourse;
$course->shortname = $extcourse;
if ($newcourseid = $this->create_course($course, true)
and $course = get_record( 'course', 'id', $newcourseid)) {
@@ -331,7 +338,7 @@
}
if ( $ers->RecordCount() == 0 ) { // if this returns empty, it means we don't have the student record.
// should not happen -- but skip it anyway
- trigger_error('weird! no user record entry?');
+ trigger_error('weird! no user record entry for '.$member);
continue;
}
$user_obj = rs_fetch_record($ers);
@@ -418,6 +425,7 @@
'enrol_remotecoursefield', 'enrol_remoteuserfield',
'enrol_db_autocreate', 'enrol_db_category', 'enrol_db_template',
'enrol_db_localrolefield', 'enrol_db_remoterolefield',
+ 'enrol_db_remotetitlefield',
'enrol_remotecoursefield', 'enrol_remoteuserfield');
foreach ($vars as $var) {
@@ -511,6 +519,16 @@
}
set_config('enrol_db_remoterolefield', $config->enrol_db_remoterolefield);
+ if (!isset($config->enrol_db_remotetitlefield)) {
+ if ($config->enrol_remotecoursefield != '') {
+ $config->enrol_remotetitlefield = $config->enrol_remotecoursefield;
+ }
+ else {
+ $config->enrol_db_remotetitlefield = '';
+ }
+ }
+ set_config('enrol_db_remotetitlefield', $config->enrol_db_remotetitlefield);
+
return true;
}
--- enrol_database.php 2007-02-24 13:22:50.000000000 +1100
+++ lang/en_utf8/enrol_database.php 2007-07-08 14:07:37.000000000 +1000
@@ -31,6 +31,7 @@
$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['remoteuserfield'] = 'The name of the field in the remote table that we are using to match entries in the user table.';
+$string['remotetitlefield'] = 'The name of the field in the remote table that we are using to label entries in the course table.';
$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).';