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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.151   ! albertel    4: # $Id: bridgetask.pm,v 1.150 2006/05/12 06:55:46 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 {
1.151   ! albertel   43:     &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','Instance','InstanceText','Criteria','ClosingParagraph'));
1.1       albertel   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.81      albertel   63:     my ($slot_name,$slot,$type)=@_;
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) {
1.138     albertel   69: 	my ($puser,$pdom)=(split(':',$possible));
1.4       albertel   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: 	    }
1.150     albertel   82: 	    if ($authenticated) {
                     83: 		&create_new_version($type,$user,$domain,$slot_name);
1.4       albertel   84: 		return 1;
                     85: 	    }
                     86: 	}
                     87:     }
                     88:     return 0;
                     89: }
                     90: 
1.150     albertel   91: sub create_new_version {
                     92:     my ($type,$user,$domain,$slot_name) = @_;
                     93:     if ($type eq 'Task') {
                     94: 	# increment version
                     95: 	my $version=
                     96: 	    $Apache::lonhomework::history{'resource.0.version'};
                     97: 	$version++;
                     98: 	
                     99: 	#clean out all current results
                    100: 	foreach my $key (keys(%Apache::lonhomework::history)) {
                    101: 	    if ($key=~/^resource\.0\./) {
                    102: 		$Apache::lonhomework::results{$key}='';
                    103: 	    }
                    104: 	}
                    105: 	
                    106: 	#setup new version and who did it
                    107: 	$Apache::lonhomework::results{'resource.0.version'}=$version;
                    108: 	if (defined($user) && defined($domain)) {
                    109: 	    $Apache::lonhomework::results{"resource.$version.0.checkedin"}=
                    110: 		$user.':'.$domain;
                    111: 	}
                    112: 	if (defined($slot_name)) {
                    113: 	    $Apache::lonhomework::results{"resource.$version.0.checkedin.slot"}=
                    114: 		$slot_name;
                    115: 	}
                    116:     } elsif ($type eq 'problem') {
                    117: 	&Apache::lonxml::debug("authed $slot_name");
                    118: 	if (defined($user) && defined($domain)) {
                    119: 	    $Apache::lonhomework::results{"resource.0.checkedin"}=
                    120: 		$user.':'.$domain;
                    121: 	}
                    122: 	if (defined($slot_name)) {
                    123: 	    $Apache::lonhomework::results{"resource.0.checkedin.slot"}=
                    124: 		$slot_name;
                    125: 	}
                    126:     }
                    127: }
                    128: 
1.25      albertel  129: sub get_version {
1.29      albertel  130:     my ($version,$previous);
1.25      albertel  131:     if ($env{'form.previousversion'} && 
1.36      albertel  132: 	$env{'form.previousversion'} ne 'current' &&
1.89      albertel  133: 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
1.29      albertel  134: 	$version=$env{'form.previousversion'};
                    135: 	$previous=1;
                    136:     } else {
1.150     albertel  137: 	if (defined($Apache::lonhomework::results{'resource.0.version'})) {
                    138: 	    $version=$Apache::lonhomework::results{'resource.0.version'};
                    139: 	} elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
                    140: 	    $version=$Apache::lonhomework::history{'resource.0.version'};
                    141: 	}
1.29      albertel  142: 	$previous=0;
                    143:     }
                    144:     if (wantarray) {
                    145: 	return ($version,$previous);
1.25      albertel  146:     }
1.29      albertel  147:     return $version;
1.25      albertel  148: }
                    149: 
1.8       albertel  150: sub add_previous_version_button {
1.25      albertel  151:     my ($status)=@_;
1.8       albertel  152:     my $result;
1.89      albertel  153:     if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
1.25      albertel  154: 	return '';
                    155:     }
1.89      albertel  156:     if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
1.29      albertel  157: 	$status ne 'NEEDS_CHECKIN') {
1.25      albertel  158: 	return '';
                    159:     }
1.29      albertel  160:     my $version=&get_version();
                    161:     if ($env{'form.previousversion'} ne '' &&
                    162: 	$env{'form.previousversion'} eq $version) {
                    163: 	$result.="<h3>".&mt("Showing previous version [_1]",$version).
                    164: 	    "</h3>\n";
                    165:     }
                    166:     my @to_show;
1.89      albertel  167:     foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
                    168: 	if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
1.29      albertel  169: 	    push(@to_show,$test_version);
                    170: 	}
                    171:     }
                    172:     my $list='<option>'.
                    173: 	join("</option>\n<option>",@to_show).
                    174: 	     "</option>\n";
1.36      albertel  175:     $list.='<option value="current">'.&mt('Current').'</option>';
1.115     albertel  176:     $result.='<form name="getprevious" method="post" action="';
1.29      albertel  177:     my $uri=$env{'request.uri'};
                    178:     if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    179:     $result.=$uri.'">'.
                    180: 	&mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
                    181: <option>'.&mt('Pick one').'</option>
                    182: '.$list.'
                    183: </select>')."</form>";
1.8       albertel  184:     return $result;
                    185: }
                    186: 
1.13      albertel  187: sub add_grading_button {
1.59      albertel  188:     my (undef,$cid)=&Apache::lonxml::whichuser();
                    189:     my $cnum=$env{'course.'.$cid.'.num'};
                    190:     my $cdom=$env{'course.'.$cid.'.domain'};
1.144     albertel  191:     my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
                    192: 
1.59      albertel  193:     my $size=5;
                    194:     if (scalar(keys(%sections)) < 3) {
                    195: 	$size=scalar(keys(%sections))+2;
                    196:     }
1.122     albertel  197:     my $sec_select = '<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
1.59      albertel  198:     $sec_select .= "<option value='all' selected='selected'>all</option>\n";
                    199:     foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
1.122     albertel  200: 	$sec_select .= "<option value=\"$sec\">$sec</option>\n";
1.59      albertel  201:     }
                    202:     $sec_select .= "<option value='none'>none</option></select>\n";
                    203:     
1.29      albertel  204:     my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13      albertel  205: 	&mt("Get a submission to grade").'" />';
                    206:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.40      albertel  207:     if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.34      albertel  208: 	my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.106     albertel  209: 	$result.='<table><tr>';
                    210: 	$result.='<td rowspan="4">Specify a section: </td><td rowspan="4">'.$sec_select.'</td>';
                    211: 	$result.='<td>'.' <input type="submit" name="reviewagrading" value="'.
                    212: 	    &mt("Select an entry from the grading queue:").'" /> ';
1.34      albertel  213: 
1.107     albertel  214: 	$result.= &mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).' </td></tr>'."\n";
1.34      albertel  215: 
                    216: 	($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
1.106     albertel  217: 	$result.='<tr><td>'.
                    218: 	    ' <input type="submit" name="reviewasubmission" value="'.
                    219: 	    &mt("Select an entry from the review queue:").'" /> ';
                    220: 	$result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
                    221: 		     $entries,$ready,$locks).'</td></tr>'."\n";
                    222: 	$result.='<tr><td> <input type="submit" name="regradeasubmission" value="'.
                    223: 	    &mt("List of user's grade status").'" /> </td></tr></table>'."\n";
1.105     albertel  224: 	$result.='<p> <input type="submit" name="regradeaspecificsubmission" value="'.
1.106     albertel  225: 	    &mt("Regrade specific user:").'" />'."\n";
1.105     albertel  226: 	$result.='<input type="text" size="12" name="gradinguser" />';
                    227: 	$result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
                    228: 						     'gradingdomain');
                    229: 	$result.=' '.
                    230: 	    &Apache::loncommon::selectstudent_link('gradesubmission',
                    231: 						   'gradinguser',
                    232: 						   'gradingdomain');
                    233: 	$result.=&Apache::loncommon::studentbrowser_javascript();
1.123     albertel  234: 	$result.= '</p>';
1.144     albertel  235:     }
1.13      albertel  236:     return $result;
                    237: }
                    238: 
1.22      albertel  239: sub add_request_another_attempt_button {
1.38      albertel  240:     my ($text)=@_;
                    241:     if (!$text) { $text="Request another attempt"; }
1.25      albertel  242:     my $result;
1.36      albertel  243:     my $symb=&Apache::lonnet::symbread();
1.149     albertel  244:     # not a slot access based resource
                    245:     my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
                    246:     if ($useslots =~ /^\s*no\s*$/i) {
                    247: 	return '';
                    248:     }
                    249: 
1.37      albertel  250:     my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38      albertel  251:     my $action='get_reservation';
1.37      albertel  252:     if ($slot_name) {
1.38      albertel  253: 	$text="Change reservation.";
                    254: 	$action='change_reservation';
1.37      albertel  255: 	my $description=&Apache::slotrequest::get_description($slot_name,
                    256: 							      $slot);
                    257: 	$result.=(<<STUFF);
                    258: <p> Will be next available: $description </p>
                    259: STUFF
                    260:     }
1.38      albertel  261:     
                    262:     if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
                    263:     $symb=&Apache::lonnet::escape($symb);
1.115     albertel  264:     $result.='<form method="post" action="/adm/slotrequest">'.
1.38      albertel  265: 	'<input type="hidden" name="symb" value="'.$symb.'" />'.
                    266: 	'<input type="hidden" name="command" value="'.$action.'" />'.
                    267: 	'<input type="submit" name="requestattempt" value="'.
                    268: 	&mt($text).'" />'.
                    269: 	'</form>';
1.25      albertel  270:     return $result;
1.22      albertel  271: }
                    272: 
1.30      albertel  273: sub preserve_grade_info {
                    274:     my $result;
                    275:     # if we are viewing someone else preserve that info
                    276:     if (defined $env{'form.grade_symb'}) {
                    277: 	foreach my $field ('symb','courseid','domain','username') {
                    278: 	    $result .= '<input type="hidden" name="grade_'.$field.
                    279: 		'" value="'.$env{"form.grade_$field"}.'" />'."\n";
                    280: 	}
                    281:     }
                    282:     return $result;
                    283: }
                    284: 
1.53      albertel  285: sub style {
1.125     albertel  286:     my ($target) = @_;
                    287:     if ($target eq 'web'
                    288: 	|| $target eq 'webgrade') {
                    289: 	return (<<STYLE);
1.126     albertel  290: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task.css" />
1.53      albertel  291: STYLE
1.125     albertel  292:     }
                    293:     return;
1.53      albertel  294: }
                    295: 
1.54      albertel  296: sub show_task {
                    297:     my ($status,$previous)=@_;
                    298:     if (!$previous && (
                    299: 		       ( $status eq 'CLOSED' ) ||
                    300: 		       ( $status eq 'BANNED') ||
                    301: 		       ( $status eq 'UNAVAILABLE') ||
                    302: 		       ( $status eq 'NOT_IN_A_SLOT') ||
                    303: 		       ( $status eq 'NEEDS_CHECKIN') ||
                    304: 		       ( $status eq 'WAITING_FOR_GRADE') ||
1.150     albertel  305: 		       ( $status eq 'INVALID_ACCESS') ||
                    306: 		       ( &get_version() eq ''))) {
1.54      albertel  307: 	return 0;
                    308:     }
1.64      albertel  309:     if ($env{'form.donescreen'}) { return 0; }
1.54      albertel  310:     return 1;
                    311: }
                    312: 
                    313: sub internal_location {
                    314:     my ($id)=@_;
                    315:     return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
                    316: }
                    317: 
1.60      albertel  318: sub submission_time_stamp {
                    319:     my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
                    320:     my $submissiontime;
1.89      albertel  321:     my $version=$Apache::lonhomework::history{'resource.0.version'};
1.60      albertel  322:     for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
                    323: 	if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
                    324: 	    $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
                    325: 	}
                    326:     }
                    327:     my $result;
                    328:     if ($submissiontime) {
1.89      albertel  329: 	my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
1.60      albertel  330: 	my %slot=&Apache::lonnet::get_slot($slot_name);
                    331: 	my $diff = $slot{'endtime'} - $submissiontime;
1.71      albertel  332: 	my ($color,$when)=('#FF6666','after');
                    333: 	if ($diff > 0) { ($color,$when)=('#336600','before'); }
1.60      albertel  334: 	my $info;
                    335: 	if ($diff%60) { $info=($diff%60).' seconds'; }
                    336: 	$diff=int($diff/60);
                    337: 	if ($diff%60) { $info=($diff%60).' minutes '.$info; }
                    338: 	$diff=int($diff/60);
                    339: 	if ($diff) {    $info=$diff.' hours '.$info; }
                    340: 	$result='<p><font color="'.$color.'">'.
                    341: 	    &mt('Student submitted [_1] [_2] the deadline. 
                    342:                  (Submission was at [_3], end of period was [_4].)',
                    343: 		$info,$when,scalar(localtime($submissiontime)),
                    344: 		scalar(localtime($slot{'endtime'}))).
                    345: 		'</font></p>';
                    346:     }
                    347:     return $result;
                    348: }
                    349: 
