File:  [LON-CAPA] / loncom / xml / scripttag.pm
Revision 1.134: download - view: text, annotated - select for diffs
Thu Dec 15 19:00:36 2005 UTC (18 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_99_1, HEAD
- <parse> was spewing output in answer mode

    1: # The LearningOnline Network with CAPA
    2: # <script> definiton
    3: #
    4: # $Id: scripttag.pm,v 1.134 2005/12/15 19:00:36 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: 
   29: package Apache::scripttag;
   30: 
   31: use strict;
   32: use Apache::lonnet;
   33: use Apache::style;
   34: 
   35: #Globals
   36: # this used to pass around the standard callsub arguments to a tag func
   37: # so xmlparse can reenter the inner_xmlparse loop.
   38: 
   39: @Apache::scripttag::parser_env = ();
   40: BEGIN {
   41:   &Apache::lonxml::register('Apache::scripttag',
   42: 			    ('script','scriptlib','parserlib','import',
   43: 			     'window','display','storetc','physnet',
   44: 			     'standalone','comment','num','parse','algebra',
   45: 			     'LONCAPA_INTERNAL_TURN_STYLE_ON',
   46: 			     'LONCAPA_INTERNAL_TURN_STYLE_OFF',
   47: 			     'LONCAPA_INTERNAL_LONHTTPD_PORT'));
   48: }
   49: 
   50: sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
   51:     $Apache::lonxml::usestyle=1;
   52:     $Apache::lonxml::style_values='';
   53:     return ('','no');
   54: }
   55: 
   56: sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
   57:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   58:     my $end=&Apache::lonxml::get_param('end',$parstack,$safeeval);
   59:     if (defined($end)) {
   60: 	&Apache::lonxml::end_tag($tagstack,$parstack,$token);
   61:     }
   62:     return ('','no');
   63: }
   64: 
   65: sub start_LONCAPA_INTERNAL_TURN_STYLE_OFF {
   66:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   67:     $Apache::lonxml::usestyle=0;
   68:     my $end=&Apache::lonxml::get_param('end',$parstack,$safeeval);
   69:     if (!$end) {
   70: 	$Apache::lonxml::style_values=$$parstack[-1];
   71: 	$Apache::lonxml::style_end_values=$$parstack[-1];
   72:     } else {
   73: 	$Apache::lonxml::style_values=$Apache::lonxml::style_end_values;
   74: 	$Apache::lonxml::style_end_values='';
   75:     }
   76:     return ('','no');
   77: }
   78: 
   79: sub end_LONCAPA_INTERNAL_TURN_STYLE_OFF {
   80:     return ('','no');
   81: }
   82: 
   83: sub start_LONCAPA_INTERNAL_LONHTTPD_PORT {
   84:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   85:     if ($target eq 'web') {
   86: 	my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
   87: 	if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
   88: 	return '<script type="text/javascript">var lonhttpdport=\''.
   89: 	    $lonhttpdPort.'\';</script>';
   90:     }
   91:     return ('','no');
   92: }
   93: 
   94: sub end_LONCAPA_INTERNAL_LONHTTPD_PORT {
   95:     return ('','no');
   96: }
   97: 
   98: sub start_script {
   99:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  100:   @Apache::scripttag::parser_env = @_;
  101:   my $result='';
  102:   my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
  103:   &Apache::lonxml::debug("found type of $type");
  104:   if ($type eq "loncapa/perl") {
  105:     if ( $target eq "modified" ) {
  106: 	$result=$token->[4].&Apache::edit::modifiedfield('/script',$parser);
  107:     } elsif ( $target eq 'web' || $target eq 'tex' ||
  108: 	      $target eq 'grade' || $target eq 'webgrade' ||
  109: 	      $target eq 'answer' || $target eq 'analyze' ) {
  110: 	my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
  111: 	if (!$Apache::lonxml::default_homework_loaded) {
  112: 	    &Apache::lonxml::default_homework_load($safeeval);
  113: 	}
  114: 	&Apache::run::run($bodytext,$safeeval);
  115: 	if (($target eq 'answer') &&
  116: 	    ($env{'form.answer_output_mode'} ne 'tex') &&
  117: 	    ($Apache::lonhomework::viewgrades == 'F')) {
  118: 	    $Apache::lonxml::evaluate--;
  119: 	    my (undef,undef,$udom,$uname)=&Apache::lonxml::whichuser();
  120: 	    my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
  121: 	    $result.="<script type=\"text/javascript\">
  122: // <![CDATA[
  123:     function LONCAPA_scriptvars_".$uname."_".$udom."_"."$Apache::lonxml::curdepth() {newWindow=open('','new_W','width=500,height=500,scrollbars=1,resizable=yes');newWindow.$windowopen;newWindow.document.writeln('<html><head><title>Script Vars</title></head><body bgcolor=\"#FFFFFF\"><pre>";
  124: 	    my $listing=&Apache::run::dump($target,$safeeval);
  125: 	    $listing=~s/\\/\\\\/g;
  126: 	    $listing=~s/\'/\\\'/g;
  127: 	    $result.=$listing;
  128: 	    $result.= "</pre></body></html>');newWindow.document.close();newWindow.focus()}
  129: // ]]>
  130: </script><a href=\"javascript:LONCAPA_scriptvars_".$uname."_".$udom."_$Apache::lonxml::curdepth();void(0);\">Script Vars</a><br />";
  131: 	}
  132:     } elsif ($target eq "edit" ) {
  133:       #&Apache::run::run($bodytext,$safeeval);
  134:       #$result="<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
  135: 	my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
  136: 	$result=&Apache::edit::tag_start($target,$token,'Script');
  137: 	$result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
  138:     } elsif ($target eq 'meta') {
  139: 	my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
  140:     }
  141:   } else {
  142:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
  143:       if ($target ne "meta" && $target ne 'tex') {
  144: 	  $result = $token->[4];
  145: 	  $result.=$bodytext;
  146:       }
  147:   }
  148:   return $result;
  149: }
  150: 
  151: sub end_script {
  152:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  153:   if ( $target eq "meta" ) { return ''; } 
  154:   my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
  155:   my $result='';
  156:   #other script blocks need to survive
  157:   if ($type ne "loncapa/perl" && $target ne 'tex') {
  158:     return $token->[2];
  159:   } elsif ($target eq 'edit' ) {
  160:     return &Apache::edit::end_table();
  161:   } elsif ($target eq 'answer') {
  162:     $Apache::lonxml::evaluate++;
  163:   }
  164:   return '';
  165: }
  166: 
  167: sub start_display {
  168:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  169:   @Apache::scripttag::parser_env = @_;
  170:   my $result;
  171: 
  172:   if ( $target eq "modified" ) {
  173:       $result=$token->[4].&Apache::edit::modifiedfield("/display",$parser);
  174:   } elsif ( $target eq 'web' || $target eq 'tex' ||
  175: 	    $target eq 'grade' || $target eq 'webgrade' ||
  176: 	    $target eq 'answer' || $target eq 'analyze') {
  177:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
  178:       if (!$Apache::lonxml::default_homework_loaded) {
  179: 	  &Apache::lonxml::default_homework_load($safeeval);
  180:       }
  181:       $result=&Apache::run::run($bodytext,$safeeval);
  182:       if ($target eq 'grade' || $target eq 'answer' ||
  183: 	  $target eq 'analyze') {
  184: 	  # grade/answer/analyxe should produce no output but if we
  185: 	  # are redirecting, the redirecter should know what to do
  186: 	  # with the output
  187: 	  if (!$Apache::lonxml::redirection) { $result=''; }
  188:       }
  189:       $Apache::lonxml::post_evaluate=0;
  190:   } elsif ($target eq "edit" ) {
  191:     my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
  192:     #$result = 
  193:     #  "<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
  194:     #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
  195:     $result=&Apache::edit::tag_start($target,$token,'Script With Display');
  196:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
  197:   } elsif ($target eq 'meta') {
  198:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
  199:   }
  200:   return $result;
  201: }
  202: 
  203: sub end_display {
  204:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  205:   if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
  206:   return '';
  207: }
  208: 
  209: sub start_scriptlib {
  210:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  211:   my $bodytext;
  212:   my $result ='';
  213:   my $error='';
  214: 
  215:   if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
  216:       $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
  217:       $target eq 'analyze') {
  218:     $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
  219:     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
  220: 				     $$parstack[$#$parstack]);
  221:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
  222: 					       $bodytext);
  223:     my $script=&Apache::lonnet::getfile($location);
  224:     if ($script == -1) {
  225:       if ($target eq 'edit') {
  226:         $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
  227:       } else {
  228: 	&Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
  229: 	return "";
  230:       }
  231:     }
  232:     &Apache::run::run($script,$safeeval);
  233:     #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
  234:   }
  235:   if ($target eq "edit" ) {
  236:     $result=
  237:       &Apache::edit::tag_start($target,$token,'New Script Functions').
  238: 	&Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
  239:             &Apache::edit::browse(undef,'textnode').
  240: 	  $error.'</td></tr>'.
  241: 	    &Apache::edit::end_table();
  242:   }
  243:   if ($target eq "modified" ) {
  244:       $result=$token->[4].&Apache::edit::modifiedfield("/scriptlib",$parser);
  245:   }
  246:   return $result;
  247: }
  248: 
  249: sub end_scriptlib {
  250:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  251:   my @result;
  252:   if ($target eq "edit" ) { $result[1]='no'; }
  253:   return @result;
  254: }
  255: 
  256: sub start_parserlib {
  257:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  258:   my $bodytext;
  259:   my $result ="";
  260:   my $error='';
  261:   if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
  262:       $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
  263:       $target eq 'analyze') {
  264:     $bodytext=$$parser[$#$parser]->get_text("/parserlib");
  265:     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
  266: 				     $$parstack[$#$parstack]);
  267:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
  268: 					       $bodytext);
  269:     my $styletext=&Apache::lonnet::getfile($location);
  270:     #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
  271:     if ($styletext == -1) {
  272:       if ($target eq 'edit') {
  273: 	$error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
  274:       } else {
  275: 	&Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
  276: 	return "";
  277:       }
  278:     }
  279:     %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
  280:   }
  281:   if ($target eq "edit" ) {
  282:     $result=
  283:       &Apache::edit::tag_start($target,$token,'New Tag Definitions').
  284: 	&Apache::edit::editline($token->[1],$bodytext,'',40).
  285: 	  $error.'</td></tr>'.
  286: 	    &Apache::edit::end_table();
  287:   }
  288:   if ($target eq "modified" ) {
  289:       $result=$token->[4].&Apache::edit::modifiedfield("/parserlib",$parser);
  290:   }
  291:   return $result;
  292: }
  293: 
  294: sub end_parserlib {
  295:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  296:   my @result;
  297:   if ($target eq "edit" ) { $result[1]='no'; }
  298:   return @result;
  299: }
  300: 
  301: sub start_window {
  302:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  303:     my $result = '';
  304:     if ($target eq 'web') {
  305: 	&Apache::lonxml::startredirection;
  306:     } elsif ($target eq 'tex') {
  307: 	$result = '\unskip\footnote{';
  308:     } elsif ($target eq 'edit') {
  309: 	$result.=&Apache::edit::tag_start($target,$token);
  310: 	$result.=&Apache::edit::text_arg('Text of Link:','linktext',$token,70);
  311: 	$result.=&Apache::edit::text_arg('Height:','height',$token,5);
  312: 	$result.=&Apache::edit::text_arg('Width:','width',$token,5);
  313: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  314:     } elsif ($target eq 'modified') {
  315: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  316: 						     $safeeval,'linktext',
  317: 						     'width','height');
  318: 	if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
  319:     }
  320:     return $result;  
  321: }
  322: 
  323: sub end_window {
  324:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  325:   my $result;
  326:   if ($target eq 'web') {
  327:     my $output=&Apache::lonxml::endredirection;
  328:     $output =~ s/[\n\r]/ /g;
  329: #    $output = &HTML::Entities::encode($output,'<>&"\'');
  330:     $output =~ s/\'/\\\'/g;
  331:     my $linktext= &Apache::lonxml::get_param('linktext',$parstack,$safeeval);
  332:     if (!$linktext) { $linktext='<sup>*</sup>'; }
  333:     my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
  334:     if (!$width) { $width='500'; }
  335:     my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
  336:     if (!$height) { $height='200'; }
  337:     $result = "<script type=\"text/javascript\"> function LONCAPA_newwindow_$Apache::lonxml::curdepth() {newWindow=open('','new_W','width=$width,height=$height,scrollbars=1');newWindow.document.open('text/html','replace');newWindow.document.writeln('<html><head><title>newwindow</title></head><body bgcolor=\"#FFFFFF\"> $output </body></html>');newWindow.document.close();}</script><a href=\"javascript:LONCAPA_newwindow_$Apache::lonxml::curdepth();void(0);\">$linktext</a>";
  338:   } elsif ($target eq 'tex') {
  339:       $result = '}';
  340:   } else {
  341:       $result = '';
  342:   }
  343:   return $result; 
  344: }
  345: 
  346: sub start_import {
  347:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  348:   my $bodytext=$$parser[$#$parser]->get_text("/import");
  349:   my $result ="";
  350: 
  351:   $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
  352: 
  353:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  354:       $target eq 'tex' || $target eq 'analyze' ) {
  355:     # FIXME this probably needs to be smart about construction vs.
  356:     # non construction space.
  357:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
  358:     my $file=&Apache::lonnet::getfile($location);
  359:     if ($file == -1) {
  360:       &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
  361:       return "";
  362:     }
  363: 
  364:     my $dir=$location;
  365:     $dir=~s:/[^/]*$::;
  366:     #  &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
  367:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
  368:     if (!$id) { $id=$Apache::lonxml::curdepth; }
  369:     push(@Apache::inputtags::import,$id);
  370:     push(@Apache::inputtags::importlist,$id);
  371: 
  372: 	&Apache::lonxml::newparser($parser,\$file,$dir);
  373: 
  374:   } elsif ($target eq "edit" ) {
  375:     $result.=&Apache::edit::tag_start($target,$token);
  376:     $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
  377:     $result.=&Apache::edit::browse(undef,'textnode');
  378:     #FIXME this need to convert $bodytext to be a contruction space reference
  379:     #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
  380:     #$result.="Click<a href=\"$location\">here</a> to edit<br />"
  381:   } elsif ($target eq 'modified') {
  382:       $result=$token->[4].&Apache::edit::modifiedfield("/import",$parser);
  383:   } elsif ($target eq 'meta') {
  384:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
  385:     $result.='<import part="'.$Apache::inputtags::part;
  386:     if ($id) {
  387:       $result.='" id="'.$id;
  388:     }
  389:     $result.='">';
  390:     $result.=$bodytext;
  391:     $result.='</import>';
  392:   }
  393:   return $result;
  394: }
  395: 
  396: sub end_import {
  397:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  398:   pop(@Apache::inputtags::import);
  399:   my $result;
  400:   if ($target eq 'edit' ) { $result=&Apache::edit::end_row.
  401: 				&Apache::edit::end_table(); }
  402:   return $result;
  403: }
  404: 
  405: sub start_storetc {
  406:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  407:   my $result = '';
  408:   &Apache::lonxml::startredirection;
  409:   return $result; 
  410: }
  411: 
  412: sub end_storetc {
  413:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  414:     my $result;
  415:     my $output=&Apache::lonxml::endredirection;
  416:     $output =~ s/\"/\&quot\;/g;
  417:     $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
  418:     return $result;
  419: }
  420: 
  421: 
  422: sub start_physnet {
  423:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  424:     my $bodytext = '/adm/includes/physnet.sty';
  425:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
  426:     my $cbistyletext=&Apache::lonnet::getfile($location);
  427: 
  428:     %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
  429:     $$parser['-1']->unget_token($token);
  430: #    if ( defined($$style{'physnet'}) ) {
  431: #        &Apache::lonxml::newparser($parser,\$$style{'physnet'});
  432: #    }
  433:     return "";
  434: }
  435: 
  436: sub end_physnet {
  437:   return '';
  438: }
  439: 
  440: sub start_standalone {
  441:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  442:   my $result='';
  443:   if ($target eq 'web' ) {
  444:     if ( $env{'request.course.id'} ) {
  445:       my $inside = &Apache::lonxml::get_all_text("/standalone",$parser,$style);
  446:     } else {
  447:       $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
  448:     }
  449:   }
  450:   return $result;
  451: }
  452: 
  453: sub end_standalone {
  454:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  455:   my $result='';
  456:   if ($target eq 'web' ) {
  457:     if ( $env{'request.course.id'} ) {
  458:     } else {
  459:       $result='</td></tr></table>';
  460:     }
  461:   }
  462:   return $result;
  463: }
  464: 
  465: sub start_comment {
  466:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  467:   my $result='';
  468:   if ($target eq 'edit') {
  469:     $result=&Apache::edit::tag_start($target,$token);
  470:     my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
  471:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
  472:   } elsif ( $target eq 'modified') {
  473:     $result=$token->[4].&Apache::edit::modifiedfield("/comment",$parser);
  474:   } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
  475: 	    $target eq 'answer' || $target eq 'meta' || $target eq 'analyze') {
  476:     #normally throw away comments
  477:     my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
  478:   }
  479:   return $result;
  480: }
  481: 
  482: sub end_comment {
  483:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  484:   if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
  485:   return '';
  486: }
  487: 
  488: 
  489: sub xmlparse {
  490:   my ($string) = @_;
  491:   &Apache::lonxml::debug("xmlparse recursion starting with $string");
  492:   # Apache::run::evaluate does an 'eval' on the name of the subroutine
  493:   # if it detects something that looks like a subroutine, this ends up calling
  494:   # things without any arguments and since perl is nice enough to pass
  495:   # along the default arguments when you don't explicitly say no arguments
  496:   # if you call &xmlparse, it gets &xmlparse passed as it argument.
  497:   # Same thing soccurs with &chemparse.
  498:   if ($string eq '&xmlparse') { return '&xmlparse'; }
  499:   if ($string eq '&chemparse') { return '&chemparse'; }
  500:   my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
  501:     @Apache::scripttag::parser_env;
  502:   my @parser;
  503:   &Apache::lonxml::newparser(\@parser,\$string);
  504:   &Apache::lonxml::startredirection();
  505:   my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
  506: 					     $parstack,\@parser,
  507: 					     $safeeval,$style);
  508:   $result.=&Apache::lonxml::endredirection();
  509:   &Apache::lonxml::debug("target is $target xmlparse recursion ending with $result");
  510:   return $result;
  511: }
  512: 
  513: sub start_num {
  514:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  515:     my $result = '';
  516:     my $inside = &Apache::lonxml::get_all_text_unbalanced("/num",$parser);
  517:     if ($target eq 'tex' || $target eq 'web') {
  518: 	$inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
  519: 	if (!$Apache::lonxml::default_homework_loaded) {
  520: 	    &Apache::lonxml::default_homework_load($safeeval);
  521: 	}
  522: 	@Apache::scripttag::parser_env = @_;
  523: 	my $format=&Apache::lonxml::get_param('format',$parstack,$safeeval);
  524: 	$result=&Apache::run::run("return &prettyprint(q\0$inside\0,q\0$format\0);",$safeeval);
  525:     }    
  526:     return $result;
  527: }
  528: 
  529: sub end_num {
  530:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  531:     my $result = '';
  532:     return $result;
  533: }
  534: 
  535: sub start_parse {
  536:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  537:     my $result = '';
  538:     if ( $target eq 'web' || $target eq 'tex' ||
  539: 	 $target eq 'grade' || $target eq 'answer' ||
  540: 	 $target eq 'analyze') {
  541: 	my $inside = &Apache::lonxml::get_all_text_unbalanced("/parse",$parser);
  542: 	$inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
  543: 	if (!$Apache::lonxml::default_homework_loaded) {
  544: 	    &Apache::lonxml::default_homework_load($safeeval);
  545: 	}
  546: 	@Apache::scripttag::parser_env = @_;
  547: 	$result=&Apache::run::run("return &xmlparse(q\0$inside\0);",$safeeval);
  548: 	if ($target eq 'grade' || $target eq 'answer' ||
  549: 	    $target eq 'analyze') {
  550: 	    # grade/answer/analyxe should produce no output but if we
  551: 	    # are redirecting, the redirecter should know what to do
  552: 	    # with the output
  553: 	    if (!$Apache::lonxml::redirection) { $result=''; }
  554: 	}
  555:     }
  556:     return $result;
  557: }
  558: 
  559: sub end_parse {
  560:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  561:     my $result = '';
  562:     return $result;
  563: }
  564: 
  565: sub start_algebra {
  566:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  567:     my $result = '';
  568:     if ( $target eq 'web' || $target eq 'tex' ||
  569: 	 $target eq 'grade' || $target eq 'answer' ||
  570: 	 $target eq 'analyze') {
  571: 	my $inside = &Apache::lonxml::get_all_text_unbalanced("/algebra",$parser);
  572: 	$inside = &Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
  573: 	if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
  574: 	    my $style=&Apache::lonxml::get_param('style',$parstack,$safeeval);
  575: 	    $result=&Apache::lontexconvert::algebra($inside,$target,$style);
  576: 	}
  577: 	$Apache::lonxml::post_evaluate=0;
  578:     }
  579:     return $result;
  580: }
  581: 
  582: sub end_algebra {
  583:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  584:     my $result = '';
  585:     return $result;
  586: }
  587: 
  588: 1;
  589: __END__

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