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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.77    ! albertel    4: # $Id: bridgetask.pm,v 1.76 2005/11/04 15:31:53 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;
1.37      albertel   39: use Apache::slotrequest();
1.1       albertel   40: use Time::HiRes qw( gettimeofday tv_interval );
1.9       albertel   41: 
1.1       albertel   42: BEGIN {
                     43:     &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
                     44: }
                     45: 
1.9       albertel   46: sub initialize_bridgetask {
                     47:     # id of current Dimension, 0 means that no dimension is current 
                     48:     # (inside <Task> only)
                     49:     $Apache::bridgetask::dimension='';
                     50:     # list of all Dimension ids seen
                     51:     @Apache::bridgetask::dimensionlist=();
1.20      albertel   52:     # mandatory attribute of all Dimensions seen
                     53:     %Apache::bridgetask::dimensionmandatory=();
1.9       albertel   54:     # list of all current Instance ids
                     55:     @Apache::bridgetask::instance=();
                     56:     # list of all Instance ids seen in this problem
                     57:     @Apache::bridgetask::instancelist=();
1.15      albertel   58:     # key of queud user data that we are currently grading
                     59:     $Apache::bridgetask::queue_key='';
1.9       albertel   60: }
                     61: 
1.4       albertel   62: sub proctor_check_auth {
1.22      albertel   63:     my ($slot_name,$slot)=@_;
1.11      albertel   64:     my $user=$env{'form.proctorname'};
                     65:     my $domain=$env{'form.proctordomain'};
1.4       albertel   66:     
                     67:     my @allowed=split(",",$slot->{'proctor'});
                     68:     foreach my $possible (@allowed) {
                     69: 	my ($puser,$pdom)=(split('@',$possible));
                     70: 	if ($puser eq $user && $pdom eq $domain) {
1.72      albertel   71: 	    my $authenticated=0;
                     72: 	    if ( $slot->{'secret'} =~ /\S/ &&
                     73: 		 $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
                     74: 		$authenticated=1;
                     75: 	    } else {
                     76: 		
                     77: 		my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
                     78: 		if ($authhost ne 'no_host') {
                     79: 		    $authenticated=1;
                     80: 		}
                     81: 	    }
                     82: 	    if ($authenticated) {
1.23      albertel   83: 		my $version=
                     84: 		    $Apache::lonhomework::results{'resource.version'}=
1.27      albertel   85: 		    ++$Apache::lonhomework::history{'resource.version'};
1.23      albertel   86: 		$Apache::lonhomework::results{"resource.$version.checkedin"}=
1.4       albertel   87: 		    $user.'@'.$domain;
1.23      albertel   88: 		$Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
1.22      albertel   89: 		    $slot_name;
1.28      albertel   90: 		foreach my $key (keys(%Apache::lonhomework::history)) {
                     91: 		    if ($key=~/^resource\.0\./) {
                     92: 			$Apache::lonhomework::results{$key}='';
                     93: 		    }
                     94: 		}
1.4       albertel   95: 		return 1;
                     96: 	    }
                     97: 	}
                     98:     }
                     99:     return 0;
                    100: }
                    101: 
1.25      albertel  102: sub get_version {
1.29      albertel  103:     my ($version,$previous);
1.25      albertel  104:     if ($env{'form.previousversion'} && 
1.36      albertel  105: 	$env{'form.previousversion'} ne 'current' &&
1.25      albertel  106: 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
1.29      albertel  107: 	$version=$env{'form.previousversion'};
                    108: 	$previous=1;
                    109:     } else {
                    110: 	$version=$Apache::lonhomework::history{'resource.version'};
                    111: 	$previous=0;
                    112:     }
                    113:     if (wantarray) {
                    114: 	return ($version,$previous);
1.25      albertel  115:     }
1.29      albertel  116:     return $version;
1.25      albertel  117: }
                    118: 
1.8       albertel  119: sub add_previous_version_button {
1.25      albertel  120:     my ($status)=@_;
1.8       albertel  121:     my $result;
1.29      albertel  122:     if ($Apache::lonhomework::history{'resource.version'} eq '') {
1.25      albertel  123: 	return '';
                    124:     }
1.29      albertel  125:     if ($Apache::lonhomework::history{'resource.version'} < 2 &&
                    126: 	$status ne 'NEEDS_CHECKIN') {
1.25      albertel  127: 	return '';
                    128:     }
1.29      albertel  129:     my $version=&get_version();
                    130:     if ($env{'form.previousversion'} ne '' &&
                    131: 	$env{'form.previousversion'} eq $version) {
                    132: 	$result.="<h3>".&mt("Showing previous version [_1]",$version).
                    133: 	    "</h3>\n";
                    134:     }
                    135:     my @to_show;
                    136:     foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
                    137: 	if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
                    138: 	    push(@to_show,$test_version);
                    139: 	}
                    140:     }
                    141:     my $list='<option>'.
                    142: 	join("</option>\n<option>",@to_show).
                    143: 	     "</option>\n";
1.36      albertel  144:     $list.='<option value="current">'.&mt('Current').'</option>';
1.29      albertel  145:     $result.='<form name="getprevious" method="POST" action="';
                    146:     my $uri=$env{'request.uri'};
                    147:     if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    148:     $result.=$uri.'">'.
                    149: 	&mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
                    150: <option>'.&mt('Pick one').'</option>
                    151: '.$list.'
                    152: </select>')."</form>";
1.8       albertel  153:     return $result;
                    154: }
                    155: 
1.13      albertel  156: sub add_grading_button {
1.59      albertel  157:     my (undef,$cid)=&Apache::lonxml::whichuser();
                    158:     my $cnum=$env{'course.'.$cid.'.num'};
                    159:     my $cdom=$env{'course.'.$cid.'.domain'};
                    160:     my %sections;
                    161:     my $numsections=&Apache::loncommon::get_sections($cdom,$cnum,\%sections);
                    162:     my $size=5;
                    163:     if (scalar(keys(%sections)) < 3) {
                    164: 	$size=scalar(keys(%sections))+2;
                    165:     }
                    166:     my $sec_select = '<select multiple name="chosensections" size="'.$size.'">'."\n";
                    167:     $sec_select .= "<option value='all' selected='selected'>all</option>\n";
                    168:     foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
                    169: 	$sec_select .= "<option name=\"$sec\">$sec</option>\n";
                    170:     }
                    171:     $sec_select .= "<option value='none'>none</option></select>\n";
                    172:     
1.29      albertel  173:     my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13      albertel  174: 	&mt("Get a submission to grade").'" />';
                    175:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.40      albertel  176:     if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.34      albertel  177: 	my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.59      albertel  178: 	$result.='<p>Specify a section: '.$sec_select.'</p>';
1.34      albertel  179: 	$result.='<p>'.&mt("Grading Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
                    180: 
                    181: 	$result.=' <input type="submit" name="reviewagrading" value="'.
                    182: 	    &mt("Select an entry from the grading queue").'" /> </p>'."\n";
                    183: 
                    184: 	($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
                    185: 	$result.='<p>'.&mt("Review Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
1.32      albertel  186: 	$result.=' <input type="submit" name="reviewasubmission" value="'.
1.34      albertel  187: 	    &mt("Select an entry from the review queue").'" /> </p>'."\n";
1.49      albertel  188: 	$result.=' <input type="submit" name="regradeasubmission" value="'.
                    189: 	    &mt("Select a user to regrade.").'" /> </p>'."\n";
1.32      albertel  190:     }
1.13      albertel  191:     return $result;
                    192: }
                    193: 
1.22      albertel  194: sub add_request_another_attempt_button {
1.38      albertel  195:     my ($text)=@_;
                    196:     if (!$text) { $text="Request another attempt"; }
1.25      albertel  197:     my $result;
1.36      albertel  198:     my $symb=&Apache::lonnet::symbread();
1.37      albertel  199:     my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38      albertel  200:     my $action='get_reservation';
1.37      albertel  201:     if ($slot_name) {
1.38      albertel  202: 	$text="Change reservation.";
                    203: 	$action='change_reservation';
1.37      albertel  204: 	my $description=&Apache::slotrequest::get_description($slot_name,
                    205: 							      $slot);
                    206: 	$result.=(<<STUFF);
                    207: <p> Will be next available: $description </p>
                    208: STUFF
                    209:     }
1.38      albertel  210:     
                    211:     if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
                    212:     $symb=&Apache::lonnet::escape($symb);
                    213:     $result.='<form method="POST" action="/adm/slotrequest">'.
                    214: 	'<input type="hidden" name="symb" value="'.$symb.'" />'.
                    215: 	'<input type="hidden" name="command" value="'.$action.'" />'.
                    216: 	'<input type="submit" name="requestattempt" value="'.
                    217: 	&mt($text).'" />'.
                    218: 	'</form>';
1.25      albertel  219:     return $result;
1.22      albertel  220: }
                    221: 
1.30      albertel  222: sub preserve_grade_info {
                    223:     my $result;
                    224:     # if we are viewing someone else preserve that info
                    225:     if (defined $env{'form.grade_symb'}) {
                    226: 	foreach my $field ('symb','courseid','domain','username') {
                    227: 	    $result .= '<input type="hidden" name="grade_'.$field.
                    228: 		'" value="'.$env{"form.grade_$field"}.'" />'."\n";
                    229: 	}
                    230:     }
                    231:     return $result;
                    232: }
                    233: 
1.53      albertel  234: sub style {
                    235:     return (<<STYLE);
                    236: <style type="text/css">
                    237: .fail, .pass, .neutral {
                    238:     position: relative;
                    239:     margin : 5px;
                    240:     margin-bottom :10px;
                    241:     padding : 4px;
                    242:     padding-left : 75px;
                    243: 	border : thin solid;
                    244:     font-weight : bolder;
                    245:     font-size: smaller;
                    246:     font-family: Arial;
                    247:     background-color : rgb(255,240,225);
                    248: }
                    249: 
                    250: .fail h4, .pass h4 {
                    251: 	position:absolute;
                    252: 	left: -4px;
                    253: 	top: -8px;
                    254: 	padding:2px;
                    255: 	margin:0;
                    256: 	background-color : rgb(255,240,225);
                    257: 	border : thin solid;
                    258: }
                    259: 
                    260: .fail {
                    261: 	color: red;
                    262: }
                    263: 
                    264: .pass {
                    265:     color : green;
                    266: }
                    267: 
                    268: .neutral {
                    269: 	color : blue;
                    270: }
                    271: 
                    272: .question {
                    273: 	border : thin solid black;
                    274: 	padding : 4px;
                    275: 	margin-bottom : 1em;
                    276: }
                    277: 
                    278: .grade {
                    279: 	font-size: x-large;
                    280: 	font-family: Arial;
                    281: 	position:absolute;
                    282: 	left: 5px;
                    283: 	top: -5px;
                    284: 	width: 70px;
                    285: }
                    286: 
                    287: div#feedback h1 {
                    288:     color : inherit;
                    289: }
                    290: </style>
                    291: STYLE
                    292: 
                    293: }
                    294: 
