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

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

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