File:  [LON-CAPA] / loncom / homework / essayresponse.pm
Revision 1.20: download - view: text, annotated - select for diffs
Fri Jan 24 18:30:54 2003 UTC (21 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Stores file now and link to it. This now needs to get incorparated into
grades.pm.

    1: # The LearningOnline Network with CAPA
    2: # essay (ungraded) style responses
    3: #
    4: # $Id: essayresponse.pm,v 1.20 2003/01/24 18:30:54 www 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: # 4/3 Guy
   29: # July, 2002, H. K. Ng
   30: #
   31: package Apache::essayresponse;
   32: use strict;
   33: use Apache::lonxml;
   34: use Apache::lonnet;
   35: 
   36: BEGIN {
   37:     &Apache::lonxml::register('Apache::essayresponse',('essayresponse'));
   38: }
   39: 
   40: sub start_essayresponse {
   41:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   42:     my $result;
   43:     my $id = &Apache::response::start_response($parstack,$safeeval);
   44:     if ($target eq 'meta') {
   45: 	$result=&Apache::response::meta_package_write('essayresponse');
   46:     } elsif ($target eq 'web') {
   47: 	my $part= $Apache::inputtags::part;
   48: 
   49: 	my $ncol= &Apache::lonnet::EXT("resource.$part".'_'."$id.maxcollaborators");
   50: 	my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"});
   51: 	my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
   52: 	my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"});
   53: 	$result='<br /><table border="1">';
   54: 	if ($ncol > 0) {
   55: 	    $result .='<tr><td>'.
   56: 		'Collaborators: <input type="text" size="70" max="80" name="HWCOL'.
   57: 		$part.'_'.$id.'" value="'.$coll.'" /><br />'.
   58: 		'(Enter maximum '.$ncol.' collaborators using username or username@domain, e.g. '.
   59: 		'smithje or smithje@'.$ENV{'user.domain'}.'.)<br />';
   60: 	    $result .= &check_collaborators($ncol,$coll) if ($coll =~ /\w+/);
   61: 	    $result .='</td></tr>';
   62: 	}
   63:         if ($uploadedfiletypes) {
   64:            $result.=
   65: '<tr><td>Submit a file: <input type="file" size="50" name="HWFILE'.
   66: 		$part.'_'.$id.'" onFocus="this.form.enctype='.
   67: "'multipart/form-data'".';" /><br />Allowed filetypes: <b>'.$uploadedfiletypes.'</b><br />';
   68:            if ($uploadedfile) {
   69: 	       $result.='Currently submitted: <tt><a href="'.
   70:                 &Apache::lonnet::tokenwrapper($Apache::lonhomework::history{"resource.$part.$id.uploadedurl"}).'">'.$uploadedfile.'</a></tt>';
   71:            } else {
   72:               $result.='(Hand in a file you have prepared on your computer)';
   73:            }
   74:            $result.='</td></tr>'; 
   75:         }
   76: 	$result.='<tr><td>'.
   77: 	    '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked>'.
   78: 	    ' Submit text below as answer to receive credit <br />'.
   79: 	    '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no">'.
   80: 	    ' Save text below as a draft answer (not submitting it for credit yet) '.
   81: 	    '</td></tr></table>';
   82:     }
   83:     return $result;
   84: }
   85: 
   86: sub end_essayresponse {
   87:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   88:     my $part          = $Apache::inputtags::part;
   89:     my $id            = $Apache::inputtags::response[-1];
   90:     my $result;
   91:     if ( $target eq 'grade' ) {
   92: 	my $collaborators = $ENV{'form.HWCOL'.$part.'_'.$id};	
   93: 	if ($collaborators =~ /[^\s]/) {
   94: 	    my $previous_list= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"});
   95: 	    $Apache::lonhomework::results{"resource.$part.$id.collaborators"}=$collaborators
   96: 		if ($collaborators ne $previous_list);
   97: 	}
   98:         my $filename= $ENV{'form.HWFILE'.$part.'_'.$id.'.filename'};
   99:         if ($filename =~ /[^\s]/) {
  100: 	    $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}=$filename;
  101:             $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=
  102:               &Apache::lonnet::userfileupload('HWFILE'.$part.'_'.$id);
  103:         }
  104: 	if ( defined $ENV{'form.submitted'}) {
  105: 	    my $response      = $ENV{'form.HWVAL'.$id};
  106: 	    if ( $response =~ /[^\s]/) {
  107: 		my $award;
  108: 		if ($ENV{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
  109: 		    $award='SUBMITTED';
  110: 		} else {
  111: 		    $award='DRAFT';
  112: 		}
  113: 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
  114: 		$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
  115: 		my %previous=&Apache::response::check_for_previous($response,$part,$id);
  116: 		&Apache::response::handle_previous(\%previous,$award);
  117: 	    }
  118: 	}
  119:     } elsif ($target eq 'edit') {
  120: 	$result.=&Apache::edit::end_table();
  121:     } elsif ($target eq 'tex') {
  122: 	if ($Apache::lonhomework::type eq 'exam') {
  123: 	    $result.='\begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]\textit{Live blank on scoring form}\vskip 0 mm';
  124: 	    &Apache::lonxml::increment_counter();
  125: 	    $result.= '\item[\textbf{'.$Apache::lonxml::counter.'}.]\textit{Leave blank on scoring form}\vskip 0 mm \end{enumerate}';
  126: 	    &Apache::lonxml::increment_counter();
  127: 	}
  128:     }
  129: 
  130:     &Apache::response::end_response;
  131:     return $result;
  132: }
  133: 
  134: sub check_collaborators {
  135:     my ($ncol,$coll) = @_;
  136:     my %classlist=&Apache::lonnet::dump('classlist',
  137: 					$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  138: 					$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  139:     my (@badcollaborators,$result);
  140:     my (@collaborators) = split(/\,?\s+/,$coll);
  141:     foreach (@collaborators) {
  142: 	my $collaborator = $_;
  143: 	if (/@/) {
  144: 	    $collaborator =~ s/@/:/;
  145: 	} else {
  146: 	    $collaborator = $_.':'.$ENV{'user.domain'};
  147: 	}
  148: 	push @badcollaborators, $_ if (!grep /^$collaborator/i,keys %classlist);
  149:     }
  150:     
  151:     if (scalar(@badcollaborators)) {
  152: 	$result = '<table border="0"><tr bgcolor="#ffbbbb"><td> The following user'.
  153: 	    (scalar(@badcollaborators) > 1 ? 's are' : ' is').' invalid: '.
  154: 	    join(', ',@badcollaborators).'. Please correct.</td></tr></table>';
  155:     }
  156:     my $toomany = scalar(@collaborators) - $ncol;
  157:     if ($toomany > 0) {
  158: 	$result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>'.
  159: 	    'You have too many collaborators. Please remove '.$toomany.' collaborator'.
  160: 	    ($toomany > 1 ? 's' :'').'.</td></tr></table>';
  161:     }
  162:     return $result;
  163: }
  164: 
  165: 1;
  166: __END__

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