Annotation of loncom/xml/scripttag.pm, revision 1.41
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # <script> definiton
1.34 albertel 3: # 2/21 Guy
1.1 albertel 4:
5: package Apache::scripttag;
6:
7: use strict;
1.3 albertel 8: use Apache::lonnet;
1.1 albertel 9:
10: sub BEGIN {
1.6 albertel 11: &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
1.20 sakharuk 12: 'parserlib','import',
1.32 albertel 13: 'window','display'));
1.1 albertel 14: }
15:
16: sub start_script {
1.40 albertel 17: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.24 albertel 18: my $result='';
1.39 albertel 19: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
20: &Apache::lonxml::debug("found type of $type");
1.17 albertel 21: if ($type eq "loncapa/perl") {
1.21 albertel 22: my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
1.17 albertel 23: if ( $target eq "modified" ) {
1.41 ! albertel 24: $result=$token->[4].&Apache::edit::modifiedfield();
1.28 albertel 25: } elsif ( $target eq "web" || $target eq "grade" ) {
26: &Apache::run::run($bodytext,$safeeval);
27: } elsif ($target eq "edit" ) {
1.41 ! albertel 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);
1.17 albertel 32: }
33: } else {
1.28 albertel 34: if ($target ne "meta") { $result = $token->[4]; }
1.13 albertel 35: }
1.24 albertel 36: return $result;
1.17 albertel 37: }
1.13 albertel 38:
1.17 albertel 39: sub end_script {
1.40 albertel 40: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.28 albertel 41: if ( $target eq "meta" ) { return ''; }
1.39 albertel 42: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.29 albertel 43: my $result='';
44: #other script blocks need to survive
45: if ($type ne "loncapa/perl") { return $token->[2]; }
1.41 ! albertel 46: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
1.28 albertel 47: return '';
1.24 albertel 48: }
49:
50: sub start_display {
1.40 albertel 51: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.39 albertel 52:
1.24 albertel 53: my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
1.39 albertel 54:
1.24 albertel 55: if ( $target eq "modified" ) {
56: }
57: my $result=&Apache::run::run($bodytext,$safeeval);
1.26 albertel 58: if ($target eq 'grade' ) {
59: # grade should produce no output
60: $result='';
61: }
1.24 albertel 62: if ($target eq "edit" ) {
63: $result =
1.33 albertel 64: "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
1.38 albertel 65: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
1.24 albertel 66: }
67: return $result;
68: }
69:
70: sub end_display {
1.38 albertel 71: return ''
1.1 albertel 72: }
1.3 albertel 73:
74: sub start_scriptlib {
1.40 albertel 75: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 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 />");
1.18 albertel 97: }
1.13 albertel 98: if ($target eq "edit" ) {
1.37 albertel 99: $result=
1.38 albertel 100: &Apache::edit::tag_start($target,$token).
101: &Apache::edit::editfield($token->[1],$bodytext,'New Script Functions',40,1).
1.37 albertel 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);
1.3 albertel 108: }
109: return $result;
110: }
111:
1.37 albertel 112: sub end_scriptlib {
1.40 albertel 113: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 114: my $result='';
115: # if ($target eq "edit" ) { $result=" "; }
116: return $result;
117: }
1.4 albertel 118:
119: sub start_parserlib {
1.40 albertel 120: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 121: my $bodytext;
1.7 albertel 122: my $result ="";
1.37 albertel 123: my $error='';
1.13 albertel 124:
1.37 albertel 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));
1.18 albertel 142: }
1.13 albertel 143: if ($target eq "edit" ) {
1.37 albertel 144: $result=
1.38 albertel 145: &Apache::edit::tag_start($target,$token).
146: &Apache::edit::editfield($token->[1],$bodytext,"New Tag Definitions",40,1).
1.37 albertel 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);
1.7 albertel 153: }
154: return $result;
1.4 albertel 155: }
156:
157: sub end_parserlib {
1.40 albertel 158: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 159: my $result='';
160: # if ($target eq "edit" ) {
1.38 albertel 161: # $result=&Apache::edit::tag_end($target,$token);
1.37 albertel 162: # }
163: return $result;
1.6 albertel 164: }
165:
1.30 sakharuk 166: sub start_window {
1.40 albertel 167: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.20 sakharuk 168: my $result = '';
1.31 albertel 169: if ($target eq 'web') {
1.34 albertel 170: &Apache::lonxml::startredirection;
1.35 sakharuk 171: } elsif ($target eq 'tex') {
172: $result = '\footnote{';
173: }
1.19 sakharuk 174: return $result;
175: }
176:
1.30 sakharuk 177: sub end_window {
1.40 albertel 178: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30 sakharuk 179: my $result;
1.31 albertel 180: if ($target eq 'web') {
1.34 albertel 181: my $output=&Apache::lonxml::endredirection;
182: $output =~ s/\"/\"\;/g;
1.35 sakharuk 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 = '}';
1.30 sakharuk 186: } else {
1.35 sakharuk 187: $result = '';
1.30 sakharuk 188: }
1.20 sakharuk 189: return $result;
1.19 sakharuk 190: }
191:
1.6 albertel 192: sub start_import {
1.40 albertel 193: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 194: my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7 albertel 195: my $result ="";
1.13 albertel 196:
197: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.18 albertel 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 "";
1.14 albertel 203: }
204:
1.18 albertel 205: my $dir=$location;
1.30 sakharuk 206: $dir=~s:/[^/]*$::;
207: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
1.18 albertel 208: &Apache::lonxml::newparser($parser,\$file,$dir);
1.13 albertel 209:
210: if ($target eq "edit" ) {
1.38 albertel 211: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
1.33 albertel 212: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br />"
1.7 albertel 213: }
1.27 albertel 214: return '';
1.6 albertel 215: }
216:
217: sub end_import {
1.7 albertel 218: }
1.30 sakharuk 219:
220: sub start_meta {
1.40 albertel 221: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30 sakharuk 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 {
1.1 albertel 233: }
1.3 albertel 234:
1.1 albertel 235: 1;
236: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>