Annotation of loncom/homework/essayresponse.pm, revision 1.124
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # essay (ungraded) style responses
1.5 albertel 3: #
1.124 ! raeburn 4: # $Id: essayresponse.pm,v 1.123 2014/12/22 17:04:03 raeburn Exp $
1.5 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.33 albertel 28:
1.1 albertel 29: package Apache::essayresponse;
30: use strict;
1.33 albertel 31: use Apache::lonxml();
1.108 raeburn 32: use Apache::lonhtmlcommon;
33: use Apache::loncommon;
1.62 albertel 34: use Apache::lonnet;
1.108 raeburn 35: use Apache::lonnavmaps;
1.33 albertel 36: use Apache::lonlocal;
1.88 raeburn 37: use LONCAPA qw(:DEFAULT :match);
1.72 www 38:
1.1 albertel 39:
1.6 harris41 40: BEGIN {
1.10 ng 41: &Apache::lonxml::register('Apache::essayresponse',('essayresponse'));
1.1 albertel 42: }
43:
44: sub start_essayresponse {
1.10 ng 45: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
46: my $result;
1.14 albertel 47: my $id = &Apache::response::start_response($parstack,$safeeval);
48: if ($target eq 'meta') {
49: $result=&Apache::response::meta_package_write('essayresponse');
1.121 raeburn 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 {
1.124 ! raeburn 71: $result = &draft_row($part,$id,$ncol,$uploadedfiletypes,'essayresponse');
1.121 raeburn 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;
1.114 raeburn 92: }
93: } else {
1.121 raeburn 94: $result = &show_status_table($part,$id,$coll);
1.114 raeburn 95: }
1.121 raeburn 96: }
97: return $result;
98: }
99:
100: sub draft_row {
1.123 raeburn 101: my ($part,$id,$ncol,$uploadedfiletypes,$resptype) = @_;
1.121 raeburn 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: }
1.123 raeburn 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: );
1.121 raeburn 120: return &Apache::lonhtmlcommon::row_title($status_text).
121: '<label>'.
122: '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" />'.
1.123 raeburn 123: ' '.$label{'submit'}{$resptype}.'</label> <br />'.
1.121 raeburn 124: '<label>'.
125: '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.
1.123 raeburn 126: $label{'draft'}{$resptype}.'</label>'.
1.121 raeburn 127: &Apache::lonhtmlcommon::row_closure($closure);
128: }
1.74 albertel 129:
1.121 raeburn 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: }
1.74 albertel 146:
1.121 raeburn 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>';
1.10 ng 161: }
1.121 raeburn 162: return;
1.1 albertel 163: }
164:
165: sub end_essayresponse {
1.10 ng 166: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.13 ng 167: my $part = $Apache::inputtags::part;
1.14 albertel 168: my $id = $Apache::inputtags::response[-1];
1.70 albertel 169: my $increment = &Apache::response::repetition();
1.15 albertel 170: my $result;
1.10 ng 171: if ( $target eq 'grade' ) {
1.121 raeburn 172: &get_collaborators($part,$id);
1.106 www 173: # Scantron
1.58 albertel 174: if ( &Apache::response::submitted('scantron') ) {
1.31 albertel 175: $increment=&Apache::response::scored_response($part,$id);
1.58 albertel 176: } elsif ( &Apache::response::submitted() ) {
1.62 albertel 177: my $response = $env{'form.HWVAL_'.$id};
1.110 raeburn 178: my $jspart=$part;
179: $jspart=~s/\./_/g;
180: my $filename = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'} ||
1.91 raeburn 181: $env{'form.HWFILETOOBIG'.$part.'_'.$id};
1.110 raeburn 182: my $portfiles = $env{'form.HWPORT'.$jspart.'_'.$id};
183: my @deletions = &Apache::loncommon::get_env_multiple('form.HWFILE'.$jspart.'_'.$id.'_delete');
1.108 raeburn 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)) {
1.61 albertel 193: my $award='DRAFT';
1.62 albertel 194: if ($env{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
1.102 raeburn 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: }
1.14 albertel 204: }
1.22 www 205: my $uploadedflag=0;
1.91 raeburn 206: my $totalsize=0;
1.108 raeburn 207: &file_submission($part,$id,\$award,\$uploadedflag,\$totalsize,\@deletions);
1.10 ng 208: $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
1.14 albertel 209: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
1.10 ng 210: my %previous=&Apache::response::check_for_previous($response,$part,$id);
1.107 raeburn 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: }
1.32 www 218: #
219: # Store with resource author for similarity testing
220: #
221: if ($award eq 'SUBMITTED') {
222: my ($symb,$crsid,$domain,$name)=
1.77 albertel 223: &Apache::lonnet::whichuser();
1.32 www 224: if ($crsid) {
1.83 albertel 225: my $akey=join('.',&escape($name),&escape($domain),
226: &escape($crsid));
1.32 www 227: my $essayurl=
228: &Apache::lonnet::declutter($ENV{'REQUEST_URI'});
229: my ($adom,$aname,$apath)=
1.80 albertel 230: ($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.72 www 231: $apath=&escape($apath);
1.32 www 232: $apath=~s/\W/\_/gs;
233: &Apache::lonnet::put('nohist_essay_'.$apath,
234: { $akey => $response },$adom,$aname);
235: }
1.42 banghart 236: }
1.108 raeburn 237: }
1.42 banghart 238: }
1.15 albertel 239: } elsif ($target eq 'edit') {
240: $result.=&Apache::edit::end_table();
1.71 albertel 241:
242: } elsif ($target eq 'tex'
243: && $Apache::lonhomework::type eq 'exam') {
244: $result .= &Apache::inputtags::exam_score_line($target);
245:
1.70 albertel 246: } elsif ($target eq 'answer') {
1.78 albertel 247: $result.=&Apache::response::answer_header($$tagstack[-1]);
1.81 foxr 248: my $answer = &mt('Essay will be hand graded.');
1.78 albertel 249: $result.=&Apache::response::answer_part($$tagstack[-1],$answer,
250: {'no_verbatim' => 1});
251: $result.=&Apache::response::answer_footer($$tagstack[-1]);
1.10 ng 252: }
1.82 albertel 253: if ($target eq 'web') {
254: &Apache::response::setup_prior_tries_hash(\&format_prior_response,
255: ['portfiles',
256: 'uploadedurl']);
257: }
1.71 albertel 258:
1.27 albertel 259: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
260: $target eq 'tex' || $target eq 'analyze') {
1.86 foxr 261: &Apache::lonxml::increment_counter($increment, "$part.$id");
1.85 foxr 262:
263: if ($target eq 'analyze') {
1.87 raeburn 264: $Apache::lonhomework::analyze{"$part.$id.type"} = 'essayresponse';
1.96 raeburn 265: push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
1.85 foxr 266: &Apache::lonhomework::set_bubble_lines();
267: }
1.27 albertel 268: }
1.10 ng 269: &Apache::response::end_response;
1.42 banghart 270:
1.15 albertel 271: return $result;
1.10 ng 272: }
273:
1.121 raeburn 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:
1.82 albertel 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').
1.118 kruse 308: '<blockquote>'.&HTML::Entities::encode($answer, '"<>&').'</blockquote></p>';
1.82 albertel 309: }
310:
311: return '<div class="LC_prior_essay">'.$output.'</div>';
312: }
313:
1.61 albertel 314: sub file_submission {
1.119 raeburn 315: my ($part,$id,$award,$uploadedflag,$totalsize,$deletions,$context,$info)=@_;
1.61 albertel 316: my $files;
1.67 albertel 317: my $jspart=$part;
318: $jspart=~s/\./_/g;
1.108 raeburn 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"}) {
1.123 raeburn 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: }
1.108 raeburn 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;
1.112 raeburn 348: } elsif ($file =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/essayresponse/[^/]+$}) {
349: $uploaded_delete = $file;
1.108 raeburn 350: }
351: }
352: }
353: }
354: foreach my $current (@portfiles) {
355: unless ($port_delete{$current}) {
356: push(@savedportfiles,$current);
357: }
358: }
359: if ($uploaded_delete) {
1.112 raeburn 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: }
1.108 raeburn 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: }
1.110 raeburn 379: if ($env{'form.HWFILETOOBIG'.$part.'_'.$id} ne '') {
1.108 raeburn 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;
1.91 raeburn 385: }
1.61 albertel 386: }
1.108 raeburn 387: if (@savedportfiles) {
388: foreach my $file (reverse(@savedportfiles)) {
389: unless(grep(/^\Q$file\E$/,@submitted_portfiles)) {
390: unshift(@submitted_portfiles,$file);
391: }
1.91 raeburn 392: }
1.108 raeburn 393: }
394: if (@submitted_portfiles || $submitted_upload) {
395: my $uploadedfiletypes=
1.91 raeburn 396: &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
1.99 raeburn 397: if ($uploadedfiletypes ne '') {
1.91 raeburn 398: $uploadedfiletypes=~s/[^\w\,]//g;
399: $uploadedfiletypes=','.$uploadedfiletypes.',';
1.108 raeburn 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;
1.91 raeburn 412: } else {
413: $$award='INVALID_FILETYPE';
1.108 raeburn 414: &delete_form_items($jspart,$id);
1.91 raeburn 415: }
416: }
1.99 raeburn 417: } else {
1.108 raeburn 418: @acceptable_portfiles = @submitted_portfiles;
419: $acceptable_upload = $submitted_upload;
1.91 raeburn 420: }
1.108 raeburn 421: }
422: if ((@acceptable_portfiles) || ($acceptable_upload ne '')) {
1.91 raeburn 423: my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
424: if (!$maxfilesize) {
1.93 raeburn 425: $maxfilesize = 10.0; #FIXME This should become a domain configuration
1.91 raeburn 426: }
427: my %dirlist;
1.108 raeburn 428: if (@acceptable_portfiles) {
429: foreach my $file (@acceptable_portfiles) {
1.97 raeburn 430: my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
1.91 raeburn 431: my $fullpath = '/userfiles/portfolio'.$path;
432: if (!exists($dirlist{$fullpath})) {
1.116 raeburn 433: my ($listref,$listerror) =
434: &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
435: if (ref($listref) eq 'ARRAY') {
436: $dirlist{$fullpath} = $listref;
437: }
1.97 raeburn 438: }
439: if (ref($dirlist{$fullpath}) eq 'ARRAY') {
440: foreach my $dir_line (@{$dirlist{$fullpath}}) {
1.91 raeburn 441: my ($fname,$dom,undef,$testdir,undef,undef,undef,undef,
1.108 raeburn 442: $size,undef,$mtime,undef,undef,undef,$obs,undef) =
1.91 raeburn 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: }
1.108 raeburn 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: }
1.91 raeburn 463: }
1.108 raeburn 464: }
465: if ($acceptable_upload ne '') {
1.91 raeburn 466: if (ref($totalsize)) {
1.108 raeburn 467: $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
1.91 raeburn 468: if ($$totalsize > $maxfilesize) {
469: $$award='EXCESS_FILESIZE';
1.108 raeburn 470: delete($env{'form.HWFILE'.$jspart.'_'.$id});
1.94 raeburn 471: } else {
1.108 raeburn 472: $accepted_upload = $acceptable_upload;
1.91 raeburn 473: }
474: } else {
1.108 raeburn 475: $accepted_upload = $acceptable_upload;
1.91 raeburn 476: }
477: }
1.108 raeburn 478: }
479: if ($accepted_upload ne '') {
1.115 raeburn 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: }
1.107 raeburn 506: }
507: }
1.108 raeburn 508: }
1.115 raeburn 509: if ($conflicts) {
510: $$award = 'FILENAME_INUSE';
1.107 raeburn 511: }
1.95 raeburn 512: }
1.115 raeburn 513: unless ($conflicts) {
514: my ($mode,%allfiles,%codebase);
515: my $result = &Apache::lonnet::userfileupload($formelement,'',
1.108 raeburn 516: $prefix.$path,$mode,\%allfiles,\%codebase);
1.115 raeburn 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: }
1.95 raeburn 526: }
1.108 raeburn 527: }
528: delete($env{'form.HWFILE'.$jspart.'_'.$id});
529: }
530: if (@accepted_portfiles) {
1.115 raeburn 531: if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
1.108 raeburn 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: }
1.112 raeburn 542: if (($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ne
543: $Apache::lonhomework::results{"resource.$part.$id.portfiles"}) ||
544: ($uploaded_delete)) {
1.108 raeburn 545: if (ref($uploadedflag)) {
546: $$uploadedflag=1;
547: }
1.61 albertel 548: }
1.119 raeburn 549: if ($context eq 'externalresponse') {
1.120 raeburn 550: my @todelete = map { "/uploaded/$udom/$uname/portfolio".$_; } keys(%port_delete);
1.119 raeburn 551: if (@tolock || @todelete) {
552: if (ref($info) eq 'HASH') {
1.122 raeburn 553: if (($info->{'ip'}) && ($info->{'is_submit'})) {
1.120 raeburn 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);
1.119 raeburn 559: }
560: }
561: }
562: }
1.108 raeburn 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;
1.61 albertel 567: }
568:
1.91 raeburn 569: sub delete_form_items {
570: my ($jspart,$id) = @_;
1.98 raeburn 571: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'});
572: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.mimetype'});
573: delete($env{'form.HWFILE'.$jspart.'_'.$id});
1.91 raeburn 574: }
575:
1.10 ng 576: sub check_collaborators {
1.11 ng 577: my ($ncol,$coll) = @_;
1.10 ng 578: my %classlist=&Apache::lonnet::dump('classlist',
1.62 albertel 579: $env{'course.'.$env{'request.course.id'}.'.domain'},
580: $env{'course.'.$env{'request.course.id'}.'.num'});
1.10 ng 581: my (@badcollaborators,$result);
1.88 raeburn 582:
1.106 www 583: my (@collaborators) = split(/[,;\s]+/,$coll);
1.88 raeburn 584: foreach my $entry (@collaborators) {
585: my $collaborator;
586: if ($entry =~ /:/) {
587: $collaborator = $entry;
1.10 ng 588: } else {
1.88 raeburn 589: $collaborator = $entry.':'.$env{'user.domain'};
1.10 ng 590: }
1.88 raeburn 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: }
1.10 ng 600: }
601:
1.88 raeburn 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>';
1.10 ng 612: }
613: my $toomany = scalar(@collaborators) - $ncol;
614: if ($toomany > 0) {
615: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>'.
1.88 raeburn 616: &mt('You have too many collaborators.').' '.
617: &mt('Please remove [quant,_1,collaborator].',$toomany).
618: '</td></tr></table>';
1.10 ng 619: }
620: return $result;
1.1 albertel 621: }
1.2 albertel 622:
623: 1;
624: __END__
1.92 jms 625:
626:
627: =pod
628:
629: =head1 NAME
630:
1.106 www 631: Apache::essayresponse
1.92 jms 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:
1.121 raeburn 646: =item draft_row()
647:
648: =item get_collab_row()
649:
650: =item show_status_table()
651:
1.92 jms 652: =item end_essayresponse()
653:
1.121 raeburn 654: =item get_collaborators()
655:
1.92 jms 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:
1.93 raeburn 666: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>