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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.52      albertel    4: # $Id: bridgetask.pm,v 1.51 2005/09/20 07:14:23 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.22      albertel   63:     my ($slot_name,$slot)=@_;
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.11      albertel   71: 	    my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4       albertel   72: 	    if ($authhost ne 'no_host') {
1.23      albertel   73: 		my $version=
                     74: 		    $Apache::lonhomework::results{'resource.version'}=
1.27      albertel   75: 		    ++$Apache::lonhomework::history{'resource.version'};
1.23      albertel   76: 		$Apache::lonhomework::results{"resource.$version.checkedin"}=
1.4       albertel   77: 		    $user.'@'.$domain;
1.23      albertel   78: 		$Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
1.22      albertel   79: 		    $slot_name;
1.28      albertel   80: 		foreach my $key (keys(%Apache::lonhomework::history)) {
                     81: 		    if ($key=~/^resource\.0\./) {
                     82: 			$Apache::lonhomework::results{$key}='';
                     83: 		    }
                     84: 		}
1.4       albertel   85: 		return 1;
                     86: 	    }
                     87: 	}
                     88:     }
                     89:     return 0;
                     90: }
                     91: 
1.25      albertel   92: sub get_version {
1.29      albertel   93:     my ($version,$previous);
1.25      albertel   94:     if ($env{'form.previousversion'} && 
1.36      albertel   95: 	$env{'form.previousversion'} ne 'current' &&
1.25      albertel   96: 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
1.29      albertel   97: 	$version=$env{'form.previousversion'};
                     98: 	$previous=1;
                     99:     } else {
                    100: 	$version=$Apache::lonhomework::history{'resource.version'};
                    101: 	$previous=0;
                    102:     }
                    103:     if (wantarray) {
                    104: 	return ($version,$previous);
1.25      albertel  105:     }
1.29      albertel  106:     return $version;
1.25      albertel  107: }
                    108: 
1.8       albertel  109: sub add_previous_version_button {
1.25      albertel  110:     my ($status)=@_;
1.8       albertel  111:     my $result;
1.29      albertel  112:     if ($Apache::lonhomework::history{'resource.version'} eq '') {
1.25      albertel  113: 	return '';
                    114:     }
1.29      albertel  115:     if ($Apache::lonhomework::history{'resource.version'} < 2 &&
                    116: 	$status ne 'NEEDS_CHECKIN') {
1.25      albertel  117: 	return '';
                    118:     }
1.29      albertel  119:     my $version=&get_version();
                    120:     if ($env{'form.previousversion'} ne '' &&
                    121: 	$env{'form.previousversion'} eq $version) {
                    122: 	$result.="<h3>".&mt("Showing previous version [_1]",$version).
                    123: 	    "</h3>\n";
                    124:     }
                    125:     my @to_show;
                    126:     foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
                    127: 	if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
                    128: 	    push(@to_show,$test_version);
                    129: 	}
                    130:     }
                    131:     my $list='<option>'.
                    132: 	join("</option>\n<option>",@to_show).
                    133: 	     "</option>\n";
1.36      albertel  134:     $list.='<option value="current">'.&mt('Current').'</option>';
1.29      albertel  135:     $result.='<form name="getprevious" method="POST" action="';
                    136:     my $uri=$env{'request.uri'};
                    137:     if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    138:     $result.=$uri.'">'.
                    139: 	&mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
                    140: <option>'.&mt('Pick one').'</option>
                    141: '.$list.'
                    142: </select>')."</form>";
1.8       albertel  143:     return $result;
                    144: }
                    145: 
1.13      albertel  146: sub add_grading_button {
1.29      albertel  147:     my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13      albertel  148: 	&mt("Get a submission to grade").'" />';
                    149:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.40      albertel  150:     if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.34      albertel  151: 	my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
                    152: 	$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);
                    153: 
                    154: 	$result.=' <input type="submit" name="reviewagrading" value="'.
                    155: 	    &mt("Select an entry from the grading queue").'" /> </p>'."\n";
                    156: 
                    157: 	($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
                    158: 	$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  159: 	$result.=' <input type="submit" name="reviewasubmission" value="'.
1.34      albertel  160: 	    &mt("Select an entry from the review queue").'" /> </p>'."\n";
1.49      albertel  161: 	$result.=' <input type="submit" name="regradeasubmission" value="'.
                    162: 	    &mt("Select a user to regrade.").'" /> </p>'."\n";
1.32      albertel  163:     }
1.13      albertel  164:     return $result;
                    165: }
                    166: 
1.22      albertel  167: sub add_request_another_attempt_button {
1.38      albertel  168:     my ($text)=@_;
                    169:     if (!$text) { $text="Request another attempt"; }
1.25      albertel  170:     my $result;
1.36      albertel  171:     my $symb=&Apache::lonnet::symbread();
1.37      albertel  172:     my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38      albertel  173:     my $action='get_reservation';
1.37      albertel  174:     if ($slot_name) {
1.38      albertel  175: 	$text="Change reservation.";
                    176: 	$action='change_reservation';
1.37      albertel  177: 	my $description=&Apache::slotrequest::get_description($slot_name,
                    178: 							      $slot);
                    179: 	$result.=(<<STUFF);
                    180: <p> Will be next available: $description </p>
                    181: STUFF
                    182:     }
1.38      albertel  183:     
                    184:     if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
                    185:     $symb=&Apache::lonnet::escape($symb);
                    186:     $result.='<form method="POST" action="/adm/slotrequest">'.
                    187: 	'<input type="hidden" name="symb" value="'.$symb.'" />'.
                    188: 	'<input type="hidden" name="command" value="'.$action.'" />'.
                    189: 	'<input type="submit" name="requestattempt" value="'.
                    190: 	&mt($text).'" />'.
                    191: 	'</form>';
1.25      albertel  192:     return $result;
1.22      albertel  193: }
                    194: 
1.30      albertel  195: sub preserve_grade_info {
                    196:     my $result;
                    197:     # if we are viewing someone else preserve that info
                    198:     if (defined $env{'form.grade_symb'}) {
                    199: 	foreach my $field ('symb','courseid','domain','username') {
                    200: 	    $result .= '<input type="hidden" name="grade_'.$field.
                    201: 		'" value="'.$env{"form.grade_$field"}.'" />'."\n";
                    202: 	}
                    203:     }
                    204:     return $result;
                    205: }
                    206: 
1.53    ! albertel  207: sub style {
        !           208:     return (<<STYLE);
        !           209: <style type="text/css">
        !           210: .fail, .pass, .neutral {
        !           211:     position: relative;
        !           212:     margin : 5px;
        !           213:     margin-bottom :10px;
        !           214:     padding : 4px;
        !           215:     padding-left : 75px;
        !           216: 	border : thin solid;
        !           217:     font-weight : bolder;
        !           218:     font-size: smaller;
        !           219:     font-family: Arial;
        !           220:     background-color : rgb(255,240,225);
        !           221: }
        !           222: 
        !           223: .fail h4, .pass h4 {
        !           224: 	position:absolute;
        !           225: 	left: -4px;
        !           226: 	top: -8px;
        !           227: 	padding:2px;
        !           228: 	margin:0;
        !           229: 	background-color : rgb(255,240,225);
        !           230: 	border : thin solid;
        !           231: }
        !           232: 
        !           233: .fail {
        !           234: 	color: red;
        !           235: }
        !           236: 
        !           237: .pass {
        !           238:     color : green;
        !           239: }
        !           240: 
        !           241: .neutral {
        !           242: 	color : blue;
        !           243: }
        !           244: 
        !           245: .question {
        !           246: 	border : thin solid black;
        !           247: 	padding : 4px;
        !           248: 	margin-bottom : 1em;
        !           249: }
        !           250: 
        !           251: .grade {
        !           252: 	font-size: x-large;
        !           253: 	font-family: Arial;
        !           254: 	position:absolute;
        !           255: 	left: 5px;
        !           256: 	top: -5px;
        !           257: 	width: 70px;
        !           258: }
        !           259: 
        !           260: div#feedback h1 {
        !           261:     color : inherit;
        !           262: }
        !           263: </style>
        !           264: STYLE
        !           265: 
        !           266: }
        !           267: 
