--- loncom/publisher/loncleanup.pm 2011/10/24 22:39:21 1.13 +++ loncom/publisher/loncleanup.pm 2013/06/04 22:20:16 1.20 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to cleanup XML files # -# $Id: loncleanup.pm,v 1.13 2011/10/24 22:39:21 www Exp $ +# $Id: loncleanup.pm,v 1.20 2013/06/04 22:20:16 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,13 +34,13 @@ use strict; use Apache::File; use File::Copy; use Apache::Constants qw(:common :http :methods); -use Apache::loncacc; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::lonlocal; use Apache::lonnet; use lib '/home/httpd/lib/perl/'; use LONCAPA; +use HTML::Entities(); sub latextrans { @@ -252,17 +252,22 @@ sub phaseone { $r->print( &Apache::lonhtmlcommon::start_pick_box() .&Apache::lonhtmlcommon::row_title(&mt('Select actions to attempt')) + .'
' + .'
' + .'
' + .'' .&Apache::lonhtmlcommon::row_closure(1) .&Apache::lonhtmlcommon::end_pick_box() ); @@ -278,13 +283,29 @@ sub phaseone { sub phasetwo { # Check original file my ($r,$fn,$uname,$udom)=@_; - open(IN,'/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$fn); my $text=''; - while (my $line=) { - $text.=$line; + my $londocroot = $r->dir_config('lonDocRoot'); + if (open(IN,"<$londocroot/priv/$udom/$uname".$fn)) { + while (my $line=) { + $text.=$line; + } + close(IN); + } + # Check if any selection was made + if ($env{'form.linefeed'} ne 'on' && + $env{'form.empty'} ne 'on' && + $env{'form.lower'} ne 'on' && + $env{'form.symbol'} ne 'on') { + $r->print( + '

' + .&mt('Please select at least one option.') + .'

' + .'

'.&mt('Back').'

' + ); + return; } - close(IN); - my $uri='/~'.$uname.$fn; + + my $uri="/priv/$udom/$uname".$fn; my $result=&Apache::lonnet::ssi_body($uri, ('grade_target'=>'web', 'return_only_error_and_warning_counts' => 1)); @@ -310,10 +331,11 @@ sub phasetwo { ($env{'form.symbol'} ne 'on')); my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; - open(OUT,'>/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$newfn); - print OUT $text; - close(OUT); - my $newuri='/~'.$uname.$newfn; + if (open(OUT,">$londocroot/priv/$udom/$uname".$newfn)) { + print OUT $text; + close(OUT); + } + my $newuri="/priv/$udom/$uname".$newfn; $result=&Apache::lonnet::ssi_body($newuri, ('grade_target'=>'web', 'return_only_error_and_warning_counts' => 1)); @@ -337,8 +359,11 @@ sub phasetwo { .'
  • ' .&mt('Open (and edit) cleaned up file in new window') .'
  • ' - .'
  • ' + .'
  • ' .&mt('Show diffs in new window') .'
  • ' .'' @@ -356,25 +381,29 @@ sub phasetwo { sub phasethree { my ($r,$fn,$uname,$udom)=@_; - my $old='/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$fn; + my $old=$r->dir_config('lonDocRoot')."/priv/$udom/$uname".$fn; my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; - my $new='/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$newfn; + my $new=$r->dir_config('lonDocRoot')."/priv/$udom/$uname".$newfn; if ($env{'form.accept'}) { - $r->print( + $r->print( '

    ' - .&mt('Accepting changes') + .&mt('Accepting changes...') .'

    ' ); move($new,$old); } else { - $r->print( + $r->print( '

    ' - .&mt('Rejecting changes') + .&mt('Rejecting changes...') .'

    ' - ); + ); unlink($new); } + $r->print( + '

    ' + .&Apache::lonhtmlcommon::confirm_success(&mt('Done'))); + '

    ' } # ---------------------------------------------------------------- Main Handler @@ -390,7 +419,7 @@ sub handler { if ($env{'form.filename'}) { $fn=$env{'form.filename'}; - $fn=~s/^https?\:\/\/[^\/]+//; + $fn=~s{^https?\://[^/]+}{}; } else { $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. ' unspecified filename for cleanup', $r->filename); @@ -407,7 +436,7 @@ sub handler { my $uname; my $udom; - ($uname,$udom)=&Apache::loncacc::constructaccess($fn); + ($uname,$udom)=&Apache::lonnet::constructaccess($fn); unless (($uname) && ($udom)) { $r->log_reason($uname.' at '.$udom. ' trying to cleanup file '.$env{'form.filename'}. @@ -416,17 +445,17 @@ sub handler { return HTTP_NOT_ACCEPTABLE; } - $fn=~s{/~($LONCAPA::username_re)}{}; - &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; # Breadcrumbs - my $brcrum = [{'href' => &Apache::loncommon::authorspace(), - 'text' => 'Construction Space'}, + my $brcrum = [{'href' => &Apache::loncommon::authorspace($fn), + 'text' => 'Authoring Space'}, {'href' => '', 'text' => 'Cleanup XML Document'}]; + $fn=~s{^/priv/$LONCAPA::domain_re/$LONCAPA::username_re}{}; + $r->print(&Apache::loncommon::start_page('Cleanup XML Document', undef, {'bread_crumbs' => $brcrum,})); @@ -434,7 +463,7 @@ sub handler { '
    '. ''); unless ($fn=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) { - $r->print(&mt('Cannot cleanup this filetype')); + $r->print('

    '.&mt('Cannot cleanup this filetype').'

    '); } else { if ($env{'form.phase'} eq 'three') { &phasethree($r,$fn,$uname,$udom); @@ -445,15 +474,14 @@ sub handler { } } my $dir=$fn; - $dir=~s/\/[^\/]+$/\//; + $dir=~s{[^/]+$}{}; $r->print( '
    ' - .&Apache::lonhtmlcommon::start_funclist() - .&Apache::lonhtmlcommon::add_item_funclist( - ''.&mt('Back to Source File').'') - .&Apache::lonhtmlcommon::add_item_funclist( - ''.&mt('Back to Source Directory').'') - .&Apache::lonhtmlcommon::end_funclist() + .&Apache::lonhtmlcommon::actionbox( + [''. + &mt('Back to Source File').'', + ''. + &mt('Back to Source Directory').'']) .&Apache::loncommon::end_page() );