--- loncom/publisher/loncleanup.pm	2006/12/20 22:41:08	1.9
+++ loncom/publisher/loncleanup.pm	2012/10/29 17:38:55	1.17
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to cleanup XML files
 #
-# $Id: loncleanup.pm,v 1.9 2006/12/20 22:41:08 albertel Exp $
+# $Id: loncleanup.pm,v 1.17 2012/10/29 17:38:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -34,8 +34,8 @@ 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/';
@@ -248,35 +248,62 @@ sub htmlclean {
 
 sub phaseone {
     my ($r,$fn,$uname,$udom)=@_;
-    $r->print(&mt('Select actions to attempt:').
-	      '<br /><input type="checkbox" name="linefeed" checked="checked" /> '.
-	      &mt('Linefeeds, formfeeds, and carriage returns').
-	      '<br /><input type="checkbox" name="empty" checked="checked" /> '.
-	      &mt('Empty tags').
-	      '<br /><input type="checkbox" name="lower" checked="checked" /> '.
-	      &mt('Lower casing').
-	      '<br /><input type="checkbox" name="symbol"checked="checked" /> '.
-	      &mt('Symbol font').
-	      '<input type="hidden" name="phase" value="two" />'.
-	      '<p><input type="submit" value="'.&mt('Cleanup').'" /></p>');
+    $r->print(
+        &Apache::lonhtmlcommon::start_pick_box()
+       .&Apache::lonhtmlcommon::row_title(&mt('Select actions to attempt'))
+       .'<input type="checkbox" name="linefeed" checked="checked" /> '
+       .&mt('Linefeeds, formfeeds, and carriage returns')
+       .'<br />'
+       .'<input type="checkbox" name="empty" checked="checked" /> '
+       .&mt('Empty tags')
+       .'<br />'
+       .'<input type="checkbox" name="lower" checked="checked" /> '
+       .&mt('Lower casing')
+       .'<br />'
+       .'<input type="checkbox" name="symbol" checked="checked" /> '
+       .&mt('Symbol font')
+       .&Apache::lonhtmlcommon::row_closure(1)
+       .&Apache::lonhtmlcommon::end_pick_box()
+    );
+
+    $r->print(
+        '<input type="hidden" name="phase" value="two" />'
+       .'<p>'
+       .'<input type="submit" value="'.&mt('Next').'" />'
+       .'</p>'
+    );
 }
 
 sub phasetwo {
+    # Check original file
     my ($r,$fn,$uname,$udom)=@_;
-    open(IN,'/home/'.$uname.'/public_html/'.$fn);
     my $text='';
-    while (my $line=<IN>) {
-	$text.=$line;
+    my $londocroot = $r->dir_config('lonDocRoot');
+    if (open(IN,"<$londocroot/priv/$udom/$uname".$fn)) {
+        while (my $line=<IN>) {
+	    $text.=$line;
+        }
+        close(IN);
     }
-    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));
     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)
+       .'<br />'
+       .&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'),
@@ -284,40 +311,70 @@ 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);
-    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));
+                                         ('grade_target'=>'web',
+                                          'return_only_error_and_warning_counts' => 1));
     ($errorcount,$warningcount)=split(':',$result);
