File:  [LON-CAPA] / loncom / xml / lonxml.pm
Revision 1.275: download - view: text, annotated - select for diffs
Thu Sep 11 22:37:54 2003 UTC (20 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- add submissions link to discussion postings
- new sumbroutine &submlink() to easily insert submissions links in other desired locales

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

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