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