File:
[LON-CAPA] /
loncom /
homework /
essayresponse.pm
Revision
1.116:
download - view:
text,
annotated -
select for diffs
Mon Oct 17 12:41:35 2011 UTC (12 years, 10 months ago) by
raeburn
Branches:
MAIN
CVS tags:
language_hyphenation_merge,
language_hyphenation,
HEAD,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- Change to way lonnet::dirlist() reports an error condition (i.e., no_host,
con_lost, no_such_dir, empty etc.) when retrieving directory list information
with ls3, ls2 or ls.
- error is passed as second item in a pair of return values.
- first item in return values is a reference to an array of actual files.
1: # The LearningOnline Network with CAPA
2: # essay (ungraded) style responses
3: #
4: # $Id: essayresponse.pm,v 1.116 2011/10/17 12:41:35 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::essayresponse;
30: use strict;
31: use Apache::lonxml();
32: use Apache::lonhtmlcommon;
33: use Apache::loncommon;
34: use Apache::lonnet;
35: use Apache::lonnavmaps;
36: use Apache::lonlocal;
37: use LONCAPA qw(:DEFAULT :match);
38:
39:
40: BEGIN {
41: &Apache::lonxml::register('Apache::essayresponse',('essayresponse'));
42: }
43:
44: sub start_essayresponse {
45: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
46: my $result;
47: my $id = &Apache::response::start_response($parstack,$safeeval);
48: if ($target eq 'meta') {
49: $result=&Apache::response::meta_package_write('essayresponse');
50: } elsif ($target eq 'web' &&
51: $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
52: my $part= $Apache::inputtags::part;
53: my $ncol= &Apache::lonnet::EXT("resource.$part".'_'."$id.maxcollaborators");
54: my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
55: my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
56: $uploadedfiletypes=~s/[^\w\,]//g;
57: my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
58: if (!defined($maxfilesize)) {
59: $maxfilesize = 10.0; #FIXME This should become a domain configuration
60: }
61: my $hiddendraft;
62: if (($Apache::lonhomework::type eq 'survey') ||
63: ($Apache::lonhomework::type eq 'surveycred') ||
64: ($Apache::lonhomework::type eq 'anonsurvey') ||
65: ($Apache::lonhomework::type eq 'anonsurveycred')) {
66: $hiddendraft = '<input type="hidden" name="HWDRAFT'.$part.'_'.$id.'" value="yes" />';
67: } else {
68: my $status_text = &mt('Submission type');
69: if ($Apache::lonhomework::history{"resource.$part.award"} eq 'DRAFT') {
70: $status_text .= '<br />'.&mt('(Currently -- draft)');
71: }
72: $result = &Apache::lonhtmlcommon::row_title($status_text);
73: my $closure;
74: unless ($ncol || $uploadedfiletypes) {
75: $closure = 1;
76: }
77: $result.=
78: '<label>'.
79: '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.
80: &mt('Submit entries below as answer to receive credit').
81: '</label> <br />'.
82: '<label>'.
83: '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.
84: &mt('Save entries below (not submitted for credit yet)').
85: '</label>'.
86: &Apache::lonhtmlcommon::row_closure($closure);
87: }
88:
89: if ($ncol > 0) {
90: $result.= &Apache::lonhtmlcommon::row_title(&mt('Collaborators')).
91: '<label>'.
92: &mt('Collaborators:').' <input type="text" size="70" max="80" name="HWCOL'.
93: $part.'_'.$id.'" value="'.$coll.'" /><br />'.
94: &mt('(Enter a maximum of [quant,_1,collaborator] using username or username:domain, e.g. smithje or smithje:[_2].)',$ncol,$env{'user.domain'});
95: if ($ncol > 1) {
96: $result .= '<br />'.&mt('If entering more than one, use spaces to separate the collaborators.');
97: }
98: $result .= '</label><br />';
99: $result .= &check_collaborators($ncol,$coll) if ($coll =~ /\w+/);
100: $result .= &Apache::lonhtmlcommon::row_closure();
101: }
102: my $filesfrom = 'both';
103: my $stuname = &Apache::lonnet::EXT('user.name');
104: my $studom = &Apache::lonnet::EXT('user.domain');
105: if (!&Apache::lonnet::usertools_access($stuname,$studom,'portfolio')) {
106: $filesfrom = 'uploadonly';
107: }
108: $result.=&Apache::inputtags::file_selector($part,$id,$uploadedfiletypes,
109: $filesfrom,undef,$maxfilesize);
110: if ($result) {
111: $result =
112: '<div>'.$hiddendraft.
113: &Apache::lonhtmlcommon::start_pick_box().
114: $result.
115: &Apache::lonhtmlcommon::end_pick_box().'</div>';
116: } else {
117: $result = $hiddendraft;
118: }
119: } elsif ($target eq 'web' &&
120: $Apache::inputtags::status[-1] ne 'CAN_ANSWER') {
121: my $part= $Apache::inputtags::part;
122: my @msgs;
123: if ($Apache::lonhomework::history{"resource.$part.$id.collaborators"} =~ /\S/) {
124: my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
125: $result .= '<td><i>'.&mt('Collaborated with [_1]',$coll).'</i></td>';
126: }
127:
128: my $current_files_display = &Apache::inputtags::current_file_submissions($part,$id);
129: if ($current_files_display) {
130: $result .= '<td><b>'.&mt('Submitted files:').'</b><br />'.
131: $current_files_display.'</td>';
132: }
133:
134: if ($result ne '') {
135: $result =
136: '<table class="LC_pastsubmission"><tr>'.$result.
137: '</tr></table>';
138: }
139: }
140: return $result;
141: }
142:
143: sub end_essayresponse {
144: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
145: my $part = $Apache::inputtags::part;
146: my $id = $Apache::inputtags::response[-1];
147: my $increment = &Apache::response::repetition();
148: my $result;
149: if ( $target eq 'grade' ) {
150: # Deal with collaborators
151: my $collaborators = $env{'form.HWCOL'.$part.'_'.$id};
152: my $previous_list= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
153: if ($collaborators ne $previous_list) {
154: # &Apache::lonnet::logthis("New collaborators [$collaborators] [$previous_list]");
155: $Apache::lonhomework::results{"resource.$part.$id.collaborators"}=$collaborators;
156: }
157: # Scantron
158: if ( &Apache::response::submitted('scantron') ) {
159: $increment=&Apache::response::scored_response($part,$id);
160: } elsif ( &Apache::response::submitted() ) {
161: my $response = $env{'form.HWVAL_'.$id};
162: my $jspart=$part;
163: $jspart=~s/\./_/g;
164: my $filename = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'} ||
165: $env{'form.HWFILETOOBIG'.$part.'_'.$id};
166: my $portfiles = $env{'form.HWPORT'.$jspart.'_'.$id};
167: my @deletions = &Apache::loncommon::get_env_multiple('form.HWFILE'.$jspart.'_'.$id.'_delete');
168: my ($is_submit,$was_draft);
169: if ($env{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
170: $is_submit = 1;
171: }
172: if ($Apache::lonhomework::history{"resource.$part.award"} eq 'DRAFT') {
173: $was_draft = 1;
174: }
175: if (($response =~ /[^\s]/) || ($filename =~ /[^\s]/) || ($portfiles =~ /[^\s]/) ||
176: (@deletions > 0) || ($was_draft && $is_submit)) {
177: my $award='DRAFT';
178: if ($env{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
179: if ($Apache::lonhomework::type eq 'anonsurvey') {
180: $award='ANONYMOUS';
181: } elsif ($Apache::lonhomework::type eq 'anonsurveycred') {
182: $award='ANONYMOUS_CREDIT';
183: } elsif ($Apache::lonhomework::type eq 'surveycred') {
184: $award='SUBMITTED_CREDIT';
185: } else {
186: $award='SUBMITTED';
187: }
188: }
189: my $uploadedflag=0;
190: my $totalsize=0;
191: &file_submission($part,$id,\$award,\$uploadedflag,\$totalsize,\@deletions);
192: $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
193: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
194: my %previous=&Apache::response::check_for_previous($response,$part,$id);
195: if ($uploadedflag) {
196: if ($award eq 'FILENAME_INUSE') {
197: delete($Apache::lonhomework::results{"resource.$id.tries"});
198: }
199: } else {
200: &Apache::response::handle_previous(\%previous,$award);
201: }
202: #
203: # Store with resource author for similarity testing
204: #
205: if ($award eq 'SUBMITTED') {
206: my ($symb,$crsid,$domain,$name)=
207: &Apache::lonnet::whichuser();
208: if ($crsid) {
209: my $akey=join('.',&escape($name),&escape($domain),
210: &escape($crsid));
211: my $essayurl=
212: &Apache::lonnet::declutter($ENV{'REQUEST_URI'});
213: my ($adom,$aname,$apath)=
214: ($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
215: $apath=&escape($apath);
216: $apath=~s/\W/\_/gs;
217: &Apache::lonnet::put('nohist_essay_'.$apath,
218: { $akey => $response },$adom,$aname);
219: }
220: }
221: }
222: }
223: } elsif ($target eq 'edit') {
224: $result.=&Apache::edit::end_table();
225:
226: } elsif ($target eq 'tex'
227: && $Apache::lonhomework::type eq 'exam') {
228: $result .= &Apache::inputtags::exam_score_line($target);
229:
230: } elsif ($target eq 'answer') {
231: $result.=&Apache::response::answer_header($$tagstack[-1]);
232: my $answer = &mt('Essay will be hand graded.');
233: $result.=&Apache::response::answer_part($$tagstack[-1],$answer,
234: {'no_verbatim' => 1});
235: $result.=&Apache::response::answer_footer($$tagstack[-1]);
236: }
237: if ($target eq 'web') {
238: &Apache::response::setup_prior_tries_hash(\&format_prior_response,
239: ['portfiles',
240: 'uploadedurl']);
241: }
242:
243: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
244: $target eq 'tex' || $target eq 'analyze') {
245: &Apache::lonxml::increment_counter($increment, "$part.$id");
246:
247: if ($target eq 'analyze') {
248: $Apache::lonhomework::analyze{"$part.$id.type"} = 'essayresponse';
249: push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
250: &Apache::lonhomework::set_bubble_lines();
251: }
252: }
253: &Apache::response::end_response;
254:
255: return $result;
256: }
257:
258: sub format_prior_response {
259: my ($mode,$answer,$other_data) = @_;
260: my $output;
261:
262: my (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
263: my $port_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
264:
265: my $file_list;
266:
267: foreach my $file (split(/\s*,\s*/,
268: $other_data->[0].','.$other_data->[1])) {
269: next if ($file!~/\S/);
270: if ($file !~ m{^/uploaded/}) { $file=$port_url.$file; }
271: $file=~s|/+|/|g;
272: &Apache::lonnet::allowuploaded('/adm/essayresponse',$file);
273: $file_list.='<li><span class="LC_nobreak"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
274: &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
275: '</a></span></li>'."\n";
276: }
277: if ($file_list) {
278: $output.= &mt('Submitted Files').'<ul>'.$file_list.'</ul>';
279: }
280: if ($answer =~ /\S/) {
281: $output.='<p>'.&mt('Submitted text').
282: '<blockquote>'.$answer.'</blockquote></p>';
283: }
284:
285: return '<div class="LC_prior_essay">'.$output.'</div>';
286: }
287:
288: sub file_submission {
289: my ($part,$id,$award,$uploadedflag,$totalsize,$deletions)=@_;
290: my $files;
291: my $jspart=$part;
292: $jspart=~s/\./_/g;
293: my ($symb,$crsid,$udom,$uname) = &Apache::lonnet::whichuser();
294: my %crsinfo = &Apache::lonnet::coursedescription($crsid);
295: my $cdom = $crsinfo{'domain'};
296: my $cnum = $crsinfo{'num'};
297: my (@portfiles,$uploadedurl,@submitted_portfiles,$submitted_upload,
298: @acceptable_portfiles,$acceptable_upload,@accepted_portfiles,
299: $accepted_upload,@savedportfiles,$stored_upload,@tolock,
300: %port_delete,$uploaded_delete);
301: if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ||
302: $Apache::lonhomework::history{"resource.$part.$id.uploadedurl"}) {
303: if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}) {
304: @portfiles = split(/,/,$Apache::lonhomework::history{"resource.$part.$id.portfiles"});
305: }
306: $uploadedurl = $Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
307: if (ref($deletions) eq 'ARRAY') {
308: if (@{$deletions} > 0) {
309: foreach my $file (@{$deletions}) {
310: $file = &HTML::Entities::decode($file);
311: if (grep(/^\Q$file\E$/,@portfiles)) {
312: $port_delete{$file} = 1;
313: } elsif ($file =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/essayresponse/\Q$cdom\E/\Q$cnum\E/}) {
314: $uploaded_delete = $file;
315: } elsif ($file =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/essayresponse/[^/]+$}) {
316: $uploaded_delete = $file;
317: }
318: }
319: }
320: }
321: foreach my $current (@portfiles) {
322: unless ($port_delete{$current}) {
323: push(@savedportfiles,$current);
324: }
325: }
326: if ($uploaded_delete) {
327: if ($uploaded_delete eq $uploadedurl) {
328: $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"} = "";
329: $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"} = "";
330: } else {
331: undef($uploaded_delete);
332: }
333: }
334: }
335: if ($env{'form.HWPORT'.$jspart.'_'.$id} ne '') {
336: my $newfiles= $env{'form.HWPORT'.$jspart.'_'.$id};
337: $newfiles =~s/,$//;
338: if ($newfiles =~ /[^\s]/) {
339: foreach my $file (split(/\s*,\s*/,$newfiles)) {
340: if ($file =~ /[^\s]/) {
341: push(@submitted_portfiles,$file);
342: }
343: }
344: }
345: }
346: if ($env{'form.HWFILETOOBIG'.$part.'_'.$id} ne '') {
347: $$award = 'EXCESS_FILESIZE';
348: } elsif ($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'} ne '') {
349: my $newfile = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'};
350: if ($newfile =~ /[^\s]/) {
351: $submitted_upload = $newfile;
352: }
353: }
354: if (@savedportfiles) {
355: foreach my $file (reverse(@savedportfiles)) {
356: unless(grep(/^\Q$file\E$/,@submitted_portfiles)) {
357: unshift(@submitted_portfiles,$file);
358: }
359: }
360: }
361: if (@submitted_portfiles || $submitted_upload) {
362: my $uploadedfiletypes=
363: &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
364: if ($uploadedfiletypes ne '') {
365: $uploadedfiletypes=~s/[^\w\,]//g;
366: $uploadedfiletypes=','.$uploadedfiletypes.',';
367: if (@submitted_portfiles) {
368: foreach my $file (@submitted_portfiles) {
369: my ($extension)=($file=~/\.(\w+)$/);
370: if ($uploadedfiletypes=~/\,\s*\Q$extension\E\s*\,/i) {
371: push(@acceptable_portfiles,$file);
372: }
373: }
374: }
375: if ($submitted_upload) {
376: my ($upload_ext)=($submitted_upload=~/\.(\w+)$/);
377: if ($uploadedfiletypes=~/\,\s*\Q$upload_ext\E\s*\,/i) {
378: $acceptable_upload = $submitted_upload;
379: } else {
380: $$award='INVALID_FILETYPE';
381: &delete_form_items($jspart,$id);
382: }
383: }
384: } else {
385: @acceptable_portfiles = @submitted_portfiles;
386: $acceptable_upload = $submitted_upload;
387: }
388: }
389: if ((@acceptable_portfiles) || ($acceptable_upload ne '')) {
390: my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
391: if (!$maxfilesize) {
392: $maxfilesize = 10.0; #FIXME This should become a domain configuration
393: }
394: my %dirlist;
395: if (@acceptable_portfiles) {
396: foreach my $file (@acceptable_portfiles) {
397: my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
398: my $fullpath = '/userfiles/portfolio'.$path;
399: if (!exists($dirlist{$fullpath})) {
400: my ($listref,$listerror) =
401: &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
402: if (ref($listref) eq 'ARRAY') {
403: $dirlist{$fullpath} = $listref;
404: }
405: }
406: if (ref($dirlist{$fullpath}) eq 'ARRAY') {
407: foreach my $dir_line (@{$dirlist{$fullpath}}) {
408: my ($fname,$dom,undef,$testdir,undef,undef,undef,undef,
409: $size,undef,$mtime,undef,undef,undef,$obs,undef) =
410: split(/\&/,$dir_line,16);
411: if ($filename eq $fname) {
412: my $mbsize = $size/(1024.0*1024.0);
413: if (ref($totalsize)) {
414: $$totalsize += $mbsize;
415: }
416: last;
417: }
418: }
419: }
420: if (ref($totalsize)) {
421: if ($$totalsize > $maxfilesize) {
422: $$award='EXCESS_FILESIZE';
423: &delete_form_items($jspart,$id);
424: } else {
425: push(@accepted_portfiles,$file);
426: }
427: } else {
428: push(@accepted_portfiles,$file);
429: }
430: }
431: }
432: if ($acceptable_upload ne '') {
433: if (ref($totalsize)) {
434: $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
435: if ($$totalsize > $maxfilesize) {
436: $$award='EXCESS_FILESIZE';
437: delete($env{'form.HWFILE'.$jspart.'_'.$id});
438: } else {
439: $accepted_upload = $acceptable_upload;
440: }
441: } else {
442: $accepted_upload = $acceptable_upload;
443: }
444: }
445: }
446: if ($accepted_upload ne '') {
447: my ($path,$multiresp) =
448: &Apache::loncommon::get_turnedin_filepath($symb,$uname,$udom,
449: 'submission');
450: if ($path eq '') {
451: $$award = 'INTERNAL_ERROR';
452: } else {
453: if ($multiresp) {
454: $path .= '/'.$jspart.'_'.$id;
455: }
456: my $prefix = 'portfolio';
457: my $formelement = 'HWFILE'.$jspart.'_'.$id;
458: my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formelement.'.filename'});
459: my $url = '/uploaded/'.$udom.'/'.$uname.'/'.$prefix.$path.'/'.$fname;
460: my @stat = &Apache::lonnet::stat_file($url);
461: my $conflicts = 0;
462: if (@stat && $stat[0] ne 'no_such_dir') {
463: my $current_permissions =
464: &Apache::lonnet::get_portfile_permissions($udom,$uname);
465: if (ref($current_permissions) eq 'HASH') {
466: if (ref($current_permissions->{$path.'/'.$fname}) eq 'ARRAY') {
467: foreach my $record (@{$current_permissions->{$path.'/'.$fname}}) {
468: if (ref($record) eq 'ARRAY') {
469: next if (($record->[0] eq $symb) &&
470: ($record->[1] eq $crsid));
471: $conflicts ++;
472: }
473: }
474: }
475: }
476: if ($conflicts) {
477: $$award = 'FILENAME_INUSE';
478: }
479: }
480: unless ($conflicts) {
481: my ($mode,%allfiles,%codebase);
482: my $result = &Apache::lonnet::userfileupload($formelement,'',
483: $prefix.$path,$mode,\%allfiles,\%codebase);
484: if ($result =~ m{^/uploaded/}) {
485: $stored_upload = $path.'/'.$fname;
486: unless (grep(/^\Q$stored_upload\E$/,@accepted_portfiles)) {
487: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = $stored_upload;
488: push(@tolock,$stored_upload);
489: }
490: } else {
491: $$award = 'INTERNAL_ERROR';
492: }
493: }
494: }
495: delete($env{'form.HWFILE'.$jspart.'_'.$id});
496: }
497: if (@accepted_portfiles) {
498: if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
499: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} .= ',';
500: }
501: $Apache::lonhomework::results{"resource.$part.$id.portfiles"}.=join(',',@accepted_portfiles);
502: push(@tolock,@accepted_portfiles);
503: }
504: if (!defined($Apache::lonhomework::results{"resource.$part.$id.portfiles"})) {
505: if (keys(%port_delete) > 0) {
506: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = "";
507: }
508: }
509: if (($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ne
510: $Apache::lonhomework::results{"resource.$part.$id.portfiles"}) ||
511: ($uploaded_delete)) {
512: if (ref($uploadedflag)) {
513: $$uploadedflag=1;
514: }
515: }
516: &Apache::lonnet::unmark_as_readonly($udom,$uname,[$symb,$crsid]);
517: &Apache::lonnet::mark_as_readonly($udom,$uname,[@tolock],[$symb,$crsid]);
518: &Apache::lonnet::clear_selected_files($uname);
519: return;
520: }
521:
522: sub delete_form_items {
523: my ($jspart,$id) = @_;
524: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'});
525: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.mimetype'});
526: delete($env{'form.HWFILE'.$jspart.'_'.$id});
527: }
528:
529: sub check_collaborators {
530: my ($ncol,$coll) = @_;
531: my %classlist=&Apache::lonnet::dump('classlist',
532: $env{'course.'.$env{'request.course.id'}.'.domain'},
533: $env{'course.'.$env{'request.course.id'}.'.num'});
534: my (@badcollaborators,$result);
535:
536: my (@collaborators) = split(/[,;\s]+/,$coll);
537: foreach my $entry (@collaborators) {
538: my $collaborator;
539: if ($entry =~ /:/) {
540: $collaborator = $entry;
541: } else {
542: $collaborator = $entry.':'.$env{'user.domain'};
543: }
544: if ($collaborator !~ /^$match_username:$match_domain$/) {
545: if (!grep(/^\Q$entry\E$/,@badcollaborators)) {
546: push(@badcollaborators,$entry);
547: }
548: } elsif (!grep(/^\Q$collaborator\E$/i,keys(%classlist))) {
549: if (!grep(/^\Q$entry\E$/,@badcollaborators)) {
550: push(@badcollaborators,$entry);
551: }
552: }
553: }
554:
555: my $numbad = scalar(@badcollaborators);
556: if ($numbad) {
557: $result = '<table border="0"><tr bgcolor="#ffbbbb"><td>';
558: if ($numbad == 1) {
559: $result .= &mt('The following user is invalid:');
560: } else {
561: $result .= &mt('The following [_1] users are invalid:',$numbad);
562: }
563: $result .= ' '.join(', ',@badcollaborators).'. '.&mt('Please correct.').
564: '</td></tr></table>';
565: }
566: my $toomany = scalar(@collaborators) - $ncol;
567: if ($toomany > 0) {
568: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>'.
569: &mt('You have too many collaborators.').' '.
570: &mt('Please remove [quant,_1,collaborator].',$toomany).
571: '</td></tr></table>';
572: }
573: return $result;
574: }
575:
576: 1;
577: __END__
578:
579:
580: =pod
581:
582: =head1 NAME
583:
584: Apache::essayresponse
585:
586: =head1 SYNOPSIS
587:
588: Handler to evaluate essay (ungraded) style responses.
589:
590: This is part of the LearningOnline Network with CAPA project
591: described at http://www.lon-capa.org.
592:
593: =head1 SUBROUTINES
594:
595: =over
596:
597: =item start_essayresponse()
598:
599: =item end_essayresponse()
600:
601: =item format_prior_response()
602:
603: =item file_submission()
604:
605: =item delete_form_items()
606:
607: =item check_collaborators()
608:
609: =back
610:
611: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>