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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.255   ! raeburn     4: # $Id: bridgetask.pm,v 1.254 2010/09/27 20:59:41 raeburn 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 LONCAPA;
                     42:  
1.9       albertel   43: 
1.1       albertel   44: BEGIN {
1.225     albertel   45:     &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','CriteriaText','GraderNote','ClosingParagraph'));
1.1       albertel   46: }
                     47: 
1.169     albertel   48: my %dimension;
1.194     albertel   49: my $top = 'top';
                     50: 
1.9       albertel   51: sub initialize_bridgetask {
                     52:     # id of current Dimension, 0 means that no dimension is current 
                     53:     # (inside <Task> only)
1.178     albertel   54:     @Apache::bridgetask::dimension=();
1.9       albertel   55:     # list of all current Instance ids
1.168     albertel   56:     %Apache::bridgetask::instance=();
1.9       albertel   57:     # list of all Instance ids seen in this problem
                     58:     @Apache::bridgetask::instancelist=();
1.15      albertel   59:     # key of queud user data that we are currently grading
                     60:     $Apache::bridgetask::queue_key='';
1.169     albertel   61:     undef(%dimension);
1.9       albertel   62: }
                     63: 
1.4       albertel   64: sub proctor_check_auth {
1.81      albertel   65:     my ($slot_name,$slot,$type)=@_;
1.11      albertel   66:     my $user=$env{'form.proctorname'};
                     67:     my $domain=$env{'form.proctordomain'};
1.4       albertel   68:     
                     69:     my @allowed=split(",",$slot->{'proctor'});
                     70:     foreach my $possible (@allowed) {
1.138     albertel   71: 	my ($puser,$pdom)=(split(':',$possible));
1.4       albertel   72: 	if ($puser eq $user && $pdom eq $domain) {
1.72      albertel   73: 	    my $authenticated=0;
                     74: 	    if ( $slot->{'secret'} =~ /\S/ &&
                     75: 		 $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
                     76: 		$authenticated=1;
                     77: 	    } else {
                     78: 		
                     79: 		my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
                     80: 		if ($authhost ne 'no_host') {
                     81: 		    $authenticated=1;
                     82: 		}
                     83: 	    }
1.150     albertel   84: 	    if ($authenticated) {
1.246     raeburn    85: 		my $check = &check_in($type,$user,$domain,$slot_name);
                     86:                 if ($check =~ /^error:/) {
                     87:                     return 0;
                     88:                 }
1.4       albertel   89: 		return 1;
                     90: 	    }
                     91: 	}
                     92:     }
                     93:     return 0;
                     94: }
                     95: 
1.174     albertel   96: sub check_in {
                     97:     my ($type,$user,$domain,$slot_name) = @_;
                     98:     my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
                     99:     if ( $useslots eq 'map_map') {
1.246     raeburn   100: 	my $result = &check_in_sequence($user,$domain,$slot_name);
                    101:         if ($result =~ /^error: /) {
                    102:             return $result;
                    103:         }
1.174     albertel  104:     } else {
                    105: 	&create_new_version($type,$user,$domain,$slot_name);
1.217     albertel  106: 	&Apache::structuretags::finalize_storage();
1.174     albertel  107:     }
                    108:     return 1;
                    109: }
                    110: 
                    111: sub check_in_sequence {
                    112:     my ($user,$domain,$slot_name) = @_;
                    113:     my $navmap = Apache::lonnavmaps::navmap->new();
1.246     raeburn   114:     if (!defined($navmap)) {
                    115:         return 'error: ';
                    116:     }
1.185     albertel  117:     my ($symb) = &Apache::lonnet::whichuser();
1.174     albertel  118:     my ($map)  = &Apache::lonnet::decode_symb($symb);
1.175     albertel  119:     my @resources = 
                    120: 	$navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
1.174     albertel  121:     my %old_history = %Apache::lonhomework::history;
                    122:     my %old_results = %Apache::lonhomework::results;
                    123: 
                    124:     foreach my $res (@resources) {
                    125: 	&Apache::lonxml::debug("doing ".$res->src);
                    126: 	&Apache::structuretags::initialize_storage($res->symb);
                    127: 	my $type = ($res->is_task()) ? 'Task' : 'problem';
                    128: 	&create_new_version($type,$user,$domain,$slot_name);
                    129: 	&Apache::structuretags::finalize_storage($res->symb);
                    130:     }
                    131:     
                    132:     %Apache::lonhomework::history = %old_history;
                    133:     %Apache::lonhomework::results = %old_results;
                    134: }
                    135: 
1.150     albertel  136: sub create_new_version {
                    137:     my ($type,$user,$domain,$slot_name) = @_;
1.174     albertel  138:     
                    139:     my $id = '0';
1.150     albertel  140:     if ($type eq 'Task') {
                    141: 	# increment version
                    142: 	my $version=
                    143: 	    $Apache::lonhomework::history{'resource.0.version'};
                    144: 	$version++;
1.152     albertel  145: 	&Apache::lonxml::debug("Making version $version");
1.150     albertel  146: 	#clean out all current results
                    147: 	foreach my $key (keys(%Apache::lonhomework::history)) {
                    148: 	    if ($key=~/^resource\.0\./) {
                    149: 		$Apache::lonhomework::results{$key}='';
                    150: 	    }
                    151: 	}
                    152: 	
                    153: 	#setup new version and who did it
1.174     albertel  154:        	$Apache::lonhomework::results{'resource.0.version'}=$version;
                    155: 	$id = "$version.0";
1.178     albertel  156: 	if (!defined($user) || !defined($domain)) {
1.174     albertel  157: 	    $user = $env{'user.name'};
                    158: 	    $domain = $env{'user.domain'};
1.150     albertel  159: 	}
1.174     albertel  160: 	
1.150     albertel  161:     } elsif ($type eq 'problem') {
                    162: 	&Apache::lonxml::debug("authed $slot_name");
1.174     albertel  163:     }
1.181     albertel  164:     if (!defined($user) || !defined($domain)) {
                    165: 	$user = $env{'user.name'};
                    166: 	$domain = $env{'user.domain'};
                    167:     }
                    168: 
                    169:     $Apache::lonhomework::results{"resource.$id.checkedin"}=
                    170: 	$user.':'.$domain;
1.174     albertel  171: 
                    172:     if (defined($slot_name)) {
                    173: 	$Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
                    174: 	    $slot_name;
1.150     albertel  175:     }
                    176: }
                    177: 
1.25      albertel  178: sub get_version {
1.29      albertel  179:     my ($version,$previous);
1.25      albertel  180:     if ($env{'form.previousversion'} && 
1.36      albertel  181: 	$env{'form.previousversion'} ne 'current' &&
1.89      albertel  182: 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
1.29      albertel  183: 	$version=$env{'form.previousversion'};
                    184: 	$previous=1;
                    185:     } else {
1.150     albertel  186: 	if (defined($Apache::lonhomework::results{'resource.0.version'})) {
                    187: 	    $version=$Apache::lonhomework::results{'resource.0.version'};
                    188: 	} elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
                    189: 	    $version=$Apache::lonhomework::history{'resource.0.version'};
                    190: 	}
1.29      albertel  191: 	$previous=0;
                    192:     }
                    193:     if (wantarray) {
                    194: 	return ($version,$previous);
1.25      albertel  195:     }
1.29      albertel  196:     return $version;
1.25      albertel  197: }
                    198: 
1.8       albertel  199: sub add_previous_version_button {
1.25      albertel  200:     my ($status)=@_;
1.8       albertel  201:     my $result;
1.89      albertel  202:     if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
1.25      albertel  203: 	return '';
                    204:     }
1.89      albertel  205:     if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
1.29      albertel  206: 	$status ne 'NEEDS_CHECKIN') {
1.25      albertel  207: 	return '';
                    208:     }
1.29      albertel  209:     my $version=&get_version();
                    210:     if ($env{'form.previousversion'} ne '' &&
                    211: 	$env{'form.previousversion'} eq $version) {
                    212: 	$result.="<h3>".&mt("Showing previous version [_1]",$version).
                    213: 	    "</h3>\n";
                    214:     }
                    215:     my @to_show;
1.89      albertel  216:     foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
                    217: 	if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
1.29      albertel  218: 	    push(@to_show,$test_version);
                    219: 	}
                    220:     }
                    221:     my $list='<option>'.
                    222: 	join("</option>\n<option>",@to_show).
                    223: 	     "</option>\n";
1.36      albertel  224:     $list.='<option value="current">'.&mt('Current').'</option>';
1.115     albertel  225:     $result.='<form name="getprevious" method="post" action="';
1.29      albertel  226:     my $uri=$env{'request.uri'};
                    227:     if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    228:     $result.=$uri.'">'.
                    229: 	&mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
                    230: <option>'.&mt('Pick one').'</option>
                    231: '.$list.'
                    232: </select>')."</form>";
1.8       albertel  233:     return $result;
                    234: }
                    235: 
1.13      albertel  236: sub add_grading_button {
1.185     albertel  237:     my (undef,$cid)=&Apache::lonnet::whichuser();
1.59      albertel  238:     my $cnum=$env{'course.'.$cid.'.num'};
                    239:     my $cdom=$env{'course.'.$cid.'.domain'};
1.144     albertel  240:     my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
                    241: 
1.59      albertel  242:     my $size=5;
                    243:     if (scalar(keys(%sections)) < 3) {
                    244: 	$size=scalar(keys(%sections))+2;
                    245:     }
1.200     albertel  246:     my $sec_select = "\n".'<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
                    247:     $sec_select .= "\t<option value='all' selected='selected'>all</option>\n";
1.59      albertel  248:     foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
1.200     albertel  249: 	$sec_select .= "\t<option value=\"$sec\">$sec</option>\n";
1.59      albertel  250:     }
1.200     albertel  251:     $sec_select .= "\t<option value='none'>none</option>\n</select>\n";
1.59      albertel  252:     
1.200     albertel  253:     my $result="\n\t".'<input type="submit" name="gradeasubmission" value="'.
1.13      albertel  254: 	&mt("Get a submission to grade").'" />';
1.200     albertel  255:     $result.="\n\t".'<input type="hidden" name="grade_target" value="webgrade" />';
1.237     albertel  256:     my $see_all = &Apache::lonnet::allowed('mgq',$env{'request.course.id'});
                    257:     my $see_sec = &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.
                    258: 					   '/'.$env{'request.course.sec'});
                    259: 
                    260:     if ($see_all || $see_sec) {
1.34      albertel  261: 	my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.200     albertel  262: 	$result.="\n\t".'<table>'."\n\t\t".'<tr>';
1.237     albertel  263: 	if ($see_all || (!&section_restricted())) {
1.239     bisitz    264: 	    $result.="\n\t\t\t".'<td rowspan="4">'.&mt('Specify a section:').' </td>'.
1.237     albertel  265: 		"\n\t\t\t".'<td rowspan="4">'.$sec_select."\n\t\t\t".'</td>';
                    266: 	} else {
1.239     bisitz    267: 	    $result.="\n\t\t\t".'<td rowspan="4">'.&mt('Grading section:').' </td>'.
1.237     albertel  268: 		"\n\t\t\t".'<td rowspan="4">'.$env{'request.course.sec'}."\n\t\t\t".'</td>';
                    269: 	}
1.200     albertel  270: 	$result.="\n\t\t\t".'<td>'.'<input type="submit" name="reviewagrading" value="'.
1.106     albertel  271: 	    &mt("Select an entry from the grading queue:").'" /> ';
1.34      albertel  272: 
1.200     albertel  273: 	$result.= "\n\t\t\t\t".&mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).'</td>'."\n\t\t".'</tr>'."\n";
1.34      albertel  274: 
                    275: 	($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
1.200     albertel  276: 	$result.="\n\t\t".'<tr>'.
                    277: 	    "\n\t\t\t".'<td>'.
                    278: 	    "\n\t\t\t\t".'<input type="submit" name="reviewasubmission" value="'.
1.106     albertel  279: 	    &mt("Select an entry from the review queue:").'" /> ';
                    280: 	$result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
1.200     albertel  281: 		     $entries,$ready,$locks).'</td>'."\n\t\t".'</tr>'."\n";
                    282: 	$result.="\n\t\t".'<tr>'.
                    283: 	    "\n\t\t\t".'<td>'.
                    284: 	    "\n\t\t\t\t".'<input type="submit" name="regradeasubmission" value="'.
                    285: 	    &mt("List of user's grade status").'" /> </td>'
                    286: 	    ."\n\t\t".'</tr>'
                    287: 	    ."\n\t".'</table>'."\n";
                    288: 	$result.="\n\t".'<p>'.
                    289: 	    "\n\t\t".'<input type="submit" name="regradeaspecificsubmission" value="'.
                    290: 	    &mt("Regrade specific user:").'" />';
                    291: 	$result.= "\n\t\t".'<input type="text" size="12" name="gradinguser" />';
1.105     albertel  292: 	$result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
                    293: 						     'gradingdomain');
                    294: 	$result.=' '.
                    295: 	    &Apache::loncommon::selectstudent_link('gradesubmission',
                    296: 						   'gradinguser',
                    297: 						   'gradingdomain');
                    298: 	$result.=&Apache::loncommon::studentbrowser_javascript();
1.200     albertel  299: 	$result.= '</p>'."\n";
1.144     albertel  300:     }
1.13      albertel  301:     return $result;
                    302: }
                    303: 
1.22      albertel  304: sub add_request_another_attempt_button {
1.38      albertel  305:     my ($text)=@_;
1.239     bisitz    306:     if (!$text) { $text=&mt('Request another attempt'); }
1.25      albertel  307:     my $result;
1.36      albertel  308:     my $symb=&Apache::lonnet::symbread();
1.149     albertel  309:     # not a slot access based resource
                    310:     my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
                    311:     if ($useslots =~ /^\s*no\s*$/i) {
                    312: 	return '';
                    313:     }
                    314: 
1.37      albertel  315:     my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38      albertel  316:     my $action='get_reservation';
1.37      albertel  317:     if ($slot_name) {
1.247     raeburn   318: 	$text=&mt('Change reservation');
1.38      albertel  319: 	$action='change_reservation';
1.37      albertel  320: 	my $description=&Apache::slotrequest::get_description($slot_name,
                    321: 							      $slot);
1.239     bisitz    322: 	$result.='<p>'
                    323:                 .&mt('Will be next available:')
                    324:                 .' '.$description
                    325:                 .'</p>';
1.37      albertel  326:     }
1.38      albertel  327:     
                    328:     if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
1.158     www       329:     $symb=&escape($symb);
1.200     albertel  330:     $result.=
                    331:         "\n\t".'<form method="post" action="/adm/slotrequest">'."\n\t\t".
                    332: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n\t\t".
                    333: 	'<input type="hidden" name="command" value="'.$action.'" />'."\n\t\t".
1.38      albertel  334: 	'<input type="submit" name="requestattempt" value="'.
1.239     bisitz    335: 	$text.'" />'."\n\t".
1.200     albertel  336: 	'</form>'."\n";
1.25      albertel  337:     return $result;
1.22      albertel  338: }
                    339: 
1.30      albertel  340: sub preserve_grade_info {
                    341:     my $result;
                    342:     # if we are viewing someone else preserve that info
                    343:     if (defined $env{'form.grade_symb'}) {
                    344: 	foreach my $field ('symb','courseid','domain','username') {
                    345: 	    $result .= '<input type="hidden" name="grade_'.$field.
                    346: 		'" value="'.$env{"form.grade_$field"}.'" />'."\n";
                    347: 	}
                    348:     }
                    349:     return $result;
                    350: }
                    351: 
1.53      albertel  352: sub style {
1.125     albertel  353:     my ($target) = @_;
                    354:     if ($target eq 'web'
                    355: 	|| $target eq 'webgrade') {
1.192     albertel  356: 	my $style = (<<STYLE);
1.126     albertel  357: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task.css" />
1.53      albertel  358: STYLE
1.192     albertel  359:         if ($env{'browser.type'} eq 'explorer'
                    360: 	    && $env{'browser.os'} eq 'win' ) {
                    361: 	    if ($env{'browser.version'} < 7) {
                    362: 		$style .= (<<STYLE);
                    363: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task_ie.css" />
                    364: STYLE
                    365:             } else {
                    366: 		$style .= (<<STYLE);
                    367: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task_ie7.css" />
                    368: STYLE
                    369: 	    }
                    370: 	}
1.193     albertel  371: 	return $style;
1.125     albertel  372:     }
                    373:     return;
1.53      albertel  374: }
                    375: 
1.54      albertel  376: sub show_task {
                    377:     my ($status,$previous)=@_;
                    378:     if (!$previous && (
                    379: 		       ( $status eq 'CLOSED' ) ||
                    380: 		       ( $status eq 'BANNED') ||
                    381: 		       ( $status eq 'UNAVAILABLE') ||
                    382: 		       ( $status eq 'NOT_IN_A_SLOT') ||
                    383: 		       ( $status eq 'NEEDS_CHECKIN') ||
                    384: 		       ( $status eq 'WAITING_FOR_GRADE') ||
1.150     albertel  385: 		       ( $status eq 'INVALID_ACCESS') ||
                    386: 		       ( &get_version() eq ''))) {
1.54      albertel  387: 	return 0;
                    388:     }
1.64      albertel  389:     if ($env{'form.donescreen'}) { return 0; }
1.54      albertel  390:     return 1;
                    391: }
                    392: 
1.173     albertel  393: my @delay;
                    394: sub nest { 
                    395:     if (@delay) {
                    396: 	return $delay[-1];
                    397:     } else {
                    398: 	return;
                    399:     }
                    400: }
                    401: 
1.208     albertel  402: sub start_delay {
                    403:     push(@delay,1);
                    404: }
                    405: sub end_delay {
                    406:     pop(@delay);
                    407: }
                    408: 
1.173     albertel  409: sub nested_parse {
                    410:     my ($str,$env,$args) = @_;
                    411:     my @old_env = @Apache::scripttag::parser_env;
                    412:     @Apache::scripttag::parser_env = @$env;
                    413:     if (exists($args->{'set_dim_id'})) {
                    414: 	&enable_dimension_parsing($args->{'set_dim_id'});
                    415:     }
                    416:     push(@delay,(($args->{'delayed_dim_results'})? 1 : 0));
                    417:     my $result = &Apache::scripttag::xmlparse($$str);
                    418:     pop(@delay);
                    419:     if (exists($args->{'set_dim_id'})) {
                    420: 	&disable_dimension_parsing();
                    421:     }
                    422:     @Apache::scripttag::parser_env = @old_env;
                    423:     if ($args->{'delayed_dim_results'}) {
                    424: 	my $dim = &get_dim_id();
1.180     albertel  425: 	&Apache::lonxml::debug(" tossing out $result ");
                    426: 	&Apache::lonxml::debug(" usining out $dim 's  ". $dimension{$dim}{'result'});
1.173     albertel  427: 	return $dimension{$dim}{'result'};
                    428:     }
                    429:     return $result;
                    430: }
                    431: 
1.54      albertel  432: sub internal_location {
                    433:     my ($id)=@_;
                    434:     return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
                    435: }
                    436: 
