File:  [LON-CAPA] / loncom / interface / lonhtmlcommon.pm
Revision 1.4: download - view: text, annotated - select for diffs
Thu Jul 25 21:23:51 2002 UTC (21 years, 10 months ago) by stredwic
Branches: MAIN
CVS tags: HEAD
Updating lonstudentassessment to add in features of lonchart.  Now the
data display is like lonchart with formatted columns of data.  The next
step will be to add in the column removal check boxes and a multiselect
box for sections.

    1: # The LearningOnline Network with CAPA
    2: # a pile of common html routines
    3: #
    4: # $Id: lonhtmlcommon.pm,v 1.4 2002/07/25 21:23:51 stredwic 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: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonhtmlcommon;
   30: 
   31: use strict;
   32: 
   33: sub MapOptions {
   34:     my ($data, $page)=@_;
   35:     my $Str = '';
   36:     $Str .= '<select name="';
   37:     $Str .= (($page)?$page:'').'Map">'."\n";
   38: 
   39:     my $selected = 0;
   40:     foreach my $sequence (split(':',$data->{'orderedSequences'})) {
   41: 	$Str .= '<option';
   42:         if($data->{$page.'Map'} eq $data->{$sequence.':title'}) {
   43:             $Str .= ' selected';
   44:             $selected = 1;
   45:         }
   46: 	$Str .= '>'.$data->{$sequence.':title'}.'</option>'."\n";	     
   47:     }
   48:     $Str .= '<option';
   49:     if(!$selected) {
   50:         $Str .= ' selected';
   51:     }
   52:     $Str .= '>All Maps</option>'."\n";
   53: 
   54:     $Str .= '</select>'."\n";
   55: 
   56:     return $Str;
   57: }
   58: 
   59: sub StudentOptions {
   60:     my ($cache, $students, $selectedName, $page, $formName)=@_;
   61: 
   62:     my $Str = '';
   63:     $Str .= '<select name="'.(($page)?$page:'').'Student"';
   64:     if($formName) {
   65:         $Str .= ' onchange="document.'.$formName.'.submit()"';
   66:     }
   67:     $Str .= '>'."\n";
   68: 
   69:     my $selected=0;
   70: 
   71:     foreach (@$students) {
   72: 	$Str .= '<option';
   73: 	if($selectedName eq $_) {
   74:             $Str .= ' selected';
   75:             $selected = 1;
   76:         }
   77:         $Str .= '>';
   78:         $Str .= $cache->{$_.':fullname'};
   79:         $Str .= '</option>'."\n";	     
   80:     }
   81: 
   82:     $Str .= '<option';
   83:     if($selectedName eq 'No Student Selected') {
   84:         $Str .= ' selected';
   85:         $selected = 1;
   86:     }
   87:     $Str .= '>No Student Selected</option>'."\n";
   88: 
   89:     $Str .= '<option';
   90:     if(!$selected) {
   91:         $Str .= ' selected';
   92:     }
   93:     $Str .= '>All Students</option>'."\n";
   94: 
   95:     $Str .= '</select>'."\n";
   96: 
   97:     return $Str;
   98: }
   99: 
  100: sub StatusOptions {
  101:     my ($status, $formName)=@_;
  102: 
  103:     my $OpSel1 = '';
  104:     my $OpSel2 = '';
  105:     my $OpSel3 = '';
  106: 
  107:     if($status eq 'Any')         { $OpSel3 = ' selected'; }
  108:     elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
  109:     else                         { $OpSel1 = ' selected'; }
  110: 
  111:     my $Str = '';
  112:     $Str .= '<select name="Status"';
  113:     if(defined($formName) && $formName ne '') {
  114:         $Str .= ' onchange="document.'.$formName.'.submit()"';
  115:     }
  116:     $Str .= '>'."\n";
  117:     $Str .= '<option'.$OpSel1.'>Active</option>'."\n";
  118:     $Str .= '<option'.$OpSel2.'>Expired</option>'."\n";
  119:     $Str .= '<option'.$OpSel3.'>Any</option>'."\n";
  120:     $Str .= '</select>'."\n";
  121: }
  122: 
  123: sub Title {
  124:     my ($pageName)=@_;
  125: 
  126:     my $Str = '';
  127: 
  128:     $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
  129:     $Str .= '<body bgcolor="#FFFFFF">'."\n";
  130:     $Str .= '<script>window.focus(); window.width=500;window.height=500;';
  131:     $Str .= '</script>'."\n";
  132:     $Str .= '<table width="100%"><tr><td valign="top">';
  133:     $Str .= '<h1> Course: ';
  134:     $Str .= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
  135:     $Str .= '</h1></td><td align="right">'."\n";
  136:     $Str .= '<img align="right" src=/adm/lonIcons/lonlogos.gif>';
  137:     $Str .= '</td></tr></table>'."\n";
  138: #    $Str .= '<h3>Current Time: '.localtime(time).'</h3><br><br><br>'."\n";
  139: 
  140:     return $Str;
  141: }
  142: 
  143: sub CreateStatisticsMainMenu {
  144:     my ($status, $reports)=@_;
  145: 
  146:     my $Str = '';
  147: 
  148:     $Str .= '<table border="0"><tbody><tr>'."\n";
  149:     $Str .= '<td></td><td></td>'."\n";
  150:     $Str .= '<td align="center"><b>Analysis Reports:</b></td>'."\n";
  151:     $Str .= '<td align="center"><b>Student Status:</b></td></tr>'."\n";
  152:     $Str .= '<tr>'."\n";
  153:     $Str .= '<td align="center"><input type="submit" name="Refresh" ';
  154:     $Str .= 'value="Refresh" /></td>'."\n";
  155:     $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
  156:     $Str .= 'value="Update All Student Data" /></td>'."\n";
  157:     $Str .= '<td align="center">';
  158:     $Str .= '<select name="reportSelected" onchange="document.';
  159:     $Str .= 'Statistics.submit()">'."\n";
  160: 
  161:     foreach (sort(keys(%$reports))) {
  162:         next if($_ eq 'reportSelected');
  163:         $Str .= '<option name="'.$_.'"';
  164:         if($reports->{'reportSelected'} eq $reports->{$_}) {
  165:             $Str .= ' selected=""';
  166:         }
  167:         $Str .= '>'.$reports->{$_}.'</option>'."\n";
  168:     }
  169:     $Str .= '</select></td>'."\n";
  170: 
  171:     $Str .= '<td align="center">';
  172:     $Str .= &StatusOptions($status, 'Statistics');
  173:     $Str .= '</td>'."\n";
  174: 
  175:     $Str .= '</tr></tbody></table>'."\n";
  176:     $Str .= '<hr>'."\n";
  177: 
  178:     return $Str;
  179: }
  180: 
  181: =pod
  182: 
  183: =item &CreateTableHeadings()
  184: 
  185: This function generates the column headings for the chart.
  186: 
  187: =over 4
  188: 
  189: Inputs: $CacheData, $keyID, $headings, $spacePadding
  190: 
  191: $CacheData: pointer to a hash tied to the cached data database
  192: 
  193: $keyID: a pointer to an array containing the names of the data 
  194: held in a column and is used as part of a key into $CacheData
  195: 
  196: $headings: The names of the headings for the student information
  197: 
  198: $spacePadding: The spaces to go between columns
  199: 
  200: Output: $Str
  201: 
  202: $Str: A formatted string of the table column headings.
  203: 
  204: =back
  205: 
  206: =cut
  207: 
  208: sub CreateHeadings {
  209:     my ($data,$keyID,$headings,$displayString,$format)=@_;
  210:     my $Str='';
  211:     my $formatting = '';
  212: 
  213:     for(my $index=0; $index<(scalar @$headings); $index++) {
  214:  	my $currentHeading=$headings->[$index];
  215:         if($format eq 'preformatted') {
  216:             my @dataLength=split(//,$currentHeading);
  217:             my $length=scalar @dataLength;
  218:             $formatting = (' 'x
  219:                       ($data->{$keyID->[$index].':columnWidth'}-$length));
  220:         }
  221:         my $linkdata=$keyID->[$index];
  222: 
  223:         my $tempString = $displayString;
  224:         $tempString =~ s/LINKDATA/$linkdata/;
  225:         $tempString =~ s/DISPLAYDATA/$currentHeading/;
  226:         $tempString =~ s/FORMATTING/$formatting/;
  227: 
  228:         $Str .= $tempString;
  229:     }
  230: 
  231:     return $Str;
  232: }
  233: 
  234: =pod
  235: 
  236: =item &FormatStudentInformation()
  237: 
  238: This function produces a formatted string of the student's information:
  239: username, domain, section, full name, and PID.
  240: 
  241: =over 4
  242: 
  243: Input: $cache, $name, $keyID, $spacePadding
  244: 
  245: $cache: This is a pointer to a hash that is tied to the cached data
  246: 
  247: $name:  The name and domain of the current student in name:domain format
  248: 
  249: $keyID: A pointer to an array holding the names used to
  250: 
  251: remove data from the hash.  They represent the name of the data to be removed.
  252: 
  253: $spacePadding: Extra spaces that represent the space between columns
  254: 
  255: Output: $Str
  256: 
  257: $Str: Formatted string.
  258: 
  259: =back
  260: 
  261: =cut
  262: 
  263: sub FormatStudentInformation {
  264:     my ($data,$name,$keyID,$displayString,$format)=@_;
  265:     my $Str='';
  266:     my $currentColumn;
  267: 
  268:     for(my $index=0; $index<(scalar @$keyID); $index++) {
  269:         $currentColumn=$data->{$name.':'.$keyID->[$index]};
  270: 
  271:         if($format eq 'preformatted') {
  272:             my @dataLength=split(//,$currentColumn);
  273:             my $length=scalar @dataLength;
  274:             $currentColumn.= (' 'x
  275:                      ($data->{$keyID->[$index].':columnWidth'}-$length));
  276:         }
  277: 
  278:         my $tempString = $displayString;
  279:         $tempString =~ s/DISPLAYDATA/$currentColumn/;
  280: 
  281:         $Str .= $tempString;
  282:     }
  283: 
  284:     return $Str;
  285: }
  286: 
  287: 1;
  288: __END__

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