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

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

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