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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
                      3: #
1.13    ! albertel    4: # $Id: bridgetask.pm,v 1.12 2005/04/08 19:21:52 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=();
                     55: }
                     56: 
1.4       albertel   57: sub proctor_check_auth {
                     58:     my ($slot)=@_;
1.11      albertel   59:     my $user=$env{'form.proctorname'};
                     60:     my $domain=$env{'form.proctordomain'};
1.4       albertel   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) {
1.11      albertel   66: 	    my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4       albertel   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: 
1.8       albertel   77: sub add_previous_version_button {
                     78:     my $result;
1.9       albertel   79:     $result.=&mt(' Show a previously done version: [_1]','<select name="previousversion">
1.8       albertel   80: <option>Pick one</option>
1.9       albertel   81: </select>');
1.8       albertel   82:     return $result;
                     83: }
                     84: 
1.13    ! albertel   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: 
1.1       albertel   93: sub start_Task {
                     94:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     95: 
1.4       albertel   96:     &Apache::structuretags::initialize_storage();
                     97:     &Apache::lonhomework::showhash(%Apache::lonhomework::history);
                     98:     my ($status,$accessmsg,$slot);
                     99:     $Apache::lonhomework::parsing_a_task=1;
1.1       albertel  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: 
1.8       albertel  104:     if ($target eq 'web') {
                    105: 	$body_tag_start.=&add_previous_version_button();
1.13    ! albertel  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: 	}
1.8       albertel  112:     }
1.1       albertel  113:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    114: 	$target eq 'tex') {
1.4       albertel  115: 	($status,$accessmsg,$slot) = 
                    116: 	    &Apache::lonhomework::check_task_access('0');
1.9       albertel  117: 	push(@Apache::inputtags::status,$status);
1.1       albertel  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') ||
1.3       albertel  125: 	    ( $status eq 'NOT_IN_A_SLOT') ||
1.4       albertel  126: 	    ( $status eq 'NEEDS_CHECKIN') ||
1.1       albertel  127: 	    ( $status eq 'INVALID_ACCESS')) {
                    128: 	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
                    129: 	    if ( $target eq "web" ) {
1.4       albertel  130: 		$result.= $head_tag_start.'</head>'.$body_tag_start;
                    131: 		my $msg;
1.1       albertel  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>';
1.3       albertel  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>';
1.4       albertel  136: 		} elsif ($status eq 'NEEDS_CHECKIN') {
                    137: 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
                    138: 			'</h1>'.&proctor_validation_screen($slot);
1.1       albertel  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: 		}
1.4       albertel  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: 		}
1.1       albertel  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
1.11      albertel  168: 	    if (defined $env{'form.grade_symb'}) {
1.1       albertel  169: 		foreach my $field ('symb','courseid','domain','username') {
                    170: 		    $result .= '<input type="hidden" name="grade_'.$field.
1.11      albertel  171: 			'" value="'.$env{"form.grade_$field"}.'" />'."\n";
1.1       albertel  172: 		}
                    173: 	    }
                    174: 	}
1.13    ! albertel  175:     } elsif ($target eq 'webgrade') {
        !           176: 	$result.=$head_tag_start.$body_tag_start.$form_tag_start.
        !           177: 	    'Yahoo!';
1.1       albertel  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' ||
1.13    ! albertel  190: 	$target eq 'tex' || $target eq 'webgrade') {
1.1       albertel  191: 	if (
1.11      albertel  192: 	    (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1       albertel  193: 	    ($target eq 'answer') || ($target eq 'tex')
                    194: 	   ) {
                    195: 	    if ($target eq 'web') {
1.9       albertel  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: 		}
1.13    ! albertel  203: 	    } 
        !           204: 	    if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  205: 		$result.=&Apache::lonxml::xmlend().'</html>';
                    206: 	    }
                    207: 	}
                    208: 	if ($target eq 'grade') {
1.12      albertel  209: 	    my $award='SUBMITTED';
                    210: 	    &Apache::essayresponse::file_submission('0','bridgetask','portfiles',$award);
1.10      albertel  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: 	    }
1.4       albertel  215: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    216: 	    &Apache::structuretags::finalize_storage();
1.1       albertel  217: 	}
                    218:     } elsif ($target eq 'meta') {
1.2       albertel  219: 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1       albertel  220: 	#$result.=&Apache::response::meta_part_order();
                    221: 	#$result.=&Apache::response::meta_response_order();
                    222:     }
