Annotation of loncom/interface/spreadsheet/classcalc.pm, revision 1.6

1.1       matthew     1: #
1.6     ! matthew     2: # $Id: classcalc.pm,v 1.5 2003/05/27 14:52:45 matthew Exp $
1.1       matthew     3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
                     26: # The LearningOnline Network with CAPA
                     27: # Spreadsheet/Grades Display Handler
                     28: #
                     29: # POD required stuff:
                     30: 
                     31: =head1 NAME
                     32: 
                     33: classcalc
                     34: 
                     35: =head1 SYNOPSIS
                     36: 
                     37: =head1 DESCRIPTION
                     38: 
                     39: =over 4
                     40: 
                     41: =cut
                     42: 
                     43: ###################################################
                     44: ###                 CourseSheet                 ###
                     45: ###################################################
                     46: package Apache::classcalc;
                     47: 
                     48: use strict;
                     49: use Apache::Constants qw(:common :http);
                     50: use Apache::loncoursedata();
                     51: use Apache::lonhtmlcommon();
                     52: use Apache::Spreadsheet;
                     53: use Apache::studentcalc;
1.5       matthew    54: use Apache::lonstatistics();
1.1       matthew    55: use HTML::Entities();
                     56: use Spreadsheet::WriteExcel;
                     57: use Apache::lonnet;
                     58: use Time::HiRes;
                     59: 
                     60: @Apache::classcalc::ISA = ('Apache::Spreadsheet');
                     61: 
1.6     ! matthew    62: ##
        !            63: ## Package variable
        !            64: ##
        !            65: 
        !            66: my @Students;
        !            67: 
        !            68: sub initialize {
        !            69:     &Apache::lonstatistics::clear_classlist_variables();
        !            70:     @Students = &Apache::lonstatistics::get_students();
        !            71:     return;
        !            72: }
        !            73: 
1.3       matthew    74: sub html_header {
                     75:     my $self = shift;
                     76:     my ($toprow,$bottomrow);
1.5       matthew    77:     &Apache::lonstatistics::clear_classlist_variables();
                     78:     foreach (['Sections',&Apache::lonstatistics::SectionSelect('Section','multpile',3)],
1.3       matthew    79:              ['Enrollment Status',&Apache::lonhtmlcommon::StatusOptions(undef,undef,3)],
                     80:              ['Output Format',&Apache::Spreadsheet::output_selector()]) {
                     81:         my ($name,$selector) = @{$_};
                     82:         $toprow .= '<th align="center"><b>'.$name.'</b></th>';
                     83:         $bottomrow .= '<td>'.$selector.'</td>';
                     84:     }
                     85:     return "<p>\n<table>\n".
                     86:         "<tr>".$toprow."</tr>\n".
                     87:         "<tr>".$bottomrow."</tr>\n".
                     88:         "</table>\n</p>";
                     89: }
                     90: 
1.1       matthew    91: sub get_title {
                     92:     my $self = shift;
                     93:     # Section info should be included
1.3       matthew    94:     my @title = ($self->{'coursedesc'}, scalar(localtime(time)) );
                     95:     return @title;
                     96: }
                     97: 
                     98: sub get_html_title {
                     99:     my $self = shift;
                    100:     my ($classcalc_title,$time) = $self->get_title();
                    101:     my $title = '<h1>'.$classcalc_title."</h1>\n".'<h3>'.$time."</h3>\n";
1.1       matthew   102:     return $title;
                    103: }
                    104: 
                    105: sub parent_link {
                    106:     return '';
                    107: }
                    108: 
                    109: sub outsheet_html {
                    110:     my $self = shift;
                    111:     my ($r) = @_;
                    112:     ###################################
                    113:     # Determine table structure
                    114:     ###################################
                    115:     my $num_uneditable = 26;
                    116:     my $num_left = 52-$num_uneditable;
                    117:     my $tableheader =<<"END";
1.2       matthew   118: <p>
1.1       matthew   119: <table border="2">
                    120: <tr>
                    121:   <th colspan="2" rowspan="2"><font size="+2">Course</font></th>
                    122:   <td bgcolor="#FFDDDD" colspan="$num_uneditable">
                    123:       <b><font size="+1">Import</font></b></td>
                    124:   <td colspan="$num_left">
                    125:       <b><font size="+1">Calculations</font></b></td>
                    126: </tr><tr>
                    127: END
                    128:     my $label_num = 0;
                    129:     foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
                    130:         if ($label_num<$num_uneditable) { 
                    131:             $tableheader.='<th bgcolor="#FFDDDD">';
                    132:         } else {
                    133:             $tableheader.='<th>';
                    134:         }
                    135:         $tableheader.="<b><font size=+1>$_</font></b></th>";
                    136:         $label_num++;
                    137:     }
                    138:     $tableheader.="</tr>\n";
                    139:     #
                    140:     $r->print($tableheader);
                    141:     #
                    142:     # Print out template row
                    143:     $r->print('<tr><td>Template</td><td>&nbsp;</td>'.
                    144: 	      $self->html_template_row($num_uneditable)."</tr>\n");
                    145:     #
                    146:     # Print out summary/export row
                    147:     $r->print('<tr><td>Summary</td><td>0</td>'.
                    148: 	      $self->html_export_row()."</tr>\n");
                    149:     #
                    150:     # Prepare to output rows
                    151:     $tableheader =<<"END";
1.2       matthew   152: </p><p>
1.1       matthew   153: <table border="2">
                    154: <tr><th>Row</th>
                    155:   <th>student</th><th>username</th><th>domain</th>
                    156:   <th>section</th><th>status</th>
                    157: END
                    158:     foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
                    159: 	if ($label_num<$num_uneditable) { 
                    160:             $tableheader.='<th bgcolor="#FFDDDD">';
                    161:         } else {
                    162:             $tableheader.='<th>';
                    163:         }
                    164:         $tableheader.="<b><font size=+1>$_</font></b></th>";
                    165:     }
                    166:     #
                    167:     my $num_output = 0;
