version 1.127, 2023/07/14 23:20:15
|
version 1.128, 2024/05/13 13:55:50
|
Line 70 use HTML::Entities();
|
Line 70 use HTML::Entities();
|
use Apache::Constants qw(:common :http :methods); |
use Apache::Constants qw(:common :http :methods); |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon(); |
use Apache::loncommon(); |
|
use Apache::lonhtmlcommon; |
use Apache::lonlocal; |
use Apache::lonlocal; |
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
|
|
|
|
my $DEBUG=0; |
my $DEBUG=0; |
my $r; # Needs to be global for some stuff RF. |
my $r; # Needs to be global for some stuff RF. |
|
|
Line 819 sub Decompress1 {
|
Line 819 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; |
|
} |
|
} |
|
if (!$canarchive) { |
|
$request->print('<p class="LC_error">'. |
|
&mt('This LON-CAPA instance does not seem to have either tar or zip installed.').'</p>'. |
|
'<span class="LC_warning">'. |
|
&mt('At least one of the two is needed in order to be able to create an archive file for: [_1].', |
|
&display($fn)). |
|
'</span></form>'); |
|
} elsif (-e $fn) { |
|
$request->print(&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')). |
|
'<fieldset><legend>'.&mt('Recurse').'</legend>'. |
|
'<span class="LC_nobreak"><label><input type="checkbox" name="recurse" /> '. |
|
&mt('include subdirectories').'</label></span>'. |
|
'</fieldset>'. |
|
'<fieldset><legend>'.&mt('File types (extensions) to include').(' 'x2). |
|
'<span style="text-decoration:line-through">'.(' 'x5).'</span>'.(' 'x2). |
|
'<input type="button" name="checkall" value="'.&mt('check all'). |
|
'" style="height:20px;" onclick="checkAll(document.phaseone.filetype);" />'. |
|
(' 'x2). |
|
'<input type="button" name="uncheckall" value="'.&mt('uncheck all'). |
|
'" style="height:20px;" onclick="uncheckAll(document.phaseone.filetype);" /></legend>'. |
|
'<table>'); |
|
my $rem; |
|
my $numinrow = 6; |
|
for (my $i=0; $i<@posstypes; $i++) { |
|
my $rem = $i%($numinrow); |
|
if ($rem == 0) { |
|
if ($i > 0) { |
|
$request->print('</tr>'."\n"); |
|
} |
|
$request->print('<tr>'."\n"); |
|
} |
|
$request->print('<td class="LC_left_item">'. |
|
'<span class="LC_nobreak"><label>'. |
|
'<input type="checkbox" name="filetype" '. |
|
'value="'.$posstypes[$i].'" /> '. |
|
$posstypes[$i].'</label></span></td>'."\n"); |
|
} |
|
$rem = scalar(@posstypes)%($numinrow); |
|
my $colsleft; |
|
if ($rem) { |
|
$colsleft = $numinrow - $rem; |
|
} |
|
if ($colsleft > 1 ) { |
|
$request->print('<td colspan="'.$colsleft.'" class="LC_left_item">'. |
|
' </td>'."\n"); |
|
} elsif ($colsleft == 1) { |
|
$request->print('<td class="LC_left_item"> </td>'."\n"); |
|
} |
|
$request->print('</tr></table>'."\n". |
|
'</fieldset>'. |
|
'<fieldset><legend>'.&mt('Archive file format').'</legend>'); |
|
foreach my $possfmt ('tar','zip') { |
|
if (exists($location_of{$possfmt})) { |
|
$request->print('<span class="LC_nobreak">'. |
|
'<label><input type="radio" name="format" value="'.$possfmt.'"'. |
|
$default{$possfmt}.' onclick="toggleCompression(this.form);" /> '. |
|
$possfmt.'</label></span> '); |
|
} |
|
} |
|
$request->print('</fieldset>'."\n". |
|
'<fieldset style="display:'.$compstyle.'" id="tar_compression">'. |
|
'<legend>'.&mt('Compression to apply to tar file').'</legend>'. |
|
'<span class="LC_nobreak">'); |
|
if ($cancompress) { |
|
foreach my $compress ('gzip','bzip2','xz') { |
|
if (exists($location_of{$compress})) { |
|
$request->print('<label><input type="radio" name="compress" value="'.$compress.'"'. |
|
$default{$compress}.' />'.$compress.'</label> '); |
|
} |
|
} |
|
} else { |
|
$request->print('<span class="LC_warning">'. |
|
&mt('This LON-CAPA instance does not seem to have gzip, bzip2 or xz installed.'). |
|
'<br />'.&mt('No compression will be used.').'</span>'); |
|
} |
|
$request->print('</fieldset>'. |
|
&Apache::lonhtmlcommon::row_closure(1). |
|
&Apache::lonhtmlcommon::end_pick_box() |
|
); |
|
&CloseForm1($request, $fn); |
|
} else { |
|
$request->print('<p class="LC_error">' |
|
.&mt('No such directory: [_1]', |
|
&display($fn)) |
|
.'</p></form>' |
|
); |
|
} |
|
} |
|
|
=pod |
=pod |
|
|
=item NewFile1 |
=item NewFile1 |
Line 994 sub phaseone {
|
Line 1118 sub phaseone {
|
'</a></p>'); |
'</a></p>'); |
return; |
return; |
} |
} |
$r->print('<form action="/adm/cfile" method="post">'. |
$r->print('<form action="/adm/cfile" method="post" name="phaseone">'. |
'<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'. |
'<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'. |
'<input type="hidden" name="phase" value="two" />'. |
'<input type="hidden" name="phase" value="two" />'. |
'<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'); |
'<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'); |
Line 1033 sub phaseone {
|
Line 1157 sub phaseone {
|
&Delete1($r, $uname, $udom, $fn); |
&Delete1($r, $uname, $udom, $fn); |
} elsif ($env{'form.action'} eq 'decompress') { |
} elsif ($env{'form.action'} eq 'decompress') { |
&Decompress1($r, $uname, $udom, $fn); |
&Decompress1($r, $uname, $udom, $fn); |
|
} elsif ($env{'form.action'} eq 'archive') { |
|
&Archive1($r,$fn); |
} elsif ($env{'form.action'} eq 'copy') { |
} elsif ($env{'form.action'} eq 'copy') { |
if ($newfilename) { |
if ($newfilename) { |
&Copy1($r, $uname, $udom, $fn, $newfilename); |
&Copy1($r, $uname, $udom, $fn, $newfilename); |
Line 1310 sub decompress2 {
|
Line 1436 sub decompress2 {
|
return 1; |
return 1; |
} |
} |
|
|
|
sub Archive2 { |
|
my ($r,$name,$udom,$fn,$identifier) = @_; |
|
my %options = ( |
|
dir => $fn, |
|
); |
|
my @filetypes = 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 (@include,%oktypes); |
|
map { $oktypes{$_} = 1; } @filetypes; |
|
my @posstypes = &Apache::loncommon::get_env_multiple('form.filetype'); |
|
foreach my $type (@posstypes) { |
|
if ($oktypes{$type}) { |
|
push(@include,$type); |
|
} |
|
} |
|
if (scalar(@include) == scalar(@filetypes)) { |
|
$options{'types'} = 'all'; |
|
} else { |
|
$options{'types'} = join(',',@include); |
|
} |
|
if (exists($env{'form.recurse'})) { |
|
$options{'recurse'} = 1; |
|
} |
|
if (exists($env{'form.encrypt'})) { |
|
if ($env{'form.enckey'} ne '') { |
|
$options{'encrypt'} = $env{'form.enckey'}; |
|
} |
|
} |
|
$options{'format'} = 'tar'; |
|
$options{'compress'} = 'gzip'; |
|
if ((exists($env{'form.format'})) && $env{'form.format'} =~ /^zip$/i) { |
|
$options{'format'} = 'zip'; |
|
delete($options{'compress'}); |
|
} elsif ((exists($env{'form.compress'})) && ($env{'form.compress'} =~ /^(xz|bzip2)$/i)) { |
|
$options{'compress'} = lc($env{'form.compress'}); |
|
} |
|
my $key = 'cgi.'.$identifier.'.archive'; |
|
my $storestring = &Apache::lonnet::freeze_escape(\%options); |
|
&Apache::lonnet::appenv({$key => $storestring}); |
|
return 1; |
|
} |
|
|
=pod |
=pod |
|
|
=item phasetwo($r, $fn, $uname, $udom) |
=item phasetwo($r, $fn, $uname, $udom,$identifier) |
|
|
Controls the phase 2 processing of file management |
Controls the phase 2 processing of file management |
requests for construction space. In phase one, the user |
requests for construction space. In phase one, the user |
Line 1343 Parameters:
|
Line 1510 Parameters:
|
=cut |
=cut |
|
|
sub phasetwo { |
sub phasetwo { |
my ($r,$fn,$uname,$udom)=@_; |
my ($r,$fn,$uname,$udom,$identifier)=@_; |
|
|
&Debug($r, "loncfile - Entering phase 2 for $fn"); |
&Debug($r, "loncfile - Entering phase 2 for $fn"); |
|
|
Line 1380 sub phasetwo {
|
Line 1547 sub phasetwo {
|
return ; |
return ; |
} |
} |
$dest = $dir."/."; |
$dest = $dir."/."; |
|
} elsif ($env{'form.action'} eq 'archive') { |
|
&Archive2($r,$uname,$udom,$fn,$identifier); |
|
return; |
} elsif ($env{'form.action'} eq 'rename' || |
} elsif ($env{'form.action'} eq 'rename' || |
$env{'form.action'} eq 'move') { |
$env{'form.action'} eq 'move') { |
if($env{'form.newfilename'}) { |
if($env{'form.newfilename'}) { |
Line 1462 sub handler {
|
Line 1632 sub handler {
|
&Debug($r, "test: $env{'form.filename'}"); |
&Debug($r, "test: $env{'form.filename'}"); |
$fn=&unescape($env{'form.filename'}); |
$fn=&unescape($env{'form.filename'}); |
$fn=&URLToPath($fn); |
$fn=&URLToPath($fn); |
} elsif($ENV{'QUERY_STRING'} && $env{'form.phase'} ne 'two') { |
} elsif($ENV{'QUERY_STRING'} && $env{'form.phase'} ne 'two') { |
#Just hijack the script only the first time around to inject the |
#Just hijack the script only the first time around to inject the |
#correct information for further processing |
#correct information for further processing |
$fn=&unescape($env{'form.decompress'}); |
$fn=&unescape($env{'form.decompress'}); |
Line 1501 sub handler {
|
Line 1671 sub handler {
|
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
|
|
my (%loaditem,$js); |
my ($js,$identifier); |
|
my $args = {}; |
|
|
if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) { |
if (($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && |
|
(($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport'))) { |
my $newdirname = $env{'form.newfilename'}; |
my $newdirname = $env{'form.newfilename'}; |
$js = qq| |
&js_escape(\$newdirname); |
|
$js = <<"ENDJS"; |
<script type="text/javascript"> |
<script type="text/javascript"> |
|
// <![CDATA[ |
function writeDone() { |
function writeDone() { |
window.focus(); |
window.focus(); |
opener.document.info.newdir.value = "$newdirname"; |
opener.document.info.newdir.value = "$newdirname"; |
setTimeout("self.close()",10000); |
setTimeout("self.close()",10000); |
} |
} |
</script> |
// ]]> |
|; |
</script> |
$loaditem{'onload'} = "writeDone()"; |
ENDJS |
|
$args->{'add_entries'} = { onload => "writeDone()" }; |
|
} elsif (($env{'form.action'} eq 'archive') && |
|
($env{'environment.authorarchive'})) { |
|
if ($env{'form.phase'} eq 'two') { |
|
$identifier = &Apache::loncommon::get_cgi_id(); |
|
$args->{'redirect'} = [0,"/cgi-bin/archive.pl?$identifier"]; |
|
} else { |
|
my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript(); |
|
$js = <<"ENDJS"; |
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
function toggleCompression(form) { |
|
if (document.getElementById('tar_compression')) { |
|
if (form.format.length > 1) { |
|
for (var i=0; i<form.format.length; i++) { |
|
if (form.format[i].checked) { |
|
if (form.format[i].value == 'zip') { |
|
document.getElementById('tar_compression').style.display = 'none'; |
|
} else if (form.format[i].value == 'tar') { |
|
document.getElementById('tar_compression').style.display = 'block'; |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
function resetForm() { |
|
if (document.phaseone.filetype.length) { |
|
for (var i=0; i<document.phaseone.filetype.length; i++) { |
|
document.phaseone.filetype[i].checked = false; |
|
} |
} |
} |
|
if (document.getElementById('tar_compression')) { |
|
if (document.phaseone.format.length) { |
|
document.getElementById('tar_compression').style.display = 'block'; |
|
for (var i=0; i<document.phaseone.format.length; i++) { |
|
if (document.phaseone.format[i].value == 'tar') { |
|
document.phaseone.format[i].checked = true; |
|
} else { |
|
document.phaseone.format[i].checked = false; |
|
} |
|
} |
|
} |
|
if (document.phaseone.compress.length) { |
|
for (var i=0; i<document.phaseone.compress.length; i++) { |
|
if (document.phaseone.compress[i].value == 'gzip') { |
|
document.phaseone.compress[i].checked = true; |
|
} else { |
|
document.phaseone.compress[i].checked = false; |
|
} |
|
} |
|
} |
|
} |
|
document.phaseone.recurse.checked = false; |
|
} |
|
|
|
$check_uncheck_js |
|
|
|
// ]]> |
|
</script> |
|
|
|
ENDJS |
|
$args->{'add_entries'} = { onload => "resetForm()" }; |
|
} |
|
} |
my $londocroot = $r->dir_config('lonDocRoot'); |
my $londocroot = $r->dir_config('lonDocRoot'); |
my $trailfile = $fn; |
my $trailfile = $fn; |
$trailfile =~ s{^/(priv/)}{$londocroot/$1}; |
$trailfile =~ s{^/(priv/)}{$londocroot/$1}; |
Line 1546 function writeDone() {
|
Line 1786 function writeDone() {
|
'href' => '', |
'href' => '', |
}); |
}); |
|
|
$r->print(&Apache::loncommon::start_page($title, |
$r->print(&Apache::loncommon::start_page($title,$js,$args) |
$js, |
|
{'add_entries' => \%loaditem,}) |
|
.&Apache::lonhtmlcommon::breadcrumbs() |
.&Apache::lonhtmlcommon::breadcrumbs() |
.&Apache::loncommon::head_subbox( |
.&Apache::loncommon::head_subbox( |
&Apache::loncommon::CSTR_pageheader($trailfile)) |
&Apache::loncommon::CSTR_pageheader($trailfile)) |
); |
); |
|
|
$r->print('<p>'.&mt('Location').': '.&display($fn).'</p>'); |
unless ($env{'form.action'} eq 'archive') { |
|
$r->print('<p>'.&mt('Location').': '.&display($fn).'</p>'); |
|
} |
|
|
if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { |
if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { |
unless ($crsauthor) { |
unless ($crsauthor) { |
Line 1573 function writeDone() {
|
Line 1813 function writeDone() {
|
'move' => 'Move', |
'move' => 'Move', |
'newdir' => 'New Directory', |
'newdir' => 'New Directory', |
'decompress' => 'Decompress', |
'decompress' => 'Decompress', |
|
'archive' => 'Export directory to archive file', |
'copy' => 'Copy', |
'copy' => 'Copy', |
'newfile' => 'New Resource', |
'newfile' => 'New Resource', |
'newhtmlfile' => 'New Resource', |
'newhtmlfile' => 'New Resource', |
Line 1604 function writeDone() {
|
Line 1845 function writeDone() {
|
); |
); |
return OK; |
return OK; |
} |
} |
|
if ($env{'form.action'} eq 'archive') { |
|
$r->print('<p>'.&mt('Location').': '.&display($fn).'</p>'."\n". |
|
'<p class="LC_error">'. |
|
&mt('Export to an archive file is not permitted in Course Authoring Space'). |
|
'</p>'."\n". |
|
&Apache::loncommon::end_page()); |
|
return OK; |
|
} |
|
} elsif ($env{'form.action'} eq 'archive') { |
|
unless ($env{'environment.authorarchive'}) { |
|
$r->print('<p>'.&mt('Location').': '.&display($fn).'</p>'."\n". |
|
'<p class="LC_error">'. |
|
&mt('You do not have permission to export to an archive file in this Authoring Space'). |
|
'</p>'."\n". |
|
&Apache::loncommon::end_page()); |
|
return OK; |
|
} |
} |
} |
$r->print('<h2>'.$action{$env{'form.action'}}.'</h2>'); |
$r->print('<h2>'.$action{$env{'form.action'}}.'</h2>'); |
} else { |
} else { |
Line 1617 function writeDone() {
|
Line 1875 function writeDone() {
|
|
|
if ($env{'form.phase'} eq 'two') { |
if ($env{'form.phase'} eq 'two') { |
&Debug($r, "loncfile::handler entering phase2"); |
&Debug($r, "loncfile::handler entering phase2"); |
&phasetwo($r,$fn,$uname,$udom); |
&phasetwo($r,$fn,$uname,$udom,$identifier); |
} else { |
} else { |
&Debug($r, "loncfile::handler entering phase1"); |
&Debug($r, "loncfile::handler entering phase1"); |
&phaseone($r,$fn,$uname,$udom); |
&phaseone($r,$fn,$uname,$udom); |