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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # <script> definiton
1.58      www         3: #
1.118   ! www         4: # $Id: scripttag.pm,v 1.117 2004/09/28 20:40:05 www 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.81      albertel   44: 			     'standalone','comment',
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.78      albertel  108: 	      $target eq 'grade' || $target eq 'answer' ||
                    109: 	      $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') &&
                    116: 	    ($ENV{'form.answer_output_mode'} ne 'tex') &&
                    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();
        !           121: 	    $result.="<script type=\"text/javascript\"> 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  122: 	    my $listing=&Apache::run::dump($target,$safeeval);
                    123: 	    $listing=~s/\'/\\\'/g;
                    124: 	    $listing=~s/\n/\\n/g;
                    125: 	    $listing=~s/\r/\\r/g;
1.79      albertel  126: 	    $result.=$listing;
1.109     albertel  127: 	    $result.= "</pre></body></html>');newWindow.document.close();}</script><a href=\"javascript:LONCAPA_scriptvars_".$uname."_".$udom."_$Apache::lonxml::curdepth();void(0);\">Script Vars</a><br />";
1.79      albertel  128: 	}
1.28      albertel  129:     } elsif ($target eq "edit" ) {
1.41      albertel  130:       #&Apache::run::run($bodytext,$safeeval);
                    131:       #$result="<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
1.107     albertel  132: 	my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.103     albertel  133: 	$result=&Apache::edit::tag_start($target,$token,'Script');
                    134: 	$result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
1.107     albertel  135:     } elsif ($target eq 'meta') {
                    136: 	my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.17      albertel  137:     }
                    138:   } else {
1.108     matthew   139:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.115     albertel  140:       if ($target ne "meta" && $target ne 'tex') {
1.112     albertel  141: 	  $result = $token->[4];
                    142: 	  $result.=$bodytext;
                    143:       }
1.13      albertel  144:   }
1.24      albertel  145:   return $result;
1.17      albertel  146: }
1.13      albertel  147: 
1.17      albertel  148: sub end_script {
1.40      albertel  149:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.28      albertel  150:   if ( $target eq "meta" ) { return ''; } 
1.39      albertel  151:   my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.29      albertel  152:   my $result='';
                    153:   #other script blocks need to survive
1.115     albertel  154:   if ($type ne "loncapa/perl" && $target ne 'tex') {
1.53      albertel  155:     return $token->[2];
                    156:   } elsif ($target eq 'edit' ) {
                    157:     return &Apache::edit::end_table();
1.78      albertel  158:   } elsif ($target eq 'answer') {
1.53      albertel  159:     $Apache::lonxml::evaluate++;
                    160:   }
1.28      albertel  161:   return '';
1.24      albertel  162: }
                    163: 
                    164: sub start_display {
1.40      albertel  165:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.39      albertel  166: 
1.48      albertel  167:   my $result;
1.39      albertel  168: 
1.24      albertel  169:   if ( $target eq "modified" ) {
1.103     albertel  170:       $result=$token->[4].&Apache::edit::modifiedfield("/display",$parser);
1.54      albertel  171:   } elsif ( $target eq 'web' || $target eq 'tex' ||
1.78      albertel  172: 	    $target eq 'grade' || $target eq 'answer' ||
                    173: 	      $target eq 'analyze') {
1.107     albertel  174:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.80      albertel  175:       if (!$Apache::lonxml::default_homework_loaded) {
                    176: 	  &Apache::lonxml::default_homework_load($safeeval);
                    177:       }
                    178:       $result=&Apache::run::run($bodytext,$safeeval);
                    179:       if ($target eq 'grade' || $target eq 'answer' ||
                    180: 	  $target eq 'analyze') {
1.114     albertel  181: 	  # grade/answer/analyxe should produce no output but if we
                    182: 	  # are redirecting, the redirecter should know what to do
                    183: 	  # with the output
                    184: 	  if (!$Apache::lonxml::redirection) { $result=''; }
1.80      albertel  185:       }
1.101     albertel  186:       $Apache::lonxml::post_evaluate=0;
1.48      albertel  187:   } elsif ($target eq "edit" ) {
1.110     albertel  188:     my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.48      albertel  189:     #$result = 
                    190:     #  "<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
                    191:     #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
                    192:     $result=&Apache::edit::tag_start($target,$token,'Script With Display');
1.77      albertel  193:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
1.107     albertel  194:   } elsif ($target eq 'meta') {
                    195:       my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.24      albertel  196:   }
                    197:   return $result;
                    198: }
                    199: 
                    200: sub end_display {
1.48      albertel  201:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    202:   if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
                    203:   return '';
1.1       albertel  204: }
1.3       albertel  205: 
                    206: sub start_scriptlib {
1.40      albertel  207:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37      albertel  208:   my $bodytext;
                    209:   my $result ='';
                    210:   my $error='';
                    211: 
1.106     albertel  212:   if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
                    213:       $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
                    214:       $target eq 'analyze') {
1.37      albertel  215:     $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
                    216:     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
                    217: 				     $$parstack[$#$parstack]);
                    218:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
                    219: 					       $bodytext);
                    220:     my $script=&Apache::lonnet::getfile($location);
                    221:     if ($script == -1) {
                    222:       if ($target eq 'edit') {
                    223:         $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
                    224:       } else {
                    225: 	&Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
                    226: 	return "";
                    227:       }
                    228:     }
                    229:     &Apache::run::run($script,$safeeval);
                    230:     #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
1.18      albertel  231:   }
1.13      albertel  232:   if ($target eq "edit" ) {
1.37      albertel  233:     $result=
1.49      albertel  234:       &Apache::edit::tag_start($target,$token,'New Script Functions').
1.83      matthew   235: 	&Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
                    236:             &Apache::edit::browse(undef,'textnode').
1.49      albertel  237: 	  $error.'</td></tr>'.
                    238: 	    &Apache::edit::end_table();
1.37      albertel  239:   }
                    240:   if ($target eq "modified" ) {
1.103     albertel  241:       $result=$token->[4].&Apache::edit::modifiedfield("/scriptlib",$parser);
1.3       albertel  242:   }
                    243:   return $result;
                    244: }
                    245: 
