File:  [LON-CAPA] / loncom / interface / statistics / lonsurveyreports.pm
Revision 1.14: download - view: text, annotated - select for diffs
Fri Aug 18 15:15:38 2006 UTC (17 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_3_X, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, HEAD
Bug 4954.  Filter title changed from "Enrollment Status" to "Access Status".  Access Status selections in lonhtmlcommon set to:
Currently Has Access
Will Have Future Access
Previously Had Access
Any Access Status
See comment appended to bug 4954 for more information.
Documentation updated to include ability to selectively display students with future access.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: lonsurveyreports.pm,v 1.14 2006/08/18 15:15:38 raeburn Exp $
    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::lonsurveyreports;
   28: 
   29: use strict;
   30: use Apache::lonnet;
   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 Spreadsheet::WriteExcel;
   38: use HTML::Entities();
   39: use Time::Local();
   40: use lib '/home/httpd/lib/perl/';
   41: use LONCAPA;
   42:  
   43: 
   44: my @SubmitButtons = (
   45:                      { name => 'break'},
   46:                      { name => 'PrevProblem',
   47:                        text => 'Previous Survey' },
   48:                      { name => 'NextProblem',
   49:                        text => 'Next Survey' },
   50:                      { name => 'SelectAnother',
   51:                        text => 'Choose a different Survey' },
   52:                      { name => 'break'},
   53:                      { name => 'Generate',
   54:                        text => 'Generate Report'},
   55:                      );
   56: 
   57: sub BuildSurveyReportsPage {
   58:     my ($r,$c)=@_;
   59:     #
   60:     my %Saveable_Parameters = ('Status' => 'scalar',
   61:                                'Section' => 'array',
   62:                                'NumPlots' => 'scalar',
   63:                                );
   64:     &Apache::loncommon::store_course_settings('survey_reports',
   65:                                               \%Saveable_Parameters);
   66:     &Apache::loncommon::restore_course_settings('survey_resports',
   67:                                                 \%Saveable_Parameters);
   68:     #
   69:     &Apache::lonstatistics::PrepareClasslist();
   70:     #
   71:     $r->print(&CreateInterface());
   72:     #
   73:     my @Students = @Apache::lonstatistics::Students;
   74:     #
   75:     if (@Students < 1) {
   76:         $r->print('<h2>There are no students in the sections selected</h2>');
   77:     }
   78:     #
   79:     my @CacheButtonHTML = 
   80:         &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
   81:     $r->rflush();
   82:     #
   83:     if (exists($env{'form.problemchoice'}) && 
   84:         ! exists($env{'form.SelectAnother'})) {
   85:         $r->print('&nbsp;'x3);
   86:         foreach my $button (@SubmitButtons) {
   87:             if ($button->{'name'} eq 'break') {
   88:                 $r->print("<br />\n");
   89:             } else {
   90:                 $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
   91:                           'value="'.&mt($button->{'text'}).'" />');
   92:                 $r->print('&nbsp;'x5);
   93:             }
   94:         }
   95:         foreach my $html (@CacheButtonHTML) {
   96:             $r->print($html.('&nbsp;'x5));
   97:         }
   98:         #
   99:         $r->print('<hr />');
  100:         $r->print('<h4>'.
  101:                   &Apache::lonlocal::locallocaltime(time).','.
  102:                   &Apache::lonstatistics::section_and_enrollment_description().
  103:                   '</h4>');
  104:         $r->rflush();
  105:         #
  106:         # Determine which problem we are to analyze
  107:         my $current_problem = &Apache::lonstathelpers::get_target_from_id
  108:             ($env{'form.problemchoice'});
  109:         #
  110:         my ($navmap,$prev,$curr,$next) = 
  111:             &Apache::lonstathelpers::get_prev_curr_next($current_problem,
  112:                                                         '.',
  113:                                                         'part_survey',
  114:                                                         );
  115:         if (exists($env{'form.PrevProblem'}) && defined($prev)) {
  116:             $current_problem = $prev;
  117:         } elsif (exists($env{'form.NextProblem'}) && defined($next)) {
  118:             $current_problem = $next;
  119:         } else {
  120:             $current_problem = $curr;
  121:         }
  122:         #
  123:         # Store the current problem choice and send it out in the form
  124:         $env{'form.problemchoice'} = 
  125:             &Apache::lonstathelpers::make_target_id($current_problem);
  126:         $r->print('<input type="hidden" name="problemchoice" value="'.
  127:                   $env{'form.problemchoice'}.'" />');
  128:         #
  129:         if (! defined($current_problem->{'resource'})) {
  130:             $r->print('resource is undefined');
  131:         } else {
  132:             my $resource = $current_problem->{'resource'};
  133:             $r->print('<h1>'.$resource->compTitle.'</h1>');
  134:             $r->print('<h3>'.$resource->src.'</h3>');
  135:             if ($env{'form.renderprob'} eq 'true') {
  136:                 $r->print(&Apache::lonstathelpers::render_resource($resource));
  137:             }
  138:             $r->rflush();
  139:             my %Data = &Apache::lonstathelpers::get_problem_data
  140:                 ($resource->src);
  141:             &compile_student_answers($r,$current_problem,\%Data,\@Students);
  142:             if ($env{'form.output'} eq 'HTML' || 
  143:                 ! defined($env{'form.output'})) {
  144:                 &make_HTML_report($r,$current_problem,\%Data,\@Students);
  145:             } elsif ($env{'form.output'} eq 'Excel') {
  146:                 &make_Excel_report($r,$current_problem,\%Data,\@Students);
  147:             } elsif ($env{'form.output'} eq 'TXT') {
  148:                 &make_text_report($r,$current_problem,\%Data,\@Students);
  149:             }
  150:         }
  151:         $r->print('<hr />');
  152:     } else {
  153:         $r->print('<input type="submit" name="Generate" value="'.
  154:                   &mt('Generate Survey Report').'" />');
  155:         $r->print('&nbsp;'x5);
  156:         $r->print('<h3>'.&mt('Please select a Survey to analyze').'</h3>');
  157:         $r->print(&SurveyProblemSelector());
  158:     }
  159: }
  160: 
  161: ##########################################################
  162: ##########################################################
  163: ##
  164: ## SurveyProblemSelector
  165: ##
  166: ##########################################################
  167: ##########################################################
  168: sub SurveyProblemSelector {
  169:     my $Str = '';
  170:     my @SurveyProblems;
  171:     my ($navmap,@sequences) = 
  172:         &Apache::lonstatistics::selected_sequences_with_assessments('all');
  173:     foreach my $seq (@sequences) {
  174:         my @resources = &Apache::lonstathelpers::get_resources($navmap,$seq);
  175:         foreach my $res (@resources) {
  176:             foreach my $part (@{$res->parts}) {
  177:                 if ($res->is_survey($part)) {
  178:                     push(@SurveyProblems,{res=>$res,seq=>$seq,part=>$part});
  179:                     last;
  180:                 }
  181:             }
  182:         }
  183:     }
  184:     if (! scalar(@SurveyProblems)) {
  185:         $Str = '<h1>'.
  186:             &mt('There are no survey problems in this course').
  187:             '</h1>'.$/;
  188:         return $Str;
  189:     }
  190:     $Str .= '<table>'.$/;
  191:     $Str .= '<tr>'.'<td></td>'.
  192:         '<th>'.&mt('Survey').'</th>'.
  193:         '</tr>'.$/;
  194:     my $id;
  195:     foreach my $problem (@SurveyProblems) {
  196:         $id++;
  197:         my $value = &Apache::lonstathelpers::make_target_id
  198:             ({symb=>$problem->{'res'}->symb,
  199:               part=>$problem->{'part'},
  200:               respid=>undef,
  201:               resptype=>undef});
  202:         my $checked = '';
  203:         if ($env{'form.problemchoice'} eq $value) {
  204:             $checked = 'checked ';
  205:         }
  206:         my $link = $problem->{'res'}->src.
  207:             '?symb='.&escape($problem->{'res'}->symb);
  208:         $Str .= '<tr><td>'.
  209:             '<input type="radio" name="problemchoice" id="'.$id.'" '.
  210:                    'value="'.$value.'" '.$checked.'/>'.'</td>'.
  211:             '<td><nobr>'.
  212:             '<label for="'.$id.'">'.$problem->{'res'}->compTitle.'('.$problem->{'seq'}->compTitle.')'.'</label>'.
  213:             ('&nbsp;'x2).
  214:             qq{<a target="preview" href="$link">view</a>}.'</td></tr>'.$/;
  215:     }
  216:     $Str .= '</table>';
  217:     return $Str;
  218: }
  219: 
  220: #########################################################
  221: #########################################################
  222: ##
  223: ## Compile Student Answers
  224: ##
  225: #########################################################
  226: #########################################################
  227: sub compile_student_answers {
  228:     my ($r,$problem,$ProblemData,$Students) = @_;
  229:     my $resource = $problem->{'resource'};
  230:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
  231:         ($r,'Processing Student Submissions',
  232:          'Processing Student Submissions', 
  233:          scalar(@$Students),'inline',undef,'Statistics','stats_status');
  234:     foreach my $student (@$Students) {
  235:         foreach my $partid (@{$resource->parts}) {
  236:             my @response_ids   = $resource->responseIds($partid);
  237:             my @response_types = $resource->responseType($partid);
  238:             for (my $i=0;$i<=$#response_ids;$i++) {
  239:                 my $respid = $response_ids[$i];
  240:                 my $resptype = $response_types[$i];
  241:                 my $results = 
  242:                     &Apache::loncoursedata::get_response_data_by_student
  243:                     ($student,$resource->symb,$respid);
  244:                 next if (! defined($results) || ref($results) ne 'ARRAY' || 
  245:                          ref($results->[0]) ne 'ARRAY');
  246:                 my $student_response = 
  247:                     $results->[0]->[&Apache::loncoursedata::RDs_submission()];
  248:                 $problem->{'responsedata'}->{$partid}->{$respid}->{'_count'}++;
  249:                 my $data = $problem->{'responsedata'}->{$partid}->{$respid};
  250:                 if ($resptype =~ /^(option|match)$/) {
  251:                     my @responses = split('&',$student_response);
  252:                     foreach my $response (@responses) {
  253:                         my ($foilid,$option) = 
  254:                             map { 
  255:                                 &unescape($_); 
  256:                             } split('=',$response);
  257:                         $data->{'foil_count'}->{$foilid}++;
  258:                         $data->{'foil_responses'}->{$foilid}->{$option}++;
  259:                     }
  260:                 } elsif ($resptype =~ /^(radiobutton)$/) {
  261:                     my ($foil,$value) = map { &unescape($_); } split('=',$student_response);
  262:                     $value += 1;  # explicitly increment it...
  263:                     $data->{'foil_responses'}->{$foil}++;
  264:                     $data->{'foil_values'}->{$value}++;
  265:                     if (! exists($data->{'map'}->{$value})) {
  266:                         $data->{'map'}->{$value} = $foil;
  267:                     }
  268:                 } else {
  269:                     # Variable stuff (essays, raw numbers, strings) go here
  270:                     push(@{$data->{'responses'}},$student_response);
  271:                 }
  272:             }
  273:         }
  274:         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
  275:                                                  'last student');
  276:     }
  277:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  278:     return;
  279: }
  280: 
  281: 
  282: #########################################################
  283: #########################################################
  284: ##
  285: ## make_text_report
  286: ##
  287: #########################################################
  288: #########################################################
  289: sub make_text_report {
  290:     my ($r,$problem,$problem_data,$students) = @_;
  291:     my ($file,$filename) = &Apache::loncommon::create_text_file($r,'txt');
  292:     if (! defined($file)) { return '';}
  293:     $r->print('<script>'.
  294:               'window.document.Statistics.stats_status.value="'.
  295:               &mt('Building text document.').
  296:               '";</script>');
  297:     my $resource = $problem->{'resource'};
  298:     print $file $resource->compTitle.$/;
  299:     print $file &Apache::lonstatistics::section_and_enrollment_description().
  300:         ' '.&mt('Generated on [_1]',&Apache::lonlocal::locallocaltime(time)).
  301:         $/;
  302:     my $something_has_been_output = 0;
  303:     foreach my $partid (@{$resource->parts}) {
  304:         my @response_ids   = $resource->responseIds($partid);
  305:         my @response_types = $resource->responseType($partid);
  306:         for (my $i=0;$i<=$#response_ids;$i++) {
  307:             my $respid   = $response_ids[$i];
  308:             my $resptype = $response_types[$i];
  309:             my $data = $problem->{'responsedata'}->{$partid}->{$respid};
  310:             if (exists($data->{'responses'}) && 
  311:                 ref($data->{'responses'}) eq 'ARRAY') {
  312:                 # Essay type response
  313:                 print $file ('-'x40).$/;
  314:                 print $file 
  315:                     $resource->part_display($partid).', '.$respid.':'.$resptype.$/;
  316:                 foreach my $submission (@{$data->{'responses'}}) {
  317:                     print $file ('-'x20).$/;
  318:                     $submission =~ s/(\\r\\n|\\n)/\n/g;
  319:                     $submission =~ s/\\(\'|\"|\`)/$1/g;
  320:                     print $file $submission.$/.$/;
  321:                     $something_has_been_output=1;
  322:                 }
  323:             }
  324:         }
  325:     }
  326:     close($file);
  327:     if($something_has_been_output) {
  328:         $r->print('<p><a href="'.$filename.'">'.
  329:                   &mt('Your text file.').
  330:                   '</a></p>'."\n");
  331:         $r->print('<script>'.
  332:                   'window.document.Statistics.stats_status.value="'.
  333:                &mt('Done compiling text file.  See link below to download.').
  334:                   '";</script>');
  335:     } else {
  336:         $r->print('<h2>'.
  337:                   &mt("There is no essay or string response data to output for this survey.").'</h2>');
  338:     }
  339:     $r->rflush();
  340:     return;
  341: }
  342: 
  343: 
  344: #########################################################
  345: #########################################################
  346: ##
  347: ## make_Excel_report
  348: ##
  349: #########################################################
  350: #########################################################
  351: sub make_Excel_report {
  352:     my ($r,$problem,$problem_data,$students) = @_;
  353:     my ($workbook,$filename,$format) = &Apache::loncommon::create_workbook($r);
  354:     if (! defined($workbook)) { return '';}
  355:     $r->print('<script>'.
  356:               'window.document.Statistics.stats_status.value="'.
  357:               &mt('Building spreadsheet.').
  358:               '";</script>');
  359:     my $worksheet  = $workbook->addworksheet('Survey Reports');
  360:     #
  361:     my $rows_output=0;
  362:     $worksheet->write($rows_output++,0,
  363:                     $env{'course.'.$env{'request.course.id'}.'.description'},
  364:                       $format->{'h1'});
  365:     $rows_output++;
  366:     #
  367:     my $resource = $problem->{'resource'};
  368:     $worksheet->write($rows_output++,0,$resource->compTitle,$format->{'h2'});
  369:     foreach my $partid (@{$resource->parts}) {
  370:         my @response_ids   = $resource->responseIds($partid);
  371:         my @response_types = $resource->responseType($partid);
  372:         for (my $i=0;$i<=$#response_ids;$i++) {
  373:             my $respid   = $response_ids[$i];
  374:             my $resptype = $response_types[$i];
  375:             my $data = $problem->{'responsedata'}->{$partid}->{$respid};
  376:             my $cols_output=0;
  377:             $worksheet->write($rows_output,$cols_output++,
  378:                               $resource->part_display($partid),$format->{'h3'});
  379:             $worksheet->write($rows_output,$cols_output++,
  380:                               'Response '.$respid.', '.$resptype,
  381:                               $format->{'h3'});
  382:             $rows_output++;
  383:             if (exists($data->{'responses'}) && 
  384:                 ref($data->{'responses'}) eq 'ARRAY') {
  385:                 my $warned_about_size = 0;
  386:                 foreach my $data (@{$data->{'responses'}}) {
  387:                     if (length($data) > 255 && ! $warned_about_size) {
  388:                         $r->print('<p>'.
  389:                                   &mt('[_1]:[_2] responses to  [_3] may be too long to fit Excel spreadsheet.',
  390:                                       $resource->compTitle,
  391:                                       $resource->part_display($partid),
  392:                                       $respid).
  393:                                   '</p>');
  394:                         $r->rflush();
  395:                         $warned_about_size=1;
  396:                     }
  397:                     $worksheet->write($rows_output++,0,$data);
  398:                 }
  399:             } elsif (exists($data->{'foil_count'}) && 
  400:                      exists($data->{'foil_responses'})) {
  401:                 my $respdata = $problem_data->{$partid.'.'.$respid};
  402:                 my @rowdata = ('Foil Name','Foil Text','Option',
  403:                                'Frequency');
  404:                 $worksheet->write_row($rows_output++,0,
  405:                                       \@rowdata,$format->{'h4'});
  406:                 #
  407:                 my @foils = sort(keys(%{$data->{'foil_responses'}}));
  408:                 foreach my $foilid (@foils) {
  409:                     my $foil_count = $data->{'foil_count'}->{$foilid};
  410:                     my $foiltext = $respdata->{'_Foils'}->{$foilid}->{'text'};
  411:                     my $foilname = $respdata->{'_Foils'}->{$foilid}->{'name'};
  412:                     $foiltext = &HTML::Entities::decode($foilname);
  413:                     my $cols_output=0;
  414:                     $worksheet->write($rows_output,$cols_output++,$foilname);
  415:                     $worksheet->write($rows_output,$cols_output++,$foiltext);  
  416:                     my $option_start_col = $cols_output;
  417:                     #
  418:                     foreach my $option (sort(@{$respdata->{'_Options'}})){
  419:                         $cols_output= $option_start_col;
  420:                         $worksheet->write($rows_output,$cols_output++,
  421:                                           $option);
  422:                         my $count=
  423:                             $data->{'foil_responses'}->{$foilid}->{$option};
  424:                         $worksheet->write($rows_output,$cols_output++,$count);
  425:                         $rows_output++;
  426:                     }
  427:                 }
  428:             } elsif (exists($data->{'_count'})      && 
  429:                      exists($data->{'foil_values'}) && 
  430:                      exists($data->{'map'})) {
  431:                 my $respdata = $problem_data->{$partid.'.'.$respid};
  432:                 my @rowdata = ('Foil Name','Foil Text','Frequency');
  433:                 $worksheet->write_row($rows_output++,0,
  434:                                       \@rowdata,$format->{'h4'});
  435:                 foreach my $value (sort(keys(%{$data->{'foil_values'}}))) {
  436:                     undef(@rowdata);
  437:                     my $foilid = $data->{'map'}->{$value};
  438:                     push(@rowdata,$respdata->{'_Foils'}->{$foilid}->{'name'});
  439:                     push(@rowdata,$respdata->{'_Foils'}->{$foilid}->{'text'});
  440:                     push(@rowdata,$data->{'foil_values'}->{$value});
  441:                     $worksheet->write_row($rows_output++,0,\@rowdata);
  442:                 }
  443:             }  
  444:             $rows_output++;
  445:         }    #response ids
  446:     }    # partids
  447:     $workbook->close();
  448:     $r->print('<p><a href="'.$filename.'">'.
  449:               &mt('Your Excel spreadsheet.').
  450:               '</a></p>'."\n");
  451:     $r->print('<script>'.
  452:               'window.document.Statistics.stats_status.value="'.
  453:               &mt('Done compiling spreadsheet.  See link below to download.').
  454:               '";</script>');
  455:     $r->rflush();
  456:     return;
  457: }
  458: 
  459: #########################################################
  460: #########################################################
  461: ##
  462: ## make_HTML_report
  463: ##
  464: #########################################################
  465: #########################################################
  466: sub make_HTML_report {
  467:     my ($r,$problem,$ProblemData,$Students) = @_;
  468:     my $resource = $problem->{'resource'};
  469:     foreach my $partid (@{$resource->parts}) {
  470:         my @response_ids   = $resource->responseIds($partid);
  471:         my @response_types = $resource->responseType($partid);
  472:         for (my $i=0;$i<=$#response_ids;$i++) {
  473:             my $Str = '<table>'.$/;
  474:             my $respid   = $response_ids[$i];
  475:             my $resptype = $response_types[$i];
  476:             my $data = $problem->{'responsedata'}->{$partid}->{$respid};
  477:             if (! defined($data) || ref($data) ne 'HASH') {
  478:                 next;
  479:             }
  480:             # Debugging code
  481: #            $Str .= '<tr>'.
  482: #                '<td>'.$partid.'</td>'.
  483: #                '<td>'.$respid.'</td>'.
  484: #                '<td>'.$resptype.'</td>'.
  485: #                '</tr>'.$/;
  486:             $Str .= '<tr>'.
  487:                 '<td><b>'.&mt('Total').'</b></td>'.
  488:                 '<td>'.$data->{'_count'}.'</td>'.
  489:                 '<td>'.&mt('Part [_1], Response [_2]',
  490: 			   $resource->part_display($partid),$respid).'</td>'.
  491:                 '</tr>';
  492:             if (exists($data->{'responses'}) && 
  493:                 ref($data->{'responses'}) eq 'ARRAY') {
  494:                 &randomize_array($data->{'responses'});
  495:                 foreach my $response (@{$data->{'responses'}}) {
  496:                     $response =~ s/\\r\\n/\n/g;
  497:                     $response =~ s/\\'/'/g;
  498:                     $response =~ s/\\"/"/g;
  499:                     $Str .= '<tr>'.
  500:                         '<td colspan="3"><pre>'.
  501:                         &HTML::Entities::encode($response,'<>&').
  502:                         '</pre><hr /></td>'.
  503:                         '</tr>'.$/;
  504:                 }
  505:             } elsif (exists($data->{'foil_count'}) && 
  506:                      exists($data->{'foil_responses'})) {
  507:                 $Str.='<tr><td colspan="3">'.
  508:                     '<table><tr>';
  509:                 my $tmp = '<th>'.join('</th><th>',
  510:                                       (&mt('Foil Name'),
  511:                                        &mt('Foil Text'),
  512:                                        &mt('Option'),
  513:                                        &mt('Frequency'),
  514:                                        &mt('Percent'))).'</th></tr>';
  515:                 my @foils = sort(keys(%{$data->{'foil_responses'}}));
  516:                 foreach my $foilid (@foils) {
  517:                     my $prob_data = $ProblemData->{$partid.'.'.$respid};
  518:                     my $foil_count = $data->{'foil_count'}->{$foilid};
  519:                     my $foiltext = $prob_data->{'_Foils'}->{$foilid}->{'text'};
  520:                     my $foilname = $prob_data->{'_Foils'}->{$foilid}->{'name'};
  521:                     my $rowspan = scalar(@{$prob_data->{'_Options'}});
  522:                     my $preamble = '<tr>'.
  523:                         '<td valign="top" rowspan="'.$rowspan.'">'.
  524:                             $foilname.'</td>'.
  525:                         '<td valign="top" rowspan="'.$rowspan.'">'.
  526:                             $foiltext.'</td>';
  527:                     foreach my $option (sort(@{$prob_data->{'_Options'}})){
  528:                         my $count = 
  529:                             $data->{'foil_responses'}->{$foilid}->{$option};
  530:                         $tmp .= $preamble.
  531:                             '<td>'.$option.'</td>'.
  532:                             '<td align="right">'.$count.'</td>'.
  533:                             '<td align="right">'.
  534:                                 sprintf('%.2f',100*$count/$foil_count).'%'.
  535:                             '</td></tr>'.$/;
  536:                         $preamble = '<tr>';
  537:                     }
  538:                 }
  539:                 $Str.=$tmp.'</table></td></tr>';
  540:             } elsif (exists($data->{'_count'})      && 
  541:                      exists($data->{'foil_values'}) && 
  542:                      exists($data->{'map'})) {
  543:                 # This is an option or radiobutton survey response
  544:                 my $total = $data->{'_count'};
  545:                 my $sum = 0;
  546:                 my $tmp;
  547:                 foreach my $value (sort(keys(%{$data->{'foil_values'}}))) {
  548:                     my $count = $data->{'foil_values'}->{$value};
  549:                     my $foilid = $data->{'map'}->{$value};
  550:                     my $foiltext = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'text'};
  551:                     my $foilname = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'name'};
  552:                     $tmp .= '<tr>'.
  553:                         '<td>'.$foilname.'</td>'.
  554:                         '<td>'.$foiltext.'</td>'.
  555:                         '<td align="right">'.$count.'</td>'.
  556:                         '<td align="right">'.
  557:                             sprintf("%.2f",$count/$total*100).'%</td>'.
  558:                         '</tr>'.$/;
  559:                 }
  560:                 $Str .= '<tr>'.
  561:                     '<th>'.&mt('Foil Name').'</th>'.
  562:                     '<th>'.&mt('Text').'</th>'.
  563:                     '<th>'.&mt('Freq').'</th>'.
  564:                     '<th>'.&mt('Percent').'</th>'.
  565:                     '</tr>'.$/.
  566:                     $tmp;
  567:             }
  568:             $Str.= '</table><hr />';
  569:             $r->print($Str);
  570:             $r->rflush();
  571:         }
  572:     }
  573:     return;
  574: }
  575: 
  576: sub randomize_array {
  577:     # Fisher Yates shuffle, lifted from p 121 of "The Perl Cookbook"
  578:     my ($array) = @_;
  579:     for (my $i=scalar(@$array);--$i;) {
  580:         my $j = int(rand($i+1));
  581:         next if ($i == $j);
  582:         @$array[$i,$j]=@$array[$j,$i];
  583:     }
  584: }
  585: 
  586: #########################################################
  587: #########################################################
  588: ##
  589: ##   Generic Interface Routines
  590: ##
  591: #########################################################
  592: #########################################################
  593: sub CreateInterface {
  594:     ##
  595:     ## Environment variable initialization
  596:     my $Str = '';
  597:     my $output_selector = '<select name="output" size="5">'.$/;
  598:     if (! exists($env{'form.output'})) {
  599:         $env{'form.output'} = 'HTML';
  600:     }
  601:     foreach my $output_format ( {name=>'HTML',text=>&mt("HTML") },
  602:                                 {name=>'Excel',text=>&mt("Excel") },
  603:                                 {name=>'TXT',text=>&mt("Text (essays only)") },
  604:                                 ) {
  605:         $output_selector.='<option value="'.$output_format->{'name'}.'"';
  606:         if ($env{'form.output'} eq $output_format->{'name'}) {
  607:             $output_selector.=' selected';
  608:         }
  609:         $output_selector.= '>'.$output_format->{'text'}.'</option>'.$/;
  610:     }
  611:     $output_selector .= '</select>'.$/;
  612:     $Str .= &Apache::lonhtmlcommon::breadcrumbs('Student Submission Reports');
  613:     $Str .= '<p>';
  614:     $Str .= '<table cellspacing="5">'."\n";
  615:     $Str .= '<tr>';
  616:     $Str .= '<th>'.&mt('Sections').'</th>';
  617:     $Str .= '<th>'.&mt('Groups').'</th>';
  618:     $Str .= '<th>'.&mt('Access Status').'</th>';
  619:     $Str .= '<th>'.&mt('Output Format').'</th>';
  620:     $Str .= '<th>'.'&nbsp;'.'</th>';
  621:     $Str .= '</tr>'."\n";
  622:     #
  623:     $Str .= '<tr><td align="center">'."\n";
  624:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
  625:     $Str .= '</td>';
  626:     #
  627:     $Str .= '<td align="center">'."\n";
  628:     $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
  629:     $Str .= '</td>';
  630:     #
  631:     $Str .= '<td align="center">';
  632:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
  633:     $Str .= '</td>';
  634:     #
  635:     $Str .= '<td align="center">'.$output_selector.'</td>';
  636:     #
  637:     # Render problem checkbox
  638:     my $prob_checkbox = '<input type="checkbox" name="renderprob" ';
  639:     if (exists($env{'form.renderprob'}) && $env{'form.renderprob'} eq 'true') {
  640:         $prob_checkbox .= 'checked ';
  641:     }
  642:     $prob_checkbox .= 'value="true" />';
  643:     $Str .= '<td align="right" valign="top">'.
  644:         '<label><b>'.
  645:         &mt('Show problem [_1]',$prob_checkbox).'</b></label><br />'.
  646:         '<label><b>'.
  647:         '</td>';
  648:     #
  649:     $Str .= '</tr>'."\n";
  650:     $Str .= '</table>'."\n";
  651:     #
  652:     $Str .= '<nobr>'.&mt('Status: [_1]',
  653:                          '<input type="text" '.
  654:                          'name="stats_status" size="60" value="" />').
  655:             '</nobr>'.'</p>';    
  656:     ##
  657:     return $Str;
  658: }
  659: 
  660: 1;
  661: 
  662: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>