1.54      albertel  295: sub show_task {
                    296:     my ($status,$previous)=@_;
                    297:     if (!$previous && (
                    298: 		       ( $status eq 'CLOSED' ) ||
                    299: 		       ( $status eq 'BANNED') ||
                    300: 		       ( $status eq 'UNAVAILABLE') ||
                    301: 		       ( $status eq 'NOT_IN_A_SLOT') ||
                    302: 		       ( $status eq 'NEEDS_CHECKIN') ||
                    303: 		       ( $status eq 'WAITING_FOR_GRADE') ||
                    304: 		       ( $status eq 'INVALID_ACCESS') )) {
                    305: 	return 0;
                    306:     }
1.64      albertel  307:     if ($env{'form.donescreen'}) { return 0; }
1.54      albertel  308:     return 1;
                    309: }
                    310: 
                    311: sub internal_location {
                    312:     my ($id)=@_;
                    313:     return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
                    314: }
                    315: 
1.60      albertel  316: sub submission_time_stamp {
                    317:     my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
                    318:     my $submissiontime;
                    319:     my $version=$Apache::lonhomework::history{'resource.version'};
                    320:     for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
                    321: 	if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
                    322: 	    $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
                    323: 	}
                    324:     }
                    325:     my $result;
                    326:     if ($submissiontime) {
                    327: 	my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.checkedin.slot'};
                    328: 	my %slot=&Apache::lonnet::get_slot($slot_name);
                    329: 	my $diff = $slot{'endtime'} - $submissiontime;
1.71      albertel  330: 	my ($color,$when)=('#FF6666','after');
                    331: 	if ($diff > 0) { ($color,$when)=('#336600','before'); }
1.60      albertel  332: 	my $info;
                    333: 	if ($diff%60) { $info=($diff%60).' seconds'; }
                    334: 	$diff=int($diff/60);
                    335: 	if ($diff%60) { $info=($diff%60).' minutes '.$info; }
                    336: 	$diff=int($diff/60);
                    337: 	if ($diff) {    $info=$diff.' hours '.$info; }
                    338: 	$result='<p><font color="'.$color.'">'.
                    339: 	    &mt('Student submitted [_1] [_2] the deadline. 
                    340:                  (Submission was at [_3], end of period was [_4].)',
                    341: 		$info,$when,scalar(localtime($submissiontime)),
                    342: 		scalar(localtime($slot{'endtime'}))).
                    343: 		'</font></p>';
                    344:     }
                    345:     return $result;
                    346: }
                    347: 
1.70      albertel  348: sub webgrade_standard_info {
                    349:     my ($version)=&get_version();
                    350:     my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
                    351:     my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
                    352:     my $file_list="<ul>\n";
                    353:     foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"})) {
                    354: 	my $file=$file_url.$partial_file;
                    355: 	$file=~s|/+|/|g;
                    356: 	&Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.73      albertel  357: 	$file_list.='<li><nobr><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
1.70      albertel  358: 	    &Apache::loncommon::icon($file).'" border=0"> '.$file.
                    359: 	    '</a></nobr></li>'."\n";
                    360:     }
                    361:     $file_list.="</ul>\n";
                    362: 
                    363:     my %lt=&Apache::lonlocal::texthash('done' => 'Done',
                    364: 				       'stop' => 'Stop',
                    365: 				       );
                    366: 				       
                    367:     my $result=<<INFO;
                    368: <div class="handininfo">
                    369:   <input type="submit" name="next" value="$lt{'done'}" />
                    370:   <input type="submit" name="stop" value="$lt{'stop'}" />
                    371:   $file_list
                    372: </div>
                    373: INFO
                    374:     return $result;
                    375: }
                    376: 
1.1       albertel  377: sub start_Task {
                    378:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    379: 
1.4       albertel  380:     my ($status,$accessmsg,$slot);
1.16      albertel  381:     if ($target ne 'webgrade') {
1.70      albertel  382: 	&Apache::structuretags::init_problem_globals('Task');
1.16      albertel  383: 	&Apache::structuretags::initialize_storage();
                    384: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.74      albertel  385: 	if ($env{'request.state'} eq 'construct') {
                    386: 	    &Apache::structuretags::setup_rndseed($safeeval);
                    387: 	}
1.16      albertel  388:     } 
                    389: 
1.4       albertel  390:     $Apache::lonhomework::parsing_a_task=1;
1.1       albertel  391:     #should get back a <html> or the neccesary stuff to start XML/MathML
                    392:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    393: 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16      albertel  394:     
1.74      albertel  395:     if ($target eq 'web' && $env{'request.state'} ne 'construct') {
1.13      albertel  396: 	if ($Apache::lonhomework::modifygrades) {
                    397: 	    $body_tag_start.='<form name="gradesubmission" method="POST" action="';
                    398: 	    my $uri=$env{'request.uri'};
                    399: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    400: 	    $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
1.38      albertel  401: 	    my $symb=&Apache::lonnet::symbread();
1.40      albertel  402: 	    if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
                    403: 		$body_tag_start.='<form method="POST" action="/adm/slotrequest">'.
                    404: 		    '<input type="hidden" name="symb" value="'.$symb.'" />'.
                    405: 		    '<input type="hidden" name="command" value="showslots" />'.
                    406: 		    '<input type="submit" name="requestattempt" value="'.
                    407: 		    &mt('Show Slot list').'" />'.
                    408: 		    '</form>';
                    409: 	    }
1.13      albertel  410: 	}
1.8       albertel  411:     }
1.74      albertel  412:     if ($target eq 'web' && $env{'request.state'} eq 'construct') {
                    413: 	$form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
                    414:     }
