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

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

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