Bug 12398: Add test for C4::Auth_with_cas::_url_with_get_params
[koha.git] / admin / stopwords.pl
blob8c3f00d3f675698c64e2413aacb624630d23a38f
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 under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use strict;
25 use warnings;
26 use CGI;
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;