* bugfixes
[koha.git] / thesaurus_popup.pl
1 #!/usr/bin/perl
2
3 # written 10/5/2002 by Paul
4 # build result field using bibliothesaurus table
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
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.
15 #
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.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use CGI;
26 use C4::Context;
27 use HTML::Template;
28 use C4::Search;
29 use C4::Output;
30 use C4::Authorities;
31 # get all the data ....
32 my %env;
33
34 my $input = new CGI;
35 my $result = $input->param('result');
36 my $search_string= $input->param('search_string');
37 my $op = $input->param('op');
38 my $id = $input->param('id');
39 my $category = $input->param('category');
40 my $index= $input->param('index');
41 my $insert = $input->param('insert');
42
43 my $dbh = C4::Context->dbh;
44
45 # make the page ...
46 #print $input->header;
47 if ($op eq "select") {
48         my $sti = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
49         $sti->execute($id);
50         my ($freelib_text) = $sti->fetchrow_array;
51         if (length($result)>0) {
52                 $result .= "|$freelib_text";
53         } else {
54                 $result = $freelib_text;
55         }
56 }
57 if ($op eq "add") {
58         newauthority($dbh,$category,$insert,$insert,'',1,'');
59         $search_string=$insert;
60 }
61
62 my $template = gettemplate("thesaurus_popup.tmpl",0);
63 # /search thesaurus terms starting by search_string
64 my @freelib;
65 my %stdlib;
66 my $select_list;
67 if ($search_string) {
68 #       my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'");
69         my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where match (category,freelib) AGAINST ('$search_string') and category ='$category'");
70                 $sti->execute;
71         while (my $line=$sti->fetchrow_hashref) {
72                 $stdlib{$line->{'id'}} = "$line->{'freelib'}";
73                 push(@freelib,$line->{'id'});
74         }
75         $select_list= CGI::scrolling_list( -name=>'id',
76                         -values=> \@freelib,
77                         -default=> "",
78                         -size=>1,
79                         -multiple=>0,
80                         -labels=> \%stdlib
81                         );
82 }
83 $template->param(select_list => $select_list,
84                                                 search_string => $search_string,
85                                                 result => $result,
86                                                 category => $category,
87                                                 index => $index
88                                                 );
89 print "Content-Type: text/html\n\n", $template->output;
90
91