1.1       albertel  268: sub start_Task {
                    269:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    270: 
1.4       albertel  271:     my ($status,$accessmsg,$slot);
1.16      albertel  272:     if ($target ne 'webgrade') {
                    273: 	&Apache::structuretags::initialize_storage();
                    274: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
                    275:     } 
                    276: 
1.4       albertel  277:     $Apache::lonhomework::parsing_a_task=1;
1.1       albertel  278:     #should get back a <html> or the neccesary stuff to start XML/MathML
                    279:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    280: 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16      albertel  281:     
1.8       albertel  282:     if ($target eq 'web') {
1.13      albertel  283: 	if ($Apache::lonhomework::modifygrades) {
                    284: 	    $body_tag_start.='<form name="gradesubmission" method="POST" action="';
                    285: 	    my $uri=$env{'request.uri'};
                    286: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    287: 	    $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
1.38      albertel  288: 	    my $symb=&Apache::lonnet::symbread();
1.40      albertel  289: 	    if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
                    290: 		$body_tag_start.='<form method="POST" action="/adm/slotrequest">'.
                    291: 		    '<input type="hidden" name="symb" value="'.$symb.'" />'.
                    292: 		    '<input type="hidden" name="command" value="showslots" />'.
                    293: 		    '<input type="submit" name="requestattempt" value="'.
                    294: 		    &mt('Show Slot list').'" />'.
                    295: 		    '</form>';
                    296: 	    }
1.13      albertel  297: 	}
1.8       albertel  298:     }
1.21      albertel  299:     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1       albertel  300: 	$target eq 'tex') {
1.29      albertel  301: 	my ($version,$previous)=&get_version();
1.14      albertel  302: 	($status,$accessmsg,my $slot_name,$slot) = 
1.4       albertel  303: 	    &Apache::lonhomework::check_task_access('0');
1.9       albertel  304: 	push(@Apache::inputtags::status,$status);
1.14      albertel  305: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  306: 	my $expression='$external::datestatus="'.$status.'";';
1.23      albertel  307: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1       albertel  308: 	&Apache::run::run($expression,$safeeval);
                    309: 	&Apache::lonxml::debug("Got $status");
1.25      albertel  310: 	$body_tag_start.=&add_previous_version_button($status);
1.29      albertel  311: 	if (!$previous && (
                    312: 			   ( $status eq 'CLOSED' ) ||
                    313: 			   ( $status eq 'BANNED') ||
                    314: 			   ( $status eq 'UNAVAILABLE') ||
                    315: 			   ( $status eq 'NOT_IN_A_SLOT') ||
                    316: 			   ( $status eq 'NEEDS_CHECKIN') ||
                    317: 			   ( $status eq 'WAITING_FOR_GRADE') ||
                    318: 			   ( $status eq 'INVALID_ACCESS') )) {
1.1       albertel  319: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    320: 	    if ( $target eq "web" ) {
1.4       albertel  321: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
                    322: 		my $msg;
1.1       albertel  323: 		if ($status eq 'UNAVAILABLE') {
                    324: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  325: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    326: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.38      albertel  327: 		    $msg.=&add_request_another_attempt_button("Sign up for time to work.");
1.4       albertel  328: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    329: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    330: 			'</h1>'.&proctor_validation_screen($slot);
1.22      albertel  331: 		} elsif ($status eq 'WAITING_FOR_GRADE') {
                    332: 		    $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1       albertel  333: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    334: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    335: 		}
                    336: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    337: 		    $msg.='The problem '.$accessmsg;
                    338: 		}
                    339: 		$result.=$msg.'<br />';
                    340: 	    } elsif ($target eq 'tex') {
                    341: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    342: 		if ($status eq 'UNAVAILABLE') {
                    343: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    344: 		} else {
                    345: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    346: 		}
1.22      albertel  347: 	    } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4       albertel  348: 		if ($status eq 'NEEDS_CHECKIN') {
1.41      albertel  349: 		    &proctor_check_auth($slot_name,$slot);
1.4       albertel  350: 		}
1.1       albertel  351: 	    }
                    352: 	} elsif ($target eq 'web') {
                    353: 	    my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    354: 	    $result.="$head_tag_start<title>$name</title></head>
1.53    ! albertel  355:               $body_tag_start \n".&style();
1.36      albertel  356: 	    
1.29      albertel  357: 	    my ($version,$previous)=&get_version();
1.25      albertel  358: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22      albertel  359: 		$result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
1.29      albertel  360: 		if (!$previous) {
                    361: 		    $result.=&add_request_another_attempt_button();
                    362: 		}
1.22      albertel  363: 	    }
1.25      albertel  364: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
1.22      albertel  365: 		$result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
                    366: 	    }
1.36      albertel  367: 	    $result.=$form_tag_start.
                    368: 		'<input type="hidden" name="submitted" value="yes" />';
                    369: 	    $result.=&preserve_grade_info();
                    370: 
1.1       albertel  371: 	}
1.21      albertel  372:     } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                    373: 	      $target eq 'webgrade') {
1.32      albertel  374: 	my $webgrade='yes';
1.21      albertel  375: 	if ($target eq 'webgrade') {
1.32      albertel  376: 	    $result.=$head_tag_start.$body_tag_start;
1.49      albertel  377: 	    #$result.='<br />Review'.&show_queue('reviewqueue');
                    378: 	    #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30      albertel  379: 	}
1.33      albertel  380: 	# FIXME Blast! still need to reorg this, need to reshow the
                    381:         #       queue being reviewed once done with the grade pass...
                    382:         #       Hrrm, vaildation pass should perhaps say 'not_locked'
                    383:         #       perhaps do a search if there is a key that is mine and if
                    384:         #       there isn't reshow the queue....
                    385: 	my ($todo,$status_code)=&get_key_todo($target);
                    386: 
                    387: 	&Apache::lonnet::logthis("got todo -$todo- stat -$status_code-");
                    388: 	if ($todo) {
                    389: 	    &setup_env_for_other_user($todo,$safeeval);
                    390: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
                    391: 	    $result.="\n".'<table><tr><td>Found '.
                    392: 		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
                    393: 	    $form_tag_start.=
                    394: 		'<input type="hidden" name="gradingkey" value="'.
                    395: 		&Apache::lonnet::escape($todo).'" />';
                    396: 	    $Apache::bridgetask::queue_key=$todo;
                    397: 	    &Apache::structuretags::initialize_storage();
                    398: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
                    399: 	    if ($target eq 'webgrade') {
1.49      albertel  400: 		#$result.='<br />After -'.&show_queue($env{'form.queue'});
1.33      albertel  401: 		$result.="\n".'<table width="100%" style="width:100%" border="1">';
                    402: 		if ($status_code eq 'selected') {
                    403: 		    $form_tag_start.=
                    404: 			'<input type="hidden" name="queuemode" value="selected" />';
                    405: 		}
                    406: 	    }
1.15      albertel  407: 	} else {
1.33      albertel  408: 	    if ($target eq 'webgrade') {
                    409: 		$result.="\n";
                    410: 		if      ($status_code eq 'stop') {
                    411: 		    $result.='<b>'.&mt("Stopped grading.").'</b>';
                    412: 		} elsif ($status_code eq 'lock_failed') {
                    413: 		    $result.='<b>'.&mt("Failed to lock the request record.").'</b>';
                    414: 		} elsif ($status_code eq 'unlock') {
                    415: 		    $result.='<b>'.&mt("Unlocked the requested record.").'</b>';
                    416: 		    $result.=&show_queue($env{'form.queue'},1);
                    417: 		} elsif ($status_code eq 'show_list') {
                    418: 		    $result.=&show_queue($env{'form.queue'},1);
1.49      albertel  419: 		} elsif ($status_code eq 'select_user') {
                    420: 		    $result.=&select_user();
1.33      albertel  421: 		} else {
                    422: 		    $result.='<b>'.&mt("No user to be graded.").'</b>';
1.32      albertel  423: 		}
1.21      albertel  424: 	    }
1.33      albertel  425: 	    $webgrade='no';
                    426: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
1.32      albertel  427: 	}
                    428: 	if ($target eq 'webgrade' && defined($env{'form.queue'})) {
                    429: 	    $result.=$form_tag_start;
                    430: 	    $result.='<input type="hidden" name="webgrade" value="'.
                    431: 		$webgrade.'" />';
                    432: 	    $result.='<input type="hidden" name="queue" value="'.
                    433: 		$env{'form.queue'}.'" />';
1.52      albertel  434: 	    if ($env{'form.regrade'}) {
                    435: 		$result.='<input type="hidden" name="regrade" value="'.
                    436: 		    $env{'form.regrade'}.'" />';
                    437: 	    }
1.15      albertel  438: 	}
1.1       albertel  439:     } else {
                    440: 	# page_start returned a starting result, delete it if we don't need it
                    441: 	$result = '';
                    442:     }
                    443:     return $result;
                    444: }
                    445: 
