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

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

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