# The LearningOnline Network with CAPA # Handler to drop and add students in courses # # (Handler to set parameters for assessments # # (Handler to resolve ambiguous file locations # # (TeX Content Handler # # 05/29/00,05/30,10/11 Gerd Kortemeyer) # # 10/11,10/12,10/16 Gerd Kortemeyer) # # 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28, # 12/08,12/12 Gerd Kortemeyer) # # 12/26,12/27,12/28, # 01/01/01 Gerd Kortemeyer package Apache::londropadd; use strict; use Apache::lonnet; use Apache::Constants qw(:common :http REDIRECT); # ================================================================ Main Handler sub handler { my $r=shift; if ($r->header_only) { $r->content_type('text/html'); $r->send_http_header; return OK; } # ----------------------------------------------------- Needs to be in a course if (($ENV{'request.course.fn'}) && (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) { # ------------------------------------------------------------------ Start page $r->content_type('text/html'); $r->send_http_header; $r->print(< LON-CAPA Student Drop/Add

Drop/Add Students

Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}

ENDHEAD # --------------------------------------------------- Phase one, initial screen unless ($ENV{'form.phase'}) { $r->print(<

Upload a courselist


Type:


Enroll a single student


Drop a student

ENDUPFORM } # ------------------------------------------------------------------- Phase two if ($ENV{'form.phase'} eq 'two') { if ($ENV{'form.fileupload'}) { my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}. '_enroll_'.$ENV{'request.course.id'}.'_'.time.'_'.$$; { my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons'). '/tmp/'.$datatoken.'.tmp'); print $fh $ENV{'form.upfile'}; } my $separator=''; my $remove=''; if ($ENV{'form.upfiletype'} eq 'csv') { $separator='\"\,\s*\"'; $remove='"'; } elsif ($ENV{'form.upfiletype'} eq 'space') { $separator='\s+'; } elsif ($ENV{'form.upfiletype'} eq 'tab') { $separator='\t+'; } elsif ($ENV{'form.upfiletype'} eq 'xml') { } my @lines=split(/\n/,$ENV{'form.upfile'}); my $total=$#lines; $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/; my $krbdefdom=$1; $krbdefdom=~tr/a-z/A-Z/; my $today=time; my $halfyear=$today+15552000; my $defdom=$r->dir_config('lonDefDomain'); $r->print(<


Identify fields

Total number of records found in file: $total ENDPICK my @sone; my @stwo; my @sthree; my $nfields=0; if ($#lines>=0) { $lines[0]=~s/^$remove//; $lines[0]=~s/$remove$//; @sone=split(/$separator/,$lines[0]); $nfields=$#sone; if ($#lines>=1) { $lines[1]=~s/^$remove//; $lines[1]=~s/$remove$//; @stwo=split(/$separator/,$lines[1]); $nfields=$#stwo; } if ($#lines>=2) { $lines[2]=~s/^$remove//; $lines[2]=~s/$remove$//; @sthree=split(/$separator/,$lines[2]); $nfields=$#sthree; } my $i; for ($i=0;$i<=$nfields;$i++) { $r->print(''); } } $r->print(<

Login Type

Kerberos authenticated with domain

Internally authenticated (with initial password )

LON-CAPA Domain for Students

LON-CAPA domain:

Starting and Ending Dates

Set Starting Date

Set Ending Date

Full Update

Full update (also dropping students)


Note: for large courses, this operation might be time consuming. ENDPICK } elsif ($ENV{'form.enroll'}) { } elsif ($ENV{'form.drop'}) { } } # ----------------------------------------------------------------- Phase three if ($ENV{'form.phase'} eq 'three') { if ($ENV{'form.datatoken'}) { my $separator=''; my $remove=''; if ($ENV{'form.upfiletype'} eq 'csv') { $separator='\"\,\s*\"'; $remove='"'; } elsif ($ENV{'form.upfiletype'} eq 'space') { $separator='\s+'; } elsif ($ENV{'form.upfiletype'} eq 'tab') { $separator='\t+'; } elsif ($ENV{'form.upfiletype'} eq 'xml') { } my %fields=(); for (my $i=0;$i<=$ENV{'form.nfields'};$i++) { $fields{$ENV{'form.f'.$i}}=$i; } my $startdate=$ENV{'form.startdate'}; my $enddate=$ENV{'form.enddate'}; if ($startdate=~/\D/) { $startdate=''; } if ($enddate=~/\D/) { $enddate=''; } my $domain=$ENV{'form.lcdomain'}; my $amode=''; my $genpwd=''; if ($ENV{'form.login'} eq 'krb') { $amode='krb4'; $genpwd=$ENV{'form.krbdom'}; } elsif ($ENV{'form.login'} eq 'int') { $amode='internal'; if ((defined($ENV{'form.intpwd'})) && ($ENV{'form.intpwd'})) { $genpwd=$ENV{'form.intpwd'}; } } unless (($domain=~/\W/) || ($amode eq '')) { $r->print('

