--- loncom/publisher/lonretrieve.pm 2008/11/10 14:11:08 1.35 +++ loncom/publisher/lonretrieve.pm 2013/06/07 16:07:49 1.52 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to retrieve an old version of a file # -# $Id: lonretrieve.pm,v 1.35 2008/11/10 14:11:08 jms Exp $ +# $Id: lonretrieve.pm,v 1.52 2013/06/07 16:07:49 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,7 +99,6 @@ use strict; use Apache::File; use File::Copy; use Apache::Constants qw(:common :http :methods); -use Apache::loncacc; use Apache::loncommon(); use Apache::lonlocal; use Apache::lonnet; @@ -108,20 +107,18 @@ use LONCAPA(); # ------------------------------------ Interface for selecting previous version sub phaseone { my ($r,$fn,$uname,$udom)=@_; - my $docroot=$r->dir_config('lonDocRoot'); - my $urldir='/res/'.$udom.'/'.$uname.$fn; - $urldir=~s/\/[^\/]+$/\//; + my $urldir = "/res/$udom/$uname".$fn; + my $resfn = $r->dir_config('lonDocRoot').$urldir; - my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn; - my $resdir=$resfn; - $resdir=~s/\/[^\/]+$/\//; + $urldir =~ s{[^/]+$}{}; + my $resdir = $r->dir_config('lonDocRoot').$urldir; my ($main,$suffix,$is_meta) = &get_file_info($fn); if (-e $resfn) { - $r->print('
'. - ''. + $r->print(''. + ''. ''. &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). @@ -152,21 +149,22 @@ sub phaseone { my $rmtime=&Apache::lonnet::metadata($resdir.'/'.$filename,'lastrevisiondate'); $r->print(&Apache::loncommon::start_data_table_row(). ''.&mt('Previously published version').' '.$version.''. - localtime($rmtime).''); + $version.'" />'.&mt('Previously published version').' '.$version.''. + ''.&Apache::lonlocal::locallocaltime($rmtime).''); if (!$is_meta) { - $r->print(''. - &mt('Metadata Version').' '.$version.''); + $r->print(''. + &Apache::loncommon::modal_link($urldir.$filename.'.meta', + &mt('Metadata Version [_1]',$version),550,450).''); } if ($is_meta || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') { - $r->print( - ''.&mt('Diffs with Version').' '.$version. - ''); + $r->print(''. + &Apache::loncommon::modal_link( + '/adm/diff?filename=/priv/'.$udom.'/'.$uname.$fn. + '&versiontwo=priv&versionone='.$version, + &mt('Diffs with Version [_1]',$version),550,450). + ''); } $r->print(&Apache::loncommon::end_data_table_row()); } @@ -175,35 +173,38 @@ sub phaseone { my $rmtime=&Apache::lonnet::metadata($resfn,'lastrevisiondate'); $r->print(&Apache::loncommon::start_data_table_row(). ''. - ''.&mt('Currently published version').''.localtime($rmtime). - ''); + ''.&mt('Currently published version').''. + ''.&Apache::lonlocal::locallocaltime($rmtime).'' + ); if (!$is_meta) { - $r->print(''. - &mt('Metadata current version').''); + $r->print('', + &Apache::loncommon::modal_link($urldir.$main.'.'.$suffix.'.meta', + &mt('Metadata current version'),550,450).''); } if ($is_meta || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') { - $r->print( - ''.&mt('Diffs with current Version').''); + $r->print(''. + &Apache::loncommon::modal_link( + '/adm/diff?filename=/priv/'. + $udom.'/'.$uname.$fn. + '&versiontwo=priv', + &mt('Diffs with current Version'),550,450). + ''); } $r->print(&Apache::loncommon::end_data_table_row(). &Apache::loncommon::end_data_table(). '

'.''. - &mt('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 Authoring Space.').'

'); if (!$is_meta) { $r->print('

