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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.16    ! albertel    4: # $Id: bridgetask.pm,v 1.15 2005/05/03 05:31:51 albertel Exp $
1.1       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: ###
                     29: 
                     30: 
                     31: package Apache::bridgetask; 
                     32: 
                     33: use strict;
                     34: use Apache::lonnet;
                     35: use Apache::File();
                     36: use Apache::lonmenu;
                     37: use Apache::lonlocal;
                     38: use Apache::lonxml;
                     39: use Time::HiRes qw( gettimeofday tv_interval );
1.9       albertel   40: 
1.1       albertel   41: BEGIN {
                     42:     &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
                     43: }
                     44: 
1.9       albertel   45: sub initialize_bridgetask {
                     46:     # id of current Dimension, 0 means that no dimension is current 
                     47:     # (inside <Task> only)
                     48:     $Apache::bridgetask::dimension='';
                     49:     # list of all Dimension ids seen
                     50:     @Apache::bridgetask::dimensionlist=();
                     51:     # list of all current Instance ids
                     52:     @Apache::bridgetask::instance=();
                     53:     # list of all Instance ids seen in this problem
                     54:     @Apache::bridgetask::instancelist=();
1.15      albertel   55:     # key of queud user data that we are currently grading
                     56:     $Apache::bridgetask::queue_key='';
1.9       albertel   57: }
                     58: 
1.4       albertel   59: sub proctor_check_auth {
                     60:     my ($slot)=@_;
1.11      albertel   61:     my $user=$env{'form.proctorname'};
                     62:     my $domain=$env{'form.proctordomain'};
1.4       albertel   63:     
                     64:     my @allowed=split(",",$slot->{'proctor'});
                     65:     foreach my $possible (@allowed) {
                     66: 	my ($puser,$pdom)=(split('@',$possible));
                     67: 	if ($puser eq $user && $pdom eq $domain) {
1.11      albertel   68: 	    my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4       albertel   69: 	    if ($authhost ne 'no_host') {
                     70: 		$Apache::lonhomework::results{'resource.checkedin'}=
                     71: 		    $user.'@'.$domain;
                     72: 		return 1;
                     73: 	    }
                     74: 	}
                     75:     }
                     76:     return 0;
                     77: }
                     78: 
