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