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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.155   ! albertel    4: # $Id: bridgetask.pm,v 1.154 2006/05/25 19:37:47 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})) {
1.154     albertel 1397: 	    &Apache::lonxml::debug("looking at slot $slot");
1.148     albertel 1398: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1399: 	    if ($slot_data{'endtime'} < time) { 
                   1400: 		$end_time = $slot_data{'endtime'};
1.154     albertel 1401: 	    } else {
                   1402: 		&Apache::lonxml::debug("not time ".$slot_data{'endtime'});
                   1403: 		next;
1.148     albertel 1404: 	    }
                   1405: 	} else {
                   1406: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154     albertel 1407: 	    if ($due_date < time) {
1.148     albertel 1408: 		$end_time = $due_date;
1.154     albertel 1409: 	    } else {
                   1410: 		&Apache::lonxml::debug("not time $due_date");
                   1411: 		next;
1.148     albertel 1412: 	    }
                   1413: 	}
                   1414: 	
1.98      albertel 1415: 	if (exists($queuedata->{"$key\0locked"})) {
1.33      albertel 1416: 	    &Apache::lonxml::debug("someone already has um.");
1.15      albertel 1417: 	    next;
                   1418: 	}
1.148     albertel 1419: 	push(@possible,[$key,$end_time]);
1.98      albertel 1420:     }
                   1421:     if (@possible) {
                   1422:         # sort entries in order by slot end time
                   1423: 	@possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137     albertel 1424: 	# pick one of the entries in the top 10% in small queues and one
                   1425: 	# of the first ten entries in large queues
1.139     albertel 1426: 	#my $ten_percent = int($#possible * 0.1);
                   1427: 	#if ($ten_percent < 1 ) { $ten_percent = 1;  }
                   1428: 	#if ($ten_percent > 10) { $ten_percent = 10; }
                   1429: 	#my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137     albertel 1430: 	
1.139     albertel 1431: 	#return $possible[int(rand($max))][0];
                   1432: 	return $possible[0][0];
1.14      albertel 1433:     }
                   1434:     return undef;
                   1435: }
                   1436: 
1.15      albertel 1437: sub find_mid_grade {
1.30      albertel 1438:     my ($queue,$symb,$cdom,$cnum)=@_;
1.16      albertel 1439:     my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.138     albertel 1440:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15      albertel 1441:     if ($todo) {
1.30      albertel 1442: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel 1443: 	if ($who eq $me) { return $todo; }
                   1444:     }
                   1445:     my $regexp="^$symb\0.*\0locked\$";
1.30      albertel 1446:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel 1447:     foreach my $key (keys(%locks)) {
                   1448: 	my $who=$locks{$key};
                   1449: 	if ($who eq $me) {
                   1450: 	    $todo=$key;
                   1451: 	    $todo=~s/\0locked$//;
                   1452: 	    return $todo;
                   1453: 	}
                   1454:     }
                   1455:     return undef;
                   1456: }
                   1457: 
1.32      albertel 1458: sub lock_key {
                   1459:     my ($queue,$todo)=@_;
1.138     albertel 1460:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.32      albertel 1461:     my (undef,$cid)=&Apache::lonxml::whichuser();
                   1462:     my $cnum=$env{'course.'.$cid.'.num'};
                   1463:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1464:     my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
                   1465: 					$cdom,$cnum);
1.33      albertel 1466:     &Apache::lonxml::debug("success $success $todo");
1.32      albertel 1467:     if ($success eq 'ok') {
                   1468: 	return 1;
                   1469:     }
                   1470:     return 0;
                   1471: }
                   1472: 
1.86      albertel 1473: sub get_queue_symb_status {
1.85      albertel 1474:     my ($queue,$symb,$cdom,$cnum) = @_;
                   1475:     if (!defined($cdom) || !defined($cnum)) {
                   1476: 	my (undef,$cid)=&Apache::lonxml::whichuser();
                   1477: 	$cnum=$env{'course.'.$cid.'.num'};
                   1478: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1479:     }
                   1480:     my $regexp="^$symb\0";
                   1481:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1482:     my ($tmp)=%queue;
                   1483:     if ($tmp=~/^error: 2 /) { return; }
                   1484:     my @users;
                   1485:     foreach my $key (sort(keys(%queue))) {
                   1486: 	next if ($key=~/locked$/);
                   1487: 	next if ($key=~/timestamp$/);
                   1488: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
                   1489: 	push(@users,"$uname:$udom");
                   1490:     }
                   1491:     return @users;
                   1492: }
                   1493: 
