Annotation of loncom/xml/scripttag.pm, revision 1.133

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # <script> definiton
1.58      www         3: #
1.133   ! albertel    4: # $Id: scripttag.pm,v 1.132 2005/09/29 19:15:47 albertel Exp $
1.58      www         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: #
1.116     www        28: 
1.47      albertel   29: package Apache::scripttag;
1.1       albertel   30: 
                     31: use strict;
1.3       albertel   32: use Apache::lonnet;
1.42      sakharuk   33: use Apache::style;
1.1       albertel   34: 
1.47      albertel   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 = ();
1.61      harris41   40: BEGIN {
1.62      albertel   41:   &Apache::lonxml::register('Apache::scripttag',
                     42: 			    ('script','scriptlib','parserlib','import',
                     43: 			     'window','display','storetc','physnet',
1.123     albertel   44: 			     'standalone','comment','num','parse','algebra',
1.86      albertel   45: 			     'LONCAPA_INTERNAL_TURN_STYLE_ON',
1.100     albertel   46: 			     'LONCAPA_INTERNAL_TURN_STYLE_OFF',
1.86      albertel   47: 			     'LONCAPA_INTERNAL_LONHTTPD_PORT'));
1.81      albertel   48: }
                     49: 
                     50: sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
                     51:     $Apache::lonxml::usestyle=1;
1.89      albertel   52:     $Apache::lonxml::style_values='';
1.81      albertel   53:     return ('','no');
                     54: }
                     55: 
                     56: sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