1.60      albertel  437: sub submission_time_stamp {
1.185     albertel  438:     my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.60      albertel  439:     my $submissiontime;
1.89      albertel  440:     my $version=$Apache::lonhomework::history{'resource.0.version'};
1.60      albertel  441:     for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
1.183     albertel  442: 	if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})
                    443: 	    && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) {
1.60      albertel  444: 	    $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
1.182     albertel  445: 	    last;
1.60      albertel  446: 	}
                    447:     }
                    448:     my $result;
                    449:     if ($submissiontime) {
1.89      albertel  450: 	my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
1.60      albertel  451: 	my %slot=&Apache::lonnet::get_slot($slot_name);
                    452: 	my $diff = $slot{'endtime'} - $submissiontime;
1.71      albertel  453: 	my ($color,$when)=('#FF6666','after');
                    454: 	if ($diff > 0) { ($color,$when)=('#336600','before'); }
1.60      albertel  455: 	my $info;
1.182     albertel  456: 	$diff = abs($diff);
1.60      albertel  457: 	if ($diff%60) { $info=($diff%60).' seconds'; }
                    458: 	$diff=int($diff/60);
                    459: 	if ($diff%60) { $info=($diff%60).' minutes '.$info; }
                    460: 	$diff=int($diff/60);
                    461: 	if ($diff) {    $info=$diff.' hours '.$info; }
                    462: 	$result='<p><font color="'.$color.'">'.
1.182     albertel  463: 	    &mt('Student submitted [_1] [_2] the deadline. '.
                    464: 		'(Submission was at [_3], end of period was [_4].)',
                    465: 		$info,$when,
                    466: 		&Apache::lonlocal::locallocaltime($submissiontime),
                    467: 		&Apache::lonlocal::locallocaltime($slot{'endtime'})).
1.60      albertel  468: 		'</font></p>';
                    469:     }
                    470:     return $result;
                    471: }
                    472: 
1.119     albertel  473: sub file_list {
                    474:     my ($files,$uname,$udom) = @_;
                    475:     if (!defined($uname) || !defined($udom)) {
1.185     albertel  476: 	(undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
1.119     albertel  477:     }
1.70      albertel  478:     my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.119     albertel  479: 
1.120     albertel  480:     my $file_list="<ul class=\"LC_GRADING_handininfo\">\n";
1.119     albertel  481:     foreach my $partial_file (split(',',$files)) {
1.70      albertel  482: 	my $file=$file_url.$partial_file;
                    483: 	$file=~s|/+|/|g;
                    484: 	&Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.243     bisitz    485: 	$file_list.='<li><span class="LC_nobreak"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
1.161     albertel  486: 	    &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
                    487: 	    '</a></span></li>'."\n";
1.70      albertel  488:     }
                    489:     $file_list.="</ul>\n";
1.119     albertel  490:     return $file_list;
                    491: }
                    492: 
1.163     albertel  493: sub grade_mode {
                    494:     if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
                    495: 	return 'regrade';
                    496:     }
                    497:     return 'queue_grade';
                    498: }
                    499: 
1.119     albertel  500: sub webgrade_standard_info {
                    501:     my ($version)=&get_version();
                    502: 
                    503:     my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
1.70      albertel  504: 
1.245     bisitz    505:     my %lt = &Apache::lonlocal::texthash(
                    506:         'done'   => 'Next Item',
                    507:         'stop'   => 'Quit Grading',
                    508:         'fail'   => 'Fail Rest',
                    509:         'cancel' => 'Cancel',
                    510:         'submit' => 'Submit Grades',
                    511:     );
1.163     albertel  512: 
1.70      albertel  513:     my $result=<<INFO;
1.120     albertel  514:   <div class="LC_GRADING_maincontrols">
1.163     albertel  515: INFO
                    516: 
1.231     albertel  517:     if ($env{'request.state'} eq 'construct') {
1.163     albertel  518: 	$result.=<<INFO;
1.231     albertel  519:     <input type="submit" name="next" value="$lt{'submit'}" />
                    520: INFO
                    521:     } else {
                    522: 	if (&grade_mode() eq 'regrade' && $env{'request.state'} ne 'construct') {
                    523: 	    $result.=<<INFO;
1.163     albertel  524:     <input type="submit" name="cancel" value="$lt{'cancel'}" />
                    525: INFO
1.231     albertel  526:         }
1.163     albertel  527: 
1.231     albertel  528: 	$result.=<<INFO;
1.111     albertel  529:     <input type="submit" name="next" value="$lt{'done'}" />
                    530:     <input type="submit" name="stop" value="$lt{'stop'}" />
1.231     albertel  531: INFO
                    532:     }
                    533:     $result.=<<INFO;
1.143     albertel  534:     <input type="button" name="fail" value="$lt{'fail'}" 
                    535:            onclick="javascript:onFailRest()" />
1.111     albertel  536:   </div>
1.70      albertel  537:   $file_list
                    538: INFO
                    539:     return $result;
1.231     albertel  540: 
1.70      albertel  541: }
                    542: 
1.166     albertel  543: sub done_screen {
                    544:     my ($version) = @_;
1.231     albertel  545:     my $title=&Apache::lonnet::gettitle($env{'request.uri'});
1.166     albertel  546:     my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
1.185     albertel  547:     my (undef,undef,$domain,$user)= &Apache::lonnet::whichuser();
1.255   ! raeburn   548:     my ($msg,$files,$shown);
        !           549:     if (@files > 0) {
        !           550:         $files = '<ul>';
        !           551:         foreach my $file (@files) {
        !           552: 	    my $url="/uploaded/$domain/$user/portfolio$file";
        !           553: 	    if (! &Apache::lonnet::stat_file($url)) {
        !           554: 	        $file = '<span class="LC_error">'
        !           555:                        .&mt('[_1]Nonexistent file:[_2]'
        !           556:                            ,'<span class="LC_error"> '
        !           557:                            ,'</span> <span class="LC_filename">'.$file.'</span>');
        !           558: 	        $msg .= "<p>".&mt('Submitted non-existent file [_1]',$file)."</p>\n";
        !           559: 	    } else {
        !           560: 	        $file = '<span class="LC_filename">'.$file.'</span>';
        !           561: 	        $msg .= "<p>".&mt('Submitted file [_1]',$file)."</p>\n";
        !           562: 	    }
        !           563: 	    $files .= '<li>'.$file.'</li>';
        !           564:         }
        !           565:         $files.='</ul>';
        !           566:         $shown = '<p>'.&mt('Files submitted: [_1]',$files).'</p>'
        !           567:                 .'<p>'.&mt('You are now done with this Bridge Task').'</p>'
        !           568:                 .'<hr />'
        !           569:                 .'<p><a href="/adm/logout">'.&mt('Logout').'</a></p>'
        !           570:                 .'<p><a href="/adm/roles">'.&mt('Change to a different course').'</a></p>';
        !           571:     } else {
        !           572:         $msg = &mt("Submission status: no files currently submitted, when 'Done' was indicated.");
        !           573:         $shown = '<p class="LC_error">'.
        !           574:                  &mt('You did not submit any files.  Please try again.').'</span>'.
        !           575:                  '</p><p><a href="javascript:history.go(-1);">'.&mt('Back to Bridge Task').'</a></p><hr />';
1.166     albertel  576:     }
1.239     bisitz    577:     my $subject = &mt('Submission message for [_1]',$title);
1.167     albertel  578:     my ($message_status,$comment_status);
                    579:     my $setting = $env{'course.'.$env{'request.course.id'}.'.task_messages'};
                    580:     $setting =~ s/^\s*(\S*)\s*$/$1/;
                    581:     $setting = lc($setting);
                    582:     if ($setting eq 'only_student'
                    583: 	|| $setting eq 'student_and_user_notes_screen') {
                    584: 	$message_status =
                    585: 	    &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
                    586: 	$message_status = '<p>'.&mt('Message sent to user: [_1]',
                    587: 				    $message_status).' </p>';
                    588:     }
                    589:     if ($setting eq 'student_and_user_notes_screen') {
                    590: 	$comment_status = 
                    591: 	    &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
                    592: 						      $msg,$user,$domain);
                    593: 	$comment_status = '<p>'.&mt('Message sent to instructor: [_1]',
                    594: 				    $comment_status).' </p>';
                    595:     }
1.255   ! raeburn   596:  
1.239     bisitz    597:     return "<h2>$title</h2>"
1.255   ! raeburn   598:           .$shown
        !           599:           .$message_status
        !           600:           .$comment_status;
1.166     albertel  601: }
                    602: 
1.1       albertel  603: sub start_Task {
1.87      albertel  604:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1       albertel  605: 
1.4       albertel  606:     my ($status,$accessmsg,$slot);
1.179     albertel  607:     &Apache::structuretags::init_problem_globals('Task');
1.16      albertel  608:     if ($target ne 'webgrade') {
                    609: 	&Apache::structuretags::initialize_storage();
                    610: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.74      albertel  611: 	if ($env{'request.state'} eq 'construct') {
                    612: 	    &Apache::structuretags::setup_rndseed($safeeval);
                    613: 	}
1.16      albertel  614:     } 
                    615: 
1.4       albertel  616:     $Apache::lonhomework::parsing_a_task=1;
1.141     albertel  617: 
                    618:     my $name;
                    619:     if ($target eq 'web' || $target eq 'webgrade') {
                    620: 	$name = &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    621:     }
                    622: 
1.145     albertel  623:     my ($result,$form_tag_start);
                    624:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
                    625: 	|| $target eq 'edit') {
                    626: 	($result,$form_tag_start) =
                    627: 	    &Apache::structuretags::page_start($target,$token,$tagstack,
                    628: 					       $parstack,$parser,$safeeval,
1.146     albertel  629: 					       $name,&style($target));
1.145     albertel  630:     }
1.123     albertel  631: 
1.74      albertel  632:     if ($target eq 'web' && $env{'request.state'} ne 'construct') {
1.147     albertel  633: 	if ($Apache::lonhomework::queuegrade
                    634: 	    || $Apache::lonhomework::modifygrades) {
1.141     albertel  635: 	    $result.='<form name="gradesubmission" method="post" action="';
1.13      albertel  636: 	    my $uri=$env{'request.uri'};
                    637: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
1.200     albertel  638: 	    $result.=$uri.'">'.&add_grading_button()."</form>\n";
1.38      albertel  639: 	    my $symb=&Apache::lonnet::symbread();
1.235     albertel  640: 	    if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})
                    641: 		|| &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
1.141     albertel  642: 		$result.='<form method="post" name="slotrequest" action="/adm/slotrequest">'.
1.40      albertel  643: 		    '<input type="hidden" name="symb" value="'.$symb.'" />'.
                    644: 		    '<input type="hidden" name="command" value="showslots" />'.
                    645: 		    '<input type="submit" name="requestattempt" value="'.
                    646: 		    &mt('Show Slot list').'" />'.
                    647: 		    '</form>';
1.108     albertel  648: 		my $target_id = 
                    649: 		    &Apache::lonstathelpers::make_target_id({symb => $symb,
                    650: 							     part => '0'});
1.238     albertel  651: 		if (!&section_restricted()) {
1.237     albertel  652: 		    $result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
                    653: 			'<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
                    654: 			'<input type="hidden" name="reportSelected" value="grading_analysis" />'.
                    655: 			'<input type="submit" name="grading" value="'.
                    656: 			&mt('Show Grading Status').'" />'.
                    657: 			'</form>';
                    658: 		}
1.40      albertel  659: 	    }
1.13      albertel  660: 	}
1.8       albertel  661:     }
1.231     albertel  662:     if ($target =~/(web|webgrade)/ && $env{'request.state'} eq 'construct') {
1.74      albertel  663: 	$form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
                    664:     }
1.163     albertel  665:     if ($target eq 'web' 
                    666: 	|| ($target eq 'grade' && !$env{'form.webgrade'}) 
                    667: 	|| $target eq 'answer' 
                    668: 	|| $target eq 'tex') {
1.29      albertel  669: 	my ($version,$previous)=&get_version();
1.14      albertel  670: 	($status,$accessmsg,my $slot_name,$slot) = 
1.81      albertel  671: 	    &Apache::lonhomework::check_slot_access('0','Task');
1.152     albertel  672: 	if ($status eq 'CAN_ANSWER' && $version eq '') {
1.177     albertel  673: 	    # CAN_ANSWER mode, and no current version, unproctored access
1.174     albertel  674: 	    # thus self-checkedin
1.246     raeburn   675: 	    my $check = &check_in('Task',undef,undef,$slot_name);
                    676:             if ($check =~ /^error: /) {
                    677:                 my $symb=&Apache::lonnet::symbread();
                    678:                 &Apache::lonnet::logthis("Error during self-checkin of version $version of Task (symb: $symb) using slot: $slot_name");   
                    679:             }
1.152     albertel  680: 	    &add_to_queue('gradingqueue',{'type' => 'Task',
                    681: 					  'time' => time,
                    682: 					  'slot' => $slot_name});
1.150     albertel  683: 	    ($version,$previous)=&get_version();
                    684: 	}
1.218     albertel  685: 	
                    686: 	my $status_id = 
                    687: 	    ($previous || $status eq 'SHOW_ANSWER') ? 'LC_task_feedback'
                    688: 	                                            : 'LC_task_take';
                    689: 	$result .= '<div class="LC_task" id="'.$status_id.'">'."\n";
1.150     albertel  690: 
1.9       albertel  691: 	push(@Apache::inputtags::status,$status);
1.14      albertel  692: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  693: 	my $expression='$external::datestatus="'.$status.'";';
1.89      albertel  694: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
1.1       albertel  695: 	&Apache::run::run($expression,$safeeval);
                    696: 	&Apache::lonxml::debug("Got $status");
1.141     albertel  697: 	$result.=&add_previous_version_button($status);
1.54      albertel  698: 	if (!&show_task($status,$previous)) {
1.87      albertel  699: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.1       albertel  700: 	    if ( $target eq "web" ) {
1.74      albertel  701: 		if ($env{'request.state'} eq 'construct') {
                    702: 		    $result.=$form_tag_start;
                    703: 		}
1.4       albertel  704: 		my $msg;
1.1       albertel  705: 		if ($status eq 'UNAVAILABLE') {
                    706: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  707: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    708: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.247     raeburn   709: 		    $msg.=&add_request_another_attempt_button("Sign up for time to work");
1.4       albertel  710: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    711: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    712: 			'</h1>'.&proctor_validation_screen($slot);
1.22      albertel  713: 		} elsif ($status eq 'WAITING_FOR_GRADE') {
                    714: 		    $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.64      albertel  715: 		} elsif ($env{'form.donescreen'}) {
1.167     albertel  716: 		    $result .= &done_screen($version);
1.1       albertel  717: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    718: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    719: 		}
                    720: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    721: 		    $msg.='The problem '.$accessmsg;
                    722: 		}
                    723: 		$result.=$msg.'<br />';
                    724: 	    } elsif ($target eq 'tex') {
1.248     foxr      725: 		$result.='\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
1.1       albertel  726: 		if ($status eq 'UNAVAILABLE') {
                    727: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    728: 		} else {
                    729: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    730: 		}
1.22      albertel  731: 	    } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4       albertel  732: 		if ($status eq 'NEEDS_CHECKIN') {
1.83      albertel  733: 		    if(&proctor_check_auth($slot_name,$slot,'Task')
                    734: 		       && defined($Apache::inputtags::slot_name)) {
1.148     albertel  735: 			my $result=
                    736: 			    &add_to_queue('gradingqueue',
1.152     albertel  737: 					  {'type' => 'Task',
1.148     albertel  738: 					   'time' => time,
                    739: 					   'slot' => 
                    740: 					       $Apache::inputtags::slot_name});
1.77      albertel  741: 			&Apache::lonxml::debug("add_to_queue said $result");
                    742: 		    }
1.4       albertel  743: 		}
1.1       albertel  744: 	    }
                    745: 	} elsif ($target eq 'web') {
1.141     albertel  746: 
1.57      albertel  747: 	    $result.=&preserve_grade_info();
1.194     albertel  748: 	    $result.=&internal_location(); 
1.200     albertel  749: 	    $result.=$form_tag_start."\t".
1.36      albertel  750: 		'<input type="hidden" name="submitted" value="yes" />';
1.54      albertel  751: 	    &Apache::lonxml::startredirection();
1.1       albertel  752: 	}
1.21      albertel  753:     } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                    754: 	      $target eq 'webgrade') {
1.32      albertel  755: 	my $webgrade='yes';
1.21      albertel  756: 	if ($target eq 'webgrade') {
1.218     albertel  757: 	    $result .= '<div class="LC_task">'."\n";
1.141     albertel  758: 	    $result.= "\n".'<div class="LC_GRADING_task">'."\n".
1.124     albertel  759: 		'<script type="text/javascript" 
1.126     albertel  760:                          src="/res/adm/includes/task_grading.js"></script>';
1.49      albertel  761: 	    #$result.='<br />Review'.&show_queue('reviewqueue');
                    762: 	    #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30      albertel  763: 	}
1.194     albertel  764: 
1.105     albertel  765: 	my ($todo,$status_code,$msg)=&get_key_todo($target);
1.33      albertel  766: 
                    767: 	if ($todo) {
                    768: 	    &setup_env_for_other_user($todo,$safeeval);
                    769: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
1.231     albertel  770: 	    if ($env{'request.state'} eq 'construct') {
                    771: 		$symb = $env{'request.uri'};
                    772: 	    }
                    773: 	    $result.="\n".'<p>'.
                    774: 		&mt('Grading [_1] for [_2] at [_3]',
                    775: 		    &Apache::lonnet::gettitle($symb),$uname,$udom).'</p>';
1.33      albertel  776: 	    $form_tag_start.=
                    777: 		'<input type="hidden" name="gradingkey" value="'.
1.158     www       778: 		&escape($todo).'" />';
1.33      albertel  779: 	    $Apache::bridgetask::queue_key=$todo;
                    780: 	    &Apache::structuretags::initialize_storage();
                    781: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.110     albertel  782: 	    if ($target eq 'webgrade' && $status_code eq 'selected') {
                    783: 		$form_tag_start.=
                    784: 		    '<input type="hidden" name="queuemode" value="selected" />';
1.33      albertel  785: 	    }
1.15      albertel  786: 	} else {
1.33      albertel  787: 	    if ($target eq 'webgrade') {
                    788: 		$result.="\n";
1.81      albertel  789: 		my $back='<p><a href="/adm/flip?postdata=return:">'.
                    790: 		    &mt('Return to resource').'</a></p>';
1.33      albertel  791: 		if      ($status_code eq 'stop') {
1.81      albertel  792: 		    $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
1.163     albertel  793: 		} elsif ($status_code eq 'cancel') {
                    794: 		    $result.='<b>'.&mt("Cancelled grading.").'</b>'.$back;
1.254     raeburn   795:                 } elsif ($status_code eq 'terminated') {
                    796:                     $result.= '<b>'.&mt('Terminated grading').'</b><br />'.
                    797:                               '<span class="LC_error">'.
                    798:                               &mt('Grading for [_1] has not been saved because of a grading key mismatch.',
                    799:                               '<tt>'.$env{'form.terminated'}.'</tt>').'</span><br />'.$back;
1.164     albertel  800: 		} elsif ($status_code eq 'never_versioned') {
                    801: 		    $result.='<b>'.
                    802: 			&mt("Requested user has never accessed the task.").
                    803: 			'</b>'.$back;
1.165     albertel  804: 		} elsif ($status_code =~ /still_open:(.*)/) {
                    805: 		    my $date = &Apache::lonlocal::locallocaltime($1);
                    806: 		    $result.='<b>'.
                    807: 			&mt("Task is still open, will close at [_1].",$date).
                    808: 			'</b>'.$back;
1.33      albertel  809: 		} elsif ($status_code eq 'lock_failed') {
1.105     albertel  810: 		    $result.='<b>'.&mt("Failed to lock the requested record.")
1.81      albertel  811: 			.'</b>'.$back;
1.33      albertel  812: 		} elsif ($status_code eq 'unlock') {
1.81      albertel  813: 		    $result.='<b>'.&mt("Unlocked the requested record.")
                    814: 			.'</b>'.$back;
1.33      albertel  815: 		    $result.=&show_queue($env{'form.queue'},1);
                    816: 		} elsif ($status_code eq 'show_list') {
                    817: 		    $result.=&show_queue($env{'form.queue'},1);
1.49      albertel  818: 		} elsif ($status_code eq 'select_user') {
                    819: 		    $result.=&select_user();
1.95      albertel  820: 		} elsif ($status_code eq 'unable') {
                    821: 		    $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
1.105     albertel  822: 		} elsif ($status_code eq 'not_allowed') {
                    823: 		    $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
1.33      albertel  824: 		} else {
1.81      albertel  825: 		    $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
1.32      albertel  826: 		}
1.21      albertel  827: 	    }
1.33      albertel  828: 	    $webgrade='no';
1.163     albertel  829: 	}
                    830: 	if (!$todo || $env{'form.cancel'}) {
1.87      albertel  831: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.32      albertel  832: 	}
                    833: 	if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.61      albertel  834: 	    if ($webgrade eq 'yes') {
                    835: 		$result.=&submission_time_stamp();
                    836: 	    }
1.32      albertel  837: 	    $result.=$form_tag_start;
                    838: 	    $result.='<input type="hidden" name="webgrade" value="'.
                    839: 		$webgrade.'" />';
                    840: 	    $result.='<input type="hidden" name="queue" value="'.
                    841: 		$env{'form.queue'}.'" />';
1.52      albertel  842: 	    if ($env{'form.regrade'}) {
                    843: 		$result.='<input type="hidden" name="regrade" value="'.
                    844: 		    $env{'form.regrade'}.'" />';
                    845: 	    }
1.237     albertel  846: 	    if ($env{'form.chosensections'} || &section_restricted()) {
                    847: 		my @chosen_sections = &get_allowed_sections();
1.62      albertel  848: 		foreach my $sec (@chosen_sections) {
                    849: 		    $result.='<input type="hidden" name="chosensections" 
                    850:                                value="'.$sec.'" />';
                    851: 		}
                    852: 	    }
1.70      albertel  853: 	    if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
1.231     albertel  854: 	} elsif ($target eq 'webgrade' 
                    855: 		 && $env{'request.state'} eq 'construct') {
                    856: 	    $result.=$form_tag_start;
                    857: 	    $result.='<input type="hidden" name="webgrade" value="'.
                    858: 		$webgrade.'" />';
                    859: 	    $result.=&webgrade_standard_info();
1.15      albertel  860: 	}
1.110     albertel  861: 	if ($target eq 'webgrade') {
1.120     albertel  862: 	    $result.="\n".'<div id="LC_GRADING_criterialist">';
1.194     albertel  863: 	    &Apache::lonxml::startredirection();
1.208     albertel  864: 	    &start_delay();
                    865: 	    $dimension{$top}{'result'}=$result;
                    866: 	    undef($result);
1.110     albertel  867: 	}
1.74      albertel  868:     } elsif ($target eq 'edit') {
1.141     albertel  869: 	$result.=$form_tag_start.
1.74      albertel  870: 	    &Apache::structuretags::problem_edit_header();
                    871: 	$Apache::lonxml::warnings_error_header=
                    872: 	    &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 />";
1.225     albertel  873: 	$result.= &Apache::edit::text_arg('Required number of passed optional elements to pass the Task:','OptionalRequired',$token,10)." <br />\n";
                    874: 	$result.= &Apache::edit::insertlist($target,$token);
                    875:     } elsif ($target eq 'modified') {
                    876: 	my $constructtag=
                    877: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
                    878: 					'OptionalRequired');
                    879: 	if ($constructtag) {
                    880: 	    $result = &Apache::edit::rebuild_tag($token);
                    881: 	}
