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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.188   ! albertel    4: # $Id: bridgetask.pm,v 1.185 2006/10/17 15:11:11 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.158     www        41: use lib '/home/httpd/lib/perl/';
                     42: use LONCAPA;
                     43:  
1.9       albertel   44: 
1.1       albertel   45: BEGIN {
1.186     albertel   46:     &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','GraderNote','ClosingParagraph'));
1.1       albertel   47: }
                     48: 
1.169     albertel   49: my %dimension;
1.9       albertel   50: sub initialize_bridgetask {
                     51:     # id of current Dimension, 0 means that no dimension is current 
                     52:     # (inside <Task> only)
1.178     albertel   53:     @Apache::bridgetask::dimension=();
1.9       albertel   54:     # list of all Dimension ids seen
1.168     albertel   55:     %Apache::bridgetask::top_dimensionlist=();
1.9       albertel   56:     # list of all current Instance ids
1.168     albertel   57:     %Apache::bridgetask::instance=();
1.9       albertel   58:     # list of all Instance ids seen in this problem
                     59:     @Apache::bridgetask::instancelist=();
1.15      albertel   60:     # key of queud user data that we are currently grading
                     61:     $Apache::bridgetask::queue_key='';
1.169     albertel   62:     undef(%dimension);
1.9       albertel   63: }
                     64: 
1.4       albertel   65: sub proctor_check_auth {
1.81      albertel   66:     my ($slot_name,$slot,$type)=@_;
1.11      albertel   67:     my $user=$env{'form.proctorname'};
                     68:     my $domain=$env{'form.proctordomain'};
1.4       albertel   69:     
                     70:     my @allowed=split(",",$slot->{'proctor'});
                     71:     foreach my $possible (@allowed) {
1.138     albertel   72: 	my ($puser,$pdom)=(split(':',$possible));
1.4       albertel   73: 	if ($puser eq $user && $pdom eq $domain) {
1.72      albertel   74: 	    my $authenticated=0;
                     75: 	    if ( $slot->{'secret'} =~ /\S/ &&
                     76: 		 $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
                     77: 		$authenticated=1;
                     78: 	    } else {
                     79: 		
                     80: 		my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
                     81: 		if ($authhost ne 'no_host') {
                     82: 		    $authenticated=1;
                     83: 		}
                     84: 	    }
1.150     albertel   85: 	    if ($authenticated) {
1.176     albertel   86: 		&check_in($type,$user,$domain,$slot_name);
1.4       albertel   87: 		return 1;
                     88: 	    }
                     89: 	}
                     90:     }
                     91:     return 0;
                     92: }
                     93: 
1.174     albertel   94: sub check_in {
                     95:     my ($type,$user,$domain,$slot_name) = @_;
                     96:     my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
                     97:     if ( $useslots eq 'map_map') {
                     98: 	&check_in_sequence($user,$domain,$slot_name);
                     99:     } else {
                    100: 	&create_new_version($type,$user,$domain,$slot_name);
                    101:     }
                    102:     return 1;
                    103: }
                    104: 
                    105: sub check_in_sequence {
                    106:     my ($user,$domain,$slot_name) = @_;
                    107:     my $navmap = Apache::lonnavmaps::navmap->new();
1.185     albertel  108:     my ($symb) = &Apache::lonnet::whichuser();
1.174     albertel  109:     my ($map)  = &Apache::lonnet::decode_symb($symb);
1.175     albertel  110:     my @resources = 
                    111: 	$navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
1.174     albertel  112:     my %old_history = %Apache::lonhomework::history;
                    113:     my %old_results = %Apache::lonhomework::results;
                    114: 
                    115:     foreach my $res (@resources) {
                    116: 	&Apache::lonxml::debug("doing ".$res->src);
                    117: 	&Apache::structuretags::initialize_storage($res->symb);
                    118: 	my $type = ($res->is_task()) ? 'Task' : 'problem';
                    119: 	&create_new_version($type,$user,$domain,$slot_name);
                    120: 	&Apache::structuretags::finalize_storage($res->symb);
                    121:     }
                    122:     
                    123:     %Apache::lonhomework::history = %old_history;
                    124:     %Apache::lonhomework::results = %old_results;
                    125: }
                    126: 
1.150     albertel  127: sub create_new_version {
                    128:     my ($type,$user,$domain,$slot_name) = @_;
1.174     albertel  129:     
                    130:     my $id = '0';
1.150     albertel  131:     if ($type eq 'Task') {
                    132: 	# increment version
                    133: 	my $version=
                    134: 	    $Apache::lonhomework::history{'resource.0.version'};
                    135: 	$version++;
1.152     albertel  136: 	&Apache::lonxml::debug("Making version $version");
1.150     albertel  137: 	#clean out all current results
                    138: 	foreach my $key (keys(%Apache::lonhomework::history)) {
                    139: 	    if ($key=~/^resource\.0\./) {
                    140: 		$Apache::lonhomework::results{$key}='';
                    141: 	    }
                    142: 	}
                    143: 	
                    144: 	#setup new version and who did it
1.174     albertel  145:        	$Apache::lonhomework::results{'resource.0.version'}=$version;
                    146: 	$id = "$version.0";
1.178     albertel  147: 	if (!defined($user) || !defined($domain)) {
1.174     albertel  148: 	    $user = $env{'user.name'};
                    149: 	    $domain = $env{'user.domain'};
1.150     albertel  150: 	}
1.174     albertel  151: 	
1.150     albertel  152:     } elsif ($type eq 'problem') {
                    153: 	&Apache::lonxml::debug("authed $slot_name");
1.174     albertel  154:     }
1.181     albertel  155:     if (!defined($user) || !defined($domain)) {
                    156: 	$user = $env{'user.name'};
                    157: 	$domain = $env{'user.domain'};
                    158:     }
                    159: 
                    160:     $Apache::lonhomework::results{"resource.$id.checkedin"}=
                    161: 	$user.':'.$domain;
1.174     albertel  162: 
                    163:     if (defined($slot_name)) {
                    164: 	$Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
                    165: 	    $slot_name;
1.150     albertel  166:     }
                    167: }
                    168: 
1.25      albertel  169: sub get_version {
1.29      albertel  170:     my ($version,$previous);
1.25      albertel  171:     if ($env{'form.previousversion'} && 
1.36      albertel  172: 	$env{'form.previousversion'} ne 'current' &&
1.89      albertel  173: 	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
1.29      albertel  174: 	$version=$env{'form.previousversion'};
                    175: 	$previous=1;
                    176:     } else {
1.150     albertel  177: 	if (defined($Apache::lonhomework::results{'resource.0.version'})) {
                    178: 	    $version=$Apache::lonhomework::results{'resource.0.version'};
                    179: 	} elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
                    180: 	    $version=$Apache::lonhomework::history{'resource.0.version'};
                    181: 	}
1.29      albertel  182: 	$previous=0;
                    183:     }
                    184:     if (wantarray) {
                    185: 	return ($version,$previous);
1.25      albertel  186:     }
1.29      albertel  187:     return $version;
1.25      albertel  188: }
                    189: 
1.8       albertel  190: sub add_previous_version_button {
1.25      albertel  191:     my ($status)=@_;
1.8       albertel  192:     my $result;
1.89      albertel  193:     if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
1.25      albertel  194: 	return '';
                    195:     }
1.89      albertel  196:     if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
1.29      albertel  197: 	$status ne 'NEEDS_CHECKIN') {
1.25      albertel  198: 	return '';
                    199:     }
1.29      albertel  200:     my $version=&get_version();
                    201:     if ($env{'form.previousversion'} ne '' &&
                    202: 	$env{'form.previousversion'} eq $version) {
                    203: 	$result.="<h3>".&mt("Showing previous version [_1]",$version).
                    204: 	    "</h3>\n";
                    205:     }
                    206:     my @to_show;
1.89      albertel  207:     foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
                    208: 	if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
1.29      albertel  209: 	    push(@to_show,$test_version);
                    210: 	}
                    211:     }
                    212:     my $list='<option>'.
                    213: 	join("</option>\n<option>",@to_show).
                    214: 	     "</option>\n";
1.36      albertel  215:     $list.='<option value="current">'.&mt('Current').'</option>';
1.115     albertel  216:     $result.='<form name="getprevious" method="post" action="';
1.29      albertel  217:     my $uri=$env{'request.uri'};
                    218:     if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
                    219:     $result.=$uri.'">'.
                    220: 	&mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
                    221: <option>'.&mt('Pick one').'</option>
                    222: '.$list.'
                    223: </select>')."</form>";
1.8       albertel  224:     return $result;
                    225: }
                    226: 
1.13      albertel  227: sub add_grading_button {
1.185     albertel  228:     my (undef,$cid)=&Apache::lonnet::whichuser();
1.59      albertel  229:     my $cnum=$env{'course.'.$cid.'.num'};
                    230:     my $cdom=$env{'course.'.$cid.'.domain'};
1.144     albertel  231:     my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
                    232: 
1.59      albertel  233:     my $size=5;
                    234:     if (scalar(keys(%sections)) < 3) {
                    235: 	$size=scalar(keys(%sections))+2;
                    236:     }
1.122     albertel  237:     my $sec_select = '<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
1.59      albertel  238:     $sec_select .= "<option value='all' selected='selected'>all</option>\n";
                    239:     foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
1.122     albertel  240: 	$sec_select .= "<option value=\"$sec\">$sec</option>\n";
1.59      albertel  241:     }
                    242:     $sec_select .= "<option value='none'>none</option></select>\n";
                    243:     
1.29      albertel  244:     my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13      albertel  245: 	&mt("Get a submission to grade").'" />';
                    246:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.40      albertel  247:     if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.34      albertel  248: 	my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.106     albertel  249: 	$result.='<table><tr>';
                    250: 	$result.='<td rowspan="4">Specify a section: </td><td rowspan="4">'.$sec_select.'</td>';
                    251: 	$result.='<td>'.' <input type="submit" name="reviewagrading" value="'.
                    252: 	    &mt("Select an entry from the grading queue:").'" /> ';
1.34      albertel  253: 
1.107     albertel  254: 	$result.= &mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).' </td></tr>'."\n";
1.34      albertel  255: 
                    256: 	($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
1.106     albertel  257: 	$result.='<tr><td>'.
                    258: 	    ' <input type="submit" name="reviewasubmission" value="'.
                    259: 	    &mt("Select an entry from the review queue:").'" /> ';
                    260: 	$result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
                    261: 		     $entries,$ready,$locks).'</td></tr>'."\n";
                    262: 	$result.='<tr><td> <input type="submit" name="regradeasubmission" value="'.
                    263: 	    &mt("List of user's grade status").'" /> </td></tr></table>'."\n";
1.105     albertel  264: 	$result.='<p> <input type="submit" name="regradeaspecificsubmission" value="'.
1.106     albertel  265: 	    &mt("Regrade specific user:").'" />'."\n";
1.105     albertel  266: 	$result.='<input type="text" size="12" name="gradinguser" />';
                    267: 	$result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
                    268: 						     'gradingdomain');
                    269: 	$result.=' '.
                    270: 	    &Apache::loncommon::selectstudent_link('gradesubmission',
                    271: 						   'gradinguser',
                    272: 						   'gradingdomain');
                    273: 	$result.=&Apache::loncommon::studentbrowser_javascript();
1.123     albertel  274: 	$result.= '</p>';
1.144     albertel  275:     }
1.13      albertel  276:     return $result;
                    277: }
                    278: 
1.22      albertel  279: sub add_request_another_attempt_button {
1.38      albertel  280:     my ($text)=@_;
                    281:     if (!$text) { $text="Request another attempt"; }
1.25      albertel  282:     my $result;
1.36      albertel  283:     my $symb=&Apache::lonnet::symbread();
1.149     albertel  284:     # not a slot access based resource
                    285:     my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
                    286:     if ($useslots =~ /^\s*no\s*$/i) {
                    287: 	return '';
                    288:     }
                    289: 
1.37      albertel  290:     my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38      albertel  291:     my $action='get_reservation';
1.37      albertel  292:     if ($slot_name) {
1.38      albertel  293: 	$text="Change reservation.";
                    294: 	$action='change_reservation';
1.37      albertel  295: 	my $description=&Apache::slotrequest::get_description($slot_name,
                    296: 							      $slot);
                    297: 	$result.=(<<STUFF);
                    298: <p> Will be next available: $description </p>
                    299: STUFF
                    300:     }
1.38      albertel  301:     
                    302:     if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
1.158     www       303:     $symb=&escape($symb);
1.115     albertel  304:     $result.='<form method="post" action="/adm/slotrequest">'.
1.38      albertel  305: 	'<input type="hidden" name="symb" value="'.$symb.'" />'.
                    306: 	'<input type="hidden" name="command" value="'.$action.'" />'.
                    307: 	'<input type="submit" name="requestattempt" value="'.
                    308: 	&mt($text).'" />'.
                    309: 	'</form>';
1.25      albertel  310:     return $result;
1.22      albertel  311: }
                    312: 
1.30      albertel  313: sub preserve_grade_info {
                    314:     my $result;
                    315:     # if we are viewing someone else preserve that info
                    316:     if (defined $env{'form.grade_symb'}) {
                    317: 	foreach my $field ('symb','courseid','domain','username') {
                    318: 	    $result .= '<input type="hidden" name="grade_'.$field.
                    319: 		'" value="'.$env{"form.grade_$field"}.'" />'."\n";
                    320: 	}
                    321:     }
                    322:     return $result;
                    323: }
                    324: 
1.53      albertel  325: sub style {
1.125     albertel  326:     my ($target) = @_;
                    327:     if ($target eq 'web'
                    328: 	|| $target eq 'webgrade') {
                    329: 	return (<<STYLE);
1.126     albertel  330: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task.css" />
1.53      albertel  331: STYLE
1.125     albertel  332:     }
                    333:     return;
1.53      albertel  334: }
                    335: 
1.54      albertel  336: sub show_task {
                    337:     my ($status,$previous)=@_;
                    338:     if (!$previous && (
                    339: 		       ( $status eq 'CLOSED' ) ||
                    340: 		       ( $status eq 'BANNED') ||
                    341: 		       ( $status eq 'UNAVAILABLE') ||
                    342: 		       ( $status eq 'NOT_IN_A_SLOT') ||
                    343: 		       ( $status eq 'NEEDS_CHECKIN') ||
                    344: 		       ( $status eq 'WAITING_FOR_GRADE') ||
1.150     albertel  345: 		       ( $status eq 'INVALID_ACCESS') ||
                    346: 		       ( &get_version() eq ''))) {
1.54      albertel  347: 	return 0;
                    348:     }
1.64      albertel  349:     if ($env{'form.donescreen'}) { return 0; }
1.54      albertel  350:     return 1;
                    351: }
                    352: 
1.173     albertel  353: my @delay;
                    354: sub nest { 
                    355:     if (@delay) {
                    356: 	return $delay[-1];
                    357:     } else {
                    358: 	return;
                    359:     }
                    360: }
                    361: 
                    362: sub nested_parse {
                    363:     my ($str,$env,$args) = @_;
                    364:     my @old_env = @Apache::scripttag::parser_env;
                    365:     @Apache::scripttag::parser_env = @$env;
                    366:     if (exists($args->{'set_dim_id'})) {
                    367: 	&enable_dimension_parsing($args->{'set_dim_id'});
                    368:     }
                    369:     push(@delay,(($args->{'delayed_dim_results'})? 1 : 0));
                    370:     my $result = &Apache::scripttag::xmlparse($$str);
                    371:     pop(@delay);
                    372:     if (exists($args->{'set_dim_id'})) {
                    373: 	&disable_dimension_parsing();
                    374:     }
                    375:     @Apache::scripttag::parser_env = @old_env;
                    376:     if ($args->{'delayed_dim_results'}) {
                    377: 	my $dim = &get_dim_id();
1.180     albertel  378: 	&Apache::lonxml::debug(" tossing out $result ");
                    379: 	&Apache::lonxml::debug(" usining out $dim 's  ". $dimension{$dim}{'result'});
1.173     albertel  380: 	return $dimension{$dim}{'result'};
                    381:     }
                    382:     return $result;
                    383: }
                    384: 
