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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.253   ! raeburn     4: # $Id: bridgetask.pm,v 1.252 2010/08/23 03:24:01 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') {
1.248     foxr      717: 		$result.='\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
1.1       albertel  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.252     raeburn  1088:                     my ($portheader,$porttext);
                   1089:                     if ($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"}) {
                   1090:                         $portheader = &mt('Submit Additional Portfolio Files for Grading');
                   1091:                         $porttext = &mt('Indicate which additional files from your portfolio are to be evaluated in grading this task.');
                   1092:                     } else {
                   1093:                         $portheader = &mt('Submit Portfolio Files for Grading');
                   1094:                         $porttext = &mt('Indicate the files from your portfolio to be evaluated in grading this task.');
                   1095:                     }
                   1096: 		    $result.="\n".'<p>'.&Apache::lonhtmlcommon::start_pick_box().
1.28      albertel 1097: 			&Apache::inputtags::file_selector("$version.0",
                   1098: 							  "bridgetask","*",
1.46      albertel 1099: 							  'portfolioonly',
1.252     raeburn  1100:                                                           '<h3>'.$portheader.'</h3><br />'.
                   1101:                                                           $porttext.'<br />').
                   1102: 			&Apache::lonhtmlcommon::end_pick_box().'</p>';
1.77      albertel 1103: 		}
1.78      albertel 1104: 		if (!$previous && $status ne 'SHOW_ANSWER' &&
                   1105: 		    &show_task($status,$previous)) {
1.232     albertel 1106: 		    $result.=&Apache::inputtags::gradestatus('0',$target,1);
1.199     albertel 1107: 		}
                   1108: 		
                   1109: 		$result.='</form>';
                   1110: 
                   1111: 		if (!$previous && $status ne 'SHOW_ANSWER' &&
                   1112: 		    &show_task($status,$previous)) {
1.116     albertel 1113: 		    my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.241     raeburn  1114:                     my $donetext = &mt('Done');
1.64      albertel 1115: 		    $result.=<<DONEBUTTON;
1.115     albertel 1116: <form name="done" method="post" action="$action">
1.64      albertel 1117:    <input type="hidden" name="donescreen" value="1" />
1.241     raeburn  1118:    <input type="submit" value="$donetext" />
1.64      albertel 1119: </form>
                   1120: DONEBUTTON
1.77      albertel 1121:                 }
1.56      albertel 1122: 		if (&show_task($status,$previous) &&
1.89      albertel 1123: 		    $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
                   1124: 		    my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1.231     albertel 1125: 		    my $title=&Apache::lonnet::gettitle($env{'request.uri'});
1.149     albertel 1126: 		    my $start_time;
                   1127: 
1.80      albertel 1128: 		    my $slot_name=
1.89      albertel 1129: 			$Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1.149     albertel 1130: 		    if ($slot_name) {
                   1131: 			my %slot=&Apache::lonnet::get_slot($slot_name);
                   1132: 
                   1133: 			$start_time=$slot{'starttime'}
                   1134: 		    } else {
                   1135: 			$start_time= 
                   1136: 			    &Apache::lonnet::EXT('resource.0.opendate');
                   1137: 		    }
                   1138: 		    $start_time=&Apache::lonlocal::locallocaltime($start_time);
1.54      albertel 1139: 
1.200     albertel 1140: 		    my $status = 
1.213     albertel 1141: 			"\n<div class='LC_$bt_status LC_criteria LC_task_overall_status'>\n\t";
1.54      albertel 1142: 		    
1.213     albertel 1143: 		    my $dim = $top;
                   1144: 		    my %counts = &get_counts($dim,undef,$parstack,
                   1145: 					     $safeeval);
                   1146: 		    my $question_status ="\n\t<p>".
                   1147: 			&question_status_message(\%counts,-1).
                   1148: 			"</p>\n";
                   1149: 
1.54      albertel 1150: 		    if ($bt_status eq 'pass')  {
1.239     bisitz   1151: 			$status.='<h2>'
                   1152:                                 .&mt('You passed the [_1] given on [_2].',$title,$start_time)
                   1153:                                 .'</h2>';
1.213     albertel 1154: 			$status.=$question_status;
1.54      albertel 1155: 		    }
                   1156: 		    if ($bt_status eq 'fail')  {
1.239     bisitz   1157: 			$status.='<h2>'
                   1158:                                 .&mt('You did not pass the [_1] given on [_2].',$title,$start_time)
                   1159:                                 .'</h2>';
1.213     albertel 1160: 			$status.=$question_status;
1.54      albertel 1161: 			if (!$previous) {
                   1162: 			    $status.=&add_request_another_attempt_button();
                   1163: 			}
                   1164: 		    }
1.213     albertel 1165: 		    
1.200     albertel 1166: 		    $status.="\n".'</div>'."\n";
1.194     albertel 1167: 
                   1168: 		    foreach my $id (@{$dimension{$dim}{'criterias'}}) {
                   1169: 			my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   1170: 			if ($type eq 'dimension') {
                   1171: 			    $result.=$dimension{$id}{'result'};
                   1172: 			    next;
                   1173: 			}
                   1174: 			my $criteria = 
                   1175: 			    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   1176: 					  [@_]);
                   1177: 			$status .= &layout_web_Criteria($dim,$id,$criteria);
                   1178: 		    }
1.54      albertel 1179: 
                   1180: 		    my $internal_location=&internal_location();
                   1181: 		    $result=~s/\Q$internal_location\E/$status/;
                   1182: 		}
1.142     albertel 1183: 		$result.="\n</div>\n".
                   1184: 		    &Apache::loncommon::end_page({'discussion' => 1});
1.1       albertel 1185: 	    }
                   1186: 	}
1.181     albertel 1187: 
                   1188: 	my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
                   1189: 	my %queue_data = ('type' => 'Task',
                   1190: 			  'time' => time,);
                   1191: 	if (defined($Apache::inputtags::slot_name)) {
                   1192: 	    $queue_data{'slot'} = $Apache::inputtags::slot_name;
                   1193: 	} elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) {
                   1194: 	    $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
                   1195: 	}
                   1196: 	
                   1197: 
1.215     albertel 1198: 	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous
                   1199: 	    && $status eq 'CAN_ANSWER') {
1.12      albertel 1200: 	    my $award='SUBMITTED';
1.252     raeburn  1201:             my $uploadedflag=0;
                   1202:             my $totalsize=0;
                   1203:             my @deletions = &Apache::loncommon::get_env_multiple('form.HWFILE'.$version.'_0_bridgetask_delete');
1.28      albertel 1204: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.252     raeburn  1205: 						    \$award,\$uploadedflag,\$totalsize,\@deletions);
1.14      albertel 1206: 	    if ($award eq 'SUBMITTED' &&
1.28      albertel 1207: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
                   1208: 		$Apache::lonhomework::results{"resource.0.tries"}=
                   1209: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
                   1210: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
                   1211: 
                   1212: 		$Apache::lonhomework::results{"resource.0.award"}=
                   1213: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
                   1214: 		    $award;
1.51      albertel 1215: 		$Apache::lonhomework::results{"resource.0.submission"}=
                   1216: 		    $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64      albertel 1217: 	    } else {
1.252     raeburn  1218:                 unless($uploadedflag) {
                   1219:                     delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
                   1220:                 }
1.77      albertel 1221: 		$award = '';
1.10      albertel 1222: 	    }
1.4       albertel 1223: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                   1224: 	    &Apache::structuretags::finalize_storage();
1.148     albertel 1225: 	    if ($award eq 'SUBMITTED') {
1.181     albertel 1226: 		&add_to_queue('gradingqueue',\%queue_data);
1.14      albertel 1227: 	    }
1.1       albertel 1228: 	}
1.163     albertel 1229: 	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' 
                   1230: 	    && exists($env{'form.cancel'})) {
                   1231: 	    &check_queue_unlock($env{'form.queue'});
                   1232: 	    &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
                   1233: 	} elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' 
                   1234: 		 && !exists($env{'form.cancel'})) {
1.20      albertel 1235: 	    my $optional_required=
                   1236: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                   1237: 					   $safeeval);
                   1238: 	    my $optional_passed=0;
                   1239: 	    my $mandatory_failed=0;
                   1240: 	    my $ungraded=0;
                   1241: 	    my $review=0;   
1.21      albertel 1242: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.194     albertel 1243: 	    my $dim = $top;
                   1244: 	    foreach my $id (@{$dimension{$dim}{'criterias'}}) {
                   1245: 		my $link=&link($id);
                   1246: 
                   1247: 		my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   1248: 
                   1249: 		if ($type eq 'criteria') {
                   1250: 		    # dimensional 'criteria' don't get assigned grades
                   1251: 		    $Apache::lonhomework::results{"resource.$version.0.$id.status"}=$env{'form.HWVAL_'.$link};
                   1252: 		    $Apache::lonhomework::results{"resource.$version.0.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
                   1253: 		} 
1.20      albertel 1254: 		my $status=
1.194     albertel 1255: 		    $Apache::lonhomework::results{"resource.$version.0.$id.status"};
                   1256: 		my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
                   1257: 
1.20      albertel 1258: 		if ($status eq 'pass') {
                   1259: 		    if (!$mandatory) { $optional_passed++; }
                   1260: 		} elsif ($status eq 'fail') {
                   1261: 		    if ($mandatory) { $mandatory_failed++; }
1.194     albertel 1262: 		} elsif ($status eq 'review') {
                   1263: 		    $review++;
1.20      albertel 1264: 		} elsif ($status eq 'ungraded') {
                   1265: 		    $ungraded++;
1.49      albertel 1266: 		} else {
                   1267: 		    $ungraded++;
                   1268: 		}
1.20      albertel 1269: 	    }
                   1270: 	    if ($optional_passed < $optional_required) {
                   1271: 		$mandatory_failed++;
                   1272: 	    }
1.194     albertel 1273: 	    &Apache::lonxml::debug(" task results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.89      albertel 1274: 	    $Apache::lonhomework::results{'resource.0.regrader'}=
1.138     albertel 1275: 		$env{'user.name'}.':'.$env{'user.domain'};
1.20      albertel 1276: 	    if ($review) {
1.89      albertel 1277: 		$Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.20      albertel 1278: 	    } elsif ($ungraded) {
1.89      albertel 1279: 		$Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.20      albertel 1280: 	    } elsif ($mandatory_failed) {
1.89      albertel 1281: 		$Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25      albertel 1282: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                   1283: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                   1284: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.185     albertel 1285: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52      albertel 1286: 		
                   1287: 		if ($env{'form.regrade'} ne 'yes') {
                   1288: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                   1289: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                   1290: 		    &Apache::grades::version_portfiles(
                   1291: 						       \%Apache::lonhomework::results,
                   1292: 						       ["$version.0.bridgetask"],$courseid,
                   1293: 						       $symb,$udom,$uname,
                   1294: 						       ["$version.0.bridgetask"]);
                   1295: 		}
1.20      albertel 1296: 	    } else {
1.89      albertel 1297: 		$Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25      albertel 1298: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                   1299: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                   1300: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.185     albertel 1301: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52      albertel 1302: 		if ($env{'form.regrade'} ne 'yes') {
                   1303: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                   1304: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                   1305: 		    &Apache::grades::version_portfiles(
                   1306: 						       \%Apache::lonhomework::results,
                   1307: 						       ["$version.0.bridgetask"],$courseid,
                   1308: 						       $symb,$udom,$uname,
                   1309: 						       ["$version.0.bridgetask"]);
                   1310: 		}
1.20      albertel 1311: 	    }
1.89      albertel 1312: 	    $Apache::lonhomework::results{"resource.0.status"}=
                   1313: 		$Apache::lonhomework::results{"resource.$version.0.status"};
1.28      albertel 1314: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel 1315: 		$Apache::lonhomework::results{"resource.0.award"}=
1.50      albertel 1316: 		    $Apache::lonhomework::results{"resource.$version.0.award"};
1.26      albertel 1317: 		$Apache::lonhomework::results{"resource.0.awarded"}=
1.50      albertel 1318: 		    $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26      albertel 1319: 		$Apache::lonhomework::results{"resource.0.solved"}=
1.50      albertel 1320: 		    $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25      albertel 1321: 	    }
1.94      albertel 1322: 	    &minimize_storage();
1.250     raeburn  1323:             my $canstore;
                   1324:             if ($env{'form.gradingkey'}) {
                   1325:                 my ($symb,$courseid,$domain,$name) =
                   1326:                     &Apache::lonnet::whichuser();
                   1327:                 my $todo=&unescape($env{'form.gradingkey'});
                   1328:                 my ($keysymb,$uname,$udom)=&decode_queue_key($todo);
                   1329:                 if ($symb eq $keysymb) {
                   1330:                     if (($domain eq $udom) && ($name eq $uname)) {
                   1331:                         $canstore = 1;           
                   1332:                     }
                   1333:                 }
                   1334:             }
                   1335:             if ($canstore) {
                   1336: 	        &Apache::structuretags::finalize_storage();
1.253   ! raeburn  1337: 	        # data stored, now handle queue
        !          1338: 	        if ($review) {
        !          1339: 		    if ($env{'form.queue'} eq 'reviewqueue') {
        !          1340: 		        &check_queue_unlock($env{'form.queue'});
        !          1341: 		        &Apache::lonxml::debug(" still needs review not changing status.");
        !          1342: 		    } else {
        !          1343: 		        if ($env{'form.queue'} ne 'none') {
        !          1344: 			    &move_between_queues($env{'form.queue'},'reviewqueue');
        !          1345: 		        } else {
        !          1346: 			    &add_to_queue('reviewqueue',\%queue_data);
        !          1347: 		        }
        !          1348: 		    }
        !          1349: 	        } elsif ($ungraded) {
        !          1350: 		    if ($env{'form.queue'} eq 'reviewqueue') {
        !          1351: 		        &Apache::lonxml::debug("moving back.");
        !          1352: 		        &move_between_queues($env{'form.queue'},
        !          1353: 					     'gradingqueue');
        !          1354: 		    } elsif ($env{'form.queue'} eq 'none' ) {
        !          1355: 		        &add_to_queue('gradingqueue',\%queue_data);	
        !          1356: 		    } else {
        !          1357: 		        &check_queue_unlock($env{'form.queue'});
        !          1358: 		    }
        !          1359: 	        } elsif ($mandatory_failed) {
        !          1360: 		    &remove_from_queue($env{'form.queue'}); 
        !          1361: 	        } else {
        !          1362: 		    &remove_from_queue($env{'form.queue'});
        !          1363: 	        }
1.250     raeburn  1364:             } else {
1.253   ! raeburn  1365:                 &check_queue_unlock($env{'form.queue'});
1.250     raeburn  1366:                 $result .= '<br /><div class="LC_error">'.
1.253   ! raeburn  1367:                            &mt('Information extracted from the current gradingkey was for a different BT or user from those for which grading data are to be stored.').' '.&mt('No grading changes stored.').'</div><br />';
1.250     raeburn  1368:             }
1.253   ! raeburn  1369:         }
1.184     albertel 1370: 	if (exists($Apache::lonhomework::results{'INTERNAL_store'})) {
1.240     bisitz   1371: 	    # instance generation occurred and hasn't yet been stored
1.184     albertel 1372: 	    &Apache::structuretags::finalize_storage();
                   1373: 	}
