lasts commits before 1.3.3 release
[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 C4::Auth;
26 use CGI;
27 use C4::Context;
28 use HTML::Template;
29 use C4::Search;
30 use C4::Output;
31 use C4::Authorities;
32 # get all the data ....
33 my %env;
34
35 my $input = new CGI;
36 my $result = $input->param('result');
37 my $search_string= $input->param('search_string');
38 my $op = $input->param('op');
39 my $id = $input->param('id');
40 my $category = $input->param('category');
41 my $index= $input->param('index');
42 my $insert = $input->param('insert');
43
44 my $dbh = C4::Context->dbh;
45
46 # make the page ...
47 #print $input->header;
48 if ($op eq "select") {
49         my $sti = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
50         $sti->execute($id);
51         my ($freelib_text) = $sti->fetchrow_array;
52         if (length($result)>0) {
53                 $result .= "|$freelib_text";
54         } else {
55                 $result = $freelib_text;
56         }
57 }
58 if ($op eq "add") {
59         newauthority($dbh,$category,$insert,$insert,'',1,'');
60         $search_string=$insert;
61 }
62 my ($template, $loggedinuser, $cookie)
63     = get_template_and_user({template_name => "thesaurus_popup.tmpl",
64                              query => $input,
65                              type => "intranet",
66                              authnotrequired => 0,
67                              flagsrequired => {parameters => 1},
68                              debug => 1,
69                              });
70 # /search thesaurus terms starting by search_string
71 my @freelib;
72 my %stdlib;
73 my $select_list;
74 if ($search_string) {
75 #       my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'");
76         my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where match (category,freelib) AGAINST ('$search_string') and category ='$category'");
77                 $sti->execute;
78         while (my $line=$sti->fetchrow_hashref) {
79                 $stdlib{$line->{'id'}} = "$line->{'freelib'}";
80                 push(@freelib,$line->{'id'});
81         }
82         $select_list= CGI::scrolling_list( -name=>'id',
83                         -values=> \@freelib,
84                         -default=> "",
85                         -size=>1,
86                         -multiple=>0,
87                         -labels=> \%stdlib
88                         );
89 }
90 $template->param(select_list => $select_list,
91                                                 search_string => $search_string,
92                                                 result => $result,
93                                                 category => $category,
94                                                 index => $index
95                                                 );
96 print $input->header(-cookie => $cookie),$template->output;
97
98