1.1       albertel  882:     } else {
                    883: 	# page_start returned a starting result, delete it if we don't need it
                    884: 	$result = '';
                    885:     }
                    886:     return $result;
                    887: }
                    888: 
1.165     albertel  889: sub get_task_end_time {
                    890:     my ($queue_entry,$symb,$udom,$uname) = @_;
                    891: 
                    892:     my $end_time;
                    893:     if (my $slot = &slotted_access($queue_entry)) {
                    894: 	my %slot_data=&Apache::lonnet::get_slot($slot);
                    895: 	$end_time = $slot_data{'endtime'};
                    896:     } else {
                    897: 	$end_time = &Apache::lonhomework::due_date('0',$symb,
                    898: 						   $udom,$uname);
                    899:     }
                    900:     return $end_time;
                    901: }
                    902: 
1.32      albertel  903: sub get_key_todo {
                    904:     my ($target)=@_;
                    905:     my $todo;
1.33      albertel  906: 
1.231     albertel  907:     if ($env{'request.state'} eq 'construct') {
                    908: 	my ($symb,$cid,$udom,$uname) = &Apache::lonnet::whichuser();
                    909: 	my $gradingkey=&encode_queue_key($symb,$udom,$uname);
                    910: 	return ($gradingkey);
                    911:     }
                    912: 
1.33      albertel  913:     if (defined($env{'form.reviewasubmission'})) {
1.54      albertel  914: 	&Apache::lonxml::debug("review a submission....");
1.33      albertel  915: 	$env{'form.queue'}='reviewqueue';
                    916: 	return (undef,'show_list');
                    917:     }
                    918: 
                    919:     if (defined($env{'form.reviewagrading'})) {
                    920: 	&Apache::lonxml::debug("review a grading....");
                    921: 	$env{'form.queue'}='gradingqueue';
                    922: 	return (undef,'show_list');
                    923:     }
                    924: 
1.49      albertel  925:     if (defined($env{'form.regradeasubmission'})) {
                    926: 	&Apache::lonxml::debug("regrade a grading....");
                    927: 	$env{'form.queue'}='none';
                    928: 	return (undef,'select_user');
                    929:     }
                    930: 
1.105     albertel  931: 
1.138     albertel  932:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.105     albertel  933: 
                    934:     #need to try both queues..
                    935:     if (defined($env{'form.regradeaspecificsubmission'}) &&
                    936: 	defined($env{'form.gradinguser'})               &&
                    937: 	defined($env{'form.gradingdomain'})               ) {
1.185     albertel  938: 	my ($symb,$cid)=&Apache::lonnet::whichuser();
1.105     albertel  939: 	my $cnum  = $env{'course.'.$cid.'.num'};
                    940: 	my $cdom  = $env{'course.'.$cid.'.domain'};
1.224     albertel  941: 	my $uname = &LONCAPA::clean_username($env{'form.gradinguser'});
                    942: 	my $udom  = &LONCAPA::clean_domain($env{'form.gradingdomain'});
1.237     albertel  943: 	
                    944: 	if (&section_restricted()) {
                    945: 	    my $classlist=&get_limited_classlist();
                    946: 	    if (!&allow_grade_user($classlist->{$uname.':'.$udom})) {
                    947: 		return (undef,'not_allowed',
                    948: 			&mt('Requested student ([_1]) is in a section you aren\'t allowed to grade.',$uname.':'.$udom));
                    949: 	    }
                    950: 	}
1.105     albertel  951: 	my $gradingkey=&encode_queue_key($symb,$udom,$uname);
                    952: 
                    953: 	my $queue;
                    954: 
                    955: 	if      (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
                    956: 	    $env{'form.queue'} = $queue = 'gradingqueue';
                    957: 	} elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
                    958: 	    $env{'form.queue'} = $queue = 'reviewqueue';
                    959: 	}
                    960: 	
                    961: 	if (!$queue) {
                    962: 	    $env{'form.queue'} = $queue = 'none';
                    963: 	    #not queued so doing either a re or pre grade
1.164     albertel  964: 	    my %status = &Apache::lonnet::restore($symb,$cid,$udom,$uname);
                    965: 	    if ($status{'resource.0.version'} < 1) {
                    966: 		return (undef,'never_versioned');
                    967: 	    }
1.105     albertel  968: 	    return ($gradingkey);
                    969: 	}
                    970: 
1.165     albertel  971: 	if ($queue) {
                    972: 	    my $queue_entry = &get_queue_data($queue,$udom,$uname);
                    973: 	
                    974: 	    my $end_time = &get_task_end_time($queue_entry,$symb,
                    975: 					      $udom,$uname);
                    976: 	    if ($end_time > time) {
                    977: 		return (undef,"still_open:$end_time");
                    978: 	    }
                    979: 	}
                    980: 
1.105     albertel  981: 	my $who=&queue_key_locked($queue,$gradingkey);
                    982: 	if ($who eq $me) {
                    983: 	    #already have the lock
1.158     www       984: 	    $env{'form.gradingkey'}=&escape($gradingkey);
1.163     albertel  985: 	    &Apache::lonxml::debug("already locked");
1.105     albertel  986: 	    return ($gradingkey);
                    987: 	}
                    988: 	
                    989: 	if (!defined($who)) {
                    990: 	    if (&lock_key($queue,$gradingkey)) {
1.163     albertel  991: 		&Apache::lonxml::debug("newly locked");
1.105     albertel  992: 		return ($gradingkey);
                    993: 	    } else {
                    994: 		return (undef,'lock_failed');
                    995: 	    }
                    996: 	}
                    997: 
                    998: 	#otherwise (defined($who) && $who ne $me) some else has it...
                    999: 	return (undef,'not_allowed',
                   1000: 		&mt('Another user ([_1]) currently has the record for [_2] locked.',
1.138     albertel 1001: 		    $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
1.105     albertel 1002:     }
                   1003: 
                   1004: 
1.32      albertel 1005:     my $queue=$env{'form.queue'};
1.33      albertel 1006: 
1.32      albertel 1007:     if (!defined($queue)) {
                   1008: 	$env{'form.queue'}=$queue='gradingqueue';
                   1009:     }
1.33      albertel 1010: 
1.158     www      1011:     my $gradingkey=&unescape($env{'form.gradingkey'});
1.33      albertel 1012: 
1.49      albertel 1013:     if ($env{'form.queue'} eq 'none') {
                   1014: 	if (defined($env{'form.gradingkey'})) {
                   1015: 	    if ($target eq 'webgrade') {
                   1016: 		if ($env{'form.stop'}) {
                   1017: 		    return (undef,'stop');
1.163     albertel 1018: 		} elsif ($env{'form.cancel'}) {
                   1019: 		    return (undef,'cancel');
1.254     raeburn  1020:                 } elsif ($env{'form.terminated'}) {
                   1021:                     return (undef, 'terminated');
1.49      albertel 1022: 		} elsif ($env{'form.next'}) {
1.59      albertel 1023: 		    return (undef,'select_user');
1.49      albertel 1024: 		}
                   1025: 	    }
                   1026: 	    return ($gradingkey,'selected');
                   1027: 	} else {
1.59      albertel 1028: 	    return (undef,'select_user');
1.49      albertel 1029: 	}
                   1030:     }
1.32      albertel 1031:     if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33      albertel 1032: 	&& !defined($env{'form.gradingaction'}) 
                   1033: 	&& $env{'form.queuemode'} eq 'selected') {
                   1034: 	
                   1035: 	my $who=&queue_key_locked($queue,$gradingkey);
                   1036: 	if ($who eq $me) {
                   1037: 	    &Apache::lonxml::debug("Found a key was given to me");
                   1038: 	    return ($gradingkey,'selected');
                   1039: 	} else {
                   1040: 	    return (undef,'show_list');
                   1041: 	}
                   1042: 
                   1043:     }
                   1044: 
                   1045:     if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
                   1046: 	if ($env{'form.gradingaction'} eq 'resume') {
                   1047: 	    delete($env{'form.gradingaction'});
                   1048: 	    &Apache::lonxml::debug("Resuming a key");
1.32      albertel 1049: 	    return ($gradingkey);
1.33      albertel 1050: 	} elsif ($env{'form.gradingaction'} eq 'unlock') {
                   1051: 	    &Apache::lonxml::debug("Unlocking a key ".
                   1052: 				     &check_queue_unlock($queue,$gradingkey,1));
                   1053: 	    return (undef,'unlock');
                   1054: 	} elsif ($env{'form.gradingaction'} eq 'select') {
                   1055: 	    &Apache::lonxml::debug("Locking a key");
                   1056: 	    if (&lock_key($queue,$gradingkey)) {
                   1057: 		&Apache::lonxml::debug("Success $queue");
                   1058: 		return ($gradingkey);
                   1059: 	    }
                   1060: 	    &Apache::lonxml::debug("Failed $queue");
                   1061: 	    return (undef,'lock_failed');
1.32      albertel 1062: 	}
                   1063:     }
1.33      albertel 1064: 
                   1065:     if ($env{'form.queuemode'} ne 'selected') {
                   1066: 	# don't get something new from the queue if they hit the stop button
1.254     raeburn  1067:     	if (!(($env{'form.cancel'} || $env{'form.stop'} || $env{'form.terminated'}) 
1.163     albertel 1068: 	      && $target eq 'webgrade') 
1.33      albertel 1069: 	    && !$env{'form.gradingaction'}) {
                   1070: 	    &Apache::lonxml::debug("Getting anew $queue");
                   1071: 	    return (&get_from_queue($queue));
                   1072: 	} else {
1.254     raeburn  1073:             if ($env{'form.terminated'}) {
                   1074:                 return (undef,'terminated');
                   1075:             } else {
                   1076:                 return (undef,'stop');
                   1077:             }
1.33      albertel 1078: 	}
1.32      albertel 1079:     }
1.33      albertel 1080:     return (undef,undef)
1.32      albertel 1081: }
1.94      albertel 1082: 
                   1083: sub minimize_storage {
                   1084:     foreach my $key (keys(%Apache::lonhomework::results)) {
                   1085: 	if ($key =~ /regrader$/) { next; }
                   1086: 	if ($Apache::lonhomework::results{$key} eq
                   1087: 	    $Apache::lonhomework::history{$key}) {
                   1088: 	    delete($Apache::lonhomework::results{$key});
                   1089: 	}
                   1090:     }
                   1091: }
                   1092: 
1.1       albertel 1093: sub end_Task {
                   1094:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1095:     my $result='';
                   1096:     my $status=$Apache::inputtags::status['-1'];
1.29      albertel 1097:     my ($version,$previous)=&get_version();
1.1       albertel 1098:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel 1099: 	$target eq 'tex') {
1.69      albertel 1100: 	if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.1       albertel 1101: 	    if ($target eq 'web') {
1.54      albertel 1102: 		if (&show_task($status,$previous)) {
                   1103: 		    $result.=&Apache::lonxml::endredirection();
                   1104: 		}
1.64      albertel 1105: 		if ($status eq 'CAN_ANSWER' && !$previous && 
                   1106: 		    !$env{'form.donescreen'}) {
1.252     raeburn  1107:                     my ($portheader,$porttext);
                   1108:                     if ($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"}) {
                   1109:                         $portheader = &mt('Submit Additional Portfolio Files for Grading');
                   1110:                         $porttext = &mt('Indicate which additional files from your portfolio are to be evaluated in grading this task.');
                   1111:                     } else {
                   1112:                         $portheader = &mt('Submit Portfolio Files for Grading');
                   1113:                         $porttext = &mt('Indicate the files from your portfolio to be evaluated in grading this task.');
                   1114:                     }
                   1115: 		    $result.="\n".'<p>'.&Apache::lonhtmlcommon::start_pick_box().
1.28      albertel 1116: 			&Apache::inputtags::file_selector("$version.0",
                   1117: 							  "bridgetask","*",
1.46      albertel 1118: 							  'portfolioonly',
1.252     raeburn  1119:                                                           '<h3>'.$portheader.'</h3><br />'.
                   1120:                                                           $porttext.'<br />').
                   1121: 			&Apache::lonhtmlcommon::end_pick_box().'</p>';
1.77      albertel 1122: 		}
1.78      albertel 1123: 		if (!$previous && $status ne 'SHOW_ANSWER' &&
                   1124: 		    &show_task($status,$previous)) {
1.232     albertel 1125: 		    $result.=&Apache::inputtags::gradestatus('0',$target,1);
1.199     albertel 1126: 		}
                   1127: 		
                   1128: 		$result.='</form>';
                   1129: 
                   1130: 		if (!$previous && $status ne 'SHOW_ANSWER' &&
                   1131: 		    &show_task($status,$previous)) {
1.116     albertel 1132: 		    my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.241     raeburn  1133:                     my $donetext = &mt('Done');
1.64      albertel 1134: 		    $result.=<<DONEBUTTON;
1.115     albertel 1135: <form name="done" method="post" action="$action">
1.64      albertel 1136:    <input type="hidden" name="donescreen" value="1" />
1.241     raeburn  1137:    <input type="submit" value="$donetext" />
1.64      albertel 1138: </form>
                   1139: DONEBUTTON
1.77      albertel 1140:                 }
1.56      albertel 1141: 		if (&show_task($status,$previous) &&
1.89      albertel 1142: 		    $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
                   1143: 		    my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1.231     albertel 1144: 		    my $title=&Apache::lonnet::gettitle($env{'request.uri'});
1.149     albertel 1145: 		    my $start_time;
                   1146: 
1.80      albertel 1147: 		    my $slot_name=
1.89      albertel 1148: 			$Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1.149     albertel 1149: 		    if ($slot_name) {
                   1150: 			my %slot=&Apache::lonnet::get_slot($slot_name);
                   1151: 
                   1152: 			$start_time=$slot{'starttime'}
                   1153: 		    } else {
                   1154: 			$start_time= 
                   1155: 			    &Apache::lonnet::EXT('resource.0.opendate');
                   1156: 		    }
                   1157: 		    $start_time=&Apache::lonlocal::locallocaltime($start_time);
1.54      albertel 1158: 
1.200     albertel 1159: 		    my $status = 
1.213     albertel 1160: 			"\n<div class='LC_$bt_status LC_criteria LC_task_overall_status'>\n\t";
1.54      albertel 1161: 		    
1.213     albertel 1162: 		    my $dim = $top;
                   1163: 		    my %counts = &get_counts($dim,undef,$parstack,
                   1164: 					     $safeeval);
                   1165: 		    my $question_status ="\n\t<p>".
                   1166: 			&question_status_message(\%counts,-1).
                   1167: 			"</p>\n";
                   1168: 
1.54      albertel 1169: 		    if ($bt_status eq 'pass')  {
1.239     bisitz   1170: 			$status.='<h2>'
                   1171:                                 .&mt('You passed the [_1] given on [_2].',$title,$start_time)
                   1172:                                 .'</h2>';
1.213     albertel 1173: 			$status.=$question_status;
1.54      albertel 1174: 		    }
                   1175: 		    if ($bt_status eq 'fail')  {
1.239     bisitz   1176: 			$status.='<h2>'
                   1177:                                 .&mt('You did not pass the [_1] given on [_2].',$title,$start_time)
                   1178:                                 .'</h2>';
1.213     albertel 1179: 			$status.=$question_status;
1.54      albertel 1180: 			if (!$previous) {
                   1181: 			    $status.=&add_request_another_attempt_button();
                   1182: 			}
                   1183: 		    }
1.213     albertel 1184: 		    
1.200     albertel 1185: 		    $status.="\n".'</div>'."\n";
1.194     albertel 1186: 
                   1187: 		    foreach my $id (@{$dimension{$dim}{'criterias'}}) {
                   1188: 			my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   1189: 			if ($type eq 'dimension') {
                   1190: 			    $result.=$dimension{$id}{'result'};
                   1191: 			    next;
                   1192: 			}
                   1193: 			my $criteria = 
                   1194: 			    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   1195: 					  [@_]);
                   1196: 			$status .= &layout_web_Criteria($dim,$id,$criteria);
                   1197: 		    }
1.54      albertel 1198: 
                   1199: 		    my $internal_location=&internal_location();
                   1200: 		    $result=~s/\Q$internal_location\E/$status/;
                   1201: 		}
1.142     albertel 1202: 		$result.="\n</div>\n".
                   1203: 		    &Apache::loncommon::end_page({'discussion' => 1});
1.1       albertel 1204: 	    }
                   1205: 	}
