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

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 25 Jun 2002 15:08:59 -0000


This is a MIME encoded message

--matthew1025017739
Content-Type: text/plain

matthew		Tue Jun 25 11:08:59 2002 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Advanced search interface:
      Changed valid field directions.
      Place submit, reset, view select buttons at head and foot of page.
      Removed "Limit by" text (it should be obvious).
      Changed mime type to 'file extension' fill-in box instead of select box.
      Wrapped part of search interface in <table></table>
  &searchphrasefield
      Inserted table tags.
      Changed field length from 80 to 50.
      Removed repetative instructions for entering fields.
  &selectbox
      Added POD documentation
      changed $value to $default.
      Provide default function for $functionref.
  
  
--matthew1025017739
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20020625110859.txt"

Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.128 loncom/interface/lonsearchcat.pm:1.129
--- loncom/interface/lonsearchcat.pm:1.128	Mon Jun 24 12:45:22 2002
+++ loncom/interface/lonsearchcat.pm	Tue Jun 25 11:08:59 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.128 2002/06/24 16:45:22 harris41 Exp $
+# $Id: lonsearchcat.pm,v 1.129 2002/06/25 15:08:59 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -273,7 +273,8 @@
 $hidden
 <h3>Basic Search</h3>
 <p>
-Enter terms or phrases separated by AND, OR, or NOT then press SEARCH below.
+Enter terms or quoted phrases separated by AND, OR, or NOT 
+then press SEARCH below.
 </p>
 <p>
 <table>
