--- loncom/interface/groupsort.pm 2005/06/09 22:06:09 1.33 +++ loncom/interface/groupsort.pm 2005/06/10 16:56:08 1.36 @@ -2,7 +2,7 @@ # The LON-CAPA group sort handler # Allows for sorting prior to import into RAT. # -# $Id: groupsort.pm,v 1.33 2005/06/09 22:06:09 www Exp $ +# $Id: groupsort.pm,v 1.36 2005/06/10 16:56:08 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -180,8 +180,7 @@ sub readfromdb { } } } else { - $r->print('Unable to tie hash to db file'); - return OK; + $r->print('Unable to tie hash to db file'); } untie %hash; return ($shash,$thash); @@ -198,12 +197,52 @@ sub cleanup { } } +# -------------------------------------------------------------- Read from file + +sub readfromfile { + my ($r,$shash,$thash,$nhash)=@_; + my $cont=&Apache::lonnet::getfile + (&Apache::lonnet::filelocation('',$env{'form.readfile'})); + if ($cont==-1) { + $r->print('Unable to read file: '. + &Apache::lonnet::filelocation('',$env{'form.readfile'})); + } else { + my $parser = HTML::TokeParser->new(\$cont); + my $token; + my $n=1; + while ($token = $parser->get_token) { + if ($token->[0] eq 'S') { + if ($token->[1] eq 'resource') { + if ($env{'form.recover'}) { + if ($token->[2]->{'type'} ne 'zombie') { next; } + } else { + if ($token->[2]->{'type'} eq 'zombie') { next; } + } + + my $url=$token->[2]->{'src'}; + my $name=$token->[2]->{'title'}; + $name=~s/ \[\((\d+)\,(\w+)\,(\w+)\)\]$//; + if ($1) { + $$nhash{$url}='
'.&mt('Removed by '). + &Apache::loncommon::plainname($2,$3).', '. + &Apache::lonlocal::locallocaltime($1); + } + $$thash{$url}=$name; + $$shash{$url}=$n; + $n++; + } + } + } + } + return ($shash,$thash); +} + # ---------------------------------------------------------------- Main Handler sub handler { my $r = shift; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['acts','catalogmode','mode']); + ['acts','catalogmode','mode','readfile','recover']); # color scheme my $fileclr = '#ffffe6'; my $titleclr = '#ddffff'; @@ -291,8 +330,13 @@ END my %shash; # sort order (key is resource location, value is sort order) my %thash; # title (key is resource location, value is title) + my %nhash; # notes (key is resource location); - &readfromdb($r,\%shash,\%thash); + if ($env{'form.readfile'}) { + &readfromfile($r,\%shash,\%thash,\%nhash); + } else { + &readfromdb($r,\%shash,\%thash); + } my $ctr = 0; my $clen = scalar(keys %shash); @@ -316,6 +360,8 @@ END + + END # --- Expand here if "GO BACK" button desired @@ -370,7 +416,7 @@ END $r->print(""); $r->print(""); $r->print(""); - $r->print("$thash{$key}\n"); + $r->print("$thash{$key}$nhash{$key}\n"); $r->print("$key\n"); } } @@ -426,7 +472,7 @@ sub select_box { my $string; $string = '