1.119     albertel  350: sub file_list {
                    351:     my ($files,$uname,$udom) = @_;
                    352:     if (!defined($uname) || !defined($udom)) {
                    353: 	(undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
                    354:     }
1.70      albertel  355:     my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.119     albertel  356: 
1.120     albertel  357:     my $file_list="<ul class=\"LC_GRADING_handininfo\">\n";
1.119     albertel  358:     foreach my $partial_file (split(',',$files)) {
1.70      albertel  359: 	my $file=$file_url.$partial_file;
                    360: 	$file=~s|/+|/|g;
                    361: 	&Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.73      albertel  362: 	$file_list.='<li><nobr><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
1.109     albertel  363: 	    &Apache::loncommon::icon($file).'" border="0"> '.$file.
1.70      albertel  364: 	    '</a></nobr></li>'."\n";
                    365:     }
                    366:     $file_list.="</ul>\n";
1.119     albertel  367:     return $file_list;
                    368: }
                    369: 
                    370: sub webgrade_standard_info {
                    371:     my ($version)=&get_version();
                    372: 
                    373:     my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
1.70      albertel  374: 
1.118     albertel  375:     my %lt=&Apache::lonlocal::texthash('done' => 'Next Item',
                    376: 				       'stop' => 'Quit Grading',
1.143     albertel  377: 				       'fail' => 'Fail Rest',
1.70      albertel  378: 				       );
                    379: 				       
                    380:     my $result=<<INFO;
1.120     albertel  381:   <div class="LC_GRADING_maincontrols">
1.111     albertel  382:     <input type="submit" name="next" value="$lt{'done'}" />
                    383:     <input type="submit" name="stop" value="$lt{'stop'}" />
1.143     albertel  384:     <input type="button" name="fail" value="$lt{'fail'}" 
                    385:            onclick="javascript:onFailRest()" />
1.111     albertel  386:   </div>
1.70      albertel  387:   $file_list
                    388: INFO
                    389:     return $result;
                    390: }
                    391: 
1.1       albertel  392: sub start_Task {
1.87      albertel  393:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1       albertel  394: 
1.4       albertel  395:     my ($status,$accessmsg,$slot);
1.16      albertel  396:     if ($target ne 'webgrade') {
1.70      albertel  397: 	&Apache::structuretags::init_problem_globals('Task');
1.16      albertel  398: 	&Apache::structuretags::initialize_storage();
                    399: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.74      albertel  400: 	if ($env{'request.state'} eq 'construct') {
                    401: 	    &Apache::structuretags::setup_rndseed($safeeval);
                    402: 	}
1.16      albertel  403:     } 
                    404: 
1.4       albertel  405:     $Apache::lonhomework::parsing_a_task=1;
1.141     albertel  406: 
                    407:     my $name;
                    408:     if ($target eq 'web' || $target eq 'webgrade') {
                    409: 	$name = &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    410:     }
                    411: 
1.145     albertel  412:     my ($result,$form_tag_start);
                    413:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
                    414: 	|| $target eq 'edit') {
                    415: 	($result,$form_tag_start) =
                    416: 	    &Apache::structuretags::page_start($target,$token,$tagstack,
                    417: 					       $parstack,$parser,$safeeval,
1.146     albertel  418: 					       $name,&style($target));
1.145     albertel  419: 	$result .= '<div class="LC_task">'."\n";
                    420:     }
1.123     albertel  421: 
1.74      albertel  422:     if ($target eq 'web' && $env{'request.state'} ne 'construct') {
1.147     albertel  423: 	if ($Apache::lonhomework::queuegrade
                    424: 	    || $Apache::lonhomework::modifygrades) {
1.141     albertel  425: 	    $result.='<form name="gradesubmission" method="post" action="';
1.13      albertel  426: 	    my $uri=$env{'request.uri'};
                    427: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
1.141     albertel  428: 	    $result.=$uri.'">'.&add_grading_button()."</form>";
1.38      albertel  429: 	    my $symb=&Apache::lonnet::symbread();
1.40      albertel  430: 	    if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.141     albertel  431: 		$result.='<form method="post" name="slotrequest" action="/adm/slotrequest">'.
1.40      albertel  432: 		    '<input type="hidden" name="symb" value="'.$symb.'" />'.
                    433: 		    '<input type="hidden" name="command" value="showslots" />'.
                    434: 		    '<input type="submit" name="requestattempt" value="'.
                    435: 		    &mt('Show Slot list').'" />'.
                    436: 		    '</form>';
1.108     albertel  437: 		my $target_id = 
                    438: 		    &Apache::lonstathelpers::make_target_id({symb => $symb,
                    439: 							     part => '0'});
1.141     albertel  440: 		$result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
1.108     albertel  441: 		    '<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
                    442: 		    '<input type="hidden" name="reportSelected" value="grading_analysis" />'.
                    443: 		    '<input type="submit" name="grading" value="'.
                    444: 		    &mt('Show Grading Status').'" />'.
                    445: 		    '</form>';
1.40      albertel  446: 	    }
1.13      albertel  447: 	}
1.8       albertel  448:     }
1.74      albertel  449:     if ($target eq 'web' && $env{'request.state'} eq 'construct') {
                    450: 	$form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
                    451:     }
1.21      albertel  452:     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1       albertel  453: 	$target eq 'tex') {
1.29      albertel  454: 	my ($version,$previous)=&get_version();
1.14      albertel  455: 	($status,$accessmsg,my $slot_name,$slot) = 
1.81      albertel  456: 	    &Apache::lonhomework::check_slot_access('0','Task');
1.150     albertel  457: 	if ($status eq 'CAN_ANSWER' && $version eq '' && $slot_name eq '') {
                    458: 	    &create_new_version('Task');
                    459: 	    ($version,$previous)=&get_version();
                    460: 	}
                    461: 
1.9       albertel  462: 	push(@Apache::inputtags::status,$status);
1.14      albertel  463: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  464: 	my $expression='$external::datestatus="'.$status.'";';
1.89      albertel  465: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
1.1       albertel  466: 	&Apache::run::run($expression,$safeeval);
                    467: 	&Apache::lonxml::debug("Got $status");
1.141     albertel  468: 	$result.=&add_previous_version_button($status);
1.54      albertel  469: 	if (!&show_task($status,$previous)) {
1.87      albertel  470: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.1       albertel  471: 	    if ( $target eq "web" ) {
1.74      albertel  472: 		if ($env{'request.state'} eq 'construct') {
                    473: 		    $result.=$form_tag_start;
                    474: 		}
1.4       albertel  475: 		my $msg;
1.1       albertel  476: 		if ($status eq 'UNAVAILABLE') {
                    477: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  478: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    479: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.38      albertel  480: 		    $msg.=&add_request_another_attempt_button("Sign up for time to work.");
1.4       albertel  481: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    482: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    483: 			'</h1>'.&proctor_validation_screen($slot);
1.22      albertel  484: 		} elsif ($status eq 'WAITING_FOR_GRADE') {
                    485: 		    $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.64      albertel  486: 		} elsif ($env{'form.donescreen'}) {
                    487: 		    my $title=&Apache::lonnet::gettitle();
1.67      albertel  488: 		    my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
1.114     albertel  489: 		    my (undef,undef,$domain,$user)=
                    490: 			&Apache::lonxml::whichuser();
                    491: 		    my $files = '<ul>';
                    492: 		    foreach my $file (@files) {
                    493: 			my $url="/uploaded/$domain/$user/portfolio$file";
1.130     albertel  494: 			if (! &Apache::lonnet::stat_file($url)) {
                    495: 			    $file = &mt('<font color="red"> Nonexistant file:</font> <tt>[_1]</tt>',$file);
                    496: 			} else {
                    497: 			    $file = '<tt>'.$file.'</tt>';
                    498: 			}
1.114     albertel  499: 			$files .= '<li>'.$file.'</li>';
                    500: 		    }
                    501: 		    $files.='</ul>';
                    502: 
1.64      albertel  503: 		    $result.=<<DONESCREEN;
                    504: <h2>$title</h2>
                    505: <p> Files submitted: $files </p>
1.67      albertel  506: <p> You are now done with this Bridge Task </p>
1.64      albertel  507: <hr />
                    508: <p> <a href="/adm/logout">Logout</a> </p>
                    509: <p> <a href="/adm/roles">Change to a different course</a> </p>
                    510: DONESCREEN
1.1       albertel  511: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    512: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    513: 		}
                    514: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    515: 		    $msg.='The problem '.$accessmsg;
                    516: 		}
                    517: 		$result.=$msg.'<br />';
                    518: 	    } elsif ($target eq 'tex') {
                    519: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    520: 		if ($status eq 'UNAVAILABLE') {
                    521: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    522: 		} else {
                    523: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    524: 		}
1.22      albertel  525: 	    } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4       albertel  526: 		if ($status eq 'NEEDS_CHECKIN') {
1.83      albertel  527: 		    if(&proctor_check_auth($slot_name,$slot,'Task')
                    528: 		       && defined($Apache::inputtags::slot_name)) {
1.148     albertel  529: 			my $result=
                    530: 			    &add_to_queue('gradingqueue',
                    531: 					  {'type' => 'task',
                    532: 					   'time' => time,
                    533: 					   'slot' => 
                    534: 					       $Apache::inputtags::slot_name});
1.77      albertel  535: 			&Apache::lonxml::debug("add_to_queue said $result");
                    536: 		    }
1.4       albertel  537: 		}
1.1       albertel  538: 	    }
                    539: 	} elsif ($target eq 'web') {
1.141     albertel  540: 
1.57      albertel  541: 	    $result.=&preserve_grade_info();
                    542: 	    $result.=&internal_location();
1.36      albertel  543: 	    $result.=$form_tag_start.
                    544: 		'<input type="hidden" name="submitted" value="yes" />';
1.54      albertel  545: 	    &Apache::lonxml::startredirection();
1.1       albertel  546: 	}
1.21      albertel  547:     } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                    548: 	      $target eq 'webgrade') {
1.32      albertel  549: 	my $webgrade='yes';
1.21      albertel  550: 	if ($target eq 'webgrade') {
1.141     albertel  551: 	    $result.= "\n".'<div class="LC_GRADING_task">'."\n".
1.124     albertel  552: 		'<script type="text/javascript" 
1.126     albertel  553:                          src="/res/adm/includes/task_grading.js"></script>';
1.49      albertel  554: 	    #$result.='<br />Review'.&show_queue('reviewqueue');
                    555: 	    #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30      albertel  556: 	}
1.33      albertel  557: 	# FIXME Blast! still need to reorg this, need to reshow the
                    558:         #       queue being reviewed once done with the grade pass...
                    559:         #       Hrrm, vaildation pass should perhaps say 'not_locked'
                    560:         #       perhaps do a search if there is a key that is mine and if
                    561:         #       there isn't reshow the queue....
1.105     albertel  562: 	my ($todo,$status_code,$msg)=&get_key_todo($target);
1.33      albertel  563: 
                    564: 	if ($todo) {
                    565: 	    &setup_env_for_other_user($todo,$safeeval);
                    566: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
                    567: 	    $result.="\n".'<table><tr><td>Found '.
                    568: 		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
                    569: 	    $form_tag_start.=
                    570: 		'<input type="hidden" name="gradingkey" value="'.
                    571: 		&Apache::lonnet::escape($todo).'" />';
                    572: 	    $Apache::bridgetask::queue_key=$todo;
                    573: 	    &Apache::structuretags::initialize_storage();
                    574: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.110     albertel  575: 	    if ($target eq 'webgrade' && $status_code eq 'selected') {
                    576: 		$form_tag_start.=
                    577: 		    '<input type="hidden" name="queuemode" value="selected" />';
1.33      albertel  578: 	    }
1.15      albertel  579: 	} else {
1.33      albertel  580: 	    if ($target eq 'webgrade') {
                    581: 		$result.="\n";
1.81      albertel  582: 		my $back='<p><a href="/adm/flip?postdata=return:">'.
                    583: 		    &mt('Return to resource').'</a></p>';
1.33      albertel  584: 		if      ($status_code eq 'stop') {
1.81      albertel  585: 		    $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
1.33      albertel  586: 		} elsif ($status_code eq 'lock_failed') {
1.105     albertel  587: 		    $result.='<b>'.&mt("Failed to lock the requested record.")
1.81      albertel  588: 			.'</b>'.$back;
1.33      albertel  589: 		} elsif ($status_code eq 'unlock') {
1.81      albertel  590: 		    $result.='<b>'.&mt("Unlocked the requested record.")
                    591: 			.'</b>'.$back;
1.33      albertel  592: 		    $result.=&show_queue($env{'form.queue'},1);
                    593: 		} elsif ($status_code eq 'show_list') {
                    594: 		    $result.=&show_queue($env{'form.queue'},1);
1.49      albertel  595: 		} elsif ($status_code eq 'select_user') {
                    596: 		    $result.=&select_user();
1.95      albertel  597: 		} elsif ($status_code eq 'unable') {
                    598: 		    $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
1.105     albertel  599: 		} elsif ($status_code eq 'not_allowed') {
                    600: 		    $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
1.33      albertel  601: 		} else {
1.81      albertel  602: 		    $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
1.32      albertel  603: 		}
1.21      albertel  604: 	    }
1.33      albertel  605: 	    $webgrade='no';
1.87      albertel  606: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.32      albertel  607: 	}
                    608: 	if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.61      albertel  609: 	    if ($webgrade eq 'yes') {
                    610: 		$result.=&submission_time_stamp();
                    611: 	    }
1.32      albertel  612: 	    $result.=$form_tag_start;
                    613: 	    $result.='<input type="hidden" name="webgrade" value="'.
                    614: 		$webgrade.'" />';
                    615: 	    $result.='<input type="hidden" name="queue" value="'.
                    616: 		$env{'form.queue'}.'" />';
1.52      albertel  617: 	    if ($env{'form.regrade'}) {
                    618: 		$result.='<input type="hidden" name="regrade" value="'.
                    619: 		    $env{'form.regrade'}.'" />';
                    620: 	    }
1.62      albertel  621: 	    if ($env{'form.chosensections'}) {
                    622: 		my @chosen_sections=
                    623: 		    &Apache::loncommon::get_env_multiple('form.chosensections');
                    624: 		foreach my $sec (@chosen_sections) {
                    625: 		    $result.='<input type="hidden" name="chosensections" 
                    626:                                value="'.$sec.'" />';
                    627: 		}
                    628: 	    }
1.70      albertel  629: 	    if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
1.15      albertel  630: 	}
1.110     albertel  631: 	if ($target eq 'webgrade') {
1.120     albertel  632: 	    $result.="\n".'<div id="LC_GRADING_criterialist">';
1.110     albertel  633: 	}
1.74      albertel  634:     } elsif ($target eq 'edit') {
1.141     albertel  635: 	$result.=$form_tag_start.
1.74      albertel  636: 	    &Apache::structuretags::problem_edit_header();
                    637: 	$Apache::lonxml::warnings_error_header=
                    638: 	    &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 />";
                    639: 	my $temp=&Apache::edit::insertlist($target,$token);
                    640: 	$result.=$temp;
1.1       albertel  641:     } else {
                    642: 	# page_start returned a starting result, delete it if we don't need it
                    643: 	$result = '';
                    644:     }
                    645:     return $result;
                    646: }
                    647: 
