--- loncom/interface/statistics/lonsurveyreports.pm 2005/03/18 00:20:44 1.7 +++ loncom/interface/statistics/lonsurveyreports.pm 2010/01/14 17:20:52 1.23 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonsurveyreports.pm,v 1.7 2005/03/18 00:20:44 matthew Exp $ +# $Id: lonsurveyreports.pm,v 1.23 2010/01/14 17:20:52 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,7 +27,7 @@ package Apache::lonsurveyreports; use strict; -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::loncoursedata(); @@ -37,6 +37,9 @@ use Apache::lonstathelpers; use Spreadsheet::WriteExcel; use HTML::Entities(); use Time::Local(); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + my @SubmitButtons = ( { name => 'break'}, @@ -70,15 +73,15 @@ sub BuildSurveyReportsPage { my @Students = @Apache::lonstatistics::Students; # if (@Students < 1) { - $r->print('

There are no students in the sections selected

'); + $r->print('

'.&mt('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'})) { + if (exists($env{'form.problemchoice'}) && + ! exists($env{'form.SelectAnother'})) { $r->print(' 'x3); foreach my $button (@SubmitButtons) { if ($button->{'name'} eq 'break') { @@ -95,33 +98,33 @@ sub BuildSurveyReportsPage { # $r->print('
'); $r->print('

'. - &Apache::lonlocal::locallocaltime(time).','. + &Apache::lonlocal::locallocaltime(time).', '. &Apache::lonstatistics::section_and_enrollment_description(). '

'); $r->rflush(); # # Determine which problem we are to analyze my $current_problem = &Apache::lonstathelpers::get_target_from_id - ($ENV{'form.problemchoice'}); + ($env{'form.problemchoice'}); # my ($navmap,$prev,$curr,$next) = &Apache::lonstathelpers::get_prev_curr_next($current_problem, '.', 'part_survey', ); - if (exists($ENV{'form.PrevProblem'}) && defined($prev)) { + if (exists($env{'form.PrevProblem'}) && defined($prev)) { $current_problem = $prev; - } elsif (exists($ENV{'form.NextProblem'}) && defined($next)) { + } 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'} = + $env{'form.problemchoice'} = &Apache::lonstathelpers::make_target_id($current_problem); $r->print(''); + $env{'form.problemchoice'}.'" />'); # if (! defined($current_problem->{'resource'})) { $r->print('resource is undefined'); @@ -129,19 +132,22 @@ sub BuildSurveyReportsPage { my $resource = $current_problem->{'resource'}; $r->print('

'.$resource->compTitle.'

'); $r->print('

'.$resource->src.'

'); - if ($ENV{'form.renderprob'} eq 'true') { - $r->print(&Apache::lonstathelpers::render_resource($resource)); + if ($env{'form.renderprob'} eq 'true') { + $r->print('
' + .&Apache::lonstathelpers::render_resource($resource) + .'
' + ); } $r->rflush(); my %Data = &Apache::lonstathelpers::get_problem_data ($resource->src); &compile_student_answers($r,$current_problem,\%Data,\@Students); - if ($ENV{'form.output'} eq 'HTML' || - ! defined($ENV{'form.output'})) { + if ($env{'form.output'} eq 'HTML' || + ! defined($env{'form.output'})) { &make_HTML_report($r,$current_problem,\%Data,\@Students); - } elsif ($ENV{'form.output'} eq 'Excel') { + } elsif ($env{'form.output'} eq 'Excel') { &make_Excel_report($r,$current_problem,\%Data,\@Students); - } elsif ($ENV{'form.output'} eq 'TXT') { + } elsif ($env{'form.output'} eq 'TXT') { &make_text_report($r,$current_problem,\%Data,\@Students); } } @@ -179,9 +185,9 @@ sub SurveyProblemSelector { } } if (! scalar(@SurveyProblems)) { - $Str = '

'. - &mt('There are no survey problems in this course'). - '

'.$/; + $Str = '

'. + &mt('There are no survey problems in this course.'). + '

