Annotation of loncom/interface/lonstatistics.pm, revision 1.118

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: #
1.118   ! matthew     3: # $Id: lonstatistics.pm,v 1.117 2005/02/25 23:23:47 matthew Exp $
1.1       albertel    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: # (Navigate problems for statistical reports
1.14      minaeibi   28: #
1.1       albertel   29: ###
                     30: 
1.59      matthew    31: =pod
                     32: 
                     33: =head1 NAME
                     34: 
                     35: lonstatistics
                     36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Main handler for statistics and chart.
                     40: 
                     41: =over 4
                     42: 
                     43: =cut
                     44: 
1.55      minaeibi   45: package Apache::lonstatistics;
1.1       albertel   46: 
1.30      stredwic   47: use strict;
1.1       albertel   48: use Apache::Constants qw(:common :http);
1.61      matthew    49: use vars qw(
                     50:     @FullClasslist 
                     51:     @Students
                     52:     @Sections 
                     53:     @SelectedSections
                     54:     %StudentData
                     55:     @StudentDataOrder
                     56:     @SelectedStudentData
1.94      matthew    57:     $enrollment_status);
1.61      matthew    58: 
1.1       albertel   59: use Apache::lonnet();
                     60: use Apache::lonhomework;
1.12      minaeibi   61: use Apache::loncommon;
1.29      stredwic   62: use Apache::loncoursedata;
                     63: use Apache::lonhtmlcommon;
1.97      matthew    64: use Apache::lonmysql;
                     65: use Apache::lonlocal;
                     66: use Time::HiRes;
                     67: #
                     68: # Statistics Packages
1.61      matthew    69: use Apache::lonproblemanalysis();
1.89      matthew    70: use Apache::lonsubmissiontimeanalysis();
1.94      matthew    71: use Apache::loncorrectproblemplot();
1.61      matthew    72: use Apache::lonproblemstatistics();
                     73: use Apache::lonstudentassessment();
1.49      stredwic   74: use Apache::lonpercentage;
1.97      matthew    75: use Apache::lonstudentsubmissions();
1.104     matthew    76: use Apache::lonsurveyreports();
1.60      matthew    77: 
                     78: #######################################################
                     79: #######################################################
                     80: 
                     81: =pod
                     82: 
                     83: =item Package Variables
                     84: 
                     85: =item @FullClasslist The full classlist
                     86: 
                     87: =item @Students The students we are concerned with for this invocation
                     88: 
                     89: =item @Sections The sections available in this class
                     90: 
                     91: =item $curr_student The student currently being examined
                     92: 
                     93: =item $prev_student The student previous in the classlist
                     94: 
                     95: =item $next_student The student next in the classlist
                     96: 
                     97: =over
                     98: 
                     99: =cut 
                    100: 
                    101: #######################################################
                    102: #######################################################
                    103: #
                    104: # Classlist variables
                    105: #
1.59      matthew   106: my $curr_student;
                    107: my $prev_student;
                    108: my $next_student;
                    109: 
                    110: #######################################################
                    111: #######################################################
                    112: 
                    113: =pod
                    114: 
                    115: =item &clear_classlist_variables()
                    116: 
                    117: undef the following package variables:
                    118: 
                    119: =over
                    120: 
1.60      matthew   121: =item @FullClasslist
                    122: 
                    123: =item @Students
1.59      matthew   124: 
1.60      matthew   125: =item @Sections
1.59      matthew   126: 
1.60      matthew   127: =item @SelectedSections
1.59      matthew   128: 
1.61      matthew   129: =item %StudentData
                    130: 
                    131: =item @StudentDataOrder
                    132: 
                    133: =item @SelectedStudentData
                    134: 
1.60      matthew   135: =item $curr_student
1.59      matthew   136: 
1.60      matthew   137: =item $prev_student
1.59      matthew   138: 
1.60      matthew   139: =item $next_student
1.59      matthew   140: 
                    141: =back
                    142: 
                    143: =cut
                    144: 
                    145: #######################################################
                    146: #######################################################
                    147: sub clear_classlist_variables {
                    148:     undef(@FullClasslist);
                    149:     undef(@Students);
                    150:     undef(@Sections);
1.60      matthew   151:     undef(@SelectedSections);
1.61      matthew   152:     undef(%StudentData);
                    153:     undef(@SelectedStudentData);
1.59      matthew   154:     undef($curr_student);
                    155:     undef($prev_student);
                    156:     undef($next_student);
                    157: }
                    158: 
                    159: #######################################################
                    160: #######################################################
                    161: 
                    162: =pod
                    163: 
                    164: =item &PrepareClasslist()
                    165: 
                    166: Build up the classlist information.  The classlist information is kept in
                    167: the following package variables:
                    168: 
                    169: =over
                    170: 
1.60      matthew   171: =item @FullClasslist
                    172: 
                    173: =item @Students
1.59      matthew   174: 
1.60      matthew   175: =item @Sections
1.59      matthew   176: 
1.60      matthew   177: =item @SelectedSections
1.59      matthew   178: 
1.61      matthew   179: =item %StudentData
                    180: 
                    181: =item @SelectedStudentData
                    182: 
