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

1.2       www         1: # The LearningOnline Network with CAPA
                      2: # a pile of common html routines
                      3: #
1.6     ! stredwic    4: # $Id: lonhtmlcommon.pm,v 1.5 2002/07/26 16:22:09 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: 
1.6     ! stredwic   33: sub AscendOrderOptions {
        !            34:     my ($order, $page, $formName)=@_;
        !            35: 
        !            36:     my $OpSel1 = '';
        !            37:     my $OpSel2 = '';
        !            38: 
        !            39:     if($order eq 'Ascending') {
        !            40:         $OpSel1 = ' selected';
        !            41:     } else {
        !            42:         $OpSel2 = ' selected';
        !            43:     }
        !            44: 
        !            45:     my $Str = '';
        !            46:     $Str .= '<select name="'.(($page)?$page:'').'Ascend"';
        !            47:     if($formName) {
        !            48:         $Str .= ' onchange="document.'.$formName.'.submit()"';
        !            49:     }
        !            50:     $Str .= '>'."\n";
        !            51:     $Str .= '<option'.$OpSel1.'>Ascending</option>'."\n".
        !            52: 	    '<option'.$OpSel2.'>Descending</option>'."\n";
        !            53:     $Str .= '</select>'."\n";
        !            54: 
        !            55:     return $Str;
        !            56: }
        !            57: 
1.1       stredwic   58: sub MapOptions {
1.6     ! stredwic   59:     my ($data, $page, $formName)=@_;
1.1       stredwic   60:     my $Str = '';
                     61:     $Str .= '<select name="';
1.6     ! stredwic   62:     $Str .= (($page)?$page:'').'Maps"';
        !            63:     if($formName) {
        !            64:         $Str .= ' onchange="document.'.$formName.'.submit()"';
        !            65:     }
        !            66:     $Str .= '>'."\n";
1.1       stredwic   67: 
                     68:     my $selected = 0;
                     69:     foreach my $sequence (split(':',$data->{'orderedSequences'})) {
                     70: 	$Str .= '<option';
                     71:         if($data->{$page.'Map'} eq $data->{$sequence.':title'}) {
                     72:             $Str .= ' selected';
                     73:             $selected = 1;
                     74:         }
                     75: 	$Str .= '>'.$data->{$sequence.':title'}.'</option>'."\n";	     
                     76:     }
                     77:     $Str .= '<option';
                     78:     if(!$selected) {
                     79:         $Str .= ' selected';
                     80:     }
                     81:     $Str .= '>All Maps</option>'."\n";
                     82: 
                     83:     $Str .= '</select>'."\n";
                     84: 
                     85:     return $Str;
                     86: }
                     87: 
                     88: sub StudentOptions {
1.4       stredwic   89:     my ($cache, $students, $selectedName, $page, $formName)=@_;
1.1       stredwic   90: 
                     91:     my $Str = '';
1.4       stredwic   92:     $Str .= '<select name="'.(($page)?$page:'').'Student"';
                     93:     if($formName) {
                     94:         $Str .= ' onchange="document.'.$formName.'.submit()"';
                     95:     }
                     96:     $Str .= '>'."\n";
1.1       stredwic   97: 
                     98:     my $selected=0;
                     99: 
                    100:     foreach (@$students) {
                    101: 	$Str .= '<option';
                    102: 	if($selectedName eq $_) {
                    103:             $Str .= ' selected';
                    104:             $selected = 1;
                    105:         }
                    106:         $Str .= '>';
                    107:         $Str .= $cache->{$_.':fullname'};
                    108:         $Str .= '</option>'."\n";	     
                    109:     }
                    110: 
                    111:     $Str .= '<option';
1.3       stredwic  112:     if($selectedName eq 'No Student Selected') {
                    113:         $Str .= ' selected';
                    114:         $selected = 1;
                    115:     }
                    116:     $Str .= '>No Student Selected</option>'."\n";
                    117: 
                    118:     $Str .= '<option';
1.1       stredwic  119:     if(!$selected) {
                    120:         $Str .= ' selected';
                    121:     }
1.3       stredwic  122:     $Str .= '>All Students</option>'."\n";
1.1       stredwic  123: 
                    124:     $Str .= '</select>'."\n";
                    125: 
                    126:     return $Str;
                    127: }
                    128: 
                    129: sub StatusOptions {
                    130:     my ($status, $formName)=@_;
                    131: 
                    132:     my $OpSel1 = '';
                    133:     my $OpSel2 = '';
                    134:     my $OpSel3 = '';
                    135: 
                    136:     if($status eq 'Any')         { $OpSel3 = ' selected'; }
                    137:     elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
                    138:     else                         { $OpSel1 = ' selected'; }
                    139: 
                    140:     my $Str = '';
                    141:     $Str .= '<select name="Status"';
                    142:     if(defined($formName) && $formName ne '') {
                    143:         $Str .= ' onchange="document.'.$formName.'.submit()"';
                    144:     }
                    145:     $Str .= '>'."\n";
                    146:     $Str .= '<option'.$OpSel1.'>Active</option>'."\n";
                    147:     $Str .= '<option'.$OpSel2.'>Expired</option>'."\n";
                    148:     $Str .= '<option'.$OpSel3.'>Any</option>'."\n";
                    149:     $Str .= '</select>'."\n";
                    150: }
                    151: 
