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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.28    ! albertel    4: # $Id: bridgetask.pm,v 1.27 2005/05/20 18:07:29 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=();
1.20      albertel   51:     # mandatory attribute of all Dimensions seen
                     52:     %Apache::bridgetask::dimensionmandatory=();
1.9       albertel   53:     # list of all current Instance ids
                     54:     @Apache::bridgetask::instance=();
                     55:     # list of all Instance ids seen in this problem
                     56:     @Apache::bridgetask::instancelist=();
1.15      albertel   57:     # key of queud user data that we are currently grading
                     58:     $Apache::bridgetask::queue_key='';
1.9       albertel   59: }
                     60: 
1.4       albertel   61: sub proctor_check_auth {
1.22      albertel   62:     my ($slot_name,$slot)=@_;
1.11      albertel   63:     my $user=$env{'form.proctorname'};
                     64:     my $domain=$env{'form.proctordomain'};
1.4       albertel   65:     
                     66:     my @allowed=split(",",$slot->{'proctor'});
                     67:     foreach my $possible (@allowed) {
                     68: 	my ($puser,$pdom)=(split('@',$possible));
                     69: 	if ($puser eq $user && $pdom eq $domain) {
1.11      albertel   70: 	    my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4       albertel   71: 	    if ($authhost ne 'no_host') {
1.23      albertel   72: 		my $version=
                     73: 		    $Apache::lonhomework::results{'resource.version'}=
1.27      albertel   74: 		    ++$Apache::lonhomework::history{'resource.version'};
1.23      albertel   75: 		$Apache::lonhomework::results{"resource.$version.checkedin"}=
1.4       albertel   76: 		    $user.'@'.$domain;
1.23      albertel   77: 		$Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
1.22      albertel   78: 		    $slot_name;
1.28    ! albertel   79: 		foreach my $key (keys(%Apache::lonhomework::history)) {
        !            80: 		    if ($key=~/^resource\.0\./) {
        !            81: 			$Apache::lonhomework::results{$key}='';
        !            82: 		    }
        !            83: 		}
1.4       albertel   84: 		return 1;
                     85: 	    }
                     86: 	}
                     87:     }
                     88:     return 0;
                     89: }
                     90: 
1.25      albertel   91: sub get_version {
                     92:     if ($env{'form.previousversion'} && 
                     93: 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
                     94: 	return $env{'form.previousversion'};
                     95:     }
                     96:     return $Apache::lonhomework::history{'resource.version'};
                     97: }
                     98: 
