--- rat/lonratsrv.pm 2002/06/27 16:43:57 1.19 +++ rat/lonratsrv.pm 2002/09/05 19:37:00 1.23 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Server for RAT Maps # -# $Id: lonratsrv.pm,v 1.19 2002/06/27 16:43:57 albertel Exp $ +# $Id: lonratsrv.pm,v 1.23 2002/09/05 19:37:00 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -69,15 +69,20 @@ sub qtunescape { sub loadmap { my ($fn,$errtext)=@_; my $outstr=''; - my @content=(); my @obj=(); my @links=(); - if (-e $fn) { + my $instr=''; + if ($fn=~/^\/*uploaded\//) { + $instr=&Apache::lonnet::getfile($fn); + } elsif (-e $fn) { + my @content=(); { my $fh=Apache::File->new($fn); @content=<$fh>; } - my $instr=join('',@content); + $instr=join('',@content); + } + if ($instr) { my $parser = HTML::TokeParser->new(\$instr); my $token; my $graphmode=0; @@ -197,11 +202,11 @@ sub loadmap { # ----------------------------------------------------------- Saves map to disk sub savemap { - my ($fn,$errtext,$r)=@_; + my ($fn,$errtext)=@_; my %alltypes; my %allvalues; - if (($fn=~/\.sequence$/) || - ($fn=~/\.page$/)) { + if (($fn=~/\.sequence(\.tmp)*$/) || + ($fn=~/\.page(\.tmp)*$/)) { # ------------------------------------------------------------- Deal with input my @tags=split(/<&>/,$ENV{'form.output'}); @@ -213,7 +218,7 @@ sub savemap { } else { $outstr="\n"; } - map { + foreach (@tags) { my @parts=split(/<:>/,$_); if ($parts[0] eq 'objcont') { my @comp=split(/:/,$parts[$#parts]); @@ -262,17 +267,19 @@ sub savemap { } elsif ($parts[0] eq 'objparms') { undef %alltypes; undef %allvalues; - map { + foreach (split(/:/,$parts[$#parts])) { my ($type,$name,$value)=split(/\_\_\_/,$_); $alltypes{$name}=$type; $allvalues{$name}=$value; - } split(/:/,$parts[$#parts]); - map { + } + foreach (keys %allvalues) { + if ($allvalues{$_} ne '') { $outstr.='' ."\n"; - } keys %allvalues; + } + } } elsif (($parts[0] ne '') && ($graphdef)) { # ------------------------------------------------------------- Graphical input $outstr.='<'.$parts[0]; @@ -282,9 +289,15 @@ sub savemap { $outstr.=' value="'.qtescape($parts[$#parts]).'">\n"; } - } @tags; + } $outstr.="\n"; - { + if ($fn=~/^\/*uploaded\/(\w+)\/(\w+)\//) { + $ENV{'form.output'}=$outstr; + my $home=&Apache::lonnet::homeserver($2,$1); + &Apache::lonnet::finishuserfileupload( + $2,$1,$home, + 'output',(split(/\//,$fn))[-1]); + } else { my $fh; if ($fh=Apache::File->new(">$fn")) { print $fh $outstr; @@ -295,7 +308,7 @@ sub savemap { } } else { # -------------------------------------------- Cannot write to that file, error - $errtext.='Map not saved: The specified '.$fn.' path does not exist. '.$r->uri(); + $errtext.='Map not saved: The specified path does not exist. '; } return $errtext; } @@ -327,7 +340,7 @@ sub handler { my $outtext=''; if ($mode ne 'loadonly') { - $errtext=&savemap($fn,$errtext,$r); + $errtext=&savemap($fn,$errtext); } ($outtext,$errtext)=&loadmap($fn,$errtext);