File:  [LON-CAPA] / loncom / homework / bridgetask.pm
Revision 1.16: download - view: text, annotated - select for diffs
Tue May 3 06:44:56 2005 UTC (19 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- setup env so lonxml::whichuser returns data for user being graded
- need to reset rndseed, since we don't know til the end of <Task> who we are grading
- remember who we are grading

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

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