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

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

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