1.91      albertel   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:     }
1.100     albertel   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 {
1.86      albertel   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 {
1.81      albertel   95:     return ('','no');
1.1       albertel   96: }
                     97: 
                     98: sub start_script {
1.40      albertel   99:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47      albertel  100:   @Apache::scripttag::parser_env = @_;
1.24      albertel  101:   my $result='';
1.39      albertel  102:   my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
                    103:   &Apache::lonxml::debug("found type of $type");
1.17      albertel  104:   if ($type eq "loncapa/perl") {
                    105:     if ( $target eq "modified" ) {
1.103     albertel  106: 	$result=$token->[4].&Apache::edit::modifiedfield('/script',$parser);
1.54      albertel  107:     } elsif ( $target eq 'web' || $target eq 'tex' ||
1.130     albertel  108: 	      $target eq 'grade' || $target eq 'webgrade' ||
                    109: 	      $target eq 'answer' || $target eq 'analyze' ) {
1.107     albertel  110: 	my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.79      albertel  111: 	if (!$Apache::lonxml::default_homework_loaded) {
                    112: 	    &Apache::lonxml::default_homework_load($safeeval);
                    113: 	}
                    114: 	&Apache::run::run($bodytext,$safeeval);
1.88      albertel  115: 	if (($target eq 'answer') &&
1.126     albertel  116: 	    ($env{'form.answer_output_mode'} ne 'tex') &&
1.88      albertel  117: 	    ($Apache::lonhomework::viewgrades == 'F')) {
1.79      albertel  118: 	    $Apache::lonxml::evaluate--;
1.109     albertel  119: 	    my (undef,undef,$udom,$uname)=&Apache::lonxml::whichuser();
1.118     www       120: 	    my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
1.121     albertel  121: 	    $result.="<script type=\"text/javascript\">
1.124     albertel  122: // <![CDATA[
1.121     albertel  123:     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('<html><head><title>Script Vars</title></head><body bgcolor=\"#FFFFFF\"><pre>";
1.99      albertel  124: 	    my $listing=&Apache::run::dump($target,$safeeval);
1.128     albertel  125: 	    $listing=~s/\\/\\\\/g;
1.99      albertel  126: 	    $listing=~s/\'/\\\'/g;
1.79      albertel  127: 	    $result.=$listing;
1.127     albertel  128: 	    $result.= "</pre></body></html>');newWindow.document.close();newWindow.focus()}
1.124     albertel  129: // ]]>
1.121     albertel  130: </script><a href=\"javascript:LONCAPA_scriptvars_".$uname."_".$udom."_$Apache::lonxml::curdepth();void(0);\">Script Vars</a><br />";
1.79      albertel  131: 	}
1.28      albertel  132:     } elsif ($target eq "edit" ) {
1.41      albertel  133:       #&Apache::run::run($bodytext,$safeeval);
                    134:       #$result="<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
1.107     albertel  135: 	my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.103     albertel  136: 	$result=&Apache::edit::tag_start($target,$token,'Script');
                    137: 	$result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
1.107     albertel  138:     } elsif ($target eq 'meta') {
                    139: 	my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.17      albertel  140:     }
                    141:   } else {
1.108     matthew   142:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.115     albertel  143:       if ($target ne "meta" && $target ne 'tex') {
1.112     albertel  144: 	  $result = $token->[4];
                    145: 	  $result.=$bodytext;
                    146:       }
1.13      albertel  147:   }
1.24      albertel  148:   return $result;
1.17      albertel  149: }
1.13      albertel  150: 
1.17      albertel  151: sub end_script {
1.40      albertel  152:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.28      albertel  153:   if ( $target eq "meta" ) { return ''; } 
1.39      albertel  154:   my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.29      albertel  155:   my $result='';
                    156:   #other script blocks need to survive
1.115     albertel  157:   if ($type ne "loncapa/perl" && $target ne 'tex') {
1.53      albertel  158:     return $token->[2];
                    159:   } elsif ($target eq 'edit' ) {
                    160:     return &Apache::edit::end_table();
1.78      albertel  161:   } elsif ($target eq 'answer') {
1.53      albertel  162:     $Apache::lonxml::evaluate++;
                    163:   }
1.28      albertel  164:   return '';
1.24      albertel  165: }
                    166: 
                    167: sub start_display {
1.40      albertel  168:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.119     albertel  169:   @Apache::scripttag::parser_env = @_;
1.48      albertel  170:   my $result;
1.39      albertel  171: 
1.24      albertel  172:   if ( $target eq "modified" ) {
1.103     albertel  173:       $result=$token->[4].&Apache::edit::modifiedfield("/display",$parser);
1.54      albertel  174:   } elsif ( $target eq 'web' || $target eq 'tex' ||
1.130     albertel  175: 	    $target eq 'grade' || $target eq 'webgrade' ||
                    176: 	    $target eq 'answer' || $target eq 'analyze') {
1.107     albertel  177:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.80      albertel  178:       if (!$Apache::lonxml::default_homework_loaded) {
                    179: 	  &Apache::lonxml::default_homework_load($safeeval);
                    180:       }
                    181:       $result=&Apache::run::run($bodytext,$safeeval);
                    182:       if ($target eq 'grade' || $target eq 'answer' ||
                    183: 	  $target eq 'analyze') {
1.114     albertel  184: 	  # grade/answer/analyxe should produce no output but if we
                    185: 	  # are redirecting, the redirecter should know what to do
                    186: 	  # with the output
                    187: 	  if (!$Apache::lonxml::redirection) { $result=''; }
1.80      albertel  188:       }
1.101     albertel  189:       $Apache::lonxml::post_evaluate=0;
1.48      albertel  190:   } elsif ($target eq "edit" ) {
1.110     albertel  191:     my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.48      albertel  192:     #$result = 
                    193:     #  "<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
                    194:     #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
                    195:     $result=&Apache::edit::tag_start($target,$token,'Script With Display');
1.77      albertel  196:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
1.107     albertel  197:   } elsif ($target eq 'meta') {
                    198:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.24      albertel  199:   }
                    200:   return $result;
                    201: }
                    202: 
                    203: sub end_display {
1.48      albertel  204:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    205:   if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
                    206:   return '';
1.1       albertel  207: }
1.3       albertel  208: 
                    209: sub start_scriptlib {
1.40      albertel  210:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37      albertel  211:   my $bodytext;
                    212:   my $result ='';
                    213:   my $error='';
                    214: 
1.106     albertel  215:   if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
                    216:       $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
                    217:       $target eq 'analyze') {
1.37      albertel  218:     $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
                    219:     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
                    220: 				     $$parstack[$#$parstack]);
                    221:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
                    222: 					       $bodytext);
                    223:     my $script=&Apache::lonnet::getfile($location);
                    224:     if ($script == -1) {
                    225:       if ($target eq 'edit') {
                    226:         $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
                    227:       } else {
                    228: 	&Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
                    229: 	return "";
                    230:       }
                    231:     }
                    232:     &Apache::run::run($script,$safeeval);
                    233:     #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
1.18      albertel  234:   }
1.13      albertel  235:   if ($target eq "edit" ) {
1.37      albertel  236:     $result=
1.49      albertel  237:       &Apache::edit::tag_start($target,$token,'New Script Functions').
1.83      matthew   238: 	&Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
                    239:             &Apache::edit::browse(undef,'textnode').
1.49      albertel  240: 	  $error.'</td></tr>'.
                    241: 	    &Apache::edit::end_table();
1.37      albertel  242:   }
                    243:   if ($target eq "modified" ) {
1.103     albertel  244:       $result=$token->[4].&Apache::edit::modifiedfield("/scriptlib",$parser);
1.3       albertel  245:   }
                    246:   return $result;
                    247: }
                    248: 
1.37      albertel  249: sub end_scriptlib {
1.40      albertel  250:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49      albertel  251:   my @result;
                    252:   if ($target eq "edit" ) { $result[1]='no'; }
                    253:   return @result;
1.37      albertel  254: }
1.4       albertel  255: 
                    256: sub start_parserlib {
1.40      albertel  257:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37      albertel  258:   my $bodytext;
1.7       albertel  259:   my $result ="";
1.37      albertel  260:   my $error='';
1.106     albertel  261:   if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
                    262:       $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
                    263:       $target eq 'analyze') {
1.37      albertel  264:     $bodytext=$$parser[$#$parser]->get_text("/parserlib");
                    265:     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
                    266: 				     $$parstack[$#$parstack]);
                    267:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
                    268: 					       $bodytext);
                    269:     my $styletext=&Apache::lonnet::getfile($location);
                    270:     #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
                    271:     if ($styletext == -1) {
                    272:       if ($target eq 'edit') {
                    273: 	$error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
                    274:       } else {
                    275: 	&Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
                    276: 	return "";
                    277:       }
                    278:     }
                    279:     %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
1.18      albertel  280:   }
1.13      albertel  281:   if ($target eq "edit" ) {
1.37      albertel  282:     $result=
1.49      albertel  283:       &Apache::edit::tag_start($target,$token,'New Tag Definitions').
1.68      albertel  284: 	&Apache::edit::editline($token->[1],$bodytext,'',40).
1.49      albertel  285: 	  $error.'</td></tr>'.
                    286: 	    &Apache::edit::end_table();
1.37      albertel  287:   }
                    288:   if ($target eq "modified" ) {
1.103     albertel  289:       $result=$token->[4].&Apache::edit::modifiedfield("/parserlib",$parser);
1.7       albertel  290:   }
                    291:   return $result;
1.4       albertel  292: }
                    293: 
                    294: sub end_parserlib {
1.40      albertel  295:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49      albertel  296:   my @result;
                    297:   if ($target eq "edit" ) { $result[1]='no'; }
                    298:   return @result;
1.6       albertel  299: }
                    300: 
1.30      sakharuk  301: sub start_window {
1.105     albertel  302:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    303:     my $result = '';
                    304:     if ($target eq 'web') {
                    305: 	&Apache::lonxml::startredirection;
                    306:     } elsif ($target eq 'tex') {
                    307: 	$result = '\unskip\footnote{';
                    308:     } elsif ($target eq 'edit') {
                    309: 	$result.=&Apache::edit::tag_start($target,$token);
                    310: 	$result.=&Apache::edit::text_arg('Text of Link:','linktext',$token,70);
1.131     albertel  311: 	$result.=&Apache::edit::text_arg('Height:','height',$token,5);
                    312: 	$result.=&Apache::edit::text_arg('Width:','width',$token,5);
1.105     albertel  313: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    314:     } elsif ($target eq 'modified') {
                    315: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.129     raeburn   316: 						     $safeeval,'linktext',
1.105     albertel  317: 						     'width','height');
                    318: 	if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
                    319:     }
                    320:     return $result;  
1.19      sakharuk  321: }
                    322: 
