[LON-CAPA-cvs] cvs: modules /raeburn localenroll.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 02 Dec 2003 00:21:28 -0000


raeburn		Mon Dec  1 19:21:28 2003 EDT

  Added files:                 
    /modules/raeburn	localenroll.pm 
  Log:
  Module created to fetch 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.  12/1/2003 SPR
  
  

Index: modules/raeburn/localenroll.pm
+++ modules/raeburn/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 ="loncapa";
  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})$/) {
          print STDERR "Looking for data for $1 $2 $3 $4\n";
          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;