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

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 26 Jun 2002 16:04:13 -0000


This is a MIME encoded message

--matthew1025107453
Content-Type: text/plain

matthew		Wed Jun 26 12:04:13 2002 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Removed the passing of %ENV to subroutines basicsearch, advancedsearch,
      and output_results.
  &basic_search_form
      Changed view selection html.
  &advanced_search_form
      Changed view selection html.
      Added <form> tag, allowing the advanced search interface to work.
      View selection element can only appear once in the page, otherwise the
          value passed back to the function is an array, which is just a can
          of worms.
  &output_results
      Changed page headers to be more concise.
      Changed view selection code to conform to new methods used in the search
          forms.
      Moved the short horizontal line to appear after results, not before.
  &search_results_header
      More POD added.
      Now takes the search mode as a parameter, so the headers and title output
          can be a little more customized.
  &detailed_citation_view
      Minor cosmetic changes.
  
  
--matthew1025107453
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20020626120413.txt"

Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.129 loncom/interface/lonsearchcat.pm:1.130
--- loncom/interface/lonsearchcat.pm:1.129	Tue Jun 25 11:08:59 2002
+++ loncom/interface/lonsearchcat.pm	Wed Jun 26 12:04:13 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.129 2002/06/25 15:08:59 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.130 2002/06/26 16:04:13 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -223,10 +223,10 @@
     ##
     if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
         # Perform basic search and give results
-	return &basicsearch($r,\%ENV,$hidden);
+	return &basicsearch($r,$hidden);
     } elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
         # Perform advanced search and give results