1.4       albertel  223:     undef($Apache::lonhomework::parsing_a_task);
1.1       albertel  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') {
1.13    ! albertel  231:     } elsif ($target eq 'webgrade') {
        !           232: 	&Apache::lonxml::startredirection();
1.1       albertel  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') {
1.13    ! albertel  241:     } elsif ($target eq 'webgrade') {
        !           242: 	&Apache::lonxml::endredirection();
1.1       albertel  243:     }
                    244:     return $result;
                    245: }
                    246: 
                    247: my %dimension;
                    248: sub start_Dimension {
                    249:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    250:     undef(%dimension);
1.9       albertel  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);
1.1       albertel  255:     return '';
                    256: }
                    257: 
1.13    ! albertel  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: 
1.1       albertel  267: sub end_Dimension {
                    268:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    269:     my $result;
                    270:     if ($target eq 'web') {
1.13    ! albertel  271: 	my $instance=&get_instance();
1.9       albertel  272: 	$result=$dimension{'intro'}.$dimension{$instance.'.text'};
1.13    ! albertel  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>';
1.1       albertel  281:     }
                    282:     return $result;
                    283: }
                    284: 
                    285: sub start_IntroParagraph {
                    286:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    287:     my $result;
1.13    ! albertel  288:     if ($target eq 'web' || $target eq 'webgrade') {
        !           289: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel  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;
1.13    ! albertel  299:     if ($target eq 'web' || $target eq 'webgrade') {
        !           300: 	if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1       albertel  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);
1.9       albertel  310:     push(@Apache::bridgetask::instance,$Apache::lonxml::curdepth);
                    311:     push(@Apache::bridgetask::instancelist,$Apache::lonxml::curdepth);
1.1       albertel  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)=@_;
1.13    ! albertel  322:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  323: 	&Apache::lonxml::startredirection();
                    324:     }
                    325:     return '';
                    326: }
                    327: 
                    328: sub end_InstanceText {
                    329:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel  330:     my $instance_id=$Apache::bridgetask::instance[-1];
1.13    ! albertel  331:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  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)=@_;
1.13    ! albertel  339:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  340: 	&Apache::lonxml::startredirection();
                    341:     }
                    342:     return '';
                    343: }
                    344: 
                    345: sub end_Criteria {
                    346:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9       albertel  347:     my $instance_id=$Apache::bridgetask::instance[-1];
1.13    ! albertel  348:     if ($target eq 'web' || $target eq 'webgrade') {
1.1       albertel  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: 
1.4       albertel  357: sub proctor_validation_screen {
                    358:     my ($slot) = @_;
                    359:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5       albertel  360:     my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11      albertel  361:     $user=$env{'form.proctorname'};
                    362:     if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4       albertel  363:     my $msg;
1.11      albertel  364:     if ($env{'form.proctorpassword'}) {
1.4       albertel  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
1.11      albertel  372: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4       albertel  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>
1.6       albertel  378:   <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4       albertel  379: </table>
                    380: <input type="submit" name="checkoutbutton" value="Validate"  /><br />
                    381: Student who should be logged in is:<br />
1.5       albertel  382: <img src="$url" /><br />
1.4       albertel  383: </form>
                    384: ENDCHECKOUT
                    385:     return $result;
                    386: }
                    387: 
1.1       albertel  388: 1;
                    389: __END__

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