1.37      albertel  246: sub end_scriptlib {
1.40      albertel  247:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49      albertel  248:   my @result;
                    249:   if ($target eq "edit" ) { $result[1]='no'; }
                    250:   return @result;
1.37      albertel  251: }
1.4       albertel  252: 
                    253: sub start_parserlib {
1.40      albertel  254:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37      albertel  255:   my $bodytext;
1.7       albertel  256:   my $result ="";
1.37      albertel  257:   my $error='';
1.106     albertel  258:   if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
                    259:       $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
                    260:       $target eq 'analyze') {
1.37      albertel  261:     $bodytext=$$parser[$#$parser]->get_text("/parserlib");
                    262:     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
                    263: 				     $$parstack[$#$parstack]);
                    264:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
                    265: 					       $bodytext);
                    266:     my $styletext=&Apache::lonnet::getfile($location);
                    267:     #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
                    268:     if ($styletext == -1) {
                    269:       if ($target eq 'edit') {
                    270: 	$error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
                    271:       } else {
                    272: 	&Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
                    273: 	return "";
                    274:       }
                    275:     }
                    276:     %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
1.18      albertel  277:   }
1.13      albertel  278:   if ($target eq "edit" ) {
1.37      albertel  279:     $result=
1.49      albertel  280:       &Apache::edit::tag_start($target,$token,'New Tag Definitions').
1.68      albertel  281: 	&Apache::edit::editline($token->[1],$bodytext,'',40).
1.49      albertel  282: 	  $error.'</td></tr>'.
                    283: 	    &Apache::edit::end_table();
1.37      albertel  284:   }
                    285:   if ($target eq "modified" ) {
1.103     albertel  286:       $result=$token->[4].&Apache::edit::modifiedfield("/parserlib",$parser);
1.7       albertel  287:   }
                    288:   return $result;
1.4       albertel  289: }
                    290: 
                    291: sub end_parserlib {
1.40      albertel  292:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49      albertel  293:   my @result;
                    294:   if ($target eq "edit" ) { $result[1]='no'; }
                    295:   return @result;
1.6       albertel  296: }
                    297: 
