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

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

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