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

1.1       matthew     1: #
1.12    ! matthew     2: # $Id: classcalc.pm,v 1.11 2003/09/05 01:06: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;
1.11      matthew    49: use warnings FATAL=>'all';
                     50: no warnings 'uninitialized';
1.1       matthew    51: use Apache::Constants qw(:common :http);
                     52: use Apache::loncoursedata();
                     53: use Apache::lonhtmlcommon();
                     54: use Apache::Spreadsheet;
                     55: use Apache::studentcalc;
1.5       matthew    56: use Apache::lonstatistics();
1.1       matthew    57: use HTML::Entities();
                     58: use Spreadsheet::WriteExcel;
                     59: use Apache::lonnet;
                     60: use Time::HiRes;
                     61: 
                     62: @Apache::classcalc::ISA = ('Apache::Spreadsheet');
                     63: 
1.6       matthew    64: ##
                     65: ## Package variable
                     66: ##
                     67: 
                     68: my @Students;
                     69: 
                     70: sub initialize {
                     71:     &Apache::lonstatistics::clear_classlist_variables();
                     72:     @Students = &Apache::lonstatistics::get_students();
                     73:     return;
                     74: }
                     75: 
1.12    ! matthew    76: sub clear_package {
        !            77:     undef(@Students);
        !            78:     &Apache::studentcalc::clear_package();
        !            79: }
        !            80: 
1.3       matthew    81: sub html_header {
                     82:     my $self = shift;
                     83:     my ($toprow,$bottomrow);
1.5       matthew    84:     &Apache::lonstatistics::clear_classlist_variables();
                     85:     foreach (['Sections',&Apache::lonstatistics::SectionSelect('Section','multpile',3)],
1.3       matthew    86:              ['Enrollment Status',&Apache::lonhtmlcommon::StatusOptions(undef,undef,3)],
                     87:              ['Output Format',&Apache::Spreadsheet::output_selector()]) {
                     88:         my ($name,$selector) = @{$_};
                     89:         $toprow .= '<th align="center"><b>'.$name.'</b></th>';
                     90:         $bottomrow .= '<td>'.$selector.'</td>';
                     91:     }
                     92:     return "<p>\n<table>\n".
                     93:         "<tr>".$toprow."</tr>\n".
                     94:         "<tr>".$bottomrow."</tr>\n".
                     95:         "</table>\n</p>";
                     96: }
                     97: 
1.1       matthew    98: sub get_title {
                     99:     my $self = shift;
                    100:     # Section info should be included
1.3       matthew   101:     my @title = ($self->{'coursedesc'}, scalar(localtime(time)) );
                    102:     return @title;
                    103: }
                    104: 
                    105: sub get_html_title {
                    106:     my $self = shift;
                    107:     my ($classcalc_title,$time) = $self->get_title();
                    108:     my $title = '<h1>'.$classcalc_title."</h1>\n".'<h3>'.$time."</h3>\n";
1.1       matthew   109:     return $title;
                    110: }
                    111: 
                    112: sub parent_link {
                    113:     return '';
                    114: }
                    115: 
                    116: sub outsheet_html {
                    117:     my $self = shift;
                    118:     my ($r) = @_;
                    119:     ###################################
                    120:     # Determine table structure
                    121:     ###################################
1.10      matthew   122:     my $importcolor = '#88FF88';
                    123:     my $exportcolor = '#BBBBFF';
1.1       matthew   124:     my $num_uneditable = 26;
                    125:     my $num_left = 52-$num_uneditable;
                    126:     my $tableheader =<<"END";
1.2       matthew   127: <p>
1.1       matthew   128: <table border="2">
                    129: <tr>
                    130:   <th colspan="2" rowspan="2"><font size="+2">Course</font></th>
1.10      matthew   131:   <td bgcolor="$importcolor" colspan="$num_uneditable">
1.1       matthew   132:       <b><font size="+1">Import</font></b></td>
                    133:   <td colspan="$num_left">
                    134:       <b><font size="+1">Calculations</font></b></td>
                    135: </tr><tr>
                    136: END
                    137:     my $label_num = 0;
                    138:     foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
                    139:         if ($label_num<$num_uneditable) { 
1.10      matthew   140:             $tableheader.='<th bgcolor="'.$importcolor.'">';
1.1       matthew   141:         } else {
                    142:             $tableheader.='<th>';
                    143:         }
                    144:         $tableheader.="<b><font size=+1>$_</font></b></th>";
                    145:         $label_num++;
                    146:     }
                    147:     $tableheader.="</tr>\n";
                    148:     #
                    149:     $r->print($tableheader);
                    150:     #
                    151:     # Print out template row
                    152:     $r->print('<tr><td>Template</td><td>&nbsp;</td>'.
1.10      matthew   153: 	      $self->html_template_row($num_uneditable,$importcolor).
                    154:               "</tr>\n");