1.21      albertel  415:     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1       albertel  416: 	$target eq 'tex') {
1.29      albertel  417: 	my ($version,$previous)=&get_version();
1.14      albertel  418: 	($status,$accessmsg,my $slot_name,$slot) = 
1.4       albertel  419: 	    &Apache::lonhomework::check_task_access('0');
1.9       albertel  420: 	push(@Apache::inputtags::status,$status);
1.14      albertel  421: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  422: 	my $expression='$external::datestatus="'.$status.'";';
1.23      albertel  423: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1       albertel  424: 	&Apache::run::run($expression,$safeeval);
                    425: 	&Apache::lonxml::debug("Got $status");
1.25      albertel  426: 	$body_tag_start.=&add_previous_version_button($status);
1.54      albertel  427: 	if (!&show_task($status,$previous)) {
1.1       albertel  428: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    429: 	    if ( $target eq "web" ) {
1.4       albertel  430: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
1.74      albertel  431: 		if ($env{'request.state'} eq 'construct') {
                    432: 		    $result.=$form_tag_start;
                    433: 		}
1.4       albertel  434: 		my $msg;
1.1       albertel  435: 		if ($status eq 'UNAVAILABLE') {
                    436: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  437: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    438: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.38      albertel  439: 		    $msg.=&add_request_another_attempt_button("Sign up for time to work.");
1.4       albertel  440: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    441: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    442: 			'</h1>'.&proctor_validation_screen($slot);
1.22      albertel  443: 		} elsif ($status eq 'WAITING_FOR_GRADE') {
                    444: 		    $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.64      albertel  445: 		} elsif ($env{'form.donescreen'}) {
                    446: 		    my $title=&Apache::lonnet::gettitle();
1.67      albertel  447: 		    my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
                    448: 		    my $files='<ul><li>'.join('</li><li>',@files).'</li></ul>';
1.64      albertel  449: 		    $result.=<<DONESCREEN;
                    450: <h2>$title</h2>
                    451: <p> Files submitted: $files </p>
1.67      albertel  452: <p> You are now done with this Bridge Task </p>
1.64      albertel  453: <hr />
                    454: <p> <a href="/adm/logout">Logout</a> </p>
                    455: <p> <a href="/adm/roles">Change to a different course</a> </p>
                    456: DONESCREEN
1.1       albertel  457: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    458: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    459: 		}
                    460: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    461: 		    $msg.='The problem '.$accessmsg;
                    462: 		}
                    463: 		$result.=$msg.'<br />';
                    464: 	    } elsif ($target eq 'tex') {
                    465: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    466: 		if ($status eq 'UNAVAILABLE') {
                    467: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    468: 		} else {
                    469: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    470: 		}
1.22      albertel  471: 	    } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4       albertel  472: 		if ($status eq 'NEEDS_CHECKIN') {
1.77    ! albertel  473: 		    if(&proctor_check_auth($slot_name,$slot)) {
        !           474: 			my $result=&add_to_queue('gradingqueue',
        !           475: 						 $Apache::inputtags::slot_name);
        !           476: 			&Apache::lonxml::debug("add_to_queue said $result");
        !           477: 		    }
1.4       albertel  478: 		}
1.1       albertel  479: 	    }
                    480: 	} elsif ($target eq 'web') {
                    481: 	    my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    482: 	    $result.="$head_tag_start<title>$name</title></head>
1.53      albertel  483:               $body_tag_start \n".&style();
1.36      albertel  484: 	    
1.57      albertel  485: 	    $result.=&preserve_grade_info();
                    486: 	    $result.=&internal_location();
1.36      albertel  487: 	    $result.=$form_tag_start.
                    488: 		'<input type="hidden" name="submitted" value="yes" />';
1.54      albertel  489: 	    &Apache::lonxml::startredirection();
1.1       albertel  490: 	}
1.21      albertel  491:     } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                    492: 	      $target eq 'webgrade') {
1.32      albertel  493: 	my $webgrade='yes';
1.21      albertel  494: 	if ($target eq 'webgrade') {
1.32      albertel  495: 	    $result.=$head_tag_start.$body_tag_start;
1.49      albertel  496: 	    #$result.='<br />Review'.&show_queue('reviewqueue');
                    497: 	    #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30      albertel  498: 	}
1.33      albertel  499: 	# FIXME Blast! still need to reorg this, need to reshow the
                    500:         #       queue being reviewed once done with the grade pass...
                    501:         #       Hrrm, vaildation pass should perhaps say 'not_locked'
                    502:         #       perhaps do a search if there is a key that is mine and if
                    503:         #       there isn't reshow the queue....
                    504: 	my ($todo,$status_code)=&get_key_todo($target);
                    505: 
                    506: 	if ($todo) {
                    507: 	    &setup_env_for_other_user($todo,$safeeval);
                    508: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
                    509: 	    $result.="\n".'<table><tr><td>Found '.
                    510: 		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
                    511: 	    $form_tag_start.=
                    512: 		'<input type="hidden" name="gradingkey" value="'.
                    513: 		&Apache::lonnet::escape($todo).'" />';
                    514: 	    $Apache::bridgetask::queue_key=$todo;
                    515: 	    &Apache::structuretags::initialize_storage();
                    516: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
                    517: 	    if ($target eq 'webgrade') {
1.49      albertel  518: 		#$result.='<br />After -'.&show_queue($env{'form.queue'});
1.33      albertel  519: 		$result.="\n".'<table width="100%" style="width:100%" border="1">';
                    520: 		if ($status_code eq 'selected') {
                    521: 		    $form_tag_start.=
                    522: 			'<input type="hidden" name="queuemode" value="selected" />';
                    523: 		}
                    524: 	    }
1.15      albertel  525: 	} else {
1.33      albertel  526: 	    if ($target eq 'webgrade') {
                    527: 		$result.="\n";
                    528: 		if      ($status_code eq 'stop') {
                    529: 		    $result.='<b>'.&mt("Stopped grading.").'</b>';
                    530: 		} elsif ($status_code eq 'lock_failed') {
                    531: 		    $result.='<b>'.&mt("Failed to lock the request record.").'</b>';
                    532: 		} elsif ($status_code eq 'unlock') {
                    533: 		    $result.='<b>'.&mt("Unlocked the requested record.").'</b>';
                    534: 		    $result.=&show_queue($env{'form.queue'},1);
                    535: 		} elsif ($status_code eq 'show_list') {
                    536: 		    $result.=&show_queue($env{'form.queue'},1);
1.49      albertel  537: 		} elsif ($status_code eq 'select_user') {
                    538: 		    $result.=&select_user();
1.33      albertel  539: 		} else {
                    540: 		    $result.='<b>'.&mt("No user to be graded.").'</b>';
1.32      albertel  541: 		}
1.21      albertel  542: 	    }
1.33      albertel  543: 	    $webgrade='no';
                    544: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
1.32      albertel  545: 	}
                    546: 	if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.61      albertel  547: 	    if ($webgrade eq 'yes') {
                    548: 		$result.=&submission_time_stamp();
                    549: 	    }
1.32      albertel  550: 	    $result.=$form_tag_start;
                    551: 	    $result.='<input type="hidden" name="webgrade" value="'.
                    552: 		$webgrade.'" />';
                    553: 	    $result.='<input type="hidden" name="queue" value="'.
                    554: 		$env{'form.queue'}.'" />';
1.52      albertel  555: 	    if ($env{'form.regrade'}) {
                    556: 		$result.='<input type="hidden" name="regrade" value="'.
                    557: 		    $env{'form.regrade'}.'" />';
                    558: 	    }
1.62      albertel  559: 	    if ($env{'form.chosensections'}) {
                    560: 		my @chosen_sections=
                    561: 		    &Apache::loncommon::get_env_multiple('form.chosensections');
                    562: 		foreach my $sec (@chosen_sections) {
                    563: 		    $result.='<input type="hidden" name="chosensections" 
                    564:                                value="'.$sec.'" />';
                    565: 		}
                    566: 	    }
1.70      albertel  567: 	    if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
1.15      albertel  568: 	}
1.74      albertel  569:     } elsif ($target eq 'edit') {
                    570: 	$result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
                    571: 	    &Apache::structuretags::problem_edit_header();
                    572: 	$Apache::lonxml::warnings_error_header=
                    573: 	    &mt("Editor Errors - these errors might not effect the running of the problem, but they will likely cause problems with further use of the Edit mode. Please use the EditXML mode to fix these errors.")."<br />";
                    574: 	my $temp=&Apache::edit::insertlist($target,$token);
                    575: 	$result.=$temp;
1.1       albertel  576:     } else {
                    577: 	# page_start returned a starting result, delete it if we don't need it
                    578: 	$result = '';
                    579:     }
                    580:     return $result;
                    581: }
                    582: 
1.32      albertel  583: sub get_key_todo {
                    584:     my ($target)=@_;
                    585:     my $todo;
1.33      albertel  586: 
                    587:     if (defined($env{'form.reviewasubmission'})) {
1.54      albertel  588: 	&Apache::lonxml::debug("review a submission....");
1.33      albertel  589: 	$env{'form.queue'}='reviewqueue';
                    590: 	return (undef,'show_list');
                    591:     }
                    592: 
                    593:     if (defined($env{'form.reviewagrading'})) {
                    594: 	&Apache::lonxml::debug("review a grading....");
                    595: 	$env{'form.queue'}='gradingqueue';
                    596: 	return (undef,'show_list');
                    597:     }
                    598: 
1.49      albertel  599:     if (defined($env{'form.regradeasubmission'})) {
                    600: 	&Apache::lonxml::debug("regrade a grading....");
                    601: 	$env{'form.queue'}='none';
                    602: 	return (undef,'select_user');
                    603:     }
                    604: 
1.32      albertel  605:     my $queue=$env{'form.queue'};
1.33      albertel  606: 
1.32      albertel  607:     if (!defined($queue)) {
                    608: 	$env{'form.queue'}=$queue='gradingqueue';
                    609:     }
1.33      albertel  610: 
1.32      albertel  611:     my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33      albertel  612: 
1.49      albertel  613:     if ($env{'form.queue'} eq 'none') {
                    614: 	if (defined($env{'form.gradingkey'})) {
                    615: 	    if ($target eq 'webgrade') {
                    616: 		if ($env{'form.stop'}) {
                    617: 		    return (undef,'stop');
                    618: 		} elsif ($env{'form.next'}) {
1.59      albertel  619: 		    return (undef,'select_user');
1.49      albertel  620: 		}
                    621: 	    }
                    622: 	    return ($gradingkey,'selected');
                    623: 	} else {
1.59      albertel  624: 	    return (undef,'select_user');
1.49      albertel  625: 	}
                    626:     }
1.32      albertel  627:     if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33      albertel  628: 	&& !defined($env{'form.gradingaction'}) 
                    629: 	&& $env{'form.queuemode'} eq 'selected') {
                    630: 	
                    631: 	my $who=&queue_key_locked($queue,$gradingkey);
                    632: 	my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    633: 	if ($who eq $me) {
                    634: 	    &Apache::lonxml::debug("Found a key was given to me");
                    635: 	    return ($gradingkey,'selected');
                    636: 	} else {
                    637: 	    return (undef,'show_list');
                    638: 	}
                    639: 
                    640:     }
                    641: 
                    642:     if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
                    643: 	if ($env{'form.gradingaction'} eq 'resume') {
                    644: 	    delete($env{'form.gradingaction'});
                    645: 	    &Apache::lonxml::debug("Resuming a key");
1.32      albertel  646: 	    return ($gradingkey);
1.33      albertel  647: 	} elsif ($env{'form.gradingaction'} eq 'unlock') {
                    648: 	    &Apache::lonxml::debug("Unlocking a key ".
                    649: 				     &check_queue_unlock($queue,$gradingkey,1));
                    650: 	    return (undef,'unlock');
                    651: 	} elsif ($env{'form.gradingaction'} eq 'select') {
                    652: 	    &Apache::lonxml::debug("Locking a key");
                    653: 	    if (&lock_key($queue,$gradingkey)) {
                    654: 		&Apache::lonxml::debug("Success $queue");
                    655: 		return ($gradingkey);
                    656: 	    }
                    657: 	    &Apache::lonxml::debug("Failed $queue");
                    658: 	    return (undef,'lock_failed');
1.32      albertel  659: 	}
                    660:     }
1.33      albertel  661: 
                    662:     if ($env{'form.queuemode'} ne 'selected') {
                    663: 	# don't get something new from the queue if they hit the stop button
                    664:     	if (!($env{'form.stop'} && $target eq 'webgrade') 
                    665: 	    && !$env{'form.gradingaction'}) {
                    666: 	    &Apache::lonxml::debug("Getting anew $queue");
                    667: 	    return (&get_from_queue($queue));
                    668: 	} else {
                    669: 	    return (undef,'stop');
                    670: 	}
1.32      albertel  671:     }
1.33      albertel  672:     return (undef,undef)
1.32      albertel  673: }
                    674: 
