--- loncom/xml/lonxml.pm 2007/10/24 10:06:22 1.467 +++ loncom/xml/lonxml.pm 2008/03/12 02:46:03 1.474 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.467 2007/10/24 10:06:22 foxr Exp $ +# $Id: lonxml.pm,v 1.474 2008/03/12 02:46:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -377,8 +377,12 @@ sub xmlparse { $finaloutput .= join('',@script_var_displays); undef(@script_var_displays); } - + &init_state(); if ($env{'form.return_only_error_and_warning_counts'}) { + if ($env{'request.filename'}=~/\.(html|htm|xml)$/i) { + my $error=&verify_html($content_file_string); + if ($error) { $errorcount++; } + } return "$errorcount:$warningcount"; } return $finaloutput; @@ -659,6 +663,7 @@ sub setup_globals { &init_counter(); &clear_bubble_lines_for_part(); &init_state(); + &set_state('target',$target); @Apache::lonxml::pwd=(); @Apache::lonxml::extlinks=(); @script_var_displays=(); @@ -722,6 +727,7 @@ sub init_safespace { $safehole->wrap(\&Apache::chemresponse::chem_standard_order,$safeeval, '&chem_standard_order'); $safehole->wrap(\&Apache::response::check_status,$safeeval,'&check_status'); + $safehole->wrap(\&Apache::response::implicit_multiplication,$safeeval,'&implicit_multiplication'); $safehole->wrap(\&Apache::lonmaxima::maxima_eval,$safeeval,'&maxima_eval'); $safehole->wrap(\&Apache::lonmaxima::maxima_check,$safeeval,'&maxima_check'); @@ -1082,7 +1088,7 @@ sub increment_counter { # If the caller supplied the response_id parameter, # Maintain its counter.. creating if necessary. - if(defined($part_response)) { + if (defined($part_response)) { if (!defined($Apache::lonxml::counters_per_part{$part_response})) { $Apache::lonxml::counters_per_part{$part_response} = 0; } @@ -1115,7 +1121,7 @@ sub init_counter { } sub store_counter { - &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter)); + &Apache::lonnet::appenv({'form.counter' => $Apache::lonxml::counter}); $Apache::lonxml::counter_changed=0; return ''; } @@ -1136,7 +1142,7 @@ sub store_counter { sub restore_problem_counter { if (defined($state)) { - &Apache::lonnet::appenv(('form.counter' => $state)); + &Apache::lonnet::appenv({'form.counter' => $state}); } } sub get_problem_counter { @@ -1148,7 +1154,7 @@ sub store_counter { =pod -=item bubble_lines_for_part(response_id) +=item bubble_lines_for_part(part_response) Returns the number of lines required to get a response for $part_response (this is just $Apache::lonxml::counters_per_part{$part_response} @@ -1163,7 +1169,6 @@ sub bubble_lines_for_part { } else { return $Apache::lonxml::counters_per_part{$part_response}; } - } =pod @@ -1182,7 +1187,7 @@ sub clear_bubble_lines_for_part { =pod -=item set_bubble_lines(response_id, value) +=item set_bubble_lines(part_response, value) If there is a problem part, that for whatever reason requires bubble lines that are not @@ -1374,7 +1379,7 @@ sub writeallows { &Apache::lonnet::hreflocation($thisdir,&unescape($_))}=$thisurl; } @extlinks=(); - &Apache::lonnet::appenv(%httpref); + &Apache::lonnet::appenv(\%httpref); } sub register_ssi { @@ -1474,11 +1479,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)=@_; + my ($filecontents, $filetype, $filename)=@_; $filecontents = &HTML::Entities::encode($filecontents,'<>&"'); -# my $editheader='Edit below
'; my $xml_help = ''; my $initialize=''; my $textarea_id = 'filecont'; @@ -1528,38 +1548,45 @@ FULLPAGE $xml_help=&Apache::loncommon::helpLatexCheatsheet(); } - my $cleanbut = ''; - my $titledisplay=&display_title(); my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit', 'vi' => 'Save and View', 'dv' => 'Discard Edits and View', 'un' => 'undo', 'ed' => 'Edit'); - my $buttons=(< -
- - -BUTTONS - $buttons.=&Apache::lonhtmlcommon::spelllink('xmledit','filecont'); + 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=(<
-$xml_help - -$buttons
- -
-
$buttons -
-$titledisplay -
+
+ +
+ $filename + + $xml_help +
+
+ + + $spelllink $htmlerror +
+
+ + +
+
+ +
+
+ $titledisplay +
ENDFOOTER @@ -1625,6 +1652,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; @@ -1689,11 +1719,12 @@ ENDNOTFOUND unless ($env{'request.state'} eq 'published') { if ($env{'form.editmode'} && (!($env{'form.viewmode'})) && (!($env{'form.discardview'}))) { - my ($edit_info, $add_to_onload, $add_to_onresize)= - &inserteditinfo($filecontents,$filetype); - my $displayfile=$request->uri; $displayfile=~s/^\/[^\/]*//; + + my ($edit_info, $add_to_onload, $add_to_onresize)= + &inserteditinfo($filecontents,$filetype,$displayfile); + my %options = ('add_entries' => {'onresize' => $add_to_onresize, @@ -1709,9 +1740,7 @@ ENDNOTFOUND my $start_page = &Apache::loncommon::start_page(undef,$js, \%options); $result=$start_page. - &Apache::lonxml::message_location().'

'. - $displayfile. - '

'. + &Apache::lonxml::message_location(). $edit_info. &Apache::loncommon::end_page(); }