--- loncom/publisher/loncfile.pm 2023/07/14 23:20:15 1.127 +++ loncom/publisher/loncfile.pm 2024/08/24 22:09:30 1.129.2.1 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.127 2023/07/14 23:20:15 raeburn Exp $ +# $Id: loncfile.pm,v 1.129.2.1 2024/08/24 22:09:30 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -70,10 +70,10 @@ use HTML::Entities(); use Apache::Constants qw(:common :http :methods); use Apache::lonnet; use Apache::loncommon(); +use Apache::lonhtmlcommon; use Apache::lonlocal; use LONCAPA qw(:DEFAULT :match); - my $DEBUG=0; my $r; # Needs to be global for some stuff RF. @@ -819,6 +819,219 @@ 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,%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.').'
'."\n". + ''. + &mt('At least one of the two is needed in order to be able to create an archive file for: [_1].', + &display($fn))."\n". + ''); + } elsif (-e $fn) { + $request->print(''."\n". + &Apache::lonhtmlcommon::start_pick_box(). + &Apache::lonhtmlcommon::row_title(&mt('Directory')). + &display($fn). + &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title(&mt('Options'). + &Apache::loncommon::help_open_topic('Archiving_Directory_Options')). + ''. + ''. + ''."\n". + ''."\n". + ''."\n". + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::end_pick_box().'' + .&mt('No such directory: [_1]', + &display($fn)) + .'
' + ); + } + 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('