3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
20 # script to administer the stopwords table
22 # - written on 2002/02/20 by paul.poulain@free.fr
24 # - experimentaly rewrittten on 2006/04/06 by Pierrick LE GALL (INEO media
30 use List::Util qw/min/;
37 use C4::Interface::CGI::Output;
40 my ($searchstring) = @_;
42 my $dbh = C4::Context->dbh;
43 $searchstring =~ s/\'/\\\'/g;
44 my @tokens = split(' ',$searchstring);
52 my $sth = $dbh->prepare($query);
53 $sth->execute($tokens[0].'%');
55 while (my $row = $sth->fetchrow_hashref) {
56 push(@results, $row->{word});
63 my $dbh = C4::Context->dbh;
67 my $searchfield = $input->param('searchfield');
68 my $script_name="/cgi-bin/koha/admin/stopwords.pl";
71 my $op = $input->param('op');
72 $searchfield=~ s/\,//g;
74 my ($template, $loggedinuser, $cookie)
75 = get_template_and_user({template_name => "admin/stopwords.tmpl",
78 flagsrequired => {parameters => 1, management => 1},
83 $template->param(script_name => $script_name,
84 searchfield => $searchfield);
86 if ($input->param('add')) {
87 if ($input->param('word')) {
88 my @words = split / |,/, $input->param('word');
93 WHERE word IN (?'.(',?' x scalar @words - 1).')
95 $sth = $dbh->prepare($query);
96 $sth->execute(@words);
104 (?)'.(',(?)' x scalar @words - 1).'
106 $sth = $dbh->prepare($query);
107 $sth->execute(@words);
110 $template->param(stopword_added => 1);
113 elsif ($input->param('deleteSelected')) {
114 if ($input->param('stopwords[]')) {
115 my @stopwords_loop = ();
117 foreach my $word ($input->param('stopwords[]')) {
118 push @stopwords_loop, {word => $word};
123 stopwords_to_delete => \@stopwords_loop,
127 elsif ($input->param('confirmDeletion')) {
128 my @words = $input->param('confirmed_stopwords[]');
133 WHERE word IN (?'.(',?' x scalar @words - 1).')
135 $sth = $dbh->prepare($query);
136 $sth->execute(@words);
139 $template->param(delete_confirmed => 1);
142 my $page = $input->param('page') || 1;
144 my @results = StringSearch($searchfield);
147 my $first = ($page - 1) * $pagesize;
149 # if we are on the last page, the number of the last word to display must
150 # not exceed the length of the results array
152 $first + $pagesize - 1,
153 scalar(@results) - 1,
156 foreach my $word (@results[$first .. $last]) {
157 push @loop, {word => $word};
162 pagination_bar => pagination_bar(
164 int(scalar(@results) / $pagesize) + 1,
170 output_html_with_http_headers $input, $cookie, $template->output;