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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.30    ! albertel    4: # $Id: bridgetask.pm,v 1.29 2005/05/20 21:23:42 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;
                     39: use Time::HiRes qw( gettimeofday tv_interval );
1.9       albertel   40: 
1.1       albertel   41: BEGIN {
                     42:     &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
                     43: }
                     44: 
1.9       albertel   45: sub initialize_bridgetask {
                     46:     # id of current Dimension, 0 means that no dimension is current 
                     47:     # (inside <Task> only)
                     48:     $Apache::bridgetask::dimension='';
                     49:     # list of all Dimension ids seen
                     50:     @Apache::bridgetask::dimensionlist=();
1.20      albertel   51:     # mandatory attribute of all Dimensions seen
                     52:     %Apache::bridgetask::dimensionmandatory=();
1.9       albertel   53:     # list of all current Instance ids
                     54:     @Apache::bridgetask::instance=();
                     55:     # list of all Instance ids seen in this problem
                     56:     @Apache::bridgetask::instancelist=();
1.15      albertel   57:     # key of queud user data that we are currently grading
                     58:     $Apache::bridgetask::queue_key='';
1.9       albertel   59: }
                     60: 
1.4       albertel   61: sub proctor_check_auth {
1.22      albertel   62:     my ($slot_name,$slot)=@_;
1.11      albertel   63:     my $user=$env{'form.proctorname'};
                     64:     my $domain=$env{'form.proctordomain'};
1.4       albertel   65:     
                     66:     my @allowed=split(",",$slot->{'proctor'});
                     67:     foreach my $possible (@allowed) {
                     68: 	my ($puser,$pdom)=(split('@',$possible));
                     69: 	if ($puser eq $user && $pdom eq $domain) {
1.11      albertel   70: 	    my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4       albertel   71: 	    if ($authhost ne 'no_host') {
1.23      albertel   72: 		my $version=
                     73: 		    $Apache::lonhomework::results{'resource.version'}=
1.27      albertel   74: 		    ++$Apache::lonhomework::history{'resource.version'};
1.23      albertel   75: 		$Apache::lonhomework::results{"resource.$version.checkedin"}=
1.4       albertel   76: 		    $user.'@'.$domain;
1.23      albertel   77: 		$Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
1.22      albertel   78: 		    $slot_name;
1.28      albertel   79: 		foreach my $key (keys(%Apache::lonhomework::history)) {
                     80: 		    if ($key=~/^resource\.0\./) {
                     81: 			$Apache::lonhomework::results{$key}='';
                     82: 		    }
                     83: 		}
1.4       albertel   84: 		return 1;
                     85: 	    }
                     86: 	}
                     87:     }
                     88:     return 0;
                     89: }
                     90: 
1.25      albertel   91: sub get_version {
1.29      albertel   92:     my ($version,$previous);
1.25      albertel   93:     if ($env{'form.previousversion'} && 
                     94: 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
1.29      albertel   95: 	$version=$env{'form.previousversion'};
                     96: 	$previous=1;
                     97:     } else {
                     98: 	$version=$Apache::lonhomework::history{'resource.version'};
                     99: 	$previous=0;
                    100:     }
                    101:     if (wantarray) {
                    102: 	return ($version,$previous);
1.25      albertel  103:     }
1.29      albertel  104:     return $version;
1.25      albertel  105: }
                    106: 
1.8       albertel  107: sub add_previous_version_button {
1.25      albertel  108:     my ($status)=@_;
1.8       albertel  109:     my $result;
1.29      albertel  110:     if ($Apache::lonhomework::history{'resource.version'} eq '') {
1.25      albertel  111: 	return '';
                    112:     }
1.29      albertel  113:     if ($Apache::lonhomework::history{'resource.version'} < 2 &&
                    114: 	$status ne 'NEEDS_CHECKIN') {
1.25      albertel  115: 	return '';
                    116:     }
1.29      albertel  117:     my $version=&get_version();
                    118:     if ($env{'form.previousversion'} ne '' &&
                    119: 	$env{'form.previousversion'} eq $version) {
                    120: 	$result.="<h3>".&mt("Showing previous version [_1]",$version).
                    121: 	    "</h3>\n";
                    122:     }
                    123:     my @to_show;
                    124:     foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
                    125: 	if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
                    126: 	    push(@to_show,$test_version);
                    127: 	}
                    128:     }
                    129:     my $list='<option>'.
                    130: 	join("</option>\n<option>",@to_show).
                    131: 	     "</option>\n";
                    132:     $result.='<form name="getprevious" method="POST" action="';
                    133:     my $uri=$env{'request.uri'};
                    134:     if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    135:     $result.=$uri.'">'.
                    136: 	&mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
                    137: <option>'.&mt('Pick one').'</option>
                    138: '.$list.'
                    139: </select>')."</form>";
1.8       albertel  140:     return $result;
                    141: }
                    142: 
1.13      albertel  143: sub add_grading_button {
1.29      albertel  144:     my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13      albertel  145: 	&mt("Get a submission to grade").'" />';
                    146:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
                    147:     return $result;
                    148: }
                    149: 