1.30      sakharuk  323: sub end_window {
1.40      albertel  324:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30      sakharuk  325:   my $result;
1.31      albertel  326:   if ($target eq 'web') {
1.34      albertel  327:     my $output=&Apache::lonxml::endredirection;
1.97      albertel  328:     $output =~ s/[\n\r]/ /g;
1.98      albertel  329: #    $output = &HTML::Entities::encode($output,'<>&"\'');
                    330:     $output =~ s/\'/\\\'/g;
1.92      albertel  331:     my $linktext= &Apache::lonxml::get_param('linktext',$parstack,$safeeval);
                    332:     if (!$linktext) { $linktext='<sup>*</sup>'; }
                    333:     my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
                    334:     if (!$width) { $width='500'; }
                    335:     my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
                    336:     if (!$height) { $height='200'; }
1.98      albertel  337:     $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('<html><head><title>newwindow</title></head><body bgcolor=\"#FFFFFF\"> $output </body></html>');newWindow.document.close();}</script><a href=\"javascript:LONCAPA_newwindow_$Apache::lonxml::curdepth();void(0);\">$linktext</a>";
1.35      sakharuk  338:   } elsif ($target eq 'tex') {
                    339:       $result = '}';
1.30      sakharuk  340:   } else {
1.35      sakharuk  341:       $result = '';
1.30      sakharuk  342:   }
1.20      sakharuk  343:   return $result; 
1.19      sakharuk  344: }
                    345: 
