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

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

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