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

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

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