Annotation of loncom/interface/statistics/lonstudentsubmissions.pm, revision 1.54.10.4
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.54.10.4! raeburn 3: # $Id: lonstudentsubmissions.pm,v 1.54.10.3 2011/11/18 22:20:20 raeburn Exp $
1.1 matthew 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: package Apache::lonstudentsubmissions;
28:
29: use strict;
1.40 albertel 30: use Apache::lonnet;
1.1 matthew 31: use Apache::loncommon();
32: use Apache::lonhtmlcommon();
33: use Apache::loncoursedata();
34: use Apache::lonstatistics;
35: use Apache::lonlocal;
36: use Apache::lonstathelpers;
37: use HTML::Entities();
38: use Time::Local();
39: use Spreadsheet::WriteExcel();
1.54.10.1 raeburn 40: use Crypt::PasswdMD5;
1.45 www 41: use lib '/home/httpd/lib/perl/';
42: use LONCAPA;
43:
1.1 matthew 44:
1.18 matthew 45: my @SubmitButtons = ({ name => 'SelectAnother',
1.1 matthew 46: text => 'Choose a different Problem' },
47: { name => 'Generate',
1.16 matthew 48: text => 'Generate Report'},
1.1 matthew 49: );
50:
51: sub BuildStudentSubmissionsPage {
52: my ($r,$c)=@_;
53: #
54: my %Saveable_Parameters = ('Status' => 'scalar',
55: 'Section' => 'array',
56: 'NumPlots' => 'scalar',
57: );
58: &Apache::loncommon::store_course_settings('student_submissions',
59: \%Saveable_Parameters);
60: &Apache::loncommon::restore_course_settings('student_submissions',
61: \%Saveable_Parameters);
62: #
63: &Apache::lonstatistics::PrepareClasslist();
64: #
65: $r->print(&CreateInterface());
66: #
67: my @Students = @Apache::lonstatistics::Students;
68: #
69: if (@Students < 1) {
1.50 bisitz 70: $r->print('<div class="LC_warning">'
71: .&mt('There are no students in the sections selected.')
72: .'</div>');
1.1 matthew 73: }
74: #
1.11 matthew 75: my @CacheButtonHTML =
1.19 matthew 76: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status',
1.50 bisitz 77: '<div class="LC_info">'.&mt('Loading student data...').'</div>');
1.1 matthew 78: $r->rflush();
79: #
1.54.10.4! raeburn 80: if ((exists($env{'form.problemchoice'}) || (exists($env{'form.allproblems'}))) &&
1.40 albertel 81: ! exists($env{'form.SelectAnother'})) {
1.1 matthew 82: foreach my $button (@SubmitButtons) {
83: if ($button->{'name'} eq 'break') {
84: $r->print("<br />\n");
85: } else {
86: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
87: 'value="'.&mt($button->{'text'}).'" />');
88: $r->print(' 'x5);
89: }
90: }
1.11 matthew 91: foreach my $html (@CacheButtonHTML) {
92: $r->print($html.(' 'x5));
93: }
1.1 matthew 94: #
1.18 matthew 95: $r->print('<hr />'.$/);
1.1 matthew 96: $r->rflush();
97: #
1.54.10.4! raeburn 98:
! 99: #
! 100: # Get resource objects
! 101: my $navmap = Apache::lonnavmaps::navmap->new();
! 102:
1.18 matthew 103: # Determine which problems we are to analyze
104: my @Symbs =
105: &Apache::lonstathelpers::get_selected_symbs('problemchoice');
1.54.10.4! raeburn 106: if (defined($navmap)) {
! 107: if ($env{'form.allproblems'}) {
! 108: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
! 109: while (my $curRes = $iterator->next()) {
! 110: next if (! ref($curRes));
! 111: if ($curRes->is_problem) {
! 112: my $symb = $curRes->symb;
! 113: unless(grep(/^\Q$symb\E$/,@Symbs)) {
! 114: push(@Symbs,$symb);
! 115: }
! 116: }
! 117: }
! 118: }
! 119: }
1.18 matthew 120: foreach my $selected (@Symbs) {
121: $r->print('<input type="hidden" name="problemchoice" value="'.
122: $selected.'" />'.$/);
123: }
124: if (!defined($navmap)) {
1.50 bisitz 125: $r->print('<div class="LC_error">'.&mt("Internal error").'</div>');
1.18 matthew 126: return;
127: }
128: my %already_seen;
1.54.10.1 raeburn 129: my (@Problems,$show_named);
130: unless (&Apache::loncommon::needs_gci_custom()) {
1.54.10.4! raeburn 131: unless ($env{'form.anonymized'} eq 'true') {
! 132: $show_named = 1;
! 133: }
1.54.10.1 raeburn 134: }
1.18 matthew 135: foreach my $symb (@Symbs) {
136: my $resource = $navmap->getBySymb($symb);
137: push(@Problems,$resource);
1.1 matthew 138: }
1.54.10.1 raeburn 139: # If these are to be anonymized, do a random shuffle of @Students.
140: unless ($show_named) {
141: &array_shuffle(\@Students);
142: }
143: my $threshold = $env{'course.'.$env{'request.course.id'}.'.internal.anonsurvey_threshold'};
144: if ($threshold eq '') {
145: my %domconfig =
146: &Apache::lonnet::get_dom('configuration',['coursedefaults'],
147: $env{'course.'.$env{'request.course.id'}.'.domain'});
148: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
149: $threshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
150: if ($threshold eq '') {
151: $threshold = 10;
152: }
153: } else {
154: $threshold = 10;
155: }
156: }
1.54.10.4! raeburn 157: unless (&Apache::loncommon::needs_gci_custom()) {
! 158: $threshold = 0;
! 159: }
1.25 matthew 160: #
1.37 matthew 161: $r->print('<h4>'.
162: &Apache::lonstatistics::section_and_enrollment_description().
163: '</h4>');
1.18 matthew 164: if (! scalar(@Problems) || ! defined($Problems[0])) {
1.1 matthew 165: $r->print('resource is undefined');
1.54.10.1 raeburn 166: } elsif (!$show_named && @Students < $threshold) {
1.54.10.3 raeburn 167: $r->print(&mt('The number of students matching the selection criteria is too few for display of submission data for anonymous surveys.').'<br />'.&mt('There must be at least [quant,_1,student].',$threshold).' '.&mt('Contact the LON-CAPA [_1]Helpdesk[_2] if you need the threshold to be changed for this course.','<a href="/adm/helpdesk?origurl=%2fadm%2fstatistics>','</a>'));
1.1 matthew 168: } else {
1.18 matthew 169: if (scalar(@Problems) == 1) {
170: my $resource = $Problems[0];
171: $r->print('<h1>'.$resource->title.'</h1>');
172: $r->print('<h3>'.$resource->src.'</h3>');
1.40 albertel 173: if ($env{'form.renderprob'} eq 'true') {
1.36 matthew 174: $r->print(&Apache::lonstathelpers::render_resource($resource));
1.18 matthew 175: $r->rflush();
176: }
177: }
1.40 albertel 178: if ($env{'form.output'} eq 'excel') {
1.54.10.1 raeburn 179: &prepare_excel_output($r,\@Problems,\@Students,$show_named);
1.40 albertel 180: } elsif ($env{'form.output'} eq 'csv') {
1.54.10.1 raeburn 181: &prepare_csv_output($r,\@Problems,\@Students,$show_named);
1.21 matthew 182: } else {
1.54.10.1 raeburn 183: &prepare_html_output($r,\@Problems,\@Students,$show_named);
1.21 matthew 184: }
1.1 matthew 185: }
186: $r->print('<hr />');
187: } else {
188: $r->print('<input type="submit" name="Generate" value="'.
1.17 matthew 189: &mt('Prepare Report').'" />');
1.1 matthew 190: $r->print(' 'x5);
1.19 matthew 191: $r->print('<p>'.
192: &mt('Computing correct answers greatly increasese the amount of time required to prepare a report.').
193: '</p>');
194: $r->print('<p>'.
1.50 bisitz 195: &mt('Please select problems and use the [_1]Prepare Report[_2] button to continue.','<b>','</b>').
1.19 matthew 196: '</p>');
1.18 matthew 197: $r->print(&Apache::lonstathelpers::MultipleProblemSelector
1.19 matthew 198: (undef,'problemchoice','Statistics'));
1.18 matthew 199: }
200: }
201:
1.54.10.1 raeburn 202: sub array_shuffle {
203: my $array = shift;
204: return unless (ref($array) eq 'ARRAY');
205: my $i = scalar(@$array);
206: my $j;
207: foreach my $item (@$array) {
208: --$i;
209: $j = int(rand($i+1));
210: next if($i == $j);
211: @$array [$i,$j] = @$array[$j,$i];
212: }
213: return @$array;
214: }
215:
1.30 matthew 216: ##
1.31 matthew 217: ## get_extra_response_headers
218: ##
1.54.10.1 raeburn 219:
1.31 matthew 220: sub get_extra_response_headers {
1.54.10.1 raeburn 221: my ($show_named) = @_;
1.31 matthew 222: my @extra_resp_headers;
1.40 albertel 223: if ($env{'form.correctans'} eq 'true') {
1.31 matthew 224: push(@extra_resp_headers,'Correct');
1.54.10.1 raeburn 225: }
226: if ($show_named) {
227: if ($env{'form.prob_status'} eq 'true') {
228: push(@extra_resp_headers,'Award Detail');
229: push(@extra_resp_headers,'Time');
230: push(@extra_resp_headers,'Attempt');
231: push(@extra_resp_headers,'Awarded');
232: }
1.31 matthew 233: }
234: return @extra_resp_headers;
235: }
236:
237: ##
1.30 matthew 238: ## get_headers:
239: ## return the proper headers for the given response
240: sub get_headers {
241: my ($prob,$partid,$respid,$resptype,$analysis,$output,$purpose,
242: @basic_headers) = @_;
243: my @headers;
244: if ($resptype eq 'essay' && $purpose eq 'display' &&
245: ($output eq 'html')) {# || scalar(@{$prob->parts})!=1)) {
246: @headers = ();
247: } elsif ($resptype =~ /^(option|match|rank)$/) {
248: my $prefix = '_';
249: if ($purpose eq 'display') {
250: $prefix = '';
251: }
252: my @foils =
253: map {
254: $prefix.$_;
255: } sort(keys(%{$analysis->{$partid.'.'.$respid}->{'_Foils'}}));
256: if (scalar(@basic_headers) && $basic_headers[0] eq 'Correct') {
257: @foils = map { ($_ , $_.' Correct') } @foils;
258: shift(@basic_headers); # Get rid of 'Correct'
259: }
260: @headers = (@foils,@basic_headers);
1.42 albertel 261: } elsif (lc($resptype) eq 'task') {
262: @headers = ('Grader','Status',@basic_headers,'Submission');
1.30 matthew 263: } else {
264: @headers = ('Submission',@basic_headers);
265: }
266: return @headers;
267: }
268:
1.18 matthew 269: #########################################################
270: #########################################################
1.21 matthew 271: ##
272: ## HTML Output Routines
273: ##
274: #########################################################
275: #########################################################
276: sub prepare_html_output {
1.54.10.1 raeburn 277: my ($r,$problems,$students,$show_named) = @_;
1.21 matthew 278: my $c = $r->connection();
1.54.10.1 raeburn 279: my $salt = '$1$'.$Apache::lonnet::perlvar{'AnonymousSalt'};
1.21 matthew 280: #
281: # Set a flag for the case when there is just one problem
282: my $single_response = 0;
283: if (scalar(@$problems) == 1 &&
284: $problems->[0]->countResponses == 1) {
285: $single_response = 1;
286: }
287: #
288: # Compute the number of columns per response
1.54.10.1 raeburn 289: my @extra_resp_headers = &get_extra_response_headers($show_named);
1.21 matthew 290: #
291: # Create the table header
1.54.10.1 raeburn 292: my @student_columns;
293: if ($show_named) {
294: @student_columns = @Apache::lonstatistics::SelectedStudentData;
295: if (grep(/^all$/,@student_columns)) {
296: @student_columns = qw(fullname username domain id section status groups comments);
297: }
298: } else {
299: @student_columns = ('username');
300: }
1.21 matthew 301: #
302: my %headers;
303: my $student_column_count = scalar(@student_columns);
304: $headers{'problem'} = qq{<th colspan="$student_column_count">\ </th>};
305: foreach (@student_columns) {
306: $headers{'student'}.= '<th>'.ucfirst($_).'</th>';
307: }
308: #
309: # we put the headers into the %headers hash
310: my $total_col = scalar(@student_columns);
311: my $nonempty_part_headers = 0;
1.30 matthew 312: #
313: my %problem_analysis;
1.21 matthew 314: foreach my $prob (@$problems) {
1.31 matthew 315: my %analysis = &Apache::lonstathelpers::get_problem_data($prob->src);
1.30 matthew 316: $problem_analysis{$prob->src}=\%analysis;
317: #
1.21 matthew 318: my $prob_span = 0;
319: my $single_part = 0;
320: if (scalar(@{$prob->parts}) == 1) {
321: $single_part = 1;
322: }
323: foreach my $partid (@{$prob->parts}) {
324: my $part_span = 0;
325: my $responses = [$prob->responseIds($partid)];
326: my $resptypes = [$prob->responseType($partid)];
327: for (my $i=0;$i<scalar(@$responses);$i++) {
1.30 matthew 328: my $respid = $responses->[$i];
329: my @headers = &get_headers($prob,$partid,$respid,
330: $resptypes->[$i],
331: $problem_analysis{$prob->src},
332: 'html','display',
333: @extra_resp_headers);
334: if (scalar(@headers)>0) {
335: $total_col += scalar(@headers);
336: $part_span += scalar(@headers);
1.21 matthew 337: $headers{'response'} .=
1.30 matthew 338: '<th colspan="'.scalar(@headers).'">'.
1.21 matthew 339: &mt('Response [_1]',$responses->[$i]).'</th>';
1.52 raeburn 340: $headers{'student'}.= '<th><span class="LC_nobreak">'.
341: join('</span></th><th><span class="LC_nobreak">',
1.30 matthew 342: @headers).
1.51 bisitz 343: '</span></th>';
1.21 matthew 344: }
345: }
1.41 matthew 346: if ($part_span == 0) {
347: next;
348: }
1.21 matthew 349: if (! $single_part) {
350: my $tmpname = $partid;
351: if ($partid =~/^\d+$/) {
1.24 matthew 352: $tmpname = $prob->part_display($partid);
1.21 matthew 353: }
1.35 matthew 354: if ($tmpname !~ /^part/) {
355: $tmpname = 'Part '.$tmpname;
356: }
1.21 matthew 357: $headers{'part'} .= qq{<th colspan="$part_span">$tmpname</th>};
358: $nonempty_part_headers = 1;
359: } else {
1.53 bisitz 360: $headers{'part'} .= qq{<th colspan="$part_span"> </th>};
1.21 matthew 361: }
362: $prob_span += $part_span;
363: }
1.23 matthew 364: my $title = $prob->compTitle;
1.54.10.4! raeburn 365: unless (&Apache::loncommon::needs_gci_custom()) {
! 366: ($title) = ($prob->src =~ m{/([^/]+)$});
! 367: }
1.21 matthew 368: if ($prob_span > 0) {
369: $headers{'problem'}.= qq{<th colspan="$prob_span">$title</th>};
370: } elsif ($single_response) {
371: $prob_span = scalar(@student_columns);
372: $headers{'problem'} = qq{<th colspan="$prob_span">$title</th>};
373: }
374: }
375: if (exists($headers{'part'})) {
376: $headers{'part'} = qq{<th colspan="$student_column_count">\ </th>}.
377: $headers{'part'};
378: }
379: if (exists($headers{'response'})) {
380: $headers{'response'}=
381: qq{<th colspan="$student_column_count">\ </th>}.
382: $headers{'response'};
383: }
384: my $full_header = $/.'<table>'.$/;
385: $full_header .= '<tr align="left">'.$headers{'problem'}.'</tr>'.$/;
386: if ($nonempty_part_headers) {
387: $full_header .= '<tr align="left">'.$headers{'part'}.'</tr>'.$/;
388: }
389: $full_header .= '<tr align="left">'.$headers{'response'}.'</tr>'.$/;
390: $full_header .= '<tr align="left">'.$headers{'student'}.'</tr>'.$/;
391: #
392: # Main loop
393: my $count;
394: $r->print($/.$full_header.$/);
395: my $row_class = 'odd'; # css
396: foreach my $student (@$students) {
397: my $student_row_data;
398: if ($count++ >= 30) {
399: $r->print('</table>'.$/.$full_header.$/);
400: $count = 0;
401: }
402: last if ($c->aborted());
1.54.10.1 raeburn 403: if ($show_named) {
404: foreach my $field (@student_columns) {
405: $student_row_data .= '<td valign="top">';
406: # handle comments like in lonstudentassessment.pm
407: if($field eq 'comments') {
408: $student_row_data .=
409: '<a href="/adm/'.$student->{'domain'}.'/'.
410: $student->{'username'}.'/'.'aboutme#coursecomment">'.&mt('Comments').'</a>';
411: } else {
412: $student_row_data .= $student->{$field};
413: }
414: $student_row_data .= '</td>';
415: }
416: } else {
417: my $anonid = &Crypt::PasswdMD5::unix_md5_crypt($student->{'username'},
418: $salt);
419: $anonid = substr($anonid,length($salt)+1);
420: $student_row_data = '<td valign="top" colspan="'.$student_column_count.'">'.
421: $anonid.'</td>';
1.21 matthew 422: }
423: #
424: # Figure out what it is we need to output for this student
425: my @essays;
1.30 matthew 426: my %prob_data;
1.21 matthew 427: my $maxrow;
428: foreach my $prob (@$problems) {
1.30 matthew 429: $prob_data{$prob->symb}={};
1.21 matthew 430: foreach my $partid (@{$prob->parts}) {
431: my @responses = $prob->responseIds($partid);
432: my @response_type = $prob->responseType($partid);
433: for (my $i=0;$i<=$#responses;$i++) {
1.30 matthew 434: my $respid = $responses[$i];
1.21 matthew 435: my $results =
436: &Apache::loncoursedata::get_response_data_by_student
437: ($student,$prob->symb(),$respid);
1.30 matthew 438: my $resptype = $response_type[$i];
439: my @headers = &get_headers($prob,$partid,$respid,
440: $resptype,
441: $problem_analysis{$prob->src},
442: 'html','normal',
443: @extra_resp_headers);
444: my $width = scalar(@headers);
1.41 matthew 445: next if ($width < 1);
1.30 matthew 446: my $resp_data;
1.41 matthew 447: $resp_data->{'fake'} = qq{<td colspan="$width"> </td>};
1.21 matthew 448: if (! defined($results)) {
449: $results = [];
450: }
1.30 matthew 451: #
1.21 matthew 452: if (scalar(@$results) > $maxrow && $resptype ne 'essay') {
453: $maxrow = scalar(@$results);
454: }
455: for (my $j=scalar(@$results)-1;$j>=0;$j--) {
1.40 albertel 456: if ($env{'form.all_sub'} ne 'true') {
1.21 matthew 457: next if ($j ne scalar(@$results)-1);
458: }
1.30 matthew 459: my $response = &hashify_response($results->[$j],
460: $prob,
461: $student,
462: $partid,
463: $respid);
1.21 matthew 464: if ($resptype eq 'essay') {
465: push(@essays,
1.30 matthew 466: &html_essay_results(\@headers,
1.21 matthew 467: $prob,$partid,$respid,
468: $response,
469: $single_response).
470: '</td>');
1.42 albertel 471: } elsif (lc($resptype) eq 'task') {
472: my $results =
473: &html_task_results(\@headers,
474: $prob,$partid,$respid,
475: $response,$resptype);
476: if ($results) {
477: push(@{$resp_data->{'real'}},$results);
478: }
1.21 matthew 479: } else {
480: push(@{$resp_data->{'real'}},
1.30 matthew 481: &html_non_essay_results(\@headers,
482: $prob,$partid,$respid,
483: $response,$resptype));
1.21 matthew 484: }
1.30 matthew 485: }
486: $prob_data{$prob->symb}->{$partid}->{$respid}=$resp_data;
1.21 matthew 487: } # end of $i loop
488: } # end of partid loop
489: } # end of prob loop
490: #
491: # if there is no data, skip this student.
492: next if (! $maxrow && ! scalar(@essays));
493: #
494: # Go through the problem data and output a row.
495: if ($row_class eq 'even') {
496: $row_class = 'odd';
497: } else {
498: $row_class = 'even';
499: }
500: my $printed_something;
501: for (my $rows_output = 0;$rows_output<$maxrow;$rows_output++) {
502: my $html;
503: my $no_data = 1;
504: foreach my $prob (@$problems) {
505: foreach my $partid (@{$prob->parts}) {
506: my @responses = $prob->responseIds($partid);
507: my @response_type = $prob->responseType($partid);
508: for (my $i=0;$i<=$#responses;$i++) {
509: my $respid = $responses[$i];
510: my $resp_data =
1.30 matthew 511: $prob_data{$prob->symb}->{$partid}->{$respid};
1.21 matthew 512: next if ($response_type[$i] eq 'essay');
513: if (defined($resp_data->{'real'}->[$rows_output])) {
514: $html .= $resp_data->{'real'}->[$rows_output];
515: $no_data = 0;
516: } else {
517: $html .= $resp_data->{'fake'};
518: }
519: }
520: }
521: }
522: if (! $no_data) {
523: $r->print(qq{<tr class="$row_class">$student_row_data$html</tr>}.$/);
524: $printed_something=1;
525: }
526: }
527: if (@essays) {
528: my $tr = qq{<tr class="$row_class">};
529: my $td = qq{<td valign="top" class="essay" colspan="$total_col">};
530: if (! $printed_something) {
531: $r->print($tr.$student_row_data.'</tr>'.$/);
532: }
533: $r->print($tr.$td.
534: join('</td></tr>'.$/.$tr.$td,@essays).'</td></tr>'.$/);
535: undef(@essays);
536: }
537: } # end of student loop
1.54.10.1 raeburn 538: $r->print('</table>'.$/);
1.21 matthew 539: return;
540: }
541:
1.30 matthew 542: sub hashify_response {
543: my ($response,$prob,$student,$partid,$respid) =@_;
544: my $resp_hash = {};
1.40 albertel 545: if ($env{'form.correctans'} eq 'true') {
1.30 matthew 546: $resp_hash->{'Correct'} =
547: &Apache::lonstathelpers::get_student_answer
548: ($prob,$student->{'username'},$student->{'domain'},
549: $partid,$respid);
550: }
551: $resp_hash->{'Submission'} =
552: $response->[&Apache::loncoursedata::RDs_submission()];
553: $resp_hash->{'Time'} =
554: $response->[&Apache::loncoursedata::RDs_timestamp()];
555: $resp_hash->{'Attempt'} =
556: $response->[&Apache::loncoursedata::RDs_tries()];
557: $resp_hash->{'Awarded'} =
558: $response->[&Apache::loncoursedata::RDs_awarded()];
1.42 albertel 559: if ($prob->is_task()) {
560: $resp_hash->{'Grader'} =
561: $response->[&Apache::loncoursedata::RDs_response_eval_2()];
562: if ($resp_hash->{'Attempt'} eq '0') {
563: $resp_hash->{'Attempt'} = '';
564: }
565: $resp_hash->{'Award Detail'} =
566: $response->[&Apache::loncoursedata::RDs_part_award()];
567: $resp_hash->{'Status'} =
568: $response->[&Apache::loncoursedata::RDs_response_eval()];
569: } else {
570: $resp_hash->{'Award Detail'} =
571: $response->[&Apache::loncoursedata::RDs_awarddetail()];
572: }
573:
1.30 matthew 574: return $resp_hash;
575: }
576:
1.21 matthew 577: #####################################################
578: ##
579: ## HTML helper routines
580: ##
581: #####################################################
582: sub html_essay_results {
1.30 matthew 583: my ($headers,$prob,$partid,$respid,$response,$single_response)=@_;
584: if (! ref($headers) || ref($headers) ne 'ARRAY') {
585: return '';
1.21 matthew 586: }
1.30 matthew 587: # Start of telling them what problem, part, and response
1.21 matthew 588: my $Str;
589: if (! $single_response) {
1.23 matthew 590: my $id = $prob->compTitle;
1.21 matthew 591: if (defined($partid) && $partid ne '0') {
1.24 matthew 592: $id .= ' '.$prob->part_display($partid);
1.21 matthew 593: }
594: if (defined($respid)) {
595: $id .= ' '.$respid;
596: }
1.51 bisitz 597: $Str .= '<span class="LC_nobreak">'.$id.'</span>'.(' 'x4);
1.21 matthew 598: }
1.30 matthew 599: #
600: shift(@$headers); # Get rid of the Submission header
601: my $correct = '';
602: if ($headers->[0] eq 'Correct') {
603: $correct = &html_format_essay_sub($response->{'Correct'});
604: shift(@$headers);
605: }
1.51 bisitz 606: $Str .= '<span class="LC_nobreak">'.
1.30 matthew 607: join('',
608: map {
609: (' 'x4).&mt($_.': [_1]',$response->{$_});
1.51 bisitz 610: } @$headers).'</span>';
1.30 matthew 611: if (@$headers || ! $single_response) {
612: $Str .= '<br />';
1.21 matthew 613: }
1.30 matthew 614: $Str .= &html_format_essay_sub($response->{'Submission'});
615: #
1.21 matthew 616: if (defined($correct) && $correct !~ /^\s*$/) {
617: $Str .= '<hr /><b>'.&mt('Correct').'</b>'.$correct
618: }
619: return $Str;
620: }
621:
1.30 matthew 622: sub html_format_essay_sub {
623: my ($submission) = @_;
624: return '' if (! defined($submission) || $submission eq '');
625: $submission = &HTML::Entities::decode($submission);
626: $submission =~ s/\\\"/\"/g;
627: $submission =~ s/\\\'/\'/g;
628: $submission =~ s|\\r\\n|$/|g;
629: $submission = &HTML::Entities::encode($submission,'<>&"');
630: $submission =~ s|$/\s*$/|$/</p><p>$/|g;
631: $submission =~ s|\\||g;
632: $submission = '<p>'.$submission.'</p>';
633: return $submission;
1.21 matthew 634: }
635:
1.42 albertel 636: sub html_task_results {
637: my ($headers,$prob,$partid,$respid,$response,$resptype) = @_;
638: if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) {
639: return '';
640: }
641:
642: my @values;
643: @values = map { $response->{$_}; } @$headers;
644:
645: my $td = '<td valign="top">';
646: my $str = $td.join('</td>'.$td,@values).'</td>';
647: return $str;
648: }
649:
1.30 matthew 650: sub html_non_essay_results {
651: my ($headers,$prob,$partid,$respid,$response,$resptype) = @_;
652: if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) {
653: return '';
654: }
655: #
1.45 www 656: my $submission = &HTML::Entities::decode(&unescape($response->{'Submission'}));
1.21 matthew 657: return '' if (! defined($submission) || $submission eq '');
1.25 matthew 658: $submission =~ s/\\\"/\"/g;
659: $submission =~ s/\\\'/\'/g;
1.30 matthew 660: if ($resptype eq 'radiobutton') {
1.25 matthew 661: $submission = &HTML::Entities::encode($submission,'<>&"');
1.21 matthew 662: $submission =~ s/=([^=])$//;
1.51 bisitz 663: $submission = '<span class="LC_nobreak">'.$submission.'</span>';
1.30 matthew 664: }
665: $response->{'Submission'} = $submission;
666: #
667: my @values;
668: if ($resptype =~ /^(option|match|rank)$/) {
669: my %submission =
670: map {
1.45 www 671: my ($foil,$value) = split('=',&unescape($_));
1.30 matthew 672: ($foil,$value);
673: } split('&',$response->{'Submission'});
674: my %correct;
675: if (exists($response->{'Correct'})) {
676: %correct =
677: map {
1.45 www 678: my ($foil,$value)=split('=',&unescape($_));
1.30 matthew 679: ($foil,$value);
680: } split('&',$response->{'Correct'});
681: }
682: #
683: foreach my $original_header (@$headers) {
684: if ($original_header =~ /^_/) {
685: # '_' denotes a foil column
686: my ($header) = ($original_header =~ m/^_(.*)$/);
687: my $option = '';
688: if ( my ($foil) = ($header =~ /(.*) Correct$/)) {
689: if (exists($correct{$foil})) {
690: $option = $correct{$foil};
691: }
692: } elsif (exists($submission{$header})) {
693: $option = $submission{$header};
694: }
695: push(@values,&HTML::Entities::encode($option));
1.38 matthew 696: } elsif ($original_header eq 'Time') {
697: push(@values,&Apache::lonlocal::locallocaltime($response->{$original_header}));
1.30 matthew 698: } else {
699: # A normal column
700: push(@values,$response->{$original_header});
701: }
702: }
1.25 matthew 703: } else {
1.30 matthew 704: @values = map { $response->{$_}; } @$headers;
1.21 matthew 705: }
1.30 matthew 706: my $td = '<td valign="top">';
707: my $str = $td.join('</td>'.$td,@values).'</td>';
708: return $str;
1.21 matthew 709: }
1.18 matthew 710:
1.30 matthew 711:
1.21 matthew 712: #########################################################
713: #########################################################
714: ##
715: ## Excel Output Routines
716: ##
717: #########################################################
718: #########################################################
719: sub prepare_excel_output {
1.54.10.1 raeburn 720: my ($r,$Problems,$Students,$show_named) = @_;
1.18 matthew 721: my $c = $r->connection();
1.54.10.1 raeburn 722: my $salt = '$1$'.$Apache::lonnet::perlvar{'AnonymousSalt'};
1.18 matthew 723: #
1.19 matthew 724: #
725: # Determine the number of columns in the spreadsheet
726: my $columncount = 3; # username, domain, id
1.31 matthew 727: my @extra_resp_headers = &get_extra_response_headers();
1.20 matthew 728: my $lastprob;
1.31 matthew 729: my %problem_analysis;
1.19 matthew 730: foreach my $prob (@$Problems) {
1.31 matthew 731: my %analysis = &Apache::lonstathelpers::get_problem_data($prob->src);
732: $problem_analysis{$prob->src}=\%analysis;
733: foreach my $partid (@{$prob->parts}) {
734: my $responses = [$prob->responseIds($partid)];
735: my $resptypes = [$prob->responseType($partid)];
736: for (my $i=0;$i<scalar(@$responses);$i++) {
737: my @headers = &get_headers($prob,$partid,$responses->[$i],
738: $resptypes->[$i],
739: $problem_analysis{$prob->src},
740: 'excel','display',
741: @extra_resp_headers);
742: $columncount += scalar(@headers);
743: }
744: }
1.19 matthew 745: last if ($columncount > 255);
1.20 matthew 746: $lastprob = $prob;
1.19 matthew 747: }
748: if ($columncount > 255) {
749: $r->print('<h1>'.&mt('Unable to complete request').'</h1>'.$/.
750: '<p>'.&mt('LON-CAPA is unable to produce your Excel spreadsheet because your selections will result in more than 255 columns. Excel allows only 255 columns in a spreadsheet.').'</p>'.$/.
1.20 matthew 751: '<p>'.&mt('Consider selecting fewer problems to generate reports on, or reducing the number of items per problem. Or use HTML or CSV output.').'</p>'.$/.
1.23 matthew 752: '<p>'.&mt('The last problem that will fit in the current spreadsheet is [_1].',$lastprob->compTitle).'</p>');
1.19 matthew 753: $r->rflush();
754: return;
755: }
756: #
757: # Print out a message telling them what we are doing
1.18 matthew 758: if (scalar(@$Problems) > 1) {
759: $r->print('<h2>'.
760: &mt('Preparing Excel spreadsheet of student responses to [_1] problems',
761: scalar(@$Problems)).
762: '</h2>');
763: } else {
764: $r->print('<h2>'.
765: &mt('Preparing Excel spreadsheet of student responses').
766: '</h2>');
767: }
768: $r->rflush();
769: #
770: # Create the excel spreadsheet
1.36 matthew 771: my ($workbook,$filename,$format) =
772: &Apache::loncommon::create_workbook($r);
773: return if (! defined($workbook));
1.18 matthew 774: my $worksheet = $workbook->addworksheet('Student Submission Data');
775: #
776: # Add headers to the worksheet
777: my $rows_output = 0;
778: $worksheet->write($rows_output++,0,
1.40 albertel 779: $env{'course.'.$env{'request.course.id'}.'.description'},
1.18 matthew 780: $format->{'h1'});
781: $rows_output++;
782: my $cols_output = 0;
783: my $title_row = $rows_output++;
784: my $partid_row = $rows_output++;
785: my $respid_row = $rows_output++;
786: my $header_row = $rows_output++;
787: $worksheet->write($title_row ,0,'Problem Title',$format->{'bold'});
788: $worksheet->write($partid_row,0,'Part ID',$format->{'bold'});
789: $worksheet->write($respid_row,0,'Response ID',$format->{'bold'});
790: # Student headers
1.54.10.1 raeburn 791: my @StudentColumns;
792: if ($show_named) {
793: @StudentColumns = qw(username domain id section);
794: } else {
795: @StudentColumns = qw(username);
796: }
797: foreach (@StudentColumns) {
798: $worksheet->write($header_row,$cols_output++,ucfirst($_),
799: $format->{'bold'});
800: }
1.18 matthew 801: # Problem headers
1.31 matthew 802: my %start_col;
1.18 matthew 803: foreach my $prob (@$Problems) {
1.23 matthew 804: my $title = $prob->compTitle;
1.54.10.4! raeburn 805: unless (&Apache::loncommon::needs_gci_custom()) {
! 806: ($title) = ($prob->src =~ m{/([^/]+)$});
! 807: }
1.18 matthew 808: $worksheet->write($title_row,$cols_output,
809: $title,$format->{'h3'});
810: foreach my $partid (@{$prob->parts}) {
1.24 matthew 811: $worksheet->write($partid_row,$cols_output,
812: $prob->part_display($partid));
1.18 matthew 813: my $responses = [$prob->responseIds($partid)];
814: my $resptypes = [$prob->responseType($partid)];
815: for (my $i=0;$i<scalar(@$responses);$i++) {
1.31 matthew 816: $start_col{$prob->symb}->{$partid}->{$responses->[$i]}=
817: $cols_output;
1.18 matthew 818: $worksheet->write($respid_row,$cols_output,
819: $resptypes->[$i].', '.$responses->[$i]);
1.31 matthew 820: my @headers = &get_headers($prob,$partid,$responses->[$i],
821: $resptypes->[$i],
822: $problem_analysis{$prob->src},
823: 'excel','display',
824: @extra_resp_headers);
825: foreach my $text (@headers) {
826: if ($text eq 'Time') {
827: $worksheet->set_column($cols_output,$cols_output,undef,
828: $format->{'date'});
829: }
830: $worksheet->write($header_row,$cols_output++,$text);
1.20 matthew 831: }
1.18 matthew 832: }
833: }
834: }
835: #
836: # Populate the worksheet with the student data
837: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
838: ($r,'Excel File Compilation Status',
839: 'Excel File Compilation Progress',
840: scalar(@$Students),'inline',undef,'Statistics','stats_status');
1.20 matthew 841: my $max_row = $rows_output;
1.18 matthew 842: foreach my $student (@$Students) {
843: last if ($c->aborted());
844: $cols_output = 0;
1.20 matthew 845: my $student_row = $max_row;
1.54.10.1 raeburn 846: my $anonid = &Crypt::PasswdMD5::unix_md5_crypt($student->{'username'},
847: $salt);
848: $anonid = substr($anonid,length($salt)+1);
1.18 matthew 849: foreach my $prob (@$Problems) {
850: foreach my $partid (@{$prob->parts}) {
851: my @Response = $prob->responseIds($partid);
852: my @ResponseType = $prob->responseType($partid);
853: for (my $i=0;$i<=$#Response;$i++) {
854: my $respid = $Response[$i];
855: my $resptype = $ResponseType[$i];
856: my $results =
857: &Apache::loncoursedata::get_response_data_by_student
858: ($student,$prob->symb(),$respid);
1.31 matthew 859: my @headers = &get_headers($prob,$partid,$respid,
860: $resptype,
861: $problem_analysis{$prob->src},
862: 'excel','normal',
863: @extra_resp_headers);
864:
1.20 matthew 865: if (! defined($results)) {
866: $results = [];
867: }
868: #
869: $rows_output = $student_row;
870: #
1.31 matthew 871: my $response_start_col = $start_col{$prob->symb}->{$partid}->{$respid};
1.20 matthew 872: for (my $j=scalar(@$results)-1;$j>=0;$j--) {
873: $cols_output = $response_start_col;
1.40 albertel 874: if ($env{'form.all_sub'} ne 'true') {
1.20 matthew 875: next if ($j ne scalar(@$results)-1);
876: }
1.31 matthew 877: my $response = &hashify_response($results->[$j],
878: $prob,
879: $student,
880: $partid,
881: $respid);
882: my @response_data =
1.33 matthew 883: &compile_response_data(\@headers,$response,
884: $prob,$partid,$respid,
885: $resptype,
886: \&excel_format_item);
1.31 matthew 887: $worksheet->write_row($rows_output++,$cols_output,
888: \@response_data);
889: $cols_output+=scalar(@response_data);
1.20 matthew 890: if ($rows_output > $max_row) {
891: $max_row = $rows_output;
892: }
1.19 matthew 893: }
1.18 matthew 894: }
895: }
896: }
1.54.10.4! raeburn 897: # Fill in the remaining rows with the students data
1.54.10.3 raeburn 898: for (my $row = $student_row;$row<$max_row;$row++) {
1.28 matthew 899: my $cols = 0;
900: foreach my $field (@StudentColumns) {
1.54.10.1 raeburn 901: if ($show_named) {
902: $worksheet->write($row,$cols++,
903: $student->{$field});
904: } else {
905: $worksheet->write($row,$cols++,
906: $anonid);
907: }
1.28 matthew 908: }
909: }
1.18 matthew 910: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
911: 'last student');
912: }
913: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
914: #
915: # Close the excel file
916: $workbook->close();
917: #
918: # Write a link to allow them to download it
919: $r->print('<p><a href="'.$filename.'">'.
920: &mt('Your Excel spreadsheet.').
921: '</a></p>'."\n");
922: $r->print('<script>'.
923: 'window.document.Statistics.stats_status.value="'.
924: 'Done compiling spreadsheet. See link below to download.'.
925: '";</script>');
926: $r->rflush();
927: return;
928: }
929:
1.33 matthew 930: sub compile_response_data {
931: my ($headers,$response,$prob,$partid,$respid,$resptype,$format) = @_;
1.31 matthew 932: if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) {
933: return ();
934: }
1.33 matthew 935: if (ref($format) ne 'CODE') {
936: $format = sub { return $_[0]; };
937: }
1.31 matthew 938: #
1.33 matthew 939: my $submission =
940: &HTML::Entities::decode
1.45 www 941: (&unescape($response->{'Submission'}));
1.42 albertel 942: if (!$prob->is_task()) {
943: return () if (! defined($submission) || $submission eq '');
944: }
1.31 matthew 945: $submission =~ s/\\\"/\"/g;
946: $submission =~ s/\\\'/\'/g;
947: if ($resptype eq 'radiobutton') {
948: $submission =~ s/=([^=])$//;
1.20 matthew 949: }
1.31 matthew 950: $response->{'Submission'} = $submission;
951: #
952: my @values;
953: if ($resptype =~ /^(option|match|rank)$/) {
954: my %submission =
955: map {
1.45 www 956: my ($foil,$value) = split('=',&unescape($_));
1.31 matthew 957: ($foil,$value);
958: } split('&',$response->{'Submission'});
959: my %correct;
960: if (exists($response->{'Correct'})) {
961: %correct =
962: map {
1.45 www 963: my ($foil,$value)=split('=',&unescape($_));
1.31 matthew 964: ($foil,$value);
965: } split('&',$response->{'Correct'});
966: }
967: #
968: foreach my $original_header (@$headers) {
969: if ($original_header =~ /^_/) {
970: # '_' denotes a foil column
971: my ($header) = ($original_header =~ m/^_(.*)$/);
972: my $option = '';
973: if ( my ($foil) = ($header =~ /(.*) Correct$/)) {
974: if (exists($correct{$foil})) {
975: $option = $correct{$foil};
976: }
977: } elsif (exists($submission{$header})) {
978: $option = $submission{$header};
979: }
1.33 matthew 980: push(@values,&{$format}($option,$header));
1.31 matthew 981: } else {
982: # A normal column
1.33 matthew 983: push(@values,&{$format}($response->{$original_header},
1.31 matthew 984: $original_header));
985: }
986: }
987: } else {
1.33 matthew 988: @values = map { &{$format}($response->{$_},$_); } @$headers;
1.20 matthew 989: }
1.31 matthew 990: return @values;
1.20 matthew 991: }
992:
1.31 matthew 993: sub excel_format_item {
994: my ($item,$type) = @_;
995: if ($type eq 'Time') {
1.33 matthew 996: $item = &Apache::lonstathelpers::calc_serial($item);
1.31 matthew 997: } else {
998: if ($item =~ m/^=/) {
999: $item = ' '.$item;
1000: }
1001: $item =~ s/\\r//g;
1002: $item =~ s/\\n/\n/g;
1003: $item =~ s/(\s*$|^\s*)//g;
1004: $item =~ s/\\\'/\'/g;
1.18 matthew 1005: }
1.31 matthew 1006: return $item;
1.1 matthew 1007: }
1008:
1009: #########################################################
1010: #########################################################
1.17 matthew 1011: ##
1012: ## CSV output of student answers
1013: ##
1014: #########################################################
1015: #########################################################
1016: sub prepare_csv_output {
1.54.10.1 raeburn 1017: my ($r,$problems,$students,$show_named) = @_;
1.17 matthew 1018: my $c = $r->connection();
1.54.10.1 raeburn 1019: my $salt = '$1$'.$Apache::lonnet::perlvar{'AnonymousSalt'};
1.17 matthew 1020: #
1021: $r->print('<h2>'.
1022: &mt('Generating CSV report of student responses').'</h2>');
1023: #
1024: # Progress window
1025: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1026: ($r,'CSV File Compilation Status',
1027: 'CSV File Compilation Progress',
1.22 matthew 1028: scalar(@$students),'inline',undef,'Statistics','stats_status');
1029:
1.17 matthew 1030: $r->rflush();
1031: #
1032: # Open a file
1033: my $outputfile;
1034: my $filename = '/prtspool/'.
1.40 albertel 1035: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.17 matthew 1036: time.'_'.rand(1000000000).'.csv';
1037: unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) {
1038: $r->log_error("Couldn't open $filename for output $!");
1.50 bisitz 1039: $r->print('<div class="LC_error">'
1040: .&mt('Problems occurred in writing the CSV file. '
1.47 bisitz 1041: .'This error has been logged. '
1.50 bisitz 1042: .'Please alert your LON-CAPA administrator.')
1043: .'</div>');
1.17 matthew 1044: $outputfile = undef;
1045: }
1046: #
1.22 matthew 1047: # Compute the number of columns per response
1.54.10.1 raeburn 1048: my @extra_resp_headers = &get_extra_response_headers($show_named);
1.22 matthew 1049: #
1050: # Create the table header
1.54.10.1 raeburn 1051: my @student_columns;
1052: if ($show_named) {
1053: @student_columns = qw(username domain id section);
1054: } else {
1055: @student_columns = qw(username);
1056: }
1.17 matthew 1057: #
1.22 matthew 1058: my %headers;
1059: push(@{$headers{'student'}},@student_columns);
1060: # Pad for the student data
1061: foreach my $row ('problem','part','response') {
1.32 matthew 1062: $headers{$row}=[map {''} @student_columns];
1.22 matthew 1063: }
1064: #
1065: # we put the headers into the %headers hash
1.32 matthew 1066: my %problem_analysis;
1067: my %start_col;
1068: my $max_column = scalar(@student_columns);
1.22 matthew 1069: foreach my $prob (@$problems) {
1.32 matthew 1070: my %analysis = &Apache::lonstathelpers::get_problem_data($prob->src);
1071: $problem_analysis{$prob->src}=\%analysis;
1.54.10.4! raeburn 1072: my $title = $prob->compTitle;
! 1073: unless (&Apache::loncommon::needs_gci_custom()) {
! 1074: ($title) = ($prob->src =~ m{/([^/]+)$});
! 1075: }
! 1076: $headers{'problem'}->[$max_column] = $title;
1.22 matthew 1077: foreach my $partid (@{$prob->parts}) {
1.32 matthew 1078: $headers{'part'}->[$max_column] = $prob->part_display($partid);
1.22 matthew 1079: my $responses = [$prob->responseIds($partid)];
1.32 matthew 1080: my $resptypes = [$prob->responseType($partid)];
1.22 matthew 1081: for (my $i=0;$i<scalar(@$responses);$i++) {
1.32 matthew 1082: my @headers = &get_headers($prob,$partid,$responses->[$i],
1083: $resptypes->[$i],
1084: $problem_analysis{$prob->src},
1085: 'csv','display',
1086: @extra_resp_headers);
1087: $start_col{$prob->symb}->{$partid}->{$responses->[$i]}=
1088: $max_column;
1089: $headers{'response'}->[$max_column]=
1.22 matthew 1090: &mt('Response [_1]',$responses->[$i]);
1.32 matthew 1091: for (my $j=0;$j<=$#headers;$j++) {
1092: $headers{'student'}->[$max_column+$j]=$headers[$j];
1.22 matthew 1093: }
1.32 matthew 1094: $max_column += scalar(@headers);
1.17 matthew 1095: }
1096: }
1097: }
1.22 matthew 1098: foreach my $row ('problem','part','response','student') {
1.32 matthew 1099: print $outputfile '"'.
1.22 matthew 1100: join('","',
1101: map {
1102: &Apache::loncommon::csv_translate($_);
1103: } @{$headers{$row}}).'"'.$/;
1.17 matthew 1104: }
1105: #
1.22 matthew 1106: # Main loop
1107: foreach my $student (@$students) {
1.27 matthew 1108: last if ($c->aborted());
1.54.10.1 raeburn 1109: my $anonid = &Crypt::PasswdMD5::unix_md5_crypt($student->{'username'},
1110: $salt);
1111: $anonid = substr($anonid,length($salt)+1);
1.22 matthew 1112: my @rows;
1113: foreach my $prob (@$problems) {
1114: foreach my $partid (@{$prob->parts}) {
1115: my @responses = $prob->responseIds($partid);
1116: my @response_type = $prob->responseType($partid);
1117: for (my $i=0;$i<=$#responses;$i++) {
1118: my $respid = $responses[$i];
1.32 matthew 1119: my $resptype = $response_type[$i];
1120: my @headers = &get_headers($prob,$partid,$respid,$resptype,
1121: $problem_analysis{$prob->src},
1122: 'csv','normal',
1123: @extra_resp_headers);
1.22 matthew 1124: my $results =
1125: &Apache::loncoursedata::get_response_data_by_student
1126: ($student,$prob->symb(),$respid);
1127: if (! defined($results)) {
1128: $results = [];
1129: }
1130: for (my $j=0; $j<scalar(@$results);$j++) {
1.40 albertel 1131: if ($env{'form.all_sub'} ne 'true') {
1.22 matthew 1132: next if ($j != 0);
1133: }
1134: my $idx = scalar(@$results) - $j - 1;
1.32 matthew 1135: my $response = &hashify_response($results->[$idx],
1136: $prob,$student,
1137: $partid,$respid);
1138: my @data = &compile_response_data(\@headers,$response,
1.22 matthew 1139: $prob,$partid,
1.33 matthew 1140: $respid,$resptype,
1141: \&csv_format_item);
1.32 matthew 1142: my $resp_start_idx =
1143: $start_col{$prob->symb}->{$partid}->{$respid};
1.22 matthew 1144: for (my $k=0;$k<=$#data;$k++) {
1.32 matthew 1145: $rows[$j]->[$resp_start_idx + $k] = $data[$k];
1.22 matthew 1146: }
1147: }
1148: }
1.17 matthew 1149: }
1.22 matthew 1150: }
1151: foreach my $row (@rows) {
1.54.10.1 raeburn 1152: my $student_row_data = '';
1153: if ($show_named) {
1154: $student_row_data = '"'.join('","',
1155: map { $student->{$_}; }
1156: @student_columns).'"';
1157: } else {
1158: $student_row_data = '"'.$anonid.'"';
1159: }
1160: print $outputfile $student_row_data;
1.32 matthew 1161: for (my $i=scalar(@student_columns);$i<$max_column;$i++) {
1.22 matthew 1162: my $value = &Apache::loncommon::csv_translate($row->[$i]);
1163: $value ||='';
1164: print $outputfile ',"'.$value.'"';
1.17 matthew 1165: }
1.22 matthew 1166: print $outputfile $/;
1.17 matthew 1167: }
1.22 matthew 1168: undef(@rows);
1.17 matthew 1169: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
1170: 'last student');
1171: }
1172: close($outputfile);
1173: #
1174: # Close the progress window
1175: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1176: #
1.48 bisitz 1177: # Tell the user where to get their CSV file
1.17 matthew 1178: $r->print('<br />'.
1.48 bisitz 1179: '<a href="'.$filename.'">'.&mt('Your CSV file.').'</a>'."\n");
1.17 matthew 1180: $r->rflush();
1181: return;
1182: }
1183:
1.32 matthew 1184: sub csv_format_item {
1185: my ($item,$type) = @_;
1186: if ($type eq 'Time') {
1187: $item = localtime($item);
1.33 matthew 1188: }
1.32 matthew 1189: $item =&Apache::loncommon::csv_translate($item);
1190: return $item;
1.15 matthew 1191: }
1192:
1.1 matthew 1193: #########################################################
1194: #########################################################
1195: ##
1196: ## Generic Interface Routines
1197: ##
1198: #########################################################
1199: #########################################################
1200: sub CreateInterface {
1201: ##
1.16 matthew 1202: ## Output Selection
1.19 matthew 1203: my $output_selector = $/.'<select name="output">'.$/;
1.22 matthew 1204: foreach ('HTML','Excel','CSV') {
1.19 matthew 1205: $output_selector .= ' <option value="'.lc($_).'"';
1.40 albertel 1206: if ($env{'form.output'} eq lc($_)) {
1.54.10.1 raeburn 1207: $output_selector .= ' selected="selected" ';
1.16 matthew 1208: }
1.19 matthew 1209: $output_selector .='>'.&mt($_).'</option>'.$/;
1.16 matthew 1210: }
1.19 matthew 1211: $output_selector .= '</select>'.$/;
1.16 matthew 1212: ##
1.1 matthew 1213: ## Environment variable initialization
1214: my $Str = '';
1.43 albertel 1215: $Str .= &Apache::lonhtmlcommon::breadcrumbs('Student Submission Reports');
1.54.10.1 raeburn 1216: $Str .= '<br />';
1.50 bisitz 1217: $Str .= &Apache::loncommon::start_data_table();
1218: $Str .= &Apache::loncommon::start_data_table_header_row();
1.16 matthew 1219: $Str .= '<th>'.&mt('Sections').'</th>';
1.44 raeburn 1220: $Str .= '<th>'.&mt('Groups').'</th>';
1.46 raeburn 1221: $Str .= '<th>'.&mt('Access Status').'</th>';
1.50 bisitz 1222: $Str .= '<th>'.&mt('Options').'</th>';
1223: $Str .= '<th>'.&mt('Output Format').'</th>';
1224: $Str .= &Apache::loncommon::end_data_table_header_row();
1.11 matthew 1225: #
1.50 bisitz 1226: $Str .= &Apache::loncommon::start_data_table_row();
1227: $Str .= '<td align="center">'."\n";
1.1 matthew 1228: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1229: $Str .= '</td>';
1230: #
1.44 raeburn 1231: $Str .= '<td align="center">'."\n";
1232: $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
1233: $Str .= '</td>';
1234: #
1.1 matthew 1235: $Str .= '<td align="center">';
1236: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1237: $Str .= '</td>';
1.6 matthew 1238: #
1.15 matthew 1239: # Render problem checkbox
1240: my $prob_checkbox = '<input type="checkbox" name="renderprob" ';
1.40 albertel 1241: if (exists($env{'form.renderprob'}) && $env{'form.renderprob'} eq 'true') {
1.50 bisitz 1242: $prob_checkbox .= 'checked="checked" ';
1.15 matthew 1243: }
1244: $prob_checkbox .= 'value="true" />';
1245: #
1246: # Compute correct answers checkbox
1247: my $ans_checkbox = '<input type="checkbox" name="correctans" ';
1.40 albertel 1248: if (exists($env{'form.correctans'}) && $env{'form.correctans'} eq 'true') {
1.50 bisitz 1249: $ans_checkbox .= 'checked="checked" ';
1.13 matthew 1250: }
1.15 matthew 1251: $ans_checkbox .= 'value="true" />';
1252: #
1.19 matthew 1253: # Show all submissions checkbox
1254: my $all_sub_checkbox = '<input type="checkbox" name="all_sub" ';
1.40 albertel 1255: if (exists($env{'form.all_sub'}) &&
1256: $env{'form.all_sub'} eq 'true') {
1.50 bisitz 1257: $all_sub_checkbox .= 'checked="checked" ';
1.15 matthew 1258: }
1.19 matthew 1259: $all_sub_checkbox.= 'value="true" />';
1.15 matthew 1260: #
1.20 matthew 1261: # problem status checkbox
1262: my $prob_status_checkbox = '<input type="checkbox" name="prob_status" ';
1.40 albertel 1263: if (exists($env{'form.prob_status'}) &&
1264: $env{'form.prob_status'} eq 'true') {
1.50 bisitz 1265: $prob_status_checkbox .= 'checked="checked" ';
1.15 matthew 1266: }
1.20 matthew 1267: $prob_status_checkbox .= 'value="true" />';
1.54.10.4! raeburn 1268: my $anon_checkbox;
! 1269: unless (&Apache::loncommon::needs_gci_custom()) {
! 1270: #
! 1271: # anonymized checkbox
! 1272: #
! 1273: $anon_checkbox = '<input type="checkbox" name="anonymized" ';
! 1274: if (exists($env{'form.anonymized'}) &&
! 1275: $env{'form.anonymized'} eq 'true') {
! 1276: $anon_checkbox .= 'checked="checked" ';
! 1277: }
! 1278: $anon_checkbox .= ' value="true" />';
! 1279: }
! 1280:
1.39 matthew 1281: $Str .= '<td align="right" valign="top">'.
1.16 matthew 1282: '<label><b>'.
1.54 bisitz 1283: &mt('Show problem').' '.$prob_checkbox.'</b></label><br />'.
1.20 matthew 1284: '<label><b>'.
1.54 bisitz 1285: &mt('Show correct answers').' '.$ans_checkbox.'</b></label><br />'.
1.20 matthew 1286: '<label><b>'.
1.54 bisitz 1287: &mt('Show all submissions').' '.$all_sub_checkbox.
1.20 matthew 1288: '</b></label><br />'.
1.15 matthew 1289: '<label><b>'.
1.54 bisitz 1290: &mt('Show problem grading').' '.$prob_status_checkbox.
1.54.10.4! raeburn 1291: '</b></label><br />';
! 1292:
! 1293: unless (&Apache::loncommon::needs_gci_custom()) {
! 1294: $Str .= '<label><b>'.
! 1295: &mt('Anonymized').' '.$anon_checkbox.
! 1296: '</b></label><br />';
! 1297: }
! 1298: $Str .= '</td>';
1.13 matthew 1299: #
1.50 bisitz 1300: $Str .= '<td align="center" valign="top">'.$output_selector.'</td>';
1301: #
1302: $Str .= &Apache::loncommon::end_data_table_row();
1303: $Str .= &Apache::loncommon::end_data_table();
1.1 matthew 1304: #
1.49 bisitz 1305: $Str .= '<p><span class="LC_nobreak">'
1306: .&mt('Status: [_1]',
1307: '<input type="text" name="stats_status"'
1308: .' size="60" value="" readonly="readonly" />')
1309: .'</span></p>';
1.11 matthew 1310: ##
1.1 matthew 1311: return $Str;
1312: }
1313:
1314: 1;
1315:
1316: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>