1.8       albertel   99: sub add_previous_version_button {
1.25      albertel  100:     my ($status)=@_;
1.8       albertel  101:     my $result;
1.25      albertel  102:     if ($Apache::lonhomework::history{'resource.version'} eq '0') {
                    103: 	return '';
                    104:     }
                    105:     my $version=&get_version();
                    106:     if ($version ne $Apache::lonhomework::history{'resource.version'}) {
                    107: 	return '';
                    108:     }
                    109: 
1.9       albertel  110:     $result.=&mt(' Show a previously done version: [_1]','<select name="previousversion">
1.8       albertel  111: <option>Pick one</option>
1.9       albertel  112: </select>');
1.8       albertel  113:     return $result;
                    114: }
                    115: 
1.13      albertel  116: sub add_grading_button {
                    117:     my $result;
                    118:     $result.=' <input type="submit" name="gradeasubmission" value="'.
                    119: 	&mt("Get a submission to grade").'" />';
                    120:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
                    121:     return $result;
                    122: }
                    123: 
1.22      albertel  124: sub add_request_another_attempt_button {
1.25      albertel  125:     my $result;
                    126:     $result.=' <input type="submit" name="requestattempt" value="'.
                    127: 	&mt("Request another attempt").'" />';
                    128:     return $result;
1.22      albertel  129: }
                    130: 
1.1       albertel  131: sub start_Task {
                    132:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    133: 
1.4       albertel  134:     my ($status,$accessmsg,$slot);
1.16      albertel  135:     if ($target ne 'webgrade') {
                    136: 	&Apache::structuretags::initialize_storage();
                    137: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
                    138:     } 
                    139: 
1.4       albertel  140:     $Apache::lonhomework::parsing_a_task=1;
1.1       albertel  141:     #should get back a <html> or the neccesary stuff to start XML/MathML
                    142:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    143: 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16      albertel  144:     
1.8       albertel  145:     if ($target eq 'web') {
1.13      albertel  146: 	if ($Apache::lonhomework::modifygrades) {
                    147: 	    $body_tag_start.='<form name="gradesubmission" method="POST" action="';
                    148: 	    my $uri=$env{'request.uri'};
                    149: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    150: 	    $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
                    151: 	}
1.8       albertel  152:     }
1.21      albertel  153:     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1       albertel  154: 	$target eq 'tex') {
1.25      albertel  155: 	my $version=&get_version();
1.14      albertel  156: 	($status,$accessmsg,my $slot_name,$slot) = 
1.4       albertel  157: 	    &Apache::lonhomework::check_task_access('0');
1.9       albertel  158: 	push(@Apache::inputtags::status,$status);
1.14      albertel  159: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  160: 	my $expression='$external::datestatus="'.$status.'";';
1.23      albertel  161: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1       albertel  162: 	&Apache::run::run($expression,$safeeval);
                    163: 	&Apache::lonxml::debug("Got $status");
1.25      albertel  164: 	$body_tag_start.=&add_previous_version_button($status);
1.1       albertel  165: 	if (( $status eq 'CLOSED' ) ||
                    166: 	    ( $status eq 'BANNED') ||
                    167: 	    ( $status eq 'UNAVAILABLE') ||
1.3       albertel  168: 	    ( $status eq 'NOT_IN_A_SLOT') ||
1.4       albertel  169: 	    ( $status eq 'NEEDS_CHECKIN') ||
1.22      albertel  170: 	    ( $status eq 'WAITING_FOR_GRADE') ||
1.1       albertel  171: 	    ( $status eq 'INVALID_ACCESS')) {
                    172: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    173: 	    if ( $target eq "web" ) {
1.4       albertel  174: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
                    175: 		my $msg;
1.1       albertel  176: 		if ($status eq 'UNAVAILABLE') {
                    177: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  178: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    179: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4       albertel  180: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    181: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    182: 			'</h1>'.&proctor_validation_screen($slot);
1.22      albertel  183: 		} elsif ($status eq 'WAITING_FOR_GRADE') {
                    184: 		    $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1       albertel  185: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    186: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    187: 		}
                    188: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    189: 		    $msg.='The problem '.$accessmsg;
                    190: 		}
                    191: 		$result.=$msg.'<br />';
                    192: 	    } elsif ($target eq 'tex') {
                    193: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    194: 		if ($status eq 'UNAVAILABLE') {
                    195: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    196: 		} else {
                    197: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    198: 		}
1.22      albertel  199: 	    } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4       albertel  200: 		if ($status eq 'NEEDS_CHECKIN') {
1.22      albertel  201: 		    if (&proctor_check_auth($slot_name,$slot)) {
1.4       albertel  202: 			#FIXME immeadiatly add this to the grading queue
                    203:                         #      with slot->{'endtime'} for when grading can 
                    204:                         #      begin on this resource
1.22      albertel  205: 			# FIXME I think the above is done by default,
                    206:                         #        need to check that
                    207:                         #        failure doesn't do this.
1.4       albertel  208:  		    }
                    209: 		}
1.1       albertel  210: 	    }
                    211: 	} elsif ($target eq 'web') {
                    212: 	    my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    213: 	    $result.="$head_tag_start<title>$name</title></head>
                    214:               $body_tag_start \n $form_tag_start".	
                    215: 	      '<input type="hidden" name="submitted" value="yes" />';
                    216: 	    # if we are viewing someone else preserve that info
1.11      albertel  217: 	    if (defined $env{'form.grade_symb'}) {
1.1       albertel  218: 		foreach my $field ('symb','courseid','domain','username') {
                    219: 		    $result .= '<input type="hidden" name="grade_'.$field.
1.11      albertel  220: 			'" value="'.$env{"form.grade_$field"}.'" />'."\n";
1.1       albertel  221: 		}
                    222: 	    }
1.25      albertel  223: 	    my $version=&get_version();
                    224: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22      albertel  225: 		$result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
1.25      albertel  226: 		$result.=&add_request_another_attempt_button();
1.22      albertel  227: 	    }
1.25      albertel  228: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
1.22      albertel  229: 		$result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
                    230: 	    }