'.$/; return $Str; } $Str .= ''.$/; @@ -197,18 +203,18 @@ sub SurveyProblemSelector { respid=>undef, resptype=>undef}); my $checked = ''; - if ($ENV{'form.problemchoice'} eq $value) { - $checked = 'checked '; + if ($env{'form.problemchoice'} eq $value) { + $checked = 'checked="checked" '; } - my $link = $problem->{'res'}->src. - '?symb='.&Apache::lonnet::escape($problem->{'res'}->symb); + my $link = $problem->{'res'}->link. + '?symb='.&escape($problem->{'res'}->shown_symb); $Str .= ''. - ''.$/; + ''.&mt('View survey').''.$/; } $Str .= '
'. ''.''. - ''. + ''. (' 'x2). - qq{view}.'
'; return $Str; @@ -249,18 +255,19 @@ sub compile_student_answers { foreach my $response (@responses) { my ($foilid,$option) = map { - &Apache::lonnet::unescape($_); + &unescape($_); } split('=',$response); $data->{'foil_count'}->{$foilid}++; $data->{'foil_responses'}->{$foilid}->{$option}++; } } elsif ($resptype =~ /^(radiobutton)$/) { - my ($foil,$value) = map { &Apache::lonnet::unescape($_); } split('=',$student_response); + my ($foil,$value) = map { &unescape($_); } split('=',$student_response); $value += 1; # explicitly increment it... $data->{'foil_responses'}->{$foil}++; $data->{'foil_values'}->{$value}++; if (! exists($data->{'map'}->{$value})) { $data->{'map'}->{$value} = $foil; + $data->{'map_fv'}->{$foil} = $value; } } else { # Variable stuff (essays, raw numbers, strings) go here @@ -322,16 +329,17 @@ sub make_text_report { } close($file); if($something_has_been_output) { - $r->print('

'. - &mt('Your text file.'). + $r->print('

'. + &mt('Your text file'). '

'."\n"); $r->print(''); } else { - $r->print('

'. - &mt("There is no essay or string response data to output for this survey.").'

'); + $r->print('

' + .&mt('There is no essay or string response data to output for this survey.') + .'

'); } $r->rflush(); return; @@ -357,7 +365,7 @@ sub make_Excel_report { # my $rows_output=0; $worksheet->write($rows_output++,0, - $ENV{'course.'.$ENV{'request.course.id'}.'.description'}, + $env{'course.'.$env{'request.course.id'}.'.description'}, $format->{'h1'}); $rows_output++; # @@ -382,8 +390,8 @@ sub make_Excel_report { my $warned_about_size = 0; foreach my $data (@{$data->{'responses'}}) { if (length($data) > 255 && ! $warned_about_size) { - $r->print('

'. - &mt('[_1]:[_2] responses to [_3] may be too long to fit Excel spreadsheet.', + $r->print('

'. + &mt('[_1]:[_2] responses to [_3] may be too long to fit Excel spreadsheet.', $resource->compTitle, $resource->part_display($partid), $respid). @@ -401,7 +409,7 @@ sub make_Excel_report { $worksheet->write_row($rows_output++,0, \@rowdata,$format->{'h4'}); # - my @foils = sort(keys(%{$data->{'foil_responses'}})); + my @foils = sort(keys(%{$respdata->{'_Foils'}})); foreach my $foilid (@foils) { my $foil_count = $data->{'foil_count'}->{$foilid}; my $foiltext = $respdata->{'_Foils'}->{$foilid}->{'text'}; @@ -429,9 +437,10 @@ sub make_Excel_report { my @rowdata = ('Foil Name','Foil Text','Frequency'); $worksheet->write_row($rows_output++,0, \@rowdata,$format->{'h4'}); - foreach my $value (sort(keys(%{$data->{'foil_values'}}))) { + my @foils = sort(keys(%{$respdata->{'_Foils'}})); + foreach my $foilid (@foils) { undef(@rowdata); - my $foilid = $data->{'map'}->{$value}; + my $value = $data->{'map_fv'}->{$foilid}; push(@rowdata,$respdata->{'_Foils'}->{$foilid}->{'name'}); push(@rowdata,$respdata->{'_Foils'}->{$foilid}->{'text'}); push(@rowdata,$data->{'foil_values'}->{$value}); @@ -442,12 +451,12 @@ sub make_Excel_report { } #response ids } # partids $workbook->close(); - $r->print('

'. + $r->print('

'. &mt('Your Excel spreadsheet.'). '