1.60      matthew   183: =item $curr_student
1.59      matthew   184: 
1.60      matthew   185: =item $prev_student
1.59      matthew   186: 
1.60      matthew   187: =item $next_student
1.59      matthew   188: 
                    189: =back
                    190: 
                    191: $curr_student, $prev_student, and $next_student may not be defined, depending
                    192: upon the calling context.
                    193: 
                    194: =cut
                    195: 
                    196: #######################################################
                    197: #######################################################
                    198: sub PrepareClasslist {
                    199:     my %Sections;
                    200:     &clear_classlist_variables();
                    201:     #
                    202:     # Retrieve the classlist
                    203:     my $cid  = $ENV{'request.course.id'};
                    204:     my $cdom = $ENV{'course.'.$cid.'.domain'};
                    205:     my $cnum = $ENV{'course.'.$cid.'.num'};
                    206:     my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cid,
                    207:                                                                   $cdom,$cnum);
1.60      matthew   208:     if (exists($ENV{'form.Section'})) {
1.59      matthew   209:         if (ref($ENV{'form.Section'})) {
1.61      matthew   210:             @SelectedSections = @{$ENV{'form.Section'}};
                    211:         } elsif ($ENV{'form.Section'} !~ /^\s*$/) {
                    212:             @SelectedSections = ($ENV{'form.Section'});
                    213:         }
                    214:     }
                    215:     @SelectedSections = ('all') if (! @SelectedSections);
                    216:     foreach (@SelectedSections) {
                    217:         if ($_ eq 'all') {
                    218:             @SelectedSections = ('all');
1.59      matthew   219:         }
                    220:     }
1.61      matthew   221:     #
1.69      matthew   222:     # Deal with instructors with restricted section access
1.70      matthew   223:     if ($ENV{'request.course.sec'} !~ /^\s*$/) {
1.69      matthew   224:         @SelectedSections = ($ENV{'request.course.sec'});
                    225:     }
                    226:     #
1.61      matthew   227:     # Set up %StudentData
1.108     matthew   228:     @StudentDataOrder = qw/fullname username domain id section status comments/;
1.61      matthew   229:     foreach my $field (@StudentDataOrder) {
1.108     matthew   230:         $StudentData{$field}->{'title'} = &mt($field);
                    231:         $StudentData{$field}->{'base_width'} = length(&mt($field));
1.61      matthew   232:         $StudentData{$field}->{'width'} = 
                    233:                                $StudentData{$field}->{'base_width'};
                    234:     }
1.59      matthew   235:     #
1.68      matthew   236:     # get the status requested
1.94      matthew   237:     $enrollment_status = 'Active';
                    238:     $enrollment_status = $ENV{'form.Status'} if (exists($ENV{'form.Status'}));
1.68      matthew   239:     #
1.59      matthew   240:     # Process the classlist
                    241:     while (my ($student,$student_data) = each (%$classlist)) {
                    242:         my $studenthash = ();
                    243:         for (my $i=0; $i< scalar(@$field_names);$i++) {
1.61      matthew   244:             my $field = $field_names->[$i];
                    245:             # Store the data
                    246:             $studenthash->{$field}=$student_data->[$i];
                    247:             # Keep track of the width of the fields
                    248:             next if (! exists($StudentData{$field}));
1.63      matthew   249:             my $length = length($student_data->[$i]);
1.61      matthew   250:             if ($StudentData{$field}->{'width'} < $length) {
                    251:                 $StudentData{$field}->{'width'} = $length; 
                    252:             }
1.59      matthew   253:         }
                    254:         push (@FullClasslist,$studenthash);
                    255:         #
                    256:         # Build up a list of sections
                    257:         my $section = $studenthash->{'section'};
1.60      matthew   258:         if (! defined($section) || $section =~/^\s*$/ || $section == -1) {
                    259:             $studenthash->{'section'} = 'none';
                    260:             $section = $studenthash->{'section'};
                    261:         }
1.59      matthew   262:         $Sections{$section}++;
                    263:         #
                    264:         # Only put in the list those students we are interested in
1.60      matthew   265:         foreach my $sect (@SelectedSections) {
1.68      matthew   266:             if ( (($sect eq 'all') || 
                    267:                   ($section eq $sect)) &&
1.94      matthew   268:                  (($studenthash->{'status'} eq $enrollment_status) || 
                    269:                   ($enrollment_status eq 'Any')) 
1.68      matthew   270:                  ){
1.60      matthew   271:                 push (@Students,$studenthash);
                    272:                 last;
                    273:             }
1.59      matthew   274:         }
                    275:     }
                    276:     #
                    277:     # Put the consolidated section data in the right place
1.70      matthew   278:     if ($ENV{'request.course.sec'} !~ /^\s*$/) {
1.69      matthew   279:         @Sections = ($ENV{'request.course.sec'});
                    280:     } else {
                    281:         @Sections = sort {$a cmp $b} keys(%Sections);
                    282:         unshift(@Sections,'all'); # Put 'all' at the front of the list
                    283:     }
1.59      matthew   284:     #
                    285:     # Sort the Students
                    286:     my $sortby = 'fullname';
1.60      matthew   287:     $sortby = $ENV{'form.sort'} if (exists($ENV{'form.sort'}));
                    288:     my @TmpStudents = sort { $a->{$sortby} cmp $b->{$sortby} ||
                    289:                              $a->{'fullname'} cmp $b->{'fullname'} } @Students;
                    290:     @Students = @TmpStudents;
1.59      matthew   291:     # 
                    292:     # Now deal with that current student thing....