1.1       albertel  231: 	}
1.21      albertel  232:     } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                    233: 	      $target eq 'webgrade') {
                    234: 	if ($target eq 'webgrade') {
                    235: 	    $result.=$head_tag_start.$body_tag_start.$form_tag_start;
                    236: 	    $result.='<input type="hidden" name="webgrade" value="yes" />';
                    237: 	    $result.=&show_queue();
                    238: 	}
1.15      albertel  239: 	my $todo=&get_from_queue();
                    240: 	if ($todo) {
1.16      albertel  241: 	    &setup_env_for_other_user($todo,$safeeval);
1.15      albertel  242: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
1.16      albertel  243: 	    $result.="\n".'<table><tr><td>Found '.
                    244: 		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
1.15      albertel  245: 	    $result.='<input type="hidden" name="gradingkey" value="'.
1.16      albertel  246: 		&Apache::lonnet::escape($todo).'" />';
1.15      albertel  247: 	    $Apache::bridgetask::queue_key=$todo;
1.16      albertel  248: 	    &Apache::structuretags::initialize_storage();
                    249: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.18      albertel  250: 	    $result.="\n".'<table width="100%" style="width:100%" border="1">';
1.15      albertel  251: 	} else {
1.21      albertel  252: 	    if ($target eq 'webgrade') {
                    253: 		$result.="\n".
                    254: 		    '<table><tr><td>No user to be graded.</td></tr></table>';
                    255: 	    }
1.15      albertel  256: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    257: 	}
1.1       albertel  258:     } else {
                    259: 	# page_start returned a starting result, delete it if we don't need it
                    260: 	$result = '';
                    261:     }
                    262:     return $result;
                    263: }
                    264: 
                    265: sub end_Task {
                    266:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    267:     my $result='';
                    268:     my $status=$Apache::inputtags::status['-1'];
1.25      albertel  269:     my $version=&get_version();
1.1       albertel  270:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel  271: 	$target eq 'tex') {
1.1       albertel  272: 	if (
1.11      albertel  273: 	    (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1       albertel  274: 	    ($target eq 'answer') || ($target eq 'tex')
                    275: 	   ) {
                    276: 	    if ($target eq 'web') {
1.9       albertel  277: 		if ($status eq 'CAN_ANSWER') {
1.15      albertel  278: 		    $result.="\n".'<table border="1">'.
1.28    ! albertel  279: 			&Apache::inputtags::file_selector("$version.0",
        !           280: 							  "bridgetask","*",
1.9       albertel  281: 							  'portfolioonly').
                    282: 							  "</table>";
                    283: 		    $result.=&Apache::inputtags::gradestatus('0');
                    284: 		}
1.13      albertel  285: 	    } 
                    286: 	    if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  287: 		$result.=&Apache::lonxml::xmlend().'</html>';
                    288: 	    }
                    289: 	}
1.20      albertel  290: 	if ($target eq 'grade' && !$env{'form.webgrade'}) {
1.12      albertel  291: 	    my $award='SUBMITTED';
1.28    ! albertel  292: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20      albertel  293: 						    'portfiles',\$award);
1.14      albertel  294: 	    if ($award eq 'SUBMITTED' &&
1.28    ! albertel  295: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
        !           296: 		$Apache::lonhomework::results{"resource.0.tries"}=
        !           297: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
        !           298: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
        !           299: 
        !           300: 		$Apache::lonhomework::results{"resource.0.award"}=
        !           301: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
        !           302: 		    $award;
1.10      albertel  303: 	    }
1.4       albertel  304: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    305: 	    &Apache::structuretags::finalize_storage();
1.14      albertel  306: 	    if ($award eq 'SUBMITTED') {
                    307: 		&add_to_queue();
                    308: 	    }
1.1       albertel  309: 	}
1.20      albertel  310: 	if ($target eq 'grade' && $env{'form.webgrade'}) {
                    311: 	    my $optional_required=
                    312: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                    313: 					   $safeeval);
                    314: 	    my $optional_passed=0;
                    315: 	    my $mandatory_failed=0;
                    316: 	    my $ungraded=0;
                    317: 	    my $review=0;   
1.21      albertel  318: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20      albertel  319: 	    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
                    320: 		my $status=
1.25      albertel  321: 		    $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20      albertel  322: 		my $mandatory=
                    323: 		    ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
                    324: 		if ($status eq 'pass') {
                    325: 		    if (!$mandatory) { $optional_passed++; }
                    326: 		} elsif ($status eq 'fail') {
                    327: 		    if ($mandatory) { $mandatory_failed++; }
                    328: 		} elsif ($status eq 'ungraded') {
                    329: 		    $ungraded++;
                    330: 		} elsif ($status eq 'review') {
                    331: 		    $review++;
                    332: 		}	
                    333: 	    }
                    334: 	    if ($optional_passed < $optional_required) {
                    335: 		$mandatory_failed++;
                    336: 	    }
1.21      albertel  337: 	    &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
                    338: 	    $Apache::lonhomework::results{'resource.grader'}=
