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/;
38 use C4::Interface::CGI::Output;
41 my ($searchstring) = @_;
43 my $dbh = C4::Context->dbh;
44 $searchstring =~ s/\'/\\\'/g;
45 my @tokens = split(' ',$searchstring);
53 my $sth = $dbh->prepare($query);
54 $sth->execute($tokens[0].'%');
56 while (my $row = $sth->fetchrow_hashref) {
57 push(@results, $row->{word});
64 my $dbh = C4::Context->dbh;
68 my $searchfield = $input->param('searchfield');
69 my $script_name="/cgi-bin/koha/admin/stopwords.pl";
72 my $op = $input->param('op');
73 $searchfield=~ s/\,//g;
75 my ($template, $loggedinuser, $cookie)
76 = get_template_and_user({template_name => "admin/stopwords.tmpl",
79 flagsrequired => {parameters => 1, management => 1},
84 $template->param(script_name => $script_name,
85 searchfield => $searchfield);
87 if ($input->param('add')) {
88 if ($input->param('word')) {
89 my @words = split / |,/, $input->param('word');
94 WHERE word IN (?'.(',?' x scalar @words - 1).')
96 $sth = $dbh->prepare($query);
97 $sth->execute(@words);
105 (?)'.(',(?)' x scalar @words - 1).'
107 $sth = $dbh->prepare($query);
108 $sth->execute(@words);
111 $template->param(stopword_added => 1);
114 elsif ($input->param('deleteSelected')) {
115 if ($input->param('stopwords[]')) {
116 my @stopwords_loop = ();
118 foreach my $word ($input->param('stopwords[]')) {
119 push @stopwords_loop, {word => $word};
124 stopwords_to_delete => \@stopwords_loop,
128 elsif ($input->param('confirmDeletion')) {
129 my @words = $input->param('confirmed_stopwords[]');
134 WHERE word IN (?'.(',?' x scalar @words - 1).')
136 $sth = $dbh->prepare($query);
137 $sth->execute(@words);
140 $template->param(delete_confirmed => 1);
143 my $page = $input->param('page') || 1;
145 my @results = StringSearch($searchfield);
148 my $first = ($page - 1) * $pagesize;
150 # if we are on the last page, the number of the last word to display must
151 # not exceed the length of the results array
153 $first + $pagesize - 1,
154 scalar(@results) - 1,
157 foreach my $word (@results[$first .. $last]) {
158 push @loop, {word => $word};
163 pagination_bar => pagination_bar(
165 getnbpages(scalar @results, $pagesize),
171 output_html_with_http_headers $input, $cookie, $template->output;