1.1       albertel  675: sub end_Task {
                    676:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    677:     my $result='';
                    678:     my $status=$Apache::inputtags::status['-1'];
1.29      albertel  679:     my ($version,$previous)=&get_version();
1.1       albertel  680:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel  681: 	$target eq 'tex') {
1.69      albertel  682: 	if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.1       albertel  683: 	    if ($target eq 'web') {
1.54      albertel  684: 		if (&show_task($status,$previous)) {
                    685: 		    $result.=&Apache::lonxml::endredirection();
                    686: 		}
1.64      albertel  687: 		if ($status eq 'CAN_ANSWER' && !$previous && 
                    688: 		    !$env{'form.donescreen'}) {
1.15      albertel  689: 		    $result.="\n".'<table border="1">'.
1.28      albertel  690: 			&Apache::inputtags::file_selector("$version.0",
                    691: 							  "bridgetask","*",
1.46      albertel  692: 							  'portfolioonly',
                    693: 							  '
                    694: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
                    695: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9       albertel  696: 							  "</table>";
1.77    ! albertel  697: 		}
        !           698: 		if (!$previous && !$env{'form.donescreen'}) {
1.9       albertel  699: 		    $result.=&Apache::inputtags::gradestatus('0');
1.64      albertel  700: 		    $result.='</form>';
                    701: 		    $result.=<<DONEBUTTON;
                    702: <form method="POST">
                    703:    <input type="hidden" name="donescreen" value="1" />
                    704:    <input type="submit" value="Done" />
                    705: </form>
                    706: DONEBUTTON
1.77    ! albertel  707:                 }
1.56      albertel  708: 		if (&show_task($status,$previous) &&
                    709: 		    $Apache::lonhomework::history{"resource.$version.status"} =~ /^(pass|fail)$/) {
1.54      albertel  710: 		    my $bt_status=$Apache::lonhomework::history{"resource.$version.status"};
                    711: 		    my $title=&Apache::lonnet::gettitle();
                    712: 		    my %slot=&Apache::lonnet::get_slot($Apache::inputtags::slot_name);
1.55      albertel  713: 		    my $start_time=
                    714: 			&Apache::lonlocal::locallocaltime($slot{'starttime'});
1.54      albertel  715: 
                    716: 		    my $status;
                    717: 		    $status.="\n<div class='$bt_status'>\n";
                    718: 		    
                    719: 		    if ($bt_status eq 'pass')  {
                    720: 			$status.='<h2>You passed the '.$title.' given on '.
1.55      albertel  721: 			    $start_time.'.</h2>';
1.54      albertel  722: 		    }
                    723: 		    if ($bt_status eq 'fail')  {
                    724: 			$status.='<h2>You did not pass the '.$title.' given on '.
1.55      albertel  725: 			    $start_time.'.</h2>';
1.54      albertel  726: 			if (!$previous) {
                    727: 			    $status.=&add_request_another_attempt_button();
                    728: 			}
                    729: 		    }
                    730: 		    my $man_count=0;
                    731: 		    my $opt_count=0;
                    732: 		    my $opt_passed=0;
                    733: 		    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
                    734: 			if ($Apache::bridgetask::dimensionmandatory{$dim_id}
                    735: 			    eq 'N') {
                    736: 			    $opt_count++;
                    737: 			    if ($Apache::lonhomework::history{"resource.$version.$dim_id.status"} eq 'pass') {
                    738: 				$opt_passed++;
                    739: 			    }
                    740: 			} else {
                    741: 			    $man_count++;
                    742: 			}
                    743: 		    }
                    744: 		    my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
                    745: 							 $parstack,$safeeval);
                    746: 		    if ($opt_req !~ /\S/) { $opt_req='0'; }
                    747: 		    $status.="\n<p>".&mt('You needed to pass all of the [_1]  mandatory components and [_2] of the [_3] optional components on the bridge task.',$man_count,$opt_req,$opt_count)."</p></div>\n";
                    748: 
                    749: 		    my $internal_location=&internal_location();
                    750: 		    $result=~s/\Q$internal_location\E/$status/;
                    751: 		}
1.13      albertel  752: 	    } 
                    753: 	    if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  754: 		$result.=&Apache::lonxml::xmlend().'</html>';
                    755: 	    }
                    756: 	}
1.29      albertel  757: 	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12      albertel  758: 	    my $award='SUBMITTED';
1.28      albertel  759: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20      albertel  760: 						    'portfiles',\$award);
1.14      albertel  761: 	    if ($award eq 'SUBMITTED' &&
1.28      albertel  762: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
                    763: 		$Apache::lonhomework::results{"resource.0.tries"}=
                    764: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
                    765: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
                    766: 
                    767: 		$Apache::lonhomework::results{"resource.0.award"}=
                    768: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
                    769: 		    $award;
1.51      albertel  770: 		$Apache::lonhomework::results{"resource.0.submission"}=
                    771: 		    $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64      albertel  772: 	    } else {
                    773: 		delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1.77    ! albertel  774: 		$award = '';
1.10      albertel  775: 	    }
1.4       albertel  776: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    777: 	    &Apache::structuretags::finalize_storage();
1.14      albertel  778: 	    if ($award eq 'SUBMITTED') {
1.31      albertel  779: 		&add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14      albertel  780: 	    }
1.1       albertel  781: 	}
1.32      albertel  782: 	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20      albertel  783: 	    my $optional_required=
                    784: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                    785: 					   $safeeval);
                    786: 	    my $optional_passed=0;
                    787: 	    my $mandatory_failed=0;
                    788: 	    my $ungraded=0;
                    789: 	    my $review=0;   
1.21      albertel  790: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20      albertel  791: 	    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
                    792: 		my $status=
1.25      albertel  793: 		    $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20      albertel  794: 		my $mandatory=
                    795: 		    ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
                    796: 		if ($status eq 'pass') {
                    797: 		    if (!$mandatory) { $optional_passed++; }
                    798: 		} elsif ($status eq 'fail') {
                    799: 		    if ($mandatory) { $mandatory_failed++; }
                    800: 		} elsif ($status eq 'ungraded') {
                    801: 		    $ungraded++;
                    802: 		} elsif ($status eq 'review') {
                    803: 		    $review++;
1.49      albertel  804: 		} else {
                    805: 		    $ungraded++;
                    806: 		}
1.20      albertel  807: 	    }
                    808: 	    if ($optional_passed < $optional_required) {
                    809: 		$mandatory_failed++;
                    810: 	    }
1.21      albertel  811: 	    &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
                    812: 	    $Apache::lonhomework::results{'resource.grader'}=
1.20      albertel  813: 		$env{'user.name'}.'@'.$env{'user.domain'};
                    814: 	    if ($review) {
1.25      albertel  815: 		$Apache::lonhomework::results{"resource.$version.status"}='review';
1.33      albertel  816: 		if ($env{'form.queue'} eq 'reviewqueue') {
                    817: 		    &check_queue_unlock($env{'form.queue'});
                    818: 		    &Apache::lonxml::debug(" still needs review not changing status.");
                    819: 		} else {
1.49      albertel  820: 		    &move_between_queues($env{'form.queue'},'reviewqueue');
1.33      albertel  821: 		}
1.20      albertel  822: 	    } elsif ($ungraded) {
1.25      albertel  823: 		$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.49      albertel  824: 		if ($env{'form.queue'} eq 'reviewqueue' ||
                    825: 		    $env{'form.queue'} eq 'none' ) {
1.33      albertel  826: 		    &Apache::lonxml::debug("moving back.");
1.49      albertel  827: 		    &move_between_queues($env{'form.queue'},'gradingqueue');
1.33      albertel  828: 		} else {
                    829: 		    &check_queue_unlock($env{'form.queue'});
                    830: 		}
1.20      albertel  831: 	    } elsif ($mandatory_failed) {
1.25      albertel  832: 		$Apache::lonhomework::results{"resource.$version.status"}='fail';
                    833: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                    834: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                    835: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39      albertel  836: 		&remove_from_queue($env{'form.queue'}); 
                    837: 
                    838: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52      albertel  839: 		
                    840: 		if ($env{'form.regrade'} ne 'yes') {
                    841: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                    842: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                    843: 		    &Apache::grades::version_portfiles(
                    844: 						       \%Apache::lonhomework::results,
                    845: 						       ["$version.0.bridgetask"],$courseid,
                    846: 						       $symb,$udom,$uname,
                    847: 						       ["$version.0.bridgetask"]);
                    848: 		}
1.20      albertel  849: 	    } else {
1.25      albertel  850: 		$Apache::lonhomework::results{"resource.$version.status"}='pass';
                    851: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                    852: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                    853: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32      albertel  854: 		&remove_from_queue($env{'form.queue'});
1.39      albertel  855: 
                    856: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52      albertel  857: 		if ($env{'form.regrade'} ne 'yes') {
                    858: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                    859: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                    860: 		    &Apache::grades::version_portfiles(
                    861: 						       \%Apache::lonhomework::results,
                    862: 						       ["$version.0.bridgetask"],$courseid,
                    863: 						       $symb,$udom,$uname,
                    864: 						       ["$version.0.bridgetask"]);
                    865: 		}
1.20      albertel  866: 	    }
1.26      albertel  867: 	    $Apache::lonhomework::results{"resource.status"}=
                    868: 		$Apache::lonhomework::results{"resource.$version.status"};
1.28      albertel  869: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel  870: 		$Apache::lonhomework::results{"resource.0.award"}=
1.50      albertel  871: 		    $Apache::lonhomework::results{"resource.$version.0.award"};
1.26      albertel  872: 		$Apache::lonhomework::results{"resource.0.awarded"}=
1.50      albertel  873: 		    $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26      albertel  874: 		$Apache::lonhomework::results{"resource.0.solved"}=
1.50      albertel  875: 		    $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25      albertel  876: 	    }
1.21      albertel  877: 	    &Apache::structuretags::finalize_storage();
1.20      albertel  878: 	}
1.15      albertel  879:     } elsif ($target eq 'webgrade') {
1.18      albertel  880: 	$result.="</table>\n<hr />";
1.20      albertel  881: 	#$result.='<input type="submit" name="next" value="'.
                    882: 	#    &mt('Save &amp; Next').'" /> ';
                    883: 	#$result.='<input type="submit" name="end" value="'.
                    884: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                    885: 	#$result.='<input type="submit" name="throwaway" value="'.
                    886: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                    887: 	#$result.='<input type="submit" name="save" value="'.
                    888: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15      albertel  889: 	$result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1       albertel  890:     } elsif ($target eq 'meta') {
1.70      albertel  891: 	$result.=&Apache::response::meta_package_write('Task');
1.77    ! albertel  892:         $result.=&Apache::response::meta_stores_write('solved','string',
        !           893: 						      'Problem Status');
        !           894: 	$result.=&Apache::response::meta_stores_write('tries','int_zeropos',
        !           895: 						      'Number of Attempts');
        !           896: 	$result.=&Apache::response::meta_stores_write('awarded','float',
        !           897: 						      'Partial Credit Factor');
        !           898: 	$result.=&Apache::response::meta_stores_write('status','string',
        !           899: 						      'Bridge Task Status');
1.1       albertel  900:     }
1.4       albertel  901:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel  902:     return $result;
                    903: }
                    904: 
