File:
[LON-CAPA] /
loncom /
interface /
spreadsheet /
classcalc.pm
Revision
1.21:
download - view:
text,
annotated -
select for diffs
Tue Jun 8 15:55:38 2004 UTC (20 years, 4 months ago) by
matthew
Branches:
MAIN
CVS tags:
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
HEAD
Modified to use inline progress window.
1: #
2: # $Id: classcalc.pm,v 1.21 2004/06/08 15:55:38 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 warnings FATAL=>'all';
50: no warnings 'uninitialized';
51: use Apache::Constants qw(:common :http);
52: use Apache::loncoursedata();
53: use Apache::lonhtmlcommon();
54: use Apache::Spreadsheet;
55: use Apache::studentcalc;
56: use Apache::lonstatistics();
57: use HTML::Entities();
58: use Spreadsheet::WriteExcel;
59: use Apache::lonnet;
60: use Time::HiRes;
61: use Apache::lonlocal;
62:
63: @Apache::classcalc::ISA = ('Apache::Spreadsheet');
64:
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:
77: sub clear_package {
78: undef(@Students);
79: &Apache::studentcalc::clear_package();
80: }
81:
82: sub html_header {
83: my $self = shift;
84: my ($toprow,$bottomrow);
85: &Apache::lonstatistics::clear_classlist_variables();
86: foreach (['Sections',&Apache::lonstatistics::SectionSelect('Section','multpile',3)],
87: ['Enrollment Status',&Apache::lonhtmlcommon::StatusOptions(undef,undef,3)],
88: ['Output Format',$self->output_selector()]) {
89: my ($name,$selector) = @{$_};
90: $toprow .= '<th align="center"><b>'.&mt($name).'</b></th>';
91: $bottomrow .= '<td>'.$selector.'</td>';
92: }
93: my $status .= '<nobr>'.&mt('Status: [_1]',
94: '<input type="text" '.
95: 'name="spreadsheet_status" size="60" value="" />'
96: ).'</nobr>';
97:
98: return "<p>\n<table>\n".
99: "<tr>".$toprow."</tr>\n".
100: "<tr>".$bottomrow."</tr>\n".
101: "</table>\n".$status."\n".
102: "</p>";
103: }
104:
105: sub get_title {
106: my $self = shift;
107: # Section info should be included
108: my @title = ($self->{'coursedesc'}, &Apache::lonlocal::locallocaltime(time) );
109: return @title;
110: }
111:
112: sub get_html_title {
113: my $self = shift;
114: my ($classcalc_title,$time) = $self->get_title();
115: my $title = '<h1>'.$classcalc_title."</h1>\n".'<h3>'.$time."</h3>\n";
116: return $title;
117: }
118:
119: sub parent_link {
120: return '';
121: }
122:
123: sub outsheet_html {
124: my $self = shift;
125: my ($r) = @_;
126: ####################################
127: # Report any calculation errors #
128: ####################################
129: $r->print($self->html_report_error());
130: ###################################
131: # Determine table structure
132: ###################################
133: my $importcolor = '#88FF88';
134: my $exportcolor = '#BBBBFF';
135: my $num_uneditable = 26;
136: my $num_left = 52-$num_uneditable;
137: #
138: my %header=&Apache::lonlocal::texthash(
139: 'course' => 'Course',
140: 'import' => 'Import',
141: 'calculations' => 'Calculations',
142: 'student' => 'Student',
143: 'status' => 'Status',
144: 'username' => 'Username',
145: 'domain' => 'Domain',
146: 'section' => 'Section',
147: 'row' => 'Row',
148: );
149: my $tableheader =<<"END";
150: <p>
151: <table border="2">
152: <tr>
153: <th colspan="2" rowspan="2"><font size="+2">$header{'course'}</font></th>
154: <td bgcolor="$importcolor" colspan="$num_uneditable">
155: <b><font size="+1">$header{'import'}</font></b></td>
156: <td colspan="$num_left">
157: <b><font size="+1">$header{'calculations'}</font></b></td>
158: </tr><tr>
159: END
160: my $label_num = 0;
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: $label_num++;
169: }
170: $tableheader.="</tr>\n";
171: #
172: $r->print($tableheader);
173: #
174: # Print out template row
175: $r->print('<tr><td>'.&mt('Template').'</td><td> </td>'.
176: $self->html_template_row($num_uneditable,$importcolor).
177: "</tr>\n");
178: #
179: # Print out summary/export row
180: $r->print('<tr><td>'.&mt('Summary').'</td><td>0</td>'.
181: $self->html_export_row($exportcolor)."</tr>\n");
182: #
183: # Prepare to output rows
184: $tableheader =<<"END";
185: </p><p>
186: <table border="2">
187: <tr><th>$header{'row'}</th>
188: <th>$header{'student'}</th>
189: <th>$header{'username'}</th>
190: <th>$header{'domain'}</th>
191: <th>$header{'section'}</th>
192: <th>$header{'status'}</th>
193: END
194: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
195: if ($label_num<$num_uneditable) {
196: $tableheader.='<th bgcolor="'.$importcolor.'">';
197: } else {
198: $tableheader.='<th>';
199: }
200: $tableheader.="<b><font size=+1>$_</font></b></th>";
201: }
202: #
203: my $num_output = 0;
204: foreach my $student (@Students) {
205: if ($num_output++ % 50 == 0) {
206: $r->print("</table>\n".$tableheader);
207: }
208: my $rownum = $self->get_row_number_from_key
209: ($student->{'username'}.':'.$student->{'domain'});
210: my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
211: '&sdomain='.$student->{'domain'}.'">';
212: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
213: $r->print('<tr>'.'<td>'.$rownum.'</td>'.
214: '<td>'.$student->{'fullname'}.'</td>'.
215: '<td>'.$link.$student->{'username'}.'</a></td>'.
216: '<td>'.$student->{'domain'} .'</td>'.
217: '<td>'.$student->{'section'} .'</td>'.
218: '<td>'.$student->{'status'} .'</td>'.
219: $self->html_row($num_uneditable,$rownum,$exportcolor,
220: $importcolor).
221: "</tr>\n");
222: }
223: $r->print("</table></p>\n");
224: return;
225: }
226:
227: sub excel_rows {
228: # writes the meat of the spreadsheet to an excel worksheet. Called
229: # by Spreadsheet::outsheet_excel;
230: my $self = shift;
231: my ($connection,$worksheet,$cols_output,$rows_output) = @_;
232: #
233: # Write a header row
234: $cols_output = 0;
235: foreach my $value ('Fullname','Username','Domain','Section','Status','ID') {
236: $worksheet->write($rows_output,$cols_output++,&mt($value));
237: }
238: $rows_output++;
239: #
240: # Write each students row
241: foreach my $student (@Students) {
242: $cols_output = 0;
243: my $rownum = $self->get_row_number_from_key
244: ($student->{'username'}.':'.$student->{'domain'});
245: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
246: my @studentdata = ($student->{'fullname'},
247: $student->{'username'},
248: $student->{'domain'},
249: $student->{'section'},
250: $student->{'status'},
251: $student->{'id'});
252: $self->excel_output_row($worksheet,$rownum,$rows_output++,
253: @studentdata);
254: }
255: return;
256: }
257:
258: sub csv_rows {
259: # writes the meat of the spreadsheet to an excel worksheet. Called
260: # by Spreadsheet::outsheet_excel;
261: my $self = shift;
262: my ($connection,$filehandle) = @_;
263: #
264: # Write a header row
265: $self->csv_output_row($filehandle,undef,
266: (&mt('Fullname'),&mt('Username'),&mt('Domain'),&mt('Section'),&mt('Status'),&mt('ID')));
267: #
268: # Write each students row
269: foreach my $student (@Students) {
270: my $rownum = $self->get_row_number_from_key
271: ($student->{'username'}.':'.$student->{'domain'});
272: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
273: my @studentdata = ($student->{'fullname'},
274: $student->{'username'},
275: $student->{'domain'},
276: $student->{'section'},
277: $student->{'status'},
278: $student->{'id'});
279: $self->csv_output_row($filehandle,$rownum,@studentdata);
280: }
281: return;
282: }
283:
284: sub output_options {
285: my $self = shift();
286: return ({value => 'htmlclasslist',
287: description => 'Student Sheet Links'},
288: {value => 'html',
289: description => 'HTML'},
290: {value => 'excel',
291: description => 'Excel'},
292: {value => 'csv',
293: description => 'Comma Separated Values'},
294: # {value => 'xml',
295: # description => 'XML'},
296: );
297: }
298:
299: sub outsheet_recursive_excel {
300: my $self = shift;
301: my ($r) = @_;
302: }
303:
304: sub outsheet_htmlclasslist {
305: my $self = shift;
306: my ($r) = @_;
307: #
308: # Determine if we should output expire caches links...
309: my $show_expire_link = 0;
310: if (exists($ENV{'user.role.dc./'.$ENV{'request.role.domain'}.'/'})){
311: $show_expire_link = 1;
312: }
313: #
314: if ($show_expire_link) {
315: $r->print('<a href="/adm/classcalc?output_format=htmlclasslist&'.
316: 'recalc=ilovewastingtime¬_first_run=1">'.
317: &mt('Expire all student spreadsheets').'</a>'.$/);
318: }
319: #
320: $r->print('<h3>'.
321: &mt('Click on a student to be taken to their spreadsheet').
322: '</h3>');
323: #
324: my %header=&Apache::lonlocal::texthash(
325: 'student' => 'Student',
326: 'status' => 'Status',
327: 'username' => 'Username',
328: 'domain' => 'Domain',
329: 'section' => 'Section',
330: );
331: #
332: # Prepare to output rows
333: my $tableheader =<<"END";
334: </p><p>
335: <table border="2">
336: <tr>
337: <th></th>
338: <th>$header{'student'}</th>
339: <th>$header{'username'}</th>
340: <th>$header{'domain'}</th>
341: <th>$header{'section'}</th>
342: <th>$header{'status'}</th>
343: END
344: if ($show_expire_link) {
345: $tableheader.= '<th> </th>';
346: }
347: $tableheader.= "</tr>\n";
348: #
349: my $num_output = 0;
350: foreach my $student (@Students) {
351: if ($num_output++ % 50 == 0) {
352: $r->print("</table>\n".$tableheader);
353: }
354: my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
355: '&sdomain='.$student->{'domain'}.'">';
356: $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
357: $r->print('<tr>'.
358: '<td>'.$num_output.'</td>'.
359: '<td>'.$link.$student->{'fullname'}.'</a></td>'.
360: '<td>'.$link.$student->{'username'}.'</a></td>'.
361: '<td>'.$student->{'domain'} .'</td>'.
362: '<td>'.$student->{'section'} .'</td>'.
363: '<td>'.$student->{'status'} .'</td>');
364: if ($show_expire_link) {
365: $r->print('<td>'.
366: '<a href="/adm/classcalc?recalc=student:'.
367: $student->{'username'}.':'.$student->{'domain'}.'&'.
368: 'output_format=htmlclasslist&'.
369: 'not_first_run=1'.'">Expire Record</a>'.$/);
370: }
371: $r->print("</tr>\n");
372: }
373: $r->print("</table></p>\n");
374: return;
375: }
376:
377: sub update_status {
378: my ($r,$message) = @_;
379: $r->print('<script>'.
380: 'window.document.sheet.spreadsheet_status.value="'.
381: $message.
382: '";</script>');
383: $r->rflush();
384: return;
385: }
386:
387: sub compute {
388: my $self = shift;
389: my ($r) = @_;
390: my $connection = $r->connection();
391: if ($connection->aborted()) { $self->cleanup(); return; }
392: $self->initialize_safe_space();
393: my %c = $self->constants();
394: my %f = $self->formulas();
395: &update_status($r,'Initializing Course Structure');
396: &Apache::studentcalc::initialize_package();
397: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
398: ($r,&mt('Spreadsheet Computation Status'),
399: &mt('Spreadsheet Computation'), scalar(@Students),'inline',undef,
400: 'sheet','spreadsheet_status');
401: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
402: &mt('Processing first student'));
403: foreach my $student (@Students) {
404: if ($connection->aborted()) { $self->cleanup(); return; }
405: my $sname = $student->{'username'}.':'.$student->{'domain'};
406: my $studentsheet = Apache::studentcalc->new
407: ($student->{'username'},$student->{'domain'},undef);
408: if ($connection->aborted()) { $self->cleanup(); return; }
409: my @exportdata = $studentsheet->export_data($r);
410: if ($studentsheet->badcalc()) {
411: $self->set_calcerror($sname.' : '.
412: $studentsheet->calcerror());
413: }
414: if ($connection->aborted()) { $self->cleanup(); return; }
415: my $rownum = $self->get_row_number_from_key($sname);
416: $f{'A'.$rownum} = $sname;
417: $self->{'row_source'}->{$rownum} = $sname;
418: $c{'A'.$rownum} = shift(@exportdata);
419: foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
420: my $cell = $_.$rownum;
421: my $data = shift(@exportdata);
422: if (defined($data)) {
423: $f{$cell} = 'import';
424: $c{$cell} = $data;
425: }
426: }
427: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
428: 'last student');
429: }
430: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
431: &update_status($r,'Done computing student sheets');
432: $r->rflush();
433: $self->constants(\%c);
434: $self->formulas(\%f);
435: $self->calcsheet();
436: $self->save() if ($self->need_to_save());
437: &update_status($r,'Done!');
438: }
439:
440: 1;
441:
442: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>