Annotation of loncom/enrollment/localenroll.pm, revision 1.3

1.3     ! albertel    1: # local bits for automated enrollment
        !             2: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
        !             3: #
        !             4: # Copyright Michigan State University Board of Trustees
        !             5: #
        !             6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !             7: #
        !             8: # LON-CAPA is free software; you can redistribute it and/or modify
        !             9: # it under the terms of the GNU General Public License as published by
        !            10: # the Free Software Foundation; either version 2 of the License, or
        !            11: # (at your option) any later version.
        !            12: #
        !            13: # LON-CAPA is distributed in the hope that it will be useful,
        !            14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            16: # GNU General Public License for more details.
        !            17: #
        !            18: # You should have received a copy of the GNU General Public License
        !            19: # along with LON-CAPA; if not, write to the Free Software
        !            20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            21: #
        !            22: # /home/httpd/html/adm/gpl.txt
        !            23: #
        !            24: # http://www.lon-capa.org/
        !            25: #
1.1       raeburn    26: package localenroll;
                     27: 
                     28: use strict;
                     29: use DBI;
                     30: use LONCAPA::Configuration;
                     31: 
                     32: sub fetch_enrollment {
                     33:   my ($dom,$affiliatesref,$replyref) = @_;
                     34:   $ENV{SYBASE} = '/usr/local/freetds';
                     35: 
                     36:   my $DB_PATH = "dbi:Sybase:server=ESDB1;database=RO_ClassList";
                     37:   my $DB_USER =""; # Not stored in CVS
                     38:   my $DB_PASSWD = ""; # Not stored in CVS
                     39: 
                     40:   my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
                     41: 
                     42:   my $dbh= DBI->connect($DB_PATH,$DB_USER,$DB_PASSWD);
                     43:   my $dbflag = 0;
                     44:   if (defined $dbh) {
                     45:      $dbflag = 1; 
                     46:      foreach my $crs (sort keys %{$affiliatesref}) {
1.2       raeburn    47:          my $xmlstem =  $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_";
                     48:          $$replyref{$crs} = &write_class_data ($dbh,$xmlstem,\@{$$affiliatesref{$crs}});
1.1       raeburn    49:      }
                     50:      $dbh->disconnect;
                     51:   }
                     52:   return $dbflag;
                     53: }
                     54: 
                     55: sub write_class_data {
1.2       raeburn    56:   my ($dbh,$xmlstem,$coursesref) = @_;
1.1       raeburn    57:   my $stucount = 0;
1.2       raeburn    58:   foreach my $class (@{$coursesref}) {
                     59:       if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
                     60:           my $xmlfile = $xmlstem.$class."_classlist.xml";
                     61:           open(FILE, ">$xmlfile");
                     62:           print FILE qq|<?xml version="1.0" encoding="UTF-8"?>
1.1       raeburn    63: <!DOCTYPE text>
                     64: <students>
                     65: |;
1.2       raeburn    66: 
1.1       raeburn    67:           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");
                     68:           $sth->execute();
                     69:           while ( my($pid,$pilot,$name)  = $sth->fetchrow_array ) {
                     70:               $stucount ++;
                     71:               $name =~ s/^\s//g;
                     72:               $name =~ s/\s$//g;
                     73:               my ($last,$given,$first,$middle);
                     74:               $last = substr($name,0,index($name,","));
                     75:               $given = substr($name,index($name,",")+1);
                     76:               $given =~ s/^\s//g;
                     77:               if ($given =~ m/\w\s\w/) {
                     78:                   $first = substr($given,0,index($given," "));
                     79:                   $middle = substr($given,index($given," ")+1);
                     80:                   $middle =~ s/\s//g;
                     81:               } else {
                     82:                   $first = $given;
                     83:               }
                     84:               $first =~ s/\s$//g;
                     85:               print FILE qq| <student username="$pilot">
                     86:   <autharg>MSU.EDU</autharg>
                     87:   <authtype>krb4</authtype>
                     88:   <email>$pilot\@msu.edu</email>
                     89:   <enddate></enddate>
                     90:   <firstname>$first</firstname>
                     91:   <generation></generation>
                     92:   <groupID>$class</groupID>
                     93:   <lastname>$last</lastname>
                     94:   <middlename>$middle</middlename>
                     95:   <startdate></startdate>
                     96:   <studentID>$pid</studentID>
                     97:  </student>
                     98: |;
                     99: # Format for startdate is YYYY:MM:DD:HH:MM:SS
                    100: # Format forenddate is YYYY:MM:DD:HH:MM:SS
                    101: # Authentication is one of: krb4, krb5, int or loc
                    102: # Password is either the password for int, or Kerberos domain (for krb4 or krb5), or argument (for loc).
                    103: # 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.
                    104:           }
                    105:           $sth->finish;
1.2       raeburn   106:           print FILE qq|</students>|;
                    107:           close(FILE);
1.1       raeburn   108:       }
                    109:   }
                    110:   return $stucount;
                    111: }
                    112: 
                    113: sub get_sections {
                    114: 
                    115: }
                    116: 
                    117: 1;

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