File:  [LON-CAPA] / loncom / homework / bridgetask.pm
Revision 1.13: download - view: text, annotated - select for diffs
Fri Apr 29 21:22:33 2005 UTC (19 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- adding 'webgrade' target for bridgetasks

    1: # The LearningOnline Network with CAPA 
    2: # definition of tags that give a structure to a document
    3: #
    4: # $Id: bridgetask.pm,v 1.13 2005/04/29 21:22:33 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: }
   56: 
   57: sub proctor_check_auth {
   58:     my ($slot)=@_;
   59:     my $user=$env{'form.proctorname'};
   60:     my $domain=$env{'form.proctordomain'};
   61:     
   62:     my @allowed=split(",",$slot->{'proctor'});
   63:     foreach my $possible (@allowed) {
   64: 	my ($puser,$pdom)=(split('@',$possible));
   65: 	if ($puser eq $user && $pdom eq $domain) {
   66: 	    my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
   67: 	    if ($authhost ne 'no_host') {
   68: 		$Apache::lonhomework::results{'resource.checkedin'}=
   69: 		    $user.'@'.$domain;
   70: 		return 1;
   71: 	    }
   72: 	}
   73:     }
   74:     return 0;
   75: }
   76: 
   77: sub add_previous_version_button {
   78:     my $result;
   79:     $result.=&mt(' Show a previously done version: [_1]','<select name="previousversion">
   80: <option>Pick one</option>
   81: </select>');
   82:     return $result;
   83: }
   84: 
   85: sub add_grading_button {
   86:     my $result;
   87:     $result.=' <input type="submit" name="gradeasubmission" value="'.
   88: 	&mt("Get a submission to grade").'" />';
   89:     $result.='<input type="hidden" name="grade_target" value="webgrade" />';
   90:     return $result;
   91: }
   92: 
   93: sub start_Task {
   94:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   95: 
   96:     &Apache::structuretags::initialize_storage();
   97:     &Apache::lonhomework::showhash(%Apache::lonhomework::history);
   98:     my ($status,$accessmsg,$slot);
   99:     $Apache::lonhomework::parsing_a_task=1;
  100:     #should get back a <html> or the neccesary stuff to start XML/MathML
  101:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
  102: 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
  103: 
  104:     if ($target eq 'web') {
  105: 	$body_tag_start.=&add_previous_version_button();
  106: 	if ($Apache::lonhomework::modifygrades) {
  107: 	    $body_tag_start.='<form name="gradesubmission" method="POST" action="';
  108: 	    my $uri=$env{'request.uri'};
  109: 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
  110: 	    $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
  111: 	}
  112:     }
  113:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  114: 	$target eq 'tex') {
  115: 	($status,$accessmsg,$slot) = 
  116: 	    &Apache::lonhomework::check_task_access('0');
  117: 	push(@Apache::inputtags::status,$status);
  118: 	my $expression='$external::datestatus="'.$status.'";';
  119: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
  120: 	&Apache::run::run($expression,$safeeval);
  121: 	&Apache::lonxml::debug("Got $status");
  122: 	if (( $status eq 'CLOSED' ) ||
  123: 	    ( $status eq 'BANNED') ||
  124: 	    ( $status eq 'UNAVAILABLE') ||
  125: 	    ( $status eq 'NOT_IN_A_SLOT') ||
  126: 	    ( $status eq 'NEEDS_CHECKIN') ||
  127: 	    ( $status eq 'INVALID_ACCESS')) {
  128: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
  129: 	    if ( $target eq "web" ) {
  130: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
  131: 		my $msg;
  132: 		if ($status eq 'UNAVAILABLE') {
  133: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
  134: 		} elsif ($status eq 'NOT_IN_A_SLOT') {
  135: 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
  136: 		} elsif ($status eq 'NEEDS_CHECKIN') {
  137: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
  138: 			'</h1>'.&proctor_validation_screen($slot);
  139: 		} elsif ($status ne 'NOT_YET_VIEWED') {
  140: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
  141: 		}
  142: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
  143: 		    $msg.='The problem '.$accessmsg;
  144: 		}
  145: 		$result.=$msg.'<br />';
  146: 	    } elsif ($target eq 'tex') {
  147: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
  148: 		if ($status eq 'UNAVAILABLE') {
  149: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
  150: 		} else {
  151: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
  152: 		}
  153: 	    } elsif ($target eq 'grade') {
  154: 		if ($status eq 'NEEDS_CHECKIN') {
  155: 		    if (&proctor_check_auth($slot)) {
  156: 			#FIXME immeadiatly add this to the grading queue
  157:                         #      with slot->{'endtime'} for when grading can 
  158:                         #      begin on this resource
  159:  		    }
  160: 		}
  161: 	    }
  162: 	} elsif ($target eq 'web') {
  163: 	    my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
  164: 	    $result.="$head_tag_start<title>$name</title></head>
  165:               $body_tag_start \n $form_tag_start".	
  166: 	      '<input type="hidden" name="submitted" value="yes" />';
  167: 	    # if we are viewing someone else preserve that info
  168: 	    if (defined $env{'form.grade_symb'}) {
  169: 		foreach my $field ('symb','courseid','domain','username') {
  170: 		    $result .= '<input type="hidden" name="grade_'.$field.
  171: 			'" value="'.$env{"form.grade_$field"}.'" />'."\n";
  172: 		}
  173: 	    }
  174: 	}
  175:     } elsif ($target eq 'webgrade') {
  176: 	$result.=$head_tag_start.$body_tag_start.$form_tag_start.
  177: 	    'Yahoo!';
  178:     } else {
  179: 	# page_start returned a starting result, delete it if we don't need it
  180: 	$result = '';
  181:     }
  182:     return $result;
  183: }
  184: 
  185: sub end_Task {
  186:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  187:     my $result='';
  188:     my $status=$Apache::inputtags::status['-1'];
  189:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
  190: 	$target eq 'tex' || $target eq 'webgrade') {
  191: 	if (
  192: 	    (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
  193: 	    ($target eq 'answer') || ($target eq 'tex')
  194: 	   ) {
  195: 	    if ($target eq 'web') {
  196: 		if ($status eq 'CAN_ANSWER') {
  197: 		    $result.='<table border="1">'.
  198: 			&Apache::inputtags::file_selector('0',"bridgetask","*",
  199: 							  'portfolioonly').
  200: 							  "</table>";
  201: 		    $result.=&Apache::inputtags::gradestatus('0');
  202: 		}
  203: 	    } 
  204: 	    if ($target eq 'web' || $target eq 'webgrade') {
  205: 		$result.=&Apache::lonxml::xmlend().'</html>';
  206: 	    }
  207: 	}
  208: 	if ($target eq 'grade') {
  209: 	    my $award='SUBMITTED';
  210: 	    &Apache::essayresponse::file_submission('0','bridgetask','portfiles',$award);
  211: 	    if ($Apache::lonhomework::results{"resource.0.bridgetask.portfiles"}) {
  212: 		$Apache::lonhomework::results{"resource.0.tries"}=
  213: 		    1+$Apache::lonhomework::history{"resource.0.tries"};
  214: 	    }
  215: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
  216: 	    &Apache::structuretags::finalize_storage();
  217: 	}
  218:     } elsif ($target eq 'meta') {
  219: 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
  220: 	#$result.=&Apache::response::meta_part_order();
  221: 	#$result.=&Apache::response::meta_response_order();
  222:     }
  223:     undef($Apache::lonhomework::parsing_a_task);
  224:     return $result;
  225: }
  226: 
  227: sub start_ClosingParagraph {
  228:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  229:     my $result;
  230:     if ($target eq 'web') {
  231:     } elsif ($target eq 'webgrade') {
  232: 	&Apache::lonxml::startredirection();
  233:     }
  234:     return $result;
  235: }
  236: 
  237: sub end_ClosingParagraph {
  238:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  239:     my $result;
  240:     if ($target eq 'web') {
  241:     } elsif ($target eq 'webgrade') {
  242: 	&Apache::lonxml::endredirection();
  243:     }
  244:     return $result;
  245: }
  246: 
  247: my %dimension;
  248: sub start_Dimension {
  249:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  250:     undef(%dimension);
  251:     my $dim_id=$Apache::lonxml::curdepth;
  252:     $Apache::bridgetask::dimension=$dim_id;
  253:     push(@Apache::bridgetask::dimensionlist,$dim_id);
  254:     undef(@Apache::bridgetask::instance);
  255:     return '';
  256: }
  257: 
  258: sub get_instance {
  259:     #FIXME just grabbing the first one for now, need
  260:     #to randomly pick one until all have been seen
  261:     #then start repicking
  262:     &Apache::response::pushrandomnumber();
  263:     my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
  264:     return $order[0];
  265: }
  266: 
  267: sub end_Dimension {
  268:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  269:     my $result;
  270:     if ($target eq 'web') {
  271: 	my $instance=&get_instance();
  272: 	$result=$dimension{'intro'}.$dimension{$instance.'.text'};
  273:     } elsif ($target eq 'webgrade') {
  274: 	my $instance=&get_instance();
  275: 	$result.='<table>';
  276: 	foreach my $id (@{$dimension{$instance.'.criterias'}}) {
  277: 	    $result.='<tr><td>'.
  278: 		$dimension{$instance.'.criteria.'.$id}.'</td></tr>';
  279: 	}
  280: 	$result.='</table>';
  281:     }
  282:     return $result;
  283: }
  284: 
  285: sub start_IntroParagraph {
  286:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  287:     my $result;
  288:     if ($target eq 'web' || $target eq 'webgrade') {
  289: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
  290: 	    &Apache::lonxml::startredirection();
  291: 	}
  292:     }
  293:     return $result;
  294: }
  295: 
  296: sub end_IntroParagraph {
  297:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  298:     my $result;
  299:     if ($target eq 'web' || $target eq 'webgrade') {
  300: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
  301: 	    $dimension{'intro'}=&Apache::lonxml::endredirection();
  302: 	}
  303:     }
  304:     return $result;
  305: }
  306: 
  307: sub start_Instance {
  308:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  309:     push(@{$dimension{'instances'}},$Apache::lonxml::curdepth);
  310:     push(@Apache::bridgetask::instance,$Apache::lonxml::curdepth);
  311:     push(@Apache::bridgetask::instancelist,$Apache::lonxml::curdepth);
  312:     return '';
  313: }
  314: 
  315: sub end_Instance {
  316:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  317:     return '';
  318: }
  319: 
  320: sub start_InstanceText {
  321:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  322:     if ($target eq 'web' || $target eq 'webgrade') {
  323: 	&Apache::lonxml::startredirection();
  324:     }
  325:     return '';
  326: }
  327: 
  328: sub end_InstanceText {
  329:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  330:     my $instance_id=$Apache::bridgetask::instance[-1];
  331:     if ($target eq 'web' || $target eq 'webgrade') {
  332: 	$dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
  333:     }
  334:     return '';
  335: }
  336: 
  337: sub start_Criteria {
  338:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  339:     if ($target eq 'web' || $target eq 'webgrade') {
  340: 	&Apache::lonxml::startredirection();
  341:     }
  342:     return '';
  343: }
  344: 
  345: sub end_Criteria {
  346:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  347:     my $instance_id=$Apache::bridgetask::instance[-1];
  348:     if ($target eq 'web' || $target eq 'webgrade') {
  349: 	my $criteria=&Apache::lonxml::endredirection();
  350: 	my $id=$Apache::lonxml::curdepth;
  351: 	$dimension{$instance_id.'.criteria.'.$id}=$criteria;
  352: 	push(@{$dimension{$instance_id.'.criterias'}},$id);
  353:     }
  354:     return '';
  355: }
  356: 
  357: sub proctor_validation_screen {
  358:     my ($slot) = @_;
  359:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
  360:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
  361:     $user=$env{'form.proctorname'};
  362:     if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
  363:     my $msg;
  364:     if ($env{'form.proctorpassword'}) {
  365: 	$msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
  366: 	    .'</font></p>';
  367:     }
  368:     my $result= (<<ENDCHECKOUT);
  369: <h2>Proctor Validation</h2>
  370:     <p>Your room's proctor needs to validate your access to this resource.</p>
  371:     $msg
  372: <form name="checkout" method="POST" action="$env{'request.uri'}">
  373: <input type="hidden" name="validate" value="yes" />
  374: <input type="hidden" name="submitted" value="yes" />
  375: <table>
  376:   <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
  377:   <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
  378:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
  379: </table>
  380: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
  381: Student who should be logged in is:<br />
  382: <img src="$url" /><br />
  383: </form>
  384: ENDCHECKOUT
  385:     return $result;
  386: }
  387: 
  388: 1;
  389: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.