1.8       albertel   79: sub add_previous_version_button {
                     80:     my $result;
1.9       albertel   81:     $result.=&mt(' Show a previously done version: [_1]','<select name="previousversion">
1.8       albertel   82: <option>Pick one</option>
1.9       albertel   83: </select>');
1.8       albertel   84:     return $result;
                     85: }
                     86: 
1.13      albertel   87: sub add_grading_button {
                     88:     my $result;
                     89:     $result.=' <input type="submit" name="gradeasubmission" value="'.
                     90: 	&mt("Get a submission to grade").'" />';
                     91:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
                     92:     return $result;
                     93: }
                     94: 
1.1       albertel   95: sub start_Task {
                     96:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     97: 
1.4       albertel   98:     my ($status,$accessmsg,$slot);
1.16    ! albertel   99:     if ($target ne 'webgrade') {
        !           100: 	&Apache::structuretags::initialize_storage();
        !           101: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
        !           102:     } 
        !           103: 
1.4       albertel  104:     $Apache::lonhomework::parsing_a_task=1;
1.1       albertel  105:     #should get back a <html> or the neccesary stuff to start XML/MathML
                    106:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    107: 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16    ! albertel  108:     
1.8       albertel  109:     if ($target eq 'web') {
                    110: 	$body_tag_start.=&add_previous_version_button();
1.13      albertel  111: 	if ($Apache::lonhomework::modifygrades) {
                    112: 	    $body_tag_start.='<form name="gradesubmission" method="POST" action="';
                    113: 	    my $uri=$env{'request.uri'};
                    114: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    115: 	    $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
                    116: 	}
1.8       albertel  117:     }
1.1       albertel  118:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    119: 	$target eq 'tex') {
1.14      albertel  120: 	($status,$accessmsg,my $slot_name,$slot) = 
1.4       albertel  121: 	    &Apache::lonhomework::check_task_access('0');
1.9       albertel  122: 	push(@Apache::inputtags::status,$status);
1.14      albertel  123: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  124: 	my $expression='$external::datestatus="'.$status.'";';
                    125: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
                    126: 	&Apache::run::run($expression,$safeeval);
                    127: 	&Apache::lonxml::debug("Got $status");
                    128: 	if (( $status eq 'CLOSED' ) ||
                    129: 	    ( $status eq 'BANNED') ||
                    130: 	    ( $status eq 'UNAVAILABLE') ||
1.3       albertel  131: 	    ( $status eq 'NOT_IN_A_SLOT') ||
1.4       albertel  132: 	    ( $status eq 'NEEDS_CHECKIN') ||
1.1       albertel  133: 	    ( $status eq 'INVALID_ACCESS')) {
                    134: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    135: 	    if ( $target eq "web" ) {
1.4       albertel  136: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
                    137: 		my $msg;
1.1       albertel  138: 		if ($status eq 'UNAVAILABLE') {
                    139: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  140: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    141: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4       albertel  142: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    143: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    144: 			'</h1>'.&proctor_validation_screen($slot);
1.1       albertel  145: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    146: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    147: 		}
                    148: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    149: 		    $msg.='The problem '.$accessmsg;
                    150: 		}
                    151: 		$result.=$msg.'<br />';
                    152: 	    } elsif ($target eq 'tex') {
                    153: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    154: 		if ($status eq 'UNAVAILABLE') {
                    155: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    156: 		} else {
                    157: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    158: 		}
1.4       albertel  159: 	    } elsif ($target eq 'grade') {
                    160: 		if ($status eq 'NEEDS_CHECKIN') {
                    161: 		    if (&proctor_check_auth($slot)) {
                    162: 			#FIXME immeadiatly add this to the grading queue
                    163:                         #      with slot->{'endtime'} for when grading can 
                    164:                         #      begin on this resource
                    165:  		    }
                    166: 		}
1.1       albertel  167: 	    }
                    168: 	} elsif ($target eq 'web') {
                    169: 	    my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    170: 	    $result.="$head_tag_start<title>$name</title></head>
                    171:               $body_tag_start \n $form_tag_start".	
                    172: 	      '<input type="hidden" name="submitted" value="yes" />';
                    173: 	    # if we are viewing someone else preserve that info
1.11      albertel  174: 	    if (defined $env{'form.grade_symb'}) {
1.1       albertel  175: 		foreach my $field ('symb','courseid','domain','username') {
                    176: 		    $result .= '<input type="hidden" name="grade_'.$field.
1.11      albertel  177: 			'" value="'.$env{"form.grade_$field"}.'" />'."\n";
1.1       albertel  178: 		}
                    179: 	    }
                    180: 	}
1.13      albertel  181:     } elsif ($target eq 'webgrade') {
1.15      albertel  182: 	$result.=$head_tag_start.$body_tag_start.$form_tag_start;
1.16    ! albertel  183: 	$result.=
        !           184: 	    '<input type="hidden" name="grade_target" value="webgrade" />';
1.14      albertel  185: 	$result.=&show_queue();
1.15      albertel  186: 	my $todo=&get_from_queue();
                    187: 	if ($todo) {
1.16    ! albertel  188: 	    &setup_env_for_other_user($todo,$safeeval);
1.15      albertel  189: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
1.16    ! albertel  190: 	    $result.="\n".'<table><tr><td>Found '.
        !           191: 		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
1.15      albertel  192: 	    $result.='<input type="hidden" name="gradingkey" value="'.
1.16    ! albertel  193: 		&Apache::lonnet::escape($todo).'" />';
1.15      albertel  194: 	    $Apache::bridgetask::queue_key=$todo;
1.16    ! albertel  195: 	    &Apache::structuretags::initialize_storage();
        !           196: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.15      albertel  197: 	} else {
                    198: 	    $result.="\n".
                    199: 		'<table><tr><td>No user to be graded.</td></tr></table>';
                    200: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    201: 	}
                    202: 	
1.1       albertel  203:     } else {
                    204: 	# page_start returned a starting result, delete it if we don't need it
                    205: 	$result = '';
                    206:     }
                    207:     return $result;
                    208: }
                    209: 
                    210: sub end_Task {
                    211:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    212:     my $result='';
                    213:     my $status=$Apache::inputtags::status['-1'];
                    214:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel  215: 	$target eq 'tex') {
1.1       albertel  216: 	if (
1.11      albertel  217: 	    (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1       albertel  218: 	    ($target eq 'answer') || ($target eq 'tex')
                    219: 	   ) {
                    220: 	    if ($target eq 'web') {
1.9       albertel  221: 		if ($status eq 'CAN_ANSWER') {
1.15      albertel  222: 		    $result.="\n".'<table border="1">'.
1.9       albertel  223: 			&Apache::inputtags::file_selector('0',"bridgetask","*",
                    224: 							  'portfolioonly').
                    225: 							  "</table>";
                    226: 		    $result.=&Apache::inputtags::gradestatus('0');
                    227: 		}
1.13      albertel  228: 	    } 
                    229: 	    if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  230: 		$result.=&Apache::lonxml::xmlend().'</html>';
                    231: 	    }
                    232: 	}
                    233: 	if ($target eq 'grade') {
1.12      albertel  234: 	    my $award='SUBMITTED';
1.14      albertel  235: 	    &Apache::essayresponse::file_submission('0','bridgetask','portfiles',\$award);
                    236: 	    if ($award eq 'SUBMITTED' &&
                    237: 		$Apache::lonhomework::results{"resource.0.bridgetask.portfiles"}) {
1.10      albertel  238: 		$Apache::lonhomework::results{"resource.0.tries"}=
                    239: 		    1+$Apache::lonhomework::history{"resource.0.tries"};
                    240: 	    }
1.14      albertel  241: 	    $Apache::lonhomework::results{"resource.0.award"}=$award;
1.4       albertel  242: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    243: 	    &Apache::structuretags::finalize_storage();
1.14      albertel  244: 	    if ($award eq 'SUBMITTED') {
                    245: 		&add_to_queue();
                    246: 	    }
1.1       albertel  247: 	}
1.15      albertel  248:     } elsif ($target eq 'webgrade') {
                    249: 	$result.="\n<hr />";
                    250: 	$result.='<input type="submit" name="next" value="'.
                    251: 	    &mt('Save & Next').'" /> ';
                    252: 	$result.='<input type="submit" name="end" value="'.
                    253: 	    &mt('Save & Stop Grading').'" /> ';
                    254: 	$result.='<input type="submit" name="end" value="'.
                    255: 	    &mt('Throw Away & Stop Grading').'" /> ';
                    256: 	$result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1       albertel  257:     } elsif ($target eq 'meta') {
1.2       albertel  258: 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1       albertel  259: 	#$result.=&Apache::response::meta_part_order();
                    260: 	#$result.=&Apache::response::meta_response_order();
                    261:     }
