Annotation of loncom/xml/lonxml.pm, revision 1.390

1.2       sakharuk    1: # The LearningOnline Network with CAPA
1.3       sakharuk    2: # XML Parser Module 
1.2       sakharuk    3: #
1.390   ! albertel    4: # $Id: lonxml.pm,v 1.389 2005/11/15 16:38:12 albertel Exp $
1.139     www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson. 
                     29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into 
                     30: # binary executable programs or libraries distributed by the 
                     31: # Michigan State University (the "Licensee"), but any binaries so 
                     32: # distributed are hereby licensed only for use in the context
                     33: # of a program or computational system for which the Licensee is the 
                     34: # primary author or distributor, and which performs substantial 
                     35: # additional tasks beyond the translation of (La)TeX into HTML.
                     36: # The C source of the Code may not be distributed by the Licensee
                     37: # to any other parties under any circumstances.
                     38: #
1.316     albertel   39: 
1.2       sakharuk   40: 
1.4       albertel   41: package Apache::lonxml; 
1.33      www        42: use vars 
1.320     www        43: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $errorcount $warningcount @htmlareafields);
1.1       sakharuk   44: use strict;
1.167     albertel   45: use HTML::LCParser();
1.161     albertel   46: use HTML::TreeBuilder();
                     47: use HTML::Entities();
                     48: use Safe();
                     49: use Safe::Hole();
                     50: use Math::Cephes();
                     51: use Math::Random();
                     52: use Opcode();
1.271     www        53: use POSIX qw(strftime);
1.339     albertel   54: use Time::HiRes qw( gettimeofday tv_interval );
1.266     bowersj2   55: 
1.72      albertel   56: sub register {
1.141     albertel   57:   my ($space,@taglist) = @_;
                     58:   foreach my $temptag (@taglist) {
                     59:     push(@{ $Apache::lonxml::alltags{$temptag} },$space);
1.72      albertel   60:   }
                     61: }
                     62: 
1.141     albertel   63: sub deregister {
                     64:   my ($space,@taglist) = @_;
                     65:   foreach my $temptag (@taglist) {
                     66:     my $tempspace = $Apache::lonxml::alltags{$temptag}[-1];
                     67:     if ($tempspace eq $space) {
                     68:       pop(@{ $Apache::lonxml::alltags{$temptag} });
                     69:     }
                     70:   }
1.142     albertel   71:   #&printalltags();
1.141     albertel   72: }
                     73: 
1.46      www        74: use Apache::Constants qw(:common);
1.161     albertel   75: use Apache::lontexconvert();
                     76: use Apache::style();
                     77: use Apache::run();
                     78: use Apache::londefdef();
                     79: use Apache::scripttag();
1.285     www        80: use Apache::languagetags();
1.161     albertel   81: use Apache::edit();
1.266     bowersj2   82: use Apache::inputtags();
                     83: use Apache::outputtags();
1.372     albertel   84: use Apache::lonnet;
1.161     albertel   85: use Apache::File();
                     86: use Apache::loncommon();
1.198     www        87: use Apache::lonfeedback();
1.200     www        88: use Apache::lonmsg();
1.217     matthew    89: use Apache::loncacc();
1.280     www        90: use Apache::lonlocal;
1.79      www        91: 
1.72      albertel   92: #==================================================   Main subroutine: xmlparse  
                     93: #debugging control, to turn on debugging modify the correct handler
                     94: $Apache::lonxml::debug=0;
1.206     albertel   95: 
                     96: # keeps count of the number of warnings and errors generated in a parse
                     97: $warningcount=0;
                     98: $errorcount=0;
1.72      albertel   99: 
                    100: #path to the directory containing the file currently being processed
                    101: @pwd=();
                    102: 
                    103: #these two are used for capturing a subset of the output for later processing,
                    104: #don't touch them directly use &startredirection and &endredirection
                    105: @outputstack = ();
                    106: $redirection = 0;
                    107: 
                    108: #controls wheter the <import> tag actually does
                    109: $import = 1;
                    110: @extlinks=();
                    111: 
                    112: # meta mode is a bit weird only some output is to be turned off
                    113: #<output> tag turns metamode off (defined in londefdef.pm)
                    114: $metamode = 0;
                    115: 
                    116: # turns on and of run::evaluate actually derefencing var refs
                    117: $evaluate = 1;
1.7       albertel  118: 
1.74      albertel  119: # data structure for eidt mode, determines what tags can go into what other tags
                    120: %insertlist=();
1.68      www       121: 
1.99      albertel  122: # stores the list of active tag namespaces
1.76      albertel  123: @namespace=();
                    124: 
1.99      albertel  125: # has the dynamic menu been updated to know about this resource
                    126: $Apache::lonxml::registered=0;
                    127: 
1.172     albertel  128: # a pointer the the Apache request object
                    129: $Apache::lonxml::request='';
                    130: 
1.216     sakharuk  131: # a problem number counter, and check on ether it is used
1.237     sakharuk  132: $Apache::lonxml::counter=1;
1.204     albertel  133: $Apache::lonxml::counter_changed=0;
                    134: 
1.212     albertel  135: #internal check on whether to look at style defs
                    136: $Apache::lonxml::usestyle=1;
1.260     albertel  137: 
                    138: #locations used to store the parameter string for style substitutions
                    139: $Apache::lonxml::style_values='';
                    140: $Apache::lonxml::style_end_values='';
1.212     albertel  141: 
1.281     albertel  142: #array of ssi calls that need to occur after we are done parsing
                    143: @Apache::lonxml::ssi_info=();
                    144: 
1.282     albertel  145: #should we do the postag variable interpolation
                    146: $Apache::lonxml::post_evaluate=1;
                    147: 
1.295     albertel  148: #a header message to emit in the case of any generated warning or errors
                    149: $Apache::lonxml::warnings_error_header='';
                    150: 
1.68      www       151: sub xmlbegin {
1.356     albertel  152:     my ($style)=@_;
                    153:     my $output='';
                    154:     @htmlareafields=();
1.372     albertel  155:     if ($env{'browser.mathml'}) {
1.356     albertel  156: 	$output='<?xml version="1.0"?>'
1.357     albertel  157:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                    158: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                    159:             
                    160: #	    .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">] >'
                    161: 	    .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
1.68      www       162:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
1.357     albertel  163: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
1.356     albertel  164:     } else {
                    165: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                    166:     }
                    167:     if ($style eq 'encode') {
                    168: 	$output=&HTML::Entities::encode($output,'<>&"');
                    169:     }
                    170:     return $output;
1.68      www       171: }
                    172: 
                    173: sub xmlend {
1.335     sakharuk  174:     my ($target,$parser)=@_;
1.278     www       175:     my $mode='xml';
                    176:     my $status='OPEN';
1.368     albertel  177:     if ($Apache::lonhomework::parsing_a_problem ||
                    178: 	$Apache::lonhomework::parsing_a_task ) {
1.278     www       179: 	$mode='problem';
                    180: 	$status=$Apache::inputtags::status[-1]; 
                    181:     }
1.362     matthew   182:     my $discussion;
1.379     albertel  183:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    184: 					   ['LONCAPA_INTERNAL_no_discussion']);
1.372     albertel  185:     if (! exists($env{'form.LONCAPA_INTERNAL_no_discussion'}) ||
                    186:         $env{'form.LONCAPA_INTERNAL_no_discussion'} ne 'true') {
1.362     matthew   187:         $discussion=&Apache::lonfeedback::list_discussion($mode,$status);
                    188:     }
1.334     sakharuk  189:     if ($target eq 'tex') {
1.335     sakharuk  190: 	$discussion.='<tex>\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\end{document}</tex>';
1.334     sakharuk  191: 	&Apache::lonxml::newparser($parser,\$discussion,'');
                    192: 	return '';
                    193:     } else {
1.360     albertel  194: 	return $discussion.&Apache::loncommon::endbodytag();
1.334     sakharuk  195:     }
1.119     www       196: }
                    197: 
                    198: sub tokeninputfield {
1.120     www       199:     my $defhost=$Apache::lonnet::perlvar{'lonHostID'};
                    200:     $defhost=~tr/a-z/A-Z/;
1.119     www       201:     return (<<ENDINPUTFIELD)
1.226     albertel  202: <script type="text/javascript">
1.120     www       203:     function updatetoken() {
                    204: 	var comp=new Array;
                    205:         var barcode=unescape(document.tokeninput.barcode.value);
                    206:         comp=barcode.split('*');
                    207:         if (typeof(comp[0])!="undefined") {
                    208: 	    document.tokeninput.codeone.value=comp[0];
                    209: 	}
                    210:         if (typeof(comp[1])!="undefined") {
                    211: 	    document.tokeninput.codetwo.value=comp[1];
                    212: 	}
                    213:         if (typeof(comp[2])!="undefined") {
                    214:             comp[2]=comp[2].toUpperCase();
                    215: 	    document.tokeninput.codethree.value=comp[2];
                    216: 	}
                    217:         document.tokeninput.barcode.value='';
                    218:     }  
                    219: </script>
                    220: <form method="post" name="tokeninput">
1.119     www       221: <table border="2" bgcolor="#FFFFBB">
                    222: <tr><th>DocID Checkin</th></tr>
                    223: <tr><td>
                    224: <table>
                    225: <tr>
                    226: <td>Scan in Barcode</td>
1.120     www       227: <td><input type="text" size="22" name="barcode" 
                    228: onChange="updatetoken()"/></td>
1.119     www       229: </tr>
                    230: <tr><td><i>or</i> Type in DocID</td>
                    231: <td>
                    232: <input type="text" size="5" name="codeone" />
1.120     www       233: <b><font size="+2">*</font></b>
1.119     www       234: <input type="text" size="5" name="codetwo" />
1.120     www       235: <b><font size="+2">*</font></b>
                    236: <input type="text" size="10" name="codethree" value="$defhost" 
                    237: onChange="this.value=this.value.toUpperCase()" />
1.119     www       238: </td></tr>
                    239: </table>
                    240: </td></tr>
                    241: <tr><td><input type="submit" value="Check in DocID" /></td></tr>
                    242: </table>
                    243: </form>
                    244: ENDINPUTFIELD
1.112     www       245: }
                    246: 
