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

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

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