1.14      albertel 1494: sub get_from_queue {
1.30      albertel 1495:     my ($queue)=@_;
1.14      albertel 1496:     my $result;
                   1497:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1498:     my $cnum=$env{'course.'.$cid.'.num'};
                   1499:     my $cdom=$env{'course.'.$cid.'.domain'};
1.32      albertel 1500:     my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33      albertel 1501:     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16      albertel 1502:     if ($todo) { return $todo; }
1.95      albertel 1503:     my $attempts=0;
1.14      albertel 1504:     while (1) {
1.95      albertel 1505: 	if ($attempts > 2) {
                   1506: 	    # tried twice to get a queue entry, giving up
                   1507: 	    return (undef,'unable');
                   1508: 	}
1.14      albertel 1509: 	my $starttime=time;
1.83      albertel 1510: 	&Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
                   1511: 			      $cdom,$cnum);
1.33      albertel 1512: 	&Apache::lonxml::debug("$starttime");
1.14      albertel 1513: 	my $regexp="^$symb\0queue\0";
1.97      albertel 1514: 	my $range= ($attempts < 1 ) ? '0-100' : '0-400';
                   1515: 
1.98      albertel 1516: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33      albertel 1517: 	#make a pass looking for a user _not_ in my section
1.14      albertel 1518: 	if ($env{'request.course.sec'}) {
1.33      albertel 1519: 	    &Apache::lonxml::debug("sce");
1.30      albertel 1520: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
                   1521: 					\%queue,$cdom,$cnum);
1.33      albertel 1522: 	    &Apache::lonxml::debug("sce $todo");
1.14      albertel 1523: 	}
1.33      albertel 1524: 	# no one _not_ in our section so look for any user that is
                   1525: 	# ready for grading
1.14      albertel 1526: 	if (!$todo) {
1.33      albertel 1527: 	    &Apache::lonxml::debug("no sce");
1.98      albertel 1528: 	    $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum);
1.33      albertel 1529: 	    &Apache::lonxml::debug("no sce $todo");
1.14      albertel 1530: 	}
                   1531: 	# no user to grade 
                   1532: 	if (!$todo) { last; }
1.33      albertel 1533: 	&Apache::lonxml::debug("got $todo");
1.14      albertel 1534: 	# otherwise found someone so lets try to lock them
1.32      albertel 1535: 	# unless someone else already picked them
1.95      albertel 1536: 	if (!&lock_key($queue,$todo)) {
                   1537: 	    $attempts++;
                   1538: 	    next;
                   1539: 	}
1.14      albertel 1540: 	my (undef,$endtime)=
1.30      albertel 1541: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel 1542: 				 $cdom,$cnum);
1.33      albertel 1543: 	&Apache::lonxml::debug("emd  $endtime");
1.14      albertel 1544: 	# someone else already modified the queue, 
                   1545: 	# perhaps our picked user wass already fully graded between
                   1546: 	# when we picked him and when we locked his record? so lets
                   1547: 	# double check.
                   1548: 	if ($endtime != $starttime) {
                   1549: 	    my ($key,$value)=
1.30      albertel 1550: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel 1551: 				     $cdom,$cnum);
1.33      albertel 1552: 	    &Apache::lonxml::debug("check  $key .. $value");
1.14      albertel 1553: 	    if ($key eq $todo && ref($value)) {
                   1554: 	    } else {
1.30      albertel 1555: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel 1556: 				     $cdom,$cnum);
1.33      albertel 1557: 		&Apache::lonxml::debug("del");
1.95      albertel 1558: 		$attempts++;
1.14      albertel 1559: 		next;
                   1560: 	    }
                   1561: 	}
1.33      albertel 1562: 	&Apache::lonxml::debug("last $todo");
1.14      albertel 1563: 	last;
                   1564:     }
                   1565:     return $todo;
                   1566: }
                   1567: 
