1: # The LearningOnline Network with CAPA
2: # <script> definiton
3: # 2/21 Guy
4:
5: package Apache::scripttag;
6:
7: use strict;
8: use Apache::lonnet;
9:
10: sub BEGIN {
11: &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
12: 'parserlib','import',
13: 'window','display'));
14: }
15:
16: sub start_script {
17: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
18: my $result='';
19: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
20: &Apache::lonxml::debug("found type of $type");
21: if ($type eq "loncapa/perl") {
22: my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
23: if ( $target eq "modified" ) {
24: $result=$token->[4].&Apache::edit::modifiedfield();
25: } elsif ( $target eq "web" || $target eq "grade" ) {
26: &Apache::run::run($bodytext,$safeeval);
27: } elsif ($target eq "edit" ) {
28: #&Apache::run::run($bodytext,$safeeval);
29: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
30: $result=&Apache::edit::tag_start($target,$token,'Script');
31: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',50,4);
32: }
33: } else {
34: if ($target ne "meta") { $result = $token->[4]; }
35: }
36: return $result;
37: }
38:
39: sub end_script {
40: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
41: if ( $target eq "meta" ) { return ''; }
42: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
43: my $result='';
44: #other script blocks need to survive
45: if ($type ne "loncapa/perl") { return $token->[2]; }
46: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
47: return '';
48: }
49:
50: sub start_display {
51: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
52:
53: my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
54:
55: if ( $target eq "modified" ) {
56: }
57: my $result=&Apache::run::run($bodytext,$safeeval);
58: if ($target eq 'grade' ) {
59: # grade should produce no output
60: $result='';
61: }
62: if ($target eq "edit" ) {
63: $result =
64: "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
65: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
66: }
67: return $result;
68: }
69:
70: sub end_display {
71: return ''
72: }
73:
74: sub start_scriptlib {
75: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
76: my $bodytext;
77: my $result ='';
78: my $error='';
79:
80: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
81: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
82: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
83: $$parstack[$#$parstack]);
84: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
85: $bodytext);
86: my $script=&Apache::lonnet::getfile($location);
87: if ($script == -1) {
88: if ($target eq 'edit') {
89: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
90: } else {
91: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
92: return "";
93: }
94: }
95: &Apache::run::run($script,$safeeval);
96: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
97: }
98: if ($target eq "edit" ) {
99: $result=
100: &Apache::edit::tag_start($target,$token).
101: &Apache::edit::editfield($token->[1],$bodytext,'New Script Functions',40,1).
102: $error;
103: }
104: if ($target eq "modified" ) {
105: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
106: $result=&Apache::edit::modifiedfield($token);
107: &Apache::lonxml::debug($result);
108: }
109: return $result;
110: }
111:
112: sub end_scriptlib {
113: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
114: my $result='';
115: # if ($target eq "edit" ) { $result=" "; }
116: return $result;
117: }
118:
119: sub start_parserlib {
120: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
121: my $bodytext;
122: my $result ="";
123: my $error='';
124:
125: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
126: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
127: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
128: $$parstack[$#$parstack]);
129: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
130: $bodytext);
131: my $styletext=&Apache::lonnet::getfile($location);
132: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
133: if ($styletext == -1) {
134: if ($target eq 'edit') {
135: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
136: } else {
137: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
138: return "";
139: }
140: }
141: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
142: }
143: if ($target eq "edit" ) {
144: $result=
145: &Apache::edit::tag_start($target,$token).
146: &Apache::edit::editfield($token->[1],$bodytext,"New Tag Definitions",40,1).
147: $error;
148: }
149: if ($target eq "modified" ) {
150: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
151: $result=&Apache::edit::modifiedfield($token);
152: &Apache::lonxml::debug($result);
153: }
154: return $result;
155: }
156:
157: sub end_parserlib {
158: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
159: my $result='';
160: # if ($target eq "edit" ) {
161: # $result=&Apache::edit::tag_end($target,$token);
162: # }
163: return $result;
164: }
165:
166: sub start_window {
167: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
168: my $result = '';
169: if ($target eq 'web') {
170: &Apache::lonxml::startredirection;
171: } elsif ($target eq 'tex') {
172: $result = '\footnote{';
173: }
174: return $result;
175: }
176:
177: sub end_window {
178: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
179: my $result;
180: if ($target eq 'web') {
181: my $output=&Apache::lonxml::endredirection;
182: $output =~ s/\"/\"\;/g;
183: $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>";
184: } elsif ($target eq 'tex') {
185: $result = '}';
186: } else {
187: $result = '';
188: }
189: return $result;
190: }
191:
192: sub start_import {
193: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
194: my $bodytext=$$parser[$#$parser]->get_text("/import");
195: my $result ="";
196:
197: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
198: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
199: my $file=&Apache::lonnet::getfile($location);
200: if ($file == -1) {
201: &Apache::lonxml::error("<b> Unable to find <i>$bodytext $location</i> for import</b>");
202: return "";
203: }
204:
205: my $dir=$location;
206: $dir=~s:/[^/]*$::;
207: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
208: &Apache::lonxml::newparser($parser,\$file,$dir);
209:
210: if ($target eq "edit" ) {
211: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
212: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br />"
213: }
214: return '';
215: }
216:
217: sub end_import {
218: }
219:
220: sub start_meta {
221: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
222: my $result = '';
223: if ($target ne 'meta') {
224: $result = &Apache::lonxml::get_all_text("/meta",$$parser[$#$parser]);
225: $result = '';
226: return $result;
227: } else {
228: return $result;
229: }
230: }
231:
232: sub end_meta {
233: }
234:
235: 1;
236: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>