1.54      albertel  385: sub internal_location {
                    386:     my ($id)=@_;
                    387:     return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
                    388: }
                    389: 
1.60      albertel  390: sub submission_time_stamp {
1.185     albertel  391:     my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.60      albertel  392:     my $submissiontime;
1.89      albertel  393:     my $version=$Apache::lonhomework::history{'resource.0.version'};
1.60      albertel  394:     for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
1.183     albertel  395: 	if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})
                    396: 	    && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) {
1.60      albertel  397: 	    $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
1.182     albertel  398: 	    last;
1.60      albertel  399: 	}
                    400:     }
                    401:     my $result;
                    402:     if ($submissiontime) {
1.89      albertel  403: 	my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
1.60      albertel  404: 	my %slot=&Apache::lonnet::get_slot($slot_name);
                    405: 	my $diff = $slot{'endtime'} - $submissiontime;
1.71      albertel  406: 	my ($color,$when)=('#FF6666','after');
                    407: 	if ($diff > 0) { ($color,$when)=('#336600','before'); }
1.60      albertel  408: 	my $info;
1.182     albertel  409: 	$diff = abs($diff);
1.60      albertel  410: 	if ($diff%60) { $info=($diff%60).' seconds'; }
                    411: 	$diff=int($diff/60);
                    412: 	if ($diff%60) { $info=($diff%60).' minutes '.$info; }
                    413: 	$diff=int($diff/60);
                    414: 	if ($diff) {    $info=$diff.' hours '.$info; }
                    415: 	$result='<p><font color="'.$color.'">'.
1.182     albertel  416: 	    &mt('Student submitted [_1] [_2] the deadline. '.
                    417: 		'(Submission was at [_3], end of period was [_4].)',
                    418: 		$info,$when,
                    419: 		&Apache::lonlocal::locallocaltime($submissiontime),
                    420: 		&Apache::lonlocal::locallocaltime($slot{'endtime'})).
1.60      albertel  421: 		'</font></p>';
                    422:     }
                    423:     return $result;
                    424: }
                    425: 
1.119     albertel  426: sub file_list {
                    427:     my ($files,$uname,$udom) = @_;
                    428:     if (!defined($uname) || !defined($udom)) {
1.185     albertel  429: 	(undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
1.119     albertel  430:     }
1.70      albertel  431:     my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.119     albertel  432: 
1.120     albertel  433:     my $file_list="<ul class=\"LC_GRADING_handininfo\">\n";
1.119     albertel  434:     foreach my $partial_file (split(',',$files)) {
1.70      albertel  435: 	my $file=$file_url.$partial_file;
                    436: 	$file=~s|/+|/|g;
                    437: 	&Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.161     albertel  438: 	$file_list.='<li><span style="white-space: nowrap;"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
                    439: 	    &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
                    440: 	    '</a></span></li>'."\n";
1.70      albertel  441:     }
                    442:     $file_list.="</ul>\n";
1.119     albertel  443:     return $file_list;
                    444: }
                    445: 
1.163     albertel  446: sub grade_mode {
                    447:     if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
                    448: 	return 'regrade';
                    449:     }
                    450:     return 'queue_grade';
                    451: }
                    452: 
1.119     albertel  453: sub webgrade_standard_info {
                    454:     my ($version)=&get_version();
                    455: 
                    456:     my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
1.70      albertel  457: 
1.163     albertel  458:     my %lt=('done'   => 'Next Item',
                    459: 	    'stop'   => 'Quit Grading',
                    460: 	    'fail'   => 'Fail Rest',
                    461: 	    'cancel' => 'Cancel',
                    462: 	    );
1.170     albertel  463:     %lt=&Apache::lonlocal::texthash(%lt);
1.163     albertel  464: 
1.70      albertel  465:     my $result=<<INFO;
1.120     albertel  466:   <div class="LC_GRADING_maincontrols">
1.163     albertel  467: INFO
                    468: 
                    469:     if (&grade_mode() eq 'regrade') {
                    470: 	$result.=<<INFO;
                    471:     <input type="submit" name="cancel" value="$lt{'cancel'}" />
                    472: INFO
                    473:     }
                    474: 
                    475:     $result.=<<INFO;
1.111     albertel  476:     <input type="submit" name="next" value="$lt{'done'}" />
                    477:     <input type="submit" name="stop" value="$lt{'stop'}" />
1.143     albertel  478:     <input type="button" name="fail" value="$lt{'fail'}" 
                    479:            onclick="javascript:onFailRest()" />
1.111     albertel  480:   </div>
1.70      albertel  481:   $file_list
                    482: INFO
                    483:     return $result;
                    484: }
                    485: 
1.166     albertel  486: sub done_screen {
                    487:     my ($version) = @_;
                    488:     my $title=&Apache::lonnet::gettitle();
                    489:     my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
1.185     albertel  490:     my (undef,undef,$domain,$user)= &Apache::lonnet::whichuser();
1.166     albertel  491:     my $files = '<ul>';
1.167     albertel  492:     my $msg;
1.166     albertel  493:     foreach my $file (@files) {
                    494: 	my $url="/uploaded/$domain/$user/portfolio$file";
                    495: 	if (! &Apache::lonnet::stat_file($url)) {
                    496: 	    $file = &mt('<span class="LC_error"> Nonexistent file:</span> '.
                    497: 			'<span class="LC_filename">[_1]</span>',$file);
1.167     albertel  498: 	    $msg .= "<p>Submitted non-existant file $file</p>\n";
1.166     albertel  499: 	} else {
                    500: 	    $file = '<span class="LC_filename">'.$file.'</span>';
1.167     albertel  501: 	    $msg .= "<p>Submitted file $file</p>\n";
1.166     albertel  502: 	}
                    503: 	$files .= '<li>'.$file.'</li>';
                    504:     }
                    505:     $files.='</ul>';
1.167     albertel  506:     my $subject = "Submission message for $title";
                    507:     my ($message_status,$comment_status);
                    508:     my $setting = $env{'course.'.$env{'request.course.id'}.'.task_messages'};
                    509:     $setting =~ s/^\s*(\S*)\s*$/$1/;
                    510:     $setting = lc($setting);
                    511:     if ($setting eq 'only_student'
                    512: 	|| $setting eq 'student_and_user_notes_screen') {
                    513: 	$message_status =
                    514: 	    &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
                    515: 	$message_status = '<p>'.&mt('Message sent to user: [_1]',
                    516: 				    $message_status).' </p>';
                    517:     }
                    518:     if ($setting eq 'student_and_user_notes_screen') {
                    519: 	$comment_status = 
                    520: 	    &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
                    521: 						      $msg,$user,$domain);
                    522: 	$comment_status = '<p>'.&mt('Message sent to instructor: [_1]',
                    523: 				    $comment_status).' </p>';
                    524:     }
1.166     albertel  525:     return <<DONESCREEN;
                    526: <h2>$title</h2>
                    527: <p> Files submitted: $files </p>
                    528: <p> You are now done with this Bridge Task </p>
                    529: <hr />
                    530: <p> <a href="/adm/logout">Logout</a> </p>
                    531: <p> <a href="/adm/roles">Change to a different course</a> </p>
1.167     albertel  532: $message_status
                    533: $comment_status
1.166     albertel  534: DONESCREEN
                    535: 
                    536: }
                    537: 
1.1       albertel  538: sub start_Task {
1.87      albertel  539:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1       albertel  540: 
1.4       albertel  541:     my ($status,$accessmsg,$slot);
1.179     albertel  542:     &Apache::structuretags::init_problem_globals('Task');
1.16      albertel  543:     if ($target ne 'webgrade') {
                    544: 	&Apache::structuretags::initialize_storage();
                    545: 	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.74      albertel  546: 	if ($env{'request.state'} eq 'construct') {
                    547: 	    &Apache::structuretags::setup_rndseed($safeeval);
                    548: 	}
1.16      albertel  549:     } 
                    550: 
1.4       albertel  551:     $Apache::lonhomework::parsing_a_task=1;
1.141     albertel  552: 
                    553:     my $name;
                    554:     if ($target eq 'web' || $target eq 'webgrade') {
                    555: 	$name = &Apache::structuretags::get_resource_name($parstack,$safeeval);
                    556:     }
                    557: 
1.145     albertel  558:     my ($result,$form_tag_start);
                    559:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
                    560: 	|| $target eq 'edit') {
                    561: 	($result,$form_tag_start) =
                    562: 	    &Apache::structuretags::page_start($target,$token,$tagstack,
                    563: 					       $parstack,$parser,$safeeval,
1.146     albertel  564: 					       $name,&style($target));
1.145     albertel  565: 	$result .= '<div class="LC_task">'."\n";
                    566:     }
1.123     albertel  567: 
1.74      albertel  568:     if ($target eq 'web' && $env{'request.state'} ne 'construct') {
1.147     albertel  569: 	if ($Apache::lonhomework::queuegrade
                    570: 	    || $Apache::lonhomework::modifygrades) {
1.141     albertel  571: 	    $result.='<form name="gradesubmission" method="post" action="';
1.13      albertel  572: 	    my $uri=$env{'request.uri'};
                    573: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
1.141     albertel  574: 	    $result.=$uri.'">'.&add_grading_button()."</form>";
1.38      albertel  575: 	    my $symb=&Apache::lonnet::symbread();
1.40      albertel  576: 	    if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.141     albertel  577: 		$result.='<form method="post" name="slotrequest" action="/adm/slotrequest">'.
1.40      albertel  578: 		    '<input type="hidden" name="symb" value="'.$symb.'" />'.
                    579: 		    '<input type="hidden" name="command" value="showslots" />'.
                    580: 		    '<input type="submit" name="requestattempt" value="'.
                    581: 		    &mt('Show Slot list').'" />'.
                    582: 		    '</form>';
1.108     albertel  583: 		my $target_id = 
                    584: 		    &Apache::lonstathelpers::make_target_id({symb => $symb,
                    585: 							     part => '0'});
1.141     albertel  586: 		$result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
1.108     albertel  587: 		    '<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
                    588: 		    '<input type="hidden" name="reportSelected" value="grading_analysis" />'.
                    589: 		    '<input type="submit" name="grading" value="'.
                    590: 		    &mt('Show Grading Status').'" />'.
                    591: 		    '</form>';
1.40      albertel  592: 	    }
1.13      albertel  593: 	}
1.8       albertel  594:     }
1.74      albertel  595:     if ($target eq 'web' && $env{'request.state'} eq 'construct') {
                    596: 	$form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
                    597:     }
