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

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

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