--- loncom/publisher/loncleanup.pm 2005/07/13 21:43:02 1.6 +++ loncom/publisher/loncleanup.pm 2011/10/24 22:39:21 1.13 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to cleanup XML files # -# $Id: loncleanup.pm,v 1.6 2005/07/13 21:43:02 www Exp $ +# $Id: loncleanup.pm,v 1.13 2011/10/24 22:39:21 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,8 +36,12 @@ 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; + sub latextrans { my $symbolfont=shift; @@ -245,22 +249,36 @@ sub htmlclean { sub phaseone { my ($r,$fn,$uname,$udom)=@_; - $r->print(&mt('Select actions to attempt:'). - '
'. - &mt('Linefeeds, formfeeds, and carriage returns'). - '
'. - &mt('Empty tags'). - '
'. - &mt('Lower casing'). - '
'. - &mt('Symbol font'). - ''. - '

'); + $r->print( + &Apache::lonhtmlcommon::start_pick_box() + .&Apache::lonhtmlcommon::row_title(&mt('Select actions to attempt')) + .' ' + .&mt('Linefeeds, formfeeds, and carriage returns') + .'
' + .' ' + .&mt('Empty tags') + .'
' + .' ' + .&mt('Lower casing') + .'
' + .' ' + .&mt('Symbol font') + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box() + ); + + $r->print( + '' + .'

' + .'' + .'

' + ); } sub phasetwo { + # Check original file my ($r,$fn,$uname,$udom)=@_; - open(IN,'/home/'.$uname.'/public_html/'.$fn); + open(IN,'/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$fn); my $text=''; while (my $line=) { $text.=$line; @@ -271,9 +289,20 @@ sub phasetwo { ('grade_target'=>'web', 'return_only_error_and_warning_counts' => 1)); my ($errorcount,$warningcount)=split(':',$result); - $r->print(&mt('Original file').': '. - $errorcount.' '.&mt('error(s)').', '. - $warningcount.' '.&mt('warning(s)')); + + # Display results for original file + $r->print( + &Apache::lonhtmlcommon::start_pick_box() + .&Apache::lonhtmlcommon::row_title(&mt('Original file')) + .&Apache::lonhtmlcommon::confirm_success( + &mt('[quant,_1,error]',$errorcount), $errorcount) + .'
' + .&Apache::lonhtmlcommon::confirm_success( + &mt('[quant,_1,warning]',$warningcount), $warningcount) + .&Apache::lonhtmlcommon::row_closure() + ); + + # Clean up file $text=&htmlclean($text,1, ($env{'form.linefeed'} ne 'on'), ($env{'form.empty'} ne 'on'), @@ -281,40 +310,69 @@ sub phasetwo { ($env{'form.symbol'} ne 'on')); my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; - open(OUT,'>/home/'.$uname.'/public_html'.$newfn); + open(OUT,'>/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$newfn); print OUT $text; close(OUT); my $newuri='/~'.$uname.$newfn; $result=&Apache::lonnet::ssi_body($newuri, - ('grade_target'=>'web', - 'return_only_error_and_warning_counts' => 1)); + ('grade_target'=>'web', + 'return_only_error_and_warning_counts' => 1)); ($errorcount,$warningcount)=split(':',$result); - $r->print('
'.&mt('Cleaned up file').': '. - $errorcount.' '.&mt('error(s)').', '. - $warningcount.' '.&mt('warning(s)'). - '
'. - &mt('Open (and edit) cleaned up file in new window').''. - '
'. - &mt('Show diffs in new window').'
'. - ''. - ''. - '' - ); + + # Display results for cleaned up file + $r->print( + &Apache::lonhtmlcommon::row_title(&mt('Cleaned up file')) + .&Apache::lonhtmlcommon::confirm_success( + &mt('[quant,_1,error]',$errorcount), $errorcount) + .'
' + .&Apache::lonhtmlcommon::confirm_success( + &mt('[quant,_1,warning]',$warningcount), $warningcount) + .&Apache::lonhtmlcommon::row_closure() + ); + + # Display actions + $r->print( + &Apache::lonhtmlcommon::row_title(&mt('Actions')) + .'' + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box() + .'

' + .'' + .'' + .' ' + .'

' + ); } sub phasethree { my ($r,$fn,$uname,$udom)=@_; - my $old='/home/'.$uname.'/public_html/'.$fn; + my $old='/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$fn; my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; - my $new='/home/'.$uname.'/public_html'.$newfn; + my $new='/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$newfn; if ($env{'form.accept'}) { - $r->print(&mt('Accepting changes')); + $r->print( + '

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

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

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

' + ); unlink($new); } } @@ -332,7 +390,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 cleanup', $r->filename); @@ -349,8 +407,7 @@ sub handler { my $uname; my $udom; - ($uname,$udom)= - &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); + ($uname,$udom)=&Apache::loncacc::constructaccess($fn); unless (($uname) && ($udom)) { $r->log_reason($uname.' at '.$udom. ' trying to cleanup file '.$env{'form.filename'}. @@ -359,15 +416,20 @@ sub handler { return HTTP_NOT_ACCEPTABLE; } - $fn=~s/\/\~(\w+)//; + $fn=~s{/~($LONCAPA::username_re)}{}; &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.'LON-CAPA Construction Space'); - - $r->print(&Apache::loncommon::bodytag('Cleanup XML Document')); + # Breadcrumbs + my $brcrum = [{'href' => &Apache::loncommon::authorspace(), + 'text' => 'Construction Space'}, + {'href' => '', + 'text' => 'Cleanup XML Document'}]; + + $r->print(&Apache::loncommon::start_page('Cleanup XML Document', + undef, + {'bread_crumbs' => $brcrum,})); $r->print('

'.$fn.'

'. '
'. ''); @@ -384,10 +446,17 @@ sub handler { } my $dir=$fn; $dir=~s/\/[^\/]+$/\//; - $r->print('
'. - '
'.&mt('Back to Source File').''. - '
'.&mt('Back to Source Directory').''. - ''); + $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::loncommon::end_page() + ); + return OK; }