'.''. - &mt('This will only retrieve the resource, if you want to retrieve the metadata you will need to do that separately.'). + &mt('This will only retrieve the resource. If you want to retrieve the metadata, you will need to do that separately.'). '

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

'.&mt('No previous versions published.').'

'); + $r->print('

'.&mt('No previous versions published.').'

'); } - $r->print('

'.&mt('Back to').' '.$fn. - '

'); + } # ---------------------------------- Interface for presenting specified version @@ -219,37 +220,41 @@ sub phasetwo { my ($main,$suffix,$is_meta) = &get_file_info($fn); my $logfile; - my $ctarget='/home/'.$uname.'/public_html'.$fn; + my $ctarget=$r->dir_config('lonDocRoot')."/priv/$udom/$uname".$fn; my $vfn=$fn; if ($version ne 'new') { $vfn=~s/\.(\Q$suffix\E)$/\.$version\.$1/; } - my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn; + my $csource=$r->dir_config('lonDocRoot')."/res/$udom/$uname".$vfn; 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').''); + $r->print('' + .&mt('No write permission to user directory, FAIL') + .''); } print $logfile "\n\n================= Retrieve ".localtime()." ================\n". "Version: $version\nSource: $csource\nTarget: $ctarget\n"; $r->print('

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

'); + $r->print('' + .&mt('ok') + .''); print $logfile "Copied sucessfully.\n\n"; + $r->print(&Apache::lonhtmlcommon::scripttag('parent.location.reload();')); } else { my $error=$!; - $r->print('fail, '.$error.'

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

'); + $r->print('

'.&mt('Please pick a version to retrieve:').'

'); &phaseone($r,$fn,$uname,$udom); } } @@ -281,7 +286,7 @@ sub handler { if ($env{'form.filename'}) { $fn=$env{'form.filename'}; - $fn=~s/^http\:\/\/[^\/]+//; + $fn =~ s{^https?\://[^/]+}{}; } else { $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. ' unspecified filename for retrieval', $r->filename); @@ -298,9 +303,8 @@ sub handler { my $uname; my $udom; - ($uname,$udom)= - &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); - unless (($uname) && ($udom)) { + ($uname,$udom) = &Apache::lonnet::constructaccess($fn); + unless (($uname ne '') && ($udom ne '')) { $r->log_reason($uname.' at '.$udom. ' trying to publish file '.$env{'form.filename'}. ' ('.$fn.') - not authorized', @@ -308,20 +312,43 @@ sub handler { return HTTP_NOT_ACCEPTABLE; } - $fn=~s{/~($LONCAPA::username_re)}{}; - &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - $r->print(&Apache::loncommon::start_page('Retrieve Published Resources')); - - - $r->print('

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

'); + # Breadcrumbs + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::lonhtmlcommon::add_breadcrumb({ + 'text' => 'Authoring Space', + 'href' => &Apache::loncommon::authorspace($fn), + }); + &Apache::lonhtmlcommon::add_breadcrumb({ + 'text' => 'Retrieve previous version', + 'href' => '', + }); + + my $londocroot = $r->dir_config('lonDocRoot'); + my $trailfile = $fn; + $trailfile =~ s{^/(priv/)}{$londocroot/$1}; + + $r->print(&Apache::loncommon::start_page('Retrieve Published Resources') + .&Apache::lonhtmlcommon::breadcrumbs() + .&Apache::loncommon::head_subbox( + &Apache::loncommon::CSTR_pageheader($trailfile)) + ); + + $fn=~s{/priv/$LONCAPA::domain_re/$LONCAPA::username_re}{}; + + $r->print('

' + .&mt('Retrieve previous versions of [_1]' + ,''.$fn.'') + .'

'); if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { - $r->print('

'.&mt('Co-Author').': '.$uname. - &mt(' at ').$udom. - '

'); + $r->print('

' + .&mt('Co-Author [_1]' + ,&Apache::loncommon::plainname($uname,$udom) + .' ('.$uname.':'.$udom.')') + .'

'); }