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