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

1.1       matthew     1: #
1.13    ! matthew     2: # $Id: classcalc.pm,v 1.12 2003/09/05 01:57:54 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.13    ! matthew   205:     my ($connection,$worksheet,$cols_output,$rows_output) = @_;
1.3       matthew   206:     #
                    207:     # Write a header row
                    208:     $cols_output = 0;
1.13    ! matthew   209:     foreach my $value ('fullname','username','domain','section','status','id') {
1.3       matthew   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'},
1.13    ! matthew   224:                            $student->{'status'},
        !           225:                            $student->{'id'});
1.3       matthew   226:         $self->excel_output_row($worksheet,$rownum,$rows_output++,
                    227:                                 @studentdata);
                    228:     }
                    229:     return;
1.1       matthew   230: }
                    231: 
1.4       matthew   232: sub csv_rows {
                    233:     # writes the meat of the spreadsheet to an excel worksheet.  Called
                    234:     # by Spreadsheet::outsheet_excel;
                    235:     my $self = shift;
1.13    ! matthew   236:     my ($connection,$filehandle) = @_;
1.4       matthew   237:     #
                    238:     # Write a header row
                    239: 
                    240:     $self->csv_output_row($filehandle,undef,
1.13    ! matthew   241:                    ('fullname','username','domain','section','status','id'));
1.4       matthew   242:     #
                    243:     # Write each students row
1.6       matthew   244:     foreach my $student (@Students) {
1.4       matthew   245: 	my $rownum = $self->get_row_number_from_key
                    246: 	    ($student->{'username'}.':'.$student->{'domain'});
                    247:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
                    248:         my @studentdata = ($student->{'fullname'},
                    249:                            $student->{'username'},
                    250:                            $student->{'domain'},
                    251:                            $student->{'section'},
1.13    ! matthew   252:                            $student->{'status'},
        !           253:                            $student->{'id'});
1.4       matthew   254:         $self->csv_output_row($filehandle,$rownum,@studentdata);
                    255:     }
                    256:     return;
                    257: }
1.3       matthew   258: 
1.1       matthew   259: sub outsheet_recursive_excel {
                    260:     my $self = shift;
                    261:     my ($r) = @_;
                    262: } 
                    263: 
                    264: sub compute {
                    265:     my $self = shift;
                    266:     my ($r) = @_;
1.12      matthew   267:     my $connection = $r->connection();
                    268:     if ($connection->aborted()) { $self->cleanup(); return; }
1.1       matthew   269:     $self->initialize_safe_space();
                    270:     my %c = $self->constants();
                    271:     my %f = $self->formulas();
                    272:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
                    273:         ($r,'Spreadsheet Computation Status',
                    274:          'Spreadsheet Computation', scalar(@Students));
1.9       matthew   275:     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
                    276:                                           'Processing course structure');
1.1       matthew   277:     &Apache::studentcalc::initialize_package();
1.9       matthew   278:     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
                    279:                                           'Processing first student');
1.6       matthew   280:     foreach my $student (@Students) {
1.12      matthew   281:         if ($connection->aborted()) { $self->cleanup(); return; }
1.1       matthew   282:         my $sname = $student->{'username'}.':'.$student->{'domain'};
                    283: 	my $studentsheet = Apache::studentcalc->new
                    284: 	    ($student->{'username'},$student->{'domain'},undef);
1.12      matthew   285:         if ($connection->aborted()) { $self->cleanup(); return; }
                    286: 	my @exportdata = $studentsheet->export_data($r);
                    287:         if ($connection->aborted()) { $self->cleanup(); return; }
1.1       matthew   288: 	my $rownum = $self->get_row_number_from_key($sname);
                    289:         $f{'A'.$rownum} = $sname;
                    290:         $self->{'row_source'}->{$rownum} = $sname;
                    291:         $c{'A'.$rownum} = shift(@exportdata);
                    292: 	foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
                    293:             my $cell = $_.$rownum;
                    294:             my $data = shift(@exportdata);
                    295:             if (defined($data)) {
                    296:                 $f{$cell} = 'import';
                    297:                 $c{$cell} = $data;
                    298:             }
                    299: 	}
                    300:         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                    301:                                                  'last student');
                    302:     }
                    303:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                    304:     $r->rflush();
                    305:     $self->constants(\%c);
                    306:     $self->formulas(\%f);
                    307:     $self->calcsheet();
1.7       matthew   308:     $self->save() if ($self->need_to_save());
1.1       matthew   309: }
                    310: 
                    311: 1;
                    312: 
                    313: __END__

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