1.15      albertel 1374:     } elsif ($target eq 'webgrade') {
1.208     albertel 1375: 	if (&nest()) {
                   1376: 	    &Apache::lonxml::endredirection();
                   1377: 	    &end_delay();
                   1378: 	    $result.=$dimension{$top}{'result'};
                   1379: 	} else {
                   1380: 	    $result.=&Apache::lonxml::endredirection();
                   1381: 	}
1.194     albertel 1382: 	my $dim = $top;
                   1383: 	foreach my $id (@{$dimension{$dim}{'criterias'}} ) {
                   1384: 	    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   1385: 	    if ($type eq 'dimension') {
                   1386: 		# dimensional 'criteria' don't get assigned grades
                   1387: 		next;
                   1388: 	    } else {
                   1389: 		my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   1390: 					     [@_]);
                   1391: 		$criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
                   1392: 		my $internal_location=&internal_location($id);
1.209     albertel 1393: 		if ($result =~ m/\Q$internal_location\E/) {
                   1394: 		    $result=~s/\Q$internal_location\E/$criteria/;
                   1395: 		} else {
                   1396: 		    $result.=$criteria;
                   1397: 		}
                   1398: 
1.194     albertel 1399: 	    }
                   1400: 	}
                   1401:         $result.="</div>";
1.20      albertel 1402: 	#$result.='<input type="submit" name="next" value="'.
                   1403: 	#    &mt('Save &amp; Next').'" /> ';
                   1404: 	#$result.='<input type="submit" name="end" value="'.
                   1405: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                   1406: 	#$result.='<input type="submit" name="throwaway" value="'.
                   1407: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                   1408: 	#$result.='<input type="submit" name="save" value="'.
                   1409: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124     albertel 1410: 	$result.='</form>'."\n</div>\n</div>\n".
1.140     albertel 1411: 	    &Apache::loncommon::end_page();
1.1       albertel 1412:     } elsif ($target eq 'meta') {
1.70      albertel 1413: 	$result.=&Apache::response::meta_package_write('Task');
1.77      albertel 1414:         $result.=&Apache::response::meta_stores_write('solved','string',
                   1415: 						      'Problem Status');
                   1416: 	$result.=&Apache::response::meta_stores_write('tries','int_zeropos',
                   1417: 						      'Number of Attempts');
                   1418: 	$result.=&Apache::response::meta_stores_write('awarded','float',
                   1419: 						      'Partial Credit Factor');
                   1420: 	$result.=&Apache::response::meta_stores_write('status','string',
                   1421: 						      'Bridge Task Status');
1.182     albertel 1422:     } elsif ($target eq 'edit') {
1.227     albertel 1423: 	$result.= &Apache::structuretags::problem_edit_footer();
1.1       albertel 1424:     }
1.179     albertel 1425:     &Apache::structuretags::reset_problem_globals('Task');
1.4       albertel 1426:     undef($Apache::lonhomework::parsing_a_task);
1.250     raeburn  1427:     if ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                   1428:           $target eq 'webgrade') {
                   1429:         delete($env{'form.grade_symb'});
                   1430:         delete($env{'form.grade_domain'});
                   1431:         delete($env{'form.grade_username'});
                   1432:         delete($env{'form.grade_courseid'});
                   1433:     }
1.1       albertel 1434:     return $result;
                   1435: }
                   1436: 
1.31      albertel 1437: sub move_between_queues {
                   1438:     my ($src_queue,$dest_queue)=@_;
1.49      albertel 1439:     my $cur_data;
                   1440:     if ($src_queue ne 'none') {
                   1441: 	$cur_data=&get_queue_data($src_queue);
                   1442: 	if (!$cur_data) { return 'not_exist'; }
                   1443:     } else {
                   1444: 	$cur_data = ['none'];
                   1445:     }
1.148     albertel 1446:     my $result=&add_to_queue($dest_queue,$cur_data);
1.31      albertel 1447:     if ($result ne 'ok') {
                   1448: 	return $result;
                   1449:     }
                   1450:     &check_queue_unlock($src_queue);
                   1451:     return &remove_from_queue($src_queue);
1.21      albertel 1452: }
                   1453: 
                   1454: sub check_queue_unlock {
1.32      albertel 1455:     my ($queue,$key,$allow_not_me)=@_;
1.49      albertel 1456:     if ($queue eq 'none') { return 'ok'; }
1.185     albertel 1457:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.32      albertel 1458:     if (!defined($key)) {
1.138     albertel 1459: 	$key="$symb\0queue\0$uname:$udom";
1.32      albertel 1460:     }
1.30      albertel 1461:     my $cnum=$env{'course.'.$cid.'.num'};
                   1462:     my $cdom=$env{'course.'.$cid.'.domain'};
1.138     albertel 1463:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30      albertel 1464:     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
                   1465:     if  ($who eq $me) {
1.163     albertel 1466: 	&Apache::lonxml::debug("unlocking my own $who");
1.32      albertel 1467: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
                   1468:     } elsif ($allow_not_me) {
1.33      albertel 1469: 	&Apache::lonxml::debug("unlocking $who by $me");
1.32      albertel 1470: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30      albertel 1471:     }
1.32      albertel 1472:     return 'not_owner';
1.21      albertel 1473: }
                   1474: 
1.88      albertel 1475: sub in_queue {
                   1476:     my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
                   1477:     if ($queue eq 'none') { return 0; }
                   1478:     if (!defined($symb) || !defined($cdom) || !defined($cnum)
                   1479: 	|| !defined($udom) || !defined($uname)) {
1.185     albertel 1480: 	($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.88      albertel 1481: 	$cnum=$env{'course.'.$cid.'.num'};
                   1482: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1483:     }
                   1484: 
                   1485:     my $key=&encode_queue_key($symb,$udom,$uname);
                   1486:     my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
                   1487: 
                   1488:     if (defined($results{$key})) {
                   1489: 	return 1;
                   1490:     }
                   1491:     return 0;
                   1492: }
                   1493: 
1.21      albertel 1494: sub remove_from_queue {
1.86      albertel 1495:     my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49      albertel 1496:     if ($queue eq 'none') { return 'ok'; }
1.86      albertel 1497:     if (!defined($symb) || !defined($cdom) || !defined($cnum)
                   1498: 	|| !defined($udom) || !defined($uname)) {
1.185     albertel 1499: 	($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.86      albertel 1500: 	$cnum=$env{'course.'.$cid.'.num'};
                   1501: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1502:     }
1.88      albertel 1503:     if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
                   1504: 	return 'ok';
                   1505:     }
1.86      albertel 1506:     my $key=&encode_queue_key($symb,$udom,$uname);
1.27      albertel 1507:     my @keys=($key,"$key\0locked");
1.31      albertel 1508:     return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21      albertel 1509: }
                   1510: 
1.16      albertel 1511: sub setup_env_for_other_user {
                   1512:     my ($queue_key,$safeeval)=@_;
                   1513:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30      albertel 1514:     &Apache::lonxml::debug("setup_env for $queue_key");
1.16      albertel 1515:     $env{'form.grade_symb'}=$symb;
                   1516:     $env{'form.grade_domain'}=$udom;
                   1517:     $env{'form.grade_username'}=$uname;
                   1518:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                   1519:     &Apache::lonxml::initialize_rndseed($safeeval);
                   1520: }
                   1521: 
1.31      albertel 1522: sub get_queue_data {
1.165     albertel 1523:     my ($queue,$udom,$uname)=@_;
1.185     albertel 1524:     my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonnet::whichuser();
1.165     albertel 1525:     if (!$uname || !$udom) {
                   1526: 	$uname=$other_uname;
                   1527: 	$udom =$other_udom;
                   1528:     }
1.31      albertel 1529:     my $cnum=$env{'course.'.$cid.'.num'};
                   1530:     my $cdom=$env{'course.'.$cid.'.domain'};
1.138     albertel 1531:     my $todo="$symb\0queue\0$uname:$udom";
1.31      albertel 1532:     my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
                   1533:     if ($key eq $todo && ref($value)) {
                   1534: 	return $value;
                   1535:     }
                   1536:     return undef;
                   1537: }
                   1538: 
1.84      albertel 1539: 
1.49      albertel 1540: sub check_queue_for_key {
1.84      albertel 1541:     my ($cdom,$cnum,$queue,$todo)=@_;
                   1542: 
1.49      albertel 1543:     my %results=
                   1544: 	&Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
                   1545:     
                   1546:     if (exists($results{$todo}) && ref($results{$todo})) {
                   1547: 	if (defined($results{"$todo\0locked"})) {
                   1548: 	    return 'locked';
                   1549: 	}
1.148     albertel 1550: 	if (my $slot=&slotted_access($results{$todo})) {
1.86      albertel 1551: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1552: 	    if ($slot_data{'endtime'} > time) { 
                   1553: 		return 'in_progress';
                   1554: 	    }
1.148     albertel 1555: 	} else {
                   1556: 	    my ($symb) = &decode_queue_key($todo);
                   1557: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1558: 	    if ($due_date > time) {
                   1559: 		return 'in_progress';
                   1560: 	    }
1.58      albertel 1561: 	}
1.49      albertel 1562: 	return 'enqueued';
                   1563:     }
                   1564:     return undef;
                   1565: }
                   1566: 
1.14      albertel 1567: sub add_to_queue {
1.82      albertel 1568:     my ($queue,$user_data)=@_;
1.49      albertel 1569:     if ($queue eq 'none') { return 'ok'; }
1.185     albertel 1570:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.82      albertel 1571:     if (!$cid || $env{'request.state'} eq 'construct') {
                   1572: 	return 'no_queue';
                   1573:     }
1.14      albertel 1574:     my $cnum=$env{'course.'.$cid.'.num'};
                   1575:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1576:     my %data;
1.138     albertel 1577:     $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83      albertel 1578:     return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14      albertel 1579: }
                   1580: 
1.156     albertel 1581: sub get_limited_classlist {
                   1582:     my ($sections) = @_;
                   1583: 
                   1584:     my $classlist = &Apache::loncoursedata::get_classlist();
1.157     albertel 1585:     foreach my $student (keys(%$classlist)) {
                   1586: 	if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
                   1587: 	     ne 'Active') {
                   1588: 	    delete($classlist->{$student});
                   1589:        	}
                   1590:     }
1.156     albertel 1591: 
1.237     albertel 1592:     if (ref($sections) && !grep {$_ eq 'all'} (@{ $sections })) {
1.156     albertel 1593: 	foreach my $student (keys(%$classlist)) {
                   1594: 	    my $section  = 
                   1595: 		$classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1.237     albertel 1596: 	    if (! grep {$_ eq $section} (@{ $sections })) {
1.156     albertel 1597: 		delete($classlist->{$student});
                   1598: 	    }
                   1599: 	}
                   1600:     }
                   1601:     return $classlist;
                   1602: }
                   1603: 
                   1604: 