1.4       albertel  262:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel  263:     return $result;
                    264: }
                    265: 
1.16    ! albertel  266: sub setup_env_for_other_user {
        !           267:     my ($queue_key,$safeeval)=@_;
        !           268:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
        !           269:     $env{'form.grade_symb'}=$symb;
        !           270:     $env{'form.grade_domain'}=$udom;
        !           271:     $env{'form.grade_username'}=$uname;
        !           272:     $env{'form.grade_courseid'}=$env{'request.course.id'};
        !           273:     &Apache::lonxml::initialize_rndseed($safeeval);
        !           274: }
        !           275: 
1.14      albertel  276: sub add_to_queue {
                    277:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    278:     my $cnum=$env{'course.'.$cid.'.num'};
                    279:     my $cdom=$env{'course.'.$cid.'.domain'};
                    280:     my %data;
                    281:     $data{"$symb\0queue\0$uname\@$udom"}=[$Apache::inputtags::slot_name];
                    282:     &Apache::lonnet::put('gradingqueue',\%data,$cdom,$cnum);
                    283: }
                    284: 
                    285: sub show_queue {
                    286:     my $result;
                    287:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    288:     my $cnum=$env{'course.'.$cid.'.num'};
                    289:     my $cdom=$env{'course.'.$cid.'.domain'};
1.16    ! albertel  290:     my $regexp="^$symb\0";
1.14      albertel  291:     my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
1.16    ! albertel  292:     $result.="\n<h3>Current Queue</h3><table><tr><th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14      albertel  293:     foreach my $key (sort(keys(%queue))) {
1.16    ! albertel  294: 	if ($key=~/locked$/) {
        !           295: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
        !           296: 	    my $title=&Apache::lonnet::gettitle($symb);
        !           297: 	    $result.="<tr><td>$title</td><td>$uname</td><td>";
        !           298: 	    $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
        !           299: 	} elsif ($key=~/timestamp$/) {
        !           300: 	    my ($symb,undef) = split("\0",$key);
        !           301: 	    my $title=&Apache::lonnet::gettitle($symb);
        !           302: 	    $result.="<tr><td>$title</td><td></td><td>";
        !           303: 	    $result.='<td>last queue modification time</td><td>'.
        !           304: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
        !           305: 	} else {
        !           306: 	    my ($symb,$uname,$udom) = &decode_queue_key($key);
        !           307: 	    my $title=&Apache::lonnet::gettitle($symb);
        !           308: 	    $result.="<tr><td>$title</td><td>$uname</td><td>";
        !           309: 	    my $slot=$queue{$key}->[0];
        !           310: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
        !           311: 	    $result.='<td>queue entry</td><td>End time: '.&Apache::lonlocal::locallocaltime($slot_data{'endtime'})."</td></tr>";
        !           312: 	}
1.14      albertel  313:     }
1.15      albertel  314:     $result.="</table><hr />\n";
1.14      albertel  315:     return $result;
                    316: }
                    317: 
                    318: sub decode_queue_key {
                    319:     my ($key)=@_;
                    320:     my ($symb,undef,$user) = split("\0",$key);
                    321:     my ($uname,$udom) = split('@',$user);
                    322:     return ($symb,$uname,$udom);
                    323: }
                    324: 
                    325: sub queue_key_locked {
1.15      albertel  326:     my ($key,$cdom,$cnum)=@_;
1.14      albertel  327:     my ($key_locked,$value)=
                    328: 	&Apache::lonnet::get('gradingqueue',["$key\0locked"],$cdom,$cnum);
                    329:     if ($key_locked eq "$key\0locked") {
                    330: 	return $value;
                    331:     }
                    332:     return undef;
                    333: }
                    334: 
                    335: sub pick_from_queue_data {
1.15      albertel  336:     my ($check_section,$queue,$cdom,$cnum)=@_;
1.16    ! albertel  337:     foreach my $key (keys(%$queue)) {
1.14      albertel  338: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
                    339: 	if ($check_section) {
                    340: 	    my $section=&Apache::lonnet::getsection($uname,$udom);
1.15      albertel  341: 	    if ($section ne $check_section) {
                    342: 		&Apache::lonnet::logthis("not my sec");
                    343: 		next;
                    344: 	    }
1.14      albertel  345: 	}
                    346: 	my $slot=$queue->{$key}[0];
                    347: 	my %slot_data=&Apache::lonnet::get_slot($slot);
1.15      albertel  348: 	if ($slot_data{'endtime'} > time) { 
                    349: 	    &Apache::lonnet::logthis("not time");
                    350: 	    next;
                    351: 	}
                    352: 	if (&queue_key_locked($key,$cdom,$cnum)) {
                    353: 	    &Apache::lonnet::logthis("someone already has um.");
                    354: 	    next;
                    355: 	}
1.14      albertel  356: 	return $key;
                    357:     }
                    358:     return undef;
                    359: }
                    360: 
