Annotation of loncom/interface/spreadsheet/classcalc.pm, revision 1.10.2.1
1.1 matthew 1: #
1.10.2.1! 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;
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) = @_;
1.10.2.1! matthew 112: ####################################
! 113: # Report any calculation errors #
! 114: ####################################
! 115: $r->print($self->html_report_error());
1.1 matthew 116: ###################################
117: # Determine table structure
118: ###################################
1.10 matthew 119: my $importcolor = '#88FF88';
120: my $exportcolor = '#BBBBFF';
1.1 matthew 121: my $num_uneditable = 26;
122: my $num_left = 52-$num_uneditable;
123: my $tableheader =<<"END";
1.2 matthew 124: <p>
1.1 matthew 125: <table border="2">
126: <tr>
127: <th colspan="2" rowspan="2"><font size="+2">Course</font></th>
1.10 matthew 128: <td bgcolor="$importcolor" colspan="$num_uneditable">
1.1 matthew 129: <b><font size="+1">Import</font></b></td>
130: <td colspan="$num_left">
131: <b><font size="+1">Calculations</font></b></td>
132: </tr><tr>
133: END
134: my $label_num = 0;
135: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
136: if ($label_num<$num_uneditable) {
1.10 matthew 137: $tableheader.='<th bgcolor="'.$importcolor.'">';
1.1 matthew 138: } else {
139: $tableheader.='<th>';
140: }
141: $tableheader.="<b><font size=+1>$_</font></b></th>";
142: $label_num++;
143: }
144: $tableheader.="</tr>\n";
145: #
146: $r->print($tableheader);
147: #
148: # Print out template row
149: $r->print('<tr><td>Template</td><td> </td>'.
1.10 matthew 150: $self->html_template_row($num_uneditable,$importcolor).
151: "</tr>\n");
1.1 matthew 152: #
153: # Print out summary/export row
154: $r->print('<tr><td>Summary</td><td>0</td>'.
1.10 matthew 155: $self->html_export_row($exportcolor)."</tr>\n");
1.1 matthew 156: #
157: # Prepare to output rows
158: $tableheader =<<"END";
1.2 matthew 159: </p><p>
1.1 matthew 160: <table border="2">
161: <tr><th>Row</th>
162: <th>student</th><th>username</th><th>domain</th>
163: <th>section</th><th>status</th>
164: END
165: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
166: if ($label_num<$num_uneditable) {
1.10 matthew 167: $tableheader.='<th bgcolor="'.$importcolor.'">';
1.1 matthew 168: } else {
169: $tableheader.='<th>';
170: }
171: $tableheader.="<b><font size=+1>$_</font></b></th>";
172: }
173: #
174: my $num_output = 0;
1.6 matthew 175: foreach my $student (@Students) {
1.1 matthew 176: if ($num_output++ % 50 == 0) {
177: $r->print("</table>\n".$tableheader);
178: }
179: my $rownum = $self->get_row_number_from_key
180: ($student->{'username'}.':'.$student->{'domain'});
181: my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
182: '&sdomain='.$student->{'domain'}.'">';
183: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
184: $r->print('<tr>'.'<td>'.$rownum.'</td>'.
1.8 matthew 185: '<td>'.$student->{'fullname'}.'</td>'.
186: '<td>'.$link.$student->{'username'}.'</a></td>'.
1.1 matthew 187: '<td>'.$student->{'domain'} .'</td>'.
188: '<td>'.$student->{'section'} .'</td>'.
189: '<td>'.$student->{'status'} .'</td>'.
1.10 matthew 190: $self->html_row($num_uneditable,$rownum,$exportcolor,
191: $importcolor).
192: "</tr>\n");
1.1 matthew 193: }
1.2 matthew 194: $r->print("</table></p>\n");
1.1 matthew 195: return;
196: }
197:
1.3 matthew 198: sub excel_rows {
199: # writes the meat of the spreadsheet to an excel worksheet. Called
200: # by Spreadsheet::outsheet_excel;
1.1 matthew 201: my $self = shift;
1.3 matthew 202: my ($worksheet,$cols_output,$rows_output) = @_;
203: #
204: # Write a header row
205: $cols_output = 0;
206: foreach my $value ('fullname','username','domain','section','status') {
207: $worksheet->write($rows_output,$cols_output++,$value);
208: }
209: $rows_output++;
210: #
211: # Write each students row
1.6 matthew 212: foreach my $student (@Students) {
1.3 matthew 213: $cols_output = 0;
214: my $rownum = $self->get_row_number_from_key
215: ($student->{'username'}.':'.$student->{'domain'});
216: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
217: my @studentdata = ($student->{'fullname'},
218: $student->{'username'},
219: $student->{'domain'},
220: $student->{'section'},
221: $student->{'status'});
222: $self->excel_output_row($worksheet,$rownum,$rows_output++,
223: @studentdata);
224: }
225: return;
1.1 matthew 226: }
227:
1.4 matthew 228: sub csv_rows {
229: # writes the meat of the spreadsheet to an excel worksheet. Called
230: # by Spreadsheet::outsheet_excel;
231: my $self = shift;
232: my ($filehandle) = @_;
233: #
234: # Write a header row
235:
236: $self->csv_output_row($filehandle,undef,
237: ('fullname','username','domain','section','status'));
238: #
239: # Write each students row
1.6 matthew 240: foreach my $student (@Students) {
1.4 matthew 241: my $rownum = $self->get_row_number_from_key
242: ($student->{'username'}.':'.$student->{'domain'});
243: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
244: my @studentdata = ($student->{'fullname'},
245: $student->{'username'},
246: $student->{'domain'},
247: $student->{'section'},
248: $student->{'status'});
249: $self->csv_output_row($filehandle,$rownum,@studentdata);
250: }
251: return;
252: }
1.3 matthew 253:
1.1 matthew 254: sub outsheet_recursive_excel {
255: my $self = shift;
256: my ($r) = @_;
257: }
258:
259: sub compute {
260: my $self = shift;
261: my ($r) = @_;
262: $self->initialize_safe_space();
263: my %c = $self->constants();
264: my %f = $self->formulas();
265: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
266: ($r,'Spreadsheet Computation Status',
267: 'Spreadsheet Computation', scalar(@Students));
1.9 matthew 268: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
269: 'Processing course structure');
1.1 matthew 270: &Apache::studentcalc::initialize_package();
1.9 matthew 271: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
272: 'Processing first student');
1.6 matthew 273: foreach my $student (@Students) {
1.1 matthew 274: my $sname = $student->{'username'}.':'.$student->{'domain'};
275: my $studentsheet = Apache::studentcalc->new
276: ($student->{'username'},$student->{'domain'},undef);
277: my @exportdata = $studentsheet->export_data();
1.10.2.1! matthew 278: if ($studentsheet->badcalc()) {
! 279: $self->set_calcerror($sname.' : '.
! 280: $studentsheet->calcerror());
! 281: }
1.1 matthew 282: my $rownum = $self->get_row_number_from_key($sname);
283: $f{'A'.$rownum} = $sname;
284: $self->{'row_source'}->{$rownum} = $sname;
285: $c{'A'.$rownum} = shift(@exportdata);
286: foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
287: my $cell = $_.$rownum;
288: my $data = shift(@exportdata);
289: if (defined($data)) {
290: $f{$cell} = 'import';
291: $c{$cell} = $data;
292: }
293: }
294: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
295: 'last student');
296: }
297: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
298: $r->rflush();
299: $self->constants(\%c);
300: $self->formulas(\%f);
301: $self->calcsheet();
1.7 matthew 302: $self->save() if ($self->need_to_save());
1.1 matthew 303: }
304:
305: 1;
306:
307: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>