1.181     albertel 1206: 
                   1207: 	my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
                   1208: 	my %queue_data = ('type' => 'Task',
                   1209: 			  'time' => time,);
                   1210: 	if (defined($Apache::inputtags::slot_name)) {
                   1211: 	    $queue_data{'slot'} = $Apache::inputtags::slot_name;
                   1212: 	} elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) {
                   1213: 	    $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
                   1214: 	}
                   1215: 	
                   1216: 
1.215     albertel 1217: 	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous
                   1218: 	    && $status eq 'CAN_ANSWER') {
1.12      albertel 1219: 	    my $award='SUBMITTED';
1.252     raeburn  1220:             my $uploadedflag=0;
                   1221:             my $totalsize=0;
                   1222:             my @deletions = &Apache::loncommon::get_env_multiple('form.HWFILE'.$version.'_0_bridgetask_delete');
1.28      albertel 1223: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.252     raeburn  1224: 						    \$award,\$uploadedflag,\$totalsize,\@deletions);
1.14      albertel 1225: 	    if ($award eq 'SUBMITTED' &&
1.28      albertel 1226: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
                   1227: 		$Apache::lonhomework::results{"resource.0.tries"}=
                   1228: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
                   1229: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
                   1230: 
                   1231: 		$Apache::lonhomework::results{"resource.0.award"}=
                   1232: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
                   1233: 		    $award;
1.51      albertel 1234: 		$Apache::lonhomework::results{"resource.0.submission"}=
                   1235: 		    $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64      albertel 1236: 	    } else {
1.252     raeburn  1237:                 unless($uploadedflag) {
                   1238:                     delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
                   1239:                 }
1.77      albertel 1240: 		$award = '';
1.10      albertel 1241: 	    }
1.4       albertel 1242: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                   1243: 	    &Apache::structuretags::finalize_storage();
1.148     albertel 1244: 	    if ($award eq 'SUBMITTED') {
1.181     albertel 1245: 		&add_to_queue('gradingqueue',\%queue_data);
1.14      albertel 1246: 	    }
1.1       albertel 1247: 	}
1.163     albertel 1248: 	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' 
                   1249: 	    && exists($env{'form.cancel'})) {
                   1250: 	    &check_queue_unlock($env{'form.queue'});
                   1251: 	    &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
                   1252: 	} elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' 
                   1253: 		 && !exists($env{'form.cancel'})) {
1.20      albertel 1254: 	    my $optional_required=
                   1255: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                   1256: 					   $safeeval);
                   1257: 	    my $optional_passed=0;
                   1258: 	    my $mandatory_failed=0;
                   1259: 	    my $ungraded=0;
                   1260: 	    my $review=0;   
1.21      albertel 1261: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.194     albertel 1262: 	    my $dim = $top;
                   1263: 	    foreach my $id (@{$dimension{$dim}{'criterias'}}) {
                   1264: 		my $link=&link($id);
                   1265: 
                   1266: 		my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   1267: 
                   1268: 		if ($type eq 'criteria') {
                   1269: 		    # dimensional 'criteria' don't get assigned grades
                   1270: 		    $Apache::lonhomework::results{"resource.$version.0.$id.status"}=$env{'form.HWVAL_'.$link};
                   1271: 		    $Apache::lonhomework::results{"resource.$version.0.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
                   1272: 		} 
1.20      albertel 1273: 		my $status=
1.194     albertel 1274: 		    $Apache::lonhomework::results{"resource.$version.0.$id.status"};
                   1275: 		my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
                   1276: 
1.20      albertel 1277: 		if ($status eq 'pass') {
                   1278: 		    if (!$mandatory) { $optional_passed++; }
                   1279: 		} elsif ($status eq 'fail') {
                   1280: 		    if ($mandatory) { $mandatory_failed++; }
1.194     albertel 1281: 		} elsif ($status eq 'review') {
                   1282: 		    $review++;
1.20      albertel 1283: 		} elsif ($status eq 'ungraded') {
                   1284: 		    $ungraded++;
1.49      albertel 1285: 		} else {
                   1286: 		    $ungraded++;
                   1287: 		}
1.20      albertel 1288: 	    }
                   1289: 	    if ($optional_passed < $optional_required) {
                   1290: 		$mandatory_failed++;
                   1291: 	    }
1.194     albertel 1292: 	    &Apache::lonxml::debug(" task results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.89      albertel 1293: 	    $Apache::lonhomework::results{'resource.0.regrader'}=
1.138     albertel 1294: 		$env{'user.name'}.':'.$env{'user.domain'};
1.20      albertel 1295: 	    if ($review) {
1.89      albertel 1296: 		$Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.20      albertel 1297: 	    } elsif ($ungraded) {
1.89      albertel 1298: 		$Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.20      albertel 1299: 	    } elsif ($mandatory_failed) {
1.89      albertel 1300: 		$Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25      albertel 1301: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                   1302: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                   1303: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.185     albertel 1304: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52      albertel 1305: 		
                   1306: 		if ($env{'form.regrade'} ne 'yes') {
                   1307: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                   1308: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                   1309: 		    &Apache::grades::version_portfiles(
                   1310: 						       \%Apache::lonhomework::results,
                   1311: 						       ["$version.0.bridgetask"],$courseid,
                   1312: 						       $symb,$udom,$uname,
                   1313: 						       ["$version.0.bridgetask"]);
                   1314: 		}
1.20      albertel 1315: 	    } else {
1.89      albertel 1316: 		$Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25      albertel 1317: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                   1318: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                   1319: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.185     albertel 1320: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52      albertel 1321: 		if ($env{'form.regrade'} ne 'yes') {
                   1322: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                   1323: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                   1324: 		    &Apache::grades::version_portfiles(
                   1325: 						       \%Apache::lonhomework::results,
                   1326: 						       ["$version.0.bridgetask"],$courseid,
                   1327: 						       $symb,$udom,$uname,
                   1328: 						       ["$version.0.bridgetask"]);
                   1329: 		}
1.20      albertel 1330: 	    }
1.89      albertel 1331: 	    $Apache::lonhomework::results{"resource.0.status"}=
                   1332: 		$Apache::lonhomework::results{"resource.$version.0.status"};
1.28      albertel 1333: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel 1334: 		$Apache::lonhomework::results{"resource.0.award"}=
1.50      albertel 1335: 		    $Apache::lonhomework::results{"resource.$version.0.award"};
1.26      albertel 1336: 		$Apache::lonhomework::results{"resource.0.awarded"}=
1.50      albertel 1337: 		    $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26      albertel 1338: 		$Apache::lonhomework::results{"resource.0.solved"}=
1.50      albertel 1339: 		    $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25      albertel 1340: 	    }
1.94      albertel 1341: 	    &minimize_storage();
1.254     raeburn  1342:             my ($canstore,$domain,$name);
1.250     raeburn  1343:             if ($env{'form.gradingkey'}) {
1.254     raeburn  1344:                 (my $symb,my $courseid,$domain,$name) =
1.250     raeburn  1345:                     &Apache::lonnet::whichuser();
                   1346:                 my $todo=&unescape($env{'form.gradingkey'});
                   1347:                 my ($keysymb,$uname,$udom)=&decode_queue_key($todo);
                   1348:                 if ($symb eq $keysymb) {
                   1349:                     if (($domain eq $udom) && ($name eq $uname)) {
                   1350:                         $canstore = 1;           
                   1351:                     }
                   1352:                 }
                   1353:             }
                   1354:             if ($canstore) {
                   1355: 	        &Apache::structuretags::finalize_storage();
1.253     raeburn  1356: 	        # data stored, now handle queue
                   1357: 	        if ($review) {
                   1358: 		    if ($env{'form.queue'} eq 'reviewqueue') {
                   1359: 		        &check_queue_unlock($env{'form.queue'});
                   1360: 		        &Apache::lonxml::debug(" still needs review not changing status.");
                   1361: 		    } else {
                   1362: 		        if ($env{'form.queue'} ne 'none') {
                   1363: 			    &move_between_queues($env{'form.queue'},'reviewqueue');
                   1364: 		        } else {
                   1365: 			    &add_to_queue('reviewqueue',\%queue_data);
                   1366: 		        }
                   1367: 		    }
                   1368: 	        } elsif ($ungraded) {
                   1369: 		    if ($env{'form.queue'} eq 'reviewqueue') {
                   1370: 		        &Apache::lonxml::debug("moving back.");
                   1371: 		        &move_between_queues($env{'form.queue'},
                   1372: 					     'gradingqueue');
                   1373: 		    } elsif ($env{'form.queue'} eq 'none' ) {
                   1374: 		        &add_to_queue('gradingqueue',\%queue_data);	
                   1375: 		    } else {
                   1376: 		        &check_queue_unlock($env{'form.queue'});
                   1377: 		    }
                   1378: 	        } elsif ($mandatory_failed) {
                   1379: 		    &remove_from_queue($env{'form.queue'}); 
                   1380: 	        } else {
                   1381: 		    &remove_from_queue($env{'form.queue'});
                   1382: 	        }
1.250     raeburn  1383:             } else {
1.253     raeburn  1384:                 &check_queue_unlock($env{'form.queue'});
1.254     raeburn  1385:                 $env{'form.terminated'} = $name.':'.$domain;
1.250     raeburn  1386:             }
1.253     raeburn  1387:         }
1.184     albertel 1388: 	if (exists($Apache::lonhomework::results{'INTERNAL_store'})) {
1.240     bisitz   1389: 	    # instance generation occurred and hasn't yet been stored
1.184     albertel 1390: 	    &Apache::structuretags::finalize_storage();
                   1391: 	}
1.15      albertel 1392:     } elsif ($target eq 'webgrade') {
1.208     albertel 1393: 	if (&nest()) {
                   1394: 	    &Apache::lonxml::endredirection();
                   1395: 	    &end_delay();
                   1396: 	    $result.=$dimension{$top}{'result'};
                   1397: 	} else {
                   1398: 	    $result.=&Apache::lonxml::endredirection();
                   1399: 	}
1.194     albertel 1400: 	my $dim = $top;
                   1401: 	foreach my $id (@{$dimension{$dim}{'criterias'}} ) {
                   1402: 	    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   1403: 	    if ($type eq 'dimension') {
                   1404: 		# dimensional 'criteria' don't get assigned grades
                   1405: 		next;
                   1406: 	    } else {
                   1407: 		my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   1408: 					     [@_]);
                   1409: 		$criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
                   1410: 		my $internal_location=&internal_location($id);
1.209     albertel 1411: 		if ($result =~ m/\Q$internal_location\E/) {
                   1412: 		    $result=~s/\Q$internal_location\E/$criteria/;
                   1413: 		} else {
                   1414: 		    $result.=$criteria;
                   1415: 		}
                   1416: 
1.194     albertel 1417: 	    }
                   1418: 	}
                   1419:         $result.="</div>";
1.20      albertel 1420: 	#$result.='<input type="submit" name="next" value="'.
                   1421: 	#    &mt('Save &amp; Next').'" /> ';
                   1422: 	#$result.='<input type="submit" name="end" value="'.
                   1423: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                   1424: 	#$result.='<input type="submit" name="throwaway" value="'.
                   1425: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                   1426: 	#$result.='<input type="submit" name="save" value="'.
                   1427: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124     albertel 1428: 	$result.='</form>'."\n</div>\n</div>\n".
1.140     albertel 1429: 	    &Apache::loncommon::end_page();
1.1       albertel 1430:     } elsif ($target eq 'meta') {
1.70      albertel 1431: 	$result.=&Apache::response::meta_package_write('Task');
1.77      albertel 1432:         $result.=&Apache::response::meta_stores_write('solved','string',
                   1433: 						      'Problem Status');
                   1434: 	$result.=&Apache::response::meta_stores_write('tries','int_zeropos',
                   1435: 						      'Number of Attempts');
                   1436: 	$result.=&Apache::response::meta_stores_write('awarded','float',
                   1437: 						      'Partial Credit Factor');
                   1438: 	$result.=&Apache::response::meta_stores_write('status','string',
                   1439: 						      'Bridge Task Status');
1.182     albertel 1440:     } elsif ($target eq 'edit') {
1.227     albertel 1441: 	$result.= &Apache::structuretags::problem_edit_footer();
1.1       albertel 1442:     }
1.179     albertel 1443:     &Apache::structuretags::reset_problem_globals('Task');
1.4       albertel 1444:     undef($Apache::lonhomework::parsing_a_task);
1.250     raeburn  1445:     if ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                   1446:           $target eq 'webgrade') {
                   1447:         delete($env{'form.grade_symb'});
                   1448:         delete($env{'form.grade_domain'});
                   1449:         delete($env{'form.grade_username'});
                   1450:         delete($env{'form.grade_courseid'});
                   1451:     }
1.1       albertel 1452:     return $result;
                   1453: }
                   1454: 
1.31      albertel 1455: sub move_between_queues {
                   1456:     my ($src_queue,$dest_queue)=@_;
1.49      albertel 1457:     my $cur_data;
                   1458:     if ($src_queue ne 'none') {
                   1459: 	$cur_data=&get_queue_data($src_queue);
                   1460: 	if (!$cur_data) { return 'not_exist'; }
                   1461:     } else {
                   1462: 	$cur_data = ['none'];
                   1463:     }
1.148     albertel 1464:     my $result=&add_to_queue($dest_queue,$cur_data);
1.31      albertel 1465:     if ($result ne 'ok') {
                   1466: 	return $result;
                   1467:     }
                   1468:     &check_queue_unlock($src_queue);
                   1469:     return &remove_from_queue($src_queue);
1.21      albertel 1470: }
                   1471: 
                   1472: sub check_queue_unlock {
1.32      albertel 1473:     my ($queue,$key,$allow_not_me)=@_;
1.49      albertel 1474:     if ($queue eq 'none') { return 'ok'; }
1.185     albertel 1475:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.32      albertel 1476:     if (!defined($key)) {
1.138     albertel 1477: 	$key="$symb\0queue\0$uname:$udom";
1.32      albertel 1478:     }
1.30      albertel 1479:     my $cnum=$env{'course.'.$cid.'.num'};
                   1480:     my $cdom=$env{'course.'.$cid.'.domain'};
1.138     albertel 1481:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30      albertel 1482:     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
                   1483:     if  ($who eq $me) {
1.163     albertel 1484: 	&Apache::lonxml::debug("unlocking my own $who");
1.32      albertel 1485: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
                   1486:     } elsif ($allow_not_me) {
1.33      albertel 1487: 	&Apache::lonxml::debug("unlocking $who by $me");
1.32      albertel 1488: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30      albertel 1489:     }
1.32      albertel 1490:     return 'not_owner';
1.21      albertel 1491: }
                   1492: 
1.88      albertel 1493: sub in_queue {
                   1494:     my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
                   1495:     if ($queue eq 'none') { return 0; }
                   1496:     if (!defined($symb) || !defined($cdom) || !defined($cnum)
                   1497: 	|| !defined($udom) || !defined($uname)) {
1.185     albertel 1498: 	($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.88      albertel 1499: 	$cnum=$env{'course.'.$cid.'.num'};
                   1500: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1501:     }
                   1502: 
                   1503:     my $key=&encode_queue_key($symb,$udom,$uname);
                   1504:     my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
                   1505: 
                   1506:     if (defined($results{$key})) {
                   1507: 	return 1;
                   1508:     }
                   1509:     return 0;
                   1510: }
                   1511: 
1.21      albertel 1512: sub remove_from_queue {
1.86      albertel 1513:     my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49      albertel 1514:     if ($queue eq 'none') { return 'ok'; }
1.86      albertel 1515:     if (!defined($symb) || !defined($cdom) || !defined($cnum)
                   1516: 	|| !defined($udom) || !defined($uname)) {
1.185     albertel 1517: 	($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.86      albertel 1518: 	$cnum=$env{'course.'.$cid.'.num'};
                   1519: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1520:     }
1.88      albertel 1521:     if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
                   1522: 	return 'ok';
                   1523:     }
1.86      albertel 1524:     my $key=&encode_queue_key($symb,$udom,$uname);
1.27      albertel 1525:     my @keys=($key,"$key\0locked");
1.31      albertel 1526:     return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21      albertel 1527: }
                   1528: 
1.16      albertel 1529: sub setup_env_for_other_user {
                   1530:     my ($queue_key,$safeeval)=@_;
                   1531:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30      albertel 1532:     &Apache::lonxml::debug("setup_env for $queue_key");
1.16      albertel 1533:     $env{'form.grade_symb'}=$symb;
                   1534:     $env{'form.grade_domain'}=$udom;
                   1535:     $env{'form.grade_username'}=$uname;
                   1536:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                   1537:     &Apache::lonxml::initialize_rndseed($safeeval);
                   1538: }
                   1539: 
1.31      albertel 1540: sub get_queue_data {
1.165     albertel 1541:     my ($queue,$udom,$uname)=@_;
1.185     albertel 1542:     my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonnet::whichuser();
1.165     albertel 1543:     if (!$uname || !$udom) {
                   1544: 	$uname=$other_uname;
                   1545: 	$udom =$other_udom;
                   1546:     }
1.31      albertel 1547:     my $cnum=$env{'course.'.$cid.'.num'};
                   1548:     my $cdom=$env{'course.'.$cid.'.domain'};
1.138     albertel 1549:     my $todo="$symb\0queue\0$uname:$udom";
1.31      albertel 1550:     my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
                   1551:     if ($key eq $todo && ref($value)) {
                   1552: 	return $value;
                   1553:     }
                   1554:     return undef;
                   1555: }
                   1556: 
1.84      albertel 1557: 
1.49      albertel 1558: sub check_queue_for_key {
1.84      albertel 1559:     my ($cdom,$cnum,$queue,$todo)=@_;
                   1560: 
1.49      albertel 1561:     my %results=
                   1562: 	&Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
                   1563:     
                   1564:     if (exists($results{$todo}) && ref($results{$todo})) {
                   1565: 	if (defined($results{"$todo\0locked"})) {
                   1566: 	    return 'locked';
                   1567: 	}
1.148     albertel 1568: 	if (my $slot=&slotted_access($results{$todo})) {
1.86      albertel 1569: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1570: 	    if ($slot_data{'endtime'} > time) { 
                   1571: 		return 'in_progress';
                   1572: 	    }
1.148     albertel 1573: 	} else {
                   1574: 	    my ($symb) = &decode_queue_key($todo);
                   1575: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1576: 	    if ($due_date > time) {
                   1577: 		return 'in_progress';
                   1578: 	    }
1.58      albertel 1579: 	}
1.49      albertel 1580: 	return 'enqueued';
                   1581:     }
                   1582:     return undef;
                   1583: }
                   1584: 
1.14      albertel 1585: sub add_to_queue {
1.82      albertel 1586:     my ($queue,$user_data)=@_;
1.49      albertel 1587:     if ($queue eq 'none') { return 'ok'; }
1.185     albertel 1588:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.82      albertel 1589:     if (!$cid || $env{'request.state'} eq 'construct') {
                   1590: 	return 'no_queue';
                   1591:     }
1.14      albertel 1592:     my $cnum=$env{'course.'.$cid.'.num'};
                   1593:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1594:     my %data;
1.138     albertel 1595:     $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83      albertel 1596:     return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14      albertel 1597: }
                   1598: 
1.156     albertel 1599: sub get_limited_classlist {
                   1600:     my ($sections) = @_;
                   1601: 
                   1602:     my $classlist = &Apache::loncoursedata::get_classlist();
1.157     albertel 1603:     foreach my $student (keys(%$classlist)) {
                   1604: 	if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
                   1605: 	     ne 'Active') {
                   1606: 	    delete($classlist->{$student});
                   1607:        	}
                   1608:     }
1.156     albertel 1609: 
1.237     albertel 1610:     if (ref($sections) && !grep {$_ eq 'all'} (@{ $sections })) {
1.156     albertel 1611: 	foreach my $student (keys(%$classlist)) {
                   1612: 	    my $section  = 
                   1613: 		$classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1.237     albertel 1614: 	    if (! grep {$_ eq $section} (@{ $sections })) {
1.156     albertel 1615: 		delete($classlist->{$student});
                   1616: 	    }
                   1617: 	}
                   1618:     }
                   1619:     return $classlist;
                   1620: }
                   1621: 
                   1622: 