1.14      albertel 1605: sub show_queue {
1.32      albertel 1606:     my ($queue,$with_selects)=@_;
1.14      albertel 1607:     my $result;
1.185     albertel 1608:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14      albertel 1609:     my $cnum=$env{'course.'.$cid.'.num'};
                   1610:     my $cdom=$env{'course.'.$cid.'.domain'};
1.59      albertel 1611: 
1.237     albertel 1612:     my @chosen_sections = &get_allowed_sections();
1.156     albertel 1613: 
                   1614:     my $classlist = &get_limited_classlist(\@chosen_sections);
                   1615: 
1.63      albertel 1616:     if (!(grep(/^all$/,@chosen_sections))) {
1.239     bisitz   1617: 	$result.='<p>'
                   1618:                 .&mt('Showing only sections [_1].'
                   1619:                     ,'<tt>'.join(', ',@chosen_sections).'</tt>')
                   1620:                 ."</p>\n";
1.63      albertel 1621:     }
1.59      albertel 1622: 
1.156     albertel 1623:     my ($view,$view_section);
                   1624:     my $scope = $env{'request.course.id'};
                   1625:     if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
                   1626: 	$scope .= '/'.$env{'request.course.sec'};
                   1627: 	if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
                   1628: 	    $view_section=$env{'request.course.sec'};
                   1629: 	} else {
                   1630: 	    undef($view);
                   1631: 	}
                   1632:     }
                   1633: 
1.234     albertel 1634:     $result .= 
                   1635: 	'<p><a href="/adm/flip?postdata=return:">'.
                   1636: 	&mt('Return to resource').'</a></p><hr />'.
1.239     bisitz   1637: 	"\n<h3>".&mt('Current Queue - [_1]',$queue)."</h3>";
1.16      albertel 1638:     my $regexp="^$symb\0";
1.30      albertel 1639:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31      albertel 1640:     my ($tmp)=%queue;
                   1641:     if ($tmp=~/^error: 2 /) {
1.234     albertel 1642: 	$result.=
1.159     albertel 1643: 	    &Apache::loncommon::start_data_table().
                   1644: 	    &Apache::loncommon::start_data_table_row().
                   1645: 	    '<td>'.&mt('Empty').'</td>'.
                   1646: 	    &Apache::loncommon::end_data_table_row().
                   1647: 	    &Apache::loncommon::end_data_table();
1.234     albertel 1648: 	return $result;
1.31      albertel 1649:     }
1.103     albertel 1650:     my $title=&Apache::lonnet::gettitle($symb);
1.234     albertel 1651:     $result.=
1.159     albertel 1652: 	&Apache::loncommon::start_data_table().
                   1653: 	&Apache::loncommon::start_data_table_header_row();
1.239     bisitz   1654:     if ($with_selects) { $result.='<th>'.&mt('Status').'</th><th></th>'; }
                   1655:     $result.='<th>'.&mt('User').'</th><th>'.&mt('Data').'</th>'.
1.159     albertel 1656: 	&Apache::loncommon::end_data_table_header_row();
1.14      albertel 1657:     foreach my $key (sort(keys(%queue))) {
1.59      albertel 1658: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
1.235     albertel 1659: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.237     albertel 1660: 	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.156     albertel 1661: 	
                   1662: 	my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
                   1663: 
                   1664: 	my $can_view=1;
                   1665: 	if (!$view
                   1666: 	    || ($view_section && !$section)
                   1667: 	    || ($view_section && $section && ($view_section ne $section))) {
                   1668: 	    $can_view=0;
                   1669: 	}
                   1670: 
1.32      albertel 1671: 	if ($key=~/locked$/ && !$with_selects) {
1.159     albertel 1672: 	    $result.= &Apache::loncommon::start_data_table_row().
                   1673: 		"<td>$uname</td>";
1.103     albertel 1674: 	    $result.='<td>'.$queue{$key}.'</td></tr>';
1.32      albertel 1675: 	} elsif ($key=~/timestamp$/ && !$with_selects) {
1.159     albertel 1676: 	    $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103     albertel 1677: 	    $result.='<td>'.
1.16      albertel 1678: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32      albertel 1679: 	} elsif ($key!~/(timestamp|locked)$/) {
1.159     albertel 1680: 	    $result.= &Apache::loncommon::start_data_table_row();
1.148     albertel 1681: 	    my ($end_time,$slot_text);
                   1682: 	    if (my $slot=&slotted_access($queue{$key})) {
                   1683: 		my %slot_data=&Apache::lonnet::get_slot($slot);
                   1684: 		$end_time = $slot_data{'endtime'};
                   1685: 		$slot_text = &mt('Slot: [_1]',$slot);
                   1686: 	    } else {
                   1687: 		$end_time = &Apache::lonhomework::due_date('0',$symb);
                   1688: 		$slot_text = '';
                   1689: 	    }
1.32      albertel 1690: 	    if ($with_selects) {
1.158     www      1691: 		my $ekey=&escape($key);
1.103     albertel 1692: 		my ($action,$description,$status)=('select',&mt('Select'));
1.32      albertel 1693: 		if (exists($queue{"$key\0locked"})) {
1.217     albertel 1694: 		    my ($locker,$time) = 
                   1695: 			&get_lock_info($queue{"$key\0locked"});
                   1696: 		    if ($time) {
1.214     albertel 1697: 			$time = 
                   1698: 			    &Apache::lonnavmaps::timeToHumanString($time,
                   1699: 								   'start');
                   1700: 		    }
1.138     albertel 1701: 		    my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.239     bisitz   1702: 		    $status=&mt('Locked by [_1] [_2]','<tt>'.$locker.'</tt>',$time);
1.217     albertel 1703: 		    if ($me eq $locker) {
1.32      albertel 1704: 			($action,$description)=('resume',&mt('Resume'));
                   1705: 		    } else {
                   1706: 			($action,$description)=('unlock',&mt('Unlock'));
                   1707: 		    }
                   1708: 		}
1.62      albertel 1709: 		my $seclist;
                   1710: 		foreach my $sec (@chosen_sections) {
                   1711: 		    $seclist.='<input type="hidden" name="chosensections" 
                   1712:                                value="'.$sec.'" />';
                   1713: 		}
1.156     albertel 1714: 		if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35      albertel 1715: 		    $result.=(<<FORM);
1.103     albertel 1716: <td>$status</td>
1.32      albertel 1717: <td>
1.115     albertel 1718: <form style="display: inline" method="post">
1.32      albertel 1719:  <input type="hidden" name="gradingkey" value="$ekey" />
                   1720:  <input type="hidden" name="queue" value="$queue" />
                   1721:  <input type="hidden" name="gradingaction" value="$action" />
                   1722:  <input type="hidden" name="webgrade" value="no" />
1.33      albertel 1723:  <input type="hidden" name="queuemode" value="selected" />
1.32      albertel 1724:  <input type="submit" name="submit" value="$description" />
1.62      albertel 1725:  $seclist
1.32      albertel 1726: </form>
                   1727: </td>
                   1728: FORM
1.156     albertel 1729:                 } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
                   1730: 		    $result.='<td>'.&mt("Not gradable").'</td><td>&nbsp;</td>'
1.35      albertel 1731:                 } else {
1.148     albertel 1732: 		    $result.='<td>'.&mt("In Progress").'</td><td>&nbsp;</td>'
1.35      albertel 1733: 		}
1.32      albertel 1734: 	    }
1.156     albertel 1735: 	    $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138     albertel 1736: 		" <tt>($uname:$udom)</tt> </td>";
1.239     bisitz   1737:             $result.='<td>'.$slot_text.' '
                   1738:                     .&mt('End time: [_1]'
                   1739:                         ,&Apache::lonlocal::locallocaltime($end_time))
                   1740:                     .'</td>'
                   1741:                     .&Apache::loncommon::end_data_table_row();
1.16      albertel 1742: 	}
1.14      albertel 1743:     }
1.159     albertel 1744:     $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14      albertel 1745:     return $result;
                   1746: }
                   1747: 
1.237     albertel 1748: sub get_allowed_sections {
                   1749:     my @chosen_sections;
                   1750:     if (&section_restricted()) {
                   1751: 	@chosen_sections = ($env{'request.course.sec'});
                   1752:     } else {
                   1753: 	@chosen_sections =
                   1754: 	    &Apache::loncommon::get_env_multiple('form.chosensections');
                   1755:     }
                   1756: 
                   1757:     return @chosen_sections;
                   1758: }
                   1759: 
1.235     albertel 1760: sub section_restricted {
1.237     albertel 1761:     my $cid =(&Apache::lonnet::whichuser())[1];
                   1762:     return (lc($env{'course.'.$cid.'.task_grading'}) eq 'section'
                   1763: 	    && $env{'request.course.sec'} ne '' );
                   1764: }
                   1765: 
                   1766: sub allow_grade_user {
1.235     albertel 1767:     my ($classlist_entry) = @_;
1.237     albertel 1768: 
                   1769:     if (&section_restricted()
1.235     albertel 1770: 	&& $env{'request.course.sec'} ne
                   1771: 	      $classlist_entry->[&Apache::loncoursedata::CL_SECTION()]) {
1.237     albertel 1772: 	return 0;
1.235     albertel 1773:     }
1.237     albertel 1774:     return 1;
1.235     albertel 1775: }
                   1776: 
1.34      albertel 1777: sub get_queue_counts {
                   1778:     my ($queue)=@_;
                   1779:     my $result;
1.185     albertel 1780:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.34      albertel 1781:     my $cnum=$env{'course.'.$cid.'.num'};
                   1782:     my $cdom=$env{'course.'.$cid.'.domain'};
1.156     albertel 1783: 
1.157     albertel 1784:     my $classlist=&get_limited_classlist();
1.156     albertel 1785: 
1.34      albertel 1786:     my $regexp="^$symb\0";
                   1787:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1788:     my ($tmp)=%queue;
                   1789:     if ($tmp=~/^error: 2 /) {
                   1790: 	return (0,0,0);
                   1791:     }
1.235     albertel 1792: 
1.34      albertel 1793:     my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96      albertel 1794:     my %slot_cache;
1.34      albertel 1795:     foreach my $key (sort(keys(%queue))) {
1.156     albertel 1796: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
1.235     albertel 1797: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.237     albertel 1798: 	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.235     albertel 1799: 
1.34      albertel 1800: 	if ($key=~/locked$/) {
                   1801: 	    $locks++;
                   1802: 	} elsif ($key=~/timestamp$/) {
                   1803: 	    #ignore
                   1804: 	} elsif ($key!~/(timestamp|locked)$/) {
                   1805: 	    $entries++;
1.148     albertel 1806: 	    if (my $slot=&slotted_access($queue{$key})) {
                   1807: 		if (!exists($slot_cache{$slot})) {
                   1808: 		    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1809: 		    $slot_cache{$slot} = \%slot_data;
                   1810: 		}
                   1811: 		if (time > $slot_cache{$slot}{'endtime'}) {
                   1812: 		    $ready_to_grade++;
                   1813: 		}
                   1814: 	    } else {
                   1815: 		my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1816: 		if ($due_date ne '' && time > $due_date) {
                   1817: 		    $ready_to_grade++;
                   1818: 		}
1.34      albertel 1819: 	    }
                   1820: 	}
                   1821:     }
                   1822:     return ($entries,$ready_to_grade,$locks);
                   1823: }
                   1824: 
1.49      albertel 1825: sub encode_queue_key {
                   1826:     my ($symb,$udom,$uname)=@_;
1.138     albertel 1827:     return "$symb\0queue\0$uname:$udom";
1.49      albertel 1828: }
                   1829: 
1.14      albertel 1830: sub decode_queue_key {
                   1831:     my ($key)=@_;
                   1832:     my ($symb,undef,$user) = split("\0",$key);
1.138     albertel 1833:     my ($uname,$udom) = split(':',$user);
1.14      albertel 1834:     return ($symb,$uname,$udom);
                   1835: }
                   1836: 
                   1837: sub queue_key_locked {
1.30      albertel 1838:     my ($queue,$key,$cdom,$cnum)=@_;
1.33      albertel 1839:     if (!defined($cdom) || !defined($cnum)) {
1.185     albertel 1840: 	my (undef,$cid)=&Apache::lonnet::whichuser();
1.33      albertel 1841: 	$cnum=$env{'course.'.$cid.'.num'};
                   1842: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1843:     }
1.14      albertel 1844:     my ($key_locked,$value)=
1.30      albertel 1845: 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14      albertel 1846:     if ($key_locked eq "$key\0locked") {
1.217     albertel 1847: 	return &get_lock_info($value);
1.14      albertel 1848:     }
                   1849:     return undef;
                   1850: }
                   1851: 
