Annotation of loncom/interface/spreadsheet/classcalc.pm, revision 1.2
1.1 matthew 1: #
1.2 ! matthew 2: # $Id: classcalc.pm,v 1.1 2003/05/16 20:55:11 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;
54: use HTML::Entities();
55: use Spreadsheet::WriteExcel;
56: use Apache::lonnet;
57: use Time::HiRes;
58:
59: @Apache::classcalc::ISA = ('Apache::Spreadsheet');
60:
61: sub get_classlist {
62: my $self = shift;
63: # Retrieve the classlist
64: my @Students = ();
65: my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist
66: ($self->{'cid'},$self->{'cdom'},$self->{'cnum'});
67: while (my ($student,$student_data) = each (%$classlist)) {
68: my $studenthash = ();
69: for (my $i=0; $i< scalar(@$field_names);$i++) {
70: my $field = $field_names->[$i];
71: $studenthash->{$field}=$student_data->[$i];
72: }
73: # This is where we can skip students because they are in
74: # the wrong section, have expired or pending roles, whatever...
75: push (@Students,$studenthash);
76: }
77: my @SortedStudents = sort { $a->{'fullname'} cmp $b->{'fullname'} } @Students;
78: return @SortedStudents;
79: }
80:
81: sub get_title {
82: my $self = shift;
1.2 ! matthew 83: my $title = '<h1>'.$self->{'coursedesc'}."</h1>\n";
1.1 matthew 84: # Section info should be included
85: return $title;
86: }
87:
88: sub parent_link {
89: return '';
90: }
91:
92: sub outsheet_html {
93: my $self = shift;
94: my ($r) = @_;
95: ###################################
96: # Determine table structure
97: ###################################
98: my $num_uneditable = 26;
99: my $num_left = 52-$num_uneditable;
100: my $tableheader =<<"END";
1.2 ! matthew 101: <p>
1.1 matthew 102: <table border="2">
103: <tr>
104: <th colspan="2" rowspan="2"><font size="+2">Course</font></th>
105: <td bgcolor="#FFDDDD" colspan="$num_uneditable">
106: <b><font size="+1">Import</font></b></td>
107: <td colspan="$num_left">
108: <b><font size="+1">Calculations</font></b></td>
109: </tr><tr>
110: END
111: my $label_num = 0;
112: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
113: if ($label_num<$num_uneditable) {
114: $tableheader.='<th bgcolor="#FFDDDD">';
115: } else {
116: $tableheader.='<th>';
117: }
118: $tableheader.="<b><font size=+1>$_</font></b></th>";
119: $label_num++;
120: }
121: $tableheader.="</tr>\n";
122: #
123: $r->print($tableheader);
124: #
125: # Print out template row
126: $r->print('<tr><td>Template</td><td> </td>'.
127: $self->html_template_row($num_uneditable)."</tr>\n");
128: #
129: # Print out summary/export row
130: $r->print('<tr><td>Summary</td><td>0</td>'.
131: $self->html_export_row()."</tr>\n");
132: #
133: # Prepare to output rows
134: $tableheader =<<"END";
1.2 ! matthew 135: </p><p>
1.1 matthew 136: <table border="2">
137: <tr><th>Row</th>
138: <th>student</th><th>username</th><th>domain</th>
139: <th>section</th><th>status</th>
140: END
141: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
142: if ($label_num<$num_uneditable) {
143: $tableheader.='<th bgcolor="#FFDDDD">';
144: } else {
145: $tableheader.='<th>';
146: }
147: $tableheader.="<b><font size=+1>$_</font></b></th>";
148: }
149: #
150: my $num_output = 0;
151: foreach my $student ($self->get_classlist()) {
152: if ($num_output++ % 50 == 0) {
153: $r->print("</table>\n".$tableheader);
154: }
155: my $rownum = $self->get_row_number_from_key
156: ($student->{'username'}.':'.$student->{'domain'});
157: my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
158: '&sdomain='.$student->{'domain'}.'">';
159: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
160: $r->print('<tr>'.'<td>'.$rownum.'</td>'.
161: '<td>'.$link.$student->{'fullname'}.'</a></td>'.
162: '<td>'.$student->{'username'}.'</td>'.
163: '<td>'.$student->{'domain'} .'</td>'.
164: '<td>'.$student->{'section'} .'</td>'.
165: '<td>'.$student->{'status'} .'</td>'.
166: $self->html_row($num_uneditable,$rownum)."</tr>\n");
167: }
1.2 ! matthew 168: $r->print("</table></p>\n");
1.1 matthew 169: return;
170: }
171:
172: sub outsheet_csv {
173: my $self = shift;
174: my ($r) = @_;
175: }
176:
177: sub outsheet_excel {
178: my $self = shift;
179: my ($r) = @_;
180: }
181:
182: sub outsheet_recursive_excel {
183: my $self = shift;
184: my ($r) = @_;
185: }
186:
187: sub display {
188: my $self = shift;
189: my ($r) = @_;
190: $self->compute($r);
191: # display as html/csv/excel/etc....
192: $self->outsheet_html($r);
193: return;
194: }
195:
196: sub compute {
197: my $self = shift;
198: my ($r) = @_;
199: $self->initialize_safe_space();
200: my %c = $self->constants();
201: my %f = $self->formulas();
202: my @Students = $self->get_classlist();
203: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
204: ($r,'Spreadsheet Computation Status',
205: 'Spreadsheet Computation', scalar(@Students));
206: &Apache::studentcalc::initialize_package();
207: foreach my $student ($self->get_classlist()) {
208: my $sname = $student->{'username'}.':'.$student->{'domain'};
209: my $studentsheet = Apache::studentcalc->new
210: ($student->{'username'},$student->{'domain'},undef);
211: my @exportdata = $studentsheet->export_data();
212: my $rownum = $self->get_row_number_from_key($sname);
213: $f{'A'.$rownum} = $sname;
214: $self->{'row_source'}->{$rownum} = $sname;
215: $c{'A'.$rownum} = shift(@exportdata);
216: foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
217: my $cell = $_.$rownum;
218: my $data = shift(@exportdata);
219: if (defined($data)) {
220: $f{$cell} = 'import';
221: $c{$cell} = $data;
222: }
223: }
224: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
225: 'last student');
226: }
227: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
228: $r->rflush();
229: $self->constants(\%c);
230: $self->formulas(\%f);
231: $self->calcsheet();
232: }
233:
234: 1;
235:
236: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>