--- loncom/publisher/lonretrieve.pm 2001/04/03 21:12:39 1.3 +++ loncom/publisher/lonretrieve.pm 2001/04/10 19:45:37 1.6 @@ -31,10 +31,11 @@ sub phaseone { my $resdir=$resfn; $resdir=~s/\/[^\/]+$/\//; - $fn=~/^\/(.+)\.(\w+)$/; + $fn=~/\/([^\/]+)\.(\w+)$/; my $main=$1; my $suffix=$2; - + + if (-e $resfn) { $r->print('
'. ''. ''. @@ -66,7 +67,53 @@ sub phaseone { '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 { @@ -107,6 +154,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); }