[LON-CAPA-cvs] cvs: modules /msu localenroll.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Sun, 05 Dec 2004 16:02:36 -0000
raeburn Sun Dec 5 11:02:36 2004 EDT
Modified files:
/modules/msu localenroll.pm
Log:
Respond to additions to CLIFMS by adding sections to the LONCAPA table in RO_ClassList that had been included in the original course request, but for which the course owner had yet to be added to CLIFMS.
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.12 modules/msu/localenroll.pm:1.13
--- modules/msu/localenroll.pm:1.12 Tue Jul 6 13:37:11 2004
+++ modules/msu/localenroll.pm Sun Dec 5 11:02:35 2004
@@ -1,6 +1,6 @@
# functions to glue school database system into Lon-CAPA for
# automated enrollment
-# $Id: localenroll.pm,v 1.12 2004/07/06 17:37:11 raeburn Exp $
+# $Id: localenroll.pm,v 1.13 2004/12/05 16:02:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -29,6 +29,7 @@
use strict;
use DBI;
use LONCAPA::Configuration;
+use Apache::lonnet;
sub run () {
my $dom = shift;
@@ -42,13 +43,13 @@
my ($dbh,$dbflag) = &connect_DB($$configvars{'lonDaemons'},'RO');
if ($dbflag) {
foreach my $crs (sort keys %{$affiliatesref}) {
- my $xmlstem = $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_";
+ my $xmlstem = $$configvars{'lonDaemons'}.'/tmp/';
my $pilotcount = 0;
my $blankcount = 1;
my $maxtries = 5;
my $numtries = 0;
while ( ($numtries < $maxtries) && ($blankcount > 0) ) {
- ($pilotcount,$blankcount) = &write_class_data ($dbh,$xmlstem,\@{$$affiliatesref{$crs}});
+ ($pilotcount,$blankcount) = &write_class_data ($dbh,$xmlstem,\@{$$affiliatesref{$crs}},$dom,$crs);
$numtries ++;
}
$$replyref{$crs} = $pilotcount;
@@ -95,37 +96,53 @@
}
sub write_class_data {
- my ($dbh,$xmlstem,$coursesref) = @_;
+ my ($dbh,$xmlstem,$coursesref,$dom,$crs) = @_;
+ $xmlstem .= $dom."_".$crs."_";
my $pilotcount = 0;
my $blankcount = 0;
+ my $owner;
foreach my $class (@{$coursesref}) {
if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
- my $xmlfile = $xmlstem.$class."_classlist.xml";
- open(FILE, ">$xmlfile");
- print FILE qq|<?xml version="1.0" encoding="UTF-8"?>
+# Check if section exists in LONCAPA table.
+ my $sectioncheck = $dbh->selectrow_array("SELECT count(*) FROM LONCAPA WHERE Term_Code = '$1' AND Subj_Code = '$2' AND Crse_Code = '$3' AND Sctn_Code = '$4'");
+ if ($sectioncheck == 0) {
+ if ($owner eq '') {
+ $owner = &get_owner($dom,$crs);
+ }
+ unless ($owner eq '' || !defined($owner)) {
+ my $outcome = &new_course($class,$owner,$dom);
+ if ($outcome eq 'ok') {
+ $sectioncheck = 1;
+ }
+ }
+ }
+ if ($sectioncheck > 1) {
+ my $xmlfile = $xmlstem.$class."_classlist.xml";
+ open(FILE, ">$xmlfile");
+ print FILE qq|<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE text>
<students>
|;
- my $sth = $dbh->prepare("SELECT Pid,Pilot_Id,Student_Name FROM LONCAPA_ClassList WHERE Term_Code = '$1' AND Subj_Code = '$2' AND Crse_Code = '$3' AND Sctn_Code = '$4' ORDER BY Student_Name");
- $sth->execute();
- while ( my($pid,$pilot,$name) = $sth->fetchrow_array ) {
- if ($pilot =~ m/^\w{1,8}$/) {
- $pilotcount ++;
- $name =~ s/^\s//g;
- $name =~ s/\s$//g;
- my ($last,$given,$first,$middle);
- $last = substr($name,0,index($name,","));
- $given = substr($name,index($name,",")+1);
- $given =~ s/^\s//g;
- if ($given =~ m/\w\s\w/) {
- $first = substr($given,0,index($given," "));
- $middle = substr($given,index($given," ")+1);
- $middle =~ s/\s//g;
- } else {
- $first = $given;
- }
- $first =~ s/\s$//g;
- print FILE qq| <student username="$pilot">
+ my $sth = $dbh->prepare("SELECT Pid,Pilot_Id,Student_Name FROM LONCAPA_ClassList WHERE Term_Code = '$1' AND Subj_Code = '$2' AND Crse_Code = '$3' AND Sctn_Code = '$4' ORDER BY Student_Name");
+ $sth->execute();
+ while ( my($pid,$pilot,$name) = $sth->fetchrow_array ) {
+ if ($pilot =~ m/^\w{1,8}$/) {
+ $pilotcount ++;
+ $name =~ s/^\s//g;
+ $name =~ s/\s$//g;
+ my ($last,$given,$first,$middle);
+ $last = substr($name,0,index($name,","));
+ $given = substr($name,index($name,",")+1);
+ $given =~ s/^\s//g;
+ if ($given =~ m/\w\s\w/) {
+ $first = substr($given,0,index($given," "));
+ $middle = substr($given,index($given," ")+1);
+ $middle =~ s/\s//g;
+ } else {
+ $first = $given;
+ }
+ $first =~ s/\s$//g;
+ print FILE qq| <student username="$pilot">
<autharg>MSU.EDU</autharg>
<authtype>krb4</authtype>
<email>$pilot\@msu.edu</email>
@@ -139,18 +156,19 @@
<studentID>$pid</studentID>
</student>
|;
- } elsif ($pilot eq '') {
- $blankcount ++;
- }
+ } elsif ($pilot eq '') {
+ $blankcount ++;
+ }
# Format for startdate is YYYY:MM:DD:HH:MM:SS
# Format forenddate is YYYY:MM:DD:HH:MM:SS
# Authentication is one of: krb4, krb5, int or loc
# Password is either the password for int, or Kerberos domain (for krb4 or krb5), or argument (for loc).
# If authentication, password, startdate or enddate are blank, the default for the course is used. These defaults can be modified using the Automated Enrollment Manager.
+ }
+ $sth->finish;
+ print FILE qq|</students>|;
+ close(FILE);
}
- $sth->finish;
- print FILE qq|</students>|;
- close(FILE);
}
}
return ($pilotcount,$blankcount);
@@ -300,4 +318,16 @@
return $outcome;
}
+sub get_owner {
+ my ($dom,$crs) = @_;
+ my $owner;
+ if (defined($dom) && defined($crs)) {
+ my %settings = &Apache::lonnet::get('environment',['internal.courseowner'],$dom,$crs);
+ if ( defined($settings{'internal.courseowner'}) ) {
+ $owner = $settings{'internal.courseowner'};
+ }
+ }
+ return $owner;
+}
+
1;