1.32      albertel  648: sub get_key_todo {
                    649:     my ($target)=@_;
                    650:     my $todo;
1.33      albertel  651: 
                    652:     if (defined($env{'form.reviewasubmission'})) {
1.54      albertel  653: 	&Apache::lonxml::debug("review a submission....");
1.33      albertel  654: 	$env{'form.queue'}='reviewqueue';
                    655: 	return (undef,'show_list');
                    656:     }
                    657: 
                    658:     if (defined($env{'form.reviewagrading'})) {
                    659: 	&Apache::lonxml::debug("review a grading....");
                    660: 	$env{'form.queue'}='gradingqueue';
                    661: 	return (undef,'show_list');
                    662:     }
                    663: 
1.49      albertel  664:     if (defined($env{'form.regradeasubmission'})) {
                    665: 	&Apache::lonxml::debug("regrade a grading....");
                    666: 	$env{'form.queue'}='none';
                    667: 	return (undef,'select_user');
                    668:     }
                    669: 
1.105     albertel  670: 
1.138     albertel  671:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.105     albertel  672: 
                    673:     #need to try both queues..
                    674:     if (defined($env{'form.regradeaspecificsubmission'}) &&
                    675: 	defined($env{'form.gradinguser'})               &&
                    676: 	defined($env{'form.gradingdomain'})               ) {
                    677: 	my ($symb,$cid)=&Apache::lonxml::whichuser();
                    678: 	my $cnum  = $env{'course.'.$cid.'.num'};
                    679: 	my $cdom  = $env{'course.'.$cid.'.domain'};
                    680: 	my $uname = $env{'form.gradinguser'};
                    681: 	my $udom  = $env{'form.gradingdomain'};
                    682: 
                    683: 	my $gradingkey=&encode_queue_key($symb,$udom,$uname);
                    684: 
                    685: 	my $queue;
                    686: 
                    687: 	if      (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
                    688: 	    $env{'form.queue'} = $queue = 'gradingqueue';
                    689: 	} elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
                    690: 	    $env{'form.queue'} = $queue = 'reviewqueue';
                    691: 	}
                    692: 	
                    693: 	if (!$queue) {
                    694: 	    $env{'form.queue'} = $queue = 'none';
                    695: 	    #not queued so doing either a re or pre grade
                    696: 	    return ($gradingkey);
                    697: 	}
                    698: 
                    699: 	my $who=&queue_key_locked($queue,$gradingkey);
                    700: 	if ($who eq $me) {
                    701: 	    #already have the lock
                    702: 	    $env{'form.gradingkey'}=&Apache::lonnet::escape($gradingkey);
                    703: 	    return ($gradingkey);
                    704: 	}
                    705: 	
                    706: 	if (!defined($who)) {
                    707: 	    if (&lock_key($queue,$gradingkey)) {
                    708: 		return ($gradingkey);
                    709: 	    } else {
                    710: 		return (undef,'lock_failed');
                    711: 	    }
                    712: 	}
                    713: 
                    714: 	#otherwise (defined($who) && $who ne $me) some else has it...
                    715: 	return (undef,'not_allowed',
                    716: 		&mt('Another user ([_1]) currently has the record for [_2] locked.',
1.138     albertel  717: 		    $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
1.105     albertel  718:     }
                    719: 
                    720: 
1.32      albertel  721:     my $queue=$env{'form.queue'};
1.33      albertel  722: 
1.32      albertel  723:     if (!defined($queue)) {
                    724: 	$env{'form.queue'}=$queue='gradingqueue';
                    725:     }
1.33      albertel  726: 
1.32      albertel  727:     my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33      albertel  728: 
1.49      albertel  729:     if ($env{'form.queue'} eq 'none') {
                    730: 	if (defined($env{'form.gradingkey'})) {
                    731: 	    if ($target eq 'webgrade') {
                    732: 		if ($env{'form.stop'}) {
                    733: 		    return (undef,'stop');
                    734: 		} elsif ($env{'form.next'}) {
1.59      albertel  735: 		    return (undef,'select_user');
1.49      albertel  736: 		}
                    737: 	    }
                    738: 	    return ($gradingkey,'selected');
                    739: 	} else {
1.59      albertel  740: 	    return (undef,'select_user');
1.49      albertel  741: 	}
                    742:     }
1.32      albertel  743:     if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33      albertel  744: 	&& !defined($env{'form.gradingaction'}) 
                    745: 	&& $env{'form.queuemode'} eq 'selected') {
                    746: 	
                    747: 	my $who=&queue_key_locked($queue,$gradingkey);
                    748: 	if ($who eq $me) {
                    749: 	    &Apache::lonxml::debug("Found a key was given to me");
                    750: 	    return ($gradingkey,'selected');
                    751: 	} else {
                    752: 	    return (undef,'show_list');
                    753: 	}
                    754: 
                    755:     }
                    756: 
                    757:     if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
                    758: 	if ($env{'form.gradingaction'} eq 'resume') {
                    759: 	    delete($env{'form.gradingaction'});
                    760: 	    &Apache::lonxml::debug("Resuming a key");
1.32      albertel  761: 	    return ($gradingkey);
1.33      albertel  762: 	} elsif ($env{'form.gradingaction'} eq 'unlock') {
                    763: 	    &Apache::lonxml::debug("Unlocking a key ".
                    764: 				     &check_queue_unlock($queue,$gradingkey,1));
                    765: 	    return (undef,'unlock');
                    766: 	} elsif ($env{'form.gradingaction'} eq 'select') {
                    767: 	    &Apache::lonxml::debug("Locking a key");
                    768: 	    if (&lock_key($queue,$gradingkey)) {
                    769: 		&Apache::lonxml::debug("Success $queue");
                    770: 		return ($gradingkey);
                    771: 	    }
                    772: 	    &Apache::lonxml::debug("Failed $queue");
                    773: 	    return (undef,'lock_failed');
1.32      albertel  774: 	}
                    775:     }
1.33      albertel  776: 
                    777:     if ($env{'form.queuemode'} ne 'selected') {
                    778: 	# don't get something new from the queue if they hit the stop button
                    779:     	if (!($env{'form.stop'} && $target eq 'webgrade') 
                    780: 	    && !$env{'form.gradingaction'}) {
                    781: 	    &Apache::lonxml::debug("Getting anew $queue");
                    782: 	    return (&get_from_queue($queue));
                    783: 	} else {
                    784: 	    return (undef,'stop');
                    785: 	}
1.32      albertel  786:     }
1.33      albertel  787:     return (undef,undef)
1.32      albertel  788: }
1.94      albertel  789: 
                    790: sub minimize_storage {
                    791:     foreach my $key (keys(%Apache::lonhomework::results)) {
                    792: 	if ($key =~ /regrader$/) { next; }
                    793: 	if ($Apache::lonhomework::results{$key} eq
                    794: 	    $Apache::lonhomework::history{$key}) {
                    795: 	    delete($Apache::lonhomework::results{$key});
                    796: 	}
                    797:     }
                    798: }
                    799: 
