--- loncom/enrollment/localenroll.pm 2003/12/05 17:03:05 1.1 +++ loncom/enrollment/localenroll.pm 2003/12/09 20:06:37 1.3 @@ -1,3 +1,28 @@ +# local bits for automated enrollment +# $Id: localenroll.pm,v 1.3 2003/12/09 20:06:37 albertel Exp $ +# +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# package localenroll; use strict; @@ -19,8 +44,8 @@ sub fetch_enrollment { 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}}); + my $xmlstem = $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_"; + $$replyref{$crs} = &write_class_data ($dbh,$xmlstem,\@{$$affiliatesref{$crs}}); } $dbh->disconnect; } @@ -28,15 +53,17 @@ sub fetch_enrollment { } sub write_class_data { - my ($dbh,$xmlfile,$coursesref) = @_; + my ($dbh,$xmlstem,$coursesref) = @_; my $stucount = 0; - open(FILE, ">$xmlfile"); - print FILE qq| + 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| |; - foreach my $class (@{$coursesref}) { - if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) { + 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 ) { @@ -76,10 +103,10 @@ sub write_class_data { # 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||; + close(FILE); } } - print FILE qq||; - close(FILE); return $stucount; }