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