Annotation of loncom/interface/spreadsheet/classcalc.pm, revision 1.4
1.1 matthew 1: #
1.4 ! matthew 2: # $Id: classcalc.pm,v 1.3 2003/05/23 19:36:04 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:
1.3 matthew 61: sub html_header {
62: my $self = shift;
63: my ($toprow,$bottomrow);
64: foreach (['Sections','Section selector goes here'],
65: ['Enrollment Status',&Apache::lonhtmlcommon::StatusOptions(undef,undef,3)],
66: ['Output Format',&Apache::Spreadsheet::output_selector()]) {
67: my ($name,$selector) = @{$_};
68: $toprow .= '<th align="center"><b>'.$name.'</b></th>';
69: $bottomrow .= '<td>'.$selector.'</td>';
70: }
71: return "<p>\n<table>\n".
72: "<tr>".$toprow."</tr>\n".
73: "<tr>".$bottomrow."</tr>\n".
74: "</table>\n</p>";
75: }
76:
1.1 matthew 77: sub get_classlist {
78: my $self = shift;
79: # Retrieve the classlist
80: my @Students = ();
81: my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist
82: ($self->{'cid'},$self->{'cdom'},$self->{'cnum'});
83: while (my ($student,$student_data) = each (%$classlist)) {
84: my $studenthash = ();
85: for (my $i=0; $i< scalar(@$field_names);$i++) {
86: my $field = $field_names->[$i];
87: $studenthash->{$field}=$student_data->[$i];
88: }
89: # This is where we can skip students because they are in
90: # the wrong section, have expired or pending roles, whatever...
91: push (@Students,$studenthash);
92: }
93: my @SortedStudents = sort { $a->{'fullname'} cmp $b->{'fullname'} } @Students;
94: return @SortedStudents;
95: }
96:
97: sub get_title {
98: my $self = shift;
99: # Section info should be included
1.3 matthew 100: my @title = ($self->{'coursedesc'}, scalar(localtime(time)) );
101: return @title;
102: }
103:
104: sub get_html_title {
105: my $self = shift;
106: my ($classcalc_title,$time) = $self->get_title();
107: my $title = '<h1>'.$classcalc_title."</h1>\n".'<h3>'.$time."</h3>\n";
1.1 matthew 108: return $title;
109: }
110:
111: sub parent_link {
112: return '';
113: }
114:
115: sub outsheet_html {
116: my $self = shift;
117: my ($r) = @_;
118: ###################################
119: # Determine table structure
120: ###################################
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>
128: <td bgcolor="#FFDDDD" colspan="$num_uneditable">
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) {
137: $tableheader.='<th bgcolor="#FFDDDD">';
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>'.
150: $self->html_template_row($num_uneditable)."</tr>\n");
151: #
152: # Print out summary/export row
153: $r->print('<tr><td>Summary</td><td>0</td>'.
154: $self->html_export_row()."</tr>\n");
155: #
156: # Prepare to output rows
157: $tableheader =<<"END";
1.2 matthew 158: </p><p>
1.1 matthew 159: <table border="2">
160: <tr><th>Row</th>
161: <th>student</th><th>username</th><th>domain</th>
162: <th>section</th><th>status</th>
163: END
164: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
165: if ($label_num<$num_uneditable) {
166: $tableheader.='<th bgcolor="#FFDDDD">';
167: } else {
168: $tableheader.='<th>';
169: }
170: $tableheader.="<b><font size=+1>$_</font></b></th>";
171: }
172: #
173: my $num_output = 0;
174: foreach my $student ($self->get_classlist()) {
175: if ($num_output++ % 50 == 0) {
176: $r->print("</table>\n".$tableheader);
177: }
178: my $rownum = $self->get_row_number_from_key
179: ($student->{'username'}.':'.$student->{'domain'});
180: my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
181: '&sdomain='.$student->{'domain'}.'">';
182: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
183: $r->print('<tr>'.'<td>'.$rownum.'</td>'.
184: '<td>'.$link.$student->{'fullname'}.'</a></td>'.
185: '<td>'.$student->{'username'}.'</td>'.
186: '<td>'.$student->{'domain'} .'</td>'.
187: '<td>'.$student->{'section'} .'</td>'.
188: '<td>'.$student->{'status'} .'</td>'.
189: $self->html_row($num_uneditable,$rownum)."</tr>\n");
190: }
1.2 matthew 191: $r->print("</table></p>\n");
1.1 matthew 192: return;
193: }
194:
1.3 matthew 195: sub excel_rows {
196: # writes the meat of the spreadsheet to an excel worksheet. Called
197: # by Spreadsheet::outsheet_excel;
1.1 matthew 198: my $self = shift;
1.3 matthew 199: my ($worksheet,$cols_output,$rows_output) = @_;
200: #
201: # Write a header row
202: $cols_output = 0;
203: foreach my $value ('fullname','username','domain','section','status') {
204: $worksheet->write($rows_output,$cols_output++,$value);
205: }
206: $rows_output++;
207: #
208: # Write each students row
209: foreach my $student ($self->get_classlist()) {
210: $cols_output = 0;
211: my $rownum = $self->get_row_number_from_key
212: ($student->{'username'}.':'.$student->{'domain'});
213: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
214: my @studentdata = ($student->{'fullname'},
215: $student->{'username'},
216: $student->{'domain'},
217: $student->{'section'},
218: $student->{'status'});
219: $self->excel_output_row($worksheet,$rownum,$rows_output++,
220: @studentdata);
221: }
222: return;
1.1 matthew 223: }
224:
1.4 ! matthew 225: sub csv_rows {
! 226: # writes the meat of the spreadsheet to an excel worksheet. Called
! 227: # by Spreadsheet::outsheet_excel;
! 228: my $self = shift;
! 229: my ($filehandle) = @_;
! 230: #
! 231: # Write a header row
! 232:
! 233: $self->csv_output_row($filehandle,undef,
! 234: ('fullname','username','domain','section','status'));
! 235: #
! 236: # Write each students row
! 237: foreach my $student ($self->get_classlist()) {
! 238: my $rownum = $self->get_row_number_from_key
! 239: ($student->{'username'}.':'.$student->{'domain'});
! 240: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
! 241: my @studentdata = ($student->{'fullname'},
! 242: $student->{'username'},
! 243: $student->{'domain'},
! 244: $student->{'section'},
! 245: $student->{'status'});
! 246: $self->csv_output_row($filehandle,$rownum,@studentdata);
! 247: }
! 248: return;
! 249: }
1.3 matthew 250:
1.1 matthew 251: sub outsheet_recursive_excel {
252: my $self = shift;
253: my ($r) = @_;
254: }
255:
256: sub compute {
257: my $self = shift;
258: my ($r) = @_;
259: $self->initialize_safe_space();
260: my %c = $self->constants();
261: my %f = $self->formulas();
262: my @Students = $self->get_classlist();
263: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
264: ($r,'Spreadsheet Computation Status',
265: 'Spreadsheet Computation', scalar(@Students));
266: &Apache::studentcalc::initialize_package();
267: foreach my $student ($self->get_classlist()) {
268: my $sname = $student->{'username'}.':'.$student->{'domain'};
269: my $studentsheet = Apache::studentcalc->new
270: ($student->{'username'},$student->{'domain'},undef);
271: my @exportdata = $studentsheet->export_data();
272: my $rownum = $self->get_row_number_from_key($sname);
273: $f{'A'.$rownum} = $sname;
274: $self->{'row_source'}->{$rownum} = $sname;
275: $c{'A'.$rownum} = shift(@exportdata);
276: foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
277: my $cell = $_.$rownum;
278: my $data = shift(@exportdata);
279: if (defined($data)) {
280: $f{$cell} = 'import';
281: $c{$cell} = $data;
282: }
283: }
284: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
285: 'last student');
286: }
287: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
288: $r->rflush();
289: $self->constants(\%c);
290: $self->formulas(\%f);
291: $self->calcsheet();
292: }
293:
294: 1;
295:
296: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>