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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # essay (ungraded) style responses
1.5       albertel    3: #
1.104   ! raeburn     4: # $Id: essayresponse.pm,v 1.103 2010/04/19 04:02:37 raeburn 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.33      albertel   28: 
1.1       albertel   29: package Apache::essayresponse;
                     30: use strict;
1.33      albertel   31: use Apache::lonxml();
1.62      albertel   32: use Apache::lonnet;
1.33      albertel   33: use Apache::lonlocal;
1.88      raeburn    34: use LONCAPA qw(:DEFAULT :match);
1.72      www        35:  
1.1       albertel   36: 
1.6       harris41   37: BEGIN {
1.10      ng         38:     &Apache::lonxml::register('Apache::essayresponse',('essayresponse'));
1.1       albertel   39: }
                     40: 
                     41: sub start_essayresponse {
1.10      ng         42:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     43:     my $result;
1.104   ! raeburn    44:     print STDERR "target is $target AND status is ".$Apache::inputtags::status[-1]." AND ".
        !            45:                  " type is ".$Apache::lonhomework::type."\n";
1.14      albertel   46:     my $id = &Apache::response::start_response($parstack,$safeeval);
                     47:     if ($target eq 'meta') {
                     48: 	$result=&Apache::response::meta_package_write('essayresponse');
1.69      albertel   49:     } elsif ($target eq 'web' &&
                     50: 	     $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.10      ng         51: 	my $part= $Apache::inputtags::part;
                     52: 	my $ncol= &Apache::lonnet::EXT("resource.$part".'_'."$id.maxcollaborators");
1.34      albertel   53: 	my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
1.17      www        54: 	my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
1.21      www        55:         $uploadedfiletypes=~s/[^\w\,]//g;
1.93      raeburn    56:         my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
                     57:         if (!defined($maxfilesize)) {
                     58:             $maxfilesize = 10.0; #FIXME This should become a domain configuration 
                     59:         }
1.102     raeburn    60: 	if (($Apache::lonhomework::type eq 'survey') ||
                     61:             ($Apache::lonhomework::type eq 'surveycred') ||
                     62:             ($Apache::lonhomework::type eq 'anonsurvey') ||
                     63:             ($Apache::lonhomework::type eq 'anonsurveycred')) {
1.75      albertel   64: 	    $result.= '<input type="hidden" name="HWDRAFT'.$part.'_'.$id.'" value="yes" /> ';
                     65: 	}
                     66: 	$result.='<br /><table border="1">';
1.102     raeburn    67: 	if (($Apache::lonhomework::type ne 'survey') &&
                     68:             ($Apache::lonhomework::type ne 'surveycred') &&
1.104   ! raeburn    69:             ($Apache::lonhomework::type ne 'anonsurvey') &&
1.102     raeburn    70:             ($Apache::lonhomework::type ne 'anonsurveycred')) {
1.75      albertel   71: 	    $result.= '<tr><td>'.
                     72: 		'<label>'.
                     73: 		'<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.
                     74: 		&mt('Submit entries below as answer to receive credit').
                     75: 		'</label> <br />'.
                     76: 		'<label>'.
                     77: 		'<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.
1.101     riegler    78: 		&mt('Save entries below (not submitted for credit yet)').
1.75      albertel   79: 		'</label>'.
                     80: 		'</td></tr>';
                     81: 	}
                     82: 
1.10      ng         83: 	if ($ncol > 0) {
1.64      matthew    84: 	    $result .='<tr><td>'.'<label>'.
1.88      raeburn    85: 		      &mt('Collaborators:').' <input type="text" size="70" max="80" name="HWCOL'.
                     86: 		      $part.'_'.$id.'" value="'.$coll.'" /><br />'.
                     87: 		      &mt('(Enter a maximum of [quant,_1,collaborator] using username or username:domain, e.g. smithje or smithje:[_2].)',$ncol,$env{'user.domain'});
                     88:             if ($ncol > 1) {
                     89:                 $result .= '<br />'.&mt('If entering more than one, use spaces to separate the collaborators.');
                     90:             }
                     91:             $result .= '</label><br />';
1.10      ng         92: 	    $result .= &check_collaborators($ncol,$coll) if ($coll =~ /\w+/);
1.13      ng         93: 	    $result .='</td></tr>';
1.10      ng         94: 	}
1.93      raeburn    95:         my $filesfrom = 'both';
                     96:         my $stuname = &Apache::lonnet::EXT('user.name');
                     97:         my $studom = &Apache::lonnet::EXT('user.domain');
                     98:         if (!&Apache::lonnet::usertools_access($stuname,$studom,'portfolio')) {
                     99:             $filesfrom = 'uploadonly';
                    100:         }
                    101: 	$result.=&Apache::inputtags::file_selector($part,$id,$uploadedfiletypes,
                    102: 						   $filesfrom,undef,$maxfilesize);
1.22      www       103:         $result.='</table>';
1.74      albertel  104:     } elsif ($target eq 'web' &&
                    105: 	     $Apache::inputtags::status[-1] ne 'CAN_ANSWER') {
                    106: 	my $part= $Apache::inputtags::part;
                    107: 	my @msgs;
                    108: 	if ($Apache::lonhomework::history{"resource.$part.$id.collaborators"} =~ /\S/) {
                    109: 	    my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
                    110: 	    $result .= '<td>'.&mt('Collaborated with [_1]',$coll).'</td>';
                    111: 	}
                    112: 
                    113: 	my $file_submission = 
                    114: 	    &Apache::inputtags::show_past_file_submission($part,$id);
                    115: 	if ($file_submission) {
                    116: 	    $result .= '<td>'.$file_submission.'</td>';
                    117: 	}
                    118: 
                    119: 	my $port_submission = 
                    120: 	    &Apache::inputtags::show_past_portfile_submission($part,$id);
                    121: 	if ($port_submission) {
                    122: 	    $result .= '<td>'.$port_submission.'</td>';
                    123: 	}
                    124: 
                    125: 	if ($result ne '') {
                    126: 	    $result = 
                    127: 		'<table class="LC_pastsubmission"><tr>'.$result.
                    128: 		'</tr></table>';
                    129: 	}
1.10      ng        130:     }
                    131:     return $result;
1.1       albertel  132: }
                    133: 
                    134: sub end_essayresponse {
1.10      ng        135:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.13      ng        136:     my $part          = $Apache::inputtags::part;
1.14      albertel  137:     my $id            = $Apache::inputtags::response[-1];
1.70      albertel  138:     my $increment     = &Apache::response::repetition();
1.15      albertel  139:     my $result;
1.10      ng        140:     if ( $target eq 'grade' ) {
1.62      albertel  141: 	my $collaborators = $env{'form.HWCOL'.$part.'_'.$id};	
1.14      albertel  142: 	if ($collaborators =~ /[^\s]/) {
1.34      albertel  143: 	    my $previous_list= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
1.14      albertel  144: 	    $Apache::lonhomework::results{"resource.$part.$id.collaborators"}=$collaborators
                    145: 		if ($collaborators ne $previous_list);
                    146: 	}
1.58      albertel  147: 	if (  &Apache::response::submitted('scantron') ) {
1.31      albertel  148: 	    $increment=&Apache::response::scored_response($part,$id);
1.58      albertel  149: 	} elsif ( &Apache::response::submitted() ) {
1.62      albertel  150: 	    my $response      = $env{'form.HWVAL_'.$id};
1.91      raeburn   151:             my $filename = $env{'form.HWFILE'.$part.'_'.$id.'.filename'} || 
                    152:                            $env{'form.HWFILETOOBIG'.$part.'_'.$id};
1.62      albertel  153:             my $portfiles = $env{'form.HWPORT'.$part.'_'.$id};
1.42      banghart  154: 	    if (( $response =~ /[^\s]/) || ($filename =~ /[^\s]/) || ($portfiles =~ /[^\s]/)) {
1.61      albertel  155:  		my $award='DRAFT';
1.62      albertel  156:         	if ($env{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
1.102     raeburn   157:                     if ($Apache::lonhomework::type eq 'anonsurvey') {
                    158:                         $award='ANONYMOUS';
                    159:                     } elsif ($Apache::lonhomework::type eq 'anonsurveycred') {
                    160:                         $award='ANONYMOUS_CREDIT';
                    161:                     } elsif ($Apache::lonhomework::type eq 'surveycred') {
                    162:                         $award='SUBMITTED_CREDIT';
                    163:                     } else {
                    164: 		        $award='SUBMITTED';
                    165:                     }
1.14      albertel  166: 		}
1.22      www       167:                 my $uploadedflag=0;
1.91      raeburn   168:                 my $totalsize=0;
                    169: 		&file_submission($part,$id,'filename',\$award,\$uploadedflag,\$totalsize);
                    170: 		&file_submission($part,$id,'portfiles',\$award,\$uploadedflag,\$totalsize);
1.10      ng        171: 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
1.14      albertel  172: 		$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
1.10      ng        173: 		my %previous=&Apache::response::check_for_previous($response,$part,$id);
1.22      www       174: 		unless ($uploadedflag) { &Apache::response::handle_previous(\%previous,$award); }
1.32      www       175: #
                    176: # Store with resource author for similarity testing
                    177: #
                    178:                 if ($award eq 'SUBMITTED') {
                    179: 		    my ($symb,$crsid,$domain,$name)=
1.77      albertel  180: 			&Apache::lonnet::whichuser();
1.32      www       181: 		    if ($crsid) {
1.83      albertel  182: 			my $akey=join('.',&escape($name),&escape($domain),
                    183: 				      &escape($crsid));
1.32      www       184: 			my $essayurl=
                    185: 			    &Apache::lonnet::declutter($ENV{'REQUEST_URI'});
                    186: 			my ($adom,$aname,$apath)=
1.80      albertel  187: 			    ($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.72      www       188:                         $apath=&escape($apath);
1.32      www       189: 			$apath=~s/\W/\_/gs;
                    190: 			&Apache::lonnet::put('nohist_essay_'.$apath,
                    191: 					 { $akey => $response },$adom,$aname);
                    192: 		    }
1.42      banghart  193:                 }
1.10      ng        194: 	    }
1.42      banghart  195: 	} 
1.15      albertel  196:     } elsif ($target eq 'edit') {
                    197: 	$result.=&Apache::edit::end_table();
1.71      albertel  198: 
                    199:     } elsif ($target eq 'tex'
                    200: 	     && $Apache::lonhomework::type eq 'exam') {
                    201: 	$result .= &Apache::inputtags::exam_score_line($target);
                    202: 
1.70      albertel  203:     } elsif ($target eq 'answer') {
1.78      albertel  204: 	$result.=&Apache::response::answer_header($$tagstack[-1]);
1.81      foxr      205: 	my $answer = &mt('Essay will be hand graded.');
1.78      albertel  206: 	$result.=&Apache::response::answer_part($$tagstack[-1],$answer,
                    207: 						{'no_verbatim' => 1});
                    208: 	$result.=&Apache::response::answer_footer($$tagstack[-1]);
1.10      ng        209:     }
1.82      albertel  210:     if ($target eq 'web') {
                    211: 	&Apache::response::setup_prior_tries_hash(\&format_prior_response,
                    212: 						  ['portfiles',
                    213: 						   'uploadedurl']);
                    214:     }
1.71      albertel  215: 
1.27      albertel  216:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
                    217: 	$target eq 'tex' || $target eq 'analyze') {
1.86      foxr      218: 	&Apache::lonxml::increment_counter($increment, "$part.$id");
1.85      foxr      219: 
                    220: 	if ($target eq 'analyze') {
1.87      raeburn   221:             $Apache::lonhomework::analyze{"$part.$id.type"} = 'essayresponse';
1.96      raeburn   222:             push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
1.85      foxr      223: 	    &Apache::lonhomework::set_bubble_lines();
                    224: 	}
1.27      albertel  225:     }
1.10      ng        226:     &Apache::response::end_response;
1.42      banghart  227: 
1.15      albertel  228:     return $result;
1.10      ng        229: }
                    230: 
1.82      albertel  231: sub format_prior_response {
                    232:     my ($mode,$answer,$other_data) = @_;
                    233:     my $output;
                    234: 
                    235:     my (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
                    236:     my $port_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
                    237: 
                    238:     my $file_list;
                    239: 
                    240:     foreach my $file (split(/\s*,\s*/,
                    241: 			    $other_data->[0].','.$other_data->[1])) {
                    242: 	next if ($file!~/\S/);
                    243: 	if ($file !~ m{^/uploaded/}) { $file=$port_url.$file; }
                    244: 	$file=~s|/+|/|g;
                    245: 	&Apache::lonnet::allowuploaded('/adm/essayresponse',$file);
                    246: 	$file_list.='<li><span class="LC_nobreak"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
                    247: 	    &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
                    248: 	    '</a></span></li>'."\n";
                    249:     }
                    250:     if ($file_list) {
                    251: 	$output.= &mt('Submitted Files').'<ul>'.$file_list.'</ul>';
                    252:     }
                    253:     if ($answer =~ /\S/) {
                    254: 	$output.='<p>'.&mt('Submitted text').
                    255: 	    '<blockquote>'.$answer.'</blockquote></p>';
                    256:     }
                    257: 
                    258:     return '<div class="LC_prior_essay">'.$output.'</div>';
                    259: }
                    260: 
1.61      albertel  261: sub file_submission {
1.91      raeburn   262:     my ($part,$id,$which,$award,$uploadedflag,$totalsize)=@_;
1.61      albertel  263:     my $files;
1.67      albertel  264:     my $jspart=$part;
                    265:     $jspart=~s/\./_/g;
1.91      raeburn   266:     if ($which eq 'portfiles') { 
                    267:         $files= $env{'form.HWPORT'.$jspart.'_'.$id};
                    268:     } elsif ($which eq 'filename') {
                    269:         if ($env{'form.HWFILETOOBIG'.$jspart.'_'.$id} ne '') {
                    270:             $$award = 'EXCESS_FILESIZE';
                    271:             return;
                    272:         } else {
                    273:             $files = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'};
                    274:         }
1.61      albertel  275:     }
                    276:     if ($files =~ /[^\s]/) {
                    277: 	$files =~s/,$//;
1.91      raeburn   278:         my (@submitted_files,@acceptable_files,@accepted_files);
                    279:         if ($which eq 'portfiles') {
                    280:             @submitted_files = split(/\s*,\s*/,$files);
                    281:         } else {
                    282:             @submitted_files = ($files);
                    283:         }
                    284:         my $uploadedfiletypes= 
                    285:             &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
1.99      raeburn   286:         if ($uploadedfiletypes ne '') {
1.91      raeburn   287:             $uploadedfiletypes=~s/[^\w\,]//g;
                    288:             $uploadedfiletypes=','.$uploadedfiletypes.',';
                    289:             foreach my $file (@submitted_files) {
                    290:                 my ($extension)=($file=~/\.(\w+)$/);
                    291:                 if ($uploadedfiletypes=~/\,\s*\Q$extension\E\s*\,/i) {
                    292:                     push(@acceptable_files,$file);
                    293:                 } else {
                    294:                     $$award='INVALID_FILETYPE';
                    295:                     if ($which eq 'filename') {
                    296:                         &delete_form_items($jspart,$id);
                    297:                     }
                    298:                 }
                    299:             }
1.99      raeburn   300:         } else {
1.100     raeburn   301:             @acceptable_files = @submitted_files;
1.91      raeburn   302:         }
                    303:         my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
                    304:         if (!$maxfilesize) {
1.93      raeburn   305:             $maxfilesize = 10.0; #FIXME This should become a domain configuration
1.91      raeburn   306:         }
                    307:         my %dirlist;
                    308:         foreach my $file (@acceptable_files) {
                    309:             if ($which eq 'filename') {
                    310:                 if (ref($totalsize)) {
                    311:                     $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
                    312:                 }
                    313:             } else {
                    314:                 my ($symb,$crsid,$udom,$uname) = &Apache::lonnet::whichuser();
1.97      raeburn   315:                 my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
1.91      raeburn   316:                 my $fullpath = '/userfiles/portfolio'.$path;
                    317:                 if (!exists($dirlist{$fullpath})) {
                    318:                     my @list = &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
1.97      raeburn   319:                     $dirlist{$fullpath} = \@list;
                    320:                 }
                    321:                 if (ref($dirlist{$fullpath}) eq 'ARRAY') {
                    322:                     foreach my $dir_line (@{$dirlist{$fullpath}}) {
1.91      raeburn   323:                         my ($fname,$dom,undef,$testdir,undef,undef,undef,undef,
                    324:                             $size,undef,$mtime,undef,undef,undef,$obs,undef) = 
                    325:                         split(/\&/,$dir_line,16);
                    326:                         if ($filename eq $fname) {
                    327:                             my $mbsize = $size/(1024.0*1024.0);
                    328:                             if (ref($totalsize)) {
                    329:                                 $$totalsize += $mbsize;
                    330:                             }
                    331:                             last;
                    332:                         }
                    333:                     }
                    334:                 }
                    335:             }
                    336:             if (ref($totalsize)) {
                    337:                 if ($$totalsize > $maxfilesize) {
                    338:                     $$award='EXCESS_FILESIZE';
                    339:                     if ($which eq 'filename') {
                    340:                         &delete_form_items($jspart,$id);
                    341:                     }
1.97      raeburn   342:                     last;
1.94      raeburn   343:                 } else {
                    344:                     push(@accepted_files,$file);
1.91      raeburn   345:                 }
                    346:             } else {
                    347:                 push(@accepted_files,$file);
                    348:             }
                    349:         }
                    350:         $Apache::lonhomework::results{"resource.$part.$id.$which"}=join(',',@accepted_files);
1.103     raeburn   351:         if (($$award eq 'INVALID_FILETYPE') || ($$award eq 'EXCESS_FILESIZE')) {
1.91      raeburn   352:             return;
                    353:         }
                    354: 	if (ref($uploadedflag)) {
1.61      albertel  355: 	    $$uploadedflag=1;
                    356: 	}
1.95      raeburn   357:         my ($symb,$crsid,$domain,$name)=&Apache::lonnet::whichuser();
1.91      raeburn   358: 	if ($which eq 'portfiles') {
1.66      albertel  359: 	    &Apache::lonnet::unmark_as_readonly($domain,$name,[$symb,$crsid]);
                    360: 	    &Apache::lonnet::mark_as_readonly($domain,$name,\@submitted_files,[$symb,$crsid]);
1.61      albertel  361: 	    &Apache::lonnet::clear_selected_files($name);
                    362: 	}
1.91      raeburn   363: 	if ($which eq 'filename') {
1.61      albertel  364: 	    $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}=
                    365: 		$files;
1.95      raeburn   366:             my $cleanpart = $part;
                    367:             $cleanpart =~ s/\W/_/g;
                    368:             my $cleanid = $id;
                    369:             $cleanid =~ s/\W/_/g;
                    370:             my ($map,$resid,$res)=&Apache::lonnet::decode_symb($symb);
                    371:             my $container;
                    372:             if ($map =~ /^uploaded/) {
                    373:                 (my $prefix,$container) = ($map =~ m{^uploaded/[^/]+/[^/]+/(default|supplemental)_?([^.]*)\.(?:sequence|page)$});
                    374:                 if (length($container) > 10) {
                    375:                     $container = substr($container,-10,10);
                    376:                 }
                    377:                 if ($container ne '') {
                    378:                     $container = $prefix.'_'.$container;
                    379:                 } else {
                    380:                     $container = $prefix;
                    381:                 } 
                    382:             } else {
                    383:                 ($container) = ($map =~ m{(.+)\.(?:sequence|page)$});
                    384:                 $container =~ s/\W/_/g;
                    385:                 if (length($container) > 255) {
                    386:                     $container = substr($container,0,254);
                    387:                 }
                    388:             }
                    389:             my $subdir = 'essayresponse';
                    390:             my %crsdesc = &Apache::lonnet::coursedescription($crsid);
                    391:             foreach my $item ($crsdesc{'domain'},$crsdesc{'num'},$container,$resid,$cleanpart,$cleanid) {
                    392:                 if ($item ne '') {
                    393:                     $subdir .= '/'.$item;
                    394:                 }
                    395:             }
1.61      albertel  396: 	    $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=
1.67      albertel  397: 		&Apache::lonnet::userfileupload('HWFILE'.$jspart.'_'.$id,undef,
1.95      raeburn   398: 						$subdir);
1.98      raeburn   399:             delete($env{'form.HWFILE'.$jspart.'_'.$id});
1.61      albertel  400: 	}
                    401:     } elsif ($which eq 'portfiles' &&
                    402: 	     $Apache::lonhomework::history{"resource.$part.$id.$which"}) {
1.77      albertel  403: 	my ($symb,$crsid,$domain,$name)=&Apache::lonnet::whichuser();
1.66      albertel  404: 	&Apache::lonnet::unmark_as_readonly($domain,$name,[$symb,$crsid]);
1.61      albertel  405: 	$Apache::lonhomework::results{"resource.$part.$id.$which"}="";
                    406:     }
                    407: }
                    408: 
1.91      raeburn   409: sub delete_form_items {
                    410:     my ($jspart,$id) = @_;
1.98      raeburn   411:     delete($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'});
                    412:     delete($env{'form.HWFILE'.$jspart.'_'.$id.'.mimetype'});
                    413:     delete($env{'form.HWFILE'.$jspart.'_'.$id});
1.91      raeburn   414: }
                    415: 
                    416: 
1.10      ng        417: sub check_collaborators {
1.11      ng        418:     my ($ncol,$coll) = @_;
1.10      ng        419:     my %classlist=&Apache::lonnet::dump('classlist',
1.62      albertel  420: 					$env{'course.'.$env{'request.course.id'}.'.domain'},
                    421: 					$env{'course.'.$env{'request.course.id'}.'.num'});
1.10      ng        422:     my (@badcollaborators,$result);
1.88      raeburn   423:   
                    424:     my (@collaborators) = split(/,?\s+/,$coll);
                    425:     foreach my $entry (@collaborators) {
                    426:         my $collaborator;
                    427: 	if ($entry =~ /:/) {
                    428: 	    $collaborator = $entry;
1.10      ng        429: 	} else {
1.88      raeburn   430: 	    $collaborator = $entry.':'.$env{'user.domain'};
1.10      ng        431: 	}
1.88      raeburn   432:         if ($collaborator !~ /^$match_username:$match_domain$/) {
                    433:             if (!grep(/^\Q$entry\E$/,@badcollaborators)) {
                    434: 	        push(@badcollaborators,$entry);
                    435:             }
                    436:         } elsif (!grep(/^\Q$collaborator\E$/i,keys(%classlist))) {
                    437:             if (!grep(/^\Q$entry\E$/,@badcollaborators)) {
                    438:                 push(@badcollaborators,$entry);
                    439:             }
                    440:         }
1.10      ng        441:     }
                    442:     
1.88      raeburn   443:     my $numbad = scalar(@badcollaborators);
                    444:     if ($numbad) {
                    445: 	$result = '<table border="0"><tr bgcolor="#ffbbbb"><td>';
                    446:         if ($numbad == 1) {
                    447:             $result .= &mt('The following user is invalid:');
                    448:         } else {
                    449:             $result .= &mt('The following [_1] users are invalid:',$numbad);
                    450:         }
                    451: 	$result .= ' '.join(', ',@badcollaborators).'. '.&mt('Please correct.').
                    452:                    '</td></tr></table>';
1.10      ng        453:     }
                    454:     my $toomany = scalar(@collaborators) - $ncol;
                    455:     if ($toomany > 0) {
                    456: 	$result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>'.
1.88      raeburn   457: 	           &mt('You have too many collaborators.').' '.
                    458:                    &mt('Please remove [quant,_1,collaborator].',$toomany).
                    459: 	           '</td></tr></table>';
1.10      ng        460:     }
                    461:     return $result;
1.1       albertel  462: }
1.2       albertel  463: 
                    464: 1;
                    465: __END__
1.92      jms       466: 
                    467: 
                    468: =pod
                    469: 
                    470: =head1 NAME
                    471: 
                    472: Apache::easyresponse
                    473: 
                    474: =head1 SYNOPSIS
                    475: 
                    476: Handler to evaluate essay (ungraded) style responses.
                    477: 
                    478: This is part of the LearningOnline Network with CAPA project
                    479: described at http://www.lon-capa.org.
                    480: 
                    481: =head1 SUBROUTINES
                    482: 
                    483: =over 
                    484: 
                    485: =item start_essayresponse()
                    486: 
                    487: =item end_essayresponse()
                    488: 
                    489: =item format_prior_response()
                    490: 
                    491: =item file_submission()
                    492: 
                    493: =item delete_form_items()
                    494: 
                    495: =item check_collaborators()
                    496: 
                    497: =back
                    498: 
1.93      raeburn   499: =cut

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