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

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

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