1.72      matthew   293:     $curr_student = undef;
                    294:     if (exists($ENV{'form.SelectedStudent'})) {
1.59      matthew   295:         my ($current_uname,$current_dom) = 
1.72      matthew   296:             split(':',$ENV{'form.SelectedStudent'});
1.59      matthew   297:         my $i;
                    298:         for ($i = 0; $i<=$#Students; $i++) {
                    299:             next if (($Students[$i]->{'username'} ne $current_uname) || 
                    300:                      ($Students[$i]->{'domain'}   ne $current_dom));
1.60      matthew   301:             $curr_student = $Students[$i];
1.59      matthew   302:             last; # If we get here, we have our student.
                    303:         }
1.72      matthew   304:         if (defined($curr_student)) {
                    305:             if ($i == 0) {
                    306:                 $prev_student = undef;
                    307:             } else {
                    308:                 $prev_student = $Students[$i-1];
                    309:             }
                    310:             if ($i == $#Students) {
                    311:                 $next_student = undef;
                    312:             } else {
                    313:                 $next_student = $Students[$i+1];
                    314:             }
1.59      matthew   315:         }
                    316:     }
1.61      matthew   317:     #
                    318:     if (exists($ENV{'form.StudentData'})) {
                    319:         if (ref($ENV{'form.StudentData'}) eq 'ARRAY') {
                    320:             @SelectedStudentData = @{$ENV{'form.StudentData'}};
                    321:         } else {
                    322:             @SelectedStudentData = ($ENV{'form.StudentData'});
                    323:         }
                    324:     } else {
1.72      matthew   325:         @SelectedStudentData = ('username');
1.61      matthew   326:     }
                    327:     foreach (@SelectedStudentData) {
                    328:         if ($_ eq 'all') {
                    329:             @SelectedStudentData = ('all');
                    330:             last;
                    331:         }
                    332:     }
                    333:     #
                    334:     return;
                    335: }
                    336: 
1.71      matthew   337: 
                    338: #######################################################
                    339: #######################################################
                    340: 
                    341: =pod
                    342: 
                    343: =item get_students
                    344: 
                    345: Returns a list of the selected students
                    346: 
                    347: =cut
                    348: 
                    349: #######################################################
                    350: #######################################################
                    351: sub get_students {
                    352:     if (! @Students) {
                    353:         &PrepareClasslist()
                    354:     }
                    355:     return @Students;
                    356: }
                    357: 
1.61      matthew   358: #######################################################
                    359: #######################################################
                    360: 
                    361: =pod
                    362: 
                    363: =item &current_student()
                    364: 
                    365: Returns a pointer to a hash containing data about the currently
                    366: selected student.
                    367: 
                    368: =cut
                    369: 
                    370: #######################################################
                    371: #######################################################
                    372: sub current_student { 
1.72      matthew   373:     return $curr_student;
1.61      matthew   374: }
                    375: 
                    376: #######################################################
                    377: #######################################################
                    378: 
                    379: =pod
                    380: 
                    381: =item &previous_student()
                    382: 
                    383: Returns a pointer to a hash containing data about the student prior
                    384: in the list of students.  Or something.  
                    385: 
                    386: =cut
                    387: 
                    388: #######################################################
                    389: #######################################################
                    390: sub previous_student { 
1.72      matthew   391:     return $prev_student;
1.59      matthew   392: }
                    393: 
                    394: #######################################################
                    395: #######################################################
1.61      matthew   396: 
                    397: =pod
                    398: 
                    399: =item &next_student()
                    400: 
                    401: Returns a pointer to a hash containing data about the next student
                    402: to be viewed.
                    403: 
                    404: =cut
                    405: 
                    406: #######################################################
                    407: #######################################################
                    408: sub next_student { 
1.72      matthew   409:     return $next_student;
1.61      matthew   410: }
1.60      matthew   411: 
1.61      matthew   412: ##############################################
                    413: ##############################################
                    414: 
                    415: =pod 
                    416: 
                    417: =item &StudentDataSelect($elementname,$status,$numvisible,$selected)
                    418: 
                    419: Returns html for a selection box allowing the user to choose one (or more) 
                    420: of the fields of student data available (fullname, username, id, section, etc)
                    421: 
                    422: =over 4
                    423: 
                    424: =item $elementname The name of the HTML form element
                    425: 
                    426: =item $status 'multiple' or 'single' selection box
                    427: 
                    428: =item $numvisible The number of options to be visible
                    429: 
                    430: =back
1.60      matthew   431: 
                    432: =cut
                    433: 
1.61      matthew   434: ##############################################
                    435: ##############################################
                    436: sub StudentDataSelect {
                    437:     my ($elementname,$status,$numvisible)=@_;
                    438:     if ($numvisible < 1) {
                    439:         return;
                    440:     }
                    441:     #
                    442:     # Build the form element
                    443:     my $Str = "\n";
                    444:     $Str .= '<select name="'.$elementname.'" ';
                    445:     if ($status ne 'single') {
                    446:         $Str .= 'multiple="true" ';
                    447:     }
                    448:     $Str .= 'size="'.$numvisible.'" >'."\n";
                    449:     #
                    450:     # Deal with 'all'
                    451:     $Str .= '    <option value="all" ';
                    452:     foreach (@SelectedStudentData) {
                    453:         if ($_ eq 'all') {
                    454:             $Str .= 'selected ';
                    455:             last;
                    456:         }
                    457:     }
                    458:     $Str .= ">all</option>\n";
                    459:     #
                    460:     # Loop through the student data fields
                    461:     foreach my $item (@StudentDataOrder) {
                    462:         $Str .= '    <option value="'.$item.'" ';
                    463:         foreach (@SelectedStudentData) {
                    464:             if ($item eq $_ ) {
                    465:                 $Str .= 'selected ';
                    466:                 last;
                    467:             }
                    468:         }
                    469:         $Str .= '>'.$item."</option>\n";
                    470:     }
                    471:     $Str .= "</select>\n";
                    472:     return $Str;
1.60      matthew   473: }
                    474: 
