[LON-CAPA-cvs] cvs: loncom /enrollment localenroll.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Fri, 05 Dec 2003 17:03:05 -0000
raeburn Fri Dec 5 12:03:05 2003 EDT
Added files:
/loncom/enrollment localenroll.pm
Log:
Module to fetch institutional class list data. Each LON-CAPA domain should create its own customized version. This version is specific to MSU data sources maintained by the Registrar's office.
Retrieves enrollment data from LONCAPA_ClassList view in RO_ClassList database. Writes enrollment for a LON-CAPA course in XML to a file in /home/httpd/perl/tmp. Data is retrieved and processed by routines in LONCAPA::Enrollment.
Index: loncom/enrollment/localenroll.pm
+++ loncom/enrollment/localenroll.pm
package localenroll;
use strict;
use DBI;
use LONCAPA::Configuration;
sub fetch_enrollment {
my ($dom,$affiliatesref,$replyref) = @_;
$ENV{SYBASE} = '/usr/local/freetds';
my $DB_PATH = "dbi:Sybase:server=ESDB1;database=RO_ClassList";
my $DB_USER =""; # Not stored in CVS
my $DB_PASSWD = ""; # Not stored in CVS
my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
my $dbh= DBI->connect($DB_PATH,$DB_USER,$DB_PASSWD);
my $dbflag = 0;
if (defined $dbh) {
$dbflag = 1;
foreach my $crs (sort keys %{$affiliatesref}) {
my $xmlfile = $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_classlist.xml";
$$replyref{$crs} = &write_class_data ($dbh,$xmlfile,\@{$$affiliatesref{$crs}});
}
$dbh->disconnect;
}
return $dbflag;
}
sub write_class_data {
my ($dbh,$xmlfile,$coursesref) = @_;
my $stucount = 0;
open(FILE, ">$xmlfile");
print FILE qq|<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE text>
<students>
|;
foreach my $class (@{$coursesref}) {
if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
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 ) {
$stucount ++;
$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>
<enddate></enddate>
<firstname>$first</firstname>
<generation></generation>
<groupID>$class</groupID>
<lastname>$last</lastname>
<middlename>$middle</middlename>
<startdate></startdate>
<studentID>$pid</studentID>
</student>
|;
# 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);
return $stucount;
}
sub get_sections {
}
1;