Annotation of loncom/homework/bridgetask.pm, revision 1.7

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.7     ! albertel    4: # $Id: bridgetask.pm,v 1.6 2005/03/28 21:50:46 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: 
1.4       albertel   44: sub proctor_check_auth {
                     45:     my ($slot)=@_;
                     46:     my $user=$ENV{'form.proctorname'};
                     47:     my $domain=$ENV{'form.proctordomain'};
                     48:     
                     49:     my @allowed=split(",",$slot->{'proctor'});
                     50:     foreach my $possible (@allowed) {
                     51: 	my ($puser,$pdom)=(split('@',$possible));
                     52: 	if ($puser eq $user && $pdom eq $domain) {
                     53: 	    my $authhost=&Apache::lonnet::authenticate($puser,$ENV{'form.proctorpassword'},$pdom);
                     54: 	    if ($authhost ne 'no_host') {
                     55: 		$Apache::lonhomework::results{'resource.checkedin'}=
                     56: 		    $user.'@'.$domain;
                     57: 		return 1;
                     58: 	    }
                     59: 	}
                     60:     }
                     61:     return 0;
                     62: }
                     63: 
1.1       albertel   64: sub start_Task {
                     65:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     66: 
1.4       albertel   67:     &Apache::structuretags::initialize_storage();
                     68:     &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.1       albertel   69: 
1.4       albertel   70:     my ($status,$accessmsg,$slot);
                     71:     $Apache::lonhomework::parsing_a_task=1;
1.1       albertel   72:     #should get back a <html> or the neccesary stuff to start XML/MathML
                     73:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                     74: 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
                     75: 
                     76:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                     77: 	$target eq 'tex') {
1.4       albertel   78: 	($status,$accessmsg,$slot) = 
                     79: 	    &Apache::lonhomework::check_task_access('0');
1.1       albertel   80: 	push (@Apache::inputtags::status,$status);
                     81: 	my $expression='$external::datestatus="'.$status.'";';
                     82: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
                     83: 	&Apache::run::run($expression,$safeeval);
                     84: 	&Apache::lonxml::debug("Got $status");
                     85: 	if (( $status eq 'CLOSED' ) ||
                     86: 	    ( $status eq 'BANNED') ||
                     87: 	    ( $status eq 'UNAVAILABLE') ||
1.3       albertel   88: 	    ( $status eq 'NOT_IN_A_SLOT') ||
1.4       albertel   89: 	    ( $status eq 'NEEDS_CHECKIN') ||
1.1       albertel   90: 	    ( $status eq 'INVALID_ACCESS')) {
                     91: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                     92: 	    if ( $target eq "web" ) {
1.4       albertel   93: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
                     94: 		my $msg;
1.1       albertel   95: 		if ($status eq 'UNAVAILABLE') {
                     96: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel   97: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                     98: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4       albertel   99: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    100: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    101: 			'</h1>'.&proctor_validation_screen($slot);
1.1       albertel  102: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    103: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    104: 		}
                    105: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    106: 		    $msg.='The problem '.$accessmsg;
                    107: 		}
                    108: 		$result.=$msg.'<br />';
                    109: 	    } elsif ($target eq 'tex') {
                    110: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    111: 		if ($status eq 'UNAVAILABLE') {
                    112: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    113: 		} else {
                    114: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    115: 		}
1.4       albertel  116: 	    } elsif ($target eq 'grade') {
                    117: 		if ($status eq 'NEEDS_CHECKIN') {
                    118: 		    if (&proctor_check_auth($slot)) {
                    119: 			#FIXME immeadiatly add this to the grading queue
                    120:                         #      with slot->{'endtime'} for when grading can 
                    121:                         #      begin on this resource
                    122:  		    }
                    123: 		}
1.1       albertel  124: 	    }
                    125: 	} elsif ($target eq 'web') {
                    126: 	    my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    127: 	    $result.="$head_tag_start<title>$name</title></head>
                    128:               $body_tag_start \n $form_tag_start".	
                    129: 	      '<input type="hidden" name="submitted" value="yes" />';
                    130: 	    # if we are viewing someone else preserve that info
                    131: 	    if (defined $ENV{'form.grade_symb'}) {
                    132: 		foreach my $field ('symb','courseid','domain','username') {
                    133: 		    $result .= '<input type="hidden" name="grade_'.$field.
                    134: 			'" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
                    135: 		}
                    136: 	    }
                    137: 	}
                    138:     } else {
                    139: 	# page_start returned a starting result, delete it if we don't need it
                    140: 	$result = '';
                    141:     }
                    142:     return $result;
                    143: }
                    144: 
                    145: sub end_Task {
                    146:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    147:     my $result='';
                    148:     my $status=$Apache::inputtags::status['-1'];
                    149:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
                    150: 	$target eq 'tex') {
                    151: 	if (
                    152: 	    (($target eq 'web') && ($ENV{'request.state'} ne 'construct')) ||
                    153: 	    ($target eq 'answer') || ($target eq 'tex')
                    154: 	   ) {
                    155: 	    if ($target eq 'web') {
                    156: 		$result.=&Apache::lonxml::xmlend().'</html>';
                    157: 	    }
                    158: 	}
                    159: 	if ($target eq 'grade') {
1.4       albertel  160: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    161: 	    &Apache::structuretags::finalize_storage();
1.1       albertel  162: 	}
                    163:     } elsif ($target eq 'meta') {
1.2       albertel  164: 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1       albertel  165: 	#$result.=&Apache::response::meta_part_order();
                    166: 	#$result.=&Apache::response::meta_response_order();
                    167:     }