1.31      albertel  905: sub move_between_queues {
                    906:     my ($src_queue,$dest_queue)=@_;
1.49      albertel  907:     my $cur_data;
                    908:     if ($src_queue ne 'none') {
                    909: 	$cur_data=&get_queue_data($src_queue);
                    910: 	if (!$cur_data) { return 'not_exist'; }
                    911:     } else {
                    912: 	$cur_data = ['none'];
                    913:     }
1.31      albertel  914:     my $result=&add_to_queue($dest_queue,$cur_data->[0]);
                    915:     if ($result ne 'ok') {
                    916: 	return $result;
                    917:     }
                    918:     &check_queue_unlock($src_queue);
                    919:     return &remove_from_queue($src_queue);
1.21      albertel  920: }
                    921: 
                    922: sub check_queue_unlock {
1.32      albertel  923:     my ($queue,$key,$allow_not_me)=@_;
1.49      albertel  924:     if ($queue eq 'none') { return 'ok'; }
1.30      albertel  925:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32      albertel  926:     if (!defined($key)) {
                    927: 	$key="$symb\0queue\0$uname\@$udom";
                    928:     }
1.30      albertel  929:     my $cnum=$env{'course.'.$cid.'.num'};
                    930:     my $cdom=$env{'course.'.$cid.'.domain'};
                    931:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    932:     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
                    933:     if  ($who eq $me) {
1.32      albertel  934: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
                    935:     } elsif ($allow_not_me) {
1.33      albertel  936: 	&Apache::lonxml::debug("unlocking $who by $me");
1.32      albertel  937: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30      albertel  938:     }
1.32      albertel  939:     return 'not_owner';
1.21      albertel  940: }
                    941: 
                    942: sub remove_from_queue {
1.30      albertel  943:     my ($queue)=@_;
1.49      albertel  944:     if ($queue eq 'none') { return 'ok'; }
1.27      albertel  945:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    946:     my $cnum=$env{'course.'.$cid.'.num'};
                    947:     my $cdom=$env{'course.'.$cid.'.domain'};
                    948:     my $key="$symb\0queue\0$uname\@$udom";
                    949:     my @keys=($key,"$key\0locked");
1.31      albertel  950:     return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21      albertel  951: }
                    952: 
1.16      albertel  953: sub setup_env_for_other_user {
                    954:     my ($queue_key,$safeeval)=@_;
                    955:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30      albertel  956:     &Apache::lonxml::debug("setup_env for $queue_key");
1.16      albertel  957:     $env{'form.grade_symb'}=$symb;
                    958:     $env{'form.grade_domain'}=$udom;
                    959:     $env{'form.grade_username'}=$uname;
                    960:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                    961:     &Apache::lonxml::initialize_rndseed($safeeval);
                    962: }
                    963: 
1.31      albertel  964: sub get_queue_data {
                    965:     my ($queue)=@_;
                    966:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    967:     my $cnum=$env{'course.'.$cid.'.num'};
                    968:     my $cdom=$env{'course.'.$cid.'.domain'};
                    969:     my $todo="$symb\0queue\0$uname\@$udom";
                    970:     my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
                    971:     if ($key eq $todo && ref($value)) {
                    972: 	return $value;
                    973:     }
                    974:     return undef;
                    975: }
                    976: 
1.49      albertel  977: sub check_queue_for_key {
                    978:     my ($cid,$queue,$todo)=@_;
                    979:     my $cnum=$env{'course.'.$cid.'.num'};
                    980:     my $cdom=$env{'course.'.$cid.'.domain'};
                    981:     my %results=
                    982: 	&Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
                    983:     
                    984:     if (exists($results{$todo}) && ref($results{$todo})) {
                    985: 	if (defined($results{"$todo\0locked"})) {
                    986: 	    return 'locked';
                    987: 	}
1.58      albertel  988: 	my $slot=$results{$todo}->[0];
                    989: 	my %slot_data=&Apache::lonnet::get_slot($slot);
                    990: 	if ($slot_data{'endtime'} > time) { 
                    991: 	    return 'in_progress';
                    992: 	}
1.49      albertel  993: 	return 'enqueued';
                    994:     }
                    995:     return undef;
                    996: }
                    997: 
1.14      albertel  998: sub add_to_queue {
1.31      albertel  999:     my ($queue,$slot_name)=@_;
1.49      albertel 1000:     if ($queue eq 'none') { return 'ok'; }
1.14      albertel 1001:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1002:     my $cnum=$env{'course.'.$cid.'.num'};
                   1003:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1004:     my %data;
1.31      albertel 1005:     $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
1.77    ! albertel 1006:     return &Apache::lonnet::newput($queue,\%data,$cdom,$cnum);
1.14      albertel 1007: }
                   1008: 
                   1009: sub show_queue {
1.32      albertel 1010:     my ($queue,$with_selects)=@_;
1.14      albertel 1011:     my $result;
                   1012:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1013:     my $cnum=$env{'course.'.$cid.'.num'};
                   1014:     my $cdom=$env{'course.'.$cid.'.domain'};
1.59      albertel 1015: 
                   1016:     my @chosen_sections=
                   1017: 	&Apache::loncommon::get_env_multiple('form.chosensections');
                   1018:     &Apache::grades::init_perm();
                   1019:     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
                   1020:     &Apache::grades::reset_perm();
1.63      albertel 1021:     if (!(grep(/^all$/,@chosen_sections))) {
                   1022: 	$result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
                   1023: 	    '</tt>.</p> '."\n";
                   1024:     }
1.59      albertel 1025: 
1.16      albertel 1026:     my $regexp="^$symb\0";
1.30      albertel 1027:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31      albertel 1028:     my ($tmp)=%queue;
                   1029:     if ($tmp=~/^error: 2 /) {
1.33      albertel 1030: 	return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31      albertel 1031:     }
1.33      albertel 1032:     $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32      albertel 1033:     if ($with_selects) { $result.="<th></th>"; }
                   1034:     $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14      albertel 1035:     foreach my $key (sort(keys(%queue))) {
1.59      albertel 1036: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
                   1037: 	if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.32      albertel 1038: 	if ($key=~/locked$/ && !$with_selects) {
1.16      albertel 1039: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel 1040: 	    $result.="<tr><td>$title</td><td>$uname</td>";
1.16      albertel 1041: 	    $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32      albertel 1042: 	} elsif ($key=~/timestamp$/ && !$with_selects) {
1.16      albertel 1043: 	    my ($symb,undef) = split("\0",$key);
                   1044: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel 1045: 	    $result.="<tr><td>$title</td><td></td>";
1.16      albertel 1046: 	    $result.='<td>last queue modification time</td><td>'.
                   1047: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32      albertel 1048: 	} elsif ($key!~/(timestamp|locked)$/) {
1.16      albertel 1049: 	    my $title=&Apache::lonnet::gettitle($symb);
1.32      albertel 1050: 	    $result.="<tr>";
1.35      albertel 1051: 	    my $slot=$queue{$key}->[0];
                   1052: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
1.32      albertel 1053: 	    if ($with_selects) {
                   1054: 		my $ekey=&Apache::lonnet::escape($key);
                   1055: 		my ($action,$description)=('select',&mt('Select'));
                   1056: 		if (exists($queue{"$key\0locked"})) {
                   1057: 		    my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                   1058: 		    if ($me eq $queue{"$key\0locked"}) {
                   1059: 			($action,$description)=('resume',&mt('Resume'));
                   1060: 		    } else {
                   1061: 			($action,$description)=('unlock',&mt('Unlock'));
                   1062: 		    }
                   1063: 		}
1.62      albertel 1064: 		my $seclist;
                   1065: 		foreach my $sec (@chosen_sections) {
                   1066: 		    $seclist.='<input type="hidden" name="chosensections" 
                   1067:                                value="'.$sec.'" />';
                   1068: 		}
1.35      albertel 1069: 		if (time > $slot_data{'endtime'}) {
                   1070: 		    $result.=(<<FORM);
1.32      albertel 1071: <td>
                   1072: <form method="POST">
                   1073:  <input type="hidden" name="gradingkey" value="$ekey" />
                   1074:  <input type="hidden" name="queue" value="$queue" />
                   1075:  <input type="hidden" name="gradingaction" value="$action" />
                   1076:  <input type="hidden" name="webgrade" value="no" />
1.33      albertel 1077:  <input type="hidden" name="queuemode" value="selected" />
1.32      albertel 1078:  <input type="submit" name="submit" value="$description" />
1.62      albertel 1079:  $seclist
1.32      albertel 1080: </form>
                   1081: </td>
                   1082: FORM
1.35      albertel 1083: 
                   1084:                 } else {
                   1085: 		    $result.='<td>'.&mt("In Progress").'</td>'
                   1086: 		}
1.32      albertel 1087: 	    }
                   1088: 	    $result.="<td>$title</td><td>$uname</td>";
1.27      albertel 1089: 	    $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20      albertel 1090: 		&Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
                   1091: 		"</td></tr>";
1.16      albertel 1092: 	}
1.14      albertel 1093:     }
1.15      albertel 1094:     $result.="</table><hr />\n";
1.14      albertel 1095:     return $result;
                   1096: }
                   1097: 
