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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.35    ! albertel    4: # $Id: bridgetask.pm,v 1.34 2005/05/31 16:27:43 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;
                     39: use Time::HiRes qw( gettimeofday tv_interval );
1.9       albertel   40: 
1.1       albertel   41: BEGIN {
                     42:     &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
                     43: }
                     44: 
1.9       albertel   45: sub initialize_bridgetask {
                     46:     # id of current Dimension, 0 means that no dimension is current 
                     47:     # (inside <Task> only)
                     48:     $Apache::bridgetask::dimension='';
                     49:     # list of all Dimension ids seen
                     50:     @Apache::bridgetask::dimensionlist=();
1.20      albertel   51:     # mandatory attribute of all Dimensions seen
                     52:     %Apache::bridgetask::dimensionmandatory=();
1.9       albertel   53:     # list of all current Instance ids
                     54:     @Apache::bridgetask::instance=();
                     55:     # list of all Instance ids seen in this problem
                     56:     @Apache::bridgetask::instancelist=();
1.15      albertel   57:     # key of queud user data that we are currently grading
                     58:     $Apache::bridgetask::queue_key='';
1.9       albertel   59: }
                     60: 
1.4       albertel   61: sub proctor_check_auth {
1.22      albertel   62:     my ($slot_name,$slot)=@_;
1.11      albertel   63:     my $user=$env{'form.proctorname'};
                     64:     my $domain=$env{'form.proctordomain'};
1.4       albertel   65:     
                     66:     my @allowed=split(",",$slot->{'proctor'});
                     67:     foreach my $possible (@allowed) {
                     68: 	my ($puser,$pdom)=(split('@',$possible));
                     69: 	if ($puser eq $user && $pdom eq $domain) {
1.11      albertel   70: 	    my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4       albertel   71: 	    if ($authhost ne 'no_host') {
1.23      albertel   72: 		my $version=
                     73: 		    $Apache::lonhomework::results{'resource.version'}=
1.27      albertel   74: 		    ++$Apache::lonhomework::history{'resource.version'};
1.23      albertel   75: 		$Apache::lonhomework::results{"resource.$version.checkedin"}=
1.4       albertel   76: 		    $user.'@'.$domain;
1.23      albertel   77: 		$Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
1.22      albertel   78: 		    $slot_name;
1.28      albertel   79: 		foreach my $key (keys(%Apache::lonhomework::history)) {
                     80: 		    if ($key=~/^resource\.0\./) {
                     81: 			$Apache::lonhomework::results{$key}='';
                     82: 		    }
                     83: 		}
1.4       albertel   84: 		return 1;
                     85: 	    }
                     86: 	}
                     87:     }
                     88:     return 0;
                     89: }
                     90: 
1.25      albertel   91: sub get_version {
1.29      albertel   92:     my ($version,$previous);
1.25      albertel   93:     if ($env{'form.previousversion'} && 
                     94: 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
1.29      albertel   95: 	$version=$env{'form.previousversion'};
                     96: 	$previous=1;
                     97:     } else {
                     98: 	$version=$Apache::lonhomework::history{'resource.version'};
                     99: 	$previous=0;
                    100:     }
                    101:     if (wantarray) {
                    102: 	return ($version,$previous);
1.25      albertel  103:     }
1.29      albertel  104:     return $version;
1.25      albertel  105: }
                    106: 
1.8       albertel  107: sub add_previous_version_button {
1.25      albertel  108:     my ($status)=@_;
1.8       albertel  109:     my $result;
1.29      albertel  110:     if ($Apache::lonhomework::history{'resource.version'} eq '') {
1.25      albertel  111: 	return '';
                    112:     }
1.29      albertel  113:     if ($Apache::lonhomework::history{'resource.version'} < 2 &&
                    114: 	$status ne 'NEEDS_CHECKIN') {
1.25      albertel  115: 	return '';
                    116:     }
1.29      albertel  117:     my $version=&get_version();
                    118:     if ($env{'form.previousversion'} ne '' &&
                    119: 	$env{'form.previousversion'} eq $version) {
                    120: 	$result.="<h3>".&mt("Showing previous version [_1]",$version).
                    121: 	    "</h3>\n";
                    122:     }
                    123:     my @to_show;
                    124:     foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
                    125: 	if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
                    126: 	    push(@to_show,$test_version);
                    127: 	}
                    128:     }
                    129:     my $list='<option>'.
                    130: 	join("</option>\n<option>",@to_show).
                    131: 	     "</option>\n";
                    132:     $result.='<form name="getprevious" method="POST" action="';
                    133:     my $uri=$env{'request.uri'};
                    134:     if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    135:     $result.=$uri.'">'.
                    136: 	&mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
                    137: <option>'.&mt('Pick one').'</option>
                    138: '.$list.'
                    139: </select>')."</form>";
1.8       albertel  140:     return $result;
                    141: }
                    142: 
1.13      albertel  143: sub add_grading_button {
1.29      albertel  144:     my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13      albertel  145: 	&mt("Get a submission to grade").'" />';
                    146:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.32      albertel  147:     if ( 1) {
                    148: 	#need a permissions for limitng this to 'powerful users'
1.34      albertel  149: 
                    150: 	my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
                    151: 	$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);
                    152: 
                    153: 	$result.=' <input type="submit" name="reviewagrading" value="'.
                    154: 	    &mt("Select an entry from the grading queue").'" /> </p>'."\n";
                    155: 
                    156: 	($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
                    157: 	$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  158: 	$result.=' <input type="submit" name="reviewasubmission" value="'.
1.34      albertel  159: 	    &mt("Select an entry from the review queue").'" /> </p>'."\n";
1.32      albertel  160:     }
1.13      albertel  161:     return $result;
                    162: }
                    163: 
1.22      albertel  164: sub add_request_another_attempt_button {
1.25      albertel  165:     my $result;
                    166:     $result.=' <input type="submit" name="requestattempt" value="'.
                    167: 	&mt("Request another attempt").'" />';
                    168:     return $result;
1.22      albertel  169: }
                    170: 
1.30      albertel  171: sub preserve_grade_info {
                    172:     my $result;
                    173:     # if we are viewing someone else preserve that info
                    174:     if (defined $env{'form.grade_symb'}) {
                    175: 	foreach my $field ('symb','courseid','domain','username') {
                    176: 	    $result .= '<input type="hidden" name="grade_'.$field.
                    177: 		'" value="'.$env{"form.grade_$field"}.'" />'."\n";
                    178: 	}
                    179:     }
                    180:     return $result;
                    181: }
                    182: 
