--- loncom/xml/lonxml.pm 2002/01/18 17:04:46 1.150 +++ loncom/xml/lonxml.pm 2002/03/21 22:10:31 1.160 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.150 2002/01/18 17:04:46 albertel Exp $ +# $Id: lonxml.pm,v 1.160 2002/03/21 22:10:31 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,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); @@ -316,12 +317,17 @@ sub fontsettings() { sub registerurl { my $forcereg=shift; - if ($ENV{'request.publicaccess'}) { + my $target = shift; + my $result = ''; + if (($ENV{'request.publicaccess'}) || + ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html')) { 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)$/) { @@ -347,13 +353,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; @@ -380,7 +386,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)'); @@ -399,13 +405,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); @@ -426,8 +432,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() { @@ -538,7 +588,7 @@ sub inner_xmlparse { &Apache::lonxml::warning('Using tag </'.$token->[1].'> as end tag to <'.$$stack[-1].'>'); last; } else { - &Apache::lonxml::warning('Found tag </'.$$stack[-1].'> when looking for </'.$token->[1].'> in file'); + &Apache::lonxml::warning('Found tag </'.$token->[1].'> when looking for </'.$$stack[-1].'> in file'); &end_tag($stack,$parstack,$token); } } @@ -626,7 +676,7 @@ sub recurse { &Apache::lonxml::warning('Using tag </'.$tokenpat->[1].'> as end tag to <'.$innerstack[-1].'>'); last; } else { - &Apache::lonxml::warning('Found tag </'.$innerstack[-1].'> when looking for </'.$tokenpat->[1].'> in file'); + &Apache::lonxml::warning('Found tag </'.$tokenpat->[1].'> when looking for </'.$innerstack[-1].'> in file'); &end_tag(\@innerstack,\@innerparstack,$tokenpat); } } @@ -689,13 +739,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]; @@ -897,10 +947,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); @@ -915,7 +965,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]; @@ -978,16 +1028,8 @@ sub writeallows { # sub afterburn { my $result=shift; - foreach (split(/&/,$ENV{'QUERY_STRING'})) { - 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; - } - } - } + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['highlight','anchor','link']); if ($ENV{'form.highlight'}) { foreach (split(/\,/,$ENV{'form.highlight'})) { my $anchorname=$_; @@ -1028,10 +1070,8 @@ sub storefile { } } -sub inserteditinfo { - my ($result,$filecontents)=@_; - unless ($filecontents) { - $filecontents=(< @@ -1045,9 +1085,13 @@ sub inserteditinfo { </body> </html> SIMPLECONTENT - } + return $filecontents; +} + - $filecontents =~ s:</textarea>:</textarea>:ig; +sub inserteditinfo { + my ($result,$filecontents)=@_; + $filecontents = &HTML::Entities::encode($filecontents); # my $editheader='<a href="#editsection">Edit below</a><hr />'; my $editfooter=(<<ENDFOOTER); <hr /> @@ -1067,10 +1111,37 @@ ENDFOOTER return $result; } +sub get_target { + my $viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); + if ( $ENV{'request.state'} eq 'published') { + if ( defined($ENV{'form.grade_target'}) + && ($viewgrades == 'F' )) { + return ($ENV{'form.grade_target'}); + } elsif (defined($ENV{'form.grade_target'})) { + if (($ENV{'form.grade_target'} eq 'web') || + ($ENV{'form.grade_target'} eq 'tex') ) { + return $ENV{'form.grade_target'} + } else { + return 'web'; + } + } else { + return 'web'; + } + } elsif ($ENV{'request.state'} eq 'construct') { + if ( defined($ENV{'form.grade_target'})) { + return ($ENV{'form.grade_target'}); + } else { + return 'web'; + } + } else { + return 'web'; + } +} + sub handler { my $request=shift; - my $target='web'; + my $target=&get_target(); $Apache::lonxml::debug=0; @@ -1109,6 +1180,10 @@ sub handler { </html> ENDNOTFOUND $filecontents=''; + if ($ENV{'request.state'} ne 'published') { + $filecontents=&createnewhtml(); + $ENV{'form.showmode'}='Edit'; #force edit mode + } } else { unless ($ENV{'request.state'} eq 'published') { if ($ENV{'form.attemptclean'}) { @@ -1179,6 +1254,7 @@ sub get_param { if ( ! $context ) { $context = -1; } my $args =''; if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; } + if ( ! $args ) { return undef; } if ( $args =~ /my \$$param=\"/ ) { return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #' } else {