File:  [LON-CAPA] / loncom / interface / statistics / lonstudentassessment.pm
Revision 1.19: download - view: text, annotated - select for diffs
Fri Dec 6 21:11:48 2002 UTC (21 years, 7 months ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
cleaning the code.

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

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