File:  [LON-CAPA] / loncom / interface / lonhtmlcommon.pm
Revision 1.1: download - view: text, annotated - select for diffs
Mon Jul 22 20:35:05 2002 UTC (21 years, 10 months ago) by stredwic
Branches: MAIN
CVS tags: HEAD
Lonchart is now part of lonstatistics.  When the CHRT button is pressed on
the remote control it will take you to the student assessment page.  In
the next commit or two, the student assessment page and lonchart will
gradually merge, or I will make chart its own report.

I added another perl module, lonhtmlcommon which will contain a series of
functions that create controls and data layouts for various different
pieces of information.  This is just a fledgling module.

The biggest feature of this commit is that the downloading of student course
data has changed slightly.  Now, the classlist will contain all students,
but will only display the appropriate ones.  Different reports require
different amounts of data, so some may only download student course data
when selected and some will download it all at once.  The downloading
will first grab the time stamp on the course.db file for the student and
compare it will the cached timestamp for that file.  It will only do a
dump if the data is not yet cached or the timestamp is newer than the one
stored.  Only when the data is processed is the timestamp update, not
when downloaded.  The Download/Process duo of function work hand in hand.
Calling both will be typical even if there was nothing actually downloaded.

The is now a new form, which is a class list with different information.
This list also contain the timestamp for each student, when their course
data was downloaded last.  Having this page is both informational, and
hopefully will mean that it is not necessary for all the other pages, at least
as defaults.

Each report now has a common header.  There is currently some white space,
but it can be filled.  The header has a refresh button, update all student
data button, a selection of forms and a selection of student status.  The
update all student data button will download all students (active and expired)
for the given course.  This allows someone to come to the entry page(
class list) update all the students while they do stuff and come back.
The two selection boxes are special in that they will update the
document when changed.  The onchange attribute was tested on mac,
linux and pc, for the different browsers.  The only noticed difference
was netscape 4.7 executes the javascript if it you select the same thing,
where all others do not.  Also, the same browser causes the first
button in the form to be pressed when the document.form.submit()
javascript is executed for the onchange of the selection box.

There was other cosmetic changes, but were minor.

package Apache::lonhtmlcommon;

use strict;

sub MapOptions {
    my ($data, $page)=@_;
    my $Str = '';
    $Str .= '<select name="';
    $Str .= (($page)?$page:'').'Map">'."\n";

    my $selected = 0;
    foreach my $sequence (split(':',$data->{'orderedSequences'})) {
	$Str .= '<option';
        if($data->{$page.'Map'} eq $data->{$sequence.':title'}) {
            $Str .= ' selected';
            $selected = 1;
        }
	$Str .= '>'.$data->{$sequence.':title'}.'</option>'."\n";	     
    }
    $Str .= '<option';
    if(!$selected) {
        $Str .= ' selected';
    }
    $Str .= '>All Maps</option>'."\n";

    $Str .= '</select>'."\n";

    return $Str;
}

sub StudentOptions {
    my ($cache, $students, $selectedName, $page)=@_;

    my $Str = '';
    $Str = '<select name="'.(($page)?$page:'').'Student">'."\n";

    my $selected=0;
    $Str .= '<option';
    if($selectedName eq 'All Students') {
        $Str .= ' selected';
        $selected = 1;
    }
    $Str .= '>All Students</option>'."\n";

    foreach (@$students) {
	$Str .= '<option';
	if($selectedName eq $_) {
            $Str .= ' selected';
            $selected = 1;
        }
        $Str .= '>';
        $Str .= $cache->{$_.':fullname'};
        $Str .= '</option>'."\n";	     
    }

    $Str .= '<option';
    if(!$selected) {
        $Str .= ' selected';
    }
    $Str .= '>No Student Selected</option>'."\n";

    $Str .= '</select>'."\n";

    return $Str;
}

sub StatusOptions {
    my ($status, $formName)=@_;

    my $OpSel1 = '';
    my $OpSel2 = '';
    my $OpSel3 = '';

    if($status eq 'Any')         { $OpSel3 = ' selected'; }
    elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
    else                         { $OpSel1 = ' selected'; }

    my $Str = '';
    $Str .= '<select name="Status"';
    if(defined($formName) && $formName ne '') {
        $Str .= ' onchange="document.'.$formName.'.submit()"';
    }
    $Str .= '>'."\n";
    $Str .= '<option'.$OpSel1.'>Active</option>'."\n";
    $Str .= '<option'.$OpSel2.'>Expired</option>'."\n";
    $Str .= '<option'.$OpSel3.'>Any</option>'."\n";
    $Str .= '</select>'."\n";
}

