3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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
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.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 TODO :: Description here
33 use C4::Dates qw(format_date);
36 use C4::Tags qw(add_tag get_tags get_tag_rows remove_tag);
44 # The trick here is to support multiple tags added to multiple bilbios in one POST.
45 # So the name of param has to have biblionumber built in.
46 # For lack of anything more compelling, we just use "newtag[biblionumber]"
47 # We split the value into tags at comma and semicolon
49 my $openadds = C4::Context->preference('TagsModeration') ? 0 : 1;
51 unless (C4::Context->preference('TagsEnabled')) {
52 push @errors, {+ tagsdisabled=>1 };
54 foreach ($query->param) {
56 my $biblionumber = $1;
57 unless ($biblionumber =~ /^\d+$/) {
58 $debug and warn "$_ references non numerical biblionumber '$biblionumber'";
59 push @errors, {+'badparam' => $_ };
62 $newtags{$biblionumber} = $query->param($_);
63 } elsif (/^del(\d+)$/) {
69 my $add_op = (scalar(keys %newtags) + scalar(@deltags)) ? 1 : 0;
70 my ($template, $loggedinuser, $cookie) = get_template_and_user({
71 template_name => "opac-tags.tmpl",
74 authnotrequired => ($add_op ? 0 : 1), # auth required to add tags
79 unless ($loggedinuser) {
80 push @errors, {+'login' => $_ };
81 %newtags=(); # zero out any attempted additions
82 @deltags=(); # zero out any attempted deletions
85 foreach my $biblionumber (keys %newtags) {
86 my @values = split /[;,]/, $newtags{$biblionumber};
91 $result = add_tag($biblionumber,$_,$loggedinuser,0); # pre-approved
93 $result = add_tag($biblionumber,$_,$loggedinuser);
96 $counts{$biblionumber}++;
98 warn "add_tag($biblionumber,$_,$loggedinuser...) returned $result";
104 remove_tag($_) and $dels++;
111 $my_tags = get_tag_rows({borrowernumber=>$loggedinuser});
112 foreach (@$my_tags) {
113 my $biblio = GetBiblioData($_->{biblionumber});
114 $_->{bib_summary} = $biblio->{title};
115 ($biblio->{author}) and $_->{bib_summary} .= " by " . $biblio->{author};
116 my $date = $_->{date_created} || '';
117 $date =~ /\s+(\d{2}\:\d{2}\:\d{2})/;
118 $_->{time_created_display} = $1;
119 $_->{date_created_display} = format_date($_->{date_created});
122 $template->param(tagsview => 1,);
125 for (values %counts) {$adds += $_;}
128 added_count => $adds,
129 deleted_count => $dels,
132 my ($arg,$limit,$tmpresults);
133 my $hardmax = 100; # you might disagree what this value should be, but there definitely should be a max
134 $limit = $query->param('limit') || $hardmax;
135 ($limit =~ /^\d+$/ and $limit <= $hardmax) or $limit = $hardmax;
136 if ($arg = $query->param('tag')) {
137 $tmpresults = get_tags({term => $arg, limit=>$limit, 'sort'=>'-weight'});
138 } elsif ($arg = $query->param('biblionumber')) {
139 $tmpresults = get_tags({biblionumber => $arg, limit=>$limit, 'sort'=>'-weight'});
141 $tmpresults = get_tags({limit=>$limit, 'sort'=>'-weight'});
144 foreach (@$tmpresults) {
145 $uniq{$_->{term}}++ and next;
149 (scalar @errors ) and $template->param(ERRORS => \@errors);
150 (scalar @$results) and $template->param(TAGLOOP => $results);
151 (scalar @$my_tags) and $template->param(MY_TAGS => $my_tags);
153 output_html_with_http_headers $query, $cookie, $template->output;