1: # The LearningOnline Network with CAPA
2: # <script> definiton
3:
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: }
14:
15: sub start_script {
16: my ($target,$token,$parstack,$parser,$safeeval)=@_;
17: my $result="";
18: my $bodytext=$$parser[$#$parser]->get_text("/script");
19: if ($target ne "edit" ) {
20: $result = &Apache::run::run($bodytext,$safeeval);
21: } else {
22: $result=&editfield($token->[1],$bodytext);
23: }
24: return $result;
25: }
26:
27: sub end_script {}
28:
29: sub start_scriptlib {
30: my ($target,$token,$parstack,$parser,$safeeval)=@_;
31: my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
32: my $result ="";
33: if ($target ne "edit" ) {
34: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
35: &Apache::run::run(&getfile($bodytext),$safeeval);
36: #print "ran $bodytext:<br>".&getfile($bodytext)."<br>";
37: } else {
38: $result=&editfield($token->[1],$bodytext);
39: }
40: return $result;
41: }
42:
43: sub end_scriptlib {}
44:
45: sub start_parserlib {
46: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
47: my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
48: my $result ="";
49: if ($target ne "edit" ) {
50: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
51: %$style = ( %$style , &Apache::style::styleparser($target,
52: &getfile($bodytext)));
53: } else {
54: $result=&editfield($token->[1],$bodytext);
55: }
56: return $result;
57: }
58:
59: sub end_parserlib {
60: }
61:
62: sub start_import {
63: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
64: my $bodytext=$$parser[$#$parser]->get_text("/import");
65: my $result ="";
66: if ($target ne "edit" ) {
67: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
68: my $file=&getfile($bodytext);
69: my $tempparser=HTML::TokeParser->new(\$file);
70: push (@$parser,$tempparser);
71: } else {
72: $result=&editfield($token->[1],$bodytext);
73: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
74: }
75: }
76:
77: sub end_import {
78: }
79:
80: sub editfield {
81: my ($tag,$data)=@_;
82:
83: my $count=0;
84: my $maxlength=-1;
85: map { $count++;
86: if (length($_) > $maxlength) { $maxlength = length ($_); }
87: } split ("\n", $data);
88:
89: return "<br></br>\n<$tag><br></br>\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br></br>\n</$tag><br></br>\n";
90: }
91:
92: sub getfile {
93: my ($filename) = @_;
94: my $a="";
95:
96: $filename=~ s/\s+//g;
97: $filename="/home/httpd/html/res".$filename;
98: if (! -e $filename ) {
99: &Apache::lonnet::subscribe($filename);
100: &Apache::lonnet::repcopy($filename);
101: }
102: my $fh=Apache::File->new($filename);
103: while (<$fh>) {
104: $a .=$_;
105: }
106: return $a
107: }
108:
109: 1;
110: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>