View | Details | Raw Unified | Return to bug 10515
Collapse All | Expand All

(-)a/C4/Branch.pm (-42 / +21 lines)
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
(-)a/admin/branches.pl (-27 / +20 lines)
Lines 234-247 sub editbranchform { Link Here
234
    my $data;
234
    my $data;
235
    my $oldprinter = "";
235
    my $oldprinter = "";
236
236
237
238
    # make the checkboxes.....
239
    my $catinfo = GetBranchCategories();
240
237
    if ($branchcode) {
241
    if ($branchcode) {
238
        $data = GetBranchInfo($branchcode);
242
        $data = GetBranchInfo($branchcode);
239
        $data = $data->[0];
243
        $data = $data->[0];
244
        if ( exists $data->{categories} ) {
245
            # Set the selected flag for the categories of this branch
246
            $catinfo = [
247
                map {
248
                    my $catcode = $_->{categorycode};
249
                    if ( grep {/$catcode/} @{$data->{categories}} ){
250
                        $_->{selected} = 1;
251
                    }
252
                    $_;
253
                } @{$catinfo}
254
            ];
255
        }
240
256
241
        # get the old printer of the branch
257
        # get the old printer of the branch
242
        $oldprinter = $data->{'branchprinter'} || '';
258
        $oldprinter = $data->{'branchprinter'} || '';
243
        _branch_to_template($data, $innertemplate);
259
        _branch_to_template($data, $innertemplate);
244
    }
260
    }
261
    $innertemplate->param( categoryloop => $catinfo );
245
262
246
    foreach my $thisprinter ( keys %$printers ) {
263
    foreach my $thisprinter ( keys %$printers ) {
247
        push @printerloop, {
264
        push @printerloop, {
Lines 252-280 sub editbranchform { Link Here
252
    }
269
    }
253
270
254
    $innertemplate->param( printerloop => \@printerloop );
271
    $innertemplate->param( printerloop => \@printerloop );
255
    # make the checkboxes.....
256
    #
257
    # We export a "categoryloop" array to the template, each element of which
258
    # contains separate 'categoryname', 'categorycode', 'codedescription', and
259
    # 'checked' fields. The $checked field is either empty or 1'
260
261
    my $catinfo = GetBranchCategory();
262
    my @categoryloop = ();
263
    foreach my $cat (@$catinfo) {
264
        my $checked;
265
        my $tmp     = quotemeta( $cat->{'categorycode'} );
266
        if ( grep { /^$tmp$/ } @{ $data->{'categories'} } ) {
267
            $checked = 1;
268
        }
269
        push @categoryloop, {
270
            categoryname    => $cat->{'categoryname'},
271
            categorycode    => $cat->{'categorycode'},
272
            categorytype    => $cat->{'categorytype'},
273
            codedescription => $cat->{'codedescription'},
274
            checked         => $checked,
275
        };
276
    }
277
    $innertemplate->param( categoryloop => \@categoryloop );
278
272
279
    for my $obsolete ( 'categoryname', 'categorycode', 'codedescription' ) {
273
    for my $obsolete ( 'categoryname', 'categorycode', 'codedescription' ) {
280
        $innertemplate->param(
274
        $innertemplate->param(
Lines 291-297 sub editcatform { Link Here
291
    my $data;
285
    my $data;
292
	if ($categorycode) {
286
	if ($categorycode) {
293
        my $data = GetBranchCategory($categorycode);
287
        my $data = GetBranchCategory($categorycode);
294
        $data = $data->[0];
295
        $innertemplate->param(
288
        $innertemplate->param(
296
            categorycode    => $data->{'categorycode'},
289
            categorycode    => $data->{'categorycode'},
297
            categoryname    => $data->{'categoryname'},
290
            categoryname    => $data->{'categoryname'},
Lines 360-366 sub branchinfotable { Link Here
360
        my $no_categories_p = 1;
353
        my $no_categories_p = 1;
361
        my @categories;
354
        my @categories;
362
        foreach my $cat ( @{ $branch->{'categories'} } ) {
355
        foreach my $cat ( @{ $branch->{'categories'} } ) {
363
            my ($catinfo) = @{ GetBranchCategory($cat) };
356
            my $catinfo = GetBranchCategory($cat);
364
            push @categories, { 'categoryname' => $catinfo->{'categoryname'} };
357
            push @categories, { 'categoryname' => $catinfo->{'categoryname'} };
365
            $no_categories_p = 0;
358
            $no_categories_p = 0;
366
        }
359
        }
Lines 375-382 sub branchinfotable { Link Here
375
    }
368
    }
376
    my @branchcategories = ();
369
    my @branchcategories = ();
377
	for my $ctype ( GetCategoryTypes() ) {
370
	for my $ctype ( GetCategoryTypes() ) {
378
    	my $catinfo = GetBranchCategories(undef,$ctype);
371
        my $catinfo = GetBranchCategories($ctype);
379
    	my @categories;
372
        my @categories;
380
		foreach my $cat (@$catinfo) {
373
		foreach my $cat (@$catinfo) {
381
            push @categories, {
374
            push @categories, {
382
                categoryname    => $cat->{'categoryname'},
375
                categoryname    => $cat->{'categoryname'},
(-)a/catalogue/search.pl (-1 / +1 lines)
Lines 237-243 my @branch_loop = map { Link Here
237
    $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
237
    $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
238
} keys %$branches;
238
} keys %$branches;
239
239
240
my $categories = GetBranchCategories(undef,'searchdomain');
240
my $categories = GetBranchCategories('searchdomain');
241
241
242
$template->param(branchloop => \@branch_loop, searchdomainloop => $categories);
242
$template->param(branchloop => \@branch_loop, searchdomainloop => $categories);
243
243
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-1 / +1 lines)
Lines 107-113 tinyMCE.init({ Link Here
107
        <ol>
107
        <ol>
108
		[% FOREACH categoryloo IN categoryloop %]
108
		[% FOREACH categoryloo IN categoryloop %]
109
            <li><label for="[% categoryloo.categorycode %]">[% categoryloo.categoryname %]: </label>
109
            <li><label for="[% categoryloo.categorycode %]">[% categoryloo.categoryname %]: </label>
110
                [% IF ( categoryloo.checked ) %]
110
                [% IF categoryloo.selected %]
111
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" checked="checked" />
111
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" checked="checked" />
112
                [% ELSE %]
112
                [% ELSE %]
113
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" />
113
                    <input type="checkbox" id="[% categoryloo.categorycode %]" name="[% categoryloo.categorycode %]" />
(-)a/opac/opac-search.pl (-2 / +1 lines)
Lines 193-199 if (C4::Context->preference('TagsEnabled')) { Link Here
193
193
194
my $branches = GetBranches();   # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
194
my $branches = GetBranches();   # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
195
$template->param(
195
$template->param(
196
    searchdomainloop => GetBranchCategories(undef,'searchdomain'),
196
    searchdomainloop => GetBranchCategories('searchdomain'),
197
);
197
);
198
198
199
# load the language limits (for search)
199
# load the language limits (for search)
200
- 

Return to bug 10515