X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FBranch.pm;h=1f26e352402f2ddbaeea0aa137284a1d2eed5bbb;hb=1e7c5166aa4fa8f983cce549803c8ddc8893c846;hp=7dfd737245be623da417b25f4316f2a2728ea705;hpb=46b9ee7a931ed079c6175330a26fc6cc155405bb;p=koha_gimpoz diff --git a/C4/Branch.pm b/C4/Branch.pm index 7dfd737245..1f26e35240 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -17,6 +17,7 @@ package C4::Branch; use strict; +#use warnings; FIXME - Bug 2505 require Exporter; use C4::Context; use C4::Koha; @@ -44,8 +45,10 @@ BEGIN { &ModBranchCategoryInfo &DelBranch &DelBranchCategory + &CheckCategoryUnique + &mybranch ); - @EXPORT_OK = qw( &onlymine &mybranch ); + @EXPORT_OK = qw( &onlymine &mybranch get_branch_code_from_name ); } =head1 NAME @@ -66,11 +69,12 @@ The functions in this module deal with branches. $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; @@ -156,7 +160,7 @@ sub GetBranchesLoop (;$$) { # since this is what most pages want anyway 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, @@ -199,34 +203,43 @@ sub ModBranch { my $query = " INSERT INTO branches (branchcode,branchname,branchaddress1, - branchaddress2,branchaddress3,branchphone, - branchfax,branchemail,branchip,branchprinter) - VALUES (?,?,?,?,?,?,?,?,?,?) + branchaddress2,branchaddress3,branchzip,branchcity, + branchcountry,branchphone,branchfax,branchemail, + branchurl,branchip,branchprinter,branchnotes) + 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->{'branchcountry'}, + $data->{'branchphone'}, $data->{'branchfax'}, + $data->{'branchemail'}, $data->{'branchurl'}, $data->{'branchip'}, $data->{'branchprinter'}, + $data->{'branchnotes'}, ); return 1 if $dbh->err; } else { my $query = " UPDATE branches SET branchname=?,branchaddress1=?, - branchaddress2=?,branchaddress3=?,branchphone=?, - branchfax=?,branchemail=?,branchip=?,branchprinter=? + branchaddress2=?,branchaddress3=?,branchzip=?, + branchcity=?,branchcountry=?,branchphone=?, + branchfax=?,branchemail=?,branchurl=?,branchip=?, + branchprinter=?,branchnotes=? 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->{'branchcountry'}, + $data->{'branchphone'}, $data->{'branchfax'}, + $data->{'branchemail'}, $data->{'branchurl'}, $data->{'branchip'}, $data->{'branchprinter'}, + $data->{'branchnotes'}, $data->{'branchcode'}, ); } @@ -516,20 +529,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); @@ -563,11 +598,20 @@ 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__ =head1 AUTHOR -Koha Developement team +Koha Development Team =cut