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