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