1.22      albertel  150: sub add_request_another_attempt_button {
1.25      albertel  151:     my $result;
                    152:     $result.=' <input type="submit" name="requestattempt" value="'.
                    153: 	&mt("Request another attempt").'" />';
                    154:     return $result;
1.22      albertel  155: }
                    156: 
1.30    ! albertel  157: sub preserve_grade_info {
        !           158:     my $result;
        !           159:     # if we are viewing someone else preserve that info
        !           160:     if (defined $env{'form.grade_symb'}) {
        !           161: 	foreach my $field ('symb','courseid','domain','username') {
        !           162: 	    $result .= '<input type="hidden" name="grade_'.$field.
        !           163: 		'" value="'.$env{"form.grade_$field"}.'" />'."\n";
        !           164: 	}
        !           165:     }
        !           166:     return $result;
        !           167: }
        !           168: 
1.1       albertel  169: sub start_Task {
                    170:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    171: 
1.4       albertel  172:     my ($status,$accessmsg,$slot);
1.16      albertel  173:     if ($target ne 'webgrade') {
                    174: 	&Apache::structuretags::initialize_storage();
                    175: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
                    176:     } 
                    177: 
1.4       albertel  178:     $Apache::lonhomework::parsing_a_task=1;
1.1       albertel  179:     #should get back a <html> or the neccesary stuff to start XML/MathML
                    180:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    181: 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16      albertel  182:     
1.8       albertel  183:     if ($target eq 'web') {
1.13      albertel  184: 	if ($Apache::lonhomework::modifygrades) {
                    185: 	    $body_tag_start.='<form name="gradesubmission" method="POST" action="';
                    186: 	    my $uri=$env{'request.uri'};
                    187: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    188: 	    $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
                    189: 	}
1.8       albertel  190:     }
1.21      albertel  191:     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1       albertel  192: 	$target eq 'tex') {
1.29      albertel  193: 	my ($version,$previous)=&get_version();
1.14      albertel  194: 	($status,$accessmsg,my $slot_name,$slot) = 
1.4       albertel  195: 	    &Apache::lonhomework::check_task_access('0');
1.9       albertel  196: 	push(@Apache::inputtags::status,$status);
1.14      albertel  197: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  198: 	my $expression='$external::datestatus="'.$status.'";';
1.23      albertel  199: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1       albertel  200: 	&Apache::run::run($expression,$safeeval);
                    201: 	&Apache::lonxml::debug("Got $status");
1.25      albertel  202: 	$body_tag_start.=&add_previous_version_button($status);
1.29      albertel  203: 	if (!$previous && (
                    204: 			   ( $status eq 'CLOSED' ) ||
                    205: 			   ( $status eq 'BANNED') ||
                    206: 			   ( $status eq 'UNAVAILABLE') ||
                    207: 			   ( $status eq 'NOT_IN_A_SLOT') ||
                    208: 			   ( $status eq 'NEEDS_CHECKIN') ||
                    209: 			   ( $status eq 'WAITING_FOR_GRADE') ||
                    210: 			   ( $status eq 'INVALID_ACCESS') )) {
1.1       albertel  211: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    212: 	    if ( $target eq "web" ) {
1.4       albertel  213: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
                    214: 		my $msg;
1.1       albertel  215: 		if ($status eq 'UNAVAILABLE') {
                    216: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  217: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    218: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4       albertel  219: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    220: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    221: 			'</h1>'.&proctor_validation_screen($slot);
1.22      albertel  222: 		} elsif ($status eq 'WAITING_FOR_GRADE') {
                    223: 		    $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1       albertel  224: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    225: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    226: 		}
                    227: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    228: 		    $msg.='The problem '.$accessmsg;
                    229: 		}
                    230: 		$result.=$msg.'<br />';
                    231: 	    } elsif ($target eq 'tex') {
                    232: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    233: 		if ($status eq 'UNAVAILABLE') {
                    234: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    235: 		} else {
                    236: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    237: 		}
1.22      albertel  238: 	    } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4       albertel  239: 		if ($status eq 'NEEDS_CHECKIN') {
1.22      albertel  240: 		    if (&proctor_check_auth($slot_name,$slot)) {
1.4       albertel  241: 			#FIXME immeadiatly add this to the grading queue
                    242:                         #      with slot->{'endtime'} for when grading can 
                    243:                         #      begin on this resource
1.22      albertel  244: 			# FIXME I think the above is done by default,
                    245:                         #        need to check that
                    246:                         #        failure doesn't do this.
1.4       albertel  247:  		    }
                    248: 		}
1.1       albertel  249: 	    }
                    250: 	} elsif ($target eq 'web') {
                    251: 	    my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    252: 	    $result.="$head_tag_start<title>$name</title></head>
                    253:               $body_tag_start \n $form_tag_start".	
                    254: 	      '<input type="hidden" name="submitted" value="yes" />';
1.30    ! albertel  255: 	    $result.=&preserve_grade_info();
1.29      albertel  256: 	    my ($version,$previous)=&get_version();
1.25      albertel  257: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22      albertel  258: 		$result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
1.29      albertel  259: 		if (!$previous) {
                    260: 		    $result.=&add_request_another_attempt_button();
                    261: 		}
1.22      albertel  262: 	    }
1.25      albertel  263: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
1.22      albertel  264: 		$result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
                    265: 	    }