1.20      albertel  339: 		$env{'user.name'}.'@'.$env{'user.domain'};
                    340: 	    if ($review) {
1.25      albertel  341: 		$Apache::lonhomework::results{"resource.$version.status"}='review';
1.20      albertel  342: 		&move_to_review_queue();
                    343: 	    } elsif ($ungraded) {
1.25      albertel  344: 		$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.20      albertel  345: 		&check_queue_unlock();
                    346: 	    } elsif ($mandatory_failed) {
1.25      albertel  347: 		$Apache::lonhomework::results{"resource.$version.status"}='fail';
                    348: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                    349: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                    350: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.20      albertel  351: 		&remove_from_queue();
                    352: 	    } else {
1.25      albertel  353: 		$Apache::lonhomework::results{"resource.$version.status"}='pass';
                    354: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                    355: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                    356: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.20      albertel  357: 		&remove_from_queue();
                    358: 	    }
1.26      albertel  359: 	    $Apache::lonhomework::results{"resource.status"}=
                    360: 		$Apache::lonhomework::results{"resource.$version.status"};
1.28    ! albertel  361: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel  362: 		$Apache::lonhomework::results{"resource.0.award"}=
                    363: 		    $Apache::lonhomework::results{"resource.$version.award"};
                    364: 		$Apache::lonhomework::results{"resource.0.awarded"}=
                    365: 		    $Apache::lonhomework::results{"resource.$version.awarded"};
                    366: 		$Apache::lonhomework::results{"resource.0.solved"}=
                    367: 		    $Apache::lonhomework::results{"resource.$version.solved"};
1.25      albertel  368: 	    }
1.21      albertel  369: 	    &Apache::structuretags::finalize_storage();
1.20      albertel  370: 	}
1.15      albertel  371:     } elsif ($target eq 'webgrade') {
1.18      albertel  372: 	$result.="</table>\n<hr />";
1.20      albertel  373: 	#$result.='<input type="submit" name="next" value="'.
                    374: 	#    &mt('Save &amp; Next').'" /> ';
                    375: 	#$result.='<input type="submit" name="end" value="'.
                    376: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                    377: 	#$result.='<input type="submit" name="throwaway" value="'.
                    378: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                    379: 	#$result.='<input type="submit" name="save" value="'.
                    380: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15      albertel  381: 	$result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1       albertel  382:     } elsif ($target eq 'meta') {
1.2       albertel  383: 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1       albertel  384: 	#$result.=&Apache::response::meta_part_order();
                    385: 	#$result.=&Apache::response::meta_response_order();
                    386:     }
1.4       albertel  387:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel  388:     return $result;
                    389: }
                    390: 
1.21      albertel  391: sub move_to_review_queue {
                    392:     &Apache::lonxml::debug("Want to move");
                    393: }
                    394: 
                    395: sub check_queue_unlock {
                    396:     &Apache::lonxml::debug("Want to unlock?");
                    397: }
                    398: 
                    399: sub remove_from_queue {
1.27      albertel  400:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    401:     my $cnum=$env{'course.'.$cid.'.num'};
                    402:     my $cdom=$env{'course.'.$cid.'.domain'};
                    403:     my $key="$symb\0queue\0$uname\@$udom";
                    404:     my @keys=($key,"$key\0locked");
                    405:     &Apache::lonnet::del('gradingqueue',\@keys,$cdom,$cnum);
1.21      albertel  406: }
                    407: 
1.16      albertel  408: sub setup_env_for_other_user {
                    409:     my ($queue_key,$safeeval)=@_;
                    410:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
                    411:     $env{'form.grade_symb'}=$symb;
                    412:     $env{'form.grade_domain'}=$udom;
                    413:     $env{'form.grade_username'}=$uname;
                    414:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                    415:     &Apache::lonxml::initialize_rndseed($safeeval);
                    416: }
                    417: 