1.32      albertel  446: sub get_key_todo {
                    447:     my ($target)=@_;
                    448:     my $todo;
1.33      albertel  449: 
                    450:     if (defined($env{'form.reviewasubmission'})) {
                    451: 	&Apache::lonnet::logthis("review a submission....");
                    452: 	$env{'form.queue'}='reviewqueue';
                    453: 	return (undef,'show_list');
                    454:     }
                    455: 
                    456:     if (defined($env{'form.reviewagrading'})) {
                    457: 	&Apache::lonxml::debug("review a grading....");
                    458: 	$env{'form.queue'}='gradingqueue';
                    459: 	return (undef,'show_list');
                    460:     }
                    461: 
1.49      albertel  462:     if (defined($env{'form.regradeasubmission'})) {
                    463: 	&Apache::lonxml::debug("regrade a grading....");
                    464: 	$env{'form.queue'}='none';
                    465: 	return (undef,'select_user');
                    466:     }
                    467: 
1.32      albertel  468:     my $queue=$env{'form.queue'};
1.33      albertel  469: 
1.32      albertel  470:     if (!defined($queue)) {
                    471: 	$env{'form.queue'}=$queue='gradingqueue';
                    472:     }
1.33      albertel  473: 
1.32      albertel  474:     my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33      albertel  475: 
1.49      albertel  476:     if ($env{'form.queue'} eq 'none') {
                    477: 	if (defined($env{'form.gradingkey'})) {
                    478: 	    if ($target eq 'webgrade') {
                    479: 		if ($env{'form.stop'}) {
                    480: 		    return (undef,'stop');
                    481: 		} elsif ($env{'form.next'}) {
                    482: 		    return (undef,'show_list');
                    483: 		}
                    484: 	    }
                    485: 	    return ($gradingkey,'selected');
                    486: 	} else {
                    487: 	    return (undef,'show_list');
                    488: 	}
                    489:     }
1.32      albertel  490:     if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33      albertel  491: 	&& !defined($env{'form.gradingaction'}) 
                    492: 	&& $env{'form.queuemode'} eq 'selected') {
                    493: 	
                    494: 	my $who=&queue_key_locked($queue,$gradingkey);
                    495: 	my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    496: 	if ($who eq $me) {
                    497: 	    &Apache::lonxml::debug("Found a key was given to me");
                    498: 	    return ($gradingkey,'selected');
                    499: 	} else {
                    500: 	    return (undef,'show_list');
                    501: 	}
                    502: 
                    503:     }
                    504: 
                    505:     if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
                    506: 	if ($env{'form.gradingaction'} eq 'resume') {
                    507: 	    delete($env{'form.gradingaction'});
                    508: 	    &Apache::lonxml::debug("Resuming a key");
1.32      albertel  509: 	    return ($gradingkey);
1.33      albertel  510: 	} elsif ($env{'form.gradingaction'} eq 'unlock') {
                    511: 	    &Apache::lonxml::debug("Unlocking a key ".
                    512: 				     &check_queue_unlock($queue,$gradingkey,1));
                    513: 	    return (undef,'unlock');
                    514: 	} elsif ($env{'form.gradingaction'} eq 'select') {
                    515: 	    &Apache::lonxml::debug("Locking a key");
                    516: 	    if (&lock_key($queue,$gradingkey)) {
                    517: 		&Apache::lonxml::debug("Success $queue");
                    518: 		return ($gradingkey);
                    519: 	    }
                    520: 	    &Apache::lonxml::debug("Failed $queue");
                    521: 	    return (undef,'lock_failed');
1.32      albertel  522: 	}
                    523:     }
1.33      albertel  524: 
                    525:     if ($env{'form.queuemode'} ne 'selected') {
                    526: 	# don't get something new from the queue if they hit the stop button
                    527:     	if (!($env{'form.stop'} && $target eq 'webgrade') 
                    528: 	    && !$env{'form.gradingaction'}) {
                    529: 	    &Apache::lonxml::debug("Getting anew $queue");
                    530: 	    return (&get_from_queue($queue));
                    531: 	} else {
                    532: 	    return (undef,'stop');
                    533: 	}
1.32      albertel  534:     }
1.33      albertel  535:     return (undef,undef)
1.32      albertel  536: }
                    537: 
1.1       albertel  538: sub end_Task {
                    539:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    540:     my $result='';
                    541:     my $status=$Apache::inputtags::status['-1'];
1.29      albertel  542:     my ($version,$previous)=&get_version();
1.1       albertel  543:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel  544: 	$target eq 'tex') {
1.1       albertel  545: 	if (
1.11      albertel  546: 	    (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1       albertel  547: 	    ($target eq 'answer') || ($target eq 'tex')
                    548: 	   ) {
                    549: 	    if ($target eq 'web') {
1.29      albertel  550: 		if ($status eq 'CAN_ANSWER' && !$previous) {
1.15      albertel  551: 		    $result.="\n".'<table border="1">'.
1.28      albertel  552: 			&Apache::inputtags::file_selector("$version.0",
                    553: 							  "bridgetask","*",
1.46      albertel  554: 							  'portfolioonly',
                    555: 							  '
                    556: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
                    557: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9       albertel  558: 							  "</table>";
                    559: 		    $result.=&Apache::inputtags::gradestatus('0');
                    560: 		}
1.13      albertel  561: 	    } 
                    562: 	    if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  563: 		$result.=&Apache::lonxml::xmlend().'</html>';
                    564: 	    }
                    565: 	}
1.29      albertel  566: 	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12      albertel  567: 	    my $award='SUBMITTED';
1.28      albertel  568: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20      albertel  569: 						    'portfiles',\$award);
1.14      albertel  570: 	    if ($award eq 'SUBMITTED' &&
1.28      albertel  571: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
                    572: 		$Apache::lonhomework::results{"resource.0.tries"}=
                    573: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
                    574: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
                    575: 
                    576: 		$Apache::lonhomework::results{"resource.0.award"}=
                    577: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
                    578: 		    $award;
1.51      albertel  579: 		$Apache::lonhomework::results{"resource.0.submission"}=
                    580: 		    $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.10      albertel  581: 	    }
1.4       albertel  582: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    583: 	    &Apache::structuretags::finalize_storage();
1.14      albertel  584: 	    if ($award eq 'SUBMITTED') {
1.31      albertel  585: 		&add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14      albertel  586: 	    }
1.1       albertel  587: 	}
1.32      albertel  588: 	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20      albertel  589: 	    my $optional_required=
                    590: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                    591: 					   $safeeval);
                    592: 	    my $optional_passed=0;
                    593: 	    my $mandatory_failed=0;
                    594: 	    my $ungraded=0;
                    595: 	    my $review=0;   