1.148     albertel 1852: sub slotted_access {
                   1853:     my ($queue_entry) = @_;
                   1854:     if (ref($queue_entry) eq 'ARRAY') {
                   1855: 	if (defined($queue_entry->[0])) {
                   1856: 	    return $queue_entry->[0];
                   1857: 	}
                   1858: 	return undef;
                   1859:     } elsif (ref($queue_entry) eq 'HASH') {
                   1860: 	if (defined($queue_entry->{'slot'})) {
                   1861: 	    return $queue_entry->{'slot'};
                   1862: 	}
                   1863: 	return undef;
                   1864:     }
                   1865:     return undef;
                   1866: }
                   1867: 
1.14      albertel 1868: sub pick_from_queue_data {
1.156     albertel 1869:     my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98      albertel 1870:     my @possible; # will hold queue entries that are valid to be selected
1.30      albertel 1871:     foreach my $key (keys(%$queuedata)) {
1.68      albertel 1872: 	if ($key =~ /\0locked$/) { next; }
                   1873: 	if ($key =~ /\0timestamp$/) { next; }
1.156     albertel 1874: 
1.14      albertel 1875: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
1.235     albertel 1876: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.237     albertel 1877: 	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.156     albertel 1878: 
1.14      albertel 1879: 	if ($check_section) {
1.156     albertel 1880: 	    my $section =
                   1881: 		$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17      albertel 1882: 	    if ($section eq $check_section) {
1.33      albertel 1883: 		&Apache::lonxml::debug("my sec");
1.15      albertel 1884: 		next;
                   1885: 	    }
1.14      albertel 1886: 	}
1.148     albertel 1887: 	my $end_time;
                   1888: 	if (my $slot=&slotted_access($queuedata->{$key})) {
1.154     albertel 1889: 	    &Apache::lonxml::debug("looking at slot $slot");
1.148     albertel 1890: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1891: 	    if ($slot_data{'endtime'} < time) { 
                   1892: 		$end_time = $slot_data{'endtime'};
1.154     albertel 1893: 	    } else {
                   1894: 		&Apache::lonxml::debug("not time ".$slot_data{'endtime'});
                   1895: 		next;
1.148     albertel 1896: 	    }
                   1897: 	} else {
                   1898: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154     albertel 1899: 	    if ($due_date < time) {
1.148     albertel 1900: 		$end_time = $due_date;
1.154     albertel 1901: 	    } else {
                   1902: 		&Apache::lonxml::debug("not time $due_date");
                   1903: 		next;
1.148     albertel 1904: 	    }
                   1905: 	}
                   1906: 	
1.98      albertel 1907: 	if (exists($queuedata->{"$key\0locked"})) {
1.33      albertel 1908: 	    &Apache::lonxml::debug("someone already has um.");
1.15      albertel 1909: 	    next;
                   1910: 	}
1.148     albertel 1911: 	push(@possible,[$key,$end_time]);
1.98      albertel 1912:     }
                   1913:     if (@possible) {
                   1914:         # sort entries in order by slot end time
                   1915: 	@possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137     albertel 1916: 	# pick one of the entries in the top 10% in small queues and one
                   1917: 	# of the first ten entries in large queues
1.139     albertel 1918: 	#my $ten_percent = int($#possible * 0.1);
                   1919: 	#if ($ten_percent < 1 ) { $ten_percent = 1;  }
                   1920: 	#if ($ten_percent > 10) { $ten_percent = 10; }
                   1921: 	#my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137     albertel 1922: 	
1.139     albertel 1923: 	#return $possible[int(rand($max))][0];
                   1924: 	return $possible[0][0];
1.14      albertel 1925:     }
                   1926:     return undef;
                   1927: }
                   1928: 
1.217     albertel 1929: sub get_lock_info {
                   1930:     my ($lock_info) = @_;
                   1931:     if (wantarray) {
                   1932: 	if (ref($lock_info) eq 'ARRAY') {
                   1933: 	    return @{$lock_info};
                   1934: 	} else {
                   1935: 	    return ($lock_info);
                   1936: 	}
                   1937:     } else {
                   1938: 	if (ref($lock_info) eq 'ARRAY') {
                   1939: 	    return $lock_info->[0];
                   1940: 	} else {
                   1941: 	    return $lock_info;
                   1942: 	}
                   1943:     }
                   1944:     return;
                   1945: }
                   1946: 
1.15      albertel 1947: sub find_mid_grade {
1.30      albertel 1948:     my ($queue,$symb,$cdom,$cnum)=@_;
1.158     www      1949:     my $todo=&unescape($env{'form.gradingkey'});
1.138     albertel 1950:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15      albertel 1951:     if ($todo) {
1.30      albertel 1952: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel 1953: 	if ($who eq $me) { return $todo; }
                   1954:     }
                   1955:     my $regexp="^$symb\0.*\0locked\$";
1.30      albertel 1956:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel 1957:     foreach my $key (keys(%locks)) {
1.217     albertel 1958: 	my $who= &get_lock_info($locks{$key});
1.15      albertel 1959: 	if ($who eq $me) {
                   1960: 	    $todo=$key;
                   1961: 	    $todo=~s/\0locked$//;
                   1962: 	    return $todo;
                   1963: 	}
                   1964:     }
                   1965:     return undef;
                   1966: }
                   1967: 
1.32      albertel 1968: sub lock_key {
                   1969:     my ($queue,$todo)=@_;
1.138     albertel 1970:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.185     albertel 1971:     my (undef,$cid)=&Apache::lonnet::whichuser();
1.32      albertel 1972:     my $cnum=$env{'course.'.$cid.'.num'};
                   1973:     my $cdom=$env{'course.'.$cid.'.domain'};
1.214     albertel 1974:     my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> [$me,time]},
1.32      albertel 1975: 					$cdom,$cnum);
1.33      albertel 1976:     &Apache::lonxml::debug("success $success $todo");
1.32      albertel 1977:     if ($success eq 'ok') {
                   1978: 	return 1;
                   1979:     }
                   1980:     return 0;
                   1981: }
                   1982: 
1.86      albertel 1983: sub get_queue_symb_status {
1.85      albertel 1984:     my ($queue,$symb,$cdom,$cnum) = @_;
                   1985:     if (!defined($cdom) || !defined($cnum)) {
1.235     albertel 1986: 	my (undef,$cid) =&Apache::lonnet::whichuser();
1.85      albertel 1987: 	$cnum=$env{'course.'.$cid.'.num'};
                   1988: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1989:     }
1.157     albertel 1990:     my $classlist=&get_limited_classlist();
1.156     albertel 1991: 
1.85      albertel 1992:     my $regexp="^$symb\0";
                   1993:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1994:     my ($tmp)=%queue;
                   1995:     if ($tmp=~/^error: 2 /) { return; }
                   1996:     my @users;
                   1997:     foreach my $key (sort(keys(%queue))) {
                   1998: 	next if ($key=~/locked$/);
                   1999: 	next if ($key=~/timestamp$/);
                   2000: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156     albertel 2001: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.237     albertel 2002: 	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.85      albertel 2003: 	push(@users,"$uname:$udom");
                   2004:     }
                   2005:     return @users;
                   2006: }
                   2007: 
1.14      albertel 2008: sub get_from_queue {
1.30      albertel 2009:     my ($queue)=@_;
1.14      albertel 2010:     my $result;
1.185     albertel 2011:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14      albertel 2012:     my $cnum=$env{'course.'.$cid.'.num'};
                   2013:     my $cdom=$env{'course.'.$cid.'.domain'};
1.32      albertel 2014:     my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33      albertel 2015:     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16      albertel 2016:     if ($todo) { return $todo; }
1.95      albertel 2017:     my $attempts=0;
1.156     albertel 2018: 
1.157     albertel 2019:     my $classlist=&get_limited_classlist();
1.156     albertel 2020: 
1.14      albertel 2021:     while (1) {
1.95      albertel 2022: 	if ($attempts > 2) {
                   2023: 	    # tried twice to get a queue entry, giving up
                   2024: 	    return (undef,'unable');
                   2025: 	}
1.14      albertel 2026: 	my $starttime=time;
1.83      albertel 2027: 	&Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
                   2028: 			      $cdom,$cnum);
1.33      albertel 2029: 	&Apache::lonxml::debug("$starttime");
1.14      albertel 2030: 	my $regexp="^$symb\0queue\0";
1.156     albertel 2031: 	#my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97      albertel 2032: 
1.98      albertel 2033: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33      albertel 2034: 	#make a pass looking for a user _not_ in my section
1.14      albertel 2035: 	if ($env{'request.course.sec'}) {
1.33      albertel 2036: 	    &Apache::lonxml::debug("sce");
1.30      albertel 2037: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156     albertel 2038: 					\%queue,$cdom,$cnum,$classlist);
1.33      albertel 2039: 	    &Apache::lonxml::debug("sce $todo");
1.14      albertel 2040: 	}
1.33      albertel 2041: 	# no one _not_ in our section so look for any user that is
                   2042: 	# ready for grading
1.14      albertel 2043: 	if (!$todo) {
1.33      albertel 2044: 	    &Apache::lonxml::debug("no sce");
1.156     albertel 2045: 	    $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
                   2046: 					$classlist);
1.33      albertel 2047: 	    &Apache::lonxml::debug("no sce $todo");
1.14      albertel 2048: 	}
                   2049: 	# no user to grade 
                   2050: 	if (!$todo) { last; }
1.33      albertel 2051: 	&Apache::lonxml::debug("got $todo");
1.14      albertel 2052: 	# otherwise found someone so lets try to lock them
1.32      albertel 2053: 	# unless someone else already picked them
1.95      albertel 2054: 	if (!&lock_key($queue,$todo)) {
                   2055: 	    $attempts++;
                   2056: 	    next;
                   2057: 	}
1.14      albertel 2058: 	my (undef,$endtime)=
1.30      albertel 2059: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel 2060: 				 $cdom,$cnum);
1.33      albertel 2061: 	&Apache::lonxml::debug("emd  $endtime");
1.14      albertel 2062: 	# someone else already modified the queue, 
                   2063: 	# perhaps our picked user wass already fully graded between
                   2064: 	# when we picked him and when we locked his record? so lets
                   2065: 	# double check.
                   2066: 	if ($endtime != $starttime) {
                   2067: 	    my ($key,$value)=
1.30      albertel 2068: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel 2069: 				     $cdom,$cnum);
1.33      albertel 2070: 	    &Apache::lonxml::debug("check  $key .. $value");
1.14      albertel 2071: 	    if ($key eq $todo && ref($value)) {
                   2072: 	    } else {
1.30      albertel 2073: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel 2074: 				     $cdom,$cnum);
1.33      albertel 2075: 		&Apache::lonxml::debug("del");
1.95      albertel 2076: 		$attempts++;
1.14      albertel 2077: 		next;
                   2078: 	    }
                   2079: 	}
1.33      albertel 2080: 	&Apache::lonxml::debug("last $todo");
1.14      albertel 2081: 	last;
                   2082:     }
                   2083:     return $todo;
                   2084: }
                   2085: 
1.49      albertel 2086: sub select_user {
1.185     albertel 2087:     my ($symb,$cid)=&Apache::lonnet::whichuser();
1.49      albertel 2088: 
1.237     albertel 2089:     my @chosen_sections = &get_allowed_sections();
1.156     albertel 2090:     my $classlist = &get_limited_classlist(\@chosen_sections);
1.63      albertel 2091:     
                   2092:     my $result;
                   2093:     if (!(grep(/^all$/,@chosen_sections))) {
1.239     bisitz   2094:         $result.='<p>'
                   2095:                 .&mt('Showing only sections [_1].'
                   2096:                     ,'<tt>'.join(', ',@chosen_sections).'</tt>')
                   2097:                 .'</p> '."\n";
1.63      albertel 2098:     }
1.159     albertel 2099:     $result.=&Apache::loncommon::start_data_table();
1.49      albertel 2100: 
1.156     albertel 2101:     foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49      albertel 2102: 	my ($uname,$udom) = split(/:/,$student);
1.59      albertel 2103: 	
1.84      albertel 2104: 	my $cnum=$env{'course.'.$cid.'.num'};
                   2105: 	my $cdom=$env{'course.'.$cid.'.domain'};
1.88      albertel 2106: 	my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
                   2107: 					 'Task');
1.49      albertel 2108: 	my $queue = 'none';
1.58      albertel 2109: 	my $cannot_grade;
                   2110: 	if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 2111: 	    $queue = 'reviewqueue';
1.58      albertel 2112: 	    if ($status{'reviewqueue'} eq 'in_progress') {
                   2113: 		$cannot_grade=1;
                   2114: 	    }
                   2115: 	} elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 2116: 	    $queue = 'gradingqueue';
1.58      albertel 2117: 	    if ($status{'gradingqueue'} eq 'in_progress') {
                   2118: 		$cannot_grade=1;
                   2119: 	    }
1.49      albertel 2120: 	}
                   2121: 	my $todo = 
