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

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

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