1.21      albertel  596: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20      albertel  597: 	    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
                    598: 		my $status=
1.25      albertel  599: 		    $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20      albertel  600: 		my $mandatory=
                    601: 		    ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
                    602: 		if ($status eq 'pass') {
                    603: 		    if (!$mandatory) { $optional_passed++; }
                    604: 		} elsif ($status eq 'fail') {
                    605: 		    if ($mandatory) { $mandatory_failed++; }
                    606: 		} elsif ($status eq 'ungraded') {
                    607: 		    $ungraded++;
                    608: 		} elsif ($status eq 'review') {
                    609: 		    $review++;
1.49      albertel  610: 		} else {
                    611: 		    $ungraded++;
                    612: 		}
1.20      albertel  613: 	    }
                    614: 	    if ($optional_passed < $optional_required) {
                    615: 		$mandatory_failed++;
                    616: 	    }
1.21      albertel  617: 	    &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
                    618: 	    $Apache::lonhomework::results{'resource.grader'}=
1.20      albertel  619: 		$env{'user.name'}.'@'.$env{'user.domain'};
                    620: 	    if ($review) {
1.25      albertel  621: 		$Apache::lonhomework::results{"resource.$version.status"}='review';
1.33      albertel  622: 		if ($env{'form.queue'} eq 'reviewqueue') {
                    623: 		    &check_queue_unlock($env{'form.queue'});
                    624: 		    &Apache::lonxml::debug(" still needs review not changing status.");
                    625: 		} else {
1.49      albertel  626: 		    &move_between_queues($env{'form.queue'},'reviewqueue');
1.33      albertel  627: 		}
1.20      albertel  628: 	    } elsif ($ungraded) {
1.25      albertel  629: 		$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.49      albertel  630: 		if ($env{'form.queue'} eq 'reviewqueue' ||
                    631: 		    $env{'form.queue'} eq 'none' ) {
1.33      albertel  632: 		    &Apache::lonxml::debug("moving back.");
1.49      albertel  633: 		    &move_between_queues($env{'form.queue'},'gradingqueue');
1.33      albertel  634: 		} else {
                    635: 		    &check_queue_unlock($env{'form.queue'});
                    636: 		}
1.20      albertel  637: 	    } elsif ($mandatory_failed) {
1.25      albertel  638: 		$Apache::lonhomework::results{"resource.$version.status"}='fail';
                    639: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                    640: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                    641: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39      albertel  642: 		&remove_from_queue($env{'form.queue'}); 
                    643: 
                    644: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52      albertel  645: 		
                    646: 		if ($env{'form.regrade'} ne 'yes') {
                    647: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                    648: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                    649: 		    &Apache::grades::version_portfiles(
                    650: 						       \%Apache::lonhomework::results,
                    651: 						       ["$version.0.bridgetask"],$courseid,
                    652: 						       $symb,$udom,$uname,
                    653: 						       ["$version.0.bridgetask"]);
                    654: 		}
1.20      albertel  655: 	    } else {
1.25      albertel  656: 		$Apache::lonhomework::results{"resource.$version.status"}='pass';
                    657: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                    658: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                    659: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32      albertel  660: 		&remove_from_queue($env{'form.queue'});
1.39      albertel  661: 
                    662: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52      albertel  663: 		if ($env{'form.regrade'} ne 'yes') {
                    664: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                    665: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                    666: 		    &Apache::grades::version_portfiles(
                    667: 						       \%Apache::lonhomework::results,
                    668: 						       ["$version.0.bridgetask"],$courseid,
                    669: 						       $symb,$udom,$uname,
                    670: 						       ["$version.0.bridgetask"]);
                    671: 		}
1.20      albertel  672: 	    }
1.26      albertel  673: 	    $Apache::lonhomework::results{"resource.status"}=
                    674: 		$Apache::lonhomework::results{"resource.$version.status"};
1.28      albertel  675: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel  676: 		$Apache::lonhomework::results{"resource.0.award"}=
1.50      albertel  677: 		    $Apache::lonhomework::results{"resource.$version.0.award"};
1.26      albertel  678: 		$Apache::lonhomework::results{"resource.0.awarded"}=
1.50      albertel  679: 		    $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26      albertel  680: 		$Apache::lonhomework::results{"resource.0.solved"}=
1.50      albertel  681: 		    $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25      albertel  682: 	    }
1.21      albertel  683: 	    &Apache::structuretags::finalize_storage();
1.20      albertel  684: 	}
1.15      albertel  685:     } elsif ($target eq 'webgrade') {
1.18      albertel  686: 	$result.="</table>\n<hr />";
1.20      albertel  687: 	#$result.='<input type="submit" name="next" value="'.
                    688: 	#    &mt('Save &amp; Next').'" /> ';
                    689: 	#$result.='<input type="submit" name="end" value="'.
                    690: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                    691: 	#$result.='<input type="submit" name="throwaway" value="'.
                    692: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                    693: 	#$result.='<input type="submit" name="save" value="'.
                    694: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15      albertel  695: 	$result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1       albertel  696:     } elsif ($target eq 'meta') {
1.2       albertel  697: 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1       albertel  698: 	#$result.=&Apache::response::meta_part_order();
                    699: 	#$result.=&Apache::response::meta_response_order();
                    700:     }
1.4       albertel  701:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel  702:     return $result;
                    703: }
                    704: 
1.31      albertel  705: sub move_between_queues {
                    706:     my ($src_queue,$dest_queue)=@_;
1.49      albertel  707:     my $cur_data;
                    708:     if ($src_queue ne 'none') {
                    709: 	$cur_data=&get_queue_data($src_queue);
                    710: 	if (!$cur_data) { return 'not_exist'; }
                    711:     } else {
                    712: 	$cur_data = ['none'];
                    713:     }
1.31      albertel  714:     my $result=&add_to_queue($dest_queue,$cur_data->[0]);
                    715:     if ($result ne 'ok') {
                    716: 	return $result;
                    717:     }
                    718:     &check_queue_unlock($src_queue);
                    719:     return &remove_from_queue($src_queue);
1.21      albertel  720: }
                    721: 
                    722: sub check_queue_unlock {
1.32      albertel  723:     my ($queue,$key,$allow_not_me)=@_;
1.49      albertel  724:     if ($queue eq 'none') { return 'ok'; }
1.30      albertel  725:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32      albertel  726:     if (!defined($key)) {
                    727: 	$key="$symb\0queue\0$uname\@$udom";
                    728:     }
1.30      albertel  729:     my $cnum=$env{'course.'.$cid.'.num'};
                    730:     my $cdom=$env{'course.'.$cid.'.domain'};
                    731:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    732:     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
                    733:     if  ($who eq $me) {
1.32      albertel  734: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
                    735:     } elsif ($allow_not_me) {
1.33      albertel  736: 	&Apache::lonxml::debug("unlocking $who by $me");
1.32      albertel  737: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30      albertel  738:     }
1.32      albertel  739:     return 'not_owner';
1.21      albertel  740: }
                    741: 
                    742: sub remove_from_queue {
1.30      albertel  743:     my ($queue)=@_;
1.49      albertel  744:     if ($queue eq 'none') { return 'ok'; }
1.27      albertel  745:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    746:     my $cnum=$env{'course.'.$cid.'.num'};
                    747:     my $cdom=$env{'course.'.$cid.'.domain'};
                    748:     my $key="$symb\0queue\0$uname\@$udom";
                    749:     my @keys=($key,"$key\0locked");
1.31      albertel  750:     return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21      albertel  751: }
                    752: 