1.1       albertel  183: sub start_Task {
                    184:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    185: 
1.4       albertel  186:     my ($status,$accessmsg,$slot);
1.16      albertel  187:     if ($target ne 'webgrade') {
                    188: 	&Apache::structuretags::initialize_storage();
                    189: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
                    190:     } 
                    191: 
1.4       albertel  192:     $Apache::lonhomework::parsing_a_task=1;
1.1       albertel  193:     #should get back a <html> or the neccesary stuff to start XML/MathML
                    194:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    195: 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16      albertel  196:     
1.8       albertel  197:     if ($target eq 'web') {
1.13      albertel  198: 	if ($Apache::lonhomework::modifygrades) {
                    199: 	    $body_tag_start.='<form name="gradesubmission" method="POST" action="';
                    200: 	    my $uri=$env{'request.uri'};
                    201: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    202: 	    $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
                    203: 	}
1.8       albertel  204:     }
1.21      albertel  205:     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1       albertel  206: 	$target eq 'tex') {
1.29      albertel  207: 	my ($version,$previous)=&get_version();
1.14      albertel  208: 	($status,$accessmsg,my $slot_name,$slot) = 
1.4       albertel  209: 	    &Apache::lonhomework::check_task_access('0');
1.9       albertel  210: 	push(@Apache::inputtags::status,$status);
1.14      albertel  211: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  212: 	my $expression='$external::datestatus="'.$status.'";';
1.23      albertel  213: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1       albertel  214: 	&Apache::run::run($expression,$safeeval);
                    215: 	&Apache::lonxml::debug("Got $status");
1.25      albertel  216: 	$body_tag_start.=&add_previous_version_button($status);
1.29      albertel  217: 	if (!$previous && (
                    218: 			   ( $status eq 'CLOSED' ) ||
                    219: 			   ( $status eq 'BANNED') ||
                    220: 			   ( $status eq 'UNAVAILABLE') ||
                    221: 			   ( $status eq 'NOT_IN_A_SLOT') ||
                    222: 			   ( $status eq 'NEEDS_CHECKIN') ||
                    223: 			   ( $status eq 'WAITING_FOR_GRADE') ||
                    224: 			   ( $status eq 'INVALID_ACCESS') )) {
1.1       albertel  225: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    226: 	    if ( $target eq "web" ) {
1.4       albertel  227: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
                    228: 		my $msg;
1.1       albertel  229: 		if ($status eq 'UNAVAILABLE') {
                    230: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  231: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    232: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4       albertel  233: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    234: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    235: 			'</h1>'.&proctor_validation_screen($slot);
1.22      albertel  236: 		} elsif ($status eq 'WAITING_FOR_GRADE') {
                    237: 		    $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1       albertel  238: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    239: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    240: 		}
                    241: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    242: 		    $msg.='The problem '.$accessmsg;
                    243: 		}
                    244: 		$result.=$msg.'<br />';
                    245: 	    } elsif ($target eq 'tex') {
                    246: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    247: 		if ($status eq 'UNAVAILABLE') {
                    248: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    249: 		} else {
                    250: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    251: 		}
1.22      albertel  252: 	    } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4       albertel  253: 		if ($status eq 'NEEDS_CHECKIN') {
1.22      albertel  254: 		    if (&proctor_check_auth($slot_name,$slot)) {
1.4       albertel  255: 			#FIXME immeadiatly add this to the grading queue
                    256:                         #      with slot->{'endtime'} for when grading can 
                    257:                         #      begin on this resource
1.22      albertel  258: 			# FIXME I think the above is done by default,
                    259:                         #        need to check that
                    260:                         #        failure doesn't do this.
1.4       albertel  261:  		    }
                    262: 		}
1.1       albertel  263: 	    }
                    264: 	} elsif ($target eq 'web') {
                    265: 	    my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    266: 	    $result.="$head_tag_start<title>$name</title></head>
                    267:               $body_tag_start \n $form_tag_start".	
                    268: 	      '<input type="hidden" name="submitted" value="yes" />';
1.30      albertel  269: 	    $result.=&preserve_grade_info();
1.29      albertel  270: 	    my ($version,$previous)=&get_version();
1.25      albertel  271: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22      albertel  272: 		$result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
1.29      albertel  273: 		if (!$previous) {
                    274: 		    $result.=&add_request_another_attempt_button();
                    275: 		}
1.22      albertel  276: 	    }
1.25      albertel  277: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
1.22      albertel  278: 		$result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
                    279: 	    }