-	return &advancedsearch($r,\%ENV,$hidden);
+	return &advancedsearch($r,$hidden);
     } elsif ($ENV{'form.reqinterface'} eq 'advanced') {
         # Output the advanced interface
         $r->print(&advanced_search_form($closebutton,$hidden));
@@ -290,15 +290,14 @@
 <p>
 &nbsp;<input type="submit" name="basicsubmit" value='SEARCH' />&nbsp;
 $closebutton
-<!-- basic view selection -->
-<select name='basicviewselect'>
-<option value='Detailed Citation View' selected="true">
-Detailed Citation View</option>
-<option value='Summary View'>Summary View</option>
-<option value='Fielded Format'>Fielded Format</option>
-<option value='XML/SGML'>XML/SGML</option>
+<!-- view selection -->
+<select name="viewselect">
+<option value="Detailed Citation View" selected="true" >Detailed Citation View</option>
+<option value="Summary View"  >Summary View</option>
+<option value="Fielded Format">Fielded Format</option>
+<option value="XML/SGML"      >XML/SGML</option>
 </select>
-<!-- end of basic view selection -->
+<!-- end of view selection -->
 <input type="button" value="HELP" onClick="openhelp()" />
 </p>
 </form>
@@ -328,15 +327,6 @@
 <input type="submit" name="advancedsubmit" value='SEARCH' />
 <input type="reset" name="reset" value='RESET' />
 $closebutton
-<!-- advance view select -->
-<select name='advancedviewselect'>
-<option value='Detailed Citation View' selected="true">
-Detailed Citation View</option>
-<option value='Summary View'>Summary View</option>
-<option value='Fielded Format'>Fielded Format</option>
-<option value='XML/SGML'>XML/SGML</option>
-</select>
-<!-- end of advanced view select -->
 <input type="button" value="HELP" onClick="openhelp()" />
 </p>
 END
@@ -358,9 +348,21 @@
 <hr />
 Enter terms or quoted phrases separated by search operators 
 such as AND, OR, or NOT.<br />
+<form method="post" action="/adm/searchcat">
 $advanced_buttons
 $hidden
 <table>
+<tr><td><font color="#800000" face="helvetica"><b>VIEW:</b></font></td>
+<td>
+<!-- view selection -->
+<select name="viewselect" size ="1">
+    <option value="Detailed Citation View" selected="true">Detailed Citation View</option>
+    <option value="Summary View">Summary View</option>
+    <option value="Fielded Format">Fielded Format</option>
+    <option value="XML/SGML">XML/SGML</option>
+</select>
+<!-- end of view selection -->
+</td></tr>
 ENDHEADER
     $scrout.=&searchphrasefield('title','title',
 			$ENV{'form.title'});
@@ -693,8 +695,7 @@
 ######################################################################
 ######################################################################
 sub advancedsearch {
-    my ($r,$envhash,$hidden)=@_;
-    my %ENV=%{$envhash};
+    my ($r,$hidden)=@_;
     my $fillflag=0;
     # Clean up fields for safety
     for my $field ('title','author','subject','keywords','url','version',
@@ -796,13 +797,13 @@
 	    $reply=&Apache::lonnet::metadata_query($query,
 						   $customquery,$customshow);
 	}
-	&output_results('Advanced',$r,$envhash,$customquery,$reply,$hidden);
+	&output_results('Advanced',$r,$customquery,$reply,$hidden);
         return OK;
     } elsif ($customquery) {
 	my $reply; # reply hash reference
 	$reply=&Apache::lonnet::metadata_query('',
 					       $customquery,$customshow);
-	&output_results('Advanced',$r,$envhash,$customquery,$reply,$hidden);
+	&output_results('Advanced',$r,$customquery,$reply,$hidden);
         return OK;
     }
     # should not get to this point
@@ -823,8 +824,7 @@
 ######################################################################
 ######################################################################
 sub basicsearch {
-    my ($r,$envhash,$hidden)=@_;
-    my %ENV=%{$envhash};
+    my ($r,$hidden)=@_;
     # Clean up fields for safety
     for my $field ('basicexp') {
 	$ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
@@ -857,7 +857,7 @@
 #    &Apache::lonnet::logthis("metadata query finished:".time);
     # Output search results
 
-    &output_results('Basic',$r,$envhash,$query,$reply,$hidden);
+    &output_results('Basic',$r,$query,$reply,$hidden);
 
     return OK;
 }
@@ -1049,27 +1049,21 @@
 sub output_results {
 #    &Apache::lonnet::logthis("output_results:".time);
     my $fnum; # search result counter
-    my ($mode,$r,$envhash,$query,$replyref,$hidden)=@_;
-    my %ENV=%{$envhash};
+    my ($mode,$r,$query,$replyref,$hidden)=@_;
     my %rhash=%{$replyref};
     my $compiledresult='';
     my $timeremain=300; # (seconds)
     my $elapsetime=0;
     my $resultflag=0;
     my $tflag=1;
+    my $viewselect=$ENV{'form.viewselect'};
     #
     # make query information persistent to allow for subsequent revision
     my $persistent=&make_persistent();
-    # spit out the generic header
-    $r->print(&search_results_header());
+    # spit out the results header
+    $r->print(&search_results_header($mode));
     $r->rflush();
     # begin showing the cataloged results
-    $r->print(<<CATALOGBEGIN);
-</head>
-<body bgcolor="#ffffff">
-<img align=right src=/adm/lonIcons/lonlogos.gif>
-<h1>Search Catalog</h1>
-CATALOGBEGIN
     my $action = "/adm/searchcat";
     if ($mode eq 'Basic') { 
         $action .= "?reqinterface=basic";
@@ -1086,19 +1080,8 @@
 $closebutton
 $persistent
 <hr />
-<h3>Search Query</h3>
 CATALOGCONTROLS
     #
-    # Remind them what they searched for
-    #
-    if ($mode eq 'Basic') {
-	$r->print('<p><b>Basic search:</b> '.$ENV{'form.basicexp'}.'</p>');
-    } elsif ($mode eq 'Advanced') {
-	$r->print('<p><b>Advanced search</b> '.$query.'</p>');
-    }
-    $r->print('<h3>Search Results</h3>');
-    $r->rflush();
-    #
     # make the pop-up window for status
     #
     $r->print(&make_popwin(%rhash));
@@ -1202,9 +1185,6 @@
                         $Fields{'extrashow'}=~s/\<\!\-\- $field \-\-\>/ $value/g;
                     }
                 }
-                if ($compiledresult or $servercount!=$servernum) {
-                    $compiledresult.="<hr align='left' width='200' noshade />";
-                }
                 $compiledresult.="\n<p>\n";
                 if ($ENV{'form.catalogmode'} eq 'interactive') {
                     my $titleesc=$Fields{'title'};
@@ -1231,13 +1211,6 @@
 # <input type="hidden" name="url$fnum" value="$url" />
                     $fnum++;
 		}
-	        my $viewselect;
-	        if ($mode eq 'Basic') {
-		    $viewselect=$ENV{'form.basicviewselect'};
-		}
-	        elsif ($mode eq 'Advanced') {
-		    $viewselect=$ENV{'form.advancedviewselect'};
-		}
 	        if ($viewselect eq 'Detailed Citation View') {
 		    $compiledresult.=&detailed_citation_view
                         (%Fields, hostname => $rkey );
@@ -1254,6 +1227,9 @@
 		    $compiledresult.=&xml_sgml_view
                         (%Fields, hostname => $rkey );
 		}
+                if ($compiledresult or $servercount!=$servernum) {
+                    $compiledresult.="<hr align='left' width='200' noshade />";
+                }
             }
             untie %hash;
         }