1.1       albertel  800: sub end_Task {
                    801:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    802:     my $result='';
                    803:     my $status=$Apache::inputtags::status['-1'];
1.29      albertel  804:     my ($version,$previous)=&get_version();
1.1       albertel  805:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel  806: 	$target eq 'tex') {
1.69      albertel  807: 	if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.1       albertel  808: 	    if ($target eq 'web') {
1.54      albertel  809: 		if (&show_task($status,$previous)) {
                    810: 		    $result.=&Apache::lonxml::endredirection();
                    811: 		}
1.64      albertel  812: 		if ($status eq 'CAN_ANSWER' && !$previous && 
                    813: 		    !$env{'form.donescreen'}) {
1.15      albertel  814: 		    $result.="\n".'<table border="1">'.
1.28      albertel  815: 			&Apache::inputtags::file_selector("$version.0",
                    816: 							  "bridgetask","*",
1.46      albertel  817: 							  'portfolioonly',
                    818: 							  '
                    819: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
                    820: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9       albertel  821: 							  "</table>";
1.77      albertel  822: 		}
1.78      albertel  823: 		if (!$previous && $status ne 'SHOW_ANSWER' &&
                    824: 		    &show_task($status,$previous)) {
1.9       albertel  825: 		    $result.=&Apache::inputtags::gradestatus('0');
1.64      albertel  826: 		    $result.='</form>';
1.116     albertel  827: 		    my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.64      albertel  828: 		    $result.=<<DONEBUTTON;
1.115     albertel  829: <form name="done" method="post" action="$action">
1.64      albertel  830:    <input type="hidden" name="donescreen" value="1" />
                    831:    <input type="submit" value="Done" />
                    832: </form>
                    833: DONEBUTTON
1.77      albertel  834:                 }
1.56      albertel  835: 		if (&show_task($status,$previous) &&
1.89      albertel  836: 		    $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
                    837: 		    my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1.54      albertel  838: 		    my $title=&Apache::lonnet::gettitle();
1.80      albertel  839: 
1.149     albertel  840: 		    my $start_time;
                    841: 
1.80      albertel  842: 		    my $slot_name=
1.89      albertel  843: 			$Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1.149     albertel  844: 		    if ($slot_name) {
                    845: 			my %slot=&Apache::lonnet::get_slot($slot_name);
                    846: 
                    847: 			$start_time=$slot{'starttime'}
                    848: 		    } else {
                    849: 			$start_time= 
                    850: 			    &Apache::lonnet::EXT('resource.0.opendate');
                    851: 		    }
                    852: 		    $start_time=&Apache::lonlocal::locallocaltime($start_time);
1.54      albertel  853: 
1.116     albertel  854: 		    my $status = "\n<div class='LC_$bt_status LC_criteria'>\n";
1.54      albertel  855: 		    
                    856: 		    if ($bt_status eq 'pass')  {
                    857: 			$status.='<h2>You passed the '.$title.' given on '.
1.80      albertel  858: 			    $start_time.'</h2>';
1.54      albertel  859: 		    }
                    860: 		    if ($bt_status eq 'fail')  {
                    861: 			$status.='<h2>You did not pass the '.$title.' given on '.
1.80      albertel  862: 			    $start_time.'</h2>';
1.54      albertel  863: 			if (!$previous) {
                    864: 			    $status.=&add_request_another_attempt_button();
                    865: 			}
                    866: 		    }
                    867: 		    my $man_count=0;
                    868: 		    my $opt_count=0;
                    869: 		    my $opt_passed=0;
                    870: 		    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
                    871: 			if ($Apache::bridgetask::dimensionmandatory{$dim_id}
                    872: 			    eq 'N') {
                    873: 			    $opt_count++;
1.89      albertel  874: 			    if ($Apache::lonhomework::history{"resource.$version.0.$dim_id.status"} eq 'pass') {
1.54      albertel  875: 				$opt_passed++;
                    876: 			    }
                    877: 			} else {
                    878: 			    $man_count++;
                    879: 			}
                    880: 		    }
1.151   ! albertel  881: 		    
1.54      albertel  882: 		    my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
                    883: 							 $parstack,$safeeval);
                    884: 		    if ($opt_req !~ /\S/) { $opt_req='0'; }
1.99      albertel  885: 		    $status.="\n<p>".&mt('You needed to pass all of the [_1]  mandatory components and [_2] of the [_3] optional components, of which you passed [_4].',$man_count,$opt_req,$opt_count,$opt_passed)."</p></div>\n";
1.54      albertel  886: 
                    887: 		    my $internal_location=&internal_location();
                    888: 		    $result=~s/\Q$internal_location\E/$status/;
                    889: 		}
1.142     albertel  890: 		$result.="\n</div>\n".
                    891: 		    &Apache::loncommon::end_page({'discussion' => 1});
1.1       albertel  892: 	    }
                    893: 	}
1.29      albertel  894: 	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12      albertel  895: 	    my $award='SUBMITTED';
1.28      albertel  896: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20      albertel  897: 						    'portfiles',\$award);
1.14      albertel  898: 	    if ($award eq 'SUBMITTED' &&
1.28      albertel  899: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
                    900: 		$Apache::lonhomework::results{"resource.0.tries"}=
                    901: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
                    902: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
                    903: 
                    904: 		$Apache::lonhomework::results{"resource.0.award"}=
                    905: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
                    906: 		    $award;
1.51      albertel  907: 		$Apache::lonhomework::results{"resource.0.submission"}=
                    908: 		    $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64      albertel  909: 	    } else {
                    910: 		delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1.77      albertel  911: 		$award = '';
1.10      albertel  912: 	    }
1.4       albertel  913: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    914: 	    &Apache::structuretags::finalize_storage();
1.148     albertel  915: 	    if ($award eq 'SUBMITTED') {
                    916: 		my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
                    917: 		if ($useslots =~ /^\s*no\s*$/i) {
                    918: 		    &add_to_queue('gradingqueue',
                    919: 				  {'type' => 'task',
                    920: 				   'time' => time});
                    921: 		} elsif (defined($Apache::inputtags::slot_name)) {
                    922: 		    &add_to_queue('gradingqueue',
                    923: 				  {'type' => 'task',
                    924: 				   'time' => time,
                    925: 				   'slot' => $Apache::inputtags::slot_name});
                    926: 		}
1.14      albertel  927: 	    }
1.79      albertel  928: 	} elsif ($Apache::lonhomework::results{'INTERNAL_store'}) {
                    929: 	    &Apache::structuretags::finalize_storage();
1.1       albertel  930: 	}
1.32      albertel  931: 	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20      albertel  932: 	    my $optional_required=
                    933: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                    934: 					   $safeeval);
                    935: 	    my $optional_passed=0;
                    936: 	    my $mandatory_failed=0;
                    937: 	    my $ungraded=0;
                    938: 	    my $review=0;   
1.21      albertel  939: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20      albertel  940: 	    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
                    941: 		my $status=
1.89      albertel  942: 		    $Apache::lonhomework::results{"resource.$version.0.$dim_id.status"};
1.20      albertel  943: 		my $mandatory=
                    944: 		    ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
                    945: 		if ($status eq 'pass') {
                    946: 		    if (!$mandatory) { $optional_passed++; }
                    947: 		} elsif ($status eq 'fail') {
                    948: 		    if ($mandatory) { $mandatory_failed++; }
                    949: 		} elsif ($status eq 'ungraded') {
                    950: 		    $ungraded++;
                    951: 		} elsif ($status eq 'review') {
                    952: 		    $review++;
1.49      albertel  953: 		} else {
                    954: 		    $ungraded++;
                    955: 		}
1.20      albertel  956: 	    }
                    957: 	    if ($optional_passed < $optional_required) {
                    958: 		$mandatory_failed++;
                    959: 	    }
1.21      albertel  960: 	    &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.89      albertel  961: 	    $Apache::lonhomework::results{'resource.0.regrader'}=
1.138     albertel  962: 		$env{'user.name'}.':'.$env{'user.domain'};
1.20      albertel  963: 	    if ($review) {
1.89      albertel  964: 		$Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.33      albertel  965: 		if ($env{'form.queue'} eq 'reviewqueue') {
                    966: 		    &check_queue_unlock($env{'form.queue'});
                    967: 		    &Apache::lonxml::debug(" still needs review not changing status.");
                    968: 		} else {
1.49      albertel  969: 		    &move_between_queues($env{'form.queue'},'reviewqueue');
1.33      albertel  970: 		}
1.20      albertel  971: 	    } elsif ($ungraded) {
1.89      albertel  972: 		$Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.49      albertel  973: 		if ($env{'form.queue'} eq 'reviewqueue' ||
                    974: 		    $env{'form.queue'} eq 'none' ) {
1.33      albertel  975: 		    &Apache::lonxml::debug("moving back.");
1.49      albertel  976: 		    &move_between_queues($env{'form.queue'},'gradingqueue');
1.33      albertel  977: 		} else {
                    978: 		    &check_queue_unlock($env{'form.queue'});
                    979: 		}
1.20      albertel  980: 	    } elsif ($mandatory_failed) {
1.89      albertel  981: 		$Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25      albertel  982: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                    983: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                    984: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39      albertel  985: 		&remove_from_queue($env{'form.queue'}); 
                    986: 
                    987: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52      albertel  988: 		
                    989: 		if ($env{'form.regrade'} ne 'yes') {
                    990: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                    991: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                    992: 		    &Apache::grades::version_portfiles(
                    993: 						       \%Apache::lonhomework::results,
                    994: 						       ["$version.0.bridgetask"],$courseid,
                    995: 						       $symb,$udom,$uname,
                    996: 						       ["$version.0.bridgetask"]);
                    997: 		}
1.20      albertel  998: 	    } else {
1.89      albertel  999: 		$Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25      albertel 1000: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                   1001: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                   1002: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32      albertel 1003: 		&remove_from_queue($env{'form.queue'});
1.39      albertel 1004: 
                   1005: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52      albertel 1006: 		if ($env{'form.regrade'} ne 'yes') {
                   1007: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                   1008: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                   1009: 		    &Apache::grades::version_portfiles(
                   1010: 						       \%Apache::lonhomework::results,
                   1011: 						       ["$version.0.bridgetask"],$courseid,
                   1012: 						       $symb,$udom,$uname,
                   1013: 						       ["$version.0.bridgetask"]);
                   1014: 		}
1.20      albertel 1015: 	    }
1.89      albertel 1016: 	    $Apache::lonhomework::results{"resource.0.status"}=
                   1017: 		$Apache::lonhomework::results{"resource.$version.0.status"};
1.28      albertel 1018: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel 1019: 		$Apache::lonhomework::results{"resource.0.award"}=
1.50      albertel 1020: 		    $Apache::lonhomework::results{"resource.$version.0.award"};
1.26      albertel 1021: 		$Apache::lonhomework::results{"resource.0.awarded"}=
1.50      albertel 1022: 		    $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26      albertel 1023: 		$Apache::lonhomework::results{"resource.0.solved"}=
1.50      albertel 1024: 		    $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25      albertel 1025: 	    }
1.94      albertel 1026: 	    &minimize_storage();
1.21      albertel 1027: 	    &Apache::structuretags::finalize_storage();
1.20      albertel 1028: 	}
1.15      albertel 1029:     } elsif ($target eq 'webgrade') {
1.131     albertel 1030: 	$result.="</div>";
1.20      albertel 1031: 	#$result.='<input type="submit" name="next" value="'.
                   1032: 	#    &mt('Save &amp; Next').'" /> ';
                   1033: 	#$result.='<input type="submit" name="end" value="'.
                   1034: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                   1035: 	#$result.='<input type="submit" name="throwaway" value="'.
                   1036: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                   1037: 	#$result.='<input type="submit" name="save" value="'.
                   1038: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124     albertel 1039: 	$result.='</form>'."\n</div>\n</div>\n".
1.140     albertel 1040: 	    &Apache::loncommon::end_page();
1.1       albertel 1041:     } elsif ($target eq 'meta') {
1.70      albertel 1042: 	$result.=&Apache::response::meta_package_write('Task');
1.77      albertel 1043:         $result.=&Apache::response::meta_stores_write('solved','string',
                   1044: 						      'Problem Status');
                   1045: 	$result.=&Apache::response::meta_stores_write('tries','int_zeropos',
                   1046: 						      'Number of Attempts');
                   1047: 	$result.=&Apache::response::meta_stores_write('awarded','float',
                   1048: 						      'Partial Credit Factor');
                   1049: 	$result.=&Apache::response::meta_stores_write('status','string',
                   1050: 						      'Bridge Task Status');
1.1       albertel 1051:     }
1.4       albertel 1052:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel 1053:     return $result;
                   1054: }
                   1055: 
1.31      albertel 1056: sub move_between_queues {
                   1057:     my ($src_queue,$dest_queue)=@_;
1.49      albertel 1058:     my $cur_data;
                   1059:     if ($src_queue ne 'none') {
                   1060: 	$cur_data=&get_queue_data($src_queue);
                   1061: 	if (!$cur_data) { return 'not_exist'; }
                   1062:     } else {
                   1063: 	$cur_data = ['none'];
                   1064:     }
1.148     albertel 1065:     my $result=&add_to_queue($dest_queue,$cur_data);
1.31      albertel 1066:     if ($result ne 'ok') {
                   1067: 	return $result;
                   1068:     }
                   1069:     &check_queue_unlock($src_queue);
                   1070:     return &remove_from_queue($src_queue);
1.21      albertel 1071: }
                   1072: 
                   1073: sub check_queue_unlock {
1.32      albertel 1074:     my ($queue,$key,$allow_not_me)=@_;
1.49      albertel 1075:     if ($queue eq 'none') { return 'ok'; }
1.30      albertel 1076:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32      albertel 1077:     if (!defined($key)) {
1.138     albertel 1078: 	$key="$symb\0queue\0$uname:$udom";
1.32      albertel 1079:     }
1.30      albertel 1080:     my $cnum=$env{'course.'.$cid.'.num'};
                   1081:     my $cdom=$env{'course.'.$cid.'.domain'};
1.138     albertel 1082:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30      albertel 1083:     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
                   1084:     if  ($who eq $me) {
1.32      albertel 1085: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
                   1086:     } elsif ($allow_not_me) {
1.33      albertel 1087: 	&Apache::lonxml::debug("unlocking $who by $me");
1.32      albertel 1088: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30      albertel 1089:     }
1.32      albertel 1090:     return 'not_owner';
1.21      albertel 1091: }
                   1092: 