1.116     www       247: sub maketoken {
1.118     www       248:     my ($symb,$tuname,$tudom,$tcrsid)=@_;
1.112     www       249:     unless ($symb) {
                    250: 	$symb=&Apache::lonnet::symbread();
                    251:     }
                    252:     unless ($tuname) {
1.372     albertel  253: 	$tuname=$env{'user.name'};
                    254:         $tudom=$env{'user.domain'};
                    255:         $tcrsid=$env{'request.course.id'};
1.112     www       256:     }
1.116     www       257: 
1.118     www       258:     return &Apache::lonnet::checkout($symb,$tuname,$tudom,$tcrsid);
                    259: }
                    260: 
                    261: sub printtokenheader {
1.133     albertel  262:     my ($target,$token,$tsymb,$tcrsid,$tudom,$tuname)=@_;
1.116     www       263:     unless ($token) { return ''; }
1.118     www       264: 
1.133     albertel  265:     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
                    266:     unless ($tsymb) {
                    267: 	$tsymb=$symb;
1.118     www       268:     }
                    269:     unless ($tuname) {
1.133     albertel  270: 	$tuname=$name;
                    271:         $tudom=$domain;
                    272:         $tcrsid=$courseid;
1.118     www       273:     }
1.114     www       274: 
1.390   ! albertel  275:     my $plainname=&Apache::loncommon::plainname($tuname,$tudom);
1.114     www       276: 
1.112     www       277:     if ($target eq 'web') {
1.145     www       278:         my %idhash=&Apache::lonnet::idrget($tudom,($tuname));
1.115     www       279: 	return 
1.221     albertel  280:  '<img align="right" src="/cgi-bin/barcode.png?encode='.$token.'" />'.
1.284     www       281:                &mt('Checked out for').' '.$plainname.
                    282:                '<br />'.&mt('User').': '.$tuname.' at '.$tudom.
                    283: 	       '<br />'.&mt('ID').': '.$idhash{$tuname}.
                    284: 	       '<br />'.&mt('CourseID').': '.$tcrsid.
1.372     albertel  285: 	       '<br />'.&mt('Course').': '.$env{'course.'.$tcrsid.'.description'}.
1.284     www       286:                '<br />'.&mt('DocID').': '.$token.
                    287:                '<br />'.&mt('Time').': '.&Apache::lonlocal::locallocaltime().'<hr />';
1.112     www       288:     } else {
1.121     albertel  289:         return $token;
1.112     www       290:     }
1.68      www       291: }
                    292: 
1.356     albertel  293: sub fontsettings {
1.70      www       294:     my $headerstring='';
1.372     albertel  295:     if (($env{'browser.os'} eq 'mac') && (!$env{'browser.mathml'})) { 
1.248     albertel  296: 	$headerstring.=
1.343     albertel  297: 	    '<meta Content-Type="text/html; charset=x-mac-roman" />';
1.372     albertel  298:     } elsif (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.248     albertel  299: 	$headerstring.=
                    300: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
1.70      www       301:     }
                    302:     return $headerstring;
1.68      www       303: }
                    304: 
1.48      albertel  305: sub printalltags {
                    306:   my $temp;
                    307:   foreach $temp (sort keys %Apache::lonxml::alltags) {
1.141     albertel  308:     &Apache::lonxml::debug("$temp -- ".
                    309: 		  join(',',@{ $Apache::lonxml::alltags{$temp} }));
1.48      albertel  310:   }
                    311: }
1.31      sakharuk  312: 
1.3       sakharuk  313: sub xmlparse {
1.172     albertel  314:  my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
1.96      albertel  315: 
1.172     albertel  316:  &setup_globals($request,$target);
1.232     albertel  317:  &Apache::inputtags::initialize_inputtags();
1.370     albertel  318:  &Apache::bridgetask::initialize_bridgetask();
1.232     albertel  319:  &Apache::outputtags::initialize_outputtags();
                    320:  &Apache::edit::initialize_edit();
1.287     albertel  321:  &Apache::londefdef::initialize_londefdef();
1.244     albertel  322: 
1.178     www       323: #
                    324: # do we have a course style file?
                    325: #
                    326: 
1.372     albertel  327:  if ($env{'request.course.id'} && $env{'request.state'} ne 'construct') {
1.178     www       328:      my $bodytext=
1.372     albertel  329: 	 $env{'course.'.$env{'request.course.id'}.'.default_xml_style'};
1.178     www       330:      if ($bodytext) {
1.337     albertel  331: 	 foreach my $file (split(',',$bodytext)) {
                    332: 	     my $location=&Apache::lonnet::filelocation('',$file);
                    333: 	     my $styletext=&Apache::lonnet::getfile($location);
                    334: 	     if ($styletext ne '-1') {
                    335: 		 %style_for_target = (%style_for_target,
                    336: 				      &Apache::style::styleparser($target,$styletext));
                    337: 	     }
                    338: 	 }
                    339:      }
1.372     albertel  340:  } elsif ($env{'construct.style'} && ($env{'request.state'} eq 'construct')) {
                    341:      my $location=&Apache::lonnet::filelocation('',$env{'construct.style'});
1.291     sakharuk  342:      my $styletext=&Apache::lonnet::getfile($location);
                    343:        if ($styletext ne '-1') {
                    344:           %style_for_target = (%style_for_target,
                    345:                           &Apache::style::styleparser($target,$styletext));
                    346:       }
1.178     www       347:  }
1.255     sakharuk  348: #&printalltags();
1.16      albertel  349:  my @pars = ();
1.372     albertel  350:  my $pwd=$env{'request.filename'};
1.23      albertel  351:  $pwd =~ s:/[^/]*$::;
                    352:  &newparser(\@pars,\$content_file_string,$pwd);
1.24      sakharuk  353: 
1.3       sakharuk  354:  my $safeeval = new Safe;
1.40      albertel  355:  my $safehole = new Safe::Hole;
1.82      ng        356:  &init_safespace($target,$safeeval,$safehole,$safeinit);
1.3       sakharuk  357: #-------------------- Redefinition of the target in the case of compound target
                    358: 
                    359:  ($target, my @tenta) = split('&&',$target);
                    360: 
1.150     albertel  361:  my @stack = ();
1.3       sakharuk  362:  my @parstack = ();
1.358     albertel  363:  &initdepth();
                    364:  &init_alarm();
1.101     albertel  365:  my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
                    366: 				   $safeeval,\%style_for_target);
1.255     sakharuk  367: 
1.372     albertel  368:  if ($env{'request.uri'}) {
                    369:     &writeallows($env{'request.uri'});
1.125     www       370:  }
1.281     albertel  371:  &do_registered_ssi();
1.204     albertel  372:  if ($Apache::lonxml::counter_changed) { &store_counter() }
1.372     albertel  373:  if ($env{'form.return_only_error_and_warning_counts'}) {
1.361     www       374:      return "$errorcount:$warningcount";
                    375:  }
1.3       sakharuk  376:  return $finaloutput;
1.106     www       377: }
                    378: 
1.191     albertel  379: sub latex_special_symbols {
1.272     albertel  380:     my ($string,$where)=@_;
1.235     sakharuk  381:     if ($where eq 'header') {
1.272     albertel  382: 	$string =~ s/(\\|_|\^)/ /g;
1.311     albertel  383: 	$string =~ s/(\$|%|\{|\})/\\$1/g;
1.273     sakharuk  384: 	$string =~ s/_/ /g;
1.311     albertel  385: 	$string=&Apache::lonprintout::character_chart($string);
                    386: 	# any & or # leftover should be safe to just escape
                    387:         $string=~s/([^\\])\&/$1\\\&/g;
                    388:         $string=~s/([^\\])\#/$1\\\#/g;
1.229     sakharuk  389:     } else {
1.312     albertel  390: 	$string=~s/\\/\\ensuremath{\\backslash}/g;
1.367     albertel  391: 	$string=~s/\\\%|\%/\\\%/g;
                    392: 	$string=~s/\\{|{/\\{/g;
                    393: 	$string=~s/\\}|}/\\}/g;
1.378     albertel  394: 	$string=~s/\\ensuremath\\{\\backslash\\}/\\ensuremath{\\backslash}/g;
1.367     albertel  395: 	$string=~s/\\\$|\$/\\\$/g;
                    396: 	$string=~s/\\\_|\_/\\\_/g;
1.313     albertel  397:         $string=~s/([^\\]|^)(\~|\^)/$1\\$2\\strut /g;
1.310     sakharuk  398: 	$string=~s/(>|<)/\\ensuremath\{$1\}/g; #more or less
1.311     albertel  399: 	$string=&Apache::lonprintout::character_chart($string);
                    400: 	# any & or # leftover should be safe to just escape
1.367     albertel  401: 	$string=~s/\\\&|\&/\\\&/g;
                    402: 	$string=~s/\\\#|\#/\\\#/g;
1.332     sakharuk  403:         $string=~s/\|/\$\\mid\$/g;
1.310     sakharuk  404: #single { or } How to escape?
1.229     sakharuk  405:     }
1.272     albertel  406:     return $string;
1.188     sakharuk  407: }
                    408: 
1.101     albertel  409: sub inner_xmlparse {
                    410:   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
                    411:   my $finaloutput = '';
                    412:   my $result;
                    413:   my $token;
1.258     albertel  414:   my $dontpop=0;
1.389     albertel  415:   my $startredirection = $Apache::lonxml::redirection;
1.101     albertel  416:   while ( $#$pars > -1 ) {
                    417:     while ($token = $$pars['-1']->get_token) {
1.261     albertel  418:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') ) {
1.101     albertel  419: 	if ($metamode<1) {
1.190     albertel  420: 	    my $text=$token->[1];
1.193     albertel  421: 	    if ($token->[0] eq 'C' && $target eq 'tex') {
1.239     sakharuk  422: 		$text = '';
                    423: #		$text = '%'.$text."\n";
1.182     sakharuk  424: 	    }
1.190     albertel  425: 	    $result.=$text;
1.101     albertel  426: 	}
1.261     albertel  427:       } elsif (($token->[0] eq 'D')) {
                    428: 	if ($metamode<1 && $target eq 'web') {
                    429: 	    my $text=$token->[1];
                    430: 	    $result.=$text;
                    431: 	}
1.101     albertel  432:       } elsif ($token->[0] eq 'PI') {
1.261     albertel  433: 	if ($metamode<1 && $target eq 'web') {
1.101     albertel  434: 	  $result=$token->[2];
                    435: 	}
                    436:       } elsif ($token->[0] eq 'S') {
1.140     albertel  437: 	# add tag to stack
1.101     albertel  438: 	push (@$stack,$token->[1]);
                    439: 	# add parameters list to another stack
                    440: 	push (@$parstack,&parstring($token));
1.140     albertel  441: 	&increasedepth($token);
1.212     albertel  442: 	if ($Apache::lonxml::usestyle &&
                    443: 	    exists($$style_for_target{$token->[1]})) {
                    444: 	    $Apache::lonxml::usestyle=0;
                    445: 	    my $string=$$style_for_target{$token->[1]}.
                    446: 	      '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
                    447: 	    &Apache::lonxml::newparser($pars,\$string);
1.257     albertel  448: 	    $Apache::lonxml::style_values=$$parstack[-1];
1.259     albertel  449: 	    $Apache::lonxml::style_end_values=$$parstack[-1];
1.101     albertel  450: 	} else {
                    451: 	  $result = &callsub("start_$token->[1]", $target, $token, $stack,
                    452: 			     $parstack, $pars, $safeeval, $style_for_target);
1.140     albertel  453: 	}
1.101     albertel  454:       } elsif ($token->[0] eq 'E') {
1.212     albertel  455: 	if ($Apache::lonxml::usestyle &&
                    456: 	    exists($$style_for_target{'/'."$token->[1]"})) {
                    457: 	    $Apache::lonxml::usestyle=0;
                    458: 	    my $string=$$style_for_target{'/'.$token->[1]}.
1.258     albertel  459: 	      '<LONCAPA_INTERNAL_TURN_STYLE_ON end="'.$token->[1].'" />';
1.212     albertel  460: 	    &Apache::lonxml::newparser($pars,\$string);
1.259     albertel  461: 	    $Apache::lonxml::style_values=$Apache::lonxml::style_end_values;
                    462: 	    $Apache::lonxml::style_end_values='';
1.258     albertel  463: 	    $dontpop=1;
1.101     albertel  464: 	} else {
1.258     albertel  465: 	    #clear out any tags that didn't end
                    466: 	    while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
                    467: 		my $lasttag=$$stack[-1];
1.317     albertel  468: 		if ($token->[1] =~ /^\Q$lasttag\E$/i) {
1.258     albertel  469: 		    &Apache::lonxml::warning('Using tag &lt;/'.$token->[1].'&gt; on line '.$token->[3].' as end tag to &lt;'.$$stack[-1].'&gt;');
                    470: 		    last;
                    471: 		} else {
                    472: 		    &Apache::lonxml::warning('Found tag &lt;/'.$token->[1].'&gt; on line '.$token->[3].' when looking for &lt;/'.$$stack[-1].'&gt; in file');
                    473: 		    &end_tag($stack,$parstack,$token);
                    474: 		}
                    475: 	    }
                    476: 	    $result = &callsub("end_$token->[1]", $target, $token, $stack,
                    477: 			       $parstack, $pars,$safeeval, $style_for_target);
1.101     albertel  478: 	}
                    479:       } else {
                    480: 	&Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
                    481:       }
                    482:       #evaluate variable refs in result
1.282     albertel  483:       if ($Apache::lonxml::post_evaluate &&$result ne "") {
1.257     albertel  484: 	  my $extras;
                    485: 	  if (!$Apache::lonxml::usestyle) {
                    486: 	      $extras=$Apache::lonxml::style_values;
                    487: 	  }
1.101     albertel  488: 	if ( $#$parstack > -1 ) {
1.257     albertel  489: 	  $result=&Apache::run::evaluate($result,$safeeval,$extras.$$parstack[-1]);
1.101     albertel  490: 	} else {
1.257     albertel  491: 	  $result= &Apache::run::evaluate($result,$safeeval,$extras);
1.101     albertel  492: 	}
1.163     albertel  493:       }
1.282     albertel  494:       $Apache::lonxml::post_evaluate=1;
                    495: 
1.190     albertel  496:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
1.249     albertel  497: 	  #Style file definitions should be correct
1.250     albertel  498: 	  if ($target eq 'tex' && ($Apache::lonxml::usestyle)) {
1.311     albertel  499: 	      $result=&latex_special_symbols($result);
1.249     albertel  500: 	  }
1.190     albertel  501:       }
                    502: 