1.115     matthew   475: #######################################################
                    476: #######################################################
                    477: 
                    478: =pod
                    479: 
                    480: =item &get_selected_maps($elementname)
                    481: 
                    482: Input: Name of the <select> form element used to specify the maps.
                    483: 
                    484: Returns: Array of symbs of selected maps or the description 'all'.
                    485:    If form.$elementname does not exist, 'all' is returned.
                    486: 
                    487: =cut
                    488: 
                    489: #######################################################
                    490: #######################################################
                    491: sub get_selected_maps {
                    492:     my ($elementname) = @_;
                    493:     my @selected_maps;
                    494:     if (exists($ENV{'form.'.$elementname})) {
                    495:         if (ref($ENV{'form.'.$elementname})) {
                    496:             @selected_maps = @{$ENV{'form.'.$elementname}};
                    497:         } else {
                    498:             @selected_maps = ($ENV{'form.'.$elementname});
                    499:         }
                    500:     } else {
                    501:         @selected_maps = ('all');
                    502:     }
1.118   ! matthew   503:     foreach my $map (@selected_maps) {
        !           504:         if ($map eq 'all') {
        !           505:             @selected_maps = ('all');
        !           506:             last;
        !           507:         }
        !           508:     }
1.115     matthew   509:     return @selected_maps;
                    510: }
                    511: 
                    512: 
                    513: #######################################################
                    514: #######################################################
                    515: 
                    516: =pod
                    517: 
1.116     matthew   518: =item &selected_sequences_with_assessments
1.115     matthew   519: 
                    520: Retrieve the sequences which were selected by the user to show.  
                    521: 
                    522: Input: $mode: scalar.  Either 'selected' or 'all'.  If not specified,
                    523:     'selected' is used.
                    524: 
                    525: Returns: an array containing a navmap object and navmap resources, 
                    526:     or an array containing a scalar with an error message.
                    527: 
                    528: =cut
                    529: 
                    530: #######################################################
                    531: #######################################################
1.116     matthew   532: sub selected_sequences_with_assessments {
1.115     matthew   533:     my ($mode) = @_;
                    534:     $mode = 'selected' if (! defined($mode));
                    535:     my $navmap = Apache::lonnavmaps::navmap->new();
                    536:     if (!defined($navmap)) {
                    537:         return ('Can not open Coursemap');
                    538:     }
                    539:     #
                    540:     my @sequences = $navmap->retrieveResources(undef,
                    541:                                                sub { shift->is_map(); },1,0,1);
                    542:     my @sequences_with_assessments;
                    543:     for my $sequence ($navmap->getById('0.0'), @sequences) {
                    544: 	if ($navmap->hasResource($sequence,sub { shift->is_problem(); }, 0)){
                    545:             push(@sequences_with_assessments,$sequence);
                    546:         }
                    547:     }
                    548:     #
                    549:     my @sequences_to_show;
                    550:     foreach my $sequence (@sequences_with_assessments) {
                    551:         if ($mode eq 'all') {
                    552:             push (@sequences_to_show,$sequence);
                    553:         } elsif ($mode eq 'selected') {
1.116     matthew   554:             foreach my $map_symb (&get_selected_maps('Maps')) {
1.115     matthew   555:                 if ($sequence->symb eq $map_symb || $map_symb eq 'all'){
                    556:                     push (@sequences_to_show,$sequence);
                    557:                     last; # Only put it in once
                    558:                 }
                    559:             }
                    560:         }
                    561: 
                    562:     }
                    563:     return $navmap,@sequences_to_show;
                    564: }
                    565: 
1.60      matthew   566: ##############################################
                    567: ##############################################
                    568: 
                    569: =pod 
                    570: 
1.115     matthew   571: =item &map_select($elementname,$status,$numvisible,$restriction) 
1.60      matthew   572: 
                    573: Returns html for a selection box allowing the user to choose one (or more) 
                    574: of the sequences in the course.  The values of the sequences are the symbs.
                    575: If the top sequence is selected, the value 'top' will result.
                    576: 
                    577: =over 4
                    578: 
                    579: =item $elementname The name of the HTML form element
                    580: 
                    581: =item $status 'multiple' or 'single' selection box
                    582: 
                    583: =item $numvisible The number of options to be visible
                    584: 
                    585: =back
                    586: 
                    587: =cut
                    588: 
                    589: ##############################################
                    590: ##############################################