1.49      albertel 1568: sub select_user {
                   1569:     my ($symb,$cid)=&Apache::lonxml::whichuser();
                   1570: 
1.59      albertel 1571:     my @chosen_sections=
                   1572: 	&Apache::loncommon::get_env_multiple('form.chosensections');
1.49      albertel 1573:     &Apache::grades::init_perm();
1.59      albertel 1574:     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
1.49      albertel 1575:     &Apache::grades::reset_perm();
1.63      albertel 1576:     
                   1577:     my $result;
                   1578:     if (!(grep(/^all$/,@chosen_sections))) {
                   1579: 	$result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
                   1580: 	    '</tt>.</p> '."\n";
                   1581:     }
                   1582:     $result.='<table border="1">';
1.49      albertel 1583: 
                   1584:     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
                   1585: 	my ($uname,$udom) = split(/:/,$student);
1.59      albertel 1586: 	
1.84      albertel 1587: 	my $cnum=$env{'course.'.$cid.'.num'};
                   1588: 	my $cdom=$env{'course.'.$cid.'.domain'};
1.88      albertel 1589: 	my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
                   1590: 					 'Task');
1.49      albertel 1591: 	my $queue = 'none';
1.58      albertel 1592: 	my $cannot_grade;
                   1593: 	if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 1594: 	    $queue = 'reviewqueue';
1.58      albertel 1595: 	    if ($status{'reviewqueue'} eq 'in_progress') {
                   1596: 		$cannot_grade=1;
                   1597: 	    }
                   1598: 	} elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 1599: 	    $queue = 'gradingqueue';
1.58      albertel 1600: 	    if ($status{'gradingqueue'} eq 'in_progress') {
                   1601: 		$cannot_grade=1;
                   1602: 	    }
1.49      albertel 1603: 	}
                   1604: 	my $todo = 
                   1605: 	    &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
1.58      albertel 1606: 	if ($cannot_grade) {
                   1607: 	    $result.='<tr><td>&nbsp;</td><td>'.$fullname->{$student}.
                   1608: 		'</td><td>';
                   1609: 	} else {
1.62      albertel 1610: 	    my $seclist;
                   1611: 	    foreach my $sec (@chosen_sections) {
                   1612: 		$seclist.='<input type="hidden" name="chosensections" 
                   1613:                                value="'.$sec.'" />';
                   1614: 	    }
1.58      albertel 1615: 	    $result.=<<RESULT;
1.49      albertel 1616: <tr>
                   1617:   <td>
1.115     albertel 1618:     <form style="display: inline" method="post">
1.49      albertel 1619:       <input type="hidden" name="gradingkey" value="$todo" />
                   1620:       <input type="hidden" name="queue" value="$queue" />
                   1621:       <input type="hidden" name="webgrade" value="no" />
1.52      albertel 1622:       <input type="hidden" name="regrade" value="yes" />
1.62      albertel 1623:       <input type="submit" name="submit" value="Regrade" />
                   1624:       $seclist
1.49      albertel 1625:     </form>
1.155   ! albertel 1626:   <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt></td>
1.49      albertel 1627:   <td>
                   1628: RESULT
1.58      albertel 1629:         }
1.49      albertel 1630:         if ($status{'status'} eq 'pass') {
                   1631: 	    $result .= '<font color="green">'.&mt('Passed').'</font>';
                   1632: 	} elsif ($status{'status'} eq 'fail') {
                   1633: 	    $result .= '<font color="red">'.&mt('Failed').'</font>';
                   1634: 	} elsif ($status{'status'} eq 'review') {
                   1635: 	    $result .= '<font color="blue">'.&mt('Under Review').'</font>';
                   1636: 	} elsif ($status{'status'} eq 'ungraded') {
                   1637: 	    $result .= &mt('Ungraded');
                   1638: 	} elsif ($status{'status'} ne '') {
                   1639: 	    $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
                   1640: 	} else {
                   1641: 	    $result.="&nbsp;";
                   1642: 	}
                   1643: 	if ($status{'version'}) {
                   1644: 	    $result .= ' '.&mt('Version').' '.$status{'version'};
                   1645: 	}
1.101     albertel 1646: 	if ($status{'grader'}) {
                   1647: 	    $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
                   1648: 	}
