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

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

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