--- loncom/xml/lonxml.pm 2006/03/09 00:39:28 1.400 +++ loncom/xml/lonxml.pm 2006/04/18 22:35:55 1.410 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.400 2006/03/09 00:39:28 albertel Exp $ +# $Id: lonxml.pm,v 1.410 2006/04/18 22:35:55 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,7 +40,7 @@ package Apache::lonxml; use vars -qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $errorcount $warningcount @htmlareafields); +qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $errorcount $warningcount); use strict; use HTML::LCParser(); use HTML::TreeBuilder(); @@ -162,28 +162,6 @@ sub disable_LaTeX_substitutions { $Apache::lonxml::substitute_LaTeX_symbols = 0; } -sub xmlbegin { - my ($style)=@_; - my $output=''; - @htmlareafields=(); - if ($env{'browser.mathml'}) { - $output='<?xml version="1.0"?>' - #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n" -# .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" ' - -# .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">] >' - .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">' - .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' - .'xmlns="http://www.w3.org/1999/xhtml">'; - } else { - $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'; - } - if ($style eq 'encode') { - $output=&HTML::Entities::encode($output,'<>&"'); - } - return $output; -} - sub xmlend { my ($target,$parser)=@_; my $mode='xml'; @@ -204,9 +182,9 @@ sub xmlend { $discussion.='<tex>\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\end{document}</tex>'; &Apache::lonxml::newparser($parser,\$discussion,''); return ''; - } else { - return $discussion.&Apache::loncommon::endbodytag(); } + + return $discussion; } sub tokeninputfield { @@ -304,18 +282,6 @@ sub printtokenheader { } } -sub fontsettings { - my $headerstring=''; - if (($env{'browser.os'} eq 'mac') && (!$env{'browser.mathml'})) { - $headerstring.= - '<meta Content-Type="text/html; charset=x-mac-roman" />'; - } elsif (!$env{'browser.mathml'} && $env{'browser.unicode'}) { - $headerstring.= - '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; - } - return $headerstring; -} - sub printalltags { my $temp; foreach $temp (sort keys %Apache::lonxml::alltags) { @@ -638,7 +604,6 @@ sub setup_globals { my ($request,$target)=@_; $Apache::lonxml::request=$request; $Apache::lonxml::registered = 0; - @Apache::lonxml::htmlareafields=(); $errorcount=0; $warningcount=0; $Apache::lonxml::default_homework_loaded=0; @@ -1038,6 +1003,7 @@ sub init_counter { sub store_counter { &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter)); + $Apache::lonxml::counter_changed=0; return ''; } @@ -1060,6 +1026,11 @@ sub store_counter { &Apache::lonnet::appenv(('form.counter' => $state)); } } + sub get_problem_counter { + if ($Apache::lonxml::counter_changed) { &store_counter() } + &Apache::lonnet::transfer_profile_to_env(); + return $env{'form.counter'}; + } } sub get_all_text { @@ -1321,8 +1292,7 @@ sub inserteditinfo { my $initialize=''; if ($filetype eq 'html') { my $addbuttons=&Apache::lonhtmlcommon::htmlareaaddbuttons(); - $initialize=&Apache::lonhtmlcommon::htmlareaheaders(). - &Apache::lonhtmlcommon::spellheader(); + $initialize=&Apache::lonhtmlcommon::spellheader(); if (!&Apache::lonhtmlcommon::htmlareablocked() && &Apache::lonhtmlcommon::htmlareabrowser()) { $initialize.=(<<FULLPAGE); @@ -1452,17 +1422,13 @@ sub handler { my $result = ''; my $filecontents=&Apache::lonnet::getfile($file); if ($filecontents eq -1) { - my $bodytag=&Apache::loncommon::bodytag('File Error'); + my $start_page=&Apache::loncommon::start_page('File Error'); + my $end_page=&Apache::loncommon::end_page('File Error'); my $fnf=&mt('File not found'); $result=(<<ENDNOTFOUND); -<html> -<head> -<title>$fnf</title> -</head> -$bodytag +$start_page <b>$fnf: $file</b> -</body> -</html> +$end_page ENDNOTFOUND $filecontents=''; if ($env{'request.state'} ne 'published') { @@ -1500,18 +1466,20 @@ ENDNOTFOUND if ($env{'form.editmode'} && (!($env{'form.viewmode'}))) { my $displayfile=$request->uri; $displayfile=~s/^\/[^\/]*//; - my $bodytag='<body bgcolor="#FFFFFF">'; - if ($env{'environment.remote'} eq 'off') { - $bodytag=&Apache::loncommon::bodytag(); + my %options = (); + if ($env{'environment.remote'} ne 'off') { + $options{'bgcolor'} = '#FFFFFF'; } - $result='<html>'.$bodytag. + my $start_page = &Apache::loncommon::start_page(undef,undef, + \%options); + $result=$start_page. &Apache::lonxml::message_location().'<h3>'. $displayfile. - '</h3></body></html>'; + '</h3>'.&Apache::loncommon::end_page(); $result=&inserteditinfo($result,$filecontents,$filetype); } } - if ($filetype eq 'html') { writeallows($request->uri); } + if ($filetype eq 'html') { &writeallows($request->uri); } &Apache::lonxml::add_messages(\$result); @@ -1574,9 +1542,10 @@ sub error { if ( !$symb ) { #public or browsers $errormsg=&mt("An error occured while processing this resource. The author has been notified."); - } + } + my $msg = join('<br />',@_); #notify author - &Apache::lonmsg::author_res_msg($env{'request.filename'},join('<br />',@_)); + &Apache::lonmsg::author_res_msg($env{'request.filename'},$msg); #notify course if ( $symb && $env{'request.course.id'} ) { my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'}; @@ -1594,7 +1563,7 @@ sub error { my $now=time; if ($now-$lastnotified{$key}>86400) { &Apache::lonmsg::user_normal_msg($user,$domain, - "Error [$declutter]",join('<br />',@_)); + "Error [$declutter]",$msg); &Apache::lonnet::put('nohist_xmlerrornotifications', {$key => $now}, $cdom,$cnum);