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