File:  [LON-CAPA] / loncom / homework / bridgetask.pm
Revision 1.22: download - view: text, annotated - select for diffs
Tue May 10 20:29:26 2005 UTC (19 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- properly detect state of 'in grading queue' and show info screen
- properly detect state of graded and show criteria and pass/failed status
- grade things correctly

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

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