Annotation of loncom/interface/statistics/lonstudentsubmissions.pm, revision 1.54.10.2
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.54.10.2! raeburn 3: # $Id: lonstudentsubmissions.pm,v 1.54.10.1 2010/09/11 19:08:22 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.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: # Problem headers
1.31 matthew 778: my %start_col;
1.18 matthew 779: foreach my $prob (@$Problems) {
1.23 matthew 780: my $title = $prob->compTitle;
1.18 matthew 781: $worksheet->write($title_row,$cols_output,
782: $title,$format->{'h3'});
783: foreach my $partid (@{$prob->parts}) {
1.24 matthew 784: $worksheet->write($partid_row,$cols_output,
785: $prob->part_display($partid));
1.18 matthew 786: my $responses = [$prob->responseIds($partid)];
787: my $resptypes = [$prob->responseType($partid)];
788: for (my $i=0;$i<scalar(@$responses);$i++) {
1.31 matthew 789: $start_col{$prob->symb}->{$partid}->{$responses->[$i]}=
790: $cols_output;
1.18 matthew 791: $worksheet->write($respid_row,$cols_output,
792: $resptypes->[$i].', '.$responses->[$i]);
1.31 matthew 793: my @headers = &get_headers($prob,$partid,$responses->[$i],
794: $resptypes->[$i],
795: $problem_analysis{$prob->src},
796: 'excel','display',
797: @extra_resp_headers);
798: foreach my $text (@headers) {
799: if ($text eq 'Time') {
800: $worksheet->set_column($cols_output,$cols_output,undef,
801: $format->{'date'});
802: }
803: $worksheet->write($header_row,$cols_output++,$text);
1.20 matthew 804: }
1.18 matthew 805: }
806: }
807: }
808: #
809: # Populate the worksheet with the student data
810: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
811: ($r,'Excel File Compilation Status',
812: 'Excel File Compilation Progress',
813: scalar(@$Students),'inline',undef,'Statistics','stats_status');
1.20 matthew 814: my $max_row = $rows_output;
1.18 matthew 815: foreach my $student (@$Students) {
816: last if ($c->aborted());
817: $cols_output = 0;
1.20 matthew 818: my $student_row = $max_row;
1.54.10.1 raeburn 819: my $anonid = &Crypt::PasswdMD5::unix_md5_crypt($student->{'username'},
820: $salt);
821: $anonid = substr($anonid,length($salt)+1);
1.18 matthew 822: foreach my $field (@StudentColumns) {
1.54.10.1 raeburn 823: if ($show_named) {
824: $worksheet->write($student_row,$cols_output++,
825: $student->{$field});
826: } else {
827: $worksheet->write($student_row,$cols_output++,
828: $anonid);
829: }
1.18 matthew 830: }
1.20 matthew 831: my $last_student_col = $cols_output-1;
1.18 matthew 832: foreach my $prob (@$Problems) {
833: foreach my $partid (@{$prob->parts}) {
834: my @Response = $prob->responseIds($partid);
835: my @ResponseType = $prob->responseType($partid);
836: for (my $i=0;$i<=$#Response;$i++) {
837: my $respid = $Response[$i];
838: my $resptype = $ResponseType[$i];
839: my $results =
840: &Apache::loncoursedata::get_response_data_by_student
841: ($student,$prob->symb(),$respid);
1.31 matthew 842: my @headers = &get_headers($prob,$partid,$respid,
843: $resptype,
844: $problem_analysis{$prob->src},
845: 'excel','normal',
846: @extra_resp_headers);
847:
1.20 matthew 848: if (! defined($results)) {
849: $results = [];
850: }
851: #
852: $rows_output = $student_row;
853: #
1.31 matthew 854: my $response_start_col = $start_col{$prob->symb}->{$partid}->{$respid};
1.20 matthew 855: for (my $j=scalar(@$results)-1;$j>=0;$j--) {
856: $cols_output = $response_start_col;
1.40 albertel 857: if ($env{'form.all_sub'} ne 'true') {
1.20 matthew 858: next if ($j ne scalar(@$results)-1);
859: }
1.31 matthew 860: my $response = &hashify_response($results->[$j],
861: $prob,
862: $student,
863: $partid,
864: $respid);
865: my @response_data =
1.33 matthew 866: &compile_response_data(\@headers,$response,
867: $prob,$partid,$respid,
868: $resptype,
869: \&excel_format_item);
1.31 matthew 870: $worksheet->write_row($rows_output++,$cols_output,
871: \@response_data);
872: $cols_output+=scalar(@response_data);
1.20 matthew 873: if ($rows_output > $max_row) {
874: $max_row = $rows_output;
875: }
1.19 matthew 876: }
1.18 matthew 877: }
878: }
879: }
1.28 matthew 880: # Fill in the remaining rows with the students data
1.34 matthew 881: for (my $row = $student_row+1;$row<$max_row;$row++) {
1.28 matthew 882: my $cols = 0;
883: foreach my $field (@StudentColumns) {
1.54.10.1 raeburn 884: if ($show_named) {
885: $worksheet->write($row,$cols++,
886: $student->{$field});
887: } else {
888: $worksheet->write($row,$cols++,
889: $anonid);
890: }
1.28 matthew 891: }
892: }
1.18 matthew 893: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
894: 'last student');
895: }
896: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
897: #
898: # Close the excel file
899: $workbook->close();
900: #
901: # Write a link to allow them to download it
902: $r->print('<p><a href="'.$filename.'">'.
903: &mt('Your Excel spreadsheet.').
904: '</a></p>'."\n");
905: $r->print('<script>'.
906: 'window.document.Statistics.stats_status.value="'.
907: 'Done compiling spreadsheet. See link below to download.'.
908: '";</script>');
909: $r->rflush();
910: return;
911: }
912:
1.33 matthew 913: sub compile_response_data {
914: my ($headers,$response,$prob,$partid,$respid,$resptype,$format) = @_;
1.31 matthew 915: if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) {
916: return ();
917: }
1.33 matthew 918: if (ref($format) ne 'CODE') {
919: $format = sub { return $_[0]; };
920: }
1.31 matthew 921: #
1.33 matthew 922: my $submission =
923: &HTML::Entities::decode
1.45 www 924: (&unescape($response->{'Submission'}));
1.42 albertel 925: if (!$prob->is_task()) {
926: return () if (! defined($submission) || $submission eq '');
927: }
1.31 matthew 928: $submission =~ s/\\\"/\"/g;
929: $submission =~ s/\\\'/\'/g;
930: if ($resptype eq 'radiobutton') {
931: $submission =~ s/=([^=])$//;
1.20 matthew 932: }
1.31 matthew 933: $response->{'Submission'} = $submission;
934: #
935: my @values;
936: if ($resptype =~ /^(option|match|rank)$/) {
937: my %submission =
938: map {
1.45 www 939: my ($foil,$value) = split('=',&unescape($_));
1.31 matthew 940: ($foil,$value);
941: } split('&',$response->{'Submission'});
942: my %correct;
943: if (exists($response->{'Correct'})) {
944: %correct =
945: map {
1.45 www 946: my ($foil,$value)=split('=',&unescape($_));
1.31 matthew 947: ($foil,$value);
948: } split('&',$response->{'Correct'});
949: }
950: #
951: foreach my $original_header (@$headers) {
952: if ($original_header =~ /^_/) {
953: # '_' denotes a foil column
954: my ($header) = ($original_header =~ m/^_(.*)$/);
955: my $option = '';
956: if ( my ($foil) = ($header =~ /(.*) Correct$/)) {
957: if (exists($correct{$foil})) {
958: $option = $correct{$foil};
959: }
960: } elsif (exists($submission{$header})) {
961: $option = $submission{$header};
962: }
1.33 matthew 963: push(@values,&{$format}($option,$header));
1.31 matthew 964: } else {
965: # A normal column
1.33 matthew 966: push(@values,&{$format}($response->{$original_header},
1.31 matthew 967: $original_header));
968: }
969: }
970: } else {
1.33 matthew 971: @values = map { &{$format}($response->{$_},$_); } @$headers;
1.20 matthew 972: }
1.31 matthew 973: return @values;
1.20 matthew 974: }
975:
1.31 matthew 976: sub excel_format_item {
977: my ($item,$type) = @_;
978: if ($type eq 'Time') {
1.33 matthew 979: $item = &Apache::lonstathelpers::calc_serial($item);
1.31 matthew 980: } else {
981: if ($item =~ m/^=/) {
982: $item = ' '.$item;
983: }
984: $item =~ s/\\r//g;
985: $item =~ s/\\n/\n/g;
986: $item =~ s/(\s*$|^\s*)//g;
987: $item =~ s/\\\'/\'/g;
1.18 matthew 988: }
1.31 matthew 989: return $item;
1.1 matthew 990: }
991:
992: #########################################################
993: #########################################################
1.17 matthew 994: ##
995: ## CSV output of student answers
996: ##
997: #########################################################
998: #########################################################
999: sub prepare_csv_output {
1.54.10.1 raeburn 1000: my ($r,$problems,$students,$show_named) = @_;
1.17 matthew 1001: my $c = $r->connection();
1.54.10.1 raeburn 1002: my $salt = '$1$'.$Apache::lonnet::perlvar{'AnonymousSalt'};
1.17 matthew 1003: #
1004: $r->print('<h2>'.
1005: &mt('Generating CSV report of student responses').'</h2>');
1006: #
1007: # Progress window
1008: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1009: ($r,'CSV File Compilation Status',
1010: 'CSV File Compilation Progress',
1.22 matthew 1011: scalar(@$students),'inline',undef,'Statistics','stats_status');
1012:
1.17 matthew 1013: $r->rflush();
1014: #
1015: # Open a file
1016: my $outputfile;
1017: my $filename = '/prtspool/'.
1.40 albertel 1018: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.17 matthew 1019: time.'_'.rand(1000000000).'.csv';
1020: unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) {
1021: $r->log_error("Couldn't open $filename for output $!");
1.50 bisitz 1022: $r->print('<div class="LC_error">'
1023: .&mt('Problems occurred in writing the CSV file. '
1.47 bisitz 1024: .'This error has been logged. '
1.50 bisitz 1025: .'Please alert your LON-CAPA administrator.')
1026: .'</div>');
1.17 matthew 1027: $outputfile = undef;
1028: }
1029: #
1.22 matthew 1030: # Compute the number of columns per response
1.54.10.1 raeburn 1031: my @extra_resp_headers = &get_extra_response_headers($show_named);
1.22 matthew 1032: #
1033: # Create the table header
1.54.10.1 raeburn 1034: my @student_columns;
1035: if ($show_named) {
1036: @student_columns = qw(username domain id section);
1037: } else {
1038: @student_columns = qw(username);
1039: }
1.17 matthew 1040: #
1.22 matthew 1041: my %headers;
1042: push(@{$headers{'student'}},@student_columns);
1043: # Pad for the student data
1044: foreach my $row ('problem','part','response') {
1.32 matthew 1045: $headers{$row}=[map {''} @student_columns];
1.22 matthew 1046: }
1047: #
1048: # we put the headers into the %headers hash
1.32 matthew 1049: my %problem_analysis;
1050: my %start_col;
1051: my $max_column = scalar(@student_columns);
1.22 matthew 1052: foreach my $prob (@$problems) {
1.32 matthew 1053: my %analysis = &Apache::lonstathelpers::get_problem_data($prob->src);
1054: $problem_analysis{$prob->src}=\%analysis;
1055: $headers{'problem'}->[$max_column] = $prob->compTitle;
1.22 matthew 1056: foreach my $partid (@{$prob->parts}) {
1.32 matthew 1057: $headers{'part'}->[$max_column] = $prob->part_display($partid);
1.22 matthew 1058: my $responses = [$prob->responseIds($partid)];
1.32 matthew 1059: my $resptypes = [$prob->responseType($partid)];
1.22 matthew 1060: for (my $i=0;$i<scalar(@$responses);$i++) {
1.32 matthew 1061: my @headers = &get_headers($prob,$partid,$responses->[$i],
1062: $resptypes->[$i],
1063: $problem_analysis{$prob->src},
1064: 'csv','display',
1065: @extra_resp_headers);
1066: $start_col{$prob->symb}->{$partid}->{$responses->[$i]}=
1067: $max_column;
1068: $headers{'response'}->[$max_column]=
1.22 matthew 1069: &mt('Response [_1]',$responses->[$i]);
1.32 matthew 1070: for (my $j=0;$j<=$#headers;$j++) {
1071: $headers{'student'}->[$max_column+$j]=$headers[$j];
1.22 matthew 1072: }
1.32 matthew 1073: $max_column += scalar(@headers);
1.17 matthew 1074: }
1075: }
1076: }
1.22 matthew 1077: foreach my $row ('problem','part','response','student') {
1.32 matthew 1078: print $outputfile '"'.
1.22 matthew 1079: join('","',
1080: map {
1081: &Apache::loncommon::csv_translate($_);
1082: } @{$headers{$row}}).'"'.$/;
1.17 matthew 1083: }
1084: #
1.22 matthew 1085: # Main loop
1086: foreach my $student (@$students) {
1.27 matthew 1087: last if ($c->aborted());
1.54.10.1 raeburn 1088: my $anonid = &Crypt::PasswdMD5::unix_md5_crypt($student->{'username'},
1089: $salt);
1090: $anonid = substr($anonid,length($salt)+1);
1.22 matthew 1091: my @rows;
1092: foreach my $prob (@$problems) {
1093: foreach my $partid (@{$prob->parts}) {
1094: my @responses = $prob->responseIds($partid);
1095: my @response_type = $prob->responseType($partid);
1096: for (my $i=0;$i<=$#responses;$i++) {
1097: my $respid = $responses[$i];
1.32 matthew 1098: my $resptype = $response_type[$i];
1099: my @headers = &get_headers($prob,$partid,$respid,$resptype,
1100: $problem_analysis{$prob->src},
1101: 'csv','normal',
1102: @extra_resp_headers);
1.22 matthew 1103: my $results =
1104: &Apache::loncoursedata::get_response_data_by_student
1105: ($student,$prob->symb(),$respid);
1106: if (! defined($results)) {
1107: $results = [];
1108: }
1109: for (my $j=0; $j<scalar(@$results);$j++) {
1.40 albertel 1110: if ($env{'form.all_sub'} ne 'true') {
1.22 matthew 1111: next if ($j != 0);
1112: }
1113: my $idx = scalar(@$results) - $j - 1;
1.32 matthew 1114: my $response = &hashify_response($results->[$idx],
1115: $prob,$student,
1116: $partid,$respid);
1117: my @data = &compile_response_data(\@headers,$response,
1.22 matthew 1118: $prob,$partid,
1.33 matthew 1119: $respid,$resptype,
1120: \&csv_format_item);
1.32 matthew 1121: my $resp_start_idx =
1122: $start_col{$prob->symb}->{$partid}->{$respid};
1.22 matthew 1123: for (my $k=0;$k<=$#data;$k++) {
1.32 matthew 1124: $rows[$j]->[$resp_start_idx + $k] = $data[$k];
1.22 matthew 1125: }
1126: }
1127: }
1.17 matthew 1128: }
1.22 matthew 1129: }
1130: foreach my $row (@rows) {
1.54.10.1 raeburn 1131: my $student_row_data = '';
1132: if ($show_named) {
1133: $student_row_data = '"'.join('","',
1134: map { $student->{$_}; }
1135: @student_columns).'"';
1136: } else {
1137: $student_row_data = '"'.$anonid.'"';
1138: }
1139: print $outputfile $student_row_data;
1.32 matthew 1140: for (my $i=scalar(@student_columns);$i<$max_column;$i++) {
1.22 matthew 1141: my $value = &Apache::loncommon::csv_translate($row->[$i]);
1142: $value ||='';
1143: print $outputfile ',"'.$value.'"';
1.17 matthew 1144: }
1.22 matthew 1145: print $outputfile $/;
1.17 matthew 1146: }
1.22 matthew 1147: undef(@rows);
1.17 matthew 1148: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
1149: 'last student');
1150: }
1151: close($outputfile);
1152: #
1153: # Close the progress window
1154: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1155: #
1.48 bisitz 1156: # Tell the user where to get their CSV file
1.17 matthew 1157: $r->print('<br />'.
1.48 bisitz 1158: '<a href="'.$filename.'">'.&mt('Your CSV file.').'</a>'."\n");
1.17 matthew 1159: $r->rflush();
1160: return;
1161: }
1162:
1.32 matthew 1163: sub csv_format_item {
1164: my ($item,$type) = @_;
1165: if ($type eq 'Time') {
1166: $item = localtime($item);
1.33 matthew 1167: }
1.32 matthew 1168: $item =&Apache::loncommon::csv_translate($item);
1169: return $item;
1.15 matthew 1170: }
1171:
1.1 matthew 1172: #########################################################
1173: #########################################################
1174: ##
1175: ## Generic Interface Routines
1176: ##
1177: #########################################################
1178: #########################################################
1179: sub CreateInterface {
1180: ##
1.16 matthew 1181: ## Output Selection
1.19 matthew 1182: my $output_selector = $/.'<select name="output">'.$/;
1.22 matthew 1183: foreach ('HTML','Excel','CSV') {
1.19 matthew 1184: $output_selector .= ' <option value="'.lc($_).'"';
1.40 albertel 1185: if ($env{'form.output'} eq lc($_)) {
1.54.10.1 raeburn 1186: $output_selector .= ' selected="selected" ';
1.16 matthew 1187: }
1.19 matthew 1188: $output_selector .='>'.&mt($_).'</option>'.$/;
1.16 matthew 1189: }
1.19 matthew 1190: $output_selector .= '</select>'.$/;
1.16 matthew 1191: ##
1.1 matthew 1192: ## Environment variable initialization
1193: my $Str = '';
1.43 albertel 1194: $Str .= &Apache::lonhtmlcommon::breadcrumbs('Student Submission Reports');
1.54.10.1 raeburn 1195: $Str .= '<br />';
1.50 bisitz 1196: $Str .= &Apache::loncommon::start_data_table();
1197: $Str .= &Apache::loncommon::start_data_table_header_row();
1.16 matthew 1198: $Str .= '<th>'.&mt('Sections').'</th>';
1.44 raeburn 1199: $Str .= '<th>'.&mt('Groups').'</th>';
1.46 raeburn 1200: $Str .= '<th>'.&mt('Access Status').'</th>';
1.50 bisitz 1201: $Str .= '<th>'.&mt('Options').'</th>';
1202: $Str .= '<th>'.&mt('Output Format').'</th>';
1203: $Str .= &Apache::loncommon::end_data_table_header_row();
1.11 matthew 1204: #
1.50 bisitz 1205: $Str .= &Apache::loncommon::start_data_table_row();
1206: $Str .= '<td align="center">'."\n";
1.1 matthew 1207: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1208: $Str .= '</td>';
1209: #
1.44 raeburn 1210: $Str .= '<td align="center">'."\n";
1211: $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
1212: $Str .= '</td>';
1213: #
1.1 matthew 1214: $Str .= '<td align="center">';
1215: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1216: $Str .= '</td>';
1.6 matthew 1217: #
1.15 matthew 1218: # Render problem checkbox
1219: my $prob_checkbox = '<input type="checkbox" name="renderprob" ';
1.40 albertel 1220: if (exists($env{'form.renderprob'}) && $env{'form.renderprob'} eq 'true') {
1.50 bisitz 1221: $prob_checkbox .= 'checked="checked" ';
1.15 matthew 1222: }
1223: $prob_checkbox .= 'value="true" />';
1224: #
1225: # Compute correct answers checkbox
1226: my $ans_checkbox = '<input type="checkbox" name="correctans" ';
1.40 albertel 1227: if (exists($env{'form.correctans'}) && $env{'form.correctans'} eq 'true') {
1.50 bisitz 1228: $ans_checkbox .= 'checked="checked" ';
1.13 matthew 1229: }
1.15 matthew 1230: $ans_checkbox .= 'value="true" />';
1231: #
1.19 matthew 1232: # Show all submissions checkbox
1233: my $all_sub_checkbox = '<input type="checkbox" name="all_sub" ';
1.40 albertel 1234: if (exists($env{'form.all_sub'}) &&
1235: $env{'form.all_sub'} eq 'true') {
1.50 bisitz 1236: $all_sub_checkbox .= 'checked="checked" ';
1.15 matthew 1237: }
1.19 matthew 1238: $all_sub_checkbox.= 'value="true" />';
1.15 matthew 1239: #
1.20 matthew 1240: # problem status checkbox
1241: my $prob_status_checkbox = '<input type="checkbox" name="prob_status" ';
1.40 albertel 1242: if (exists($env{'form.prob_status'}) &&
1243: $env{'form.prob_status'} eq 'true') {
1.50 bisitz 1244: $prob_status_checkbox .= 'checked="checked" ';
1.15 matthew 1245: }
1.20 matthew 1246: $prob_status_checkbox .= 'value="true" />';
1.15 matthew 1247: #
1.39 matthew 1248: $Str .= '<td align="right" valign="top">'.
1.16 matthew 1249: '<label><b>'.
1.54 bisitz 1250: &mt('Show problem').' '.$prob_checkbox.'</b></label><br />'.
1.20 matthew 1251: '<label><b>'.
1.54 bisitz 1252: &mt('Show correct answers').' '.$ans_checkbox.'</b></label><br />'.
1.20 matthew 1253: '<label><b>'.
1.54 bisitz 1254: &mt('Show all submissions').' '.$all_sub_checkbox.
1.20 matthew 1255: '</b></label><br />'.
1.15 matthew 1256: '<label><b>'.
1.54 bisitz 1257: &mt('Show problem grading').' '.$prob_status_checkbox.
1.20 matthew 1258: '</b></label><br />'.
1.15 matthew 1259: '</td>';
1.13 matthew 1260: #
1.50 bisitz 1261: $Str .= '<td align="center" valign="top">'.$output_selector.'</td>';
1262: #
1263: $Str .= &Apache::loncommon::end_data_table_row();
1264: $Str .= &Apache::loncommon::end_data_table();
1.1 matthew 1265: #
1.49 bisitz 1266: $Str .= '<p><span class="LC_nobreak">'
1267: .&mt('Status: [_1]',
1268: '<input type="text" name="stats_status"'
1269: .' size="60" value="" readonly="readonly" />')
1270: .'</span></p>';
1.11 matthew 1271: ##
1.1 matthew 1272: return $Str;
1273: }
1274:
1275: 1;
1276:
1277: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>