Bug 6933 [REVISED] Add a view of titles with a particular tag to the staff client
[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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use warnings;
21 use strict;
22 use CGI;
23
24 use C4::Auth qw(:DEFAULT check_cookie_auth);
25 use C4::Biblio;
26 use C4::Context;
27 use C4::Dates qw(format_date);
28 use C4::Items;
29 use C4::Koha;
30 use C4::Tags 0.03 qw(get_tags remove_tag get_tag_rows);
31 use C4::Output;
32
33 my $needed_flags = { tools => 'moderate_tags' }; # 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         template_name => "tags/list.tmpl",
43         query => $query,
44         type => "intranet",
45         debug => 1,
46         authnotrequired => 0,
47         flagsrequired => $needed_flags,
48 });
49
50 if( $op eq "del" ){
51         remove_tag($tag_id);
52         print $query->redirect("/cgi-bin/koha/tags/list.pl?tag=$tag");
53 } else {
54
55 my $marcflavour = C4::Context->preference('marcflavour');
56 my @results;
57
58 if ($tag) {
59         my $taglist = get_tag_rows({term=>$tag});
60         for ( @{$taglist} ) {
61         my $dat                 = &GetBiblioData($_->{biblionumber});
62         my $record              = &GetMarcBiblio($_->{biblionumber});
63         $dat->{'subtitle'}      = GetRecordValue('subtitle', $record, GetFrameworkCode($_->{biblionumber}));
64         my @items               = GetItemsInfo( $_->{biblionumber} );
65         $dat->{biblionumber}    = $_->{biblionumber};
66         $dat->{tag_id}          = $_->{tag_id};
67         $dat->{items}           = \@items;
68         $dat->{TagLoop}         = get_tags({biblionumber=>$_->{biblionumber}, 'sort'=>'-weight',limit=>10 });
69         push( @results, $dat );
70     }
71
72 my $resultsarray = \@results;
73
74 $template->param(
75     tag => $tag,
76     titles => $resultsarray,
77 );
78 }
79 }
80
81 output_html_with_http_headers $query, $cookie, $template->output;