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

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

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