1.115     matthew   591: sub map_select {
                    592:     my ($elementname,$status,$numvisible)=@_;
1.60      matthew   593:     if ($numvisible < 1) {
                    594:         return;
                    595:     }
                    596:     #
                    597:     # Set up array of selected items
1.115     matthew   598:     my @selected_maps = &get_selected_maps($elementname);
1.60      matthew   599:     #
                    600:     # Build the form element
1.115     matthew   601:     my $form = "\n";
                    602:     $form .= '<select name="'.$elementname.'" ';
1.60      matthew   603:     if ($status ne 'single') {
1.115     matthew   604:         $form .= 'multiple="true" ';
1.60      matthew   605:     }
1.115     matthew   606:     $form .= 'size="'.$numvisible.'" >'."\n";
1.60      matthew   607:     #
1.61      matthew   608:     # Put in option for 'all'
1.115     matthew   609:     $form .= '    <option value="all" ';
1.118   ! matthew   610:     if ($selected_maps[0] eq 'all') {
        !           611:         $form .= 'selected ';
1.61      matthew   612:     }
1.115     matthew   613:     $form .= ">all</option>\n";
1.61      matthew   614:     #
1.60      matthew   615:     # Loop through the sequences
1.117     matthew   616:     my @sequences = &selected_sequences_with_assessments('all');
1.115     matthew   617:     my $navmap;
                    618:     if (!ref($sequences[0])) {
                    619:         return $sequences[0];
                    620:     } else {
                    621:         $navmap = shift(@sequences);
                    622:     }
                    623:     foreach my $seq (@sequences){
                    624:         $form .= '    <option value="'.$seq->symb.'" ';
                    625:         foreach (@selected_maps) {
                    626:             if ($seq->symb eq $_) {
                    627:                 $form .= 'selected ';
1.60      matthew   628:                 last;
                    629:             }
                    630:         }
1.115     matthew   631:         $form .= '>'.$seq->compTitle."</option>\n";
1.60      matthew   632:     }
1.115     matthew   633:     $form .= "</select>\n";
                    634:     return $form;
1.60      matthew   635: }
                    636: 
                    637: ##############################################
                    638: ##############################################
                    639: 
                    640: =pod 
                    641: 
                    642: =item &SectionSelect($elementname,$status,$numvisible) 
                    643: 
                    644: Returns html for a selection box allowing the user to choose one (or more) 
                    645: of the sections in the course.  
                    646: 
1.71      matthew   647: Uses the package variables @Sections and @SelectedSections
1.60      matthew   648: =over 4
                    649: 
                    650: =item $elementname The name of the HTML form element
                    651: 
                    652: =item $status 'multiple' or 'single' selection box
                    653: 
                    654: =item $numvisible The number of options to be visible
                    655: 
                    656: =back
                    657: 
                    658: =cut
                    659: 
                    660: ##############################################
                    661: ##############################################
                    662: sub SectionSelect {
                    663:     my ($elementname,$status,$numvisible)=@_;
                    664:     if ($numvisible < 1) {
                    665:         return;
                    666:     }
                    667:     #
1.71      matthew   668:     # Make sure we have the data we need to continue
                    669:     if (! @Sections) {
                    670:         &PrepareClasslist()
                    671:     }
                    672:     #
1.60      matthew   673:     # Build the form element
                    674:     my $Str = "\n";
                    675:     $Str .= '<select name="'.$elementname.'" ';
                    676:     if ($status ne 'single') {
                    677:         $Str .= 'multiple="true" ';
                    678:     }
                    679:     $Str .= 'size="'.$numvisible.'" >'."\n";
                    680:     #
                    681:     # Loop through the sequences
                    682:     foreach my $s (@Sections) {
                    683:         $Str .= '    <option value="'.$s.'" ';
                    684:         foreach (@SelectedSections) {
1.61      matthew   685:             if ($s eq $_) {
1.60      matthew   686:                 $Str .= 'selected ';
                    687:                 last;
                    688:             }
                    689:         }
                    690:         $Str .= '>'.$s."</option>\n";
                    691:     }
                    692:     $Str .= "</select>\n";
                    693:     return $Str;
1.80      matthew   694: }
                    695: 
1.61      matthew   696: ##################################################
                    697: ##################################################
