--- rat/lonratsrv.pm 2001/11/29 19:23:49 1.16 +++ rat/lonratsrv.pm 2002/08/31 00:42:30 1.22 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Server for RAT Maps # -# $Id: lonratsrv.pm,v 1.16 2001/11/29 19:23:49 www Exp $ +# $Id: lonratsrv.pm,v 1.22 2002/08/31 00:42:30 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; @@ -200,8 +205,8 @@ sub savemap { 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'}); @@ -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]; @@ -284,13 +291,20 @@ sub savemap { } } @tags; $outstr.="\n"; - { + if ($fn=~/^\/*uploaded\//) { + $ENV{'form.output'}=$outstr; + &Apache::lonnet::finishuserfileupload( + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.home'}, + 'output',(split(/\//,$fn))[-1]); + } else { my $fh; if ($fh=Apache::File->new(">$fn")) { print $fh $outstr; $errtext.="Map saved as $fn. "; } else { - $errtext.='Could not write file $fn. Map not saved. '; + $errtext.='Could not write file '.$fn.'. Map not saved. '; } } } else { @@ -316,6 +330,13 @@ sub handler { $url=~s/\/loadonly\/ratserver$/\/save\/ratserver/; my $fn=$r->filename; + my $lonDocRoot=$r->dir_config('lonDocRoot'); + if ( $fn =~ /$lonDocRoot/ ) { + #internal authentication, needs fixup. + $fn = $url; + $fn=~s|^/~(\w+)|/home/$1/public_html|; + $fn=~s|/[^/]*/ratserver$||; + } my $errtext=''; my $outtext='';