--- loncom/interface/lonclonecourse.pm 2008/09/11 13:19:28 1.7 +++ loncom/interface/lonclonecourse.pm 2010/02/26 22:45:03 1.7.12.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # routines for clone a course # -# $Id: lonclonecourse.pm,v 1.7 2008/09/11 13:19:28 raeburn Exp $ +# $Id: lonclonecourse.pm,v 1.7.12.1 2010/02/26 22:45:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,6 +30,7 @@ package Apache::lonclonecourse; use LONCAPA; use Apache::lonnet; +use Apache::loncoursedata; # ================================================ Get course directory listing @@ -241,4 +242,67 @@ sub copycoursefiles { ©resourcedb($origcrsid,$newcrsid,$date_mode,$date_shift); } +sub copyroster { + my ($origcrsid,$newcrsid,$accessstart,$accessend) = @_; + my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid); + my $newcrsiddata=&Apache::lonnet::coursedescription($newcrsid); + + my $classlist = + &Apache::loncoursedata::get_classlist($origcrsdata{'domain'},$origcrsdata{'num'}); + my %origdate = &Apache::lonnet::get('environment', + ['default_enrollment_end_date'], + $origcrsdata{'domain'},$origcrsdata{'num'}); + + my $enddate = $origdate{'default_enrollment_end_date'}; + + my $sec_idx = &Apache::loncoursedata::CL_SECTION(); + my $status_idx = &Apache::loncoursedata::CL_STATUS(); + my $end_idx = &Apache::loncoursedata::CL_END(); + my $start_idx = &Apache::loncoursedata::CL_START(); + + my (%newstudents,%rolesadded,$numadded); + my $numadded = 0; + my $classlist = &Apache::loncoursedata::get_classlist(); + if (ref($classlist) eq 'HASH') { + foreach my $student (sort(keys(%{$classlist}))) { + my ($sname,$sdom) = split(/:/,$student); + next if ($classlist->{$student}->[$end_idx] eq '-1' + || ($classlist->{$student}->[$start_idx] eq '-1')); + if (($classlist->{$student}->[$status_idx] eq 'Active') || + ($classlist->{$student}->[$end_idx] >= $enddate)) { + if (ref($classlist->{$student}) eq 'ARRAY') { + my @info = @{$classlist->{$student}}; + $info[$end_idx] = $accessend; + $info[$start_idx] = $accessstart; + $newstudents{$student}{'info'} = join(':',@info); + $newstudents{$student}{'section'} = + $classlist->{$student}->[$sec_idx]; + } + } + } + } + if (keys(%newstudents)) { + my $uurl='/'.$newcrsid; + $uurl=~s/\_/\//g; + foreach my $student (sort(keys(%newstudents))) { + my $surl = $uurl; + if ($newstudents{$student}{'section'}) { + $surl.='/'.$newstudents{$student}{'section'}; + } + if (&assignrole($sdom,$sname,$uurl,'st',$accessend,$accessstart,undef,undef,'requestcourses') eq 'ok') { + $rolesadded{$student} = $newstudents{$student}; + $numadded ++ ; + } + } + } + my $clisterror; + if (keys(%rolesadded) > 0) { + my $reply=cput('classlist',\%rolesadded,$newcrsdata{'domain'},$newcrsdata{'num'}); + unless (($reply eq 'ok') || ($reply eq 'delayed')) { + $clisterror = 'error: '.$reply; + } + } + return ($numadded,$clisterror); +} + 1;