1.34      albertel 1098: sub get_queue_counts {
                   1099:     my ($queue)=@_;
                   1100:     my $result;
                   1101:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1102:     my $cnum=$env{'course.'.$cid.'.num'};
                   1103:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1104:     my $regexp="^$symb\0";
                   1105:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1106:     my ($tmp)=%queue;
                   1107:     if ($tmp=~/^error: 2 /) {
                   1108: 	return (0,0,0);
                   1109:     }
                   1110:     my ($entries,$ready_to_grade,$locks)=(0,0,0);
                   1111:     foreach my $key (sort(keys(%queue))) {
                   1112: 	if ($key=~/locked$/) {
                   1113: 	    $locks++;
                   1114: 	} elsif ($key=~/timestamp$/) {
                   1115: 	    #ignore
                   1116: 	} elsif ($key!~/(timestamp|locked)$/) {
                   1117: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                   1118: 	    $entries++;
                   1119: 	    my $slot=$queue{$key}->[0];
                   1120: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1121: 	    if (time > $slot_data{'endtime'}) {
                   1122: 		$ready_to_grade++;
                   1123: 	    }
                   1124: 	}
                   1125:     }
                   1126:     return ($entries,$ready_to_grade,$locks);
                   1127: }
                   1128: 
1.49      albertel 1129: sub encode_queue_key {
                   1130:     my ($symb,$udom,$uname)=@_;
                   1131:     return "$symb\0queue\0$uname\@$udom";
                   1132: }
                   1133: 
1.14      albertel 1134: sub decode_queue_key {
                   1135:     my ($key)=@_;
                   1136:     my ($symb,undef,$user) = split("\0",$key);
                   1137:     my ($uname,$udom) = split('@',$user);
                   1138:     return ($symb,$uname,$udom);
                   1139: }
                   1140: 
                   1141: sub queue_key_locked {
1.30      albertel 1142:     my ($queue,$key,$cdom,$cnum)=@_;
1.33      albertel 1143:     if (!defined($cdom) || !defined($cnum)) {
                   1144: 	my (undef,$cid)=&Apache::lonxml::whichuser();
                   1145: 	$cnum=$env{'course.'.$cid.'.num'};
                   1146: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1147:     }
1.14      albertel 1148:     my ($key_locked,$value)=
1.30      albertel 1149: 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14      albertel 1150:     if ($key_locked eq "$key\0locked") {
                   1151: 	return $value;
                   1152:     }
                   1153:     return undef;
                   1154: }
                   1155: 
                   1156: sub pick_from_queue_data {
1.30      albertel 1157:     my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
                   1158:     foreach my $key (keys(%$queuedata)) {
1.68      albertel 1159: 	if ($key =~ /\0locked$/) { next; }
                   1160: 	if ($key =~ /\0timestamp$/) { next; }
1.14      albertel 1161: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
                   1162: 	if ($check_section) {
                   1163: 	    my $section=&Apache::lonnet::getsection($uname,$udom);
1.17      albertel 1164: 	    if ($section eq $check_section) {
1.33      albertel 1165: 		&Apache::lonxml::debug("my sec");
1.15      albertel 1166: 		next;
                   1167: 	    }
1.14      albertel 1168: 	}
1.30      albertel 1169: 	my $slot=$queuedata->{$key}[0];
1.14      albertel 1170: 	my %slot_data=&Apache::lonnet::get_slot($slot);
1.15      albertel 1171: 	if ($slot_data{'endtime'} > time) { 
1.33      albertel 1172: 	    &Apache::lonxml::debug("not time");
1.15      albertel 1173: 	    next;
                   1174: 	}
1.30      albertel 1175: 	if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33      albertel 1176: 	    &Apache::lonxml::debug("someone already has um.");
1.15      albertel 1177: 	    next;
                   1178: 	}
1.14      albertel 1179: 	return $key;
                   1180:     }
                   1181:     return undef;
                   1182: }
                   1183: 
1.15      albertel 1184: sub find_mid_grade {
1.30      albertel 1185:     my ($queue,$symb,$cdom,$cnum)=@_;
1.16      albertel 1186:     my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15      albertel 1187:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                   1188:     if ($todo) {
1.30      albertel 1189: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel 1190: 	if ($who eq $me) { return $todo; }
                   1191:     }
                   1192:     my $regexp="^$symb\0.*\0locked\$";
1.30      albertel 1193:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel 1194:     foreach my $key (keys(%locks)) {
                   1195: 	my $who=$locks{$key};
                   1196: 	if ($who eq $me) {
                   1197: 	    $todo=$key;
                   1198: 	    $todo=~s/\0locked$//;
                   1199: 	    return $todo;
                   1200: 	}
                   1201:     }
                   1202:     return undef;
                   1203: }
                   1204: 
1.32      albertel 1205: sub lock_key {
                   1206:     my ($queue,$todo)=@_;
                   1207:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                   1208:     my (undef,$cid)=&Apache::lonxml::whichuser();
                   1209:     my $cnum=$env{'course.'.$cid.'.num'};
                   1210:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1211:     my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
                   1212: 					$cdom,$cnum);
1.33      albertel 1213:     &Apache::lonxml::debug("success $success $todo");
1.32      albertel 1214:     if ($success eq 'ok') {
                   1215: 	return 1;
                   1216:     }
                   1217:     return 0;
                   1218: }
                   1219: 
1.14      albertel 1220: sub get_from_queue {
1.30      albertel 1221:     my ($queue)=@_;
1.14      albertel 1222:     my $result;
                   1223:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1224:     my $cnum=$env{'course.'.$cid.'.num'};
                   1225:     my $cdom=$env{'course.'.$cid.'.domain'};
1.32      albertel 1226:     my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33      albertel 1227:     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16      albertel 1228:     if ($todo) { return $todo; }
1.14      albertel 1229:     while (1) {
                   1230: 	my $starttime=time;
1.30      albertel 1231: 	&Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14      albertel 1232: 			     $cdom,$cnum);
1.33      albertel 1233: 	&Apache::lonxml::debug("$starttime");
1.14      albertel 1234: 	my $regexp="^$symb\0queue\0";
1.30      albertel 1235: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33      albertel 1236: 	#make a pass looking for a user _not_ in my section
1.14      albertel 1237: 	if ($env{'request.course.sec'}) {
1.33      albertel 1238: 	    &Apache::lonxml::debug("sce");
1.30      albertel 1239: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
                   1240: 					\%queue,$cdom,$cnum);
1.33      albertel 1241: 	    &Apache::lonxml::debug("sce $todo");
1.14      albertel 1242: 	}
1.33      albertel 1243: 	# no one _not_ in our section so look for any user that is
                   1244: 	# ready for grading
1.14      albertel 1245: 	if (!$todo) {
1.33      albertel 1246: 	    &Apache::lonxml::debug("no sce");
1.31      albertel 1247: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
                   1248: 					\%queue,$cdom,$cnum);
1.33      albertel 1249: 	    &Apache::lonxml::debug("no sce $todo");
1.14      albertel 1250: 	}
                   1251: 	# no user to grade 
                   1252: 	if (!$todo) { last; }
1.33      albertel 1253: 	&Apache::lonxml::debug("got $todo");
1.14      albertel 1254: 	# otherwise found someone so lets try to lock them
1.32      albertel 1255: 	# unless someone else already picked them
                   1256: 	if (!&lock_key($queue,$todo)) { next; }
1.14      albertel 1257: 	my (undef,$endtime)=
1.30      albertel 1258: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel 1259: 				 $cdom,$cnum);
1.33      albertel 1260: 	&Apache::lonxml::debug("emd  $endtime");
1.14      albertel 1261: 	# someone else already modified the queue, 
                   1262: 	# perhaps our picked user wass already fully graded between
                   1263: 	# when we picked him and when we locked his record? so lets
                   1264: 	# double check.
                   1265: 	if ($endtime != $starttime) {
                   1266: 	    my ($key,$value)=
1.30      albertel 1267: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel 1268: 				     $cdom,$cnum);
1.33      albertel 1269: 	    &Apache::lonxml::debug("check  $key .. $value");
1.14      albertel 1270: 	    if ($key eq $todo && ref($value)) {
                   1271: 	    } else {
1.30      albertel 1272: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel 1273: 				     $cdom,$cnum);
1.33      albertel 1274: 		&Apache::lonxml::debug("del");
1.14      albertel 1275: 		next;
                   1276: 	    }
                   1277: 	}
1.33      albertel 1278: 	&Apache::lonxml::debug("last $todo");
1.14      albertel 1279: 	last;
                   1280:     }
                   1281:     return $todo;
                   1282: }
                   1283: 
1.49      albertel 1284: sub select_user {
                   1285:     my ($symb,$cid)=&Apache::lonxml::whichuser();
                   1286: 
1.59      albertel 1287:     my @chosen_sections=
                   1288: 	&Apache::loncommon::get_env_multiple('form.chosensections');
1.49      albertel 1289:     &Apache::grades::init_perm();
1.59      albertel 1290:     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
1.49      albertel 1291:     &Apache::grades::reset_perm();
1.63      albertel 1292:     
                   1293:     my $result;
                   1294:     if (!(grep(/^all$/,@chosen_sections))) {
                   1295: 	$result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
                   1296: 	    '</tt>.</p> '."\n";
                   1297:     }
                   1298:     $result.='<table border="1">';
1.49      albertel 1299: 
                   1300:     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
                   1301: 	my ($uname,$udom) = split(/:/,$student);
1.59      albertel 1302: 	
1.49      albertel 1303: 	my %status = &get_student_status($symb,$cid,$udom,$uname);
                   1304: 	my $queue = 'none';
1.58      albertel 1305: 	my $cannot_grade;
                   1306: 	if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 1307: 	    $queue = 'reviewqueue';
1.58      albertel 1308: 	    if ($status{'reviewqueue'} eq 'in_progress') {
                   1309: 		$cannot_grade=1;
                   1310: 	    }
                   1311: 	} elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 1312: 	    $queue = 'gradingqueue';