1.16      albertel  753: sub setup_env_for_other_user {
                    754:     my ($queue_key,$safeeval)=@_;
                    755:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30      albertel  756:     &Apache::lonxml::debug("setup_env for $queue_key");
1.16      albertel  757:     $env{'form.grade_symb'}=$symb;
                    758:     $env{'form.grade_domain'}=$udom;
                    759:     $env{'form.grade_username'}=$uname;
                    760:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                    761:     &Apache::lonxml::initialize_rndseed($safeeval);
                    762: }
                    763: 
1.31      albertel  764: sub get_queue_data {
                    765:     my ($queue)=@_;
                    766:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    767:     my $cnum=$env{'course.'.$cid.'.num'};
                    768:     my $cdom=$env{'course.'.$cid.'.domain'};
                    769:     my $todo="$symb\0queue\0$uname\@$udom";
                    770:     my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
                    771:     if ($key eq $todo && ref($value)) {
                    772: 	return $value;
                    773:     }
                    774:     return undef;
                    775: }
                    776: 
1.49      albertel  777: sub check_queue_for_key {
                    778:     my ($cid,$queue,$todo)=@_;
                    779:     my $cnum=$env{'course.'.$cid.'.num'};
                    780:     my $cdom=$env{'course.'.$cid.'.domain'};
                    781:     my %results=
                    782: 	&Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
                    783:     
                    784:     if (exists($results{$todo}) && ref($results{$todo})) {
                    785: 	if (defined($results{"$todo\0locked"})) {
                    786: 	    return 'locked';
                    787: 	}
                    788: 	return 'enqueued';
                    789:     }
                    790:     return undef;
                    791: }
                    792: 
1.14      albertel  793: sub add_to_queue {
1.31      albertel  794:     my ($queue,$slot_name)=@_;
1.49      albertel  795:     if ($queue eq 'none') { return 'ok'; }
1.14      albertel  796:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    797:     my $cnum=$env{'course.'.$cid.'.num'};
                    798:     my $cdom=$env{'course.'.$cid.'.domain'};
                    799:     my %data;
1.31      albertel  800:     $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
                    801:     return &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14      albertel  802: }
                    803: 
                    804: sub show_queue {
1.32      albertel  805:     my ($queue,$with_selects)=@_;
1.14      albertel  806:     my $result;
                    807:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    808:     my $cnum=$env{'course.'.$cid.'.num'};
                    809:     my $cdom=$env{'course.'.$cid.'.domain'};
1.16      albertel  810:     my $regexp="^$symb\0";
1.30      albertel  811:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31      albertel  812:     my ($tmp)=%queue;
                    813:     if ($tmp=~/^error: 2 /) {
1.33      albertel  814: 	return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31      albertel  815:     }
1.33      albertel  816:     $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32      albertel  817:     if ($with_selects) { $result.="<th></th>"; }
                    818:     $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14      albertel  819:     foreach my $key (sort(keys(%queue))) {
1.32      albertel  820: 	if ($key=~/locked$/ && !$with_selects) {
1.16      albertel  821: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    822: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  823: 	    $result.="<tr><td>$title</td><td>$uname</td>";
1.16      albertel  824: 	    $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32      albertel  825: 	} elsif ($key=~/timestamp$/ && !$with_selects) {
1.16      albertel  826: 	    my ($symb,undef) = split("\0",$key);
                    827: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  828: 	    $result.="<tr><td>$title</td><td></td>";
1.16      albertel  829: 	    $result.='<td>last queue modification time</td><td>'.
                    830: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32      albertel  831: 	} elsif ($key!~/(timestamp|locked)$/) {
1.16      albertel  832: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    833: 	    my $title=&Apache::lonnet::gettitle($symb);
1.32      albertel  834: 	    $result.="<tr>";
1.35      albertel  835: 	    my $slot=$queue{$key}->[0];
                    836: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
1.32      albertel  837: 	    if ($with_selects) {
                    838: 		my $ekey=&Apache::lonnet::escape($key);
                    839: 		my ($action,$description)=('select',&mt('Select'));
                    840: 		if (exists($queue{"$key\0locked"})) {
                    841: 		    my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    842: 		    if ($me eq $queue{"$key\0locked"}) {
                    843: 			($action,$description)=('resume',&mt('Resume'));
                    844: 		    } else {
                    845: 			($action,$description)=('unlock',&mt('Unlock'));
                    846: 		    }
                    847: 		}
1.35      albertel  848: 		if (time > $slot_data{'endtime'}) {
                    849: 		    $result.=(<<FORM);
1.32      albertel  850: <td>
                    851: <form method="POST">
                    852:  <input type="hidden" name="gradingkey" value="$ekey" />
                    853:  <input type="hidden" name="queue" value="$queue" />
                    854:  <input type="hidden" name="gradingaction" value="$action" />
                    855:  <input type="hidden" name="webgrade" value="no" />
1.33      albertel  856:  <input type="hidden" name="queuemode" value="selected" />
1.32      albertel  857:  <input type="submit" name="submit" value="$description" />
                    858: </form>
                    859: </td>
                    860: FORM
1.35      albertel  861: 
                    862:                 } else {
                    863: 		    $result.='<td>'.&mt("In Progress").'</td>'
                    864: 		}
1.32      albertel  865: 	    }
                    866: 	    $result.="<td>$title</td><td>$uname</td>";
1.27      albertel  867: 	    $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20      albertel  868: 		&Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
                    869: 		"</td></tr>";
1.16      albertel  870: 	}
1.14      albertel  871:     }
1.15      albertel  872:     $result.="</table><hr />\n";
1.14      albertel  873:     return $result;
                    874: }
                    875: 
1.34      albertel  876: sub get_queue_counts {
                    877:     my ($queue)=@_;
                    878:     my $result;
                    879:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    880:     my $cnum=$env{'course.'.$cid.'.num'};
                    881:     my $cdom=$env{'course.'.$cid.'.domain'};
                    882:     my $regexp="^$symb\0";
                    883:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                    884:     my ($tmp)=%queue;
                    885:     if ($tmp=~/^error: 2 /) {
                    886: 	return (0,0,0);
                    887:     }
                    888:     my ($entries,$ready_to_grade,$locks)=(0,0,0);
                    889:     foreach my $key (sort(keys(%queue))) {
                    890: 	if ($key=~/locked$/) {
                    891: 	    $locks++;
                    892: 	} elsif ($key=~/timestamp$/) {
                    893: 	    #ignore
                    894: 	} elsif ($key!~/(timestamp|locked)$/) {
                    895: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    896: 	    $entries++;
                    897: 	    my $slot=$queue{$key}->[0];
                    898: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                    899: 	    if (time > $slot_data{'endtime'}) {
                    900: 		$ready_to_grade++;
                    901: 	    }
                    902: 	}
                    903:     }
                    904:     return ($entries,$ready_to_grade,$locks);
                    905: }
                    906: 
1.49      albertel  907: sub encode_queue_key {
                    908:     my ($symb,$udom,$uname)=@_;
                    909:     return "$symb\0queue\0$uname\@$udom";
                    910: }
                    911: 
