File:  [LON-CAPA] / loncom / interface / statistics / lonsurveyreports.pm
Revision 1.10: download - view: text, annotated - select for diffs
Tue Feb 14 15:44:25 2006 UTC (18 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- typo

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

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