1.1       matthew   155:     #
                    156:     # Print out summary/export row
                    157:     $r->print('<tr><td>Summary</td><td>0</td>'.
1.10      matthew   158: 	      $self->html_export_row($exportcolor)."</tr>\n");
1.1       matthew   159:     #
                    160:     # Prepare to output rows
                    161:     $tableheader =<<"END";
1.2       matthew   162: </p><p>
1.1       matthew   163: <table border="2">
                    164: <tr><th>Row</th>
                    165:   <th>student</th><th>username</th><th>domain</th>
                    166:   <th>section</th><th>status</th>
                    167: END
                    168:     foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
                    169: 	if ($label_num<$num_uneditable) { 
1.10      matthew   170:             $tableheader.='<th bgcolor="'.$importcolor.'">';
1.1       matthew   171:         } else {
                    172:             $tableheader.='<th>';
                    173:         }
                    174:         $tableheader.="<b><font size=+1>$_</font></b></th>";
                    175:     }
                    176:     #
                    177:     my $num_output = 0;
1.6       matthew   178:     foreach my $student (@Students) {
1.1       matthew   179: 	if ($num_output++ % 50 == 0) {
                    180: 	    $r->print("</table>\n".$tableheader);
                    181: 	}
                    182: 	my $rownum = $self->get_row_number_from_key
                    183: 	    ($student->{'username'}.':'.$student->{'domain'});
                    184:         my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
                    185:             '&sdomain='.$student->{'domain'}.'">';
                    186:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
                    187: 	$r->print('<tr>'.'<td>'.$rownum.'</td>'.
1.8       matthew   188: 		  '<td>'.$student->{'fullname'}.'</td>'.
                    189: 		  '<td>'.$link.$student->{'username'}.'</a></td>'.
1.1       matthew   190: 		  '<td>'.$student->{'domain'}  .'</td>'.
                    191: 		  '<td>'.$student->{'section'} .'</td>'.
                    192: 		  '<td>'.$student->{'status'}  .'</td>'.
1.10      matthew   193: 		  $self->html_row($num_uneditable,$rownum,$exportcolor,
                    194:                                   $importcolor).
                    195:                   "</tr>\n");
1.1       matthew   196:     }
1.2       matthew   197:     $r->print("</table></p>\n");
1.1       matthew   198:     return;
                    199: }
                    200: 
1.3       matthew   201: sub excel_rows {
                    202:     # writes the meat of the spreadsheet to an excel worksheet.  Called
                    203:     # by Spreadsheet::outsheet_excel;
1.1       matthew   204:     my $self = shift;
1.3       matthew   205:     my ($worksheet,$cols_output,$rows_output) = @_;
                    206:     #
                    207:     # Write a header row
                    208:     $cols_output = 0;
                    209:     foreach my $value ('fullname','username','domain','section','status') {
                    210:         $worksheet->write($rows_output,$cols_output++,$value);
                    211:     }
                    212:     $rows_output++;    
                    213:     #
                    214:     # Write each students row
1.6       matthew   215:     foreach my $student (@Students) {
1.3       matthew   216:         $cols_output = 0;
                    217: 	my $rownum = $self->get_row_number_from_key
                    218: 	    ($student->{'username'}.':'.$student->{'domain'});
                    219:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
                    220:         my @studentdata = ($student->{'fullname'},
                    221:                            $student->{'username'},
                    222:                            $student->{'domain'},
                    223:                            $student->{'section'},
                    224:                            $student->{'status'});
                    225:         $self->excel_output_row($worksheet,$rownum,$rows_output++,
                    226:                                 @studentdata);
                    227:     }
                    228:     return;
1.1       matthew   229: }
                    230: 
