1: # The LearningOnline Network with CAPA
2: # <script> definiton
3: #
4: # $Id: scripttag.pm,v 1.145 2007/11/17 01:43:00 albertel Exp $
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: #
28:
29: package Apache::scripttag;
30:
31: use strict;
32: use Apache::lonnet;
33: use Apache::lonlocal;
34: use Apache::style();
35:
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 = ();
41: BEGIN {
42: &Apache::lonxml::register('Apache::scripttag',
43: ('script','scriptlib','parserlib','import',
44: 'window','display','storetc','physnet',
45: 'standalone','comment','num','parse','algebra',
46: 'LONCAPA_INTERNAL_TURN_STYLE_ON',
47: 'LONCAPA_INTERNAL_TURN_STYLE_OFF',
48: 'LONCAPA_INTERNAL_LONHTTPD_PORT'));
49: }
50:
51: sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
52: $Apache::lonxml::usestyle=1;
53: $Apache::lonxml::style_values='';
54: return ('','no');
55: }
56:
57: sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
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: }
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 {
81: return ('','no');
82: }
83:
84: =pod
85:
86: =item start_LONCAPA_INTERNAL_LONHTTPD_PORT
87:
88: emits a pice of javascript that says a global js variable to the
89: current lonhttp port, currently used by the remote control to find out
90: where to load images from
91:
92: =cut
93:
94: sub start_LONCAPA_INTERNAL_LONHTTPD_PORT {
95: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
96: if ($target eq 'web' || $target eq 'webgrade') {
97: return '<script type="text/javascript">var lonhttpdport=\''.
98: &Apache::loncommon::lonhttpd_port().'\';</script>';
99: }
100: return ('','no');
101: }
102:
103: sub end_LONCAPA_INTERNAL_LONHTTPD_PORT {
104: return ('','no');
105: }
106:
107: sub start_script {
108: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
109: @Apache::scripttag::parser_env = @_;
110: my $result='';
111: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
112: &Apache::lonxml::debug("found type of $type");
113: if ($type eq "loncapa/perl") {
114: if ( $target eq "modified" ) {
115: $result=$token->[4].&Apache::edit::modifiedfield('/script',$parser);
116: } elsif ( $target eq 'web' || $target eq 'tex' ||
117: $target eq 'grade' || $target eq 'webgrade' ||
118: $target eq 'answer' || $target eq 'analyze' ) {
119: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
120: if (!$Apache::lonxml::default_homework_loaded) {
121: &Apache::lonxml::default_homework_load($safeeval);
122: }
123: &Apache::run::run($bodytext,$safeeval);
124: if (($target eq 'answer') &&
125: ($env{'form.answer_output_mode'} ne 'tex') &&
126: ($Apache::lonhomework::viewgrades == 'F')) {
127: $Apache::lonxml::evaluate--;
128: my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
129: my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
130: my $start_page =
131: &Apache::loncommon::start_page('Script Vars', undef,
132: {'only_body' => 1,
133: 'bgcolor' => '#FFFFFF',
134: 'js_ready' => 1,});
135: my $end_page =
136: &Apache::loncommon::end_page({'js_ready' => 1,});
137:
138: $uname =~s/\W//g;
139: $udom =~s/\W//g;
140: my $function_name =
141: join('_','LONCAPA_scriptvars',$uname,$udom,
142: $env{'form.counter'},$Apache::lonxml::curdepth);
143: my $script_var ="<script type=\"text/javascript\">
144: // <![CDATA[
145: function $function_name() {newWindow=open('','new_W','width=500,height=500,scrollbars=1,resizable=yes');newWindow.$windowopen;newWindow.document.writeln('$start_page<pre>";
146: my $listing=&Apache::run::dump($target,$safeeval);
147: $listing=~s/\\/\\\\/g;
148: $listing=~s/\'/\\\'/g;
149: $script_var.=$listing;
150: $script_var.= "<\\/pre>$end_page');newWindow.document.close();newWindow.focus()}
151: // ]]>
152: </script><a href=\"javascript:$function_name();void(0);\">".&mt('Script Vars')."</a><br />";
153: &Apache::lonxml::add_script_result($script_var);
154: }
155: } elsif ($target eq "edit" ) {
156: #&Apache::run::run($bodytext,$safeeval);
157: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
158: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
159: $result=&Apache::edit::tag_start($target,$token,'Script');
160: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
161: } elsif ($target eq 'meta') {
162: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
163: }
164: } else {
165: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
166: if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') {
167: $result = $token->[4];
168: $result.=$bodytext;
169: }
170: }
171: return $result;
172: }
173:
174: sub end_script {
175: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
176: if ( $target eq "meta" ) { return ''; }
177: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
178: my $result='';
179: #other script blocks need to survive
180: if ($type ne "loncapa/perl" && $target ne 'tex') {
181: return $token->[2];
182: } elsif ($target eq 'edit' ) {
183: return &Apache::edit::end_table();
184: } elsif ($target eq 'answer') {
185: $Apache::lonxml::evaluate++;
186: }
187: return '';
188: }
189:
190: sub start_display {
191: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
192: @Apache::scripttag::parser_env = @_;
193: my $result;
194:
195: if ( $target eq "modified" ) {
196: $result=$token->[4].&Apache::edit::modifiedfield("/display",$parser);
197: } elsif ( $target eq 'web' || $target eq 'tex' ||
198: $target eq 'grade' || $target eq 'webgrade' ||
199: $target eq 'answer' || $target eq 'analyze') {
200: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
201: if (!$Apache::lonxml::default_homework_loaded) {
202: &Apache::lonxml::default_homework_load($safeeval);
203: }
204: $result=&Apache::run::run($bodytext,$safeeval);
205: if ($target eq 'grade' || $target eq 'answer' ||
206: $target eq 'analyze') {
207: # grade/answer/analyxe should produce no output but if we
208: # are redirecting, the redirecter should know what to do
209: # with the output
210: if (!$Apache::lonxml::redirection) { $result=''; }
211: }
212: $Apache::lonxml::post_evaluate=0;
213: } elsif ($target eq "edit" ) {
214: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
215: #$result =
216: # "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
217: #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
218: $result=&Apache::edit::tag_start($target,$token,'Script With Display');
219: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
220: } elsif ($target eq 'meta') {
221: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
222: }
223: return $result;
224: }
225:
226: sub end_display {
227: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
228: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
229: return '';
230: }
231:
232: sub start_scriptlib {
233: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
234: my $bodytext;
235: my $result ='';
236: my $error='';
237:
238: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
239: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
240: $target eq 'analyze' || $target eq 'webgrade') {
241: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
242: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
243: $$parstack[$#$parstack]);
244: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
245: $bodytext);
246: my $script=&Apache::lonnet::getfile($location);
247: if ($script == -1) {
248: if ($target eq 'edit') {
249: $error='</tr><tr><td>'.&mt('Errors').'</td><td colspan="2"><b>'.&mt(' Unable to find [_1]','<span class="LC_filename">'.$location.'</span>').'</b></td>'."\n";
250: } else {
251: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
252: return "";
253: }
254: }
255: &Apache::run::run($script,$safeeval);
256: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
257: }
258: if ($target eq "edit" ) {
259: $result=
260: &Apache::edit::tag_start($target,$token,'New Script Functions').
261: &Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
262: &Apache::edit::browse(undef,'textnode').
263: $error.'</td></tr>'.
264: &Apache::edit::end_table();
265: }
266: if ($target eq "modified" ) {
267: $result=$token->[4].&Apache::edit::modifiedfield("/scriptlib",$parser);
268: }
269: return $result;
270: }
271:
272: sub end_scriptlib {
273: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
274: my @result;
275: if ($target eq "edit" ) { $result[1]='no'; }
276: return @result;
277: }
278:
279: sub start_parserlib {
280: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
281: my $bodytext;
282: my $result ="";
283: my $error='';
284: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
285: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
286: $target eq 'analyze' || $target eq 'webgrade') {
287: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
288: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
289: $$parstack[$#$parstack]);
290: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
291: $bodytext);
292: my $styletext=&Apache::lonnet::getfile($location);
293: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
294: if ($styletext == -1) {
295: if ($target eq 'edit') {
296: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
297: } else {
298: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
299: return "";
300: }
301: }
302: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
303: }
304: if ($target eq "edit" ) {
305: $result=
306: &Apache::edit::tag_start($target,$token,'New Tag Definitions').
307: &Apache::edit::editline($token->[1],$bodytext,'',40).
308: $error.'</td></tr>'.
309: &Apache::edit::end_table();
310: }
311: if ($target eq "modified" ) {
312: $result=$token->[4].&Apache::edit::modifiedfield("/parserlib",$parser);
313: }
314: return $result;
315: }
316:
317: sub end_parserlib {
318: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
319: my @result;
320: if ($target eq "edit" ) { $result[1]='no'; }
321: return @result;
322: }
323:
324: sub start_window {
325: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
326: my $result = '';
327: if ($target eq 'web' || $target eq 'webgrade') {
328: &Apache::lonxml::startredirection;
329: } elsif ($target eq 'tex') {
330: $result = '\unskip\footnote{';
331: } elsif ($target eq 'edit') {
332: $result.=&Apache::edit::tag_start($target,$token);
333: $result.=&Apache::edit::text_arg('Text of Link:','linktext',$token,70);
334: $result.=&Apache::edit::text_arg('Height:','height',$token,5);
335: $result.=&Apache::edit::text_arg('Width:','width',$token,5);
336: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
337: } elsif ($target eq 'modified') {
338: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
339: $safeeval,'linktext',
340: 'width','height');
341: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
342: }
343: return $result;
344: }
345:
346: sub end_window {
347: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
348: my $result;
349: if ($target eq 'web' || $target eq 'webgrade') {
350: my $output=&Apache::lonxml::endredirection;
351: $output =~ s/[\n\r]/ /g;
352: # $output = &HTML::Entities::encode($output,'<>&"\'');
353: $output =~ s/\'/\\\'/g;
354: my $linktext= &Apache::lonxml::get_param('linktext',$parstack,$safeeval);
355: if (!$linktext) { $linktext='<sup>*</sup>'; }
356: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
357: if (!$width) { $width='500'; }
358: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
359: if (!$height) { $height='200'; }
360:
361: my $start_page =
362: &Apache::loncommon::start_page($linktext, undef,
363: {'only_body' => 1,
364: 'bgcolor' => '#FFFFFF',
365: 'js_ready' => 1,});
366: my $end_page =
367: &Apache::loncommon::end_page({'js_ready' => 1,});
368: $result = "<script type=\"text/javascript\">
369: //<!--
370: function LONCAPA_newwindow_$Apache::lonxml::curdepth() {
371: newWindow=open(".&Apache::lonhtmlcommon::javascript_nothing().",'new_W','width=$width,height=$height,scrollbars=1');
372: newWindow.".&Apache::lonhtmlcommon::javascript_docopen().";
373: newWindow.document.writeln('$start_page $output $end_page');
374: newWindow.document.close();}
375: //-->
376: </script><a href=\"javascript:LONCAPA_newwindow_$Apache::lonxml::curdepth();void(0);\">$linktext</a>";
377: } elsif ($target eq 'tex') {
378: $result = '}';
379: } else {
380: $result = '';
381: }
382: return $result;
383: }
384:
385: sub start_import {
386: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
387: my $bodytext=$$parser[$#$parser]->get_text("/import");
388: my $result ="";
389:
390: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
391:
392: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade'
393: || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze' ) {
394: # FIXME this probably needs to be smart about construction vs.
395: # non construction space.
396: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
397: my $file=&Apache::lonnet::getfile($location);
398: if ($file == -1) {
399: &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
400: return "";
401: }
402:
403: my $dir=$location;
404: $dir=~s:/[^/]*$::;
405: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
406: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
407: if (!$id) { $id=$Apache::lonxml::curdepth; }
408: push(@Apache::inputtags::import,$id);
409: push(@Apache::inputtags::importlist,$id);
410:
411: &Apache::lonxml::newparser($parser,\$file,$dir);
412:
413: } elsif ($target eq "edit" ) {
414: $result.=&Apache::edit::tag_start($target,$token);
415: $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
416: $result.=&Apache::edit::browse(undef,'textnode');
417: #FIXME this need to convert $bodytext to be a contruction space reference
418: #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
419: #$result.="Click<a href=\"$location\">here</a> to edit<br />"
420: } elsif ($target eq 'modified') {
421: $result=$token->[4].&Apache::edit::modifiedfield("/import",$parser);
422: } elsif ($target eq 'meta') {
423: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
424: $result.='<import part="'.$Apache::inputtags::part;
425: if ($id) {
426: $result.='" id="'.$id;
427: }
428: $result.='">';
429: $result.=$bodytext;
430: $result.='</import>';
431: }
432: return $result;
433: }
434:
435: sub end_import {
436: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
437: pop(@Apache::inputtags::import);
438: my $result;
439: if ($target eq 'edit' ) { $result=&Apache::edit::end_row.
440: &Apache::edit::end_table(); }
441: return $result;
442: }
443:
444: sub start_storetc {
445: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
446: my $result = '';
447: &Apache::lonxml::startredirection;
448: return $result;
449: }
450:
451: sub end_storetc {
452: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
453: my $result;
454: my $output=&Apache::lonxml::endredirection;
455: $output =~ s/\"/\"\;/g;
456: $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
457: return $result;
458: }
459:
460:
461: sub start_physnet {
462: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
463: my $bodytext = '/adm/includes/physnet.sty';
464: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
465: my $cbistyletext=&Apache::lonnet::getfile($location);
466:
467: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
468: $$parser['-1']->unget_token($token);
469: # if ( defined($$style{'physnet'}) ) {
470: # &Apache::lonxml::newparser($parser,\$$style{'physnet'});
471: # }
472: return "";
473: }
474:
475: sub end_physnet {
476: return '';
477: }
478:
479: sub start_standalone {
480: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
481: my $result='';
482: if ($target eq 'web' || $target eq 'webgrade') {
483: if ( $env{'request.course.id'} ) {
484: my $inside = &Apache::lonxml::get_all_text("/standalone",$parser,$style);
485: } else {
486: $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
487: }
488: }
489: return $result;
490: }
491:
492: sub end_standalone {
493: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
494: my $result='';
495: if ($target eq 'web' || $target eq 'webgrade' ) {
496: if ( $env{'request.course.id'} ) {
497: } else {
498: $result='</td></tr></table>';
499: }
500: }
501: return $result;
502: }
503:
504: sub start_comment {
505: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
506: my $result='';
507: if ($target eq 'edit') {
508: $result=&Apache::edit::tag_start($target,$token);
509: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
510: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
511: } elsif ( $target eq 'modified') {
512: $result=$token->[4].&Apache::edit::modifiedfield("/comment",$parser);
513: } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
514: $target eq 'answer' || $target eq 'meta' || $target eq 'analyze' ||
515: $target eq 'webgrade') {
516: #normally throw away comments
517: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
518: }
519: return $result;
520: }
521:
522: sub end_comment {
523: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
524: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
525: return '';
526: }
527:
528:
529: sub xmlparse {
530: my ($string) = @_;
531: &Apache::lonxml::debug("xmlparse recursion starting with $string");
532: # Apache::run::evaluate does an 'eval' on the name of the subroutine
533: # if it detects something that looks like a subroutine, this ends up calling
534: # things without any arguments and since perl is nice enough to pass
535: # along the default arguments when you don't explicitly say no arguments
536: # if you call &xmlparse, it gets &xmlparse passed as it argument.
537: # Same thing soccurs with &chemparse.
538: if ($string eq '&xmlparse') { return '&xmlparse'; }
539: if ($string eq '&chemparse') { return '&chemparse'; }
540: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
541: @Apache::scripttag::parser_env;
542: my @parser;
543: &Apache::lonxml::newparser(\@parser,\$string);
544: &Apache::lonxml::startredirection();
545: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
546: $parstack,\@parser,
547: $safeeval,$style);
548: $result.=&Apache::lonxml::endredirection();
549: &Apache::lonxml::debug("target is $target xmlparse recursion ending with $result");
550: return $result;
551: }
552:
553: sub start_num {
554: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
555: my $result = '';
556: my $inside = &Apache::lonxml::get_all_text_unbalanced("/num",$parser);
557: if ($target eq 'tex' || $target eq 'web' || $target eq 'webgrade') {
558: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
559: if (!$Apache::lonxml::default_homework_loaded) {
560: &Apache::lonxml::default_homework_load($safeeval);
561: }
562: @Apache::scripttag::parser_env = @_;
563: my $format=&Apache::lonxml::get_param('format',$parstack,$safeeval);
564: $result=&Apache::run::run("return &prettyprint(q\0$inside\0,q\0$format\0);",$safeeval);
565: }
566: return $result;
567: }
568:
569: sub end_num {
570: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
571: my $result = '';
572: return $result;
573: }
574:
575: sub start_parse {
576: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
577: my $result = '';
578: if ( $target eq 'web' || $target eq 'tex' ||
579: $target eq 'grade' || $target eq 'answer' ||
580: $target eq 'analyze'|| $target eq 'webgrade') {
581: my $inside = &Apache::lonxml::get_all_text_unbalanced("/parse",$parser);
582: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
583: if (!$Apache::lonxml::default_homework_loaded) {
584: &Apache::lonxml::default_homework_load($safeeval);
585: }
586: @Apache::scripttag::parser_env = @_;
587: $result=&Apache::run::run("return &xmlparse(q\0$inside\0);",$safeeval);
588: if ($target eq 'grade' || $target eq 'answer' ||
589: $target eq 'analyze') {
590: # grade/answer/analyxe should produce no output but if we
591: # are redirecting, the redirecter should know what to do
592: # with the output
593: if (!$Apache::lonxml::redirection) { $result=''; }
594: }
595: }
596: return $result;
597: }
598:
599: sub end_parse {
600: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
601: my $result = '';
602: return $result;
603: }
604:
605: sub start_algebra {
606: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
607: my $result = '';
608: if ( $target eq 'web' || $target eq 'tex' ||
609: $target eq 'grade' || $target eq 'answer' ||
610: $target eq 'analyze' || $target eq 'webgrade') {
611: my $inside = &Apache::lonxml::get_all_text_unbalanced("/algebra",$parser);
612: $inside = &Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
613: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
614: my $style=&Apache::lonxml::get_param('style',$parstack,$safeeval);
615: $result=&Apache::lontexconvert::algebra($inside,$target,$style);
616: }
617: $Apache::lonxml::post_evaluate=0;
618: }
619: return $result;
620: }
621:
622: sub end_algebra {
623: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
624: my $result = '';
625: return $result;
626: }
627:
628: 1;
629: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>