version 1.12, 2011/10/23 23:46:07
|
version 1.18, 2012/12/05 18:19:45
|
Line 34 use strict;
|
Line 34 use strict;
|
use Apache::File; |
use Apache::File; |
use File::Copy; |
use File::Copy; |
use Apache::Constants qw(:common :http :methods); |
use Apache::Constants qw(:common :http :methods); |
use Apache::loncacc; |
|
use Apache::loncommon(); |
use Apache::loncommon(); |
use Apache::lonhtmlcommon(); |
use Apache::lonhtmlcommon(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
Line 252 sub phaseone {
|
Line 251 sub phaseone {
|
$r->print( |
$r->print( |
&Apache::lonhtmlcommon::start_pick_box() |
&Apache::lonhtmlcommon::start_pick_box() |
.&Apache::lonhtmlcommon::row_title(&mt('Select actions to attempt')) |
.&Apache::lonhtmlcommon::row_title(&mt('Select actions to attempt')) |
|
.'<label>' |
.'<input type="checkbox" name="linefeed" checked="checked" /> ' |
.'<input type="checkbox" name="linefeed" checked="checked" /> ' |
.&mt('Linefeeds, formfeeds, and carriage returns') |
.&mt('Linefeeds, formfeeds, and carriage returns') |
.'<br />' |
.'</label><br />' |
|
.'<label>' |
.'<input type="checkbox" name="empty" checked="checked" /> ' |
.'<input type="checkbox" name="empty" checked="checked" /> ' |
.&mt('Empty tags') |
.&mt('Empty tags') |
.'<br />' |
.'</label><br />' |
|
.'<label>' |
.'<input type="checkbox" name="lower" checked="checked" /> ' |
.'<input type="checkbox" name="lower" checked="checked" /> ' |
.&mt('Lower casing') |
.&mt('Lower casing') |
.'<br />' |
.'</label><br />' |
|
.'<label>' |
.'<input type="checkbox" name="symbol" checked="checked" /> ' |
.'<input type="checkbox" name="symbol" checked="checked" /> ' |
.&mt('Symbol font') |
.&mt('Symbol font') |
|
.'</label>' |
.&Apache::lonhtmlcommon::row_closure(1) |
.&Apache::lonhtmlcommon::row_closure(1) |
.&Apache::lonhtmlcommon::end_pick_box() |
.&Apache::lonhtmlcommon::end_pick_box() |
); |
); |
Line 278 sub phaseone {
|
Line 282 sub phaseone {
|
sub phasetwo { |
sub phasetwo { |
# Check original file |
# Check original file |
my ($r,$fn,$uname,$udom)=@_; |
my ($r,$fn,$uname,$udom)=@_; |
open(IN,'/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$fn); |
|
my $text=''; |
my $text=''; |
while (my $line=<IN>) { |
my $londocroot = $r->dir_config('lonDocRoot'); |
$text.=$line; |
if (open(IN,"<$londocroot/priv/$udom/$uname".$fn)) { |
|
while (my $line=<IN>) { |
|
$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( |
|
'<p class="LC_warning">' |
|
.&mt('Please select at least one option.') |
|
.'</p>' |
|
.'<p><a href="javascript:history.back();">'.&mt('Back').'</p>' |
|
); |
|
return; |
} |
} |
close(IN); |
|
my $uri='/~'.$uname.$fn; |
my $uri="/priv/$udom/$uname".$fn; |
my $result=&Apache::lonnet::ssi_body($uri, |
my $result=&Apache::lonnet::ssi_body($uri, |
('grade_target'=>'web', |
('grade_target'=>'web', |
'return_only_error_and_warning_counts' => 1)); |
'return_only_error_and_warning_counts' => 1)); |
Line 310 sub phasetwo {
|
Line 330 sub phasetwo {
|
($env{'form.symbol'} ne 'on')); |
($env{'form.symbol'} ne 'on')); |
my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); |
my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); |
my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; |
my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; |
open(OUT,'>/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$newfn); |
if (open(OUT,">$londocroot/priv/$udom/$uname".$newfn)) { |
print OUT $text; |
print OUT $text; |
close(OUT); |
close(OUT); |
my $newuri='/~'.$uname.$newfn; |
} |
|
my $newuri="/priv/$udom/$uname".$newfn; |
$result=&Apache::lonnet::ssi_body($newuri, |
$result=&Apache::lonnet::ssi_body($newuri, |
('grade_target'=>'web', |
('grade_target'=>'web', |
'return_only_error_and_warning_counts' => 1)); |
'return_only_error_and_warning_counts' => 1)); |
Line 337 sub phasetwo {
|
Line 358 sub phasetwo {
|
.'<li><a href="'.$newuri.'" target="prev">' |
.'<li><a href="'.$newuri.'" target="prev">' |
.&mt('Open (and edit) cleaned up file in new window') |
.&mt('Open (and edit) cleaned up file in new window') |
.'</a></li>' |
.'</a></li>' |
.'<li><a href="/adm/diff?filename='.&escape($uri) |
.'<li><a href="' |
.'&versionone=priv&filetwo='.&escape($newuri).'" target="prev">' |
.&HTML::Entities::encode( |
|
'/adm/diff?filename='.&escape($uri) |
|
.'&versionone=priv&filetwo='.&escape($newuri)) |
|
.'" target="prev">' |
.&mt('Show diffs in new window') |
.&mt('Show diffs in new window') |
.'</a></li>' |
.'</a></li>' |
.'</ul>' |
.'</ul>' |
Line 356 sub phasetwo {
|
Line 380 sub phasetwo {
|
|
|
sub phasethree { |
sub phasethree { |
my ($r,$fn,$uname,$udom)=@_; |
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 ($main,$ext)=($fn=~/^(.*)\.(\w+)/); |
my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; |
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'}) { |
if ($env{'form.accept'}) { |
$r->print( |
$r->print( |
'<p class="LC_info">' |
'<p class="LC_info">' |
.&mt('Accepting changes') |
.&mt('Accepting changes...') |
.'</p>' |
.'</p>' |
); |
); |
move($new,$old); |
move($new,$old); |
} else { |
} else { |
$r->print( |
$r->print( |
'<p class="LC_info">' |
'<p class="LC_info">' |
.&mt('Rejecting changes') |
.&mt('Rejecting changes...') |
.'</p>' |
.'</p>' |
); |
); |
unlink($new); |
unlink($new); |
} |
} |
|
$r->print( |
|
'<p>' |
|
.&Apache::lonhtmlcommon::confirm_success(&mt('Done'))); |
|
'</p>' |
} |
} |
|
|
# ---------------------------------------------------------------- Main Handler |
# ---------------------------------------------------------------- Main Handler |
Line 390 sub handler {
|
Line 418 sub handler {
|
|
|
if ($env{'form.filename'}) { |
if ($env{'form.filename'}) { |
$fn=$env{'form.filename'}; |
$fn=$env{'form.filename'}; |
$fn=~s/^https?\:\/\/[^\/]+//; |
$fn=~s{^https?\://[^/]+}{}; |
} else { |
} else { |
$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. |
$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. |
' unspecified filename for cleanup', $r->filename); |
' unspecified filename for cleanup', $r->filename); |
Line 407 sub handler {
|
Line 435 sub handler {
|
my $uname; |
my $uname; |
my $udom; |
my $udom; |
|
|
($uname,$udom)= |
($uname,$udom)=&Apache::lonnet::constructaccess($fn); |
&Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); |
|
unless (($uname) && ($udom)) { |
unless (($uname) && ($udom)) { |
$r->log_reason($uname.' at '.$udom. |
$r->log_reason($uname.' at '.$udom. |
' trying to cleanup file '.$env{'form.filename'}. |
' trying to cleanup file '.$env{'form.filename'}. |
Line 417 sub handler {
|
Line 444 sub handler {
|
return HTTP_NOT_ACCEPTABLE; |
return HTTP_NOT_ACCEPTABLE; |
} |
} |
|
|
$fn=~s{/~($LONCAPA::username_re)}{}; |
|
|
|
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
|
|
# Breadcrumbs |
# Breadcrumbs |
my $brcrum = [{'href' => &Apache::loncommon::authorspace(), |
my $brcrum = [{'href' => &Apache::loncommon::authorspace($fn), |
'text' => 'Construction Space'}, |
'text' => 'Construction Space'}, |
{'href' => '', |
{'href' => '', |
'text' => 'Cleanup XML Document'}]; |
'text' => 'Cleanup XML Document'}]; |
|
|
|
$fn=~s{^/priv/$LONCAPA::domain_re/$LONCAPA::username_re}{}; |
|
|
$r->print(&Apache::loncommon::start_page('Cleanup XML Document', |
$r->print(&Apache::loncommon::start_page('Cleanup XML Document', |
undef, |
undef, |
{'bread_crumbs' => $brcrum,})); |
{'bread_crumbs' => $brcrum,})); |
Line 435 sub handler {
|
Line 462 sub handler {
|
'<form action="/adm/cleanup" method="post">'. |
'<form action="/adm/cleanup" method="post">'. |
'<input type="hidden" name="filename" value="'.$env{'form.filename'}.'" />'); |
'<input type="hidden" name="filename" value="'.$env{'form.filename'}.'" />'); |
unless ($fn=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) { |
unless ($fn=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) { |
$r->print(&mt('Cannot cleanup this filetype')); |
$r->print('<p class="LC_warning">'.&mt('Cannot cleanup this filetype').'</p>'); |
} else { |
} else { |
if ($env{'form.phase'} eq 'three') { |
if ($env{'form.phase'} eq 'three') { |
&phasethree($r,$fn,$uname,$udom); |
&phasethree($r,$fn,$uname,$udom); |
Line 446 sub handler {
|
Line 473 sub handler {
|
} |
} |
} |
} |
my $dir=$fn; |
my $dir=$fn; |
$dir=~s/\/[^\/]+$/\//; |
$dir=~s{[^/]+$}{}; |
$r->print( |
$r->print( |
'</form>' |
'</form>' |
.&Apache::lonhtmlcommon::start_funclist() |
.&Apache::lonhtmlcommon::actionbox( |
.&Apache::lonhtmlcommon::add_item_funclist( |
['<a href="/priv/'.$udom.'/'.$uname.$fn.'">'. |
'<a href="/priv/'.$uname.'/'.$fn.'">'.&mt('Back to Source File').'</a>') |
&mt('Back to Source File').'</a>', |
.&Apache::lonhtmlcommon::add_item_funclist( |
'<a href="/priv/'.$udom.'/'.$uname.$dir.'">'. |
'<a href="/priv/'.$uname.'/'.$dir.'">'.&mt('Back to Source Directory').'</a>') |
&mt('Back to Source Directory').'</a>']) |
.&Apache::lonhtmlcommon::end_funclist() |
|
.&Apache::loncommon::end_page() |
.&Apache::loncommon::end_page() |
); |
); |
|
|