1.49      albertel 1649: 	$result.= '</td><td>';
                   1650: 	if ($status{'reviewqueue'} eq 'enqueued') {
                   1651: 	    $result .= &mt('Awaiting Review');
                   1652: 	} elsif ($status{'reviewqueue'} eq 'locked') {
                   1653: 	    $result .= &mt('Under Review');
1.58      albertel 1654: 	} elsif ($status{'reviewqueue'} eq 'in_progress') {
                   1655: 	    $result .= &mt('Still being worked on.');
1.49      albertel 1656: 	} elsif ($status{'gradingqueue'} eq 'enqueued') {
                   1657: 	    $result .= &mt('Awaiting Grading');
                   1658: 	} elsif ($status{'gradingqueue'} eq 'locked') {
                   1659: 	    $result .= &mt('Being Graded');
1.58      albertel 1660: 	} elsif ($status{'gradingqueue'} eq 'in_progress') {
                   1661: 	    $result .= &mt('Still being worked on.');
1.49      albertel 1662: 	} else {
                   1663: 	    $result.="&nbsp;";
                   1664: 	}
                   1665: 	$result.= '</td></tr>';
                   1666:     }
                   1667:     $result.='</table>';
                   1668:     return $result;
                   1669: }
                   1670: 
                   1671: sub get_student_status {
1.86      albertel 1672:     my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
                   1673: 
                   1674:     my %status;
                   1675: 
                   1676:     if ($type eq 'Task') {
                   1677: 	my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49      albertel 1678: 					  $udom,$uname);
1.89      albertel 1679: 	$status{'status'}=$record{'resource.0.status'};
                   1680: 	$status{'version'}=$record{'resource.0.version'};
                   1681: 	$status{'grader'}=$record{'resource.0.regrader'};
1.86      albertel 1682:     }
                   1683:     $status{'reviewqueue'}=
                   1684: 	&check_queue_for_key($cdom,$cnum,'reviewqueue',
                   1685: 			     &encode_queue_key($symb,$udom,$uname));
                   1686:     $status{'gradingqueue'}=
                   1687: 	&check_queue_for_key($cdom,$cnum,'gradingqueue',
                   1688: 			     &encode_queue_key($symb,$udom,$uname));
1.49      albertel 1689:     return %status;
                   1690: }
                   1691: 
1.1       albertel 1692: sub start_ClosingParagraph {
                   1693:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1694:     my $result;
                   1695:     if ($target eq 'web') {
1.13      albertel 1696:     } elsif ($target eq 'webgrade') {
                   1697: 	&Apache::lonxml::startredirection();
1.1       albertel 1698:     }
                   1699:     return $result;
                   1700: }
                   1701: 
                   1702: sub end_ClosingParagraph {
                   1703:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1704:     my $result;
                   1705:     if ($target eq 'web') {
1.13      albertel 1706:     } elsif ($target eq 'webgrade') {
                   1707: 	&Apache::lonxml::endredirection();
1.1       albertel 1708:     }
                   1709:     return $result;
                   1710: }
                   1711: 
1.19      albertel 1712: sub get_id {
                   1713:     my ($parstack,$safeeval)=@_;
                   1714:     my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
                   1715:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                   1716:     return $id;
                   1717: }
                   1718: 
1.1       albertel 1719: my %dimension;
1.151     albertel 1720: sub start_Question { return &start_Dimension(@_); }
1.1       albertel 1721: sub start_Dimension {
                   1722:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1723:     undef(%dimension);
1.19      albertel 1724:     my $dim_id=&get_id($parstack,$safeeval);
1.9       albertel 1725:     $Apache::bridgetask::dimension=$dim_id;
                   1726:     push(@Apache::bridgetask::dimensionlist,$dim_id);
                   1727:     undef(@Apache::bridgetask::instance);
1.20      albertel 1728:     $Apache::bridgetask::dimensionmandatory{$dim_id}=
                   1729: 	&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.54      albertel 1730:     &Apache::lonxml::startredirection();
                   1731:     return &internal_location($dim_id);
1.1       albertel 1732: }
                   1733: 
1.13      albertel 1734: sub get_instance {
1.75      albertel 1735:     my ($dim)=@_;
                   1736:     my $rand_alg=&Apache::lonnet::get_rand_alg();
                   1737:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
                   1738: 	$rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
                   1739: 	$rand_alg eq '64bit4' ) {
                   1740: 	&Apache::response::pushrandomnumber();
                   1741: 	my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
                   1742: 	my $num=@order;
                   1743: 	my $version=&get_version();
                   1744: 	my $which=($version-1)%$num;
                   1745: 	return $order[$which];
                   1746:     } else {
                   1747: 	my ($version,$previous) = &get_version();
                   1748: 	my $instance = 
                   1749: 	    $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
                   1750: 	if (defined($instance)) { return $instance; }
                   1751: 
                   1752: 	&Apache::response::pushrandomnumber();
                   1753: 	my @instances = @{$dimension{'instances'}};
                   1754: 	# remove disabled instances
                   1755: 	for (my $i=0; $i < $#instances; $i++) {
                   1756: 	    if ($dimension{$instances[$i].'.disabled'}) {
                   1757: 		splice(@instances,$i,1);
                   1758: 		$i--;
                   1759: 	    }
                   1760: 	}
                   1761: 	@instances = &Math::Random::random_permutation(@instances);
                   1762: 	$instance  = $instances[($version-1)%scalar(@instances)];
1.150     albertel 1763: 	if ($version =~ /^\d$/) {
                   1764: 	    $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = 
                   1765: 		$instance;
                   1766: 	    $Apache::lonhomework::results{'INTERNAL_store'} = 1; 
                   1767: 	}
1.75      albertel 1768: 	&Apache::response::poprandomnumber();
                   1769: 	return $instance;
                   1770:     }