1.14      albertel  418: sub add_to_queue {
                    419:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    420:     my $cnum=$env{'course.'.$cid.'.num'};
                    421:     my $cdom=$env{'course.'.$cid.'.domain'};
                    422:     my %data;
                    423:     $data{"$symb\0queue\0$uname\@$udom"}=[$Apache::inputtags::slot_name];
                    424:     &Apache::lonnet::put('gradingqueue',\%data,$cdom,$cnum);
                    425: }
                    426: 
                    427: sub show_queue {
                    428:     my $result;
                    429:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    430:     my $cnum=$env{'course.'.$cid.'.num'};
                    431:     my $cdom=$env{'course.'.$cid.'.domain'};
1.16      albertel  432:     my $regexp="^$symb\0";
1.14      albertel  433:     my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
1.27      albertel  434:     $result.="\n<h3>Current Queue</h3><table border='1'><tr><th>resource</th>".
1.20      albertel  435: 	"<th>user</th><th>type</th><th>data</th></tr>";
1.14      albertel  436:     foreach my $key (sort(keys(%queue))) {
1.16      albertel  437: 	if ($key=~/locked$/) {
                    438: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    439: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  440: 	    $result.="<tr><td>$title</td><td>$uname</td>";
1.16      albertel  441: 	    $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
                    442: 	} elsif ($key=~/timestamp$/) {
                    443: 	    my ($symb,undef) = split("\0",$key);
                    444: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  445: 	    $result.="<tr><td>$title</td><td></td>";
1.16      albertel  446: 	    $result.='<td>last queue modification time</td><td>'.
                    447: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
                    448: 	} else {
                    449: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    450: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  451: 	    $result.="<tr><td>$title</td><td>$uname</td>";
1.16      albertel  452: 	    my $slot=$queue{$key}->[0];
                    453: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
1.27      albertel  454: 	    $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20      albertel  455: 		&Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
                    456: 		"</td></tr>";
1.16      albertel  457: 	}
1.14      albertel  458:     }
1.15      albertel  459:     $result.="</table><hr />\n";
1.14      albertel  460:     return $result;
                    461: }
                    462: 
                    463: sub decode_queue_key {
                    464:     my ($key)=@_;
                    465:     my ($symb,undef,$user) = split("\0",$key);
                    466:     my ($uname,$udom) = split('@',$user);
                    467:     return ($symb,$uname,$udom);
                    468: }
                    469: 
                    470: sub queue_key_locked {
1.15      albertel  471:     my ($key,$cdom,$cnum)=@_;
1.14      albertel  472:     my ($key_locked,$value)=
                    473: 	&Apache::lonnet::get('gradingqueue',["$key\0locked"],$cdom,$cnum);
                    474:     if ($key_locked eq "$key\0locked") {
                    475: 	return $value;
                    476:     }
                    477:     return undef;
                    478: }
                    479: 
                    480: sub pick_from_queue_data {
1.15      albertel  481:     my ($check_section,$queue,$cdom,$cnum)=@_;
1.16      albertel  482:     foreach my $key (keys(%$queue)) {
1.14      albertel  483: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
                    484: 	if ($check_section) {
                    485: 	    my $section=&Apache::lonnet::getsection($uname,$udom);
1.17      albertel  486: 	    if ($section eq $check_section) {
                    487: 		&Apache::lonnet::logthis("my sec");
1.15      albertel  488: 		next;
                    489: 	    }
1.14      albertel  490: 	}
                    491: 	my $slot=$queue->{$key}[0];
                    492: 	my %slot_data=&Apache::lonnet::get_slot($slot);
1.15      albertel  493: 	if ($slot_data{'endtime'} > time) { 
                    494: 	    &Apache::lonnet::logthis("not time");
                    495: 	    next;
                    496: 	}
                    497: 	if (&queue_key_locked($key,$cdom,$cnum)) {
                    498: 	    &Apache::lonnet::logthis("someone already has um.");
                    499: 	    next;
                    500: 	}
1.14      albertel  501: 	return $key;
                    502:     }
                    503:     return undef;
                    504: }
                    505: 
1.15      albertel  506: sub find_mid_grade {
                    507:     my ($symb,$cdom,$cnum)=@_;
1.16      albertel  508:     my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15      albertel  509:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    510:     if ($todo) {
                    511: 	my $who=&queue_key_locked($todo,$cdom,$cnum);
                    512: 	if ($who eq $me) { return $todo; }
                    513:     }
                    514:     my $regexp="^$symb\0.*\0locked\$";
                    515:     my %locks=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
                    516:     foreach my $key (keys(%locks)) {
                    517: 	my $who=$locks{$key};
                    518: 	if ($who eq $me) {
                    519: 	    $todo=$key;
                    520: 	    $todo=~s/\0locked$//;
                    521: 	    return $todo;
                    522: 	}
                    523:     }
                    524:     return undef;
                    525: }
                    526: 
1.14      albertel  527: sub get_from_queue {
                    528:     my $result;
                    529:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    530:     my $cnum=$env{'course.'.$cid.'.num'};
                    531:     my $cdom=$env{'course.'.$cid.'.domain'};
                    532:     my $todo;
1.15      albertel  533:     # FIXME need to find if I am 'mid grading'
                    534:     $todo=&find_mid_grade($symb,$cdom,$cnum);
                    535:     &Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo)));