sub Title {
    my ($pageName)=@_;

    my $Str = '';

    $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
    $Str .= '<body bgcolor="#FFFFFF">'."\n";
    $Str .= '<script>window.focus(); window.width=500;window.height=500;';
    $Str .= '</script>'."\n";
    $Str .= '<table width="100%"><tr><td valign="top">';
    $Str .= '<h1> Course: ';
    $Str .= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
    $Str .= '</h1></td><td align="right">'."\n";
    $Str .= '<img align="right" src=/adm/lonIcons/lonlogos.gif>';
    $Str .= '</td></tr></table>'."\n";
#    $Str .= '<h3>Current Time: '.localtime(time).'</h3><br><br><br>'."\n";

    return $Str;
}

sub CreateStatisticsMainMenu {
    my ($status, $reports)=@_;

    my $Str = '';

    $Str .= '<table border="0"><tbody><tr>'."\n";
    $Str .= '<td></td><td></td>'."\n";
    $Str .= '<td align="center"><b>Analysis Reports:</b></td>'."\n";
    $Str .= '<td align="center"><b>Student Status:</b></td></tr>'."\n";
    $Str .= '<tr>'."\n";
    $Str .= '<td align="center"><input type="submit" name="Refresh" ';
    $Str .= 'value="Refresh" /></td>'."\n";
    $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
    $Str .= 'value="Update All Student Data" /></td>'."\n";
    $Str .= '<td align="center">';
    $Str .= '<select name="reportSelected" onchange="document.';
    $Str .= 'Statistics.submit()">'."\n";

    foreach (sort(keys(%$reports))) {
        next if($_ eq 'reportSelected');
        $Str .= '<option name="'.$_.'"';
        if($reports->{'reportSelected'} eq $reports->{$_}) {
            $Str .= ' selected=""';
        }
        $Str .= '>'.$reports->{$_}.'</option>'."\n";
    }
    $Str .= '</select></td>'."\n";

    $Str .= '<td align="center">';
    $Str .= &StatusOptions($status, 'Statistics');
    $Str .= '</td>'."\n";

    $Str .= '</tr></tbody></table>'."\n";
    $Str .= '<hr>'."\n";

    return $Str;
}

=pod

=item &CreateTableHeadings()

This function generates the column headings for the chart.

=over 4

Inputs: $CacheData, $studentInformation, $headings, $spacePadding

$CacheData: pointer to a hash tied to the cached data database

$studentInformation: a pointer to an array containing the names of the data 
held in a column and is used as part of a key into $CacheData

$headings: The names of the headings for the student information

$spacePadding: The spaces to go between columns

Output: $Str

$Str: A formatted string of the table column headings.

=back

=cut

sub CreateStudentInformationHeadings {
    my ($data,$studentInformation,$headings,$displayString)=@_;
    my $Str='';

    for(my $index=0; $index<(scalar @$headings); $index++) {
#        if(!&ShouldShowColumn($data, 'ChartHeading'.$index)) {
#            next;
#        }
 	my $data=$headings->[$index];
        my $linkdata=$studentInformation->[$index];
        my $tempString = $displayString;
        $tempString =~ s/LINKDATA/$linkdata/;
        $tempString =~ s/DISPLAYDATA/$data/;
        $Str .= $tempString;
    }

    return $Str;
}

=pod

=item &FormatStudentInformation()

This function produces a formatted string of the student's information:
username, domain, section, full name, and PID.

=over 4

Input: $cache, $name, $studentInformation, $spacePadding

$cache: This is a pointer to a hash that is tied to the cached data

$name:  The name and domain of the current student in name:domain format

$studentInformation: A pointer to an array holding the names used to

remove data from the hash.  They represent the name of the data to be removed.

$spacePadding: Extra spaces that represent the space between columns

Output: $Str

$Str: Formatted string.

=back

=cut

sub FormatStudentInformation {
    my ($cache,$name,$studentInformation,$spacePadding)=@_;
    my $Str='';
    my $data;

    for(my $index=0; $index<(scalar @$studentInformation); $index++) {
        if(!&ShouldShowColumn($cache, 'ChartHeading'.$index)) {
            next;
        }
        $data=$cache->{$name.':'.$studentInformation->[$index]};
	$Str .= $data;

	my @dataLength=split(//,$data);
	my $length=scalar @dataLength;
	$Str .= (' 'x($cache->{$studentInformation->[$index].'Length'}-
                      $length));
	$Str .= $spacePadding;
    }

    return $Str;
}

1;
__END__

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