1.6       albertel  346: sub start_import {
1.40      albertel  347:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31      albertel  348:   my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7       albertel  349:   my $result ="";
1.13      albertel  350: 
                    351:   $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.14      albertel  352: 
1.78      albertel  353:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    354:       $target eq 'tex' || $target eq 'analyze' ) {
1.46      albertel  355:     # FIXME this probably needs to be smart about construction vs.
                    356:     # non construction space.
                    357:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
                    358:     my $file=&Apache::lonnet::getfile($location);
                    359:     if ($file == -1) {
                    360:       &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
                    361:       return "";
                    362:     }
1.13      albertel  363: 
1.46      albertel  364:     my $dir=$location;
                    365:     $dir=~s:/[^/]*$::;
                    366:     #  &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
1.57      albertel  367:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                    368:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                    369:     push(@Apache::inputtags::import,$id);
1.90      albertel  370:     push(@Apache::inputtags::importlist,$id);
1.87      sakharuk  371: 
                    372: 	&Apache::lonxml::newparser($parser,\$file,$dir);
                    373: 
1.56      albertel  374:   } elsif ($target eq "edit" ) {
1.46      albertel  375:     $result.=&Apache::edit::tag_start($target,$token);
1.68      albertel  376:     $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
1.83      matthew   377:     $result.=&Apache::edit::browse(undef,'textnode');
1.46      albertel  378:     #FIXME this need to convert $bodytext to be a contruction space reference
                    379:     #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
                    380:     #$result.="Click<a href=\"$location\">here</a> to edit<br />"
1.56      albertel  381:   } elsif ($target eq 'modified') {
1.103     albertel  382:       $result=$token->[4].&Apache::edit::modifiedfield("/import",$parser);
1.56      albertel  383:   } elsif ($target eq 'meta') {
1.57      albertel  384:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                    385:     $result.='<import part="'.$Apache::inputtags::part;
                    386:     if ($id) {
                    387:       $result.='" id="'.$id;
                    388:     }
                    389:     $result.='">';
1.56      albertel  390:     $result.=$bodytext;
                    391:     $result.='</import>';
1.46      albertel  392:   }
                    393:   return $result;