1.88      albertel 1093: sub in_queue {
                   1094:     my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
                   1095:     if ($queue eq 'none') { return 0; }
                   1096:     if (!defined($symb) || !defined($cdom) || !defined($cnum)
                   1097: 	|| !defined($udom) || !defined($uname)) {
                   1098: 	($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1099: 	$cnum=$env{'course.'.$cid.'.num'};
                   1100: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1101:     }
                   1102: 
                   1103:     my $key=&encode_queue_key($symb,$udom,$uname);
                   1104:     my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
                   1105: 
                   1106:     if (defined($results{$key})) {
                   1107: 	return 1;
                   1108:     }
                   1109:     return 0;
                   1110: }
                   1111: 
1.21      albertel 1112: sub remove_from_queue {
1.86      albertel 1113:     my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49      albertel 1114:     if ($queue eq 'none') { return 'ok'; }
1.86      albertel 1115:     if (!defined($symb) || !defined($cdom) || !defined($cnum)
                   1116: 	|| !defined($udom) || !defined($uname)) {
                   1117: 	($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1118: 	$cnum=$env{'course.'.$cid.'.num'};
                   1119: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1120:     }
1.88      albertel 1121:     if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
                   1122: 	return 'ok';
                   1123:     }
1.86      albertel 1124:     my $key=&encode_queue_key($symb,$udom,$uname);
1.27      albertel 1125:     my @keys=($key,"$key\0locked");
1.31      albertel 1126:     return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21      albertel 1127: }
                   1128: 
1.16      albertel 1129: sub setup_env_for_other_user {
                   1130:     my ($queue_key,$safeeval)=@_;
                   1131:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30      albertel 1132:     &Apache::lonxml::debug("setup_env for $queue_key");
1.16      albertel 1133:     $env{'form.grade_symb'}=$symb;
                   1134:     $env{'form.grade_domain'}=$udom;
                   1135:     $env{'form.grade_username'}=$uname;
                   1136:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                   1137:     &Apache::lonxml::initialize_rndseed($safeeval);
                   1138: }
                   1139: 
1.31      albertel 1140: sub get_queue_data {
                   1141:     my ($queue)=@_;
                   1142:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1143:     my $cnum=$env{'course.'.$cid.'.num'};
                   1144:     my $cdom=$env{'course.'.$cid.'.domain'};
1.138     albertel 1145:     my $todo="$symb\0queue\0$uname:$udom";
1.31      albertel 1146:     my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
                   1147:     if ($key eq $todo && ref($value)) {
                   1148: 	return $value;
                   1149:     }
                   1150:     return undef;
                   1151: }
                   1152: 
1.84      albertel 1153: 
1.49      albertel 1154: sub check_queue_for_key {
1.84      albertel 1155:     my ($cdom,$cnum,$queue,$todo)=@_;
                   1156: 
1.49      albertel 1157:     my %results=
                   1158: 	&Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
                   1159:     
                   1160:     if (exists($results{$todo}) && ref($results{$todo})) {
                   1161: 	if (defined($results{"$todo\0locked"})) {
                   1162: 	    return 'locked';
                   1163: 	}
1.148     albertel 1164: 	if (my $slot=&slotted_access($results{$todo})) {
1.86      albertel 1165: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1166: 	    if ($slot_data{'endtime'} > time) { 
                   1167: 		return 'in_progress';
                   1168: 	    }
1.148     albertel 1169: 	} else {
                   1170: 	    my ($symb) = &decode_queue_key($todo);
                   1171: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1172: 	    if ($due_date > time) {
                   1173: 		return 'in_progress';
                   1174: 	    }
1.58      albertel 1175: 	}
1.49      albertel 1176: 	return 'enqueued';
                   1177:     }
                   1178:     return undef;
                   1179: }
                   1180: 
1.14      albertel 1181: sub add_to_queue {
1.82      albertel 1182:     my ($queue,$user_data)=@_;
1.49      albertel 1183:     if ($queue eq 'none') { return 'ok'; }
1.14      albertel 1184:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.82      albertel 1185:     if (!$cid || $env{'request.state'} eq 'construct') {
                   1186: 	return 'no_queue';
                   1187:     }
1.14      albertel 1188:     my $cnum=$env{'course.'.$cid.'.num'};
                   1189:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1190:     my %data;
1.138     albertel 1191:     $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83      albertel 1192:     return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14      albertel 1193: }
                   1194: 
                   1195: sub show_queue {
1.32      albertel 1196:     my ($queue,$with_selects)=@_;
1.14      albertel 1197:     my $result;
                   1198:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1199:     my $cnum=$env{'course.'.$cid.'.num'};
                   1200:     my $cdom=$env{'course.'.$cid.'.domain'};
1.59      albertel 1201: 
                   1202:     my @chosen_sections=
                   1203: 	&Apache::loncommon::get_env_multiple('form.chosensections');
                   1204:     &Apache::grades::init_perm();
                   1205:     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
                   1206:     &Apache::grades::reset_perm();
1.63      albertel 1207:     if (!(grep(/^all$/,@chosen_sections))) {
                   1208: 	$result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
                   1209: 	    '</tt>.</p> '."\n";
                   1210:     }
1.59      albertel 1211: 
1.16      albertel 1212:     my $regexp="^$symb\0";
1.30      albertel 1213:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31      albertel 1214:     my ($tmp)=%queue;
                   1215:     if ($tmp=~/^error: 2 /) {
1.33      albertel 1216: 	return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31      albertel 1217:     }
1.103     albertel 1218:     my $title=&Apache::lonnet::gettitle($symb);
                   1219:     $result.="\n<h3>Current Queue - $title $queue </h3><table border='1'><tr>";
                   1220:     if ($with_selects) { $result.="<th>Status</th><th></th>"; }
                   1221:     $result.="<th>user</th><th>data</th></tr>";
1.14      albertel 1222:     foreach my $key (sort(keys(%queue))) {
1.59      albertel 1223: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
                   1224: 	if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.32      albertel 1225: 	if ($key=~/locked$/ && !$with_selects) {
1.103     albertel 1226: 	    $result.="<tr><td>$uname</td>";
                   1227: 	    $result.='<td>'.$queue{$key}.'</td></tr>';
1.32      albertel 1228: 	} elsif ($key=~/timestamp$/ && !$with_selects) {
1.103     albertel 1229: 	    $result.="<tr><td></td>";
                   1230: 	    $result.='<td>'.
1.16      albertel 1231: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32      albertel 1232: 	} elsif ($key!~/(timestamp|locked)$/) {
                   1233: 	    $result.="<tr>";
1.148     albertel 1234: 	    my ($end_time,$slot_text);
                   1235: 	    if (my $slot=&slotted_access($queue{$key})) {
                   1236: 		my %slot_data=&Apache::lonnet::get_slot($slot);
                   1237: 		$end_time = $slot_data{'endtime'};
                   1238: 		$slot_text = &mt('Slot: [_1]',$slot);
                   1239: 	    } else {
                   1240: 		$end_time = &Apache::lonhomework::due_date('0',$symb);
                   1241: 		$slot_text = '';
                   1242: 	    }
1.32      albertel 1243: 	    if ($with_selects) {
                   1244: 		my $ekey=&Apache::lonnet::escape($key);
1.103     albertel 1245: 		my ($action,$description,$status)=('select',&mt('Select'));
1.32      albertel 1246: 		if (exists($queue{"$key\0locked"})) {
1.138     albertel 1247: 		    my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.103     albertel 1248: 		    $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
1.32      albertel 1249: 		    if ($me eq $queue{"$key\0locked"}) {
                   1250: 			($action,$description)=('resume',&mt('Resume'));
                   1251: 		    } else {
                   1252: 			($action,$description)=('unlock',&mt('Unlock'));
                   1253: 		    }
                   1254: 		}
1.62      albertel 1255: 		my $seclist;
                   1256: 		foreach my $sec (@chosen_sections) {
                   1257: 		    $seclist.='<input type="hidden" name="chosensections" 
                   1258:                                value="'.$sec.'" />';
                   1259: 		}
1.148     albertel 1260: 		if ($end_time ne '' && time > $end_time) {
1.35      albertel 1261: 		    $result.=(<<FORM);
1.103     albertel 1262: <td>$status</td>
1.32      albertel 1263: <td>
1.115     albertel 1264: <form style="display: inline" method="post">
1.32      albertel 1265:  <input type="hidden" name="gradingkey" value="$ekey" />
                   1266:  <input type="hidden" name="queue" value="$queue" />
                   1267:  <input type="hidden" name="gradingaction" value="$action" />
                   1268:  <input type="hidden" name="webgrade" value="no" />
1.33      albertel 1269:  <input type="hidden" name="queuemode" value="selected" />
1.32      albertel 1270:  <input type="submit" name="submit" value="$description" />
1.62      albertel 1271:  $seclist
1.32      albertel 1272: </form>
                   1273: </td>
                   1274: FORM
1.35      albertel 1275: 
                   1276:                 } else {
1.148     albertel 1277: 		    $result.='<td>'.&mt("In Progress").'</td><td>&nbsp;</td>'
1.35      albertel 1278: 		}
1.32      albertel 1279: 	    }
1.104     albertel 1280: 	    $result.= "<td>".$fullname->{$uname.':'.$udom}.
1.138     albertel 1281: 		" <tt>($uname:$udom)</tt> </td>";
1.148     albertel 1282: 	    $result.='<td>'.$slot_text.' End time: '.
                   1283: 		&Apache::lonlocal::locallocaltime($end_time).
1.20      albertel 1284: 		"</td></tr>";
1.16      albertel 1285: 	}
1.14      albertel 1286:     }
1.15      albertel 1287:     $result.="</table><hr />\n";
1.14      albertel 1288:     return $result;
                   1289: }
                   1290: 
1.34      albertel 1291: sub get_queue_counts {
                   1292:     my ($queue)=@_;
                   1293:     my $result;
                   1294:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1295:     my $cnum=$env{'course.'.$cid.'.num'};
                   1296:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1297:     my $regexp="^$symb\0";
                   1298:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1299:     my ($tmp)=%queue;
                   1300:     if ($tmp=~/^error: 2 /) {
                   1301: 	return (0,0,0);
                   1302:     }
                   1303:     my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96      albertel 1304:     my %slot_cache;
1.34      albertel 1305:     foreach my $key (sort(keys(%queue))) {
                   1306: 	if ($key=~/locked$/) {
                   1307: 	    $locks++;
                   1308: 	} elsif ($key=~/timestamp$/) {
                   1309: 	    #ignore
                   1310: 	} elsif ($key!~/(timestamp|locked)$/) {
                   1311: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                   1312: 	    $entries++;
1.148     albertel 1313: 	    if (my $slot=&slotted_access($queue{$key})) {
                   1314: 		if (!exists($slot_cache{$slot})) {
                   1315: 		    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1316: 		    $slot_cache{$slot} = \%slot_data;
                   1317: 		}
                   1318: 		if (time > $slot_cache{$slot}{'endtime'}) {
                   1319: 		    $ready_to_grade++;
                   1320: 		}
                   1321: 	    } else {
                   1322: 		my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1323: 		if ($due_date ne '' && time > $due_date) {
                   1324: 		    $ready_to_grade++;
                   1325: 		}
1.34      albertel 1326: 	    }
                   1327: 	}
                   1328:     }
                   1329:     return ($entries,$ready_to_grade,$locks);
                   1330: }
                   1331: 
1.49      albertel 1332: sub encode_queue_key {
                   1333:     my ($symb,$udom,$uname)=@_;
1.138     albertel 1334:     return "$symb\0queue\0$uname:$udom";
1.49      albertel 1335: }
                   1336: 
1.14      albertel 1337: sub decode_queue_key {
                   1338:     my ($key)=@_;
                   1339:     my ($symb,undef,$user) = split("\0",$key);
1.138     albertel 1340:     my ($uname,$udom) = split(':',$user);
1.14      albertel 1341:     return ($symb,$uname,$udom);
                   1342: }
                   1343: 
                   1344: sub queue_key_locked {
1.30      albertel 1345:     my ($queue,$key,$cdom,$cnum)=@_;
1.33      albertel 1346:     if (!defined($cdom) || !defined($cnum)) {
                   1347: 	my (undef,$cid)=&Apache::lonxml::whichuser();
                   1348: 	$cnum=$env{'course.'.$cid.'.num'};
                   1349: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1350:     }
1.14      albertel 1351:     my ($key_locked,$value)=
1.30      albertel 1352: 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14      albertel 1353:     if ($key_locked eq "$key\0locked") {
                   1354: 	return $value;
                   1355:     }
                   1356:     return undef;
                   1357: }
                   1358: 
1.148     albertel 1359: sub slotted_access {
                   1360:     my ($queue_entry) = @_;
                   1361:     if (ref($queue_entry) eq 'ARRAY') {
                   1362: 	if (defined($queue_entry->[0])) {
                   1363: 	    return $queue_entry->[0];
                   1364: 	}
                   1365: 	return undef;
                   1366:     } elsif (ref($queue_entry) eq 'HASH') {
                   1367: 	if (defined($queue_entry->{'slot'})) {
                   1368: 	    return $queue_entry->{'slot'};
                   1369: 	}
                   1370: 	return undef;
                   1371:     }
                   1372:     return undef;
                   1373: }
                   1374: 
1.14      albertel 1375: sub pick_from_queue_data {
1.30      albertel 1376:     my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
1.98      albertel 1377:     my @possible; # will hold queue entries that are valid to be selected
1.30      albertel 1378:     foreach my $key (keys(%$queuedata)) {
1.68      albertel 1379: 	if ($key =~ /\0locked$/) { next; }
                   1380: 	if ($key =~ /\0timestamp$/) { next; }
1.14      albertel 1381: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
                   1382: 	if ($check_section) {
                   1383: 	    my $section=&Apache::lonnet::getsection($uname,$udom);
1.17      albertel 1384: 	    if ($section eq $check_section) {
1.33      albertel 1385: 		&Apache::lonxml::debug("my sec");
1.15      albertel 1386: 		next;
                   1387: 	    }
1.14      albertel 1388: 	}
1.148     albertel 1389: 	my $end_time;
                   1390: 	if (my $slot=&slotted_access($queuedata->{$key})) {
                   1391: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1392: 	    if ($slot_data{'endtime'} < time) { 
                   1393: 		$end_time = $slot_data{'endtime'};
                   1394: 	    }
                   1395: 	} else {
                   1396: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1397: 	    if ($due_date > time) {
                   1398: 		$end_time = $due_date;
                   1399: 	    }
                   1400: 	}
                   1401: 	if ($end_time ne '') {
1.33      albertel 1402: 	    &Apache::lonxml::debug("not time");
1.15      albertel 1403: 	    next;
                   1404: 	}
1.148     albertel 1405: 	
1.98      albertel 1406: 	if (exists($queuedata->{"$key\0locked"})) {
1.33      albertel 1407: 	    &Apache::lonxml::debug("someone already has um.");
1.15      albertel 1408: 	    next;
                   1409: 	}
1.148     albertel 1410: 	push(@possible,[$key,$end_time]);
1.98      albertel 1411:     }
                   1412:     if (@possible) {
                   1413:         # sort entries in order by slot end time
                   1414: 	@possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137     albertel 1415: 	# pick one of the entries in the top 10% in small queues and one
                   1416: 	# of the first ten entries in large queues
1.139     albertel 1417: 	#my $ten_percent = int($#possible * 0.1);
                   1418: 	#if ($ten_percent < 1 ) { $ten_percent = 1;  }
                   1419: 	#if ($ten_percent > 10) { $ten_percent = 10; }
                   1420: 	#my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137     albertel 1421: 	
1.139     albertel 1422: 	#return $possible[int(rand($max))][0];
                   1423: 	return $possible[0][0];
1.14      albertel 1424:     }
                   1425:     return undef;
                   1426: }
                   1427: 
1.15      albertel 1428: sub find_mid_grade {
1.30      albertel 1429:     my ($queue,$symb,$cdom,$cnum)=@_;
1.16      albertel 1430:     my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.138     albertel 1431:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15      albertel 1432:     if ($todo) {
1.30      albertel 1433: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel 1434: 	if ($who eq $me) { return $todo; }
                   1435:     }
                   1436:     my $regexp="^$symb\0.*\0locked\$";
1.30      albertel 1437:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel 1438:     foreach my $key (keys(%locks)) {
                   1439: 	my $who=$locks{$key};
                   1440: 	if ($who eq $me) {
                   1441: 	    $todo=$key;
                   1442: 	    $todo=~s/\0locked$//;
                   1443: 	    return $todo;
                   1444: 	}
                   1445:     }
                   1446:     return undef;
                   1447: }
                   1448: 
1.32      albertel 1449: sub lock_key {
                   1450:     my ($queue,$todo)=@_;
1.138     albertel 1451:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.32      albertel 1452:     my (undef,$cid)=&Apache::lonxml::whichuser();
                   1453:     my $cnum=$env{'course.'.$cid.'.num'};
                   1454:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1455:     my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
                   1456: 					$cdom,$cnum);
1.33      albertel 1457:     &Apache::lonxml::debug("success $success $todo");
1.32      albertel 1458:     if ($success eq 'ok') {
                   1459: 	return 1;
                   1460:     }
                   1461:     return 0;
                   1462: }
                   1463: 