1.163     albertel  598:     if ($target eq 'web' 
                    599: 	|| ($target eq 'grade' && !$env{'form.webgrade'}) 
                    600: 	|| $target eq 'answer' 
                    601: 	|| $target eq 'tex') {
1.29      albertel  602: 	my ($version,$previous)=&get_version();
1.14      albertel  603: 	($status,$accessmsg,my $slot_name,$slot) = 
1.81      albertel  604: 	    &Apache::lonhomework::check_slot_access('0','Task');
1.152     albertel  605: 	if ($status eq 'CAN_ANSWER' && $version eq '') {
1.177     albertel  606: 	    # CAN_ANSWER mode, and no current version, unproctored access
1.174     albertel  607: 	    # thus self-checkedin
1.177     albertel  608: 	    &check_in('Task',undef,undef,$slot_name);
1.152     albertel  609: 	    &add_to_queue('gradingqueue',{'type' => 'Task',
                    610: 					  'time' => time,
                    611: 					  'slot' => $slot_name});
1.150     albertel  612: 	    ($version,$previous)=&get_version();
                    613: 	}
                    614: 
1.9       albertel  615: 	push(@Apache::inputtags::status,$status);
1.14      albertel  616: 	$Apache::inputtags::slot_name=$slot_name;
1.1       albertel  617: 	my $expression='$external::datestatus="'.$status.'";';
1.89      albertel  618: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
1.1       albertel  619: 	&Apache::run::run($expression,$safeeval);
                    620: 	&Apache::lonxml::debug("Got $status");
1.141     albertel  621: 	$result.=&add_previous_version_button($status);
1.54      albertel  622: 	if (!&show_task($status,$previous)) {
1.87      albertel  623: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.1       albertel  624: 	    if ( $target eq "web" ) {
1.74      albertel  625: 		if ($env{'request.state'} eq 'construct') {
                    626: 		    $result.=$form_tag_start;
                    627: 		}
1.4       albertel  628: 		my $msg;
1.1       albertel  629: 		if ($status eq 'UNAVAILABLE') {
                    630: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3       albertel  631: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
                    632: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.38      albertel  633: 		    $msg.=&add_request_another_attempt_button("Sign up for time to work.");
1.4       albertel  634: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    635: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    636: 			'</h1>'.&proctor_validation_screen($slot);
1.22      albertel  637: 		} elsif ($status eq 'WAITING_FOR_GRADE') {
                    638: 		    $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.64      albertel  639: 		} elsif ($env{'form.donescreen'}) {
1.167     albertel  640: 		    $result .= &done_screen($version);
1.1       albertel  641: 		} elsif ($status ne 'NOT_YET_VIEWED') {
                    642: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
                    643: 		}
                    644: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
                    645: 		    $msg.='The problem '.$accessmsg;
                    646: 		}
                    647: 		$result.=$msg.'<br />';
                    648: 	    } elsif ($target eq 'tex') {
                    649: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    650: 		if ($status eq 'UNAVAILABLE') {
                    651: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
                    652: 		} else {
                    653: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
                    654: 		}
1.22      albertel  655: 	    } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4       albertel  656: 		if ($status eq 'NEEDS_CHECKIN') {
1.83      albertel  657: 		    if(&proctor_check_auth($slot_name,$slot,'Task')
                    658: 		       && defined($Apache::inputtags::slot_name)) {
1.148     albertel  659: 			my $result=
                    660: 			    &add_to_queue('gradingqueue',
1.152     albertel  661: 					  {'type' => 'Task',
1.148     albertel  662: 					   'time' => time,
                    663: 					   'slot' => 
                    664: 					       $Apache::inputtags::slot_name});
1.77      albertel  665: 			&Apache::lonxml::debug("add_to_queue said $result");
                    666: 		    }
1.4       albertel  667: 		}
1.1       albertel  668: 	    }
                    669: 	} elsif ($target eq 'web') {
1.141     albertel  670: 
1.57      albertel  671: 	    $result.=&preserve_grade_info();
                    672: 	    $result.=&internal_location();
1.36      albertel  673: 	    $result.=$form_tag_start.
                    674: 		'<input type="hidden" name="submitted" value="yes" />';
1.54      albertel  675: 	    &Apache::lonxml::startredirection();
1.1       albertel  676: 	}
1.21      albertel  677:     } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
                    678: 	      $target eq 'webgrade') {
1.32      albertel  679: 	my $webgrade='yes';
1.21      albertel  680: 	if ($target eq 'webgrade') {
1.141     albertel  681: 	    $result.= "\n".'<div class="LC_GRADING_task">'."\n".
1.124     albertel  682: 		'<script type="text/javascript" 
1.126     albertel  683:                          src="/res/adm/includes/task_grading.js"></script>';
1.49      albertel  684: 	    #$result.='<br />Review'.&show_queue('reviewqueue');
                    685: 	    #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30      albertel  686: 	}
1.33      albertel  687: 	# FIXME Blast! still need to reorg this, need to reshow the
                    688:         #       queue being reviewed once done with the grade pass...
                    689:         #       Hrrm, vaildation pass should perhaps say 'not_locked'
                    690:         #       perhaps do a search if there is a key that is mine and if
                    691:         #       there isn't reshow the queue....
1.105     albertel  692: 	my ($todo,$status_code,$msg)=&get_key_todo($target);
1.33      albertel  693: 
                    694: 	if ($todo) {
                    695: 	    &setup_env_for_other_user($todo,$safeeval);
                    696: 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
                    697: 	    $result.="\n".'<table><tr><td>Found '.
                    698: 		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
                    699: 	    $form_tag_start.=
                    700: 		'<input type="hidden" name="gradingkey" value="'.
1.158     www       701: 		&escape($todo).'" />';
1.33      albertel  702: 	    $Apache::bridgetask::queue_key=$todo;
                    703: 	    &Apache::structuretags::initialize_storage();
                    704: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.110     albertel  705: 	    if ($target eq 'webgrade' && $status_code eq 'selected') {
                    706: 		$form_tag_start.=
                    707: 		    '<input type="hidden" name="queuemode" value="selected" />';
1.33      albertel  708: 	    }
1.15      albertel  709: 	} else {
1.33      albertel  710: 	    if ($target eq 'webgrade') {
                    711: 		$result.="\n";
1.81      albertel  712: 		my $back='<p><a href="/adm/flip?postdata=return:">'.
                    713: 		    &mt('Return to resource').'</a></p>';
1.33      albertel  714: 		if      ($status_code eq 'stop') {
1.81      albertel  715: 		    $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
1.163     albertel  716: 		} elsif ($status_code eq 'cancel') {
                    717: 		    $result.='<b>'.&mt("Cancelled grading.").'</b>'.$back;
1.164     albertel  718: 		} elsif ($status_code eq 'never_versioned') {
                    719: 		    $result.='<b>'.
                    720: 			&mt("Requested user has never accessed the task.").
                    721: 			'</b>'.$back;
1.165     albertel  722: 		} elsif ($status_code =~ /still_open:(.*)/) {
                    723: 		    my $date = &Apache::lonlocal::locallocaltime($1);
                    724: 		    $result.='<b>'.
                    725: 			&mt("Task is still open, will close at [_1].",$date).
                    726: 			'</b>'.$back;
1.33      albertel  727: 		} elsif ($status_code eq 'lock_failed') {
1.105     albertel  728: 		    $result.='<b>'.&mt("Failed to lock the requested record.")
1.81      albertel  729: 			.'</b>'.$back;
1.33      albertel  730: 		} elsif ($status_code eq 'unlock') {
1.81      albertel  731: 		    $result.='<b>'.&mt("Unlocked the requested record.")
                    732: 			.'</b>'.$back;
1.33      albertel  733: 		    $result.=&show_queue($env{'form.queue'},1);
                    734: 		} elsif ($status_code eq 'show_list') {
                    735: 		    $result.=&show_queue($env{'form.queue'},1);
1.49      albertel  736: 		} elsif ($status_code eq 'select_user') {
                    737: 		    $result.=&select_user();
1.95      albertel  738: 		} elsif ($status_code eq 'unable') {
                    739: 		    $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
1.105     albertel  740: 		} elsif ($status_code eq 'not_allowed') {
                    741: 		    $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
1.33      albertel  742: 		} else {
1.81      albertel  743: 		    $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
1.32      albertel  744: 		}
1.21      albertel  745: 	    }
1.33      albertel  746: 	    $webgrade='no';
1.163     albertel  747: 	}
                    748: 	if (!$todo || $env{'form.cancel'}) {
1.87      albertel  749: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.32      albertel  750: 	}
                    751: 	if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.61      albertel  752: 	    if ($webgrade eq 'yes') {
                    753: 		$result.=&submission_time_stamp();
                    754: 	    }
1.32      albertel  755: 	    $result.=$form_tag_start;
                    756: 	    $result.='<input type="hidden" name="webgrade" value="'.
                    757: 		$webgrade.'" />';
                    758: 	    $result.='<input type="hidden" name="queue" value="'.
                    759: 		$env{'form.queue'}.'" />';
1.52      albertel  760: 	    if ($env{'form.regrade'}) {
                    761: 		$result.='<input type="hidden" name="regrade" value="'.
                    762: 		    $env{'form.regrade'}.'" />';
                    763: 	    }
1.62      albertel  764: 	    if ($env{'form.chosensections'}) {
                    765: 		my @chosen_sections=
                    766: 		    &Apache::loncommon::get_env_multiple('form.chosensections');
                    767: 		foreach my $sec (@chosen_sections) {
                    768: 		    $result.='<input type="hidden" name="chosensections" 
                    769:                                value="'.$sec.'" />';
                    770: 		}
                    771: 	    }
1.70      albertel  772: 	    if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
1.15      albertel  773: 	}
1.110     albertel  774: 	if ($target eq 'webgrade') {
1.120     albertel  775: 	    $result.="\n".'<div id="LC_GRADING_criterialist">';
1.110     albertel  776: 	}
1.74      albertel  777:     } elsif ($target eq 'edit') {
1.141     albertel  778: 	$result.=$form_tag_start.
1.74      albertel  779: 	    &Apache::structuretags::problem_edit_header();
                    780: 	$Apache::lonxml::warnings_error_header=
                    781: 	    &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 />";
                    782: 	my $temp=&Apache::edit::insertlist($target,$token);
                    783: 	$result.=$temp;
1.1       albertel  784:     } else {
                    785: 	# page_start returned a starting result, delete it if we don't need it
                    786: 	$result = '';
                    787:     }
                    788:     return $result;
                    789: }
                    790: 
1.165     albertel  791: sub get_task_end_time {
                    792:     my ($queue_entry,$symb,$udom,$uname) = @_;
                    793: 
                    794:     my $end_time;
                    795:     if (my $slot = &slotted_access($queue_entry)) {
                    796: 	my %slot_data=&Apache::lonnet::get_slot($slot);
                    797: 	$end_time = $slot_data{'endtime'};
                    798:     } else {
                    799: 	$end_time = &Apache::lonhomework::due_date('0',$symb,
                    800: 						   $udom,$uname);
                    801:     }
                    802:     return $end_time;
                    803: }
                    804: 
1.32      albertel  805: sub get_key_todo {
                    806:     my ($target)=@_;
                    807:     my $todo;
1.33      albertel  808: 
                    809:     if (defined($env{'form.reviewasubmission'})) {
1.54      albertel  810: 	&Apache::lonxml::debug("review a submission....");
1.33      albertel  811: 	$env{'form.queue'}='reviewqueue';
                    812: 	return (undef,'show_list');
                    813:     }
                    814: 
                    815:     if (defined($env{'form.reviewagrading'})) {
                    816: 	&Apache::lonxml::debug("review a grading....");
                    817: 	$env{'form.queue'}='gradingqueue';
                    818: 	return (undef,'show_list');
                    819:     }
                    820: 
1.49      albertel  821:     if (defined($env{'form.regradeasubmission'})) {
                    822: 	&Apache::lonxml::debug("regrade a grading....");
                    823: 	$env{'form.queue'}='none';
                    824: 	return (undef,'select_user');
                    825:     }
                    826: 
1.105     albertel  827: 
1.138     albertel  828:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.105     albertel  829: 
                    830:     #need to try both queues..
                    831:     if (defined($env{'form.regradeaspecificsubmission'}) &&
                    832: 	defined($env{'form.gradinguser'})               &&
                    833: 	defined($env{'form.gradingdomain'})               ) {
1.185     albertel  834: 	my ($symb,$cid)=&Apache::lonnet::whichuser();
1.105     albertel  835: 	my $cnum  = $env{'course.'.$cid.'.num'};
                    836: 	my $cdom  = $env{'course.'.$cid.'.domain'};
                    837: 	my $uname = $env{'form.gradinguser'};
                    838: 	my $udom  = $env{'form.gradingdomain'};
                    839: 
                    840: 	my $gradingkey=&encode_queue_key($symb,$udom,$uname);
                    841: 
                    842: 	my $queue;
                    843: 
                    844: 	if      (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
                    845: 	    $env{'form.queue'} = $queue = 'gradingqueue';
                    846: 	} elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
                    847: 	    $env{'form.queue'} = $queue = 'reviewqueue';
                    848: 	}
                    849: 	
                    850: 	if (!$queue) {
                    851: 	    $env{'form.queue'} = $queue = 'none';
                    852: 	    #not queued so doing either a re or pre grade
1.164     albertel  853: 	    my %status = &Apache::lonnet::restore($symb,$cid,$udom,$uname);
                    854: 	    if ($status{'resource.0.version'} < 1) {
                    855: 		return (undef,'never_versioned');
                    856: 	    }
1.105     albertel  857: 	    return ($gradingkey);
                    858: 	}
                    859: 
1.165     albertel  860: 	if ($queue) {
                    861: 	    my $queue_entry = &get_queue_data($queue,$udom,$uname);
                    862: 	
                    863: 	    my $end_time = &get_task_end_time($queue_entry,$symb,
                    864: 					      $udom,$uname);
                    865: 	    if ($end_time > time) {
                    866: 		return (undef,"still_open:$end_time");
                    867: 	    }
                    868: 	}
                    869: 
1.105     albertel  870: 	my $who=&queue_key_locked($queue,$gradingkey);
                    871: 	if ($who eq $me) {
                    872: 	    #already have the lock
1.158     www       873: 	    $env{'form.gradingkey'}=&escape($gradingkey);
1.163     albertel  874: 	    &Apache::lonxml::debug("already locked");
1.105     albertel  875: 	    return ($gradingkey);
                    876: 	}
                    877: 	
                    878: 	if (!defined($who)) {
                    879: 	    if (&lock_key($queue,$gradingkey)) {
1.163     albertel  880: 		&Apache::lonxml::debug("newly locked");
1.105     albertel  881: 		return ($gradingkey);
                    882: 	    } else {
                    883: 		return (undef,'lock_failed');
                    884: 	    }
                    885: 	}
                    886: 
                    887: 	#otherwise (defined($who) && $who ne $me) some else has it...
                    888: 	return (undef,'not_allowed',
                    889: 		&mt('Another user ([_1]) currently has the record for [_2] locked.',
1.138     albertel  890: 		    $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
1.105     albertel  891:     }
                    892: 
                    893: 
1.32      albertel  894:     my $queue=$env{'form.queue'};
1.33      albertel  895: 
1.32      albertel  896:     if (!defined($queue)) {
                    897: 	$env{'form.queue'}=$queue='gradingqueue';
                    898:     }
1.33      albertel  899: 
1.158     www       900:     my $gradingkey=&unescape($env{'form.gradingkey'});
1.33      albertel  901: 
1.49      albertel  902:     if ($env{'form.queue'} eq 'none') {
                    903: 	if (defined($env{'form.gradingkey'})) {
                    904: 	    if ($target eq 'webgrade') {
                    905: 		if ($env{'form.stop'}) {
                    906: 		    return (undef,'stop');
1.163     albertel  907: 		} elsif ($env{'form.cancel'}) {
                    908: 		    return (undef,'cancel');
1.49      albertel  909: 		} elsif ($env{'form.next'}) {
1.59      albertel  910: 		    return (undef,'select_user');
1.49      albertel  911: 		}
                    912: 	    }
                    913: 	    return ($gradingkey,'selected');
                    914: 	} else {
1.59      albertel  915: 	    return (undef,'select_user');
1.49      albertel  916: 	}
                    917:     }
1.32      albertel  918:     if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33      albertel  919: 	&& !defined($env{'form.gradingaction'}) 
                    920: 	&& $env{'form.queuemode'} eq 'selected') {
                    921: 	
                    922: 	my $who=&queue_key_locked($queue,$gradingkey);
                    923: 	if ($who eq $me) {
                    924: 	    &Apache::lonxml::debug("Found a key was given to me");
                    925: 	    return ($gradingkey,'selected');
                    926: 	} else {
                    927: 	    return (undef,'show_list');
                    928: 	}
                    929: 
                    930:     }
                    931: 
                    932:     if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
                    933: 	if ($env{'form.gradingaction'} eq 'resume') {
                    934: 	    delete($env{'form.gradingaction'});
                    935: 	    &Apache::lonxml::debug("Resuming a key");
1.32      albertel  936: 	    return ($gradingkey);
1.33      albertel  937: 	} elsif ($env{'form.gradingaction'} eq 'unlock') {
                    938: 	    &Apache::lonxml::debug("Unlocking a key ".
                    939: 				     &check_queue_unlock($queue,$gradingkey,1));
                    940: 	    return (undef,'unlock');
                    941: 	} elsif ($env{'form.gradingaction'} eq 'select') {
                    942: 	    &Apache::lonxml::debug("Locking a key");
                    943: 	    if (&lock_key($queue,$gradingkey)) {
                    944: 		&Apache::lonxml::debug("Success $queue");
                    945: 		return ($gradingkey);
                    946: 	    }
                    947: 	    &Apache::lonxml::debug("Failed $queue");
                    948: 	    return (undef,'lock_failed');
1.32      albertel  949: 	}
                    950:     }
1.33      albertel  951: 
                    952:     if ($env{'form.queuemode'} ne 'selected') {
                    953: 	# don't get something new from the queue if they hit the stop button
1.163     albertel  954:     	if (!(($env{'form.cancel'} || $env{'form.stop'}) 
                    955: 	      && $target eq 'webgrade') 
1.33      albertel  956: 	    && !$env{'form.gradingaction'}) {
                    957: 	    &Apache::lonxml::debug("Getting anew $queue");
                    958: 	    return (&get_from_queue($queue));
                    959: 	} else {
                    960: 	    return (undef,'stop');
                    961: 	}
1.32      albertel  962:     }
1.33      albertel  963:     return (undef,undef)
1.32      albertel  964: }
1.94      albertel  965: 
                    966: sub minimize_storage {
                    967:     foreach my $key (keys(%Apache::lonhomework::results)) {
                    968: 	if ($key =~ /regrader$/) { next; }
                    969: 	if ($Apache::lonhomework::results{$key} eq
                    970: 	    $Apache::lonhomework::history{$key}) {
                    971: 	    delete($Apache::lonhomework::results{$key});
                    972: 	}
                    973:     }
                    974: }
                    975: 
