File:  [LON-CAPA] / loncom / interface / statistics / lonstudentassessment.pm
Revision 1.26: download - view: text, annotated - select for diffs
Thu Jan 9 16:37:48 2003 UTC (21 years, 6 months ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
Regarding bug #1049 I revised chart slightly.
if you create a course and, before enrolling students, check CHRT.  The header of
the page comes with this mesage "No students enrolled or Please Select a student"

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonstudentassessment.pm,v 1.26 2003/01/09 16:37:48 minaeibi Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    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
   28: # YEAR=2001
   29: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
   30: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
   31: # YEAR=2002
   32: # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
   33: # 5/12,5/14,5/15,5/19,5/26,7/16,12/24  Behrouz Minaei
   34: #
   35: ###
   36: 
   37: package Apache::lonstudentassessment;
   38: 
   39: use strict;
   40: use Apache::lonhtmlcommon;
   41: use Apache::loncoursedata;
   42: use GDBM_File;
   43: 
   44: #my $jr;
   45: 
   46: sub BuildStudentAssessmentPage {
   47:     my ($cacheDB,$students,$courseID,$formName,$headings,$spacing,
   48:         $studentInformation,$r,$c)=@_;
   49: #    $jr = $r;
   50:     my %cache;
   51:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
   52:         $r->print('<html><body>Unable to tie database.</body></html>');
   53:         return;
   54:     }
   55: 
   56:     # Remove students who don't have the proper section.
   57:     my @sectionsSelected = split(':',$cache{'sectionsSelected'});
   58:     for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
   59:         $studentIndex--) {
   60:         my $value = $cache{$students->[$studentIndex].':section'};
   61:         my $found = 0;
   62:         foreach (@sectionsSelected) {
   63:             if($_ eq 'none') {
   64:                 if($value eq '' || !defined($value) || $value eq ' ') {
   65:                     $found = 1;
   66:                     last;
   67:                 }
   68:             } else {
   69:                 if($value eq $_) {
   70:                     $found = 1;
   71:                     last;
   72:                 }
   73:             }
   74:         }
   75:         if($found == 0) {
   76:             splice(@$students, $studentIndex, 1);
   77:         }
   78:     }
   79:     my ($infoHeadings, $infoKeys, $sequenceHeadings, $sequenceKeys,
   80:         $doNotShow) =
   81:         &ShouldShowColumns(\%cache, $headings, $studentInformation);
   82: 
   83:     my $selectedName = &FindSelectedStudent(\%cache,
   84:                                             $cache{'StudentAssessmentStudent'},
   85:                                             $students);
   86:     $r->print(&CreateInterface(\%cache, $selectedName, $students, $formName,
   87:                                $doNotShow));
   88:     $r->rflush();
   89: 
   90:     my $Str = '';
   91:     if($selectedName eq 'No Student Selected') {
   92: 	$Str .= '<h3><font color=blue>WARNING: ';
   93:         $Str .= 'Please select a student</font></h3>';
   94:         $r->print($Str);
   95:         return;
   96:     }
   97: 
   98:     $r->print(&CreateTableHeadings(\%cache, $spacing, $infoKeys, $infoHeadings,
   99:                                    $sequenceKeys, $sequenceHeadings));
  100:     untie(%cache);
  101:     if($c->aborted()) {  return $Str; }
  102: 
  103:     my $selected=0;
  104:     my $Count = 0;
  105:     $r->print('<pre>'."\n");
  106:     foreach (@$students) {
  107:         if($c->aborted()) { return $Str; }
  108:         next if ($_ ne $selectedName &&
  109:                  $selectedName ne 'All Students');
  110:         $selected = 1;
  111: 
  112:         my @who = ($_);
  113:         next if(&Apache::loncoursedata::DownloadStudentCourseData(\@who, 'true',
  114:                                                              $cacheDB, 'true',
  115:                                                              'false', $courseID,
  116:                                                              $r, $c) ne 'OK');
  117:         next if($c->aborted());
  118: 
  119:         if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  120:             my @before=();
  121:             my @after=();
  122:             my @updateColumn=();
  123:             my $foundUpdate = 0;
  124:             foreach(@$infoKeys) {
  125:                 if(/updateTime/) {
  126:                     $foundUpdate=1;
  127:                     push(@updateColumn, $_);
  128:                     next;
  129:                 }
  130:                 if($foundUpdate) {
  131:                     push(@after, $_);
  132:                 } else {
  133:                     push(@before, $_);
  134:                 }
  135:             }
  136:             $Count++;
  137: 	    my $out = '';
  138: #	    $out .= sprintf("%3d", $Count);
  139:             if($Count % 2) {
  140:                 $out .= '<bgcolor="#FFFFFF">';
  141:             } else {
  142:                 $out .= '<bgcolor="#F0F0F0">';
  143:             }
  144: 	    my $displayString = $out.'DISPLAYDATA'.$spacing;
  145: 	    $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
  146:                                                          \%cache, $_,
  147:                                                          \@before,
  148:                                                          $displayString,
  149:                                                          'preformatted'));
  150: 
  151:             if($foundUpdate) {
  152:                 $displayString = '';
  153:                 $displayString .= '<a href="/adm/statistics?reportSelected=';
  154:                 $displayString .= &Apache::lonnet::escape('Student Assessment');
  155:                 $displayString .= '&download='.$_.'">';
  156:                 $displayString .= 'DISPLAYDATA</a>'.$spacing;
  157:                 $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
  158:                                                                    \%cache, $_,
  159:                                                                    \@updateColumn,
  160:                                                                    $displayString,
  161:                                                                    'preformatted'));
  162:             }
  163: 
  164:             $displayString = 'DISPLAYDATA'.$spacing;
  165:             $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
  166:                                                          \%cache, $_,
  167:                                                          \@after,
  168:                                                          $displayString,
  169:                                                          'preformatted'));
  170:             $r->print(&StudentReport(\%cache, $_, $spacing, $sequenceKeys));
  171:             $r->print("\n");
  172:             $r->rflush();
  173:             untie(%cache);
  174:         }
  175:     }
  176:     $r->print('</pre>'."\n"); 
  177:     if($selected == 0) {
  178: 	$Str .= '<h3><font color=blue>WARNING: ';
  179:         $Str .= 'No Students enrolled OR Please select a student</font></h3>';
  180:         $r->print($Str);
  181:     } else {
  182: 	if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  183: 	    $r->print(&StudentAverageTotal(\%cache, $students, $sequenceKeys));
  184: 	    untie(%cache);
  185: 	}
  186:     }
  187:     return;
  188: }
  189: 
  190: 
  191: 
  192: 
  193: #---- Student Assessment Web Page --------------------------------------------
  194: 
  195: sub CreateInterface {
  196:     my($cache,$selectedName,$students,$formName,$doNotShow)=@_;
  197: 
  198:     my $Str = '';
  199:     $Str .= &CreateLegend();
  200:     $Str .= '<table><tr><td>'."\n";
  201:     $Str .= '<input type="submit" name="PreviousStudent" ';
  202:     $Str .= 'value="Previous Student" />'."\n";
  203:     $Str .= '&nbsp&nbsp&nbsp'."\n";
  204:     $Str .= &Apache::lonhtmlcommon::StudentOptions($cache, $students,
  205:                                                    $selectedName,
  206:                                                    'StudentAssessment',
  207:                                                    $formName);
  208:     $Str .= "\n".'&nbsp&nbsp&nbsp'."\n";
  209:     $Str .= '<input type="submit" name="NextStudent" ';
  210:     $Str .= 'value="Next Student" />'."\n";
  211:     $Str .= '</td></tr></table>'."\n";
  212:     $Str .= '<table cellspacing="5"><tr>'."\n";
  213:     $Str .= '<td align="center"><b>Select Sections</b>'."\n";
  214:     $Str .= '</td>'."\n";
  215:     $Str .= '<td align="center"><b>Select column to view:</b></td>'."\n";
  216:     $Str .= '<td></td></tr>'."\n";
  217: 
  218:     $Str .= '<tr><td align="center">'."\n";
  219:     my @sections = split(':',$cache->{'sectionList'});
  220:     my @selectedSections = split(':',$cache->{'sectionsSelected'});
  221:     $Str .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
  222:                                                           \@selectedSections,
  223:                                                           'Statistics');
  224:     $Str .= '</td><td align="center">';
  225:     $Str .= &CreateColumnSelectionBox($doNotShow);
  226:     $Str .= '</td><td>'."\n";
  227:     $Str .= '<input type="submit" name="DefaultColumns" ';
  228:     $Str .= 'value="Default Column Display" />'."\n";
  229:     $Str .= '</td><td>'."\n";
  230:     $Str .= '<input type="submit" name="displaymode" ';
  231:     if (! exists($ENV{'form.displaymode'}) ||
  232:         lc($ENV{'form.displaymode'}) eq 'display with links') {
  233:         $Str .= 'value="Display without links" />';
  234:         # Set the current value, in case it is undefined
  235:         $ENV{'form.displaymode'} = 'Display with links';
  236:     } else {
  237:         $Str .= 'value="Display with links" />';
  238:     }
  239:     $Str .= "\n";
  240:     $Str .= '</td></tr></table>'."\n";
  241: 
  242:     return $Str;
  243: }
  244: 
  245: sub CreateTableHeadings {
  246:     my($cache,$spacing,$infoKeys,$infoHeadings,$sequenceKeys,
  247:        $sequenceHeadings)=@_;
  248: 
  249: #    my $Str = '&nbsp&nbsp&nbsp&nbsp&nbsp';
  250:     my $Str = '';
  251:     $Str .= '<table border="0" cellpadding="0" cellspacing="0">'."\n";
  252: 
  253:     $Str .= '<tr>'."\n";
  254:     $Str .= &CreateColumnSelectors($infoHeadings, $sequenceHeadings,
  255:                                    $sequenceKeys);
  256:     $Str .= '<td></td></tr>'."\n";
  257: 
  258:     $Str .= '<tr>'."\n";
  259:     my $displayString = '<td align="left"><pre><a href="/adm/statistics?';
  260:     $displayString .= 'sort=LINKDATA">DISPLAYDATA</a>FORMATTING';
  261:     $displayString .= $spacing.'</pre></td>'."\n";
  262:     $Str .= &Apache::lonhtmlcommon::CreateHeadings($cache,
  263:                                                    $infoKeys,
  264:                                                    $infoHeadings,
  265:                                                    $displayString,
  266:                                                    'preformatted');
  267: 
  268:     $displayString  = '<td align="left"><pre>DISPLAYDATAFORMATTING'.$spacing;
  269:     $displayString .= '</pre></td>'."\n";
  270:     $Str .= &Apache::lonhtmlcommon::CreateHeadings($cache,
  271:                                                    $sequenceKeys,
  272:                                                    $sequenceHeadings,
  273:                                                    $displayString,
  274:                                                    'preformatted');
  275: 
  276:     $Str .= '<td><pre>Total Solved/Total Problems</pre></td>';
  277:     $Str .= '</tr></table>'."\n";
  278: 
  279:     return $Str;
  280: }
  281: 
  282: =pod
  283: 
  284: =item &FormatStudentData()
  285: 
  286: First, FormatStudentInformation is called and prefixes the course information.
  287: This function produces a formatted string of the student\'s course information.
  288: Each column of data represents all the problems for a given sequence.  For
  289: valid grade data, a link is created for that problem to a submission record
  290: for that problem.
  291: 
  292: =over 4
  293: 
  294: Input: $name, $studentInformation, $ChartDB
  295: 
  296: $name: The name and domain of the current student in name:domain format
  297: 
  298: $studentInformation: A pointer to an array holding the names used to 
  299: remove data from the hash.  They represent 
  300: the name of the data to be removed.
  301: 
  302: $ChartDB: The name of the cached data database which will be tied to that 
  303: database.
  304: 
  305: Output: $Str
  306: 
  307: $Str: Formatted string that is an entire row of the chart.  It is a
  308: concatenation of student information and student course information.
  309: 
  310: =back
  311: 
  312: =cut
  313: 
  314: sub StudentReport {
  315:     my ($cache,$name,$spacing,$showSequences)=@_;
  316:     my ($username,$domain)=split(':',$name);
  317: 
  318:     my $Str = '';
  319:     if(defined($cache->{$name.':error'})) {
  320:         return $Str;
  321:     }
  322:     if($cache->{$name.':error'} =~ /course/) {
  323:         $Str .= '<b><font color="blue">No course data for student </font>';
  324:         $Str .= '<font color="red">'.$username.'.</font></b><br>';
  325:         return $Str;
  326:     }
  327: 
  328:     my $hasVersion = 'false';
  329:     my $hasFinalData = 'false';
  330:     foreach my $sequence (@$showSequences) {
  331:         my $hasData = 'false';
  332:         my $characterCount=0;
  333:         foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
  334:             my $problem = $cache->{$problemID.':problem'};
  335:             # All grades (except for versionless parts) are displayed as links
  336:             # to their submission record.  Loop through all the parts for the
  337:             # current problem in the correct order and prepare the output links
  338:             foreach(split(/\:/,$cache->{$sequence.':'.$problemID.
  339:                                         ':parts'})) {
  340:                 if($cache->{$name.':'.$problemID.':NoVersion'} eq 'true' ||
  341:                    $cache->{$name.':'.$problemID.':'.$_.':code'} eq ' ' ||
  342:                    $cache->{$name.':'.$problemID.':'.$_.':code'} eq '') {
  343:                     $Str .= ' ';
  344:                     $characterCount++;
  345:                     next;
  346:                 }
  347:                 $hasVersion = 'true';
  348:                 $hasData = 'true';
  349:                 if (lc($ENV{'form.displaymode'}) ne 'display without links') {
  350:                     $Str .= '<a href="/adm/grades?symb=';
  351:                     $Str .= &Apache::lonnet::escape($problem);
  352:                     $Str .= '&student='.$username.'&domain='.$domain;
  353:                     $Str .= '&command=submission">';
  354:                 }
  355:                 my $code = $cache->{$name.':'.$problemID.':'.$_.':code'};
  356:                 my $tries = $cache->{$name.':'.$problemID.':'.$_.':tries'};
  357:                 if($code eq '*' && $tries < 10 && $tries ne '') {
  358:                     $code = $tries;
  359:                 }
  360:                 $Str .= $code;
  361:                 if (lc($ENV{'form.displaymode'}) ne 'display without links') {
  362:                     $Str .= '</a>';
  363:                 }
  364:                 $characterCount++;
  365:             }
  366:         }
  367: 
  368:         # Output the number of correct answers for the current sequence.
  369:         # This part takes up 6 character slots, but is formated right
  370:         # justified.
  371:         my $spacesNeeded=$cache->{$sequence.':columnWidth'}-$characterCount;
  372:         $spacesNeeded -= 3;
  373:         $Str .= (' 'x$spacesNeeded);
  374: 
  375: #        my $outputProblemsCorrect = sprintf("%3d", $cache->{$name.':'.$sequence.
  376: #							    ':problemsCorrect'});
  377: 
  378: 	my $outputProblemsCorrect = sprintf("%2d/%2d", $cache->{$name.':'.$sequence.
  379:                                             ':problemsCorrect'},
  380:                                             $characterCount);
  381:         if($hasData eq 'true') {
  382:             $Str .= '<font color="#007700">'.$outputProblemsCorrect.'</font>';
  383:             $hasFinalData = 'true';
  384:         } else {
  385:             $Str .= '<font color="#007700">     </font>';
  386:         }
  387:         $Str .= $spacing;
  388:     }
  389: 
  390:     # Output the total correct problems over the total number of problems.
  391:     # I don't like this type of formatting, but it is a solution.  Need
  392:     # a way to dynamically determine the space requirements.
  393:     my $outputProblemsSolved = sprintf("%4d", $cache->{$name.':problemsSolved'});
  394:     my $outputTotalProblems  = sprintf("%4d", $cache->{$name.':totalProblems'});
  395:     if($hasFinalData eq 'true') {
  396:         $Str .= '<font color="#000088">'.$outputProblemsSolved.
  397: 	    ' / '.$outputTotalProblems.'</font>';
  398:     } else {
  399:         $Str .= '<font color="#000088">           </font>';
  400:     }
  401: 
  402:     if($hasVersion eq 'false') {
  403:         $Str = '<b><font color="blue">No course data.</font></b>';
  404:     }
  405: 
  406:     return $Str;
  407: }
  408: 
  409: 
  410: sub StudentAverageTotal {
  411:     my ($cache, $students, $sequenceKeys)=@_;
  412:     my $Str = "\n<b>Summary Tables:</b>\n";
  413:     my %Correct = ();
  414:     my $ProblemsSolved = 0;
  415:     my $TotalProblems = 0;
  416:     my $StudentCount = 0;
  417: 
  418:     foreach my $name (@$students) {
  419:         $StudentCount++;
  420:         foreach my $sequence (@$sequenceKeys) {
  421:             $Correct{$sequence} +=
  422: 	       $cache->{$name.':'.$sequence.':problemsCorrect'};
  423:         }
  424: 	$ProblemsSolved += $cache->{$name.':problemsSolved'};
  425:         $TotalProblems += $cache->{$name.':totalProblems'};
  426:     }
  427:     if ($StudentCount) { 
  428:         $ProblemsSolved /= $StudentCount;
  429:         $TotalProblems /= $StudentCount;
  430:     } else {
  431:         $ProblemsSolved = 0;
  432:         $TotalProblems  = 0;
  433:     }
  434:     $Str .= '<table border=2 cellspacing="1">'."\n";
  435:     $Str .= '<tr><td><b>Students Count</b></td><td><b>'.
  436:             $StudentCount.'</b></td></tr>'."\n";
  437:     $Str .= '<tr><td><b>Total Problems</b></td><td><b>'.
  438:             $TotalProblems.'</b></td></tr>'."\n";
  439:     $Str .= '<tr><td><b>Average Correct</b></td><td><b>'.
  440:             $ProblemsSolved.'</b></td></tr>'."\n";
  441:     $Str .= '</table>'."\n";
  442: 
  443:     $Str .= '<table border=2 cellspacing="1">'."\n";
  444:     $Str .= '<tr><th>Title</th><th>Total Problems</th>'.
  445:             '<th>Average Correct</th></tr>'."\n";
  446:     foreach my $S(@$sequenceKeys) {
  447:         my $title=$cache->{$S.':title'};
  448: 	#$Str .= $cache->{$S.':problems'};
  449: 	#my @problems=split(':', $cache->{$S.':problems'});
  450: 	#my $pCount=scalar @problems;
  451: 	my $pCount=MaxSeqPr($cache,@$students[0],$S);
  452:         my $crr;
  453: 	if ($StudentCount) {
  454:             $crr=sprintf( "%.2f", $Correct{$S}/$StudentCount );
  455:         } else {
  456:             $crr="0.00";
  457:         }
  458:         $Str .= '<tr><td>'.$title.
  459:                 '</td><td align=center>'.$pCount.
  460:                 '</td><td align=center>'.$crr.
  461:                 '</td></tr>'."\n";
  462:     }
  463: 
  464:     $Str .= '</table>'."\n";
  465: 
  466:     return $Str;
  467: }
  468: 
  469: 
  470: 
  471: sub MaxSeqPr {
  472:     my ($cache, $name, $sequence)=@_;
  473:     my $prCount=0;
  474:     foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
  475:         my $problem = $cache->{$problemID.':problem'};
  476:         foreach(split(/\:/,$cache->{$sequence.':'.$problemID.':parts'})) {
  477:             if($cache->{$name.':'.$problemID.':NoVersion'} eq 'true' ||
  478:                $cache->{$name.':'.$problemID.':'.$_.':code'} eq ' ' ||
  479:                $cache->{$name.':'.$problemID.':'.$_.':code'} eq '') {
  480:                  $prCount++;
  481:                  next;
  482:             }
  483:             $prCount++;
  484:         }
  485:     }
  486:     return $prCount;
  487: }
  488: 
  489: 
  490: 
  491: 
  492: 
  493: =pod
  494: 
  495: =item &CreateLegend()
  496: 
  497: This function returns a formatted string containing the legend for the
  498: chart.  The legend describes the symbols used to represent grades for
  499: problems.
  500: 
  501: =cut
  502: 
  503: sub CreateLegend {
  504:     my $Str = "<p><pre>".
  505:               "   1  correct by student in 1 try\n".
  506:               "   7  correct by student in 7 tries\n".
  507:               "   *  correct by student in more than 9 tries\n".
  508: 	      "   +  correct by hand grading or override\n".
  509:               "   -  incorrect by override\n".
  510: 	      "   .  incorrect attempted\n".
  511: 	      "   #  ungraded attempted\n".
  512:               "      not attempted (blank field)\n".
  513: 	      "   x  excused".
  514:               "</pre><p>";
  515:     return $Str;
  516: }
  517: 
  518: =pod
  519: 
  520: =item &CreateColumnSelectionBox()
  521: 
  522: If there are columns not being displayed then this selection box is created
  523: with a list of those columns.  When selections are made and the page
  524: refreshed, the columns will be removed from this box and the column is
  525: put back in the chart.  If there is no columns to select, no row is added
  526: to the interface table.
  527: 
  528: =over 4
  529: Input: $CacheData, $headings
  530: 
  531: 
  532: $CacheData: A pointer to a hash tied to the cached data
  533: 
  534: $headings:  An array of the names of the columns for the student information.
  535: They are used for displaying which columns are missing.
  536: 
  537: Output: $notThere
  538: 
  539: $notThere: The string contains one row of a table.  The first column has the
  540: name of the selection box.  The second contains the selection box
  541: which has a size of four.
  542: 
  543: =back
  544: 
  545: =cut
  546: 
  547: sub CreateColumnSelectionBox {
  548:     my ($doNotShow)=@_;
  549: 
  550:     my $notThere = '';
  551:     $notThere .= '<select name="ReselectColumns" size="4" ';
  552:     $notThere .= 'multiple="true">'."\n";
  553: 
  554:     for(my $index=0; $index<$doNotShow->{'count'}; $index++) {
  555:         my $name = $doNotShow->{$index.':name'};
  556:         $notThere .= '<option value="';
  557:         $notThere .= $doNotShow->{$index.':id'}.'">';
  558:         $notThere .= $name.'</option>'."\n";
  559:     }
  560: 
  561:     $notThere .= '</select>';
  562: 
  563:     return $notThere;
  564: }
  565: 
  566: =pod
  567: 
  568: =item &CreateColumnSelectors()
  569: 
  570: This function generates the checkboxes above the column headings.  The
  571: column will be removed if the checkbox is unchecked.
  572: 
  573: =over 4
  574: 
  575: Input: $CacheData, $headings
  576: 
  577: $CacheData: A pointer to a hash tied to the cached data
  578: 
  579: $headings:  An array of the names of the columns for the student 
  580: information.  They are used to know what are the student information columns
  581: 
  582: Output: $present
  583: 
  584: $present: The string contains the first row of a table.  Each column contains
  585: a checkbox which is left justified.  Currently left justification is used
  586: for consistency of location over the column in which it presides.
  587: 
  588: =back
  589: 
  590: =cut
  591: 
  592: sub CreateColumnSelectors {
  593:     my ($infoHeadings, $sequenceHeadings, $sequenceKeys)=@_;
  594: 
  595:     my $present = '';
  596:     for(my $index=0; $index<(scalar @$infoHeadings); $index++) {
  597:         $present .= '<td align="left">';
  598:         $present .= '<input type="checkbox" checked="on" ';
  599:         $present .= 'name="HeadingColumn'.$infoHeadings->[$index].'" />';
  600:         $present .= '</td>'."\n";
  601:     }
  602: 
  603:     for(my $index=0; $index<(scalar @$sequenceHeadings); $index++) {
  604:         $present .= '<td align="left">';
  605:         $present .= '<input type="checkbox" checked="on" ';
  606:         $present .= 'name="SequenceColumn'.$sequenceKeys->[$index].'" />';
  607:         $present .= '</td>'."\n";
  608:     }
  609: 
  610:     return $present;
  611: }
  612: 
  613: #---- END Student Assessment Web Page ----------------------------------------
  614: 
  615: #---- Student Assessment Worker Functions ------------------------------------
  616: 
  617: sub FindSelectedStudent {
  618:     my($cache, $selectedName, $students)=@_;
  619: 
  620:     if($selectedName eq 'All Students' ||
  621:        $selectedName eq 'No Student Selected') {
  622:         return $selectedName;
  623:     }
  624: 
  625:     for(my $index=0; $index<(scalar @$students); $index++) {
  626:         my $fullname = $cache->{$students->[$index].':fullname'};
  627:         if($fullname eq $selectedName) {
  628:             if($cache->{'StudentAssessmentMove'} eq 'next') {
  629:                 if($index == ((scalar @$students) - 1)) {
  630:                     $selectedName = $students->[0];
  631:                     return $selectedName;
  632:                 } else {
  633:                     $selectedName = $students->[$index+1];
  634:                     return $selectedName;
  635:                 }
  636:             } elsif($cache->{'StudentAssessmentMove'} eq 'previous') {
  637:                 if($index == 0) {
  638:                     $selectedName = $students->[-1];
  639:                     return $selectedName;
  640:                 } else {
  641:                     $selectedName = $students->[$index-1];
  642:                     return $selectedName;
  643:                 }
  644:             } else {
  645:                 $selectedName = $students->[$index];
  646:                 return $selectedName;
  647:             }
  648:             last;
  649:         }
  650:     }
  651: 
  652:     return 'No Student Selected';
  653: }
  654: 
  655: =pod
  656: 
  657: =item &ShouldShowColumn()
  658: 
  659: Determine if a specified column should be shown on the chart.
  660: 
  661: =over 4
  662: 
  663: Input: $cache, $test
  664: 
  665: $cache: A pointer to the hash tied to the cached data
  666: 
  667: $test: The form name of the column (heading.$headingIndex) or 
  668: (sequence.$sequenceIndex)
  669: 
  670: Output: 0 (false), 1 (true)
  671: 
  672: =back
  673: 
  674: =cut
  675: 
  676: sub ShouldShowColumns {
  677:     my ($cache,$headings,$cacheKey)=@_;
  678: 
  679:     my @infoKeys=();
  680:     my @infoHeadings=();
  681: 
  682:     my @sequenceKeys=();
  683:     my @sequenceHeadings=();
  684: 
  685:     my %doNotShow;
  686: 
  687:     my $index;
  688:     my $count = 0;
  689:     my $check = '';
  690:     for($index=0; $index < scalar @$headings; $index++) {
  691:         $check = 'HeadingColumn'.$headings->[$index];
  692:         if($cache->{'HeadingsFound'} =~ /$check/) {
  693:             push(@infoHeadings, $headings->[$index]);
  694:             push(@infoKeys, $cacheKey->[$index]);
  695:         } else {
  696:             $doNotShow{$count.':name'} = $headings->[$index];
  697:             $doNotShow{$count.':id'} = 'HeadingColumn'.$headings->[$index];
  698:             $count++;
  699:         }
  700:     }
  701: 
  702:     foreach my $sequence (split(/\:/,$cache->{'orderedSequences'})) {
  703:         $check = 'SequenceColumn'.$sequence;
  704:         if($cache->{'SequencesFound'} eq 'All Sequences' ||
  705:            $cache->{'SequencesFound'} =~ /$check/) {
  706:             push(@sequenceHeadings, $cache->{$sequence.':title'});
  707:             push(@sequenceKeys, $sequence);
  708:         } else {
  709:             $doNotShow{$count.':name'} = $cache->{$sequence.':title'};
  710:             $doNotShow{$count.':id'} = 'SequenceColumn'.$sequence;
  711:             $count++;
  712:         }
  713:     }
  714: 
  715:     $doNotShow{'count'} = $count;
  716: 
  717:     return (\@infoHeadings, \@infoKeys, \@sequenceHeadings,
  718:             \@sequenceKeys, \%doNotShow);
  719: }
  720: 
  721: #---- END Student Assessment Worker Functions --------------------------------
  722: 
  723: 1;
  724: __END__

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