Annotation of loncom/homework/essayresponse.pm, revision 1.111
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # essay (ungraded) style responses
1.5 albertel 3: #
1.111 ! raeburn 4: # $Id: essayresponse.pm,v 1.110 2010/08/23 03:21:26 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: }
71: $result.= '<p>'.&Apache::lonhtmlcommon::start_pick_box().
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.108 raeburn 114: $result.=&Apache::lonhtmlcommon::end_pick_box().'</p>';
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;
311: }
312: }
313: }
314: }
315: foreach my $current (@portfiles) {
316: unless ($port_delete{$current}) {
317: push(@savedportfiles,$current);
318: }
319: }
320: if ($uploaded_delete) {
321: $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"} = "";
322: $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"} = "";
323: }
324: }
325: if ($env{'form.HWPORT'.$jspart.'_'.$id} ne '') {
326: my $newfiles= $env{'form.HWPORT'.$jspart.'_'.$id};
327: $newfiles =~s/,$//;
328: if ($newfiles =~ /[^\s]/) {
329: foreach my $file (split(/\s*,\s*/,$newfiles)) {
330: if ($file =~ /[^\s]/) {
331: push(@submitted_portfiles,$file);
332: }
333: }
334: }
335: }
1.110 raeburn 336: if ($env{'form.HWFILETOOBIG'.$part.'_'.$id} ne '') {
1.108 raeburn 337: $$award = 'EXCESS_FILESIZE';
338: } elsif ($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'} ne '') {
339: my $newfile = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'};
340: if ($newfile =~ /[^\s]/) {
341: $submitted_upload = $newfile;
1.91 raeburn 342: }
1.61 albertel 343: }
1.108 raeburn 344: if (@savedportfiles) {
345: foreach my $file (reverse(@savedportfiles)) {
346: unless(grep(/^\Q$file\E$/,@submitted_portfiles)) {
347: unshift(@submitted_portfiles,$file);
348: }
1.91 raeburn 349: }
1.108 raeburn 350: }
351: if (@submitted_portfiles || $submitted_upload) {
352: my $uploadedfiletypes=
1.91 raeburn 353: &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
1.99 raeburn 354: if ($uploadedfiletypes ne '') {
1.91 raeburn 355: $uploadedfiletypes=~s/[^\w\,]//g;
356: $uploadedfiletypes=','.$uploadedfiletypes.',';
1.108 raeburn 357: if (@submitted_portfiles) {
358: foreach my $file (@submitted_portfiles) {
359: my ($extension)=($file=~/\.(\w+)$/);
360: if ($uploadedfiletypes=~/\,\s*\Q$extension\E\s*\,/i) {
361: push(@acceptable_portfiles,$file);
362: }
363: }
364: }
365: if ($submitted_upload) {
366: my ($upload_ext)=($submitted_upload=~/\.(\w+)$/);
367: if ($uploadedfiletypes=~/\,\s*\Q$upload_ext\E\s*\,/i) {
368: $acceptable_upload = $submitted_upload;
1.91 raeburn 369: } else {
370: $$award='INVALID_FILETYPE';
1.108 raeburn 371: &delete_form_items($jspart,$id);
1.91 raeburn 372: }
373: }
1.99 raeburn 374: } else {
1.108 raeburn 375: @acceptable_portfiles = @submitted_portfiles;
376: $acceptable_upload = $submitted_upload;
1.91 raeburn 377: }
1.108 raeburn 378: }
379: if ((@acceptable_portfiles) || ($acceptable_upload ne '')) {
1.91 raeburn 380: my $maxfilesize=&Apache::lonnet::EXT("resource.$part".'_'."$id.maxfilesize");
381: if (!$maxfilesize) {
1.93 raeburn 382: $maxfilesize = 10.0; #FIXME This should become a domain configuration
1.91 raeburn 383: }
384: my %dirlist;
1.108 raeburn 385: if (@acceptable_portfiles) {
386: foreach my $file (@acceptable_portfiles) {
1.97 raeburn 387: my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
1.91 raeburn 388: my $fullpath = '/userfiles/portfolio'.$path;
389: if (!exists($dirlist{$fullpath})) {
390: my @list = &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
1.97 raeburn 391: $dirlist{$fullpath} = \@list;
392: }
393: if (ref($dirlist{$fullpath}) eq 'ARRAY') {
394: foreach my $dir_line (@{$dirlist{$fullpath}}) {
1.91 raeburn 395: my ($fname,$dom,undef,$testdir,undef,undef,undef,undef,
1.108 raeburn 396: $size,undef,$mtime,undef,undef,undef,$obs,undef) =
1.91 raeburn 397: split(/\&/,$dir_line,16);
398: if ($filename eq $fname) {
399: my $mbsize = $size/(1024.0*1024.0);
400: if (ref($totalsize)) {
401: $$totalsize += $mbsize;
402: }
403: last;
404: }
405: }
406: }
1.108 raeburn 407: if (ref($totalsize)) {
408: if ($$totalsize > $maxfilesize) {
409: $$award='EXCESS_FILESIZE';
410: &delete_form_items($jspart,$id);
411: } else {
412: push(@accepted_portfiles,$file);
413: }
414: } else {
415: push(@accepted_portfiles,$file);
416: }
1.91 raeburn 417: }
1.108 raeburn 418: }
419: if ($acceptable_upload ne '') {
1.91 raeburn 420: if (ref($totalsize)) {
1.108 raeburn 421: $$totalsize += $env{'form.HWFILESIZE'.$jspart.'_'.$id};
1.91 raeburn 422: if ($$totalsize > $maxfilesize) {
423: $$award='EXCESS_FILESIZE';
1.108 raeburn 424: delete($env{'form.HWFILE'.$jspart.'_'.$id});
1.94 raeburn 425: } else {
1.108 raeburn 426: $accepted_upload = $acceptable_upload;
1.91 raeburn 427: }
428: } else {
1.108 raeburn 429: $accepted_upload = $acceptable_upload;
1.91 raeburn 430: }
431: }
1.108 raeburn 432: }
433: if ($accepted_upload ne '') {
434: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
435: my $turnindir;
436: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
437: $turnindir = $userhash{'turnindir'};
438: if ($turnindir eq '') {
439: $turnindir = &mt('turned in');
440: $turnindir =~ s/\W+/_/g;
441: my %newhash = (
442: 'turnindir' => $turnindir,
443: );
444: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
445: }
446: my $prefix = 'portfolio';
447: my $path = '/'.$turnindir.'/';
448: my $restitle=&Apache::lonnet::gettitle($symb);
449: $restitle =~ s/\W+/_/g;
450: if ($restitle eq '') {
451: $restitle = ($resurl =~ m{/[^/]+$});
452: if ($restitle eq '') {
453: $restitle = time;
1.107 raeburn 454: }
1.91 raeburn 455: }
1.108 raeburn 456: my @pathitems;
457: my $navmap = Apache::lonnavmaps::navmap->new();
458: if (defined($navmap)) {
459: my $mapres = $navmap->getResourceByUrl($map);
460: if (ref($mapres)) {
461: my $pcslist = $mapres->map_hierarchy();
462: if ($pcslist ne '') {
463: foreach my $pc (split(/,/,$pcslist)) {
464: my $res = $navmap->getByMapPc($pc);
465: if (ref($res)) {
466: my $title = $res->compTitle();
467: $title =~ s/\W+/_/g;
468: if ($title ne '') {
469: push(@pathitems,$title);
1.107 raeburn 470: }
471: }
472: }
1.108 raeburn 473: }
474: my $maptitle = $mapres->compTitle();
475: $maptitle =~ s/\W+/_/g;
476: if ($maptitle ne '') {
477: push(@pathitems,$maptitle);
1.107 raeburn 478: }
1.95 raeburn 479: } else {
1.107 raeburn 480: $$award = 'INTERNAL_ERROR';
1.95 raeburn 481: }
1.108 raeburn 482: } else {
483: $$award = 'INTERNAL_ERROR';
484: }
485: push(@pathitems,$restitle);
486: $path .= join('/',@pathitems);
487: my $formelement = 'HWFILE'.$jspart.'_'.$id;
1.111 ! raeburn 488: my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formelement.'.filename'});
1.108 raeburn 489: my $url = '/uploaded/'.$udom.'/'.$uname.'/'.$prefix.$path.'/'.$fname;
490: my @stat = &Apache::lonnet::stat_file($url);
491: if (@stat && $stat[0] ne 'no_such_dir') {
492: $$award = 'FILENAME_INUSE';
493: } else {
494: my ($mode,%allfiles,%codebase);
495: my $result = &Apache::lonnet::userfileupload($formelement,'',
496: $prefix.$path,$mode,\%allfiles,\%codebase);
497: if ($result =~ m{^/uploaded/}) {
498: $stored_upload = $path.'/'.$fname;
499: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = $stored_upload;
500: push(@tolock,$stored_upload);
1.107 raeburn 501: } else {
1.108 raeburn 502: $$award = 'INTERNAL_ERROR';
1.95 raeburn 503: }
1.108 raeburn 504: }
505: delete($env{'form.HWFILE'.$jspart.'_'.$id});
506: }
507: if (@accepted_portfiles) {
508: if ($stored_upload) {
509: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} .= ',';
510: }
511: $Apache::lonhomework::results{"resource.$part.$id.portfiles"}.=join(',',@accepted_portfiles);
512: push(@tolock,@accepted_portfiles);
513: }
514: if (!defined($Apache::lonhomework::results{"resource.$part.$id.portfiles"})) {
515: if (keys(%port_delete) > 0) {
516: $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = "";
517: }
518: }
519: if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"} ne $Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
520: if (ref($uploadedflag)) {
521: $$uploadedflag=1;
522: }
1.61 albertel 523: }
1.108 raeburn 524: &Apache::lonnet::unmark_as_readonly($udom,$uname,[$symb,$crsid]);
525: &Apache::lonnet::mark_as_readonly($udom,$uname,[@tolock],[$symb,$crsid]);
526: &Apache::lonnet::clear_selected_files($uname);
527: return;
1.61 albertel 528: }
529:
1.91 raeburn 530: sub delete_form_items {
531: my ($jspart,$id) = @_;
1.98 raeburn 532: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.filename'});
533: delete($env{'form.HWFILE'.$jspart.'_'.$id.'.mimetype'});
534: delete($env{'form.HWFILE'.$jspart.'_'.$id});
1.91 raeburn 535: }
536:
1.10 ng 537: sub check_collaborators {
1.11 ng 538: my ($ncol,$coll) = @_;
1.10 ng 539: my %classlist=&Apache::lonnet::dump('classlist',
1.62 albertel 540: $env{'course.'.$env{'request.course.id'}.'.domain'},
541: $env{'course.'.$env{'request.course.id'}.'.num'});
1.10 ng 542: my (@badcollaborators,$result);
1.88 raeburn 543:
1.106 www 544: my (@collaborators) = split(/[,;\s]+/,$coll);
1.88 raeburn 545: foreach my $entry (@collaborators) {
546: my $collaborator;
547: if ($entry =~ /:/) {
548: $collaborator = $entry;
1.10 ng 549: } else {
1.88 raeburn 550: $collaborator = $entry.':'.$env{'user.domain'};
1.10 ng 551: }
1.88 raeburn 552: if ($collaborator !~ /^$match_username:$match_domain$/) {
553: if (!grep(/^\Q$entry\E$/,@badcollaborators)) {
554: push(@badcollaborators,$entry);
555: }
556: } elsif (!grep(/^\Q$collaborator\E$/i,keys(%classlist))) {
557: if (!grep(/^\Q$entry\E$/,@badcollaborators)) {
558: push(@badcollaborators,$entry);
559: }
560: }
1.10 ng 561: }
562:
1.88 raeburn 563: my $numbad = scalar(@badcollaborators);
564: if ($numbad) {
565: $result = '<table border="0"><tr bgcolor="#ffbbbb"><td>';
566: if ($numbad == 1) {
567: $result .= &mt('The following user is invalid:');
568: } else {
569: $result .= &mt('The following [_1] users are invalid:',$numbad);
570: }
571: $result .= ' '.join(', ',@badcollaborators).'. '.&mt('Please correct.').
572: '</td></tr></table>';
1.10 ng 573: }
574: my $toomany = scalar(@collaborators) - $ncol;
575: if ($toomany > 0) {
576: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>'.
1.88 raeburn 577: &mt('You have too many collaborators.').' '.
578: &mt('Please remove [quant,_1,collaborator].',$toomany).
579: '</td></tr></table>';
1.10 ng 580: }
581: return $result;
1.1 albertel 582: }
1.2 albertel 583:
584: 1;
585: __END__
1.92 jms 586:
587:
588: =pod
589:
590: =head1 NAME
591:
1.106 www 592: Apache::essayresponse
1.92 jms 593:
594: =head1 SYNOPSIS
595:
596: Handler to evaluate essay (ungraded) style responses.
597:
598: This is part of the LearningOnline Network with CAPA project
599: described at http://www.lon-capa.org.
600:
601: =head1 SUBROUTINES
602:
603: =over
604:
605: =item start_essayresponse()
606:
607: =item end_essayresponse()
608:
609: =item format_prior_response()
610:
611: =item file_submission()
612:
613: =item delete_form_items()
614:
615: =item check_collaborators()
616:
617: =back
618:
1.93 raeburn 619: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>