1.1       albertel  266: 	}
1.21      albertel  267:     } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                    268: 	      $target eq 'webgrade') {
                    269: 	if ($target eq 'webgrade') {
                    270: 	    $result.=$head_tag_start.$body_tag_start.$form_tag_start;
                    271: 	    $result.='<input type="hidden" name="webgrade" value="yes" />';
1.30    ! albertel  272: 	    $result.='<br />Before'.&show_queue('gradingqueue');
        !           273: 	}
        !           274: 	my $todo;
        !           275: 	# don't get something new from the queue if they hit the stop button
        !           276: 	if (!($env{'form.stop'} && $target eq 'webgrade')) {
        !           277: 	    $todo=&get_from_queue('gradingqueue');
1.21      albertel  278: 	}
1.15      albertel  279: 	if ($todo) {
1.16      albertel  280: 	    &setup_env_for_other_user($todo,$safeeval);
1.15      albertel  281: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
1.16      albertel  282: 	    $result.="\n".'<table><tr><td>Found '.
                    283: 		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
1.15      albertel  284: 	    $result.='<input type="hidden" name="gradingkey" value="'.
1.16      albertel  285: 		&Apache::lonnet::escape($todo).'" />';
1.15      albertel  286: 	    $Apache::bridgetask::queue_key=$todo;
1.16      albertel  287: 	    &Apache::structuretags::initialize_storage();
                    288: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.30    ! albertel  289: 	    if ($target eq 'webgrade') {
        !           290: 		$result.='<br />After'.&show_queue('gradingqueue');
        !           291: 		$result.="\n".'<table width="100%" style="width:100%" border="1">';
        !           292: 	    }
1.15      albertel  293: 	} else {
1.21      albertel  294: 	    if ($target eq 'webgrade') {
1.30    ! albertel  295: 		$result.="\n".'<table><tr><td><b>';
        !           296: 		if ($env{'form.stop'}) {
        !           297: 		    $result.=&mt("Stopped grading.");
        !           298: 		} else {
        !           299: 		    $result.=&mt("No user to be graded.");
        !           300: 		}
        !           301: 		$result.='</b></td></tr></table>';
1.21      albertel  302: 	    }
1.15      albertel  303: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    304: 	}
1.1       albertel  305:     } else {
                    306: 	# page_start returned a starting result, delete it if we don't need it
                    307: 	$result = '';
                    308:     }
                    309:     return $result;
                    310: }
                    311: 
                    312: sub end_Task {
                    313:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    314:     my $result='';
                    315:     my $status=$Apache::inputtags::status['-1'];
1.29      albertel  316:     my ($version,$previous)=&get_version();
1.1       albertel  317:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel  318: 	$target eq 'tex') {
1.1       albertel  319: 	if (
1.11      albertel  320: 	    (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1       albertel  321: 	    ($target eq 'answer') || ($target eq 'tex')
                    322: 	   ) {
                    323: 	    if ($target eq 'web') {
1.29      albertel  324: 		if ($status eq 'CAN_ANSWER' && !$previous) {
1.15      albertel  325: 		    $result.="\n".'<table border="1">'.
1.28      albertel  326: 			&Apache::inputtags::file_selector("$version.0",
                    327: 							  "bridgetask","*",
1.9       albertel  328: 							  'portfolioonly').
                    329: 							  "</table>";
                    330: 		    $result.=&Apache::inputtags::gradestatus('0');
                    331: 		}
1.13      albertel  332: 	    } 
                    333: 	    if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  334: 		$result.=&Apache::lonxml::xmlend().'</html>';
                    335: 	    }
                    336: 	}
1.29      albertel  337: 	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12      albertel  338: 	    my $award='SUBMITTED';
1.28      albertel  339: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20      albertel  340: 						    'portfiles',\$award);
1.14      albertel  341: 	    if ($award eq 'SUBMITTED' &&
1.28      albertel  342: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
                    343: 		$Apache::lonhomework::results{"resource.0.tries"}=
                    344: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
                    345: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
                    346: 
                    347: 		$Apache::lonhomework::results{"resource.0.award"}=
                    348: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
                    349: 		    $award;
1.10      albertel  350: 	    }
1.4       albertel  351: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    352: 	    &Apache::structuretags::finalize_storage();
1.14      albertel  353: 	    if ($award eq 'SUBMITTED') {
1.30    ! albertel  354: 		&add_to_queue('gradingqueue');
1.14      albertel  355: 	    }
1.1       albertel  356: 	}
1.20      albertel  357: 	if ($target eq 'grade' && $env{'form.webgrade'}) {
                    358: 	    my $optional_required=
                    359: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                    360: 					   $safeeval);
                    361: 	    my $optional_passed=0;
                    362: 	    my $mandatory_failed=0;
                    363: 	    my $ungraded=0;
                    364: 	    my $review=0;   
