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

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

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