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

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

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