1.13      albertel 1771: }
                   1772: 
1.18      albertel 1773: {
                   1774:     my $last_link;
1.122     albertel 1775:     sub link {
1.151     albertel 1776: 	my ($id) = @_;
                   1777: 	$id =~ s/\./_/g;
                   1778: 	return 'LC_GRADING_criteria_'.$id;
1.122     albertel 1779:     }
1.151     albertel 1780:     sub end_Question { return &end_Dimension(@_); }
1.18      albertel 1781:     sub end_Dimension {
                   1782: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54      albertel 1783: 	my $result=&Apache::lonxml::endredirection();
1.25      albertel 1784: 	my $dim=&get_id($parstack,$safeeval);
1.75      albertel 1785: 	my $instance=&get_instance($dim);
1.25      albertel 1786: 	my $version=&get_version();
1.18      albertel 1787: 	if ($target eq 'web') {
1.47      albertel 1788: 	    @Apache::scripttag::parser_env = @_;
                   1789: 	    $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1.76      albertel 1790: 	    my @instances = $instance;
                   1791: 	    if (&Apache::response::showallfoils()) {
                   1792: 		@instances = @{$dimension{'instances'}};
                   1793: 	    }
                   1794: 	    foreach my $instance (@instances) {
                   1795: 		@Apache::scripttag::parser_env = @_;
                   1796: 		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.89      albertel 1797: 		if ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass' ||
                   1798: 		    $Apache::lonhomework::history{"resource.$version.0.status"} eq 'fail') {
1.76      albertel 1799: 
1.89      albertel 1800: 		    my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
1.76      albertel 1801: 		    my $mandatory='Mandatory';
                   1802: 		    if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
                   1803: 			$mandatory='Optional';
                   1804: 		    }
1.116     albertel 1805: 		    my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
1.76      albertel 1806: 		    if ($dim_status eq 'pass') {
                   1807: 			$dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1.54      albertel 1808: 		    }
1.76      albertel 1809: 		    if ($dim_status eq 'fail') {
                   1810: 			$dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1.53      albertel 1811: 		    }
1.76      albertel 1812: 		    my $man_count=0;
                   1813: 		    my $man_passed=0;
                   1814: 		    my $opt_count=0;
                   1815: 		    my $opt_passed=0;
1.151     albertel 1816: 		    foreach my $id ( @{$dimension{$instance.'.criterias'}},
                   1817: 				     @{$dimension{'criterias'}} ) {
                   1818: 			if ($dimension{'criteria.'.$id.'.mandatory'} 
1.76      albertel 1819: 			    eq 'N') {
                   1820: 			    $opt_count++;
1.151     albertel 1821: 			    if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"} eq 'pass') {
1.76      albertel 1822: 				$opt_passed++;
                   1823: 			    }
                   1824: 			} else {
                   1825: 			    $man_count++;
1.89      albertel 1826: 			    if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"} eq 'pass') {
1.76      albertel 1827: 				$man_passed++;
                   1828: 			    }
                   1829: 			}
1.22      albertel 1830: 		    }
1.76      albertel 1831: 		    if ($man_passed eq $man_count) { $man_passed='all'; }
1.151     albertel 1832: 
1.76      albertel 1833: 		    my $opt_req=$dimension{$instance.'.optionalrequired'};
1.151     albertel 1834: 		    if ($opt_req !~ /\S/) {
                   1835: 			$opt_req=
                   1836: 			    &Apache::lonxml::get_param('OptionalRequired',
                   1837: 						       $parstack,$safeeval);
                   1838: 			if ($opt_req !~ /\S/) { $opt_req = 0; }
                   1839: 		    }
1.76      albertel 1840: 		    $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>";
                   1841: 
                   1842: 		    my $internal_location=&internal_location($dim);
                   1843: 		    $result=~s/\Q$internal_location\E/$dim_info/;
                   1844: 
1.151     albertel 1845: 		    foreach my $id (@{$dimension{$instance.'.criterias'}},
                   1846: 				    @{$dimension{'criterias'}}) {
                   1847: 			my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"};
                   1848: 			my $comment=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"};
                   1849: 			my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N');
1.76      albertel 1850: 			if ($mandatory) {
                   1851: 			    $mandatory='Mandatory';
                   1852: 			} else {
                   1853: 			    $mandatory='Optional';
                   1854: 			}
                   1855: 			if ($status eq 'fail') {
                   1856: 			} elsif ($status eq 'pass') {
                   1857: 			} else {
                   1858: 			    &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
                   1859: 			}
                   1860: 			my $status_display=$status;
                   1861: 			$status_display=~s/^([a-z])/uc($1)/e;
1.116     albertel 1862: 			$result.=
                   1863: 			    '<div class="LC_'.$status.' LC_criteria"><h4>'
                   1864: 			    .$mandatory.' Criteria</h4><p>';
1.76      albertel 1865: 			@Apache::scripttag::parser_env = @_;
1.151     albertel 1866: 			$result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id});
1.116     albertel 1867: 			$result.='</p><p class="LC_grade">'.$status_display.'</p>';
1.151     albertel 1868: 			if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}) {
                   1869: 			    $result.='<p class="LC_comment">'.&mt('Comment: [_1]',$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}).'</p>';
