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