File:  [LON-CAPA] / loncom / xml / scripttag.pm
Revision 1.141: download - view: text, annotated - select for diffs
Mon Jun 11 20:52:40 2007 UTC (17 years ago) by albertel
Branches: MAIN
CVS tags: version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, HEAD
- <while> tag was mishandling the grade/answer/analyze modes when displayed output was generated
- moving script var generation out-of main result mechanism and move it to an out of the way location the xml parser handles readding

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

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