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

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

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