1.1       albertel  280: 	}
1.21      albertel  281:     } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                    282: 	      $target eq 'webgrade') {
1.32      albertel  283: 	my $webgrade='yes';
1.21      albertel  284: 	if ($target eq 'webgrade') {
1.32      albertel  285: 	    $result.=$head_tag_start.$body_tag_start;
1.31      albertel  286: 	    $result.='<br />Review'.&show_queue('reviewqueue');
1.33      albertel  287: 	    $result.='<br />Grade'.&show_queue('gradingqueue');
1.30      albertel  288: 	}
1.33      albertel  289: 	# FIXME Blast! still need to reorg this, need to reshow the
                    290:         #       queue being reviewed once done with the grade pass...
                    291:         #       Hrrm, vaildation pass should perhaps say 'not_locked'
                    292:         #       perhaps do a search if there is a key that is mine and if
                    293:         #       there isn't reshow the queue....
                    294: 	my ($todo,$status_code)=&get_key_todo($target);
                    295: 
                    296: 	&Apache::lonnet::logthis("got todo -$todo- stat -$status_code-");
                    297: 	if ($todo) {
                    298: 	    &setup_env_for_other_user($todo,$safeeval);
                    299: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
                    300: 	    $result.="\n".'<table><tr><td>Found '.
                    301: 		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
                    302: 	    $form_tag_start.=
                    303: 		'<input type="hidden" name="gradingkey" value="'.
                    304: 		&Apache::lonnet::escape($todo).'" />';
                    305: 	    $Apache::bridgetask::queue_key=$todo;
                    306: 	    &Apache::structuretags::initialize_storage();
                    307: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
                    308: 	    if ($target eq 'webgrade') {
                    309: 		$result.='<br />After -'.&show_queue($env{'form.queue'});
                    310: 		$result.="\n".'<table width="100%" style="width:100%" border="1">';
                    311: 		if ($status_code eq 'selected') {
                    312: 		    $form_tag_start.=
                    313: 			'<input type="hidden" name="queuemode" value="selected" />';
                    314: 		}
                    315: 	    }
1.15      albertel  316: 	} else {
1.33      albertel  317: 	    if ($target eq 'webgrade') {
                    318: 		$result.="\n";
                    319: 		if      ($status_code eq 'stop') {
                    320: 		    $result.='<b>'.&mt("Stopped grading.").'</b>';
                    321: 		} elsif ($status_code eq 'lock_failed') {
                    322: 		    $result.='<b>'.&mt("Failed to lock the request record.").'</b>';
                    323: 		} elsif ($status_code eq 'unlock') {
                    324: 		    $result.='<b>'.&mt("Unlocked the requested record.").'</b>';
                    325: 		    $result.=&show_queue($env{'form.queue'},1);
                    326: 		} elsif ($status_code eq 'show_list') {
                    327: 		    $result.=&show_queue($env{'form.queue'},1);
                    328: 		} else {
                    329: 		    $result.='<b>'.&mt("No user to be graded.").'</b>';
1.32      albertel  330: 		}
1.21      albertel  331: 	    }
1.33      albertel  332: 	    $webgrade='no';
                    333: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
1.32      albertel  334: 	}
                    335: 	if ($target eq 'webgrade' && defined($env{'form.queue'})) {
                    336: 	    $result.=$form_tag_start;
                    337: 	    $result.='<input type="hidden" name="webgrade" value="'.
                    338: 		$webgrade.'" />';
                    339: 	    $result.='<input type="hidden" name="queue" value="'.
                    340: 		$env{'form.queue'}.'" />';
1.15      albertel  341: 	}
1.1       albertel  342:     } else {
                    343: 	# page_start returned a starting result, delete it if we don't need it
                    344: 	$result = '';
                    345:     }
                    346:     return $result;
                    347: }
                    348: 
1.32      albertel  349: sub get_key_todo {
                    350:     my ($target)=@_;
                    351:     my $todo;
1.33      albertel  352: 
                    353:     if (defined($env{'form.reviewasubmission'})) {
                    354: 	&Apache::lonnet::logthis("review a submission....");
                    355: 	$env{'form.queue'}='reviewqueue';
                    356: 	return (undef,'show_list');
                    357:     }
                    358: 
                    359:     if (defined($env{'form.reviewagrading'})) {
                    360: 	&Apache::lonxml::debug("review a grading....");
                    361: 	$env{'form.queue'}='gradingqueue';
                    362: 	return (undef,'show_list');
                    363:     }
                    364: 
1.32      albertel  365:     my $queue=$env{'form.queue'};
1.33      albertel  366: 
1.32      albertel  367:     if (!defined($queue)) {
                    368: 	$env{'form.queue'}=$queue='gradingqueue';
                    369:     }
1.33      albertel  370: 
1.32      albertel  371:     my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33      albertel  372: 
1.32      albertel  373:     if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33      albertel  374: 	&& !defined($env{'form.gradingaction'}) 
                    375: 	&& $env{'form.queuemode'} eq 'selected') {
                    376: 	
                    377: 	my $who=&queue_key_locked($queue,$gradingkey);
                    378: 	my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    379: 	if ($who eq $me) {
                    380: 	    &Apache::lonxml::debug("Found a key was given to me");
                    381: 	    return ($gradingkey,'selected');
                    382: 	} else {
                    383: 	    return (undef,'show_list');
                    384: 	}
                    385: 
                    386:     }
                    387: 
                    388:     if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
                    389: 	if ($env{'form.gradingaction'} eq 'resume') {
                    390: 	    delete($env{'form.gradingaction'});
                    391: 	    &Apache::lonxml::debug("Resuming a key");
1.32      albertel  392: 	    return ($gradingkey);
1.33      albertel  393: 	} elsif ($env{'form.gradingaction'} eq 'unlock') {
                    394: 	    &Apache::lonxml::debug("Unlocking a key ".
                    395: 				     &check_queue_unlock($queue,$gradingkey,1));
                    396: 	    return (undef,'unlock');
                    397: 	} elsif ($env{'form.gradingaction'} eq 'select') {
                    398: 	    &Apache::lonxml::debug("Locking a key");
                    399: 	    if (&lock_key($queue,$gradingkey)) {
                    400: 		&Apache::lonxml::debug("Success $queue");
                    401: 		return ($gradingkey);
                    402: 	    }
                    403: 	    &Apache::lonxml::debug("Failed $queue");
                    404: 	    return (undef,'lock_failed');
1.32      albertel  405: 	}
                    406:     }
1.33      albertel  407: 
                    408:     if ($env{'form.queuemode'} ne 'selected') {
                    409: 	# don't get something new from the queue if they hit the stop button
                    410:     	if (!($env{'form.stop'} && $target eq 'webgrade') 
                    411: 	    && !$env{'form.gradingaction'}) {
                    412: 	    &Apache::lonxml::debug("Getting anew $queue");
                    413: 	    return (&get_from_queue($queue));
                    414: 	} else {
                    415: 	    return (undef,'stop');
                    416: 	}
1.32      albertel  417:     }
1.33      albertel  418:     return (undef,undef)
1.32      albertel  419: }
                    420: 
