--- loncom/interface/londocs.pm 2004/12/23 14:00:58 1.158 +++ loncom/interface/londocs.pm 2004/12/23 16:31:27 1.159 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.158 2004/12/23 14:00:58 raeburn Exp $ +# $Id: londocs.pm,v 1.159 2004/12/23 16:31:27 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -486,6 +486,9 @@ sub create_ims_store { if (!-e $$tempexport) { mkdir($$tempexport,0700); } + if (!-e "$$tempexport/resources") { + mkdir("$$tempexport/resources",0700); + } # open manifest file my $manifest = '/imsmanifest.xml'; my $manifestfilename = $$tempexport.$manifest; @@ -609,7 +612,7 @@ sub build_package { } my %extras = ( caller => 'imsexport', - tempexport => $tempexport, + tempexport => $tempexport.'/resources', count => $count ); my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras); @@ -729,7 +732,7 @@ sub process_content { if (@uploads > 0) { foreach my $item (@uploads) { my $uploadmsg = ''; - &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'uploaded'); + &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload'); if ($uploadmsg) { $$copyresult .= $uploadmsg."\n"; } @@ -742,9 +745,13 @@ sub process_content { sub replicate_content { my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_; - my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); - my $feedurl = &Apache::lonnet::clutter($url); - + my ($map,$ind,$url); + if ($caller eq 'templateupload') { + $url = $symb; + $url =~ s#//#/#g; + } else { + ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); + } my $content; my $filename; my $repstatus; @@ -769,7 +776,7 @@ sub replicate_content { &extract_media($content,$count,$tempexport,$href,'resource'); $repstatus = 'ok'; } - } elsif ($caller eq 'noedit' || $caller eq 'uploaded') { + } elsif ($caller eq 'noedit' || $caller eq 'uploaded' || $caller eq 'templateupload') { my $rtncode; $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode); if ($repstatus eq 'ok') { @@ -788,7 +795,7 @@ sub replicate_content { $$message = 'Could not open destination file for '.$filename."\n"; } } else { - $$message = 'Could not determine name of file for '.$url."\n"; + $$message = 'Could not determine name of file for '.$symb."\n"; } if ($repstatus eq 'ok') { $content_name = $count.'/'.$filename; @@ -808,13 +815,25 @@ sub extract_media { sub store_template { my ($contents,$tempexport,$count,$content_type) = @_; if ($contents) { - my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml'; - my $storetemplate; - if ($storetemplate = Apache::File->new('>'.$destination)) { - print $storetemplate $contents; - close($storetemplate); + if ($tempexport) { + if (!-e $tempexport.'/resources') { + mkdir($tempexport.'/resources',0700); + } + if (!-e $tempexport.'/resources/'.$count) { + mkdir($tempexport.'/resources/'.$count,0700); + } + my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml'; + my $storetemplate; + if ($storetemplate = Apache::File->new('>'.$destination)) { + print $storetemplate $contents; + close($storetemplate); + } + if ($content_type eq 'external') { + return $count.'/'.$content_type.'.html'; + } else { + return $count.'/'.$content_type.'.xml'; + } } - return $count.'/'.$content_type.'.xml'; } }