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

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

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