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

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

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