|
Lines 33-39
BEGIN {
Link Here
|
| 33 |
&GetBranch |
33 |
&GetBranch |
| 34 |
&GetBranches |
34 |
&GetBranches |
| 35 |
&GetBranchesLoop |
35 |
&GetBranchesLoop |
| 36 |
&ModBranch |
|
|
| 37 |
&GetBranchInfo |
36 |
&GetBranchInfo |
| 38 |
&mybranch |
37 |
&mybranch |
| 39 |
); |
38 |
); |
|
Lines 171-282
sub GetBranchName {
Link Here
|
| 171 |
return ($branchname); |
170 |
return ($branchname); |
| 172 |
} |
171 |
} |
| 173 |
|
172 |
|
| 174 |
=head2 ModBranch |
|
|
| 175 |
|
| 176 |
$error = &ModBranch($newvalue); |
| 177 |
|
| 178 |
This function modifies an existing branch |
| 179 |
|
| 180 |
C<$newvalue> is a ref to an array which contains all the columns from branches table. |
| 181 |
|
| 182 |
=cut |
| 183 |
|
| 184 |
sub ModBranch { |
| 185 |
my ($data) = @_; |
| 186 |
|
| 187 |
my $dbh = C4::Context->dbh; |
| 188 |
if ($data->{add}) { |
| 189 |
my $query = " |
| 190 |
INSERT INTO branches |
| 191 |
(branchcode,branchname,branchaddress1, |
| 192 |
branchaddress2,branchaddress3,branchzip,branchcity,branchstate, |
| 193 |
branchcountry,branchphone,branchfax,branchemail, |
| 194 |
branchurl,branchip,branchprinter,branchnotes,opac_info, |
| 195 |
branchreplyto, branchreturnpath) |
| 196 |
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |
| 197 |
"; |
| 198 |
my $sth = $dbh->prepare($query); |
| 199 |
$sth->execute( |
| 200 |
$data->{'branchcode'}, $data->{'branchname'}, |
| 201 |
$data->{'branchaddress1'}, $data->{'branchaddress2'}, |
| 202 |
$data->{'branchaddress3'}, $data->{'branchzip'}, |
| 203 |
$data->{'branchcity'}, $data->{'branchstate'}, |
| 204 |
$data->{'branchcountry'}, |
| 205 |
$data->{'branchphone'}, $data->{'branchfax'}, |
| 206 |
$data->{'branchemail'}, $data->{'branchurl'}, |
| 207 |
$data->{'branchip'}, $data->{'branchprinter'}, |
| 208 |
$data->{'branchnotes'}, $data->{opac_info}, |
| 209 |
$data->{'branchreplyto'}, $data->{'branchreturnpath'} |
| 210 |
); |
| 211 |
return 1 if $dbh->err; |
| 212 |
} else { |
| 213 |
my $query = " |
| 214 |
UPDATE branches |
| 215 |
SET branchname=?,branchaddress1=?, |
| 216 |
branchaddress2=?,branchaddress3=?,branchzip=?, |
| 217 |
branchcity=?,branchstate=?,branchcountry=?,branchphone=?, |
| 218 |
branchfax=?,branchemail=?,branchurl=?,branchip=?, |
| 219 |
branchprinter=?,branchnotes=?,opac_info=?, |
| 220 |
branchreplyto=?, branchreturnpath=? |
| 221 |
WHERE branchcode=? |
| 222 |
"; |
| 223 |
my $sth = $dbh->prepare($query); |
| 224 |
$sth->execute( |
| 225 |
$data->{'branchname'}, |
| 226 |
$data->{'branchaddress1'}, $data->{'branchaddress2'}, |
| 227 |
$data->{'branchaddress3'}, $data->{'branchzip'}, |
| 228 |
$data->{'branchcity'}, $data->{'branchstate'}, |
| 229 |
$data->{'branchcountry'}, |
| 230 |
$data->{'branchphone'}, $data->{'branchfax'}, |
| 231 |
$data->{'branchemail'}, $data->{'branchurl'}, |
| 232 |
$data->{'branchip'}, $data->{'branchprinter'}, |
| 233 |
$data->{'branchnotes'}, $data->{opac_info}, |
| 234 |
$data->{'branchreplyto'}, $data->{'branchreturnpath'}, |
| 235 |
$data->{'branchcode'}, |
| 236 |
); |
| 237 |
} |
| 238 |
# sort out the categories.... |
| 239 |
my @checkedcats; |
| 240 |
my @cats = Koha::LibraryCategories->search; |
| 241 |
foreach my $cat (@cats) { |
| 242 |
my $code = $cat->categorycode; |
| 243 |
if ( $data->{$code} ) { |
| 244 |
push( @checkedcats, $code ); |
| 245 |
} |
| 246 |
} |
| 247 |
my $branchcode = uc( $data->{'branchcode'} ); |
| 248 |
my $branch = GetBranchInfo($branchcode); |
| 249 |
$branch = $branch->[0]; |
| 250 |
my $branchcats = $branch->{'categories'}; |
| 251 |
my @addcats; |
| 252 |
my @removecats; |
| 253 |
foreach my $bcat (@$branchcats) { |
| 254 |
|
| 255 |
unless ( grep { /^$bcat$/ } @checkedcats ) { |
| 256 |
push( @removecats, $bcat ); |
| 257 |
} |
| 258 |
} |
| 259 |
foreach my $ccat (@checkedcats) { |
| 260 |
unless ( grep { /^$ccat$/ } @$branchcats ) { |
| 261 |
push( @addcats, $ccat ); |
| 262 |
} |
| 263 |
} |
| 264 |
foreach my $cat (@addcats) { |
| 265 |
my $sth = |
| 266 |
$dbh->prepare( |
| 267 |
"insert into branchrelations (branchcode, categorycode) values(?, ?)" |
| 268 |
); |
| 269 |
$sth->execute( $branchcode, $cat ); |
| 270 |
} |
| 271 |
foreach my $cat (@removecats) { |
| 272 |
my $sth = |
| 273 |
$dbh->prepare( |
| 274 |
"delete from branchrelations where branchcode=? and categorycode=?" |
| 275 |
); |
| 276 |
$sth->execute( $branchcode, $cat ); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
=head2 GetBranch |
173 |
=head2 GetBranch |
| 281 |
|
174 |
|
| 282 |
$branch = GetBranch( $query, $branches ); |
175 |
$branch = GetBranch( $query, $branches ); |