[LON-CAPA-cvs] cvs: loncom /interface/spreadsheet Spreadsheet.pm classcalc.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Fri, 21 Nov 2003 21:51:29 -0000
This is a MIME encoded message
--matthew1069451489
Content-Type: text/plain
matthew Fri Nov 21 16:51:29 2003 EDT
Modified files:
/loncom/interface/spreadsheet Spreadsheet.pm classcalc.pm
Log:
Added new output mode at the course level. It just displays the
students with a link to their spreadsheet. Reworked how output options
are handled to be able to vary them by spreadsheet. Reworked some confusing
(to me) localization code.
--matthew1069451489
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20031121165129.txt"
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.30 loncom/interface/spreadsheet/Spreadsheet.pm:1.31
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.30 Mon Nov 17 14:55:41 2003
+++ loncom/interface/spreadsheet/Spreadsheet.pm Fri Nov 21 16:51:28 2003
@@ -1,5 +1,5 @@
#
-# $Id: Spreadsheet.pm,v 1.30 2003/11/17 19:55:41 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.31 2003/11/21 21:51:28 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1190,16 +1190,24 @@
sub display {
my $self = shift;
my ($r) = @_;
- $self->compute($r);
my $outputmode = 'html';
- if ($ENV{'form.output_format'} =~ /^(html|excel|csv)$/) {
- $outputmode = $ENV{'form.output_format'};
+ foreach ($self->output_options()) {
+ if ($ENV{'form.output_format'} eq $_->{'value'}) {
+ $outputmode = $_->{'value'};
+ last;
+ }
}
if ($outputmode eq 'html') {
+ $self->compute($r);
$self->outsheet_html($r);
+ } elsif ($outputmode eq 'htmlclasslist') {
+ # No computation neccessary... This is kludgy
+ $self->outsheet_htmlclasslist($r);
} elsif ($outputmode eq 'excel') {
+ $self->compute($r);
$self->outsheet_excel($r);
} elsif ($outputmode eq 'csv') {
+ $self->compute($r);
$self->outsheet_csv($r);
}
$self->cleanup();
@@ -1336,11 +1344,24 @@
return '' if (! $ENV{'request.role.adv'});
return "<table>\n".
'<tr><th align="center">'.&mt('Output Format').'</th></tr>'."\n".
- '<tr><td>'.&output_selector()."</td></tr>\n".
+ '<tr><td>'.$self->output_selector()."</td></tr>\n".
"</table>\n";
}
+##
+## Default output types are HTML, Excel, and CSV
+sub output_options {
+ my $self = shift();
+ return ({value => 'html',
+ description => 'HTML'},
+ {value => 'excel',
+ description => 'Excel'},
+ {value => 'csv',
+ description => 'Comma Separated Values'},);
+}
+
sub output_selector {
+ my $self = shift();
my $output_selector = '<select name="output_format" size="3">'."\n";
my $default = 'html';
if (exists($ENV{'form.output_format'})) {
@@ -1348,15 +1369,12 @@
} else {
$ENV{'form.output_format'} = $default;
}
- foreach (['html','HTML'],
- ['excel','Excel'],
- ['csv','Comma Separated Values']) {
- my ($name,$description) = @{$_};
- $output_selector.=qq{<option value="$name"};
- if ($name eq $default) {
+ foreach ($self->output_options()) {
+ $output_selector.='<option value="'.$_->{'value'}.'"';
+ if ($_->{'value'} eq $default) {
$output_selector .= ' selected';
}
- $output_selector .= ">".&mt($description)."</option>\n";
+ $output_selector .= ">".&mt($_->{'description'})."</option>\n";
}
$output_selector .= "</select>\n";
return $output_selector;
@@ -1403,6 +1421,16 @@
#
# Determine the name to give the worksheet
return ($workbook,$filename);
+}
+
+#
+# This routine is just a stub
+sub outsheet_htmlclasslist {
+ my $self = shift;
+ my ($r) = @_;
+ $r->print('<h2>'.&mt("This output is not supported").'</h2>');
+ $r->rflush();
+ return;
}
sub outsheet_excel {
Index: loncom/interface/spreadsheet/classcalc.pm
diff -u loncom/interface/spreadsheet/classcalc.pm:1.15 loncom/interface/spreadsheet/classcalc.pm:1.16
--- loncom/interface/spreadsheet/classcalc.pm:1.15 Mon Nov 17 14:55:41 2003
+++ loncom/interface/spreadsheet/classcalc.pm Fri Nov 21 16:51:28 2003
@@ -1,5 +1,5 @@
#
-# $Id: classcalc.pm,v 1.15 2003/11/17 19:55:41 matthew Exp $
+# $Id: classcalc.pm,v 1.16 2003/11/21 21:51:28 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -85,7 +85,7 @@
&Apache::lonstatistics::clear_classlist_variables();
foreach (['Sections',&Apache::lonstatistics::SectionSelect('Section','multpile',3)],
['Enrollment Status',&Apache::lonhtmlcommon::StatusOptions(undef,undef,3)],
- ['Output Format',&Apache::Spreadsheet::output_selector()]) {
+ ['Output Format',$self->output_selector()]) {
my ($name,$selector) = @{$_};
$toprow .= '<th align="center"><b>'.&mt($name).'</b></th>';
$bottomrow .= '<td>'.$selector.'</td>';
@@ -128,25 +128,27 @@
my $exportcolor = '#BBBBFF';
my $num_uneditable = 26;
my $num_left = 52-$num_uneditable;
- my %lt=&Apache::lonlocal::texthash(
- 'co' => 'Course',
- 'im' => 'Import',
- 'ca' => 'Calculations',
- 'stu' => 'Student',
- 'sta' => 'Status',
- 'usr' => 'Username',
- 'dom' => 'Domain',
- 'sec' => 'Section',
- );
+ #
+ my %header=&Apache::lonlocal::texthash(
+ 'course' => 'Course',
+ 'import' => 'Import',
+ 'calculations' => 'Calculations',
+ 'student' => 'Student',
+ 'status' => 'Status',
+ 'username' => 'Username',
+ 'domain' => 'Domain',
+ 'section' => 'Section',
+ 'row' => 'Row',
+ );
my $tableheader =<<"END";
<p>
<table border="2">
<tr>
- <th colspan="2" rowspan="2"><font size="+2">$lt{'co'}</font></th>
+ <th colspan="2" rowspan="2"><font size="+2">$header{'course'}</font></th>
<td bgcolor="$importcolor" colspan="$num_uneditable">
- <b><font size="+1">$lt{'im'}</font></b></td>
+ <b><font size="+1">$header{'import'}</font></b></td>
<td colspan="$num_left">
- <b><font size="+1">$lt{'ca'}</font></b></td>
+ <b><font size="+1">$header{'calculations'}</font></b></td>
</tr><tr>
END
my $label_num = 0;
@@ -176,9 +178,12 @@
$tableheader =<<"END";
</p><p>
<table border="2">
-<tr><th>$lt{'ro'}</th>
- <th>$lt{'stu'}</th><th>$lt{'usr'}</th><th>$lt{'dom'}</th>
- <th>$lt{'sec'}</th><th>$lt{'sta'}</th>
+<tr><th>$header{'row'}</th>
+ <th>$header{'student'}</th>
+ <th>$header{'username'}</th>
+ <th>$header{'domain'}</th>
+ <th>$header{'section'}</th>
+ <th>$header{'status'}</th>
END
foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
if ($label_num<$num_uneditable) {
@@ -270,9 +275,71 @@
return;
}
+sub output_options {
+ my $self = shift();
+ return ({value => 'htmlclasslist',
+ description => 'Student Sheet Links'},
+ {value => 'html',
+ description => 'HTML'},
+ {value => 'excel',
+ description => 'Excel'},
+ {value => 'csv',
+ description => 'Comma Separated Values'},
+);
+}
+
sub outsheet_recursive_excel {
my $self = shift;
my ($r) = @_;
+}
+
+sub outsheet_htmlclasslist {
+ my $self = shift;
+ my ($r) = @_;
+ #
+ $r->print('<h3>'.
+ &mt('Click on a student to be taken to their spreadsheet').
+ '</h3>');
+ #
+ my %header=&Apache::lonlocal::texthash(
+ 'student' => 'Student',
+ 'status' => 'Status',
+ 'username' => 'Username',
+ 'domain' => 'Domain',
+ 'section' => 'Section',
+ );
+ #
+ # Prepare to output rows
+ my $tableheader =<<"END";
+</p><p>
+<table border="2">
+<tr>
+ <th>$header{'student'}</th>
+ <th>$header{'username'}</th>
+ <th>$header{'domain'}</th>
+ <th>$header{'section'}</th>
+ <th>$header{'status'}</th>
+</tr>
+END
+ #
+ my $num_output = 0;
+ foreach my $student (@Students) {
+ if ($num_output++ % 50 == 0) {
+ $r->print("</table>\n".$tableheader);
+ }
+ my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
+ '&sdomain='.$student->{'domain'}.'">';
+ $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
+ $r->print('<tr>'.
+ '<td>'.$link.$student->{'fullname'}.'</a></td>'.
+ '<td>'.$link.$student->{'username'}.'</a></td>'.
+ '<td>'.$student->{'domain'} .'</td>'.
+ '<td>'.$student->{'section'} .'</td>'.
+ '<td>'.$student->{'status'} .'</td>'.
+ "</tr>\n");
+ }
+ $r->print("</table></p>\n");
+ return;
}
sub compute {
--matthew1069451489--