Annotation of loncom/enrollment/localenroll.pm, revision 1.2
1.1 raeburn 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}) {
1.2 ! raeburn 22: my $xmlstem = $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_";
! 23: $$replyref{$crs} = &write_class_data ($dbh,$xmlstem,\@{$$affiliatesref{$crs}});
1.1 raeburn 24: }
25: $dbh->disconnect;
26: }
27: return $dbflag;
28: }
29:
30: sub write_class_data {
1.2 ! raeburn 31: my ($dbh,$xmlstem,$coursesref) = @_;
1.1 raeburn 32: my $stucount = 0;
1.2 ! raeburn 33: foreach my $class (@{$coursesref}) {
! 34: if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
! 35: my $xmlfile = $xmlstem.$class."_classlist.xml";
! 36: open(FILE, ">$xmlfile");
! 37: print FILE qq|<?xml version="1.0" encoding="UTF-8"?>
1.1 raeburn 38: <!DOCTYPE text>
39: <students>
40: |;
1.2 ! raeburn 41:
1.1 raeburn 42: 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");
43: $sth->execute();
44: while ( my($pid,$pilot,$name) = $sth->fetchrow_array ) {
45: $stucount ++;
46: $name =~ s/^\s//g;
47: $name =~ s/\s$//g;
48: my ($last,$given,$first,$middle);
49: $last = substr($name,0,index($name,","));
50: $given = substr($name,index($name,",")+1);
51: $given =~ s/^\s//g;
52: if ($given =~ m/\w\s\w/) {
53: $first = substr($given,0,index($given," "));
54: $middle = substr($given,index($given," ")+1);
55: $middle =~ s/\s//g;
56: } else {
57: $first = $given;
58: }
59: $first =~ s/\s$//g;
60: print FILE qq| <student username="$pilot">
61: <autharg>MSU.EDU</autharg>
62: <authtype>krb4</authtype>
63: <email>$pilot\@msu.edu</email>
64: <enddate></enddate>
65: <firstname>$first</firstname>
66: <generation></generation>
67: <groupID>$class</groupID>
68: <lastname>$last</lastname>
69: <middlename>$middle</middlename>
70: <startdate></startdate>
71: <studentID>$pid</studentID>
72: </student>
73: |;
74: # Format for startdate is YYYY:MM:DD:HH:MM:SS
75: # Format forenddate is YYYY:MM:DD:HH:MM:SS
76: # Authentication is one of: krb4, krb5, int or loc
77: # Password is either the password for int, or Kerberos domain (for krb4 or krb5), or argument (for loc).
78: # 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.
79: }
80: $sth->finish;
1.2 ! raeburn 81: print FILE qq|</students>|;
! 82: close(FILE);
1.1 raeburn 83: }
84: }
85: return $stucount;
86: }
87:
88: sub get_sections {
89:
90: }
91:
92: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>