Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.5

1.2       www         1: # The LearningOnline Network with CAPA
                      2: # a pile of common html routines
                      3: #
1.5     ! stredwic    4: # $Id: lonhtmlcommon.pm,v 1.4 2002/07/25 21:23:51 stredwic Exp $
1.2       www         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: 
1.1       stredwic   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 {
1.4       stredwic   60:     my ($cache, $students, $selectedName, $page, $formName)=@_;
1.1       stredwic   61: 
                     62:     my $Str = '';
1.4       stredwic   63:     $Str .= '<select name="'.(($page)?$page:'').'Student"';
                     64:     if($formName) {
                     65:         $Str .= ' onchange="document.'.$formName.'.submit()"';
                     66:     }
                     67:     $Str .= '>'."\n";
1.1       stredwic   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';
1.3       stredwic   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';
1.1       stredwic   90:     if(!$selected) {
                     91:         $Str .= ' selected';
                     92:     }
1.3       stredwic   93:     $Str .= '>All Students</option>'."\n";
1.1       stredwic   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: 
1.5     ! stredwic  123: sub MultipleSectionSelect {
        !           124:     my ($sections,$selectedSections)=@_;
        !           125: 
        !           126:     my $Str = '';
        !           127:     $Str .= '<select name="Section" multiple="" size="4">'."\n";
        !           128: 
        !           129:     foreach (@$sections) {
        !           130:         $Str .= '<option';
        !           131:         foreach my $selected (@$selectedSections) {
        !           132:             if($_ eq $selected) {
        !           133:                 $Str .= ' selected=""';
        !           134:             }
        !           135:         }
        !           136:         $Str .= '>'.$_.'</option>'."\n";
        !           137:     }
        !           138:     $Str .= '</select>'."\n";
        !           139: 
        !           140:     return $Str;
        !           141: }
        !           142: 
1.1       stredwic  143: sub Title {
                    144:     my ($pageName)=@_;
                    145: 
                    146:     my $Str = '';
                    147: 
                    148:     $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
                    149:     $Str .= '<body bgcolor="#FFFFFF">'."\n";
                    150:     $Str .= '<script>window.focus(); window.width=500;window.height=500;';
                    151:     $Str .= '</script>'."\n";
                    152:     $Str .= '<table width="100%"><tr><td valign="top">';
                    153:     $Str .= '<h1> Course: ';
                    154:     $Str .= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                    155:     $Str .= '</h1></td><td align="right">'."\n";
                    156:     $Str .= '<img align="right" src=/adm/lonIcons/lonlogos.gif>';
                    157:     $Str .= '</td></tr></table>'."\n";
                    158: 
                    159:     return $Str;
                    160: }
                    161: 
                    162: =pod
                    163: 
                    164: =item &CreateTableHeadings()
                    165: 
                    166: This function generates the column headings for the chart.
                    167: 
                    168: =over 4
                    169: 
1.4       stredwic  170: Inputs: $CacheData, $keyID, $headings, $spacePadding
1.1       stredwic  171: 
                    172: $CacheData: pointer to a hash tied to the cached data database
                    173: 
1.4       stredwic  174: $keyID: a pointer to an array containing the names of the data 
1.1       stredwic  175: held in a column and is used as part of a key into $CacheData
                    176: 
                    177: $headings: The names of the headings for the student information
                    178: 
                    179: $spacePadding: The spaces to go between columns
                    180: 
                    181: Output: $Str
                    182: 
                    183: $Str: A formatted string of the table column headings.
                    184: 
                    185: =back
                    186: 
                    187: =cut
                    188: 
1.4       stredwic  189: sub CreateHeadings {
                    190:     my ($data,$keyID,$headings,$displayString,$format)=@_;
1.1       stredwic  191:     my $Str='';
1.4       stredwic  192:     my $formatting = '';
1.1       stredwic  193: 
                    194:     for(my $index=0; $index<(scalar @$headings); $index++) {
1.4       stredwic  195:  	my $currentHeading=$headings->[$index];
                    196:         if($format eq 'preformatted') {
                    197:             my @dataLength=split(//,$currentHeading);
                    198:             my $length=scalar @dataLength;
                    199:             $formatting = (' 'x
                    200:                       ($data->{$keyID->[$index].':columnWidth'}-$length));
                    201:         }
                    202:         my $linkdata=$keyID->[$index];
                    203: 
1.1       stredwic  204:         my $tempString = $displayString;
                    205:         $tempString =~ s/LINKDATA/$linkdata/;
1.4       stredwic  206:         $tempString =~ s/DISPLAYDATA/$currentHeading/;
                    207:         $tempString =~ s/FORMATTING/$formatting/;
                    208: 
1.1       stredwic  209:         $Str .= $tempString;
                    210:     }
                    211: 
                    212:     return $Str;
                    213: }
                    214: 
                    215: =pod
                    216: 
                    217: =item &FormatStudentInformation()
                    218: 
                    219: This function produces a formatted string of the student's information:
                    220: username, domain, section, full name, and PID.
                    221: 
                    222: =over 4
                    223: 
1.4       stredwic  224: Input: $cache, $name, $keyID, $spacePadding
1.1       stredwic  225: 
                    226: $cache: This is a pointer to a hash that is tied to the cached data
                    227: 
                    228: $name:  The name and domain of the current student in name:domain format
                    229: 
1.4       stredwic  230: $keyID: A pointer to an array holding the names used to
1.1       stredwic  231: 
                    232: remove data from the hash.  They represent the name of the data to be removed.
                    233: 
                    234: $spacePadding: Extra spaces that represent the space between columns
                    235: 
                    236: Output: $Str
                    237: 
                    238: $Str: Formatted string.
                    239: 
                    240: =back
                    241: 
                    242: =cut
                    243: 
                    244: sub FormatStudentInformation {
1.4       stredwic  245:     my ($data,$name,$keyID,$displayString,$format)=@_;
1.1       stredwic  246:     my $Str='';
1.4       stredwic  247:     my $currentColumn;
                    248: 
                    249:     for(my $index=0; $index<(scalar @$keyID); $index++) {
                    250:         $currentColumn=$data->{$name.':'.$keyID->[$index]};
1.1       stredwic  251: 
1.4       stredwic  252:         if($format eq 'preformatted') {
                    253:             my @dataLength=split(//,$currentColumn);
                    254:             my $length=scalar @dataLength;
                    255:             $currentColumn.= (' 'x
                    256:                      ($data->{$keyID->[$index].':columnWidth'}-$length));
1.1       stredwic  257:         }
                    258: 
1.4       stredwic  259:         my $tempString = $displayString;
                    260:         $tempString =~ s/DISPLAYDATA/$currentColumn/;
                    261: 
                    262:         $Str .= $tempString;
1.1       stredwic  263:     }
                    264: 
                    265:     return $Str;
                    266: }
                    267: 
                    268: 1;
                    269: __END__

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