[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 04 Nov 2002 22:35:45 -0000


This is a MIME encoded message

--matthew1036449345
Content-Type: text/plain

matthew		Mon Nov  4 17:35:45 2002 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm 
  Log:
  Major changes:
  Outputting of the spreadsheet is beginning to be broken up into smaller
  pieces.  HTML output works as best as I can test it.  The function
  &outsheet was added to handle the calling of the proper output function for
  the requested target.  Currently &outsheet_html is the only implemented option.
  *** This means CSV output is broken in this commit ***  If this affects you,
  you are me.
  The function &rown has been removed and given a respectful burial.
  &getrow was reworked to call &templaterow, &outrowassess, and &outrow.
  Each of the functions &templaterow, &outrowassess, and &outrow have been
  modified to return a row label (colon seperated string) and an array of
  hash pointers which describe the cells (name,formula, and value).
  Sorting of the rows of the spreadsheet has been moved to &sort_indicies.
  &format_rowlabel was modified to deal with 'template' and 'export' rows 
  without incident.
  
  Some debugging code has been added (and commented out).
  
  Bug Fix: &mask had an error introduced in it during a minor change -
  doing 
  
  ($v1,$v2)=($f=~/(regexpA)(regexpB)/);
  ($v3,$v4)=($g=~/(regexpA)(regexpB)/);
  
  is not the same as doing:
  
  $f=~/(regexpA)(regexpB)/;
  ($v1,$v2)=($1,$2);
  $g=~/(regexpA)(regexpB)/;
  ($v3,$v4)=($1,$2);
  
  Because in the second case if $g is undefined its pattern match does not 
  occur and the variables $1 and $2 retain their values from the pattern match
  on $f.  Perl is rather devious at times....
  
  
  
--matthew1036449345
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20021104173545.txt"

Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.131 loncom/interface/lonspreadsheet.pm:1.132
--- loncom/interface/lonspreadsheet.pm:1.131	Wed Oct 30 10:07:20 2002
+++ loncom/interface/lonspreadsheet.pm	Mon Nov  4 17:35:45 2002
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.131 2002/10/30 15:07:20 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.132 2002/11/04 22:35:45 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -122,6 +122,7 @@
 ##
 sub mask {
     my ($lower,$upper)=@_;
+    $upper = $lower if (! defined($upper));
     #
     my ($la,$ld) = ($lower=~/([A-Za-z]|\*)(\d+|\*)/);
     my ($ua,$ud) = ($upper=~/([A-Za-z]|\*)(\d+|\*)/);
@@ -130,9 +131,8 @@
     my $num='';
     #
     if (($la eq '*') || ($ua eq '*')) {
-       $alpha='[A-Za-z]';
+        $alpha='[A-Za-z]';
     } else {
-        
        if (($la=~/[A-Z]/) && ($ua=~/[A-Z]/) ||
            ($la=~/[a-z]/) && ($ua=~/[a-z]/)) {
           $alpha='['.$la.'-'.$ua.']';
@@ -194,8 +194,6 @@
     return '^'.$alpha.$num."\$";
 }
 
-
-
 sub initsheet {
     my $safeeval = new Safe(shift);
     my $safehole = new Safe::Hole;
@@ -238,6 +236,7 @@
     # the spreadsheets that are available for the assessment sheet.
     # Set by &setothersheets.  &setothersheets is called by &handler.  A
     # related subroutine is &othersheets.
+#$errorlog = '';
 
 $maxrow = 0;
 $sheettype = '';
@@ -591,7 +590,8 @@
 #-------------------------------------------------------
 sub MEAN {
     my $mask=mask(@_);
-    my $sum=0; my $num=0;
+    my $sum=0; 
+    my $num=0;
     foreach (grep /$mask/,keys(%sheet_values)) {
         $sum+=$sheet_values{$_};
         $num++;
@@ -926,6 +926,7 @@
     while ($notfinished) {
 	$notfinished=0;
         foreach (keys(%t)) {
+            #$errorlog .= "$_:".$t{$_};
             my $old=$sheet_values{$_};
             $sheet_values{$_}=eval $t{$_};
 	    if ($@) {
@@ -933,6 +934,7 @@
                 return $_.': '.$@;
             }
 	    if ($sheet_values{$_} ne $old) { $notfinished=1; $lastcalc=$_; }
+            #$errorlog .= ":".$sheet_values{$_}."\n";
         }
         $depth++;
         if ($depth>100) {
@@ -950,54 +952,39 @@
 }
 
 #
-#
+# 
 #
 sub templaterow {
     my $sheet = shift;
     my @cols=();
-    $cols[0]='<b><font size=+1>Template</font></b>';
+    my $rowlabel = 'Template';
     foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
 	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
 	     'a','b','c','d','e','f','g','h','i','j','k','l','m',
 	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
         my $fm=$sheet->{'f'}->{'template_'.$_};
         $fm=~s/[\'\"]/\&\#34;/g;
-        push(@cols,"'template_$_','$fm'".'___eq___'.$fm);
+        push(@cols,{ name    => 'template_'.$_,
+                     formula => $fm,
+                     value   => $fm });
     }
-    return @cols;
+    return ($rowlabel,@cols);
 }
 
-
 sub outrowassess {
     # $n is the current row number
-    my $sheet = shift;
-    my $n=shift; 
-    my $csv = $ENV{'form.showcsv'};
+    my ($sheet,$n) = @_;
     my @cols=();
+    my $rowlabel='';
     if ($n) {
         my ($usy,$ufn)=split(/__&&&\__/,$sheet->{'f'}->{'A'.$n});
-        if ($sheet->{'rowlabel'}->{$usy}) {
-            $cols[0]=&format_rowlabel($sheet->{'rowlabel'}->{$usy});
-            if (! $csv) {
-                $cols[0].='<br>'.
-                '<select name="sel_'.$n.'" onChange="changesheet('.$n.')">'.
-                    '<option name="default">Default</option>';
-            }
+        if (exists($sheet->{'rowlabel'}->{$usy})) {
+            $rowlabel = $sheet->{'rowlabel'}->{$usy};
         } else { 
-            $cols[0]=''; 
-        }
-        if (! $csv) {
-            foreach (@{$sheet->{'othersheets'}}) {
-                $cols[0].='<option name="'.$_.'"';
-                if ($ufn eq $_) {
-                    $cols[0].=' selected';
-                }
-                $cols[0].='>'.$_.'</option>';
-            }
-            $cols[0].='</select>';
+            $rowlabel = '';
         }
     } else {
-        $cols[0]='<b><font size=+1>Export</font></b>';
+        $rowlabel = 'Export';
     }
     foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
 	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
@@ -1005,19 +992,25 @@
 	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
         my $fm=$sheet->{'f'}->{$_.$n};
         $fm=~s/[\'\"]/\&\#34;/g;
-        push(@cols,"'$_$n','$fm'".'___eq___'.$sheet->{'values'}->{$_.$n});
+        push(@cols,{ name    => $_.$n,
+                     formula => $fm,
+                     value   => $sheet->{'values'}->{$_.$n}});
     }
-    return @cols;
+    return ($rowlabel,@cols);
 }
 
 sub outrow {
-    my $sheet=shift;
-    my $n=shift;
+    my ($sheet,$n)=@_;
     my @cols=();
+    my $rowlabel;
     if ($n) {
-        $cols[0]=&format_rowlabel($sheet->{'rowlabel'}->{$sheet->{'f'}->{'A'.$n}});
+        $rowlabel = $sheet->{'rowlabel'}->{$sheet->{'f'}->{'A'.$n}};
     } else {
-       $cols[0]='<b><font size=+1>Export</font></b>';
+        if ($sheet->{'sheettype'} eq 'classcalc') {
+            $rowlabel = 'Summary';
+        } else {
+            $rowlabel = 'Export';
+        }
     }
     foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
 	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
@@ -1025,9 +1018,11 @@
 	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
         my $fm=$sheet->{'f'}->{$_.$n};
         $fm=~s/[\'\"]/\&\#34;/g;
-        push(@cols,"'$_$n','$fm'".'___eq___'.$sheet->{'values'}->{$_.$n});
+        push(@cols,{ name    => $_.$n,
+                     formula => $fm,
+                     value   => $sheet->{'values'}->{$_.$n}});
     }
-    return @cols;
+    return ($rowlabel,@cols);
 }
 
 # ------------------------------------------------ Add or change formula values
@@ -1083,6 +1078,11 @@
     return %{$sheet->{'safe'}->varglob('f')};
 }
 
+sub geterrorlog {
+    my $sheet = shift;
+    return ${$sheet->{'safe'}->varglob('errorlog')};    
+}
+
 # ----------------------------------------------------- Get value of $f{'A'.$n}
 sub getfa {
     my $sheet = shift;
@@ -1113,176 +1113,273 @@
 #
 # --------------------------------------------- Produce output row n from sheet
 
-sub rown {
-    my ($sheet,$n)=@_;
-    my $defaultbg;
-    my $rowdata='';
-    my $dataflag=0;
-    unless ($n eq '-') {
-        $defaultbg=((($n-1)/5)==int(($n-1)/5))?'#E0E0':'#FFFF';
-    } else {
-        $defaultbg='#E0FF';
-    }
-    unless ($ENV{'form.showcsv'}) {
-        $rowdata.="\n<tr><td><b><font size=+1>$n</font></b></td>";
-    } else {
-        $rowdata.="\n".'"'.$n.'"';
-    }
-    my $showf=0;
-    #
-    # Determine how many pink (uneditable) cells there are in this sheet.
-    my $maxred=1;
-    my $sheettype=$sheet->{'sheettype'};
-    if ($sheettype eq 'studentcalc') {
-        $maxred=26;
-    } elsif ($sheettype eq 'assesscalc') {
-        $maxred=1;
-    } else {
-        $maxred=26;
-    }
-    $maxred=1 if (&getfa($sheet,$n)=~/^[\~\-]/);
-    #
-    # Get the proper row
-    my @rowdata;
+sub get_row {
+    my ($sheet,$n) = @_;
+    my ($rowlabel,@rowdata);
     if ($n eq '-') { 
-        @rowdata = &templaterow($sheet);
-        $n=-1; 
-        $dataflag=1; 
-    } elsif ($sheettype eq 'studentcalc') {
-        @rowdata = &outrowassess($sheet,$n);
-    } else {
-        @rowdata = &outrow($sheet,$n);
-    }
-    #
-    foreach (@rowdata) {
-        my $bgcolor=$defaultbg.((($showf-1)/5==int(($showf-1)/5))?'99':'DD');
-        my ($fm,$vl)=split(/\_\_\_eq\_\_\_/,$_);
-        if ((($vl ne '') || ($vl eq '0')) &&
-            (($showf==1) || ($sheettype ne 'studentcalc'))) { $dataflag=1; }
-        if ($showf==0) { $vl=$_; }
-        unless ($ENV{'form.showcsv'}) {
-            if ($showf<=$maxred) { $bgcolor='#FFDDDD'; }
-            if (($n==0) && ($showf<=26)) { $bgcolor='#CCCCFF'; } 
-            if (($showf>$maxred) || ((!$n) && ($showf>0))) {
-                if ($vl eq '') {
-                    $vl='<font size=+2 color='.$bgcolor.'>&#35;</font>';
-                }
-                $rowdata.='<td bgcolor='.$bgcolor.'>';
-                if ($ENV{'request.role'} =~ /^st\./) {
-                    $rowdata.=$vl;
-                } else {
-                    $rowdata.='<a href="javascript:celledit('.$fm.');">'.
-                        $vl.'</a>';
-                }
-                $rowdata.='</td>';
-            } else {
-                $rowdata.='<td bgcolor='.$bgcolor.'>&nbsp;'.$vl.'&nbsp;</td>';
-            }
-        } else {
-            $rowdata.=',"'.$vl.'"';
-        }
-        $showf++;
-    }  # End of foreach($safeval...)
-    if ($ENV{'form.showall'} || ($dataflag)) {
-        return $rowdata.($ENV{'form.showcsv'}?'':'</tr>');
+        ($rowlabel,@rowdata) = &templaterow($sheet);
+    } elsif ($sheet->{'sheettype'} eq 'studentcalc') {
+        ($rowlabel,@rowdata) = &outrowassess($sheet,$n);
     } else {
-        return '';
+        ($rowlabel,@rowdata) = &outrow($sheet,$n);
     }
+    return ($rowlabel,@rowdata);
 }
 
-# ------------------------------------------------------------- Print out sheet
-
-sub outsheet {
-    my ($r,$sheet)=@_;
-    my $maxred = 26;    # The maximum number of cells to show as 
-                        # red (uneditable) 
-                        # To make student sheets uneditable could we 
-                        # set $maxred = 52?
-                        #
-    my $realm='Course'; # 'assessment', 'user', or 'course' sheet
-    if ($sheet->{'sheettype'} eq 'assesscalc') {
-        $maxred=1;
-        $realm='Assessment';
-    } elsif ($sheet->{'sheettype'} eq 'studentcalc') {
-        $maxred=26;
-        $realm='User';
-    }
-    #
-    # Column label
-    my $tabledata;
-    if ($ENV{'form.showcsv'}) {
-        $tabledata='<pre>';
-    } else { 
-        $tabledata='<table border=2><tr><th colspan=2 rowspan=2>'.
-            '<font size=+2>'.$realm.'</font></th>'.
-                  '<td bgcolor=#FFDDDD colspan='.$maxred.
-                  '><b><font size=+1>Import</font></b></td>'.
-                  '<td colspan='.(52-$maxred).
-		  '><b><font size=+1>Calculations</font></b></td></tr><tr>';
-        my $showf=0;
-        foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
-                 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
-                 'a','b','c','d','e','f','g','h','i','j','k','l','m',
-                 'n','o','p','q','r','s','t','u','v','w','x','y','z') {
-            $showf++;
-            if ($showf<=$maxred) { 
-                $tabledata.='<td bgcolor="#FFDDDD">'; 
-            } else {
-                $tabledata.='<td>';
-            }
-            $tabledata.="<b><font size=+1>$_</font></b></td>";
-        }
-        $tabledata.='</tr>'.&rown($sheet,'-').
-            &rown($sheet,0);
-    }
-    $r->print($tabledata);
-    #
-    # Prepare to output rows
-    my $row;
+########################################################################
+########################################################################
+sub sort_indicies {
+    my $sheet = shift;
     #
     # Sort the rows in some manner
     #
     my @sortby=();
     my @sortidx=();
-    for ($row=1;$row<=$sheet->{'maxrow'};$row++) {
+    for (my $row=1;$row<=$sheet->{'maxrow'};$row++) {
         push (@sortby, $sheet->{'safe'}->reval('$f{"A'.$row.'"}'));
-        push (@sortidx, $row-1);
+        push (@sortidx, $row);
     }
     @sortidx=sort { lc($sortby[$a]) cmp lc($sortby[$b]); } @sortidx;
+    return @sortidx;
+}
+
+########################################################################
+########################################################################
+
+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'};
+        $formula = $cell->{'formula'};
+        $value   = $cell->{'value'};
+    }
+    $name    = '' if (! defined($name));
+    $formula = '' if (! defined($formula));
+    if (! defined($value)) {
+        $value = '<font color="'.$bgcolor.'">#</font>';
+        if ($formula ne '') {
+            $value = '<i>undefined value</i>';
+        }
+    }
     #
-    # Determine the type of child spreadsheets
-    my $what='Student';
+    $result .= '<a href="javascript:celledit(\''.
+        $name.'\',\''.$formula.'\');">'.$value.'</a>';
+    return $result;
+}
+
+sub html_uneditable_cell {
+    my ($cell,$bgcolor) = @_;
+    my $value = (defined($cell) ? $cell->{'value'} : '');
+    return '&nbsp;'.$value.'&nbsp;';
+}
+
+########################################################################
+########################################################################
+
+sub outsheet_html  {
+    my ($sheet,$r) = @_;
+    my ($num_uneditable,$realm,$row_type);
     if ($sheet->{'sheettype'} eq 'assesscalc') {
-        $what='Item';
+        $num_uneditable = 1;
+        $realm = 'Assessment';
+        $row_type = 'Item';
     } elsif ($sheet->{'sheettype'} eq 'studentcalc') {
-        $what='Assessment';
+        $num_uneditable = 26;
+        $realm = 'User';
+        $row_type = 'Assessment';
+    } elsif ($sheet->{'sheettype'} eq 'classcalc') {
+        $num_uneditable = 26;
+        $realm = 'Course';
+        $row_type = 'Student';
+    } else {
+        return;  # error
+    }
+    ####################################
+    # Print out header table
+    ####################################
+    my $num_left = 52-$num_uneditable;
+    my $tabledata =<<"END";
+<table border="2">
+<tr>
+  <th colspan="1" rowspan="2"><font size="+2">$realm</font></th>
+  <td bgcolor="#FFDDDD" colspan="$num_uneditable">
+      <b><font size="+1">Import</font></b></td>
+  <td colspan="$num_left">
+      <b><font size="+1">Calculations</font></b></td>
+</tr><tr>
+END
+    my $label_num = 0;
+    foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
+        if ($label_num<$num_uneditable) { 
+            $tabledata.='<td bgcolor="#FFDDDD">';
+        } else {
+            $tabledata.='<td>';
+        }
+        $tabledata.="<b><font size=+1>$_</font></b></td>";
+        $label_num++;
     }
+    $tabledata.="</tr>\n";
+    $r->print($tabledata);
+    ####################################
+    # Print out template row
+    ####################################
+    my ($rowlabel,@rowdata) = &get_row($sheet,'-');
+    my $row_html = '<tr><td>'.&format_rowlabel($rowlabel).'</td>';
+    my $num_cols_output = 0;
+    foreach my $cell (@rowdata) {
+        if ($num_cols_output++ < $num_uneditable) {
+            $row_html .= '<td bgcolor="#FFDDDD">';
+            $row_html .= &html_uneditable_cell($cell,'#FFDDDD');
+        } else {
+            $row_html .= '<td bgcolor="#EOFFDD">';
+            $row_html .= &html_editable_cell($cell,'#E0FFDD');
+        }
+        $row_html .= '</td>';
+    }
+    $row_html.= "</tr>\n";
+    $r->print($row_html);
+    ####################################
+    # Print out summary/export row
+    ####################################
+    my ($rowlabel,@rowdata) = &get_row($sheet,'0');
+    my $rowcount = 0;
+    $row_html = '<tr><td>'.&format_rowlabel($rowlabel).'</td>';
+    $num_cols_output = 0;
+    foreach my $cell (@rowdata) {
+        if ($num_cols_output++ < 26) {
+            $row_html .= '<td bgcolor="#CCCCFF">';
+            $row_html .= &html_editable_cell($cell,'#CCCCFF');
+        } else {
+            $row_html .= '<td bgcolor="#DDCCFF">';
+            $row_html .= &html_uneditable_cell(undef,'#CCCCFF');
+        }
+        $row_html .= '</td>';
+    }
+    $row_html.= "</tr>\n";
+    $r->print($row_html);
+    $r->print('</table>');
+    ####################################
+    # Prepare to output rows
+    ####################################
+    my @Rows = &sort_indicies($sheet);
     #
     # Loop through the rows and output them one at a time
-    my $n=0;
-    for ($row=0;$row<$sheet->{'maxrow'};$row++) {
-        my $thisrow=&rown($sheet,$sortidx[$row]+1);
-        if ($thisrow) {
-            if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) {
+    my $rows_output=0;
+    foreach my $rownum (@Rows) {
+        my ($rowlabel,@rowdata) = &get_row($sheet,$rownum);
+        #
+        my $defaultbg='#E0FF';
+        #
+        my $row_html ="\n".'<tr><td><b><font size=+1>'.$rownum.
+            '</font></b></td>';
+        #
+        if ($sheet->{'sheettype'} eq 'classcalc') {
+            $row_html.='<td>'.&format_rowlabel($rowlabel).'</td>';
+            # Output links for each student?
+            # Nope, that is already done for us in format_rowlabel (for now)
+        } elsif ($sheet->{'sheettype'} eq 'studentcalc') {
+            $row_html.='<td>'.&format_rowlabel($rowlabel);
+            $row_html.= '<br>'.
+                '<select name="sel_'.$rownum.'" '.
+                    'onChange="changesheet('.$rownum.')">'.
+                        '<option name="default">Default</option>';
+            foreach (@{$sheet->{'othersheets'}}) {
+                $row_html.='<option name="'.$_.'"';
+                #if ($ufn eq $_) {
+                #    $row_html.=' selected';
+                #}
+                $row_html.='>'.$_.'</option>';
+            }
+            $row_html.='</select></td>';
+        } elsif ($sheet->{'sheettype'} eq 'assesscalc') {
+            $row_html.='<td>'.&format_rowlabel($rowlabel).'</td>';
+        }
+        #
+        my $shown_cells = 0;
+        foreach my $cell (@rowdata) {
+            my $value    = $cell->{'value'};
+            my $formula  = $cell->{'formula'};
+            my $cellname = $cell->{'name'};
+            #
+            my $bgcolor;
+            if ($shown_cells && ($shown_cells/5 == int($shown_cells/5))) {
+                $bgcolor = $defaultbg.'99';
+            } else {
+                $bgcolor = $defaultbg.'DD';
+            }
+            $bgcolor='#FFDDDD' if ($shown_cells < $num_uneditable);
+            #
+            $row_html.='<td bgcolor='.$bgcolor.'>';
+            if ($shown_cells < $num_uneditable) {
+                $row_html .= &html_uneditable_cell($cell,$bgcolor);
+            } else {
+                $row_html .= &html_editable_cell($cell,$bgcolor);
+            }
+            $row_html.='</td>';
+            $shown_cells++;
+        }
+        if ($row_html) {
+            if ($rows_output % 25 == 0) {
                 $r->print("</table>\n<br>\n");
                 $r->rflush();
-                $r->print('<table border=2><tr><td>&nbsp;<td>'.$what.'</td>');
-                $r->print('<td>'.
+                $r->print('<table border=2>'.
+                          '<tr><td>&nbsp;<td>'.$row_type.'</td>'.
+                          '<td>'.
                           join('</td><td>',
                                (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
                                       'abcdefghijklmnopqrstuvwxyz'))).
                           "</td></tr>\n");
             }
-            $n++;
-            $r->print($thisrow);
+            $rows_output++;
+            $r->print($row_html);
         }
     }
-    $r->print($ENV{'form.showcsv'}?'</pre>':'</table>');
+    #
+    $r->print('</table>');
+    #
+    # Debugging code (be sure to uncomment errorlog code in safe space):
+    #
+    # $r->print("\n<pre>");
+    # $r->print(&geterrorlog($sheet));
+    # $r->print("\n</pre>");
+    return 1;
 }
 
-#
-# ----------------------------------------------- Read list of available sheets
-# 
+sub outsheet_csv   {
+    my ($sheet,$r) = @_;
+}
+
+sub outsheet_excel {
+    my ($sheet,$r) = @_;
+}
+
+sub outsheet_xml   {
+    my ($sheet,$r) = @_;
+}
+
+sub outsheet {
+    my ($r,$sheet)=@_;
+    &outsheet_html($sheet,$r);
+#    if (exists($ENV{'form.csv'})) {
+#        &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);
+#    }
+}
+
+########################################################################
+########################################################################
 sub othersheets {
     my ($sheet,$stype)=@_;
     $stype = $sheet->{'sheettype'} if (! defined($stype));
@@ -1300,7 +1397,6 @@
     return @alternatives; 
 }
 
-
 #
 # -------------------------------------- Parse a spreadsheet
 # 
@@ -1616,6 +1712,7 @@
 
 sub format_rowlabel {
     my $rowlabel = shift;
+    return '' if ($rowlabel eq '');
     my ($type,$labeldata) = split(':',$rowlabel,2);
     my $result = '';
     if ($type eq 'symb') {
@@ -1643,7 +1740,11 @@
         }
         $result = $labeldata;
     } else {
-        &Apache::lonnet::logthis("lonspreadsheet:bogus rowlabel type: $type");
+        if ($ENV{'form.showcsv'}) {
+            $result = $rowlabel;
+        } else {
+            $result = '<b><font size=+1>'.$rowlabel.'</font></b>';
+        }
     }
     return $result;
 }
@@ -1932,7 +2033,7 @@
         my $index=0;
         foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
                  'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {
-            if (defined($studentdata[$index++])) {
+            if (defined($studentdata[$index])) {
                 my $col=$_;
                 if ($studentdata[$index]=~/\D/) {
                     $c{$col.$row}="'".$studentdata[$index]."'";
@@ -1942,7 +2043,8 @@
                 unless ($col eq 'A') { 
                     $f{$col.$row}='import';
                 }
-            }
+            } 
+            $index++;
         }
     }
     $sheet->{'f'}=\%f;
@@ -2172,7 +2274,8 @@
     $udom  = $udom  || $sheet->{'udom'};
     $stype = $stype || $sheet->{'sheettype'};
     my @exportarr=();
-    if (defined($usymb) && ($usymb=~/^\_(\w+)/) && (!$fn)) {
+    if (defined($usymb) && ($usymb=~/^\_(\w+)/) && 
+        (!defined($fn) || $fn eq '')) {
         $fn='default_'.$1;
     }
     #

--matthew1036449345--