1.169     albertel  503:       if ($Apache::lonxml::redirection) {
                    504: 	$Apache::lonxml::outputstack['-1'] .= $result;
                    505:       } else {
                    506: 	$finaloutput.=$result;
                    507:       }
                    508:       $result = '';
                    509: 
1.258     albertel  510:       if ($token->[0] eq 'E' && !$dontpop) {
1.101     albertel  511: 	&end_tag($stack,$parstack,$token);
                    512:       }
1.258     albertel  513:       $dontpop=0;
1.224     albertel  514:     }	
1.212     albertel  515:     if ($#$pars > -1) {
                    516: 	pop @$pars;
                    517: 	pop @Apache::lonxml::pwd;
                    518:     }
1.101     albertel  519:   }
                    520: 
                    521:   # if ($target eq 'meta') {
                    522:   #   $finaloutput.=&endredirection;
                    523:   # }
                    524: 
1.387     albertel  525:   if ($target eq 'grade') { &endredirection(); }
1.389     albertel  526:   if ( $Apache::lonxml::redirection > $startredirection) {
                    527:       while ($Apache::lonxml::redirection > $startredirection) {
                    528: 	  $finaloutput .= &endredirection();
1.387     albertel  529:       }
                    530:   }
1.101     albertel  531:   if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
                    532:     $finaloutput=&afterburn($finaloutput);
1.216     sakharuk  533:   }	    
1.101     albertel  534:   return $finaloutput;
                    535: }
1.67      www       536: 
1.318     matthew   537: ## 
                    538: ## Looks to see if there is a subroutine defined for this tag.  If so, call it,
                    539: ## otherwise do not call it as we do not know what it is.
                    540: ##
1.7       albertel  541: sub callsub {
1.84      albertel  542:   my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.7       albertel  543:   my $currentstring='';
1.72      albertel  544:   my $nodefault;
1.7       albertel  545:   {
1.59      albertel  546:     my $sub1;
1.7       albertel  547:     no strict 'refs';
1.68      www       548:     my $tag=$token->[1];
1.236     www       549: # get utterly rid of extended html tags
                    550:     if ($tag=~/^x\-/i) { return ''; }
1.141     albertel  551:     my $space=$Apache::lonxml::alltags{$tag}[-1];
1.68      www       552:     if (!$space) {
1.141     albertel  553:      	$tag=~tr/A-Z/a-z/;
1.68      www       554: 	$sub=~tr/A-Z/a-z/;
1.141     albertel  555: 	$space=$Apache::lonxml::alltags{$tag}[-1]
1.68      www       556:     }
1.97      albertel  557: 
                    558:     my $deleted=0;
                    559:     $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
                    560:     if (($token->[0] eq 'S') && ($target eq 'modified')) {
                    561:       $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
                    562: 					     $parstack,$parser,$safeeval,
                    563: 					     $style);
                    564:     }
                    565:     if (!$deleted) {
                    566:       if ($space) {
1.220     albertel  567: 	#&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
1.97      albertel  568: 	$sub1="$space\:\:$sub";
                    569: 	($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
                    570: 					     $parstack,$parser,$safeeval,
                    571: 					     $style);
                    572:       } else {
1.318     matthew   573:           if ($target eq 'tex') {
                    574:               # throw away tag name
                    575:               return '';
                    576:           }
1.220     albertel  577: 	#&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
1.97      albertel  578: 	if ($metamode <1) {
                    579: 	  if (defined($token->[4]) && ($metamode < 1)) {
                    580: 	    $currentstring = $token->[4];
                    581: 	  } else {
                    582: 	    $currentstring = $token->[2];
                    583: 	  }
1.62      sakharuk  584: 	}
1.7       albertel  585:       }
1.97      albertel  586:       #    &Apache::lonxml::debug("nodefalt:$nodefault:");
                    587:       if ($currentstring eq '' && $nodefault eq '') {
                    588: 	if ($target eq 'edit') {
1.220     albertel  589: 	  #&Apache::lonxml::debug("doing default edit for $token->[1]");
1.97      albertel  590: 	  if ($token->[0] eq 'S') {
                    591: 	    $currentstring = &Apache::edit::tag_start($target,$token);
                    592: 	  } elsif ($token->[0] eq 'E') {
                    593: 	    $currentstring = &Apache::edit::tag_end($target,$token);
                    594: 	  }
                    595: 	} elsif ($target eq 'modified') {
                    596: 	  if ($token->[0] eq 'S') {
                    597: 	    $currentstring = $token->[4];
                    598: 	    $currentstring.=&Apache::edit::handle_insert();
1.210     www       599: 	  } elsif ($token->[0] eq 'E') {
                    600: 	    $currentstring = $token->[2];
                    601:             $currentstring.=&Apache::edit::handle_insertafter($token->[1]);
1.97      albertel  602: 	  } else {
                    603: 	    $currentstring = $token->[2];
                    604: 	  }
1.72      albertel  605: 	}
                    606:       }
1.7       albertel  607:     }
                    608:     use strict 'refs';
                    609:   }
                    610:   return $currentstring;
1.82      ng        611: }
                    612: 
1.96      albertel  613: sub setup_globals {
1.172     albertel  614:   my ($request,$target)=@_;
                    615:   $Apache::lonxml::request=$request;
1.99      albertel  616:   $Apache::lonxml::registered = 0;
1.325     www       617:   @Apache::lonxml::htmlareafields=();
1.205     www       618:   $errorcount=0;
                    619:   $warningcount=0;
1.207     albertel  620:   $Apache::lonxml::default_homework_loaded=0;
1.212     albertel  621:   $Apache::lonxml::usestyle=1;
1.204     albertel  622:   &init_counter();
1.101     albertel  623:   @Apache::lonxml::pwd=();
1.124     albertel  624:   @Apache::lonxml::extlinks=();
1.281     albertel  625:   @Apache::lonxml::ssi_info=();
1.282     albertel  626:   $Apache::lonxml::post_evaluate=1;
1.295     albertel  627:   $Apache::lonxml::warnings_error_header='';
1.96      albertel  628:   if ($target eq 'meta') {
                    629:     $Apache::lonxml::redirection = 0;
                    630:     $Apache::lonxml::metamode = 1;
                    631:     $Apache::lonxml::evaluate = 1;
                    632:     $Apache::lonxml::import = 0;
1.129     albertel  633:   } elsif ($target eq 'answer') {
                    634:     $Apache::lonxml::redirection = 0;
                    635:     $Apache::lonxml::metamode = 1;
                    636:     $Apache::lonxml::evaluate = 1;
                    637:     $Apache::lonxml::import = 1;
1.96      albertel  638:   } elsif ($target eq 'grade') {
1.387     albertel  639:     &startredirection(); #ended in inner_xmlparse on exit
1.96      albertel  640:     $Apache::lonxml::metamode = 0;
                    641:     $Apache::lonxml::evaluate = 1;
                    642:     $Apache::lonxml::import = 1;
                    643:   } elsif ($target eq 'modified') {
                    644:     $Apache::lonxml::redirection = 0;
                    645:     $Apache::lonxml::metamode = 0;
                    646:     $Apache::lonxml::evaluate = 0;
                    647:     $Apache::lonxml::import = 0;
                    648:   } elsif ($target eq 'edit') {
                    649:     $Apache::lonxml::redirection = 0;
                    650:     $Apache::lonxml::metamode = 0;
                    651:     $Apache::lonxml::evaluate = 0;
                    652:     $Apache::lonxml::import = 0;
1.163     albertel  653:   } elsif ($target eq 'analyze') {
                    654:     $Apache::lonxml::redirection = 0;
                    655:     $Apache::lonxml::metamode = 0;
                    656:     $Apache::lonxml::evaluate = 1;
                    657:     $Apache::lonxml::import = 1;
1.96      albertel  658:   } else {
                    659:     $Apache::lonxml::redirection = 0;
                    660:     $Apache::lonxml::metamode = 0;
                    661:     $Apache::lonxml::evaluate = 1;
                    662:     $Apache::lonxml::import = 1;
                    663:   }
                    664: }
                    665: 