1.1       albertel  421: sub end_Task {
                    422:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    423:     my $result='';
                    424:     my $status=$Apache::inputtags::status['-1'];
1.29      albertel  425:     my ($version,$previous)=&get_version();
1.1       albertel  426:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel  427: 	$target eq 'tex') {
1.1       albertel  428: 	if (
1.11      albertel  429: 	    (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1       albertel  430: 	    ($target eq 'answer') || ($target eq 'tex')
                    431: 	   ) {
                    432: 	    if ($target eq 'web') {
1.29      albertel  433: 		if ($status eq 'CAN_ANSWER' && !$previous) {
1.15      albertel  434: 		    $result.="\n".'<table border="1">'.
1.28      albertel  435: 			&Apache::inputtags::file_selector("$version.0",
                    436: 							  "bridgetask","*",
1.9       albertel  437: 							  'portfolioonly').
                    438: 							  "</table>";
                    439: 		    $result.=&Apache::inputtags::gradestatus('0');
                    440: 		}
1.13      albertel  441: 	    } 
                    442: 	    if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  443: 		$result.=&Apache::lonxml::xmlend().'</html>';
                    444: 	    }
                    445: 	}
1.29      albertel  446: 	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12      albertel  447: 	    my $award='SUBMITTED';
1.28      albertel  448: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20      albertel  449: 						    'portfiles',\$award);
1.14      albertel  450: 	    if ($award eq 'SUBMITTED' &&
1.28      albertel  451: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
                    452: 		$Apache::lonhomework::results{"resource.0.tries"}=
                    453: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
                    454: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
                    455: 
                    456: 		$Apache::lonhomework::results{"resource.0.award"}=
                    457: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
                    458: 		    $award;
1.10      albertel  459: 	    }
1.4       albertel  460: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    461: 	    &Apache::structuretags::finalize_storage();
1.14      albertel  462: 	    if ($award eq 'SUBMITTED') {
1.31      albertel  463: 		&add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14      albertel  464: 	    }
1.1       albertel  465: 	}
1.32      albertel  466: 	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20      albertel  467: 	    my $optional_required=
                    468: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                    469: 					   $safeeval);
                    470: 	    my $optional_passed=0;
                    471: 	    my $mandatory_failed=0;
                    472: 	    my $ungraded=0;
                    473: 	    my $review=0;   
1.21      albertel  474: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20      albertel  475: 	    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
                    476: 		my $status=
1.25      albertel  477: 		    $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20      albertel  478: 		my $mandatory=
                    479: 		    ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
                    480: 		if ($status eq 'pass') {
                    481: 		    if (!$mandatory) { $optional_passed++; }
                    482: 		} elsif ($status eq 'fail') {
                    483: 		    if ($mandatory) { $mandatory_failed++; }
                    484: 		} elsif ($status eq 'ungraded') {
                    485: 		    $ungraded++;
                    486: 		} elsif ($status eq 'review') {
                    487: 		    $review++;
                    488: 		}	
                    489: 	    }
                    490: 	    if ($optional_passed < $optional_required) {
                    491: 		$mandatory_failed++;
                    492: 	    }
1.21      albertel  493: 	    &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
                    494: 	    $Apache::lonhomework::results{'resource.grader'}=
1.20      albertel  495: 		$env{'user.name'}.'@'.$env{'user.domain'};
                    496: 	    if ($review) {
1.25      albertel  497: 		$Apache::lonhomework::results{"resource.$version.status"}='review';
1.33      albertel  498: 		if ($env{'form.queue'} eq 'reviewqueue') {
                    499: 		    &check_queue_unlock($env{'form.queue'});
                    500: 		    &Apache::lonxml::debug(" still needs review not changing status.");
                    501: 		} else {
                    502: 		    &move_between_queues('gradingqueue','reviewqueue');
                    503: 		}
1.20      albertel  504: 	    } elsif ($ungraded) {
1.25      albertel  505: 		$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.32      albertel  506: 		# FIXME if in review queue need to move back to grading queue
1.33      albertel  507: 		if ($env{'form.queue'} eq 'reviewqueue') {
                    508: 		    &Apache::lonxml::debug("moving back.");
                    509: 		    &move_between_queues('reviewqueue','gradingqueue');
                    510: 		} else {
                    511: 		    &check_queue_unlock($env{'form.queue'});
                    512: 		}
1.20      albertel  513: 	    } elsif ($mandatory_failed) {
1.25      albertel  514: 		$Apache::lonhomework::results{"resource.$version.status"}='fail';
                    515: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                    516: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                    517: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.32      albertel  518: 		&remove_from_queue($env{'form.queue'});
1.20      albertel  519: 	    } else {
1.25      albertel  520: 		$Apache::lonhomework::results{"resource.$version.status"}='pass';
                    521: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                    522: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                    523: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32      albertel  524: 		&remove_from_queue($env{'form.queue'});
1.20      albertel  525: 	    }
1.26      albertel  526: 	    $Apache::lonhomework::results{"resource.status"}=
                    527: 		$Apache::lonhomework::results{"resource.$version.status"};
1.28      albertel  528: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel  529: 		$Apache::lonhomework::results{"resource.0.award"}=
                    530: 		    $Apache::lonhomework::results{"resource.$version.award"};
                    531: 		$Apache::lonhomework::results{"resource.0.awarded"}=
                    532: 		    $Apache::lonhomework::results{"resource.$version.awarded"};
                    533: 		$Apache::lonhomework::results{"resource.0.solved"}=
                    534: 		    $Apache::lonhomework::results{"resource.$version.solved"};
1.25      albertel  535: 	    }
1.21      albertel  536: 	    &Apache::structuretags::finalize_storage();
1.20      albertel  537: 	}
1.15      albertel  538:     } elsif ($target eq 'webgrade') {
1.18      albertel  539: 	$result.="</table>\n<hr />";
1.20      albertel  540: 	#$result.='<input type="submit" name="next" value="'.
                    541: 	#    &mt('Save &amp; Next').'" /> ';
                    542: 	#$result.='<input type="submit" name="end" value="'.
                    543: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                    544: 	#$result.='<input type="submit" name="throwaway" value="'.
                    545: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                    546: 	#$result.='<input type="submit" name="save" value="'.
                    547: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15      albertel  548: 	$result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1       albertel  549:     } elsif ($target eq 'meta') {
1.2       albertel  550: 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1       albertel  551: 	#$result.=&Apache::response::meta_part_order();
                    552: 	#$result.=&Apache::response::meta_response_order();
                    553:     }
1.4       albertel  554:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel  555:     return $result;
                    556: }
                    557: 