1.86      albertel 1464: sub get_queue_symb_status {
1.85      albertel 1465:     my ($queue,$symb,$cdom,$cnum) = @_;
                   1466:     if (!defined($cdom) || !defined($cnum)) {
                   1467: 	my (undef,$cid)=&Apache::lonxml::whichuser();
                   1468: 	$cnum=$env{'course.'.$cid.'.num'};
                   1469: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1470:     }
                   1471:     my $regexp="^$symb\0";
                   1472:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1473:     my ($tmp)=%queue;
                   1474:     if ($tmp=~/^error: 2 /) { return; }
                   1475:     my @users;
                   1476:     foreach my $key (sort(keys(%queue))) {
                   1477: 	next if ($key=~/locked$/);
                   1478: 	next if ($key=~/timestamp$/);
                   1479: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
                   1480: 	push(@users,"$uname:$udom");
                   1481:     }
                   1482:     return @users;
                   1483: }
                   1484: 
1.14      albertel 1485: sub get_from_queue {
1.30      albertel 1486:     my ($queue)=@_;
1.14      albertel 1487:     my $result;
                   1488:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1489:     my $cnum=$env{'course.'.$cid.'.num'};
                   1490:     my $cdom=$env{'course.'.$cid.'.domain'};
1.32      albertel 1491:     my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33      albertel 1492:     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16      albertel 1493:     if ($todo) { return $todo; }
1.95      albertel 1494:     my $attempts=0;
1.14      albertel 1495:     while (1) {
1.95      albertel 1496: 	if ($attempts > 2) {
                   1497: 	    # tried twice to get a queue entry, giving up
                   1498: 	    return (undef,'unable');
                   1499: 	}
1.14      albertel 1500: 	my $starttime=time;
1.83      albertel 1501: 	&Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
                   1502: 			      $cdom,$cnum);
1.33      albertel 1503: 	&Apache::lonxml::debug("$starttime");
1.14      albertel 1504: 	my $regexp="^$symb\0queue\0";
1.97      albertel 1505: 	my $range= ($attempts < 1 ) ? '0-100' : '0-400';
                   1506: 
1.98      albertel 1507: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33      albertel 1508: 	#make a pass looking for a user _not_ in my section
1.14      albertel 1509: 	if ($env{'request.course.sec'}) {
1.33      albertel 1510: 	    &Apache::lonxml::debug("sce");
1.30      albertel 1511: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
                   1512: 					\%queue,$cdom,$cnum);
1.33      albertel 1513: 	    &Apache::lonxml::debug("sce $todo");
1.14      albertel 1514: 	}
1.33      albertel 1515: 	# no one _not_ in our section so look for any user that is
                   1516: 	# ready for grading
1.14      albertel 1517: 	if (!$todo) {
1.33      albertel 1518: 	    &Apache::lonxml::debug("no sce");
1.98      albertel 1519: 	    $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum);
1.33      albertel 1520: 	    &Apache::lonxml::debug("no sce $todo");
1.14      albertel 1521: 	}
                   1522: 	# no user to grade 
                   1523: 	if (!$todo) { last; }
1.33      albertel 1524: 	&Apache::lonxml::debug("got $todo");
1.14      albertel 1525: 	# otherwise found someone so lets try to lock them
1.32      albertel 1526: 	# unless someone else already picked them
1.95      albertel 1527: 	if (!&lock_key($queue,$todo)) {
                   1528: 	    $attempts++;
                   1529: 	    next;
                   1530: 	}
1.14      albertel 1531: 	my (undef,$endtime)=
1.30      albertel 1532: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel 1533: 				 $cdom,$cnum);
1.33      albertel 1534: 	&Apache::lonxml::debug("emd  $endtime");
1.14      albertel 1535: 	# someone else already modified the queue, 
                   1536: 	# perhaps our picked user wass already fully graded between
                   1537: 	# when we picked him and when we locked his record? so lets
                   1538: 	# double check.
                   1539: 	if ($endtime != $starttime) {
                   1540: 	    my ($key,$value)=
1.30      albertel 1541: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel 1542: 				     $cdom,$cnum);
1.33      albertel 1543: 	    &Apache::lonxml::debug("check  $key .. $value");
1.14      albertel 1544: 	    if ($key eq $todo && ref($value)) {
                   1545: 	    } else {
1.30      albertel 1546: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel 1547: 				     $cdom,$cnum);
1.33      albertel 1548: 		&Apache::lonxml::debug("del");
1.95      albertel 1549: 		$attempts++;
1.14      albertel 1550: 		next;
                   1551: 	    }
                   1552: 	}
1.33      albertel 1553: 	&Apache::lonxml::debug("last $todo");
1.14      albertel 1554: 	last;
                   1555:     }
                   1556:     return $todo;
                   1557: }
                   1558: 
1.49      albertel 1559: sub select_user {
                   1560:     my ($symb,$cid)=&Apache::lonxml::whichuser();
                   1561: 
1.59      albertel 1562:     my @chosen_sections=
                   1563: 	&Apache::loncommon::get_env_multiple('form.chosensections');
1.49      albertel 1564:     &Apache::grades::init_perm();
1.59      albertel 1565:     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
1.49      albertel 1566:     &Apache::grades::reset_perm();
1.63      albertel 1567:     
                   1568:     my $result;
                   1569:     if (!(grep(/^all$/,@chosen_sections))) {
                   1570: 	$result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
                   1571: 	    '</tt>.</p> '."\n";
                   1572:     }
                   1573:     $result.='<table border="1">';
1.49      albertel 1574: 
                   1575:     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
                   1576: 	my ($uname,$udom) = split(/:/,$student);
1.59      albertel 1577: 	
1.84      albertel 1578: 	my $cnum=$env{'course.'.$cid.'.num'};
                   1579: 	my $cdom=$env{'course.'.$cid.'.domain'};
1.88      albertel 1580: 	my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
                   1581: 					 'Task');
1.49      albertel 1582: 	my $queue = 'none';
1.58      albertel 1583: 	my $cannot_grade;
                   1584: 	if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 1585: 	    $queue = 'reviewqueue';
1.58      albertel 1586: 	    if ($status{'reviewqueue'} eq 'in_progress') {
                   1587: 		$cannot_grade=1;
                   1588: 	    }
                   1589: 	} elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 1590: 	    $queue = 'gradingqueue';
1.58      albertel 1591: 	    if ($status{'gradingqueue'} eq 'in_progress') {
                   1592: 		$cannot_grade=1;
                   1593: 	    }
1.49      albertel 1594: 	}
                   1595: 	my $todo = 
                   1596: 	    &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
