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

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 05 Jul 2002 18:56:53 -0000


matthew		Fri Jul  5 14:56:53 2002 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  &output_results:
      Removed use of $viewselect and replaced with function pointer code.
      Removed $percent variable which was unused for some reason.
      Minor change to comments.
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.135 loncom/interface/lonsearchcat.pm:1.136
--- loncom/interface/lonsearchcat.pm:1.135	Wed Jul  3 16:10:14 2002
+++ loncom/interface/lonsearchcat.pm	Fri Jul  5 14:56:52 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.135 2002/07/03 20:10:14 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.136 2002/07/05 18:56:52 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1107,13 +1107,32 @@
     my $elapsetime=0;
     my $resultflag=0;
     my $tflag=1;
-    my $viewselect=$ENV{'form.viewselect'};
+    ##
+    ## Set viewing function
+    ##
+    my $viewfunction = undef;
+    if ($ENV{'form.viewselect'} eq 'Detailed Citation View') {
+        $viewfunction = \&detailed_citation_view;
+    } elsif ($ENV{'form.viewselect'} eq 'Summary View') {
+        $viewfunction = \&summary_view;
+    } elsif ($ENV{'form.viewselect'} eq 'Fielded Format') {
+        $viewfunction = \&fielded_format_view;
+    } elsif ($ENV{'form.viewselect'} eq 'XML/SGML') {
+        $viewfunction = \&xml_sgml_view;
+    }
+    if (!defined($viewfunction)) {
+        $r->print("Internal Error - Bad view selected.\n");
+        $r->rflush();
+        return;
+    }
     #
     # make query information persistent to allow for subsequent revision
     my $persistent=&make_persistent(\%ENV);
-    # spit out the results header
+    #
+    # Begin producing output
     $r->print(&search_results_header($mode));
     $r->rflush();
+    #
     # begin showing the cataloged results
     my $action = "/adm/searchcat";
     if ($mode eq 'Basic') { 
@@ -1134,7 +1153,6 @@
 CATALOGCONTROLS
     #
     # make the pop-up window for status
-    #
     $r->print(&make_popwin(%rhash));
     $r->rflush();
     ##
@@ -1211,7 +1229,8 @@
 	} # end of if ($reply eq 'con_lost') else statement
         my %Fields = undef;     # Holds the data to be sent to the various 
                                 # *_view routines.
-        my ($extrashow,$customfields,$customhash) = &handle_custom_fields(\@results);
+        my ($extrashow,$customfields,$customhash) = 
+                                    &handle_custom_fields(\@results);
         my @customfields = @$customfields;
         my %customhash   = %$customhash;
 	untie %hash if (keys %hash);
@@ -1262,22 +1281,8 @@
 # <input type="hidden" name="url$fnum" value="$url" />
                     $fnum++;
 		}
-	        if ($viewselect eq 'Detailed Citation View') {
-		    $compiledresult.=&detailed_citation_view
-                        (%Fields, hostname => $rkey );
-		}
-                elsif ($viewselect eq 'Summary View') {
-		    $compiledresult.=&summary_view
-                        (%Fields, hostname => $rkey );
-	        }
-                elsif ($viewselect eq 'Fielded Format') {
-		    $compiledresult.=&fielded_format_view
-                        (%Fields, hostname => $rkey );
-	        }
-                elsif ($viewselect eq 'XML/SGML') {
-		    $compiledresult.=&xml_sgml_view
-                        (%Fields, hostname => $rkey );
-		}
+                # Render the result into html
+                $compiledresult.= &$viewfunction(%Fields, hostname => $rkey );
                 if ($compiledresult or $servercount!=$servernum) {
                     $compiledresult.="<hr align='left' width='200' noshade />";
                 }
@@ -1288,7 +1293,6 @@
 	    $resultflag=1;
             $r->print($compiledresult);
 	}
-        my $percent=sprintf('%3.0f',($servercount/$servernum*100));
       } # End of foreach loop over servers remaining
     }   # End of big loop - while($serversleft && $timeremain)
     unless ($resultflag) {