1.14      albertel 1623: sub show_queue {
1.32      albertel 1624:     my ($queue,$with_selects)=@_;
1.14      albertel 1625:     my $result;
1.185     albertel 1626:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14      albertel 1627:     my $cnum=$env{'course.'.$cid.'.num'};
                   1628:     my $cdom=$env{'course.'.$cid.'.domain'};
1.59      albertel 1629: 
1.237     albertel 1630:     my @chosen_sections = &get_allowed_sections();
1.156     albertel 1631: 
                   1632:     my $classlist = &get_limited_classlist(\@chosen_sections);
                   1633: 
1.63      albertel 1634:     if (!(grep(/^all$/,@chosen_sections))) {
1.239     bisitz   1635: 	$result.='<p>'
                   1636:                 .&mt('Showing only sections [_1].'
                   1637:                     ,'<tt>'.join(', ',@chosen_sections).'</tt>')
                   1638:                 ."</p>\n";
1.63      albertel 1639:     }
1.59      albertel 1640: 
1.156     albertel 1641:     my ($view,$view_section);
                   1642:     my $scope = $env{'request.course.id'};
                   1643:     if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
                   1644: 	$scope .= '/'.$env{'request.course.sec'};
                   1645: 	if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
                   1646: 	    $view_section=$env{'request.course.sec'};
                   1647: 	} else {
                   1648: 	    undef($view);
                   1649: 	}
                   1650:     }
                   1651: 
1.234     albertel 1652:     $result .= 
                   1653: 	'<p><a href="/adm/flip?postdata=return:">'.
                   1654: 	&mt('Return to resource').'</a></p><hr />'.
1.239     bisitz   1655: 	"\n<h3>".&mt('Current Queue - [_1]',$queue)."</h3>";
1.16      albertel 1656:     my $regexp="^$symb\0";
1.30      albertel 1657:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31      albertel 1658:     my ($tmp)=%queue;
                   1659:     if ($tmp=~/^error: 2 /) {
1.234     albertel 1660: 	$result.=
1.159     albertel 1661: 	    &Apache::loncommon::start_data_table().
                   1662: 	    &Apache::loncommon::start_data_table_row().
                   1663: 	    '<td>'.&mt('Empty').'</td>'.
                   1664: 	    &Apache::loncommon::end_data_table_row().
                   1665: 	    &Apache::loncommon::end_data_table();
1.234     albertel 1666: 	return $result;
1.31      albertel 1667:     }
1.103     albertel 1668:     my $title=&Apache::lonnet::gettitle($symb);
1.234     albertel 1669:     $result.=
1.159     albertel 1670: 	&Apache::loncommon::start_data_table().
                   1671: 	&Apache::loncommon::start_data_table_header_row();
1.239     bisitz   1672:     if ($with_selects) { $result.='<th>'.&mt('Status').'</th><th></th>'; }
                   1673:     $result.='<th>'.&mt('User').'</th><th>'.&mt('Data').'</th>'.
1.159     albertel 1674: 	&Apache::loncommon::end_data_table_header_row();
1.14      albertel 1675:     foreach my $key (sort(keys(%queue))) {
1.59      albertel 1676: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
1.235     albertel 1677: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.237     albertel 1678: 	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.156     albertel 1679: 	
                   1680: 	my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
                   1681: 
                   1682: 	my $can_view=1;
                   1683: 	if (!$view
                   1684: 	    || ($view_section && !$section)
                   1685: 	    || ($view_section && $section && ($view_section ne $section))) {
                   1686: 	    $can_view=0;
                   1687: 	}
                   1688: 
1.32      albertel 1689: 	if ($key=~/locked$/ && !$with_selects) {
1.159     albertel 1690: 	    $result.= &Apache::loncommon::start_data_table_row().
                   1691: 		"<td>$uname</td>";
1.103     albertel 1692: 	    $result.='<td>'.$queue{$key}.'</td></tr>';
1.32      albertel 1693: 	} elsif ($key=~/timestamp$/ && !$with_selects) {
1.159     albertel 1694: 	    $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103     albertel 1695: 	    $result.='<td>'.
1.16      albertel 1696: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32      albertel 1697: 	} elsif ($key!~/(timestamp|locked)$/) {
1.159     albertel 1698: 	    $result.= &Apache::loncommon::start_data_table_row();
1.148     albertel 1699: 	    my ($end_time,$slot_text);
                   1700: 	    if (my $slot=&slotted_access($queue{$key})) {
                   1701: 		my %slot_data=&Apache::lonnet::get_slot($slot);
                   1702: 		$end_time = $slot_data{'endtime'};
                   1703: 		$slot_text = &mt('Slot: [_1]',$slot);
                   1704: 	    } else {
                   1705: 		$end_time = &Apache::lonhomework::due_date('0',$symb);
                   1706: 		$slot_text = '';
                   1707: 	    }
1.32      albertel 1708: 	    if ($with_selects) {
1.158     www      1709: 		my $ekey=&escape($key);
1.103     albertel 1710: 		my ($action,$description,$status)=('select',&mt('Select'));
1.32      albertel 1711: 		if (exists($queue{"$key\0locked"})) {
1.217     albertel 1712: 		    my ($locker,$time) = 
                   1713: 			&get_lock_info($queue{"$key\0locked"});
                   1714: 		    if ($time) {
1.214     albertel 1715: 			$time = 
                   1716: 			    &Apache::lonnavmaps::timeToHumanString($time,
                   1717: 								   'start');
                   1718: 		    }
1.138     albertel 1719: 		    my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.239     bisitz   1720: 		    $status=&mt('Locked by [_1] [_2]','<tt>'.$locker.'</tt>',$time);
1.217     albertel 1721: 		    if ($me eq $locker) {
1.32      albertel 1722: 			($action,$description)=('resume',&mt('Resume'));
                   1723: 		    } else {
                   1724: 			($action,$description)=('unlock',&mt('Unlock'));
                   1725: 		    }
                   1726: 		}
1.62      albertel 1727: 		my $seclist;
                   1728: 		foreach my $sec (@chosen_sections) {
                   1729: 		    $seclist.='<input type="hidden" name="chosensections" 
                   1730:                                value="'.$sec.'" />';
                   1731: 		}
1.156     albertel 1732: 		if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35      albertel 1733: 		    $result.=(<<FORM);
1.103     albertel 1734: <td>$status</td>
1.32      albertel 1735: <td>
1.115     albertel 1736: <form style="display: inline" method="post">
1.32      albertel 1737:  <input type="hidden" name="gradingkey" value="$ekey" />
                   1738:  <input type="hidden" name="queue" value="$queue" />
                   1739:  <input type="hidden" name="gradingaction" value="$action" />
                   1740:  <input type="hidden" name="webgrade" value="no" />
1.33      albertel 1741:  <input type="hidden" name="queuemode" value="selected" />
1.32      albertel 1742:  <input type="submit" name="submit" value="$description" />
1.62      albertel 1743:  $seclist
1.32      albertel 1744: </form>
                   1745: </td>
                   1746: FORM
1.156     albertel 1747:                 } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
                   1748: 		    $result.='<td>'.&mt("Not gradable").'</td><td>&nbsp;</td>'
1.35      albertel 1749:                 } else {
1.148     albertel 1750: 		    $result.='<td>'.&mt("In Progress").'</td><td>&nbsp;</td>'
1.35      albertel 1751: 		}
1.32      albertel 1752: 	    }
1.156     albertel 1753: 	    $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138     albertel 1754: 		" <tt>($uname:$udom)</tt> </td>";
1.239     bisitz   1755:             $result.='<td>'.$slot_text.' '
                   1756:                     .&mt('End time: [_1]'
                   1757:                         ,&Apache::lonlocal::locallocaltime($end_time))
                   1758:                     .'</td>'
                   1759:                     .&Apache::loncommon::end_data_table_row();
1.16      albertel 1760: 	}
1.14      albertel 1761:     }
1.159     albertel 1762:     $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14      albertel 1763:     return $result;
                   1764: }
                   1765: 
1.237     albertel 1766: sub get_allowed_sections {
                   1767:     my @chosen_sections;
                   1768:     if (&section_restricted()) {
                   1769: 	@chosen_sections = ($env{'request.course.sec'});
                   1770:     } else {
                   1771: 	@chosen_sections =
                   1772: 	    &Apache::loncommon::get_env_multiple('form.chosensections');
                   1773:     }
                   1774: 
                   1775:     return @chosen_sections;
                   1776: }
                   1777: 
1.235     albertel 1778: sub section_restricted {
1.237     albertel 1779:     my $cid =(&Apache::lonnet::whichuser())[1];
                   1780:     return (lc($env{'course.'.$cid.'.task_grading'}) eq 'section'
                   1781: 	    && $env{'request.course.sec'} ne '' );
                   1782: }
                   1783: 
                   1784: sub allow_grade_user {
1.235     albertel 1785:     my ($classlist_entry) = @_;
1.237     albertel 1786: 
                   1787:     if (&section_restricted()
1.235     albertel 1788: 	&& $env{'request.course.sec'} ne
                   1789: 	      $classlist_entry->[&Apache::loncoursedata::CL_SECTION()]) {
1.237     albertel 1790: 	return 0;
1.235     albertel 1791:     }
1.237     albertel 1792:     return 1;
1.235     albertel 1793: }
                   1794: 
1.34      albertel 1795: sub get_queue_counts {
                   1796:     my ($queue)=@_;
                   1797:     my $result;
1.185     albertel 1798:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.34      albertel 1799:     my $cnum=$env{'course.'.$cid.'.num'};
                   1800:     my $cdom=$env{'course.'.$cid.'.domain'};
1.156     albertel 1801: 
1.157     albertel 1802:     my $classlist=&get_limited_classlist();
1.156     albertel 1803: 
1.34      albertel 1804:     my $regexp="^$symb\0";
                   1805:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1806:     my ($tmp)=%queue;
                   1807:     if ($tmp=~/^error: 2 /) {
                   1808: 	return (0,0,0);
                   1809:     }
1.235     albertel 1810: 
1.34      albertel 1811:     my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96      albertel 1812:     my %slot_cache;
1.34      albertel 1813:     foreach my $key (sort(keys(%queue))) {
1.156     albertel 1814: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
1.235     albertel 1815: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.237     albertel 1816: 	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.235     albertel 1817: 
1.34      albertel 1818: 	if ($key=~/locked$/) {
                   1819: 	    $locks++;
                   1820: 	} elsif ($key=~/timestamp$/) {
                   1821: 	    #ignore
                   1822: 	} elsif ($key!~/(timestamp|locked)$/) {
                   1823: 	    $entries++;
1.148     albertel 1824: 	    if (my $slot=&slotted_access($queue{$key})) {
                   1825: 		if (!exists($slot_cache{$slot})) {
                   1826: 		    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1827: 		    $slot_cache{$slot} = \%slot_data;
                   1828: 		}
                   1829: 		if (time > $slot_cache{$slot}{'endtime'}) {
                   1830: 		    $ready_to_grade++;
                   1831: 		}
                   1832: 	    } else {
                   1833: 		my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1834: 		if ($due_date ne '' && time > $due_date) {
                   1835: 		    $ready_to_grade++;
                   1836: 		}
1.34      albertel 1837: 	    }
                   1838: 	}
                   1839:     }
                   1840:     return ($entries,$ready_to_grade,$locks);
                   1841: }
                   1842: 
1.49      albertel 1843: sub encode_queue_key {
                   1844:     my ($symb,$udom,$uname)=@_;
1.138     albertel 1845:     return "$symb\0queue\0$uname:$udom";
1.49      albertel 1846: }
                   1847: 
1.14      albertel 1848: sub decode_queue_key {
                   1849:     my ($key)=@_;
                   1850:     my ($symb,undef,$user) = split("\0",$key);
1.138     albertel 1851:     my ($uname,$udom) = split(':',$user);
1.14      albertel 1852:     return ($symb,$uname,$udom);
                   1853: }
                   1854: 
                   1855: sub queue_key_locked {
1.30      albertel 1856:     my ($queue,$key,$cdom,$cnum)=@_;
1.33      albertel 1857:     if (!defined($cdom) || !defined($cnum)) {
1.185     albertel 1858: 	my (undef,$cid)=&Apache::lonnet::whichuser();
1.33      albertel 1859: 	$cnum=$env{'course.'.$cid.'.num'};
                   1860: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1861:     }
1.14      albertel 1862:     my ($key_locked,$value)=
1.30      albertel 1863: 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14      albertel 1864:     if ($key_locked eq "$key\0locked") {
1.217     albertel 1865: 	return &get_lock_info($value);
1.14      albertel 1866:     }
                   1867:     return undef;
                   1868: }
                   1869: 
1.148     albertel 1870: sub slotted_access {
                   1871:     my ($queue_entry) = @_;
                   1872:     if (ref($queue_entry) eq 'ARRAY') {
                   1873: 	if (defined($queue_entry->[0])) {
                   1874: 	    return $queue_entry->[0];
                   1875: 	}
                   1876: 	return undef;
                   1877:     } elsif (ref($queue_entry) eq 'HASH') {
                   1878: 	if (defined($queue_entry->{'slot'})) {
                   1879: 	    return $queue_entry->{'slot'};
                   1880: 	}
                   1881: 	return undef;
                   1882:     }
                   1883:     return undef;
                   1884: }
                   1885: 
1.14      albertel 1886: sub pick_from_queue_data {
1.156     albertel 1887:     my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98      albertel 1888:     my @possible; # will hold queue entries that are valid to be selected
1.30      albertel 1889:     foreach my $key (keys(%$queuedata)) {
1.68      albertel 1890: 	if ($key =~ /\0locked$/) { next; }
                   1891: 	if ($key =~ /\0timestamp$/) { next; }
1.156     albertel 1892: 
1.14      albertel 1893: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
1.235     albertel 1894: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.237     albertel 1895: 	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.156     albertel 1896: 
1.14      albertel 1897: 	if ($check_section) {
1.156     albertel 1898: 	    my $section =
                   1899: 		$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17      albertel 1900: 	    if ($section eq $check_section) {
1.33      albertel 1901: 		&Apache::lonxml::debug("my sec");
1.15      albertel 1902: 		next;
                   1903: 	    }
1.14      albertel 1904: 	}
1.148     albertel 1905: 	my $end_time;
                   1906: 	if (my $slot=&slotted_access($queuedata->{$key})) {
1.154     albertel 1907: 	    &Apache::lonxml::debug("looking at slot $slot");
1.148     albertel 1908: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1909: 	    if ($slot_data{'endtime'} < time) { 
                   1910: 		$end_time = $slot_data{'endtime'};
1.154     albertel 1911: 	    } else {
                   1912: 		&Apache::lonxml::debug("not time ".$slot_data{'endtime'});
                   1913: 		next;
1.148     albertel 1914: 	    }
                   1915: 	} else {
                   1916: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154     albertel 1917: 	    if ($due_date < time) {
1.148     albertel 1918: 		$end_time = $due_date;
1.154     albertel 1919: 	    } else {
                   1920: 		&Apache::lonxml::debug("not time $due_date");
                   1921: 		next;
1.148     albertel 1922: 	    }
                   1923: 	}
                   1924: 	
1.98      albertel 1925: 	if (exists($queuedata->{"$key\0locked"})) {
1.33      albertel 1926: 	    &Apache::lonxml::debug("someone already has um.");
1.15      albertel 1927: 	    next;
                   1928: 	}
1.148     albertel 1929: 	push(@possible,[$key,$end_time]);
1.98      albertel 1930:     }
                   1931:     if (@possible) {
                   1932:         # sort entries in order by slot end time
                   1933: 	@possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137     albertel 1934: 	# pick one of the entries in the top 10% in small queues and one
                   1935: 	# of the first ten entries in large queues
1.139     albertel 1936: 	#my $ten_percent = int($#possible * 0.1);
                   1937: 	#if ($ten_percent < 1 ) { $ten_percent = 1;  }
                   1938: 	#if ($ten_percent > 10) { $ten_percent = 10; }
                   1939: 	#my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137     albertel 1940: 	
1.139     albertel 1941: 	#return $possible[int(rand($max))][0];
                   1942: 	return $possible[0][0];
1.14      albertel 1943:     }
                   1944:     return undef;
                   1945: }
                   1946: 
1.217     albertel 1947: sub get_lock_info {
                   1948:     my ($lock_info) = @_;
                   1949:     if (wantarray) {
                   1950: 	if (ref($lock_info) eq 'ARRAY') {
                   1951: 	    return @{$lock_info};
                   1952: 	} else {
                   1953: 	    return ($lock_info);
                   1954: 	}
                   1955:     } else {
                   1956: 	if (ref($lock_info) eq 'ARRAY') {
                   1957: 	    return $lock_info->[0];
                   1958: 	} else {
                   1959: 	    return $lock_info;
                   1960: 	}
                   1961:     }
                   1962:     return;
                   1963: }
                   1964: 
1.15      albertel 1965: sub find_mid_grade {
1.30      albertel 1966:     my ($queue,$symb,$cdom,$cnum)=@_;
1.158     www      1967:     my $todo=&unescape($env{'form.gradingkey'});
1.138     albertel 1968:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15      albertel 1969:     if ($todo) {
1.30      albertel 1970: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel 1971: 	if ($who eq $me) { return $todo; }
                   1972:     }
                   1973:     my $regexp="^$symb\0.*\0locked\$";
1.30      albertel 1974:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel 1975:     foreach my $key (keys(%locks)) {
1.217     albertel 1976: 	my $who= &get_lock_info($locks{$key});
1.15      albertel 1977: 	if ($who eq $me) {
                   1978: 	    $todo=$key;
                   1979: 	    $todo=~s/\0locked$//;
                   1980: 	    return $todo;
                   1981: 	}
                   1982:     }
                   1983:     return undef;
                   1984: }
                   1985: 
1.32      albertel 1986: sub lock_key {
                   1987:     my ($queue,$todo)=@_;
1.138     albertel 1988:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.185     albertel 1989:     my (undef,$cid)=&Apache::lonnet::whichuser();
1.32      albertel 1990:     my $cnum=$env{'course.'.$cid.'.num'};
                   1991:     my $cdom=$env{'course.'.$cid.'.domain'};
1.214     albertel 1992:     my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> [$me,time]},
1.32      albertel 1993: 					$cdom,$cnum);
1.33      albertel 1994:     &Apache::lonxml::debug("success $success $todo");
1.32      albertel 1995:     if ($success eq 'ok') {
                   1996: 	return 1;
                   1997:     }
                   1998:     return 0;
                   1999: }
                   2000: 
