File:  [LON-CAPA] / loncom / xml / scripttag.pm
Revision 1.135: download - view: text, annotated - select for diffs
Thu Mar 23 23:47:56 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- start_page
- increasing support for webgrade

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

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