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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.4     ! albertel    4: # $Id: bridgetask.pm,v 1.3 2005/03/17 21:56:04 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: 	$result='<table border="1"><tr><td>Closing</td></tr><tr><td>';
                    177:     }
                    178:     return $result;
                    179: }
                    180: 
                    181: sub end_ClosingParagraph {
                    182:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    183:     my $result;
                    184:     if ($target eq 'web') {
                    185: 	$result='</td></tr></table>';
                    186:     }
                    187:     return $result;
                    188: }
                    189: 
                    190: my %dimension;
                    191: my $dim_id;
                    192: sub start_Dimension {
                    193:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    194:     undef(%dimension);
                    195:     $dim_id=$Apache::lonxml::curdepth;
                    196:     return '';
                    197: }
                    198: 
                    199: sub end_Dimension {
                    200:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    201:     my $result;
                    202:     if ($target eq 'web') {
                    203: 	#FIXME just grabbing the first one for now, need
                    204: 	#to randomly pick one until all have been seen
                    205: 	#then start repicking
                    206: 	my $instance=$dimension{'instances'}->[0];
1.2       albertel  207: 	$result=$dimension{'intro'}.
1.1       albertel  208: 	    $dimension{$instance.'.text'}.
                    209: 	    '<table border="1"><tr><td>Criteria</td></tr><tr><td>';
                    210: 	foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                    211: 	    $result.=$dimension{$instance.'.criteria.'.$id}.
                    212: 		'</td></tr><tr><td>';
                    213: 	}
                    214: 	$result=~s/<tr><td>$//;
                    215: 	$result.='</table>';
                    216:     }
                    217:     return $result;
                    218: }
                    219: 
                    220: sub start_IntroParagraph {
                    221:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    222:     my $result;
                    223:     if ($target eq 'web') {
                    224: 	if ($tagstack->[-2] eq 'Dimension') {
                    225: 	    &Apache::lonxml::startredirection();
                    226: 	} else {
                    227: 	    $result='<table border="1"><tr><td>Intro</td></tr><tr><td>';
                    228: 	}
                    229:     }
                    230:     return $result;
                    231: }
                    232: 
                    233: sub end_IntroParagraph {
                    234:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    235:     my $result;
                    236:     if ($target eq 'web') {
                    237: 	if ($tagstack->[-2] eq 'Dimension') {
                    238: 	    $dimension{'intro'}=&Apache::lonxml::endredirection();
                    239: 	} else {
                    240: 	    $result='</td></tr></table>';
                    241: 	}
                    242:     }
                    243:     return $result;
                    244: }
                    245: 
                    246: my $instance_id;
                    247: sub start_Instance {
                    248:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    249:     push(@{$dimension{'instances'}},$Apache::lonxml::curdepth);
                    250:     $instance_id=$Apache::lonxml::curdepth;
                    251:     return '';
                    252: }
                    253: 
                    254: sub end_Instance {
                    255:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    256:     return '';
                    257: }
                    258: 
                    259: sub start_InstanceText {
                    260:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    261:     if ($target eq 'web') {
                    262: 	&Apache::lonxml::startredirection();
                    263:     }
                    264:     return '';
                    265: }
                    266: 
                    267: sub end_InstanceText {
                    268:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    269:     if ($target eq 'web') {
                    270: 	$dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
                    271:     }
                    272:     return '';
                    273: }
                    274: 
                    275: sub start_Criteria {
                    276:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    277:     if ($target eq 'web') {
                    278: 	&Apache::lonxml::startredirection();
                    279:     }
                    280:     return '';
                    281: }
                    282: 
                    283: sub end_Criteria {
                    284:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    285:     if ($target eq 'web') {
                    286: 	my $criteria=&Apache::lonxml::endredirection();
                    287: 	my $id=$Apache::lonxml::curdepth;
                    288: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
                    289: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
                    290:     }
                    291:     return '';
                    292: }
                    293: 
1.4     ! albertel  294: sub proctor_validation_screen {
        !           295:     my ($slot) = @_;
        !           296:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
        !           297:     my $ret=&Apache::lonnet::reply("studentphoto:$domain:$user:gif",&Apache::lonnet::homeserver($user,$domain));
        !           298:     my $url="/uploaded/$domain/$user/internal/studentphoto.gif";
        !           299:     my $tokenurl=&Apache::lonnet::tokenwrapper($url);
        !           300:     my $dom=(&Apache::lonxml::whichuser())[2];
        !           301:     my $user=$ENV{'form.proctorname'};
        !           302:     if ($ENV{'form.proctordomain'}) { $dom=$ENV{'form.proctordomain'}; }
        !           303:     my $msg;
        !           304:     if ($ENV{'form.proctorpassword'}) {
        !           305: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
        !           306: 	    .'</font></p>';
        !           307:     }
        !           308:     my $result= (<<ENDCHECKOUT);
        !           309: <h2>Proctor Validation</h2>
        !           310:     <p>Your room's proctor needs to validate your access to this resource.</p>
        !           311:     $msg
        !           312: <form name="checkout" method="POST" action="$ENV{'request.uri'}">
        !           313: <input type="hidden" name="validate" value="yes" />
        !           314: <input type="hidden" name="submitted" value="yes" />
        !           315: <table>
        !           316:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
        !           317:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
        !           318:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$dom" /></td></tr>
        !           319: </table>
        !           320: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
        !           321: Student who should be logged in is:<br />
        !           322: <img src="$tokenurl" /><br />
        !           323: </form>
        !           324: ENDCHECKOUT
        !           325:     return $result;
        !           326: }
        !           327: 
1.1       albertel  328: 1;
                    329: __END__

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