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