[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Tue, 05 Nov 2002 15:00:27 -0000
matthew Tue Nov 5 10:00:27 2002 EDT
Modified files:
/loncom/interface lonspreadsheet.pm
Log:
CSV download now works as it used to.
Removed debugging code from html_editable_cell.
Fixed bug which caused cells which had only whitespace as a value to be
uneditable.
Broke &format_rowlabel into
&format_html_rowlabel, &format_csv_rowlabel, and &format_plain_rowlabel
Added meat to &outsheet_csv (look at how short it is!)
Modified &outsheet to call &outsheet_csv or &outsheet_html
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.132 loncom/interface/lonspreadsheet.pm:1.133
--- loncom/interface/lonspreadsheet.pm:1.132 Mon Nov 4 17:35:45 2002
+++ loncom/interface/lonspreadsheet.pm Tue Nov 5 10:00:27 2002
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.132 2002/11/04 22:35:45 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.133 2002/11/05 15:00:27 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1149,11 +1149,6 @@
sub html_editable_cell {
my ($cell,$bgcolor) = @_;
my $result;
-# if (defined($cell)) {
-# &Apache::lonnet::logthis("cell ".$cell->{'name'}.
-# " = ".$cell->{'value'}.
-# " : ".$cell->{'formula'});
-# }
my ($name,$formula,$value);
if (defined($cell)) {
$name = $cell->{'name'};
@@ -1168,7 +1163,9 @@
$value = '<i>undefined value</i>';
}
}
- #
+ if ($value =~ /^\s*$/ ) {
+ $value = '<font color="'.$bgcolor.'">#</font>';
+ }
$result .= '<a href="javascript:celledit(\''.
$name.'\',\''.$formula.'\');">'.$value.'</a>';
return $result;
@@ -1231,7 +1228,7 @@
# Print out template row
####################################
my ($rowlabel,@rowdata) = &get_row($sheet,'-');
- my $row_html = '<tr><td>'.&format_rowlabel($rowlabel).'</td>';
+ my $row_html = '<tr><td>'.&format_html_rowlabel($rowlabel).'</td>';
my $num_cols_output = 0;
foreach my $cell (@rowdata) {
if ($num_cols_output++ < $num_uneditable) {
@@ -1250,7 +1247,7 @@
####################################
my ($rowlabel,@rowdata) = &get_row($sheet,'0');
my $rowcount = 0;
- $row_html = '<tr><td>'.&format_rowlabel($rowlabel).'</td>';
+ $row_html = '<tr><td>'.&format_html_rowlabel($rowlabel).'</td>';
$num_cols_output = 0;
foreach my $cell (@rowdata) {
if ($num_cols_output++ < 26) {
@@ -1281,11 +1278,11 @@
'</font></b></td>';
#
if ($sheet->{'sheettype'} eq 'classcalc') {
- $row_html.='<td>'.&format_rowlabel($rowlabel).'</td>';
+ $row_html.='<td>'.&format_html_rowlabel($rowlabel).'</td>';
# Output links for each student?
- # Nope, that is already done for us in format_rowlabel (for now)
+ # Nope, that is already done for us in format_html_rowlabel (for now)
} elsif ($sheet->{'sheettype'} eq 'studentcalc') {
- $row_html.='<td>'.&format_rowlabel($rowlabel);
+ $row_html.='<td>'.&format_html_rowlabel($rowlabel);
$row_html.= '<br>'.
'<select name="sel_'.$rownum.'" '.
'onChange="changesheet('.$rownum.')">'.
@@ -1299,7 +1296,7 @@
}
$row_html.='</select></td>';
} elsif ($sheet->{'sheettype'} eq 'assesscalc') {
- $row_html.='<td>'.&format_rowlabel($rowlabel).'</td>';
+ $row_html.='<td>'.&format_html_rowlabel($rowlabel).'</td>';
}
#
my $shown_cells = 0;
@@ -1354,6 +1351,28 @@
sub outsheet_csv {
my ($sheet,$r) = @_;
+ my $csvdata = '';
+ my @Values;
+ ####################################
+ # Prepare to output rows
+ ####################################
+ my @Rows = &sort_indicies($sheet);
+ #
+ # Loop through the rows and output them one at a time
+ my $rows_output=0;
+ foreach my $rownum (@Rows) {
+ my ($rowlabel,@rowdata) = &get_row($sheet,$rownum);
+ push (@Values,&format_csv_rowlabel($rowlabel));
+ foreach my $cell (@rowdata) {
+ push (@Values,'"'.$cell->{'value'}.'"');
+ }
+ $csvdata.= join(',',@Values)."\n";
+ @Values = ();
+ }
+ #
+ $r->print('<pre>'.$csvdata."\n</pre>");
+ #
+ return 1;
}
sub outsheet_excel {
@@ -1366,16 +1385,15 @@
sub outsheet {
my ($r,$sheet)=@_;
- &outsheet_html($sheet,$r);
-# if (exists($ENV{'form.csv'})) {
-# &outsheet_csv($sheet,$r);
+ if (exists($ENV{'form.showcsv'})) {
+ &outsheet_csv($sheet,$r);
# } elsif (exists($ENV{'form.excel'})) {
# &outsheet_excel($sheet,$r);
# } elsif (exists($ENV{'form.xml'})) {
# &outsheet_xml($sheet,$r);
-# } else {
-# &outsheet_html($sheet,$r);
-# }
+ } else {
+ &outsheet_html($sheet,$r);
+ }
}
########################################################################
@@ -1710,7 +1728,11 @@
return &Apache::lonnet::metadata($fn,$rwhat.'.default');
}
-sub format_rowlabel {
+
+##################################################################
+## Row label formatting routines ##
+##################################################################
+sub format_html_rowlabel {
my $rowlabel = shift;
return '' if ($rowlabel eq '');
my ($type,$labeldata) = split(':',$rowlabel,2);
@@ -1718,33 +1740,60 @@
if ($type eq 'symb') {
my ($symb,$uname,$udom,$title) = split(':',$labeldata);
$symb = &Apache::lonnet::unescape($symb);
- if ($ENV{'form.showcsv'}) {
- $result = $title;
- } else {
- $result = '<a href="/adm/assesscalc?usymb='.$symb.
- '&uname='.$uname.'&udom='.$udom.'">'.$title.'</a>';
- }
+ $result = '<a href="/adm/assesscalc?usymb='.$symb.
+ '&uname='.$uname.'&udom='.$udom.'">'.$title.'</a>';
+ } elsif ($type eq 'student') {
+ my ($sname,$sdom,$fullname,$section,$id) = split(':',$labeldata);
+ $result ='<a href="/adm/studentcalc?uname='.$sname.
+ '&udom='.$sdom.'">';
+ $result.=$section.' '.$id." ".$fullname.'</a>';
+ } elsif ($type eq 'parameter') {
+ $result = $labeldata;
+ } else {
+ $result = '<b><font size=+1>'.$rowlabel.'</font></b>';
+ }
+ return $result;
+}
+
+sub format_csv_rowlabel {
+ my $rowlabel = shift;
+ return '' if ($rowlabel eq '');
+ my ($type,$labeldata) = split(':',$rowlabel,2);
+ my $result = '';
+ if ($type eq 'symb') {
+ my ($symb,$uname,$udom,$title) = split(':',$labeldata);
+ $symb = &Apache::lonnet::unescape($symb);
+ $result = $title;
+ } elsif ($type eq 'student') {
+ my ($sname,$sdom,$fullname,$section,$id) = split(':',$labeldata);
+ $result = join('","',($sname,$sdom,$fullname,$section,$id));
+ } elsif ($type eq 'parameter') {
+ $labeldata =~ s/<br>/ /g;
+ $result = $labeldata;
+ } else {
+ $result = $rowlabel;
+ }
+ return '"'.$result.'"';
+}
+
+sub format_plain_rowlabel {
+ my $rowlabel = shift;
+ return '' if ($rowlabel eq '');
+ my ($type,$labeldata) = split(':',$rowlabel,2);
+ my $result = '';
+ if ($type eq 'symb') {
+ my ($symb,$uname,$udom,$title) = split(':',$labeldata);
+ $symb = &Apache::lonnet::unescape($symb);
+ $result = $title;
} elsif ($type eq 'student') {
my ($sname,$sdom,$fullname,$section,$id) = split(':',$labeldata);
- if ($ENV{'form.showcsv'}) {
$result = '"'.
join('","',($sname,$sdom,$fullname,$section,$id).'"');
- } else {
- $result ='<a href="/adm/studentcalc?uname='.$sname.
- '&udom='.$sdom.'">';
- $result.=$section.' '.$id." ".$fullname.'</a>';
- }
} elsif ($type eq 'parameter') {
- if ($ENV{'form.showcsv'}) {
- $labeldata =~ s/<br>/ /g;
- }
+ $labeldata =~ s/<br>/ /g;
$result = $labeldata;
} else {
- if ($ENV{'form.showcsv'}) {
- $result = $rowlabel;
- } else {
- $result = '<b><font size=+1>'.$rowlabel.'</font></b>';
- }
+ $result = $rowlabel;
}
return $result;
}