--- loncom/publisher/lonretrieve.pm 2001/04/03 18:12:57 1.2 +++ loncom/publisher/lonretrieve.pm 2001/05/02 21:35:15 1.8 @@ -11,7 +11,7 @@ # 03/23 Guy Albertelli # 03/24,03/29 Gerd Kortemeyer) # -# 03/31 Gerd Kortemeyer +# 03/31,04/03,05/02 Gerd Kortemeyer package Apache::lonretrieve; @@ -24,21 +24,103 @@ sub phaseone { my ($r,$fn,$uname,$udom)=@_; 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/\/[^\/]+$/\//; - $fn=~/^\/(.+)\.(\w+)$/; + $fn=~/\/([^\/]+)\.(\w+)$/; my $main=$1; my $suffix=$2; - + + if (-e $resfn) { + $r->print('
'. + ''. + ''. + ''. + ''. + ''); my $filename; opendir(DIR,$resdir); while ($filename=readdir(DIR)) { if ($filename=~/^$main\.(\d+)\.$suffix$/) { - $r->print($resdir.' = '.$filename.'
'); + my $version=$1; + my ($rdev,$rino,$rmode,$rnlink, + $ruid,$rgid,$rrdev,$rsize, + $ratime,$rmtime,$rctime, + $rblksize,$rblocks)=stat($resdir.'/'.$filename); + $r->print(''); } } closedir(DIR); + my ($rdev,$rino,$rmode,$rnlink, + $ruid,$rgid,$rrdev,$rsize, + $ratime,$rmtime,$rctime, + $rblksize,$rblocks)=stat($resfn); + $r->print(''. + '
SelectVersionBecame this version on ...Metadata
'.$version.''. + localtime($rmtime).''. + ''. + 'Metadata Version '.$version); + if (&Apache::lonnet::fileembstyle($suffix) eq 'ssi') { + $r->print( + '  Diffs with Version '.$version.''); + } + $r->print('
Current'.localtime($rmtime). + ''. + 'Metadata current version

'. + 'Retrieval of an old version will '. + 'overwrite the file currently in construction space

'. + '

'); +} else { + $r->print('

No previous versions published.

'); +} +} + +sub phasetwo { + my ($r,$fn,$uname,$udom)=@_; + if ($ENV{'form.version'}) { + my $version=$ENV{'form.version'}; + if ($version eq 'new') { + $r->print('

Retrieving current (most recent) version

'); + } else { + $r->print('

Retrieving old version '.$version.'

'); + } + my $logfile; + my $ctarget='/home/'.$uname.'/public_html'.$fn; + my $vfn=$fn; + if ($version ne 'new') { + $vfn=~s/\.(\w+)$/\.$version\.$1/; + } + 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'); + } + print $logfile +"\n\n================= Retrieve ".localtime()." ================\n". +"Version: $version\nSource: $csource\nTarget: $ctarget\n"; + $r->print('

Copying file: '); + if (copy($csource,$ctarget)) { + $r->print('ok

'); + print $logfile "Copied sucessfully.\n\n"; + } else { + my $error=$!; + $r->print('fail, '.$error.'

'); + print $logfile "Copy failed: $error\n\n"; + } + $r->print('Back to '.$fn.''); + } else { + $r->print( + 'Please pick a version to retrieve

'); + &phaseone($r,$fn,$uname,$udom); + } } sub handler { @@ -79,6 +161,7 @@ sub handler { $r->print('

Retrieve previous versions of '.$fn.'

'); if ($ENV{'form.phase'} eq 'two') { + &phasetwo($r,$fn,$uname,$udom); } else { &phaseone($r,$fn,$uname,$udom); } @@ -86,3 +169,6 @@ sub handler { $r->print(''); return OK; } + +1; +__END__