--- loncom/publisher/loncfile.pm 2024/05/13 13:55:50 1.128
+++ loncom/publisher/loncfile.pm 2024/05/21 02:57:16 1.129
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.128 2024/05/13 13:55:50 raeburn Exp $
+# $Id: loncfile.pm,v 1.129 2024/05/21 02:57:16 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -822,42 +822,19 @@ sub Decompress1 {
sub Archive1 {
my ($request,$fn) = @_;
my @posstypes = qw(problem library sty sequence page task rights meta xml html xhtml htm xhtm css js tex txt gif jpg jpeg png svg other);
- my (%location_of,%default,$compstyle);
- foreach my $program ('tar','gzip','bzip2','xz','zip') {
- foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
- '/usr/sbin/') {
- if (-x $dir.$program) {
- $location_of{$program} = $dir.$program;
- last;
- }
- }
- }
- my (%defaults,$cancompress,$canarchive);
- if (exists($location_of{'tar'})) {
- $default{'tar'} = ' checked="checked"';
- $canarchive = 1;
- $compstyle = 'block';
- } elsif (exists($location_of{'zip'})) {
- $default{'zip'} = ' checked="checked"';
- $canarchive = 1;
- $compstyle = 'none';
- }
- foreach my $compress ('gzip','bzip2','xz') {
- if (exists($location_of{$compress})) {
- $default{$compress} = ' checked="checked"';
- $cancompress = 1;
- last;
- }
- }
+ my (%location_of,%defaults);
+ my ($compstyle,$canarchive,$cancompress,$numformat,$numcompress,$defext) =
+ &archive_tools(\%location_of,\%defaults);
if (!$canarchive) {
$request->print('
'.
- &mt('This LON-CAPA instance does not seem to have either tar or zip installed.').'
'.
+ &mt('This LON-CAPA instance does not seem to have either tar or zip installed.').''."\n".
''.
&mt('At least one of the two is needed in order to be able to create an archive file for: [_1].',
- &display($fn)).
+ &display($fn))."\n".
'');
} elsif (-e $fn) {
- $request->print(&Apache::lonhtmlcommon::start_pick_box().
+ $request->print(''."\n".
+ &Apache::lonhtmlcommon::start_pick_box().
&Apache::lonhtmlcommon::row_title(&mt('Directory')).
&display($fn).
&Apache::lonhtmlcommon::row_closure().
@@ -909,7 +886,7 @@ sub Archive1 {
if (exists($location_of{$possfmt})) {
$request->print(''.
' ');
}
}
@@ -921,7 +898,8 @@ sub Archive1 {
foreach my $compress ('gzip','bzip2','xz') {
if (exists($location_of{$compress})) {
$request->print(' ');
+ $defaults{$compress}.' onclick="setArchiveExt(this.form);" />'.
+ $compress.' ');
}
}
} else {
@@ -929,9 +907,16 @@ sub Archive1 {
&mt('This LON-CAPA instance does not seem to have gzip, bzip2 or xz installed.').
'
'.&mt('No compression will be used.').'');
}
- $request->print(''.
+ $request->print(''."\n".
+ ''."\n".
&Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::end_pick_box()
+ &Apache::lonhtmlcommon::end_pick_box().'
'."\n"
);
&CloseForm1($request, $fn);
} else {
@@ -941,6 +926,110 @@ sub Archive1 {
.''
);
}
+ return;
+}
+
+sub archive_tools {
+ my ($location_of,$defaults) = @_;
+ my ($compstyle,$canarchive,$cancompress,$numformat,$numcompress,$defext);
+ ($numformat,$numcompress) = (0,0);
+ if ((ref($location_of) eq 'HASH') && (ref($defaults) eq 'HASH')) {
+ foreach my $program ('tar','gzip','bzip2','xz','zip') {
+ foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
+ '/usr/sbin/') {
+ if (-x $dir.$program) {
+ $location_of->{$program} = $dir.$program;
+ last;
+ }
+ }
+ }
+ foreach my $format ('tar','zip') {
+ if (exists($location_of->{$format})) {
+ unless ($canarchive) {
+ $defext = $format;
+ $defaults->{$format} = ' checked="checked"';
+ if ($format eq 'tar') {
+ $compstyle = 'block';
+ } else {
+ $compstyle = 'none';
+ }
+ }
+ $canarchive = 1;
+ $numformat ++;
+ }
+ }
+ foreach my $compress ('gzip','bzip2','xz') {
+ if (exists($location_of->{$compress})) {
+ $numcompress ++;
+ unless ($cancompress) {
+ if ($defext eq 'tar') {
+ if ($compress eq 'gzip') {
+ $defext .= '.gz';
+ } elsif ($compress eq 'bzip2') {
+ $defext .= '.bz2';
+ } else {
+ $defext .= ".$compress";
+ }
+ }
+ $defaults->{$compress} = ' checked="checked"';
+ $cancompress = 1;
+ }
+ }
+ }
+ }
+ if (wantarray) {
+ return ($compstyle,$canarchive,$cancompress,$numformat,$numcompress,$defext);
+ } else {
+ return $defext;
+ }
+}
+
+sub archive_in_progress {
+ my ($earlyout,$idnum);
+ if ($env{'cgi.author.archive'} =~ /^(\d+)_\d+_\d+$/) {
+ my $timestamp = $1;
+ $idnum = $env{'cgi.author.archive'};
+ if (exists($env{'cgi.'.$idnum.'.archive'})) {
+ my $hashref = &Apache::lonnet::thaw_unescape($env{'cgi.'.$idnum.'.archive'});
+ my $lonprtdir = $Apache::lonnet::perlvar{'lonPrtDir'};
+ if (-e $lonprtdir.'/'.$env{'user.name'}.'_'.$env{'user.domain'}.'_archive_'.$idnum.'.txt') {
+ $earlyout = $timestamp;
+ } elsif (ref($hashref) eq 'HASH') {
+ my $suffix = $hashref->{'extension'};
+ if (-e $lonprtdir.'/'.$env{'user.name'}.'_'.$env{'user.domain'}.'_archive_'.$idnum.$suffix) {
+ $earlyout = $timestamp;
+ }
+ }
+ unless ($earlyout) {
+ &Apache::lonnet::delenv('cgi.'.$idnum.'.archive');
+ &Apache::lonnet::delenv('cgi.author.archive');
+ }
+ } else {
+ &Apache::lonnet::delenv('cgi.author.archive');
+ }
+ }
+ return ($earlyout,$idnum);
+}
+
+sub cancel_archive_form {
+ my ($r,$title,$fname,$earlyout,$idnum) = @_;
+ $r->print(''.$title.'
'."\n".
+ '