1.30      sakharuk  298: sub start_window {
1.105     albertel  299:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    300:     my $result = '';
                    301:     if ($target eq 'web') {
                    302: 	&Apache::lonxml::startredirection;
                    303:     } elsif ($target eq 'tex') {
                    304: 	$result = '\unskip\footnote{';
                    305:     } elsif ($target eq 'edit') {
                    306: 	$result.=&Apache::edit::tag_start($target,$token);
                    307: 	$result.=&Apache::edit::text_arg('Text of Link:','linktext',$token,70);
                    308: 	$result.=&Apache::edit::text_arg('Height:','width',$token,5);
                    309: 	$result.=&Apache::edit::text_arg('Width:','height',$token,5);
                    310: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    311:     } elsif ($target eq 'modified') {
                    312: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    313: 						     $safeeval,'linttext',
                    314: 						     'width','height');
                    315: 	if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
                    316:     }
                    317:     return $result;  
1.19      sakharuk  318: }
                    319: 
1.30      sakharuk  320: sub end_window {
1.40      albertel  321:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30      sakharuk  322:   my $result;
1.31      albertel  323:   if ($target eq 'web') {
1.34      albertel  324:     my $output=&Apache::lonxml::endredirection;
1.97      albertel  325:     $output =~ s/[\n\r]/ /g;
1.98      albertel  326: #    $output = &HTML::Entities::encode($output,'<>&"\'');
                    327:     $output =~ s/\'/\\\'/g;
1.92      albertel  328:     my $linktext= &Apache::lonxml::get_param('linktext',$parstack,$safeeval);
                    329:     if (!$linktext) { $linktext='<sup>*</sup>'; }
                    330:     my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
                    331:     if (!$width) { $width='500'; }
                    332:     my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
                    333:     if (!$height) { $height='200'; }
1.98      albertel  334:     $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  335:   } elsif ($target eq 'tex') {
                    336:       $result = '}';
1.30      sakharuk  337:   } else {
1.35      sakharuk  338:       $result = '';
1.30      sakharuk  339:   }
1.20      sakharuk  340:   return $result; 
1.19      sakharuk  341: }
                    342: 
1.6       albertel  343: sub start_import {
1.40      albertel  344:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31      albertel  345:   my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7       albertel  346:   my $result ="";
1.13      albertel  347: 
                    348:   $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.14      albertel  349: 
1.78      albertel  350:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    351:       $target eq 'tex' || $target eq 'analyze' ) {
1.46      albertel  352:     # FIXME this probably needs to be smart about construction vs.
                    353:     # non construction space.
                    354:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
                    355:     my $file=&Apache::lonnet::getfile($location);
                    356:     if ($file == -1) {
                    357:       &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
                    358:       return "";
                    359:     }
1.13      albertel  360: 
1.46      albertel  361:     my $dir=$location;
                    362:     $dir=~s:/[^/]*$::;
                    363:     #  &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
1.57      albertel  364:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                    365:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                    366:     push(@Apache::inputtags::import,$id);
1.90      albertel  367:     push(@Apache::inputtags::importlist,$id);
1.87      sakharuk  368: 
                    369: 	&Apache::lonxml::newparser($parser,\$file,$dir);
                    370: 
1.56      albertel  371:   } elsif ($target eq "edit" ) {
1.46      albertel  372:     $result.=&Apache::edit::tag_start($target,$token);
1.68      albertel  373:     $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
1.83      matthew   374:     $result.=&Apache::edit::browse(undef,'textnode');
1.46      albertel  375:     #FIXME this need to convert $bodytext to be a contruction space reference
                    376:     #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
                    377:     #$result.="Click<a href=\"$location\">here</a> to edit<br />"
1.56      albertel  378:   } elsif ($target eq 'modified') {
1.103     albertel  379:       $result=$token->[4].&Apache::edit::modifiedfield("/import",$parser);
1.56      albertel  380:   } elsif ($target eq 'meta') {
1.57      albertel  381:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                    382:     $result.='<import part="'.$Apache::inputtags::part;
                    383:     if ($id) {
                    384:       $result.='" id="'.$id;
                    385:     }
                    386:     $result.='">';
1.56      albertel  387:     $result.=$bodytext;
                    388:     $result.='</import>';
1.46      albertel  389:   }
                    390:   return $result;
