--- loncom/publisher/lonretrieve.pm 2005/04/07 06:56:27 1.27 +++ loncom/publisher/lonretrieve.pm 2006/09/13 21:43:26 1.31 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to retrieve an old version of a file # -# $Id: lonretrieve.pm,v 1.27 2005/04/07 06:56:27 albertel Exp $ +# $Id: lonretrieve.pm,v 1.31 2006/09/13 21:43:26 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,53 +51,75 @@ sub phaseone { my $resdir=$resfn; $resdir=~s/\/[^\/]+$/\//; - $fn=~/\/([^\/]+)\.(\w+)$/; - my $main=$1; - my $suffix=$2; - + my ($main,$suffix,$is_meta) = &get_file_info($fn); + if (-e $resfn) { $r->print('
'. ''. ''. ''. - ''. - ''); - my $filename; + ''); + if (!$is_meta) { + $r->print(''); + } + if ($is_meta + || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') { + $r->print(''); + } + $r->print(''); + opendir(DIR,$resdir); - while ($filename=readdir(DIR)) { + 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 $rmtime=&Apache::lonnet::metadata($resdir.'/'.$filename,'lastrevisiondate'); $r->print(''); + + if (!$is_meta) { + $r->print(''); + } + if ($is_meta + || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') { $r->print( - '  '.&mt('Diffs with Version').' '.$version.''); + '">'.&mt('Diffs with Version').' '.$version. + ''); } - $r->print(''); + $r->print(''); } } closedir(DIR); my $rmtime=&Apache::lonnet::metadata($resfn,'lastrevisiondate'); $r->print(''. - ''); + if (!$is_meta) { + $r->print(''); + } + if ($is_meta + || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') { $r->print( - '  '.&mt('Diffs with current Version').''); + '">'.&mt('Diffs with current Version').''); } - $r->print('
'.&mt('Select').''. &mt('Version').''.&mt('Published on ...').''.&mt('Metadata').'
'.&mt('Published on ...').''.&mt('Metadata').''.&mt('Diffs').'
'.&mt('Previously published version').' '.$version.''. - localtime($rmtime).''. - ''. - &mt('Metadata Version').' '.$version.''); - if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') { + localtime($rmtime).''. + &mt('Metadata Version').' '.$version.'
'.&mt('Currently public version').''.localtime($rmtime). - ''. - &mt('Metadata current version').''); - if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') { + ''.&mt('Currently published version').''.localtime($rmtime). + ''. + &mt('Metadata current version').'

'. + $r->print('

'. ''. &mt('Retrieval of an old version will overwrite the file currently in construction space').'

'. '

'); @@ -118,14 +140,21 @@ sub phasetwo { } else { $r->print('

'.&mt('Retrieving old version').' '.$version.'

'); } + my ($main,$suffix,$is_meta) = &get_file_info($fn); + my $logfile; my $ctarget='/home/'.$uname.'/public_html'.$fn; my $vfn=$fn; if ($version ne 'new') { - $vfn=~s/\.(\w+)$/\.$version\.$1/; + $vfn=~s/\.(\Q$suffix\E)$/\.$version\.$1/; } + my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn; - unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) { + + my $logname = $ctarget; + if ($is_meta) { $logname =~ s/\.meta$//; } + $logname = $ctarget.'.log'; + unless ($logfile=Apache::File->new('>>'.$logname)) { $r->print( ''.&mt('No write permission to user directory, FAIL').''); } @@ -133,7 +162,7 @@ sub phasetwo { "\n\n================= Retrieve ".localtime()." ================\n". "Version: $version\nSource: $csource\nTarget: $ctarget\n"; $r->print('

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

'); print $logfile "Copied sucessfully.\n\n"; } else { @@ -150,6 +179,18 @@ sub phasetwo { } } +sub get_file_info { + my ($fn) = @_; + my ($main,$suffix) = ($fn=~/\/([^\/]+)\.(\w+)$/); + my $is_meta=0; + if ($suffix eq 'meta') { + $is_meta = 1; + ($main,$suffix) = ($main=~/(.+)\.(\w+)$/); + $suffix .= '.meta'; + } + return ($main,$suffix,$is_meta); +} + # ---------------------------------------------------------------- Main Handler sub handler { @@ -197,9 +238,7 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - $r->print('LON-CAPA Construction Space'); - - $r->print(&Apache::loncommon::bodytag('Retrieve Published Resources')); + $r->print(&Apache::loncommon::start_page('Retrieve Published Resources')); $r->print('

'.&mt('Retrieve previous versions of').' '.$fn.'

'); @@ -217,7 +256,7 @@ sub handler { &phaseone($r,$fn,$uname,$udom); } - $r->print(''); + $r->print(&Apache::loncommon::end_page()); return OK; }