File:  [LON-CAPA] / loncom / xml / scripttag.pm
Revision 1.140: download - view: text, annotated - select for diffs
Tue Jan 23 21:28:41 2007 UTC (17 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: version_2_4_0, version_2_3_99_0, HEAD
- js doesn't like - or . in function names

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

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