--- loncom/xml/lonxml.pm 2001/12/14 22:59:34 1.141
+++ loncom/xml/lonxml.pm 2002/03/21 20:51:10 1.159
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.141 2001/12/14 22:59:34 albertel Exp $
+# $Id: lonxml.pm,v 1.159 2002/03/21 20:51:10 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -51,7 +51,12 @@
# 8/7,8/9,8/10,8/11,8/15,8/16,8/17,8/18,8/20,8/23,8/24 Gerd Kortemeyer
# Guy Albertelli
# 9/26 Gerd Kortemeyer
-
+# Dec Guy Albertelli
+# YEAR=2002
+# 1/1 Gerd Kortemeyer
+# 1/2 Matthew Hall
+# 1/3 Gerd Kortemeyer
+#
package Apache::lonxml;
use vars
@@ -59,6 +64,7 @@ qw(@pwd @outputstack $redirection $impor
use strict;
use HTML::TokeParser;
use HTML::TreeBuilder;
+use HTML::Entities;
use Safe;
use Safe::Hole;
use Math::Cephes qw(:trigs :hypers :bessels erf erfc);
@@ -74,14 +80,13 @@ sub register {
sub deregister {
my ($space,@taglist) = @_;
- &printalltags();
foreach my $temptag (@taglist) {
my $tempspace = $Apache::lonxml::alltags{$temptag}[-1];
if ($tempspace eq $space) {
pop(@{ $Apache::lonxml::alltags{$temptag} });
}
}
- &printalltags();
+ #&printalltags();
}
use Apache::Constants qw(:common);
@@ -286,11 +291,14 @@ sub printtokenheader {
$reply{'generation'};
if ($target eq 'web') {
+ my %idhash=&Apache::lonnet::idrget($tudom,($tuname));
return
''.
'Checked out for '.$plainname.
'
User: '.$tuname.' at '.$tudom.
+ '
ID: '.$idhash{$tuname}.
'
CourseID: '.$tcrsid.
+ '
Course: '.$ENV{'course.'.$tcrsid.'.description'}.
'
DocID: '.$token.
'
Time: '.localtime().'
';
} else {
@@ -309,12 +317,16 @@ sub fontsettings() {
sub registerurl {
my $forcereg=shift;
+ my $target = shift;
+ my $result = '';
if ($ENV{'request.publicaccess'}) {
return
'';
}
if ($Apache::lonxml::registered && !$forcereg) { return ''; }
$Apache::lonxml::registered=1;
+ my $nothing='';
+ if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
my $hwkadd='';
if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
@@ -340,13 +352,13 @@ ENDGRDS
ENDPARM
}
}
- return (<
// BEGIN LON-CAPA Internal
function LONCAPAreg() {
- menu=window.open("","LONCAPAmenu");
+ menu=window.open("$nothing","LONCAPAmenu","",false);
menu.clearTimeout(menu.menucltim);
menu.currentURL=window.location.pathname;
menu.currentStale=0;
@@ -373,7 +385,7 @@ ENDPARM
}
function LONCAPAstale() {
- menu=window.open("","LONCAPAmenu");
+ menu=window.open("$nothing","LONCAPAmenu","",false);
menu.currentStale=1;
menu.switchbutton
(3,1,'reload.gif','return','location','go(currentURL)');
@@ -392,13 +404,13 @@ ENDPARM
ENDREGTHIS
} else {
- return (<
// BEGIN LON-CAPA Internal
function LONCAPAreg() {
- menu=window.open("","LONCAPAmenu");
+ menu=window.open("$nothing","LONCAPAmenu","",false);
menu.currentStale=1;
menu.clearbut(2,1);
menu.clearbut(2,3);
@@ -419,8 +431,52 @@ ENDREGTHIS
// END LON-CAPA Internal
ENDDONOTREGTHIS
-
}
+ if ($target eq 'edit') {
+ # Javascript routines for construction space:
+ # openbrowser and opensearcher will start the file browser
+ # (lonindexer) and searcher (lonsearchcat) respectively.
+ # Inputs are the name of the html form being used
+ # and the name of the element the selected URL should
+ # be placed in.
+ $result .=<<"ENDBROWSERSCRIPT";
+
+ENDBROWSERSCRIPT
+ }
+ return $result;
}
sub loadevents() {
@@ -456,7 +512,7 @@ sub xmlparse {
($target, my @tenta) = split('&&',$target);
- my @stack = ();
+ my @stack = ();
my @parstack = ();
&initdepth;
@@ -526,8 +582,14 @@ sub inner_xmlparse {
} elsif ($token->[0] eq 'E') {
#clear out any tags that didn't end
while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
- &Apache::lonxml::warning('Missing tag </'.$$stack['-1'].'> in file');
- &end_tag($stack,$parstack,$token);
+ my $lasttag=$$stack[-1];
+ if ($token->[1] =~ /^$lasttag$/i) {
+ &Apache::lonxml::warning('Using tag </'.$token->[1].'> as end tag to <'.$$stack[-1].'>');
+ last;
+ } else {
+ &Apache::lonxml::warning('Found tag </'.$token->[1].'> when looking for </'.$$stack[-1].'> in file');
+ &end_tag($stack,$parstack,$token);
+ }
}
if (exists($$style_for_target{'/'."$token->[1]"})) {
@@ -606,10 +668,16 @@ sub recurse {
$safeeval, $style_for_target);
} elsif ($tokenpat->[0] eq 'E') {
#clear out any tags that didn't end
- while ($tokenpat->[1] ne $innerstack[$#innerstack]
+ while ($tokenpat->[1] ne $innerstack[$#innerstack]
&& ($#innerstack > -1)) {
- &Apache::lonxml::warning('Missing tag </'.$innerstack['-1'].'> in style');
- &end_tag(\@innerstack,\@innerparstack,$tokenpat);
+ my $lasttag=$innerstack[-1];
+ if ($tokenpat->[1] =~ /^$lasttag$/i) {
+ &Apache::lonxml::warning('Using tag </'.$tokenpat->[1].'> as end tag to <'.$innerstack[-1].'>');
+ last;
+ } else {
+ &Apache::lonxml::warning('Found tag </'.$tokenpat->[1].'> when looking for </'.$innerstack[-1].'> in file');
+ &end_tag(\@innerstack,\@innerparstack,$tokenpat);
+ }
}
$partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat,
\@innerstack, \@innerparstack, \@pat,
@@ -670,13 +738,13 @@ sub callsub {
}
if (!$deleted) {
if ($space) {
- #&Apache::lonxml::debug("Calling sub $sub in $space $metamode
\n");
+ #&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
$sub1="$space\:\:$sub";
($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
$parstack,$parser,$safeeval,
$style);
} else {
- #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode
\n");
+ #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
if ($metamode <1) {
if (defined($token->[4]) && ($metamode < 1)) {
$currentstring = $token->[4];
@@ -878,10 +946,10 @@ sub get_all_text {
} elsif ($token->[0] eq 'PI') {
$result.=$token->[2];
} elsif ($token->[0] eq 'S') {
- if ($token->[1] eq $tag) { $depth++; }
+ if ($token->[1] =~ /^$tag$/i) { $depth++; }
$result.=$token->[4];
} elsif ($token->[0] eq 'E') {
- if ( $token->[1] eq $tag) { $depth--; }
+ if ( $token->[1] =~ /^$tag$/i) { $depth--; }
#skip sending back the last end tag
if ($depth > -1) { $result.=$token->[2]; } else {
$pars->unget_token($token);
@@ -896,7 +964,7 @@ sub get_all_text {
} elsif ($token->[0] eq 'PI') {
$result.=$token->[2];
} elsif ($token->[0] eq 'S') {
- if ( $token->[1] eq $tag) {
+ if ( $token->[1] =~ /^$tag$/i) {
$pars->unget_token($token); last;
} else {
$result.=$token->[4];
@@ -926,14 +994,14 @@ sub newparser {
sub parstring {
my ($token) = @_;
my $temp='';
- map {
+ foreach (@{$token->[3]}) {
unless ($_=~/\W/) {
my $val=$token->[2]->{$_};
- $val =~ s/([\%\@\\])/\\$1/g;
+ $val =~ s/([\%\@\\\"])/\\$1/g;
#if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
$temp .= "my \$$_=\"$val\";"
}
- } @{$token->[3]};
+ }
return $temp;
}
@@ -946,10 +1014,10 @@ sub writeallows {
my $thisdir=$thisurl;
$thisdir=~s/\/[^\/]+$//;
my %httpref=();
- map {
+ foreach (@extlinks) {
$httpref{'httpref.'.
&Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
- } @extlinks;
+ }
@extlinks=();
&Apache::lonnet::appenv(%httpref);
}
@@ -959,31 +1027,23 @@ sub writeallows {
#
sub afterburn {
my $result=shift;
- map {
- my ($name, $value) = split(/=/,$_);
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
- unless ($ENV{'form.'.$name}) {
- $ENV{'form.'.$name}=$value;
- }
- }
- } (split(/&/,$ENV{'QUERY_STRING'}));
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['highlight','anchor','link']);
if ($ENV{'form.highlight'}) {
- map {
+ foreach (split(/\,/,$ENV{'form.highlight'})) {
my $anchorname=$_;
my $matchthis=$anchorname;
$matchthis=~s/\_+/\\s\+/g;
$result=~s/($matchthis)/\$1\<\/font\>/gs;
- } split(/\,/,$ENV{'form.highlight'});
+ }
}
if ($ENV{'form.link'}) {
- map {
+ foreach (split(/\,/,$ENV{'form.link'})) {
my ($anchorname,$linkurl)=split(/\>/,$_);
my $matchthis=$anchorname;
$matchthis=~s/\_+/\\s\+/g;
$result=~s/($matchthis)/\$1\<\/a\>/gs;
- } split(/\,/,$ENV{'form.link'});
+ }
}
if ($ENV{'form.anchor'}) {
my $anchorname=$ENV{'form.anchor'};
@@ -1004,13 +1064,13 @@ sub storefile {
if (my $fh=Apache::File->new('>'.$file)) {
print $fh $contents;
$fh->close();
+ } else {
+ &warning("Unable to save file $file");
}
}
-sub inserteditinfo {
- my ($result,$filecontents)=@_;
- unless ($filecontents) {
- $filecontents=(<
@@ -1024,28 +1084,63 @@ sub inserteditinfo {