1.31      albertel  558: sub move_between_queues {
                    559:     my ($src_queue,$dest_queue)=@_;
                    560:     my $cur_data=&get_queue_data($src_queue);
                    561:     if (!$cur_data) { return 'not_exist'; }
                    562:     my $result=&add_to_queue($dest_queue,$cur_data->[0]);
                    563:     if ($result ne 'ok') {
                    564: 	return $result;
                    565:     }
                    566:     &check_queue_unlock($src_queue);
                    567:     return &remove_from_queue($src_queue);
1.21      albertel  568: }
                    569: 
                    570: sub check_queue_unlock {
1.32      albertel  571:     my ($queue,$key,$allow_not_me)=@_;
1.30      albertel  572:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32      albertel  573:     if (!defined($key)) {
                    574: 	$key="$symb\0queue\0$uname\@$udom";
                    575:     }
1.30      albertel  576:     my $cnum=$env{'course.'.$cid.'.num'};
                    577:     my $cdom=$env{'course.'.$cid.'.domain'};
                    578:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    579:     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
                    580:     if  ($who eq $me) {
1.32      albertel  581: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
                    582:     } elsif ($allow_not_me) {
1.33      albertel  583: 	&Apache::lonxml::debug("unlocking $who by $me");
1.32      albertel  584: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30      albertel  585:     }
1.32      albertel  586:     return 'not_owner';
1.21      albertel  587: }
                    588: 
                    589: sub remove_from_queue {
1.30      albertel  590:     my ($queue)=@_;
1.27      albertel  591:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    592:     my $cnum=$env{'course.'.$cid.'.num'};
                    593:     my $cdom=$env{'course.'.$cid.'.domain'};
                    594:     my $key="$symb\0queue\0$uname\@$udom";
                    595:     my @keys=($key,"$key\0locked");
1.31      albertel  596:     return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21      albertel  597: }
                    598: 
1.16      albertel  599: sub setup_env_for_other_user {
                    600:     my ($queue_key,$safeeval)=@_;
                    601:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30      albertel  602:     &Apache::lonxml::debug("setup_env for $queue_key");
1.16      albertel  603:     $env{'form.grade_symb'}=$symb;
                    604:     $env{'form.grade_domain'}=$udom;
                    605:     $env{'form.grade_username'}=$uname;
                    606:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                    607:     &Apache::lonxml::initialize_rndseed($safeeval);
                    608: }
                    609: 
1.31      albertel  610: sub get_queue_data {
                    611:     my ($queue)=@_;
                    612:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    613:     my $cnum=$env{'course.'.$cid.'.num'};
                    614:     my $cdom=$env{'course.'.$cid.'.domain'};
                    615:     my $todo="$symb\0queue\0$uname\@$udom";
                    616:     my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
                    617:     if ($key eq $todo && ref($value)) {
                    618: 	return $value;
                    619:     }
                    620:     return undef;
                    621: }
                    622: 
1.14      albertel  623: sub add_to_queue {
1.31      albertel  624:     my ($queue,$slot_name)=@_;
1.14      albertel  625:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    626:     my $cnum=$env{'course.'.$cid.'.num'};
                    627:     my $cdom=$env{'course.'.$cid.'.domain'};
                    628:     my %data;
1.31      albertel  629:     $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
                    630:     return &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14      albertel  631: }
                    632: 
                    633: sub show_queue {
1.32      albertel  634:     my ($queue,$with_selects)=@_;
1.14      albertel  635:     my $result;
                    636:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    637:     my $cnum=$env{'course.'.$cid.'.num'};
                    638:     my $cdom=$env{'course.'.$cid.'.domain'};
1.16      albertel  639:     my $regexp="^$symb\0";
1.30      albertel  640:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31      albertel  641:     my ($tmp)=%queue;
                    642:     if ($tmp=~/^error: 2 /) {
1.33      albertel  643: 	return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31      albertel  644:     }
1.33      albertel  645:     $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32      albertel  646:     if ($with_selects) { $result.="<th></th>"; }
                    647:     $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14      albertel  648:     foreach my $key (sort(keys(%queue))) {
1.32      albertel  649: 	if ($key=~/locked$/ && !$with_selects) {
1.16      albertel  650: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    651: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  652: 	    $result.="<tr><td>$title</td><td>$uname</td>";
1.16      albertel  653: 	    $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32      albertel  654: 	} elsif ($key=~/timestamp$/ && !$with_selects) {
1.16      albertel  655: 	    my ($symb,undef) = split("\0",$key);
                    656: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  657: 	    $result.="<tr><td>$title</td><td></td>";
1.16      albertel  658: 	    $result.='<td>last queue modification time</td><td>'.
                    659: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32      albertel  660: 	} elsif ($key!~/(timestamp|locked)$/) {
1.16      albertel  661: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    662: 	    my $title=&Apache::lonnet::gettitle($symb);
1.32      albertel  663: 	    $result.="<tr>";
1.35    ! albertel  664: 	    my $slot=$queue{$key}->[0];
        !           665: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
1.32      albertel  666: 	    if ($with_selects) {
                    667: 		my $ekey=&Apache::lonnet::escape($key);
                    668: 		my ($action,$description)=('select',&mt('Select'));
                    669: 		if (exists($queue{"$key\0locked"})) {
                    670: 		    my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    671: 		    if ($me eq $queue{"$key\0locked"}) {
                    672: 			($action,$description)=('resume',&mt('Resume'));
                    673: 		    } else {
                    674: 			($action,$description)=('unlock',&mt('Unlock'));
                    675: 		    }
                    676: 		}
1.35    ! albertel  677: 		if (time > $slot_data{'endtime'}) {
        !           678: 		    $result.=(<<FORM);
1.32      albertel  679: <td>
                    680: <form method="POST">
                    681:  <input type="hidden" name="gradingkey" value="$ekey" />
                    682:  <input type="hidden" name="queue" value="$queue" />
                    683:  <input type="hidden" name="gradingaction" value="$action" />
                    684:  <input type="hidden" name="webgrade" value="no" />
1.33      albertel  685:  <input type="hidden" name="queuemode" value="selected" />
1.32      albertel  686:  <input type="submit" name="submit" value="$description" />
                    687: </form>
                    688: </td>
                    689: FORM
1.35    ! albertel  690: 
        !           691:                 } else {
        !           692: 		    $result.='<td>'.&mt("In Progress").'</td>'
        !           693: 		}
1.32      albertel  694: 	    }
                    695: 	    $result.="<td>$title</td><td>$uname</td>";
1.27      albertel  696: 	    $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20      albertel  697: 		&Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
                    698: 		"</td></tr>";
1.16      albertel  699: 	}
1.14      albertel  700:     }
1.15      albertel  701:     $result.="</table><hr />\n";
1.14      albertel  702:     return $result;
                    703: }
                    704: 