1.6       albertel  391: }
                    392: 
                    393: sub end_import {
1.69      albertel  394:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.57      albertel  395:   pop(@Apache::inputtags::import);
1.69      albertel  396:   my $result;
                    397:   if ($target eq 'edit' ) { $result=&Apache::edit::end_table(); }
                    398:   return $result;
1.1       albertel  399: }
1.42      sakharuk  400: 
                    401: sub start_storetc {
1.43      albertel  402:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42      sakharuk  403:   my $result = '';
                    404:   &Apache::lonxml::startredirection;
                    405:   return $result; 
                    406: }
                    407: 
                    408: sub end_storetc {
1.43      albertel  409:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42      sakharuk  410:     my $result;
                    411:     my $output=&Apache::lonxml::endredirection;
                    412:     $output =~ s/\"/\&quot\;/g;
1.52      albertel  413:     $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
                    414:     return $result;
1.42      sakharuk  415: }
                    416: 
                    417: 
                    418: sub start_physnet {
1.45      sakharuk  419:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.50      www       420:     my $bodytext = '/adm/includes/physnet.sty';
1.45      sakharuk  421:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
                    422:     my $cbistyletext=&Apache::lonnet::getfile($location);
1.42      sakharuk  423: 
1.45      sakharuk  424:     %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
1.59      albertel  425:     $$parser['-1']->unget_token($token);
                    426: #    if ( defined($$style{'physnet'}) ) {
                    427: #        &Apache::lonxml::newparser($parser,\$$style{'physnet'});
                    428: #    }
1.45      sakharuk  429:     return "";
                    430: }
1.42      sakharuk  431: 
1.45      sakharuk  432: sub end_physnet {
1.47      albertel  433:   return '';
1.42      sakharuk  434: }
1.62      albertel  435: 
                    436: sub start_standalone {
                    437:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.75      albertel  438:   my $result='';
                    439:   if ($target eq 'web' ) {
                    440:     if ( $ENV{'request.course.id'} ) {
1.85      albertel  441:       my $inside = &Apache::lonxml::get_all_text("/standalone",$parser);
1.75      albertel  442:     } else {
                    443:       $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
                    444:     }
1.62      albertel  445:   }
1.75      albertel  446:   return $result;
1.62      albertel  447: }
                    448: 
                    449: sub end_standalone {
1.75      albertel  450:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    451:   my $result='';
                    452:   if ($target eq 'web' ) {
                    453:     if ( $ENV{'request.course.id'} ) {
                    454:     } else {
                    455:       $result='</td></tr></table>';
                    456:     }
                    457:   }
                    458:   return $result;
1.74      albertel  459: }
                    460: 
                    461: sub start_comment {
                    462:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    463:   my $result='';
                    464:   if ($target eq 'edit') {
                    465:     $result=&Apache::edit::tag_start($target,$token);
1.85      albertel  466:     my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser);
1.77      albertel  467:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
1.74      albertel  468:   } elsif ( $target eq 'modified') {
1.103     albertel  469:     $result=$token->[4].&Apache::edit::modifiedfield("/comment",$parser);
1.78      albertel  470:   } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
                    471: 	    $target eq 'answer' || $target eq 'meta' || $target eq 'analyze') {
1.74      albertel  472:     #normally throw away comments
1.85      albertel  473:     my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser);
1.74      albertel  474:   }
                    475:   return $result;
                    476: }
                    477: 
                    478: sub end_comment {
                    479:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    480:   if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
1.62      albertel  481:   return '';
                    482: }
                    483: 
1.42      sakharuk  484: 
1.47      albertel  485: sub xmlparse {
                    486:   my ($string) = @_;
1.111     albertel  487:   &Apache::lonxml::debug("xmlparse recursion starting with $string");
1.113     albertel  488:   # Apache::run::evaluate does an 'eval' on the name of the subroutine
                    489:   # if it detects something that looks like a subroutine, this ends up calling
                    490:   # things without any arguments and since perl is nice enough to pass
                    491:   # along the default arguments when you don't explicitly say no arguments
                    492:   # if you call &xmlparse, it gets &xmlparse passed as it argument.
                    493:   # Same thing soccurs with &chemparse.
1.111     albertel  494:   if ($string eq '&xmlparse') { return '&xmlparse'; }
1.113     albertel  495:   if ($string eq '&chemparse') { return '&chemparse'; }
1.47      albertel  496:   my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
                    497:     @Apache::scripttag::parser_env;
                    498:   my @parser;
                    499:   &Apache::lonxml::newparser(\@parser,\$string);
                    500:   my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
                    501: 					     $parstack,\@parser,
                    502: 					     $safeeval,$style);
1.111     albertel  503:   &Apache::lonxml::debug("xmlparse recursion ending with $result");
1.47      albertel  504:   return $result;
                    505: }
1.3       albertel  506: 
1.1       albertel  507: 1;
                    508: __END__

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