--- loncom/xml/lonxml.pm 2004/10/05 18:51:50 1.339 +++ loncom/xml/lonxml.pm 2004/11/30 22:57:16 1.348 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.339 2004/10/05 18:51:50 albertel Exp $ +# $Id: lonxml.pm,v 1.348 2004/11/30 22:57:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -159,7 +159,8 @@ sub xmlbegin { .''; } else { - $output=''; + $output=' +'; } return $output; } @@ -287,7 +288,7 @@ sub fontsettings() { my $headerstring=''; if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) { $headerstring.= - ''; + ''; } elsif (!$ENV{'browser.mathml'} && $ENV{'browser.unicode'}) { $headerstring.= ''; @@ -824,9 +825,12 @@ sub increasedepth { if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) { $Apache::lonxml::olddepth=$Apache::lonxml::depth; } - push(@timers,[&gettimeofday()]); - my $time=&tv_interval($lasttime); - $lasttime=[&gettimeofday()]; + my $time; + if ($Apache::lonxml::debug eq "1") { + push(@timers,[&gettimeofday()]); + $time=&tv_interval($lasttime); + $lasttime=[&gettimeofday()]; + } my $spacing=' 'x($Apache::lonxml::depth-1); my $curdepth=join('_',@Apache::lonxml::depthcounter); &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : \n"); @@ -844,9 +848,12 @@ sub decreasedepth { &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file.")); $Apache::lonxml::depth='-1'; } - my $timer=pop(@timers); - my $time=&tv_interval($lasttime); - $lasttime=[&gettimeofday()]; + my ($timer,$time); + if ($Apache::lonxml::debug eq "1") { + $timer=pop(@timers); + $time=&tv_interval($lasttime); + $lasttime=[&gettimeofday()]; + } my $spacing=' 'x$Apache::lonxml::depth; my $curdepth=join('_',@Apache::lonxml::depthcounter); &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : ".&tv_interval($timer)."\n"); @@ -1022,6 +1029,8 @@ sub parstring { unless ($_=~/\W/) { my $val=$token->[2]->{$_}; $val =~ s/([\%\@\\\"\'])/\\$1/g; + $val =~ s/(\$[^{a-zA-Z_])/\\$1/g; + $val =~ s/(\$)$/\\$1/; #if ($val =~ m/^[\%\@]/) { $val="\\".$val; } $temp .= "my \$$_=\"$val\";"; } @@ -1148,7 +1157,10 @@ sub inserteditinfo { if ($filetype eq 'html') { my $addbuttons=&Apache::lonhtmlcommon::htmlareaaddbuttons(); $initialize=&Apache::lonhtmlcommon::htmlareaheaders(). - &Apache::lonhtmlcommon::spellheader().(< $addbuttons @@ -1161,6 +1173,15 @@ $addbuttons } FULLPAGE + } else { + $initialize.=(< +$addbuttons + function initDocument() { + } + +FULLPAGE + } $result=~s/\]*)\>/\/i; $xml_help=&Apache::loncommon::helpLatexCheatsheet(); } @@ -1281,7 +1302,7 @@ $bodytag ENDNOTFOUND - $filecontents=''; + $filecontents=''; if ($ENV{'request.state'} ne 'published') { if ($filetype eq 'sty') { $filecontents=&createnewsty(); @@ -1292,6 +1313,10 @@ ENDNOTFOUND } } else { unless ($ENV{'request.state'} eq 'published') { + if ($filecontents=~/BEGIN LON-CAPA Internal/) { + &Apache::lonxml::error(&mt('This file appears to be a rendering of a Lon-CAPA resource. If this is correct, this resource will act very oddly and incorrectly.')); + } + if ($ENV{'form.attemptclean'}) { $filecontents=&htmlclean($filecontents,1); } @@ -1348,13 +1373,21 @@ sub debug { my $request=$Apache::lonxml::request; if (!$request) { $request=Apache->request; } $request->print('
DEBUG:'.&HTML::Entities::encode($_[0],'<>&"')."
\n"); -# &Apache::lonnet::logthis($_[0]); + #&Apache::lonnet::logthis($_[0]); } } +sub show_error_warn_msg { + return (($Apache::lonxml::debug eq 1) || + ($ENV{'request.state'} eq 'construct') || + ($Apache::lonhomework::browse eq 'F' + && + $ENV{'form.show_errors'} eq 'on')); +} + sub error { $errorcount++; - if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) { + if ( &show_error_warn_msg() ) { # If printing in construction space, put the error inside

 	push(@Apache::lonxml::error_messages,
 	     $Apache::lonxml::warnings_error_header.
@@ -1394,7 +1427,7 @@ sub warning {
     $warningcount++;
   
     if ($ENV{'form.grade_target'} ne 'tex') {
-	if ($ENV{'request.state'} eq 'construct' || $Apache::lonxml::debug) {
+	if ( &show_error_warn_msg() ) {
 	    my $request=$Apache::lonxml::request;
 	    if (!$request) { $request=Apache->request; }
 	    push(@Apache::lonxml::warning_messages,
@@ -1471,7 +1504,7 @@ sub get_param_var {
   } elsif ( $args !~ /my \$\Q$param\E=\"/ ) { return undef; }
   my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
   &Apache::lonxml::debug("first run is $value");
-  if ($value =~ /^[\$\@\%]\w+$/) {
+  if ($value =~ /^[\$\@\%][a-zA-Z_]\w*$/) {
       &Apache::lonxml::debug("doing second");
       my @result=&Apache::run::run("return $value",$safeeval,1);
       if (!defined($result[0])) {
@@ -1561,6 +1594,12 @@ sub whichuser {
   if (defined($ENV{'form.grade_symb'})) {
     my $tmp_courseid=$ENV{'form.grade_courseid'};
     my $allowed=&Apache::lonnet::allowed('vgr',$tmp_courseid);
+    if (!$allowed && 
+	exists($ENV{'request.course.sec'}) && 
+	$ENV{'request.course.sec'} !~ /^\s*$/) {
+	$allowed=&Apache::lonnet::allowed('vgr',$ENV{'form.grade_courseid'}.
+					  '/'.$ENV{'request.course.sec'});
+    }
     if ($allowed) {
       $symb=$ENV{'form.grade_symb'};
       $courseid=$ENV{'form.grade_courseid'};