File:  [LON-CAPA] / loncom / enrollment / localenroll.pm
Revision 1.1: download - view: text, annotated - select for diffs
Fri Dec 5 17:03:05 2003 UTC (20 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
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.

    1: package localenroll;
    2: 
    3: use strict;
    4: use DBI;
    5: use LONCAPA::Configuration;
    6: 
    7: sub fetch_enrollment {
    8:   my ($dom,$affiliatesref,$replyref) = @_;
    9:   $ENV{SYBASE} = '/usr/local/freetds';
   10: 
   11:   my $DB_PATH = "dbi:Sybase:server=ESDB1;database=RO_ClassList";
   12:   my $DB_USER =""; # Not stored in CVS
   13:   my $DB_PASSWD = ""; # Not stored in CVS
   14: 
   15:   my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
   16: 
   17:   my $dbh= DBI->connect($DB_PATH,$DB_USER,$DB_PASSWD);
   18:   my $dbflag = 0;
   19:   if (defined $dbh) {
   20:      $dbflag = 1; 
   21:      foreach my $crs (sort keys %{$affiliatesref}) {
   22:          my $xmlfile =  $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_classlist.xml";
   23:          $$replyref{$crs} = &write_class_data ($dbh,$xmlfile,\@{$$affiliatesref{$crs}});
   24:      }
   25:      $dbh->disconnect;
   26:   }
   27:   return $dbflag;
   28: }
   29: 
   30: sub write_class_data {
   31:   my ($dbh,$xmlfile,$coursesref) = @_;
   32:   my $stucount = 0;
   33:   open(FILE, ">$xmlfile");
   34:   print FILE qq|<?xml version="1.0" encoding="UTF-8"?>
   35: <!DOCTYPE text>
   36: <students>
   37: |;
   38:   foreach my $class (@{$coursesref}) {
   39:       if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
   40:           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");
   41:           $sth->execute();
   42:           while ( my($pid,$pilot,$name)  = $sth->fetchrow_array ) {
   43:               $stucount ++;
   44:               $name =~ s/^\s//g;
   45:               $name =~ s/\s$//g;
   46:               my ($last,$given,$first,$middle);
   47:               $last = substr($name,0,index($name,","));
   48:               $given = substr($name,index($name,",")+1);
   49:               $given =~ s/^\s//g;
   50:               if ($given =~ m/\w\s\w/) {
   51:                   $first = substr($given,0,index($given," "));
   52:                   $middle = substr($given,index($given," ")+1);
   53:                   $middle =~ s/\s//g;
   54:               } else {
   55:                   $first = $given;
   56:               }
   57:               $first =~ s/\s$//g;
   58:               print FILE qq| <student username="$pilot">
   59:   <autharg>MSU.EDU</autharg>
   60:   <authtype>krb4</authtype>
   61:   <email>$pilot\@msu.edu</email>
   62:   <enddate></enddate>
   63:   <firstname>$first</firstname>
   64:   <generation></generation>
   65:   <groupID>$class</groupID>
   66:   <lastname>$last</lastname>
   67:   <middlename>$middle</middlename>
   68:   <startdate></startdate>
   69:   <studentID>$pid</studentID>
   70:  </student>
   71: |;
   72: # Format for startdate is YYYY:MM:DD:HH:MM:SS
   73: # Format forenddate is YYYY:MM:DD:HH:MM:SS
   74: # Authentication is one of: krb4, krb5, int or loc
   75: # Password is either the password for int, or Kerberos domain (for krb4 or krb5), or argument (for loc).
   76: # 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.
   77:           }
   78:           $sth->finish;
   79:       }
   80:   }
   81:   print FILE qq|</students>|;
   82:   close(FILE);
   83:   return $stucount;
   84: }
   85: 
   86: sub get_sections {
   87: 
   88: }
   89: 
   90: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>