Annotation of loncom/homework/essayresponse.pm, revision 1.20

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # essay (ungraded) style responses
1.5       albertel    3: #
1.20    ! www         4: # $Id: essayresponse.pm,v 1.19 2003/01/23 22:28:55 www Exp $
1.5       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: #
1.1       albertel   28: # 4/3 Guy
1.10      ng         29: # July, 2002, H. K. Ng
                     30: #
1.1       albertel   31: package Apache::essayresponse;
                     32: use strict;
1.16      sakharuk   33: use Apache::lonxml;
1.20    ! www        34: use Apache::lonnet;
1.1       albertel   35: 
1.6       harris41   36: BEGIN {
1.10      ng         37:     &Apache::lonxml::register('Apache::essayresponse',('essayresponse'));
1.1       albertel   38: }
                     39: 
                     40: sub start_essayresponse {
1.10      ng         41:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     42:     my $result;
1.14      albertel   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') {
1.10      ng         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"});
1.17      www        51: 	my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
                     52: 	my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"});
1.13      ng         53: 	$result='<br /><table border="1">';
1.10      ng         54: 	if ($ncol > 0) {
1.13      ng         55: 	    $result .='<tr><td>'.
                     56: 		'Collaborators: <input type="text" size="70" max="80" name="HWCOL'.
                     57: 		$part.'_'.$id.'" value="'.$coll.'" /><br />'.
1.10      ng         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+/);
1.13      ng         61: 	    $result .='</td></tr>';
1.10      ng         62: 	}
1.17      www        63:         if ($uploadedfiletypes) {
                     64:            $result.=
                     65: '<tr><td>Submit a file: <input type="file" size="50" name="HWFILE'.
1.19      www        66: 		$part.'_'.$id.'" onFocus="this.form.enctype='.
                     67: "'multipart/form-data'".';" /><br />Allowed filetypes: <b>'.$uploadedfiletypes.'</b><br />';
                     68:            if ($uploadedfile) {
1.20    ! www        69: 	       $result.='Currently submitted: <tt><a href="'.
        !            70:                 &Apache::lonnet::tokenwrapper($Apache::lonhomework::history{"resource.$part.$id.uploadedurl"}).'">'.$uploadedfile.'</a></tt>';
1.19      www        71:            } else {
                     72:               $result.='(Hand in a file you have prepared on your computer)';
                     73:            }
                     74:            $result.='</td></tr>'; 
1.17      www        75:         }
1.13      ng         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>';
1.10      ng         82:     }
                     83:     return $result;
1.1       albertel   84: }
                     85: 
                     86: sub end_essayresponse {
1.10      ng         87:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.13      ng         88:     my $part          = $Apache::inputtags::part;
1.14      albertel   89:     my $id            = $Apache::inputtags::response[-1];
1.15      albertel   90:     my $result;
1.10      ng         91:     if ( $target eq 'grade' ) {
1.14      albertel   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: 	}
1.19      www        98:         my $filename= $ENV{'form.HWFILE'.$part.'_'.$id.'.filename'};
                     99:         if ($filename =~ /[^\s]/) {
                    100: 	    $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}=$filename;
1.20    ! www       101:             $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=
        !           102:               &Apache::lonnet::userfileupload('HWFILE'.$part.'_'.$id);
1.19      www       103:         }
1.10      ng        104: 	if ( defined $ENV{'form.submitted'}) {
                    105: 	    my $response      = $ENV{'form.HWVAL'.$id};
                    106: 	    if ( $response =~ /[^\s]/) {
1.14      albertel  107: 		my $award;
                    108: 		if ($ENV{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
                    109: 		    $award='SUBMITTED';
                    110: 		} else {
                    111: 		    $award='DRAFT';
                    112: 		}
1.10      ng        113: 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
1.14      albertel  114: 		$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
1.10      ng        115: 		my %previous=&Apache::response::check_for_previous($response,$part,$id);
1.14      albertel  116: 		&Apache::response::handle_previous(\%previous,$award);
1.10      ng        117: 	    }
                    118: 	}
1.15      albertel  119:     } elsif ($target eq 'edit') {
                    120: 	$result.=&Apache::edit::end_table();
1.16      sakharuk  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();
1.18      www       125: 	    $result.= '\item[\textbf{'.$Apache::lonxml::counter.'}.]\textit{Leave blank on scoring form}\vskip 0 mm \end{enumerate}';
1.16      sakharuk  126: 	    &Apache::lonxml::increment_counter();
                    127: 	}
1.10      ng        128:     }
1.11      ng        129: 
1.10      ng        130:     &Apache::response::end_response;
1.15      albertel  131:     return $result;
1.10      ng        132: }
                    133: 
                    134: sub check_collaborators {
1.11      ng        135:     my ($ncol,$coll) = @_;
1.10      ng        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)) {
1.11      ng        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>';
1.10      ng        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;
1.1       albertel  163: }
1.2       albertel  164: 
                    165: 1;
                    166: __END__

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