bug 4182: add emailLibrarianWhenHoldIsPlaced to preferences editor
[koha_gimpoz] / C4 / Branch.pm
index a6ab59c..a6b1a3a 100644 (file)
@@ -44,8 +44,9 @@ BEGIN {
                &ModBranchCategoryInfo
                &DelBranch
                &DelBranchCategory
+               &CheckCategoryUnique
        );
-       @EXPORT_OK = qw( &onlymine &mybranch );
+       @EXPORT_OK = qw( &onlymine &mybranch get_branch_code_from_name );
 }
 
 =head1 NAME
@@ -156,10 +157,11 @@ sub GetBranchesLoop (;$$) {  # since this is what most pages want anyway
     my $onlymine = @_ ? shift : onlymine();
     my $branches = GetBranches($onlymine);
     my @loop;
+    my $searchMyLibraryFirst = C4::Context->preference("SearchMyLibraryFirst");;
     foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
         push @loop, {
             value => $_,
-            selected => ($_ eq $branch) ? 1 : 0, 
+            selected => (($_ eq $branch) && $searchMyLibraryFirst ) ? 1 : 0, 
             branchname => $branches->{$_}->{branchname},
         };
     }
@@ -525,20 +527,42 @@ sets the data from the editbranch form, and writes to the database...
 sub ModBranchCategoryInfo {
     my ($data) = @_;
     my $dbh    = C4::Context->dbh;
-       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();
-       }
+    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 CheckCategoryUnique
+
+if (CheckCategoryUnique($categorycode)){
+  # do something
+}
+
+=cut
+
+sub CheckCategoryUnique {
+    my $categorycode = shift;
+    my $dbh    = C4::Context->dbh;
+    my $sth = $dbh->prepare("SELECT categorycode FROM branchcategories WHERE categorycode = ?");
+    $sth->execute(uc( $categorycode) );
+    if (my $data = $sth->fetchrow_hashref){
+       return 0;
+    }
+    else {
+       return 1;
+    }
 }
 
+    
 =head2 DeleteBranchCategory
 
 DeleteBranchCategory($categorycode);
@@ -572,6 +596,15 @@ sub CheckBranchCategorycode {
     return $total;
 }
 
+sub get_branch_code_from_name {
+   my @branch_name = @_;
+   my $query = "SELECT branchcode FROM branches WHERE branchname=?;";
+   my $dbh = C4::Context->dbh();
+   my $sth = $dbh->prepare($query);
+   $sth->execute(@branch_name);
+   return $sth->fetchrow_array;
+}
+
 1;
 __END__