1.60      matthew   698: sub DisplayClasslist {
                    699:     my ($r)=@_;
1.107     matthew   700:     &Apache::lonhtmlcommon::add_breadcrumb
                    701:         ({text=>'Select One Student'});
1.60      matthew   702:     #
1.105     matthew   703:     # Output some of the standard interface components
                    704:     my $Str;
1.107     matthew   705:     $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Select One Student');
1.105     matthew   706:     $Str .= '<p><table cellspacing="5">'."\n";
                    707:     $Str .= '<tr>';
                    708:     $Str .= '<th align="center"><b>'.&mt('Sections').'</b></th>';
                    709:     $Str .= '<th align="center"><b>'.&mt('Enrollment Status').'</b></th>';
                    710:     $Str .= '</tr>'.$/;
                    711:     $Str .= '<tr>';
                    712:     $Str .= '<td>'.
                    713:         &Apache::lonstatistics::SectionSelect('Section','multiple',5).
                    714:         '</td>';
                    715:     $Str .= '<td>'.
                    716:         &Apache::lonhtmlcommon::StatusOptions(undef,undef,5).
                    717:         '</td>';
                    718:     
                    719:     $Str .= '</tr>'.$/;
                    720:     $Str .= '</table></p>';
                    721:     $Str .= '<input type="submit" name="selectstudent" value="'.
                    722:         &mt('Update Display').'" />';
                    723:     $r->print($Str);
                    724:     $r->rflush();
                    725:     #
                    726:     my @Fields = ('fullname','username','domain','id','section','status');
1.60      matthew   727:     #
1.105     matthew   728:     $Str = '';
1.78      matthew   729:     if (! @Students) {
                    730:         if ($SelectedSections[0] eq 'all') { 
                    731:             if (lc($ENV{'form.Status'}) eq 'any') {
1.106     matthew   732:                 $Str .= '<h2>'.
                    733:                     &mt('There are no students in the course.').
                    734:                     '</h2>';
1.78      matthew   735:             } elsif (lc($ENV{'form.Status'}) eq 'active') {
1.106     matthew   736:                 $Str .= '<h2>'.
                    737:                 &mt('There are no currently enrolled students in the course.').
                    738:                     '</h2>';
1.78      matthew   739:             } elsif (lc($ENV{'form.Status'}) eq 'expired') {
1.106     matthew   740:                 $Str .= '<h2>'.
                    741:                     &mt('There are no previously enrolled students in the course.').
                    742:                         '</h2>';
1.78      matthew   743:             }
                    744:         } else { 
                    745:             my $sections;
                    746:             if (lc($ENV{'form.Status'}) eq 'any') {
1.106     matthew   747:                 $Str .= '<h2>'.
                    748:                     &mt('There are no students in the selected sections.').
                    749:                     '</h2>';
1.78      matthew   750:             } elsif (lc($ENV{'form.Status'}) eq 'active') {
1.106     matthew   751:                 $Str .= '<h2>'.
                    752:                     &mt('There are no currently enrolled students in the selected sections.').
                    753:                     '</h2>';
1.78      matthew   754:             } elsif (lc($ENV{'form.Status'}) eq 'expired') {
1.106     matthew   755:                 $Str .= '<h2>'.
                    756:                     &mt('There are no previously enrolled students in the selected sections.').
                    757:                     '</h2>';
1.78      matthew   758:             }
                    759:         }
                    760:         $Str.= '<a href="/adm/statistics?reportSelected=student_assessment">'.
1.106     matthew   761:             &mt('Click here to return to the chart').'</a>';
1.78      matthew   762:         $r->print($Str);
                    763:         $r->rflush();
                    764:         return;
                    765:     }
                    766: 
1.76      matthew   767:     # "Click" is asinine but it is probably not my place to change the world.
1.78      matthew   768:     $Str .= '<h2>Click on a students name or username to view their chart</h2>';
1.60      matthew   769:     $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
                    770:     $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
                    771:     foreach my $field (@Fields) {
1.101     matthew   772:         $Str .= '<th><a href="/adm/statistics?'.
                    773:             'reportSelected=student_assessment&'.
                    774:             'selectstudent=1&'.
1.106     matthew   775:             'sort='.$field.'">'.&mt($field).
1.60      matthew   776:             '</a></th>';
                    777:     }
                    778:     $Str .= '</tr>'."\n";
                    779:     #
                    780:     my $alternate = 0;
1.65      matthew   781:     foreach my $student (@Students) { # @Students is a package variable
1.60      matthew   782:         my $sname = $student->{'username'}.':'.$student->{'domain'};
                    783:         if($alternate) {
                    784:             $Str .= '<tr bgcolor="#ffffe6">';
                    785:         } else {
                    786:             $Str .= '<tr bgcolor="#ffffc6">';
                    787:         }
                    788:         $alternate = ($alternate + 1) % 2;
                    789:         #
                    790:         foreach my $field (@Fields) {
                    791:             $Str .= '<td>';
1.78      matthew   792:             if ($field eq 'fullname' || $field eq 'username') {
1.60      matthew   793:                 $Str .= '<a href="/adm/statistics?reportSelected=';
1.65      matthew   794:                 $Str .= &Apache::lonnet::escape('student_assessment');
1.72      matthew   795:                 $Str .= '&sort='.&Apache::lonnet::escape($ENV{'form.sort'});
                    796:                 $Str .= '&SelectedStudent=';
1.61      matthew   797:                 $Str .= &Apache::lonnet::escape($sname).'">';
1.60      matthew   798:                 $Str .= $student->{$field}.'&nbsp';
                    799:                 $Str .= '</a>';
1.106     matthew   800:             } elsif ($field eq 'status') {
                    801:                 $Str .= &mt($student->{$field});
1.60      matthew   802:             } else {
                    803:                 $Str .= $student->{$field};
                    804:             }
                    805:             $Str .= '</td>';
                    806:         }
                    807:         $Str .= "</tr>\n";
                    808:     }
                    809:     $Str .= '</table></td></tr></table>'."\n";
                    810:     #
                    811:     $r->print($Str);
                    812:     $r->rflush();
                    813:     #
                    814:     return;
                    815: }
                    816: 
1.65      matthew   817: ##############################################
                    818: ##############################################
