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

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

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