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