1.76      albertel 1870: 			}
                   1871: 			$result.='</div>';
1.22      albertel 1872: 		    }
                   1873: 		}
                   1874: 	    }
1.18      albertel 1875: 	} elsif ($target eq 'webgrade') {
1.47      albertel 1876: 	    # in case of any side effects that we need
                   1877: 	    @Apache::scripttag::parser_env = @_;
                   1878: 	    &Apache::scripttag::xmlparse($dimension{'intro'});
                   1879: 	    @Apache::scripttag::parser_env = @_;
                   1880: 	    &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.151     albertel 1881: 	    foreach my $id (@{$dimension{$instance.'.criterias'}},
                   1882: 			    @{$dimension{'criterias'}} ) {
                   1883: 		my $link=&link($id);
                   1884: 		my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"};
1.120     albertel 1885: 		$result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
1.136     albertel 1886: 		    '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
1.47      albertel 1887: 		@Apache::scripttag::parser_env = @_;
1.151     albertel 1888: 		$result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id});
1.111     albertel 1889: 		$result.='</div>'."\n".
1.151     albertel 1890: 		    #$dimension{'criteria.'.$id}.
1.120     albertel 1891: 		    '<div class="LC_GRADING_grade">'."\n".
                   1892: 		    '<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
                   1893: 		    '<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
                   1894: 		    '<label class="LC_GRADING_pass"><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label>'."\n".
                   1895: 		    '<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 1896: 		    '</div>'."\n".
1.120     albertel 1897: 		    '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
1.151     albertel 1898: 		    '<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 1899: 		    '</label>'."\n".
1.120     albertel 1900: 		    '<ul class="LC_GRADING_navbuttons">'."\n".
1.111     albertel 1901: 		    '<li><a href="#'.$last_link.'">Prev</a></li>'."\n".
                   1902: 		    '<li><a href="#next_'.$link.'">Next</a></li>'."\n".
                   1903: 		    '</ul>'."\n".
                   1904:                     '</div>'."\n";
1.151     albertel 1905: 		$result.=&grading_history($version,$dim,$id);
1.18      albertel 1906: 		$last_link=$link;
                   1907: 	    }
1.22      albertel 1908: 	} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19      albertel 1909: 	    my $optional_passed=0;
1.20      albertel 1910: 	    my $mandatory_failed=0;
                   1911: 	    my $ungraded=0;
                   1912: 	    my $review=0;
