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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 15 Dec 2005 22:10:51 -0000


albertel		Thu Dec 15 17:10:51 2005 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - skip lines that have now values in the upload scores 'samples' display BUG#3936
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.300 loncom/interface/loncommon.pm:1.301
--- loncom/interface/loncommon.pm:1.300	Thu Dec  1 18:04:08 2005
+++ loncom/interface/loncommon.pm	Thu Dec 15 17:10:49 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.300 2005/12/01 23:04:08 albertel Exp $
+# $Id: loncommon.pm,v 1.301 2005/12/15 22:10:49 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3724,6 +3724,22 @@
     return $Str;
 }
 
+sub get_samples {
+    my ($records,$toget) = @_;
+    my @samples=({});
+    my $got=0;
+    foreach my $rec (@$records) {
+	my %temp = &record_sep($rec);
+	if (! grep(/\S/, values(%temp))) { next; }
+	if (%temp) {
+	    $samples[$got]=\%temp;
+	    $got++;
+	    if ($got == $toget) { last; }
+	}
+    }
+    return \@samples;
+}
+
 ######################################################
 ######################################################
 
@@ -3741,18 +3757,15 @@
 ######################################################
 sub csv_print_samples {
     my ($r,$records) = @_;
-    my (%sone,%stwo,%sthree);
-    %sone=&record_sep($$records[0]);
-    if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
-    if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
-    #
+    my $samples = &get_samples($records,3);
+
     $r->print(&mt('Samples').'<br /><table border="2"><tr>');
-    foreach (sort({$a <=> $b} keys(%sone))) { 
+    foreach (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
         $r->print('<th>'.&mt('Column&nbsp;[_1]',($_+1)).'</th>'); }
     $r->print('</tr>');
-    foreach my $hash (\%sone,\%stwo,\%sthree) {
+    foreach my $hash (@$samples) {
 	$r->print('<tr>');
-	foreach (sort({$a <=> $b} keys(%sone))) {
+	foreach (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
 	    $r->print('<td>');
 	    if (defined($$hash{$_})) { $r->print($$hash{$_}); }
 	    $r->print('</td>');
@@ -3781,8 +3794,8 @@
 ######################################################
 sub csv_print_select_table {
     my ($r,$records,$d) = @_;
-    my $i=0;my %sone;
-    %sone=&record_sep($$records[0]);
+    my $i=0;
+    my $samples = &get_samples($records,1);
     $r->print(&mt('Associate columns with student attributes.')."\n".
 	     '<table border="2"><tr>'.
               '<th>'.&mt('Attribute').'</th>'.
@@ -3794,7 +3807,7 @@
 	$r->print('<td><select name=f'.$i.
 		  ' onchange="javascript:flip(this.form,'.$i.');">');
 	$r->print('<option value="none"></option>');
-	foreach (sort({$a <=> $b} keys(%sone))) {
+	foreach (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
 	    $r->print('<option value="'.$_.'"'.
                       ($_ eq $defaultcol ? ' selected="selected" ' : '').
                       '>Column '.($_+1).'</option>');
@@ -3825,28 +3838,27 @@
 ######################################################
 sub csv_samples_select_table {
     my ($r,$records,$d) = @_;
-    my %sone; my %stwo; my %sthree;
     my $i=0;
     #
+    my $samples = &get_samples($records,3);
     $r->print('<table border=2><tr><th>'.
               &mt('Field').'</th><th>'.&mt('Samples').'</th></tr>');
-    %sone=&record_sep($$records[0]);
-    if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
-    if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
-    #
-    foreach (sort keys %sone) {
+
+    foreach my $key (sort(keys(%{ $samples->[0] }))) {
 	$r->print('<tr><td><select name="f'.$i.'"'.
 		  ' onchange="javascript:flip(this.form,'.$i.');">');
-	foreach (@$d) {
-	    my ($value,$display,$defaultcol)=@{ $_ };
+	foreach my $option (@$d) {
+	    my ($value,$display,$defaultcol)=@{ $option };
 	    $r->print('<option value="'.$value.'"'.
                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
                       $display.'</option>');
 	}
 	$r->print('</select></td><td>');
-	if (defined($sone{$_})) { $r->print($sone{$_}."<br />\n"); }
-	if (defined($stwo{$_})) { $r->print($stwo{$_}."<br />\n"); }
-	if (defined($sthree{$_})) { $r->print($sthree{$_}."<br />\n"); }
+	foreach my $line (0..2) {
+	    if (defined($samples->[$line]{$key})) { 
+		$r->print($samples->[$line]{$key}."<br />\n"); 
+	    }
+	}
 	$r->print('</td></tr>');
 	$i++;
     }