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

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

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