1.4       matthew   231: sub csv_rows {
                    232:     # writes the meat of the spreadsheet to an excel worksheet.  Called
                    233:     # by Spreadsheet::outsheet_excel;
                    234:     my $self = shift;
                    235:     my ($filehandle) = @_;
                    236:     #
                    237:     # Write a header row
                    238: 
                    239:     $self->csv_output_row($filehandle,undef,
                    240:                           ('fullname','username','domain','section','status'));
                    241:     #
                    242:     # Write each students row
1.6       matthew   243:     foreach my $student (@Students) {
1.4       matthew   244: 	my $rownum = $self->get_row_number_from_key
                    245: 	    ($student->{'username'}.':'.$student->{'domain'});
                    246:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
                    247:         my @studentdata = ($student->{'fullname'},
                    248:                            $student->{'username'},
                    249:                            $student->{'domain'},
                    250:                            $student->{'section'},
                    251:                            $student->{'status'});
                    252:         $self->csv_output_row($filehandle,$rownum,@studentdata);
                    253:     }
                    254:     return;
                    255: }
1.3       matthew   256: 
1.1       matthew   257: sub outsheet_recursive_excel {
                    258:     my $self = shift;
                    259:     my ($r) = @_;
                    260: } 
                    261: 
                    262: sub compute {
                    263:     my $self = shift;
                    264:     my ($r) = @_;
1.12    ! matthew   265:     my $connection = $r->connection();
        !           266:     if ($connection->aborted()) { $self->cleanup(); return; }
1.1       matthew   267:     $self->initialize_safe_space();
                    268:     my %c = $self->constants();
                    269:     my %f = $self->formulas();
                    270:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
                    271:         ($r,'Spreadsheet Computation Status',
                    272:          'Spreadsheet Computation', scalar(@Students));
1.9       matthew   273:     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
                    274:                                           'Processing course structure');
1.1       matthew   275:     &Apache::studentcalc::initialize_package();
1.9       matthew   276:     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
                    277:                                           'Processing first student');
1.6       matthew   278:     foreach my $student (@Students) {
1.12    ! matthew   279:         if ($connection->aborted()) { $self->cleanup(); return; }
1.1       matthew   280:         my $sname = $student->{'username'}.':'.$student->{'domain'};
                    281: 	my $studentsheet = Apache::studentcalc->new
                    282: 	    ($student->{'username'},$student->{'domain'},undef);
1.12    ! matthew   283:         if ($connection->aborted()) { $self->cleanup(); return; }
        !           284: 	my @exportdata = $studentsheet->export_data($r);
        !           285:         if ($connection->aborted()) { $self->cleanup(); return; }
1.1       matthew   286: 	my $rownum = $self->get_row_number_from_key($sname);
                    287:         $f{'A'.$rownum} = $sname;
                    288:         $self->{'row_source'}->{$rownum} = $sname;
                    289:         $c{'A'.$rownum} = shift(@exportdata);
                    290: 	foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
                    291:             my $cell = $_.$rownum;
                    292:             my $data = shift(@exportdata);
                    293:             if (defined($data)) {
                    294:                 $f{$cell} = 'import';
                    295:                 $c{$cell} = $data;
                    296:             }
                    297: 	}
                    298:         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                    299:                                                  'last student');
                    300:     }
                    301:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                    302:     $r->rflush();
                    303:     $self->constants(\%c);
                    304:     $self->formulas(\%f);
                    305:     $self->calcsheet();
1.7       matthew   306:     $self->save() if ($self->need_to_save());
1.1       matthew   307: }
                    308: 
                    309: 1;
                    310: 
                    311: __END__

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