--- loncom/interface/groupsort.pm 2005/06/09 22:06:09 1.33 +++ loncom/interface/groupsort.pm 2006/03/19 22:26:31 1.40 @@ -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.40 2006/03/19 22:26:31 albertel 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); @@ -196,6 +195,48 @@ sub cleanup { &Apache::lonnet::logthis('Failed cleanup groupsort: hash'); } } + return OK; +} + +# -------------------------------------------------------------- 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); + } + $name=~s/\&colon\;/\:/g; + $$thash{$url}=$name; + $$shash{$url}=$n; + $n++; + } + } + } + } + return ($shash,$thash); } # ---------------------------------------------------------------- Main Handler @@ -203,7 +244,7 @@ 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'; @@ -214,14 +255,22 @@ sub handler { # finish_import looks different for graphical or "simple" RAT my $finishimport=''; + my $begincondition=''; + my $endcondition=''; + if ($env{'form.readfile'}) { + $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {'; + $endcondition='}'; + } if ($env{'form.mode'} eq 'simple' || $env{'form.mode'} eq '') { $finishimport=(< + my $js = < function insertRowInLastRow() { opener.insertrow(opener.maxrow); opener.addobj(opener.maxrow,'e&2'); @@ -283,7 +330,6 @@ function orderchange(val,newval) { document.forms.groupsort.submit(); } - END # read pertinent machine configuration my $domain = $r->dir_config('lonDefDomain'); @@ -291,12 +337,17 @@ 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); - if ($clen > 1) { + if (($clen > 1) || ($env{'form.readfile'})) { my %lt=&Apache::lonlocal::texthash( 'fin'=> 'Finalize order of resources', 'gb' => 'Go Back', @@ -305,9 +356,11 @@ END 'ca' => 'Cancel', 'co' => 'Change Order', 'ti' => 'Title', - 'pa' => 'Path' + 'pa' => 'Path', + 'in' => 'Include' ); - $r->print(&Apache::loncommon::bodytag('Sort Imported Resources')); + $r->print(&Apache::loncommon::start_page('Sort Imported Resources', + $js)); $r->print(<$lt{'fin'}
+ + END # --- Expand here if "GO BACK" button desired @@ -341,12 +396,17 @@ END END $r->print("
"); $r->print("\n"); - $r->print("\n"); + if ($env{'form.readfile'}) { + $r->print("\n"); + } else { + $r->print("\n"); + } $r->print("\n"); $r->print("\n"); } else { + $r->print(&Apache::loncommon::start_page(undef,$js, + {'only_body' => 1}); $r->print(< @@ -359,22 +419,30 @@ END my $key=$_; $ctr++; my $iconname=&Apache::loncommon::icon($key); - if ($clen > 1) { + if (($clen > 1) || ($env{'form.readfile'})) { $r->print(""); + unless ($env{'form.readfile'}) { + $r->print(""); + } + $r->print("\n"); } } - if ($clen > 1) { + if (($clen > 1) || ($env{'form.readfile'})) { $r->print("
$lt{'co'}$lt{'in'}$lt{'co'}$lt{'ti'}$lt{'pa'}
"); - $r->print(&movers($clen,$ctr)); + if ($env{'form.readfile'}) { + $r->print(&checkbox($ctr-1)); + } else { + $r->print(&movers($clen,$ctr)); + } } $r->print(&hidden($ctr-1,$thash{$key},$key)); - if ($clen > 1) { - $r->print(""); - $r->print(&select_box($clen,$ctr)); - $r->print(""); + if (($clen > 1) || ($env{'form.readfile'})) { + $r->print("". + &select_box($clen,$ctr). + ""); $r->print(""); $r->print(""); - $r->print("$thash{$key}\n"); + $r->print("$thash{$key}$nhash{$key}\n"); $r->print("$key
"); } else { $r->print(< END } - $r->print(< - -END + + $r->print(&Apache::loncommon::end_page()); return OK; } @@ -426,7 +492,7 @@ sub select_box { my $string; $string = ''.&mt('Include').''; +} + 1; __END__