1.15      albertel  361: sub find_mid_grade {
                    362:     my ($symb,$cdom,$cnum)=@_;
1.16    ! albertel  363:     my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15      albertel  364:     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
                    365:     if ($todo) {
                    366: 	my $who=&queue_key_locked($todo,$cdom,$cnum);
                    367: 	if ($who eq $me) { return $todo; }
                    368:     }
                    369:     my $regexp="^$symb\0.*\0locked\$";
                    370:     my %locks=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
                    371:     foreach my $key (keys(%locks)) {
                    372: 	my $who=$locks{$key};
                    373: 	if ($who eq $me) {
                    374: 	    $todo=$key;
                    375: 	    $todo=~s/\0locked$//;
                    376: 	    return $todo;
                    377: 	}
                    378:     }
                    379:     return undef;
                    380: }
                    381: 
1.14      albertel  382: sub get_from_queue {
                    383:     my $result;
                    384:     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
                    385:     my $cnum=$env{'course.'.$cid.'.num'};
                    386:     my $cdom=$env{'course.'.$cid.'.domain'};
                    387:     my $todo;
1.15      albertel  388:     # FIXME need to find if I am 'mid grading'
                    389:     $todo=&find_mid_grade($symb,$cdom,$cnum);
                    390:     &Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo)));
