Annotation of loncom/xml/scripttag.pm, revision 1.145
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # <script> definiton
1.58 www 3: #
1.145 ! albertel 4: # $Id: scripttag.pm,v 1.144 2007/10/11 00:24:46 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.145 ! albertel 33: use Apache::lonlocal;
! 34: use Apache::style();
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:
1.143 albertel 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:
1.86 albertel 94: sub start_LONCAPA_INTERNAL_LONHTTPD_PORT {
95: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.137 albertel 96: if ($target eq 'web' || $target eq 'webgrade') {
1.86 albertel 97: return '<script type="text/javascript">var lonhttpdport=\''.
1.143 albertel 98: &Apache::loncommon::lonhttpd_port().'\';</script>';
1.86 albertel 99: }
100: return ('','no');
101: }
102:
103: sub end_LONCAPA_INTERNAL_LONHTTPD_PORT {
1.81 albertel 104: return ('','no');
1.1 albertel 105: }
106:
107: sub start_script {
1.40 albertel 108: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47 albertel 109: @Apache::scripttag::parser_env = @_;
1.24 albertel 110: my $result='';
1.39 albertel 111: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
112: &Apache::lonxml::debug("found type of $type");
1.17 albertel 113: if ($type eq "loncapa/perl") {
114: if ( $target eq "modified" ) {
1.103 albertel 115: $result=$token->[4].&Apache::edit::modifiedfield('/script',$parser);
1.54 albertel 116: } elsif ( $target eq 'web' || $target eq 'tex' ||
1.130 albertel 117: $target eq 'grade' || $target eq 'webgrade' ||
118: $target eq 'answer' || $target eq 'analyze' ) {
1.107 albertel 119: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.79 albertel 120: if (!$Apache::lonxml::default_homework_loaded) {
121: &Apache::lonxml::default_homework_load($safeeval);
122: }
123: &Apache::run::run($bodytext,$safeeval);
1.88 albertel 124: if (($target eq 'answer') &&
1.126 albertel 125: ($env{'form.answer_output_mode'} ne 'tex') &&
1.88 albertel 126: ($Apache::lonhomework::viewgrades == 'F')) {
1.79 albertel 127: $Apache::lonxml::evaluate--;
1.138 albertel 128: my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
1.118 www 129: my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
1.135 albertel 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:
1.140 albertel 138: $uname =~s/\W//g;
139: $udom =~s/\W//g;
1.145 ! albertel 140: my $function_name =
! 141: join('_','LONCAPA_scriptvars',$uname,$udom,
! 142: $env{'form.counter'},$Apache::lonxml::curdepth);
1.141 albertel 143: my $script_var ="<script type=\"text/javascript\">
1.124 albertel 144: // <![CDATA[
1.145 ! albertel 145: function $function_name() {newWindow=open('','new_W','width=500,height=500,scrollbars=1,resizable=yes');newWindow.$windowopen;newWindow.document.writeln('$start_page<pre>";
1.99 albertel 146: my $listing=&Apache::run::dump($target,$safeeval);
1.128 albertel 147: $listing=~s/\\/\\\\/g;
1.99 albertel 148: $listing=~s/\'/\\\'/g;
1.141 albertel 149: $script_var.=$listing;
150: $script_var.= "<\\/pre>$end_page');newWindow.document.close();newWindow.focus()}
1.124 albertel 151: // ]]>
1.145 ! albertel 152: </script><a href=\"javascript:$function_name();void(0);\">".&mt('Script Vars')."</a><br />";
1.141 albertel 153: &Apache::lonxml::add_script_result($script_var);
1.79 albertel 154: }
1.28 albertel 155: } elsif ($target eq "edit" ) {
1.41 albertel 156: #&Apache::run::run($bodytext,$safeeval);
157: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
1.107 albertel 158: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.103 albertel 159: $result=&Apache::edit::tag_start($target,$token,'Script');
160: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
1.107 albertel 161: } elsif ($target eq 'meta') {
162: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.17 albertel 163: }
164: } else {
1.108 matthew 165: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.144 albertel 166: if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') {
1.112 albertel 167: $result = $token->[4];
168: $result.=$bodytext;
169: }
1.13 albertel 170: }
1.24 albertel 171: return $result;
1.17 albertel 172: }
1.13 albertel 173:
1.17 albertel 174: sub end_script {
1.40 albertel 175: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.28 albertel 176: if ( $target eq "meta" ) { return ''; }
1.39 albertel 177: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.29 albertel 178: my $result='';
179: #other script blocks need to survive
1.115 albertel 180: if ($type ne "loncapa/perl" && $target ne 'tex') {
1.53 albertel 181: return $token->[2];
182: } elsif ($target eq 'edit' ) {
183: return &Apache::edit::end_table();
1.78 albertel 184: } elsif ($target eq 'answer') {
1.53 albertel 185: $Apache::lonxml::evaluate++;
186: }
1.28 albertel 187: return '';
1.24 albertel 188: }
189:
190: sub start_display {
1.40 albertel 191: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.119 albertel 192: @Apache::scripttag::parser_env = @_;
1.48 albertel 193: my $result;
1.39 albertel 194:
1.24 albertel 195: if ( $target eq "modified" ) {
1.103 albertel 196: $result=$token->[4].&Apache::edit::modifiedfield("/display",$parser);
1.54 albertel 197: } elsif ( $target eq 'web' || $target eq 'tex' ||
1.130 albertel 198: $target eq 'grade' || $target eq 'webgrade' ||
199: $target eq 'answer' || $target eq 'analyze') {
1.107 albertel 200: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.80 albertel 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') {
1.114 albertel 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=''; }
1.80 albertel 211: }
1.101 albertel 212: $Apache::lonxml::post_evaluate=0;
1.48 albertel 213: } elsif ($target eq "edit" ) {
1.110 albertel 214: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.48 albertel 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');
1.77 albertel 219: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
1.107 albertel 220: } elsif ($target eq 'meta') {
221: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.24 albertel 222: }
223: return $result;
224: }
225:
226: sub end_display {
1.48 albertel 227: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
228: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
229: return '';
1.1 albertel 230: }
1.3 albertel 231:
232: sub start_scriptlib {
1.40 albertel 233: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 234: my $bodytext;
235: my $result ='';
236: my $error='';
237:
1.106 albertel 238: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
239: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
1.137 albertel 240: $target eq 'analyze' || $target eq 'webgrade') {
1.37 albertel 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') {
1.145 ! albertel 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";
1.37 albertel 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 />");
1.18 albertel 257: }
1.13 albertel 258: if ($target eq "edit" ) {
1.37 albertel 259: $result=
1.49 albertel 260: &Apache::edit::tag_start($target,$token,'New Script Functions').
1.83 matthew 261: &Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
262: &Apache::edit::browse(undef,'textnode').
1.49 albertel 263: $error.'</td></tr>'.
264: &Apache::edit::end_table();
1.37 albertel 265: }
266: if ($target eq "modified" ) {
1.103 albertel 267: $result=$token->[4].&Apache::edit::modifiedfield("/scriptlib",$parser);
1.3 albertel 268: }
269: return $result;
270: }
271:
1.37 albertel 272: sub end_scriptlib {
1.40 albertel 273: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49 albertel 274: my @result;
275: if ($target eq "edit" ) { $result[1]='no'; }
276: return @result;
1.37 albertel 277: }
1.4 albertel 278:
279: sub start_parserlib {
1.40 albertel 280: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 281: my $bodytext;
1.7 albertel 282: my $result ="";
1.37 albertel 283: my $error='';
1.106 albertel 284: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
285: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
1.137 albertel 286: $target eq 'analyze' || $target eq 'webgrade') {
1.37 albertel 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));
1.18 albertel 303: }
1.13 albertel 304: if ($target eq "edit" ) {
1.37 albertel 305: $result=
1.49 albertel 306: &Apache::edit::tag_start($target,$token,'New Tag Definitions').
1.68 albertel 307: &Apache::edit::editline($token->[1],$bodytext,'',40).
1.49 albertel 308: $error.'</td></tr>'.
309: &Apache::edit::end_table();
1.37 albertel 310: }
311: if ($target eq "modified" ) {
1.103 albertel 312: $result=$token->[4].&Apache::edit::modifiedfield("/parserlib",$parser);
1.7 albertel 313: }
314: return $result;
1.4 albertel 315: }
316:
317: sub end_parserlib {
1.40 albertel 318: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49 albertel 319: my @result;
320: if ($target eq "edit" ) { $result[1]='no'; }
321: return @result;
1.6 albertel 322: }
323:
1.30 sakharuk 324: sub start_window {
1.105 albertel 325: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
326: my $result = '';
1.137 albertel 327: if ($target eq 'web' || $target eq 'webgrade') {
1.105 albertel 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);
1.131 albertel 334: $result.=&Apache::edit::text_arg('Height:','height',$token,5);
335: $result.=&Apache::edit::text_arg('Width:','width',$token,5);
1.105 albertel 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,
1.129 raeburn 339: $safeeval,'linktext',
1.105 albertel 340: 'width','height');
341: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
342: }
343: return $result;
1.19 sakharuk 344: }
345:
1.30 sakharuk 346: sub end_window {
1.40 albertel 347: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30 sakharuk 348: my $result;
1.137 albertel 349: if ($target eq 'web' || $target eq 'webgrade') {
1.34 albertel 350: my $output=&Apache::lonxml::endredirection;
1.97 albertel 351: $output =~ s/[\n\r]/ /g;
1.98 albertel 352: # $output = &HTML::Entities::encode($output,'<>&"\'');
353: $output =~ s/\'/\\\'/g;
1.92 albertel 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'; }
1.135 albertel 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,});
1.136 albertel 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>";
1.35 sakharuk 377: } elsif ($target eq 'tex') {
378: $result = '}';
1.30 sakharuk 379: } else {
1.35 sakharuk 380: $result = '';
1.30 sakharuk 381: }
1.20 sakharuk 382: return $result;
1.19 sakharuk 383: }
384:
1.6 albertel 385: sub start_import {
1.40 albertel 386: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 387: my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7 albertel 388: my $result ="";
1.13 albertel 389:
390: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.14 albertel 391:
1.135 albertel 392: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade'
393: || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze' ) {
1.46 albertel 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: }
1.13 albertel 402:
1.46 albertel 403: my $dir=$location;
404: $dir=~s:/[^/]*$::;
405: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
1.142 albertel 406: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
1.57 albertel 407: if (!$id) { $id=$Apache::lonxml::curdepth; }
408: push(@Apache::inputtags::import,$id);
1.90 albertel 409: push(@Apache::inputtags::importlist,$id);
1.87 sakharuk 410:
1.144 albertel 411: &Apache::lonxml::newparser($parser,\$file,$dir);
1.87 sakharuk 412:
1.56 albertel 413: } elsif ($target eq "edit" ) {
1.46 albertel 414: $result.=&Apache::edit::tag_start($target,$token);
1.68 albertel 415: $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
1.83 matthew 416: $result.=&Apache::edit::browse(undef,'textnode');
1.46 albertel 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 />"
1.56 albertel 420: } elsif ($target eq 'modified') {
1.103 albertel 421: $result=$token->[4].&Apache::edit::modifiedfield("/import",$parser);
1.56 albertel 422: } elsif ($target eq 'meta') {
1.142 albertel 423: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
1.57 albertel 424: $result.='<import part="'.$Apache::inputtags::part;
425: if ($id) {
426: $result.='" id="'.$id;
427: }
428: $result.='">';
1.56 albertel 429: $result.=$bodytext;
430: $result.='</import>';
1.46 albertel 431: }
432: return $result;
1.6 albertel 433: }
434:
435: sub end_import {
1.69 albertel 436: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.57 albertel 437: pop(@Apache::inputtags::import);
1.69 albertel 438: my $result;
1.120 albertel 439: if ($target eq 'edit' ) { $result=&Apache::edit::end_row.
440: &Apache::edit::end_table(); }
1.69 albertel 441: return $result;
1.1 albertel 442: }
1.42 sakharuk 443:
444: sub start_storetc {
1.43 albertel 445: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42 sakharuk 446: my $result = '';
447: &Apache::lonxml::startredirection;
448: return $result;
449: }
450:
451: sub end_storetc {
1.43 albertel 452: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42 sakharuk 453: my $result;
454: my $output=&Apache::lonxml::endredirection;
455: $output =~ s/\"/\"\;/g;
1.52 albertel 456: $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
457: return $result;
1.42 sakharuk 458: }
459:
460:
461: sub start_physnet {
1.45 sakharuk 462: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.50 www 463: my $bodytext = '/adm/includes/physnet.sty';
1.45 sakharuk 464: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
465: my $cbistyletext=&Apache::lonnet::getfile($location);
1.42 sakharuk 466:
1.45 sakharuk 467: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
1.59 albertel 468: $$parser['-1']->unget_token($token);
469: # if ( defined($$style{'physnet'}) ) {
470: # &Apache::lonxml::newparser($parser,\$$style{'physnet'});
471: # }
1.45 sakharuk 472: return "";
473: }
1.42 sakharuk 474:
1.45 sakharuk 475: sub end_physnet {
1.47 albertel 476: return '';
1.42 sakharuk 477: }
1.62 albertel 478:
479: sub start_standalone {
480: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.75 albertel 481: my $result='';
1.137 albertel 482: if ($target eq 'web' || $target eq 'webgrade') {
1.126 albertel 483: if ( $env{'request.course.id'} ) {
1.133 albertel 484: my $inside = &Apache::lonxml::get_all_text("/standalone",$parser,$style);
1.75 albertel 485: } else {
486: $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
487: }
1.62 albertel 488: }
1.75 albertel 489: return $result;
1.62 albertel 490: }
491:
492: sub end_standalone {
1.75 albertel 493: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
494: my $result='';
1.137 albertel 495: if ($target eq 'web' || $target eq 'webgrade' ) {
1.126 albertel 496: if ( $env{'request.course.id'} ) {
1.75 albertel 497: } else {
498: $result='</td></tr></table>';
499: }
500: }
501: return $result;
1.74 albertel 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);
1.133 albertel 509: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
1.77 albertel 510: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
1.74 albertel 511: } elsif ( $target eq 'modified') {
1.103 albertel 512: $result=$token->[4].&Apache::edit::modifiedfield("/comment",$parser);
1.137 albertel 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') {
1.74 albertel 516: #normally throw away comments
1.133 albertel 517: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
1.74 albertel 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(); }
1.62 albertel 525: return '';
526: }
527:
1.42 sakharuk 528:
1.47 albertel 529: sub xmlparse {
530: my ($string) = @_;
1.111 albertel 531: &Apache::lonxml::debug("xmlparse recursion starting with $string");
1.113 albertel 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.
1.111 albertel 538: if ($string eq '&xmlparse') { return '&xmlparse'; }
1.113 albertel 539: if ($string eq '&chemparse') { return '&chemparse'; }
1.47 albertel 540: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
541: @Apache::scripttag::parser_env;
542: my @parser;
543: &Apache::lonxml::newparser(\@parser,\$string);
1.132 albertel 544: &Apache::lonxml::startredirection();
1.47 albertel 545: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
546: $parstack,\@parser,
547: $safeeval,$style);
1.132 albertel 548: $result.=&Apache::lonxml::endredirection();
1.122 albertel 549: &Apache::lonxml::debug("target is $target xmlparse recursion ending with $result");
1.47 albertel 550: return $result;
551: }
1.3 albertel 552:
1.122 albertel 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);
1.137 albertel 557: if ($target eq 'tex' || $target eq 'web' || $target eq 'webgrade') {
1.122 albertel 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 = '';
1.137 albertel 578: if ( $target eq 'web' || $target eq 'tex' ||
579: $target eq 'grade' || $target eq 'answer' ||
580: $target eq 'analyze'|| $target eq 'webgrade') {
1.122 albertel 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);
1.134 albertel 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: }
1.122 albertel 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: }
1.123 albertel 604:
605: sub start_algebra {
606: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
607: my $result = '';
1.137 albertel 608: if ( $target eq 'web' || $target eq 'tex' ||
609: $target eq 'grade' || $target eq 'answer' ||
610: $target eq 'analyze' || $target eq 'webgrade') {
1.123 albertel 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') {
1.125 albertel 614: my $style=&Apache::lonxml::get_param('style',$parstack,$safeeval);
615: $result=&Apache::lontexconvert::algebra($inside,$target,$style);
1.123 albertel 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:
1.1 albertel 628: 1;
629: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>