1.16      albertel  536:     if ($todo) { return $todo; }
1.14      albertel  537:     while (1) {
                    538: 	my $starttime=time;
                    539: 	&Apache::lonnet::put('gradingqueue',{"$symb\0timestamp"=>$starttime},
                    540: 			     $cdom,$cnum);
1.15      albertel  541: 	&Apache::lonnet::logthis("$starttime");
1.14      albertel  542: 	my $regexp="^$symb\0queue\0";
                    543: 	my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
                    544: 	#make a pass looking for a user in my section
                    545: 	if ($env{'request.course.sec'}) {
1.15      albertel  546: 	    &Apache::lonnet::logthis("sce");
                    547: 	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
                    548: 					$cdom,$cnum);
                    549: 	    &Apache::lonnet::logthis("sce $todo");
1.14      albertel  550: 	}
                    551: 	# no one in our section so look for any user that is ready for grading
                    552: 	if (!$todo) {
1.15      albertel  553: 	    &Apache::lonnet::logthis("no sce");
                    554: 	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
                    555: 					$cdom,$cnum);
                    556: 	    &Apache::lonnet::logthis("no sce $todo");
1.14      albertel  557: 	}
                    558: 	# no user to grade 
                    559: 	if (!$todo) { last; }
1.15      albertel  560: 	&Apache::lonnet::logthis("got $todo");
1.14      albertel  561: 	# otherwise found someone so lets try to lock them
                    562: 	my $success=&Apache::lonnet::newput('gradingqueue',
                    563: 					    {"$todo\0locked"=>
                    564: 						 $env{'user.name'}.'@'.$env{'user.domain'}},
                    565: 					   $cdom,$cnum);
                    566: 	# someone else already picked them
1.15      albertel  567: 	&Apache::lonnet::logthis("success $todo");
1.14      albertel  568: 	if ($success ne 'ok') { next; }
                    569: 	my (undef,$endtime)=
                    570: 	    &Apache::lonnet::get('gradingqueue',["$symb\0timestamp"],
                    571: 				 $cdom,$cnum);
1.15      albertel  572: 	&Apache::lonnet::logthis("emd  $endtime");
1.14      albertel  573: 	# someone else already modified the queue, 
                    574: 	# perhaps our picked user wass already fully graded between
                    575: 	# when we picked him and when we locked his record? so lets
                    576: 	# double check.
                    577: 	if ($endtime != $starttime) {
                    578: 	    my ($key,$value)=
                    579: 		&Apache::lonnet::get('gradingqueue',["$todo"],
                    580: 				     $cdom,$cnum);
1.15      albertel  581: 	    &Apache::lonnet::logthis("check  $key .. $value");
1.14      albertel  582: 	    if ($key eq $todo && ref($value)) {
                    583: 	    } else {
                    584: 		&Apache::lonnet::del('gradingqueue',["$todo\0locked"],
                    585: 				     $cdom,$cnum);
1.15      albertel  586: 		&Apache::lonnet::logthis("del");
1.14      albertel  587: 		next;
                    588: 	    }
                    589: 	}
1.15      albertel  590: 	&Apache::lonnet::logthis("last $todo");
1.14      albertel  591: 	last;
                    592:     }
                    593:     return $todo;
                    594: }
                    595: 
1.1       albertel  596: sub start_ClosingParagraph {
                    597:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    598:     my $result;
                    599:     if ($target eq 'web') {
1.13      albertel  600:     } elsif ($target eq 'webgrade') {
                    601: 	&Apache::lonxml::startredirection();
1.1       albertel  602:     }
                    603:     return $result;
                    604: }
                    605: 
                    606: sub end_ClosingParagraph {
                    607:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    608:     my $result;
                    609:     if ($target eq 'web') {
1.13      albertel  610:     } elsif ($target eq 'webgrade') {
                    611: 	&Apache::lonxml::endredirection();
1.1       albertel  612:     }
                    613:     return $result;
                    614: }
                    615: 
1.19      albertel  616: sub get_id {
                    617:     my ($parstack,$safeeval)=@_;
                    618:     my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
                    619:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                    620:     return $id;
                    621: }
                    622: 
1.1       albertel  623: my %dimension;
                    624: sub start_Dimension {
                    625:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    626:     undef(%dimension);
1.19      albertel  627:     my $dim_id=&get_id($parstack,$safeeval);
1.9       albertel  628:     $Apache::bridgetask::dimension=$dim_id;
                    629:     push(@Apache::bridgetask::dimensionlist,$dim_id);
                    630:     undef(@Apache::bridgetask::instance);
1.20      albertel  631:     $Apache::bridgetask::dimensionmandatory{$dim_id}=
                    632: 	&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel  633:     return '';
                    634: }
                    635: 