1.58      albertel 1313: 	    if ($status{'gradingqueue'} eq 'in_progress') {
                   1314: 		$cannot_grade=1;
                   1315: 	    }
1.49      albertel 1316: 	}
                   1317: 	my $todo = 
                   1318: 	    &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
1.58      albertel 1319: 	if ($cannot_grade) {
                   1320: 	    $result.='<tr><td>&nbsp;</td><td>'.$fullname->{$student}.
                   1321: 		'</td><td>';
                   1322: 	} else {
1.62      albertel 1323: 	    my $seclist;
                   1324: 	    foreach my $sec (@chosen_sections) {
                   1325: 		$seclist.='<input type="hidden" name="chosensections" 
                   1326:                                value="'.$sec.'" />';
                   1327: 	    }
1.58      albertel 1328: 	    $result.=<<RESULT;
1.49      albertel 1329: <tr>
                   1330:   <td>
                   1331:     <form method="POST">
                   1332:       <input type="hidden" name="gradingkey" value="$todo" />
                   1333:       <input type="hidden" name="queue" value="$queue" />
                   1334:       <input type="hidden" name="webgrade" value="no" />
1.52      albertel 1335:       <input type="hidden" name="regrade" value="yes" />
1.62      albertel 1336:       <input type="submit" name="submit" value="Regrade" />
                   1337:       $seclist
1.49      albertel 1338:     </form>
                   1339:   <td>$fullname->{$student}</td>
                   1340:   <td>
                   1341: RESULT
1.58      albertel 1342:         }
1.49      albertel 1343:         if ($status{'status'} eq 'pass') {
                   1344: 	    $result .= '<font color="green">'.&mt('Passed').'</font>';
                   1345: 	} elsif ($status{'status'} eq 'fail') {
                   1346: 	    $result .= '<font color="red">'.&mt('Failed').'</font>';
                   1347: 	} elsif ($status{'status'} eq 'review') {
                   1348: 	    $result .= '<font color="blue">'.&mt('Under Review').'</font>';
                   1349: 	} elsif ($status{'status'} eq 'ungraded') {
                   1350: 	    $result .= &mt('Ungraded');
                   1351: 	} elsif ($status{'status'} ne '') {
                   1352: 	    $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
                   1353: 	} else {
                   1354: 	    $result.="&nbsp;";
                   1355: 	}
                   1356: 	if ($status{'version'}) {
                   1357: 	    $result .= ' '.&mt('Version').' '.$status{'version'};
                   1358: 	}
                   1359: 	$result.= '</td><td>';
                   1360: 	if ($status{'reviewqueue'} eq 'enqueued') {
                   1361: 	    $result .= &mt('Awaiting Review');
                   1362: 	} elsif ($status{'reviewqueue'} eq 'locked') {
                   1363: 	    $result .= &mt('Under Review');
1.58      albertel 1364: 	} elsif ($status{'reviewqueue'} eq 'in_progress') {
                   1365: 	    $result .= &mt('Still being worked on.');
1.49      albertel 1366: 	} elsif ($status{'gradingqueue'} eq 'enqueued') {
                   1367: 	    $result .= &mt('Awaiting Grading');
                   1368: 	} elsif ($status{'gradingqueue'} eq 'locked') {
                   1369: 	    $result .= &mt('Being Graded');
1.58      albertel 1370: 	} elsif ($status{'gradingqueue'} eq 'in_progress') {
                   1371: 	    $result .= &mt('Still being worked on.');
1.49      albertel 1372: 	} else {
                   1373: 	    $result.="&nbsp;";
                   1374: 	}
                   1375: 	$result.= '</td></tr>';
                   1376:     }
                   1377:     $result.='</table>';
                   1378:     return $result;
                   1379: }
                   1380: 
                   1381: sub get_student_status {
                   1382:     my ($symb,$cid,$udom,$uname)=@_;
                   1383:     my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
                   1384: 					  $udom,$uname);
                   1385:     my %status;
                   1386:     $status{'status'}=$record{'resource.status'};
                   1387:     $status{'version'}=$record{'resource.version'};
                   1388:     $status{'grader'}=$record{'resource.grader'};
                   1389:     $status{'reviewqueue'}=&check_queue_for_key($cid,'reviewqueue',
                   1390: 				       &encode_queue_key($symb,$udom,$uname));
                   1391:     $status{'gradingqueue'}=&check_queue_for_key($cid,'gradingqueue',
                   1392: 				       &encode_queue_key($symb,$udom,$uname));
                   1393:     return %status;
                   1394: }
                   1395: 
1.1       albertel 1396: sub start_ClosingParagraph {
                   1397:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1398:     my $result;
                   1399:     if ($target eq 'web') {
1.13      albertel 1400:     } elsif ($target eq 'webgrade') {
                   1401: 	&Apache::lonxml::startredirection();
1.1       albertel 1402:     }
                   1403:     return $result;
                   1404: }
                   1405: 
                   1406: sub end_ClosingParagraph {
                   1407:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1408:     my $result;
                   1409:     if ($target eq 'web') {
1.13      albertel 1410:     } elsif ($target eq 'webgrade') {
                   1411: 	&Apache::lonxml::endredirection();
1.1       albertel 1412:     }
                   1413:     return $result;
                   1414: }
                   1415: 
1.19      albertel 1416: sub get_id {
                   1417:     my ($parstack,$safeeval)=@_;
                   1418:     my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
                   1419:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                   1420:     return $id;
                   1421: }
                   1422: 
1.1       albertel 1423: my %dimension;
                   1424: sub start_Dimension {
                   1425:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1426:     undef(%dimension);
1.19      albertel 1427:     my $dim_id=&get_id($parstack,$safeeval);
1.9       albertel 1428:     $Apache::bridgetask::dimension=$dim_id;
                   1429:     push(@Apache::bridgetask::dimensionlist,$dim_id);
                   1430:     undef(@Apache::bridgetask::instance);
1.20      albertel 1431:     $Apache::bridgetask::dimensionmandatory{$dim_id}=
                   1432: 	&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.54      albertel 1433:     &Apache::lonxml::startredirection();
                   1434:     return &internal_location($dim_id);
1.1       albertel 1435: }
                   1436: 
1.13      albertel 1437: sub get_instance {
1.75      albertel 1438:     my ($dim)=@_;
                   1439:     my $rand_alg=&Apache::lonnet::get_rand_alg();
                   1440:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
                   1441: 	$rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
                   1442: 	$rand_alg eq '64bit4' ) {
                   1443: 	&Apache::response::pushrandomnumber();
                   1444: 	my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
                   1445: 	my $num=@order;
                   1446: 	my $version=&get_version();
                   1447: 	my $which=($version-1)%$num;
                   1448: 	return $order[$which];
                   1449:     } else {
                   1450: 	my ($version,$previous) = &get_version();
                   1451: 	my $instance = 
                   1452: 	    $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
                   1453: 	if (defined($instance)) { return $instance; }
                   1454: 
                   1455: 	&Apache::response::pushrandomnumber();
                   1456: 	my @instances = @{$dimension{'instances'}};
                   1457: 	# remove disabled instances
                   1458: 	for (my $i=0; $i < $#instances; $i++) {
                   1459: 	    if ($dimension{$instances[$i].'.disabled'}) {
                   1460: 		splice(@instances,$i,1);
                   1461: 		$i--;
                   1462: 	    }
                   1463: 	}
                   1464: 	@instances = &Math::Random::random_permutation(@instances);
                   1465: 	$instance  = $instances[($version-1)%scalar(@instances)];
                   1466: 	$Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = 
                   1467: 	    $instance;
                   1468: 	&Apache::response::poprandomnumber();
                   1469: 	return $instance;
                   1470:     }
1.13      albertel 1471: }
                   1472: 
1.18      albertel 1473: {
                   1474:     my $last_link;
                   1475:     sub end_Dimension {
                   1476: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54      albertel 1477: 	my $result=&Apache::lonxml::endredirection();
1.25      albertel 1478: 	my $dim=&get_id($parstack,$safeeval);
1.75      albertel 1479: 	my $instance=&get_instance($dim);
1.25      albertel 1480: 	my $version=&get_version();
1.18      albertel 1481: 	if ($target eq 'web') {
1.47      albertel 1482: 	    @Apache::scripttag::parser_env = @_;
                   1483: 	    $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1.76      albertel 1484: 	    my @instances = $instance;
                   1485: 	    if (&Apache::response::showallfoils()) {
                   1486: 		@instances = @{$dimension{'instances'}};
                   1487: 	    }
                   1488: 	    foreach my $instance (@instances) {
                   1489: 		@Apache::scripttag::parser_env = @_;
                   1490: 		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
                   1491: 		if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
                   1492: 		    $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
                   1493: 
                   1494: 		    my $dim_status=$Apache::lonhomework::history{"resource.$version.$dim.status"};
                   1495: 		    my $mandatory='Mandatory';
                   1496: 		    if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
                   1497: 			$mandatory='Optional';
                   1498: 		    }
                   1499: 		    my $dim_info="<div class='$dim_status'>\n";
                   1500: 		    if ($dim_status eq 'pass') {
                   1501: 			$dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1.54      albertel 1502: 		    }
1.76      albertel 1503: 		    if ($dim_status eq 'fail') {
                   1504: 			$dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1.53      albertel 1505: 		    }
1.76      albertel 1506: 		    my $man_count=0;
                   1507: 		    my $man_passed=0;
                   1508: 		    my $opt_count=0;
                   1509: 		    my $opt_passed=0;
                   1510: 		    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                   1511: 			if ($dimension{$instance.'.criteria.'.$id.'.mandatory'} 
                   1512: 			    eq 'N') {
                   1513: 			    $opt_count++;
                   1514: 			    if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
                   1515: 				$opt_passed++;
                   1516: 			    }
                   1517: 			} else {
                   1518: 			    $man_count++;
                   1519: 			    if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
                   1520: 				$man_passed++;
                   1521: 			    }
                   1522: 			}
1.22      albertel 1523: 		    }
1.76      albertel 1524: 		    if ($man_passed eq $man_count) { $man_passed='all'; }
                   1525: 		    my $opt_req=$dimension{$instance.'.optionalrequired'};
                   1526: 		    if ($opt_req !~ /\S/) { $opt_req='0'; }
                   1527: 		    $dim_info.="\n<p>".&mt('You passed [_1] of the [_2] mandatory components and [_3] of the [_4] optional components, of which you were required to pass [_5].',$man_passed,$man_count,$opt_passed,$opt_count,$opt_req)."</p>\n</div>";
                   1528: 
                   1529: 		    my $internal_location=&internal_location($dim);
                   1530: 		    $result=~s/\Q$internal_location\E/$dim_info/;
                   1531: 
                   1532: 		    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                   1533: 			my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
                   1534: 			my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
                   1535: 			my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
                   1536: 			if ($mandatory) {
                   1537: 			    $mandatory='Mandatory';
                   1538: 			} else {
                   1539: 			    $mandatory='Optional';
                   1540: 			}
                   1541: 			if ($status eq 'fail') {
                   1542: 			} elsif ($status eq 'pass') {
                   1543: 			} else {
                   1544: 			    &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
                   1545: 			}
                   1546: 			my $status_display=$status;
                   1547: 			$status_display=~s/^([a-z])/uc($1)/e;
                   1548: 			@Apache::scripttag::parser_env = @_;
                   1549: 			$result.='<div class="'.$status.'"><h4>'.$mandatory.
                   1550: 			    ' Criteria</h4><p>';
                   1551: 			@Apache::scripttag::parser_env = @_;
                   1552: 			$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
                   1553: 			$result.='</p><p class="grade">'.$status_display.'</p>';
                   1554: 			if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
                   1555: 			    $result.='<p class="comment">'.$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</p>';
                   1556: 			}
                   1557: 			$result.='</div>';