1.153     albertel 1913: 
                   1914: 	    @Apache::scripttag::parser_env = @_;
                   1915: 	    $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1.151     albertel 1916: 	    foreach my $id (@{$dimension{$instance.'.criterias'}},
                   1917: 			    @{$dimension{'criterias'}}) {
                   1918: 		my $link=&link($id);
1.153     albertel 1919: 		@Apache::scripttag::parser_env = @_;
                   1920: 		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.151     albertel 1921: 		my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
                   1922: 		$Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
                   1923: 		my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N');
1.20      albertel 1924: 		if ($status eq 'pass') {
                   1925: 		    if (!$mandatory) { $optional_passed++; }
                   1926: 		} elsif ($status eq 'fail') {
                   1927: 		    if ($mandatory) { $mandatory_failed++; }
1.21      albertel 1928: 		} elsif ($status eq 'review') {
                   1929: 		    $review++;
1.20      albertel 1930: 		} elsif ($status eq 'ungraded') {
                   1931: 		    $ungraded++;
1.21      albertel 1932: 		} else {
1.47      albertel 1933: 		    $ungraded++;
1.19      albertel 1934: 		}
                   1935: 	    }
1.151     albertel 1936: 	    # FIXME optional required can apply to only <instance> right now...
                   1937: 	    my $opt_req=$dimension{$instance.'.optionalrequired'};
                   1938: 	    if ($opt_req !~ /\S/) {
                   1939: 		$opt_req=
                   1940: 		    &Apache::lonxml::get_param('OptionalRequired',
                   1941: 					       $parstack,$safeeval);
                   1942: 		if ($opt_req !~ /\S/) { $opt_req = 0; }
                   1943: 	    }
                   1944: 	    if ($optional_passed < $opt_req) {
1.20      albertel 1945: 		$mandatory_failed++;
                   1946: 	    }
1.21      albertel 1947: 	    &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 1948: 	    if ($review) {
1.89      albertel 1949: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 1950: 		    'review';
1.20      albertel 1951: 	    } elsif ($ungraded) {
1.89      albertel 1952: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 1953: 		    'ungraded';
1.20      albertel 1954: 	    } elsif ($mandatory_failed) {
1.89      albertel 1955: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 1956: 		    'fail';
1.20      albertel 1957: 	    } else {
1.91      albertel 1958: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 1959: 		    'pass';
1.20      albertel 1960: 	    }
1.69      albertel 1961: 	} else {
                   1962: 	    # any other targets no output
                   1963: 	    undef($result);
1.13      albertel 1964: 	}
1.18      albertel 1965: 	return $result;
1.1       albertel 1966:     }
                   1967: }
                   1968: 
1.113     albertel 1969: sub grading_history {
1.151     albertel 1970:     my ($version,$dim,$id) = @_;
1.113     albertel 1971:     if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
                   1972: 	return '';
                   1973:     }
                   1974:     my ($result,$grader);
1.151     albertel 1975:     my $scope="resource.$version.0.$dim.$id";
1.113     albertel 1976:     foreach my $t (1..$Apache::lonhomework::history{'version'}) {
                   1977: 	if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
                   1978: 	    my ($gname,$gdom) = 
1.138     albertel 1979: 		split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113     albertel 1980: 	    my $fullname = &Apache::loncommon::plainname($gname,$gdom);
                   1981: 	    $grader = &Apache::loncommon::aboutmewrapper($fullname,
                   1982: 							 $gname,$gdom);
                   1983: 	}
                   1984: 	my $entry;
                   1985: 	if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
                   1986: 	    $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
                   1987: 	}
                   1988: 	if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
                   1989: 	    $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
                   1990: 	}
                   1991: 	if ($entry) {
                   1992: 	    $result.= "<li>$grader : $entry </li>";
                   1993: 	}
                   1994:     }
                   1995:     if ($result) {
1.120     albertel 1996: 	return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
1.113     albertel 1997:     }
                   1998:     return '';
                   1999: }
                   2000: 
1.1       albertel 2001: sub start_IntroParagraph {
1.87      albertel 2002:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1       albertel 2003:     my $result;
1.153     albertel 2004:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151     albertel 2005: 	if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
                   2006: 	    $dimension{'intro'}=
                   2007: 		&Apache::lonxml::get_all_text('/introparagraph',
                   2008: 					      $parser,$style);
                   2009:        	} elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2010: 	    &Apache::lonxml::startredirection();
1.1       albertel 2011: 	}
1.47      albertel 2012: 	
1.1       albertel 2013:     }
                   2014:     return $result;
                   2015: }
                   2016: 
                   2017: sub end_IntroParagraph {
1.127     albertel 2018:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128     albertel 2019:     if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2020: 	my $result = &Apache::lonxml::endredirection();
                   2021:     }
