# The LearningOnline Network with CAPA # # $Id: lonstudentsubmissions.pm,v 1.15 2004/09/01 21:13:04 matthew Exp $ # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # # LON-CAPA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LON-CAPA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ # package Apache::lonstudentsubmissions; use strict; use Apache::lonnet(); use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::loncoursedata(); use Apache::lonstatistics; use Apache::lonlocal; use Apache::lonstathelpers; use HTML::Entities(); use Time::Local(); use Spreadsheet::WriteExcel(); my @SubmitButtons = ({ name => 'PrevProblem', text => 'Previous Problem' }, { name => 'NextProblem', text => 'Next Problem' }, { name => 'break'}, { name => 'SelectAnother', text => 'Choose a different Problem' }, { name => 'Generate', text => 'Generate Spreadsheet'}, ); sub BuildStudentSubmissionsPage { my ($r,$c)=@_; # my %Saveable_Parameters = ('Status' => 'scalar', 'Section' => 'array', 'NumPlots' => 'scalar', ); &Apache::loncommon::store_course_settings('student_submissions', \%Saveable_Parameters); &Apache::loncommon::restore_course_settings('student_submissions', \%Saveable_Parameters); # &Apache::lonstatistics::PrepareClasslist(); # $r->print(&CreateInterface()); # my @Students = @Apache::lonstatistics::Students; # if (@Students < 1) { $r->print('

There are no students in the sections selected

'); } # my @CacheButtonHTML = &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status'); $r->rflush(); # if (exists($ENV{'form.problemchoice'}) && ! exists($ENV{'form.SelectAnother'})) { foreach my $button (@SubmitButtons) { if ($button->{'name'} eq 'break') { $r->print("
\n"); } else { $r->print(''); $r->print(' 'x5); } } foreach my $html (@CacheButtonHTML) { $r->print($html.(' 'x5)); } # $r->print('
'); $r->rflush(); # # Determine which problem we are to analyze my $current_problem = &Apache::lonstathelpers::get_target_from_id ($ENV{'form.problemchoice'}); # my ($prev,$curr,$next) = &Apache::lonstathelpers::get_prev_curr_next($current_problem, '.', 'response', ); if (exists($ENV{'form.PrevProblem'}) && defined($prev)) { $current_problem = $prev; } elsif (exists($ENV{'form.NextProblem'}) && defined($next)) { $current_problem = $next; } else { $current_problem = $curr; } # # Store the current problem choice and send it out in the form $ENV{'form.problemchoice'} = &Apache::lonstathelpers::make_target_id($current_problem); $r->print(''); # if (! defined($current_problem->{'resource'})) { $r->print('resource is undefined'); } else { my $resource = $current_problem->{'resource'}; $r->print('

'.$resource->{'title'}.'

'); $r->print('

'.$resource->{'src'}.'

'); if ($ENV{'form.renderprob'} eq 'true') { $r->print(&Apache::lonstathelpers::render_resource($resource)); } $r->rflush(); my %Data = &Apache::lonstathelpers::get_problem_data ($resource->{'src'}); my $ProblemData = $Data{$current_problem->{'part'}. '.'. $current_problem->{'respid'}}; &prepare_html_output($r,$current_problem, $ProblemData,\@Students); # &prepare_excel_output($r,$current_problem, # $ProblemData,\@Students); } $r->print('
'); } else { $r->print(''); $r->print(' 'x5); $r->print('

'.&mt('Please select a problem to analyze').'

'); $r->print(&Apache::lonstathelpers::ProblemSelector('.')); } } ######################################################### ######################################################### ## ## prepare_html_output ## ######################################################### ######################################################### sub prepare_html_output { my ($r,$problem,$ProblemData,$Students) = @_; my $c = $r->connection(); my ($resource,$respid,$partid) = ($problem->{'resource'}, $problem->{'respid'}, $problem->{'part'}); $r->print('

'.&mt('Student Responses').'

'); # if ($ENV{'form.correctans'} eq 'true') { &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students, 'Statistics', 'stats_status'); } # $r->rflush(); my $response_type; for (my $i=0; $i{'partdata'}->{$partid}->{'ResponseIds'}}); $i++) { if($resource->{'partdata'}->{$partid}->{'ResponseIds'}->[$i] eq $respid){ $response_type = $resource->{'partdata'}->{$partid}->{'ResponseTypes'}->[$i]; last; } } if (! defined($response_type)) { $r->print('

'.&mt('Unable to determine response type').'

