version 1.2, 2001/04/03 18:12:57
|
version 1.4, 2001/04/03 22:03:55
|
Line 11
|
Line 11
|
# 03/23 Guy Albertelli |
# 03/23 Guy Albertelli |
# 03/24,03/29 Gerd Kortemeyer) |
# 03/24,03/29 Gerd Kortemeyer) |
# |
# |
# 03/31 Gerd Kortemeyer |
# 03/31,04/03 Gerd Kortemeyer |
|
|
package Apache::lonretrieve; |
package Apache::lonretrieve; |
|
|
Line 24 sub phaseone {
|
Line 24 sub phaseone {
|
my ($r,$fn,$uname,$udom)=@_; |
my ($r,$fn,$uname,$udom)=@_; |
my $docroot=$r->dir_config('lonDocRoot'); |
my $docroot=$r->dir_config('lonDocRoot'); |
|
|
my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$fn; |
my $urldir='/res/'.$udom.'/'.$uname.$fn; |
|
$urldir=~s/\/[^\/]+$/\//; |
|
|
|
my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn; |
|
my $resdir=$resfn; |
$resdir=~s/\/[^\/]+$/\//; |
$resdir=~s/\/[^\/]+$/\//; |
|
|
$fn=~/^\/(.+)\.(\w+)$/; |
$fn=~/^\/(.+)\.(\w+)$/; |
my $main=$1; |
my $main=$1; |
my $suffix=$2; |
my $suffix=$2; |
|
|
|
$r->print('<form action=/adm/retrieve method=post>'. |
|
'<input type=hidden name=filename value="'.$fn.'">'. |
|
'<input type=hidden name=phase value=two>'. |
|
'<table border=2><tr><th>Select</th><th>Version</th>'. |
|
'<th>Became this version on ...</th>'. |
|
'<th>Metadata</th></tr>'); |
my $filename; |
my $filename; |
opendir(DIR,$resdir); |
opendir(DIR,$resdir); |
while ($filename=readdir(DIR)) { |
while ($filename=readdir(DIR)) { |
if ($filename=~/^$main\.(\d+)\.$suffix$/) { |
if ($filename=~/^$main\.(\d+)\.$suffix$/) { |
$r->print($resdir.' = '.$filename.'<br>'); |
my $version=$1; |
|
my ($rdev,$rino,$rmode,$rnlink, |
|
$ruid,$rgid,$rrdev,$rsize, |
|
$ratime,$rmtime,$rctime, |
|
$rblksize,$rblocks)=stat($resdir.'/'.$filename); |
|
$r->print('<tr><td><input type=radio name=version value="'. |
|
$version.'"></td><th>'.$version.'</th><td>'. |
|
localtime($rmtime).'</td><td>'. |
|
'<a href="'.$urldir.$filename.'.meta" target=cat>'. |
|
'Metadata Version '.$version.'</a></td></tr>'); |
} |
} |
} |
} |
closedir(DIR); |
closedir(DIR); |
|
my ($rdev,$rino,$rmode,$rnlink, |
|
$ruid,$rgid,$rrdev,$rsize, |
|
$ratime,$rmtime,$rctime, |
|
$rblksize,$rblocks)=stat($resfn); |
|
$r->print('<tr><td><input type=radio name=version value="new"></td>'. |
|
'<th>Current</th><td>'.localtime($rmtime). |
|
'</td><td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'. |
|
'Metadata current version</a></td></tr></table><p>'. |
|
'<font size=+1 color=red>Retrieval of an old version will '. |
|
'overwrite the file currently in construction space</font><p>'. |
|
'<input type=submit value="Retrieve version"></form>'); |
|
} |
|
|
|
sub phasetwo { |
|
my ($r,$fn,$uname,$udom)=@_; |
|
if ($ENV{'form.version'}) { |
|
my $version=$ENV{'form.version'}; |
|
if ($version eq 'new') { |
|
$r->print('<h3>Retrieving current (most recent) version</h3>'); |
|
} else { |
|
$r->print('<h3>Retrieving old version '.$version.'</h3>'); |
|
} |
|
my $logfile; |
|
my $ctarget='/home/'.$uname.'/public_html'.$fn; |
|
unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) { |
|
$r->print( |
|
'<font color=red>No write permission to user directory, FAIL</font>'); |
|
} |
|
print $logfile |
|
"\n\n================= Retrieve ".localtime()." ================\n". |
|
"Version $version\n\n"; |
|
|
|
} else { |
|
$r->print( |
|
'<font size=+1 color=red>Please pick a version to retrieve</font><p>'); |
|
&phaseone($r,$fn,$uname,$udom); |
|
} |
} |
} |
|
|
sub handler { |
sub handler { |
Line 79 sub handler {
|
Line 135 sub handler {
|
$r->print('<h1>Retrieve previous versions of <tt>'.$fn.'</tt></h1>'); |
$r->print('<h1>Retrieve previous versions of <tt>'.$fn.'</tt></h1>'); |
|
|
if ($ENV{'form.phase'} eq 'two') { |
if ($ENV{'form.phase'} eq 'two') { |
|
&phasetwo($r,$fn,$uname,$udom); |
} else { |
} else { |
&phaseone($r,$fn,$uname,$udom); |
&phaseone($r,$fn,$uname,$udom); |
} |
} |