1.33      stredwic  819: sub CreateMainMenu {
1.65      matthew   820:     #
1.85      matthew   821:     # Define menu data
                    822:     my @reports = ({ internal_name => 'problem_statistics',
                    823:                      name => &mt('Overall Problem Statistics'),
                    824:                      short_description => 
                    825:     &mt('Student performance statistics on all problems.'),
                    826:                  },
                    827:                    { internal_name => 'problem_analysis',
                    828:                      name => &mt('Detailed Problem Analysis'),
                    829:                      short_description => 
                    830:     &mt('Detailed statistics and graphs of student performance on problems.'),
                    831:                  },
1.89      matthew   832:                    { internal_name => 'submissiontime_analysis',
1.94      matthew   833:                      name => &mt('Submission Time Plots'),
1.89      matthew   834:                      short_description => 
                    835:     &mt('Display and analysis of submission times on assessments.'),
                    836:                  },
1.97      matthew   837:                    { internal_name => 'student_submission_reports',
                    838:                      name => &mt('Student Submission Reports'),
                    839:                      short_description => 
1.111     matthew   840:     &mt('Prepare reports of student submissions.'),
1.97      matthew   841:                  },
1.104     matthew   842:                    { internal_name => 'survey_reports',
                    843:                      name => &mt('Survey Reports'),
                    844:                      short_description => 
                    845:     &mt('Prepare reports on survey results.'),
                    846:                  },
1.94      matthew   847:                    { internal_name => 'correct_problems_plot',
                    848:                      name => &mt('Correct Problems Plot'),
                    849:                      short_description => 
                    850:     &mt('Display a histogram of student performance in the course.'),
                    851:                  },
1.88      matthew   852: #                   { internal_name => 'student_assessment',
                    853: #                     name => &mt('Problem Status Chart'),
                    854: #                     short_description => 
                    855: #    &mt('Brief view of each students performance in course.'),
                    856: #                 },
1.85      matthew   857:                    # 'percentage'  => 'Correct-problems Plot',
                    858:                    # 'activitylog' => 'Activity Log',
                    859:                    );
1.65      matthew   860:     #
1.85      matthew   861:     # Create the menu
                    862:     my $Str;
1.98      matthew   863:     $Str .= '<h2>'.&mt('Please select a report to generate').'</h2>';
1.85      matthew   864:     foreach my $reportdata (@reports) {
1.87      matthew   865:         $Str .='    <h3><a href="/adm/statistics?reportSelected='.
1.85      matthew   866:             $reportdata->{'internal_name'}.'" >'.
1.87      matthew   867:             $reportdata->{'name'}."</a></h3>\n";
                    868:         $Str .= '    '.('&nbsp;'x8).$reportdata->{'short_description'}.
                    869:             "\n";
1.85      matthew   870:     }
                    871:     $Str .="</dl>\n";
1.65      matthew   872:     #
1.33      stredwic  873:     return $Str;
                    874: }
                    875: 
1.65      matthew   876: ##############################################
                    877: ##############################################
1.1       albertel  878: sub handler {
1.31      minaeibi  879:     my $r=shift;
1.65      matthew   880:     my $c = $r->connection();
                    881:     #
                    882:     # Check for overloading
1.51      www       883:     my $loaderror=&Apache::lonnet::overloaderror($r);
                    884:     if ($loaderror) { return $loaderror; }
                    885:     $loaderror=
                    886:        &Apache::lonnet::overloaderror($r,
                    887:          $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
                    888:     if ($loaderror) { return $loaderror; }
1.65      matthew   889:     #
                    890:     # Check for access
1.69      matthew   891:     if (! &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
1.27      stredwic  892:         $ENV{'user.error.msg'}=
1.69      matthew   893:             $r->uri.":vgr:0:0:Cannot view grades for complete course";
                    894:         if (! &Apache::lonnet::allowed('vgr',
                    895:                       $ENV{'request.course.id'}.'/'.$ENV{'request.course.sec'})) {
                    896:             $ENV{'user.error.msg'}=
                    897:                 $r->uri.":vgr:0:0:Cannot view grades with given role";
                    898:             return HTTP_NOT_ACCEPTABLE;
                    899:         }
1.27      stredwic  900:     }
1.65      matthew   901:     #
                    902:     # Send the header
1.92      www       903:     &Apache::loncommon::no_cache($r);
                    904:     &Apache::loncommon::content_type($r,'text/html');
1.27      stredwic  905:     $r->send_http_header;
1.92      www       906:     if ($r->header_only) { return OK; }
1.65      matthew   907:     #
                    908:     # Extract form elements from query string
1.60      matthew   909:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.65      matthew   910:                                             ['sort','reportSelected',
1.72      matthew   911:                                              'SelectedStudent']);
1.65      matthew   912:     #
                    913:     # Give the LON-CAPA page header
1.109     matthew   914:     my $style = <<ENDSTYLE;
                    915: <style type="text/css">
                    916:     ul.sub_studentans { list-style-type: none }
                    917:     ul.sub_correctans { list-style-type: none }
1.110     matthew   918:     tr.even           { background-color: \#CCCCCC }
                    919:     td.essay          { border: 1px solid gray; }
1.109     matthew   920: </style>
                    921: ENDSTYLE
1.114     albertel  922:     my $html=&Apache::lonxml::xmlbegin();
                    923:     $r->print($html.'<head><title>'.
1.96      matthew   924:               &mt('Course Statistics and Charts').
1.109     matthew   925:               '</title>'.$style.
                    926:               "</head>\n".
1.98      matthew   927:               &Apache::loncommon::bodytag('Course Statistics and Charts'));
1.65      matthew   928:     $r->rflush();
1.85      matthew   929:     # 
                    930:     # Either print out a menu for them or send them to a report
1.98      matthew   931:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    932:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/statistics',
1.100     matthew   933:                                             title=>'Statistics',
                    934:                                             text =>'Statistics',
1.98      matthew   935:                                             faq=>139,
                    936:                                             bug=>'Statistics and Charts'});