1.14      albertel  912: sub decode_queue_key {
                    913:     my ($key)=@_;
                    914:     my ($symb,undef,$user) = split("\0",$key);
                    915:     my ($uname,$udom) = split('@',$user);
                    916:     return ($symb,$uname,$udom);
                    917: }
                    918: 
                    919: sub queue_key_locked {
1.30      albertel  920:     my ($queue,$key,$cdom,$cnum)=@_;
1.33      albertel  921:     if (!defined($cdom) || !defined($cnum)) {
                    922: 	my (undef,$cid)=&Apache::lonxml::whichuser();
                    923: 	$cnum=$env{'course.'.$cid.'.num'};
                    924: 	$cdom=$env{'course.'.$cid.'.domain'};
                    925:     }
1.14      albertel  926:     my ($key_locked,$value)=
1.30      albertel  927: 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14      albertel  928:     if ($key_locked eq "$key\0locked") {
                    929: 	return $value;
                    930:     }
                    931:     return undef;
                    932: }
                    933: 
                    934: sub pick_from_queue_data {
1.30      albertel  935:     my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
                    936:     foreach my $key (keys(%$queuedata)) {
1.14      albertel  937: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
                    938: 	if ($check_section) {
                    939: 	    my $section=&Apache::lonnet::getsection($uname,$udom);
1.17      albertel  940: 	    if ($section eq $check_section) {
1.33      albertel  941: 		&Apache::lonxml::debug("my sec");
1.15      albertel  942: 		next;
                    943: 	    }
1.14      albertel  944: 	}
1.30      albertel  945: 	my $slot=$queuedata->{$key}[0];
1.14      albertel  946: 	my %slot_data=&Apache::lonnet::get_slot($slot);
1.15      albertel  947: 	if ($slot_data{'endtime'} > time) { 
1.33      albertel  948: 	    &Apache::lonxml::debug("not time");
1.15      albertel  949: 	    next;
                    950: 	}
1.30      albertel  951: 	if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33      albertel  952: 	    &Apache::lonxml::debug("someone already has um.");
1.15      albertel  953: 	    next;
                    954: 	}
1.14      albertel  955: 	return $key;
                    956:     }
                    957:     return undef;
                    958: }
                    959: 
1.15      albertel  960: sub find_mid_grade {
1.30      albertel  961:     my ($queue,$symb,$cdom,$cnum)=@_;
1.16      albertel  962:     my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15      albertel  963:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    964:     if ($todo) {
1.30      albertel  965: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel  966: 	if ($who eq $me) { return $todo; }
                    967:     }
                    968:     my $regexp="^$symb\0.*\0locked\$";
1.30      albertel  969:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel  970:     foreach my $key (keys(%locks)) {
                    971: 	my $who=$locks{$key};
                    972: 	if ($who eq $me) {
                    973: 	    $todo=$key;
                    974: 	    $todo=~s/\0locked$//;
                    975: 	    return $todo;
                    976: 	}
                    977:     }
                    978:     return undef;
                    979: }
                    980: 
1.32      albertel  981: sub lock_key {
                    982:     my ($queue,$todo)=@_;
                    983:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    984:     my (undef,$cid)=&Apache::lonxml::whichuser();
                    985:     my $cnum=$env{'course.'.$cid.'.num'};
                    986:     my $cdom=$env{'course.'.$cid.'.domain'};
                    987:     my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
                    988: 					$cdom,$cnum);
1.33      albertel  989:     &Apache::lonxml::debug("success $success $todo");
1.32      albertel  990:     if ($success eq 'ok') {
                    991: 	return 1;
                    992:     }
                    993:     return 0;
                    994: }
                    995: 
1.14      albertel  996: sub get_from_queue {
1.30      albertel  997:     my ($queue)=@_;
1.14      albertel  998:     my $result;
                    999:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                   1000:     my $cnum=$env{'course.'.$cid.'.num'};
                   1001:     my $cdom=$env{'course.'.$cid.'.domain'};
1.32      albertel 1002:     my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33      albertel 1003:     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16      albertel 1004:     if ($todo) { return $todo; }
1.14      albertel 1005:     while (1) {
                   1006: 	my $starttime=time;
1.30      albertel 1007: 	&Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14      albertel 1008: 			     $cdom,$cnum);
1.33      albertel 1009: 	&Apache::lonxml::debug("$starttime");
1.14      albertel 1010: 	my $regexp="^$symb\0queue\0";
1.30      albertel 1011: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33      albertel 1012: 	#make a pass looking for a user _not_ in my section
1.14      albertel 1013: 	if ($env{'request.course.sec'}) {
1.33      albertel 1014: 	    &Apache::lonxml::debug("sce");
1.30      albertel 1015: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
                   1016: 					\%queue,$cdom,$cnum);
1.33      albertel 1017: 	    &Apache::lonxml::debug("sce $todo");
1.14      albertel 1018: 	}
1.33      albertel 1019: 	# no one _not_ in our section so look for any user that is
                   1020: 	# ready for grading
1.14      albertel 1021: 	if (!$todo) {
1.33      albertel 1022: 	    &Apache::lonxml::debug("no sce");
1.31      albertel 1023: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
                   1024: 					\%queue,$cdom,$cnum);
1.33      albertel 1025: 	    &Apache::lonxml::debug("no sce $todo");
1.14      albertel 1026: 	}
                   1027: 	# no user to grade 
                   1028: 	if (!$todo) { last; }
1.33      albertel 1029: 	&Apache::lonxml::debug("got $todo");
1.14      albertel 1030: 	# otherwise found someone so lets try to lock them
1.32      albertel 1031: 	# unless someone else already picked them
                   1032: 	if (!&lock_key($queue,$todo)) { next; }
1.14      albertel 1033: 	my (undef,$endtime)=
1.30      albertel 1034: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel 1035: 				 $cdom,$cnum);
1.33      albertel 1036: 	&Apache::lonxml::debug("emd  $endtime");
1.14      albertel 1037: 	# someone else already modified the queue, 
                   1038: 	# perhaps our picked user wass already fully graded between
                   1039: 	# when we picked him and when we locked his record? so lets
                   1040: 	# double check.
                   1041: 	if ($endtime != $starttime) {
                   1042: 	    my ($key,$value)=
1.30      albertel 1043: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel 1044: 				     $cdom,$cnum);
1.33      albertel 1045: 	    &Apache::lonxml::debug("check  $key .. $value");
1.14      albertel 1046: 	    if ($key eq $todo && ref($value)) {
                   1047: 	    } else {
1.30      albertel 1048: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel 1049: 				     $cdom,$cnum);
1.33      albertel 1050: 		&Apache::lonxml::debug("del");
1.14      albertel 1051: 		next;
                   1052: 	    }
                   1053: 	}
1.33      albertel 1054: 	&Apache::lonxml::debug("last $todo");
1.14      albertel 1055: 	last;
                   1056:     }
                   1057:     return $todo;
                   1058: }
                   1059: 
