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

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

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