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

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

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