1.86      albertel 2001: sub get_queue_symb_status {
1.85      albertel 2002:     my ($queue,$symb,$cdom,$cnum) = @_;
                   2003:     if (!defined($cdom) || !defined($cnum)) {
1.235     albertel 2004: 	my (undef,$cid) =&Apache::lonnet::whichuser();
1.85      albertel 2005: 	$cnum=$env{'course.'.$cid.'.num'};
                   2006: 	$cdom=$env{'course.'.$cid.'.domain'};
                   2007:     }
1.157     albertel 2008:     my $classlist=&get_limited_classlist();
1.156     albertel 2009: 
1.85      albertel 2010:     my $regexp="^$symb\0";
                   2011:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   2012:     my ($tmp)=%queue;
                   2013:     if ($tmp=~/^error: 2 /) { return; }
                   2014:     my @users;
                   2015:     foreach my $key (sort(keys(%queue))) {
                   2016: 	next if ($key=~/locked$/);
                   2017: 	next if ($key=~/timestamp$/);
                   2018: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156     albertel 2019: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.237     albertel 2020: 	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.85      albertel 2021: 	push(@users,"$uname:$udom");
                   2022:     }
                   2023:     return @users;
                   2024: }
                   2025: 
1.14      albertel 2026: sub get_from_queue {
1.30      albertel 2027:     my ($queue)=@_;
1.14      albertel 2028:     my $result;
1.185     albertel 2029:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14      albertel 2030:     my $cnum=$env{'course.'.$cid.'.num'};
                   2031:     my $cdom=$env{'course.'.$cid.'.domain'};
1.32      albertel 2032:     my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33      albertel 2033:     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16      albertel 2034:     if ($todo) { return $todo; }
1.95      albertel 2035:     my $attempts=0;
1.156     albertel 2036: 
1.157     albertel 2037:     my $classlist=&get_limited_classlist();
1.156     albertel 2038: 
1.14      albertel 2039:     while (1) {
1.95      albertel 2040: 	if ($attempts > 2) {
                   2041: 	    # tried twice to get a queue entry, giving up
                   2042: 	    return (undef,'unable');
                   2043: 	}
1.14      albertel 2044: 	my $starttime=time;
1.83      albertel 2045: 	&Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
                   2046: 			      $cdom,$cnum);
1.33      albertel 2047: 	&Apache::lonxml::debug("$starttime");
1.14      albertel 2048: 	my $regexp="^$symb\0queue\0";
1.156     albertel 2049: 	#my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97      albertel 2050: 
1.98      albertel 2051: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33      albertel 2052: 	#make a pass looking for a user _not_ in my section
1.14      albertel 2053: 	if ($env{'request.course.sec'}) {
1.33      albertel 2054: 	    &Apache::lonxml::debug("sce");
1.30      albertel 2055: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156     albertel 2056: 					\%queue,$cdom,$cnum,$classlist);
1.33      albertel 2057: 	    &Apache::lonxml::debug("sce $todo");
1.14      albertel 2058: 	}
1.33      albertel 2059: 	# no one _not_ in our section so look for any user that is
                   2060: 	# ready for grading
1.14      albertel 2061: 	if (!$todo) {
1.33      albertel 2062: 	    &Apache::lonxml::debug("no sce");
1.156     albertel 2063: 	    $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
                   2064: 					$classlist);
1.33      albertel 2065: 	    &Apache::lonxml::debug("no sce $todo");
1.14      albertel 2066: 	}
                   2067: 	# no user to grade 
                   2068: 	if (!$todo) { last; }
1.33      albertel 2069: 	&Apache::lonxml::debug("got $todo");
1.14      albertel 2070: 	# otherwise found someone so lets try to lock them
1.32      albertel 2071: 	# unless someone else already picked them
1.95      albertel 2072: 	if (!&lock_key($queue,$todo)) {
                   2073: 	    $attempts++;
                   2074: 	    next;
                   2075: 	}
1.14      albertel 2076: 	my (undef,$endtime)=
1.30      albertel 2077: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel 2078: 				 $cdom,$cnum);
1.33      albertel 2079: 	&Apache::lonxml::debug("emd  $endtime");
1.14      albertel 2080: 	# someone else already modified the queue, 
                   2081: 	# perhaps our picked user wass already fully graded between
                   2082: 	# when we picked him and when we locked his record? so lets
                   2083: 	# double check.
                   2084: 	if ($endtime != $starttime) {
                   2085: 	    my ($key,$value)=
1.30      albertel 2086: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel 2087: 				     $cdom,$cnum);
1.33      albertel 2088: 	    &Apache::lonxml::debug("check  $key .. $value");
1.14      albertel 2089: 	    if ($key eq $todo && ref($value)) {
                   2090: 	    } else {
1.30      albertel 2091: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel 2092: 				     $cdom,$cnum);
1.33      albertel 2093: 		&Apache::lonxml::debug("del");
1.95      albertel 2094: 		$attempts++;
1.14      albertel 2095: 		next;
                   2096: 	    }
                   2097: 	}
1.33      albertel 2098: 	&Apache::lonxml::debug("last $todo");
1.14      albertel 2099: 	last;
                   2100:     }
                   2101:     return $todo;
                   2102: }
                   2103: 
1.49      albertel 2104: sub select_user {
1.185     albertel 2105:     my ($symb,$cid)=&Apache::lonnet::whichuser();
1.49      albertel 2106: 
1.237     albertel 2107:     my @chosen_sections = &get_allowed_sections();
1.156     albertel 2108:     my $classlist = &get_limited_classlist(\@chosen_sections);
1.63      albertel 2109:     
                   2110:     my $result;
                   2111:     if (!(grep(/^all$/,@chosen_sections))) {
1.239     bisitz   2112:         $result.='<p>'
                   2113:                 .&mt('Showing only sections [_1].'
                   2114:                     ,'<tt>'.join(', ',@chosen_sections).'</tt>')
                   2115:                 .'</p> '."\n";
1.63      albertel 2116:     }
1.159     albertel 2117:     $result.=&Apache::loncommon::start_data_table();
1.49      albertel 2118: 
1.156     albertel 2119:     foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49      albertel 2120: 	my ($uname,$udom) = split(/:/,$student);
1.59      albertel 2121: 	
1.84      albertel 2122: 	my $cnum=$env{'course.'.$cid.'.num'};
                   2123: 	my $cdom=$env{'course.'.$cid.'.domain'};
1.88      albertel 2124: 	my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
                   2125: 					 'Task');
1.49      albertel 2126: 	my $queue = 'none';
1.58      albertel 2127: 	my $cannot_grade;
                   2128: 	if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 2129: 	    $queue = 'reviewqueue';
1.58      albertel 2130: 	    if ($status{'reviewqueue'} eq 'in_progress') {
                   2131: 		$cannot_grade=1;
                   2132: 	    }
                   2133: 	} elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 2134: 	    $queue = 'gradingqueue';
1.58      albertel 2135: 	    if ($status{'gradingqueue'} eq 'in_progress') {
                   2136: 		$cannot_grade=1;
                   2137: 	    }
1.49      albertel 2138: 	}
                   2139: 	my $todo = 
1.158     www      2140: 	    &escape(&encode_queue_key($symb,$udom,$uname));
1.58      albertel 2141: 	if ($cannot_grade) {
1.159     albertel 2142: 	    $result.=&Apache::loncommon::start_data_table_row().
                   2143: 		'<td>&nbsp;</td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58      albertel 2144: 		'</td><td>';
                   2145: 	} else {
1.62      albertel 2146: 	    my $seclist;
                   2147: 	    foreach my $sec (@chosen_sections) {
                   2148: 		$seclist.='<input type="hidden" name="chosensections" 
                   2149:                                value="'.$sec.'" />';
                   2150: 	    }
1.242     bisitz   2151:             my $buttontext=&mt('Regrade');
1.159     albertel 2152: 	    $result.=&Apache::loncommon::start_data_table_row();
1.58      albertel 2153: 	    $result.=<<RESULT;
1.49      albertel 2154:   <td>
1.115     albertel 2155:     <form style="display: inline" method="post">
1.49      albertel 2156:       <input type="hidden" name="gradingkey" value="$todo" />
                   2157:       <input type="hidden" name="queue" value="$queue" />
                   2158:       <input type="hidden" name="webgrade" value="no" />
1.52      albertel 2159:       <input type="hidden" name="regrade" value="yes" />
1.242     bisitz   2160:       <input type="submit" name="submit" value="$buttontext" />
1.62      albertel 2161:       $seclist
1.49      albertel 2162:     </form>
1.237     albertel 2163:   <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt> Sec: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()]</td>
1.49      albertel 2164:   <td>
                   2165: RESULT
1.58      albertel 2166:         }
1.49      albertel 2167:         if ($status{'status'} eq 'pass') {
                   2168: 	    $result .= '<font color="green">'.&mt('Passed').'</font>';
                   2169: 	} elsif ($status{'status'} eq 'fail') {
                   2170: 	    $result .= '<font color="red">'.&mt('Failed').'</font>';
                   2171: 	} elsif ($status{'status'} eq 'review') {
                   2172: 	    $result .= '<font color="blue">'.&mt('Under Review').'</font>';
                   2173: 	} elsif ($status{'status'} eq 'ungraded') {
                   2174: 	    $result .= &mt('Ungraded');
                   2175: 	} elsif ($status{'status'} ne '') {
                   2176: 	    $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
                   2177: 	} else {
                   2178: 	    $result.="&nbsp;";
                   2179: 	}
                   2180: 	if ($status{'version'}) {
                   2181: 	    $result .= ' '.&mt('Version').' '.$status{'version'};
                   2182: 	}
1.101     albertel 2183: 	if ($status{'grader'}) {
                   2184: 	    $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
                   2185: 	}
1.49      albertel 2186: 	$result.= '</td><td>';
                   2187: 	if ($status{'reviewqueue'} eq 'enqueued') {
                   2188: 	    $result .= &mt('Awaiting Review');
                   2189: 	} elsif ($status{'reviewqueue'} eq 'locked') {
                   2190: 	    $result .= &mt('Under Review');
1.58      albertel 2191: 	} elsif ($status{'reviewqueue'} eq 'in_progress') {
                   2192: 	    $result .= &mt('Still being worked on.');
1.49      albertel 2193: 	} elsif ($status{'gradingqueue'} eq 'enqueued') {
                   2194: 	    $result .= &mt('Awaiting Grading');
                   2195: 	} elsif ($status{'gradingqueue'} eq 'locked') {
                   2196: 	    $result .= &mt('Being Graded');
1.58      albertel 2197: 	} elsif ($status{'gradingqueue'} eq 'in_progress') {
                   2198: 	    $result .= &mt('Still being worked on.');
1.49      albertel 2199: 	} else {
                   2200: 	    $result.="&nbsp;";
                   2201: 	}
1.159     albertel 2202: 	$result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49      albertel 2203:     }
1.159     albertel 2204:     $result.=&Apache::loncommon::end_data_table();
1.49      albertel 2205:     return $result;
                   2206: }
                   2207: 
                   2208: sub get_student_status {
1.86      albertel 2209:     my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
                   2210: 
                   2211:     my %status;
                   2212: 
                   2213:     if ($type eq 'Task') {
                   2214: 	my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49      albertel 2215: 					  $udom,$uname);
1.89      albertel 2216: 	$status{'status'}=$record{'resource.0.status'};
                   2217: 	$status{'version'}=$record{'resource.0.version'};
                   2218: 	$status{'grader'}=$record{'resource.0.regrader'};
1.86      albertel 2219:     }
                   2220:     $status{'reviewqueue'}=
                   2221: 	&check_queue_for_key($cdom,$cnum,'reviewqueue',
                   2222: 			     &encode_queue_key($symb,$udom,$uname));
                   2223:     $status{'gradingqueue'}=
                   2224: 	&check_queue_for_key($cdom,$cnum,'gradingqueue',
                   2225: 			     &encode_queue_key($symb,$udom,$uname));
1.49      albertel 2226:     return %status;
                   2227: }
                   2228: 
1.1       albertel 2229: sub start_ClosingParagraph {
                   2230:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   2231:     my $result;
                   2232:     if ($target eq 'web') {
1.13      albertel 2233:     } elsif ($target eq 'webgrade') {
                   2234: 	&Apache::lonxml::startredirection();
1.225     albertel 2235:     } elsif ($target eq 'edit') {
                   2236: 	$result = &Apache::edit::tag_start($target,$token);
                   2237:     } elsif ($target eq 'modified') {
1.1       albertel 2238:     }
                   2239:     return $result;
                   2240: }
                   2241: 
                   2242: sub end_ClosingParagraph {
                   2243:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   2244:     my $result;
                   2245:     if ($target eq 'web') {
1.13      albertel 2246:     } elsif ($target eq 'webgrade') {
                   2247: 	&Apache::lonxml::endredirection();
1.1       albertel 2248:     }
                   2249:     return $result;
                   2250: }
                   2251: 
1.227     albertel 2252: sub insert_ClosingParagraph {
                   2253:     return '
                   2254: <ClosingParagraph>
                   2255:     <startouttext />
                   2256:     <endouttext />
                   2257: </ClosingParagraph>';
                   2258: }
                   2259: 
1.168     albertel 2260: sub get_dim_id {
1.194     albertel 2261:     if (@Apache::bridgetask::dimension) {
                   2262: 	return $Apache::bridgetask::dimension[-1];
                   2263:     } else {
                   2264: 	return $top;
                   2265:     }
1.168     albertel 2266: }
                   2267: 
1.19      albertel 2268: sub get_id {
                   2269:     my ($parstack,$safeeval)=@_;
1.236     albertel 2270:     return &Apache::lonxml::get_id($parstack,$safeeval);
1.19      albertel 2271: }
                   2272: 
1.162     albertel 2273: sub start_Setup {
                   2274:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225     albertel 2275:     my $result;
1.168     albertel 2276:     my $dim = &get_id($parstack,$safeeval);
                   2277:     push(@Apache::bridgetask::dimension,$dim);
1.225     albertel 2278:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
                   2279: 	&Apache::lonxml::startredirection();
                   2280:     } elsif ($target eq 'edit') {
                   2281: 	$result = &Apache::edit::tag_start($target,$token);
                   2282: 	$result.= &Apache::edit::text_arg('Id:','id',$token,10).
                   2283: 	    &Apache::edit::end_row().
                   2284: 	    &Apache::edit::start_spanning_row();
                   2285:     } elsif ($target eq 'modified') {
                   2286: 	my $constructtag=
                   2287: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,'id');
                   2288: 	if ($constructtag) {
                   2289: 	    $result = &Apache::edit::rebuild_tag($token);
                   2290: 	}
                   2291:     }
                   2292:     return $result;
1.162     albertel 2293: }
1.173     albertel 2294: 
                   2295: {
                   2296:     my @allowed;
                   2297:     sub enable_dimension_parsing {
                   2298: 	my ($id) = @_;
                   2299: 	push(@allowed,$id);
                   2300:     }
                   2301:     sub disable_dimension_parsing {
                   2302: 	pop(@allowed);
                   2303:     }
                   2304:     sub skip_dimension_parsing {
                   2305: 	my ($check) = @_;
                   2306: 	if (!@allowed) { return 0;}
                   2307: 	# if unspecified allow any id
                   2308: 	if ($allowed[-1] eq undef) { return 0;}
                   2309: 
                   2310: 	return ($check ne $allowed[-1]);
                   2311:     }
                   2312: }
                   2313: 
1.151     albertel 2314: sub start_Question { return &start_Dimension(@_); }
1.1       albertel 2315: sub start_Dimension {
1.173     albertel 2316:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168     albertel 2317:     my $dim = &get_id($parstack,$safeeval);
                   2318:     my $previous_dim;
1.225     albertel 2319:     my $result;
                   2320:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   2321: 	if (@Apache::bridgetask::dimension) {
                   2322: 	    $previous_dim = $Apache::bridgetask::dimension[-1];
                   2323: 	    push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
                   2324: 		 $dim);
                   2325: 	    if(&skip_dimension_parsing($dim)) {
                   2326: 		$dimension{$previous_dim}{'criteria.'.$dim} =
                   2327: 		    $token->[4]
                   2328: 		    .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
                   2329: 						   $style)
                   2330: 		    .'</'.$tagstack->[-1].'>';
                   2331: 	    }
                   2332: 	    $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
                   2333: 	    $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
                   2334: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
                   2335: 	    push(@{$dimension{$previous_dim}{'criterias'}},$dim);
                   2336: 	    $dimension{$dim}{'nested'}=$previous_dim;
                   2337: 	    $dimension{$dim}{'depth'} = 1 + $dimension{$previous_dim}{'depth'};
                   2338: 	    
                   2339: 	    &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
                   2340: 	} else {
                   2341: 	    $dimension{$top}{'depth'}=0;
                   2342: 	    $dimension{$top}{'criteria.'.$dim.'.type'}='dimension';
                   2343: 	    $dimension{$top}{'criteria.'.$dim.'.mandatory'}=
                   2344: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
                   2345: 	    push(@{$dimension{$top}{'criterias'}},$dim);
                   2346: 	    $dimension{$dim}{'nested'}=$top;
                   2347: 	}
                   2348:         push(@Apache::bridgetask::dimension,$dim);
                   2349: 	&Apache::lonxml::startredirection();
                   2350: 	if (!&skip_dimension_parsing($dim)) {
                   2351: 	    &enable_dimension_parsing($dim);
                   2352: 	}
                   2353:     } elsif ($target eq 'edit') {
                   2354:   	$result = &Apache::edit::tag_start($target,$token);
                   2355: 	$result.=  
                   2356: 	    &Apache::edit::text_arg('Id:','id',$token,10).' '.
                   2357: 	    &Apache::edit::select_arg('Passing is Mandatory:','Mandatory',
1.233     albertel 2358: 				      [['Y', 'Yes'],
                   2359: 				       ['N','No'],],
1.225     albertel 2360: 				      $token).' <br /> '.
                   2361: 	    &Apache::edit::text_arg('Required number of passed optional elements to pass the '.$token->[1].':',
                   2362: 				    'OptionalRequired',$token,4).
                   2363: 	    &Apache::edit::end_row().
                   2364: 	    &Apache::edit::start_spanning_row();
                   2365:     } elsif ($target eq 'modified') {
                   2366: 	my $constructtag=
                   2367: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
                   2368: 					'id','Mandatory','OptionalRequired');
                   2369: 	if ($constructtag) {
                   2370: 	    $result = &Apache::edit::rebuild_tag($token);
                   2371: 	}
1.168     albertel 2372:     }
1.225     albertel 2373:     return $result;# &internal_location($dim);
1.1       albertel 2374: }
                   2375: 
1.160     albertel 2376: sub start_QuestionText {
                   2377:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225     albertel 2378:     my $result;
                   2379:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   2380: 	my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
1.168     albertel 2381:     my $dim = &get_dim_id();
1.169     albertel 2382: 	$dimension{$dim}{'questiontext'}=$text;
1.225     albertel 2383:     } elsif ($target eq 'edit') {
                   2384: 	$result = &Apache::edit::tag_start($target,$token);
                   2385:     } elsif ($target eq 'modified') {
1.160     albertel 2386:     }
1.225     albertel 2387:     return $result;
1.160     albertel 2388: }
                   2389: 
                   2390: sub end_QuestionText {
                   2391:     return '';
                   2392: }
                   2393: 
1.227     albertel 2394: sub insert_QuestionText {
                   2395:     return '
                   2396: <QuestionText>
                   2397:     <startouttext />
                   2398:     <endouttext />
                   2399: </QuestionText>';
                   2400: }
                   2401: 