1.158     www      2122: 	    &escape(&encode_queue_key($symb,$udom,$uname));
1.58      albertel 2123: 	if ($cannot_grade) {
1.159     albertel 2124: 	    $result.=&Apache::loncommon::start_data_table_row().
                   2125: 		'<td>&nbsp;</td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58      albertel 2126: 		'</td><td>';
                   2127: 	} else {
1.62      albertel 2128: 	    my $seclist;
                   2129: 	    foreach my $sec (@chosen_sections) {
                   2130: 		$seclist.='<input type="hidden" name="chosensections" 
                   2131:                                value="'.$sec.'" />';
                   2132: 	    }
1.242     bisitz   2133:             my $buttontext=&mt('Regrade');
1.159     albertel 2134: 	    $result.=&Apache::loncommon::start_data_table_row();
1.58      albertel 2135: 	    $result.=<<RESULT;
1.49      albertel 2136:   <td>
1.115     albertel 2137:     <form style="display: inline" method="post">
1.49      albertel 2138:       <input type="hidden" name="gradingkey" value="$todo" />
                   2139:       <input type="hidden" name="queue" value="$queue" />
                   2140:       <input type="hidden" name="webgrade" value="no" />
1.52      albertel 2141:       <input type="hidden" name="regrade" value="yes" />
1.242     bisitz   2142:       <input type="submit" name="submit" value="$buttontext" />
1.62      albertel 2143:       $seclist
1.49      albertel 2144:     </form>
1.237     albertel 2145:   <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt> Sec: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()]</td>
1.49      albertel 2146:   <td>
                   2147: RESULT
1.58      albertel 2148:         }
1.49      albertel 2149:         if ($status{'status'} eq 'pass') {
                   2150: 	    $result .= '<font color="green">'.&mt('Passed').'</font>';
                   2151: 	} elsif ($status{'status'} eq 'fail') {
                   2152: 	    $result .= '<font color="red">'.&mt('Failed').'</font>';
                   2153: 	} elsif ($status{'status'} eq 'review') {
                   2154: 	    $result .= '<font color="blue">'.&mt('Under Review').'</font>';
                   2155: 	} elsif ($status{'status'} eq 'ungraded') {
                   2156: 	    $result .= &mt('Ungraded');
                   2157: 	} elsif ($status{'status'} ne '') {
                   2158: 	    $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
                   2159: 	} else {
                   2160: 	    $result.="&nbsp;";
                   2161: 	}
                   2162: 	if ($status{'version'}) {
                   2163: 	    $result .= ' '.&mt('Version').' '.$status{'version'};
                   2164: 	}
1.101     albertel 2165: 	if ($status{'grader'}) {
                   2166: 	    $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
                   2167: 	}
1.49      albertel 2168: 	$result.= '</td><td>';
                   2169: 	if ($status{'reviewqueue'} eq 'enqueued') {
                   2170: 	    $result .= &mt('Awaiting Review');
                   2171: 	} elsif ($status{'reviewqueue'} eq 'locked') {
                   2172: 	    $result .= &mt('Under Review');
1.58      albertel 2173: 	} elsif ($status{'reviewqueue'} eq 'in_progress') {
                   2174: 	    $result .= &mt('Still being worked on.');
1.49      albertel 2175: 	} elsif ($status{'gradingqueue'} eq 'enqueued') {
                   2176: 	    $result .= &mt('Awaiting Grading');
                   2177: 	} elsif ($status{'gradingqueue'} eq 'locked') {
                   2178: 	    $result .= &mt('Being Graded');
1.58      albertel 2179: 	} elsif ($status{'gradingqueue'} eq 'in_progress') {
                   2180: 	    $result .= &mt('Still being worked on.');
1.49      albertel 2181: 	} else {
                   2182: 	    $result.="&nbsp;";
                   2183: 	}
1.159     albertel 2184: 	$result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49      albertel 2185:     }
1.159     albertel 2186:     $result.=&Apache::loncommon::end_data_table();
1.49      albertel 2187:     return $result;
                   2188: }
                   2189: 
                   2190: sub get_student_status {
1.86      albertel 2191:     my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
                   2192: 
                   2193:     my %status;
                   2194: 
                   2195:     if ($type eq 'Task') {
                   2196: 	my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49      albertel 2197: 					  $udom,$uname);
1.89      albertel 2198: 	$status{'status'}=$record{'resource.0.status'};
                   2199: 	$status{'version'}=$record{'resource.0.version'};
                   2200: 	$status{'grader'}=$record{'resource.0.regrader'};
1.86      albertel 2201:     }
                   2202:     $status{'reviewqueue'}=
                   2203: 	&check_queue_for_key($cdom,$cnum,'reviewqueue',
                   2204: 			     &encode_queue_key($symb,$udom,$uname));
                   2205:     $status{'gradingqueue'}=
                   2206: 	&check_queue_for_key($cdom,$cnum,'gradingqueue',
                   2207: 			     &encode_queue_key($symb,$udom,$uname));
1.49      albertel 2208:     return %status;
                   2209: }
                   2210: 
1.1       albertel 2211: sub start_ClosingParagraph {
                   2212:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   2213:     my $result;
                   2214:     if ($target eq 'web') {
1.13      albertel 2215:     } elsif ($target eq 'webgrade') {
                   2216: 	&Apache::lonxml::startredirection();
1.225     albertel 2217:     } elsif ($target eq 'edit') {
                   2218: 	$result = &Apache::edit::tag_start($target,$token);
                   2219:     } elsif ($target eq 'modified') {
1.1       albertel 2220:     }
                   2221:     return $result;
                   2222: }
                   2223: 
                   2224: sub end_ClosingParagraph {
                   2225:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   2226:     my $result;
                   2227:     if ($target eq 'web') {
1.13      albertel 2228:     } elsif ($target eq 'webgrade') {
                   2229: 	&Apache::lonxml::endredirection();
1.1       albertel 2230:     }
                   2231:     return $result;
                   2232: }
                   2233: 
1.227     albertel 2234: sub insert_ClosingParagraph {
                   2235:     return '
                   2236: <ClosingParagraph>
                   2237:     <startouttext />
                   2238:     <endouttext />
                   2239: </ClosingParagraph>';
                   2240: }
                   2241: 
1.168     albertel 2242: sub get_dim_id {
1.194     albertel 2243:     if (@Apache::bridgetask::dimension) {
                   2244: 	return $Apache::bridgetask::dimension[-1];
                   2245:     } else {
                   2246: 	return $top;
                   2247:     }
1.168     albertel 2248: }
                   2249: 
1.19      albertel 2250: sub get_id {
                   2251:     my ($parstack,$safeeval)=@_;
1.236     albertel 2252:     return &Apache::lonxml::get_id($parstack,$safeeval);
1.19      albertel 2253: }
                   2254: 
1.162     albertel 2255: sub start_Setup {
                   2256:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225     albertel 2257:     my $result;
1.168     albertel 2258:     my $dim = &get_id($parstack,$safeeval);
                   2259:     push(@Apache::bridgetask::dimension,$dim);
1.225     albertel 2260:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
                   2261: 	&Apache::lonxml::startredirection();
                   2262:     } elsif ($target eq 'edit') {
                   2263: 	$result = &Apache::edit::tag_start($target,$token);
                   2264: 	$result.= &Apache::edit::text_arg('Id:','id',$token,10).
                   2265: 	    &Apache::edit::end_row().
                   2266: 	    &Apache::edit::start_spanning_row();
                   2267:     } elsif ($target eq 'modified') {
                   2268: 	my $constructtag=
                   2269: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,'id');
                   2270: 	if ($constructtag) {
                   2271: 	    $result = &Apache::edit::rebuild_tag($token);
                   2272: 	}
                   2273:     }
                   2274:     return $result;
1.162     albertel 2275: }
1.173     albertel 2276: 
                   2277: {
                   2278:     my @allowed;
                   2279:     sub enable_dimension_parsing {
                   2280: 	my ($id) = @_;
                   2281: 	push(@allowed,$id);
                   2282:     }
                   2283:     sub disable_dimension_parsing {
                   2284: 	pop(@allowed);
                   2285:     }
                   2286:     sub skip_dimension_parsing {
                   2287: 	my ($check) = @_;
                   2288: 	if (!@allowed) { return 0;}
                   2289: 	# if unspecified allow any id
                   2290: 	if ($allowed[-1] eq undef) { return 0;}
                   2291: 
                   2292: 	return ($check ne $allowed[-1]);
                   2293:     }
                   2294: }
                   2295: 
1.151     albertel 2296: sub start_Question { return &start_Dimension(@_); }
1.1       albertel 2297: sub start_Dimension {
1.173     albertel 2298:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168     albertel 2299:     my $dim = &get_id($parstack,$safeeval);
                   2300:     my $previous_dim;
1.225     albertel 2301:     my $result;
                   2302:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   2303: 	if (@Apache::bridgetask::dimension) {
                   2304: 	    $previous_dim = $Apache::bridgetask::dimension[-1];
                   2305: 	    push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
                   2306: 		 $dim);
                   2307: 	    if(&skip_dimension_parsing($dim)) {
                   2308: 		$dimension{$previous_dim}{'criteria.'.$dim} =
                   2309: 		    $token->[4]
                   2310: 		    .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
                   2311: 						   $style)
                   2312: 		    .'</'.$tagstack->[-1].'>';
                   2313: 	    }
                   2314: 	    $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
                   2315: 	    $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
                   2316: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
                   2317: 	    push(@{$dimension{$previous_dim}{'criterias'}},$dim);
                   2318: 	    $dimension{$dim}{'nested'}=$previous_dim;
                   2319: 	    $dimension{$dim}{'depth'} = 1 + $dimension{$previous_dim}{'depth'};
                   2320: 	    
                   2321: 	    &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
                   2322: 	} else {
                   2323: 	    $dimension{$top}{'depth'}=0;
                   2324: 	    $dimension{$top}{'criteria.'.$dim.'.type'}='dimension';
                   2325: 	    $dimension{$top}{'criteria.'.$dim.'.mandatory'}=
                   2326: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
                   2327: 	    push(@{$dimension{$top}{'criterias'}},$dim);
                   2328: 	    $dimension{$dim}{'nested'}=$top;
                   2329: 	}
                   2330:         push(@Apache::bridgetask::dimension,$dim);
                   2331: 	&Apache::lonxml::startredirection();
                   2332: 	if (!&skip_dimension_parsing($dim)) {
                   2333: 	    &enable_dimension_parsing($dim);
                   2334: 	}
                   2335:     } elsif ($target eq 'edit') {
                   2336:   	$result = &Apache::edit::tag_start($target,$token);
                   2337: 	$result.=  
                   2338: 	    &Apache::edit::text_arg('Id:','id',$token,10).' '.
                   2339: 	    &Apache::edit::select_arg('Passing is Mandatory:','Mandatory',
1.233     albertel 2340: 				      [['Y', 'Yes'],
                   2341: 				       ['N','No'],],
1.225     albertel 2342: 				      $token).' <br /> '.
                   2343: 	    &Apache::edit::text_arg('Required number of passed optional elements to pass the '.$token->[1].':',
                   2344: 				    'OptionalRequired',$token,4).
                   2345: 	    &Apache::edit::end_row().
                   2346: 	    &Apache::edit::start_spanning_row();
                   2347:     } elsif ($target eq 'modified') {
                   2348: 	my $constructtag=
                   2349: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
                   2350: 					'id','Mandatory','OptionalRequired');
                   2351: 	if ($constructtag) {
                   2352: 	    $result = &Apache::edit::rebuild_tag($token);
                   2353: 	}
1.168     albertel 2354:     }
1.225     albertel 2355:     return $result;# &internal_location($dim);
1.1       albertel 2356: }
                   2357: 
1.160     albertel 2358: sub start_QuestionText {
                   2359:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225     albertel 2360:     my $result;
                   2361:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   2362: 	my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
1.168     albertel 2363:     my $dim = &get_dim_id();
1.169     albertel 2364: 	$dimension{$dim}{'questiontext'}=$text;
1.225     albertel 2365:     } elsif ($target eq 'edit') {
                   2366: 	$result = &Apache::edit::tag_start($target,$token);
                   2367:     } elsif ($target eq 'modified') {
1.160     albertel 2368:     }
1.225     albertel 2369:     return $result;
1.160     albertel 2370: }
                   2371: 
                   2372: sub end_QuestionText {
                   2373:     return '';
                   2374: }
                   2375: 
1.227     albertel 2376: sub insert_QuestionText {
                   2377:     return '
                   2378: <QuestionText>
                   2379:     <startouttext />
                   2380:     <endouttext />
                   2381: </QuestionText>';
                   2382: }
                   2383: 
