bug 2518: remove useless patron and branch lookups
[koha_fer] / C4 / Branch.pm
index f8edb6a..c09b129 100644 (file)
@@ -23,8 +23,28 @@ use C4::Koha;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
-# set the version for version checking
-$VERSION = 3.00;
+BEGIN {
+       # set the version for version checking
+       $VERSION = 3.01;
+       @ISA    = qw(Exporter);
+       @EXPORT = qw(
+               &GetBranchCategory
+               &GetBranchName
+               &GetBranch
+               &GetBranches
+               &GetBranchDetail
+               &get_branchinfos_of
+               &ModBranch
+               &CheckBranchCategorycode
+               &GetBranchInfo
+               &GetCategoryTypes
+               &GetBranchCategories
+               &GetBranchesInCategory
+               &ModBranchCategoryInfo
+               &DelBranch
+               &DelBranchCategory
+       );
+}
 
 =head1 NAME
 
@@ -40,27 +60,6 @@ The functions in this module deal with branches.
 
 =head1 FUNCTIONS
 
-=cut
-
-@ISA    = qw(Exporter);
-@EXPORT = qw(
-   &GetBranchCategory
-   &GetBranchName
-   &GetBranch
-   &GetBranches
-   &GetBranchDetail
-   &get_branchinfos_of
-   &ModBranch
-   &CheckBranchCategorycode
-   &GetBranchInfo
-   &GetCategoryTypes
-   &GetBranchCategories
-   &GetBranchesInCategory
-   &ModBranchCategoryInfo
-   &DelBranch
-   &DelBranchCategory
-);
-
 =head2 GetBranches
 
   $branches = &GetBranches();
@@ -84,7 +83,6 @@ foreach my $thisbranch (keys %$branches) {
     push @branchloop, \%row;
 }
 
-
 =head3 in TEMPLATE
             <select name="branch">
                 <option value="">Default</option>
@@ -101,17 +99,19 @@ sub GetBranches {
     my %branches;
     my $dbh = C4::Context->dbh;
     my $sth;
-    my $query="SELECT * from branches";
+    my $query="SELECT * FROM branches";
+    my @bind_parameters;
     if ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){
-      $query .= " WHERE branchcode =".$dbh->quote(C4::Context->userenv->{branch});
+      $query .= ' WHERE branchcode = ? ';
+      push @bind_parameters, C4::Context->userenv->{branch};
     }
-    $query.=" order by branchname";
+        $query.=" ORDER BY branchname";
     $sth = $dbh->prepare($query);
-    $sth->execute;
+    $sth->execute( @bind_parameters );
     while ( my $branch = $sth->fetchrow_hashref ) {
         my $nsth =
           $dbh->prepare(
-            "select categorycode from branchrelations where branchcode = ?");
+            "SELECT categorycode FROM branchrelations WHERE branchcode = ?");
         $nsth->execute( $branch->{'branchcode'} );
         while ( my ($cat) = $nsth->fetchrow_array ) {
 
@@ -482,12 +482,20 @@ sets the data from the editbranch form, and writes to the database...
 =cut
 
 sub ModBranchCategoryInfo {
-
     my ($data) = @_;
     my $dbh    = C4::Context->dbh;
-    my $sth    = $dbh->prepare("replace branchcategories (categorycode,categoryname,codedescription,categorytype) values (?,?,?,?)");
-    $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'} );
-    $sth->finish;
+       if ($data->{'add'}){
+               # we are doing an insert
+               my $sth   = $dbh->prepare("INSERT INTO branchcategories (categorycode,categoryname,codedescription,categorytype) VALUES (?,?,?,?)");
+               $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'} );
+               $sth->finish();         
+       }
+       else {
+               # modifying
+               my $sth = $dbh->prepare("UPDATE branchcategories SET categoryname=?,codedescription=?,categorytype=? WHERE categorycode=?");
+               $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},uc( $data->{'categorycode'} ) );
+               $sth->finish();
+       }
 }
 
 =head2 DeleteBranchCategory
@@ -523,7 +531,8 @@ sub CheckBranchCategorycode {
     return $total;
 }
 
-
+1;
+__END__
 
 =head1 AUTHOR