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