1.6       albertel  394: }
                    395: 
                    396: sub end_import {
1.69      albertel  397:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.57      albertel  398:   pop(@Apache::inputtags::import);
1.69      albertel  399:   my $result;
1.120     albertel  400:   if ($target eq 'edit' ) { $result=&Apache::edit::end_row.
                    401: 				&Apache::edit::end_table(); }
1.69      albertel  402:   return $result;
1.1       albertel  403: }
1.42      sakharuk  404: 
                    405: sub start_storetc {
1.43      albertel  406:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42      sakharuk  407:   my $result = '';
                    408:   &Apache::lonxml::startredirection;
                    409:   return $result; 
                    410: }
                    411: 
                    412: sub end_storetc {
1.43      albertel  413:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42      sakharuk  414:     my $result;
                    415:     my $output=&Apache::lonxml::endredirection;
                    416:     $output =~ s/\"/\&quot\;/g;
1.52      albertel  417:     $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
                    418:     return $result;
1.42      sakharuk  419: }
                    420: 
                    421: 
                    422: sub start_physnet {
1.45      sakharuk  423:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.50      www       424:     my $bodytext = '/adm/includes/physnet.sty';
1.45      sakharuk  425:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
                    426:     my $cbistyletext=&Apache::lonnet::getfile($location);
1.42      sakharuk  427: 
1.45      sakharuk  428:     %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
1.59      albertel  429:     $$parser['-1']->unget_token($token);
                    430: #    if ( defined($$style{'physnet'}) ) {
                    431: #        &Apache::lonxml::newparser($parser,\$$style{'physnet'});
                    432: #    }
1.45      sakharuk  433:     return "";
                    434: }
1.42      sakharuk  435: 
1.45      sakharuk  436: sub end_physnet {
1.47      albertel  437:   return '';
1.42      sakharuk  438: }
1.62      albertel  439: 
                    440: sub start_standalone {
                    441:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.75      albertel  442:   my $result='';
                    443:   if ($target eq 'web' ) {
1.126     albertel  444:     if ( $env{'request.course.id'} ) {
1.133   ! albertel  445:       my $inside = &Apache::lonxml::get_all_text("/standalone",$parser,$style);
1.75      albertel  446:     } else {
                    447:       $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
                    448:     }
1.62      albertel  449:   }
1.75      albertel  450:   return $result;
1.62      albertel  451: }
                    452: 
                    453: sub end_standalone {
1.75      albertel  454:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    455:   my $result='';
                    456:   if ($target eq 'web' ) {
1.126     albertel  457:     if ( $env{'request.course.id'} ) {
1.75      albertel  458:     } else {
                    459:       $result='</td></tr></table>';
                    460:     }
                    461:   }
                    462:   return $result;
1.74      albertel  463: }
                    464: 
                    465: sub start_comment {
                    466:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    467:   my $result='';
                    468:   if ($target eq 'edit') {
                    469:     $result=&Apache::edit::tag_start($target,$token);
1.133   ! albertel  470:     my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
1.77      albertel  471:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
1.74      albertel  472:   } elsif ( $target eq 'modified') {
1.103     albertel  473:     $result=$token->[4].&Apache::edit::modifiedfield("/comment",$parser);
1.78      albertel  474:   } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
                    475: 	    $target eq 'answer' || $target eq 'meta' || $target eq 'analyze') {
1.74      albertel  476:     #normally throw away comments
1.133   ! albertel  477:     my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
1.74      albertel  478:   }
                    479:   return $result;
                    480: }
                    481: 
                    482: sub end_comment {
                    483:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    484:   if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
1.62      albertel  485:   return '';
                    486: }
                    487: 