1.85      matthew   937:     if (! exists($ENV{'form.reportSelected'}) || 
                    938:         $ENV{'form.reportSelected'} eq '') {
1.98      matthew   939:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.99      matthew   940:                   (undef,&mt('Statistics Main Page')).
1.98      matthew   941:                   &CreateMainMenu());
1.85      matthew   942:     } else {
1.65      matthew   943:     #
1.85      matthew   944:         if (! &Apache::lonmysql::verify_sql_connection()) {
                    945:             my $serveradmin = $r->dir_config('lonAdmEMail');
                    946:             $r->print('<h2><font color="Red">'.
                    947:                       &mt('Unable to connect to database!').
                    948:                       '</font></h2>');
                    949:             $r->print('<p>'.
                    950:                       &mt('Please notify the server administrator ').
                    951:                       '<b>'.$serveradmin.'</b></p>');
                    952:             $r->print('<p>'.
                    953:                       &mt('Course Statistics and Charts cannot be '.
                    954:                           'retrieved until the database is restarted.  '.
                    955:                           'Your data is intact but cannot be displayed '.
                    956:                           'at this time.').'</p>');
                    957:             $r->print('</body></html>');
                    958:             return;
                    959:         }
                    960:         #
                    961:         # Clean out the caches
                    962:         if (exists($ENV{'form.ClearCache'})) {
                    963:             &Apache::loncoursedata::delete_caches($ENV{'requres.course.id'});
                    964:         }
                    965:         #
                    966:         # Begin form output
                    967:         $r->print('<form name="Statistics" ');
                    968:         $r->print('method="post" action="/adm/statistics">');
                    969:         $r->rflush();
                    970:         #
                    971:         my $GoToPage = $ENV{'form.reportSelected'};
1.90      matthew   972:         #
1.85      matthew   973:         $r->print('<input type="hidden" name="reportSelected" value="'.
                    974:                   $GoToPage.'">');
                    975:         if($GoToPage eq 'activitylog') {
1.65      matthew   976: #        &Apache::lonproblemstatistics::Activity();
1.85      matthew   977:         } elsif($GoToPage eq 'problem_statistics') {
1.98      matthew   978:             &Apache::lonhtmlcommon::add_breadcrumb
                    979:                 ({href=>'/adm/statistics?reportselected=problem_statistics',
1.100     matthew   980:                   text=>'Overall Problem Statistics'});
1.85      matthew   981:             &Apache::lonproblemstatistics::BuildProblemStatisticsPage($r,$c);
                    982:         } elsif($GoToPage eq 'problem_analysis') {
1.98      matthew   983:             &Apache::lonhtmlcommon::add_breadcrumb
                    984:                 ({href=>'/adm/statistics?reportselected=problem_analysis',
1.100     matthew   985:                   text=>'Detailed Problem Analysis'});
1.85      matthew   986:             &Apache::lonproblemanalysis::BuildProblemAnalysisPage($r,$c);
1.89      matthew   987:         } elsif($GoToPage eq 'submissiontime_analysis') {
1.98      matthew   988:             &Apache::lonhtmlcommon::add_breadcrumb
                    989:                 ({href=>
                    990:                       '/adm/statistics?reportselected=submissiontime_analysis',
1.100     matthew   991:                       text=>'Submission Time Plots'});
1.89      matthew   992:             &Apache::lonsubmissiontimeanalysis::BuildSubmissionTimePage($r,$c);
1.97      matthew   993:         } elsif($GoToPage eq 'student_submission_reports') {
1.98      matthew   994:             &Apache::lonhtmlcommon::add_breadcrumb
                    995:                 ({href=>
                    996:                   '/adm/statistics?reportselected=student_submission_reports',
1.100     matthew   997:                   text=>'Student Submission Reports'});
1.97      matthew   998:             &Apache::lonstudentsubmissions::BuildStudentSubmissionsPage($r,$c);
1.104     matthew   999:         } elsif($GoToPage eq 'survey_reports') {
                   1000:             &Apache::lonhtmlcommon::add_breadcrumb
                   1001:                 ({href=>
                   1002:                   '/adm/statistics?reportselected=survey_reports',
                   1003:                   text=>'Survey Reports'});
                   1004:             &Apache::lonsurveyreports::BuildSurveyReportsPage($r,$c);
1.94      matthew  1005:         } elsif($GoToPage eq 'correct_problems_plot') {
1.98      matthew  1006:             &Apache::lonhtmlcommon::add_breadcrumb
                   1007:                 ({href=>'/adm/statistics?reportselected=correct_problems_plot',
1.100     matthew  1008:                   text=>'Correct Problems Plot'});
1.94      matthew  1009:             &Apache::loncorrectproblemplot::BuildCorrectProblemsPage($r,$c);
1.85      matthew  1010:         } elsif($GoToPage eq 'student_assessment') {
1.98      matthew  1011:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                   1012:             &Apache::lonhtmlcommon::add_breadcrumb
                   1013:                 ({href=>'/adm/statistics?reportselected=student_assessment',
1.100     matthew  1014:                   text=>'Chart'});
1.85      matthew  1015:             &Apache::lonstudentassessment::BuildStudentAssessmentPage($r,$c);
                   1016:         }
                   1017:         #
                   1018:         $r->print("</form>\n");
1.65      matthew  1019:     }
                   1020:     $r->print("</body>\n</html>\n");
                   1021:     $r->rflush();
                   1022:     #
1.27      stredwic 1023:     return OK;
1.1       albertel 1024: }
1.65      matthew  1025: 
1.1       albertel 1026: 1;
1.59      matthew  1027: 
1.65      matthew  1028: #######################################################
                   1029: #######################################################
                   1030: 
1.59      matthew  1031: =pod
                   1032: 
                   1033: =back
                   1034: 
                   1035: =cut
1.65      matthew  1036: 
                   1037: #######################################################
                   1038: #######################################################
1.59      matthew  1039: 
1.1       albertel 1040: __END__
1.31      minaeibi 1041: 

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