File:  [LON-CAPA] / loncom / xml / scripttag.pm
Revision 1.143: download - view: text, annotated - select for diffs
Thu Aug 30 22:56:43 2007 UTC (16 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_2_5_X, version_2_5_2, version_2_5_1, HEAD
- eliminating some other location that access lonhttpurl directly
- switch remote control to note and use needed protocol for server

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

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