1.4       albertel  168:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel  169:     return $result;
                    170: }
                    171: 
                    172: sub start_ClosingParagraph {
                    173:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    174:     my $result;
                    175:     if ($target eq 'web') {
                    176:     }
                    177:     return $result;
                    178: }
                    179: 
                    180: sub end_ClosingParagraph {
                    181:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    182:     my $result;
                    183:     if ($target eq 'web') {
                    184:     }
                    185:     return $result;
                    186: }
                    187: 
                    188: my %dimension;
                    189: my $dim_id;
                    190: sub start_Dimension {
                    191:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    192:     undef(%dimension);
                    193:     $dim_id=$Apache::lonxml::curdepth;
                    194:     return '';
                    195: }
                    196: 
                    197: sub end_Dimension {
                    198:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    199:     my $result;
                    200:     if ($target eq 'web') {
                    201: 	#FIXME just grabbing the first one for now, need
                    202: 	#to randomly pick one until all have been seen
                    203: 	#then start repicking
                    204: 	my $instance=$dimension{'instances'}->[0];
1.2       albertel  205: 	$result=$dimension{'intro'}.
1.7     ! albertel  206: 	    $dimension{$instance.'.text'};
        !           207: 	#FIXME: don't show the criteria yet
        !           208: 	#foreach my $id (@{$dimension{$instance.'.criterias'}}) {
        !           209: 	#    $result.=$dimension{$instance.'.criteria.'.$id};
        !           210: 	#}
1.1       albertel  211:     }
                    212:     return $result;
                    213: }
                    214: 
                    215: sub start_IntroParagraph {
                    216:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    217:     my $result;
                    218:     if ($target eq 'web') {
                    219: 	if ($tagstack->[-2] eq 'Dimension') {
                    220: 	    &Apache::lonxml::startredirection();
                    221: 	}
                    222:     }
                    223:     return $result;
                    224: }
                    225: 
                    226: sub end_IntroParagraph {
                    227:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    228:     my $result;
                    229:     if ($target eq 'web') {
                    230: 	if ($tagstack->[-2] eq 'Dimension') {
                    231: 	    $dimension{'intro'}=&Apache::lonxml::endredirection();
                    232: 	}
                    233:     }
                    234:     return $result;
                    235: }
                    236: 
                    237: my $instance_id;
                    238: sub start_Instance {
                    239:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    240:     push(@{$dimension{'instances'}},$Apache::lonxml::curdepth);
                    241:     $instance_id=$Apache::lonxml::curdepth;
                    242:     return '';
                    243: }
                    244: 
                    245: sub end_Instance {
                    246:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    247:     return '';
                    248: }
                    249: 
                    250: sub start_InstanceText {
                    251:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    252:     if ($target eq 'web') {
                    253: 	&Apache::lonxml::startredirection();
                    254:     }
                    255:     return '';
                    256: }
                    257: 
                    258: sub end_InstanceText {
                    259:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    260:     if ($target eq 'web') {
                    261: 	$dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
                    262:     }
                    263:     return '';
                    264: }
                    265: 
                    266: sub start_Criteria {
                    267:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    268:     if ($target eq 'web') {
                    269: 	&Apache::lonxml::startredirection();
                    270:     }
                    271:     return '';
                    272: }
                    273: 
                    274: sub end_Criteria {
                    275:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    276:     if ($target eq 'web') {
                    277: 	my $criteria=&Apache::lonxml::endredirection();
                    278: 	my $id=$Apache::lonxml::curdepth;
                    279: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
                    280: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
                    281:     }
                    282:     return '';
                    283: }
                    284: 
1.4       albertel  285: sub proctor_validation_screen {
                    286:     my ($slot) = @_;
                    287:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel  288:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.6       albertel  289:     $user=$ENV{'form.proctorname'};
                    290:     if ($ENV{'form.proctordomain'}) { $domain=$ENV{'form.proctordomain'}; }
1.4       albertel  291:     my $msg;
                    292:     if ($ENV{'form.proctorpassword'}) {
                    293: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                    294: 	    .'</font></p>';
                    295:     }
                    296:     my $result= (<<ENDCHECKOUT);
                    297: <h2>Proctor Validation</h2>
                    298:     <p>Your room's proctor needs to validate your access to this resource.</p>
                    299:     $msg
                    300: <form name="checkout" method="POST" action="$ENV{'request.uri'}">
                    301: <input type="hidden" name="validate" value="yes" />
                    302: <input type="hidden" name="submitted" value="yes" />
                    303: <table>
                    304:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
                    305:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6       albertel  306:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4       albertel  307: </table>
                    308: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
                    309: Student who should be logged in is:<br />
1.5       albertel  310: <img src="$url" /><br />
1.4       albertel  311: </form>
                    312: ENDCHECKOUT
                    313:     return $result;
                    314: }
                    315: 
1.1       albertel  316: 1;
                    317: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>