1.21      albertel  365: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20      albertel  366: 	    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
                    367: 		my $status=
1.25      albertel  368: 		    $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20      albertel  369: 		my $mandatory=
                    370: 		    ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
                    371: 		if ($status eq 'pass') {
                    372: 		    if (!$mandatory) { $optional_passed++; }
                    373: 		} elsif ($status eq 'fail') {
                    374: 		    if ($mandatory) { $mandatory_failed++; }
                    375: 		} elsif ($status eq 'ungraded') {
                    376: 		    $ungraded++;
                    377: 		} elsif ($status eq 'review') {
                    378: 		    $review++;
                    379: 		}	
                    380: 	    }
                    381: 	    if ($optional_passed < $optional_required) {
                    382: 		$mandatory_failed++;
                    383: 	    }
1.21      albertel  384: 	    &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
                    385: 	    $Apache::lonhomework::results{'resource.grader'}=
1.20      albertel  386: 		$env{'user.name'}.'@'.$env{'user.domain'};
                    387: 	    if ($review) {
1.25      albertel  388: 		$Apache::lonhomework::results{"resource.$version.status"}='review';
1.20      albertel  389: 		&move_to_review_queue();
                    390: 	    } elsif ($ungraded) {
1.25      albertel  391: 		$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.30    ! albertel  392: 		&check_queue_unlock('gradingqueue');
1.20      albertel  393: 	    } elsif ($mandatory_failed) {
1.25      albertel  394: 		$Apache::lonhomework::results{"resource.$version.status"}='fail';
                    395: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                    396: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                    397: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.30    ! albertel  398: 		&remove_from_queue('gradingqueue');
1.20      albertel  399: 	    } else {
1.25      albertel  400: 		$Apache::lonhomework::results{"resource.$version.status"}='pass';
                    401: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                    402: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                    403: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.20      albertel  404: 		&remove_from_queue();
                    405: 	    }
1.26      albertel  406: 	    $Apache::lonhomework::results{"resource.status"}=
                    407: 		$Apache::lonhomework::results{"resource.$version.status"};
1.28      albertel  408: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel  409: 		$Apache::lonhomework::results{"resource.0.award"}=
                    410: 		    $Apache::lonhomework::results{"resource.$version.award"};
                    411: 		$Apache::lonhomework::results{"resource.0.awarded"}=
                    412: 		    $Apache::lonhomework::results{"resource.$version.awarded"};
                    413: 		$Apache::lonhomework::results{"resource.0.solved"}=
                    414: 		    $Apache::lonhomework::results{"resource.$version.solved"};
1.25      albertel  415: 	    }
1.21      albertel  416: 	    &Apache::structuretags::finalize_storage();
1.20      albertel  417: 	}
1.15      albertel  418:     } elsif ($target eq 'webgrade') {
1.18      albertel  419: 	$result.="</table>\n<hr />";
1.20      albertel  420: 	#$result.='<input type="submit" name="next" value="'.
                    421: 	#    &mt('Save &amp; Next').'" /> ';
                    422: 	#$result.='<input type="submit" name="end" value="'.
                    423: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                    424: 	#$result.='<input type="submit" name="throwaway" value="'.
                    425: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                    426: 	#$result.='<input type="submit" name="save" value="'.
                    427: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15      albertel  428: 	$result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1       albertel  429:     } elsif ($target eq 'meta') {
1.2       albertel  430: 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1       albertel  431: 	#$result.=&Apache::response::meta_part_order();
                    432: 	#$result.=&Apache::response::meta_response_order();
                    433:     }
1.4       albertel  434:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel  435:     return $result;
                    436: }
                    437: 
1.21      albertel  438: sub move_to_review_queue {
1.30    ! albertel  439: 
1.21      albertel  440:     &Apache::lonxml::debug("Want to move");
                    441: }
                    442: 
                    443: sub check_queue_unlock {
1.30    ! albertel  444:     my ($queue)=@_;
        !           445:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
        !           446:     my $cnum=$env{'course.'.$cid.'.num'};
        !           447:     my $cdom=$env{'course.'.$cid.'.domain'};
        !           448:     my $key="$symb\0queue\0$uname\@$udom";
        !           449:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
        !           450:     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
        !           451:     if  ($who eq $me) {
        !           452: 	&Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
        !           453:     }
1.21      albertel  454: }
                    455: 
                    456: sub remove_from_queue {
1.30    ! albertel  457:     my ($queue)=@_;
1.27      albertel  458:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    459:     my $cnum=$env{'course.'.$cid.'.num'};
                    460:     my $cdom=$env{'course.'.$cid.'.domain'};
                    461:     my $key="$symb\0queue\0$uname\@$udom";
                    462:     my @keys=($key,"$key\0locked");
1.30    ! albertel  463:     &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21      albertel  464: }
                    465: 
