Annotation of loncom/homework/bridgetask.pm, revision 1.2
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.2 ! albertel 4: # $Id: bridgetask.pm,v 1.1 2005/03/16 19:09:44 albertel Exp $
1.1 albertel 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: ###
29:
30:
31: package Apache::bridgetask;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::File();
36: use Apache::lonmenu;
37: use Apache::lonlocal;
38: use Apache::lonxml;
39: use Time::HiRes qw( gettimeofday tv_interval );
40: BEGIN {
41: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
42: }
43:
44: sub start_Task {
45: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
46:
47: #&initialize_storage();
48:
49: my $status;
50: my $accessmsg;
51:
52: #should get back a <html> or the neccesary stuff to start XML/MathML
53: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
54: &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
55:
56: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
57: $target eq 'tex') {
58: ($status,$accessmsg) = &Apache::lonhomework::check_task_access('0');
59: push (@Apache::inputtags::status,$status);
60: my $expression='$external::datestatus="'.$status.'";';
61: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
62: &Apache::run::run($expression,$safeeval);
63: &Apache::lonxml::debug("Got $status");
64: if (( $status eq 'CLOSED' ) ||
65: ( $status eq 'BANNED') ||
66: ( $status eq 'UNAVAILABLE') ||
67: ( $status eq 'INVALID_ACCESS')) {
68: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
69: if ( $target eq "web" ) {
70: $result.= $head_tag_start.'</head>';
71: my $msg=$body_tag_start;
72: if ($status eq 'UNAVAILABLE') {
73: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
74: } elsif ($status ne 'NOT_YET_VIEWED') {
75: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
76: }
77: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
78: $msg.='The problem '.$accessmsg;
79: }
80: $result.=$msg.'<br />';
81: } elsif ($target eq 'tex') {
82: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
83: if ($status eq 'UNAVAILABLE') {
84: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
85: } else {
86: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
87: }
88: }
89: } elsif ($target eq 'web') {
90: my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
91: $result.="$head_tag_start<title>$name</title></head>
92: $body_tag_start \n $form_tag_start".
93: '<input type="hidden" name="submitted" value="yes" />';
94: # if we are viewing someone else preserve that info
95: if (defined $ENV{'form.grade_symb'}) {
96: foreach my $field ('symb','courseid','domain','username') {
97: $result .= '<input type="hidden" name="grade_'.$field.
98: '" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
99: }
100: }
101: }
102: } else {
103: # page_start returned a starting result, delete it if we don't need it
104: $result = '';
105: }
106: return $result;
107: }
108:
109: sub end_Task {
110: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
111: my $result='';
112: my $status=$Apache::inputtags::status['-1'];
113: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
114: $target eq 'tex') {
115: if (
116: (($target eq 'web') && ($ENV{'request.state'} ne 'construct')) ||
117: ($target eq 'answer') || ($target eq 'tex')
118: ) {
119: if ($target eq 'web') {
120: $result.=&Apache::lonxml::xmlend().'</html>';
121: }
122: }
123: if ($target eq 'grade') {
124: #&Apache::lonhomework::showhash(%Apache::lonhomework::results);
125: #&finalize_storage();
126: }
127: } elsif ($target eq 'meta') {
1.2 ! albertel 128: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 129: #$result.=&Apache::response::meta_part_order();
130: #$result.=&Apache::response::meta_response_order();
131: }
132: return $result;
133: }
134:
135: sub start_ClosingParagraph {
136: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
137: my $result;
138: if ($target eq 'web') {
139: $result='<table border="1"><tr><td>Closing</td></tr><tr><td>';
140: }
141: return $result;
142: }
143:
144: sub end_ClosingParagraph {
145: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
146: my $result;
147: if ($target eq 'web') {
148: $result='</td></tr></table>';
149: }
150: return $result;
151: }
152:
153: my %dimension;
154: my $dim_id;
155: sub start_Dimension {
156: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
157: undef(%dimension);
158: $dim_id=$Apache::lonxml::curdepth;
159: return '';
160: }
161:
162: sub end_Dimension {
163: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
164: my $result;
165: if ($target eq 'web') {
166: #FIXME just grabbing the first one for now, need
167: #to randomly pick one until all have been seen
168: #then start repicking
169: my $instance=$dimension{'instances'}->[0];
1.2 ! albertel 170: $result=$dimension{'intro'}.
1.1 albertel 171: $dimension{$instance.'.text'}.
172: '<table border="1"><tr><td>Criteria</td></tr><tr><td>';
173: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
174: $result.=$dimension{$instance.'.criteria.'.$id}.
175: '</td></tr><tr><td>';
176: }
177: $result=~s/<tr><td>$//;
178: $result.='</table>';
179: }
180: return $result;
181: }
182:
183: sub start_IntroParagraph {
184: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
185: my $result;
186: if ($target eq 'web') {
187: if ($tagstack->[-2] eq 'Dimension') {
188: &Apache::lonxml::startredirection();
189: } else {
190: $result='<table border="1"><tr><td>Intro</td></tr><tr><td>';
191: }
192: }
193: return $result;
194: }
195:
196: sub end_IntroParagraph {
197: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
198: my $result;
199: if ($target eq 'web') {
200: if ($tagstack->[-2] eq 'Dimension') {
201: $dimension{'intro'}=&Apache::lonxml::endredirection();
202: } else {
203: $result='</td></tr></table>';
204: }
205: }
206: return $result;
207: }
208:
209: my $instance_id;
210: sub start_Instance {
211: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
212: push(@{$dimension{'instances'}},$Apache::lonxml::curdepth);
213: $instance_id=$Apache::lonxml::curdepth;
214: return '';
215: }
216:
217: sub end_Instance {
218: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
219: return '';
220: }
221:
222: sub start_InstanceText {
223: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
224: if ($target eq 'web') {
225: &Apache::lonxml::startredirection();
226: }
227: return '';
228: }
229:
230: sub end_InstanceText {
231: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
232: if ($target eq 'web') {
233: $dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
234: }
235: return '';
236: }
237:
238: sub start_Criteria {
239: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
240: if ($target eq 'web') {
241: &Apache::lonxml::startredirection();
242: }
243: return '';
244: }
245:
246: sub end_Criteria {
247: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
248: if ($target eq 'web') {
249: my $criteria=&Apache::lonxml::endredirection();
250: my $id=$Apache::lonxml::curdepth;
251: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
252: push(@{$dimension{$instance_id.'.criterias'}},$id);
253: }
254: return '';
255: }
256:
257: 1;
258: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>