Bug 19040: Refactor GetMarcBiblio parameters
[koha.git] / tags / list.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011 Athens County Public Libraries
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use warnings;
21 use strict;
22 use CGI qw ( -utf8 );
23
24 use C4::Auth qw(:DEFAULT check_cookie_auth);
25 use C4::Biblio;
26 use C4::Context;
27 use C4::Items;
28 use C4::Koha;
29 use C4::Tags qw(get_tags remove_tag get_tag_rows);
30 use C4::Output;
31
32 my $needed_flags = { tools => 'moderate_tags'
33 };    # FIXME: replace when more specific permission is created.
34
35 my $query        = CGI->new;
36 my $op           = $query->param('op') || '';
37 my $biblionumber = $query->param('biblionumber');
38 my $tag          = $query->param('tag');
39 my $tag_id       = $query->param('tag_id');
40
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
42     {
43         template_name   => "tags/list.tt",
44         query           => $query,
45         type            => "intranet",
46         debug           => 1,
47         authnotrequired => 0,
48         flagsrequired   => $needed_flags,
49     }
50 );
51
52 if ( $op eq "del" ) {
53     remove_tag($tag_id);
54     print $query->redirect("/cgi-bin/koha/tags/list.pl?tag=$tag");
55 }
56 else {
57
58     my $marcflavour = C4::Context->preference('marcflavour');
59     my @results;
60
61     if ($tag) {
62         my $taglist = get_tag_rows( { term => $tag } );
63         for ( @{$taglist} ) {
64             my $dat    = &GetBiblioData( $_->{biblionumber} );
65             my $record = &GetMarcBiblio({ biblionumber => $_->{biblionumber} });
66             $dat->{'subtitle'} =
67               GetRecordValue( 'subtitle', $record,
68                 GetFrameworkCode( $_->{biblionumber} ) );
69             my @items = GetItemsInfo( $_->{biblionumber} );
70             $dat->{biblionumber} = $_->{biblionumber};
71             $dat->{tag_id}       = $_->{tag_id};
72             $dat->{items}        = \@items;
73             $dat->{TagLoop}      = get_tags(
74                 {
75                     biblionumber => $_->{biblionumber},
76                     'sort'       => '-weight',
77                     limit        => 10
78                 }
79             );
80             push( @results, $dat );
81         }
82
83         my $resultsarray = \@results;
84
85         $template->param(
86             tag    => $tag,
87             titles => $resultsarray,
88         );
89     }
90 }
91
92 output_html_with_http_headers $query, $cookie, $template->output;