1.13      albertel 2384: sub get_instance {
1.75      albertel 2385:     my ($dim)=@_;
                   2386:     my $rand_alg=&Apache::lonnet::get_rand_alg();
                   2387:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
                   2388: 	$rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
                   2389: 	$rand_alg eq '64bit4' ) {
                   2390: 	&Apache::response::pushrandomnumber();
1.169     albertel 2391: 	my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75      albertel 2392: 	my $num=@order;
                   2393: 	my $version=&get_version();
                   2394: 	my $which=($version-1)%$num;
                   2395: 	return $order[$which];
                   2396:     } else {
                   2397: 	my ($version,$previous) = &get_version();
                   2398: 	my $instance = 
                   2399: 	    $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
                   2400: 	if (defined($instance)) { return $instance; }
                   2401: 
                   2402: 	&Apache::response::pushrandomnumber();
1.173     albertel 2403: 	if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
                   2404: 	    my @instances = @{$dimension{$dim}{'instances'}};
                   2405: 	    # remove disabled instances
                   2406: 	    for (my $i=0; $i < $#instances; $i++) {
                   2407: 		if ($dimension{$dim}{$instances[$i].'.disabled'}) {
                   2408: 		    splice(@instances,$i,1);
                   2409: 		    $i--;
                   2410: 		}
                   2411: 	    }
                   2412: 	    @instances = &Math::Random::random_permutation(@instances);
                   2413: 	    $instance  = $instances[($version-1)%scalar(@instances)];
                   2414: 	    if ($version =~ /^\d$/) {
                   2415: 		$Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = 
                   2416: 		    $instance;
                   2417: 		$Apache::lonhomework::results{'INTERNAL_store'} = 1; 
1.75      albertel 2418: 	    }
                   2419: 	}
                   2420: 	&Apache::response::poprandomnumber();
                   2421: 	return $instance;
                   2422:     }
1.13      albertel 2423: }
                   2424: 
1.169     albertel 2425: sub get_criteria {
                   2426:     my ($what,$version,$dim,$id) = @_;
                   2427:     my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.194     albertel 2428:     my $prefix = ($type eq 'criteria' && $dim ne $top) ? "$dim.$id"
                   2429: 	                                               : "$id";
1.169     albertel 2430:     my $entry = "resource.$version.0.$prefix.$what";
                   2431:     if (exists($Apache::lonhomework::results{$entry})) {
                   2432: 	return $Apache::lonhomework::results{$entry};
                   2433:     }
                   2434:     return $Apache::lonhomework::history{$entry};
                   2435: }
                   2436: 
1.194     albertel 2437: sub link {
                   2438:     my ($id) = @_;
                   2439:     $id =~ s/\./_/g;
                   2440:     return 'LC_GRADING_criteria_'.$id;
                   2441: }
                   2442: sub end_Question { return &end_Dimension(@_); }
                   2443: sub end_Dimension {
                   2444:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225     albertel 2445:     my $result;
1.194     albertel 2446:     my $dim=&get_id($parstack,$safeeval);
1.225     albertel 2447:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   2448: 	$result=&Apache::lonxml::endredirection();
                   2449: 	if (&skip_dimension_parsing($dim)) {
                   2450: 	    pop(@Apache::bridgetask::dimension);
                   2451: 	    return;
                   2452: 	}
1.122     albertel 2453:     }
1.194     albertel 2454:     my $instance=&get_instance($dim);
                   2455:     my $version=&get_version();
                   2456:     if ($target eq 'web') {
                   2457: 	$result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
                   2458: 	my @instances = $instance;
                   2459: 	if (&Apache::response::showallfoils()) {
                   2460: 	    @instances = @{$dimension{$dim}{'instances'}};
1.173     albertel 2461: 	}
1.194     albertel 2462: 	my $shown_question_text;
                   2463: 	foreach my $instance (@instances) {
                   2464: 	    $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
                   2465: 				     [@_]);
                   2466: 	    $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
                   2467: 				     [@_],{'set_dim_id' => undef});
                   2468: 	    my $task_status = 
                   2469: 		$Apache::lonhomework::history{"resource.$version.0.status"};
                   2470: 	    if ($task_status ne 'pass' && $task_status ne 'fail') {
                   2471: 		
                   2472: 		foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2473: 				@{$dimension{$dim}{'criterias'}}) {
                   2474: 		    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2475: 		    &Apache::lonxml::debug("$id is $type");
                   2476: 		    if ($type eq 'dimension') {
                   2477: 			$result.=
                   2478: 			    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2479: 					  [@_],{'set_dim_id' => $id});
1.173     albertel 2480: 		    }
1.194     albertel 2481: 		}
                   2482: 	    } else {
                   2483: 		my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
                   2484: 		my $mandatory='Mandatory';
                   2485: 		if (&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval) eq 'N') {
                   2486: 		    $mandatory='Optional';
                   2487: 		}
1.200     albertel 2488: 		my $dim_info=
                   2489: 		    "\n<div class='LC_$dim_status LC_question_grade'>\n\t";
1.212     albertel 2490: 		my $ucquestion = 
                   2491: 		    my $question = 
                   2492: 		    ('sub' x $dimension{$dim}{'depth'}).'question';
                   2493: 		$ucquestion =~ s/^(.)/uc($1)/e;
1.194     albertel 2494: 		if ($dim_status eq 'pass') {
1.239     bisitz   2495:                     $dim_info.='<h3>'.$ucquestion.' : '
                   2496:                               .&mt('you passed this [_1] [_2]',$mandatory,$question)
                   2497:                               .'</h3>';
1.194     albertel 2498: 		}
                   2499: 		if ($dim_status eq 'fail') {
1.239     bisitz   2500:                     $dim_info.='<h3>'.$ucquestion.' : '
                   2501:                               .&mt('you did not pass this [_1] [_2]',$mandatory,$question)
                   2502:                               .'</h3>';
1.194     albertel 2503: 		}
1.197     albertel 2504: 		my %counts = &get_counts($dim,$instance,$parstack,
                   2505: 					 $safeeval);
                   2506: 
1.200     albertel 2507: 		$dim_info.="\n\t<p>"
1.197     albertel 2508: 		    .&question_status_message(\%counts,
                   2509: 					      $dimension{$dim}{'depth'})
1.200     albertel 2510: 		    ."</p>\n</div>\n";
1.194     albertel 2511: 		
                   2512: 		foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2513: 				@{$dimension{$dim}{'criterias'}}) {
                   2514: 		    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2515: 		    if ($type eq 'dimension') {
1.205     albertel 2516: 			if (defined($dimension{$id}{'result'})) {
                   2517: 			    $result.=$dimension{$id}{'result'};
                   2518: 			    next;
                   2519: 			} else {
                   2520: 			    $dim_info .=
                   2521: 				&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2522: 					      [@_],{'set_dim_id' => $id});
                   2523: 			}
                   2524: 		    } else {
                   2525: 			my $criteria =
                   2526: 			    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2527: 					  [@_]);
                   2528: 			$dim_info .= &layout_web_Criteria($dim,$id,$criteria);
1.194     albertel 2529: 		    }
1.169     albertel 2530: 		}
1.202     albertel 2531: 		# puts the results at the end of the dimension
1.226     albertel 2532: 		if ($result =~m{<QuestionGradeInfo\s*/>}) {
                   2533: 		    $result=~s{<QuestionGradeInfo\s*/>}{$dim_info};
                   2534: 		} else {
                   2535: 		    $result .= $dim_info;
                   2536: 		}
1.202     albertel 2537: 		# puts the results at the beginning of the dimension
                   2538: 		# my $internal_location=&internal_location($dim);
                   2539: 		# $result=~s/\Q$internal_location\E/$dim_info/;
1.19      albertel 2540: 	    }
1.194     albertel 2541: 	}
1.206     albertel 2542: 	if ($result !~ /^\s*$/s) {
1.209     albertel 2543: 	    # FIXME? this maybe unneccssary in the future, (CSE101 BT
                   2544: 	    # from Fall 2006 geenrate a div that attempts to hide some
                   2545: 	    # of the output in an odd way, this is a workaround so
                   2546: 	    # those old ones will continue to work.  # It puts the
                   2547: 	    # LC_question div to come after any starting closie div
                   2548: 	    # that the dimension produces
1.211     albertel 2549: 	    if ($result =~ m{^\s*</div>}) {
                   2550: 		$result =~ s{^(\s*</div>)}
1.210     albertel 2551: 		            {$1\n<div id="$dim" class="LC_question">};
1.209     albertel 2552: 	    } else {
1.210     albertel 2553: 		$result = "\n".'<div id="'.$dim.'" class="LC_question">'.
1.209     albertel 2554: 		    "\n".$result;
                   2555: 	    }
                   2556: 	    $result .= "\n</div>\n";
1.206     albertel 2557: 	}
1.194     albertel 2558:     } elsif ($target eq 'webgrade') {
                   2559: 	# in case of any side effects that we need
                   2560: 	&nested_parse(\$dimension{$dim}{'intro'},[@_]);
                   2561: 	&nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
                   2562: 	$result.=
                   2563: 	    &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
                   2564: 			  {'set_dim_id'          => undef,
1.195     albertel 2565: 			   'delayed_dim_results' => 1});
1.194     albertel 2566: 	foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2567: 			@{$dimension{$dim}{'criterias'}} ) {
                   2568: 	    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2569: 	    if ($type eq 'dimension') {
                   2570: 		# dimensional 'criteria' don't get assigned grades
                   2571: 		$result.=
                   2572: 		    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2573: 				  [@_],{'set_dim_id' => $id});
                   2574: 		next;
                   2575: 	    } else {
                   2576: 		my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2577: 					     [@_]);
                   2578: 		$criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
                   2579: 		my $internal_location=&internal_location($id);
1.209     albertel 2580: 		if ($result =~ m/\Q$internal_location\E/) {
                   2581: 		    $result =~ s/\Q$internal_location\E/$criteria/;
                   2582: 		} else {
                   2583: 		    $result.=$criteria ;
                   2584: 		}
1.151     albertel 2585: 	    }
1.194     albertel 2586: 	}
                   2587: 	if (&nest()) {
                   2588: 	    &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
                   2589: 	    $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
                   2590: 	    undef($result);
                   2591: 	}
                   2592:     } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
                   2593: 	my $optional_passed=0;
                   2594: 	my $mandatory_failed=0;
                   2595: 	my $ungraded=0;
                   2596: 	my $review=0;
                   2597: 	
                   2598: 	$result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
                   2599: 	$result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
                   2600: 				 [@_]);
                   2601: 	$result .= &nested_parse(\$dimension{$dim}{'questiontext'},
                   2602: 				 [@_],{'set_dim_id' => undef});
                   2603: 	
                   2604: 	foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2605: 			@{$dimension{$dim}{'criterias'}}) {
                   2606: 	    my $link=&link($id);
                   2607: 	    
                   2608: 	    my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2609: 	    if ($type eq 'criteria') {
                   2610: 		# dimensional 'criteria' don't get assigned grades
                   2611: 		$Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
                   2612: 		$Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
                   2613: 	    } else {
                   2614: 		$result .=
                   2615: 		    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2616: 				  [@_],{'set_dim_id' => $id});
1.20      albertel 2617: 	    }
1.194     albertel 2618: 	    my $status= &get_criteria('status',$version,$dim,$id);
                   2619: 	    
                   2620: 	    my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
                   2621: 	    if ($status eq 'pass') {
                   2622: 		if (!$mandatory) { $optional_passed++; }
                   2623: 	    } elsif ($status eq 'fail') {
                   2624: 		if ($mandatory) { $mandatory_failed++; }
                   2625: 	    } elsif ($status eq 'review') {
                   2626: 		$review++;
                   2627: 	    } elsif ($status eq 'ungraded') {
                   2628: 		$ungraded++;
1.20      albertel 2629: 	    } else {
1.194     albertel 2630: 		$ungraded++;
1.20      albertel 2631: 	    }
1.194     albertel 2632: 	}
                   2633: 
                   2634: 	my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
                   2635: 	if ($opt_req !~ /\S/) {
                   2636: 	    $opt_req=
                   2637: 		&Apache::lonxml::get_param('OptionalRequired',
                   2638: 					   $parstack,$safeeval);
                   2639: 	    if ($opt_req !~ /\S/) { $opt_req = 0; }
                   2640: 	}
                   2641: 	if ($optional_passed < $opt_req) {
                   2642: 	    $mandatory_failed++;
                   2643: 	}
                   2644: 	&Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
                   2645: 	if ($review) {
                   2646: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
                   2647: 		'review';
                   2648: 	} elsif ($ungraded) {
                   2649: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
                   2650: 		'ungraded';
                   2651: 	} elsif ($mandatory_failed) {
                   2652: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
                   2653: 		'fail';
1.69      albertel 2654: 	} else {
1.194     albertel 2655: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
                   2656: 		'pass';
1.13      albertel 2657: 	}
1.225     albertel 2658:     } elsif ($target eq 'edit') {
                   2659:     } elsif ($target eq 'modified') {
1.194     albertel 2660:     } else {
                   2661: 	# any other targets no output
                   2662: 	undef($result);
1.1       albertel 2663:     }
1.225     albertel 2664:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   2665: 	&disable_dimension_parsing();
                   2666: 	pop(@Apache::bridgetask::dimension);
                   2667:     }
1.194     albertel 2668:     return $result;
                   2669: }