@@ -322,6 +323,23 @@
 
 sub advanced_search_form{
     my ($closebutton,$hidden) = @_;
+    my $advanced_buttons = <<"END";
+<p>
+<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
     my $scrout=<<"ENDHEADER";
 <html>
 <head>
@@ -336,34 +354,44 @@
 </head>
 <body bgcolor="#FFFFFF">
 <img align='right' src='/adm/lonIcons/lonlogos.gif' />
-<h1>Search Catalog</h1>
-<form method="post" action="/adm/searchcat">
-$hidden
+<h1>Advanced Catalog Search</h1>
 <hr />
-<h3>Advanced Search</h3>
+Enter terms or quoted phrases separated by search operators 
+such as AND, OR, or NOT.<br />
+$advanced_buttons
+$hidden
+<table>
 ENDHEADER
-    $scrout.=&searchphrasefield('Limit by title','title',
+    $scrout.=&searchphrasefield('title','title',
 			$ENV{'form.title'});
-    $scrout.=&searchphrasefield('Limit by author','author',
+    $scrout.=&searchphrasefield('author','author',
 			$ENV{'form.author'});
-    $scrout.=&searchphrasefield('Limit by subject','subject',
+    $scrout.=&searchphrasefield('subject','subject',
 			$ENV{'form.subject'});
-    $scrout.=&searchphrasefield('Limit by keywords','keywords',
+    $scrout.=&searchphrasefield('keywords','keywords',
 			$ENV{'form.keywords'});
-    $scrout.=&searchphrasefield('Limit by URL','url',
+    $scrout.=&searchphrasefield('URL','url',
 			$ENV{'form.url'});
 #    $scrout.=&searchphrasefield('Limit by version','version',
 #			$ENV{'form.version'});
-    $scrout.=&searchphrasefield('Limit by notes','notes',
+    $scrout.=&searchphrasefield('notes','notes',
 			$ENV{'form.notes'});
-    $scrout.=&searchphrasefield('Limit by abstract','abstract',
+    $scrout.=&searchphrasefield('abstract','abstract',
 			$ENV{'form.abstract'});
-    $ENV{'form.mime'}='any' unless length($ENV{'form.mime'});
-    $scrout.=&selectbox('Limit by MIME type','mime',
-			$ENV{'form.mime'},
-			'any','Any type',
-			\&{Apache::loncommon::filedescriptionex},
-			(&Apache::loncommon::fileextensions));
+    # Hack - an empty table row.
+    $scrout.="<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
+    $scrout.=&searchphrasefield('file<br />extension','mime',
+                        $ENV{'form.mime'});
+    $scrout.="<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
+    $scrout.=&searchphrasefield('publisher<br />owner','owner',
+				$ENV{'form.owner'});
+    $scrout.="</table>\n";
+#    $ENV{'form.mime'}='any' unless length($ENV{'form.mime'});
+#    $scrout.=&selectbox('Limit by MIME type','mime',
+#			$ENV{'form.mime'},
+#			'any','Any type',
+#			\&{Apache::loncommon::filedescriptionex},
+#			(&Apache::loncommon::fileextensions));
     $ENV{'form.language'}='any' unless length($ENV{'form.language'});
     $scrout.=&selectbox('Limit by language','language',
 			$ENV{'form.language'},'any','Any Language',
@@ -410,8 +438,6 @@
 			$ENV{'form.lastrevisiondateend_year'},
 			);
     $scrout.='</p>';
-    $scrout.=&searchphrasefield('Limit by publisher/owner','owner',
-				$ENV{'form.owner'});
     $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
     $scrout.=&selectbox('Limit by copyright/distribution','copyright',
 			 $ENV{'form.copyright'},
@@ -440,21 +466,7 @@
 CUSTOMSHOW
     $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
     $scrout.=<<ENDDOCUMENT;
-<p>
-<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>
+$advanced_buttons
 </form>
 </body>
 </html>
@@ -534,7 +546,46 @@
 
 =item &selectbox()
 
-Returns html selection form.
+Returns a scalar containing an html <select> form.  
+
+Inputs: 
+
+=over 4
+
+=item $title 
+
+Printed above the select box, in uppercase.
+
+=item $name 
+
+The name element of the <select> tag.
+
+=item $default 
+
+The default value of the form.  Can be $anyvalue or in @idlist.
+
+=item $anyvalue 
+
+The <option value="..."> used to indicate a default of 
+none of the values.
+
+=item $anytag 
+
+The text associate with $anyvalue above.
+
+=item $functionref 
+
+Each element in @idlist will be passed as a parameter 
+to the function referenced here.  The return value of the function should
+be a scalar description of the items.  If this value is undefined the 
+description of each item in @idlist will be the item name.
+
+=item @idlist 
+
+The items to be selected from.  One of these or $anyvalue will be the 
+value returned by the form element, $ENV{form.$name}.
+
+=back
 
 =back 
 
@@ -553,19 +604,16 @@
 sub simplecheckbox {
     my ($name,$value)=@_;
     my $checked='';
-    $checked="CHECKED" if $value eq 'on';
+    $checked="checked" if $value eq 'on';
     return '<input type="checkbox" name="'.$name.'" '. $checked . ' />';
 }
 
 sub searchphrasefield {
     my ($title,$name,$value)=@_;
-    my $instruction=<<END;
-Enter terms or phrases separated by search operators such as AND, OR, or NOT.
-END
     my $uctitle=uc($title);
-    return "\n".
-        '<p><font color="#800000" face="helvetica"><b>'.$uctitle.':</b>'.
-        "</FONT> $instruction<br />".&simpletextfield($name,$value,80);
+    return '<tr><td><font color="#800000" face="helvetica">'.
+        '<b>'.$uctitle.':&nbsp;</b></font></td><td>'.
+                &simpletextfield($name,$value,50)."</td></tr>\n";
 }
 
 sub dateboxes {
@@ -613,21 +661,22 @@
 }
 
 sub selectbox {
-    my ($title,$name,$value,$anyvalue,$anytag,$functionref,@idlist)=@_;
+    my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;
+    if (! defined($functionref)) { $functionref = sub { $_[0]}; }
     my $uctitle=uc($title);
     my $selout="\n".'<p><font color="#800000" face="helvetica">'.
         '<b>'.$uctitle.':</b></font><br /><select name="'.$name.'">';
     foreach ($anyvalue,@idlist) {
         $selout.='<option value="'.$_.'"';
-        if ($_ eq $value and !/^any$/) {
+        if ($_ eq $default and !/^any$/) {
 	    $selout.=' selected >'.&{$functionref}($_).'</option>';
 	}
-	elsif ($_ eq $value and /^$anyvalue$/) {
+	elsif ($_ eq $default and /^$anyvalue$/) {
 	    $selout.=' selected >'.$anytag.'</option>';
 	}
         else {$selout.='>'.&{$functionref}($_).'</option>';}
     }
-    return $selout.'</select>';
+    return $selout.'</select></p>';
 }
 
 ######################################################################
@@ -682,7 +731,7 @@
     my @queries;
     # Evaluate logical expression AND/OR/NOT phrase fields.
     foreach my $field ('title','author','subject','notes','abstract','url',
-		       'keywords','version','owner') {
+		       'keywords','version','owner','mime') {
 	if ($ENV{'form.'.$field}) {
 	    push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
 	}
@@ -691,9 +740,9 @@
     if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
 	push @queries,"(language like \"$ENV{'form.language'}\")";
     }
-    if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
-	push @queries,"(mime like \"$ENV{'form.mime'}\")";
-    }
+#    if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
+#	push @queries,"(mime like \"$ENV{'form.mime'}\")";
+#    }
     if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
 	push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
     }
@@ -1021,8 +1070,14 @@
 <img align=right src=/adm/lonIcons/lonlogos.gif>
 <h1>Search Catalog</h1>
 CATALOGBEGIN
-        $r->print(<<CATALOGCONTROLS);
-<form name='results' method="post" action="/adm/searchcat">
+    my $action = "/adm/searchcat";
+    if ($mode eq 'Basic') { 
+        $action .= "?reqinterface=basic";
+    } elsif ($mode eq 'Advanced') {
+        $action .= "?reqinterface=advanced";
+    }
+    $r->print(<<CATALOGCONTROLS);
+<form name='results' method="post" action="$action">
 $hidden
 <input type='hidden' name='acts' value='' />
 <input type='button' value='Revise search request'

--matthew1025017739--