1.49      albertel 1060: sub select_user {
                   1061:     my ($symb,$cid)=&Apache::lonxml::whichuser();
                   1062:     my $result.='<table border="1">';
                   1063: 
                   1064:     &Apache::grades::init_perm();
                   1065:     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all',);
                   1066:     &Apache::grades::reset_perm();
                   1067: 
                   1068:     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
                   1069: 	my ($uname,$udom) = split(/:/,$student);
                   1070: 	my %status = &get_student_status($symb,$cid,$udom,$uname);
                   1071: 	my $queue = 'none';
                   1072: 	if ($status{'reviewqueue'} eq 'enqueued') {
                   1073: 	    $queue = 'reviewqueue';
                   1074: 	} elsif ($status{'gradingqueue'} eq 'enqueued') {
                   1075: 	    $queue = 'gradingqueue';
                   1076: 	}
                   1077: 	my $todo = 
                   1078: 	    &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
                   1079: 	$result.=<<RESULT;
                   1080: <tr>
                   1081:   <td>
                   1082:     <form method="POST">
                   1083:       <input type="hidden" name="gradingkey" value="$todo" />
                   1084:       <input type="hidden" name="queue" value="$queue" />
                   1085:       <input type="hidden" name="webgrade" value="no" />
1.52      albertel 1086:       <input type="hidden" name="regrade" value="yes" />
1.49      albertel 1087:      <input type="submit" name="submit" value="Regrade" />
                   1088:     </form>
                   1089:   <td>$fullname->{$student}</td>
                   1090:   <td>
                   1091: RESULT
                   1092: 
                   1093:         if ($status{'status'} eq 'pass') {
                   1094: 	    $result .= '<font color="green">'.&mt('Passed').'</font>';
                   1095: 	} elsif ($status{'status'} eq 'fail') {
                   1096: 	    $result .= '<font color="red">'.&mt('Failed').'</font>';
                   1097: 	} elsif ($status{'status'} eq 'review') {
                   1098: 	    $result .= '<font color="blue">'.&mt('Under Review').'</font>';
                   1099: 	} elsif ($status{'status'} eq 'ungraded') {
                   1100: 	    $result .= &mt('Ungraded');
                   1101: 	} elsif ($status{'status'} ne '') {
                   1102: 	    $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
                   1103: 	} else {
                   1104: 	    $result.="&nbsp;";
                   1105: 	}
                   1106: 	if ($status{'version'}) {
                   1107: 	    $result .= ' '.&mt('Version').' '.$status{'version'};
                   1108: 	}
                   1109: 	$result.= '</td><td>';
                   1110: 	if ($status{'reviewqueue'} eq 'enqueued') {
                   1111: 	    $result .= &mt('Awaiting Review');
                   1112: 	} elsif ($status{'reviewqueue'} eq 'locked') {
                   1113: 	    $result .= &mt('Under Review');
                   1114: 	} elsif ($status{'gradingqueue'} eq 'enqueued') {
                   1115: 	    $result .= &mt('Awaiting Grading');
                   1116: 	} elsif ($status{'gradingqueue'} eq 'locked') {
                   1117: 	    $result .= &mt('Being Graded');
                   1118: 	} else {
                   1119: 	    $result.="&nbsp;";
                   1120: 	}
                   1121: 	$result.= '</td></tr>';
                   1122:     }
                   1123:     $result.='</table>';
                   1124:     return $result;
                   1125: }
                   1126: 
                   1127: sub get_student_status {
                   1128:     my ($symb,$cid,$udom,$uname)=@_;
                   1129:     my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
                   1130: 					  $udom,$uname);
                   1131:     my %status;
                   1132:     $status{'status'}=$record{'resource.status'};
                   1133:     $status{'version'}=$record{'resource.version'};
                   1134:     $status{'grader'}=$record{'resource.grader'};
                   1135:     $status{'reviewqueue'}=&check_queue_for_key($cid,'reviewqueue',
                   1136: 				       &encode_queue_key($symb,$udom,$uname));
                   1137:     $status{'gradingqueue'}=&check_queue_for_key($cid,'gradingqueue',
                   1138: 				       &encode_queue_key($symb,$udom,$uname));
                   1139:     return %status;
                   1140: }
                   1141: 
1.1       albertel 1142: sub start_ClosingParagraph {
                   1143:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1144:     my $result;
                   1145:     if ($target eq 'web') {
1.13      albertel 1146:     } elsif ($target eq 'webgrade') {
                   1147: 	&Apache::lonxml::startredirection();
1.1       albertel 1148:     }
                   1149:     return $result;
                   1150: }
                   1151: 
                   1152: sub end_ClosingParagraph {
                   1153:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1154:     my $result;
                   1155:     if ($target eq 'web') {
1.13      albertel 1156:     } elsif ($target eq 'webgrade') {
                   1157: 	&Apache::lonxml::endredirection();
1.1       albertel 1158:     }
                   1159:     return $result;
                   1160: }
                   1161: 
1.19      albertel 1162: sub get_id {
                   1163:     my ($parstack,$safeeval)=@_;
                   1164:     my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
                   1165:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                   1166:     return $id;
                   1167: }
                   1168: 
1.1       albertel 1169: my %dimension;
                   1170: sub start_Dimension {
                   1171:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1172:     undef(%dimension);
1.19      albertel 1173:     my $dim_id=&get_id($parstack,$safeeval);
1.9       albertel 1174:     $Apache::bridgetask::dimension=$dim_id;
                   1175:     push(@Apache::bridgetask::dimensionlist,$dim_id);
                   1176:     undef(@Apache::bridgetask::instance);
1.20      albertel 1177:     $Apache::bridgetask::dimensionmandatory{$dim_id}=
                   1178: 	&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel 1179:     return '';
                   1180: }
                   1181: 
1.13      albertel 1182: sub get_instance {
                   1183:     &Apache::response::pushrandomnumber();
                   1184:     my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29      albertel 1185:     my $num=@order;
                   1186:     my $version=&get_version();
                   1187:     my $which=($version-1)%$num;
                   1188:     return $order[$which];
1.13      albertel 1189: }
                   1190: 
1.18      albertel 1191: {
                   1192:     my $last_link;
                   1193:     sub end_Dimension {
                   1194: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1195: 	my $result;
1.25      albertel 1196: 	my $dim=&get_id($parstack,$safeeval);
1.19      albertel 1197: 	my $instance=&get_instance();
1.25      albertel 1198: 	my $version=&get_version();
1.18      albertel 1199: 	if ($target eq 'web') {
1.47      albertel 1200: 	    @Apache::scripttag::parser_env = @_;
                   1201: 	    $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
                   1202: 	    @Apache::scripttag::parser_env = @_;
                   1203: 	    $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.26      albertel 1204: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
                   1205: 		$Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22      albertel 1206: 		foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel 1207: 		    my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
                   1208: 		    my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.53    ! albertel 1209: 		    my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
        !          1210: 		    if ($mandatory) {
        !          1211: 			$mandatory='Mandatory';
        !          1212: 		    } else {
        !          1213: 			$mandatory='Optional';
        !          1214: 		    }
1.22      albertel 1215: 		    if ($status eq 'fail') {
                   1216: 		    } elsif ($status eq 'pass') {
                   1217: 		    } else {
1.49      albertel 1218: 			&Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
1.22      albertel 1219: 		    }
1.53    ! albertel 1220: 		    my $status_display=$status;
        !          1221: 		    $status_display=~s/^([a-z])/uc($1)/e;
        !          1222: 		    $result.='<div class="'.$status.'"><h4>'.$mandatory.
        !          1223: 			' Criteria</h4><p>'.
        !          1224: 			$dimension{$instance.'.criteria.'.$id}.
        !          1225: 			'</p><p class="grade">'.$status_display.'</p>';
1.25      albertel 1226: 		    if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
1.53    ! albertel 1227: 			$result.='<p class="comment">'.$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</p>';
1.22      albertel 1228: 		    }
1.53    ! albertel 1229: 		    $result.='</div>';
1.22      albertel 1230: 		}
                   1231: 	    }
