adding branch groups search in intranet.
authorRyan Higgins <rch@liblime.com>
Sun, 21 Oct 2007 20:11:38 +0000 (15:11 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Mon, 22 Oct 2007 00:18:39 +0000 (19:18 -0500)
Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Branch.pm
catalogue/search.pl
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl

index 08b10ae..f8edb6a 100644 (file)
@@ -275,6 +275,41 @@ sub GetBranchCategory {
     return \@results;
 }
 
+=head2 GetBranchCategories
+
+  my $categories = GetBranchCategories($branchcode,$categorytype);
+
+Returns a list ref of anon hashrefs with keys eq columns of branchcategories table,
+i.e. categorycode, categorydescription, categorytype, categoryname.
+if $branchcode and/or $categorytype are passed, limit set to categories that
+$branchcode is a member of , and to $categorytype.
+
+=cut
+
+sub GetBranchCategories {
+    my ($branchcode,$categorytype) = @_;
+       my $dbh = C4::Context->dbh();
+       my $query = "SELECT c.* FROM branchcategories c";
+       my (@where, @bind);
+       if($branchcode) {
+               $query .= ",branchrelations r, branches b ";
+               push @where, "c.categorycode=r.categorycode and r.branchcode=? ";  
+               push @bind , $branchcode;
+       }
+       if ($categorytype) {
+               push @where, " c.categorytype=? ";
+               push @bind, $categorytype;
+       }
+       $query .= " where " . join(" and ", @where) if(@where);
+       $query .= " order by categorytype,c.categorycode";
+       my $sth=$dbh->prepare( $query);
+       $sth->execute(@bind);
+       
+       my $branchcats = $sth->fetchall_arrayref({});
+       $sth->finish();
+       return( $branchcats );
+}
+
 =head2 GetCategoryTypes
 
 $categorytypes = GetCategoryTypes;
@@ -353,39 +388,6 @@ sub get_branchinfos_of {
     return C4::Koha::get_infos_of( $query, 'branchcode' );
 }
 
-=head2 GetBranchCategories
-
-  my $categories = GetBranchCategories($branchcode,$categorytype);
-
-Returns a list ref of anon hashrefs with keys eq columns of branchcategories table,
-i.e. categorycode, categorydescription, categorytype, categoryname.
-if $branchcode and/or $categorytype are passed, limit set to categories that
-$branchcode is a member of , and to $categorytype.
-
-=cut
-
-sub GetBranchCategories($$) {
-    my ($branchcode,$categorytype) = @_;
-       my $dbh = C4::Context->dbh();
-       my $select = "SELECT c.* FROM branchcategories c";
-       my (@where, @bind);
-       if($branchcode) {
-               $select .= ",branchrelations r, branches b ";
-               push @where, "c.categorycode=r.categorycode and r.branchcode=? ";  
-               push @bind , $branchcode;
-       }
-       if ($categorytype) {
-               push @where, " c.categorytype=? ";
-               push @bind, $categorytype;
-       }
-    my $sth=$dbh->prepare( $select . " where " . join(" and ", @where) );
-       $sth->execute(@bind);
-       
-       my $branchcats = $sth->fetchall_arrayref({});
-       $sth->finish();
-       return( $branchcats );
-}
-
 
 =head2 GetBranchesInCategory
 
@@ -397,13 +399,16 @@ Returns a href:  keys %$branches eq (branchcode,branchname) .
 
 sub GetBranchesInCategory($) {
     my ($categorycode) = @_;
-       my $dbh = C4::context->dbh();
-       my $sth=$dbh->prepare( "SELECT branchcode, branchname FROM branchrelations r, branches b 
+       my @branches;
+       my $dbh = C4::Context->dbh();
+       my $sth=$dbh->prepare( "SELECT b.branchcode FROM branchrelations r, branches b 
                                                        where r.branchcode=b.branchcode and r.categorycode=?");
     $sth->execute($categorycode);
-       my $branches = $sth->fetchall_hashref;
+       while (my $branch = $sth->fetchrow) {
+               push @branches, $branch;
+       }
        $sth->finish();
-       return( $branches );
+       return( \@branches );
 }
 
 =head2 GetBranchInfo
index da672d7..fff41df 100755 (executable)
@@ -162,13 +162,12 @@ my ($template,$borrowernumber,$cookie);
 # decide which template to use
 my $template_name;
 my @params = $cgi->param("limit");
-if ((@params>=1) || ($cgi->param("q")) ) {
+if ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) ) {
     $template_name = 'catalogue/results.tmpl';
 }
 else {
     $template_name = 'catalogue/advsearch.tmpl';
 }
-
 # load the template
 ($template, $borrowernumber, $cookie) = get_template_and_user({
     template_name => $template_name,
@@ -216,9 +215,12 @@ my $branches = GetBranches();
 my @branch_loop;
 #push @branch_loop, {value => "", branchname => "All Branches", };
 for my $branch_hash (sort keys %$branches) {
-    push @branch_loop, {value => "branch: $branch_hash", branchname => $branches->{$branch_hash}->{'branchname'}, };
+    push @branch_loop, {value => "branch:$branch_hash" , branchname => $branches->{$branch_hash}->{'branchname'}, };
 }
-$template->param(branchloop => \@branch_loop,);
+
+my $categories = GetBranchCategories(undef,'searchdomain');
+
+$template->param(branchloop => \@branch_loop, searchdomainloop => $categories);
 
 # load the itemtypes (Called Collection Codes in the template -- used for circ rules )
 my $itemtypes = GetItemTypes;
@@ -345,6 +347,10 @@ my @operands;
 my @limits;
 @limits = split("\0",$params->{'limit'}) if $params->{'limit'};
 
+if($params->{'multibranchlimit'}) {
+push @limits, join(" or ", map { "branch: $_ "}  @{GetBranchesInCategory($params->{'multibranchlimit'})}) ;
+}
+
 my $available;
 foreach my $limit(@limits) {
     if ($limit =~/available/) {
index 9e36d20..07ad4aa 100644 (file)
 <!-- AVAILABILITY LIMITS -->
     <fieldset><legend>Location and availability: </legend>
         <p>
-        <label>Library</label><select name="limit" id="branchloop">
-        <option value="">All Locations</option>
+        <label for="available-items">Only items currently available</label><input type="checkbox" id="available-items" name="limit" value="datedue:0000-00-00" /></p>
+        <p>
+        <label>Individual Libraries </label><select name="limit" id="branchloop" onchange='if(this.value != ""){document.getElementById("categoryloop").disabled=true;} else {document.getElementById("categoryloop").disabled=false;}'>
+        <option value="">All Libraries</option>
         <!-- TMPL_LOOP NAME="branchloop" -->
         <option value="<!-- TMPL_VAR NAME='value' -->"><!-- TMPL_VAR NAME='branchname' --></option>
         <!-- /TMPL_LOOP -->
         </select>
+               <!-- <input type='hidden' name='limit' value='branch: MAIN' /> -->
         </p>
-        <p>
-        <label for="available-items">Only items currently available</label><input type="checkbox" id="available-items" name="limit" value="datedue:0000-00-00" /></p>
+        <!-- TMPL_IF NAME="searchdomainloop" -->
+               <p>OR<p> <!-- should addjs to grey out group pulldown if a library is selected. -->
+               <p>
+        <label>Groups of Libraries</label><select name="multibranchlimit" id="categoryloop">
+        <option value=""> -- none -- </option>
+        <!-- TMPL_LOOP NAME="searchdomainloop" -->
+        <option value="<!-- TMPL_VAR NAME='categorycode' -->"><!-- TMPL_VAR NAME='categoryname' --></option>
+        <!-- /TMPL_LOOP -->
+        </select>
+        </p>
+               <!-- /TMPL_IF -->
     </fieldset>
 <!-- /AVAILABILITY LIMITS -->