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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 09 Dec 2003 20:03:04 -0000


albertel		Tue Dec  9 15:03:04 2003 EDT

  Added files:                 
    /modules/msu	localenroll.pm 
  Log:
  - MSU specific localenroll.pm
  
  

Index: modules/msu/localenroll.pm
+++ modules/msu/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 $xmlstem =  $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_";
         $$replyref{$crs} = &write_class_data ($dbh,$xmlstem,\@{$$affiliatesref{$crs}});
     }
     $dbh->disconnect;
  }
  return $dbflag;
}

sub write_class_data {
  my ($dbh,$xmlstem,$coursesref) = @_;
  my $stucount = 0;
  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"?>
<!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 ) {
              $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;