1.16      albertel  466: sub setup_env_for_other_user {
                    467:     my ($queue_key,$safeeval)=@_;
                    468:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30    ! albertel  469:     &Apache::lonxml::debug("setup_env for $queue_key");
1.16      albertel  470:     $env{'form.grade_symb'}=$symb;
                    471:     $env{'form.grade_domain'}=$udom;
                    472:     $env{'form.grade_username'}=$uname;
                    473:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                    474:     &Apache::lonxml::initialize_rndseed($safeeval);
                    475: }
                    476: 
1.14      albertel  477: sub add_to_queue {
1.30    ! albertel  478:     my ($queue)=@_;
1.14      albertel  479:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    480:     my $cnum=$env{'course.'.$cid.'.num'};
                    481:     my $cdom=$env{'course.'.$cid.'.domain'};
                    482:     my %data;
                    483:     $data{"$symb\0queue\0$uname\@$udom"}=[$Apache::inputtags::slot_name];
1.30    ! albertel  484:     &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14      albertel  485: }
                    486: 
                    487: sub show_queue {
1.30    ! albertel  488:     my ($queue)=@_;
1.14      albertel  489:     my $result;
                    490:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    491:     my $cnum=$env{'course.'.$cid.'.num'};
                    492:     my $cdom=$env{'course.'.$cid.'.domain'};
1.16      albertel  493:     my $regexp="^$symb\0";
1.30    ! albertel  494:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.27      albertel  495:     $result.="\n<h3>Current Queue</h3><table border='1'><tr><th>resource</th>".
1.20      albertel  496: 	"<th>user</th><th>type</th><th>data</th></tr>";
1.14      albertel  497:     foreach my $key (sort(keys(%queue))) {
1.16      albertel  498: 	if ($key=~/locked$/) {
                    499: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    500: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  501: 	    $result.="<tr><td>$title</td><td>$uname</td>";
1.16      albertel  502: 	    $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
                    503: 	} elsif ($key=~/timestamp$/) {
                    504: 	    my ($symb,undef) = split("\0",$key);
                    505: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  506: 	    $result.="<tr><td>$title</td><td></td>";
1.16      albertel  507: 	    $result.='<td>last queue modification time</td><td>'.
                    508: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
                    509: 	} else {
                    510: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
                    511: 	    my $title=&Apache::lonnet::gettitle($symb);
1.27      albertel  512: 	    $result.="<tr><td>$title</td><td>$uname</td>";
1.16      albertel  513: 	    my $slot=$queue{$key}->[0];
                    514: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
1.27      albertel  515: 	    $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20      albertel  516: 		&Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
                    517: 		"</td></tr>";
1.16      albertel  518: 	}
1.14      albertel  519:     }
1.15      albertel  520:     $result.="</table><hr />\n";
1.14      albertel  521:     return $result;
                    522: }
                    523: 
                    524: sub decode_queue_key {
                    525:     my ($key)=@_;
                    526:     my ($symb,undef,$user) = split("\0",$key);
                    527:     my ($uname,$udom) = split('@',$user);
                    528:     return ($symb,$uname,$udom);
                    529: }
                    530: 
                    531: sub queue_key_locked {
1.30    ! albertel  532:     my ($queue,$key,$cdom,$cnum)=@_;
1.14      albertel  533:     my ($key_locked,$value)=
1.30    ! albertel  534: 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14      albertel  535:     if ($key_locked eq "$key\0locked") {
                    536: 	return $value;
                    537:     }
                    538:     return undef;
                    539: }
                    540: 
                    541: sub pick_from_queue_data {
1.30    ! albertel  542:     my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
        !           543:     foreach my $key (keys(%$queuedata)) {
1.14      albertel  544: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
                    545: 	if ($check_section) {
                    546: 	    my $section=&Apache::lonnet::getsection($uname,$udom);
1.17      albertel  547: 	    if ($section eq $check_section) {
                    548: 		&Apache::lonnet::logthis("my sec");
1.15      albertel  549: 		next;
                    550: 	    }
1.14      albertel  551: 	}
1.30    ! albertel  552: 	my $slot=$queuedata->{$key}[0];
1.14      albertel  553: 	my %slot_data=&Apache::lonnet::get_slot($slot);
1.15      albertel  554: 	if ($slot_data{'endtime'} > time) { 
                    555: 	    &Apache::lonnet::logthis("not time");
                    556: 	    next;
                    557: 	}
1.30    ! albertel  558: 	if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.15      albertel  559: 	    &Apache::lonnet::logthis("someone already has um.");
                    560: 	    next;
                    561: 	}
1.14      albertel  562: 	return $key;
                    563:     }
                    564:     return undef;
                    565: }
                    566: 
