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