1.6     ! matthew   168:     foreach my $student (@Students) {
1.1       matthew   169: 	if ($num_output++ % 50 == 0) {
                    170: 	    $r->print("</table>\n".$tableheader);
                    171: 	}
                    172: 	my $rownum = $self->get_row_number_from_key
                    173: 	    ($student->{'username'}.':'.$student->{'domain'});
                    174:         my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
                    175:             '&sdomain='.$student->{'domain'}.'">';
                    176:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
                    177: 	$r->print('<tr>'.'<td>'.$rownum.'</td>'.
                    178: 		  '<td>'.$link.$student->{'fullname'}.'</a></td>'.
                    179: 		  '<td>'.$student->{'username'}.'</td>'.
                    180: 		  '<td>'.$student->{'domain'}  .'</td>'.
                    181: 		  '<td>'.$student->{'section'} .'</td>'.
                    182: 		  '<td>'.$student->{'status'}  .'</td>'.
                    183: 		  $self->html_row($num_uneditable,$rownum)."</tr>\n");
                    184:     }
1.2       matthew   185:     $r->print("</table></p>\n");
1.1       matthew   186:     return;
                    187: }
                    188: 
1.3       matthew   189: sub excel_rows {
                    190:     # writes the meat of the spreadsheet to an excel worksheet.  Called
                    191:     # by Spreadsheet::outsheet_excel;
1.1       matthew   192:     my $self = shift;
1.3       matthew   193:     my ($worksheet,$cols_output,$rows_output) = @_;
                    194:     #
                    195:     # Write a header row
                    196:     $cols_output = 0;
                    197:     foreach my $value ('fullname','username','domain','section','status') {
                    198:         $worksheet->write($rows_output,$cols_output++,$value);
                    199:     }
                    200:     $rows_output++;    
                    201:     #
                    202:     # Write each students row
1.6     ! matthew   203:     foreach my $student (@Students) {
1.3       matthew   204:         $cols_output = 0;
                    205: 	my $rownum = $self->get_row_number_from_key
                    206: 	    ($student->{'username'}.':'.$student->{'domain'});
                    207:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
                    208:         my @studentdata = ($student->{'fullname'},
                    209:                            $student->{'username'},
                    210:                            $student->{'domain'},
                    211:                            $student->{'section'},
                    212:                            $student->{'status'});
                    213:         $self->excel_output_row($worksheet,$rownum,$rows_output++,
                    214:                                 @studentdata);
                    215:     }
                    216:     return;
1.1       matthew   217: }
                    218: 
1.4       matthew   219: sub csv_rows {
                    220:     # writes the meat of the spreadsheet to an excel worksheet.  Called
                    221:     # by Spreadsheet::outsheet_excel;
                    222:     my $self = shift;
                    223:     my ($filehandle) = @_;
                    224:     #
                    225:     # Write a header row
                    226: 
                    227:     $self->csv_output_row($filehandle,undef,
                    228:                           ('fullname','username','domain','section','status'));
                    229:     #
                    230:     # Write each students row
1.6     ! matthew   231:     foreach my $student (@Students) {
1.4       matthew   232: 	my $rownum = $self->get_row_number_from_key
                    233: 	    ($student->{'username'}.':'.$student->{'domain'});
                    234:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
                    235:         my @studentdata = ($student->{'fullname'},
                    236:                            $student->{'username'},
                    237:                            $student->{'domain'},
                    238:                            $student->{'section'},
                    239:                            $student->{'status'});
                    240:         $self->csv_output_row($filehandle,$rownum,@studentdata);
                    241:     }
                    242:     return;
                    243: }
1.3       matthew   244: 
1.1       matthew   245: sub outsheet_recursive_excel {
                    246:     my $self = shift;
                    247:     my ($r) = @_;
                    248: } 
                    249: 
                    250: sub compute {
                    251:     my $self = shift;
                    252:     my ($r) = @_;
                    253:     $self->initialize_safe_space();
                    254:     my %c = $self->constants();
                    255:     my %f = $self->formulas();
                    256:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
                    257:         ($r,'Spreadsheet Computation Status',
                    258:          'Spreadsheet Computation', scalar(@Students));
                    259:     &Apache::studentcalc::initialize_package();
1.6     ! matthew   260:     foreach my $student (@Students) {
1.1       matthew   261:         my $sname = $student->{'username'}.':'.$student->{'domain'};
                    262: 	my $studentsheet = Apache::studentcalc->new
                    263: 	    ($student->{'username'},$student->{'domain'},undef);
                    264: 	my @exportdata = $studentsheet->export_data();
                    265: 	my $rownum = $self->get_row_number_from_key($sname);
                    266:         $f{'A'.$rownum} = $sname;
                    267:         $self->{'row_source'}->{$rownum} = $sname;
                    268:         $c{'A'.$rownum} = shift(@exportdata);
                    269: 	foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
                    270:             my $cell = $_.$rownum;
                    271:             my $data = shift(@exportdata);
                    272:             if (defined($data)) {
                    273:                 $f{$cell} = 'import';
                    274:                 $c{$cell} = $data;
                    275:             }
                    276: 	}
                    277:         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                    278:                                                  'last student');
                    279:     }
                    280:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                    281:     $r->rflush();
                    282:     $self->constants(\%c);
                    283:     $self->formulas(\%f);
                    284:     $self->calcsheet();
                    285: }
                    286: 
                    287: 1;
                    288: 
                    289: __END__

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