1.22      albertel 1558: 		    }
                   1559: 		}
                   1560: 	    }
1.18      albertel 1561: 	} elsif ($target eq 'webgrade') {
1.47      albertel 1562: 	    # in case of any side effects that we need
                   1563: 	    @Apache::scripttag::parser_env = @_;
                   1564: 	    &Apache::scripttag::xmlparse($dimension{'intro'});
                   1565: 	    @Apache::scripttag::parser_env = @_;
                   1566: 	    &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.18      albertel 1567: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                   1568: 		my $link='criteria_'.$instance.'_'.$id;
1.25      albertel 1569: 		my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19      albertel 1570: 		$result.='<tr><td width="100%" valign="top">'.
1.18      albertel 1571: 		    '<a name="'.$link.'" />'.
                   1572: 		    '<a name="next_'.$last_link.'" />'.
1.47      albertel 1573: 		    '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">';
                   1574: 		@Apache::scripttag::parser_env = @_;
                   1575: 		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
                   1576: 		$result.='</textarea>'.
1.18      albertel 1577: 		    #$dimension{$instance.'.criteria.'.$id}.
                   1578: 		    '</td>'.
1.19      albertel 1579: 		    '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25      albertel 1580: 		    '<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 1581: 		    '</td>'.
                   1582: 		    '<td>'.
1.47      albertel 1583: 		    '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label></nobr><br />'.
1.30      albertel 1584: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
                   1585: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
                   1586: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18      albertel 1587: 		    '</td>'.
                   1588: 		    '<td>'.
                   1589: 		    '<a href="#'.$last_link.'">Prev</a><br />'.
1.20      albertel 1590: 		    '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
1.18      albertel 1591: 		    '</td></tr>';
                   1592: 		$last_link=$link;
                   1593: 	    }
1.22      albertel 1594: 	} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19      albertel 1595: 	    my $optional_passed=0;
1.20      albertel 1596: 	    my $mandatory_failed=0;
                   1597: 	    my $ungraded=0;
                   1598: 	    my $review=0;
1.19      albertel 1599: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel 1600: 		my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
                   1601: 		$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20      albertel 1602: 		my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
                   1603: 		if ($status eq 'pass') {
                   1604: 		    if (!$mandatory) { $optional_passed++; }
                   1605: 		} elsif ($status eq 'fail') {
                   1606: 		    if ($mandatory) { $mandatory_failed++; }
1.21      albertel 1607: 		} elsif ($status eq 'review') {
                   1608: 		    $review++;
1.20      albertel 1609: 		} elsif ($status eq 'ungraded') {
                   1610: 		    $ungraded++;
1.21      albertel 1611: 		} else {
1.47      albertel 1612: 		    $ungraded++;
1.19      albertel 1613: 		}
                   1614: 	    }
1.20      albertel 1615: 	    if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
                   1616: 		$mandatory_failed++;
                   1617: 	    }
1.21      albertel 1618: 	    &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 1619: 	    if ($review) {
1.25      albertel 1620: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1621: 		    'review';
1.20      albertel 1622: 	    } elsif ($ungraded) {
1.25      albertel 1623: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1624: 		    'ungraded';
1.20      albertel 1625: 	    } elsif ($mandatory_failed) {
1.25      albertel 1626: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1627: 		    'fail';
1.20      albertel 1628: 	    } else {
1.25      albertel 1629: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1630: 		    'pass';
1.20      albertel 1631: 	    }
1.69      albertel 1632: 	} else {
                   1633: 	    # any other targets no output
                   1634: 	    undef($result);
1.13      albertel 1635: 	}
1.18      albertel 1636: 	return $result;
1.1       albertel 1637:     }
                   1638: }
                   1639: 
                   1640: sub start_IntroParagraph {
                   1641:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1642:     my $result;
1.13      albertel 1643:     if ($target eq 'web' || $target eq 'webgrade') {
1.47      albertel 1644: 	if ($tagstack->[-2] eq 'Dimension') {
                   1645: 	    $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser);
                   1646: 	
                   1647: 	} elsif ($target eq 'webgrade') {
                   1648: 	    &Apache::lonxml::get_all_text('/introparagraph',$parser);
1.1       albertel 1649: 	}
1.47      albertel 1650: 	
1.1       albertel 1651:     }
                   1652:     return $result;
                   1653: }
                   1654: 
                   1655: sub end_IntroParagraph {
                   1656: }
                   1657: 
                   1658: sub start_Instance {
                   1659:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel 1660:     my $id=&get_id($parstack,$safeeval);
                   1661:     push(@{$dimension{'instances'}},$id);
                   1662:     push(@Apache::bridgetask::instance,$id);
                   1663:     push(@Apache::bridgetask::instancelist,$id);
1.20      albertel 1664:     $dimension{$id.'.optionalrequired'}=
1.19      albertel 1665: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75      albertel 1666:     my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
                   1667:     if (lc($disabled) eq 'yes') {
                   1668: 	$dimension{$id.'.disabled'}='1';
                   1669:     }
1.1       albertel 1670:     return '';
                   1671: }
                   1672: 
                   1673: sub end_Instance {
                   1674: }
                   1675: 
                   1676: sub start_InstanceText {
                   1677:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47      albertel 1678:     my $instance_id=$Apache::bridgetask::instance[-1];
                   1679:     my $text=&Apache::lonxml::get_all_text('/instancetext',$parser);
1.13      albertel 1680:     if ($target eq 'web' || $target eq 'webgrade') {
1.47      albertel 1681: 	$dimension{$instance_id.'.text'}=$text;
1.1       albertel 1682:     }
                   1683:     return '';
                   1684: }
                   1685: 
                   1686: sub end_InstanceText {
                   1687:     return '';
                   1688: }
                   1689: 
                   1690: sub start_Criteria {
                   1691:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel 1692:     my $instance_id=$Apache::bridgetask::instance[-1];
1.47      albertel 1693:     my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser);
1.21      albertel 1694:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.19      albertel 1695: 	my $id=&get_id($parstack,$safeeval);
1.1       albertel 1696: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19      albertel 1697: 	$dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
                   1698: 	    &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel 1699: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
                   1700:     }
                   1701:     return '';
                   1702: }
                   1703: 
1.47      albertel 1704: sub end_Criteria {
                   1705: }
                   1706: 
1.4       albertel 1707: sub proctor_validation_screen {
                   1708:     my ($slot) = @_;
                   1709:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel 1710:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44      albertel 1711:     my $name=&Apache::loncommon::plainname($user,$domain);
                   1712:     
1.4       albertel 1713:     my $msg;
1.11      albertel 1714:     if ($env{'form.proctorpassword'}) {
1.4       albertel 1715: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                   1716: 	    .'</font></p>';
                   1717:     }
1.47      albertel 1718:     if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4       albertel 1719:     my $result= (<<ENDCHECKOUT);
                   1720: <h2>Proctor Validation</h2>
                   1721:     <p>Your room's proctor needs to validate your access to this resource.</p>
                   1722:     $msg
1.11      albertel 1723: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4       albertel 1724: <input type="hidden" name="validate" value="yes" />
                   1725: <input type="hidden" name="submitted" value="yes" />
                   1726: <table>
1.44      albertel 1727:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4       albertel 1728:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46      albertel 1729:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4       albertel 1730: </table>
                   1731: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
1.44      albertel 1732: <table border="1">
                   1733:   <tr><td>
                   1734:     <table>
                   1735:       <tr><td colspan="2">Student who should be logged in is:</td></tr>
                   1736:       <tr><td>Name:</td><td>$name</td></tr>
1.45      albertel 1737:       <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.44      albertel 1738:       <tr><td>Usename</td><td>$user\@$domain</td></tr>
                   1739:       <tr><td colspan="2"><img src="$url" /></td></tr>
                   1740:     </table>
                   1741:   </tr></td>
                   1742: </table>
1.4       albertel 1743: </form>
                   1744: ENDCHECKOUT
                   1745:     return $result;
                   1746: }
                   1747: 
1.1       albertel 1748: 1;
                   1749: __END__

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