1.18      albertel 1232: 	} elsif ($target eq 'webgrade') {
1.47      albertel 1233: 	    # in case of any side effects that we need
                   1234: 	    @Apache::scripttag::parser_env = @_;
                   1235: 	    &Apache::scripttag::xmlparse($dimension{'intro'});
                   1236: 	    @Apache::scripttag::parser_env = @_;
                   1237: 	    &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.18      albertel 1238: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                   1239: 		my $link='criteria_'.$instance.'_'.$id;
1.25      albertel 1240: 		my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19      albertel 1241: 		$result.='<tr><td width="100%" valign="top">'.
1.18      albertel 1242: 		    '<a name="'.$link.'" />'.
                   1243: 		    '<a name="next_'.$last_link.'" />'.
1.47      albertel 1244: 		    '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">';
                   1245: 		@Apache::scripttag::parser_env = @_;
                   1246: 		$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
                   1247: 		$result.='</textarea>'.
1.18      albertel 1248: 		    #$dimension{$instance.'.criteria.'.$id}.
                   1249: 		    '</td>'.
1.19      albertel 1250: 		    '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25      albertel 1251: 		    '<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 1252: 		    '</td>'.
                   1253: 		    '<td>'.
1.47      albertel 1254: 		    '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label></nobr><br />'.
1.30      albertel 1255: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
                   1256: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
                   1257: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18      albertel 1258: 		    '</td>'.
                   1259: 		    '<td>'.
                   1260: 		    '<a href="#'.$last_link.'">Prev</a><br />'.
1.20      albertel 1261: 		    '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
                   1262: 		    '<input type="submit" name="next" value="'.
                   1263: 		    &mt('Done').'" /> '.
1.30      albertel 1264: 		    '<input type="submit" name="stop" value="'.
                   1265: 		    &mt('Stop').'" /> '.
1.18      albertel 1266: 		    '</td></tr>';
1.22      albertel 1267: 		$result.='<tr><td colspan="4">';
                   1268: 		my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
1.52      albertel 1269: 		my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.43      albertel 1270: 		foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"})) {
1.22      albertel 1271: 		    my $file=$file_url.$partial_file;
1.52      albertel 1272: 		    $file=~s|/+|/|g;
1.22      albertel 1273: 		    &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.48      albertel 1274: 		    $result.='<nobr><a href="'.$file.'" target="lonGRDs"><img src="'.
1.22      albertel 1275: 			&Apache::loncommon::icon($file).'" border=0"> '.$file.
1.48      albertel 1276: 			'</a></nobr> ';
1.22      albertel 1277: 		}
                   1278: 		$result.='</td></tr>';
1.18      albertel 1279: 		$last_link=$link;
                   1280: 	    }
1.22      albertel 1281: 	} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19      albertel 1282: 	    my $optional_passed=0;
1.20      albertel 1283: 	    my $mandatory_failed=0;
                   1284: 	    my $ungraded=0;
                   1285: 	    my $review=0;
1.19      albertel 1286: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel 1287: 		my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
                   1288: 		$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20      albertel 1289: 		my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
                   1290: 		if ($status eq 'pass') {
                   1291: 		    if (!$mandatory) { $optional_passed++; }
                   1292: 		} elsif ($status eq 'fail') {
                   1293: 		    if ($mandatory) { $mandatory_failed++; }
1.21      albertel 1294: 		} elsif ($status eq 'review') {
                   1295: 		    $review++;
1.20      albertel 1296: 		} elsif ($status eq 'ungraded') {
                   1297: 		    $ungraded++;
1.21      albertel 1298: 		} else {
1.47      albertel 1299: 		    $ungraded++;
1.19      albertel 1300: 		}
                   1301: 	    }
1.20      albertel 1302: 	    if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
                   1303: 		$mandatory_failed++;
                   1304: 	    }
1.21      albertel 1305: 	    &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 1306: 	    if ($review) {
1.25      albertel 1307: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1308: 		    'review';
1.20      albertel 1309: 	    } elsif ($ungraded) {
1.25      albertel 1310: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1311: 		    'ungraded';
1.20      albertel 1312: 	    } elsif ($mandatory_failed) {
1.25      albertel 1313: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1314: 		    'fail';
1.20      albertel 1315: 	    } else {
1.25      albertel 1316: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel 1317: 		    'pass';
1.20      albertel 1318: 	    }
1.13      albertel 1319: 	}
1.18      albertel 1320: 	return $result;
1.1       albertel 1321:     }
                   1322: }
                   1323: 
                   1324: sub start_IntroParagraph {
                   1325:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1326:     my $result;
1.13      albertel 1327:     if ($target eq 'web' || $target eq 'webgrade') {
1.47      albertel 1328: 	if ($tagstack->[-2] eq 'Dimension') {
                   1329: 	    $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser);
                   1330: 	
                   1331: 	} elsif ($target eq 'webgrade') {
                   1332: 	    &Apache::lonxml::get_all_text('/introparagraph',$parser);
1.1       albertel 1333: 	}
1.47      albertel 1334: 	
1.1       albertel 1335:     }
                   1336:     return $result;
                   1337: }
                   1338: 
                   1339: sub end_IntroParagraph {
                   1340: }
                   1341: 
                   1342: sub start_Instance {
                   1343:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel 1344:     my $id=&get_id($parstack,$safeeval);
                   1345:     push(@{$dimension{'instances'}},$id);
                   1346:     push(@Apache::bridgetask::instance,$id);
                   1347:     push(@Apache::bridgetask::instancelist,$id);
1.20      albertel 1348:     $dimension{$id.'.optionalrequired'}=
1.19      albertel 1349: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1       albertel 1350:     return '';
                   1351: }
                   1352: 
                   1353: sub end_Instance {
                   1354: }
                   1355: 
                   1356: sub start_InstanceText {
                   1357:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47      albertel 1358:     my $instance_id=$Apache::bridgetask::instance[-1];
                   1359:     my $text=&Apache::lonxml::get_all_text('/instancetext',$parser);
1.13      albertel 1360:     if ($target eq 'web' || $target eq 'webgrade') {
1.47      albertel 1361: 	$dimension{$instance_id.'.text'}=$text;
1.1       albertel 1362:     }
                   1363:     return '';
                   1364: }
                   1365: 
                   1366: sub end_InstanceText {
                   1367:     return '';
                   1368: }
                   1369: 
                   1370: sub start_Criteria {
                   1371:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel 1372:     my $instance_id=$Apache::bridgetask::instance[-1];
1.47      albertel 1373:     my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser);
1.21      albertel 1374:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.19      albertel 1375: 	my $id=&get_id($parstack,$safeeval);
1.1       albertel 1376: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19      albertel 1377: 	$dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
                   1378: 	    &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel 1379: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
                   1380:     }
                   1381:     return '';
                   1382: }
                   1383: 
1.47      albertel 1384: sub end_Criteria {
                   1385: }
                   1386: 
1.4       albertel 1387: sub proctor_validation_screen {
                   1388:     my ($slot) = @_;
                   1389:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel 1390:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44      albertel 1391:     my $name=&Apache::loncommon::plainname($user,$domain);
                   1392:     
1.4       albertel 1393:     my $msg;
1.11      albertel 1394:     if ($env{'form.proctorpassword'}) {
1.4       albertel 1395: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                   1396: 	    .'</font></p>';
                   1397:     }
1.47      albertel 1398:     if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4       albertel 1399:     my $result= (<<ENDCHECKOUT);
                   1400: <h2>Proctor Validation</h2>
                   1401:     <p>Your room's proctor needs to validate your access to this resource.</p>
                   1402:     $msg
1.11      albertel 1403: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4       albertel 1404: <input type="hidden" name="validate" value="yes" />
                   1405: <input type="hidden" name="submitted" value="yes" />
                   1406: <table>
1.44      albertel 1407:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4       albertel 1408:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46      albertel 1409:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4       albertel 1410: </table>
                   1411: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
1.44      albertel 1412: <table border="1">
                   1413:   <tr><td>
                   1414:     <table>
                   1415:       <tr><td colspan="2">Student who should be logged in is:</td></tr>
                   1416:       <tr><td>Name:</td><td>$name</td></tr>
1.45      albertel 1417:       <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.44      albertel 1418:       <tr><td>Usename</td><td>$user\@$domain</td></tr>
                   1419:       <tr><td colspan="2"><img src="$url" /></td></tr>
                   1420:     </table>
                   1421:   </tr></td>
                   1422: </table>
1.4       albertel 1423: </form>
                   1424: ENDCHECKOUT
                   1425:     return $result;
                   1426: }
                   1427: 
1.1       albertel 1428: 1;
                   1429: __END__

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