--- loncom/interface/Attic/londropadd.pm 2000/12/26 16:39:28 1.1 +++ loncom/interface/Attic/londropadd.pm 2001/01/15 14:51:18 1.9 @@ -14,7 +14,8 @@ # 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28, # 12/08,12/12 Gerd Kortemeyer) # -# 12/26 Gerd Kortemeyer +# 12/26,12/27,12/28, +# 01/01/01,01/15 Gerd Kortemeyer package Apache::londropadd; @@ -54,7 +55,473 @@ sub handler { action="/adm/dropadd" name="studentform">
+
+
+ENDUPFORM
+ }
+# ------------------------------------------------------------------- Phase two
+ if ($ENV{'form.phase'} eq 'two') {
+ if ($ENV{'form.fileupload'}) {
+ $ENV{'form.upfile'}=~s/\r/\n/gs;
+ $ENV{'form.upfile'}=~s/\f/\n/gs;
+ $ENV{'form.upfile'}=~s/\n+/\n/gs;
+ 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(<
+
+Internally authenticated (with initial password
+)
+
+
+
+ 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('
+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('Field Samples ');
+ }
+ }
+ $r->print(<');
+ 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(' Login Type
+
+Kerberos authenticated with domain
+LON-CAPA Domain for Students
+LON-CAPA domain: Starting and Ending Dates
+
+
+
+
+
+Set Starting DateFull 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('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('