1.1       albertel  976: sub end_Task {
                    977:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    978:     my $result='';
                    979:     my $status=$Apache::inputtags::status['-1'];
1.29      albertel  980:     my ($version,$previous)=&get_version();
1.1       albertel  981:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15      albertel  982: 	$target eq 'tex') {
1.69      albertel  983: 	if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.1       albertel  984: 	    if ($target eq 'web') {
1.54      albertel  985: 		if (&show_task($status,$previous)) {
                    986: 		    $result.=&Apache::lonxml::endredirection();
                    987: 		}
1.64      albertel  988: 		if ($status eq 'CAN_ANSWER' && !$previous && 
                    989: 		    !$env{'form.donescreen'}) {
1.15      albertel  990: 		    $result.="\n".'<table border="1">'.
1.28      albertel  991: 			&Apache::inputtags::file_selector("$version.0",
                    992: 							  "bridgetask","*",
1.46      albertel  993: 							  'portfolioonly',
                    994: 							  '
                    995: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
                    996: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9       albertel  997: 							  "</table>";
1.77      albertel  998: 		}
1.78      albertel  999: 		if (!$previous && $status ne 'SHOW_ANSWER' &&
                   1000: 		    &show_task($status,$previous)) {
1.9       albertel 1001: 		    $result.=&Apache::inputtags::gradestatus('0');
1.64      albertel 1002: 		    $result.='</form>';
1.116     albertel 1003: 		    my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.64      albertel 1004: 		    $result.=<<DONEBUTTON;
1.115     albertel 1005: <form name="done" method="post" action="$action">
1.64      albertel 1006:    <input type="hidden" name="donescreen" value="1" />
                   1007:    <input type="submit" value="Done" />
                   1008: </form>
                   1009: DONEBUTTON
1.77      albertel 1010:                 }
1.56      albertel 1011: 		if (&show_task($status,$previous) &&
1.89      albertel 1012: 		    $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
                   1013: 		    my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1.54      albertel 1014: 		    my $title=&Apache::lonnet::gettitle();
1.80      albertel 1015: 
1.149     albertel 1016: 		    my $start_time;
                   1017: 
1.80      albertel 1018: 		    my $slot_name=
1.89      albertel 1019: 			$Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1.149     albertel 1020: 		    if ($slot_name) {
                   1021: 			my %slot=&Apache::lonnet::get_slot($slot_name);
                   1022: 
                   1023: 			$start_time=$slot{'starttime'}
                   1024: 		    } else {
                   1025: 			$start_time= 
                   1026: 			    &Apache::lonnet::EXT('resource.0.opendate');
                   1027: 		    }
                   1028: 		    $start_time=&Apache::lonlocal::locallocaltime($start_time);
1.54      albertel 1029: 
1.116     albertel 1030: 		    my $status = "\n<div class='LC_$bt_status LC_criteria'>\n";
1.54      albertel 1031: 		    
                   1032: 		    if ($bt_status eq 'pass')  {
                   1033: 			$status.='<h2>You passed the '.$title.' given on '.
1.80      albertel 1034: 			    $start_time.'</h2>';
1.54      albertel 1035: 		    }
                   1036: 		    if ($bt_status eq 'fail')  {
                   1037: 			$status.='<h2>You did not pass the '.$title.' given on '.
1.80      albertel 1038: 			    $start_time.'</h2>';
1.54      albertel 1039: 			if (!$previous) {
                   1040: 			    $status.=&add_request_another_attempt_button();
                   1041: 			}
                   1042: 		    }
                   1043: 		    my $man_count=0;
                   1044: 		    my $opt_count=0;
                   1045: 		    my $opt_passed=0;
1.168     albertel 1046: 		    foreach my $dim (keys(%Apache::bridgetask::top_dimensionlist)) {
                   1047: 			if ($Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'}
1.54      albertel 1048: 			    eq 'N') {
                   1049: 			    $opt_count++;
1.168     albertel 1050: 			    if ($Apache::lonhomework::history{"resource.$version.0.$dim.status"} eq 'pass') {
1.54      albertel 1051: 				$opt_passed++;
                   1052: 			    }
                   1053: 			} else {
                   1054: 			    $man_count++;
                   1055: 			}
                   1056: 		    }
1.151     albertel 1057: 		    
1.54      albertel 1058: 		    my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
                   1059: 							 $parstack,$safeeval);
                   1060: 		    if ($opt_req !~ /\S/) { $opt_req='0'; }
1.99      albertel 1061: 		    $status.="\n<p>".&mt('You needed to pass all of the [_1]  mandatory components and [_2] of the [_3] optional components, of which you passed [_4].',$man_count,$opt_req,$opt_count,$opt_passed)."</p></div>\n";
1.54      albertel 1062: 
                   1063: 		    my $internal_location=&internal_location();
                   1064: 		    $result=~s/\Q$internal_location\E/$status/;
                   1065: 		}
1.142     albertel 1066: 		$result.="\n</div>\n".
                   1067: 		    &Apache::loncommon::end_page({'discussion' => 1});
1.1       albertel 1068: 	    }
                   1069: 	}
1.181     albertel 1070: 
                   1071: 	my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
                   1072: 	my %queue_data = ('type' => 'Task',
                   1073: 			  'time' => time,);
                   1074: 	if (defined($Apache::inputtags::slot_name)) {
                   1075: 	    $queue_data{'slot'} = $Apache::inputtags::slot_name;
                   1076: 	} elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) {
                   1077: 	    $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
                   1078: 	}
                   1079: 	
                   1080: 
1.29      albertel 1081: 	if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12      albertel 1082: 	    my $award='SUBMITTED';
1.28      albertel 1083: 	    &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20      albertel 1084: 						    'portfiles',\$award);
1.14      albertel 1085: 	    if ($award eq 'SUBMITTED' &&
1.28      albertel 1086: 		$Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
                   1087: 		$Apache::lonhomework::results{"resource.0.tries"}=
                   1088: 		    $Apache::lonhomework::results{"resource.$version.0.tries"}=
                   1089: 		    1+$Apache::lonhomework::history{"resource.$version.0.tries"};
                   1090: 
                   1091: 		$Apache::lonhomework::results{"resource.0.award"}=
                   1092: 		    $Apache::lonhomework::results{"resource.$version.0.award"}=
                   1093: 		    $award;
1.51      albertel 1094: 		$Apache::lonhomework::results{"resource.0.submission"}=
                   1095: 		    $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64      albertel 1096: 	    } else {
                   1097: 		delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1.77      albertel 1098: 		$award = '';
1.10      albertel 1099: 	    }
1.4       albertel 1100: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                   1101: 	    &Apache::structuretags::finalize_storage();
1.148     albertel 1102: 	    if ($award eq 'SUBMITTED') {
1.181     albertel 1103: 		&add_to_queue('gradingqueue',\%queue_data);
1.14      albertel 1104: 	    }
1.1       albertel 1105: 	}
1.163     albertel 1106: 	if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' 
                   1107: 	    && exists($env{'form.cancel'})) {
                   1108: 	    &check_queue_unlock($env{'form.queue'});
                   1109: 	    &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
                   1110: 	} elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' 
                   1111: 		 && !exists($env{'form.cancel'})) {
1.20      albertel 1112: 	    my $optional_required=
                   1113: 		&Apache::lonxml::get_param('OptionalRequired',$parstack,
                   1114: 					   $safeeval);
                   1115: 	    my $optional_passed=0;
                   1116: 	    my $mandatory_failed=0;
                   1117: 	    my $ungraded=0;
                   1118: 	    my $review=0;   
1.21      albertel 1119: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.168     albertel 1120: 	    foreach my $dim (keys(%Apache::bridgetask::top_dimensionlist)) {
1.20      albertel 1121: 		my $status=
1.168     albertel 1122: 		    $Apache::lonhomework::results{"resource.$version.0.$dim.status"};
1.20      albertel 1123: 		my $mandatory=
1.168     albertel 1124: 		    ($Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'} ne 'N');
1.20      albertel 1125: 		if ($status eq 'pass') {
                   1126: 		    if (!$mandatory) { $optional_passed++; }
                   1127: 		} elsif ($status eq 'fail') {
                   1128: 		    if ($mandatory) { $mandatory_failed++; }
                   1129: 		} elsif ($status eq 'ungraded') {
                   1130: 		    $ungraded++;
                   1131: 		} elsif ($status eq 'review') {
                   1132: 		    $review++;
1.49      albertel 1133: 		} else {
                   1134: 		    $ungraded++;
                   1135: 		}
1.20      albertel 1136: 	    }
                   1137: 	    if ($optional_passed < $optional_required) {
                   1138: 		$mandatory_failed++;
                   1139: 	    }
1.168     albertel 1140: 	    &Apache::lonxml::debug("all dim ".join(':',keys(%Apache::bridgetask::top_dimensionlist))."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.89      albertel 1141: 	    $Apache::lonhomework::results{'resource.0.regrader'}=
1.138     albertel 1142: 		$env{'user.name'}.':'.$env{'user.domain'};
1.20      albertel 1143: 	    if ($review) {
1.89      albertel 1144: 		$Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.20      albertel 1145: 	    } elsif ($ungraded) {
1.89      albertel 1146: 		$Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.20      albertel 1147: 	    } elsif ($mandatory_failed) {
1.89      albertel 1148: 		$Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25      albertel 1149: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
                   1150: 		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
                   1151: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.185     albertel 1152: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52      albertel 1153: 		
                   1154: 		if ($env{'form.regrade'} ne 'yes') {
                   1155: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                   1156: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                   1157: 		    &Apache::grades::version_portfiles(
                   1158: 						       \%Apache::lonhomework::results,
                   1159: 						       ["$version.0.bridgetask"],$courseid,
                   1160: 						       $symb,$udom,$uname,
                   1161: 						       ["$version.0.bridgetask"]);
                   1162: 		}
1.20      albertel 1163: 	    } else {
1.89      albertel 1164: 		$Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25      albertel 1165: 		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
                   1166: 		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
                   1167: 		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.185     albertel 1168: 		my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52      albertel 1169: 		if ($env{'form.regrade'} ne 'yes') {
                   1170: 		    $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
                   1171: 			$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
                   1172: 		    &Apache::grades::version_portfiles(
                   1173: 						       \%Apache::lonhomework::results,
                   1174: 						       ["$version.0.bridgetask"],$courseid,
                   1175: 						       $symb,$udom,$uname,
                   1176: 						       ["$version.0.bridgetask"]);
                   1177: 		}
1.20      albertel 1178: 	    }
1.89      albertel 1179: 	    $Apache::lonhomework::results{"resource.0.status"}=
                   1180: 		$Apache::lonhomework::results{"resource.$version.0.status"};
1.28      albertel 1181: 	    if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26      albertel 1182: 		$Apache::lonhomework::results{"resource.0.award"}=
1.50      albertel 1183: 		    $Apache::lonhomework::results{"resource.$version.0.award"};
1.26      albertel 1184: 		$Apache::lonhomework::results{"resource.0.awarded"}=
1.50      albertel 1185: 		    $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26      albertel 1186: 		$Apache::lonhomework::results{"resource.0.solved"}=
1.50      albertel 1187: 		    $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25      albertel 1188: 	    }
1.94      albertel 1189: 	    &minimize_storage();
1.21      albertel 1190: 	    &Apache::structuretags::finalize_storage();
1.188   ! albertel 1191: 	    
        !          1192: 	    # data stored, now handle queue
        !          1193: 	    if ($review) {
        !          1194: 		if ($env{'form.queue'} eq 'reviewqueue') {
        !          1195: 		    &check_queue_unlock($env{'form.queue'});
        !          1196: 		    &Apache::lonxml::debug(" still needs review not changing status.");
        !          1197: 		} else {
        !          1198: 		    if ($env{'form.queue'} ne 'none') {
        !          1199: 			&move_between_queues($env{'form.queue'},'reviewqueue');
        !          1200: 		    } else {
        !          1201: 			&add_to_queue('reviewqueue',\%queue_data);
        !          1202: 		    }
        !          1203: 		}
        !          1204: 	    } elsif ($ungraded) {
        !          1205: 		if ($env{'form.queue'} eq 'reviewqueue') {
        !          1206: 		    &Apache::lonxml::debug("moving back.");
        !          1207: 		    &move_between_queues($env{'form.queue'},
        !          1208: 					 'gradingqueue');
        !          1209: 		} elsif ($env{'form.queue'} eq 'none' ) {
        !          1210: 		    &add_to_queue('gradingqueue',\%queue_data);	
        !          1211: 		} else {
        !          1212: 		    &check_queue_unlock($env{'form.queue'});
        !          1213: 		}
        !          1214: 	    } elsif ($mandatory_failed) {
        !          1215: 		&remove_from_queue($env{'form.queue'}); 
        !          1216: 	    } else {
        !          1217: 		&remove_from_queue($env{'form.queue'});
        !          1218: 	    }
1.20      albertel 1219: 	}
1.184     albertel 1220: 	if (exists($Apache::lonhomework::results{'INTERNAL_store'})) {
                   1221: 	    # instance generation occured and hasn't yet been stored
                   1222: 	    &Apache::structuretags::finalize_storage();
                   1223: 	}
1.15      albertel 1224:     } elsif ($target eq 'webgrade') {
1.131     albertel 1225: 	$result.="</div>";
1.20      albertel 1226: 	#$result.='<input type="submit" name="next" value="'.
                   1227: 	#    &mt('Save &amp; Next').'" /> ';
                   1228: 	#$result.='<input type="submit" name="end" value="'.
                   1229: 	#    &mt('Save &amp; Stop Grading').'" /> ';
                   1230: 	#$result.='<input type="submit" name="throwaway" value="'.
                   1231: 	#    &mt('Throw Away &amp; Stop Grading').'" /> ';
                   1232: 	#$result.='<input type="submit" name="save" value="'.
                   1233: 	#    &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124     albertel 1234: 	$result.='</form>'."\n</div>\n</div>\n".
1.140     albertel 1235: 	    &Apache::loncommon::end_page();
1.1       albertel 1236:     } elsif ($target eq 'meta') {
1.70      albertel 1237: 	$result.=&Apache::response::meta_package_write('Task');
1.77      albertel 1238:         $result.=&Apache::response::meta_stores_write('solved','string',
                   1239: 						      'Problem Status');
                   1240: 	$result.=&Apache::response::meta_stores_write('tries','int_zeropos',
                   1241: 						      'Number of Attempts');
                   1242: 	$result.=&Apache::response::meta_stores_write('awarded','float',
                   1243: 						      'Partial Credit Factor');
                   1244: 	$result.=&Apache::response::meta_stores_write('status','string',
                   1245: 						      'Bridge Task Status');
1.182     albertel 1246:     } elsif ($target eq 'edit') {
                   1247: 	&Apache::structuretags::reset_problem_globals('Task');
                   1248: 	undef($Apache::lonhomework::parsing_a_task);
                   1249: 	return ('','no');
1.1       albertel 1250:     }
1.179     albertel 1251:     &Apache::structuretags::reset_problem_globals('Task');
1.4       albertel 1252:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel 1253:     return $result;
                   1254: }
                   1255: 
1.31      albertel 1256: sub move_between_queues {
                   1257:     my ($src_queue,$dest_queue)=@_;
1.49      albertel 1258:     my $cur_data;
                   1259:     if ($src_queue ne 'none') {
                   1260: 	$cur_data=&get_queue_data($src_queue);
                   1261: 	if (!$cur_data) { return 'not_exist'; }
                   1262:     } else {
                   1263: 	$cur_data = ['none'];
                   1264:     }
1.148     albertel 1265:     my $result=&add_to_queue($dest_queue,$cur_data);
1.31      albertel 1266:     if ($result ne 'ok') {
                   1267: 	return $result;
                   1268:     }
                   1269:     &check_queue_unlock($src_queue);
                   1270:     return &remove_from_queue($src_queue);
1.21      albertel 1271: }
                   1272: 
                   1273: sub check_queue_unlock {
1.32      albertel 1274:     my ($queue,$key,$allow_not_me)=@_;
1.49      albertel 1275:     if ($queue eq 'none') { return 'ok'; }
1.185     albertel 1276:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.32      albertel 1277:     if (!defined($key)) {
1.138     albertel 1278: 	$key="$symb\0queue\0$uname:$udom";
1.32      albertel 1279:     }
1.30      albertel 1280:     my $cnum=$env{'course.'.$cid.'.num'};
                   1281:     my $cdom=$env{'course.'.$cid.'.domain'};
1.138     albertel 1282:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30      albertel 1283:     my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
                   1284:     if  ($who eq $me) {
1.163     albertel 1285: 	&Apache::lonxml::debug("unlocking my own $who");
1.32      albertel 1286: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
                   1287:     } elsif ($allow_not_me) {
1.33      albertel 1288: 	&Apache::lonxml::debug("unlocking $who by $me");
1.32      albertel 1289: 	return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30      albertel 1290:     }
1.32      albertel 1291:     return 'not_owner';
1.21      albertel 1292: }
                   1293: 
