File:  [LON-CAPA] / loncom / xml / scripttag.pm
Revision 1.147: download - view: text, annotated - select for diffs
Sat Nov 17 01:51:11 2007 UTC (16 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_99_1, version_2_5_99_0, HEAD
- BUG#5523 - close then open the window so the correct size is applied

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

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