use strict;
+#use warnings; FIXME - Bug 2505
require Exporter;
use C4::Context;
-use C4::Koha;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
BEGIN {
# set the version for version checking
- $VERSION = 3.02;
+ $VERSION = 3.07.00.049;
@ISA = qw(Exporter);
@EXPORT = qw(
&GetBranchCategory
&ModBranchCategoryInfo
&DelBranch
&DelBranchCategory
+ &CheckCategoryUnique
+ &mybranch
);
- @EXPORT_OK = qw( &onlymine &mybranch );
+ @EXPORT_OK = qw( &onlymine &mybranch get_branch_code_from_name );
}
=head1 NAME
$branches = &GetBranches();
- Returns informations about ALL branches, IndependantBranches Insensitive.
- GetBranchInfo() returns the same information without the problems of this function
- (namespace collision, mainly).
- Create a branch selector with the following code.
-
+Returns informations about ALL branches, IndependantBranches Insensitive.
+GetBranchInfo() returns the same information without the problems of this function
+(namespace collision, mainly).
+
+Create a branch selector with the following code.
+
=head3 in PERL SCRIPT
my $branches = GetBranches;
my $onlymine = @_ ? shift : onlymine();
my $branches = GetBranches($onlymine);
my @loop;
- foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
+ foreach ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
push @loop, {
value => $_,
selected => ($_ eq $branch) ? 1 : 0,
my $query = "
INSERT INTO branches
(branchcode,branchname,branchaddress1,
- branchaddress2,branchaddress3,branchphone,
- branchfax,branchemail,branchip,branchprinter)
- VALUES (?,?,?,?,?,?,?,?,?,?)
+ branchaddress2,branchaddress3,branchzip,branchcity,branchstate,
+ branchcountry,branchphone,branchfax,branchemail,
+ branchurl,branchip,branchprinter,branchnotes,opac_info)
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
";
my $sth = $dbh->prepare($query);
$sth->execute(
$data->{'branchcode'}, $data->{'branchname'},
$data->{'branchaddress1'}, $data->{'branchaddress2'},
- $data->{'branchaddress3'}, $data->{'branchphone'},
- $data->{'branchfax'}, $data->{'branchemail'},
+ $data->{'branchaddress3'}, $data->{'branchzip'},
+ $data->{'branchcity'}, $data->{'branchstate'},
+ $data->{'branchcountry'},
+ $data->{'branchphone'}, $data->{'branchfax'},
+ $data->{'branchemail'}, $data->{'branchurl'},
$data->{'branchip'}, $data->{'branchprinter'},
+ $data->{'branchnotes'}, $data->{opac_info},
);
return 1 if $dbh->err;
} else {
my $query = "
UPDATE branches
SET branchname=?,branchaddress1=?,
- branchaddress2=?,branchaddress3=?,branchphone=?,
- branchfax=?,branchemail=?,branchip=?,branchprinter=?
+ branchaddress2=?,branchaddress3=?,branchzip=?,
+ branchcity=?,branchstate=?,branchcountry=?,branchphone=?,
+ branchfax=?,branchemail=?,branchurl=?,branchip=?,
+ branchprinter=?,branchnotes=?,opac_info=?
WHERE branchcode=?
";
my $sth = $dbh->prepare($query);
$sth->execute(
$data->{'branchname'},
$data->{'branchaddress1'}, $data->{'branchaddress2'},
- $data->{'branchaddress3'}, $data->{'branchphone'},
- $data->{'branchfax'}, $data->{'branchemail'},
+ $data->{'branchaddress3'}, $data->{'branchzip'},
+ $data->{'branchcity'}, $data->{'branchstate'},
+ $data->{'branchcountry'},
+ $data->{'branchphone'}, $data->{'branchfax'},
+ $data->{'branchemail'}, $data->{'branchurl'},
$data->{'branchip'}, $data->{'branchprinter'},
+ $data->{'branchnotes'}, $data->{opac_info},
$data->{'branchcode'},
);
}
return $sth->fetchrow_hashref();
}
-=head2 get_branchinfos_of
-
- my $branchinfos_of = get_branchinfos_of(@branchcodes);
-
-Associates a list of branchcodes to the information of the branch, taken in
-branches table.
-
-Returns a href where keys are branchcodes and values are href where keys are
-branch information key.
-
- print 'branchname is ', $branchinfos_of->{$code}->{branchname};
-
-=cut
-
-sub get_branchinfos_of {
- my @branchcodes = @_;
-
- my $query = '
- SELECT branchcode,
- branchname
- FROM branches
- WHERE branchcode IN ('
- . join( ',', map( { "'" . $_ . "'" } @branchcodes ) ) . ')
-';
- return C4::Koha::get_infos_of( $query, 'branchcode' );
-}
-
-
=head2 GetBranchesInCategory
my $branches = GetBranchesInCategory($categorycode);
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);
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__
=head1 AUTHOR
-Koha Developement team <info@koha.org>
+Koha Development Team <http://koha-community.org/>
=cut