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