File:
[LON-CAPA] /
loncom /
homework /
essayresponse.pm
Revision
1.118.2.1:
download - view:
text,
annotated -
select for diffs
Tue Feb 19 14:24:38 2019 UTC (5 years, 6 months ago) by
raeburn
Branches:
version_2_11_X
CVS tags:
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3
Diff to branchpoint 1.118:
preferred,
unified
- For 2.11
Backport 1.125, 1.126
1: # The LearningOnline Network with CAPA
2: # essay (ungraded) style responses
3: #
4: # $Id: essayresponse.pm,v 1.118.2.1 2019/02/19 14:24:38 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: if ($essayurl eq 'lib/templates/simpleproblem.problem') {
214: my %crsinfo = &Apache::lonnet::coursedescription($crsid);
215: my $cdom = $crsinfo{'domain'};
216: my $cnum = $crsinfo{'num'};
217: my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
218: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(default(?:|_\d+)\.(?:sequence|page))$}) {
219: my $apath = $1.'_'.$id;
220: $apath=~s/\W/\_/gs;
221: my $akey = join('.',&escape($name),&escape($domain));
222: &Apache::lonnet::put('nohist_essay_'.$apath,
223: { $akey => $response },$cdom,$cnum);
224: }
225: } else {
226: my ($adom,$aname,$apath)=
227: ($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
228: $apath=&escape($apath);
229: $apath=~s/\W/\_/gs;
230: &Apache::lonnet::put('nohist_essay_'.$apath,
231: { $akey => $response },$adom,$aname);
232: }
233: }
234: }
235: }
236: }
237: } elsif ($target eq 'edit') {
238: $result.=&Apache::edit::end_table();
239:
240: } elsif ($target eq 'tex'
241: && $Apache::lonhomework::type eq 'exam') {
242: $result .= &Apache::inputtags::exam_score_line($target);
243:
244: } elsif ($target eq 'answer') {
245: $result.=&Apache::response::answer_header($$tagstack[-1]);
246: my $answer = &mt('Essay will be hand graded.');
247: $result.=&Apache::response::answer_part($$tagstack[-1],$answer,
248: {'no_verbatim' => 1});
249: $result.=&Apache::response::answer_footer($$tagstack[-1]);
250: }
251: if ($target eq 'web') {
252: &Apache::response::setup_prior_tries_hash(\&format_prior_response,
253: ['portfiles',
254: 'uploadedurl']);
255: }
256:
257: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
258: $target eq 'tex' || $target eq 'analyze') {
259: &Apache::lonxml::increment_counter($increment, "$part.$id");
260:
261: if ($target eq 'analyze') {
262: $Apache::lonhomework::analyze{"$part.$id.type"} = 'essayresponse';
263: push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
264: &Apache::lonhomework::set_bubble_lines();
265: }
266: }
267: &Apache::response::end_response;
268:
269: return $result;
270: }
271:
272: sub format_prior_response {
273: my ($mode,$answer,$other_data) = @_;
274: my $output;
275:
276: my (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
277: my $port_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
278:
279: my $file_list;
280:
281: foreach my $file (split(/\s*,\s*/,
282: $other_data->[0].','.$other_data->[1])) {
283: next if ($file!~/\S/);
284: if ($file !~ m{^/uploaded/}) { $file=$port_url.$file; }
285: $file=~s|/+|/|g;
286: &Apache::lonnet::allowuploaded('/adm/essayresponse',$file);
287: $file_list.='<li><span class="LC_nobreak"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
288: &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
289: '</a></span></li>'."\n";
290: }
291: if ($file_list) {
292: $output.= &mt('Submitted Files').'<ul>'.$file_list.'</ul>';
293: }
294: if ($answer =~ /\S/) {
295: $output.='<p>'.&mt('Submitted text').
296: '<blockquote>'.&HTML::Entities::encode($answer, '"<>&').'</blockquote></p>';
297: }
298:
299: return '<div class="LC_prior_essay">'.$output.'</div>';
300: }
301:
302: sub file_submission {
303: my ($part,$id,$award,$uploadedflag,$totalsize,$deletions)=@_;
304: my $files;
305: my $jspart=$part;
306: $jspart=~s/\./_/g;
307: my ($symb,$crsid,$udom,$uname) = &Apache::lonnet::whichuser();
308: my %crsinfo = &Apache::lonnet::coursedescription($crsid);
309: my $cdom = $crsinfo{'domain'};
310: my $cnum = $crsinfo{'num'};
311: my (@portfiles,$uploadedurl,@submitted_portfiles,$submitted_upload,
312: @acceptable_portfiles,$acceptable_upload,@accepted_portfiles,
313: $accepted_upload,@savedportfiles,$stored_upload,@tolock,
314: %port_delete,$uploaded_delete);
315: if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ||
316: $Apache::lonhomework::history{"resource.$part.$id.uploadedurl"}) {
317: if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}) {
318: @portfiles = split(/,/,$Apache::lonhomework::history{"resource.$part.$id.portfiles"});
319: }
320: $uploadedurl = $Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
321: if (ref($deletions) eq 'ARRAY') {
322: if (@{$deletions} > 0) {
323: foreach my $file (@{$deletions}) {
324: $file = &HTML::Entities::decode($file);
325: if (grep(/^\Q$file\E$/,@portfiles)) {
326: $port_delete{$file} = 1;
327: } elsif ($file =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/essayresponse/\Q$cdom\E/\Q$cnum\E/}) {
328: $uploaded_delete = $file;
329: } elsif ($file =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/essayresponse/[^/]+$}) {
330: $uploaded_delete = $file;
331: }
332: }
333: }
334: }
335: foreach my $current (@portfiles) {
336: unless ($port_delete{$current}) {
337: push(@savedportfiles,$current);
338: }
339: }
340: if ($uploaded_delete) {
341: if ($uploaded_delete eq $uploadedurl) {
342: $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"} = "";
343: $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"} = "";
344: } else {
345: undef($uploaded_delete);
346: }
347: }
348: }
349: if ($env{'form.HWPORT'.$jspart.'_'.$id} ne '') {
350: my $newfiles= $env{'form.HWPORT'.$jspart.'_'.$id};
351: $newfiles =~s/,$//;
352: if ($newfiles =~ /[^\s]/) {
353: foreach my $file (split(/\s*,\s*/,$newfiles)) {
354: if ($file =~ /[^\s]/) {
355: push(@submitted_portfiles,$file);
356: }
357: }
358: }
359: }
360: if ($env{'form.HWFILETOOBIG'.$part.'_'.$id} ne '') {
361: $$award = 'EXCESS_FILESIZE';
362: } elsif ($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'} ne '') {
363: my $newfile = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'};
364: if ($newfile =~ /[^\s]/) {
365: $submitted_upload = $newfile;
366: }
367: }
368: if (@savedportfiles) {
369: foreach my $file (reverse(@savedportfiles)) {
370: unless(grep(/^\Q$file\E$/,@submitted_portfiles)) {
371: unshift(@submitted_portfiles,$file);
372: }
373: }
374: }
375: if (@submitted_portfiles || $submitted_upload) {
376: my $uploadedfiletypes=
377: &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
378: if ($uploadedfiletypes ne '') {
379: $uploadedfiletypes=~s/[^\w\,]//g;
380: $uploadedfiletypes=','.$uploadedfiletypes.',';
381: if (@submitted_portfiles) {
382: foreach my $file (@submitted_portfiles) {
383: my ($extension)=($file=~/\.(\w+)$/);
384: if ($uploadedfiletypes=~/\,\s*\Q$extension\E\s*\,/i) {
385: push(@acceptable_portfiles,$file);
386: }
387: }
388: }
389: if ($submitted_upload) {
390: my ($upload_ext)=($submitted_upload=~/\.(\w+)$/);
391: if ($uploadedfiletypes=~/\,\s*\Q$upload_ext\E\s*\,/i) {
392: $acceptable_upload = $submitted_upload;
393: } else {
394: $$award='INVALID_FILETYPE';
395: &delete_form_items($jspart,$id);
396: }
397: }
398: } else {
399: @acceptable_portfiles = @submitted_portfiles;
400: $acceptable_upload = $submitted_upload;
401: }
402: }
403: if ((@acceptable_portfiles) || ($acceptable_upload ne '')) {
404: my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
405: if (!$maxfilesize) {
406: $maxfilesize = 10.0; #FIXME This should become a domain configuration
407: }
408: my %dirlist;
409: if (@acceptable_portfiles) {
410: foreach my $file (@acceptable_portfiles) {
411: my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
412: my $fullpath = '/userfiles/portfolio'.$path;
413: if (!exists($dirlist{$fullpath})) {
414: my ($listref,$listerror) =
415: &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
416: if (ref($listref) eq 'ARRAY') {
417: $dirlist{$fullpath} = $listref;
418: }
419: }
420: if (ref($dirlist{$fullpath}) eq 'ARRAY') {
421: foreach my $dir_line (@{$dirlist{$fullpath}}) {
422: my ($fname,$dom,undef,$testdir,undef,undef,undef,undef,
423: $size,undef,$mtime,undef,undef,undef,$obs,undef) =
424: split(/\&/,$dir_line,16);
425: if ($filename eq $fname) {
426: my $mbsize = $size/(1024.0*1024.0);
427: if (ref($totalsize)) {
428: $$totalsize += $mbsize;
429: }
430: last;
431: }
432: }
433: }
434: if (ref($totalsize)) {
435: if ($$totalsize > $maxfilesize) {
436: $$award='EXCESS_FILESIZE';
437: &delete_form_items($jspart,$id);
438: } else {
439: push(@accepted_portfiles,$file);
440: }
441: } else {
442: push(@accepted_portfiles,$file);
443: }
444: }
445: }
446: if ($acceptable_upload ne '') {
447: if (ref($totalsize)) {
448: $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
449: if ($$totalsize > $maxfilesize) {
450: $$award='EXCESS_FILESIZE';
451: delete($env{'form.HWFILE'.$jspart.'_'.$id});
452: } else {
453: $accepted_upload = $acceptable_upload;
454: }
455: } else {
456: $accepted_upload = $acceptable_upload;
457: }
458: }
459: }
460: if ($accepted_upload ne '') {
461: my ($path,$multiresp) =
462: &Apache::loncommon::get_turnedin_filepath($symb,$uname,$udom,
463: 'submission');
464: if ($path eq '') {
465: $$award = 'INTERNAL_ERROR';
466: } else {
467: if ($multiresp) {
468: $path .= '/'.$jspart.'_'.$id;
469: }
470: my $prefix = 'portfolio';
471: my $formelement = 'HWFILE'.$jspart.'_'.$id;
472: my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formelement.'.filename'});
473: my $url = '/uploaded/'.$udom.'/'.$uname.'/'.$prefix.$path.'/'.$fname;
474: my @stat = &Apache::lonnet::stat_file($url);
475: my $conflicts = 0;
476: if (@stat && $stat[0] ne 'no_such_dir') {
477: my $current_permissions =
478: &Apache::lonnet::get_portfile_permissions($udom,$uname);
479: if (ref($current_permissions) eq 'HASH') {
480: if (ref($current_permissions->{$path.'/'.$fname}) eq 'ARRAY') {
481: foreach my $record (@{$current_permissions->{$path.'/'.$fname}}) {
482: if (ref($record) eq 'ARRAY') {
483: next if (($record->[0] eq $symb) &&
484: ($record->[1] eq $crsid));
485: $conflicts ++;
486: }
487: }
488: }
489: }
490: if ($conflicts) {
491: $$award = 'FILENAME_INUSE';
492: }
493: }
494: unless ($conflicts) {
495: my ($mode,%allfiles,%codebase);
496: my $result = &Apache::lonnet::userfileupload($formelement,'',
497: $prefix.$path,$mode,\%allfiles,\%codebase);
498: if ($result =~ m{^/uploaded/}) {
499: $stored_upload = $path.'/'.$fname;
500: unless (grep(/^\Q$stored_upload\E$/,@accepted_portfiles)) {
501: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = $stored_upload;
502: push(@tolock,$stored_upload);
503: }
504: } else {
505: $$award = 'INTERNAL_ERROR';
506: }
507: }
508: }
509: delete($env{'form.HWFILE'.$jspart.'_'.$id});
510: }
511: if (@accepted_portfiles) {
512: if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
513: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} .= ',';
514: }
515: $Apache::lonhomework::results{"resource.$part.$id.portfiles"}.=join(',',@accepted_portfiles);
516: push(@tolock,@accepted_portfiles);
517: }
518: if (!defined($Apache::lonhomework::results{"resource.$part.$id.portfiles"})) {
519: if (keys(%port_delete) > 0) {
520: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = "";
521: }
522: }
523: if (($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ne
524: $Apache::lonhomework::results{"resource.$part.$id.portfiles"}) ||
525: ($uploaded_delete)) {
526: if (ref($uploadedflag)) {
527: $$uploadedflag=1;
528: }
529: }
530: &Apache::lonnet::unmark_as_readonly($udom,$uname,[$symb,$crsid]);
531: &Apache::lonnet::mark_as_readonly($udom,$uname,[@tolock],[$symb,$crsid]);
532: &Apache::lonnet::clear_selected_files($uname);
533: return;
534: }
535:
536: sub delete_form_items {
537: my ($jspart,$id) = @_;
538: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'});
539: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.mimetype'});
540: delete($env{'form.HWFILE'.$jspart.'_'.$id});
541: }
542:
543: sub check_collaborators {
544: my ($ncol,$coll) = @_;
545: my %classlist=&Apache::lonnet::dump('classlist',
546: $env{'course.'.$env{'request.course.id'}.'.domain'},
547: $env{'course.'.$env{'request.course.id'}.'.num'});
548: my (@badcollaborators,$result);
549:
550: my (@collaborators) = split(/[,;\s]+/,$coll);
551: foreach my $entry (@collaborators) {
552: my $collaborator;
553: if ($entry =~ /:/) {
554: $collaborator = $entry;
555: } else {
556: $collaborator = $entry.':'.$env{'user.domain'};
557: }
558: if ($collaborator !~ /^$match_username:$match_domain$/) {
559: if (!grep(/^\Q$entry\E$/,@badcollaborators)) {
560: push(@badcollaborators,$entry);
561: }
562: } elsif (!grep(/^\Q$collaborator\E$/i,keys(%classlist))) {
563: if (!grep(/^\Q$entry\E$/,@badcollaborators)) {
564: push(@badcollaborators,$entry);
565: }
566: }
567: }
568:
569: my $numbad = scalar(@badcollaborators);
570: if ($numbad) {
571: $result = '<table border="0"><tr bgcolor="#ffbbbb"><td>';
572: if ($numbad == 1) {
573: $result .= &mt('The following user is invalid:');
574: } else {
575: $result .= &mt('The following [_1] users are invalid:',$numbad);
576: }
577: $result .= ' '.join(', ',@badcollaborators).'. '.&mt('Please correct.').
578: '</td></tr></table>';
579: }
580: my $toomany = scalar(@collaborators) - $ncol;
581: if ($toomany > 0) {
582: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>'.
583: &mt('You have too many collaborators.').' '.
584: &mt('Please remove [quant,_1,collaborator].',$toomany).
585: '</td></tr></table>';
586: }
587: return $result;
588: }
589:
590: 1;
591: __END__
592:
593:
594: =pod
595:
596: =head1 NAME
597:
598: Apache::essayresponse
599:
600: =head1 SYNOPSIS
601:
602: Handler to evaluate essay (ungraded) style responses.
603:
604: This is part of the LearningOnline Network with CAPA project
605: described at http://www.lon-capa.org.
606:
607: =head1 SUBROUTINES
608:
609: =over
610:
611: =item start_essayresponse()
612:
613: =item end_essayresponse()
614:
615: =item format_prior_response()
616:
617: =item file_submission()
618:
619: =item delete_form_items()
620:
621: =item check_collaborators()
622:
623: =back
624:
625: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>