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

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

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