1.88      albertel 1294: sub in_queue {
                   1295:     my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
                   1296:     if ($queue eq 'none') { return 0; }
                   1297:     if (!defined($symb) || !defined($cdom) || !defined($cnum)
                   1298: 	|| !defined($udom) || !defined($uname)) {
1.185     albertel 1299: 	($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.88      albertel 1300: 	$cnum=$env{'course.'.$cid.'.num'};
                   1301: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1302:     }
                   1303: 
                   1304:     my $key=&encode_queue_key($symb,$udom,$uname);
                   1305:     my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
                   1306: 
                   1307:     if (defined($results{$key})) {
                   1308: 	return 1;
                   1309:     }
                   1310:     return 0;
                   1311: }
                   1312: 
1.21      albertel 1313: sub remove_from_queue {
1.86      albertel 1314:     my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49      albertel 1315:     if ($queue eq 'none') { return 'ok'; }
1.86      albertel 1316:     if (!defined($symb) || !defined($cdom) || !defined($cnum)
                   1317: 	|| !defined($udom) || !defined($uname)) {
1.185     albertel 1318: 	($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.86      albertel 1319: 	$cnum=$env{'course.'.$cid.'.num'};
                   1320: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1321:     }
1.88      albertel 1322:     if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
                   1323: 	return 'ok';
                   1324:     }
1.86      albertel 1325:     my $key=&encode_queue_key($symb,$udom,$uname);
1.27      albertel 1326:     my @keys=($key,"$key\0locked");
1.31      albertel 1327:     return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21      albertel 1328: }
                   1329: 
1.16      albertel 1330: sub setup_env_for_other_user {
                   1331:     my ($queue_key,$safeeval)=@_;
                   1332:     my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30      albertel 1333:     &Apache::lonxml::debug("setup_env for $queue_key");
1.16      albertel 1334:     $env{'form.grade_symb'}=$symb;
                   1335:     $env{'form.grade_domain'}=$udom;
                   1336:     $env{'form.grade_username'}=$uname;
                   1337:     $env{'form.grade_courseid'}=$env{'request.course.id'};
                   1338:     &Apache::lonxml::initialize_rndseed($safeeval);
                   1339: }
                   1340: 
1.31      albertel 1341: sub get_queue_data {
1.165     albertel 1342:     my ($queue,$udom,$uname)=@_;
1.185     albertel 1343:     my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonnet::whichuser();
1.165     albertel 1344:     if (!$uname || !$udom) {
                   1345: 	$uname=$other_uname;
                   1346: 	$udom =$other_udom;
                   1347:     }
1.31      albertel 1348:     my $cnum=$env{'course.'.$cid.'.num'};
                   1349:     my $cdom=$env{'course.'.$cid.'.domain'};
1.138     albertel 1350:     my $todo="$symb\0queue\0$uname:$udom";
1.31      albertel 1351:     my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
                   1352:     if ($key eq $todo && ref($value)) {
                   1353: 	return $value;
                   1354:     }
                   1355:     return undef;
                   1356: }
                   1357: 
1.84      albertel 1358: 
1.49      albertel 1359: sub check_queue_for_key {
1.84      albertel 1360:     my ($cdom,$cnum,$queue,$todo)=@_;
                   1361: 
1.49      albertel 1362:     my %results=
                   1363: 	&Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
                   1364:     
                   1365:     if (exists($results{$todo}) && ref($results{$todo})) {
                   1366: 	if (defined($results{"$todo\0locked"})) {
                   1367: 	    return 'locked';
                   1368: 	}
1.148     albertel 1369: 	if (my $slot=&slotted_access($results{$todo})) {
1.86      albertel 1370: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1371: 	    if ($slot_data{'endtime'} > time) { 
                   1372: 		return 'in_progress';
                   1373: 	    }
1.148     albertel 1374: 	} else {
                   1375: 	    my ($symb) = &decode_queue_key($todo);
                   1376: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1377: 	    if ($due_date > time) {
                   1378: 		return 'in_progress';
                   1379: 	    }
1.58      albertel 1380: 	}
1.49      albertel 1381: 	return 'enqueued';
                   1382:     }
                   1383:     return undef;
                   1384: }
                   1385: 
1.14      albertel 1386: sub add_to_queue {
1.82      albertel 1387:     my ($queue,$user_data)=@_;
1.49      albertel 1388:     if ($queue eq 'none') { return 'ok'; }
1.185     albertel 1389:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.82      albertel 1390:     if (!$cid || $env{'request.state'} eq 'construct') {
                   1391: 	return 'no_queue';
                   1392:     }
1.14      albertel 1393:     my $cnum=$env{'course.'.$cid.'.num'};
                   1394:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1395:     my %data;
1.138     albertel 1396:     $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83      albertel 1397:     return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14      albertel 1398: }
                   1399: 
1.156     albertel 1400: sub get_limited_classlist {
                   1401:     my ($sections) = @_;
                   1402: 
                   1403:     my $classlist = &Apache::loncoursedata::get_classlist();
1.157     albertel 1404:     foreach my $student (keys(%$classlist)) {
                   1405: 	if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
                   1406: 	     ne 'Active') {
                   1407: 	    delete($classlist->{$student});
                   1408:        	}
                   1409:     }
1.156     albertel 1410: 
1.157     albertel 1411:     if (ref($sections) && !grep('all',@{ $sections })) {
1.156     albertel 1412: 	foreach my $student (keys(%$classlist)) {
                   1413: 	    my $section  = 
                   1414: 		$classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
                   1415: 	    if (! grep($section,@{ $sections })) {
                   1416: 		delete($classlist->{$student});
                   1417: 	    }
                   1418: 	}
                   1419:     }
                   1420:     return $classlist;
                   1421: }
                   1422: 
                   1423: 
1.14      albertel 1424: sub show_queue {
1.32      albertel 1425:     my ($queue,$with_selects)=@_;
1.14      albertel 1426:     my $result;
1.185     albertel 1427:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14      albertel 1428:     my $cnum=$env{'course.'.$cid.'.num'};
                   1429:     my $cdom=$env{'course.'.$cid.'.domain'};
1.59      albertel 1430: 
                   1431:     my @chosen_sections=
                   1432: 	&Apache::loncommon::get_env_multiple('form.chosensections');
1.156     albertel 1433: 
                   1434:     my $classlist = &get_limited_classlist(\@chosen_sections);
                   1435: 
1.63      albertel 1436:     if (!(grep(/^all$/,@chosen_sections))) {
                   1437: 	$result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
                   1438: 	    '</tt>.</p> '."\n";
                   1439:     }
1.59      albertel 1440: 
1.156     albertel 1441:     my ($view,$view_section);
                   1442:     my $scope = $env{'request.course.id'};
                   1443:     if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
                   1444: 	$scope .= '/'.$env{'request.course.sec'};
                   1445: 	if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
                   1446: 	    $view_section=$env{'request.course.sec'};
                   1447: 	} else {
                   1448: 	    undef($view);
                   1449: 	}
                   1450:     }
                   1451: 
1.16      albertel 1452:     my $regexp="^$symb\0";
1.30      albertel 1453:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31      albertel 1454:     my ($tmp)=%queue;
                   1455:     if ($tmp=~/^error: 2 /) {
1.159     albertel 1456: 	return "\n<h3>Current Queue - $queue</h3>".
                   1457: 	    &Apache::loncommon::start_data_table().
                   1458: 	    &Apache::loncommon::start_data_table_row().
                   1459: 	    '<td>'.&mt('Empty').'</td>'.
                   1460: 	    &Apache::loncommon::end_data_table_row().
                   1461: 	    &Apache::loncommon::end_data_table();
1.31      albertel 1462:     }
1.103     albertel 1463:     my $title=&Apache::lonnet::gettitle($symb);
1.159     albertel 1464:     $result.="\n<h3>Current Queue - $title $queue </h3>".
                   1465: 	&Apache::loncommon::start_data_table().
                   1466: 	&Apache::loncommon::start_data_table_header_row();
1.103     albertel 1467:     if ($with_selects) { $result.="<th>Status</th><th></th>"; }
1.159     albertel 1468:     $result.="<th>user</th><th>data</th>".
                   1469: 	&Apache::loncommon::end_data_table_header_row();
1.14      albertel 1470:     foreach my $key (sort(keys(%queue))) {
1.59      albertel 1471: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
                   1472: 	if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.156     albertel 1473: 	
                   1474: 	my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
                   1475: 
                   1476: 	my $can_view=1;
                   1477: 	if (!$view
                   1478: 	    || ($view_section && !$section)
                   1479: 	    || ($view_section && $section && ($view_section ne $section))) {
                   1480: 	    $can_view=0;
                   1481: 	}
                   1482: 
1.32      albertel 1483: 	if ($key=~/locked$/ && !$with_selects) {
1.159     albertel 1484: 	    $result.= &Apache::loncommon::start_data_table_row().
                   1485: 		"<td>$uname</td>";
1.103     albertel 1486: 	    $result.='<td>'.$queue{$key}.'</td></tr>';
1.32      albertel 1487: 	} elsif ($key=~/timestamp$/ && !$with_selects) {
1.159     albertel 1488: 	    $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103     albertel 1489: 	    $result.='<td>'.
1.16      albertel 1490: 		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32      albertel 1491: 	} elsif ($key!~/(timestamp|locked)$/) {
1.159     albertel 1492: 	    $result.= &Apache::loncommon::start_data_table_row();
1.148     albertel 1493: 	    my ($end_time,$slot_text);
                   1494: 	    if (my $slot=&slotted_access($queue{$key})) {
                   1495: 		my %slot_data=&Apache::lonnet::get_slot($slot);
                   1496: 		$end_time = $slot_data{'endtime'};
                   1497: 		$slot_text = &mt('Slot: [_1]',$slot);
                   1498: 	    } else {
                   1499: 		$end_time = &Apache::lonhomework::due_date('0',$symb);
                   1500: 		$slot_text = '';
                   1501: 	    }
1.32      albertel 1502: 	    if ($with_selects) {
1.158     www      1503: 		my $ekey=&escape($key);
1.103     albertel 1504: 		my ($action,$description,$status)=('select',&mt('Select'));
1.32      albertel 1505: 		if (exists($queue{"$key\0locked"})) {
1.138     albertel 1506: 		    my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.103     albertel 1507: 		    $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
1.32      albertel 1508: 		    if ($me eq $queue{"$key\0locked"}) {
                   1509: 			($action,$description)=('resume',&mt('Resume'));
                   1510: 		    } else {
                   1511: 			($action,$description)=('unlock',&mt('Unlock'));
                   1512: 		    }
                   1513: 		}
1.62      albertel 1514: 		my $seclist;
                   1515: 		foreach my $sec (@chosen_sections) {
                   1516: 		    $seclist.='<input type="hidden" name="chosensections" 
                   1517:                                value="'.$sec.'" />';
                   1518: 		}
1.156     albertel 1519: 		if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35      albertel 1520: 		    $result.=(<<FORM);
1.103     albertel 1521: <td>$status</td>
1.32      albertel 1522: <td>
1.115     albertel 1523: <form style="display: inline" method="post">
1.32      albertel 1524:  <input type="hidden" name="gradingkey" value="$ekey" />
                   1525:  <input type="hidden" name="queue" value="$queue" />
                   1526:  <input type="hidden" name="gradingaction" value="$action" />
                   1527:  <input type="hidden" name="webgrade" value="no" />
1.33      albertel 1528:  <input type="hidden" name="queuemode" value="selected" />
1.32      albertel 1529:  <input type="submit" name="submit" value="$description" />
1.62      albertel 1530:  $seclist
1.32      albertel 1531: </form>
                   1532: </td>
                   1533: FORM
1.156     albertel 1534:                 } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
                   1535: 		    $result.='<td>'.&mt("Not gradable").'</td><td>&nbsp;</td>'
1.35      albertel 1536:                 } else {
1.148     albertel 1537: 		    $result.='<td>'.&mt("In Progress").'</td><td>&nbsp;</td>'
1.35      albertel 1538: 		}
1.32      albertel 1539: 	    }
1.156     albertel 1540: 	    $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138     albertel 1541: 		" <tt>($uname:$udom)</tt> </td>";
1.148     albertel 1542: 	    $result.='<td>'.$slot_text.' End time: '.
                   1543: 		&Apache::lonlocal::locallocaltime($end_time).
1.159     albertel 1544: 		"</td>".&Apache::loncommon::end_data_table_row();
1.16      albertel 1545: 	}
1.14      albertel 1546:     }
1.159     albertel 1547:     $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14      albertel 1548:     return $result;
                   1549: }
                   1550: 
1.34      albertel 1551: sub get_queue_counts {
                   1552:     my ($queue)=@_;
                   1553:     my $result;
1.185     albertel 1554:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.34      albertel 1555:     my $cnum=$env{'course.'.$cid.'.num'};
                   1556:     my $cdom=$env{'course.'.$cid.'.domain'};
1.156     albertel 1557: 
1.157     albertel 1558:     my $classlist=&get_limited_classlist();
1.156     albertel 1559: 
1.34      albertel 1560:     my $regexp="^$symb\0";
                   1561:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1562:     my ($tmp)=%queue;
                   1563:     if ($tmp=~/^error: 2 /) {
                   1564: 	return (0,0,0);
                   1565:     }
                   1566:     my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96      albertel 1567:     my %slot_cache;
1.34      albertel 1568:     foreach my $key (sort(keys(%queue))) {
1.156     albertel 1569: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
                   1570: 	if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.34      albertel 1571: 	if ($key=~/locked$/) {
                   1572: 	    $locks++;
                   1573: 	} elsif ($key=~/timestamp$/) {
                   1574: 	    #ignore
                   1575: 	} elsif ($key!~/(timestamp|locked)$/) {
                   1576: 	    $entries++;
1.148     albertel 1577: 	    if (my $slot=&slotted_access($queue{$key})) {
                   1578: 		if (!exists($slot_cache{$slot})) {
                   1579: 		    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1580: 		    $slot_cache{$slot} = \%slot_data;
                   1581: 		}
                   1582: 		if (time > $slot_cache{$slot}{'endtime'}) {
                   1583: 		    $ready_to_grade++;
                   1584: 		}
                   1585: 	    } else {
                   1586: 		my $due_date = &Apache::lonhomework::due_date('0',$symb);
                   1587: 		if ($due_date ne '' && time > $due_date) {
                   1588: 		    $ready_to_grade++;
                   1589: 		}
1.34      albertel 1590: 	    }
                   1591: 	}
                   1592:     }
                   1593:     return ($entries,$ready_to_grade,$locks);
                   1594: }
                   1595: 
1.49      albertel 1596: sub encode_queue_key {
                   1597:     my ($symb,$udom,$uname)=@_;
1.138     albertel 1598:     return "$symb\0queue\0$uname:$udom";
1.49      albertel 1599: }
                   1600: 
