[LON-CAPA-cvs] cvs: loncom /interface londocs.pm
raeburn
raeburn at source.lon-capa.org
Thu Apr 5 11:22:39 EDT 2012
raeburn Thu Apr 5 15:22:39 2012 EDT
Modified files:
/loncom/interface londocs.pm
Log:
Extraction of contents of archive files (zip, tar etc.) from a file
uploaded directly to a course.
- Option for permanent removal of archive file offered later in process.
- Preview of archive file contents.
- Where decompression of archive would overwrite an existing file,
option to overwrite existing file, or discard file in the archive
during extraction.
-------------- next part --------------
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.479 loncom/interface/londocs.pm:1.480
--- loncom/interface/londocs.pm:1.479 Wed Mar 28 12:58:42 2012
+++ loncom/interface/londocs.pm Thu Apr 5 15:22:39 2012
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.479 2012/03/28 12:58:42 goltermann Exp $
+# $Id: londocs.pm,v 1.480 2012/04/05 15:22:39 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1120,17 +1120,46 @@
position => $position,
phase => $nextphase,
comment => $comment,
- );
+ );
+ my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
+ my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
$$upload_output = $showupload.
&Apache::loncommon::decompress_form($mimetype,
$archiveurl,'/adm/coursedocs',$noextract,
- \%archiveitems);
+ \%archiveitems,\@current);
}
}
}
return $nextphase;
}
+sub get_dir_list {
+ my ($url,$coursenum,$coursedom,$newidx) = @_;
+ my ($destination,$dir_root) = &embedded_destination();
+ my ($dirlistref,$listerror) =
+ &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
+ my @dir_lines;
+ my $dirptr=16384;
+ if (ref($dirlistref) eq 'ARRAY') {
+ foreach my $dir_line (sort
+ {
+ my ($afile)=split('&',$a,2);
+ my ($bfile)=split('&',$b,2);
+ return (lc($afile) cmp lc($bfile));
+ } (@{$dirlistref})) {
+ my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
+ $filename =~ s/\s+$//;
+ next if ($filename =~ /^\.\.?$/);
+ my $isdir = 0;
+ if ($dirptr&$testdir) {
+ $isdir = 1;
+ }
+ push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
+ }
+ }
+ return @dir_lines;
+}
+
sub is_supplemental_title {
my ($title) = @_;
return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
@@ -2991,18 +3020,20 @@
my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
my $container='sequence';
- my $hiddenelem;
+ my ($pathitem,$hiddenelem);
+ my @hiddens = ('newidx','comment','position');
if ($env{'form.pagepath'}) {
$container='page';
- $hiddenelem = '<input type="hidden" name="pagepath" value="'.$env{'form.pagepath'}.'" />'."\n";
+ $pathitem = 'pagepath';
} else {
- $hiddenelem = '<input type="hidden" name="folderpath" value="'.$env{'form.folderpath'}.'" />'."\n";
+ $pathitem = 'folderpath';
}
- if ($env{'form.newidx'}) {
- $hiddenelem .= '<input type="hidden" name="newidx" value="'.$env{'form.newidx'}.'" />'."\n";
- }
- if ($env{'form.comment'}) {
- $hiddenelem .= '<input type="hidden" name="comment" value="'.$env{'form.comment'}.'" />'."\n";
+ unshift(@hiddens,$pathitem);
+ foreach my $item (@hiddens) {
+ if ($env{'form.'.$item}) {
+ $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
+ $env{'form.'.$item}.'" />'."\n";
+ }
}
return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
$hiddenelem);
@@ -3017,44 +3048,6 @@
} else {
my $file = $1;
$output = &Apache::loncommon::process_decompression($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem);
- if ($env{'form.archivedelete'}) {
- my $map = $env{'form.folder'}.'.'.$container;
- my ($delwarning,$delresult);
- my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
- if ($fatal) {
- if ($container eq 'page') {
- $delwarning = &mt('An error occurred retrieving the contents of the current page.');
- } else {
- $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
- }
- $delwarning .= &mt('As a result the archive file has not been removed.');
- } else {
- my $currcmd = $env{'form.cmd'};
- $env{'form.cmd'} = 'del_'.$env{'form.position'};
- if (&handle_edit_cmd($docuname,$docudom)) {
- ($errtext,$fatal) = &storemap($docuname,$docudom,$map);
- if ($fatal) {
- if ($container eq 'page') {
- $delwarning = &mt('An error occurred updating the contents of the current page.');
- } else {
- $delwarning = &mt('An error occurred updating the contents of the current folder.');
- }
- }
- }
- $env{'form.cmd'} = $currcmd;
- $delresult = &mt('Archive file removed after extracting files.');
- }
- if ($delwarning) {
- $output .= '<p class="LC_warning">'.
- $delwarning.
- '</p>';
- }
- if ($delresult) {
- $output .= '<p class="LC_info">'.
- $delresult.
- '</p>';
- }
- }
}
if ($error) {
$output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
@@ -3069,12 +3062,64 @@
sub decompression_phase_two {
my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
&decompression_info();
- my $output =
- &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
+ my ($output,$url);
+ if ($env{'form.archivedelete'}) {
+ ($output,$url) = &remove_archive($docudom,$docuname,$container);
+ }
+ $output .=
+ &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,$url,
$destination,$dir_root,$hiddenelem);
return $output;
}
+sub remove_archive {
+ my ($docudom,$docuname,$container) = @_;
+ my $map = $env{'form.folder'}.'.'.$container;
+ my ($output,$delwarning,$delresult,$url,$outcome);
+ my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
+ if ($fatal) {
+ if ($container eq 'page') {
+ $delwarning = &mt('An error occurred retrieving the contents of the current page.');
+ } else {
+ $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
+ }
+ $delwarning .= &mt('As a result the archive file has not been removed.');
+ } else {
+ my $currcmd = $env{'form.cmd'};
+ my $position = $env{'form.position'};
+ if ($position > 0) {
+ $env{'form.cmd'} = 'del_'.$position;
+ my ($title,$url, at rrest) =
+ split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
+ if (&handle_edit_cmd($docuname,$docudom)) {
+ ($errtext,$fatal) = &storemap($docuname,$docudom,$map);
+ if ($fatal) {
+ if ($container eq 'page') {
+ $delwarning = &mt('An error occurred updating the contents of the current page.');
+ } else {
+ $delwarning = &mt('An error occurred updating the contents of the current folder.');
+ }
+ } else {
+ $outcome = 'ok';
+ }
+ $delresult = &mt('Archive file removed.');
+ }
+ }
+ $env{'form.cmd'} = $currcmd;
+ }
+ if ($delwarning) {
+ $output = '<p class="LC_warning">'.
+ $delwarning.
+ '</p>';
+ }
+ if ($delresult) {
+ $output .= '<p class="LC_info">'.
+ $delresult.
+ '</p>';
+ }
+ return ($output,$url,$outcome);
+}
+
sub generate_admin_options {
my ($help_ref,$env_ref) = @_;
my %lt=&Apache::lonlocal::texthash(
@@ -3315,7 +3360,6 @@
newWindow.location.href = newlocation;
}
-
function finishpick() {
var title=this.document.forms.extimport.title.value;
var url=this.document.forms.extimport.url.value;
More information about the LON-CAPA-cvs
mailing list