1.13      albertel 2402: sub get_instance {
1.75      albertel 2403:     my ($dim)=@_;
                   2404:     my $rand_alg=&Apache::lonnet::get_rand_alg();
                   2405:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
                   2406: 	$rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
                   2407: 	$rand_alg eq '64bit4' ) {
                   2408: 	&Apache::response::pushrandomnumber();
1.169     albertel 2409: 	my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75      albertel 2410: 	my $num=@order;
                   2411: 	my $version=&get_version();
                   2412: 	my $which=($version-1)%$num;
                   2413: 	return $order[$which];
                   2414:     } else {
                   2415: 	my ($version,$previous) = &get_version();
                   2416: 	my $instance = 
                   2417: 	    $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
                   2418: 	if (defined($instance)) { return $instance; }
                   2419: 
                   2420: 	&Apache::response::pushrandomnumber();
1.173     albertel 2421: 	if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
                   2422: 	    my @instances = @{$dimension{$dim}{'instances'}};
                   2423: 	    # remove disabled instances
                   2424: 	    for (my $i=0; $i < $#instances; $i++) {
                   2425: 		if ($dimension{$dim}{$instances[$i].'.disabled'}) {
                   2426: 		    splice(@instances,$i,1);
                   2427: 		    $i--;
                   2428: 		}
                   2429: 	    }
                   2430: 	    @instances = &Math::Random::random_permutation(@instances);
                   2431: 	    $instance  = $instances[($version-1)%scalar(@instances)];
                   2432: 	    if ($version =~ /^\d$/) {
                   2433: 		$Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = 
                   2434: 		    $instance;
                   2435: 		$Apache::lonhomework::results{'INTERNAL_store'} = 1; 
1.75      albertel 2436: 	    }
                   2437: 	}
                   2438: 	&Apache::response::poprandomnumber();
                   2439: 	return $instance;
                   2440:     }
1.13      albertel 2441: }
                   2442: 
1.169     albertel 2443: sub get_criteria {
                   2444:     my ($what,$version,$dim,$id) = @_;
                   2445:     my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.194     albertel 2446:     my $prefix = ($type eq 'criteria' && $dim ne $top) ? "$dim.$id"
                   2447: 	                                               : "$id";
1.169     albertel 2448:     my $entry = "resource.$version.0.$prefix.$what";
                   2449:     if (exists($Apache::lonhomework::results{$entry})) {
                   2450: 	return $Apache::lonhomework::results{$entry};
                   2451:     }
                   2452:     return $Apache::lonhomework::history{$entry};
                   2453: }
                   2454: 
1.194     albertel 2455: sub link {
                   2456:     my ($id) = @_;
                   2457:     $id =~ s/\./_/g;
                   2458:     return 'LC_GRADING_criteria_'.$id;
                   2459: }
                   2460: sub end_Question { return &end_Dimension(@_); }
                   2461: sub end_Dimension {
                   2462:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225     albertel 2463:     my $result;
1.194     albertel 2464:     my $dim=&get_id($parstack,$safeeval);
1.225     albertel 2465:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   2466: 	$result=&Apache::lonxml::endredirection();
                   2467: 	if (&skip_dimension_parsing($dim)) {
                   2468: 	    pop(@Apache::bridgetask::dimension);
                   2469: 	    return;
                   2470: 	}
1.122     albertel 2471:     }
1.194     albertel 2472:     my $instance=&get_instance($dim);
                   2473:     my $version=&get_version();
                   2474:     if ($target eq 'web') {
                   2475: 	$result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
                   2476: 	my @instances = $instance;
                   2477: 	if (&Apache::response::showallfoils()) {
                   2478: 	    @instances = @{$dimension{$dim}{'instances'}};
1.173     albertel 2479: 	}
1.194     albertel 2480: 	my $shown_question_text;
                   2481: 	foreach my $instance (@instances) {
                   2482: 	    $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
                   2483: 				     [@_]);
                   2484: 	    $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
                   2485: 				     [@_],{'set_dim_id' => undef});
                   2486: 	    my $task_status = 
                   2487: 		$Apache::lonhomework::history{"resource.$version.0.status"};
                   2488: 	    if ($task_status ne 'pass' && $task_status ne 'fail') {
                   2489: 		
                   2490: 		foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2491: 				@{$dimension{$dim}{'criterias'}}) {
                   2492: 		    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2493: 		    &Apache::lonxml::debug("$id is $type");
                   2494: 		    if ($type eq 'dimension') {
                   2495: 			$result.=
                   2496: 			    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2497: 					  [@_],{'set_dim_id' => $id});
1.173     albertel 2498: 		    }
1.194     albertel 2499: 		}
                   2500: 	    } else {
                   2501: 		my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
                   2502: 		my $mandatory='Mandatory';
                   2503: 		if (&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval) eq 'N') {
                   2504: 		    $mandatory='Optional';
                   2505: 		}
1.200     albertel 2506: 		my $dim_info=
                   2507: 		    "\n<div class='LC_$dim_status LC_question_grade'>\n\t";
1.212     albertel 2508: 		my $ucquestion = 
                   2509: 		    my $question = 
                   2510: 		    ('sub' x $dimension{$dim}{'depth'}).'question';
                   2511: 		$ucquestion =~ s/^(.)/uc($1)/e;
1.194     albertel 2512: 		if ($dim_status eq 'pass') {
1.239     bisitz   2513:                     $dim_info.='<h3>'.$ucquestion.' : '
                   2514:                               .&mt('you passed this [_1] [_2]',$mandatory,$question)
                   2515:                               .'</h3>';
1.194     albertel 2516: 		}
                   2517: 		if ($dim_status eq 'fail') {
1.239     bisitz   2518:                     $dim_info.='<h3>'.$ucquestion.' : '
                   2519:                               .&mt('you did not pass this [_1] [_2]',$mandatory,$question)
                   2520:                               .'</h3>';
1.194     albertel 2521: 		}
1.197     albertel 2522: 		my %counts = &get_counts($dim,$instance,$parstack,
                   2523: 					 $safeeval);
                   2524: 
1.200     albertel 2525: 		$dim_info.="\n\t<p>"
1.197     albertel 2526: 		    .&question_status_message(\%counts,
                   2527: 					      $dimension{$dim}{'depth'})
1.200     albertel 2528: 		    ."</p>\n</div>\n";
1.194     albertel 2529: 		
                   2530: 		foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2531: 				@{$dimension{$dim}{'criterias'}}) {
                   2532: 		    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2533: 		    if ($type eq 'dimension') {
1.205     albertel 2534: 			if (defined($dimension{$id}{'result'})) {
                   2535: 			    $result.=$dimension{$id}{'result'};
                   2536: 			    next;
                   2537: 			} else {
                   2538: 			    $dim_info .=
                   2539: 				&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2540: 					      [@_],{'set_dim_id' => $id});
                   2541: 			}
                   2542: 		    } else {
                   2543: 			my $criteria =
                   2544: 			    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2545: 					  [@_]);
                   2546: 			$dim_info .= &layout_web_Criteria($dim,$id,$criteria);
1.194     albertel 2547: 		    }
1.169     albertel 2548: 		}
1.202     albertel 2549: 		# puts the results at the end of the dimension
1.226     albertel 2550: 		if ($result =~m{<QuestionGradeInfo\s*/>}) {
                   2551: 		    $result=~s{<QuestionGradeInfo\s*/>}{$dim_info};
                   2552: 		} else {
                   2553: 		    $result .= $dim_info;
                   2554: 		}
1.202     albertel 2555: 		# puts the results at the beginning of the dimension
                   2556: 		# my $internal_location=&internal_location($dim);
                   2557: 		# $result=~s/\Q$internal_location\E/$dim_info/;
1.19      albertel 2558: 	    }
1.194     albertel 2559: 	}
1.206     albertel 2560: 	if ($result !~ /^\s*$/s) {
1.209     albertel 2561: 	    # FIXME? this maybe unneccssary in the future, (CSE101 BT
                   2562: 	    # from Fall 2006 geenrate a div that attempts to hide some
                   2563: 	    # of the output in an odd way, this is a workaround so
                   2564: 	    # those old ones will continue to work.  # It puts the
                   2565: 	    # LC_question div to come after any starting closie div
                   2566: 	    # that the dimension produces
1.211     albertel 2567: 	    if ($result =~ m{^\s*</div>}) {
                   2568: 		$result =~ s{^(\s*</div>)}
1.210     albertel 2569: 		            {$1\n<div id="$dim" class="LC_question">};
1.209     albertel 2570: 	    } else {
1.210     albertel 2571: 		$result = "\n".'<div id="'.$dim.'" class="LC_question">'.
1.209     albertel 2572: 		    "\n".$result;
                   2573: 	    }
                   2574: 	    $result .= "\n</div>\n";
1.206     albertel 2575: 	}
1.194     albertel 2576:     } elsif ($target eq 'webgrade') {
                   2577: 	# in case of any side effects that we need
                   2578: 	&nested_parse(\$dimension{$dim}{'intro'},[@_]);
                   2579: 	&nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
                   2580: 	$result.=
                   2581: 	    &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
                   2582: 			  {'set_dim_id'          => undef,
1.195     albertel 2583: 			   'delayed_dim_results' => 1});
1.194     albertel 2584: 	foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2585: 			@{$dimension{$dim}{'criterias'}} ) {
                   2586: 	    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2587: 	    if ($type eq 'dimension') {
                   2588: 		# dimensional 'criteria' don't get assigned grades
                   2589: 		$result.=
                   2590: 		    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2591: 				  [@_],{'set_dim_id' => $id});
                   2592: 		next;
                   2593: 	    } else {
                   2594: 		my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2595: 					     [@_]);
                   2596: 		$criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
                   2597: 		my $internal_location=&internal_location($id);
1.209     albertel 2598: 		if ($result =~ m/\Q$internal_location\E/) {
                   2599: 		    $result =~ s/\Q$internal_location\E/$criteria/;
                   2600: 		} else {
                   2601: 		    $result.=$criteria ;
                   2602: 		}
1.151     albertel 2603: 	    }
1.194     albertel 2604: 	}
                   2605: 	if (&nest()) {
                   2606: 	    &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
                   2607: 	    $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
                   2608: 	    undef($result);
                   2609: 	}
                   2610:     } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
                   2611: 	my $optional_passed=0;
                   2612: 	my $mandatory_failed=0;
                   2613: 	my $ungraded=0;
                   2614: 	my $review=0;
                   2615: 	
                   2616: 	$result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
                   2617: 	$result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
                   2618: 				 [@_]);
                   2619: 	$result .= &nested_parse(\$dimension{$dim}{'questiontext'},
                   2620: 				 [@_],{'set_dim_id' => undef});
                   2621: 	
                   2622: 	foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2623: 			@{$dimension{$dim}{'criterias'}}) {
                   2624: 	    my $link=&link($id);
                   2625: 	    
                   2626: 	    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2627: 	    if ($type eq 'criteria') {
                   2628: 		# dimensional 'criteria' don't get assigned grades
                   2629: 		$Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
                   2630: 		$Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
                   2631: 	    } else {
                   2632: 		$result .=
                   2633: 		    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2634: 				  [@_],{'set_dim_id' => $id});
1.20      albertel 2635: 	    }
1.194     albertel 2636: 	    my $status= &get_criteria('status',$version,$dim,$id);
                   2637: 	    
                   2638: 	    my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
                   2639: 	    if ($status eq 'pass') {
                   2640: 		if (!$mandatory) { $optional_passed++; }
                   2641: 	    } elsif ($status eq 'fail') {
                   2642: 		if ($mandatory) { $mandatory_failed++; }
                   2643: 	    } elsif ($status eq 'review') {
                   2644: 		$review++;
                   2645: 	    } elsif ($status eq 'ungraded') {
                   2646: 		$ungraded++;
1.20      albertel 2647: 	    } else {
1.194     albertel 2648: 		$ungraded++;
1.20      albertel 2649: 	    }
1.194     albertel 2650: 	}
                   2651: 
                   2652: 	my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
                   2653: 	if ($opt_req !~ /\S/) {
                   2654: 	    $opt_req=
                   2655: 		&Apache::lonxml::get_param('OptionalRequired',
                   2656: 					   $parstack,$safeeval);
                   2657: 	    if ($opt_req !~ /\S/) { $opt_req = 0; }
                   2658: 	}
                   2659: 	if ($optional_passed < $opt_req) {
                   2660: 	    $mandatory_failed++;
                   2661: 	}
                   2662: 	&Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
                   2663: 	if ($review) {
                   2664: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
                   2665: 		'review';
                   2666: 	} elsif ($ungraded) {
                   2667: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
                   2668: 		'ungraded';
                   2669: 	} elsif ($mandatory_failed) {
                   2670: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
                   2671: 		'fail';
1.69      albertel 2672: 	} else {
1.194     albertel 2673: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
                   2674: 		'pass';
1.13      albertel 2675: 	}
1.225     albertel 2676:     } elsif ($target eq 'edit') {
                   2677:     } elsif ($target eq 'modified') {
1.194     albertel 2678:     } else {
                   2679: 	# any other targets no output
                   2680: 	undef($result);
1.1       albertel 2681:     }
1.225     albertel 2682:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   2683: 	&disable_dimension_parsing();
                   2684: 	pop(@Apache::bridgetask::dimension);
                   2685:     }
1.194     albertel 2686:     return $result;
                   2687: }
1.162     albertel 2688: 
1.198     albertel 2689: sub question_status_message {
1.197     albertel 2690:     my ($counts,$depth) = @_;
                   2691:     my %req  = ('man' => 'mandatory',
                   2692: 		'opt' => 'optional',);
                   2693:     my %type = ('cri' => 'criteria',
                   2694: 		'dim' => ('sub'x($depth+1)).'questions',);
                   2695:     my @sections;
                   2696:     foreach my $req ('man','opt') {
                   2697: 	foreach my $type ('cri','dim') {
                   2698: 	    if ($counts->{$req.'_'.$type}) {
                   2699: 		push(@sections,
1.213     albertel 2700: 		     $counts->{$req.'_'.$type.'_passed'}.' of the '.
1.197     albertel 2701: 		     $counts->{$req.'_'.$type}.' '.
                   2702: 		     $req{$req}.' '.$type{$type});
                   2703: 	    }
                   2704: 	}
                   2705:     }
                   2706: 
                   2707:     my $status = 'You passed ';
                   2708:     if (@sections == -1) {
                   2709:     } elsif (@sections == 1) {
                   2710: 	$status .= $sections[0];
                   2711:     } elsif (@sections == 2) {
                   2712: 	$status .= $sections[0].' and '.$sections[1];
                   2713:     } else {
                   2714: 	my $last = pop(@sections);
                   2715: 	$status .= join(', ',@sections).', and '.$last;
                   2716:     }
                   2717:     $status .= '.';
                   2718:     if ($counts->{'opt'}) {
1.241     raeburn  2719:         if ($counts->{'opt_dim'} + $counts->{'man_dim'} < 1) {
                   2720:             $status .= ' '.&mt('You were required to pass [quant,_1,optional criterion,optional criteria].',$counts->{'opt_req'});
                   2721:         } else { 
                   2722:             $status .= ' '.&mt('You were required to pass [quant,_1,optional component].',$counts->{'opt_req'});
                   2723:         }
1.197     albertel 2724:     }
                   2725:     return $status;
                   2726: }
                   2727: 
                   2728: sub get_counts {
                   2729:     my ($dim,$instance,$parstack,$safeeval) = @_;
                   2730:     my %counts;
                   2731:     my @possible = ('man_cri','man_dim',
                   2732: 		    'opt_cri','opt_dim',
                   2733: 		    'man_cri_passed', 'man_dim_passed',
                   2734: 		    'opt_cri_passed', 'opt_dim_passed',
                   2735: 		    'man_passed',
                   2736: 		    'opt_passed',
                   2737: 		    'opt_req');
                   2738:     foreach my $which (@possible) { $counts{$which} = 0; }
                   2739: 
                   2740:     my $version = &get_version();
                   2741: 
                   2742:     foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
                   2743: 		     @{$dimension{$dim}{'criterias'}} ) {
                   2744: 	my $status = &get_criteria('status',$version,$dim,$id);
                   2745: 	my $which;
                   2746: 	if ($dimension{$dim}{'criteria.'.$id.'.mandatory'} 
                   2747: 	    eq 'N') {
                   2748: 	    $which = 'opt';
                   2749: 	} else {
                   2750: 	    $which = 'man';
                   2751: 	}
                   2752: 	$counts{$which}++;
                   2753: 	if ($status eq 'pass') { $counts{$which.'_passed'}++; }
                   2754: 	if ($dimension{$dim}{'criteria.'.$id.'.type'}
                   2755: 	    eq 'dimension') {
                   2756: 	    $which .= '_dim';
                   2757: 	} else {
                   2758: 	    $which .= '_cri';
                   2759: 	}
                   2760: 	$counts{$which}++;
                   2761: 	if ($status eq 'pass') { $counts{$which.'_passed'}++; }
                   2762: 
                   2763: 
                   2764:     }
                   2765:     if ($counts{'man_dim_passed'} eq $counts{'man_dim'}) {
                   2766: 	$counts{'man_dim_passed'}='all';
                   2767:     }
                   2768:     if ($counts{'man_cri_passed'} eq $counts{'man_cri'}) {
                   2769: 	$counts{'man_cri_passed'}='all';
                   2770:     }
                   2771:     
                   2772:     $counts{'opt_req'}=$dimension{$dim}{$instance.'.optionalrequired'};
                   2773:     if ($counts{'opt_req'} !~ /\S/) {
                   2774: 	$counts{'opt_req'}= &Apache::lonxml::get_param('OptionalRequired',
                   2775: 						       $parstack,$safeeval);
                   2776: 	if ($counts{'opt_req'} !~ /\S/) { $counts{'opt_req'} = 0; }
                   2777:     }
                   2778:     return %counts;
                   2779: }
                   2780: 
1.194     albertel 2781: sub end_Setup {
                   2782:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225     albertel 2783:     my $result;
1.194     albertel 2784:     my $dim=&get_id($parstack,$safeeval);
                   2785:     my $instance=&get_instance($dim);
                   2786:     my $version=&get_version();
1.225     albertel 2787:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
                   2788: 	$result=&Apache::lonxml::endredirection();
                   2789:     }
1.194     albertel 2790:     if ($target eq 'web') {
                   2791: 	@Apache::scripttag::parser_env = @_;
                   2792: 	$result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
                   2793: 	my @instances = $instance;
                   2794: 	if (&Apache::response::showallfoils()) {
                   2795: 	    @instances = @{$dimension{$dim}{'instances'}};
                   2796: 	}
                   2797: 	foreach my $instance (@instances) {
1.162     albertel 2798: 	    @Apache::scripttag::parser_env = @_;
1.194     albertel 2799: 	    $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162     albertel 2800: 	    @Apache::scripttag::parser_env = @_;
1.194     albertel 2801: 	    $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162     albertel 2802: 	}
1.194     albertel 2803:     } elsif ($target eq 'webgrade' 
                   2804: 	     || $target eq 'grade' && $env{'form.webgrade'}) {
                   2805: 	# in case of any side effects that we need
                   2806: 	@Apache::scripttag::parser_env = @_;
                   2807: 	&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
                   2808: 	@Apache::scripttag::parser_env = @_;
                   2809: 	&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
                   2810: 	@Apache::scripttag::parser_env = @_;
                   2811: 	&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
                   2812:     } else {
                   2813: 	# any other targets no output
                   2814: 	undef($result);
1.162     albertel 2815:     }
1.194     albertel 2816:     pop(@Apache::bridgetask::dimension);
                   2817:     return $result;
1.1       albertel 2818: }
                   2819: 
1.113     albertel 2820: sub grading_history {
1.151     albertel 2821:     my ($version,$dim,$id) = @_;
1.235     albertel 2822:     if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})
                   2823: 	&& !&Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
