--- loncom/xml/lonxml.pm 2006/11/10 19:41:34 1.425
+++ loncom/xml/lonxml.pm 2007/05/14 08:42:13 1.445
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.425 2006/11/10 19:41:34 albertel Exp $
+# $Id: lonxml.pm,v 1.445 2007/05/14 08:42:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,6 +42,7 @@ package Apache::lonxml;
use vars
qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $errorcount $warningcount);
use strict;
+use LONCAPA;
use HTML::LCParser();
use HTML::TreeBuilder();
use HTML::Entities();
@@ -88,6 +89,7 @@ use Apache::loncommon();
use Apache::lonfeedback();
use Apache::lonmsg();
use Apache::loncacc();
+use Apache::lonmaxima();
use Apache::lonlocal;
#================================================== Main subroutine: xmlparse
@@ -549,7 +551,6 @@ sub callsub {
}
my $deleted=0;
- $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
if (($token->[0] eq 'S') && ($target eq 'modified')) {
$deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
$parstack,$parser,$safeeval,
@@ -585,17 +586,23 @@ sub callsub {
} elsif ($token->[0] eq 'E') {
$currentstring = &Apache::edit::tag_end($target,$token);
}
- } elsif ($target eq 'modified') {
+ }
+ }
+ if ($target eq 'modified' && $nodefault eq '') {
+ if ($currentstring eq '') {
+ if ($token->[0] eq 'S') {
+ $currentstring = $token->[4];
+ } elsif ($token->[0] eq 'E') {
+ $currentstring = $token->[2];
+ } else {
+ $currentstring = $token->[2];
+ }
+ }
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];
}
- }
}
}
use strict 'refs';
@@ -674,6 +681,14 @@ sub init_safespace {
'&chem_standard_order');
$safehole->wrap(\&Apache::response::check_status,$safeeval,'&check_status');
+ $safehole->wrap(\&Apache::lonmaxima::maxima_eval,$safeeval,'&maxima_eval');
+ $safehole->wrap(\&Apache::lonmaxima::maxima_check,$safeeval,'&maxima_check');
+ $safehole->wrap(\&Apache::lonmaxima::maxima_cas_formula_fix,$safeeval,
+ '&maxima_cas_formula_fix');
+
+ $safehole->wrap(\&Apache::caparesponse::capa_formula_fix,$safeeval,
+ '&capa_formula_fix');
+
$safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
$safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
$safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
@@ -780,8 +795,8 @@ sub init_safespace {
$safehole->wrap(\&Apache::lonnet::logthis,$safeeval,'&LONCAPA_INTERNAL_LOGTHIS');
$safehole->wrap(\&Apache::inputtags::finalizeawards,$safeeval,'&LONCAPA_INTERNAL_FINALIZEAWARDS');
$safehole->wrap(\&Apache::caparesponse::get_sigrange,$safeeval,'&LONCAPA_INTERNAL_get_sigrange');
- use Data::Dumper;
- $safehole->wrap(\&Data::Dumper::Dumper,$safeeval,'&LONCAPA_INTERNAL_Dumper');
+# use Data::Dumper;
+# $safehole->wrap(\&Data::Dumper::Dumper,$safeeval,'&LONCAPA_INTERNAL_Dumper');
#need to inspect this class of ops
# $safeeval->deny(":base_orig");
$safeeval->permit("require");
@@ -893,51 +908,50 @@ sub end_tag {
sub initdepth {
@Apache::lonxml::depthcounter=();
- $Apache::lonxml::depth=-1;
- $Apache::lonxml::olddepth=-1;
+ undef($Apache::lonxml::last_depth_count);
}
+
my @timers;
my $lasttime;
+# @Apache::lonxml::depthcounter -> count of tags that exist so
+# far at each level
+# $Apache::lonxml::last_depth_count -> when ascending, need to
+# remember the count for the level below the current level (for
+# example going from 1_2 -> 1 -> 1_3 need to remember the 2 )
+
sub increasedepth {
my ($token) = @_;
- $Apache::lonxml::depth++;
- $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
- if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
- $Apache::lonxml::olddepth=$Apache::lonxml::depth;
- }
+ push(@Apache::lonxml::depthcounter,$Apache::lonxml::last_depth_count+1);
+ undef($Apache::lonxml::last_depth_count);
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");
+ my $spacing=' 'x($#Apache::lonxml::depthcounter);
+ $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
+# &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time");
#print "
s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
}
sub decreasedepth {
my ($token) = @_;
- $Apache::lonxml::depth--;
- if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
- $#Apache::lonxml::depthcounter--;
- $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
- }
- if ( $Apache::lonxml::depth < -1) {
- &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
- $Apache::lonxml::depth='-1';
+ if ( $#Apache::lonxml::depthcounter == -1) {
+ &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
}
+ $Apache::lonxml::last_depth_count = pop(@Apache::lonxml::depthcounter);
+
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");
+ my $spacing=' 'x($#Apache::lonxml::depthcounter);
+ $Apache::lonxml::curdepth = join('_',@Apache::lonxml::depthcounter);
+# &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time : ".&tv_interval($timer));
#print "
e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
}
@@ -1195,7 +1209,7 @@ sub writeallows {
my %httpref=();
foreach (@extlinks) {
$httpref{'httpref.'.
- &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
+ &Apache::lonnet::hreflocation($thisdir,&unescape($_))}=$thisurl;
}
@extlinks=();
&Apache::lonnet::appenv(%httpref);
@@ -1332,11 +1346,15 @@ FULLPAGE
my $cleanbut = '';
my $titledisplay=&display_title();
- my %lt=&Apache::lonlocal::texthash('st' => 'Save this',
- 'vi' => 'View',
+ my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit',
+ 'vi' => 'Save and View',
+ 'dv' => 'Discard Edits and View',
+ 'un' => 'undo',
'ed' => 'Edit');
my $buttons=(<