1.15      albertel  567: sub find_mid_grade {
1.30    ! albertel  568:     my ($queue,$symb,$cdom,$cnum)=@_;
1.16      albertel  569:     my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15      albertel  570:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    571:     if ($todo) {
1.30    ! albertel  572: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel  573: 	if ($who eq $me) { return $todo; }
                    574:     }
                    575:     my $regexp="^$symb\0.*\0locked\$";
1.30    ! albertel  576:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel  577:     foreach my $key (keys(%locks)) {
                    578: 	my $who=$locks{$key};
                    579: 	if ($who eq $me) {
                    580: 	    $todo=$key;
                    581: 	    $todo=~s/\0locked$//;
                    582: 	    return $todo;
                    583: 	}
                    584:     }
                    585:     return undef;
                    586: }
                    587: 
1.14      albertel  588: sub get_from_queue {
1.30    ! albertel  589:     my ($queue)=@_;
1.14      albertel  590:     my $result;
                    591:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    592:     my $cnum=$env{'course.'.$cid.'.num'};
                    593:     my $cdom=$env{'course.'.$cid.'.domain'};
                    594:     my $todo;
1.15      albertel  595:     # FIXME need to find if I am 'mid grading'
1.30    ! albertel  596:     $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.15      albertel  597:     &Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo)));
1.16      albertel  598:     if ($todo) { return $todo; }
1.14      albertel  599:     while (1) {
                    600: 	my $starttime=time;
1.30    ! albertel  601: 	&Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14      albertel  602: 			     $cdom,$cnum);
1.15      albertel  603: 	&Apache::lonnet::logthis("$starttime");
1.14      albertel  604: 	my $regexp="^$symb\0queue\0";
1.30    ! albertel  605: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.14      albertel  606: 	#make a pass looking for a user in my section
                    607: 	if ($env{'request.course.sec'}) {
1.15      albertel  608: 	    &Apache::lonnet::logthis("sce");
1.30    ! albertel  609: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
        !           610: 					\%queue,$cdom,$cnum);
1.15      albertel  611: 	    &Apache::lonnet::logthis("sce $todo");
1.14      albertel  612: 	}
                    613: 	# no one in our section so look for any user that is ready for grading
                    614: 	if (!$todo) {
1.15      albertel  615: 	    &Apache::lonnet::logthis("no sce");
                    616: 	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
                    617: 					$cdom,$cnum);
                    618: 	    &Apache::lonnet::logthis("no sce $todo");
1.14      albertel  619: 	}
                    620: 	# no user to grade 
                    621: 	if (!$todo) { last; }
1.15      albertel  622: 	&Apache::lonnet::logthis("got $todo");
1.14      albertel  623: 	# otherwise found someone so lets try to lock them
1.30    ! albertel  624: 	my $success=&Apache::lonnet::newput($queue,
1.14      albertel  625: 					    {"$todo\0locked"=>
                    626: 						 $env{'user.name'}.'@'.$env{'user.domain'}},
                    627: 					   $cdom,$cnum);
                    628: 	# someone else already picked them
1.15      albertel  629: 	&Apache::lonnet::logthis("success $todo");
1.14      albertel  630: 	if ($success ne 'ok') { next; }
                    631: 	my (undef,$endtime)=
1.30    ! albertel  632: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel  633: 				 $cdom,$cnum);
1.15      albertel  634: 	&Apache::lonnet::logthis("emd  $endtime");
1.14      albertel  635: 	# someone else already modified the queue, 
                    636: 	# perhaps our picked user wass already fully graded between
                    637: 	# when we picked him and when we locked his record? so lets
                    638: 	# double check.
                    639: 	if ($endtime != $starttime) {
                    640: 	    my ($key,$value)=
1.30    ! albertel  641: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel  642: 				     $cdom,$cnum);
1.15      albertel  643: 	    &Apache::lonnet::logthis("check  $key .. $value");
1.14      albertel  644: 	    if ($key eq $todo && ref($value)) {
                    645: 	    } else {
1.30    ! albertel  646: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel  647: 				     $cdom,$cnum);
1.15      albertel  648: 		&Apache::lonnet::logthis("del");
1.14      albertel  649: 		next;
                    650: 	    }
                    651: 	}
1.15      albertel  652: 	&Apache::lonnet::logthis("last $todo");
1.14      albertel  653: 	last;
                    654:     }
                    655:     return $todo;
                    656: }
                    657: 
1.1       albertel  658: sub start_ClosingParagraph {
                    659:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    660:     my $result;
                    661:     if ($target eq 'web') {
1.13      albertel  662:     } elsif ($target eq 'webgrade') {
                    663: 	&Apache::lonxml::startredirection();
1.1       albertel  664:     }
                    665:     return $result;
                    666: }
                    667: 
                    668: sub end_ClosingParagraph {
                    669:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    670:     my $result;
                    671:     if ($target eq 'web') {
1.13      albertel  672:     } elsif ($target eq 'webgrade') {
                    673: 	&Apache::lonxml::endredirection();
1.1       albertel  674:     }
                    675:     return $result;
                    676: }
                    677: 
1.19      albertel  678: sub get_id {
                    679:     my ($parstack,$safeeval)=@_;
                    680:     my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
                    681:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                    682:     return $id;
                    683: }
                    684: 