1.113     albertel 2824: 	return '';
                   2825:     }
                   2826:     my ($result,$grader);
1.194     albertel 2827:     my $scope="resource.$version.0.";
                   2828:     $scope .= ($dim ne $top) ? "$dim.$id"
                   2829: 	                     : "$id";
1.113     albertel 2830:     foreach my $t (1..$Apache::lonhomework::history{'version'}) {
                   2831: 	if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
                   2832: 	    my ($gname,$gdom) = 
1.138     albertel 2833: 		split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113     albertel 2834: 	    my $fullname = &Apache::loncommon::plainname($gname,$gdom);
                   2835: 	    $grader = &Apache::loncommon::aboutmewrapper($fullname,
                   2836: 							 $gname,$gdom);
                   2837: 	}
                   2838: 	my $entry;
                   2839: 	if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
                   2840: 	    $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
                   2841: 	}
                   2842: 	if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
                   2843: 	    $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
                   2844: 	}
                   2845: 	if ($entry) {
1.200     albertel 2846: 	    $result.= "\n\t\t<li>\n\t\t\t$grader :\n\t\t\t $entry \n\t\t</li>";
1.113     albertel 2847: 	}
                   2848:     }
                   2849:     if ($result) {
1.200     albertel 2850: 	return "\n\t".'<ul class="LC_GRADING_pastgrading">'.$result.
                   2851: 	    "\n\t".'</ul>'."\n";
1.113     albertel 2852:     }
                   2853:     return '';
                   2854: }
                   2855: 
1.1       albertel 2856: sub start_IntroParagraph {
1.87      albertel 2857:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1       albertel 2858:     my $result;
1.168     albertel 2859:     my $dim = &get_dim_id();
1.153     albertel 2860:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151     albertel 2861: 	if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169     albertel 2862: 	    $dimension{$dim}{'intro'}=
1.151     albertel 2863: 		&Apache::lonxml::get_all_text('/introparagraph',
                   2864: 					      $parser,$style);
                   2865:        	} elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2866: 	    &Apache::lonxml::startredirection();
1.1       albertel 2867: 	}
1.47      albertel 2868: 	
1.225     albertel 2869:     } elsif ($target eq 'edit') {
                   2870: 	$result = &Apache::edit::tag_start($target,$token);
                   2871:     } elsif ($target eq 'modified') {
1.1       albertel 2872:     }
                   2873:     return $result;
                   2874: }
                   2875: 
                   2876: sub end_IntroParagraph {
1.127     albertel 2877:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128     albertel 2878:     if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2879: 	my $result = &Apache::lonxml::endredirection();
                   2880:     }
1.1       albertel 2881: }
                   2882: 
1.227     albertel 2883: sub insert_IntroParagraph {
                   2884:     return '
                   2885: <IntroParagraph>
                   2886:     <startouttext />
                   2887:     <endouttext />
                   2888: </IntroParagraph>';
                   2889: }
                   2890: 
1.1       albertel 2891: sub start_Instance {
                   2892:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168     albertel 2893:     my $dim = &get_dim_id();
                   2894:     my $id  = &get_id($parstack,$safeeval);
1.169     albertel 2895:     push(@{$dimension{$dim}{'instances'}},$id);
1.168     albertel 2896:     push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19      albertel 2897:     push(@Apache::bridgetask::instancelist,$id);
1.169     albertel 2898:     $dimension{$dim}{$id.'.optionalrequired'}=
1.19      albertel 2899: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75      albertel 2900:     my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
                   2901:     if (lc($disabled) eq 'yes') {
1.169     albertel 2902: 	$dimension{$dim}{$id.'.disabled'}='1';
1.75      albertel 2903:     }
1.225     albertel 2904:     my $result;
                   2905:     if ($target eq 'edit') {
                   2906: 	$result = &Apache::edit::tag_start($target,$token);
                   2907: 	$result.=  
                   2908: 	    &Apache::edit::text_arg('Id:','id',$token,10).' '.
                   2909: 	    &Apache::edit::select_arg('Instance is Disabled:','Disabled',
                   2910: 				      [['no', 'No'],
                   2911: 				       ['yes','Yes'],],
                   2912: 				      $token)
                   2913: 	    .' <br /> '.
                   2914: 	    &Apache::edit::text_arg('Required number of passed optional elements to pass the Instance:',
                   2915: 				    'OptionalRequired',$token,4)
                   2916: 	    .&Apache::edit::end_row().
                   2917: 	    &Apache::edit::start_spanning_row();
                   2918:     } elsif ($target eq 'modified') {
                   2919: 	my $constructtag=
                   2920: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
                   2921: 					'id','OptionalRequired','Disabled');
                   2922: 	if ($constructtag) {
                   2923: 	    $result = &Apache::edit::rebuild_tag($token);
                   2924: 	}
                   2925:     }
                   2926:     return $result;
1.1       albertel 2927: }
                   2928: 
                   2929: sub end_Instance {
1.225     albertel 2930:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   2931:     my $result;
                   2932:     if ($target eq 'edit') {
                   2933: 	$result = &Apache::edit::tag_end($target,$token);
                   2934:     }
                   2935:     return $result;
1.1       albertel 2936: }
                   2937: 
                   2938: sub start_InstanceText {
1.87      albertel 2939:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225     albertel 2940:     my $result;
1.153     albertel 2941:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.225     albertel 2942: 	my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
                   2943: 	my $dim = &get_dim_id();
                   2944: 	my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169     albertel 2945: 	$dimension{$dim}{$instance_id.'.text'}=$text;
1.225     albertel 2946:     } elsif ($target eq 'edit') {
                   2947: 	$result = &Apache::edit::tag_start($target,$token);
                   2948:     } elsif ($target eq 'modified') {
1.1       albertel 2949:     }
1.225     albertel 2950:     return $result;
1.1       albertel 2951: }
                   2952: 
                   2953: sub end_InstanceText {
                   2954:     return '';
                   2955: }
                   2956: 
1.227     albertel 2957: sub insert_InstanceText {
                   2958:     return '
                   2959: <InstanceText>
                   2960:     <startouttext />
                   2961:     <endouttext />
                   2962: </InstanceText>';
                   2963: }
                   2964: 
1.1       albertel 2965: sub start_Criteria {
1.87      albertel 2966:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.190     albertel 2967:     my $result = '';
1.21      albertel 2968:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.225     albertel 2969: 	my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.168     albertel 2970: 	my $dim = &get_dim_id();
1.19      albertel 2971: 	my $id=&get_id($parstack,$safeeval);
1.194     albertel 2972: 	if ($target eq 'web' || $target eq 'webgrade') {
1.208     albertel 2973: 	    if ($target eq 'webgrade') {
1.195     albertel 2974: 		&Apache::lonxml::debug(" for $dim $id stashing results into $dim ");
                   2975: 		$dimension{$dim}{'result'} .= &internal_location($id);
                   2976: 	    } else {
                   2977: 		&Apache::lonxml::debug(" not stashing $dim $id");
1.206     albertel 2978: 		#$result .= &internal_location($id);
1.195     albertel 2979: 	    }
1.194     albertel 2980: 	}
1.169     albertel 2981: 	&Apache::lonxml::debug("Criteria $id with $dim");
1.151     albertel 2982: 	if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168     albertel 2983: 	    my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169     albertel 2984: 	    $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
                   2985: 	    $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
                   2986: 	    $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151     albertel 2987: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169     albertel 2988: 	    push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151     albertel 2989: 	} else {
1.169     albertel 2990: 	    $dimension{$dim}{'criteria.'.$id}=$criteria;
                   2991: 	    $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
                   2992: 	    $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151     albertel 2993: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169     albertel 2994: 	    push(@{$dimension{$dim}{'criterias'}},$id);
1.194     albertel 2995: 	}
1.225     albertel 2996:     } elsif ($target eq 'edit') {
                   2997: 	$result .=&Apache::edit::tag_start($target,$token);
                   2998: 	$result.=  
                   2999: 	    &Apache::edit::text_arg('Id:','id',$token,10).' '.
                   3000: 	    &Apache::edit::select_arg('Passing is Mandatory:','Mandatory',
1.233     albertel 3001: 				      [['Y', 'Yes'],
                   3002: 				       ['N','No'],],
1.225     albertel 3003: 				      $token)
                   3004: 	    .' <br /> '.&Apache::edit::end_row().
                   3005: 	    &Apache::edit::start_spanning_row();
                   3006:     } elsif ($target eq 'modified') {
                   3007: 	my $constructtag=
                   3008: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
                   3009: 					'id','Mandatory');
                   3010: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.194     albertel 3011:     }
                   3012:     return $result;
                   3013: }
                   3014: 
                   3015: sub layout_web_Criteria {
                   3016:     my ($dim,$id,$criteria) = @_;
1.190     albertel 3017: 
1.194     albertel 3018:     my $version = &get_version();
                   3019:     my $status= &get_criteria('status', $version,$dim,$id);
                   3020:     my $comment=&get_criteria('comment',$version,$dim,$id);
                   3021:     my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
                   3022:     if ($mandatory) {
                   3023: 	$mandatory='Mandatory';
                   3024:     } else {
                   3025: 	$mandatory='Optional';
1.1       albertel 3026:     }
1.194     albertel 3027:     my $status_display=$status;
                   3028:     $status_display=~s/^([a-z])/uc($1)/e;
                   3029:     my $criteria_info.=
1.200     albertel 3030: 	'<div class="LC_'.$status.' LC_criteria">'."\n\t".'<h4>'
1.204     albertel 3031: 	.$mandatory.' Criteria</h4>'."\n\t".'<p class="LC_criteria_text">'
                   3032: 	."\n";
1.202     albertel 3033:     $criteria =~ s/^\s*//s;
                   3034:     $criteria =~ s/\s*$//s;
1.194     albertel 3035:     $criteria_info.= $criteria;
1.200     albertel 3036:     $criteria_info.="\n\t".'</p>'.
                   3037: 	"\n\t".'<p class="LC_grade">'.$status_display.'</p>';
1.194     albertel 3038:     if ($comment =~ /\w/) {
1.200     albertel 3039: 	$criteria_info.=
                   3040: 	    "\n\t".
                   3041: 	    '<p class="LC_comment">'.&mt('Comment: [_1]',$comment).'</p>';
1.194     albertel 3042:     }
1.200     albertel 3043:     $criteria_info.="\n".'</div>'."\n";
                   3044:     
1.194     albertel 3045:     return $criteria_info;
                   3046: }
                   3047: 
                   3048: sub layout_webgrade_Criteria {
                   3049:     my ($dim,$id,$criteria) = @_;
                   3050:     my $link=&link($id);
                   3051:     my $version = &get_version();
                   3052:     my $status  = &get_criteria('status',$version,$dim,$id);
1.245     bisitz   3053:     my %lt = &Apache::lonlocal::texthash(
                   3054:         'ungraded' => 'Ungraded',
                   3055:         'fail'     => 'Fail',
                   3056:         'pass'     => 'Pass',
                   3057:         'review'   => 'Review',
                   3058:         'comment'  => 'Additional Comment for Student',
                   3059:     );
1.200     albertel 3060:     my $comment = &get_criteria('comment',$version,$dim,$id);
                   3061:     $comment = &HTML::Entities::encode($comment,'<>"&');
                   3062:     my %checked;
                   3063:     foreach my $which ('ungraded','fail','pass','review') {
1.249     bisitz   3064: 	if ($status eq $which) { $checked{$which} = ' checked="checked"'; }
1.200     albertel 3065:     }
1.249     bisitz   3066:     if (!%checked) { $checked{'ungraded'} = ' checked="checked"'; }
1.201     albertel 3067:     my $buttons;
                   3068:     foreach my $which  ('ungraded','fail','pass','review') {
                   3069: 	$buttons .= <<END_BUTTON;
                   3070: 		<label class="LC_GRADING_$which">
1.249     bisitz   3071: 			<input type="radio" name="HWVAL_$link" value="$which"$checked{$which} />
1.201     albertel 3072: 			$lt{$which}
                   3073: 		</label>
                   3074: END_BUTTON
                   3075:     }
1.202     albertel 3076:     $criteria =~ s/^\s*//s;
                   3077:     $criteria =~ s/\s*$//s;
1.200     albertel 3078:     my $result = <<END_CRITERIA;
1.201     albertel 3079: <div class="LC_GRADING_criteria">
                   3080: 	<div class="LC_GRADING_criteriatext">
                   3081: 		$criteria
                   3082: 	</div>
                   3083: 	<div class="LC_GRADING_grade">
                   3084: $buttons
                   3085: 	</div>
                   3086: 	<label class="LC_GRADING_comment">
                   3087: 		$lt{'comment'}
                   3088: 		<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_$link">$comment</textarea>
                   3089: 	</label>
                   3090: </div>
1.200     albertel 3091: END_CRITERIA
                   3092:     $result .= &grading_history($version,$dim,$id);
1.190     albertel 3093:     return $result;
1.1       albertel 3094: }
                   3095: 
1.47      albertel 3096: sub end_Criteria {
1.225     albertel 3097:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   3098:     if ($target eq 'edit') {
                   3099:     } elsif ($target eq 'modified') {
                   3100:     }
                   3101: }
1.227     albertel 3102: sub insert_Criteria {
                   3103:     return '
                   3104: <Criteria>
                   3105:     <CriteriaText>
                   3106:         <startouttext />
                   3107:         <endouttext />
                   3108:     </CriteriaText>
                   3109: </Criteria>';
                   3110: }
1.225     albertel 3111: 
                   3112: sub start_CriteriaText {
                   3113:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   3114:     my $result;
                   3115:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   3116: 	
                   3117:     } elsif ($target eq 'edit') {
                   3118: 	$result = &Apache::edit::tag_start($target,$token);
                   3119:     } elsif ($target eq 'modified') {
                   3120:     }
                   3121:     return $result;
                   3122: }
                   3123: 
                   3124: sub end_CriteriaText {
                   3125:     return '';
1.47      albertel 3126: }
                   3127: 
1.227     albertel 3128: sub insert_CriteriaText {
                   3129:     return '
                   3130: <CriteriaText>
                   3131:     <startouttext />
                   3132:     <endouttext />
                   3133: </CriteriaText>';
                   3134: }
                   3135: 
1.186     albertel 3136: sub start_GraderNote {
                   3137:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225     albertel 3138:     my $result;
1.186     albertel 3139:     if ($target eq 'webgrade') {
1.225     albertel 3140: 	$result = '<div class="LC_GRADING_gradernote"><b>'.
1.187     albertel 3141: 	    &mt('Note to graders:').'</b>';
1.225     albertel 3142:     } elsif ($target eq 'edit') {
                   3143: 	$result = &Apache::edit::tag_start($target,$token);
                   3144:     } elsif ($target eq 'modified') {
                   3145:     } elsif ($target eq 'web' || $target eq 'grade') {
                   3146: 	my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style); 
1.186     albertel 3147:     }
1.225     albertel 3148:     return $result;
1.186     albertel 3149: }
                   3150: 
                   3151: sub end_GraderNote {
                   3152:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   3153: 
                   3154:     if ($target eq 'webgrade') {
                   3155: 	return '</div>';
                   3156:     }
                   3157:     return;
                   3158: }
                   3159: 
1.227     albertel 3160: sub insert_GraderNote {
                   3161:     return '
                   3162: <GraderNote>
                   3163:     <startouttext />
                   3164:     <endouttext />
                   3165: </GraderNote>';
                   3166: }
1.186     albertel 3167: 
                   3168: 
1.4       albertel 3169: sub proctor_validation_screen {
                   3170:     my ($slot) = @_;
1.185     albertel 3171:     my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
1.5       albertel 3172:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.230     albertel 3173:     if ($url ne '/adm/lonKaputt/lonlogo_broken.gif') {
                   3174: 	$url = "<tr><td colspan=\"2\"><img src=\"$url\" /></td></tr>";
                   3175:     } else {
                   3176: 	undef($url);
                   3177:     }
                   3178: 
1.44      albertel 3179:     my $name=&Apache::loncommon::plainname($user,$domain);
                   3180:     
1.4       albertel 3181:     my $msg;
1.11      albertel 3182:     if ($env{'form.proctorpassword'}) {
1.230     albertel 3183: 	$msg.='<p><span class="LC_warning">'
                   3184: 	    .&mt("Failed to authenticate the proctor.")
                   3185: 	    .'</span></p>';
1.4       albertel 3186:     }
1.230     albertel 3187: 
                   3188:     my $valid;
                   3189:     my @possible_proctors=split(",",$slot->{'proctor'});
                   3190:     foreach my $proctor (@possible_proctors) {
                   3191: 	if ($proctor =~ /$LONCAPA::username_re:$LONCAPA::domain_re/) {
                   3192: 	    $valid = 1;
                   3193: 	    last;
                   3194: 	}
                   3195:     }
                   3196:     if (!$valid) {
                   3197: 	$msg.='<p><span class="LC_error">'
1.239     bisitz   3198: 	    .&mt("No valid proctors are defined.")
1.230     albertel 3199: 	    .'</span></p>';
                   3200:     }
                   3201:     
1.47      albertel 3202:     if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.229     albertel 3203:     my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
                   3204:     $uri = &HTML::Entities::encode($uri,'<>&"');
1.241     raeburn  3205:     my %lt = &Apache::lonlocal::texthash(
                   3206:                             'prva' => "Proctor Validation",
                   3207:                             'yoro' => "Your room's proctor needs to validate your access to this resource.",
                   3208:                             'prus'  => "Proctor's Username:",
                   3209:                             'pasw'  => "Password:",
                   3210:                             'prdo'  => "Proctor's Domain:",
                   3211:                             'vali'  => 'Validate',
                   3212:                             'stui'  => "Student who should be logged in is:",
                   3213:                             'name'  => "Name:",
1.251     raeburn  3214:                             'sid'   => "Student/Employee ID",
1.241     raeburn  3215:                             'unam'  => "Username:",
                   3216:                            );
1.4       albertel 3217:     my $result= (<<ENDCHECKOUT);
1.241     raeburn  3218: <h2>$lt{'prva'}</h2>
                   3219:     <p>$lt{'yoro'}</p>
1.4       albertel 3220:     $msg
1.229     albertel 3221: <form name="checkout" method="post" action="$uri">
1.4       albertel 3222: <input type="hidden" name="validate" value="yes" />
                   3223: <input type="hidden" name="submitted" value="yes" />
                   3224: <table>
1.241     raeburn  3225:   <tr><td>$lt{'prus'}</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
                   3226:   <tr><td>$lt{'pasw'}</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
                   3227:   <tr><td>$lt{'prdo'}</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4       albertel 3228: </table>
1.241     raeburn  3229: <input type="submit" name="checkoutbutton" value="$lt{'vali'}"  /><br />
1.44      albertel 3230: <table border="1">
                   3231:   <tr><td>
                   3232:     <table>
1.241     raeburn  3233:       <tr><td colspan="2">$lt{'stui'}</td></tr>
                   3234:       <tr><td>$lt{'name'}</td><td>$name</td></tr>
                   3235:       <tr><td>$lt{'sid'}</td><td>$env{'environment.id'}</td></tr>
                   3236:       <tr><td>$lt{'unam'}</td><td>$user:$domain</td></tr>
1.230     albertel 3237:       $url
1.44      albertel 3238:     </table>
                   3239:   </tr></td>
                   3240: </table>
1.4       albertel 3241: </form>
                   3242: ENDCHECKOUT
1.241     raeburn  3243: 
1.4       albertel 3244:     return $result;
                   3245: }
                   3246: 
1.1       albertel 3247: 1;
                   3248: __END__

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