1.14      albertel 1601: sub decode_queue_key {
                   1602:     my ($key)=@_;
                   1603:     my ($symb,undef,$user) = split("\0",$key);
1.138     albertel 1604:     my ($uname,$udom) = split(':',$user);
1.14      albertel 1605:     return ($symb,$uname,$udom);
                   1606: }
                   1607: 
                   1608: sub queue_key_locked {
1.30      albertel 1609:     my ($queue,$key,$cdom,$cnum)=@_;
1.33      albertel 1610:     if (!defined($cdom) || !defined($cnum)) {
1.185     albertel 1611: 	my (undef,$cid)=&Apache::lonnet::whichuser();
1.33      albertel 1612: 	$cnum=$env{'course.'.$cid.'.num'};
                   1613: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1614:     }
1.14      albertel 1615:     my ($key_locked,$value)=
1.30      albertel 1616: 	&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14      albertel 1617:     if ($key_locked eq "$key\0locked") {
                   1618: 	return $value;
                   1619:     }
                   1620:     return undef;
                   1621: }
                   1622: 
1.148     albertel 1623: sub slotted_access {
                   1624:     my ($queue_entry) = @_;
                   1625:     if (ref($queue_entry) eq 'ARRAY') {
                   1626: 	if (defined($queue_entry->[0])) {
                   1627: 	    return $queue_entry->[0];
                   1628: 	}
                   1629: 	return undef;
                   1630:     } elsif (ref($queue_entry) eq 'HASH') {
                   1631: 	if (defined($queue_entry->{'slot'})) {
                   1632: 	    return $queue_entry->{'slot'};
                   1633: 	}
                   1634: 	return undef;
                   1635:     }
                   1636:     return undef;
                   1637: }
                   1638: 
1.14      albertel 1639: sub pick_from_queue_data {
1.156     albertel 1640:     my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98      albertel 1641:     my @possible; # will hold queue entries that are valid to be selected
1.30      albertel 1642:     foreach my $key (keys(%$queuedata)) {
1.68      albertel 1643: 	if ($key =~ /\0locked$/) { next; }
                   1644: 	if ($key =~ /\0timestamp$/) { next; }
1.156     albertel 1645: 
1.14      albertel 1646: 	my ($symb,$uname,$udom)=&decode_queue_key($key);
1.156     albertel 1647: 	if (!defined($classlist->{$uname.':'.$udom})) { next; }
                   1648: 
1.14      albertel 1649: 	if ($check_section) {
1.156     albertel 1650: 	    my $section =
                   1651: 		$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17      albertel 1652: 	    if ($section eq $check_section) {
1.33      albertel 1653: 		&Apache::lonxml::debug("my sec");
1.15      albertel 1654: 		next;
                   1655: 	    }
1.14      albertel 1656: 	}
1.148     albertel 1657: 	my $end_time;
                   1658: 	if (my $slot=&slotted_access($queuedata->{$key})) {
1.154     albertel 1659: 	    &Apache::lonxml::debug("looking at slot $slot");
1.148     albertel 1660: 	    my %slot_data=&Apache::lonnet::get_slot($slot);
                   1661: 	    if ($slot_data{'endtime'} < time) { 
                   1662: 		$end_time = $slot_data{'endtime'};
1.154     albertel 1663: 	    } else {
                   1664: 		&Apache::lonxml::debug("not time ".$slot_data{'endtime'});
                   1665: 		next;
1.148     albertel 1666: 	    }
                   1667: 	} else {
                   1668: 	    my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154     albertel 1669: 	    if ($due_date < time) {
1.148     albertel 1670: 		$end_time = $due_date;
1.154     albertel 1671: 	    } else {
                   1672: 		&Apache::lonxml::debug("not time $due_date");
                   1673: 		next;
1.148     albertel 1674: 	    }
                   1675: 	}
                   1676: 	
1.98      albertel 1677: 	if (exists($queuedata->{"$key\0locked"})) {
1.33      albertel 1678: 	    &Apache::lonxml::debug("someone already has um.");
1.15      albertel 1679: 	    next;
                   1680: 	}
1.148     albertel 1681: 	push(@possible,[$key,$end_time]);
1.98      albertel 1682:     }
                   1683:     if (@possible) {
                   1684:         # sort entries in order by slot end time
                   1685: 	@possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137     albertel 1686: 	# pick one of the entries in the top 10% in small queues and one
                   1687: 	# of the first ten entries in large queues
1.139     albertel 1688: 	#my $ten_percent = int($#possible * 0.1);
                   1689: 	#if ($ten_percent < 1 ) { $ten_percent = 1;  }
                   1690: 	#if ($ten_percent > 10) { $ten_percent = 10; }
                   1691: 	#my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137     albertel 1692: 	
1.139     albertel 1693: 	#return $possible[int(rand($max))][0];
                   1694: 	return $possible[0][0];
1.14      albertel 1695:     }
                   1696:     return undef;
                   1697: }
                   1698: 
1.15      albertel 1699: sub find_mid_grade {
1.30      albertel 1700:     my ($queue,$symb,$cdom,$cnum)=@_;
1.158     www      1701:     my $todo=&unescape($env{'form.gradingkey'});
1.138     albertel 1702:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15      albertel 1703:     if ($todo) {
1.30      albertel 1704: 	my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15      albertel 1705: 	if ($who eq $me) { return $todo; }
                   1706:     }
                   1707:     my $regexp="^$symb\0.*\0locked\$";
1.30      albertel 1708:     my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15      albertel 1709:     foreach my $key (keys(%locks)) {
                   1710: 	my $who=$locks{$key};
                   1711: 	if ($who eq $me) {
                   1712: 	    $todo=$key;
                   1713: 	    $todo=~s/\0locked$//;
                   1714: 	    return $todo;
                   1715: 	}
                   1716:     }
                   1717:     return undef;
                   1718: }
                   1719: 
1.32      albertel 1720: sub lock_key {
                   1721:     my ($queue,$todo)=@_;
1.138     albertel 1722:     my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.185     albertel 1723:     my (undef,$cid)=&Apache::lonnet::whichuser();
1.32      albertel 1724:     my $cnum=$env{'course.'.$cid.'.num'};
                   1725:     my $cdom=$env{'course.'.$cid.'.domain'};
                   1726:     my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
                   1727: 					$cdom,$cnum);
1.33      albertel 1728:     &Apache::lonxml::debug("success $success $todo");
1.32      albertel 1729:     if ($success eq 'ok') {
                   1730: 	return 1;
                   1731:     }
                   1732:     return 0;
                   1733: }
                   1734: 
1.86      albertel 1735: sub get_queue_symb_status {
1.85      albertel 1736:     my ($queue,$symb,$cdom,$cnum) = @_;
                   1737:     if (!defined($cdom) || !defined($cnum)) {
1.185     albertel 1738: 	my (undef,$cid)=&Apache::lonnet::whichuser();
1.85      albertel 1739: 	$cnum=$env{'course.'.$cid.'.num'};
                   1740: 	$cdom=$env{'course.'.$cid.'.domain'};
                   1741:     }
1.157     albertel 1742:     my $classlist=&get_limited_classlist();
1.156     albertel 1743: 
1.85      albertel 1744:     my $regexp="^$symb\0";
                   1745:     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
                   1746:     my ($tmp)=%queue;
                   1747:     if ($tmp=~/^error: 2 /) { return; }
                   1748:     my @users;
                   1749:     foreach my $key (sort(keys(%queue))) {
                   1750: 	next if ($key=~/locked$/);
                   1751: 	next if ($key=~/timestamp$/);
                   1752: 	my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156     albertel 1753: 	next if (!defined($classlist->{$uname.':'.$udom}));
1.85      albertel 1754: 	push(@users,"$uname:$udom");
                   1755:     }
                   1756:     return @users;
                   1757: }
                   1758: 
1.14      albertel 1759: sub get_from_queue {
1.30      albertel 1760:     my ($queue)=@_;
1.14      albertel 1761:     my $result;
1.185     albertel 1762:     my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14      albertel 1763:     my $cnum=$env{'course.'.$cid.'.num'};
                   1764:     my $cdom=$env{'course.'.$cid.'.domain'};
1.32      albertel 1765:     my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33      albertel 1766:     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16      albertel 1767:     if ($todo) { return $todo; }
1.95      albertel 1768:     my $attempts=0;
1.156     albertel 1769: 
1.157     albertel 1770:     my $classlist=&get_limited_classlist();
1.156     albertel 1771: 
1.14      albertel 1772:     while (1) {
1.95      albertel 1773: 	if ($attempts > 2) {
                   1774: 	    # tried twice to get a queue entry, giving up
                   1775: 	    return (undef,'unable');
                   1776: 	}
1.14      albertel 1777: 	my $starttime=time;
1.83      albertel 1778: 	&Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
                   1779: 			      $cdom,$cnum);
1.33      albertel 1780: 	&Apache::lonxml::debug("$starttime");
1.14      albertel 1781: 	my $regexp="^$symb\0queue\0";
1.156     albertel 1782: 	#my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97      albertel 1783: 
1.98      albertel 1784: 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33      albertel 1785: 	#make a pass looking for a user _not_ in my section
1.14      albertel 1786: 	if ($env{'request.course.sec'}) {
1.33      albertel 1787: 	    &Apache::lonxml::debug("sce");
1.30      albertel 1788: 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156     albertel 1789: 					\%queue,$cdom,$cnum,$classlist);
1.33      albertel 1790: 	    &Apache::lonxml::debug("sce $todo");
1.14      albertel 1791: 	}
1.33      albertel 1792: 	# no one _not_ in our section so look for any user that is
                   1793: 	# ready for grading
1.14      albertel 1794: 	if (!$todo) {
1.33      albertel 1795: 	    &Apache::lonxml::debug("no sce");
1.156     albertel 1796: 	    $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
                   1797: 					$classlist);
1.33      albertel 1798: 	    &Apache::lonxml::debug("no sce $todo");
1.14      albertel 1799: 	}
                   1800: 	# no user to grade 
                   1801: 	if (!$todo) { last; }
1.33      albertel 1802: 	&Apache::lonxml::debug("got $todo");
1.14      albertel 1803: 	# otherwise found someone so lets try to lock them
1.32      albertel 1804: 	# unless someone else already picked them
1.95      albertel 1805: 	if (!&lock_key($queue,$todo)) {
                   1806: 	    $attempts++;
                   1807: 	    next;
                   1808: 	}
1.14      albertel 1809: 	my (undef,$endtime)=
1.30      albertel 1810: 	    &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14      albertel 1811: 				 $cdom,$cnum);
1.33      albertel 1812: 	&Apache::lonxml::debug("emd  $endtime");
1.14      albertel 1813: 	# someone else already modified the queue, 
                   1814: 	# perhaps our picked user wass already fully graded between
                   1815: 	# when we picked him and when we locked his record? so lets
                   1816: 	# double check.
                   1817: 	if ($endtime != $starttime) {
                   1818: 	    my ($key,$value)=
1.30      albertel 1819: 		&Apache::lonnet::get($queue,["$todo"],
1.14      albertel 1820: 				     $cdom,$cnum);
1.33      albertel 1821: 	    &Apache::lonxml::debug("check  $key .. $value");
1.14      albertel 1822: 	    if ($key eq $todo && ref($value)) {
                   1823: 	    } else {
1.30      albertel 1824: 		&Apache::lonnet::del($queue,["$todo\0locked"],
1.14      albertel 1825: 				     $cdom,$cnum);
1.33      albertel 1826: 		&Apache::lonxml::debug("del");
1.95      albertel 1827: 		$attempts++;
1.14      albertel 1828: 		next;
                   1829: 	    }
                   1830: 	}
1.33      albertel 1831: 	&Apache::lonxml::debug("last $todo");
1.14      albertel 1832: 	last;
                   1833:     }
                   1834:     return $todo;
                   1835: }
                   1836: 
1.49      albertel 1837: sub select_user {
1.185     albertel 1838:     my ($symb,$cid)=&Apache::lonnet::whichuser();
1.49      albertel 1839: 
1.59      albertel 1840:     my @chosen_sections=
                   1841: 	&Apache::loncommon::get_env_multiple('form.chosensections');
1.156     albertel 1842: 
                   1843:     my $classlist = &get_limited_classlist(\@chosen_sections);
1.63      albertel 1844:     
                   1845:     my $result;
                   1846:     if (!(grep(/^all$/,@chosen_sections))) {
                   1847: 	$result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
                   1848: 	    '</tt>.</p> '."\n";
                   1849:     }
1.159     albertel 1850:     $result.=&Apache::loncommon::start_data_table();
1.49      albertel 1851: 
1.156     albertel 1852:     foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49      albertel 1853: 	my ($uname,$udom) = split(/:/,$student);
1.59      albertel 1854: 	
1.84      albertel 1855: 	my $cnum=$env{'course.'.$cid.'.num'};
                   1856: 	my $cdom=$env{'course.'.$cid.'.domain'};
1.88      albertel 1857: 	my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
                   1858: 					 'Task');
1.49      albertel 1859: 	my $queue = 'none';
1.58      albertel 1860: 	my $cannot_grade;
                   1861: 	if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 1862: 	    $queue = 'reviewqueue';
1.58      albertel 1863: 	    if ($status{'reviewqueue'} eq 'in_progress') {
                   1864: 		$cannot_grade=1;
                   1865: 	    }
                   1866: 	} elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49      albertel 1867: 	    $queue = 'gradingqueue';
1.58      albertel 1868: 	    if ($status{'gradingqueue'} eq 'in_progress') {
                   1869: 		$cannot_grade=1;
                   1870: 	    }
1.49      albertel 1871: 	}
                   1872: 	my $todo = 
1.158     www      1873: 	    &escape(&encode_queue_key($symb,$udom,$uname));
1.58      albertel 1874: 	if ($cannot_grade) {
1.159     albertel 1875: 	    $result.=&Apache::loncommon::start_data_table_row().
                   1876: 		'<td>&nbsp;</td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58      albertel 1877: 		'</td><td>';
                   1878: 	} else {
1.62      albertel 1879: 	    my $seclist;
                   1880: 	    foreach my $sec (@chosen_sections) {
                   1881: 		$seclist.='<input type="hidden" name="chosensections" 
                   1882:                                value="'.$sec.'" />';
                   1883: 	    }
1.159     albertel 1884: 	    $result.=&Apache::loncommon::start_data_table_row();
1.58      albertel 1885: 	    $result.=<<RESULT;
1.49      albertel 1886:   <td>
1.115     albertel 1887:     <form style="display: inline" method="post">
1.49      albertel 1888:       <input type="hidden" name="gradingkey" value="$todo" />
                   1889:       <input type="hidden" name="queue" value="$queue" />
                   1890:       <input type="hidden" name="webgrade" value="no" />
1.52      albertel 1891:       <input type="hidden" name="regrade" value="yes" />
1.62      albertel 1892:       <input type="submit" name="submit" value="Regrade" />
                   1893:       $seclist
1.49      albertel 1894:     </form>
1.155     albertel 1895:   <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt></td>
1.49      albertel 1896:   <td>
                   1897: RESULT
1.58      albertel 1898:         }
1.49      albertel 1899:         if ($status{'status'} eq 'pass') {
                   1900: 	    $result .= '<font color="green">'.&mt('Passed').'</font>';
                   1901: 	} elsif ($status{'status'} eq 'fail') {
                   1902: 	    $result .= '<font color="red">'.&mt('Failed').'</font>';
                   1903: 	} elsif ($status{'status'} eq 'review') {
                   1904: 	    $result .= '<font color="blue">'.&mt('Under Review').'</font>';
                   1905: 	} elsif ($status{'status'} eq 'ungraded') {
                   1906: 	    $result .= &mt('Ungraded');
                   1907: 	} elsif ($status{'status'} ne '') {
                   1908: 	    $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
                   1909: 	} else {
                   1910: 	    $result.="&nbsp;";
                   1911: 	}
                   1912: 	if ($status{'version'}) {
                   1913: 	    $result .= ' '.&mt('Version').' '.$status{'version'};
                   1914: 	}
