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

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

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