--- loncom/interface/londocs.pm 2005/06/26 15:42:52 1.191
+++ loncom/interface/londocs.pm 2005/07/26 13:30:34 1.197
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.191 2005/06/26 15:42:52 raeburn Exp $
+# $Id: londocs.pm,v 1.197 2005/07/26 13:30:34 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -249,7 +249,6 @@ sub dumpcourse {
# ------------------------------------------------------ Generate "export" button
sub exportbutton {
- return '';
return '
'.
''.
@@ -748,11 +747,13 @@ sub replicate_content {
if ($copiedfile = Apache::File->new('>'.$destination)) {
my $content;
if ($caller eq 'resource') {
- $content = &Apache::lonnet::getfile('/home/httpd/html/res/'.$url);
+ my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
+ my $filepath = &Apache::lonnet::filelocation($respath,$url);
+ $content = &Apache::lonnet::getfile($filepath);
if ($content eq -1) {
$$message = 'Could not copy file '.$filename;
} else {
- &extract_media($content,$count,$tempexport,$href,'resource');
+ &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
$repstatus = 'ok';
}
} elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
@@ -760,10 +761,10 @@ sub replicate_content {
$repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
if ($repstatus eq 'ok') {
if ($url =~ /\.html?$/i) {
- &extract_media(\$content,$count,$tempexport,$href,'uploaded');
+ &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
}
} else {
- $$message = 'Could not render '.$url.' server message - '.$rtncode;
+ $$message = 'Could not render '.$url.' server message - '.$rtncode." \n";
}
} elsif ($caller eq 'noedit') {
# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
@@ -775,10 +776,10 @@ sub replicate_content {
}
close($copiedfile);
} else {
- $$message = 'Could not open destination file for '.$filename."\n";
+ $$message = 'Could not open destination file for '.$filename." \n";
}
} else {
- $$message = 'Could not determine name of file for '.$symb."\n";
+ $$message = 'Could not determine name of file for '.$symb." \n";
}
if ($repstatus eq 'ok') {
$content_name = $count.'/'.$filename;
@@ -787,11 +788,66 @@ sub replicate_content {
}
sub extract_media {
- my ($content,$count,$tempexport,$href,$caller) = @_;
-# @$href will contain path to any embedded resources in the content.
-# For LON-CAPA problems this would be images. applets etc.
-# For uploaded HTML files this would be images etc.
-# paths will be in the form $count/res/$file, and urls in the $content will be rewritten with the new paths.
+ my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
+ my %allfiles = ();
+ my %codebase = ();
+ $url =~ s#([^/]+)$##;
+ &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content);
+ foreach my $embed_file (keys(%allfiles)) {
+ my $filename;
+ if ($embed_file =~ m#([^/]+)$#) {
+ $filename = $1;
+ } else {
+ $filename = $embed_file;
+ }
+ my $newname = 'res/'.$filename;
+ my ($rtncode,$embed_content,$repstatus);
+ my $embed_url;
+ if ($embed_file =~ m-^/-) {
+ $embed_url = $embed_file; # points to absolute path
+ } else {
+ if ($embed_file =~ m-https?://-) {
+ next; # points to url
+ } else {
+ $embed_url = $url.$embed_file; # points to relative path
+ }
+ }
+ if ($caller eq 'resource') {
+ my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
+ my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
+ $embed_content = &Apache::lonnet::getfile($embed_path);
+ unless ($embed_content eq -1) {
+ $repstatus = 'ok';
+ }
+ } elsif ($caller eq 'uploaded') {
+
+ $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
+ }
+ if ($repstatus eq 'ok') {
+ my $destination = $tempexport.'/resources/'.$count.'/res';
+ if (!-e "$destination") {
+ mkdir($destination,0755);
+ }
+ $destination .= '/'.$filename;
+ my $copiedfile;
+ if ($copiedfile = Apache::File->new('>'.$destination)) {
+ print $copiedfile $embed_content;
+ push @{$href}, .'resources/'.$count.'/res/'.$filename;
+ my $attrib_regexp = '';
+ if (@{$allfiles{$embed_file}} > 1) {
+ $attrib_regexp = join('|',@{$allfiles{$embed_file}});
+ } else {
+ $attrib_regexp = $allfiles{$embed_file}[0];
+ }
+ $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
+ if ($caller eq 'resource' && $url =~ /\.(problem|library)$/) {
+ $$content =~ s#\Q$embed_file\E#$newname#gi;
+ }
+ }
+ } else {
+ $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode." \n";
+ }
+ }
return;
}
@@ -1175,7 +1231,7 @@ FOLDERINFO
}
sub process_file_upload {
- my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase) = @_;
+ my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
# upload a file, if present
my $parseaction;
if ($env{'form.parserflag'}) {
@@ -1183,10 +1239,10 @@ sub process_file_upload {
}
my $phase_status;
my $folder=$env{'form.folder'};
- if ($folder eq '' || $folder eq 'supplemental') {
+ if ($folder eq '') {
$folder='default';
}
- if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
+ if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
my $errtext='';
my $fatal=0;
my $container='sequence';
@@ -1203,10 +1259,13 @@ sub process_file_upload {
return 'failed';
}
my $destination = 'docs/';
- if ($folder eq 'default') {
+ if ($folder =~ /^supplemental/) {
+ $destination = 'supplemental/';
+ }
+ if (($folder eq 'default') || ($folder eq 'supplemental')) {
$destination .= 'default/';
- } elsif ($folder =~ /^default_(\d+)$/) {
- $destination .= $1.'/';
+ } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
+ $destination .= $2.'/';
}
# this is for a course, not a user, so set coursedoc flag
# probably the only place in the system where this should be "1"
@@ -1285,9 +1344,12 @@ sub process_secondary_uploads {
my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
my $folder=$env{'form.folder'};
my $destination = 'docs/';
- if ($folder eq 'default') {
+ if ($folder =~ /^supplemental/) {
+ $destination = 'supplemental/';
+ }
+ if (($folder eq 'default') || ($folder eq 'supplemental')) {
$destination .= 'default/';
- } elsif ($folder =~ /^default_(\d+)$/) {
+ } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
$destination .= $1.'/';
}
$destination .= $newidx;
@@ -1667,8 +1729,15 @@ sub verifycontent {
&mt('Return to DOCS').'');
}
+
# -------------------------------------------------------------- Check Versions
+sub devalidateversioncache {
+ my $src=shift;
+ &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
+ &Apache::lonnet::clutter($src));
+}
+
sub checkversions {
my $r=shift;
my $html=&Apache::lonxml::xmlbegin();
@@ -1695,6 +1764,7 @@ sub checkversions {
foreach (keys %hash) {
if ($_=~/^ids\_(\/res\/.+)$/) {
$newsetversions{$1}='mostrecent';
+ &devalidateversioncache($1);
}
}
} elsif ($env{'form.setcurrent'}) {
@@ -1704,6 +1774,7 @@ sub checkversions {
my $getvers=&Apache::lonnet::getversion($1);
if ($getvers>0) {
$newsetversions{$1}=$getvers;
+ &devalidateversioncache($1);
}
}
}
@@ -1714,6 +1785,7 @@ sub checkversions {
my $src=$1;
if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
$newsetversions{$src}=$env{$_};
+ &devalidateversioncache($src);
}
}
}
@@ -1943,7 +2015,7 @@ sub changewarning {
if (defined($env{'form.pagepath'})) {
$pathvar='pagepath';
$path=&Apache::lonnet::escape($env{'form.pagepath'});
- $path.='&symb='.&Apache::lonnet::escape($env{'form.pagesymb'});
+ $path.='&pagesymb='.&Apache::lonnet::escape($env{'form.pagesymb'});
}
$url='/adm/coursedocs?'.$pathvar.'='.$path;
}
@@ -2246,7 +2318,7 @@ ENDNEWSCRIPT
# Process file upload - phase one - upload and parse primary file.
$upload_result = &process_file_upload(\$upload_output,$coursenum,
$coursedom,\%allfiles,
- \%codebase);
+ \%codebase,$1);
if ($upload_result eq 'phasetwo') {
$r->print($upload_output);
}
@@ -2647,7 +2719,15 @@ ENDBLOCK
|
|