File:
[LON-CAPA] /
loncom /
xml /
scripttag.pm
Revision
1.90:
download - view:
text,
annotated -
select for diffs
Fri May 23 16:26:28 2003 UTC (21 years, 3 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_0_99_0,
HEAD
- fixes BUG#1364, produces an error messages if a duplicated id is seen while in CSTR space and viewing a problem.
- now tracks all part numbers seen, and tracks all import ids seen
- properly use @Apace::inputtags::response for the list of response ids in this part
and responselist for all ids in the problem
1: # The LearningOnline Network with CAPA
2: # <script> definiton
3: #
4: # $Id: scripttag.pm,v 1.90 2003/05/23 16:26:28 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # 2/21 Guy
29: # 8/20 Gerd Kortemeyer
30:
31: package Apache::scripttag;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::style;
36:
37: #Globals
38: # this used to pass around the standard callsub arguments to a tag func
39: # so xmlparse can reenter the inner_xmlparse loop.
40:
41: @Apache::scripttag::parser_env = ();
42: BEGIN {
43: &Apache::lonxml::register('Apache::scripttag',
44: ('script','scriptlib','parserlib','import',
45: 'window','display','storetc','physnet',
46: 'standalone','comment',
47: 'LONCAPA_INTERNAL_TURN_STYLE_ON',
48: 'LONCAPA_INTERNAL_LONHTTPD_PORT'));
49: }
50:
51: sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
52: $Apache::lonxml::usestyle=1;
53: $Apache::lonxml::style_values='';
54: return ('','no');
55: }
56:
57: sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
58: return ('','no');
59: }
60:
61: sub start_LONCAPA_INTERNAL_LONHTTPD_PORT {
62: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
63: if ($target eq 'web') {
64: my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
65: if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
66: return '<script type="text/javascript">var lonhttpdport=\''.
67: $lonhttpdPort.'\';</script>';
68: }
69: return ('','no');
70: }
71:
72: sub end_LONCAPA_INTERNAL_LONHTTPD_PORT {
73: return ('','no');
74: }
75:
76: sub start_script {
77: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
78: @Apache::scripttag::parser_env = @_;
79: my $result='';
80: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
81: &Apache::lonxml::debug("found type of $type");
82: if ($type eq "loncapa/perl") {
83: my $bodytext=&Apache::lonxml::get_all_text("/script",$parser);
84: if ( $target eq "modified" ) {
85: $result=$token->[4].&Apache::edit::modifiedfield();
86: } elsif ( $target eq 'web' || $target eq 'tex' ||
87: $target eq 'grade' || $target eq 'answer' ||
88: $target eq 'analyze' ) {
89: if (!$Apache::lonxml::default_homework_loaded) {
90: &Apache::lonxml::default_homework_load($safeeval);
91: }
92: &Apache::run::run($bodytext,$safeeval);
93: if (($target eq 'answer') &&
94: ($ENV{'form.answer_output_mode'} ne 'tex') &&
95: ($Apache::lonhomework::viewgrades == 'F')) {
96: $Apache::lonxml::evaluate--;
97: $result.="<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor="#FFFFFF"><pre>";
98: my $listing= &HTML::Entities::encode(&Apache::run::dump($target,$safeeval));
99:
100: $result.=$listing;
101: $result.= "</pre></body></html>\');newWindow.document.close();void(0);\">Script Vars</a><br />";
102: }
103: } elsif ($target eq "edit" ) {
104: #&Apache::run::run($bodytext,$safeeval);
105: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
106: $result=&Apache::edit::tag_start($target,$token,'Script');
107: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
108: }
109: } else {
110: if ($target ne "meta") {
111: $result = $token->[4];
112: my $bodytext=&Apache::lonxml::get_all_text("/script",$parser);
113: $result.=$bodytext;
114: }
115: }
116: return $result;
117: }
118:
119: sub end_script {
120: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
121: if ( $target eq "meta" ) { return ''; }
122: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
123: my $result='';
124: #other script blocks need to survive
125: if ($type ne "loncapa/perl") {
126: return $token->[2];
127: } elsif ($target eq 'edit' ) {
128: return &Apache::edit::end_table();
129: } elsif ($target eq 'answer') {
130: $Apache::lonxml::evaluate++;
131: }
132: return '';
133: }
134:
135: sub start_display {
136: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
137:
138: my $result;
139: my $bodytext=&Apache::lonxml::get_all_text("/display",$parser);
140:
141: if ( $target eq "modified" ) {
142: $result=$token->[4].&Apache::edit::modifiedfield();
143: } elsif ( $target eq 'web' || $target eq 'tex' ||
144: $target eq 'grade' || $target eq 'answer' ||
145: $target eq 'analyze') {
146: if (!$Apache::lonxml::default_homework_loaded) {
147: &Apache::lonxml::default_homework_load($safeeval);
148: }
149: $result=&Apache::run::run($bodytext,$safeeval);
150: if ($target eq 'grade' || $target eq 'answer' ||
151: $target eq 'analyze') {
152: $result=''; # grade should produce no output
153: }
154: } elsif ($target eq "edit" ) {
155: #$result =
156: # "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
157: #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
158: $result=&Apache::edit::tag_start($target,$token,'Script With Display');
159: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
160: }
161: return $result;
162: }
163:
164: sub end_display {
165: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
166: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
167: return '';
168: }
169:
170: sub start_scriptlib {
171: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
172: my $bodytext;
173: my $result ='';
174: my $error='';
175:
176: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' ||
177: $target eq 'edit' || $target eq 'answer' || $target eq 'analyze') {
178: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
179: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
180: $$parstack[$#$parstack]);
181: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
182: $bodytext);
183: my $script=&Apache::lonnet::getfile($location);
184: if ($script == -1) {
185: if ($target eq 'edit') {
186: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
187: } else {
188: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
189: return "";
190: }
191: }
192: &Apache::run::run($script,$safeeval);
193: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
194: }
195: if ($target eq "edit" ) {
196: $result=
197: &Apache::edit::tag_start($target,$token,'New Script Functions').
198: &Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
199: &Apache::edit::browse(undef,'textnode').
200: $error.'</td></tr>'.
201: &Apache::edit::end_table();
202: }
203: if ($target eq "modified" ) {
204: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
205: $result=$token->[4].&Apache::edit::modifiedfield($token);
206: &Apache::lonxml::debug($result);
207: }
208: return $result;
209: }
210:
211: sub end_scriptlib {
212: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
213: my @result;
214: if ($target eq "edit" ) { $result[1]='no'; }
215: return @result;
216: }
217:
218: sub start_parserlib {
219: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
220: my $bodytext;
221: my $result ="";
222: my $error='';
223: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' ||
224: $target eq 'edit' || $target eq 'answer' || $target eq 'analyze') {
225: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
226: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
227: $$parstack[$#$parstack]);
228: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
229: $bodytext);
230: my $styletext=&Apache::lonnet::getfile($location);
231: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
232: if ($styletext == -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 parserlib</b>");
237: return "";
238: }
239: }
240: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
241: }
242: if ($target eq "edit" ) {
243: $result=
244: &Apache::edit::tag_start($target,$token,'New Tag Definitions').
245: &Apache::edit::editline($token->[1],$bodytext,'',40).
246: $error.'</td></tr>'.
247: &Apache::edit::end_table();
248: }
249: if ($target eq "modified" ) {
250: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
251: $result=$token->[4].&Apache::edit::modifiedfield($token);
252: &Apache::lonxml::debug($result);
253: }
254: return $result;
255: }
256:
257: sub end_parserlib {
258: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
259: my @result;
260: if ($target eq "edit" ) { $result[1]='no'; }
261: return @result;
262: }
263:
264: sub start_window {
265: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
266: my $result = '';
267: if ($target eq 'web') {
268: &Apache::lonxml::startredirection;
269: } elsif ($target eq 'tex') {
270: $result = '\unskip\footnote{';
271: }
272: return $result;
273: }
274:
275: sub end_window {
276: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
277: my $result;
278: if ($target eq 'web') {
279: my $output=&Apache::lonxml::endredirection;
280: $output =~ s/\"/\"\;/g;
281: $result = "<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor="#FFFFFF"> $output </body></html>\');newWindow.document.close();void(0);\"><sup>*</sup></a>";
282: } elsif ($target eq 'tex') {
283: $result = '}';
284: } else {
285: $result = '';
286: }
287: return $result;
288: }
289:
290: sub start_import {
291: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
292: my $bodytext=$$parser[$#$parser]->get_text("/import");
293: my $result ="";
294:
295: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
296:
297: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
298: $target eq 'tex' || $target eq 'analyze' ) {
299: # FIXME this probably needs to be smart about construction vs.
300: # non construction space.
301: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
302: my $file=&Apache::lonnet::getfile($location);
303: if ($file == -1) {
304: &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
305: return "";
306: }
307:
308: my $dir=$location;
309: $dir=~s:/[^/]*$::;
310: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
311: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
312: if (!$id) { $id=$Apache::lonxml::curdepth; }
313: push(@Apache::inputtags::import,$id);
314: push(@Apache::inputtags::importlist,$id);
315:
316: &Apache::lonxml::newparser($parser,\$file,$dir);
317:
318: } elsif ($target eq "edit" ) {
319: $result.=&Apache::edit::tag_start($target,$token);
320: $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
321: $result.=&Apache::edit::browse(undef,'textnode');
322: #FIXME this need to convert $bodytext to be a contruction space reference
323: #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
324: #$result.="Click<a href=\"$location\">here</a> to edit<br />"
325: } elsif ($target eq 'modified') {
326: $bodytext=$$parser[$#$parser]->get_text("/import");
327: $result=$token->[4].&Apache::edit::modifiedfield($token);
328: &Apache::lonxml::debug($result);
329: } elsif ($target eq 'meta') {
330: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
331: $result.='<import part="'.$Apache::inputtags::part;
332: if ($id) {
333: $result.='" id="'.$id;
334: }
335: $result.='">';
336: $result.=$bodytext;
337: $result.='</import>';
338: }
339: return $result;
340: }
341:
342: sub end_import {
343: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
344: pop(@Apache::inputtags::import);
345: my $result;
346: if ($target eq 'edit' ) { $result=&Apache::edit::end_table(); }
347: return $result;
348: }
349:
350: sub start_storetc {
351: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
352: my $result = '';
353: &Apache::lonxml::startredirection;
354: return $result;
355: }
356:
357: sub end_storetc {
358: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
359: my $result;
360: my $output=&Apache::lonxml::endredirection;
361: $output =~ s/\"/\"\;/g;
362: $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
363: return $result;
364: }
365:
366:
367: sub start_physnet {
368: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
369: my $bodytext = '/adm/includes/physnet.sty';
370: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
371: my $cbistyletext=&Apache::lonnet::getfile($location);
372:
373: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
374: $$parser['-1']->unget_token($token);
375: # if ( defined($$style{'physnet'}) ) {
376: # &Apache::lonxml::newparser($parser,\$$style{'physnet'});
377: # }
378: return "";
379: }
380:
381: sub end_physnet {
382: return '';
383: }
384:
385: sub start_standalone {
386: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
387: my $result='';
388: if ($target eq 'web' ) {
389: if ( $ENV{'request.course.id'} ) {
390: my $inside = &Apache::lonxml::get_all_text("/standalone",$parser);
391: } else {
392: $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
393: }
394: }
395: return $result;
396: }
397:
398: sub end_standalone {
399: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
400: my $result='';
401: if ($target eq 'web' ) {
402: if ( $ENV{'request.course.id'} ) {
403: } else {
404: $result='</td></tr></table>';
405: }
406: }
407: return $result;
408: }
409:
410: sub start_comment {
411: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
412: my $result='';
413: if ($target eq 'edit') {
414: $result=&Apache::edit::tag_start($target,$token);
415: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser);
416: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
417: } elsif ( $target eq 'modified') {
418: $result=$token->[4].&Apache::edit::modifiedfield($token);
419: } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
420: $target eq 'answer' || $target eq 'meta' || $target eq 'analyze') {
421: #normally throw away comments
422: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser);
423: }
424: return $result;
425: }
426:
427: sub end_comment {
428: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
429: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
430: return '';
431: }
432:
433:
434: sub xmlparse {
435: my ($string) = @_;
436: # &Apache::lonxml::debug("Got $string");
437: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
438: @Apache::scripttag::parser_env;
439: my @parser;
440: &Apache::lonxml::newparser(\@parser,\$string);
441: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
442: $parstack,\@parser,
443: $safeeval,$style);
444: return $result;
445: }
446:
447: 1;
448: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>