1.58      albertel 1597: 	if ($cannot_grade) {
                   1598: 	    $result.='<tr><td>&nbsp;</td><td>'.$fullname->{$student}.
                   1599: 		'</td><td>';
                   1600: 	} else {
1.62      albertel 1601: 	    my $seclist;
                   1602: 	    foreach my $sec (@chosen_sections) {
                   1603: 		$seclist.='<input type="hidden" name="chosensections" 
                   1604:                                value="'.$sec.'" />';
                   1605: 	    }
1.102     albertel 1606: 	    my $studentdis = $student;
                   1607: 	    $studentdis =~ tr/:/@/;
1.58      albertel 1608: 	    $result.=<<RESULT;
1.49      albertel 1609: <tr>
                   1610:   <td>
1.115     albertel 1611:     <form style="display: inline" method="post">
1.49      albertel 1612:       <input type="hidden" name="gradingkey" value="$todo" />
                   1613:       <input type="hidden" name="queue" value="$queue" />
                   1614:       <input type="hidden" name="webgrade" value="no" />
1.52      albertel 1615:       <input type="hidden" name="regrade" value="yes" />
1.62      albertel 1616:       <input type="submit" name="submit" value="Regrade" />
                   1617:       $seclist
1.49      albertel 1618:     </form>
1.102     albertel 1619:   <td>$fullname->{$student} <tt>($studentdis)</tt></td>
1.49      albertel 1620:   <td>
                   1621: RESULT
1.58      albertel 1622:         }
1.49      albertel 1623:         if ($status{'status'} eq 'pass') {
                   1624: 	    $result .= '<font color="green">'.&mt('Passed').'</font>';
                   1625: 	} elsif ($status{'status'} eq 'fail') {
                   1626: 	    $result .= '<font color="red">'.&mt('Failed').'</font>';
                   1627: 	} elsif ($status{'status'} eq 'review') {
                   1628: 	    $result .= '<font color="blue">'.&mt('Under Review').'</font>';
                   1629: 	} elsif ($status{'status'} eq 'ungraded') {
                   1630: 	    $result .= &mt('Ungraded');
                   1631: 	} elsif ($status{'status'} ne '') {
                   1632: 	    $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
                   1633: 	} else {
                   1634: 	    $result.="&nbsp;";
                   1635: 	}
                   1636: 	if ($status{'version'}) {
                   1637: 	    $result .= ' '.&mt('Version').' '.$status{'version'};
                   1638: 	}
1.101     albertel 1639: 	if ($status{'grader'}) {
                   1640: 	    $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
                   1641: 	}
1.49      albertel 1642: 	$result.= '</td><td>';
                   1643: 	if ($status{'reviewqueue'} eq 'enqueued') {
                   1644: 	    $result .= &mt('Awaiting Review');
                   1645: 	} elsif ($status{'reviewqueue'} eq 'locked') {
                   1646: 	    $result .= &mt('Under Review');
1.58      albertel 1647: 	} elsif ($status{'reviewqueue'} eq 'in_progress') {
                   1648: 	    $result .= &mt('Still being worked on.');
1.49      albertel 1649: 	} elsif ($status{'gradingqueue'} eq 'enqueued') {
                   1650: 	    $result .= &mt('Awaiting Grading');
                   1651: 	} elsif ($status{'gradingqueue'} eq 'locked') {
                   1652: 	    $result .= &mt('Being Graded');
1.58      albertel 1653: 	} elsif ($status{'gradingqueue'} eq 'in_progress') {
                   1654: 	    $result .= &mt('Still being worked on.');
1.49      albertel 1655: 	} else {
                   1656: 	    $result.="&nbsp;";
                   1657: 	}
                   1658: 	$result.= '</td></tr>';
                   1659:     }
                   1660:     $result.='</table>';
                   1661:     return $result;
                   1662: }
                   1663: 
                   1664: sub get_student_status {
1.86      albertel 1665:     my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
                   1666: 
                   1667:     my %status;
                   1668: 
                   1669:     if ($type eq 'Task') {
                   1670: 	my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49      albertel 1671: 					  $udom,$uname);
1.89      albertel 1672: 	$status{'status'}=$record{'resource.0.status'};
                   1673: 	$status{'version'}=$record{'resource.0.version'};
                   1674: 	$status{'grader'}=$record{'resource.0.regrader'};
1.86      albertel 1675:     }
                   1676:     $status{'reviewqueue'}=
                   1677: 	&check_queue_for_key($cdom,$cnum,'reviewqueue',
                   1678: 			     &encode_queue_key($symb,$udom,$uname));
                   1679:     $status{'gradingqueue'}=
                   1680: 	&check_queue_for_key($cdom,$cnum,'gradingqueue',
                   1681: 			     &encode_queue_key($symb,$udom,$uname));
1.49      albertel 1682:     return %status;
                   1683: }
                   1684: 
1.1       albertel 1685: sub start_ClosingParagraph {
                   1686:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1687:     my $result;
                   1688:     if ($target eq 'web') {
1.13      albertel 1689:     } elsif ($target eq 'webgrade') {
                   1690: 	&Apache::lonxml::startredirection();
1.1       albertel 1691:     }
                   1692:     return $result;
                   1693: }
                   1694: 
                   1695: sub end_ClosingParagraph {
                   1696:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1697:     my $result;
                   1698:     if ($target eq 'web') {
1.13      albertel 1699:     } elsif ($target eq 'webgrade') {
                   1700: 	&Apache::lonxml::endredirection();
1.1       albertel 1701:     }
                   1702:     return $result;
                   1703: }
                   1704: 
1.19      albertel 1705: sub get_id {
                   1706:     my ($parstack,$safeeval)=@_;
                   1707:     my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
                   1708:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                   1709:     return $id;
                   1710: }
                   1711: 
1.1       albertel 1712: my %dimension;
1.151   ! albertel 1713: sub start_Question { return &start_Dimension(@_); }
1.1       albertel 1714: sub start_Dimension {
                   1715:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1716:     undef(%dimension);
1.19      albertel 1717:     my $dim_id=&get_id($parstack,$safeeval);
1.9       albertel 1718:     $Apache::bridgetask::dimension=$dim_id;
                   1719:     push(@Apache::bridgetask::dimensionlist,$dim_id);
                   1720:     undef(@Apache::bridgetask::instance);
1.20      albertel 1721:     $Apache::bridgetask::dimensionmandatory{$dim_id}=
                   1722: 	&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.54      albertel 1723:     &Apache::lonxml::startredirection();
                   1724:     return &internal_location($dim_id);
1.1       albertel 1725: }
                   1726: 
1.13      albertel 1727: sub get_instance {
1.75      albertel 1728:     my ($dim)=@_;
                   1729:     my $rand_alg=&Apache::lonnet::get_rand_alg();
                   1730:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
                   1731: 	$rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
                   1732: 	$rand_alg eq '64bit4' ) {
                   1733: 	&Apache::response::pushrandomnumber();
                   1734: 	my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
                   1735: 	my $num=@order;
                   1736: 	my $version=&get_version();
                   1737: 	my $which=($version-1)%$num;
                   1738: 	return $order[$which];
                   1739:     } else {
                   1740: 	my ($version,$previous) = &get_version();
                   1741: 	my $instance = 
                   1742: 	    $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
                   1743: 	if (defined($instance)) { return $instance; }
                   1744: 
                   1745: 	&Apache::response::pushrandomnumber();
                   1746: 	my @instances = @{$dimension{'instances'}};
                   1747: 	# remove disabled instances
                   1748: 	for (my $i=0; $i < $#instances; $i++) {
                   1749: 	    if ($dimension{$instances[$i].'.disabled'}) {
                   1750: 		splice(@instances,$i,1);
                   1751: 		$i--;
                   1752: 	    }
                   1753: 	}
                   1754: 	@instances = &Math::Random::random_permutation(@instances);
                   1755: 	$instance  = $instances[($version-1)%scalar(@instances)];
1.150     albertel 1756: 	if ($version =~ /^\d$/) {
                   1757: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = 
                   1758: 		$instance;
                   1759: 	    $Apache::lonhomework::results{'INTERNAL_store'} = 1; 
                   1760: 	}
1.75      albertel 1761: 	&Apache::response::poprandomnumber();
                   1762: 	return $instance;
                   1763:     }
1.13      albertel 1764: }
                   1765: 
1.18      albertel 1766: {
                   1767:     my $last_link;
1.122     albertel 1768:     sub link {
1.151   ! albertel 1769: 	my ($id) = @_;
        !          1770: 	$id =~ s/\./_/g;
        !          1771: 	return 'LC_GRADING_criteria_'.$id;
1.122     albertel 1772:     }
1.151   ! albertel 1773:     sub end_Question { return &end_Dimension(@_); }
1.18      albertel 1774:     sub end_Dimension {
                   1775: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54      albertel 1776: 	my $result=&Apache::lonxml::endredirection();
1.25      albertel 1777: 	my $dim=&get_id($parstack,$safeeval);
1.75      albertel 1778: 	my $instance=&get_instance($dim);
1.25      albertel 1779: 	my $version=&get_version();
1.151   ! albertel 1780: 	    use Data::Dumper;
        !          1781: 	    &Apache::lonxml::debug(Dumper(\%dimension));
1.18      albertel 1782: 	if ($target eq 'web') {
1.47      albertel 1783: 	    @Apache::scripttag::parser_env = @_;
                   1784: 	    $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1.76      albertel 1785: 	    my @instances = $instance;
                   1786: 	    if (&Apache::response::showallfoils()) {
                   1787: 		@instances = @{$dimension{'instances'}};
                   1788: 	    }
                   1789: 	    foreach my $instance (@instances) {
                   1790: 		@Apache::scripttag::parser_env = @_;
                   1791: 		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.89      albertel 1792: 		if ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass' ||
                   1793: 		    $Apache::lonhomework::history{"resource.$version.0.status"} eq 'fail') {
1.76      albertel 1794: 
1.89      albertel 1795: 		    my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
1.76      albertel 1796: 		    my $mandatory='Mandatory';
                   1797: 		    if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
                   1798: 			$mandatory='Optional';
                   1799: 		    }
1.116     albertel 1800: 		    my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
1.76      albertel 1801: 		    if ($dim_status eq 'pass') {
                   1802: 			$dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1.54      albertel 1803: 		    }
1.76      albertel 1804: 		    if ($dim_status eq 'fail') {
                   1805: 			$dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1.53      albertel 1806: 		    }
1.76      albertel 1807: 		    my $man_count=0;
                   1808: 		    my $man_passed=0;
                   1809: 		    my $opt_count=0;
                   1810: 		    my $opt_passed=0;
1.151   ! albertel 1811: 		    foreach my $id ( @{$dimension{$instance.'.criterias'}},
        !          1812: 				     @{$dimension{'criterias'}} ) {
        !          1813: 			if ($dimension{'criteria.'.$id.'.mandatory'} 
1.76      albertel 1814: 			    eq 'N') {
                   1815: 			    $opt_count++;
1.151   ! albertel 1816: 			    if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"} eq 'pass') {
1.76      albertel 1817: 				$opt_passed++;
                   1818: 			    }
                   1819: 			} else {
                   1820: 			    $man_count++;
1.89      albertel 1821: 			    if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"} eq 'pass') {
1.76      albertel 1822: 				$man_passed++;
                   1823: 			    }
                   1824: 			}
1.22      albertel 1825: 		    }
1.76      albertel 1826: 		    if ($man_passed eq $man_count) { $man_passed='all'; }
1.151   ! albertel 1827: 
1.76      albertel 1828: 		    my $opt_req=$dimension{$instance.'.optionalrequired'};
1.151   ! albertel 1829: 		    if ($opt_req !~ /\S/) {
        !          1830: 			$opt_req=
        !          1831: 			    &Apache::lonxml::get_param('OptionalRequired',
        !          1832: 						       $parstack,$safeeval);
        !          1833: 			if ($opt_req !~ /\S/) { $opt_req = 0; }
        !          1834: 		    }
1.76      albertel 1835: 		    $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>";
                   1836: 
                   1837: 		    my $internal_location=&internal_location($dim);
                   1838: 		    $result=~s/\Q$internal_location\E/$dim_info/;
                   1839: 
1.151   ! albertel 1840: 		    foreach my $id (@{$dimension{$instance.'.criterias'}},
        !          1841: 				    @{$dimension{'criterias'}}) {
        !          1842: 			my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"};
        !          1843: 			my $comment=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"};
        !          1844: 			my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N');
1.76      albertel 1845: 			if ($mandatory) {
                   1846: 			    $mandatory='Mandatory';
                   1847: 			} else {
                   1848: 			    $mandatory='Optional';
                   1849: 			}
                   1850: 			if ($status eq 'fail') {
                   1851: 			} elsif ($status eq 'pass') {
                   1852: 			} else {
                   1853: 			    &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
                   1854: 			}
                   1855: 			my $status_display=$status;
                   1856: 			$status_display=~s/^([a-z])/uc($1)/e;
1.116     albertel 1857: 			$result.=
                   1858: 			    '<div class="LC_'.$status.' LC_criteria"><h4>'
                   1859: 			    .$mandatory.' Criteria</h4><p>';
1.76      albertel 1860: 			@Apache::scripttag::parser_env = @_;
1.151   ! albertel 1861: 			$result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id});
1.116     albertel 1862: 			$result.='</p><p class="LC_grade">'.$status_display.'</p>';
1.151   ! albertel 1863: 			if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}) {
        !          1864: 			    $result.='<p class="LC_comment">'.&mt('Comment: [_1]',$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}).'</p>';