1.82      ng        666: sub init_safespace {
                    667:   my ($target,$safeeval,$safehole,$safeinit) = @_;
1.383     albertel  668:   $safeeval->deny_only(':dangerous');
                    669:   $safeeval->reval('use Math::Complex;');
                    670:   $safeeval->permit_only(":default");
1.82      ng        671:   $safeeval->permit("entereval");
                    672:   $safeeval->permit(":base_math");
                    673:   $safeeval->permit("sort");
1.286     albertel  674:   $safeeval->permit("time");
1.371     albertel  675:   $safeeval->deny("rand");
                    676:   $safeeval->deny("srand");
1.82      ng        677:   $safeeval->deny(":base_io");
1.102     albertel  678:   $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
1.251     albertel  679:   $safehole->wrap(\&Apache::outputtags::multipart,$safeeval,'&multipart');
1.82      ng        680:   $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
1.324     albertel  681:   $safehole->wrap(\&Apache::chemresponse::chem_standard_order,$safeeval,
                    682: 		  '&chem_standard_order');
1.369     albertel  683:   $safehole->wrap(\&Apache::response::check_status,$safeeval,'&check_status');
1.324     albertel  684: 
1.82      ng        685:   $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
                    686:   $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
                    687:   $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
                    688:   $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
                    689:   $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
                    690:   $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
                    691:   $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
                    692:   $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
                    693:   $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
                    694:   $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
                    695:   $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
                    696:   $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
                    697:   $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
                    698:   $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
                    699:   $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
                    700:   $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
                    701:   $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
                    702:   $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
                    703:   $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
1.215     albertel  704:   
                    705:   $safehole->wrap(\&Math::Cephes::bdtr  ,$safeeval,'&bdtr'  );
                    706:   $safehole->wrap(\&Math::Cephes::bdtrc ,$safeeval,'&bdtrc' );
                    707:   $safehole->wrap(\&Math::Cephes::bdtri ,$safeeval,'&bdtri' );
                    708:   $safehole->wrap(\&Math::Cephes::btdtr ,$safeeval,'&btdtr' );
                    709:   $safehole->wrap(\&Math::Cephes::chdtr ,$safeeval,'&chdtr' );
                    710:   $safehole->wrap(\&Math::Cephes::chdtrc,$safeeval,'&chdtrc');
                    711:   $safehole->wrap(\&Math::Cephes::chdtri,$safeeval,'&chdtri');
                    712:   $safehole->wrap(\&Math::Cephes::fdtr  ,$safeeval,'&fdtr'  );
                    713:   $safehole->wrap(\&Math::Cephes::fdtrc ,$safeeval,'&fdtrc' );
                    714:   $safehole->wrap(\&Math::Cephes::fdtri ,$safeeval,'&fdtri' );
                    715:   $safehole->wrap(\&Math::Cephes::gdtr  ,$safeeval,'&gdtr'  );
                    716:   $safehole->wrap(\&Math::Cephes::gdtrc ,$safeeval,'&gdtrc' );
                    717:   $safehole->wrap(\&Math::Cephes::nbdtr ,$safeeval,'&nbdtr' );
                    718:   $safehole->wrap(\&Math::Cephes::nbdtrc,$safeeval,'&nbdtrc');
                    719:   $safehole->wrap(\&Math::Cephes::nbdtri,$safeeval,'&nbdtri');
                    720:   $safehole->wrap(\&Math::Cephes::ndtr  ,$safeeval,'&ndtr'  );
                    721:   $safehole->wrap(\&Math::Cephes::ndtri ,$safeeval,'&ndtri' );
                    722:   $safehole->wrap(\&Math::Cephes::pdtr  ,$safeeval,'&pdtr'  );
                    723:   $safehole->wrap(\&Math::Cephes::pdtrc ,$safeeval,'&pdtrc' );
                    724:   $safehole->wrap(\&Math::Cephes::pdtri ,$safeeval,'&pdtri' );
                    725:   $safehole->wrap(\&Math::Cephes::stdtr ,$safeeval,'&stdtr' );
                    726:   $safehole->wrap(\&Math::Cephes::stdtri,$safeeval,'&stdtri');
                    727: 
1.383     albertel  728:   $safehole->wrap(\&Math::Cephes::Matrix::mat,$safeeval,'&mat');
                    729:   $safehole->wrap(\&Math::Cephes::Matrix::new,$safeeval,
                    730: 		  '&Math::Cephes::Matrix::new');
                    731:   $safehole->wrap(\&Math::Cephes::Matrix::coef,$safeeval,
                    732: 		  '&Math::Cephes::Matrix::coef');
                    733:   $safehole->wrap(\&Math::Cephes::Matrix::clr,$safeeval,
                    734: 		  '&Math::Cephes::Matrix::clr');
                    735:   $safehole->wrap(\&Math::Cephes::Matrix::add,$safeeval,
                    736: 		  '&Math::Cephes::Matrix::add');
                    737:   $safehole->wrap(\&Math::Cephes::Matrix::sub,$safeeval,
                    738: 		  '&Math::Cephes::Matrix::sub');
                    739:   $safehole->wrap(\&Math::Cephes::Matrix::mul,$safeeval,
                    740: 		  '&Math::Cephes::Matrix::mul');
                    741:   $safehole->wrap(\&Math::Cephes::Matrix::div,$safeeval,
                    742: 		  '&Math::Cephes::Matrix::div');
                    743:   $safehole->wrap(\&Math::Cephes::Matrix::inv,$safeeval,
                    744: 		  '&Math::Cephes::Matrix::inv');
                    745:   $safehole->wrap(\&Math::Cephes::Matrix::transp,$safeeval,
                    746: 		  '&Math::Cephes::Matrix::transp');
                    747:   $safehole->wrap(\&Math::Cephes::Matrix::simq,$safeeval,
                    748: 		  '&Math::Cephes::Matrix::simq');
                    749:   $safehole->wrap(\&Math::Cephes::Matrix::mat_to_vec,$safeeval,
                    750: 		  '&Math::Cephes::Matrix::mat_to_vec');
                    751:   $safehole->wrap(\&Math::Cephes::Matrix::vec_to_mat,$safeeval,
                    752: 		  '&Math::Cephes::Matrix::vec_to_mat');
                    753:   $safehole->wrap(\&Math::Cephes::Matrix::check,$safeeval,
                    754: 		  '&Math::Cephes::Matrix::check');
                    755:   $safehole->wrap(\&Math::Cephes::Matrix::check,$safeeval,
                    756: 		  '&Math::Cephes::Matrix::check');
                    757: 
1.215     albertel  758: #  $safehole->wrap(\&Math::Cephes::new_fract,$safeeval,'&new_fract');
                    759: #  $safehole->wrap(\&Math::Cephes::radd,$safeeval,'&radd');
                    760: #  $safehole->wrap(\&Math::Cephes::rsub,$safeeval,'&rsub');
                    761: #  $safehole->wrap(\&Math::Cephes::rmul,$safeeval,'&rmul');
                    762: #  $safehole->wrap(\&Math::Cephes::rdiv,$safeeval,'&rdiv');
                    763: #  $safehole->wrap(\&Math::Cephes::euclid,$safeeval,'&euclid');
                    764: 
1.91      ng        765:   $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
                    766:   $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
                    767:   $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
                    768:   $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
                    769:   $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
                    770:   $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
                    771:   $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
                    772:   $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
                    773:   $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
                    774:   $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
                    775:   $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
1.93      ng        776:   $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
1.91      ng        777:   $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
                    778:   $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
                    779:   $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
                    780:   $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
                    781:   $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
                    782:   $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
                    783:   $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
                    784:   $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
                    785:   $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
1.305     albertel  786:   $safehole->wrap(\&Apache::lonxml::error,$safeeval,'&LONCAPA_INTERNAL_ERROR');
1.311     albertel  787:   $safehole->wrap(\&Apache::lonxml::debug,$safeeval,'&LONCAPA_INTERNAL_DEBUG');
1.322     albertel  788:   $safehole->wrap(\&Apache::caparesponse::get_sigrange,$safeeval,'&LONCAPA_INTERNAL_get_sigrange');
1.91      ng        789: 
1.82      ng        790: #need to inspect this class of ops
                    791: # $safeeval->deny(":base_orig");
1.331     albertel  792:   $safeeval->permit("require");
1.91      ng        793:   $safeinit .= ';$external::target="'.$target.'";';
1.82      ng        794:   &Apache::run::run($safeinit,$safeeval);
1.373     albertel  795:   &initialize_rndseed($safeeval);
                    796: }
1.303     albertel  797: 
1.373     albertel  798: sub initialize_rndseed {
                    799:     my ($safeeval)=@_;
                    800:     my $rndseed;
                    801:     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
                    802:     $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
                    803:     my $safeinit = '$external::randomseed="'.$rndseed.'";';
                    804:     &Apache::lonxml::debug("Setting rndseed to $rndseed");
                    805:     &Apache::run::run($safeinit,$safeeval);
1.207     albertel  806: }
                    807: 
                    808: sub default_homework_load {
                    809:     my ($safeeval)=@_;
                    810:     &Apache::lonxml::debug('Loading default_homework');
                    811:     my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
1.241     albertel  812:     if ($default eq -1) {
1.207     albertel  813: 	&Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
                    814:     } else {
                    815: 	&Apache::run::run($default,$safeeval);
                    816: 	$Apache::lonxml::default_homework_loaded=1;
                    817:     }
1.17      albertel  818: }
                    819: 
1.358     albertel  820: {
                    821:     my $alarm_depth;
                    822:     sub init_alarm {
                    823: 	alarm(0);
                    824: 	$alarm_depth=0;
                    825:     }
                    826: 
                    827:     sub start_alarm {
                    828: 	if ($alarm_depth<1) {
                    829: 	    my $old=alarm($Apache::lonnet::perlvar{'lonScriptTimeout'});
                    830: 	    if ($old) {
                    831: 		&Apache::lonxml::error("Cancelled an alarm of $old, this shouldn't occur.");
                    832: 	    }
                    833: 	}
                    834: 	$alarm_depth++;
                    835:     }
                    836: 
                    837:     sub end_alarm {
                    838: 	$alarm_depth--;
                    839: 	if ($alarm_depth<1) { alarm(0); }
                    840:     }
                    841: }
1.328     albertel  842: my $metamode_was;
1.55      albertel  843: sub startredirection {
1.328     albertel  844:     if (!$Apache::lonxml::redirection) {
                    845: 	$metamode_was=$Apache::lonxml::metamode;
                    846:     }
                    847:     $Apache::lonxml::metamode=0;
                    848:     $Apache::lonxml::redirection++;
                    849:     push (@Apache::lonxml::outputstack, '');
1.55      albertel  850: }
                    851: 
                    852: sub endredirection {
1.328     albertel  853:     if (!$Apache::lonxml::redirection) {
1.380     www       854: 	&Apache::lonxml::error("Endredirection was called before a startredirection, perhaps you have unbalanced tags. Some debugging information:".join ":",caller);
1.328     albertel  855: 	return '';
                    856:     }
                    857:     $Apache::lonxml::redirection--;
                    858:     if (!$Apache::lonxml::redirection) {
                    859: 	$Apache::lonxml::metamode=$metamode_was;
                    860:     }
                    861:     pop @Apache::lonxml::outputstack;
1.97      albertel  862: }
                    863: 
                    864: sub end_tag {
                    865:   my ($tagstack,$parstack,$token)=@_;
                    866:   pop(@$tagstack);
                    867:   pop(@$parstack);
                    868:   &decreasedepth($token);
1.55      albertel  869: }
                    870: 