1.101     albertel 1915: 	if ($status{'grader'}) {
                   1916: 	    $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
                   1917: 	}
1.49      albertel 1918: 	$result.= '</td><td>';
                   1919: 	if ($status{'reviewqueue'} eq 'enqueued') {
                   1920: 	    $result .= &mt('Awaiting Review');
                   1921: 	} elsif ($status{'reviewqueue'} eq 'locked') {
                   1922: 	    $result .= &mt('Under Review');
1.58      albertel 1923: 	} elsif ($status{'reviewqueue'} eq 'in_progress') {
                   1924: 	    $result .= &mt('Still being worked on.');
1.49      albertel 1925: 	} elsif ($status{'gradingqueue'} eq 'enqueued') {
                   1926: 	    $result .= &mt('Awaiting Grading');
                   1927: 	} elsif ($status{'gradingqueue'} eq 'locked') {
                   1928: 	    $result .= &mt('Being Graded');
1.58      albertel 1929: 	} elsif ($status{'gradingqueue'} eq 'in_progress') {
                   1930: 	    $result .= &mt('Still being worked on.');
1.49      albertel 1931: 	} else {
                   1932: 	    $result.="&nbsp;";
                   1933: 	}
1.159     albertel 1934: 	$result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49      albertel 1935:     }
1.159     albertel 1936:     $result.=&Apache::loncommon::end_data_table();
1.49      albertel 1937:     return $result;
                   1938: }
                   1939: 
                   1940: sub get_student_status {
1.86      albertel 1941:     my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
                   1942: 
                   1943:     my %status;
                   1944: 
                   1945:     if ($type eq 'Task') {
                   1946: 	my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49      albertel 1947: 					  $udom,$uname);
1.89      albertel 1948: 	$status{'status'}=$record{'resource.0.status'};
                   1949: 	$status{'version'}=$record{'resource.0.version'};
                   1950: 	$status{'grader'}=$record{'resource.0.regrader'};
1.86      albertel 1951:     }
                   1952:     $status{'reviewqueue'}=
                   1953: 	&check_queue_for_key($cdom,$cnum,'reviewqueue',
                   1954: 			     &encode_queue_key($symb,$udom,$uname));
                   1955:     $status{'gradingqueue'}=
                   1956: 	&check_queue_for_key($cdom,$cnum,'gradingqueue',
                   1957: 			     &encode_queue_key($symb,$udom,$uname));
1.49      albertel 1958:     return %status;
                   1959: }
                   1960: 
1.1       albertel 1961: sub start_ClosingParagraph {
                   1962:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1963:     my $result;
                   1964:     if ($target eq 'web') {
1.13      albertel 1965:     } elsif ($target eq 'webgrade') {
                   1966: 	&Apache::lonxml::startredirection();
1.1       albertel 1967:     }
                   1968:     return $result;
                   1969: }
                   1970: 
                   1971: sub end_ClosingParagraph {
                   1972:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1973:     my $result;
                   1974:     if ($target eq 'web') {
1.13      albertel 1975:     } elsif ($target eq 'webgrade') {
                   1976: 	&Apache::lonxml::endredirection();
1.1       albertel 1977:     }
                   1978:     return $result;
                   1979: }
                   1980: 
1.168     albertel 1981: sub get_dim_id {
                   1982:     return $Apache::bridgetask::dimension[-1];
                   1983: }
                   1984: 
1.19      albertel 1985: sub get_id {
                   1986:     my ($parstack,$safeeval)=@_;
                   1987:     my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
                   1988:     if (!$id) { $id=$Apache::lonxml::curdepth; }
                   1989:     return $id;
                   1990: }
                   1991: 
1.162     albertel 1992: sub start_Setup {
                   1993:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168     albertel 1994:     #undef(%dimension);
                   1995:     my $dim = &get_id($parstack,$safeeval);
                   1996:     push(@Apache::bridgetask::dimension,$dim);
1.162     albertel 1997:     &Apache::lonxml::startredirection();
1.168     albertel 1998:     return &internal_location($dim);
1.162     albertel 1999: }
1.173     albertel 2000: 
                   2001: {
                   2002:     my @allowed;
                   2003:     sub enable_dimension_parsing {
                   2004: 	my ($id) = @_;
                   2005: 	push(@allowed,$id);
                   2006:     }
                   2007:     sub disable_dimension_parsing {
                   2008: 	pop(@allowed);
                   2009:     }
                   2010:     sub skip_dimension_parsing {
                   2011: 	my ($check) = @_;
                   2012: 	if (!@allowed) { return 0;}
                   2013: 	# if unspecified allow any id
                   2014: 	if ($allowed[-1] eq undef) { return 0;}
                   2015: 
                   2016: 	return ($check ne $allowed[-1]);
                   2017:     }
                   2018: }
                   2019: 
1.151     albertel 2020: sub start_Question { return &start_Dimension(@_); }
1.1       albertel 2021: sub start_Dimension {
1.173     albertel 2022:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168     albertel 2023:     my $dim = &get_id($parstack,$safeeval);
                   2024:     my $previous_dim;
                   2025:     if (@Apache::bridgetask::dimension) {
                   2026: 	$previous_dim = $Apache::bridgetask::dimension[-1];
                   2027: 	push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
                   2028: 	     $dim);
1.173     albertel 2029: 	if(&skip_dimension_parsing($dim)) {
                   2030: 	    $dimension{$previous_dim}{'criteria.'.$dim} =
                   2031: 		$token->[4]
                   2032: 		.&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
                   2033: 					      $style)
                   2034: 		.'</'.$tagstack->[-1].'>';
                   2035: 	}
1.169     albertel 2036: 	$dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
                   2037: 	$dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
                   2038: 	    &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
                   2039: 	push(@{$dimension{$previous_dim}{'criterias'}},$dim);
1.171     albertel 2040: 	$dimension{$dim}{'nested'}=$previous_dim;
1.172     albertel 2041: 	&Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
1.168     albertel 2042:     } else {
                   2043: 	$Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'}=
                   2044: 	    &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
                   2045:     }
                   2046:     push(@Apache::bridgetask::dimension,$dim);
1.54      albertel 2047:     &Apache::lonxml::startredirection();
1.173     albertel 2048:     &enable_dimension_parsing($dim);
1.168     albertel 2049:     return &internal_location($dim);
1.1       albertel 2050: }
                   2051: 
1.160     albertel 2052: sub start_QuestionText {
                   2053:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168     albertel 2054:     my $dim = &get_dim_id();
1.160     albertel 2055:     my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
                   2056:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169     albertel 2057: 	$dimension{$dim}{'questiontext'}=$text;
1.160     albertel 2058:     }
                   2059:     return '';
                   2060: }
                   2061: 
                   2062: sub end_QuestionText {
                   2063:     return '';
                   2064: }
                   2065: 
1.13      albertel 2066: sub get_instance {
1.75      albertel 2067:     my ($dim)=@_;
                   2068:     my $rand_alg=&Apache::lonnet::get_rand_alg();
                   2069:     if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
                   2070: 	$rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
                   2071: 	$rand_alg eq '64bit4' ) {
                   2072: 	&Apache::response::pushrandomnumber();
1.169     albertel 2073: 	my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75      albertel 2074: 	my $num=@order;
                   2075: 	my $version=&get_version();
                   2076: 	my $which=($version-1)%$num;
                   2077: 	return $order[$which];
                   2078:     } else {
                   2079: 	my ($version,$previous) = &get_version();
                   2080: 	my $instance = 
                   2081: 	    $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
                   2082: 	if (defined($instance)) { return $instance; }
                   2083: 
                   2084: 	&Apache::response::pushrandomnumber();
1.173     albertel 2085: 	if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
                   2086: 	    my @instances = @{$dimension{$dim}{'instances'}};
                   2087: 	    # remove disabled instances
                   2088: 	    for (my $i=0; $i < $#instances; $i++) {
                   2089: 		if ($dimension{$dim}{$instances[$i].'.disabled'}) {
                   2090: 		    splice(@instances,$i,1);
                   2091: 		    $i--;
                   2092: 		}
                   2093: 	    }
                   2094: 	    @instances = &Math::Random::random_permutation(@instances);
                   2095: 	    $instance  = $instances[($version-1)%scalar(@instances)];
                   2096: 	    if ($version =~ /^\d$/) {
                   2097: 		$Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = 
                   2098: 		    $instance;
                   2099: 		$Apache::lonhomework::results{'INTERNAL_store'} = 1; 
1.75      albertel 2100: 	    }
                   2101: 	}
                   2102: 	&Apache::response::poprandomnumber();
                   2103: 	return $instance;
                   2104:     }
1.13      albertel 2105: }
                   2106: 
1.169     albertel 2107: sub get_criteria {
                   2108:     my ($what,$version,$dim,$id) = @_;
                   2109:     my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2110:     my $prefix = ($type eq 'criteria') ? "$dim.$id"
                   2111: 	                               : "$id";
                   2112:     my $entry = "resource.$version.0.$prefix.$what";
                   2113:     if (exists($Apache::lonhomework::results{$entry})) {
                   2114: 	return $Apache::lonhomework::results{$entry};
                   2115:     }
                   2116:     return $Apache::lonhomework::history{$entry};
                   2117: }
                   2118: 
1.18      albertel 2119: {
                   2120:     my $last_link;
1.122     albertel 2121:     sub link {
1.151     albertel 2122: 	my ($id) = @_;
                   2123: 	$id =~ s/\./_/g;
                   2124: 	return 'LC_GRADING_criteria_'.$id;
1.122     albertel 2125:     }
1.151     albertel 2126:     sub end_Question { return &end_Dimension(@_); }
1.18      albertel 2127:     sub end_Dimension {
                   2128: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54      albertel 2129: 	my $result=&Apache::lonxml::endredirection();
1.25      albertel 2130: 	my $dim=&get_id($parstack,$safeeval);
1.173     albertel 2131: 	if (&skip_dimension_parsing($dim)) {
                   2132: 	    &disable_dimension_parsing($dim);
                   2133: 	    pop(@Apache::bridgetask::dimension);
                   2134: 	    return;
                   2135: 	}
1.75      albertel 2136: 	my $instance=&get_instance($dim);
1.25      albertel 2137: 	my $version=&get_version();
1.18      albertel 2138: 	if ($target eq 'web') {
1.173     albertel 2139: 	    $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
1.76      albertel 2140: 	    my @instances = $instance;
                   2141: 	    if (&Apache::response::showallfoils()) {
1.169     albertel 2142: 		@instances = @{$dimension{$dim}{'instances'}};
1.76      albertel 2143: 	    }
1.160     albertel 2144: 	    my $shown_question_text;
1.76      albertel 2145: 	    foreach my $instance (@instances) {
1.173     albertel 2146: 		$result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
                   2147: 					 [@_]);
                   2148: 		$result .= &nested_parse(\$dimension{$dim}{'questiontext'},
                   2149: 					 [@_],{'set_dim_id' => undef});
1.169     albertel 2150: 		my $task_status = 
                   2151: 		    $Apache::lonhomework::history{"resource.$version.0.status"};
1.173     albertel 2152: 		if ($task_status ne 'pass' && $task_status ne 'fail') {
1.76      albertel 2153: 
1.173     albertel 2154: 		    foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2155: 				    @{$dimension{$dim}{'criterias'}}) {
                   2156: 			my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2157: 			&Apache::lonxml::debug("$id is $type");
                   2158: 			if ($type eq 'dimension') {
                   2159: 			    $result.=
                   2160: 				&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2161: 					      [@_],{'set_dim_id' => $id});
                   2162: 			}
                   2163: 		    }
                   2164: 		} else {
1.89      albertel 2165: 		    my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
1.76      albertel 2166: 		    my $mandatory='Mandatory';
                   2167: 		    if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
                   2168: 			$mandatory='Optional';
                   2169: 		    }
1.116     albertel 2170: 		    my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
1.76      albertel 2171: 		    if ($dim_status eq 'pass') {
                   2172: 			$dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1.54      albertel 2173: 		    }
1.76      albertel 2174: 		    if ($dim_status eq 'fail') {
                   2175: 			$dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1.53      albertel 2176: 		    }
1.76      albertel 2177: 		    my $man_count=0;
                   2178: 		    my $man_passed=0;
                   2179: 		    my $opt_count=0;
                   2180: 		    my $opt_passed=0;
1.169     albertel 2181: 		    foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
                   2182: 				     @{$dimension{$dim}{'criterias'}} ) {
                   2183: 			my $status = &get_criteria('status',$version,$dim,$id);
                   2184: 			if ($dimension{$dim}{'criteria.'.$id.'.mandatory'} 
1.76      albertel 2185: 			    eq 'N') {
                   2186: 			    $opt_count++;
1.169     albertel 2187: 			    if ($status eq 'pass') { $opt_passed++; }
1.76      albertel 2188: 			} else {
                   2189: 			    $man_count++;
1.169     albertel 2190: 			    if ($status eq 'pass') { $man_passed++; }
1.76      albertel 2191: 			}
1.22      albertel 2192: 		    }
1.76      albertel 2193: 		    if ($man_passed eq $man_count) { $man_passed='all'; }
1.151     albertel 2194: 
1.169     albertel 2195: 		    my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
1.151     albertel 2196: 		    if ($opt_req !~ /\S/) {
                   2197: 			$opt_req=
                   2198: 			    &Apache::lonxml::get_param('OptionalRequired',
                   2199: 						       $parstack,$safeeval);
                   2200: 			if ($opt_req !~ /\S/) { $opt_req = 0; }
                   2201: 		    }
1.76      albertel 2202: 		    $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>";
                   2203: 
                   2204: 		    my $internal_location=&internal_location($dim);
                   2205: 		    $result=~s/\Q$internal_location\E/$dim_info/;
                   2206: 
1.169     albertel 2207: 		    foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2208: 				    @{$dimension{$dim}{'criterias'}}) {
                   2209: 			my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.171     albertel 2210: 			if ($type eq 'dimension') {
                   2211: 			    $result.=$dimension{$id}{'result'};
                   2212: 			    next;
                   2213: 			}
1.169     albertel 2214: 			my $status= &get_criteria('status', $version,$dim,$id);
                   2215: 			my $comment=&get_criteria('comment',$version,$dim,$id);
                   2216: 			my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1.76      albertel 2217: 			if ($mandatory) {
                   2218: 			    $mandatory='Mandatory';
                   2219: 			} else {
                   2220: 			    $mandatory='Optional';
                   2221: 			}
                   2222: 			if ($status eq 'fail') {
                   2223: 			} elsif ($status eq 'pass') {
                   2224: 			} else {
                   2225: 			    &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
                   2226: 			}
                   2227: 			my $status_display=$status;
                   2228: 			$status_display=~s/^([a-z])/uc($1)/e;
1.116     albertel 2229: 			$result.=
                   2230: 			    '<div class="LC_'.$status.' LC_criteria"><h4>'
                   2231: 			    .$mandatory.' Criteria</h4><p>';
1.173     albertel 2232: 			$result.=
                   2233: 			    &nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2234: 					  [@_],{'set_dim_id' => $id});
1.116     albertel 2235: 			$result.='</p><p class="LC_grade">'.$status_display.'</p>';
1.169     albertel 2236: 			if ($comment) {
                   2237: 			    $result.='<p class="LC_comment">'.
                   2238: 				&mt('Comment: [_1]',$comment).'</p>';
1.76      albertel 2239: 			}
                   2240: 			$result.='</div>';