1.34      albertel  705: sub get_queue_counts {
                    706:     my ($queue)=@_;
                    707:     my $result;
                    708:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    709:     my $cnum=$env{'course.'.$cid.'.num'};
                    710:     my $cdom=$env{'course.'.$cid.'.domain'};
                    711:     my $regexp="^$symb\0";
                    712:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                    713:     my ($tmp)=%queue;
                    714:     if ($tmp=~/^error: 2 /) {
                    715: 	return (0,0,0);
                    716:     }
                    717:     my ($entries,$ready_to_grade,$locks)=(0,0,0);
                    718:     foreach my $key (sort(keys(%queue))) {
                    719: 	if ($key=~/locked$/) {
                    720: 	    $locks++;
                    721: 	} elsif ($key=~/timestamp$/) {
                    722: 	    #ignore
                    723: 	} elsif ($key!~/(timestamp|locked)$/) {
                    724: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    725: 	    $entries++;
                    726: 	    my $slot=$queue{$key}->[0];
                    727: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                    728: 	    if (time > $slot_data{'endtime'}) {
                    729: 		$ready_to_grade++;
                    730: 	    }
                    731: 	}
                    732:     }
                    733:     return ($entries,$ready_to_grade,$locks);
                    734: }
                    735: 
1.14      albertel  736: sub decode_queue_key {
                    737:     my ($key)=@_;
                    738:     my ($symb,undef,$user) = split("\0",$key);
                    739:     my ($uname,$udom) = split('@',$user);
                    740:     return ($symb,$uname,$udom);
                    741: }
                    742: 
                    743: sub queue_key_locked {
1.30      albertel  744:     my ($queue,$key,$cdom,$cnum)=@_;
1.33      albertel  745:     if (!defined($cdom) || !defined($cnum)) {
                    746: 	my (undef,$cid)=&Apache::lonxml::whichuser();
                    747: 	$cnum=$env{'course.'.$cid.'.num'};
                    748: 	$cdom=$env{'course.'.$cid.'.domain'};
                    749:     }
1.14      albertel  750:     my ($key_locked,$value)=
1.30      albertel  751: 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14      albertel  752:     if ($key_locked eq "$key\0locked") {
                    753: 	return $value;
                    754:     }
                    755:     return undef;
                    756: }
                    757: 
                    758: sub pick_from_queue_data {
1.30      albertel  759:     my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
                    760:     foreach my $key (keys(%$queuedata)) {
1.14      albertel  761: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
                    762: 	if ($check_section) {
                    763: 	    my $section=&Apache::lonnet::getsection($uname,$udom);
1.17      albertel  764: 	    if ($section eq $check_section) {
1.33      albertel  765: 		&Apache::lonxml::debug("my sec");
1.15      albertel  766: 		next;
                    767: 	    }
1.14      albertel  768: 	}
1.30      albertel  769: 	my $slot=$queuedata->{$key}[0];
1.14      albertel  770: 	my %slot_data=&Apache::lonnet::get_slot($slot);
1.15      albertel  771: 	if ($slot_data{'endtime'} > time) { 
1.33      albertel  772: 	    &Apache::lonxml::debug("not time");
1.15      albertel  773: 	    next;
                    774: 	}
1.30      albertel  775: 	if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33      albertel  776: 	    &Apache::lonxml::debug("someone already has um.");
1.15      albertel  777: 	    next;
                    778: 	}
1.14      albertel  779: 	return $key;
                    780:     }
                    781:     return undef;
                    782: }
                    783: 
1.15      albertel  784: sub find_mid_grade {
1.30      albertel  785:     my ($queue,$symb,$cdom,$cnum)=@_;
1.16      albertel  786:     my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15      albertel  787:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    788:     if ($todo) {
1.30      albertel  789: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel  790: 	if ($who eq $me) { return $todo; }
                    791:     }
                    792:     my $regexp="^$symb\0.*\0locked\$";
1.30      albertel  793:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel  794:     foreach my $key (keys(%locks)) {
                    795: 	my $who=$locks{$key};
                    796: 	if ($who eq $me) {
                    797: 	    $todo=$key;
                    798: 	    $todo=~s/\0locked$//;
                    799: 	    return $todo;
                    800: 	}
                    801:     }
                    802:     return undef;
                    803: }
                    804: 
1.32      albertel  805: sub lock_key {
                    806:     my ($queue,$todo)=@_;
                    807:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    808:     my (undef,$cid)=&Apache::lonxml::whichuser();
                    809:     my $cnum=$env{'course.'.$cid.'.num'};
                    810:     my $cdom=$env{'course.'.$cid.'.domain'};
                    811:     my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
                    812: 					$cdom,$cnum);
1.33      albertel  813:     &Apache::lonxml::debug("success $success $todo");
1.32      albertel  814:     if ($success eq 'ok') {
                    815: 	return 1;
                    816:     }
                    817:     return 0;
                    818: }
                    819: 
1.14      albertel  820: sub get_from_queue {
1.30      albertel  821:     my ($queue)=@_;
1.14      albertel  822:     my $result;
                    823:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    824:     my $cnum=$env{'course.'.$cid.'.num'};
                    825:     my $cdom=$env{'course.'.$cid.'.domain'};
1.32      albertel  826:     my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33      albertel  827:     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16      albertel  828:     if ($todo) { return $todo; }
1.14      albertel  829:     while (1) {
                    830: 	my $starttime=time;
1.30      albertel  831: 	&Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14      albertel  832: 			     $cdom,$cnum);
1.33      albertel  833: 	&Apache::lonxml::debug("$starttime");
1.14      albertel  834: 	my $regexp="^$symb\0queue\0";
1.30      albertel  835: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33      albertel  836: 	#make a pass looking for a user _not_ in my section
1.14      albertel  837: 	if ($env{'request.course.sec'}) {
1.33      albertel  838: 	    &Apache::lonxml::debug("sce");
1.30      albertel  839: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
                    840: 					\%queue,$cdom,$cnum);
1.33      albertel  841: 	    &Apache::lonxml::debug("sce $todo");
1.14      albertel  842: 	}
1.33      albertel  843: 	# no one _not_ in our section so look for any user that is
                    844: 	# ready for grading
1.14      albertel  845: 	if (!$todo) {
1.33      albertel  846: 	    &Apache::lonxml::debug("no sce");
1.31      albertel  847: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
                    848: 					\%queue,$cdom,$cnum);
