File:  [LON-CAPA] / loncom / xml / lonxml.pm
Revision 1.310: download - view: text, annotated - select for diffs
Fri Mar 12 17:26:29 2004 UTC (20 years, 4 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Cleanup has been done for latex_special_symbols. Now you can print carets, ~, $, $$$, #, ###, %, and ... correctly

    1: # The LearningOnline Network with CAPA
    2: # XML Parser Module 
    3: #
    4: # $Id: lonxml.pm,v 1.310 2004/03/12 17:26:29 sakharuk Exp $
    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: #
   39: # last modified 06/26/00 by Alexander Sakharuk
   40: # 11/6 Gerd Kortemeyer
   41: # 6/1/1 Gerd Kortemeyer
   42: # 2/21,3/13 Guy
   43: # 3/29,5/4 Gerd Kortemeyer
   44: # 5/26 Gerd Kortemeyer
   45: # 5/27 H. K. Ng
   46: # 6/2,6/3,6/8,6/9 Gerd Kortemeyer
   47: # 6/12,6/13 H. K. Ng
   48: # 6/16 Gerd Kortemeyer
   49: # 7/27 H. K. Ng
   50: # 8/7,8/9,8/10,8/11,8/15,8/16,8/17,8/18,8/20,8/23,8/24 Gerd Kortemeyer
   51: # Guy Albertelli
   52: # 9/26 Gerd Kortemeyer
   53: # Dec Guy Albertelli
   54: # YEAR=2002
   55: # 1/1 Gerd Kortemeyer
   56: # 1/2 Matthew Hall
   57: # 1/3 Gerd Kortemeyer
   58: #
   59: 
   60: package Apache::lonxml; 
   61: use vars 
   62: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode $errorcount $warningcount);
   63: use strict;
   64: use HTML::LCParser();
   65: use HTML::TreeBuilder();
   66: use HTML::Entities();
   67: use Safe();
   68: use Safe::Hole();
   69: use Math::Cephes();
   70: use Math::Random();
   71: use Opcode();
   72: use POSIX qw(strftime);
   73: 
   74: 
   75: sub register {
   76:   my ($space,@taglist) = @_;
   77:   foreach my $temptag (@taglist) {
   78:     push(@{ $Apache::lonxml::alltags{$temptag} },$space);
   79:   }
   80: }
   81: 
   82: sub deregister {
   83:   my ($space,@taglist) = @_;
   84:   foreach my $temptag (@taglist) {
   85:     my $tempspace = $Apache::lonxml::alltags{$temptag}[-1];
   86:     if ($tempspace eq $space) {
   87:       pop(@{ $Apache::lonxml::alltags{$temptag} });
   88:     }
   89:   }
   90:   #&printalltags();
   91: }
   92: 
   93: use Apache::Constants qw(:common);
   94: use Apache::lontexconvert();
   95: use Apache::style();
   96: use Apache::run();
   97: use Apache::londefdef();
   98: use Apache::scripttag();
   99: use Apache::languagetags();
  100: use Apache::edit();
  101: use Apache::inputtags();
  102: use Apache::outputtags();
  103: use Apache::lonnet();
  104: use Apache::File();
  105: use Apache::loncommon();
  106: use Apache::lonfeedback();
  107: use Apache::lonmsg();
  108: use Apache::loncacc();
  109: use Apache::lonlocal;
  110: 
  111: #==================================================   Main subroutine: xmlparse  
  112: #debugging control, to turn on debugging modify the correct handler
  113: $Apache::lonxml::debug=0;
  114: 
  115: # keeps count of the number of warnings and errors generated in a parse
  116: $warningcount=0;
  117: $errorcount=0;
  118: 
  119: #path to the directory containing the file currently being processed
  120: @pwd=();
  121: 
  122: #these two are used for capturing a subset of the output for later processing,
  123: #don't touch them directly use &startredirection and &endredirection
  124: @outputstack = ();
  125: $redirection = 0;
  126: 
  127: #controls wheter the <import> tag actually does
  128: $import = 1;
  129: @extlinks=();
  130: 
  131: # meta mode is a bit weird only some output is to be turned off
  132: #<output> tag turns metamode off (defined in londefdef.pm)
  133: $metamode = 0;
  134: 
  135: # turns on and of run::evaluate actually derefencing var refs
  136: $evaluate = 1;
  137: 
  138: # data structure for eidt mode, determines what tags can go into what other tags
  139: %insertlist=();
  140: 
  141: # stores the list of active tag namespaces
  142: @namespace=();
  143: 
  144: # if 0 all high ASCII characters will be encoded into HTML Entities
  145: $prevent_entity_encode=0;
  146: 
  147: # has the dynamic menu been updated to know about this resource
  148: $Apache::lonxml::registered=0;
  149: 
  150: # a pointer the the Apache request object
  151: $Apache::lonxml::request='';
  152: 
  153: # a problem number counter, and check on ether it is used
  154: $Apache::lonxml::counter=1;
  155: $Apache::lonxml::counter_changed=0;
  156: 
  157: #internal check on whether to look at style defs
  158: $Apache::lonxml::usestyle=1;
  159: 
  160: #locations used to store the parameter string for style substitutions
  161: $Apache::lonxml::style_values='';
  162: $Apache::lonxml::style_end_values='';
  163: 
  164: #array of ssi calls that need to occur after we are done parsing
  165: @Apache::lonxml::ssi_info=();
  166: 
  167: #should we do the postag variable interpolation
  168: $Apache::lonxml::post_evaluate=1;
  169: 
  170: #a header message to emit in the case of any generated warning or errors
  171: $Apache::lonxml::warnings_error_header='';
  172: 
  173: sub xmlbegin {
  174:   my $output='';
  175:   if ($ENV{'browser.mathml'}) {
  176:       $output='<?xml version="1.0"?>'
  177:             .'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'
  178:             .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
  179:             .'[<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">]>'
  180:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
  181: 		.'xmlns="http://www.w3.org/TR/REC-html40">';
  182:   } else {
  183:       $output='<html>';
  184:   }
  185:   return $output;
  186: }
  187: 
  188: sub xmlend {
  189:     my $mode='xml';
  190:     my $status='OPEN';
  191:     if ($Apache::lonhomework::parsing_a_problem) {
  192: 	$mode='problem';
  193: 	$status=$Apache::inputtags::status[-1]; 
  194:     }
  195:     return &Apache::lonfeedback::list_discussion($mode,$status).'</html>';
  196: }
  197: 
  198: sub tokeninputfield {
  199:     my $defhost=$Apache::lonnet::perlvar{'lonHostID'};
  200:     $defhost=~tr/a-z/A-Z/;
  201:     return (<<ENDINPUTFIELD)
  202: <script type="text/javascript">
  203:     function updatetoken() {
  204: 	var comp=new Array;
  205:         var barcode=unescape(document.tokeninput.barcode.value);
  206:         comp=barcode.split('*');
  207:         if (typeof(comp[0])!="undefined") {
  208: 	    document.tokeninput.codeone.value=comp[0];
  209: 	}
  210:         if (typeof(comp[1])!="undefined") {
  211: 	    document.tokeninput.codetwo.value=comp[1];
  212: 	}
  213:         if (typeof(comp[2])!="undefined") {
  214:             comp[2]=comp[2].toUpperCase();
  215: 	    document.tokeninput.codethree.value=comp[2];
  216: 	}
  217:         document.tokeninput.barcode.value='';
  218:     }  
  219: </script>
  220: <form method="post" name="tokeninput">
  221: <table border="2" bgcolor="#FFFFBB">
  222: <tr><th>DocID Checkin</th></tr>
  223: <tr><td>
  224: <table>
  225: <tr>
  226: <td>Scan in Barcode</td>
  227: <td><input type="text" size="22" name="barcode" 
  228: onChange="updatetoken()"/></td>
  229: </tr>
  230: <tr><td><i>or</i> Type in DocID</td>
  231: <td>
  232: <input type="text" size="5" name="codeone" />
  233: <b><font size="+2">*</font></b>
  234: <input type="text" size="5" name="codetwo" />
  235: <b><font size="+2">*</font></b>
  236: <input type="text" size="10" name="codethree" value="$defhost" 
  237: onChange="this.value=this.value.toUpperCase()" />
  238: </td></tr>
  239: </table>
  240: </td></tr>
  241: <tr><td><input type="submit" value="Check in DocID" /></td></tr>
  242: </table>
  243: </form>
  244: ENDINPUTFIELD
  245: }
  246: 
  247: sub maketoken {
  248:     my ($symb,$tuname,$tudom,$tcrsid)=@_;
  249:     unless ($symb) {
  250: 	$symb=&Apache::lonnet::symbread();
  251:     }
  252:     unless ($tuname) {
  253: 	$tuname=$ENV{'user.name'};
  254:         $tudom=$ENV{'user.domain'};
  255:         $tcrsid=$ENV{'request.course.id'};
  256:     }
  257: 
  258:     return &Apache::lonnet::checkout($symb,$tuname,$tudom,$tcrsid);
  259: }
  260: 
  261: sub printtokenheader {
  262:     my ($target,$token,$tsymb,$tcrsid,$tudom,$tuname)=@_;
  263:     unless ($token) { return ''; }
  264: 
  265:     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
  266:     unless ($tsymb) {
  267: 	$tsymb=$symb;
  268:     }
  269:     unless ($tuname) {
  270: 	$tuname=$name;
  271:         $tudom=$domain;
  272:         $tcrsid=$courseid;
  273:     }
  274: 
  275:     my %reply=&Apache::lonnet::get('environment',
  276:               ['firstname','middlename','lastname','generation'],
  277:               $tudom,$tuname);
  278:     my $plainname=$reply{'firstname'}.' '. 
  279:                   $reply{'middlename'}.' '.
  280:                   $reply{'lastname'}.' '.
  281: 		  $reply{'generation'};
  282: 
  283:     if ($target eq 'web') {
  284:         my %idhash=&Apache::lonnet::idrget($tudom,($tuname));
  285: 	return 
  286:  '<img align="right" src="/cgi-bin/barcode.png?encode='.$token.'" />'.
  287:                &mt('Checked out for').' '.$plainname.
  288:                '<br />'.&mt('User').': '.$tuname.' at '.$tudom.
  289: 	       '<br />'.&mt('ID').': '.$idhash{$tuname}.
  290: 	       '<br />'.&mt('CourseID').': '.$tcrsid.
  291: 	       '<br />'.&mt('Course').': '.$ENV{'course.'.$tcrsid.'.description'}.
  292:                '<br />'.&mt('DocID').': '.$token.
  293:                '<br />'.&mt('Time').': '.&Apache::lonlocal::locallocaltime().'<hr />';
  294:     } else {
  295:         return $token;
  296:     }
  297: }
  298: 
  299: sub fontsettings() {
  300:     my $headerstring='';
  301:     if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) { 
  302: 	$headerstring.=
  303: 	    '<meta Content-Type="text/html; charset=x-mac-roman">';
  304:     } elsif (!$ENV{'browser.mathml'} && $ENV{'browser.unicode'}) {
  305: 	$headerstring.=
  306: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
  307:     }
  308:     return $headerstring;
  309: }
  310: 
  311: sub printalltags {
  312:   my $temp;
  313:   foreach $temp (sort keys %Apache::lonxml::alltags) {
  314:     &Apache::lonxml::debug("$temp -- ".
  315: 		  join(',',@{ $Apache::lonxml::alltags{$temp} }));
  316:   }
  317: }
  318: 
  319: sub xmlparse {
  320:  my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
  321: 
  322:  &setup_globals($request,$target);
  323:  &Apache::inputtags::initialize_inputtags();
  324:  &Apache::outputtags::initialize_outputtags();
  325:  &Apache::edit::initialize_edit();
  326:  &Apache::londefdef::initialize_londefdef();
  327: 
  328: #
  329: # do we have a course style file?
  330: #
  331: 
  332:  if ($ENV{'request.course.id'} && $ENV{'request.state'} ne 'construct') {
  333:      my $bodytext=
  334: 	 $ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'};
  335:      if ($bodytext) {
  336:        my $location=&Apache::lonnet::filelocation('',$bodytext);
  337:        my $styletext=&Apache::lonnet::getfile($location);
  338:        if ($styletext ne '-1') {
  339:           %style_for_target = (%style_for_target,
  340:                           &Apache::style::styleparser($target,$styletext));
  341:        }
  342:     }
  343:  } elsif ($ENV{'construct.style'} && ($ENV{'request.state'} eq 'construct')) {
  344:      my $location=&Apache::lonnet::filelocation('',$ENV{'construct.style'});
  345:      my $styletext=&Apache::lonnet::getfile($location);
  346:        if ($styletext ne '-1') {
  347:           %style_for_target = (%style_for_target,
  348:                           &Apache::style::styleparser($target,$styletext));
  349:       }
  350:  }
  351: #&printalltags();
  352:  my @pars = ();
  353:  my $pwd=$ENV{'request.filename'};
  354:  $pwd =~ s:/[^/]*$::;
  355:  &newparser(\@pars,\$content_file_string,$pwd);
  356: 
  357:  my $safeeval = new Safe;
  358:  my $safehole = new Safe::Hole;
  359:  &init_safespace($target,$safeeval,$safehole,$safeinit);
  360: #-------------------- Redefinition of the target in the case of compound target
  361: 
  362:  ($target, my @tenta) = split('&&',$target);
  363: 
  364:  my @stack = ();
  365:  my @parstack = ();
  366:  &initdepth;
  367: 
  368:  my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
  369: 				   $safeeval,\%style_for_target);
  370: 
  371:  if ($ENV{'request.uri'}) {
  372:     &writeallows($ENV{'request.uri'});
  373:  }
  374:  &do_registered_ssi();
  375:  if ($Apache::lonxml::counter_changed) { &store_counter() }
  376:  return $finaloutput;
  377: }
  378: 
  379: sub htmlclean {
  380:     my ($raw,$full)=@_;
  381: 
  382:     my $tree = HTML::TreeBuilder->new;
  383:     $tree->ignore_unknown(0);
  384: 
  385:     $tree->parse($raw);
  386: 
  387:     my $output= $tree->as_HTML(undef,' ');
  388: 
  389:     $output=~s/\<(br|hr|img|meta|allow)(.*?)\>/\<$1$2 \/\>/gis;
  390:     $output=~s/\<\/(br|hr|img|meta|allow)\>//gis;
  391:     unless ($full) {
  392:        $output=~s/\<[\/]*(body|head|html)\>//gis;
  393:     }
  394: 
  395:     $tree = $tree->delete;
  396: 
  397:     return $output;
  398: }
  399: 
  400: sub latex_special_symbols {
  401:     my ($string,$where)=@_;
  402:     if ($where eq 'header') {
  403: 	$string =~ s/(\\|_|\^)/ /g;
  404: 	$string =~ s/(\$|%|\#|&|\{|\})/\\$1/g;
  405: 	$string =~ s/_/ /g;
  406:     } else {
  407: 	$string=~s/([^\\])\%/$1\\\%/g;
  408: 	$string=~s/([^\\])(\$|_)/$1\\$2/g;
  409: 	$string=~s/\$\$/\$\\\$/g;
  410:         $string=~s/([^\\])\&/$1\\\&/g;
  411:         $string=~s/([^\\])\#/$1\\\#/g;
  412: 	$string=~s/\#\#/\#\\\#/g;
  413:         $string=~s/([^\\])(\~|\^)/$1\\$2\\strut /g;
  414: 	$string=~s/(>|<)/\\ensuremath\{$1\}/g; #more or less
  415: #single { or } How to escape?
  416:     }
  417:     return $string;
  418: }
  419: 
  420: sub inner_xmlparse {
  421:   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
  422:   my $finaloutput = '';
  423:   my $result;
  424:   my $token;
  425:   my $dontpop=0;
  426:   while ( $#$pars > -1 ) {
  427:     while ($token = $$pars['-1']->get_token) {
  428:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') ) {
  429: 	if ($metamode<1) {
  430: 	    my $text=$token->[1];
  431: 	    if ($token->[0] eq 'C' && $target eq 'tex') {
  432: 		$text = '';
  433: #		$text = '%'.$text."\n";
  434: 	    }
  435: 	    $result.=$text;
  436: 	}
  437:       } elsif (($token->[0] eq 'D')) {
  438: 	if ($metamode<1 && $target eq 'web') {
  439: 	    my $text=$token->[1];
  440: 	    $result.=$text;
  441: 	}
  442:       } elsif ($token->[0] eq 'PI') {
  443: 	if ($metamode<1 && $target eq 'web') {
  444: 	  $result=$token->[2];
  445: 	}
  446:       } elsif ($token->[0] eq 'S') {
  447: 	# add tag to stack
  448: 	push (@$stack,$token->[1]);
  449: 	# add parameters list to another stack
  450: 	push (@$parstack,&parstring($token));
  451: 	&increasedepth($token);
  452: 	if ($Apache::lonxml::usestyle &&
  453: 	    exists($$style_for_target{$token->[1]})) {
  454: 	    $Apache::lonxml::usestyle=0;
  455: 	    my $string=$$style_for_target{$token->[1]}.
  456: 	      '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
  457: 	    &Apache::lonxml::newparser($pars,\$string);
  458: 	    $Apache::lonxml::style_values=$$parstack[-1];
  459: 	    $Apache::lonxml::style_end_values=$$parstack[-1];
  460: 	} else {
  461: 	  $result = &callsub("start_$token->[1]", $target, $token, $stack,
  462: 			     $parstack, $pars, $safeeval, $style_for_target);
  463: 	}
  464:       } elsif ($token->[0] eq 'E') {
  465: 	if ($Apache::lonxml::usestyle &&
  466: 	    exists($$style_for_target{'/'."$token->[1]"})) {
  467: 	    $Apache::lonxml::usestyle=0;
  468: 	    my $string=$$style_for_target{'/'.$token->[1]}.
  469: 	      '<LONCAPA_INTERNAL_TURN_STYLE_ON end="'.$token->[1].'" />';
  470: 	    &Apache::lonxml::newparser($pars,\$string);
  471: 	    $Apache::lonxml::style_values=$Apache::lonxml::style_end_values;
  472: 	    $Apache::lonxml::style_end_values='';
  473: 	    $dontpop=1;
  474: 	} else {
  475: 	    #clear out any tags that didn't end
  476: 	    while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
  477: 		my $lasttag=$$stack[-1];
  478: 		if ($token->[1] =~ /^$lasttag$/i) {
  479: 		    &Apache::lonxml::warning('Using tag &lt;/'.$token->[1].'&gt; on line '.$token->[3].' as end tag to &lt;'.$$stack[-1].'&gt;');
  480: 		    last;
  481: 		} else {
  482: 		    &Apache::lonxml::warning('Found tag &lt;/'.$token->[1].'&gt; on line '.$token->[3].' when looking for &lt;/'.$$stack[-1].'&gt; in file');
  483: 		    &end_tag($stack,$parstack,$token);
  484: 		}
  485: 	    }
  486: 	    $result = &callsub("end_$token->[1]", $target, $token, $stack,
  487: 			       $parstack, $pars,$safeeval, $style_for_target);
  488: 	}
  489:       } else {
  490: 	&Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
  491:       }
  492:       #evaluate variable refs in result
  493:       if ($Apache::lonxml::post_evaluate &&$result ne "") {
  494: 	  my $extras;
  495: 	  if (!$Apache::lonxml::usestyle) {
  496: 	      $extras=$Apache::lonxml::style_values;
  497: 	  }
  498: 	if ( $#$parstack > -1 ) {
  499: 	  $result=&Apache::run::evaluate($result,$safeeval,$extras.$$parstack[-1]);
  500: 	} else {
  501: 	  $result= &Apache::run::evaluate($result,$safeeval,$extras);
  502: 	}
  503:       }
  504:       $Apache::lonxml::post_evaluate=1;
  505: 
  506:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
  507: 	  #Style file definitions should be correct
  508: 	  if ($target eq 'tex' && ($Apache::lonxml::usestyle)) {
  509: 	      $result=&latex_special_symbols(&Apache::lonprintout::character_chart($result));
  510: 	  }
  511:       }
  512: 
  513:       # Encode any high ASCII characters
  514: #      if (!$Apache::lonxml::prevent_entity_encode) {
  515: #	$result=&HTML::Entities::encode($result,"\200-\377");
  516: #      }
  517:       if ($Apache::lonxml::redirection) {
  518: 	$Apache::lonxml::outputstack['-1'] .= $result;
  519:       } else {
  520: 	$finaloutput.=$result;
  521:       }
  522:       $result = '';
  523: 
  524:       if ($token->[0] eq 'E' && !$dontpop) {
  525: 	&end_tag($stack,$parstack,$token);
  526:       }
  527:       $dontpop=0;
  528:     }	
  529:     if ($#$pars > -1) {
  530: 	pop @$pars;
  531: 	pop @Apache::lonxml::pwd;
  532:     }
  533:   }
  534: 
  535:   # if ($target eq 'meta') {
  536:   #   $finaloutput.=&endredirection;
  537:   # }
  538: 
  539: 
  540:   if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
  541:     $finaloutput=&afterburn($finaloutput);
  542:   }	    
  543:   return $finaloutput;
  544: }
  545: 
  546: sub callsub {
  547:   my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  548:   my $currentstring='';
  549:   my $nodefault;
  550:   {
  551:     my $sub1;
  552:     no strict 'refs';
  553:     my $tag=$token->[1];
  554: # get utterly rid of extended html tags
  555:     if ($tag=~/^x\-/i) { return ''; }
  556:     my $space=$Apache::lonxml::alltags{$tag}[-1];
  557:     if (!$space) {
  558:      	$tag=~tr/A-Z/a-z/;
  559: 	$sub=~tr/A-Z/a-z/;
  560: 	$space=$Apache::lonxml::alltags{$tag}[-1]
  561:     }
  562: 
  563:     my $deleted=0;
  564:     $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
  565:     if (($token->[0] eq 'S') && ($target eq 'modified')) {
  566:       $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
  567: 					     $parstack,$parser,$safeeval,
  568: 					     $style);
  569:     }
  570:     if (!$deleted) {
  571:       if ($space) {
  572: 	#&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
  573: 	$sub1="$space\:\:$sub";
  574: 	($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
  575: 					     $parstack,$parser,$safeeval,
  576: 					     $style);
  577:       } else {
  578: 	#&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
  579: 	if ($metamode <1) {
  580: 	  if (defined($token->[4]) && ($metamode < 1)) {
  581: 	    $currentstring = $token->[4];
  582: 	  } else {
  583: 	    $currentstring = $token->[2];
  584: 	  }
  585: 	}
  586:       }
  587:       #    &Apache::lonxml::debug("nodefalt:$nodefault:");
  588:       if ($currentstring eq '' && $nodefault eq '') {
  589: 	if ($target eq 'edit') {
  590: 	  #&Apache::lonxml::debug("doing default edit for $token->[1]");
  591: 	  if ($token->[0] eq 'S') {
  592: 	    $currentstring = &Apache::edit::tag_start($target,$token);
  593: 	  } elsif ($token->[0] eq 'E') {
  594: 	    $currentstring = &Apache::edit::tag_end($target,$token);
  595: 	  }
  596: 	} elsif ($target eq 'modified') {
  597: 	  if ($token->[0] eq 'S') {
  598: 	    $currentstring = $token->[4];
  599: 	    $currentstring.=&Apache::edit::handle_insert();
  600: 	  } elsif ($token->[0] eq 'E') {
  601: 	    $currentstring = $token->[2];
  602:             $currentstring.=&Apache::edit::handle_insertafter($token->[1]);
  603: 	  } else {
  604: 	    $currentstring = $token->[2];
  605: 	  }
  606: 	}
  607:       }
  608:     }
  609:     use strict 'refs';
  610:   }
  611:   return $currentstring;
  612: }
  613: 
  614: sub setup_globals {
  615:   my ($request,$target)=@_;
  616:   $Apache::lonxml::request=$request;
  617:   $Apache::lonxml::registered = 0;
  618:   $errorcount=0;
  619:   $warningcount=0;
  620:   $Apache::lonxml::default_homework_loaded=0;
  621:   $Apache::lonxml::usestyle=1;
  622:   &init_counter();
  623:   @Apache::lonxml::pwd=();
  624:   @Apache::lonxml::extlinks=();
  625:   @Apache::lonxml::ssi_info=();
  626:   $Apache::lonxml::post_evaluate=1;
  627:   $Apache::lonxml::warnings_error_header='';
  628:   if ($target eq 'meta') {
  629:     $Apache::lonxml::redirection = 0;
  630:     $Apache::lonxml::metamode = 1;
  631:     $Apache::lonxml::evaluate = 1;
  632:     $Apache::lonxml::import = 0;
  633:   } elsif ($target eq 'answer') {
  634:     $Apache::lonxml::redirection = 0;
  635:     $Apache::lonxml::metamode = 1;
  636:     $Apache::lonxml::evaluate = 1;
  637:     $Apache::lonxml::import = 1;
  638:   } elsif ($target eq 'grade') {
  639:     &startredirection;
  640:     $Apache::lonxml::metamode = 0;
  641:     $Apache::lonxml::evaluate = 1;
  642:     $Apache::lonxml::import = 1;
  643:   } elsif ($target eq 'modified') {
  644:     $Apache::lonxml::redirection = 0;
  645:     $Apache::lonxml::metamode = 0;
  646:     $Apache::lonxml::evaluate = 0;
  647:     $Apache::lonxml::import = 0;
  648:   } elsif ($target eq 'edit') {
  649:     $Apache::lonxml::redirection = 0;
  650:     $Apache::lonxml::metamode = 0;
  651:     $Apache::lonxml::evaluate = 0;
  652:     $Apache::lonxml::import = 0;
  653:   } elsif ($target eq 'analyze') {
  654:     $Apache::lonxml::redirection = 0;
  655:     $Apache::lonxml::metamode = 0;
  656:     $Apache::lonxml::evaluate = 1;
  657:     $Apache::lonxml::import = 1;
  658:   } else {
  659:     $Apache::lonxml::redirection = 0;
  660:     $Apache::lonxml::metamode = 0;
  661:     $Apache::lonxml::evaluate = 1;
  662:     $Apache::lonxml::import = 1;
  663:   }
  664: }
  665: 
  666: sub init_safespace {
  667:   my ($target,$safeeval,$safehole,$safeinit) = @_;
  668:   $safeeval->permit("entereval");
  669:   $safeeval->permit(":base_math");
  670:   $safeeval->permit("sort");
  671:   $safeeval->permit("time");
  672:   $safeeval->deny(":base_io");
  673:   $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
  674:   $safehole->wrap(\&Apache::outputtags::multipart,$safeeval,'&multipart');
  675:   $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
  676:   
  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');
  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: 
  720: #  $safehole->wrap(\&Math::Cephes::new_fract,$safeeval,'&new_fract');
  721: #  $safehole->wrap(\&Math::Cephes::radd,$safeeval,'&radd');
  722: #  $safehole->wrap(\&Math::Cephes::rsub,$safeeval,'&rsub');
  723: #  $safehole->wrap(\&Math::Cephes::rmul,$safeeval,'&rmul');
  724: #  $safehole->wrap(\&Math::Cephes::rdiv,$safeeval,'&rdiv');
  725: #  $safehole->wrap(\&Math::Cephes::euclid,$safeeval,'&euclid');
  726: 
  727:   $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
  728:   $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
  729:   $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
  730:   $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
  731:   $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
  732:   $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
  733:   $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
  734:   $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
  735:   $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
  736:   $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
  737:   $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
  738:   $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
  739:   $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
  740:   $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
  741:   $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
  742:   $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
  743:   $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
  744:   $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
  745:   $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
  746:   $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
  747:   $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
  748:   $safehole->wrap(\&Apache::lonxml::error,$safeeval,'&LONCAPA_INTERNAL_ERROR');
  749: 
  750: #need to inspect this class of ops
  751: # $safeeval->deny(":base_orig");
  752:   $safeinit .= ';$external::target="'.$target.'";';
  753:   my $rndseed;
  754:   my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
  755:   $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
  756:   $safeinit .= ';$external::randomseed='.$rndseed.';';
  757:   &Apache::lonxml::debug("Setting rndseed to $rndseed");
  758:   &Apache::run::run($safeinit,$safeeval);
  759: 
  760:   my $subroutine=<<'EVALUATESUB';
  761: sub __LC_INTERNAL_EVALUATE__ {
  762:     my ($__LC__a,$__LC__b,$__LC__c)=@_;
  763:     my $__LC__prefix;
  764:     while(1){
  765: 	{ 
  766: 	    use strict;
  767: 	    no strict "vars";
  768: 	    if (eval(defined(eval($__LC__a.$__LC__b)))) {
  769: 		return $__LC__prefix.eval($__LC__a.$__LC__b.$__LC__c);
  770: 	    }
  771: 	}
  772: 	$__LC__prefix.=substr($__LC__a,0,1,"");
  773: 	if ($__LC__a!~/^(\$|&|\#)/) { last; }
  774:     }
  775:     return $__LC__prefix.$__LC__a.$__LC__b.$__LC__c;
  776: }
  777: EVALUATESUB
  778:     $safeeval->permit("require");
  779:     $safeeval->reval($subroutine);
  780:     $safeeval->deny("require");
  781: }
  782: 
  783: sub default_homework_load {
  784:     my ($safeeval)=@_;
  785:     &Apache::lonxml::debug('Loading default_homework');
  786:     my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
  787:     if ($default eq -1) {
  788: 	&Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
  789:     } else {
  790: 	&Apache::run::run($default,$safeeval);
  791: 	$Apache::lonxml::default_homework_loaded=1;
  792:     }
  793: }
  794: 
  795: sub startredirection {
  796:   $Apache::lonxml::redirection++;
  797:   push (@Apache::lonxml::outputstack, '');
  798: }
  799: 
  800: sub endredirection {
  801:   if (!$Apache::lonxml::redirection) {
  802:     &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
  803:     return '';
  804:   }
  805:   $Apache::lonxml::redirection--;
  806:   pop @Apache::lonxml::outputstack;
  807: }
  808: 
  809: sub end_tag {
  810:   my ($tagstack,$parstack,$token)=@_;
  811:   pop(@$tagstack);
  812:   pop(@$parstack);
  813:   &decreasedepth($token);
  814: }
  815: 
  816: sub initdepth {
  817:   @Apache::lonxml::depthcounter=();
  818:   $Apache::lonxml::depth=-1;
  819:   $Apache::lonxml::olddepth=-1;
  820: }
  821: 
  822: sub increasedepth {
  823:   my ($token) = @_;
  824:   $Apache::lonxml::depth++;
  825:   $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
  826:   if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
  827:     $Apache::lonxml::olddepth=$Apache::lonxml::depth;
  828:   }
  829:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
  830:   &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
  831: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
  832: }
  833: 
  834: sub decreasedepth {
  835:   my ($token) = @_;
  836:   $Apache::lonxml::depth--;
  837:   if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
  838:     $#Apache::lonxml::depthcounter--;
  839:     $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
  840:   }
  841:   if (  $Apache::lonxml::depth < -1) {
  842:     &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
  843:     $Apache::lonxml::depth='-1';
  844:   }
  845:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
  846:   &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
  847: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
  848: }
  849: 
  850: sub get_all_text_unbalanced {
  851: #there is a copy of this in lonpublisher.pm
  852:  my($tag,$pars)= @_;
  853:  my $token;
  854:  my $result='';
  855:  $tag='<'.$tag.'>';
  856:  while ($token = $$pars[-1]->get_token) {
  857:    if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
  858:      $result.=$token->[1];
  859:    } elsif ($token->[0] eq 'PI') {
  860:      $result.=$token->[2];
  861:    } elsif ($token->[0] eq 'S') {
  862:      $result.=$token->[4];
  863:    } elsif ($token->[0] eq 'E')  {
  864:      $result.=$token->[2];
  865:    }
  866:    if ($result =~ /(.*)\Q$tag\E(.*)/s) {
  867:      &Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
  868:      &Apache::lonxml::debug('Result is :'.$1);
  869:      $result=$1;
  870:      my $redo=$tag.$2;
  871:      &Apache::lonxml::newparser($pars,\$redo);
  872:      last;
  873:    }
  874:  }
  875:  return $result
  876: }
  877: 
  878: sub increment_counter {
  879:     my ($increment) = @_;
  880:     if (defined($increment) && $increment gt 0) {
  881: 	$Apache::lonxml::counter+=$increment;
  882:     } else {
  883: 	$Apache::lonxml::counter++;
  884:     }
  885:     $Apache::lonxml::counter_changed=1;
  886: }
  887: 
  888: sub init_counter {
  889:     if (defined($ENV{'form.counter'})) {
  890: 	$Apache::lonxml::counter=$ENV{'form.counter'};
  891: 	$Apache::lonxml::counter_changed=0;
  892:     } else {
  893: 	$Apache::lonxml::counter=1;
  894: 	$Apache::lonxml::counter_changed=1;
  895:     }
  896: }
  897: 
  898: sub store_counter {
  899:     &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter));
  900:     return '';
  901: }
  902: 
  903: sub get_all_text {
  904:     my($tag,$pars,$style)= @_;
  905:     my $gotfullstack=1;
  906:     if (ref($pars) ne 'ARRAY') {
  907: 	$gotfullstack=0;
  908: 	$pars=[$pars];
  909:     }
  910:     if (ref($style) ne 'HASH') {
  911: 	$style={};
  912:     }
  913:     my $depth=0;
  914:     my $token;
  915:     my $result='';
  916:     if ( $tag =~ m:^/: ) { 
  917: 	my $tag=substr($tag,1); 
  918: 	#&Apache::lonxml::debug("have:$tag:");
  919: 	my $top_empty=0;
  920: 	while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
  921: 	    while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
  922: 		#&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
  923: 		if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
  924: 		    $result.=$token->[1];
  925: 		} elsif ($token->[0] eq 'PI') {
  926: 		    $result.=$token->[2];
  927: 		} elsif ($token->[0] eq 'S') {
  928: 		    if ($token->[1] =~ /^$tag$/i) { $depth++; }
  929: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/i) { $Apache::lonxml::usestyle=1; }
  930: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/i) { $Apache::lonxml::usestyle=0; }
  931: 		    $result.=$token->[4];
  932: 		} elsif ($token->[0] eq 'E')  {
  933: 		    if ( $token->[1] =~ /^$tag$/i) { $depth--; }
  934: 		    #skip sending back the last end tag
  935: 		    if ($depth == 0 && exists($$style{'/'.$token->[1]}) && $Apache::lonxml::usestyle) {
  936: 			my $string=
  937: 			    '<LONCAPA_INTERNAL_TURN_STYLE_OFF end="yes" />'.
  938: 				$$style{'/'.$token->[1]}.
  939: 				    $token->[2].
  940: 					'<LONCAPA_INTERNAL_TURN_STYLE_ON />';
  941: 			&Apache::lonxml::newparser($pars,\$string);
  942: 			#&Apache::lonxml::debug("reParsing $string");
  943: 			next;
  944: 		    }
  945: 		    if ($depth > -1) {
  946: 			$result.=$token->[2];
  947: 		    } else {
  948: 			$$pars[-1]->unget_token($token);
  949: 		    }
  950: 		}
  951: 	    }
  952: 	    if (($depth >=0) && ($#$pars == 0) ) { $top_empty=1; }
  953: 	    if (($depth >=0) && ($#$pars > 0) ) {
  954: 		pop(@$pars);
  955: 		pop(@Apache::lonxml::pwd);
  956: 	    }
  957: 	}
  958: 	if ($top_empty && $depth >= 0) {
  959: 	    #never found the end tag ran out of text, throw error send back blank
  960: 	    &error('Never found end tag for &lt;'.$tag.
  961: 		   '&gt; current string <pre>'.
  962: 		   &HTML::Entities::encode($result).
  963: 		   '</pre>');
  964: 	    if ($gotfullstack) {
  965: 		my $newstring='</'.$tag.'>'.$result;
  966: 		&Apache::lonxml::newparser($pars,\$newstring);
  967: 	    }
  968: 	    $result='';
  969: 	}
  970:     } else {
  971: 	while ($#$pars > -1) {
  972: 	    while ($token = $$pars[-1]->get_token) {
  973: 		#&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
  974: 		if (($token->[0] eq 'T')||($token->[0] eq 'C')||
  975: 		    ($token->[0] eq 'D')) {
  976: 		    $result.=$token->[1];
  977: 		} elsif ($token->[0] eq 'PI') {
  978: 		    $result.=$token->[2];
  979: 		} elsif ($token->[0] eq 'S') {
  980: 		    if ( $token->[1] =~ /^$tag$/i) {
  981: 			$$pars[-1]->unget_token($token); last;
  982: 		    } else {
  983: 			$result.=$token->[4];
  984: 		    }
  985: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/i) { $Apache::lonxml::usestyle=1; }
  986: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/i) { $Apache::lonxml::usestyle=0; }
  987: 		} elsif ($token->[0] eq 'E')  {
  988: 		    $result.=$token->[2];
  989: 		}
  990: 	    }
  991: 	    if (($#$pars > 0) ) {
  992: 		pop(@$pars);
  993: 		pop(@Apache::lonxml::pwd);
  994: 	    } else { last; }
  995: 	}
  996:     }
  997:     #&Apache::lonxml::debug("Exit:$result:");
  998:     return $result
  999: }
 1000: 
 1001: sub newparser {
 1002:   my ($parser,$contentref,$dir) = @_;
 1003:   push (@$parser,HTML::LCParser->new($contentref));
 1004:   $$parser['-1']->xml_mode('1');
 1005:   if ( $dir eq '' ) {
 1006:     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
 1007:   } else {
 1008:     push (@Apache::lonxml::pwd, $dir);
 1009:   } 
 1010: }
 1011: 
 1012: sub parstring {
 1013:   my ($token) = @_;
 1014:   my $temp='';
 1015:   foreach (@{$token->[3]}) {
 1016:     unless ($_=~/\W/) {
 1017:       my $val=$token->[2]->{$_};
 1018:       $val =~ s/([\%\@\\\"\'])/\\$1/g;
 1019:       #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
 1020:       $temp .= "my \$$_=\"$val\";";
 1021:     }
 1022:   }
 1023:   return $temp;
 1024: }
 1025: 
 1026: sub writeallows {
 1027:     unless ($#extlinks>=0) { return; }
 1028:     my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
 1029:     if ($ENV{'httpref.'.$thisurl}) {
 1030: 	$thisurl=$ENV{'httpref.'.$thisurl};
 1031:     }
 1032:     my $thisdir=$thisurl;
 1033:     $thisdir=~s/\/[^\/]+$//;
 1034:     my %httpref=();
 1035:     foreach (@extlinks) {
 1036:        $httpref{'httpref.'.
 1037:  	        &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
 1038:     }
 1039:     @extlinks=();
 1040:     &Apache::lonnet::appenv(%httpref);
 1041: }
 1042: 
 1043: sub register_ssi {
 1044:     my ($url,%form)=@_;
 1045:     push (@Apache::lonxml::ssi_info,{'url'=>$url,'form'=>\%form});
 1046:     return '';
 1047: }
 1048: 
 1049: sub do_registered_ssi {
 1050:     foreach my $info (@Apache::lonxml::ssi_info) {
 1051: 	my %form=%{ $info->{'form'}};
 1052: 	my $url=$info->{'url'};
 1053: 	&Apache::lonnet::ssi($url,%form);
 1054:     }
 1055: }
 1056: #
 1057: # Afterburner handles anchors, highlights and links
 1058: #
 1059: sub afterburn {
 1060:     my $result=shift;
 1061:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1062: 					    ['highlight','anchor','link']);
 1063:     if ($ENV{'form.highlight'}) {
 1064:        foreach (split(/\,/,$ENV{'form.highlight'})) {
 1065:            my $anchorname=$_;
 1066: 	   my $matchthis=$anchorname;
 1067:            $matchthis=~s/\_+/\\s\+/g;
 1068:            $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
 1069:        }
 1070:     }
 1071:     if ($ENV{'form.link'}) {
 1072:        foreach (split(/\,/,$ENV{'form.link'})) {
 1073:            my ($anchorname,$linkurl)=split(/\>/,$_);
 1074: 	   my $matchthis=$anchorname;
 1075:            $matchthis=~s/\_+/\\s\+/g;
 1076:            $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
 1077:        }
 1078:     }
 1079:     if ($ENV{'form.anchor'}) {
 1080:         my $anchorname=$ENV{'form.anchor'};
 1081: 	my $matchthis=$anchorname;
 1082:         $matchthis=~s/\_+/\\s\+/g;
 1083:         $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
 1084:         $result.=(<<"ENDSCRIPT");
 1085: <script type="text/javascript">
 1086:     document.location.hash='$anchorname';
 1087: </script>
 1088: ENDSCRIPT
 1089:     }
 1090:     return $result;
 1091: }
 1092: 
 1093: sub storefile {
 1094:     my ($file,$contents)=@_;
 1095:     &Apache::lonnet::correct_line_ends(\$contents);
 1096:     if (my $fh=Apache::File->new('>'.$file)) {
 1097: 	print $fh $contents;
 1098:         $fh->close();
 1099:         return 1;
 1100:     } else {
 1101: 	&warning("Unable to save file $file");
 1102: 	return 0;
 1103:     }
 1104: }
 1105: 
 1106: sub createnewhtml {
 1107:   my $filecontents=(<<SIMPLECONTENT);
 1108: <html>
 1109: <head>
 1110: <title>
 1111:                            Title of Document Goes Here
 1112: </title>
 1113: </head>
 1114: <body bgcolor="#FFFFFF">
 1115: 
 1116:                            Body of Document Goes Here
 1117: 
 1118: </body>
 1119: </html>
 1120: SIMPLECONTENT
 1121:   return $filecontents;
 1122: }
 1123: 
 1124: sub createnewsty {
 1125:   my $filecontents=(<<SIMPLECONTENT);
 1126: <definetag name="">
 1127:     <render>
 1128:        <web></web>
 1129:        <tex></tex>
 1130:     </render>
 1131: </definetag>
 1132: SIMPLECONTENT
 1133:   return $filecontents;
 1134: }
 1135: 
 1136: 
 1137: sub inserteditinfo {
 1138:       my ($result,$filecontents,$filetype)=@_;
 1139:       $filecontents = &HTML::Entities::encode($filecontents);
 1140: #      my $editheader='<a href="#editsection">Edit below</a><hr />';
 1141:       my $xml_help = '';
 1142:       if ($filetype eq 'html') {
 1143: 	  $xml_help=Apache::loncommon::helpLatexCheatsheet();
 1144:       }
 1145:       my $cleanbut = '';
 1146:       if ($filetype eq 'html') {
 1147: 	  $cleanbut='<input type="submit" name="attemptclean" value="'.
 1148: 	      &mt('Save and then attempt to clean HTML').'" />';
 1149:       }
 1150:       my $titledisplay=&display_title();
 1151:       my %lt=&Apache::lonlocal::texthash('st' => 'Save this',
 1152: 					 'vi' => 'View',
 1153: 					 'ed' => 'Edit');
 1154:       my $buttons=(<<BUTTONS);
 1155: $cleanbut
 1156: <input type="submit" name="savethisfile" accesskey="s"  value="$lt{'st'}" />
 1157: <input type="submit" name="viewmode" accesskey="v" value="$lt{'vi'}" />
 1158: BUTTONS
 1159:       my $editfooter=(<<ENDFOOTER);
 1160: <hr />
 1161: <a name="editsection" />
 1162: <form method="post">
 1163: $xml_help
 1164: <input type="hidden" name="editmode" value="$lt{'ed'}" />
 1165: $buttons<br />
 1166: <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
 1167: <br />$buttons
 1168: <br />
 1169: </form>
 1170: $titledisplay
 1171: ENDFOOTER
 1172: #      $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
 1173:       $result=~s/(\<\/body\>)/$editfooter/is;
 1174:       return $result;
 1175: }
 1176: 
 1177: sub get_target {
 1178:   my $viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
 1179:   if ( $ENV{'request.state'} eq 'published') {
 1180:     if ( defined($ENV{'form.grade_target'})
 1181: 	 && ($viewgrades == 'F' )) {
 1182:       return ($ENV{'form.grade_target'});
 1183:     } elsif (defined($ENV{'form.grade_target'})) {
 1184:       if (($ENV{'form.grade_target'} eq 'web') ||
 1185: 	  ($ENV{'form.grade_target'} eq 'tex') ) {
 1186: 	return $ENV{'form.grade_target'}
 1187:       } else {
 1188: 	return 'web';
 1189:       }
 1190:     } else {
 1191:       return 'web';
 1192:     }
 1193:   } elsif ($ENV{'request.state'} eq 'construct') {
 1194:     if ( defined($ENV{'form.grade_target'})) {
 1195:       return ($ENV{'form.grade_target'});
 1196:     } else {
 1197:       return 'web';
 1198:     }
 1199:   } else {
 1200:     return 'web';
 1201:   }
 1202: }
 1203: 
 1204: sub handler {
 1205:     my $request=shift;
 1206:     
 1207:     my $target=&get_target();
 1208:     
 1209:     $Apache::lonxml::debug=$ENV{'user.debug'};
 1210:     
 1211:     if ($ENV{'browser.mathml'}) {
 1212: 	&Apache::loncommon::content_type($request,'text/xml');
 1213:     } else {
 1214: 	&Apache::loncommon::content_type($request,'text/html');
 1215:     }
 1216:     &Apache::loncommon::no_cache($request);
 1217:     $request->send_http_header;
 1218:     
 1219:     return OK if $request->header_only;
 1220: 
 1221: 
 1222:     my $file=&Apache::lonnet::filelocation("",$request->uri);
 1223:     my $filetype;
 1224:     if ($file =~ /\.sty$/) {
 1225: 	$filetype='sty';
 1226:     } else {
 1227: 	$filetype='html';
 1228:     }
 1229: #
 1230: # Edit action? Save file.
 1231: #
 1232:     unless ($ENV{'request.state'} eq 'published') {
 1233: 	if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
 1234: 	    if (&storefile($file,$ENV{'form.filecont'})) {
 1235: 		&Apache::lonxml::info("<font COLOR=\"#0000FF\">".
 1236: 				      &mt('Updated').": ".
 1237: 				      &Apache::lonlocal::locallocaltime(time).
 1238: 				      " </font>");
 1239: 	    } 
 1240: 	}
 1241:     }
 1242:     my %mystyle;
 1243:     my $result = '';
 1244:     my $filecontents=&Apache::lonnet::getfile($file);
 1245:     if ($filecontents eq -1) {
 1246: 	my $bodytag=&Apache::loncommon::bodytag('File Error');
 1247: 	my $fnf=&mt('File not found');
 1248: 	$result=(<<ENDNOTFOUND);
 1249: <html>
 1250: <head>
 1251: <title>$fnf</title>
 1252: </head>
 1253: $bodytag
 1254: <b>$fnf: $file</b>
 1255: </body>
 1256: </html>
 1257: ENDNOTFOUND
 1258:     $filecontents='';
 1259: 	if ($ENV{'request.state'} ne 'published') {
 1260: 	    if ($filetype eq 'sty') {
 1261: 		$filecontents=&createnewsty();
 1262: 	    } else {
 1263: 		$filecontents=&createnewhtml();
 1264: 	    }
 1265: 	    $ENV{'form.editmode'}='Edit'; #force edit mode
 1266: 	}
 1267:     } else {
 1268: 	unless ($ENV{'request.state'} eq 'published') {
 1269: 	    if ($ENV{'form.attemptclean'}) {
 1270: 		$filecontents=&htmlclean($filecontents,1);
 1271: 	    }
 1272: #
 1273: # we are in construction space, see if edit mode forced
 1274:             &Apache::loncommon::get_unprocessed_cgi
 1275:                           ($ENV{'QUERY_STRING'},['editmode']);
 1276: 	}
 1277: 	if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
 1278: 	    $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
 1279: 						'',%mystyle);
 1280: 	}
 1281:     }
 1282:     
 1283: #
 1284: # Edit action? Insert editing commands
 1285: #
 1286:     unless ($ENV{'request.state'} eq 'published') {
 1287: 	if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
 1288: 	    my $displayfile=$request->uri;
 1289: 	    $displayfile=~s/^\/[^\/]*//;
 1290: 	    $result='<html><body bgcolor="#FFFFFF">'.
 1291: 		&Apache::lonxml::message_location().'<h3>'.
 1292: 		$displayfile.
 1293: 		'</h3></body></html>';
 1294: 	    $result=&inserteditinfo($result,$filecontents,$filetype);
 1295: 	}
 1296:     }
 1297:     if ($filetype eq 'html') { writeallows($request->uri); }
 1298: 	
 1299:     
 1300:     &Apache::lonxml::add_messages(\$result);
 1301:     $request->print($result);
 1302:     
 1303:     return OK;
 1304: }
 1305: 
 1306: sub display_title {
 1307:     my $result;
 1308:     if ($ENV{'request.state'} eq 'construct') {
 1309: 	my $title=&Apache::lonnet::gettitle();
 1310: 	if (!defined($title) || $title eq '') {
 1311: 	    $title = $ENV{'request.filename'};
 1312: 	    $title = substr($title, rindex($title, '/') + 1);
 1313: 	}
 1314: 	$result = "<script type='text/javascript'>top.document.title = '$title - LON-CAPA Construction Space';</script>";
 1315:     }
 1316:     return $result;
 1317: }
 1318: 
 1319: sub debug {
 1320:     if ($Apache::lonxml::debug eq "1") {
 1321: 	$|=1;
 1322: 	my $request=$Apache::lonxml::request;
 1323: 	if (!$request) { $request=Apache->request; }
 1324: 	$request->print('<font size="-2"><pre>DEBUG:'.&HTML::Entities::encode($_[0])."</pre></font>\n");
 1325:     }
 1326: }
 1327: 
 1328: sub error {
 1329:   $errorcount++;
 1330:   my $request=$Apache::lonxml::request;
 1331:   if (!$request) { $request=Apache->request; }
 1332:   if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
 1333:     # If printing in construction space, put the error inside <pre></pre>
 1334:       push(@Apache::lonxml::error_messages,
 1335: 	   $Apache::lonxml::warnings_error_header.
 1336: 	   "<b>ERROR:</b>".join("<br />\n",@_)."<br />\n");
 1337:       $Apache::lonxml::warnings_error_header='';
 1338:   } else {
 1339:       push(@Apache::lonxml::error_messages,
 1340: 	   "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />");
 1341:     #notify author
 1342:     &Apache::lonmsg::author_res_msg($ENV{'request.filename'},join('<br />',@_));
 1343:     #notify course
 1344:     if ( $ENV{'request.course.id'} ) {
 1345:       my (undef,%users)=&Apache::lonfeedback::decide_receiver(undef,0,1,1,1);
 1346:       my $declutter=&Apache::lonnet::declutter($ENV{'request.filename'});
 1347:       foreach (keys %users) {
 1348: 	my ($user,$domain) = split(/:/, $_);
 1349: 	&Apache::lonmsg::user_normal_msg($user,$domain,
 1350:         "Error [$declutter]",join('<br />',@_));
 1351:       }
 1352:     }
 1353:   }
 1354: }
 1355: 
 1356: sub warning {
 1357:     $warningcount++;
 1358:   
 1359:     if ($ENV{'form.grade_target'} ne 'tex') {
 1360: 	if ($ENV{'request.state'} eq 'construct' || $Apache::lonxml::debug) {
 1361: 	    my $request=$Apache::lonxml::request;
 1362: 	    if (!$request) { $request=Apache->request; }
 1363: 	    push(@Apache::lonxml::warning_messages,
 1364: 		 $Apache::lonxml::warnings_error_header.
 1365: 		 "<b>W</b>ARNING<b>:</b>".join('<br />',@_)."<br />\n");
 1366: 	    $Apache::lonxml::warnings_error_header='';
 1367: 	}
 1368:     }
 1369: }
 1370: 
 1371: sub info {
 1372:     if ($ENV{'form.grade_target'} ne 'tex' 
 1373: 	&& $ENV{'request.state'} eq 'construct') {
 1374: 	push(@Apache::lonxml::info_messages,join('<br />',@_)."<br />\n");
 1375:     }
 1376: }
 1377: 
 1378: sub message_location {
 1379:     return '__LONCAPA_INTERNAL_MESSAGE_LOCATION__';
 1380: }
 1381: 
 1382: sub add_messages {
 1383:     my ($msg)=@_;
 1384:     my $result=join(' ',
 1385: 		    @Apache::lonxml::info_messages,
 1386: 		    @Apache::lonxml::error_messages,
 1387: 		    @Apache::lonxml::warning_messages);
 1388:     undef(@Apache::lonxml::info_messages);
 1389:     undef(@Apache::lonxml::error_messages);
 1390:     undef(@Apache::lonxml::warning_messages);
 1391:     $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__/$result/;
 1392:     $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__//g;
 1393: }
 1394: 
 1395: sub get_param {
 1396:     my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
 1397:     if ( ! $context ) { $context = -1; }
 1398:     my $args ='';
 1399:     if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
 1400:     if ( ! $Apache::lonxml::usestyle ) {
 1401: 	$args=$Apache::lonxml::style_values.$args;
 1402:     }
 1403:     if ( ! $args ) { return undef; }
 1404:     if ( $case_insensitive ) {
 1405: 	if ($args =~ s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei) {
 1406: 	    return &Apache::run::run("{$args;".'return $'.$param.'}',
 1407:                                      $safeeval); #'
 1408: 	} else {
 1409: 	    return undef;
 1410: 	}
 1411:     } else {
 1412: 	if ( $args =~ /my \$\Q$param\E=\"/ ) {
 1413: 	    return &Apache::run::run("{$args;".'return $'.$param.'}',
 1414:                                      $safeeval); #'
 1415: 	} else {
 1416: 	    return undef;
 1417: 	}
 1418:     }
 1419: }
 1420: 
 1421: sub get_param_var {
 1422:   my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
 1423:   if ( ! $context ) { $context = -1; }
 1424:   my $args ='';
 1425:   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
 1426:   if ( ! $Apache::lonxml::usestyle ) {
 1427:       $args=$Apache::lonxml::style_values.$args;
 1428:   }
 1429:   &Apache::lonxml::debug("Args are $args param is $param");
 1430:   if ($case_insensitive) {
 1431:       if (! ($args=~s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei)) {
 1432: 	  return undef;
 1433:       }
 1434:   } elsif ( $args !~ /my \$\Q$param\E=\"/ ) { return undef; }
 1435:   my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
 1436:   &Apache::lonxml::debug("first run is $value");
 1437:   if ($value =~ /^[\$\@\%]\w+$/) {
 1438:       &Apache::lonxml::debug("doing second");
 1439:       my @result=&Apache::run::run("return $value",$safeeval,1);
 1440:       if (!defined($result[0])) {
 1441: 	  return $value
 1442:       } else {
 1443: 	  if (wantarray) { return @result; } else { return $result[0]; }
 1444:       }
 1445:   } else {
 1446:     return $value;
 1447:   }
 1448: }
 1449: 
 1450: sub register_insert {
 1451:   my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
 1452:   my $i;
 1453:   my $tagnum=0;
 1454:   my @order;
 1455:   for ($i=0;$i < $#data; $i++) {
 1456:     my $line = $data[$i];
 1457:     if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
 1458:     if ( $line =~ /TABLE/ ) { last; }
 1459:     my ($tag,$descrip,$color,$function,$show,$helpfile,$helpdesc) = split(/,/, $line);
 1460:     if ($tag) {
 1461:       $insertlist{"$tagnum.tag"} = $tag;
 1462:       $insertlist{"$tagnum.description"} = $descrip;
 1463:       $insertlist{"$tagnum.color"} = $color;
 1464:       $insertlist{"$tagnum.function"} = $function;
 1465:       if (!defined($show)) { $show='yes'; }
 1466:       $insertlist{"$tagnum.show"}= $show;
 1467:       $insertlist{"$tagnum.helpfile"} = $helpfile;
 1468:       $insertlist{"$tagnum.helpdesc"} = $helpdesc;
 1469:       $insertlist{"$tag.num"}=$tagnum;
 1470:       $tagnum++;
 1471:     }
 1472:   }
 1473:   $i++; #skipping TABLE line
 1474:   $tagnum = 0;
 1475:   for (;$i < $#data;$i++) {
 1476:     my $line = $data[$i];
 1477:     my ($mnemonic,@which) = split(/ +/,$line);
 1478:     my $tag = $insertlist{"$tagnum.tag"};
 1479:     for (my $j=0;$j <=$#which;$j++) {
 1480:       if ( $which[$j] eq 'Y' ) {
 1481: 	if ($insertlist{"$j.show"} ne 'no') {
 1482: 	  push(@{ $insertlist{"$tag.which"} },$j);
 1483: 	}
 1484:       }
 1485:     }
 1486:     $tagnum++;
 1487:   }
 1488: }
 1489: 
 1490: sub description {
 1491:   my ($token)=@_;
 1492:   my $tagnum;
 1493:   my $tag=$token->[1];
 1494:   foreach my $namespace (reverse @Apache::lonxml::namespace) {
 1495:     my $testtag=$namespace.'::'.$tag;
 1496:     $tagnum=$insertlist{"$testtag.num"};
 1497:     if (defined($tagnum)) { last; }
 1498:   }
 1499:   if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
 1500:   return $insertlist{$tagnum.'.description'};
 1501: }
 1502: 
 1503: # Returns a list containing the help file, and the description
 1504: sub helpinfo {
 1505:   my ($token)=@_;
 1506:   my $tagnum;
 1507:   my $tag=$token->[1];
 1508:   foreach my $namespace (reverse @Apache::lonxml::namespace) {
 1509:     my $testtag=$namespace.'::'.$tag;
 1510:     $tagnum=$insertlist{"$testtag.num"};
 1511:     if (defined($tagnum)) { last; }
 1512:   }
 1513:   if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
 1514:   return ($insertlist{$tagnum.'.helpfile'}, $insertlist{$tagnum.'.helpdesc'});
 1515: }
 1516: 
 1517: # ----------------------------------------------------------------- whichuser
 1518: # returns a list of $symb, $courseid, $domain, $name that is correct for
 1519: # calls to lonnet functions for this setup.
 1520: # - looks for form.grade_ parameters
 1521: sub whichuser {
 1522:   my ($passedsymb)=@_;
 1523:   my ($symb,$courseid,$domain,$name,$publicuser);
 1524:   if (defined($ENV{'form.grade_symb'})) {
 1525:     my $tmp_courseid=$ENV{'form.grade_courseid'};
 1526:     my $allowed=&Apache::lonnet::allowed('vgr',$tmp_courseid);
 1527:     if ($allowed) {
 1528:       $symb=$ENV{'form.grade_symb'};
 1529:       $courseid=$ENV{'form.grade_courseid'};
 1530:       $domain=$ENV{'form.grade_domain'};
 1531:       $name=$ENV{'form.grade_username'};
 1532:     }
 1533:   } else {
 1534:       if (!$passedsymb) {
 1535:           $symb=&Apache::lonnet::symbread();
 1536:       } else {
 1537:           $symb=$passedsymb;
 1538:       }
 1539:       $courseid=$ENV{'request.course.id'};
 1540:       $domain=$ENV{'user.domain'};
 1541:       $name=$ENV{'user.name'};
 1542:       if ($name eq 'public' && $domain eq 'public') {
 1543: 	  if (!defined($ENV{'form.username'})) {
 1544: 	      $ENV{'form.username'}.=time.rand(10000000);
 1545: 	  }
 1546: 	  $name.=$ENV{'form.username'};
 1547:       }
 1548:   }
 1549:   return ($symb,$courseid,$domain,$name,$publicuser);
 1550: }
 1551: 
 1552: 1;
 1553: __END__
 1554: 
 1555: 

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