1.16    ! albertel  391:     if ($todo) { return $todo; }
1.14      albertel  392:     while (1) {
                    393: 	my $starttime=time;
                    394: 	&Apache::lonnet::put('gradingqueue',{"$symb\0timestamp"=>$starttime},
                    395: 			     $cdom,$cnum);
1.15      albertel  396: 	&Apache::lonnet::logthis("$starttime");
1.14      albertel  397: 	my $regexp="^$symb\0queue\0";
                    398: 	my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
                    399: 	#make a pass looking for a user in my section
                    400: 	if ($env{'request.course.sec'}) {
1.15      albertel  401: 	    &Apache::lonnet::logthis("sce");
                    402: 	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
                    403: 					$cdom,$cnum);
                    404: 	    &Apache::lonnet::logthis("sce $todo");
1.14      albertel  405: 	}
                    406: 	# no one in our section so look for any user that is ready for grading
                    407: 	if (!$todo) {
1.15      albertel  408: 	    &Apache::lonnet::logthis("no sce");
                    409: 	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
                    410: 					$cdom,$cnum);
                    411: 	    &Apache::lonnet::logthis("no sce $todo");
1.14      albertel  412: 	}
                    413: 	# no user to grade 
                    414: 	if (!$todo) { last; }
1.15      albertel  415: 	&Apache::lonnet::logthis("got $todo");
1.14      albertel  416: 	# otherwise found someone so lets try to lock them
                    417: 	my $success=&Apache::lonnet::newput('gradingqueue',
                    418: 					    {"$todo\0locked"=>
                    419: 						 $env{'user.name'}.'@'.$env{'user.domain'}},
                    420: 					   $cdom,$cnum);
                    421: 	# someone else already picked them
1.15      albertel  422: 	&Apache::lonnet::logthis("success $todo");
1.14      albertel  423: 	if ($success ne 'ok') { next; }
                    424: 	my (undef,$endtime)=
                    425: 	    &Apache::lonnet::get('gradingqueue',["$symb\0timestamp"],
                    426: 				 $cdom,$cnum);
1.15      albertel  427: 	&Apache::lonnet::logthis("emd  $endtime");
1.14      albertel  428: 	# someone else already modified the queue, 
                    429: 	# perhaps our picked user wass already fully graded between
                    430: 	# when we picked him and when we locked his record? so lets
                    431: 	# double check.
                    432: 	if ($endtime != $starttime) {
                    433: 	    my ($key,$value)=
                    434: 		&Apache::lonnet::get('gradingqueue',["$todo"],
                    435: 				     $cdom,$cnum);
1.15      albertel  436: 	    &Apache::lonnet::logthis("check  $key .. $value");
1.14      albertel  437: 	    if ($key eq $todo && ref($value)) {
                    438: 	    } else {
                    439: 		&Apache::lonnet::del('gradingqueue',["$todo\0locked"],
                    440: 				     $cdom,$cnum);
1.15      albertel  441: 		&Apache::lonnet::logthis("del");
1.14      albertel  442: 		next;
                    443: 	    }
                    444: 	}
1.15      albertel  445: 	&Apache::lonnet::logthis("last $todo");
1.14      albertel  446: 	last;
                    447:     }
                    448:     return $todo;
                    449: }
                    450: 
1.1       albertel  451: sub start_ClosingParagraph {
                    452:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    453:     my $result;
                    454:     if ($target eq 'web') {
1.13      albertel  455:     } elsif ($target eq 'webgrade') {
                    456: 	&Apache::lonxml::startredirection();
1.1       albertel  457:     }
                    458:     return $result;
                    459: }
                    460: 
                    461: sub end_ClosingParagraph {
                    462:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    463:     my $result;
                    464:     if ($target eq 'web') {
1.13      albertel  465:     } elsif ($target eq 'webgrade') {
                    466: 	&Apache::lonxml::endredirection();
1.1       albertel  467:     }
                    468:     return $result;
                    469: }
                    470: 
                    471: my %dimension;
                    472: sub start_Dimension {
                    473:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    474:     undef(%dimension);
1.9       albertel  475:     my $dim_id=$Apache::lonxml::curdepth;
                    476:     $Apache::bridgetask::dimension=$dim_id;
                    477:     push(@Apache::bridgetask::dimensionlist,$dim_id);
                    478:     undef(@Apache::bridgetask::instance);
1.1       albertel  479:     return '';
                    480: }
                    481: 
1.13      albertel  482: sub get_instance {
                    483:     #FIXME just grabbing the first one for now, need
                    484:     #to randomly pick one until all have been seen
                    485:     #then start repicking
                    486:     &Apache::response::pushrandomnumber();
                    487:     my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
                    488:     return $order[0];
                    489: }
                    490: 