1.1       albertel 2022: }
                   2023: 
                   2024: sub start_Instance {
                   2025:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel 2026:     my $id=&get_id($parstack,$safeeval);
                   2027:     push(@{$dimension{'instances'}},$id);
                   2028:     push(@Apache::bridgetask::instance,$id);
                   2029:     push(@Apache::bridgetask::instancelist,$id);
1.20      albertel 2030:     $dimension{$id.'.optionalrequired'}=
1.19      albertel 2031: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75      albertel 2032:     my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
                   2033:     if (lc($disabled) eq 'yes') {
                   2034: 	$dimension{$id.'.disabled'}='1';
                   2035:     }
1.1       albertel 2036:     return '';
                   2037: }
                   2038: 
                   2039: sub end_Instance {
                   2040: }
                   2041: 
                   2042: sub start_InstanceText {
1.87      albertel 2043:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.47      albertel 2044:     my $instance_id=$Apache::bridgetask::instance[-1];
1.87      albertel 2045:     my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
1.153     albertel 2046:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.47      albertel 2047: 	$dimension{$instance_id.'.text'}=$text;
1.1       albertel 2048:     }
                   2049:     return '';
                   2050: }
                   2051: 
                   2052: sub end_InstanceText {
                   2053:     return '';
                   2054: }
                   2055: 
                   2056: sub start_Criteria {
1.87      albertel 2057:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   2058:     my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.21      albertel 2059:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.19      albertel 2060: 	my $id=&get_id($parstack,$safeeval);
1.151     albertel 2061: 	if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
                   2062: 	    my $instance_id=$Apache::bridgetask::instance[-1];
                   2063: 	    $dimension{"criteria.$instance_id.$id"}=$criteria;
                   2064: 	    $dimension{"criteria.$instance_id.$id.mandatory"}=
                   2065: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
                   2066: 	    push(@{$dimension{$instance_id.'.criterias'}},"$instance_id.$id");
                   2067: 	} else {
                   2068: 	    $dimension{'criteria.'.$id}=$criteria;
                   2069: 	    $dimension{'criteria.'.$id.'.mandatory'}=
                   2070: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
                   2071: 	    push(@{$dimension{'criterias'}},$id);
                   2072: 	}
1.1       albertel 2073:     }
                   2074:     return '';
                   2075: }
                   2076: 
1.47      albertel 2077: sub end_Criteria {
                   2078: }
                   2079: 
1.4       albertel 2080: sub proctor_validation_screen {
                   2081:     my ($slot) = @_;
                   2082:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel 2083:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44      albertel 2084:     my $name=&Apache::loncommon::plainname($user,$domain);
                   2085:     
1.4       albertel 2086:     my $msg;
1.11      albertel 2087:     if ($env{'form.proctorpassword'}) {
1.4       albertel 2088: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                   2089: 	    .'</font></p>';
                   2090:     }
1.47      albertel 2091:     if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4       albertel 2092:     my $result= (<<ENDCHECKOUT);
                   2093: <h2>Proctor Validation</h2>
                   2094:     <p>Your room's proctor needs to validate your access to this resource.</p>
                   2095:     $msg
1.115     albertel 2096: <form name="checkout" method="post" action="$env{'request.uri'}">
1.4       albertel 2097: <input type="hidden" name="validate" value="yes" />
                   2098: <input type="hidden" name="submitted" value="yes" />
                   2099: <table>
1.44      albertel 2100:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4       albertel 2101:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46      albertel 2102:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4       albertel 2103: </table>
                   2104: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
1.44      albertel 2105: <table border="1">
                   2106:   <tr><td>
                   2107:     <table>
                   2108:       <tr><td colspan="2">Student who should be logged in is:</td></tr>
                   2109:       <tr><td>Name:</td><td>$name</td></tr>
1.45      albertel 2110:       <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.138     albertel 2111:       <tr><td>Usename</td><td>$user:$domain</td></tr>
1.44      albertel 2112:       <tr><td colspan="2"><img src="$url" /></td></tr>
                   2113:     </table>
                   2114:   </tr></td>
                   2115: </table>
1.4       albertel 2116: </form>
                   2117: ENDCHECKOUT
                   2118:     return $result;
                   2119: }
                   2120: 
1.1       albertel 2121: 1;
                   2122: __END__

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