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

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

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