--- loncom/enrollment/Autoenroll.pl 2016/09/14 20:58:27 1.34 +++ loncom/enrollment/Autoenroll.pl 2021/06/15 20:52:27 1.35 @@ -1,7 +1,7 @@ #!/usr/bin/perl # #Automated Enrollment script -# $Id: Autoenroll.pl,v 1.34 2016/09/14 20:58:27 raeburn Exp $ +# $Id: Autoenroll.pl,v 1.35 2021/06/15 20:52:27 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -74,6 +74,8 @@ # Determine the courses my %courses = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@hostids,'Course'); my %affiliates = (); + my %unclutteredsec = (); + my %unclutteredlcsec = (); my %enrollvar = (); my %reply = (); my %LC_code = (); @@ -120,17 +122,21 @@ $sections[0] = $enrollvar{$crs}{sectionnums}; } if ($enrollvar{$crs}{crosslistings} =~ m/,/) { - @crosslistings = split/,/,$enrollvar{$crs}{crosslistings} + @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}; } else { @crosslistings = $enrollvar{$crs}{crosslistings}; } + my $crscode = $enrollvar{$crs}{coursecode}; + my $crskey = $crs.':'.$crscode; + @{$unclutteredsec{$crskey}} = (); + @{$unclutteredlcsec{$crskey}} = (); foreach my $sec (@sections) { if ($sec =~ m/^(\w+):(\w*)$/ ) { - my $course_id = $enrollvar{$crs}{coursecode}.$1; + my $instsec = $1; my $gp = $2; - if (!grep/^\Q$course_id\E$/,@{$affiliates{$crs}}) { - push @{$affiliates{$crs}}, $course_id; - $LC_code{$crs}{$course_id} = $gp; + unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) { + push(@{$unclutteredsec{$crskey}},$instsec); + push(@{$unclutteredlcsec{$crskey}},$gp); } } } @@ -146,6 +152,19 @@ } } } + } + my %formattedsec = &Apache::lonnet::auto_instsec_reformat($dom,'clutter',\%unclutteredsec); + foreach my $crskey (keys(%formattedsec)) { + my ($crs,$instcode) = split(/:/,$crskey); + if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) { + for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) { + my $course_id = $instcode.$formattedsec{$crskey}[$i]; + unless (grep/^\Q$course_id\E$/,@{$affiliates{$crs}}) { + push(@{$affiliates{$crs}},$course_id); + $LC_code{$crs}{$course_id} = $unclutteredlcsec{$crskey}[$i]; + } + } + } } my $outcome = &Apache::lonnet::fetch_enrollment_query('automated',\%affiliates,\%reply,$dom);