1.162     albertel 2670: 
1.198     albertel 2671: sub question_status_message {
1.197     albertel 2672:     my ($counts,$depth) = @_;
                   2673:     my %req  = ('man' => 'mandatory',
                   2674: 		'opt' => 'optional',);
                   2675:     my %type = ('cri' => 'criteria',
                   2676: 		'dim' => ('sub'x($depth+1)).'questions',);
                   2677:     my @sections;
                   2678:     foreach my $req ('man','opt') {
                   2679: 	foreach my $type ('cri','dim') {
                   2680: 	    if ($counts->{$req.'_'.$type}) {
                   2681: 		push(@sections,
1.213     albertel 2682: 		     $counts->{$req.'_'.$type.'_passed'}.' of the '.
1.197     albertel 2683: 		     $counts->{$req.'_'.$type}.' '.
                   2684: 		     $req{$req}.' '.$type{$type});
                   2685: 	    }
                   2686: 	}
                   2687:     }
                   2688: 
                   2689:     my $status = 'You passed ';
                   2690:     if (@sections == -1) {
                   2691:     } elsif (@sections == 1) {
                   2692: 	$status .= $sections[0];
                   2693:     } elsif (@sections == 2) {
                   2694: 	$status .= $sections[0].' and '.$sections[1];
                   2695:     } else {
                   2696: 	my $last = pop(@sections);
                   2697: 	$status .= join(', ',@sections).', and '.$last;
                   2698:     }
                   2699:     $status .= '.';
                   2700:     if ($counts->{'opt'}) {
1.241     raeburn  2701:         if ($counts->{'opt_dim'} + $counts->{'man_dim'} < 1) {
                   2702:             $status .= ' '.&mt('You were required to pass [quant,_1,optional criterion,optional criteria].',$counts->{'opt_req'});
                   2703:         } else { 
                   2704:             $status .= ' '.&mt('You were required to pass [quant,_1,optional component].',$counts->{'opt_req'});
                   2705:         }
1.197     albertel 2706:     }
                   2707:     return $status;
                   2708: }
                   2709: 
                   2710: sub get_counts {
                   2711:     my ($dim,$instance,$parstack,$safeeval) = @_;
                   2712:     my %counts;
                   2713:     my @possible = ('man_cri','man_dim',
                   2714: 		    'opt_cri','opt_dim',
                   2715: 		    'man_cri_passed', 'man_dim_passed',
                   2716: 		    'opt_cri_passed', 'opt_dim_passed',
                   2717: 		    'man_passed',
                   2718: 		    'opt_passed',
                   2719: 		    'opt_req');
                   2720:     foreach my $which (@possible) { $counts{$which} = 0; }
                   2721: 
                   2722:     my $version = &get_version();
                   2723: 
                   2724:     foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
                   2725: 		     @{$dimension{$dim}{'criterias'}} ) {
                   2726: 	my $status = &get_criteria('status',$version,$dim,$id);
                   2727: 	my $which;
                   2728: 	if ($dimension{$dim}{'criteria.'.$id.'.mandatory'} 
                   2729: 	    eq 'N') {
                   2730: 	    $which = 'opt';
                   2731: 	} else {
                   2732: 	    $which = 'man';
                   2733: 	}
                   2734: 	$counts{$which}++;
                   2735: 	if ($status eq 'pass') { $counts{$which.'_passed'}++; }
                   2736: 	if ($dimension{$dim}{'criteria.'.$id.'.type'}
                   2737: 	    eq 'dimension') {
                   2738: 	    $which .= '_dim';
                   2739: 	} else {
                   2740: 	    $which .= '_cri';
                   2741: 	}
                   2742: 	$counts{$which}++;
                   2743: 	if ($status eq 'pass') { $counts{$which.'_passed'}++; }
                   2744: 
                   2745: 
                   2746:     }
                   2747:     if ($counts{'man_dim_passed'} eq $counts{'man_dim'}) {
                   2748: 	$counts{'man_dim_passed'}='all';
                   2749:     }
                   2750:     if ($counts{'man_cri_passed'} eq $counts{'man_cri'}) {
                   2751: 	$counts{'man_cri_passed'}='all';
                   2752:     }
                   2753:     
                   2754:     $counts{'opt_req'}=$dimension{$dim}{$instance.'.optionalrequired'};
                   2755:     if ($counts{'opt_req'} !~ /\S/) {
                   2756: 	$counts{'opt_req'}= &Apache::lonxml::get_param('OptionalRequired',
                   2757: 						       $parstack,$safeeval);
                   2758: 	if ($counts{'opt_req'} !~ /\S/) { $counts{'opt_req'} = 0; }
                   2759:     }
                   2760:     return %counts;
                   2761: }
                   2762: 
1.194     albertel 2763: sub end_Setup {
                   2764:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225     albertel 2765:     my $result;
1.194     albertel 2766:     my $dim=&get_id($parstack,$safeeval);
                   2767:     my $instance=&get_instance($dim);
                   2768:     my $version=&get_version();
1.225     albertel 2769:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
                   2770: 	$result=&Apache::lonxml::endredirection();
                   2771:     }
1.194     albertel 2772:     if ($target eq 'web') {
                   2773: 	@Apache::scripttag::parser_env = @_;
                   2774: 	$result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
                   2775: 	my @instances = $instance;
                   2776: 	if (&Apache::response::showallfoils()) {
                   2777: 	    @instances = @{$dimension{$dim}{'instances'}};
                   2778: 	}
                   2779: 	foreach my $instance (@instances) {
1.162     albertel 2780: 	    @Apache::scripttag::parser_env = @_;
1.194     albertel 2781: 	    $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162     albertel 2782: 	    @Apache::scripttag::parser_env = @_;
1.194     albertel 2783: 	    $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162     albertel 2784: 	}
1.194     albertel 2785:     } elsif ($target eq 'webgrade' 
                   2786: 	     || $target eq 'grade' && $env{'form.webgrade'}) {
                   2787: 	# in case of any side effects that we need
                   2788: 	@Apache::scripttag::parser_env = @_;
                   2789: 	&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
                   2790: 	@Apache::scripttag::parser_env = @_;
                   2791: 	&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
                   2792: 	@Apache::scripttag::parser_env = @_;
                   2793: 	&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
                   2794:     } else {
                   2795: 	# any other targets no output
                   2796: 	undef($result);
1.162     albertel 2797:     }
1.194     albertel 2798:     pop(@Apache::bridgetask::dimension);
                   2799:     return $result;
1.1       albertel 2800: }
                   2801: 
1.113     albertel 2802: sub grading_history {
1.151     albertel 2803:     my ($version,$dim,$id) = @_;
1.235     albertel 2804:     if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})
                   2805: 	&& !&Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
1.113     albertel 2806: 	return '';
                   2807:     }
                   2808:     my ($result,$grader);
1.194     albertel 2809:     my $scope="resource.$version.0.";
                   2810:     $scope .= ($dim ne $top) ? "$dim.$id"
                   2811: 	                     : "$id";
1.113     albertel 2812:     foreach my $t (1..$Apache::lonhomework::history{'version'}) {
                   2813: 	if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
                   2814: 	    my ($gname,$gdom) = 
1.138     albertel 2815: 		split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113     albertel 2816: 	    my $fullname = &Apache::loncommon::plainname($gname,$gdom);
                   2817: 	    $grader = &Apache::loncommon::aboutmewrapper($fullname,
                   2818: 							 $gname,$gdom);
                   2819: 	}
                   2820: 	my $entry;
                   2821: 	if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
                   2822: 	    $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
                   2823: 	}
                   2824: 	if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
                   2825: 	    $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
                   2826: 	}
                   2827: 	if ($entry) {
1.200     albertel 2828: 	    $result.= "\n\t\t<li>\n\t\t\t$grader :\n\t\t\t $entry \n\t\t</li>";
1.113     albertel 2829: 	}
                   2830:     }
                   2831:     if ($result) {
1.200     albertel 2832: 	return "\n\t".'<ul class="LC_GRADING_pastgrading">'.$result.
                   2833: 	    "\n\t".'</ul>'."\n";
1.113     albertel 2834:     }
                   2835:     return '';
                   2836: }
                   2837: 
1.1       albertel 2838: sub start_IntroParagraph {
1.87      albertel 2839:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1       albertel 2840:     my $result;
1.168     albertel 2841:     my $dim = &get_dim_id();
1.153     albertel 2842:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151     albertel 2843: 	if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169     albertel 2844: 	    $dimension{$dim}{'intro'}=
1.151     albertel 2845: 		&Apache::lonxml::get_all_text('/introparagraph',
                   2846: 					      $parser,$style);
                   2847:        	} elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2848: 	    &Apache::lonxml::startredirection();
1.1       albertel 2849: 	}
1.47      albertel 2850: 	
1.225     albertel 2851:     } elsif ($target eq 'edit') {
                   2852: 	$result = &Apache::edit::tag_start($target,$token);
                   2853:     } elsif ($target eq 'modified') {
1.1       albertel 2854:     }
                   2855:     return $result;
                   2856: }
                   2857: 
                   2858: sub end_IntroParagraph {
1.127     albertel 2859:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128     albertel 2860:     if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2861: 	my $result = &Apache::lonxml::endredirection();
                   2862:     }
1.1       albertel 2863: }
                   2864: 
1.227     albertel 2865: sub insert_IntroParagraph {
                   2866:     return '
                   2867: <IntroParagraph>
                   2868:     <startouttext />
                   2869:     <endouttext />
                   2870: </IntroParagraph>';
                   2871: }
                   2872: 
1.1       albertel 2873: sub start_Instance {
                   2874:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168     albertel 2875:     my $dim = &get_dim_id();
                   2876:     my $id  = &get_id($parstack,$safeeval);
1.169     albertel 2877:     push(@{$dimension{$dim}{'instances'}},$id);
1.168     albertel 2878:     push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19      albertel 2879:     push(@Apache::bridgetask::instancelist,$id);
1.169     albertel 2880:     $dimension{$dim}{$id.'.optionalrequired'}=
1.19      albertel 2881: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75      albertel 2882:     my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
                   2883:     if (lc($disabled) eq 'yes') {
1.169     albertel 2884: 	$dimension{$dim}{$id.'.disabled'}='1';
1.75      albertel 2885:     }
1.225     albertel 2886:     my $result;
                   2887:     if ($target eq 'edit') {
                   2888: 	$result = &Apache::edit::tag_start($target,$token);
                   2889: 	$result.=  
                   2890: 	    &Apache::edit::text_arg('Id:','id',$token,10).' '.
                   2891: 	    &Apache::edit::select_arg('Instance is Disabled:','Disabled',
                   2892: 				      [['no', 'No'],
                   2893: 				       ['yes','Yes'],],
                   2894: 				      $token)
                   2895: 	    .' <br /> '.
                   2896: 	    &Apache::edit::text_arg('Required number of passed optional elements to pass the Instance:',
                   2897: 				    'OptionalRequired',$token,4)
                   2898: 	    .&Apache::edit::end_row().
                   2899: 	    &Apache::edit::start_spanning_row();
                   2900:     } elsif ($target eq 'modified') {
                   2901: 	my $constructtag=
                   2902: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
                   2903: 					'id','OptionalRequired','Disabled');
                   2904: 	if ($constructtag) {
                   2905: 	    $result = &Apache::edit::rebuild_tag($token);
                   2906: 	}
                   2907:     }
                   2908:     return $result;
1.1       albertel 2909: }
                   2910: 
                   2911: sub end_Instance {
1.225     albertel 2912:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   2913:     my $result;
                   2914:     if ($target eq 'edit') {
                   2915: 	$result = &Apache::edit::tag_end($target,$token);
                   2916:     }
                   2917:     return $result;
1.1       albertel 2918: }
                   2919: 
                   2920: sub start_InstanceText {
1.87      albertel 2921:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225     albertel 2922:     my $result;
1.153     albertel 2923:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.225     albertel 2924: 	my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
                   2925: 	my $dim = &get_dim_id();
                   2926: 	my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169     albertel 2927: 	$dimension{$dim}{$instance_id.'.text'}=$text;
1.225     albertel 2928:     } elsif ($target eq 'edit') {
                   2929: 	$result = &Apache::edit::tag_start($target,$token);
                   2930:     } elsif ($target eq 'modified') {
1.1       albertel 2931:     }
1.225     albertel 2932:     return $result;
1.1       albertel 2933: }
                   2934: 
                   2935: sub end_InstanceText {
                   2936:     return '';
                   2937: }
                   2938: 
1.227     albertel 2939: sub insert_InstanceText {
                   2940:     return '
                   2941: <InstanceText>
                   2942:     <startouttext />
                   2943:     <endouttext />
                   2944: </InstanceText>';
                   2945: }
                   2946: 