1.22      albertel 2241: 		    }
                   2242: 		}
                   2243: 	    }
1.18      albertel 2244: 	} elsif ($target eq 'webgrade') {
1.47      albertel 2245: 	    # in case of any side effects that we need
1.173     albertel 2246: 	    &nested_parse(\$dimension{$dim}{'intro'},[@_]);
                   2247: 	    &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
                   2248: 	    $result.=
                   2249: 		&nested_parse(\$dimension{$dim}{'questiontext'},[@_],
1.180     albertel 2250: 			      {'set_dim_id'          => undef,
                   2251: 			       'delayed_dim_results' => 1});
1.169     albertel 2252: 	    foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2253: 			    @{$dimension{$dim}{'criterias'}} ) {
                   2254: 		my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.171     albertel 2255: 		if ($type eq 'dimension') {
                   2256: 		    # dimensional 'criteria' don't get assigned grades
1.173     albertel 2257: 		    $result.=
                   2258: 			&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2259: 				      [@_],{'set_dim_id' => $id});
1.171     albertel 2260: 		    next;
                   2261: 		}
1.169     albertel 2262: 
1.151     albertel 2263: 		my $link=&link($id);
1.169     albertel 2264: 		my $status= &get_criteria('status',$version,$dim,$id);
1.120     albertel 2265: 		$result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
1.136     albertel 2266: 		    '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
1.173     albertel 2267: 		$result.=
                   2268: 		    &nested_parse(\$dimension{$dim}{'criteria.'.$id},[@_]);
                   2269: 
1.111     albertel 2270: 		$result.='</div>'."\n".
1.120     albertel 2271: 		    '<div class="LC_GRADING_grade">'."\n".
                   2272: 		    '<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
                   2273: 		    '<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
                   2274: 		    '<label class="LC_GRADING_pass"><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label>'."\n".
                   2275: 		    '<label class="LC_GRADING_review"><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label>'."\n".
1.111     albertel 2276: 		    '</div>'."\n".
1.120     albertel 2277: 		    '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
1.169     albertel 2278: 		    '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode(&get_criteria('comment',$version,$dim,$id),'<>"&').'</textarea>'."\n".
1.111     albertel 2279: 		    '</label>'."\n".
1.120     albertel 2280: 		    '<ul class="LC_GRADING_navbuttons">'."\n".
1.111     albertel 2281: 		    '<li><a href="#'.$last_link.'">Prev</a></li>'."\n".
                   2282: 		    '<li><a href="#next_'.$link.'">Next</a></li>'."\n".
                   2283: 		    '</ul>'."\n".
                   2284:                     '</div>'."\n";
1.151     albertel 2285: 		$result.=&grading_history($version,$dim,$id);
1.18      albertel 2286: 		$last_link=$link;
                   2287: 	    }
1.180     albertel 2288: 	    if (&nest()) {
1.173     albertel 2289: 		&Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
                   2290: 		$dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
1.171     albertel 2291: 		undef($result);
                   2292: 	    }
1.22      albertel 2293: 	} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19      albertel 2294: 	    my $optional_passed=0;
1.20      albertel 2295: 	    my $mandatory_failed=0;
                   2296: 	    my $ungraded=0;
                   2297: 	    my $review=0;
1.153     albertel 2298: 
1.173     albertel 2299: 	    $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
                   2300: 	    $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
                   2301: 				     [@_]);
                   2302: 	    $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
                   2303: 				     [@_],{'set_dim_id' => undef});
1.160     albertel 2304: 
1.169     albertel 2305: 	    foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
                   2306: 			    @{$dimension{$dim}{'criterias'}}) {
1.151     albertel 2307: 		my $link=&link($id);
1.169     albertel 2308: 
                   2309: 		my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
                   2310: 		if ($type eq 'criteria') {
                   2311: 		    # dimensional 'criteria' don't get assigned grades
                   2312: 		    $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
                   2313: 		    $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1.173     albertel 2314: 		} else {
                   2315: 		    $result .=
                   2316: 			&nested_parse(\$dimension{$dim}{'criteria.'.$id},
                   2317: 				      [@_],{'set_dim_id' => $id});
1.169     albertel 2318: 		}
                   2319: 		my $status= &get_criteria('status',$version,$dim,$id);
                   2320: 
                   2321: 		my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1.20      albertel 2322: 		if ($status eq 'pass') {
                   2323: 		    if (!$mandatory) { $optional_passed++; }
                   2324: 		} elsif ($status eq 'fail') {
                   2325: 		    if ($mandatory) { $mandatory_failed++; }
1.21      albertel 2326: 		} elsif ($status eq 'review') {
                   2327: 		    $review++;
1.20      albertel 2328: 		} elsif ($status eq 'ungraded') {
                   2329: 		    $ungraded++;
1.21      albertel 2330: 		} else {
1.47      albertel 2331: 		    $ungraded++;
1.19      albertel 2332: 		}
                   2333: 	    }
1.151     albertel 2334: 	    # FIXME optional required can apply to only <instance> right now...
1.169     albertel 2335: 	    my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
1.151     albertel 2336: 	    if ($opt_req !~ /\S/) {
                   2337: 		$opt_req=
                   2338: 		    &Apache::lonxml::get_param('OptionalRequired',
                   2339: 					       $parstack,$safeeval);
                   2340: 		if ($opt_req !~ /\S/) { $opt_req = 0; }
                   2341: 	    }
                   2342: 	    if ($optional_passed < $opt_req) {
1.20      albertel 2343: 		$mandatory_failed++;
                   2344: 	    }
1.169     albertel 2345: 	    &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.20      albertel 2346: 	    if ($review) {
1.89      albertel 2347: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 2348: 		    'review';
1.20      albertel 2349: 	    } elsif ($ungraded) {
1.89      albertel 2350: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 2351: 		    'ungraded';
1.20      albertel 2352: 	    } elsif ($mandatory_failed) {
1.89      albertel 2353: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 2354: 		    'fail';
1.20      albertel 2355: 	    } else {
1.91      albertel 2356: 		$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22      albertel 2357: 		    'pass';
1.20      albertel 2358: 	    }
1.69      albertel 2359: 	} else {
                   2360: 	    # any other targets no output
                   2361: 	    undef($result);
1.13      albertel 2362: 	}
1.173     albertel 2363: 	&disable_dimension_parsing();
1.169     albertel 2364: 	pop(@Apache::bridgetask::dimension);
1.18      albertel 2365: 	return $result;
1.1       albertel 2366:     }
1.162     albertel 2367: 
                   2368:     sub end_Setup {
                   2369: 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   2370: 	my $result=&Apache::lonxml::endredirection();
                   2371: 	my $dim=&get_id($parstack,$safeeval);
                   2372: 	my $instance=&get_instance($dim);
                   2373: 	my $version=&get_version();
                   2374: 	if ($target eq 'web') {
                   2375: 	    @Apache::scripttag::parser_env = @_;
1.169     albertel 2376: 	    $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
1.162     albertel 2377: 	    my @instances = $instance;
                   2378: 	    if (&Apache::response::showallfoils()) {
1.169     albertel 2379: 		@instances = @{$dimension{$dim}{'instances'}};
1.162     albertel 2380: 	    }
                   2381: 	    foreach my $instance (@instances) {
                   2382: 		@Apache::scripttag::parser_env = @_;
1.169     albertel 2383: 		$result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162     albertel 2384: 		@Apache::scripttag::parser_env = @_;
1.169     albertel 2385: 		$result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162     albertel 2386: 	    }
                   2387: 	} elsif ($target eq 'webgrade' 
                   2388: 		 || $target eq 'grade' && $env{'form.webgrade'}) {
                   2389: 	    # in case of any side effects that we need
                   2390: 	    @Apache::scripttag::parser_env = @_;
1.169     albertel 2391: 	    &Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
1.162     albertel 2392: 	    @Apache::scripttag::parser_env = @_;
1.169     albertel 2393: 	    &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162     albertel 2394: 	    @Apache::scripttag::parser_env = @_;
1.169     albertel 2395: 	    &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162     albertel 2396: 	} else {
                   2397: 	    # any other targets no output
                   2398: 	    undef($result);
                   2399: 	}
1.169     albertel 2400: 	pop(@Apache::bridgetask::dimension);
1.162     albertel 2401: 	return $result;
                   2402:     }
1.1       albertel 2403: }
                   2404: 
1.113     albertel 2405: sub grading_history {
1.151     albertel 2406:     my ($version,$dim,$id) = @_;
1.113     albertel 2407:     if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
                   2408: 	return '';
                   2409:     }
                   2410:     my ($result,$grader);
1.151     albertel 2411:     my $scope="resource.$version.0.$dim.$id";
1.113     albertel 2412:     foreach my $t (1..$Apache::lonhomework::history{'version'}) {
                   2413: 	if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
                   2414: 	    my ($gname,$gdom) = 
1.138     albertel 2415: 		split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113     albertel 2416: 	    my $fullname = &Apache::loncommon::plainname($gname,$gdom);
                   2417: 	    $grader = &Apache::loncommon::aboutmewrapper($fullname,
                   2418: 							 $gname,$gdom);
                   2419: 	}
                   2420: 	my $entry;
                   2421: 	if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
                   2422: 	    $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
                   2423: 	}
                   2424: 	if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
                   2425: 	    $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
                   2426: 	}
                   2427: 	if ($entry) {
                   2428: 	    $result.= "<li>$grader : $entry </li>";
                   2429: 	}
                   2430:     }
                   2431:     if ($result) {
1.120     albertel 2432: 	return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
1.113     albertel 2433:     }
                   2434:     return '';
                   2435: }
                   2436: 
1.1       albertel 2437: sub start_IntroParagraph {
1.87      albertel 2438:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1       albertel 2439:     my $result;
1.168     albertel 2440:     my $dim = &get_dim_id();
1.153     albertel 2441:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151     albertel 2442: 	if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169     albertel 2443: 	    $dimension{$dim}{'intro'}=
1.151     albertel 2444: 		&Apache::lonxml::get_all_text('/introparagraph',
                   2445: 					      $parser,$style);
                   2446:        	} elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2447: 	    &Apache::lonxml::startredirection();
1.1       albertel 2448: 	}
1.47      albertel 2449: 	
1.1       albertel 2450:     }
                   2451:     return $result;
                   2452: }
                   2453: 
                   2454: sub end_IntroParagraph {
1.127     albertel 2455:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128     albertel 2456:     if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127     albertel 2457: 	my $result = &Apache::lonxml::endredirection();
                   2458:     }
1.1       albertel 2459: }
                   2460: 
                   2461: sub start_Instance {
                   2462:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168     albertel 2463:     my $dim = &get_dim_id();
                   2464:     my $id  = &get_id($parstack,$safeeval);
1.169     albertel 2465:     push(@{$dimension{$dim}{'instances'}},$id);
1.168     albertel 2466:     push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19      albertel 2467:     push(@Apache::bridgetask::instancelist,$id);
1.169     albertel 2468:     $dimension{$dim}{$id.'.optionalrequired'}=
1.19      albertel 2469: 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75      albertel 2470:     my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
                   2471:     if (lc($disabled) eq 'yes') {
1.169     albertel 2472: 	$dimension{$dim}{$id.'.disabled'}='1';
1.75      albertel 2473:     }
1.1       albertel 2474:     return '';
                   2475: }
                   2476: 
                   2477: sub end_Instance {
                   2478: }
                   2479: 
                   2480: sub start_InstanceText {
1.87      albertel 2481:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168     albertel 2482:     my $dim = &get_dim_id();
                   2483:     my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.87      albertel 2484:     my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
1.153     albertel 2485:     if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169     albertel 2486: 	$dimension{$dim}{$instance_id.'.text'}=$text;
1.1       albertel 2487:     }
                   2488:     return '';
                   2489: }
                   2490: 
                   2491: sub end_InstanceText {
                   2492:     return '';
                   2493: }
                   2494: 
                   2495: sub start_Criteria {
1.87      albertel 2496:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   2497:     my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.21      albertel 2498:     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.168     albertel 2499: 	my $dim = &get_dim_id();
1.19      albertel 2500: 	my $id=&get_id($parstack,$safeeval);
1.169     albertel 2501: 	&Apache::lonxml::debug("Criteria $id with $dim");
1.151     albertel 2502: 	if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168     albertel 2503: 	    my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169     albertel 2504: 	    $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
                   2505: 	    $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
                   2506: 	    $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151     albertel 2507: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169     albertel 2508: 	    push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151     albertel 2509: 	} else {
1.169     albertel 2510: 	    $dimension{$dim}{'criteria.'.$id}=$criteria;
                   2511: 	    $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
                   2512: 	    $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151     albertel 2513: 		&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169     albertel 2514: 	    push(@{$dimension{$dim}{'criterias'}},$id);
1.151     albertel 2515: 	}
1.1       albertel 2516:     }
                   2517:     return '';
                   2518: }
                   2519: 
1.47      albertel 2520: sub end_Criteria {
                   2521: }
                   2522: 
1.186     albertel 2523: sub start_GraderNote {
                   2524:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   2525:     
                   2526:     if ($target eq 'webgrade') {
1.187     albertel 2527: 	return '<div class="LC_GRADING_gradernote"><b>'.
                   2528: 	    &mt('Note to graders:').'</b>';
1.186     albertel 2529:     }
                   2530:     my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style); 
                   2531:     return;
                   2532: }
                   2533: 
                   2534: sub end_GraderNote {
                   2535:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                   2536: 
                   2537:     if ($target eq 'webgrade') {
                   2538: 	return '</div>';
                   2539:     }
                   2540:     return;
                   2541: }
                   2542: 
                   2543: 
                   2544: 
1.4       albertel 2545: sub proctor_validation_screen {
                   2546:     my ($slot) = @_;
1.185     albertel 2547:     my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
1.5       albertel 2548:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44      albertel 2549:     my $name=&Apache::loncommon::plainname($user,$domain);
                   2550:     
1.4       albertel 2551:     my $msg;
1.11      albertel 2552:     if ($env{'form.proctorpassword'}) {
1.4       albertel 2553: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
                   2554: 	    .'</font></p>';
                   2555:     }
1.47      albertel 2556:     if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4       albertel 2557:     my $result= (<<ENDCHECKOUT);
                   2558: <h2>Proctor Validation</h2>
                   2559:     <p>Your room's proctor needs to validate your access to this resource.</p>
                   2560:     $msg
1.115     albertel 2561: <form name="checkout" method="post" action="$env{'request.uri'}">
1.4       albertel 2562: <input type="hidden" name="validate" value="yes" />
                   2563: <input type="hidden" name="submitted" value="yes" />
                   2564: <table>
1.44      albertel 2565:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4       albertel 2566:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46      albertel 2567:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4       albertel 2568: </table>
                   2569: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
1.44      albertel 2570: <table border="1">
                   2571:   <tr><td>
                   2572:     <table>
                   2573:       <tr><td colspan="2">Student who should be logged in is:</td></tr>
                   2574:       <tr><td>Name:</td><td>$name</td></tr>
1.45      albertel 2575:       <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.138     albertel 2576:       <tr><td>Usename</td><td>$user:$domain</td></tr>
1.44      albertel 2577:       <tr><td colspan="2"><img src="$url" /></td></tr>
                   2578:     </table>
                   2579:   </tr></td>
                   2580: </table>
1.4       albertel 2581: </form>
                   2582: ENDCHECKOUT
                   2583:     return $result;
                   2584: }
                   2585: 
1.1       albertel 2586: 1;
                   2587: __END__

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