--- loncom/interface/londocs.pm 2012/01/29 19:50:53 1.475
+++ loncom/interface/londocs.pm 2012/01/31 23:47:15 1.476
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.475 2012/01/29 19:50:53 raeburn Exp $
+# $Id: londocs.pm,v 1.476 2012/01/31 23:47:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1109,6 +1109,23 @@ sub process_file_upload {
$$upload_output .= &mt('No embedded items identified').'
';
}
$$upload_output = '
'.$$upload_output.'
';
+ } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
+ $nextphase = 'decompress_uploaded';
+ my $position = scalar(@LONCAPA::map::order)-1;
+ my $noextract = &return_to_editor();
+ my $archiveurl = &HTML::Entities::encode($url,'<>&"');
+ my %archiveitems = (
+ folderpath => $env{'form.folderpath'},
+ pagepath => $env{'form.pagepath'},
+ cmd => $nextphase,
+ newidx => $newidx,
+ position => $position,
+ phase => $nextphase,
+ );
+ $$upload_output = $showupload.
+ &Apache::loncommon::decompress_form($mimetype,
+ $archiveurl,'/adm/coursedocs',$noextract,
+ \%archiveitems);
}
}
}
@@ -2363,6 +2380,14 @@ sub handler {
$docuname,$docudom,undef,
$dir_root).
&return_to_editor());
+ } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
+ $uploadphase = 'decompress_phase_one';
+ $r->print(&decompression_phase_one().
+ &return_to_editor());
+ } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
+ $uploadphase = 'decompress_phase_two';
+ $r->print(&decompression_phase_two().
+ &return_to_editor());
}
}
@@ -2933,6 +2958,93 @@ sub return_to_editor {
'';
}
+sub decompression_info {
+ my ($destination,$dir_root) = &embedded_destination();
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $container='sequence';
+ my $hiddenelem;
+ if ($env{'form.pagepath'}) {
+ $container='page';
+ $hiddenelem = ''."\n";
+ } else {
+ $hiddenelem = ''."\n";
+ }
+ if ($env{'form.newidx'}) {
+ $hiddenelem .= ''."\n";
+ }
+ return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
+ $hiddenelem);
+}
+
+sub decompression_phase_one {
+ my ($dir,$file,$warning,$error,$output);
+ my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
+ &decompression_info();
+ if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/docs/\E(?:default|supplemental|\d+).*/([^/]+)$}) {
+ $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
+ } 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 .= ''.
+ $delwarning.
+ '
';
+ }
+ if ($delresult) {
+ $output .= ''.
+ $delresult.
+ '
';
+ }
+ }
+ }
+ if ($error) {
+ $output .= ''.&mt('Not extracted.').'
'.
+ $error.'
'."\n";
+ }
+ if ($warning) {
+ $output .= ''.$warning.'
'."\n";
+ }
+ return $output;
+}
+
+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,
+ $destination,$dir_root,$hiddenelem);
+ return $output;
+}
+
sub generate_admin_options {
my ($help_ref,$env_ref) = @_;
my %lt=&Apache::lonlocal::texthash(