Annotation of loncom/homework/essayresponse.pm, revision 1.118.2.1
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # essay (ungraded) style responses
1.5 albertel 3: #
1.118.2.1! raeburn 4: # $Id: essayresponse.pm,v 1.118 2014/01/21 14:38:55 kruse 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.69 albertel 50: } elsif ($target eq 'web' &&
51: $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.10 ng 52: my $part= $Apache::inputtags::part;
53: my $ncol= &Apache::lonnet::EXT("resource.$part".'_'."$id.maxcollaborators");
1.34 albertel 54: my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
1.17 www 55: my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
1.21 www 56: $uploadedfiletypes=~s/[^\w\,]//g;
1.93 raeburn 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: }
1.114 raeburn 61: my $hiddendraft;
1.102 raeburn 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')) {
1.114 raeburn 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);
1.108 raeburn 73: my $closure;
74: unless ($ncol || $uploadedfiletypes) {
75: $closure = 1;
76: }
77: $result.=
1.75 albertel 78: '<label>'.
1.108 raeburn 79: '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.
1.75 albertel 80: &mt('Submit entries below as answer to receive credit').
81: '</label> <br />'.
82: '<label>'.
1.108 raeburn 83: '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.
1.101 riegler 84: &mt('Save entries below (not submitted for credit yet)').
1.75 albertel 85: '</label>'.
1.108 raeburn 86: &Apache::lonhtmlcommon::row_closure($closure);
1.75 albertel 87: }
88:
1.10 ng 89: if ($ncol > 0) {
1.108 raeburn 90: $result.= &Apache::lonhtmlcommon::row_title(&mt('Collaborators')).
91: '<label>'.
1.88 raeburn 92: &mt('Collaborators:').' <input type="text" size="70" max="80" name="HWCOL'.
93: $part.'_'.$id.'" value="'.$coll.'" /><br />'.
1.117 raeburn 94: &mt('Enter a maximum of [quant,_1,collaborator] using username or username:domain, e.g. smithje or smithje:[_2].',$ncol,$env{'user.domain'});
1.88 raeburn 95: if ($ncol > 1) {
96: $result .= '<br />'.&mt('If entering more than one, use spaces to separate the collaborators.');
97: }
98: $result .= '</label><br />';
1.10 ng 99: $result .= &check_collaborators($ncol,$coll) if ($coll =~ /\w+/);
1.108 raeburn 100: $result .= &Apache::lonhtmlcommon::row_closure();
1.10 ng 101: }
1.93 raeburn 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);
1.114 raeburn 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: }
1.74 albertel 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"},'<>&"');
1.106 www 125: $result .= '<td><i>'.&mt('Collaborated with [_1]',$coll).'</i></td>';
1.74 albertel 126: }
127:
1.109 raeburn 128: my $current_files_display = &Apache::inputtags::current_file_submissions($part,$id);
1.108 raeburn 129: if ($current_files_display) {
130: $result .= '<td><b>'.&mt('Submitted files:').'</b><br />'.
131: $current_files_display.'</td>';
132: }
1.74 albertel 133:
134: if ($result ne '') {
135: $result =
136: '<table class="LC_pastsubmission"><tr>'.$result.
137: '</tr></table>';
138: }
1.10 ng 139: }
140: return $result;
1.1 albertel 141: }
142:
143: sub end_essayresponse {
1.10 ng 144: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.13 ng 145: my $part = $Apache::inputtags::part;
1.14 albertel 146: my $id = $Apache::inputtags::response[-1];
1.70 albertel 147: my $increment = &Apache::response::repetition();
1.15 albertel 148: my $result;
1.10 ng 149: if ( $target eq 'grade' ) {
1.106 www 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
1.58 albertel 158: if ( &Apache::response::submitted('scantron') ) {
1.31 albertel 159: $increment=&Apache::response::scored_response($part,$id);
1.58 albertel 160: } elsif ( &Apache::response::submitted() ) {
1.62 albertel 161: my $response = $env{'form.HWVAL_'.$id};
1.110 raeburn 162: my $jspart=$part;
163: $jspart=~s/\./_/g;
164: my $filename = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'} ||
1.91 raeburn 165: $env{'form.HWFILETOOBIG'.$part.'_'.$id};
1.110 raeburn 166: my $portfiles = $env{'form.HWPORT'.$jspart.'_'.$id};
167: my @deletions = &Apache::loncommon::get_env_multiple('form.HWFILE'.$jspart.'_'.$id.'_delete');
1.108 raeburn 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)) {
1.61 albertel 177: my $award='DRAFT';
1.62 albertel 178: if ($env{'form.HWDRAFT'.$part.'_'.$id} eq 'yes') {
1.102 raeburn 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: }
1.14 albertel 188: }
1.22 www 189: my $uploadedflag=0;
1.91 raeburn 190: my $totalsize=0;
1.108 raeburn 191: &file_submission($part,$id,\$award,\$uploadedflag,\$totalsize,\@deletions);
1.10 ng 192: $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
1.14 albertel 193: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
1.10 ng 194: my %previous=&Apache::response::check_for_previous($response,$part,$id);
1.107 raeburn 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: }
1.32 www 202: #
203: # Store with resource author for similarity testing
204: #
205: if ($award eq 'SUBMITTED') {
206: my ($symb,$crsid,$domain,$name)=
1.77 albertel 207: &Apache::lonnet::whichuser();
1.32 www 208: if ($crsid) {
1.83 albertel 209: my $akey=join('.',&escape($name),&escape($domain),
210: &escape($crsid));
1.32 www 211: my $essayurl=
212: &Apache::lonnet::declutter($ENV{'REQUEST_URI'});
1.118.2.1! raeburn 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: }
1.42 banghart 234: }
1.108 raeburn 235: }
1.118.2.1! raeburn 236: }
1.15 albertel 237: } elsif ($target eq 'edit') {
238: $result.=&Apache::edit::end_table();
1.71 albertel 239:
240: } elsif ($target eq 'tex'
241: && $Apache::lonhomework::type eq 'exam') {
242: $result .= &Apache::inputtags::exam_score_line($target);
243:
1.70 albertel 244: } elsif ($target eq 'answer') {
1.78 albertel 245: $result.=&Apache::response::answer_header($$tagstack[-1]);
1.81 foxr 246: my $answer = &mt('Essay will be hand graded.');
1.78 albertel 247: $result.=&Apache::response::answer_part($$tagstack[-1],$answer,
248: {'no_verbatim' => 1});
249: $result.=&Apache::response::answer_footer($$tagstack[-1]);
1.10 ng 250: }
1.82 albertel 251: if ($target eq 'web') {
252: &Apache::response::setup_prior_tries_hash(\&format_prior_response,
253: ['portfiles',
254: 'uploadedurl']);
255: }
1.71 albertel 256:
1.27 albertel 257: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
258: $target eq 'tex' || $target eq 'analyze') {
1.86 foxr 259: &Apache::lonxml::increment_counter($increment, "$part.$id");
1.85 foxr 260:
261: if ($target eq 'analyze') {
1.87 raeburn 262: $Apache::lonhomework::analyze{"$part.$id.type"} = 'essayresponse';
1.96 raeburn 263: push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
1.85 foxr 264: &Apache::lonhomework::set_bubble_lines();
265: }
1.27 albertel 266: }
1.10 ng 267: &Apache::response::end_response;
1.42 banghart 268:
1.15 albertel 269: return $result;
1.10 ng 270: }
271:
1.82 albertel 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').
1.118 kruse 296: '<blockquote>'.&HTML::Entities::encode($answer, '"<>&').'</blockquote></p>';
1.82 albertel 297: }
298:
299: return '<div class="LC_prior_essay">'.$output.'</div>';
300: }
301:
1.61 albertel 302: sub file_submission {
1.108 raeburn 303: my ($part,$id,$award,$uploadedflag,$totalsize,$deletions)=@_;
1.61 albertel 304: my $files;
1.67 albertel 305: my $jspart=$part;
306: $jspart=~s/\./_/g;
1.108 raeburn 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;
1.112 raeburn 329: } elsif ($file =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/essayresponse/[^/]+$}) {
330: $uploaded_delete = $file;
1.108 raeburn 331: }
332: }
333: }
334: }
335: foreach my $current (@portfiles) {
336: unless ($port_delete{$current}) {
337: push(@savedportfiles,$current);
338: }
339: }
340: if ($uploaded_delete) {
1.112 raeburn 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: }
1.108 raeburn 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: }
1.110 raeburn 360: if ($env{'form.HWFILETOOBIG'.$part.'_'.$id} ne '') {
1.108 raeburn 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;
1.91 raeburn 366: }
1.61 albertel 367: }
1.108 raeburn 368: if (@savedportfiles) {
369: foreach my $file (reverse(@savedportfiles)) {
370: unless(grep(/^\Q$file\E$/,@submitted_portfiles)) {
371: unshift(@submitted_portfiles,$file);
372: }
1.91 raeburn 373: }
1.108 raeburn 374: }
375: if (@submitted_portfiles || $submitted_upload) {
376: my $uploadedfiletypes=
1.91 raeburn 377: &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
1.99 raeburn 378: if ($uploadedfiletypes ne '') {
1.91 raeburn 379: $uploadedfiletypes=~s/[^\w\,]//g;
380: $uploadedfiletypes=','.$uploadedfiletypes.',';
1.108 raeburn 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;
1.91 raeburn 393: } else {
394: $$award='INVALID_FILETYPE';
1.108 raeburn 395: &delete_form_items($jspart,$id);
1.91 raeburn 396: }
397: }
1.99 raeburn 398: } else {
1.108 raeburn 399: @acceptable_portfiles = @submitted_portfiles;
400: $acceptable_upload = $submitted_upload;
1.91 raeburn 401: }
1.108 raeburn 402: }
403: if ((@acceptable_portfiles) || ($acceptable_upload ne '')) {
1.91 raeburn 404: my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
405: if (!$maxfilesize) {
1.93 raeburn 406: $maxfilesize = 10.0; #FIXME This should become a domain configuration
1.91 raeburn 407: }
408: my %dirlist;
1.108 raeburn 409: if (@acceptable_portfiles) {
410: foreach my $file (@acceptable_portfiles) {
1.97 raeburn 411: my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
1.91 raeburn 412: my $fullpath = '/userfiles/portfolio'.$path;
413: if (!exists($dirlist{$fullpath})) {
1.116 raeburn 414: my ($listref,$listerror) =
415: &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
416: if (ref($listref) eq 'ARRAY') {
417: $dirlist{$fullpath} = $listref;
418: }
1.97 raeburn 419: }
420: if (ref($dirlist{$fullpath}) eq 'ARRAY') {
421: foreach my $dir_line (@{$dirlist{$fullpath}}) {
1.91 raeburn 422: my ($fname,$dom,undef,$testdir,undef,undef,undef,undef,
1.108 raeburn 423: $size,undef,$mtime,undef,undef,undef,$obs,undef) =
1.91 raeburn 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: }
1.108 raeburn 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: }
1.91 raeburn 444: }
1.108 raeburn 445: }
446: if ($acceptable_upload ne '') {
1.91 raeburn 447: if (ref($totalsize)) {
1.108 raeburn 448: $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
1.91 raeburn 449: if ($$totalsize > $maxfilesize) {
450: $$award='EXCESS_FILESIZE';
1.108 raeburn 451: delete($env{'form.HWFILE'.$jspart.'_'.$id});
1.94 raeburn 452: } else {
1.108 raeburn 453: $accepted_upload = $acceptable_upload;
1.91 raeburn 454: }
455: } else {
1.108 raeburn 456: $accepted_upload = $acceptable_upload;
1.91 raeburn 457: }
458: }
1.108 raeburn 459: }
460: if ($accepted_upload ne '') {
1.115 raeburn 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: }
1.107 raeburn 487: }
488: }
1.108 raeburn 489: }
1.115 raeburn 490: if ($conflicts) {
491: $$award = 'FILENAME_INUSE';
1.107 raeburn 492: }
1.95 raeburn 493: }
1.115 raeburn 494: unless ($conflicts) {
495: my ($mode,%allfiles,%codebase);
496: my $result = &Apache::lonnet::userfileupload($formelement,'',
1.108 raeburn 497: $prefix.$path,$mode,\%allfiles,\%codebase);
1.115 raeburn 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: }
1.95 raeburn 507: }
1.108 raeburn 508: }
509: delete($env{'form.HWFILE'.$jspart.'_'.$id});
510: }
511: if (@accepted_portfiles) {
1.115 raeburn 512: if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
1.108 raeburn 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: }
1.112 raeburn 523: if (($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ne
524: $Apache::lonhomework::results{"resource.$part.$id.portfiles"}) ||
525: ($uploaded_delete)) {
1.108 raeburn 526: if (ref($uploadedflag)) {
527: $$uploadedflag=1;
528: }
1.61 albertel 529: }
1.108 raeburn 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;
1.61 albertel 534: }
535:
1.91 raeburn 536: sub delete_form_items {
537: my ($jspart,$id) = @_;
1.98 raeburn 538: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'});
539: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.mimetype'});
540: delete($env{'form.HWFILE'.$jspart.'_'.$id});
1.91 raeburn 541: }
542:
1.10 ng 543: sub check_collaborators {
1.11 ng 544: my ($ncol,$coll) = @_;
1.10 ng 545: my %classlist=&Apache::lonnet::dump('classlist',
1.62 albertel 546: $env{'course.'.$env{'request.course.id'}.'.domain'},
547: $env{'course.'.$env{'request.course.id'}.'.num'});
1.10 ng 548: my (@badcollaborators,$result);
1.88 raeburn 549:
1.106 www 550: my (@collaborators) = split(/[,;\s]+/,$coll);
1.88 raeburn 551: foreach my $entry (@collaborators) {
552: my $collaborator;
553: if ($entry =~ /:/) {
554: $collaborator = $entry;
1.10 ng 555: } else {
1.88 raeburn 556: $collaborator = $entry.':'.$env{'user.domain'};
1.10 ng 557: }
1.88 raeburn 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: }
1.10 ng 567: }
568:
1.88 raeburn 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>';
1.10 ng 579: }
580: my $toomany = scalar(@collaborators) - $ncol;
581: if ($toomany > 0) {
582: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>'.
1.88 raeburn 583: &mt('You have too many collaborators.').' '.
584: &mt('Please remove [quant,_1,collaborator].',$toomany).
585: '</td></tr></table>';
1.10 ng 586: }
587: return $result;
1.1 albertel 588: }
1.2 albertel 589:
590: 1;
591: __END__
1.92 jms 592:
593:
594: =pod
595:
596: =head1 NAME
597:
1.106 www 598: Apache::essayresponse
1.92 jms 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:
1.93 raeburn 625: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>