--- loncom/interface/Attic/lonspreadsheet.pm 2002/11/04 22:35:45 1.132 +++ loncom/interface/Attic/lonspreadsheet.pm 2002/11/05 15:00:27 1.133 @@ -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 sort_indicies { 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 @@ sub html_editable_cell { $value = 'undefined value'; } } - # + if ($value =~ /^\s*$/ ) { + $value = '#'; + } $result .= ''.$value.''; return $result; @@ -1231,7 +1228,7 @@ END # Print out template row #################################### my ($rowlabel,@rowdata) = &get_row($sheet,'-'); - my $row_html = ''.&format_rowlabel($rowlabel).''; + my $row_html = ''.&format_html_rowlabel($rowlabel).''; my $num_cols_output = 0; foreach my $cell (@rowdata) { if ($num_cols_output++ < $num_uneditable) { @@ -1250,7 +1247,7 @@ END #################################### my ($rowlabel,@rowdata) = &get_row($sheet,'0'); my $rowcount = 0; - $row_html = ''.&format_rowlabel($rowlabel).''; + $row_html = ''.&format_html_rowlabel($rowlabel).''; $num_cols_output = 0; foreach my $cell (@rowdata) { if ($num_cols_output++ < 26) { @@ -1281,11 +1278,11 @@ END ''; # if ($sheet->{'sheettype'} eq 'classcalc') { - $row_html.=''.&format_rowlabel($rowlabel).''; + $row_html.=''.&format_html_rowlabel($rowlabel).''; # 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.=''.&format_rowlabel($rowlabel); + $row_html.=''.&format_html_rowlabel($rowlabel); $row_html.= '
'. ''; } elsif ($sheet->{'sheettype'} eq 'assesscalc') { - $row_html.=''.&format_rowlabel($rowlabel).''; + $row_html.=''.&format_html_rowlabel($rowlabel).''; } # my $shown_cells = 0; @@ -1354,6 +1351,28 @@ END 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('
'.$csvdata."\n
"); + # + return 1; } sub outsheet_excel { @@ -1366,16 +1385,15 @@ sub outsheet_xml { 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 @@ sub parmval { 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 @@ sub format_rowlabel { if ($type eq 'symb') { my ($symb,$uname,$udom,$title) = split(':',$labeldata); $symb = &Apache::lonnet::unescape($symb); - if ($ENV{'form.showcsv'}) { - $result = $title; - } else { - $result = ''.$title.''; - } + $result = ''.$title.''; + } elsif ($type eq 'student') { + my ($sname,$sdom,$fullname,$section,$id) = split(':',$labeldata); + $result =''; + $result.=$section.' '.$id." ".$fullname.''; + } elsif ($type eq 'parameter') { + $result = $labeldata; + } else { + $result = ''.$rowlabel.''; + } + 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/
/ /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 =''; - $result.=$section.' '.$id." ".$fullname.''; - } } elsif ($type eq 'parameter') { - if ($ENV{'form.showcsv'}) { - $labeldata =~ s/
/ /g; - } + $labeldata =~ s/
/ /g; $result = $labeldata; } else { - if ($ENV{'form.showcsv'}) { - $result = $rowlabel; - } else { - $result = ''.$rowlabel.''; - } + $result = $rowlabel; } return $result; }