1.1       albertel  685: my %dimension;
                    686: sub start_Dimension {
                    687:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    688:     undef(%dimension);
1.19      albertel  689:     my $dim_id=&get_id($parstack,$safeeval);
1.9       albertel  690:     $Apache::bridgetask::dimension=$dim_id;
                    691:     push(@Apache::bridgetask::dimensionlist,$dim_id);
                    692:     undef(@Apache::bridgetask::instance);
1.20      albertel  693:     $Apache::bridgetask::dimensionmandatory{$dim_id}=
                    694: 	&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel  695:     return '';
                    696: }
                    697: 
1.13      albertel  698: sub get_instance {
                    699:     #FIXME just grabbing the first one for now, need
                    700:     #to randomly pick one until all have been seen
                    701:     #then start repicking
                    702:     &Apache::response::pushrandomnumber();
                    703:     my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29      albertel  704:     my $num=@order;
                    705:     my $version=&get_version();
                    706:     my $which=($version-1)%$num;
                    707:     return $order[$which];
1.13      albertel  708: }
                    709: 
1.18      albertel  710: {
                    711:     my $last_link;
                    712:     sub end_Dimension {
                    713: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    714: 	my $result;
1.25      albertel  715: 	my $dim=&get_id($parstack,$safeeval);
1.19      albertel  716: 	my $instance=&get_instance();
1.25      albertel  717: 	my $version=&get_version();
1.18      albertel  718: 	if ($target eq 'web') {
                    719: 	    $result=$dimension{'intro'}.$dimension{$instance.'.text'};
1.26      albertel  720: 	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
                    721: 		$Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22      albertel  722: 		foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel  723: 		    my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
                    724: 		    my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.22      albertel  725: 		    $result.='<table border="1"><tr><td>';
                    726: 		    if ($status eq 'fail') {
                    727: 			$result.='<font color="red">'.&mt('Did not pass').'</font>';
                    728: 		    } elsif ($status eq 'pass') {
                    729: 			$result.='<font color="green">'.&mt('Passed').'</font>';
                    730: 		    } else {
                    731: 			&Apache::lonxml::error("Student viewing a graded bridgetask was show a status of $status");
                    732: 		    }
                    733: 		    $result.='</td></tr><tr><td>';
1.25      albertel  734: 		    if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
                    735: 			$result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</td></tr><tr><td>';
1.22      albertel  736: 		    }
                    737: 		    $result.=$dimension{$instance.'.criteria.'.$id}.
                    738: 			'</td></tr></table>';
                    739: 		}
                    740: 	    }
1.18      albertel  741: 	} elsif ($target eq 'webgrade') {
                    742: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                    743: 		my $link='criteria_'.$instance.'_'.$id;
1.25      albertel  744: 		my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19      albertel  745: 		$result.='<tr><td width="100%" valign="top">'.
1.18      albertel  746: 		    '<a name="'.$link.'" />'.
                    747: 		    '<a name="next_'.$last_link.'" />'.
                    748: 		    '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">'.$dimension{$instance.'.criteria.'.$id}.'</textarea>'.
                    749: 		    #$dimension{$instance.'.criteria.'.$id}.
                    750: 		    '</td>'.
1.19      albertel  751: 		    '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25      albertel  752: 		    '<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  753: 		    '</td>'.
                    754: 		    '<td>'.
1.30    ! albertel  755: 		    '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').'/>'.&mt('Ungraded').'</label></nobr><br />'.
        !           756: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
        !           757: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
        !           758: 		    '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18      albertel  759: 		    '</td>'.
                    760: 		    '<td>'.
                    761: 		    '<a href="#'.$last_link.'">Prev</a><br />'.
1.20      albertel  762: 		    '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
                    763: 		    '<input type="submit" name="next" value="'.
                    764: 		    &mt('Done').'" /> '.
1.30    ! albertel  765: 		    '<input type="submit" name="stop" value="'.
        !           766: 		    &mt('Stop').'" /> '.
1.18      albertel  767: 		    '</td></tr>';
1.22      albertel  768: 		$result.='<tr><td colspan="4">';
                    769: 		my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
                    770: 		my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
1.23      albertel  771: 		foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.bridgetask.portfiles"})) {
1.22      albertel  772: 		    my $file=$file_url.$partial_file;
                    773: 		    &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
                    774: 		    $result.='<a href="'.$file.'" target="lonGRDs"><img src="'.
                    775: 			&Apache::loncommon::icon($file).'" border=0"> '.$file.
                    776: 			'</a>';
                    777: 		}
                    778: 		$result.='</td></tr>';
1.18      albertel  779: 		$last_link=$link;
                    780: 	    }
1.22      albertel  781: 	} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19      albertel  782: 	    my $optional_passed=0;
1.20      albertel  783: 	    my $mandatory_failed=0;
                    784: 	    my $ungraded=0;
                    785: 	    my $review=0;