1.42      sakharuk  488: 
1.47      albertel  489: sub xmlparse {
                    490:   my ($string) = @_;
1.111     albertel  491:   &Apache::lonxml::debug("xmlparse recursion starting with $string");
1.113     albertel  492:   # Apache::run::evaluate does an 'eval' on the name of the subroutine
                    493:   # if it detects something that looks like a subroutine, this ends up calling
                    494:   # things without any arguments and since perl is nice enough to pass
                    495:   # along the default arguments when you don't explicitly say no arguments
                    496:   # if you call &xmlparse, it gets &xmlparse passed as it argument.
                    497:   # Same thing soccurs with &chemparse.
1.111     albertel  498:   if ($string eq '&xmlparse') { return '&xmlparse'; }
1.113     albertel  499:   if ($string eq '&chemparse') { return '&chemparse'; }
1.47      albertel  500:   my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
                    501:     @Apache::scripttag::parser_env;
                    502:   my @parser;
                    503:   &Apache::lonxml::newparser(\@parser,\$string);
1.132     albertel  504:   &Apache::lonxml::startredirection();
1.47      albertel  505:   my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
                    506: 					     $parstack,\@parser,
                    507: 					     $safeeval,$style);
1.132     albertel  508:   $result.=&Apache::lonxml::endredirection();
1.122     albertel  509:   &Apache::lonxml::debug("target is $target xmlparse recursion ending with $result");
1.47      albertel  510:   return $result;
                    511: }
1.3       albertel  512: 
1.122     albertel  513: sub start_num {
                    514:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
                    515:     my $result = '';
                    516:     my $inside = &Apache::lonxml::get_all_text_unbalanced("/num",$parser);
                    517:     if ($target eq 'tex' || $target eq 'web') {
                    518: 	$inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
                    519: 	if (!$Apache::lonxml::default_homework_loaded) {
                    520: 	    &Apache::lonxml::default_homework_load($safeeval);
                    521: 	}
                    522: 	@Apache::scripttag::parser_env = @_;
                    523: 	my $format=&Apache::lonxml::get_param('format',$parstack,$safeeval);
                    524: 	$result=&Apache::run::run("return &prettyprint(q\0$inside\0,q\0$format\0);",$safeeval);
                    525:     }    
                    526:     return $result;
                    527: }
                    528: 
                    529: sub end_num {
                    530:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
                    531:     my $result = '';
                    532:     return $result;
                    533: }
                    534: 
                    535: sub start_parse {
                    536:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
                    537:     my $result = '';
                    538:     if ( $target eq 'web' || $target eq 'tex' ||
                    539: 	 $target eq 'grade' || $target eq 'answer' ||
                    540: 	 $target eq 'analyze') {
                    541: 	my $inside = &Apache::lonxml::get_all_text_unbalanced("/parse",$parser);
                    542: 	$inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
                    543: 	if (!$Apache::lonxml::default_homework_loaded) {
                    544: 	    &Apache::lonxml::default_homework_load($safeeval);
                    545: 	}
                    546: 	@Apache::scripttag::parser_env = @_;
                    547: 	$result=&Apache::run::run("return &xmlparse(q\0$inside\0);",$safeeval);
                    548:     }
                    549:     return $result;
                    550: }
                    551: 
                    552: sub end_parse {
                    553:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
                    554:     my $result = '';
                    555:     return $result;
                    556: }
1.123     albertel  557: 
                    558: sub start_algebra {
                    559:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
                    560:     my $result = '';
                    561:     if ( $target eq 'web' || $target eq 'tex' ||
                    562: 	 $target eq 'grade' || $target eq 'answer' ||
                    563: 	 $target eq 'analyze') {
                    564: 	my $inside = &Apache::lonxml::get_all_text_unbalanced("/algebra",$parser);
                    565: 	$inside = &Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
                    566: 	if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.125     albertel  567: 	    my $style=&Apache::lonxml::get_param('style',$parstack,$safeeval);
                    568: 	    $result=&Apache::lontexconvert::algebra($inside,$target,$style);
1.123     albertel  569: 	}
                    570: 	$Apache::lonxml::post_evaluate=0;
                    571:     }
                    572:     return $result;
                    573: }
                    574: 
                    575: sub end_algebra {
                    576:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
                    577:     my $result = '';
                    578:     return $result;
                    579: }
                    580: 
1.1       albertel  581: 1;
                    582: __END__

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