'."\n"); $r->print(''); $r->rflush(); return; @@ -483,7 +492,8 @@ sub make_HTML_report { $Str .= ''. ''.&mt('Total').''. ''.$data->{'_count'}.''. - ''.&mt('Part [_1], Response [_2]',$partid,$respid).''. + ''.&mt('Part [_1], Response [_2]', + $resource->part_display($partid),$respid).''. ''; if (exists($data->{'responses'}) && ref($data->{'responses'}) eq 'ARRAY') { @@ -500,22 +510,25 @@ sub make_HTML_report { } } elsif (exists($data->{'foil_count'}) && exists($data->{'foil_responses'})) { - $Str.=''. - ''; + $Str.='' + .''; - my @foils = sort(keys(%{$data->{'foil_responses'}})); + &mt('Percent'))).'' + .&Apache::loncommon::end_data_table_header_row(); + my @foils = sort(keys(%{$ProblemData->{$partid.'.'.$respid}->{'_Foils'}})); foreach my $foilid (@foils) { my $prob_data = $ProblemData->{$partid.'.'.$respid}; my $foil_count = $data->{'foil_count'}->{$foilid}; my $foiltext = $prob_data->{'_Foils'}->{$foilid}->{'text'}; my $foilname = $prob_data->{'_Foils'}->{$foilid}->{'name'}; my $rowspan = scalar(@{$prob_data->{'_Options'}}); - my $preamble = ''. + my $preamble = &Apache::loncommon::start_data_table_row(). ''. ''. ''.$/; - $preamble = ''; + ''.&Apache::loncommon::end_data_table_row().$/; + $preamble = &Apache::loncommon::continue_data_table_row(); #&Apache::loncommon::start_data_table_row(); } } - $Str.=$tmp.'
' + .&Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table_header_row(); my $tmp = ''.join('', (&mt('Foil Name'), &mt('Foil Text'), &mt('Option'), &mt('Frequency'), - &mt('Percent'))).'
'. $foilname.''. @@ -528,11 +541,12 @@ sub make_HTML_report { ''.$count.''. sprintf('%.2f',100*$count/$foil_count).'%'. - '
'; + $Str.=$tmp.&Apache::loncommon::end_data_table() + .''; } elsif (exists($data->{'_count'}) && exists($data->{'foil_values'}) && exists($data->{'map'})) { @@ -540,28 +554,35 @@ sub make_HTML_report { my $total = $data->{'_count'}; my $sum = 0; my $tmp; - foreach my $value (sort(keys(%{$data->{'foil_values'}}))) { + my @foils = sort(keys(%{$ProblemData->{$partid.'.'.$respid} + ->{'_Foils'}})); + foreach my $foilid (@foils) { + my $value = $data->{'map_fv'}->{$foilid}; my $count = $data->{'foil_values'}->{$value}; - my $foilid = $data->{'map'}->{$value}; my $foiltext = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'text'}; my $foilname = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'name'}; - $tmp .= ''. + $tmp .= &Apache::loncommon::start_data_table_row(). ''.$foilname.''. ''.$foiltext.''. ''.$count.''. ''. sprintf("%.2f",$count/$total*100).'%'. - ''.$/; + &Apache::loncommon::end_data_table_row().$/; } - $Str .= ''. - ''.&mt('Foil Name').''. - ''.&mt('Text').''. - ''.&mt('Freq').''. - ''.&mt('Percent').''. - ''.$/. - $tmp; + $Str.='' + .'' + .&Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table_header_row() + .''.&mt('Foil Name').'' + .''.&mt('Text').'' + .''.&mt('Frequency').'' + .''.&mt('Percent').'' + .&Apache::loncommon::end_data_table_header_row().$/ + .$tmp + .&Apache::loncommon::end_data_table() + .''; } - $Str.= '
'; + $Str.= ''; $r->print($Str); $r->rflush(); } @@ -591,35 +612,40 @@ sub CreateInterface { ## Environment variable initialization my $Str = ''; my $output_selector = ''.$/; - $Str .= &Apache::lonhtmlcommon::breadcrumbs - (undef,'Student Submission Reports'); + $Str .= &Apache::lonhtmlcommon::breadcrumbs('Student Submission Reports'); $Str .= '

'; - $Str .= ''."\n"; - $Str .= ''; + $Str .= &Apache::loncommon::start_data_table(); + $Str .= &Apache::loncommon::start_data_table_header_row(); $Str .= ''; - $Str .= ''; + $Str .= ''; + $Str .= ''; $Str .= ''; - $Str .= ''; - $Str .= ''."\n"; + $Str .= ''; + $Str .= &Apache::loncommon::end_data_table_header_row(); # - $Str .= ''; # + $Str .= ''; + # $Str .= ''; @@ -628,23 +654,26 @@ sub CreateInterface { # # Render problem checkbox my $prob_checkbox = ''. - &mt('Show problem [_1]',$prob_checkbox).'
'. - ''."\n"; - $Str .= '
'.&mt('Sections').''.&mt('Enrollment Status').''.&mt('Groups').''.&mt('Access Status').''.&mt('Output Format').''.' '.'
'.&mt('Options').'
'."\n"; + $Str .= &Apache::loncommon::start_data_table_row(); + $Str .= ''."\n"; $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5); $Str .= ''."\n"; + $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5); + $Str .= ''; $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5); $Str .= '
'."\n"; - # - $Str .= ''.&mt('Status: [_1]', - ''). - ''.'

'; + $Str .= + '' + .'' + .''; + # + $Str .= &Apache::loncommon::end_data_table_row(); + $Str .= &Apache::loncommon::end_data_table(); + # + $Str .= '

' + .&mt('Status: [_1]', + '') + .'

'; + $Str .= '

'; ## return $Str; }