1.1       albertel 2947: sub start_Criteria {
1.87      albertel 2948:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.190     albertel 2949:     my $result = '';
1.21      albertel 2950:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.225     albertel 2951: 	my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.168     albertel 2952: 	my $dim = &get_dim_id();
1.19      albertel 2953: 	my $id=&get_id($parstack,$safeeval);
1.194     albertel 2954: 	if ($target eq 'web' || $target eq 'webgrade') {
1.208     albertel 2955: 	    if ($target eq 'webgrade') {
1.195     albertel 2956: 		&Apache::lonxml::debug(" for $dim $id stashing results into $dim ");
                   2957: 		$dimension{$dim}{'result'} .= &internal_location($id);
                   2958: 	    } else {
                   2959: 		&Apache::lonxml::debug(" not stashing $dim $id");
1.206     albertel 2960: 		#$result .= &internal_location($id);
1.195     albertel 2961: 	    }
1.194     albertel 2962: 	}
1.169     albertel 2963: 	&Apache::lonxml::debug("Criteria $id with $dim");
1.151     albertel 2964: 	if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168     albertel 2965: 	    my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169     albertel 2966: 	    $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
                   2967: 	    $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
                   2968: 	    $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151     albertel 2969: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169     albertel 2970: 	    push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151     albertel 2971: 	} else {
1.169     albertel 2972: 	    $dimension{$dim}{'criteria.'.$id}=$criteria;
                   2973: 	    $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
                   2974: 	    $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151     albertel 2975: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169     albertel 2976: 	    push(@{$dimension{$dim}{'criterias'}},$id);
1.194     albertel 2977: 	}
1.225     albertel 2978:     } elsif ($target eq 'edit') {
                   2979: 	$result .=&Apache::edit::tag_start($target,$token);
                   2980: 	$result.=  
                   2981: 	    &Apache::edit::text_arg('Id:','id',$token,10).' '.
                   2982: 	    &Apache::edit::select_arg('Passing is Mandatory:','Mandatory',
1.233     albertel 2983: 				      [['Y', 'Yes'],
                   2984: 				       ['N','No'],],
1.225     albertel 2985: 				      $token)
                   2986: 	    .' <br /> '.&Apache::edit::end_row().
                   2987: 	    &Apache::edit::start_spanning_row();
                   2988:     } elsif ($target eq 'modified') {
                   2989: 	my $constructtag=
                   2990: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
                   2991: 					'id','Mandatory');
                   2992: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.194     albertel 2993:     }
                   2994:     return $result;
                   2995: }
                   2996: 
                   2997: sub layout_web_Criteria {
                   2998:     my ($dim,$id,$criteria) = @_;
1.190     albertel 2999: 
1.194     albertel 3000:     my $version = &get_version();
                   3001:     my $status= &get_criteria('status', $version,$dim,$id);
                   3002:     my $comment=&get_criteria('comment',$version,$dim,$id);
                   3003:     my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
                   3004:     if ($mandatory) {
                   3005: 	$mandatory='Mandatory';
                   3006:     } else {
                   3007: 	$mandatory='Optional';
1.1       albertel 3008:     }
1.194     albertel 3009:     my $status_display=$status;
                   3010:     $status_display=~s/^([a-z])/uc($1)/e;
                   3011:     my $criteria_info.=
1.200     albertel 3012: 	'<div class="LC_'.$status.' LC_criteria">'."\n\t".'<h4>'
1.204     albertel 3013: 	.$mandatory.' Criteria</h4>'."\n\t".'<p class="LC_criteria_text">'
                   3014: 	."\n";
1.202     albertel 3015:     $criteria =~ s/^\s*//s;
                   3016:     $criteria =~ s/\s*$//s;
1.194     albertel 3017:     $criteria_info.= $criteria;
1.200     albertel 3018:     $criteria_info.="\n\t".'</p>'.
                   3019: 	"\n\t".'<p class="LC_grade">'.$status_display.'</p>';
1.194     albertel 3020:     if ($comment =~ /\w/) {
1.200     albertel 3021: 	$criteria_info.=
                   3022: 	    "\n\t".
                   3023: 	    '<p class="LC_comment">'.&mt('Comment: [_1]',$comment).'</p>';
1.194     albertel 3024:     }
1.200     albertel 3025:     $criteria_info.="\n".'</div>'."\n";
                   3026:     
1.194     albertel 3027:     return $criteria_info;
                   3028: }
                   3029: 
                   3030: sub layout_webgrade_Criteria {
                   3031:     my ($dim,$id,$criteria) = @_;
                   3032:     my $link=&link($id);
                   3033:     my $version = &get_version();
                   3034:     my $status  = &get_criteria('status',$version,$dim,$id);
1.245     bisitz   3035:     my %lt = &Apache::lonlocal::texthash(
                   3036:         'ungraded' => 'Ungraded',
                   3037:         'fail'     => 'Fail',
                   3038:         'pass'     => 'Pass',
                   3039:         'review'   => 'Review',
                   3040:         'comment'  => 'Additional Comment for Student',
                   3041:     );
1.200     albertel 3042:     my $comment = &get_criteria('comment',$version,$dim,$id);
                   3043:     $comment = &HTML::Entities::encode($comment,'<>"&');
                   3044:     my %checked;
                   3045:     foreach my $which ('ungraded','fail','pass','review') {
1.249     bisitz   3046: 	if ($status eq $which) { $checked{$which} = ' checked="checked"'; }
1.200     albertel 3047:     }
1.249     bisitz   3048:     if (!%checked) { $checked{'ungraded'} = ' checked="checked"'; }
1.201     albertel 3049:     my $buttons;
                   3050:     foreach my $which  ('ungraded','fail','pass','review') {
                   3051: 	$buttons .= <<END_BUTTON;
                   3052: 		<label class="LC_GRADING_$which">
1.249     bisitz   3053: 			<input type="radio" name="HWVAL_$link" value="$which"$checked{$which} />
1.201     albertel 3054: 			$lt{$which}
                   3055: 		</label>
                   3056: END_BUTTON
                   3057:     }
1.202     albertel 3058:     $criteria =~ s/^\s*//s;
                   3059:     $criteria =~ s/\s*$//s;
1.200     albertel 3060:     my $result = <<END_CRITERIA;
1.201     albertel 3061: <div class="LC_GRADING_criteria">
                   3062: 	<div class="LC_GRADING_criteriatext">
                   3063: 		$criteria
                   3064: 	</div>
                   3065: 	<div class="LC_GRADING_grade">
                   3066: $buttons
                   3067: 	</div>
                   3068: 	<label class="LC_GRADING_comment">
                   3069: 		$lt{'comment'}
                   3070: 		<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_$link">$comment</textarea>
                   3071: 	</label>
                   3072: </div>
1.200     albertel 3073: END_CRITERIA
                   3074:     $result .= &grading_history($version,$dim,$id);
1.190     albertel 3075:     return $result;
1.1       albertel 3076: }
                   3077: 
1.47      albertel 3078: sub end_Criteria {
1.225     albertel 3079:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   3080:     if ($target eq 'edit') {
                   3081:     } elsif ($target eq 'modified') {
                   3082:     }
                   3083: }
1.227     albertel 3084: sub insert_Criteria {
                   3085:     return '
                   3086: <Criteria>
                   3087:     <CriteriaText>
                   3088:         <startouttext />
                   3089:         <endouttext />
                   3090:     </CriteriaText>
                   3091: </Criteria>';
                   3092: }
1.225     albertel 3093: 
                   3094: sub start_CriteriaText {
                   3095:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   3096:     my $result;
                   3097:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
                   3098: 	
                   3099:     } elsif ($target eq 'edit') {
                   3100: 	$result = &Apache::edit::tag_start($target,$token);
                   3101:     } elsif ($target eq 'modified') {
                   3102:     }
                   3103:     return $result;
                   3104: }
                   3105: 
                   3106: sub end_CriteriaText {
                   3107:     return '';
1.47      albertel 3108: }
                   3109: 
1.227     albertel 3110: sub insert_CriteriaText {
                   3111:     return '
                   3112: <CriteriaText>
                   3113:     <startouttext />
                   3114:     <endouttext />
                   3115: </CriteriaText>';
                   3116: }
                   3117: 
1.186     albertel 3118: sub start_GraderNote {
                   3119:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225     albertel 3120:     my $result;
1.186     albertel 3121:     if ($target eq 'webgrade') {
1.225     albertel 3122: 	$result = '<div class="LC_GRADING_gradernote"><b>'.
1.187     albertel 3123: 	    &mt('Note to graders:').'</b>';
1.225     albertel 3124:     } elsif ($target eq 'edit') {
                   3125: 	$result = &Apache::edit::tag_start($target,$token);
                   3126:     } elsif ($target eq 'modified') {
                   3127:     } elsif ($target eq 'web' || $target eq 'grade') {
                   3128: 	my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style); 
1.186     albertel 3129:     }
1.225     albertel 3130:     return $result;
1.186     albertel 3131: }
                   3132: 
                   3133: sub end_GraderNote {
                   3134:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   3135: 
                   3136:     if ($target eq 'webgrade') {
                   3137: 	return '</div>';
                   3138:     }
                   3139:     return;
                   3140: }
                   3141: 
1.227     albertel 3142: sub insert_GraderNote {
                   3143:     return '
                   3144: <GraderNote>
                   3145:     <startouttext />
                   3146:     <endouttext />
                   3147: </GraderNote>';
                   3148: }
1.186     albertel 3149: 
                   3150: 
1.4       albertel 3151: sub proctor_validation_screen {
                   3152:     my ($slot) = @_;
1.185     albertel 3153:     my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
1.5       albertel 3154:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.230     albertel 3155:     if ($url ne '/adm/lonKaputt/lonlogo_broken.gif') {
                   3156: 	$url = "<tr><td colspan=\"2\"><img src=\"$url\" /></td></tr>";
                   3157:     } else {
                   3158: 	undef($url);
                   3159:     }
                   3160: 
1.44      albertel 3161:     my $name=&Apache::loncommon::plainname($user,$domain);
                   3162:     
1.4       albertel 3163:     my $msg;
1.11      albertel 3164:     if ($env{'form.proctorpassword'}) {
1.230     albertel 3165: 	$msg.='<p><span class="LC_warning">'
                   3166: 	    .&mt("Failed to authenticate the proctor.")
                   3167: 	    .'</span></p>';
1.4       albertel 3168:     }
1.230     albertel 3169: 
                   3170:     my $valid;
                   3171:     my @possible_proctors=split(",",$slot->{'proctor'});
                   3172:     foreach my $proctor (@possible_proctors) {
                   3173: 	if ($proctor =~ /$LONCAPA::username_re:$LONCAPA::domain_re/) {
                   3174: 	    $valid = 1;
                   3175: 	    last;
                   3176: 	}
                   3177:     }
                   3178:     if (!$valid) {
                   3179: 	$msg.='<p><span class="LC_error">'
1.239     bisitz   3180: 	    .&mt("No valid proctors are defined.")
1.230     albertel 3181: 	    .'</span></p>';
                   3182:     }
                   3183:     
1.47      albertel 3184:     if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.229     albertel 3185:     my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
                   3186:     $uri = &HTML::Entities::encode($uri,'<>&"');
1.241     raeburn  3187:     my %lt = &Apache::lonlocal::texthash(
                   3188:                             'prva' => "Proctor Validation",
                   3189:                             'yoro' => "Your room's proctor needs to validate your access to this resource.",
                   3190:                             'prus'  => "Proctor's Username:",
                   3191:                             'pasw'  => "Password:",
                   3192:                             'prdo'  => "Proctor's Domain:",
                   3193:                             'vali'  => 'Validate',
                   3194:                             'stui'  => "Student who should be logged in is:",
                   3195:                             'name'  => "Name:",
1.251     raeburn  3196:                             'sid'   => "Student/Employee ID",
1.241     raeburn  3197:                             'unam'  => "Username:",
                   3198:                            );
1.4       albertel 3199:     my $result= (<<ENDCHECKOUT);
1.241     raeburn  3200: <h2>$lt{'prva'}</h2>
                   3201:     <p>$lt{'yoro'}</p>
1.4       albertel 3202:     $msg
1.229     albertel 3203: <form name="checkout" method="post" action="$uri">
1.4       albertel 3204: <input type="hidden" name="validate" value="yes" />
                   3205: <input type="hidden" name="submitted" value="yes" />
                   3206: <table>
1.241     raeburn  3207:   <tr><td>$lt{'prus'}</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
                   3208:   <tr><td>$lt{'pasw'}</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
                   3209:   <tr><td>$lt{'prdo'}</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4       albertel 3210: </table>
1.241     raeburn  3211: <input type="submit" name="checkoutbutton" value="$lt{'vali'}"  /><br />
1.44      albertel 3212: <table border="1">
                   3213:   <tr><td>
                   3214:     <table>
1.241     raeburn  3215:       <tr><td colspan="2">$lt{'stui'}</td></tr>
                   3216:       <tr><td>$lt{'name'}</td><td>$name</td></tr>
                   3217:       <tr><td>$lt{'sid'}</td><td>$env{'environment.id'}</td></tr>
                   3218:       <tr><td>$lt{'unam'}</td><td>$user:$domain</td></tr>
1.230     albertel 3219:       $url
1.44      albertel 3220:     </table>
                   3221:   </tr></td>
                   3222: </table>
1.4       albertel 3223: </form>
                   3224: ENDCHECKOUT
1.241     raeburn  3225: 
1.4       albertel 3226:     return $result;
                   3227: }
                   3228: 
1.1       albertel 3229: 1;
                   3230: __END__

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