-    $r->print('<br />'.&mt('Cleaned up file').': '.
-	      $errorcount.' '.&mt('error(s)').', '.
-	      $warningcount.' '.&mt('warning(s)').
-              '<br /><a href="'.$newuri.'" target="prev">'.
-	      &mt('Open (and edit) cleaned up file in new window').'</a>'.
-              '<br /><a href="/adm/diff?filename='.&escape($uri).
-	      '&versionone=priv&filetwo='.
-	      &escape($newuri).'" target="prev">'.
-	      &mt('Show diffs in new window').'</a><br />'.
-	      '<input type="hidden" name="phase" value="three" />'.
-	      '<input type="submit" name="accept" value="'.&mt('Accept Result').'" />'.
-	      '<input type="submit" name="reject" value="'.&mt('Reject Result').'" />'
-	      );
+
+    # 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)
+       .'<br />'
+       .&Apache::lonhtmlcommon::confirm_success(
+           &mt('[quant,_1,warning]',$warningcount), $warningcount)
+       .&Apache::lonhtmlcommon::row_closure()
+    );
+
+    # Display actions
+    $r->print(
+        &Apache::lonhtmlcommon::row_title(&mt('Actions'))
+       .'<ul>'
+       .'<li><a href="'.$newuri.'" target="prev">'
+       .&mt('Open (and edit) cleaned up file in new window')
+       .'</a></li>'
+       .'<li><a href="/adm/diff?filename='.&escape($uri)
+       .'&versionone=priv&filetwo='.&escape($newuri).'" target="prev">'
+       .&mt('Show diffs in new window')
+       .'</a></li>'
+       .'</ul>'
+       .&Apache::lonhtmlcommon::row_closure(1)
+       .&Apache::lonhtmlcommon::end_pick_box()
+       .'<p>'
+       .'<input type="hidden" name="phase" value="three" />'
+       .'<input type="submit" name="accept" value="'
+       .&mt('Clean Up').'" />'
+       .' <input type="submit" name="reject" value="'
+       .&mt('Cancel').'" />'
+       .'</p>'
+    );
 }
 
 sub phasethree {
     my ($r,$fn,$uname,$udom)=@_;
-    my $old='/home/'.$uname.'/public_html/'.$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/'.$uname.'/public_html'.$newfn;
+    my $new=$r->dir_config('lonDocRoot')."/priv/$udom/$uname".$newfn;
     if ($env{'form.accept'}) {
-	$r->print(&mt('Accepting changes'));
+	$r->print(
+        '<p class="LC_info">'
+       .&mt('Accepting changes')
+       .'</p>'
+    );
         move($new,$old);
     } else {
-	$r->print(&mt('Rejeting changes'));
+	$r->print(
+        '<p class="LC_info">'
+       .&mt('Rejecting changes')
+       .'</p>'
+    );
         unlink($new);
     }
 }
@@ -335,7 +392,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); 
@@ -352,8 +409,7 @@ sub handler {
     my $uname;
     my $udom;
 
-    ($uname,$udom)=
-	&Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
+    ($uname,$udom)=&Apache::lonnet::constructaccess($fn);
     unless (($uname) && ($udom)) {
 	$r->log_reason($uname.' at '.$udom.
 		       ' trying to cleanup file '.$env{'form.filename'}.
@@ -362,12 +418,20 @@ 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('Cleanup XML Document'));
+    # Breadcrumbs
+    my $brcrum = [{'href' => &Apache::loncommon::authorspace($fn),
+                   'text' => 'Construction 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,}));
     $r->print('<h2>'.$fn.'</h2>'.
               '<form action="/adm/cleanup" method="post">'.
               '<input type="hidden" name="filename" value="'.$env{'form.filename'}.'" />');
@@ -383,11 +447,18 @@ sub handler {
 	}
     }
     my $dir=$fn;
-    $dir=~s/\/[^\/]+$/\//;
-    $r->print('</form>'.
-	      '<br /><a href="/priv/'.$uname.'/'.$fn.'">'.&mt('Back to Source File').'</a>'.
-              '<br /><a href="/priv/'.$uname.'/'.$dir.'">'.&mt('Back to Source Directory').'</a>'.
-	      &Apache::loncommon::end_page());
+    $dir=~s{[^/]+$}{};
+    $r->print(
+        '</form>'
+       .&Apache::lonhtmlcommon::start_funclist()
+       .&Apache::lonhtmlcommon::add_item_funclist(
+            '<a href="/priv/'.$udom.'/'.$uname.$fn.'">'.&mt('Back to Source File').'</a>')
+       .&Apache::lonhtmlcommon::add_item_funclist(
+            '<a href="/priv/'.$udom.'/'.$uname.$dir.'">'.&mt('Back to Source Directory').'</a>')
+       .&Apache::lonhtmlcommon::end_funclist()
+       .&Apache::loncommon::end_page()
+    );
+
     return OK;  
 }