1.76      albertel 1865: 			}
                   1866: 			$result.='</div>';
1.22      albertel 1867: 		    }
                   1868: 		}
                   1869: 	    }
1.18      albertel 1870: 	} elsif ($target eq 'webgrade') {
1.47      albertel 1871: 	    # in case of any side effects that we need
                   1872: 	    @Apache::scripttag::parser_env = @_;
                   1873: 	    &Apache::scripttag::xmlparse($dimension{'intro'});
                   1874: 	    @Apache::scripttag::parser_env = @_;
                   1875: 	    &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.151   ! albertel 1876: 	    foreach my $id (@{$dimension{$instance.'.criterias'}},
        !          1877: 			    @{$dimension{'criterias'}} ) {
        !          1878: 		my $link=&link($id);
        !          1879: 		my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"};
1.120     albertel 1880: 		$result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
1.136     albertel 1881: 		    '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
1.47      albertel 1882: 		@Apache::scripttag::parser_env = @_;
1.151   ! albertel 1883: 		$result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id});
1.111     albertel 1884: 		$result.='</div>'."\n".
1.151   ! albertel 1885: 		    #$dimension{'criteria.'.$id}.
1.120     albertel 1886: 		    '<div class="LC_GRADING_grade">'."\n".
                   1887: 		    '<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
                   1888: 		    '<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
                   1889: 		    '<label class="LC_GRADING_pass"><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label>'."\n".
                   1890: 		    '<label class="LC_GRADING_review"><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label>'."\n".
1.111     albertel 1891: 		    '</div>'."\n".
1.120     albertel 1892: 		    '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
1.151   ! albertel 1893: 		    '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}).'</textarea>'."\n".
1.111     albertel 1894: 		    '</label>'."\n".
1.120     albertel 1895: 		    '<ul class="LC_GRADING_navbuttons">'."\n".
1.111     albertel 1896: 		    '<li><a href="#'.$last_link.'">Prev</a></li>'."\n".
                   1897: 		    '<li><a href="#next_'.$link.'">Next</a></li>'."\n".
                   1898: 		    '</ul>'."\n".
                   1899:                     '</div>'."\n";
1.151   ! albertel 1900: 		$result.=&grading_history($version,$dim,$id);
1.18      albertel 1901: 		$last_link=$link;
                   1902: 	    }
1.22      albertel 1903: 	} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19      albertel 1904: 	    my $optional_passed=0;
1.20      albertel 1905: 	    my $mandatory_failed=0;
                   1906: 	    my $ungraded=0;
                   1907: 	    my $review=0;
1.151   ! albertel 1908: 	    foreach my $id (@{$dimension{$instance.'.criterias'}},
        !          1909: 			    @{$dimension{'criterias'}}) {
        !          1910: 		my $link=&link($id);
        !          1911: 		my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
        !          1912: 		$Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
        !          1913: 		my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N');
1.20      albertel 1914: 		if ($status eq 'pass') {
                   1915: 		    if (!$mandatory) { $optional_passed++; }
                   1916: 		} elsif ($status eq 'fail') {
                   1917: 		    if ($mandatory) { $mandatory_failed++; }
1.21      albertel 1918: 		} elsif ($status eq 'review') {
                   1919: 		    $review++;
1.20      albertel 1920: 		} elsif ($status eq 'ungraded') {
                   1921: 		    $ungraded++;
1.21      albertel 1922: 		} else {
1.47      albertel 1923: 		    $ungraded++;
1.19      albertel 1924: 		}
                   1925: 	    }
1.151   ! albertel 1926: 	    # FIXME optional required can apply to only <instance> right now...
        !          1927: 	    my $opt_req=$dimension{$instance.'.optionalrequired'};
        !          1928: 	    if ($opt_req !~ /\S/) {
        !          1929: 		$opt_req=
        !          1930: 		    &Apache::lonxml::get_param('OptionalRequired',
        !          1931: 					       $parstack,$safeeval);
        !          1932: 		if ($opt_req !~ /\S/) { $opt_req = 0; }
        !          1933: 	    }
        !          1934: 	    if ($optional_passed < $opt_req) {
1.20      albertel 1935: 		$mandatory_failed++;
                   1936: 	    }
1.21      albertel 1937: 	    &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 1938: 	    if ($review) {
1.89      albertel 1939: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 1940: 		    'review';
1.20      albertel 1941: 	    } elsif ($ungraded) {
1.89      albertel 1942: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 1943: 		    'ungraded';
1.20      albertel 1944: 	    } elsif ($mandatory_failed) {
1.89      albertel 1945: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 1946: 		    'fail';
1.20      albertel 1947: 	    } else {
1.91      albertel 1948: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 1949: 		    'pass';
1.20      albertel 1950: 	    }
1.69      albertel 1951: 	} else {
                   1952: 	    # any other targets no output
                   1953: 	    undef($result);
1.13      albertel 1954: 	}
1.18      albertel 1955: 	return $result;
1.1       albertel 1956:     }
                   1957: }
                   1958: 
1.113     albertel 1959: sub grading_history {
1.151   ! albertel 1960:     my ($version,$dim,$id) = @_;
1.113     albertel 1961:     if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
                   1962: 	return '';
                   1963:     }
                   1964:     my ($result,$grader);
1.151   ! albertel 1965:     my $scope="resource.$version.0.$dim.$id";
1.113     albertel 1966:     foreach my $t (1..$Apache::lonhomework::history{'version'}) {
                   1967: 	if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
                   1968: 	    my ($gname,$gdom) = 
1.138     albertel 1969: 		split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113     albertel 1970: 	    my $fullname = &Apache::loncommon::plainname($gname,$gdom);
                   1971: 	    $grader = &Apache::loncommon::aboutmewrapper($fullname,
                   1972: 							 $gname,$gdom);
                   1973: 	}
                   1974: 	my $entry;
                   1975: 	if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
                   1976: 	    $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
                   1977: 	}
                   1978: 	if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
                   1979: 	    $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
                   1980: 	}
                   1981: 	if ($entry) {
                   1982: 	    $result.= "<li>$grader : $entry </li>";
                   1983: 	}
                   1984:     }
                   1985:     if ($result) {
1.120     albertel 1986: 	return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
1.113     albertel 1987:     }
                   1988:     return '';
                   1989: }
                   1990: 
1.1       albertel 1991: sub start_IntroParagraph {
1.87      albertel 1992:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1       albertel 1993:     my $result;
1.13      albertel 1994:     if ($target eq 'web' || $target eq 'webgrade') {
1.151   ! albertel 1995: 	if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
        !          1996: 	    $dimension{'intro'}=
        !          1997: 		&Apache::lonxml::get_all_text('/introparagraph',
        !          1998: 					      $parser,$style);
        !          1999:        	} elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2000: 	    &Apache::lonxml::startredirection();
1.1       albertel 2001: 	}
1.47      albertel 2002: 	
1.1       albertel 2003:     }
                   2004:     return $result;
                   2005: }
                   2006: 
                   2007: sub end_IntroParagraph {
1.127     albertel 2008:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128     albertel 2009:     if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2010: 	my $result = &Apache::lonxml::endredirection();
                   2011:     }
1.1       albertel 2012: }
                   2013: 
                   2014: sub start_Instance {
                   2015:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel 2016:     my $id=&get_id($parstack,$safeeval);
                   2017:     push(@{$dimension{'instances'}},$id);
                   2018:     push(@Apache::bridgetask::instance,$id);
                   2019:     push(@Apache::bridgetask::instancelist,$id);
1.20      albertel 2020:     $dimension{$id.'.optionalrequired'}=
1.19      albertel 2021: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75      albertel 2022:     my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
                   2023:     if (lc($disabled) eq 'yes') {
                   2024: 	$dimension{$id.'.disabled'}='1';
                   2025:     }
1.1       albertel 2026:     return '';
                   2027: }
                   2028: 
                   2029: sub end_Instance {
                   2030: }
                   2031: 
                   2032: sub start_InstanceText {
1.87      albertel 2033:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.47      albertel 2034:     my $instance_id=$Apache::bridgetask::instance[-1];
1.87      albertel 2035:     my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
1.13      albertel 2036:     if ($target eq 'web' || $target eq 'webgrade') {
1.47      albertel 2037: 	$dimension{$instance_id.'.text'}=$text;
1.1       albertel 2038:     }
                   2039:     return '';
                   2040: }
                   2041: 
                   2042: sub end_InstanceText {
                   2043:     return '';
                   2044: }
                   2045: 
                   2046: sub start_Criteria {
1.87      albertel 2047:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   2048:     my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.21      albertel 2049:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.19      albertel 2050: 	my $id=&get_id($parstack,$safeeval);
1.151   ! albertel 2051: 	if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
        !          2052: 	    my $instance_id=$Apache::bridgetask::instance[-1];
        !          2053: 	    $dimension{"criteria.$instance_id.$id"}=$criteria;
        !          2054: 	    $dimension{"criteria.$instance_id.$id.mandatory"}=
        !          2055: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
        !          2056: 	    push(@{$dimension{$instance_id.'.criterias'}},"$instance_id.$id");
        !          2057: 	} else {
        !          2058: 	    $dimension{'criteria.'.$id}=$criteria;
        !          2059: 	    $dimension{'criteria.'.$id.'.mandatory'}=
        !          2060: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
        !          2061: 	    push(@{$dimension{'criterias'}},$id);
        !          2062: 	}
1.1       albertel 2063:     }
                   2064:     return '';
                   2065: }
                   2066: 
1.47      albertel 2067: sub end_Criteria {
                   2068: }
                   2069: 
1.4       albertel 2070: sub proctor_validation_screen {
                   2071:     my ($slot) = @_;
                   2072:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel 2073:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44      albertel 2074:     my $name=&Apache::loncommon::plainname($user,$domain);
                   2075:     
1.4       albertel 2076:     my $msg;
1.11      albertel 2077:     if ($env{'form.proctorpassword'}) {
1.4       albertel 2078: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                   2079: 	    .'</font></p>';
                   2080:     }
1.47      albertel 2081:     if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4       albertel 2082:     my $result= (<<ENDCHECKOUT);
                   2083: <h2>Proctor Validation</h2>
                   2084:     <p>Your room's proctor needs to validate your access to this resource.</p>
                   2085:     $msg
1.115     albertel 2086: <form name="checkout" method="post" action="$env{'request.uri'}">
1.4       albertel 2087: <input type="hidden" name="validate" value="yes" />
                   2088: <input type="hidden" name="submitted" value="yes" />
                   2089: <table>
1.44      albertel 2090:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4       albertel 2091:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46      albertel 2092:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4       albertel 2093: </table>
                   2094: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
1.44      albertel 2095: <table border="1">
                   2096:   <tr><td>
                   2097:     <table>
                   2098:       <tr><td colspan="2">Student who should be logged in is:</td></tr>
                   2099:       <tr><td>Name:</td><td>$name</td></tr>
1.45      albertel 2100:       <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.138     albertel 2101:       <tr><td>Usename</td><td>$user:$domain</td></tr>
1.44      albertel 2102:       <tr><td colspan="2"><img src="$url" /></td></tr>
                   2103:     </table>
                   2104:   </tr></td>
                   2105: </table>
1.4       albertel 2106: </form>
                   2107: ENDCHECKOUT
                   2108:     return $result;
                   2109: }
                   2110: 
1.1       albertel 2111: 1;
                   2112: __END__

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