1.17      albertel  871: sub initdepth {
                    872:   @Apache::lonxml::depthcounter=();
                    873:   $Apache::lonxml::depth=-1;
                    874:   $Apache::lonxml::olddepth=-1;
                    875: }
                    876: 
1.339     albertel  877: my @timers;
                    878: my $lasttime;
1.17      albertel  879: sub increasedepth {
1.19      albertel  880:   my ($token) = @_;
1.17      albertel  881:   $Apache::lonxml::depth++;
                    882:   $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
                    883:   if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
                    884:     $Apache::lonxml::olddepth=$Apache::lonxml::depth;
                    885:   }
1.340     albertel  886:   my $time;
                    887:   if ($Apache::lonxml::debug eq "1") {
                    888:       push(@timers,[&gettimeofday()]);
                    889:       $time=&tv_interval($lasttime);
                    890:       $lasttime=[&gettimeofday()];
                    891:   }
1.339     albertel  892:   my $spacing='  'x($Apache::lonxml::depth-1);
1.42      albertel  893:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.339     albertel  894:   &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : \n");
1.54      albertel  895: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17      albertel  896: }
                    897: 
                    898: sub decreasedepth {
1.19      albertel  899:   my ($token) = @_;
1.17      albertel  900:   $Apache::lonxml::depth--;
1.36      albertel  901:   if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
                    902:     $#Apache::lonxml::depthcounter--;
                    903:     $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
                    904:   }
1.43      albertel  905:   if (  $Apache::lonxml::depth < -1) {
1.280     www       906:     &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
1.43      albertel  907:     $Apache::lonxml::depth='-1';
                    908:   }
1.340     albertel  909:   my ($timer,$time);
                    910:   if ($Apache::lonxml::debug eq "1") {
                    911:       $timer=pop(@timers);
                    912:       $time=&tv_interval($lasttime);
                    913:       $lasttime=[&gettimeofday()];
                    914:   }
1.339     albertel  915:   my $spacing='  'x$Apache::lonxml::depth;
1.42      albertel  916:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.339     albertel  917:   &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : ".&tv_interval($timer)."\n");
1.54      albertel  918: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1       sakharuk  919: }
1.19      albertel  920: 
1.180     albertel  921: sub get_all_text_unbalanced {
1.190     albertel  922: #there is a copy of this in lonpublisher.pm
1.326     albertel  923:     my($tag,$pars)= @_;
                    924:     my $token;
                    925:     my $result='';
                    926:     $tag='<'.$tag.'>';
                    927:     while ($token = $$pars[-1]->get_token) {
                    928: 	if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1.386     albertel  929: 	    if ($token->[0] eq 'T' && $token->[2]) {
1.382     albertel  930: 		$result.='<![CDATA['.$token->[1].']]>';
                    931: 	    } else {
                    932: 		$result.=$token->[1];
                    933: 	    }
1.326     albertel  934: 	} elsif ($token->[0] eq 'PI') {
                    935: 	    $result.=$token->[2];
                    936: 	} elsif ($token->[0] eq 'S') {
                    937: 	    $result.=$token->[4];
                    938: 	} elsif ($token->[0] eq 'E')  {
                    939: 	    $result.=$token->[2];
                    940: 	}
                    941: 	if ($result =~ /\Q$tag\E/is) {
                    942: 	    ($result,my $redo)=$result =~ /(.*)\Q$tag\E(.*)/is;
                    943: 	    #&Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
                    944: 	    #&Apache::lonxml::debug('Result is :'.$1);
                    945: 	    $redo=$tag.$redo;
                    946: 	    &Apache::lonxml::newparser($pars,\$redo);
                    947: 	    last;
                    948: 	}
                    949:     }
                    950:     return $result
1.204     albertel  951: }
                    952: 
                    953: sub increment_counter {
1.247     albertel  954:     my ($increment) = @_;
1.289     sakharuk  955:     if (defined($increment) && $increment gt 0) {
                    956: 	$Apache::lonxml::counter+=$increment;
                    957:     } else {
                    958: 	$Apache::lonxml::counter++;
1.247     albertel  959:     }
1.289     sakharuk  960:     $Apache::lonxml::counter_changed=1;
1.204     albertel  961: }
                    962: 
                    963: sub init_counter {
1.372     albertel  964:     if (defined($env{'form.counter'})) {
                    965: 	$Apache::lonxml::counter=$env{'form.counter'};
1.247     albertel  966: 	$Apache::lonxml::counter_changed=0;
1.237     sakharuk  967:     } else {
1.204     albertel  968: 	$Apache::lonxml::counter=1;
1.247     albertel  969: 	$Apache::lonxml::counter_changed=1;
1.204     albertel  970:     }
                    971: }
                    972: 
                    973: sub store_counter {
                    974:     &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter));
                    975:     return '';
1.180     albertel  976: }
                    977: 
1.19      albertel  978: sub get_all_text {
1.270     albertel  979:     my($tag,$pars,$style)= @_;
                    980:     my $gotfullstack=1;
                    981:     if (ref($pars) ne 'ARRAY') {
                    982: 	$gotfullstack=0;
                    983: 	$pars=[$pars];
                    984:     }
                    985:     if (ref($style) ne 'HASH') {
                    986: 	$style={};
                    987:     }
                    988:     my $depth=0;
                    989:     my $token;
                    990:     my $result='';
                    991:     if ( $tag =~ m:^/: ) { 
                    992: 	my $tag=substr($tag,1); 
                    993: 	#&Apache::lonxml::debug("have:$tag:");
                    994: 	my $top_empty=0;
                    995: 	while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
                    996: 	    while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
                    997: 		#&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
                    998: 		if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1.382     albertel  999: 		    if ($token->[2]) {
                   1000: 			$result.='<![CDATA['.$token->[1].']]>';
                   1001: 		    } else {
                   1002: 			$result.=$token->[1];
                   1003: 		    }
1.270     albertel 1004: 		} elsif ($token->[0] eq 'PI') {
                   1005: 		    $result.=$token->[2];
                   1006: 		} elsif ($token->[0] eq 'S') {
1.316     albertel 1007: 		    if ($token->[1] =~ /^\Q$tag\E$/i) { $depth++; }
                   1008: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/) { $Apache::lonxml::usestyle=1; }
                   1009: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/) { $Apache::lonxml::usestyle=0; }
1.270     albertel 1010: 		    $result.=$token->[4];
                   1011: 		} elsif ($token->[0] eq 'E')  {
1.316     albertel 1012: 		    if ( $token->[1] =~ /^\Q$tag\E$/i) { $depth--; }
1.270     albertel 1013: 		    #skip sending back the last end tag
1.283     albertel 1014: 		    if ($depth == 0 && exists($$style{'/'.$token->[1]}) && $Apache::lonxml::usestyle) {
1.270     albertel 1015: 			my $string=
                   1016: 			    '<LONCAPA_INTERNAL_TURN_STYLE_OFF end="yes" />'.
                   1017: 				$$style{'/'.$token->[1]}.
                   1018: 				    $token->[2].
                   1019: 					'<LONCAPA_INTERNAL_TURN_STYLE_ON />';
                   1020: 			&Apache::lonxml::newparser($pars,\$string);
                   1021: 			#&Apache::lonxml::debug("reParsing $string");
                   1022: 			next;
                   1023: 		    }
                   1024: 		    if ($depth > -1) {
                   1025: 			$result.=$token->[2];
                   1026: 		    } else {
                   1027: 			$$pars[-1]->unget_token($token);
                   1028: 		    }
                   1029: 		}
                   1030: 	    }
                   1031: 	    if (($depth >=0) && ($#$pars == 0) ) { $top_empty=1; }
                   1032: 	    if (($depth >=0) && ($#$pars > 0) ) {
                   1033: 		pop(@$pars);
                   1034: 		pop(@Apache::lonxml::pwd);
                   1035: 	    }
                   1036: 	}
                   1037: 	if ($top_empty && $depth >= 0) {
                   1038: 	    #never found the end tag ran out of text, throw error send back blank
                   1039: 	    &error('Never found end tag for &lt;'.$tag.
                   1040: 		   '&gt; current string <pre>'.
1.314     albertel 1041: 		   &HTML::Entities::encode($result,'<>&"').
1.270     albertel 1042: 		   '</pre>');
                   1043: 	    if ($gotfullstack) {
                   1044: 		my $newstring='</'.$tag.'>'.$result;
                   1045: 		&Apache::lonxml::newparser($pars,\$newstring);
                   1046: 	    }
                   1047: 	    $result='';
                   1048: 	}
                   1049:     } else {
                   1050: 	while ($#$pars > -1) {
                   1051: 	    while ($token = $$pars[-1]->get_token) {
                   1052: 		#&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
                   1053: 		if (($token->[0] eq 'T')||($token->[0] eq 'C')||
                   1054: 		    ($token->[0] eq 'D')) {
1.382     albertel 1055: 		    if ($token->[2]) {
                   1056: 			$result.='<![CDATA['.$token->[1].']]>';
                   1057: 		    } else {
                   1058: 			$result.=$token->[1];
                   1059: 		    }
1.270     albertel 1060: 		} elsif ($token->[0] eq 'PI') {
                   1061: 		    $result.=$token->[2];
                   1062: 		} elsif ($token->[0] eq 'S') {
1.316     albertel 1063: 		    if ( $token->[1] =~ /^\Q$tag\E$/i) {
1.270     albertel 1064: 			$$pars[-1]->unget_token($token); last;
                   1065: 		    } else {
                   1066: 			$result.=$token->[4];
                   1067: 		    }
1.316     albertel 1068: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/) { $Apache::lonxml::usestyle=1; }
                   1069: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/) { $Apache::lonxml::usestyle=0; }
1.270     albertel 1070: 		} elsif ($token->[0] eq 'E')  {
                   1071: 		    $result.=$token->[2];
                   1072: 		}
                   1073: 	    }
                   1074: 	    if (($#$pars > 0) ) {
                   1075: 		pop(@$pars);
                   1076: 		pop(@Apache::lonxml::pwd);
                   1077: 	    } else { last; }
                   1078: 	}
                   1079:     }
                   1080:     #&Apache::lonxml::debug("Exit:$result:");
                   1081:     return $result
1.19      albertel 1082: }
                   1083: 
1.23      albertel 1084: sub newparser {
                   1085:   my ($parser,$contentref,$dir) = @_;
1.167     albertel 1086:   push (@$parser,HTML::LCParser->new($contentref));
1.365     albertel 1087:   $$parser[-1]->xml_mode(1);
                   1088:   $$parser[-1]->marked_sections(1);
1.23      albertel 1089:   if ( $dir eq '' ) {
                   1090:     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
                   1091:   } else {
                   1092:     push (@Apache::lonxml::pwd, $dir);
                   1093:   } 
                   1094: }
