--- loncom/xml/lonxml.pm 2002/10/11 20:52:13 1.201
+++ loncom/xml/lonxml.pm 2002/11/06 22:36:08 1.211
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.201 2002/10/11 20:52:13 www Exp $
+# $Id: lonxml.pm,v 1.211 2002/11/06 22:36:08 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -60,7 +60,7 @@
package Apache::lonxml;
use vars
-qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode);
+qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode $errorcount $warningcount);
use strict;
use HTML::LCParser();
use HTML::TreeBuilder();
@@ -106,6 +106,10 @@ use Apache::lonmsg();
#debugging control, to turn on debugging modify the correct handler
$Apache::lonxml::debug=0;
+# keeps count of the number of warnings and errors generated in a parse
+$warningcount=0;
+$errorcount=0;
+
#path to the directory containing the file currently being processed
@pwd=();
@@ -140,6 +144,10 @@ $Apache::lonxml::registered=0;
# a pointer the the Apache request object
$Apache::lonxml::request='';
+# a problem number counter, and check on hether it is used
+$Apache::lonxml::counter=0;
+$Apache::lonxml::counter_changed=0;
+
sub xmlbegin {
my $output='';
if ($ENV{'browser.mathml'}) {
@@ -520,7 +528,7 @@ sub xmlparse {
# do we have a course style file?
#
- if ($ENV{'request.course.id'}) {
+ if ($ENV{'request.course.id'} && $ENV{'request.state'} ne 'construct') {
my $bodytext=
$ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'};
if ($bodytext) {
@@ -555,6 +563,7 @@ sub xmlparse {
if ($ENV{'request.uri'}) {
&writeallows($ENV{'request.uri'});
}
+ if ($Apache::lonxml::counter_changed) { &store_counter() }
return $finaloutput;
}
@@ -585,11 +594,7 @@ sub latex_special_symbols {
$current_token=~s/\^/\\char94 /g;
$current_token=~s/\~/\\char126 /g;
$current_token=~s/(&[^a-z\#])/\\$1/g;
- if ($current_token=~/ \#\w/) {
- $current_token=~s/ \#(\w)/ \\#$1/;
- } else {
- $current_token=~s/([^&])(\#)/$1\\$2/g;
- }
+ $current_token=~s/([^&])\#/$1\\#/g;
$current_token=~s/(\$|_|{|})/\\$1/g;
$current_token=~s/\\char92 /\\texttt{\\char92}/g;
$current_token=~s/>/\$>\$/g; #more
@@ -836,6 +841,9 @@ sub callsub {
if ($token->[0] eq 'S') {
$currentstring = $token->[4];
$currentstring.=&Apache::edit::handle_insert();
+ } elsif ($token->[0] eq 'E') {
+ $currentstring = $token->[2];
+ $currentstring.=&Apache::edit::handle_insertafter($token->[1]);
} else {
$currentstring = $token->[2];
}
@@ -851,6 +859,10 @@ sub setup_globals {
my ($request,$target)=@_;
$Apache::lonxml::request=$request;
$Apache::lonxml::registered = 0;
+ $errorcount=0;
+ $warningcount=0;
+ $Apache::lonxml::default_homework_loaded=0;
+ &init_counter();
@Apache::lonxml::pwd=();
@Apache::lonxml::extlinks=();
if ($target eq 'meta') {
@@ -951,6 +963,18 @@ sub init_safespace {
&Apache::run::run($safeinit,$safeeval);
}
+sub default_homework_load {
+ my ($safeeval)=@_;
+ &Apache::lonxml::debug('Loading default_homework');
+ my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
+ if ($default == -1) {
+ &Apache::lonxml::error("Unable to find default_homework.lcpm");
+ } else {
+ &Apache::run::run($default,$safeeval);
+ $Apache::lonxml::default_homework_loaded=1;
+ }
+}
+
sub startredirection {
$Apache::lonxml::redirection++;
push (@Apache::lonxml::outputstack, '');
@@ -1022,7 +1046,7 @@ sub get_all_text_unbalanced {
} elsif ($token->[0] eq 'E') {
$result.=$token->[2];
}
- if ($result =~ /(.*)$tag(.*)/) {
+ if ($result =~ /(.*)\Q$tag\E(.*)/s) {
&Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
&Apache::lonxml::debug('Result is :'.$1);
$result=$1;
@@ -1034,6 +1058,26 @@ sub get_all_text_unbalanced {
return $result
}
+sub increment_counter {
+ $Apache::lonxml::counter++;
+ $Apache::lonxml::counter_changed=1;
+}
+
+sub init_counter {
+ if (defined($ENV{'form.counter'})) {
+ $Apache::lonxml::counter=$ENV{'form.counter'};
+ } elsif (not defined($Apache::lonxml::counter)) {
+ $Apache::lonxml::counter=1;
+ &store_counter();
+ }
+ $Apache::lonxml::counter_changed=0;
+}
+
+sub store_counter {
+ &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter));
+ return '';
+}
+
sub get_all_text {
my($tag,$pars)= @_;
my $depth=0;
@@ -1325,11 +1369,12 @@ ENDNOTFOUND
sub debug {
if ($Apache::lonxml::debug eq 1) {
$|=1;
- print("DEBUG:".&HTML::Entities::encode($_[0])."
\n");
+ print('DEBUG:'.&HTML::Entities::encode($_[0])."\n");
}
}
sub error {
+ $errorcount++;
if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
# If printing in construction space, put the error inside