1.13      albertel  636: sub get_instance {
                    637:     #FIXME just grabbing the first one for now, need
                    638:     #to randomly pick one until all have been seen
                    639:     #then start repicking
                    640:     &Apache::response::pushrandomnumber();
                    641:     my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
                    642:     return $order[0];
                    643: }
                    644: 
1.18      albertel  645: {
                    646:     my $last_link;
                    647:     sub end_Dimension {
                    648: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    649: 	my $result;
1.25      albertel  650: 	my $dim=&get_id($parstack,$safeeval);
1.19      albertel  651: 	my $instance=&get_instance();
1.25      albertel  652: 	my $version=&get_version();
1.18      albertel  653: 	if ($target eq 'web') {
                    654: 	    $result=$dimension{'intro'}.$dimension{$instance.'.text'};
1.26      albertel  655: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
                    656: 		$Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22      albertel  657: 		foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel  658: 		    my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
                    659: 		    my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.22      albertel  660: 		    $result.='<table border="1"><tr><td>';
                    661: 		    if ($status eq 'fail') {
                    662: 			$result.='<font color="red">'.&mt('Did not pass').'</font>';
                    663: 		    } elsif ($status eq 'pass') {
                    664: 			$result.='<font color="green">'.&mt('Passed').'</font>';
                    665: 		    } else {
                    666: 			&Apache::lonxml::error("Student viewing a graded bridgetask was show a status of $status");
                    667: 		    }
                    668: 		    $result.='</td></tr><tr><td>';
1.25      albertel  669: 		    if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
                    670: 			$result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</td></tr><tr><td>';
1.22      albertel  671: 		    }
                    672: 		    $result.=$dimension{$instance.'.criteria.'.$id}.
                    673: 			'</td></tr></table>';
                    674: 		}
                    675: 	    }
1.18      albertel  676: 	} elsif ($target eq 'webgrade') {
                    677: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                    678: 		my $link='criteria_'.$instance.'_'.$id;
1.25      albertel  679: 		my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19      albertel  680: 		$result.='<tr><td width="100%" valign="top">'.
1.18      albertel  681: 		    '<a name="'.$link.'" />'.
                    682: 		    '<a name="next_'.$last_link.'" />'.
                    683: 		    '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">'.$dimension{$instance.'.criteria.'.$id}.'</textarea>'.
                    684: 		    #$dimension{$instance.'.criteria.'.$id}.
                    685: 		    '</td>'.
1.19      albertel  686: 		    '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25      albertel  687: 		    '<textarea style="width:100%" rows="8" width="25" wrap="hard" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}).'</textarea>'.
1.18      albertel  688: 		    '</td>'.
                    689: 		    '<td>'.
1.20      albertel  690: 		    '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').'/>Ungraded</label></nobr><br />'.
                    691: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />Pass</label><br />'.
                    692: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />Fail</label><br />'.
                    693: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />Review</label><br />'.
1.18      albertel  694: 		    '</td>'.
                    695: 		    '<td>'.
                    696: 		    '<a href="#'.$last_link.'">Prev</a><br />'.
1.20      albertel  697: 		    '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
                    698: 		    '<input type="submit" name="next" value="'.
                    699: 		    &mt('Done').'" /> '.
1.18      albertel  700: 		    '</td></tr>';
1.22      albertel  701: 		$result.='<tr><td colspan="4">';
                    702: 		my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
                    703: 		my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
1.23      albertel  704: 		foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.bridgetask.portfiles"})) {
1.22      albertel  705: 		    my $file=$file_url.$partial_file;
                    706: 		    &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
                    707: 		    $result.='<a href="'.$file.'" target="lonGRDs"><img src="'.
                    708: 			&Apache::loncommon::icon($file).'" border=0"> '.$file.
                    709: 			'</a>';
                    710: 		}
                    711: 		$result.='</td></tr>';
1.18      albertel  712: 		$last_link=$link;
                    713: 	    }
1.22      albertel  714: 	} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19      albertel  715: 	    my $optional_passed=0;
1.20      albertel  716: 	    my $mandatory_failed=0;
                    717: 	    my $ungraded=0;
                    718: 	    my $review=0;
1.19      albertel  719: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel  720: 		my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
                    721: 		$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20      albertel  722: 		my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
                    723: 		if ($status eq 'pass') {
                    724: 		    if (!$mandatory) { $optional_passed++; }
                    725: 		} elsif ($status eq 'fail') {
                    726: 		    if ($mandatory) { $mandatory_failed++; }
1.21      albertel  727: 		} elsif ($status eq 'review') {
                    728: 		    $review++;
1.20      albertel  729: 		} elsif ($status eq 'ungraded') {
                    730: 		    $ungraded++;
1.21      albertel  731: 		} else {
1.22      albertel  732: 		    &Apache::lonxml::error("got weird status --$status--");
1.19      albertel  733: 		}
                    734: 	    }