1.33      albertel  849: 	    &Apache::lonxml::debug("no sce $todo");
1.14      albertel  850: 	}
                    851: 	# no user to grade 
                    852: 	if (!$todo) { last; }
1.33      albertel  853: 	&Apache::lonxml::debug("got $todo");
1.14      albertel  854: 	# otherwise found someone so lets try to lock them
1.32      albertel  855: 	# unless someone else already picked them
                    856: 	if (!&lock_key($queue,$todo)) { next; }
1.14      albertel  857: 	my (undef,$endtime)=
1.30      albertel  858: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel  859: 				 $cdom,$cnum);
1.33      albertel  860: 	&Apache::lonxml::debug("emd  $endtime");
1.14      albertel  861: 	# someone else already modified the queue, 
                    862: 	# perhaps our picked user wass already fully graded between
                    863: 	# when we picked him and when we locked his record? so lets
                    864: 	# double check.
                    865: 	if ($endtime != $starttime) {
                    866: 	    my ($key,$value)=
1.30      albertel  867: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel  868: 				     $cdom,$cnum);
1.33      albertel  869: 	    &Apache::lonxml::debug("check  $key .. $value");
1.14      albertel  870: 	    if ($key eq $todo && ref($value)) {
                    871: 	    } else {
1.30      albertel  872: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel  873: 				     $cdom,$cnum);
1.33      albertel  874: 		&Apache::lonxml::debug("del");
1.14      albertel  875: 		next;
                    876: 	    }
                    877: 	}
1.33      albertel  878: 	&Apache::lonxml::debug("last $todo");
1.14      albertel  879: 	last;
                    880:     }
                    881:     return $todo;
                    882: }
                    883: 
1.1       albertel  884: sub start_ClosingParagraph {
                    885:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    886:     my $result;
                    887:     if ($target eq 'web') {
1.13      albertel  888:     } elsif ($target eq 'webgrade') {
                    889: 	&Apache::lonxml::startredirection();
1.1       albertel  890:     }
                    891:     return $result;
                    892: }
                    893: 
                    894: sub end_ClosingParagraph {
                    895:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    896:     my $result;
                    897:     if ($target eq 'web') {
1.13      albertel  898:     } elsif ($target eq 'webgrade') {
                    899: 	&Apache::lonxml::endredirection();
1.1       albertel  900:     }
                    901:     return $result;
                    902: }
                    903: 
1.19      albertel  904: sub get_id {
                    905:     my ($parstack,$safeeval)=@_;
                    906:     my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
                    907:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                    908:     return $id;
                    909: }
                    910: 
1.1       albertel  911: my %dimension;
                    912: sub start_Dimension {
                    913:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    914:     undef(%dimension);
1.19      albertel  915:     my $dim_id=&get_id($parstack,$safeeval);
1.9       albertel  916:     $Apache::bridgetask::dimension=$dim_id;
                    917:     push(@Apache::bridgetask::dimensionlist,$dim_id);
                    918:     undef(@Apache::bridgetask::instance);
1.20      albertel  919:     $Apache::bridgetask::dimensionmandatory{$dim_id}=
                    920: 	&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel  921:     return '';
                    922: }
                    923: 
1.13      albertel  924: sub get_instance {
                    925:     &Apache::response::pushrandomnumber();
                    926:     my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29      albertel  927:     my $num=@order;
                    928:     my $version=&get_version();
                    929:     my $which=($version-1)%$num;
                    930:     return $order[$which];
1.13      albertel  931: }
                    932: 
1.18      albertel  933: {
                    934:     my $last_link;
                    935:     sub end_Dimension {
                    936: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    937: 	my $result;
1.25      albertel  938: 	my $dim=&get_id($parstack,$safeeval);
1.19      albertel  939: 	my $instance=&get_instance();
1.25      albertel  940: 	my $version=&get_version();
1.18      albertel  941: 	if ($target eq 'web') {
                    942: 	    $result=$dimension{'intro'}.$dimension{$instance.'.text'};
1.26      albertel  943: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
                    944: 		$Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22      albertel  945: 		foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel  946: 		    my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
                    947: 		    my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.22      albertel  948: 		    $result.='<table border="1"><tr><td>';
                    949: 		    if ($status eq 'fail') {
                    950: 			$result.='<font color="red">'.&mt('Did not pass').'</font>';
                    951: 		    } elsif ($status eq 'pass') {
                    952: 			$result.='<font color="green">'.&mt('Passed').'</font>';
                    953: 		    } else {
                    954: 			&Apache::lonxml::error("Student viewing a graded bridgetask was show a status of $status");
                    955: 		    }
                    956: 		    $result.='</td></tr><tr><td>';
1.25      albertel  957: 		    if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
                    958: 			$result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</td></tr><tr><td>';
1.22      albertel  959: 		    }
                    960: 		    $result.=$dimension{$instance.'.criteria.'.$id}.
                    961: 			'</td></tr></table>';
                    962: 		}
                    963: 	    }
1.18      albertel  964: 	} elsif ($target eq 'webgrade') {
                    965: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                    966: 		my $link='criteria_'.$instance.'_'.$id;
1.25      albertel  967: 		my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19      albertel  968: 		$result.='<tr><td width="100%" valign="top">'.
1.18      albertel  969: 		    '<a name="'.$link.'" />'.
                    970: 		    '<a name="next_'.$last_link.'" />'.
                    971: 		    '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">'.$dimension{$instance.'.criteria.'.$id}.'</textarea>'.
                    972: 		    #$dimension{$instance.'.criteria.'.$id}.
                    973: 		    '</td>'.
1.19      albertel  974: 		    '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25      albertel  975: 		    '<textarea style="width:100%" rows="8" width="25" wrap="hard" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}).'</textarea>'.
1.18      albertel  976: 		    '</td>'.
                    977: 		    '<td>'.
1.30      albertel  978: 		    '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').'/>'.&mt('Ungraded').'</label></nobr><br />'.
                    979: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
                    980: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
                    981: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18      albertel  982: 		    '</td>'.
                    983: 		    '<td>'.
                    984: 		    '<a href="#'.$last_link.'">Prev</a><br />'.
1.20      albertel  985: 		    '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
                    986: 		    '<input type="submit" name="next" value="'.
                    987: 		    &mt('Done').'" /> '.
1.30      albertel  988: 		    '<input type="submit" name="stop" value="'.
                    989: 		    &mt('Stop').'" /> '.
