'.&mt('Internal Filename').' | '.&mt('Title').' | '.&mt('Save as ...').' |
');
@@ -223,12 +232,13 @@ sub dumpcourse {
my ($ext)=($_=~/\.(\w+)$/);
my $title=$hash{'title_'.$hash{
'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
+ $title=~s/:/:/g;
$r->print(''.($title?$title:' ').' | ');
unless ($title) {
$title=$_;
}
$title=~s/\.(\w+)$//;
- $title=~s/[^\w\/]+/\_/gs;
+ $title=&clean($title);
$title.='.'.$ext;
$r->print("\n | \n");
}
@@ -245,13 +255,13 @@ sub exportbutton {
return ''.
''.
- &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
+ &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
}
sub exportcourse {
my $r=shift;
my %discussiontime = &Apache::lonnet::dump('discussiontimes',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
my $numdisc = keys %discussiontime;
my $navmap = Apache::lonnavmaps::navmap->new();
my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
@@ -260,26 +270,12 @@ sub exportcourse {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['finishexport']);
- if ($ENV{'form.finishexport'}) {
+ if ($env{'form.finishexport'}) {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['archive','discussion']);
- my @exportitems = ();
- if (defined($ENV{'form.archive'})) {
- if (ref($ENV{'form.archive'}) eq 'ARRAY') {
- @exportitems = @{$ENV{'form.archive'}};
- } else {
- $exportitems[0] = $ENV{'form.archive'};
- }
- }
- my @discussions = ();
- if (defined($ENV{'form.discussion'})) {
- if (ref($ENV{'form.discussion'}) eq 'ARRAY') {
- @discussions = $ENV{'form.discussion'};
- } else {
- $discussions[0] = $ENV{'form.discussion'};
- }
- }
+ my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
+ my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
if (@exportitems == 0 && @discussions == 0) {
$outcome = ' As you did not select any content items or discussions for export, an IMS package has not been created. Please go back to select either content items or discussions for export';
} else {
@@ -296,20 +292,14 @@ sub exportcourse {
#Create zip file in prtspool
my $imszipfile = '/prtspool/'.
- $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
+ $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
time.'_'.rand(1000000000).'.zip';
-# zip can cause an sh launch which can pass along all of %ENV
-# which can be too large for /bin/sh to handle
- my %oldENV=%ENV;
- undef(%ENV);
my $cwd = &Cwd::getcwd();
my $imszip = '/home/httpd/'.$imszipfile;
chdir $tempexport;
open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
close(OUTPUT);
chdir $cwd;
- %ENV=%oldENV;
- undef(%oldENV);
$outcome .= 'Download the zip file from IMS course archive ';
if ($copyresult) {
$outcome .= 'The following errors occurred during export - '.$copyresult;
@@ -318,8 +308,8 @@ sub exportcourse {
$outcome = ' Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file. ';
}
}
-
- $r->print('Export Course'.
+ my $html=&Apache::lonxml::xmlbegin();
+ $r->print($html.'Export Course'.
&Apache::loncommon::bodytag('Export course to IMS content package'));
$r->print($outcome);
$r->print('');
@@ -460,7 +450,8 @@ function containerCheck(item) {
|;
- $r->print('Export Course'.$scripttag.''.
+ my $html=&Apache::lonxml::xmlbegin();
+ $r->print($html.'Export Course'.$scripttag.''.
&Apache::loncommon::bodytag('Export course to IMS content package'
));
@@ -482,10 +473,13 @@ sub create_ims_store {
if (!-e $$tempexport) {
mkdir($$tempexport,0700);
}
- $$tempexport .= '/'.$ENV{'user.domain'}.'_'.$ENV{'user.name'};
+ $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
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;
@@ -496,13 +490,24 @@ sub create_ims_store {
''."\n".
-' '."\n".
-'
+
+
+
+ '.$env{'request.course.id'}.'
+
+ '.$env{'course.'.$env{'request.course.id'}.'.description'}.'
+
+
+
+ '."\n".
+' '."\n".
+' '."\n".
-' '.$ENV{'request.'.$ENV{'request.course.id'}.'.description'}.''
+' '.$env{'course.'.$env{'request.course.id'}.'.description'}.''
} else {
$$outcome .= 'An error occurred opening the IMS manifest file. '
;
@@ -520,8 +525,8 @@ sub build_package {
my $lastcontainer = 0;
my %parent = ();
my @dependencies = ();
- my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
- my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
while ($curRes = $it->next()) {
if (ref($curRes)) {
$count ++;
@@ -550,7 +555,6 @@ sub build_package {
$count = 0;
my $imsresources;
my $pkgdepth;
- my $included = 0;
while ($curRes = $it->next()) {
if ($curRes == $it->BEGIN_MAP()) {
$prevdepth = $depth;
@@ -571,16 +575,19 @@ sub build_package {
$isvisible = 'false';
}
unless ($curRes->is_sequence()) {
- $resourceref = 'identifierref="RES-'.$ENV{'request.course.id'}.'-'.$count.'"';
+ $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
}
- if (($depth <= $prevdepth) && ($count > 1) && ($included)) {
- print $ims_manifest "\n".' '."\n";
+ my $step = $prevdepth - $depth;
+ if (($step >= 0) && ($count > 1)) {
+ while ($step >= 0) {
+ print $ims_manifest "\n".' '."\n";
+ $step --;
+ }
}
- $included = 1;
$prevdepth = $depth;
my $itementry =
- '- '.
''.$curRes->title().'';
print $ims_manifest "\n".$itementry;
@@ -591,7 +598,7 @@ sub build_package {
&process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
if ($content_file) {
$imsresources .= "\n".
- ' '."\n".
' '."\n";
foreach (@hrefs) {
@@ -609,7 +616,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);
@@ -618,8 +625,6 @@ sub build_package {
}
}
$pkgdepth = $depth;
- } else {
- $included = 0;
}
}
}
@@ -654,8 +659,6 @@ sub process_content {
my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
my $content_type;
my $message;
-# find where user is author or co-author
- my %roleshash = &Apache::lonnet::get_my_roles();
my @uploads = ();
if ($curRes->is_sequence()) {
$content_type = 'sequence';
@@ -688,7 +691,7 @@ sub process_content {
if ($contents) {
$$content_file = &store_template($contents,$tempexport,$count,$content_type);
}
- } elsif ($symb =~ m-lib/templates/examupload\.problem-m) {
+ } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
$content_type = 'examupload';
} elsif ($symb =~ m-adm/(\w+)/(\w+)/(\d+)/bulletinboard$-) {
$content_type = 'bulletinboard';
@@ -702,34 +705,26 @@ sub process_content {
if ($contents) {
$$content_file = &store_template($contents,$tempexport,$count,$content_type);
}
- } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
- $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
} elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
$$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
- } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/])/([^/])-) {
- my $coauth = $3.':'.$2.':ca';
+ } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
my $canedit = 0;
- if ($2 eq $ENV{'user.domain'} && $3 eq $ENV{'user.name'}) {
+ if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) {
$canedit= 1;
- } elsif (defined($roleshash{$coauth})) {
- if ($roleshash{$coauth} =~ /(\d+):(\d+)/) {
- if (($1 < time || $1 == 0) && ($2 == 0 || $2 >= time)) {
- $canedit = 1;
- }
- } elsif ($roleshash{$coauth} eq ':') {
- $canedit = 1;
- }
}
+# only include problem code where current user is author
if ($canedit) {
$$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
} else {
$$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
}
+ } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
+ $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
}
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 +737,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;
@@ -762,59 +761,139 @@ sub replicate_content {
if ($copiedfile = Apache::File->new('>'.$destination)) {
my $content;
if ($caller eq 'resource') {
- $content = &Apache::lonnet::getfile($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 'noedit' || $caller eq 'uploaded') {
+ } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
my $rtncode;
$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.
+ $repstatus = 'ok';
+ $content = 'Not the owner of this resource';
}
if ($repstatus eq 'ok') {
print $copiedfile $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 '.$url."\n";
+ $$message = 'Could not determine name of file for '.$symb." \n";
}
if ($repstatus eq 'ok') {
- $content_name = $count.'/'.$filename;
+ $content_name = 'resources/'.$count.'/'.$filename;
}
return $content_name;
}
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 ($dirpath,$container);
+ my %allfiles = ();
+ my %codebase = ();
+ if ($url =~ m-(.*/)([^/]+)$-) {
+ $dirpath = $1;
+ $container = $2;
+ } else {
+ $dirpath = $url;
+ $container = '';
+ }
+ &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 = $dirpath.$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' && $container =~ /\.(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;
}
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 'resources/'.$count.'/'.$content_type.'.html';
+ } else {
+ return 'resources/'.$count.'/'.$content_type.'.xml';
+ }
}
- return $count.'/'.$content_type.'.xml';
}
}
@@ -837,9 +916,8 @@ sub group_import {
''."\n".
''."\n".
'';
- $ENV{'form.output'}=$newmapstr;
- my $home=&Apache::lonnet::homeserver($coursenum,$coursedom);
- my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$home,
+ $env{'form.output'}=$newmapstr;
+ my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
'output',$1.$2);
if ($result != m|^/uploaded/|) {
$errtext.='Map not saved: A network error occured when trying to save the new map. ';
@@ -850,7 +928,7 @@ sub group_import {
}
}
if ($url) {
- my $idx = $#Apache::lonratedt::resources + 1;
+ my $idx = &Apache::lonratedt::getresidx($url);
$Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
my $ext = 'false';
if ($url=~/^http:\/\//) { $ext = 'true'; }
@@ -867,12 +945,20 @@ sub breadcrumbs {
my ($where)=@_;
&Apache::lonhtmlcommon::clear_breadcrumbs();
my (@folders);
- if ($ENV{'form.pagepath'}) {
- @folders = split('&',$ENV{'form.pagepath'});
+ if ($env{'form.pagepath'}) {
+ @folders = split('&',$env{'form.pagepath'});
} else {
- @folders=split('&',$ENV{'form.folderpath'});
+ @folders=split('&',$env{'form.folderpath'});
}
my $folderpath;
+ my $cpinfo='';
+ if ($env{'form.markedcopy_url'}) {
+ &Apache::lonnet::logthis('Found '.$env{'form.markedcopy_url'});
+ $cpinfo='&markedcopy_url='.
+ &Apache::lonnet::escape($env{'form.markedcopy_url'}).
+ '&markedcopy_title='.
+ &Apache::lonnet::escape($env{'form.markedcopy_title'});
+ }
while (@folders) {
my $folder=shift(@folders);
my $foldername=shift(@folders);
@@ -881,7 +967,7 @@ sub breadcrumbs {
my $url='/adm/coursedocs?folderpath='.
&Apache::lonnet::escape($folderpath);
&Apache::lonhtmlcommon::add_breadcrumb(
- {'href'=>$url,
+ {'href'=>$url.$cpinfo,
'title'=>&Apache::lonnet::unescape($foldername),
'text'=>''.
&Apache::lonnet::unescape($foldername).''
@@ -894,53 +980,60 @@ sub breadcrumbs {
}
sub editor {
- my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
-
- $r->print(&breadcrumbs($folder));
+ my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_;
my $errtext='';
my $fatal=0;
my $container='sequence';
- if ($ENV{'form.pagepath'}) {
+ if ($env{'form.pagepath'}) {
$container='page';
}
($errtext,$fatal)=
&mapread($coursenum,$coursedom,$folder.'.'.$container);
if ($#Apache::lonratedt::order<1) {
- $Apache::lonratedt::order[0]=1;
- $Apache::lonratedt::resources[1]='';
+ my $idx=&Apache::lonratedt::getresidx();
+ if ($idx<=0) { $idx=1; }
+ $Apache::lonratedt::order[0]=$idx;
+ $Apache::lonratedt::resources[$idx]='';
+ }
+ if (defined($env{'form.markcopy'})) {
+# Mark for copying
+ my ($title,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$env{'form.markcopy'}]]);
+ $env{'form.markedcopy_title'}=$title;
+ $env{'form.markedcopy_url'}=$url;
}
+ $r->print(&breadcrumbs($folder));
if ($fatal) {
$r->print(''.$errtext.' ');
} else {
# ------------------------------------------------------------ Process commands
# ---------------- if they are for this folder and user allowed to make changes
- if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
+ if (($allowed) && ($env{'form.folder'} eq $folder)) {
# set parameters and change order
- if (defined($ENV{'form.setparms'})) {
- my $idx=$ENV{'form.setparms'};
+ if (defined($env{'form.setparms'})) {
+ my $idx=$env{'form.setparms'};
# set parameters
- if ($ENV{'form.randpick_'.$idx}) {
- &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
+ if ($env{'form.randpick_'.$idx}) {
+ &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
} else {
&Apache::lonratedt::delparameter($idx,'parameter_randompick');
}
- if ($ENV{'form.hidprs_'.$idx}) {
+ if ($env{'form.hidprs_'.$idx}) {
&Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
} else {
&Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
}
- if ($ENV{'form.encprs_'.$idx}) {
+ if ($env{'form.encprs_'.$idx}) {
&Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
} else {
&Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
}
- if ($ENV{'form.newpos'}) {
+ if ($env{'form.newpos'}) {
# change order
- my $newpos=$ENV{'form.newpos'}-1;
- my $currentpos=$ENV{'form.currentpos'}-1;
+ my $newpos=$env{'form.newpos'}-1;
+ my $currentpos=$env{'form.currentpos'}-1;
my $i;
my @neworder=();
if ($newpos>$currentpos) {
@@ -979,50 +1072,66 @@ sub editor {
}
}
+ if ($env{'form.pastemarked'}) {
+# paste resource to end of list
+ my $url=$env{'form.markedcopy_url'};
+ my $title=$env{'form.markedcopy_title'};
+# Maps need to be copied first
+ if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
+ $title=&mt('Copy of').' '.$title;
+ my $newid=$$.time;
+ $url=~/^(.+)\.(\w+)$/;
+ my $newurl=$1.$newid.'.'.$2;
+ my $storefn=$newurl;
+ $storefn=~s/^\/\w+\/\w+\/\w+\///;
+ &Apache::loncreatecourse::writefile
+ ($env{'request.course.id'},$storefn,
+ &Apache::lonnet::getfile($url));
+ $url=$newurl;
+ }
+ $title=~s/\\<\;/g;
+ $title=~s/\>/\>\;/g;
+ $title=~s/\:/\:/g;
+ my $ext='false';
+ if ($url=~/^http\:\/\//) { $ext='true'; }
+ $url=~s/\:/\:/g;
+# Now insert the URL at the bottom
+ my $newidx=&Apache::lonratedt::getresidx($url);
+ $Apache::lonratedt::resources[$newidx]=
+ $title.':'.$url.':'.$ext.':normal:res';
+ $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
+# Store the result
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ if ($fatal) {
+ $r->print(''.$errtext.' ');
+ return;
+ }
-# upload a file, if present
- if (($ENV{'form.uploaddoc.filename'}) &&
- ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
- if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
-# this is for a course, not a user, so set coursedoc flag
-# probably the only place in the system where this should be "1"
- my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
- my $ext='false';
- if ($url=~/^http\:\/\//) { $ext='true'; }
- $url=~s/\:/\:/g;
- my $comment=$ENV{'form.comment'};
- $comment=~s/\\<\;/g;
- $comment=~s/\>/\>\;/g;
- $comment=~s/\:/\:/g;
- if ($folder=~/^supplemental/) {
- $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
- $ENV{'user.domain'}.'___&&&___'.$comment;
- }
- my $newidx=$#Apache::lonratedt::resources+1;
- $Apache::lonratedt::resources[$newidx]=
- $comment.':'.$url.':'.$ext.':normal:res';
- $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
- $newidx;
-
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
- if ($fatal) {
- $r->print(''.$errtext.' ');
- return;
- }
- }
- }
- if ($ENV{'form.cmd'}) {
- my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
+ }
+ $r->print($upload_output);
+ if ($env{'form.cmd'}) {
+ my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
if ($cmd eq 'del') {
my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
- if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
+ if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
+ ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
&Apache::lonnet::removeuploadedurl($url);
+ } else {
+ &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
}
for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
$Apache::lonratedt::order[$i]=
$Apache::lonratedt::order[$i+1];
}
$#Apache::lonratedt::order--;
+ } elsif ($cmd eq 'cut') {
+ my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
+ &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
+ for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
+ $Apache::lonratedt::order[$i]=
+ $Apache::lonratedt::order[$i+1];
+ }
+ $#Apache::lonratedt::order--;
} elsif ($cmd eq 'up') {
if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
my $i=$Apache::lonratedt::order[$idx-1];
@@ -1043,7 +1152,7 @@ sub editor {
$Apache::lonratedt::resources[
$Apache::lonratedt::order[$idx]]);
my $comment=
- &HTML::Entities::decode($ENV{'form.title'});
+ &HTML::Entities::decode($env{'form.title'});
$comment=~s/\\<\;/g;
$comment=~s/\>/\>\;/g;
$comment=~s/\:/\:/g;
@@ -1062,9 +1171,9 @@ sub editor {
}
}
# Group import/search
- if ($ENV{'form.importdetail'}) {
+ if ($env{'form.importdetail'}) {
my @imports;
- foreach (split(/\&/,$ENV{'form.importdetail'})) {
+ foreach (split(/\&/,$env{'form.importdetail'})) {
if (defined($_)) {
my ($name,$url)=split(/\=/,$_);
$name=&Apache::lonnet::unescape($name);
@@ -1081,10 +1190,10 @@ sub editor {
}
}
# Loading a complete map
- if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
- foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
- my $idx=$#Apache::lonratedt::resources;
- $idx++;
+ if (($env{'form.importmap'}) && ($env{'form.loadmap'})) {
+ foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
+ my ($title,$url,$ext,$type)=split(/\:/,$_);
+ my $idx=&Apache::lonratedt::getresidx($url);
$Apache::lonratedt::resources[$idx]=$_;
$Apache::lonratedt::order
[$#Apache::lonratedt::order+1]=$idx;
@@ -1106,6 +1215,8 @@ sub editor {
$r->print('');
foreach (@Apache::lonratedt::order) {
my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
+ $name=&Apache::lonratsrv::qtescape($name);
+ $url=&Apache::lonratsrv::qtescape($url);
unless ($name) { $name=(split(/\//,$url))[-1]; }
unless ($name) { $idx++; next; }
$r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
@@ -1115,8 +1226,160 @@ sub editor {
unless ($shown) {
$r->print(''.&mt('Currently no documents.').' | ');
}
- $r->print(' ');
+ $r->print("\n |
\n");
+ if ($env{'form.markedcopy_url'}) {
+ $r->print(<