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

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

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