1.19      albertel  786: 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25      albertel  787: 		my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
                    788: 		$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20      albertel  789: 		my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
                    790: 		if ($status eq 'pass') {
                    791: 		    if (!$mandatory) { $optional_passed++; }
                    792: 		} elsif ($status eq 'fail') {
                    793: 		    if ($mandatory) { $mandatory_failed++; }
1.21      albertel  794: 		} elsif ($status eq 'review') {
                    795: 		    $review++;
1.20      albertel  796: 		} elsif ($status eq 'ungraded') {
                    797: 		    $ungraded++;
1.21      albertel  798: 		} else {
1.22      albertel  799: 		    &Apache::lonxml::error("got weird status --$status--");
1.19      albertel  800: 		}
                    801: 	    }
1.20      albertel  802: 	    if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
                    803: 		$mandatory_failed++;
                    804: 	    }
1.21      albertel  805: 	    &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  806: 	    if ($review) {
1.25      albertel  807: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel  808: 		    'review';
1.20      albertel  809: 	    } elsif ($ungraded) {
1.25      albertel  810: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel  811: 		    'ungraded';
1.20      albertel  812: 	    } elsif ($mandatory_failed) {
1.25      albertel  813: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel  814: 		    'fail';
1.20      albertel  815: 	    } else {
1.25      albertel  816: 		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22      albertel  817: 		    'pass';
1.20      albertel  818: 	    }
1.13      albertel  819: 	}
1.18      albertel  820: 	return $result;
1.1       albertel  821:     }
                    822: }
                    823: 
                    824: sub start_IntroParagraph {
                    825:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    826:     my $result;
1.13      albertel  827:     if ($target eq 'web' || $target eq 'webgrade') {
                    828: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel  829: 	    &Apache::lonxml::startredirection();
                    830: 	}
                    831:     }
                    832:     return $result;
                    833: }
                    834: 
                    835: sub end_IntroParagraph {
                    836:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    837:     my $result;
1.13      albertel  838:     if ($target eq 'web' || $target eq 'webgrade') {
                    839: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel  840: 	    $dimension{'intro'}=&Apache::lonxml::endredirection();
                    841: 	}
                    842:     }
                    843:     return $result;
                    844: }
                    845: 
                    846: sub start_Instance {
                    847:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel  848:     my $id=&get_id($parstack,$safeeval);
                    849:     push(@{$dimension{'instances'}},$id);
                    850:     push(@Apache::bridgetask::instance,$id);
                    851:     push(@Apache::bridgetask::instancelist,$id);
1.20      albertel  852:     $dimension{$id.'.optionalrequired'}=
1.19      albertel  853: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1       albertel  854:     return '';
                    855: }
                    856: 
                    857: sub end_Instance {
                    858:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    859:     return '';
                    860: }
                    861: 
                    862: sub start_InstanceText {
                    863:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13      albertel  864:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  865: 	&Apache::lonxml::startredirection();
                    866:     }
                    867:     return '';
                    868: }
                    869: 
                    870: sub end_InstanceText {
                    871:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel  872:     my $instance_id=$Apache::bridgetask::instance[-1];
1.13      albertel  873:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  874: 	$dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
                    875:     }
                    876:     return '';
                    877: }
                    878: 
                    879: sub start_Criteria {
                    880:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.21      albertel  881:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1       albertel  882: 	&Apache::lonxml::startredirection();
                    883:     }
                    884:     return '';
                    885: }
                    886: 
                    887: sub end_Criteria {
                    888:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel  889:     my $instance_id=$Apache::bridgetask::instance[-1];
1.21      albertel  890:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1       albertel  891: 	my $criteria=&Apache::lonxml::endredirection();
1.19      albertel  892: 	my $id=&get_id($parstack,$safeeval);
1.1       albertel  893: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19      albertel  894: 	$dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
                    895: 	    &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1       albertel  896: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
                    897:     }
                    898:     return '';
                    899: }
                    900: 
1.4       albertel  901: sub proctor_validation_screen {
                    902:     my ($slot) = @_;
                    903:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel  904:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11      albertel  905:     $user=$env{'form.proctorname'};
                    906:     if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4       albertel  907:     my $msg;
1.11      albertel  908:     if ($env{'form.proctorpassword'}) {
1.4       albertel  909: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                    910: 	    .'</font></p>';
                    911:     }
                    912:     my $result= (<<ENDCHECKOUT);
                    913: <h2>Proctor Validation</h2>
                    914:     <p>Your room's proctor needs to validate your access to this resource.</p>
                    915:     $msg
1.11      albertel  916: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4       albertel  917: <input type="hidden" name="validate" value="yes" />
                    918: <input type="hidden" name="submitted" value="yes" />
                    919: <table>
                    920:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
                    921:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6       albertel  922:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4       albertel  923: </table>
                    924: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
                    925: Student who should be logged in is:<br />
1.5       albertel  926: <img src="$url" /><br />
1.4       albertel  927: </form>
                    928: ENDCHECKOUT
                    929:     return $result;
                    930: }
                    931: 
1.1       albertel  932: 1;
                    933: __END__

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