1.5       stredwic  152: sub MultipleSectionSelect {
                    153:     my ($sections,$selectedSections)=@_;
                    154: 
                    155:     my $Str = '';
                    156:     $Str .= '<select name="Section" multiple="" size="4">'."\n";
                    157: 
                    158:     foreach (@$sections) {
                    159:         $Str .= '<option';
                    160:         foreach my $selected (@$selectedSections) {
                    161:             if($_ eq $selected) {
                    162:                 $Str .= ' selected=""';
                    163:             }
                    164:         }
                    165:         $Str .= '>'.$_.'</option>'."\n";
                    166:     }
                    167:     $Str .= '</select>'."\n";
                    168: 
                    169:     return $Str;
                    170: }
                    171: 
1.1       stredwic  172: sub Title {
                    173:     my ($pageName)=@_;
                    174: 
                    175:     my $Str = '';
                    176: 
                    177:     $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
                    178:     $Str .= '<body bgcolor="#FFFFFF">'."\n";
                    179:     $Str .= '<script>window.focus(); window.width=500;window.height=500;';
                    180:     $Str .= '</script>'."\n";
                    181:     $Str .= '<table width="100%"><tr><td valign="top">';
                    182:     $Str .= '<h1> Course: ';
                    183:     $Str .= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                    184:     $Str .= '</h1></td><td align="right">'."\n";
                    185:     $Str .= '<img align="right" src=/adm/lonIcons/lonlogos.gif>';
                    186:     $Str .= '</td></tr></table>'."\n";
                    187: 
                    188:     return $Str;
                    189: }
                    190: 
                    191: =pod
                    192: 
                    193: =item &CreateTableHeadings()
                    194: 
                    195: This function generates the column headings for the chart.
                    196: 
                    197: =over 4
                    198: 
1.4       stredwic  199: Inputs: $CacheData, $keyID, $headings, $spacePadding
1.1       stredwic  200: 
                    201: $CacheData: pointer to a hash tied to the cached data database
                    202: 
1.4       stredwic  203: $keyID: a pointer to an array containing the names of the data 
1.1       stredwic  204: held in a column and is used as part of a key into $CacheData
                    205: 
                    206: $headings: The names of the headings for the student information
                    207: 
                    208: $spacePadding: The spaces to go between columns
                    209: 
                    210: Output: $Str
                    211: 
                    212: $Str: A formatted string of the table column headings.
                    213: 
                    214: =back
                    215: 
                    216: =cut
                    217: 
1.4       stredwic  218: sub CreateHeadings {
                    219:     my ($data,$keyID,$headings,$displayString,$format)=@_;
1.1       stredwic  220:     my $Str='';
1.4       stredwic  221:     my $formatting = '';
1.1       stredwic  222: 
                    223:     for(my $index=0; $index<(scalar @$headings); $index++) {
1.4       stredwic  224:  	my $currentHeading=$headings->[$index];
                    225:         if($format eq 'preformatted') {
                    226:             my @dataLength=split(//,$currentHeading);
                    227:             my $length=scalar @dataLength;
                    228:             $formatting = (' 'x
                    229:                       ($data->{$keyID->[$index].':columnWidth'}-$length));
                    230:         }
                    231:         my $linkdata=$keyID->[$index];
                    232: 
1.1       stredwic  233:         my $tempString = $displayString;
                    234:         $tempString =~ s/LINKDATA/$linkdata/;
1.4       stredwic  235:         $tempString =~ s/DISPLAYDATA/$currentHeading/;
                    236:         $tempString =~ s/FORMATTING/$formatting/;
                    237: 
1.1       stredwic  238:         $Str .= $tempString;
                    239:     }
                    240: 
                    241:     return $Str;
                    242: }
                    243: 
                    244: =pod
                    245: 
                    246: =item &FormatStudentInformation()
                    247: 
                    248: This function produces a formatted string of the student's information:
                    249: username, domain, section, full name, and PID.
                    250: 
                    251: =over 4
                    252: 
1.4       stredwic  253: Input: $cache, $name, $keyID, $spacePadding
1.1       stredwic  254: 
                    255: $cache: This is a pointer to a hash that is tied to the cached data
                    256: 
                    257: $name:  The name and domain of the current student in name:domain format
                    258: 
1.4       stredwic  259: $keyID: A pointer to an array holding the names used to
1.1       stredwic  260: 
                    261: remove data from the hash.  They represent the name of the data to be removed.
                    262: 
                    263: $spacePadding: Extra spaces that represent the space between columns
                    264: 
                    265: Output: $Str
                    266: 
                    267: $Str: Formatted string.
                    268: 
                    269: =back
                    270: 
                    271: =cut
                    272: 
                    273: sub FormatStudentInformation {
1.4       stredwic  274:     my ($data,$name,$keyID,$displayString,$format)=@_;
1.1       stredwic  275:     my $Str='';
1.4       stredwic  276:     my $currentColumn;
                    277: 
                    278:     for(my $index=0; $index<(scalar @$keyID); $index++) {
                    279:         $currentColumn=$data->{$name.':'.$keyID->[$index]};
1.1       stredwic  280: 
1.4       stredwic  281:         if($format eq 'preformatted') {
                    282:             my @dataLength=split(//,$currentColumn);
                    283:             my $length=scalar @dataLength;
                    284:             $currentColumn.= (' 'x
                    285:                      ($data->{$keyID->[$index].':columnWidth'}-$length));
1.1       stredwic  286:         }
                    287: 
1.4       stredwic  288:         my $tempString = $displayString;
                    289:         $tempString =~ s/DISPLAYDATA/$currentColumn/;
                    290: 
                    291:         $Str .= $tempString;
1.1       stredwic  292:     }
                    293: 
                    294:     return $Str;
                    295: }
                    296: 
                    297: 1;
                    298: __END__

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