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