--- loncom/xml/lonxml.pm 2008/02/15 12:59:50 1.471 +++ loncom/xml/lonxml.pm 2008/03/07 20:49:17 1.472 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.471 2008/02/15 12:59:50 bisitz Exp $ +# $Id: lonxml.pm,v 1.472 2008/03/07 20:49:17 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1475,11 +1475,26 @@ SIMPLECONTENT return $filecontents; } +sub verify_html { + my ($filecontents)=@_; + if ($filecontents!~/(?:\<|\<\;)(?:html|xml)[^\<]*(?:\>|\>\;)/is) { + return &mt('File does not have [_1] or [_2] starting tag','<html>','<xml>'); + } + if ($filecontents!~/(?:\<|\<\;)\/(?:html|xml)(?:\>|\>\;)/is) { + return &mt('File does not have [_1] or [_2] ending tag','<html>','<xml>'); + } + if ($filecontents!~/(?:\<|\<\;)(?:body|frameset)[^\<]*(?:\>|\>\;)/is) { + return &mt('File does not have [_1] or [_2] starting tag','<body>','<frameset>'); + } + if ($filecontents!~/(?:\<|\<\;)\/(?:body|frameset)[^\<]*(?:\>|\>\;)/is) { + return &mt('File does not have [_1] or [_2] ending tag','<body>','<frameset>'); + } + return ''; +} sub inserteditinfo { my ($filecontents, $filetype, $filename)=@_; $filecontents = &HTML::Entities::encode($filecontents,'<>&"'); -# my $editheader='Edit below
'; my $xml_help = ''; my $initialize=''; my $textarea_id = 'filecont'; @@ -1538,6 +1553,10 @@ FULLPAGE my $spelllink .=&Apache::lonhtmlcommon::spelllink('xmledit','filecont'); my $textarea_events = &Apache::edit::element_change_detection(); my $form_events = &Apache::edit::form_change_detection(); + my $htmlerror=&verify_html($filecontents); + if ($htmlerror) { + $htmlerror=''.$htmlerror.'

'; + } my $editfooter=(< @@ -1552,7 +1571,7 @@ $initialize
- $spelllink + $spelllink $htmlerror
@@ -1629,6 +1648,9 @@ sub handler { if ($env{'form.savethisfile'} || $env{'form.viewmode'} || $env{'form.Undo'}) { my $html_file=&Apache::lonnet::getfile($file); my $error = &Apache::lonhomework::handle_save_or_undo($request, \$html_file, \$env{'form.filecont'}); + if ($env{'form.savethisfile'}) { + $env{'form.editmode'}='Edit'; #force edit mode + } } } my %mystyle;