@@ -1402,10 +1378,18 @@
 
 =item &search_results_header
 
-Output the proper javascript code to deal with different calling modes.
+Output the proper html headers and javascript code to deal with different 
+calling modes.
+
+Takes most inputs directly from %ENV, except $mode.  
+
+=over 4
+
+=item $mode is either (at this writing) 'Basic' or 'Advanced'
+
+=back
 
-Takes inputs directly from from %ENV.  The following environment variables
-are checked:
+The following environment variables are checked:
 
 =over 4
 
@@ -1428,12 +1412,20 @@
 ######################################################################
 ######################################################################
 sub search_results_header {
+    my ($mode) = @_;
+    $mode = lc($mode);
+    my $title;
+    if ($mode eq 'advanced') {
+        $title = "Advanced Search Results";
+    } elsif ($mode eq 'basic') {
+        $title = "Basic Search Results";
+    }
     my $result = '';
     # output beginning of search page
     $result.=<<BEGINNING;
 <html>
 <head>
-<title>The LearningOnline Network with CAPA</title>
+<title>$title</title>
 BEGINNING
     # conditional output of script functions dependent on the mode in
     # which the search was invoked
@@ -1516,6 +1508,12 @@
     }
 </script>
 SCRIPT
+    $result.=<<END;
+</head>
+<body bgcolor="#ffffff">
+<img align=right src=/adm/lonIcons/lonlogos.gif>
+<h1>$title</h1>
+END
     return $result;
 }
 
@@ -1639,30 +1637,17 @@
 sub detailed_citation_view {
     my %values = @_;
     my $result=<<END;
-<i>$values{'owner'}</i>, last revised $values{'lastrevisiondate'}
 <h3><a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
     target='search_preview'>$values{'title'}</a></h3>
-<h3>$values{'author'}</h3>
-</p>
 <p>
-<b>Subject:</b> $values{'subject'}<br />
-<b>Keyword(s):</b> $values{'keywords'}<br />
-<b>Notes:</b> $values{'notes'}<br />
-<b>MIME Type:</b>
-END
-    $result.=&Apache::loncommon::filedescription($values{'mime'});
-    $result.=<<END;
-<br />
-<b>Language:</b> 
-END
-    $result.=&Apache::loncommon::languagedescription($values{'lang'});
-    $result.=<<END;
-<br />
-<b>Copyright/Distribution:</b> 
-END
-    $result.=&Apache::loncommon::copyrightdescription($values{'copyright'});
-    $result.=<<END;
-<br />
+<b>$values{'author'}</b>, <i>$values{'owner'}</i><br />
+
+<b>Subject:       </b> $values{'subject'}<br />
+<b>Keyword(s):    </b> $values{'keywords'}<br />
+<b>Notes:         </b> $values{'notes'}<br />
+<b>MIME Type:     </b> $values{'mimetag'}<br />
+<b>Language:      </b> $values{'language'}<br />
+<b>Copyright/Distribution:</b> $values{'cprtag'}<br />
 </p>
 $values{'extrashow'}
 <p>

--matthew1025107453--