'); } else { my $count = 0; my $header; if ($response_type eq 'essay') { $header = &html_essay_header(); } elsif ($response_type eq 'radiobutton') { $header = &html_radiobutton_header(); } elsif ($response_type eq 'option') { $header = &html_option_header(); } else { $header = &html_generic_header(); } $header = ''.$header.''; # $r->print($/.''.$/.$header.$/); foreach my $student (@$Students) { if ($count >= 50) { $r->print('
'.$/.''.$/.$header.$/); $count = 0; } last if ($c->aborted()); my $results = &Apache::loncoursedata::get_response_data_by_student ($student,$resource->{'symb'},$respid); next if (! defined($results) || ref($results) ne 'ARRAY'); for (my $i=0;$i[$i]; if ($ENV{'form.last_sub_only'} eq 'true' && $i < (scalar(@$results)-1)) { next; } my $data; $data->{'sname'} = $student->{'username'}.'@'. $student->{'domain'}; $data->{'time'} = &Apache::lonlocal::locallocaltime ($response->[&Apache::loncoursedata::RDs_timestamp()]); $data->{'attempt'} = $response->[&Apache::loncoursedata::RDs_tries()]; $data->{'submission'} = $response->[&Apache::loncoursedata::RDs_submission()]; $data->{'correct'} = $student->{'answer'}; my $row; if ($response_type eq 'essay') { $row = &html_essay($data); } elsif ($response_type eq 'radiobutton') { $row = &html_radiobutton($data); } elsif ($response_type eq 'option') { $row = &html_option($data); } else { $row = &html_generic($data); } $r->print($row.$/); $count++; } } $r->print('
'.$/); } return; } ##################################################### ## ## HTML helper routines ## ##################################################### my @FullHeaders = ( {name=>'sname', display=>'Student'}, {name => 'id', display => 'Id'}, {name => 'time', display =>'Time'}, {name => 'attempt', display =>'Attempt'}, {name => 'grading', display =>'Grading'}, ); sub html_essay_header { my $header; if ($ENV{'form.subdata'} eq 'true') { foreach (@FullHeaders) { $header .= ''.&mt($_->{'display'}).''; } } else { $header = ''.&mt('Username and Submission').''; } return $header; } sub html_essay { my ($data)=@_; # $data->{'submission'} =~ s|\\r\\n|$/|g; $data->{'submission'} = &HTML::Entities::encode($data->{'submission'},'<>&"'); $data->{'submission'} =~ s|$/\s*$/|$/

$/|g; $data->{'submission'} =~ s|\\||g; $data->{'submission'} = '

'.$data->{'submission'}.'

'; # my $Str = ''; if ($ENV{'form.subdata'} eq 'true') { $Str .= ''.$data->{'sname'}.''. ''.$data->{'time'}.''. ''.$data->{'attempt'}.''; $Str .= ''; $Str .= ''. $data->{'submission'}.''; } else { $Str .= ''.$data->{'sname'}.''. $data->{'submission'}.''; } if ($ENV{'form.correctans'} eq 'true') { $Str .= ''; if (defined($data->{'correct'}) && $data->{'correct'} !~ /^\s*$/) { $Str .= ''. ''.&mt('Correct Answer:').''.$data->{'correct'}.''; } } $Str .= ''; # return $Str; } sub html_radiobutton_header { my $header; if ($ENV{'form.subdata'} eq 'true') { foreach (@FullHeaders) { $header .= ''.&mt($_->{'display'}).''; } } else { $header = ''.&mt('Username').''; } $header .=''.&mt('Submission').''; if ($ENV{'form.correctans'} eq 'true') { $header .= ''.&mt('Correct').''; } return $header; } sub html_radiobutton { my ($data)=@_; # $data->{'submission'} =~ s/=([^=])$//; # my $Str = ''; if ($ENV{'form.subdata'} eq 'true') { $Str .= ''.''.$data->{'sname'}.''. ''.$data->{'time'}.''. ''.$data->{'attempt'}.''; $Str .= ''.$data->{'submission'}.''; if ($ENV{'form.correctans'} eq 'true') { $Str .= ''.$data->{'correct'}.''; } } else { $Str .= ''.$data->{'sname'}.''; $Str .= ''.$data->{'submission'}.''; if ($ENV{'form.correctans'} eq 'true') { $Str .= ''.$data->{'correct'}.''; } } $Str .= ''; # return $Str; } sub html_generic_header { my $header; if ($ENV{'form.subdata'} eq 'true') { foreach (@FullHeaders) { $header .= ''.&mt($_->{'display'}).''; } } else { $header = ''.&mt('Username').''; } $header .= ''.&mt('Submission').''; if ($ENV{'form.correctans'} eq 'true') { $header .= ''.&mt('Correct').''; } return $header; } sub html_generic { my ($data)=@_; $data->{'submission'} = &Apache::lonnet::unescape($data->{'submission'}); my $Str = ''; if ($ENV{'form.subdata'} eq 'true') { $Str .= ''.$data->{'sname'}.''. ''.$data->{'time'}.''. ''.$data->{'attempt'}.''; } else { $Str .= ''.$data->{'sname'}.''; } $Str .= ''.$data->{'submission'}.''; if ($ENV{'form.correctans'} eq 'true') { $Str .= ''.$data->{'correct'}.''; } $Str .= ''; return $Str; } sub html_option_header { my $header; if ($ENV{'form.subdata'} eq 'true') { foreach (@FullHeaders) { $header .= ''.&mt($_->{'display'}).''; } } else { $header = ''.&mt('Username').''; } $header .= ''.&mt('Submission').''; if ($ENV{'form.correctans'} eq 'true') { $header .= ''.&mt('Correct').''; } return $header; } sub html_option { my ($data)=@_; $data->{'submission'} = '