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

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

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