Lines 248-254
sub ModBranch {
Link Here
|
248 |
} |
248 |
} |
249 |
# sort out the categories.... |
249 |
# sort out the categories.... |
250 |
my @checkedcats; |
250 |
my @checkedcats; |
251 |
my $cats = GetBranchCategory(); |
251 |
my $cats = GetBranchCategories(); |
252 |
foreach my $cat (@$cats) { |
252 |
foreach my $cat (@$cats) { |
253 |
my $code = $cat->{'categorycode'}; |
253 |
my $code = $cat->{'categorycode'}; |
254 |
if ( $data->{$code} ) { |
254 |
if ( $data->{$code} ) { |
Lines 294-380
sub ModBranch {
Link Here
|
294 |
|
294 |
|
295 |
$results = GetBranchCategory($categorycode); |
295 |
$results = GetBranchCategory($categorycode); |
296 |
|
296 |
|
297 |
C<$results> is an ref to an array. |
297 |
C<$results> is an hashref |
298 |
|
298 |
|
299 |
=cut |
299 |
=cut |
300 |
|
300 |
|
301 |
sub GetBranchCategory { |
301 |
sub GetBranchCategory { |
302 |
|
|
|
303 |
# returns a reference to an array of hashes containing branches, |
304 |
my ($catcode) = @_; |
302 |
my ($catcode) = @_; |
|
|
303 |
return unless $catcode; |
304 |
|
305 |
my $dbh = C4::Context->dbh; |
305 |
my $dbh = C4::Context->dbh; |
306 |
my $sth; |
306 |
my $sth; |
307 |
|
307 |
|
308 |
# print DEBUG "GetBranchCategory: entry: catcode=".cvs($catcode)."\n"; |
308 |
$sth = $dbh->prepare(q{ |
309 |
if ($catcode) { |
309 |
SELECT * |
310 |
$sth = |
310 |
FROM branchcategories |
311 |
$dbh->prepare( |
311 |
WHERE categorycode = ? |
312 |
"select * from branchcategories where categorycode = ?"); |
312 |
}); |
313 |
$sth->execute($catcode); |
313 |
$sth->execute( $catcode ); |
314 |
} |
314 |
return $sth->fetchrow_hashref; |
315 |
else { |
|
|
316 |
$sth = $dbh->prepare("Select * from branchcategories"); |
317 |
$sth->execute(); |
318 |
} |
319 |
my @results; |
320 |
while ( my $data = $sth->fetchrow_hashref ) { |
321 |
push( @results, $data ); |
322 |
} |
323 |
$sth->finish; |
324 |
|
325 |
# print DEBUG "GetBranchCategory: exit: returning ".cvs(\@results)."\n"; |
326 |
return \@results; |
327 |
} |
315 |
} |
328 |
|
316 |
|
329 |
=head2 GetBranchCategories |
317 |
=head2 GetBranchCategories |
330 |
|
318 |
|
331 |
my $categories = GetBranchCategories($branchcode,$categorytype,$show_in_pulldown,$selected_in_pulldown); |
319 |
my $categories = GetBranchCategories($categorytype,$show_in_pulldown,$selected_in_pulldown); |
332 |
|
320 |
|
333 |
Returns a list ref of anon hashrefs with keys eq columns of branchcategories table, |
321 |
Returns a list ref of anon hashrefs with keys eq columns of branchcategories table, |
334 |
i.e. categorycode, categorydescription, categorytype, categoryname. |
322 |
i.e. categorydescription, categorytype, categoryname. |
335 |
if $branchcode and/or $categorytype are passed, limit set to categories that |
|
|
336 |
$branchcode is a member of , and to $categorytype. |
337 |
|
323 |
|
338 |
=cut |
324 |
=cut |
339 |
|
325 |
|
340 |
sub GetBranchCategories { |
326 |
sub GetBranchCategories { |
341 |
my ( $branchcode, $categorytype, $show_in_pulldown, $selected_in_pulldown ) = @_; |
327 |
my ( $categorytype, $show_in_pulldown, $selected_in_pulldown ) = @_; |
342 |
my $dbh = C4::Context->dbh(); |
328 |
my $dbh = C4::Context->dbh(); |
343 |
|
329 |
|
344 |
my $query = "SELECT c.* FROM branchcategories c"; |
330 |
my $query = "SELECT * FROM branchcategories "; |
345 |
my ( @where, @bind ); |
|
|
346 |
|
347 |
if( $branchcode ) { |
348 |
$query .= ",branchrelations r, branches b "; |
349 |
push @where, "c.categorycode = r.categorycode AND r.branchcode = ? "; |
350 |
push @bind , $branchcode; |
351 |
} |
352 |
|
331 |
|
|
|
332 |
my ( @where, @bind ); |
353 |
if ( $categorytype ) { |
333 |
if ( $categorytype ) { |
354 |
push @where, " c.categorytype = ? "; |
334 |
push @where, " categorytype = ? "; |
355 |
push @bind, $categorytype; |
335 |
push @bind, $categorytype; |
356 |
} |
336 |
} |
357 |
|
337 |
|
358 |
if ( defined( $show_in_pulldown ) ) { |
338 |
if ( defined( $show_in_pulldown ) ) { |
359 |
push( @where, " c.show_in_pulldown = ? " ); |
339 |
push( @where, " show_in_pulldown = ? " ); |
360 |
push( @bind, $show_in_pulldown ); |
340 |
push( @bind, $show_in_pulldown ); |
361 |
} |
341 |
} |
362 |
|
342 |
|
363 |
$query .= " WHERE " . join(" AND ", @where) if(@where); |
343 |
$query .= " WHERE " . join(" AND ", @where) if(@where); |
364 |
$query .= " ORDER BY categorytype,c.categorycode"; |
344 |
$query .= " ORDER BY categorytype, categorycode"; |
365 |
my $sth=$dbh->prepare( $query); |
345 |
my $sth=$dbh->prepare( $query); |
366 |
$sth->execute(@bind); |
346 |
$sth->execute(@bind); |
367 |
|
347 |
|
368 |
my $branchcats = $sth->fetchall_arrayref({}); |
348 |
my $branchcats = $sth->fetchall_arrayref({}); |
369 |
$sth->finish(); |
|
|
370 |
|
349 |
|
371 |
if ( $selected_in_pulldown ) { |
350 |
if ( $selected_in_pulldown ) { |
372 |
foreach my $bc ( @$branchcats ) { |
351 |
foreach my $bc ( @$branchcats ) { |
373 |
$bc->{'selected'} = 1 if ( $bc->{'categorycode'} eq $selected_in_pulldown ); |
352 |
$bc->{selected} = 1 if $bc->{categorycode} eq $selected_in_pulldown; |
374 |
} |
353 |
} |
375 |
} |
354 |
} |
376 |
|
355 |
|
377 |
return( $branchcats ); |
356 |
return $branchcats; |
378 |
} |
357 |
} |
379 |
|
358 |
|
380 |
=head2 GetCategoryTypes |
359 |
=head2 GetCategoryTypes |