Select | Version | '.
- 'Became this version on ... | '.
- 'Metadata |
');
- my $filename;
+ ''.&mt('Select').' | '.
+ &mt('Version').' | '.
+ ''.&mt('Published on ...').' | '.
+ ''.&mt('Metadata').' |
');
+
opendir(DIR,$resdir);
- while ($filename=readdir(DIR)) {
- if ($filename=~/^$main\.(\d+)\.$suffix$/) {
+ my @files = grep(/^\Q$main\E\.(\d+)\.\Q$suffix\E$/,readdir(DIR));
+ @files = sort {
+ my ($aver) = ($a=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/);
+ my ($bver) = ($b=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/);
+ return $aver <=> $bver;
+ } (@files);
+ closedir(DIR);
+
+ foreach my $filename (@files) {
+ if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
my $version=$1;
- my ($rdev,$rino,$rmode,$rnlink,
- $ruid,$rgid,$rrdev,$rsize,
- $ratime,$rmtime,$rctime,
- $rblksize,$rblocks)=stat($resdir.'/'.$filename);
+ my $rmtime=&Apache::lonnet::metadata($resdir.'/'.$filename,'lastrevisiondate');
$r->print(' | '.$version.' | '.
+ $version.'"> | '.&mt('Previously published version').' '.$version.' | '.
localtime($rmtime).' | '.
''.
- 'Metadata Version '.$version.'');
- if (&Apache::lonnet::fileembstyle($suffix) eq 'ssi') {
+ &mt('Metadata Version').' '.$version.'');
+ if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
$r->print(
' Diffs with Version '.$version.'');
+ '&versiontwo=priv&versionone='.$version.
+ '">'.&mt('Diffs with Version').' '.$version.'');
}
$r->print(' |
');
}
}
closedir(DIR);
- my ($rdev,$rino,$rmode,$rnlink,
- $ruid,$rgid,$rrdev,$rsize,
- $ratime,$rmtime,$rctime,
- $rblksize,$rblocks)=stat($resfn);
+ my $rmtime=&Apache::lonnet::metadata($resfn,'lastrevisiondate');
$r->print(' | '.
- 'Current | '.localtime($rmtime).
+ ' | '.&mt('Currently published version').' | '.localtime($rmtime).
' | '.
- 'Metadata current version');
- if (&Apache::lonnet::fileembstyle($suffix) eq 'ssi') {
+ &mt('Metadata current version').'');
+ if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
$r->print(
' Diffs with current Version');
+ '&versiontwo=priv'.
+ '">'.&mt('Diffs with current Version').'');
}
$r->print(' |
---|
'.
- 'Retrieval of an old version will '.
- 'overwrite the file currently in construction space
'.
- '');
+ ''.
+&mt('Retrieval of an old version will overwrite the file currently in construction space').'
'.
+ '');
} else {
- $r->print('
No previous versions published.
');
+ $r->print(''.&mt('No previous versions published.').'
');
}
+ $r->print(''.&mt('Back to').' '.$fn.
+ '
');
}
+# ---------------------------------- Interface for presenting specified version
sub phasetwo {
my ($r,$fn,$uname,$udom)=@_;
- if ($ENV{'form.version'}) {
- my $version=$ENV{'form.version'};
+ if ($env{'form.version'}) {
+ my $version=$env{'form.version'};
if ($version eq 'new') {
- $r->print('Retrieving current (most recent) version
');
+ $r->print(''.&mt('Retrieving current (most recent) version').'
');
} else {
- $r->print('Retrieving old version '.$version.'
');
+ $r->print(''.&mt('Retrieving old version').' '.$version.'
');
}
my $logfile;
my $ctarget='/home/'.$uname.'/public_html'.$fn;
@@ -135,12 +135,12 @@ sub phasetwo {
my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn;
unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) {
$r->print(
- 'No write permission to user directory, FAIL');
+ ''.&mt('No write permission to user directory, FAIL').'');
}
print $logfile
"\n\n================= Retrieve ".localtime()." ================\n".
"Version: $version\nSource: $csource\nTarget: $ctarget\n";
- $r->print('Copying file: ');
+ $r->print('
'.&mt('Copying file').': ');
if (copy($csource,$ctarget)) {
$r->print('ok
');
print $logfile "Copied sucessfully.\n\n";
@@ -150,14 +150,15 @@ sub phasetwo {
print $logfile "Copy failed: $error\n\n";
}
$r->print('Back to '.$fn.'');
+ '">'.&mt('Back to').' '.$fn.'');
} else {
$r->print(
- 'Please pick a version to retrieve
');
+ ''.&mt('Please pick a version to retrieve').'
');
&phaseone($r,$fn,$uname,$udom);
}
}
+# ---------------------------------------------------------------- Main Handler
sub handler {
my $r=shift;
@@ -167,29 +168,20 @@ sub handler {
# Get query string for limited number of parameters
- map {
- my ($name, $value) = split(/=/,$_);
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- if ($name eq 'filename') {
- unless ($ENV{'form.'.$name}) {
- $ENV{'form.'.$name}=$value;
- }
- }
- } (split(/&/,$ENV{'QUERY_STRING'}));
-
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['filename']);
- if ($ENV{'form.filename'}) {
- $fn=$ENV{'form.filename'};
+ if ($env{'form.filename'}) {
+ $fn=$env{'form.filename'};
$fn=~s/^http\:\/\/[^\/]+//;
} else {
- $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
+ $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
' unspecified filename for retrieval', $r->filename);
return HTTP_NOT_FOUND;
}
unless ($fn) {
- $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
+ $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
' trying to retrieve non-existing file', $r->filename);
return HTTP_NOT_FOUND;
}
@@ -202,7 +194,7 @@ sub handler {
&Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
unless (($uname) && ($udom)) {
$r->log_reason($uname.' at '.$udom.
- ' trying to publish file '.$ENV{'form.filename'}.
+ ' trying to publish file '.$env{'form.filename'}.
' ('.$fn.') - not authorized',
$r->filename);
return HTTP_NOT_ACCEPTABLE;
@@ -210,24 +202,24 @@ sub handler {
$fn=~s/\/\~(\w+)//;
- $r->content_type('text/html');
+ &Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
$r->print('
LON-CAPA Construction Space');
- $r->print(
- '');
+ $r->print(&Apache::loncommon::bodytag('Retrieve Published Resources'));
- $r->print('Retrieve previous versions of '.$fn.'
');
+ $r->print(''.&mt('Retrieve previous versions of').' '.$fn.'
');
- if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
- $r->print('Co-Author: '.$uname.' at '.$udom.
+ if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
+ $r->print(''.&mt('Co-Author').': '.$uname.
+ &mt(' at ').$udom.
'
');
}
- if ($ENV{'form.phase'} eq 'two') {
+ if ($env{'form.phase'} eq 'two') {
&phasetwo($r,$fn,$uname,$udom);
} else {
&phaseone($r,$fn,$uname,$udom);
@@ -239,3 +231,68 @@ sub handler {
1;
__END__
+
+=head1 NAME
+
+Apache::lonretrieve - retrieves an old version of a file
+
+=head1 SYNOPSIS
+
+Invoked by /etc/httpd/conf/srm.conf:
+
+
+ PerlAccessHandler Apache::lonacc
+ SetHandler perl-script
+ PerlHandler Apache::lonretrieve
+ ErrorDocument 403 /adm/login
+ ErrorDocument 404 /adm/notfound.html
+ ErrorDocument 406 /adm/unauthorized.html
+ ErrorDocument 500 /adm/errorhandler
+
+
+=head1 INTRODUCTION
+
+This module retrieves an old published version of a file.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 HANDLER SUBROUTINE
+
+This routine is called by Apache and mod_perl.
+
+=over 4
+
+=item *
+
+Get query string for limited number of parameters
+
+=item *
+
+Start page output
+
+=item *
+
+print phase relevant output
+
+=item *
+
+(phase one is to select version; phase two retrieves version)
+
+=back
+
+=head1 OTHER SUBROUTINES
+
+=over 4
+
+=item *
+
+phaseone() : Interface for selecting previous version.
+
+=item *
+
+phasetwo() : Interface for presenting specified version.
+
+=back
+
+=cut