Enrolling Students

'); my $count=0; my $flushc=0; my %student=(); # ----------------------------------------------------------- Get new classlist my @studentdata=(); { my $fh; if ($fh=Apache::File->new($r->dir_config('lonDaemons'). '/tmp/'.$ENV{'form.datatoken'}.'.tmp')) { @studentdata=<$fh>; } } # --------------------------------------------------------- Enroll new students map { my $line=$_; chomp($line); $line=~s/^$remove//; $line=~s/$remove$//; my @entries=split(/$separator/,$line); unless (($entries[$fields{'username'}] eq '') || (!defined($entries[$fields{'username'}]))) { my $fname=''; my $mname=''; my $lname=''; my $gen=''; if (defined($fields{'names'})) { ($lname,$fname,$mname)= ($entries[$fields{'names'}]=~/([^\,]+)\,\s*(\w+)\s*(.*)$/); } else { if (defined($fields{'fname'})) { $fname=$entries[$fields{'fname'}]; } if (defined($fields{'mname'})) { $mname=$entries[$fields{'mname'}]; } if (defined($fields{'lname'})) { $lname=$entries[$fields{'lname'}]; } if (defined($fields{'gen'})) { $gen=$entries[$fields{'gen'}]; } } if ($entries[$fields{'username'}]=~/\W/) { $r->print('

Unacceptable username: '. $entries[$fields{'username'}].' for user '. $fname.' '.$mname.' '.$lname.' '.$gen.'

'); } else { my $sec=''; my $username=$entries[$fields{'username'}]; if (defined($fields{'sec'})) { if (defined($entries[$fields{'sec'}])) { $sec=$entries[$fields{'sec'}]; } } my $id=''; if (defined($fields{'id'})) { if (defined($entries[$fields{'id'}])) { $id=$entries[$fields{'id'}]; } $id=~tr/A-Z/a-z/; } my $password=''; if ($genpwd) { $password=$genpwd; } else { if (defined($fields{'ipwd'})) { if ($entries[$fields{'ipwd'}]) { $password=$entries[$fields{'ipwd'}]; } } } if ($password) { my $reply=&Apache::lonnet::modifystudent( $domain,$username,$id,$amode,$password, $fname,$mname,$lname,$gen,$sec,$enddate,$startdate); unless ($reply eq 'ok') { $r->print( "

Error enrolling $username: $reply

"); } else { $count++; $flushc++; $student{$username}=1; $r->print('. '); if ($flushc>15) { $r->rflush; $flushc=0; } } } else { $r->print( "

No password for $username

"); } } } } @studentdata; $r->print('

Processed Students: '.$count); # --------------------------------------------------------------- Drop students if ($ENV{'form.fullup'} eq 'yes') { $r->print('

Dropping Students

'); # ------------------------------------------------------- Get current classlist my $cid=$ENV{'request.course.id'}; my $classlst=&Apache::lonnet::reply ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'. $ENV{'course.'.$cid.'.num'}.':classlist', $ENV{'course.'.$cid.'.home'}); my %currentlist=(); my $now=time; unless ($classlst=~/^error\:/) { map { my ($name,$value)=split(/\=/,$_); my ($end,$start)=split(/\_/, &Apache::lonnet::unescape($value)); my $active=1; if (($end) && ($now>$end)) { $active=0; } if ($active) { $currentlist{&Apache::lonnet::unescape($name)}=1; } } split(/\&/,$classlst); } else { $r->print( '

Could not access classlist: '.$classlst. '

'); } } # ------------------------------------------------------------------------ Done } } } # ------------------------------------------------------------------------- End $r->print(''); } else { # ----------------------------- Not in a course, or not allowed to modify parms $ENV{'user.error.msg'}= "/adm/dropadd:cst:0:0:Cannot drop or add students"; return HTTP_NOT_ACCEPTABLE; } return OK; } 1; __END__
FieldSamples
'); if (defined($sone[$i])) { $r->print($sone[$i]."
\n"); } if (defined($stwo[$i])) { $r->print($stwo[$i]."
\n"); } if (defined($sthree[$i])) { $r->print($sthree[$i]."
\n"); } $r->print('