1.1       albertel  491: sub end_Dimension {
                    492:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    493:     my $result;
                    494:     if ($target eq 'web') {
1.13      albertel  495: 	my $instance=&get_instance();
1.9       albertel  496: 	$result=$dimension{'intro'}.$dimension{$instance.'.text'};
1.13      albertel  497:     } elsif ($target eq 'webgrade') {
                    498: 	my $instance=&get_instance();
1.15      albertel  499: 	$result.="\n".'<table>';
1.13      albertel  500: 	foreach my $id (@{$dimension{$instance.'.criterias'}}) {
                    501: 	    $result.='<tr><td>'.
                    502: 		$dimension{$instance.'.criteria.'.$id}.'</td></tr>';
                    503: 	}
                    504: 	$result.='</table>';
1.1       albertel  505:     }
                    506:     return $result;
                    507: }
                    508: 
                    509: sub start_IntroParagraph {
                    510:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    511:     my $result;
1.13      albertel  512:     if ($target eq 'web' || $target eq 'webgrade') {
                    513: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel  514: 	    &Apache::lonxml::startredirection();
                    515: 	}
                    516:     }
                    517:     return $result;
                    518: }
                    519: 
                    520: sub end_IntroParagraph {
                    521:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    522:     my $result;
1.13      albertel  523:     if ($target eq 'web' || $target eq 'webgrade') {
                    524: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel  525: 	    $dimension{'intro'}=&Apache::lonxml::endredirection();
                    526: 	}
                    527:     }
                    528:     return $result;
                    529: }
                    530: 
                    531: sub start_Instance {
                    532:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    533:     push(@{$dimension{'instances'}},$Apache::lonxml::curdepth);
1.9       albertel  534:     push(@Apache::bridgetask::instance,$Apache::lonxml::curdepth);
                    535:     push(@Apache::bridgetask::instancelist,$Apache::lonxml::curdepth);
1.1       albertel  536:     return '';
                    537: }
                    538: 
                    539: sub end_Instance {
                    540:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    541:     return '';
                    542: }
                    543: 
                    544: sub start_InstanceText {
                    545:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13      albertel  546:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  547: 	&Apache::lonxml::startredirection();
                    548:     }
                    549:     return '';
                    550: }
                    551: 
                    552: sub end_InstanceText {
                    553:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel  554:     my $instance_id=$Apache::bridgetask::instance[-1];
1.13      albertel  555:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  556: 	$dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
                    557:     }
                    558:     return '';
                    559: }
                    560: 
                    561: sub start_Criteria {
                    562:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13      albertel  563:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  564: 	&Apache::lonxml::startredirection();
                    565:     }
                    566:     return '';
                    567: }
                    568: 
                    569: sub end_Criteria {
                    570:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel  571:     my $instance_id=$Apache::bridgetask::instance[-1];
1.13      albertel  572:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  573: 	my $criteria=&Apache::lonxml::endredirection();
                    574: 	my $id=$Apache::lonxml::curdepth;
                    575: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
                    576: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
                    577:     }
                    578:     return '';
                    579: }
                    580: 
1.4       albertel  581: sub proctor_validation_screen {
                    582:     my ($slot) = @_;
                    583:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel  584:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11      albertel  585:     $user=$env{'form.proctorname'};
                    586:     if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4       albertel  587:     my $msg;
1.11      albertel  588:     if ($env{'form.proctorpassword'}) {
1.4       albertel  589: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                    590: 	    .'</font></p>';
                    591:     }
                    592:     my $result= (<<ENDCHECKOUT);
                    593: <h2>Proctor Validation</h2>
                    594:     <p>Your room's proctor needs to validate your access to this resource.</p>
                    595:     $msg
1.11      albertel  596: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4       albertel  597: <input type="hidden" name="validate" value="yes" />
                    598: <input type="hidden" name="submitted" value="yes" />
                    599: <table>
                    600:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
                    601:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6       albertel  602:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4       albertel  603: </table>
                    604: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
                    605: Student who should be logged in is:<br />
1.5       albertel  606: <img src="$url" /><br />
1.4       albertel  607: </form>
                    608: ENDCHECKOUT
                    609:     return $result;
                    610: }
                    611: 
1.1       albertel  612: 1;
                    613: __END__

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