File:  [LON-CAPA] / loncom / interface / lonhtmlcommon.pm
Revision 1.2: download - view: text, annotated - select for diffs
Mon Jul 22 21:21:32 2002 UTC (21 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
We are GNU GPL - Yeah!!!

    1: # The LearningOnline Network with CAPA
    2: # a pile of common html routines
    3: #
    4: # $Id: lonhtmlcommon.pm,v 1.2 2002/07/22 21:21:32 www 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)=@_;
   61: 
   62:     my $Str = '';
   63:     $Str = '<select name="'.(($page)?$page:'').'Student">'."\n";
   64: 
   65:     my $selected=0;
   66:     $Str .= '<option';
   67:     if($selectedName eq 'All Students') {
   68:         $Str .= ' selected';
   69:         $selected = 1;
   70:     }
   71:     $Str .= '>All Students</option>'."\n";
   72: 
   73:     foreach (@$students) {
   74: 	$Str .= '<option';
   75: 	if($selectedName eq $_) {
   76:             $Str .= ' selected';
   77:             $selected = 1;
   78:         }
   79:         $Str .= '>';
   80:         $Str .= $cache->{$_.':fullname'};
   81:         $Str .= '</option>'."\n";	     
   82:     }
   83: 
   84:     $Str .= '<option';
   85:     if(!$selected) {
   86:         $Str .= ' selected';
   87:     }
   88:     $Str .= '>No Student Selected</option>'."\n";
   89: 
   90:     $Str .= '</select>'."\n";
   91: 
   92:     return $Str;
   93: }
   94: 
   95: sub StatusOptions {
   96:     my ($status, $formName)=@_;
   97: 
   98:     my $OpSel1 = '';
   99:     my $OpSel2 = '';
  100:     my $OpSel3 = '';
  101: 
  102:     if($status eq 'Any')         { $OpSel3 = ' selected'; }
  103:     elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
  104:     else                         { $OpSel1 = ' selected'; }
  105: 
  106:     my $Str = '';
  107:     $Str .= '<select name="Status"';
  108:     if(defined($formName) && $formName ne '') {
  109:         $Str .= ' onchange="document.'.$formName.'.submit()"';
  110:     }
  111:     $Str .= '>'."\n";
  112:     $Str .= '<option'.$OpSel1.'>Active</option>'."\n";
  113:     $Str .= '<option'.$OpSel2.'>Expired</option>'."\n";
  114:     $Str .= '<option'.$OpSel3.'>Any</option>'."\n";
  115:     $Str .= '</select>'."\n";
  116: }
  117: 
  118: sub Title {
  119:     my ($pageName)=@_;
  120: 
  121:     my $Str = '';
  122: 
  123:     $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
  124:     $Str .= '<body bgcolor="#FFFFFF">'."\n";
  125:     $Str .= '<script>window.focus(); window.width=500;window.height=500;';
  126:     $Str .= '</script>'."\n";
  127:     $Str .= '<table width="100%"><tr><td valign="top">';
  128:     $Str .= '<h1> Course: ';
  129:     $Str .= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
  130:     $Str .= '</h1></td><td align="right">'."\n";
  131:     $Str .= '<img align="right" src=/adm/lonIcons/lonlogos.gif>';
  132:     $Str .= '</td></tr></table>'."\n";
  133: #    $Str .= '<h3>Current Time: '.localtime(time).'</h3><br><br><br>'."\n";
  134: 
  135:     return $Str;
  136: }
  137: 
  138: sub CreateStatisticsMainMenu {
  139:     my ($status, $reports)=@_;
  140: 
  141:     my $Str = '';
  142: 
  143:     $Str .= '<table border="0"><tbody><tr>'."\n";
  144:     $Str .= '<td></td><td></td>'."\n";
  145:     $Str .= '<td align="center"><b>Analysis Reports:</b></td>'."\n";
  146:     $Str .= '<td align="center"><b>Student Status:</b></td></tr>'."\n";
  147:     $Str .= '<tr>'."\n";
  148:     $Str .= '<td align="center"><input type="submit" name="Refresh" ';
  149:     $Str .= 'value="Refresh" /></td>'."\n";
  150:     $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
  151:     $Str .= 'value="Update All Student Data" /></td>'."\n";
  152:     $Str .= '<td align="center">';
  153:     $Str .= '<select name="reportSelected" onchange="document.';
  154:     $Str .= 'Statistics.submit()">'."\n";
  155: 
  156:     foreach (sort(keys(%$reports))) {
  157:         next if($_ eq 'reportSelected');
  158:         $Str .= '<option name="'.$_.'"';
  159:         if($reports->{'reportSelected'} eq $reports->{$_}) {
  160:             $Str .= ' selected=""';
  161:         }
  162:         $Str .= '>'.$reports->{$_}.'</option>'."\n";
  163:     }
  164:     $Str .= '</select></td>'."\n";
  165: 
  166:     $Str .= '<td align="center">';
  167:     $Str .= &StatusOptions($status, 'Statistics');
  168:     $Str .= '</td>'."\n";
  169: 
  170:     $Str .= '</tr></tbody></table>'."\n";
  171:     $Str .= '<hr>'."\n";
  172: 
  173:     return $Str;
  174: }
  175: 
  176: =pod
  177: 
  178: =item &CreateTableHeadings()
  179: 
  180: This function generates the column headings for the chart.
  181: 
  182: =over 4
  183: 
  184: Inputs: $CacheData, $studentInformation, $headings, $spacePadding
  185: 
  186: $CacheData: pointer to a hash tied to the cached data database
  187: 
  188: $studentInformation: a pointer to an array containing the names of the data 
  189: held in a column and is used as part of a key into $CacheData
  190: 
  191: $headings: The names of the headings for the student information
  192: 
  193: $spacePadding: The spaces to go between columns
  194: 
  195: Output: $Str
  196: 
  197: $Str: A formatted string of the table column headings.
  198: 
  199: =back
  200: 
  201: =cut
  202: 
  203: sub CreateStudentInformationHeadings {
  204:     my ($data,$studentInformation,$headings,$displayString)=@_;
  205:     my $Str='';
  206: 
  207:     for(my $index=0; $index<(scalar @$headings); $index++) {
  208: #        if(!&ShouldShowColumn($data, 'ChartHeading'.$index)) {
  209: #            next;
  210: #        }
  211:  	my $data=$headings->[$index];
  212:         my $linkdata=$studentInformation->[$index];
  213:         my $tempString = $displayString;
  214:         $tempString =~ s/LINKDATA/$linkdata/;
  215:         $tempString =~ s/DISPLAYDATA/$data/;
  216:         $Str .= $tempString;
  217:     }
  218: 
  219:     return $Str;
  220: }
  221: 
  222: =pod
  223: 
  224: =item &FormatStudentInformation()
  225: 
  226: This function produces a formatted string of the student's information:
  227: username, domain, section, full name, and PID.
  228: 
  229: =over 4
  230: 
  231: Input: $cache, $name, $studentInformation, $spacePadding
  232: 
  233: $cache: This is a pointer to a hash that is tied to the cached data
  234: 
  235: $name:  The name and domain of the current student in name:domain format
  236: 
  237: $studentInformation: A pointer to an array holding the names used to
  238: 
  239: remove data from the hash.  They represent the name of the data to be removed.
  240: 
  241: $spacePadding: Extra spaces that represent the space between columns
  242: 
  243: Output: $Str
  244: 
  245: $Str: Formatted string.
  246: 
  247: =back
  248: 
  249: =cut
  250: 
  251: sub FormatStudentInformation {
  252:     my ($cache,$name,$studentInformation,$spacePadding)=@_;
  253:     my $Str='';
  254:     my $data;
  255: 
  256:     for(my $index=0; $index<(scalar @$studentInformation); $index++) {
  257:         if(!&ShouldShowColumn($cache, 'ChartHeading'.$index)) {
  258:             next;
  259:         }
  260:         $data=$cache->{$name.':'.$studentInformation->[$index]};
  261: 	$Str .= $data;
  262: 
  263: 	my @dataLength=split(//,$data);
  264: 	my $length=scalar @dataLength;
  265: 	$Str .= (' 'x($cache->{$studentInformation->[$index].'Length'}-
  266:                       $length));
  267: 	$Str .= $spacePadding;
  268:     }
  269: 
  270:     return $Str;
  271: }
  272: 
  273: 1;
  274: __END__

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