1.18      albertel  990: 		    '</td></tr>';
1.22      albertel  991: 		$result.='<tr><td colspan="4">';
                    992: 		my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
                    993: 		my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
1.23      albertel  994: 		foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.bridgetask.portfiles"})) {
1.22      albertel  995: 		    my $file=$file_url.$partial_file;
                    996: 		    &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
                    997: 		    $result.='<a href="'.$file.'" target="lonGRDs"><img src="'.
                    998: 			&Apache::loncommon::icon($file).'" border=0"> '.$file.
                    999: 			'</a>';
                   1000: 		}
                   1001: 		$result.='</td></tr>';
1.18      albertel 1002: 		$last_link=$link;
                   1003: 	    }
1.22      albertel 1004: 	} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19      albertel 1005: 	    my $optional_passed=0;
1.20      albertel 1006: 	    my $mandatory_failed=0;
                   1007: 	    my $ungraded=0;
                   1008: 	    my $review=0;
1.19      albertel 1009: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel 1010: 		my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
                   1011: 		$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20      albertel 1012: 		my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
                   1013: 		if ($status eq 'pass') {
                   1014: 		    if (!$mandatory) { $optional_passed++; }
                   1015: 		} elsif ($status eq 'fail') {
                   1016: 		    if ($mandatory) { $mandatory_failed++; }
1.21      albertel 1017: 		} elsif ($status eq 'review') {
                   1018: 		    $review++;
1.20      albertel 1019: 		} elsif ($status eq 'ungraded') {
                   1020: 		    $ungraded++;
1.21      albertel 1021: 		} else {
1.22      albertel 1022: 		    &Apache::lonxml::error("got weird status --$status--");
1.19      albertel 1023: 		}
                   1024: 	    }
1.20      albertel 1025: 	    if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
                   1026: 		$mandatory_failed++;
                   1027: 	    }
1.21      albertel 1028: 	    &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 1029: 	    if ($review) {
1.25      albertel 1030: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1031: 		    'review';
1.20      albertel 1032: 	    } elsif ($ungraded) {
1.25      albertel 1033: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1034: 		    'ungraded';
1.20      albertel 1035: 	    } elsif ($mandatory_failed) {
1.25      albertel 1036: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1037: 		    'fail';
1.20      albertel 1038: 	    } else {
1.25      albertel 1039: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1040: 		    'pass';
1.20      albertel 1041: 	    }
1.13      albertel 1042: 	}
1.18      albertel 1043: 	return $result;
1.1       albertel 1044:     }
                   1045: }
                   1046: 
                   1047: sub start_IntroParagraph {
                   1048:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1049:     my $result;
1.13      albertel 1050:     if ($target eq 'web' || $target eq 'webgrade') {
                   1051: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel 1052: 	    &Apache::lonxml::startredirection();
                   1053: 	}
                   1054:     }
                   1055:     return $result;
                   1056: }
                   1057: 
                   1058: sub end_IntroParagraph {
                   1059:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1060:     my $result;
1.13      albertel 1061:     if ($target eq 'web' || $target eq 'webgrade') {
                   1062: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel 1063: 	    $dimension{'intro'}=&Apache::lonxml::endredirection();
                   1064: 	}
                   1065:     }
                   1066:     return $result;
                   1067: }
                   1068: 
                   1069: sub start_Instance {
                   1070:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel 1071:     my $id=&get_id($parstack,$safeeval);
                   1072:     push(@{$dimension{'instances'}},$id);
                   1073:     push(@Apache::bridgetask::instance,$id);
                   1074:     push(@Apache::bridgetask::instancelist,$id);
1.20      albertel 1075:     $dimension{$id.'.optionalrequired'}=
1.19      albertel 1076: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1       albertel 1077:     return '';
                   1078: }
                   1079: 
                   1080: sub end_Instance {
                   1081:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1082:     return '';
                   1083: }
                   1084: 
                   1085: sub start_InstanceText {
                   1086:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13      albertel 1087:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel 1088: 	&Apache::lonxml::startredirection();
                   1089:     }
                   1090:     return '';
                   1091: }
                   1092: 
                   1093: sub end_InstanceText {
                   1094:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel 1095:     my $instance_id=$Apache::bridgetask::instance[-1];
1.13      albertel 1096:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel 1097: 	$dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
                   1098:     }
                   1099:     return '';
                   1100: }
                   1101: 
                   1102: sub start_Criteria {
                   1103:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.21      albertel 1104:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1       albertel 1105: 	&Apache::lonxml::startredirection();
                   1106:     }
                   1107:     return '';
                   1108: }
                   1109: 
                   1110: sub end_Criteria {
                   1111:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel 1112:     my $instance_id=$Apache::bridgetask::instance[-1];
1.21      albertel 1113:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1       albertel 1114: 	my $criteria=&Apache::lonxml::endredirection();
1.19      albertel 1115: 	my $id=&get_id($parstack,$safeeval);
1.1       albertel 1116: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19      albertel 1117: 	$dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
                   1118: 	    &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel 1119: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
                   1120:     }
                   1121:     return '';
                   1122: }
                   1123: 
1.4       albertel 1124: sub proctor_validation_screen {
                   1125:     my ($slot) = @_;
                   1126:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel 1127:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11      albertel 1128:     $user=$env{'form.proctorname'};
                   1129:     if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4       albertel 1130:     my $msg;
1.11      albertel 1131:     if ($env{'form.proctorpassword'}) {
1.4       albertel 1132: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                   1133: 	    .'</font></p>';
                   1134:     }
                   1135:     my $result= (<<ENDCHECKOUT);
                   1136: <h2>Proctor Validation</h2>
                   1137:     <p>Your room's proctor needs to validate your access to this resource.</p>
                   1138:     $msg
1.11      albertel 1139: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4       albertel 1140: <input type="hidden" name="validate" value="yes" />
                   1141: <input type="hidden" name="submitted" value="yes" />
                   1142: <table>
                   1143:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
                   1144:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6       albertel 1145:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4       albertel 1146: </table>
                   1147: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
                   1148: Student who should be logged in is:<br />
1.5       albertel 1149: <img src="$url" /><br />
1.4       albertel 1150: </form>
                   1151: ENDCHECKOUT
                   1152:     return $result;
                   1153: }
                   1154: 
1.1       albertel 1155: 1;
                   1156: __END__

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