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