1.1       sakharuk 1095: 
1.8       albertel 1096: sub parstring {
                   1097:   my ($token) = @_;
                   1098:   my $temp='';
1.142     albertel 1099:   foreach (@{$token->[3]}) {
1.35      www      1100:     unless ($_=~/\W/) {
1.42      albertel 1101:       my $val=$token->[2]->{$_};
1.231     albertel 1102:       $val =~ s/([\%\@\\\"\'])/\\$1/g;
1.342     albertel 1103:       $val =~ s/(\$[^{a-zA-Z_])/\\$1/g;
1.346     albertel 1104:       $val =~ s/(\$)$/\\$1/;
1.51      albertel 1105:       #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.267     sakharuk 1106:       $temp .= "my \$$_=\"$val\";";
1.20      albertel 1107:     }
1.142     albertel 1108:   }
1.8       albertel 1109:   return $temp;
                   1110: }
1.22      albertel 1111: 
1.384     albertel 1112: sub extlink {
                   1113:     my ($res,$exact)=@_;
                   1114:     if (!$exact) {
                   1115: 	$res=&Apache::lonnet::hreflocation($Apache::lonxml::pwd[-1],$res);
                   1116:     }
                   1117:     push(@Apache::lonxml::extlinks,$res)	 
                   1118: }
                   1119: 
1.34      www      1120: sub writeallows {
1.126     www      1121:     unless ($#extlinks>=0) { return; }
1.377     albertel 1122:     my $thisurl = &Apache::lonnet::clutter(shift);
1.372     albertel 1123:     if ($env{'httpref.'.$thisurl}) {
                   1124: 	$thisurl=$env{'httpref.'.$thisurl};
1.111     www      1125:     }
1.34      www      1126:     my $thisdir=$thisurl;
                   1127:     $thisdir=~s/\/[^\/]+$//;
                   1128:     my %httpref=();
1.142     albertel 1129:     foreach (@extlinks) {
1.34      www      1130:        $httpref{'httpref.'.
1.125     www      1131:  	        &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
1.142     albertel 1132:     }
1.126     www      1133:     @extlinks=();
1.34      www      1134:     &Apache::lonnet::appenv(%httpref);
                   1135: }
                   1136: 
1.281     albertel 1137: sub register_ssi {
                   1138:     my ($url,%form)=@_;
                   1139:     push (@Apache::lonxml::ssi_info,{'url'=>$url,'form'=>\%form});
                   1140:     return '';
                   1141: }
                   1142: 
                   1143: sub do_registered_ssi {
                   1144:     foreach my $info (@Apache::lonxml::ssi_info) {
                   1145: 	my %form=%{ $info->{'form'}};
                   1146: 	my $url=$info->{'url'};
                   1147: 	&Apache::lonnet::ssi($url,%form);
                   1148:     }
                   1149: }
1.66      www      1150: #
                   1151: # Afterburner handles anchors, highlights and links
                   1152: #
                   1153: sub afterburn {
                   1154:     my $result=shift;
1.154     albertel 1155:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1156: 					    ['highlight','anchor','link']);
1.372     albertel 1157:     if ($env{'form.highlight'}) {
                   1158:        foreach (split(/\,/,$env{'form.highlight'})) {
1.66      www      1159:            my $anchorname=$_;
                   1160: 	   my $matchthis=$anchorname;
                   1161:            $matchthis=~s/\_+/\\s\+/g;
1.317     albertel 1162:            $result=~s/(\Q$matchthis\E)/\<font color=\"red\"\>$1\<\/font\>/gs;
1.142     albertel 1163:        }
1.66      www      1164:     }
1.372     albertel 1165:     if ($env{'form.link'}) {
                   1166:        foreach (split(/\,/,$env{'form.link'})) {
1.66      www      1167:            my ($anchorname,$linkurl)=split(/\>/,$_);
                   1168: 	   my $matchthis=$anchorname;
                   1169:            $matchthis=~s/\_+/\\s\+/g;
1.317     albertel 1170:            $result=~s/(\Q$matchthis\E)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
1.142     albertel 1171:        }
1.66      www      1172:     }
1.372     albertel 1173:     if ($env{'form.anchor'}) {
                   1174:         my $anchorname=$env{'form.anchor'};
1.66      www      1175: 	my $matchthis=$anchorname;
                   1176:         $matchthis=~s/\_+/\\s\+/g;
1.317     albertel 1177:         $result=~s/(\Q$matchthis\E)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
1.66      www      1178:         $result.=(<<"ENDSCRIPT");
1.226     albertel 1179: <script type="text/javascript">
1.66      www      1180:     document.location.hash='$anchorname';
                   1181: </script>
                   1182: ENDSCRIPT
                   1183:     }
                   1184:     return $result;
                   1185: }
                   1186: 
1.79      www      1187: sub storefile {
                   1188:     my ($file,$contents)=@_;
1.290     albertel 1189:     &Apache::lonnet::correct_line_ends(\$contents);
1.79      www      1190:     if (my $fh=Apache::File->new('>'.$file)) {
                   1191: 	print $fh $contents;
                   1192:         $fh->close();
1.271     www      1193:         return 1;
1.147     albertel 1194:     } else {
1.271     www      1195: 	&warning("Unable to save file $file");
                   1196: 	return 0;
1.79      www      1197:     }
                   1198: }
                   1199: 
1.151     albertel 1200: sub createnewhtml {
1.321     www      1201:     my $title=&mt('Title of document goes here');
                   1202:     my $body=&mt('Body of document goes here');
                   1203:     my $filecontents=(<<SIMPLECONTENT);
1.78      www      1204: <html>
                   1205: <head>
1.321     www      1206: <title>$title</title>
1.78      www      1207: </head>
                   1208: <body bgcolor="#FFFFFF">
1.321     www      1209: $body
1.78      www      1210: </body>
                   1211: </html>
                   1212: SIMPLECONTENT
1.321     www      1213:     return $filecontents;
1.151     albertel 1214: }
                   1215: 
1.274     albertel 1216: sub createnewsty {
                   1217:   my $filecontents=(<<SIMPLECONTENT);
                   1218: <definetag name="">
                   1219:     <render>
                   1220:        <web></web>
                   1221:        <tex></tex>
                   1222:     </render>
                   1223: </definetag>
                   1224: SIMPLECONTENT
                   1225:   return $filecontents;
                   1226: }
                   1227: 
1.147     albertel 1228: 
1.151     albertel 1229: sub inserteditinfo {
1.274     albertel 1230:       my ($result,$filecontents,$filetype)=@_;
1.314     albertel 1231:       $filecontents = &HTML::Entities::encode($filecontents,'<>&"');
1.147     albertel 1232: #      my $editheader='<a href="#editsection">Edit below</a><hr />';
1.274     albertel 1233:       my $xml_help = '';
1.321     www      1234:       my $initialize='';
1.274     albertel 1235:       if ($filetype eq 'html') {
1.323     www      1236: 	  my $addbuttons=&Apache::lonhtmlcommon::htmlareaaddbuttons();
1.333     www      1237: 	  $initialize=&Apache::lonhtmlcommon::htmlareaheaders().
1.347     albertel 1238: 	      &Apache::lonhtmlcommon::spellheader();
                   1239: 	  if (!&Apache::lonhtmlcommon::htmlareablocked() &&
                   1240: 	      &Apache::lonhtmlcommon::htmlareabrowser()) {
                   1241: 	      $initialize.=(<<FULLPAGE);
1.321     www      1242: <script type="text/javascript">
1.323     www      1243: $addbuttons
                   1244: 
1.321     www      1245:     HTMLArea.loadPlugin("FullPage");
                   1246: 
                   1247:     function initDocument() {
1.323     www      1248: 	var editor=new HTMLArea("filecont",config);
1.321     www      1249: 	editor.registerPlugin(FullPage);
                   1250: 	editor.generate();
                   1251:     }
                   1252: </script>
                   1253: FULLPAGE
1.347     albertel 1254:           } else {
                   1255: 	      $initialize.=(<<FULLPAGE);
                   1256: <script type="text/javascript">
                   1257: $addbuttons
                   1258:     function initDocument() {
                   1259:     }
                   1260: </script>
                   1261: FULLPAGE
                   1262: 	  }
1.321     www      1263:           $result=~s/\<body([^\>]*)\>/\<body onload="initDocument()" $1\>/i;
                   1264: 	  $xml_help=&Apache::loncommon::helpLatexCheatsheet();
1.274     albertel 1265:       }
                   1266:       my $cleanbut = '';
1.374     www      1267: 
1.254     albertel 1268:       my $titledisplay=&display_title();
1.280     www      1269:       my %lt=&Apache::lonlocal::texthash('st' => 'Save this',
                   1270: 					 'vi' => 'View',
                   1271: 					 'ed' => 'Edit');
1.161     albertel 1272:       my $buttons=(<<BUTTONS);
1.274     albertel 1273: $cleanbut
1.304     matthew  1274: <input type="submit" name="savethisfile" accesskey="s"  value="$lt{'st'}" />
                   1275: <input type="submit" name="viewmode" accesskey="v" value="$lt{'vi'}" />
1.161     albertel 1276: BUTTONS
1.333     www      1277:       $buttons.=&Apache::lonhtmlcommon::spelllink('xmledit','filecont');
1.338     albertel 1278:       $buttons.=&Apache::lonhtmlcommon::htmlareaselectactive('filecont');
1.78      www      1279:       my $editfooter=(<<ENDFOOTER);
1.321     www      1280: $initialize
1.78      www      1281: <hr />
                   1282: <a name="editsection" />
1.333     www      1283: <form method="post" name="xmledit">
1.240     albertel 1284: $xml_help
1.280     www      1285: <input type="hidden" name="editmode" value="$lt{'ed'}" />
1.170     www      1286: $buttons<br />
1.366     albertel 1287: <textarea style="width:100%" cols="80" rows="44" name="filecont" id="filecont">$filecontents</textarea>
1.170     www      1288: <br />$buttons
1.78      www      1289: <br />
                   1290: </form>
1.254     albertel 1291: $titledisplay
1.321     www      1292: </body>
1.78      www      1293: ENDFOOTER
1.147     albertel 1294: #      $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
1.78      www      1295:       $result=~s/(\<\/body\>)/$editfooter/is;
                   1296:       return $result;
                   1297: }
                   1298: 
1.152     albertel 1299: sub get_target {
1.372     albertel 1300:   my $viewgrades=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
                   1301:   if ( $env{'request.state'} eq 'published') {
                   1302:     if ( defined($env{'form.grade_target'})
1.152     albertel 1303: 	 && ($viewgrades == 'F' )) {
1.372     albertel 1304:       return ($env{'form.grade_target'});
                   1305:     } elsif (defined($env{'form.grade_target'})) {
                   1306:       if (($env{'form.grade_target'} eq 'web') ||
                   1307: 	  ($env{'form.grade_target'} eq 'tex') ) {
                   1308: 	return $env{'form.grade_target'}
1.153     albertel 1309:       } else {
                   1310: 	return 'web';
                   1311:       }
1.152     albertel 1312:     } else {
                   1313:       return 'web';
                   1314:     }
1.372     albertel 1315:   } elsif ($env{'request.state'} eq 'construct') {
                   1316:     if ( defined($env{'form.grade_target'})) {
                   1317:       return ($env{'form.grade_target'});
1.152     albertel 1318:     } else {
                   1319:       return 'web';
                   1320:     }
                   1321:   } else {
                   1322:     return 'web';
                   1323:   }
                   1324: }
                   1325: 
1.24      sakharuk 1326: sub handler {
1.255     sakharuk 1327:     my $request=shift;
                   1328:     
                   1329:     my $target=&get_target();
                   1330:     
1.372     albertel 1331:     $Apache::lonxml::debug=$env{'user.debug'};
1.255     sakharuk 1332:     
1.364     albertel 1333:     &Apache::loncommon::content_type($request,'text/html');
1.255     sakharuk 1334:     &Apache::loncommon::no_cache($request);
1.372     albertel 1335:     if ($env{'request.state'} eq 'published') {
1.363     albertel 1336: 	$request->set_last_modified(&Apache::lonnet::metadata($request->uri,
                   1337: 							      'lastrevisiondate'));
                   1338:     }
1.255     sakharuk 1339:     $request->send_http_header;
                   1340:     
                   1341:     return OK if $request->header_only;
1.68      www      1342: 
                   1343: 
1.255     sakharuk 1344:     my $file=&Apache::lonnet::filelocation("",$request->uri);
1.274     albertel 1345:     my $filetype;
                   1346:     if ($file =~ /\.sty$/) {
                   1347: 	$filetype='sty';
                   1348:     } else {
                   1349: 	$filetype='html';
                   1350:     }
1.78      www      1351: #
                   1352: # Edit action? Save file.
                   1353: #
1.372     albertel 1354:     unless ($env{'request.state'} eq 'published') {
1.374     www      1355: 	if ($env{'form.savethisfile'}) {
1.372     albertel 1356: 	    if (&storefile($file,$env{'form.filecont'})) {
1.309     albertel 1357: 		&Apache::lonxml::info("<font COLOR=\"#0000FF\">".
                   1358: 				      &mt('Updated').": ".
                   1359: 				      &Apache::lonlocal::locallocaltime(time).
                   1360: 				      " </font>");
1.271     www      1361: 	    } 
1.255     sakharuk 1362: 	}
                   1363:     }
                   1364:     my %mystyle;
                   1365:     my $result = '';
                   1366:     my $filecontents=&Apache::lonnet::getfile($file);
                   1367:     if ($filecontents eq -1) {
1.284     www      1368: 	my $bodytag=&Apache::loncommon::bodytag('File Error');
                   1369: 	my $fnf=&mt('File not found');
1.255     sakharuk 1370: 	$result=(<<ENDNOTFOUND);
1.78      www      1371: <html>
                   1372: <head>
1.284     www      1373: <title>$fnf</title>
1.78      www      1374: </head>
1.284     www      1375: $bodytag
                   1376: <b>$fnf: $file</b>
1.78      www      1377: </body>
                   1378: </html>
                   1379: ENDNOTFOUND
1.343     albertel 1380:         $filecontents='';
1.372     albertel 1381: 	if ($env{'request.state'} ne 'published') {
1.274     albertel 1382: 	    if ($filetype eq 'sty') {
                   1383: 		$filecontents=&createnewsty();
                   1384: 	    } else {
                   1385: 		$filecontents=&createnewhtml();
                   1386: 	    }
1.372     albertel 1387: 	    $env{'form.editmode'}='Edit'; #force edit mode
1.255     sakharuk 1388: 	}
                   1389:     } else {
1.372     albertel 1390: 	unless ($env{'request.state'} eq 'published') {
1.343     albertel 1391: 	    if ($filecontents=~/BEGIN LON-CAPA Internal/) {
1.381     www      1392: 		&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.'));
1.343     albertel 1393: 	    }
1.264     www      1394: #
                   1395: # we are in construction space, see if edit mode forced
1.385     albertel 1396:             &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1397: 						    ['editmode']);
1.255     sakharuk 1398: 	}
1.372     albertel 1399: 	if (!$env{'form.editmode'} || $env{'form.viewmode'}) {
1.255     sakharuk 1400: 	    $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
                   1401: 						'',%mystyle);
1.368     albertel 1402: 	    undef($Apache::lonhomework::parsing_a_task);
1.385     albertel 1403: 	    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1404: 						    ['rawmode']);
                   1405: 	    if ($env{'rawmode'}) { $result = $filecontents; }
1.255     sakharuk 1406: 	}
1.147     albertel 1407:     }
1.255     sakharuk 1408:     
1.78      www      1409: #
                   1410: # Edit action? Insert editing commands
                   1411: #
1.372     albertel 1412:     unless ($env{'request.state'} eq 'published') {
                   1413: 	if ($env{'form.editmode'} && (!($env{'form.viewmode'}))) {
1.255     sakharuk 1414: 	    my $displayfile=$request->uri;
                   1415: 	    $displayfile=~s/^\/[^\/]*//;
1.349     albertel 1416: 	    my $bodytag='<body bgcolor="#FFFFFF">';
1.372     albertel 1417: 	    if ($env{'environment.remote'} eq 'off') {
1.349     albertel 1418: 		$bodytag=&Apache::loncommon::bodytag();
                   1419: 	    }
                   1420: 	    $result='<html>'.$bodytag.
1.309     albertel 1421: 		&Apache::lonxml::message_location().'<h3>'.
                   1422: 		$displayfile.
1.255     sakharuk 1423: 		'</h3></body></html>';
1.274     albertel 1424: 	    $result=&inserteditinfo($result,$filecontents,$filetype);
1.255     sakharuk 1425: 	}
1.147     albertel 1426:     }
1.274     albertel 1427:     if ($filetype eq 'html') { writeallows($request->uri); }
                   1428: 	
1.255     sakharuk 1429:     
1.309     albertel 1430:     &Apache::lonxml::add_messages(\$result);
1.255     sakharuk 1431:     $request->print($result);
                   1432:     
                   1433:     return OK;
1.253     albertel 1434: }
                   1435: 
                   1436: sub display_title {
                   1437:     my $result;
1.372     albertel 1438:     if ($env{'request.state'} eq 'construct') {
1.253     albertel 1439: 	my $title=&Apache::lonnet::gettitle();
                   1440: 	if (!defined($title) || $title eq '') {
1.372     albertel 1441: 	    $title = $env{'request.filename'};
1.253     albertel 1442: 	    $title = substr($title, rindex($title, '/') + 1);
                   1443: 	}
                   1444: 	$result = "<script type='text/javascript'>top.document.title = '$title - LON-CAPA Construction Space';</script>";
                   1445:     }
                   1446:     return $result;
1.24      sakharuk 1447: }
1.147     albertel 1448: 
1.22      albertel 1449: sub debug {
1.298     albertel 1450:     if ($Apache::lonxml::debug eq "1") {
                   1451: 	$|=1;
1.300     albertel 1452: 	my $request=$Apache::lonxml::request;
1.388     albertel 1453: 	if (!$request) {
                   1454: 	    eval { $request=Apache->request; };
                   1455: 	}
                   1456: 	if (!$request) {
                   1457: 	    eval { $request=Apache2::RequestUtil->request; };
                   1458: 	}
1.314     albertel 1459: 	$request->print('<font size="-2"><pre>DEBUG:'.&HTML::Entities::encode($_[0],'<>&"')."</pre></font>\n");
1.346     albertel 1460: 	#&Apache::lonnet::logthis($_[0]);
1.298     albertel 1461:     }
1.22      albertel 1462: }
1.49      albertel 1463: 
1.348     albertel 1464: sub show_error_warn_msg {
1.372     albertel 1465:     if ($env{'request.filename'} eq '/home/httpd/html/res/lib/templates/simpleproblem.problem' &&
                   1466: 	&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.351     albertel 1467: 	return 1;
                   1468:     }
1.348     albertel 1469:     return (($Apache::lonxml::debug eq 1) ||
1.372     albertel 1470: 	    ($env{'request.state'} eq 'construct') ||
1.348     albertel 1471: 	    ($Apache::lonhomework::browse eq 'F'
                   1472: 	     &&
1.372     albertel 1473: 	     $env{'form.show_errors'} eq 'on'));
1.348     albertel 1474: }
                   1475: 
1.22      albertel 1476: sub error {
1.336     albertel 1477:     $errorcount++;
1.348     albertel 1478:     if ( &show_error_warn_msg() ) {
1.336     albertel 1479: 	# If printing in construction space, put the error inside <pre></pre>
                   1480: 	push(@Apache::lonxml::error_messages,
                   1481: 	     $Apache::lonxml::warnings_error_header.
                   1482: 	     "<b>ERROR:</b>".join("<br />\n",@_)."<br />\n");
                   1483: 	$Apache::lonxml::warnings_error_header='';
                   1484:     } else {
                   1485: 	my $errormsg;
                   1486: 	my ($symb)=&Apache::lonnet::symbread();
                   1487: 	if ( !$symb ) {
                   1488: 	    #public or browsers
                   1489: 	    $errormsg=&mt("An error occured while processing this resource. The author has been notified.");
                   1490: 	} 
                   1491: 	#notify author
1.372     albertel 1492: 	&Apache::lonmsg::author_res_msg($env{'request.filename'},join('<br />',@_));
1.336     albertel 1493: 	#notify course
1.372     albertel 1494: 	if ( $symb && $env{'request.course.id'} ) {
1.380     www      1495: 	    my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   1496: 	    my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.336     albertel 1497: 	    my (undef,%users)=&Apache::lonfeedback::decide_receiver(undef,0,1,1,1);
1.372     albertel 1498: 	    my $declutter=&Apache::lonnet::declutter($env{'request.filename'});
1.336     albertel 1499: 	    my @userlist;
                   1500: 	    foreach (keys %users) {
                   1501: 		my ($user,$domain) = split(/:/, $_);
                   1502: 		push(@userlist,"$user\@$domain");
1.380     www      1503: 		my $key=$declutter.'_'.$user.'_'.$domain;
                   1504: 		my %lastnotified=&Apache::lonnet::get('nohist_xmlerrornotifications',
                   1505: 						      [$key],
                   1506: 						      $cdom,$cnum);
                   1507: 		my $now=time;
                   1508: 		if ($now-$lastnotified{$key}>86400) {
                   1509: 		    &Apache::lonmsg::user_normal_msg($user,$domain,
1.336     albertel 1510: 						 "Error [$declutter]",join('<br />',@_));
1.380     www      1511: 		    &Apache::lonnet::put('nohist_xmlerrornotifications',
                   1512: 					 {$key => $now},
                   1513: 					 $cdom,$cnum);		
                   1514: 		}
1.336     albertel 1515: 	    }
1.372     albertel 1516: 	    if ($env{'request.role.adv'}) {
1.336     albertel 1517: 		$errormsg=&mt("An error occured while processing this resource. The course personnel ([_1]) and the author have been notified.",join(', ',@userlist));
                   1518: 	    } else {
                   1519: 		$errormsg=&mt("An error occured while processing this resource. The instructor has been notified.");
                   1520: 	    }
                   1521: 	}
                   1522: 	push(@Apache::lonxml::error_messages,"<b>$errormsg</b> <br />");
1.52      albertel 1523:     }
1.22      albertel 1524: }
1.49      albertel 1525: 
1.22      albertel 1526: sub warning {
1.295     albertel 1527:     $warningcount++;
1.261     albertel 1528:   
1.372     albertel 1529:     if ($env{'form.grade_target'} ne 'tex') {
1.348     albertel 1530: 	if ( &show_error_warn_msg() ) {
1.309     albertel 1531: 	    push(@Apache::lonxml::warning_messages,
                   1532: 		 $Apache::lonxml::warnings_error_header.
                   1533: 		 "<b>W</b>ARNING<b>:</b>".join('<br />',@_)."<br />\n");
1.295     albertel 1534: 	    $Apache::lonxml::warnings_error_header='';
                   1535: 	}
                   1536:     }
1.309     albertel 1537: }
                   1538: 
                   1539: sub info {
1.372     albertel 1540:     if ($env{'form.grade_target'} ne 'tex' 
                   1541: 	&& $env{'request.state'} eq 'construct') {
1.309     albertel 1542: 	push(@Apache::lonxml::info_messages,join('<br />',@_)."<br />\n");
                   1543:     }
                   1544: }
                   1545: 
                   1546: sub message_location {
                   1547:     return '__LONCAPA_INTERNAL_MESSAGE_LOCATION__';
                   1548: }
                   1549: 
                   1550: sub add_messages {
                   1551:     my ($msg)=@_;
                   1552:     my $result=join(' ',
                   1553: 		    @Apache::lonxml::info_messages,
                   1554: 		    @Apache::lonxml::error_messages,
                   1555: 		    @Apache::lonxml::warning_messages);
                   1556:     undef(@Apache::lonxml::info_messages);
                   1557:     undef(@Apache::lonxml::error_messages);
                   1558:     undef(@Apache::lonxml::warning_messages);
                   1559:     $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__/$result/;
                   1560:     $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__//g;
1.83      albertel 1561: }
                   1562: 
                   1563: sub get_param {
1.213     albertel 1564:     my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
                   1565:     if ( ! $context ) { $context = -1; }
                   1566:     my $args ='';
                   1567:     if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1.297     sakharuk 1568:     if ( ! $Apache::lonxml::usestyle ) {
                   1569: 	$args=$Apache::lonxml::style_values.$args;
                   1570:     }
1.213     albertel 1571:     if ( ! $args ) { return undef; }
                   1572:     if ( $case_insensitive ) {
                   1573: 	if ($args =~ s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei) {
                   1574: 	    return &Apache::run::run("{$args;".'return $'.$param.'}',
                   1575:                                      $safeeval); #'
                   1576: 	} else {
                   1577: 	    return undef;
                   1578: 	}
                   1579:     } else {
                   1580: 	if ( $args =~ /my \$\Q$param\E=\"/ ) {
                   1581: 	    return &Apache::run::run("{$args;".'return $'.$param.'}',
                   1582:                                      $safeeval); #'
                   1583: 	} else {
                   1584: 	    return undef;
                   1585: 	}
                   1586:     }
1.22      albertel 1587: }
                   1588: 
1.132     albertel 1589: sub get_param_var {
1.213     albertel 1590:   my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
1.132     albertel 1591:   if ( ! $context ) { $context = -1; }
                   1592:   my $args ='';
                   1593:   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1.297     sakharuk 1594:   if ( ! $Apache::lonxml::usestyle ) {
                   1595:       $args=$Apache::lonxml::style_values.$args;
                   1596:   }
1.230     albertel 1597:   &Apache::lonxml::debug("Args are $args param is $param");
1.213     albertel 1598:   if ($case_insensitive) {
                   1599:       if (! ($args=~s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei)) {
                   1600: 	  return undef;
                   1601:       }
                   1602:   } elsif ( $args !~ /my \$\Q$param\E=\"/ ) { return undef; }
1.132     albertel 1603:   my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
1.230     albertel 1604:   &Apache::lonxml::debug("first run is $value");
1.341     albertel 1605:   if ($value =~ /^[\$\@\%][a-zA-Z_]\w*$/) {
1.230     albertel 1606:       &Apache::lonxml::debug("doing second");
                   1607:       my @result=&Apache::run::run("return $value",$safeeval,1);
                   1608:       if (!defined($result[0])) {
                   1609: 	  return $value
                   1610:       } else {
                   1611: 	  if (wantarray) { return @result; } else { return $result[0]; }
                   1612:       }
1.132     albertel 1613:   } else {
                   1614:     return $value;
                   1615:   }
                   1616: }
                   1617: 
1.74      albertel 1618: sub register_insert {
1.75      albertel 1619:   my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
1.74      albertel 1620:   my $i;
1.76      albertel 1621:   my $tagnum=0;
1.74      albertel 1622:   my @order;
                   1623:   for ($i=0;$i < $#data; $i++) {
                   1624:     my $line = $data[$i];
                   1625:     if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
                   1626:     if ( $line =~ /TABLE/ ) { last; }
1.268     bowersj2 1627:     my ($tag,$descrip,$color,$function,$show,$helpfile,$helpdesc) = split(/,/, $line);
1.135     albertel 1628:     if ($tag) {
                   1629:       $insertlist{"$tagnum.tag"} = $tag;
                   1630:       $insertlist{"$tagnum.description"} = $descrip;
                   1631:       $insertlist{"$tagnum.color"} = $color;
                   1632:       $insertlist{"$tagnum.function"} = $function;
                   1633:       if (!defined($show)) { $show='yes'; }
                   1634:       $insertlist{"$tagnum.show"}= $show;
1.268     bowersj2 1635:       $insertlist{"$tagnum.helpfile"} = $helpfile;
                   1636:       $insertlist{"$tagnum.helpdesc"} = $helpdesc;
1.135     albertel 1637:       $insertlist{"$tag.num"}=$tagnum;
                   1638:       $tagnum++;
                   1639:     }
1.74      albertel 1640:   }
1.76      albertel 1641:   $i++; #skipping TABLE line
                   1642:   $tagnum = 0;
1.74      albertel 1643:   for (;$i < $#data;$i++) {
                   1644:     my $line = $data[$i];
1.76      albertel 1645:     my ($mnemonic,@which) = split(/ +/,$line);
                   1646:     my $tag = $insertlist{"$tagnum.tag"};
1.144     matthew  1647:     for (my $j=0;$j <=$#which;$j++) {
1.74      albertel 1648:       if ( $which[$j] eq 'Y' ) {
1.76      albertel 1649: 	if ($insertlist{"$j.show"} ne 'no') {
                   1650: 	  push(@{ $insertlist{"$tag.which"} },$j);
                   1651: 	}
1.74      albertel 1652:       }
                   1653:     }
1.76      albertel 1654:     $tagnum++;
1.74      albertel 1655:   }
                   1656: }
1.98      albertel 1657: 
                   1658: sub description {
                   1659:   my ($token)=@_;
1.138     albertel 1660:   my $tagnum;
                   1661:   my $tag=$token->[1];
                   1662:   foreach my $namespace (reverse @Apache::lonxml::namespace) {
                   1663:     my $testtag=$namespace.'::'.$tag;
                   1664:     $tagnum=$insertlist{"$testtag.num"};
                   1665:     if (defined($tagnum)) { last; }
                   1666:   }
                   1667:   if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
                   1668:   return $insertlist{$tagnum.'.description'};
1.268     bowersj2 1669: }
                   1670: 
                   1671: # Returns a list containing the help file, and the description
                   1672: sub helpinfo {
                   1673:   my ($token)=@_;
                   1674:   my $tagnum;
                   1675:   my $tag=$token->[1];
                   1676:   foreach my $namespace (reverse @Apache::lonxml::namespace) {
                   1677:     my $testtag=$namespace.'::'.$tag;
                   1678:     $tagnum=$insertlist{"$testtag.num"};
                   1679:     if (defined($tagnum)) { last; }
                   1680:   }
                   1681:   if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
                   1682:   return ($insertlist{$tagnum.'.helpfile'}, $insertlist{$tagnum.'.helpdesc'});
1.98      albertel 1683: }
1.123     albertel 1684: 
                   1685: # ----------------------------------------------------------------- whichuser
                   1686: # returns a list of $symb, $courseid, $domain, $name that is correct for
                   1687: # calls to lonnet functions for this setup.
                   1688: # - looks for form.grade_ parameters
                   1689: sub whichuser {
1.262     matthew  1690:   my ($passedsymb)=@_;
1.245     albertel 1691:   my ($symb,$courseid,$domain,$name,$publicuser);
1.372     albertel 1692:   if (defined($env{'form.grade_symb'})) {
1.350     albertel 1693:       my ($tmp_courseid)=
                   1694: 	  &Apache::loncommon::get_env_multiple('form.grade_courseid');
                   1695:       my $allowed=&Apache::lonnet::allowed('vgr',$tmp_courseid);
                   1696:       if (!$allowed && 
1.372     albertel 1697: 	  exists($env{'request.course.sec'}) && 
                   1698: 	  $env{'request.course.sec'} !~ /^\s*$/) {
1.350     albertel 1699: 	  $allowed=&Apache::lonnet::allowed('vgr',$tmp_courseid.
1.372     albertel 1700: 					    '/'.$env{'request.course.sec'});
1.350     albertel 1701:       }
                   1702:       if ($allowed) {
                   1703: 	  ($symb)=&Apache::loncommon::get_env_multiple('form.grade_symb');
                   1704: 	  $courseid=$tmp_courseid;
                   1705: 	  ($domain)=&Apache::loncommon::get_env_multiple('form.grade_domain');
                   1706: 	  ($name)=&Apache::loncommon::get_env_multiple('form.grade_username');
                   1707: 	  return ($symb,$courseid,$domain,$name,$publicuser);
                   1708:       }
                   1709:   }
                   1710:   if (!$passedsymb) {
                   1711:       $symb=&Apache::lonnet::symbread();
1.134     albertel 1712:   } else {
1.350     albertel 1713:       $symb=$passedsymb;
                   1714:   }
1.372     albertel 1715:   $courseid=$env{'request.course.id'};
                   1716:   $domain=$env{'user.domain'};
                   1717:   $name=$env{'user.name'};
1.350     albertel 1718:   if ($name eq 'public' && $domain eq 'public') {
1.372     albertel 1719:       if (!defined($env{'form.username'})) {
                   1720: 	  $env{'form.username'}.=time.rand(10000000);
1.244     albertel 1721:       }
1.372     albertel 1722:       $name.=$env{'form.username'};
1.123     albertel 1723:   }
1.245     albertel 1724:   return ($symb,$courseid,$domain,$name,$publicuser);
1.123     albertel 1725: }
                   1726: 
1.1       sakharuk 1727: 1;
                   1728: __END__
1.68      www      1729: 
                   1730: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>