1.20      albertel  735: 	    if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
                    736: 		$mandatory_failed++;
                    737: 	    }
1.21      albertel  738: 	    &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.20      albertel  739: 	    if ($review) {
1.25      albertel  740: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel  741: 		    'review';
1.20      albertel  742: 	    } elsif ($ungraded) {
1.25      albertel  743: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel  744: 		    'ungraded';
1.20      albertel  745: 	    } elsif ($mandatory_failed) {
1.25      albertel  746: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel  747: 		    'fail';
1.20      albertel  748: 	    } else {
1.25      albertel  749: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel  750: 		    'pass';
1.20      albertel  751: 	    }
1.13      albertel  752: 	}
1.18      albertel  753: 	return $result;
1.1       albertel  754:     }
                    755: }
                    756: 
                    757: sub start_IntroParagraph {
                    758:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    759:     my $result;
1.13      albertel  760:     if ($target eq 'web' || $target eq 'webgrade') {
                    761: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel  762: 	    &Apache::lonxml::startredirection();
                    763: 	}
                    764:     }
                    765:     return $result;
                    766: }
                    767: 
                    768: sub end_IntroParagraph {
                    769:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    770:     my $result;
1.13      albertel  771:     if ($target eq 'web' || $target eq 'webgrade') {
                    772: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel  773: 	    $dimension{'intro'}=&Apache::lonxml::endredirection();
                    774: 	}
                    775:     }
                    776:     return $result;
                    777: }
                    778: 
                    779: sub start_Instance {
                    780:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel  781:     my $id=&get_id($parstack,$safeeval);
                    782:     push(@{$dimension{'instances'}},$id);
                    783:     push(@Apache::bridgetask::instance,$id);
                    784:     push(@Apache::bridgetask::instancelist,$id);
1.20      albertel  785:     $dimension{$id.'.optionalrequired'}=
1.19      albertel  786: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1       albertel  787:     return '';
                    788: }
                    789: 
                    790: sub end_Instance {
                    791:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    792:     return '';
                    793: }
                    794: 
                    795: sub start_InstanceText {
                    796:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13      albertel  797:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  798: 	&Apache::lonxml::startredirection();
                    799:     }
                    800:     return '';
                    801: }
                    802: 
                    803: sub end_InstanceText {
                    804:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel  805:     my $instance_id=$Apache::bridgetask::instance[-1];
1.13      albertel  806:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  807: 	$dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
                    808:     }
                    809:     return '';
                    810: }
                    811: 
                    812: sub start_Criteria {
                    813:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.21      albertel  814:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1       albertel  815: 	&Apache::lonxml::startredirection();
                    816:     }
                    817:     return '';
                    818: }
                    819: 
                    820: sub end_Criteria {
                    821:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel  822:     my $instance_id=$Apache::bridgetask::instance[-1];
1.21      albertel  823:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1       albertel  824: 	my $criteria=&Apache::lonxml::endredirection();
1.19      albertel  825: 	my $id=&get_id($parstack,$safeeval);
1.1       albertel  826: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19      albertel  827: 	$dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
                    828: 	    &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel  829: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
                    830:     }
                    831:     return '';
                    832: }
                    833: 
1.4       albertel  834: sub proctor_validation_screen {
                    835:     my ($slot) = @_;
                    836:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel  837:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11      albertel  838:     $user=$env{'form.proctorname'};
                    839:     if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4       albertel  840:     my $msg;
1.11      albertel  841:     if ($env{'form.proctorpassword'}) {
1.4       albertel  842: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                    843: 	    .'</font></p>';
                    844:     }
                    845:     my $result= (<<ENDCHECKOUT);
                    846: <h2>Proctor Validation</h2>
                    847:     <p>Your room's proctor needs to validate your access to this resource.</p>
                    848:     $msg
1.11      albertel  849: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4       albertel  850: <input type="hidden" name="validate" value="yes" />
                    851: <input type="hidden" name="submitted" value="yes" />
                    852: <table>
                    853:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
                    854:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6       albertel  855:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4       albertel  856: </table>
                    857: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
                    858: Student who should be logged in is:<br />
1.5       albertel  859: <img src="$url" /><br />
1.4       albertel  860: </form>
                    861: ENDCHECKOUT
                    862:     return $result;
                    863: }
                    864: 
1.1       albertel  865: 1;
                    866: __END__

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