--- enrol.php 2011-03-23 11:23:53.000000000 +1100 +++ enrol.php 2011-01-25 12:46:45.000000000 +1100 @@ -271,7 +271,7 @@ if (empty($CFG->enrol_imsfilelocation)) { // $filename = "$CFG->dirroot/enrol/imsenterprise/example.xml"; // Default location $filename = "$CFG->dataroot/1/imsenterprise-enrol.xml"; // Default location - } else { + }else { $filename = $CFG->enrol_imsfilelocation; } @@ -466,7 +466,7 @@ } if(preg_match('{.*?()?.*?}is', $tagcontents, $matches)){ $group->description = trim($matches[2]); - } else { + }else { $group->description = ""; } }else if(preg_match('{.*?(.*?).*?}is', $tagcontents, $matches)){ @@ -479,22 +479,22 @@ if(preg_match('{.*?()?.*?}is', $tagcontents, $matches)){ $group->summary = trim($matches[2]); - } else { + }else { $group->summary = ""; } if(preg_match('{.*?()?.*?}is', $tagcontents, $matches)){ $group->category = trim($matches[2]); - } else { + }else { $group->category = ""; } if(preg_match('{.*?(.*?).*?}is', $tagcontents, $matches)){ $group->startdate = mktime(0,0,0,substr($matches[1],5,2),substr($matches[1],8,2),substr($matches[1],0,4)); - } else { + }else { $group->startdate = ""; } if(preg_match('{.*?(.*?).*?}is', $tagcontents, $matches)){ $group->visible = trim($matches[1]); - } else { + }else { $group->visible = ""; } $recstatus = ($this->get_recstatus($tagcontents, 'group')); @@ -527,49 +527,72 @@ //foreach($group->coursecode as $coursecode){ $coursecode = trim($group->coursecode); if(!get_field('course', 'id', 'idnumber', $coursecode) && $CFG->enrol_createnewcourses){ -// Handle course categorisation (taken from the group.org.orgunit field if present) + // Handle course categorisation (taken from the group.org.orgunit field if present) if(strlen($group->category)>0){ -// If the category is defined and exists in Moodle, we want to store it in that one + // If the category is defined and exists in Moodle, we want to store it in that one if($catid = get_field('course_categories', 'id', 'name', addslashes($group->category))){ -//do nothing + //do nothing }elseif($CFG->enrol_createnewcategories){ -// Else if we're allowed to create new categories, let's create this one - $newcat->name = $group->category; - $newcat->visible = 0; - if($catid = insert_record('course_categories', $newcat)){ - $this->log_line("Created new (hidden) category, #$catid: $newcat->name"); - }else{ - $this->log_line('Failed to create new category: '.$newcat->name); - } + // Else if we're allowed to create new categories, let's create this one + $newcat->name = $group->category; + $newcat->visible = 0; + if($catid = insert_record('course_categories', $newcat)){ + $this->log_line("Created new (hidden) category, #$catid: $newcat->name"); + }else{ + $this->log_line('Failed to create new category: '.$newcat->name); + } }else{ -// If not found and not allowed to create, stick with default + // If not found and not allowed to create, stick with default $this->log_line('Category '.$group->category.' not found in Moodle database, so using default category instead.'); $catid = 1; } }else{ $catid = 1; } -//[Paolo] If this category has course profile use it + //[Paolo] If this category has course profile use it if ($default_course_used =get_record('course_default','category',$catid)) { unset($default_course_used->id); $course=$default_course_used; - } else if ($default_course_used =get_record('course_default','category',1)) { + }else if ($default_course_used =get_record('course_default','category',1)) { unset($default_course_used->id); $course=$default_course_used; } $course->category = $catid; -// Create the (hidden) course(s) if not found + // Create the (hidden) course(s) if not found $course->fullname = addslashes($group->description); if (intval($CFG->enrol_useshortname)==0 || strlen($course->fullname)==0) { $course->shortname = $coursecode; $course->fullname = addslashes($group->shortname); - } + } $course->shortname = $group->shortname; $course->summary = addslashes($group->summary); $course->idnumber = $coursecode; - $course->visible = $group->visible; + // $course->visible = $group->visible; Overridden + $course->visible = 0; // can be auto set, see above + $course->enrollable = 0; // set to 1 for enrollable $course->enrol = 'imsenterprise'; -// Insert default names for teachers/students, from the current language + $course->timecreated = time(); + $course->startdate = time(); + // Only populate these properties if category defaults not set + if (!$default_course_used) { + // Load Moodle course default values + $courseconfig = get_config('moodlecourse'); + // Set Moodle course default values + $course->format = $courseconfig->format; + $course->numsections = $courseconfig->numsections; + $course->hiddensections = $courseconfig->hiddensections; + $course->newsitems = $courseconfig->newsitems; + $course->showgrades = $courseconfig->showgrades; + $course->showreports = $courseconfig->showreports; + $course->maxbytes = $courseconfig->maxbytes; + } + + // if ($CFG->enrol_imsstartdate) { + // $course->startdate = isset($group->startdate) ? $group->startdate : $course->startdate; + + // } + + // Insert default names for teachers/students, from the current language $site = get_site(); if (current_language() == $CFG->lang) { $course->teacher = $site->teacher; @@ -582,18 +605,6 @@ $course->student = get_string("defaultcoursestudent"); $course->students = get_string("defaultcoursestudents"); } - $course->timecreated = time(); -// Only populate these properties if defaults not set - if (!$default_course_used) { - $course->numsections = 1; - $course->startdate = time(); - $course->format = 'topics'; - $course->visible = 0; - } -// if ($CFG->enrol_imsstartdate) { - $course->startdate = isset($group->startdate) ? $group->startdate : $course->startdate; - -// } // Choose a sort order that puts us at the start of the list! $sortinfo = get_record_sql('SELECT MIN(sortorder) AS min, MAX(sortorder) AS max @@ -786,8 +797,11 @@ }else{ // If they don't exist and they have a defined username, and $CFG->enrol_createnewusers == true, we create them. - $person->lang = 'manual'; //TODO: this needs more work due tu multiauth changes - $person->auth = $CFG->auth; + $person->lang = $CFG->lang; //TODO: this needs more work due tu multiauth changes + // $person->auth = $CFG->auth; + $person->auth = 'ldap'; + // $person->country = 'AU'; // Two letter country code + // $person->city = 'Home'; // Text field $person->confirmed = 1; $person->timemodified = time(); $person->mnethostid = $CFG->mnet_localhost_id;