Bug 15168: (followup) remove useless diags
[koha.git] / admin / stopwords.pl
blob6d6aad916c206b4467d211b63eeeadfdcee1c073
1 #!/usr/bin/perl
3 #script to administer the stopwords table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use strict;
25 use warnings;
26 use CGI qw ( -utf8 );
27 use C4::Context;
28 use C4::Output;
29 use C4::Auth;
31 sub StringSearch {
32 my $sth = C4::Context->dbh->prepare("
33 SELECT word FROM stopwords WHERE (word LIKE ?) ORDER BY word
34 ");
35 $sth->execute((shift || '') . "%");
36 return $sth->fetchall_arrayref({});
39 my $input = new CGI;
40 my $searchfield = $input->param('searchfield');
41 my $offset = $input->param('offset') || 0;
42 my $script_name = "/cgi-bin/koha/admin/stopwords.pl";
44 my $pagesize = 20;
45 my $op = $input->param('op') || '';
47 my ($template, $loggedinuser, $cookie)
48 = get_template_and_user({template_name => "admin/stopwords.tt",
49 query => $input,
50 type => "intranet",
51 flagsrequired => {parameters => 'parameters_remaining_permissions'},
52 authnotrequired => 0,
53 debug => 1,
54 });
56 $template->param(script_name => $script_name,
57 searchfield => $searchfield);
59 my $dbh = C4::Context->dbh;
60 if ($op eq 'add_form') {
61 $template->param(add_form => 1);
62 } elsif ($op eq 'add_validate') {
63 $template->param(add_validate => 1);
64 my @tab = split / |,/, $input->param('word');
65 my $sth=$dbh->prepare("INSERT INTO stopwords (word) VALUES (?)");
66 foreach my $insert_value (@tab) {
67 $sth->execute($insert_value);
69 } elsif ($op eq 'delete_confirm') {
70 $template->param(delete_confirm => 1);
71 } elsif ($op eq 'delete_confirmed') {
72 $template->param(delete_confirmed => 1);
73 my $sth=$dbh->prepare("delete from stopwords where word=?");
74 $sth->execute($searchfield);
75 } else { # DEFAULT
76 $template->param(else => 1);
77 my $results = StringSearch($searchfield);
78 my $count = scalar(@$results);
79 my @loop;
80 # FIXME: limit and offset should get to the SQL query
81 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
82 push @loop, {word => $results->[$i]{'word'}};
84 $template->param(loop => \@loop);
85 if ($offset > 0) {
86 $template->param(offsetgtzero => 1,
87 prevpage => $offset-$pagesize);
89 if ($offset+$pagesize < scalar(@$results)) {
90 $template->param(ltcount => 1,
91 nextpage => $offset+$pagesize);
95 output_html_with_http_headers $input, $cookie, $template->output;