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

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

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