porting 22 fixes to head
[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 use C4::Interface::CGI::Output;
33 # get all the data ....
34 my %env;
35
36 my $input = new CGI;
37 my $result = $input->param('result');
38 my $search_string= $input->param('search_string');
39 $search_string = $result unless ($search_string);
40 my $op = $input->param('op');
41 my $id = $input->param('id');
42 my $category = $input->param('category');
43 my $index= $input->param('index');
44 my $insert = $input->param('insert');
45 my $nohierarchy = $input->param('nohierarchy'); # if 1, just show the last part of entry (Marseille). If 0, show everything (Europe -- France --Marseille)
46 my $dbh = C4::Context->dbh;
47
48 # make the page ...
49 #print $input->header;
50 if ($op eq "select") {
51         my $sti = $dbh->prepare("select father,stdlib from bibliothesaurus where id=?");
52         $sti->execute($id);
53         my ($father,$freelib_text) = $sti->fetchrow_array;
54         if (length($result)>0) {
55                 if ($nohierarchy) {
56                         $result .= "|$freelib_text";
57                 } else {
58                         $result .= "|$father $freelib_text";
59                 }
60         } else {
61                 if ($nohierarchy) {
62                         $result = "$freelib_text";
63                 } else {
64                         $result = "$father $freelib_text";
65                 }
66         }
67 }
68 if ($op eq "add") {
69         newauthority($dbh,$category,$insert,$insert,'',1,'');
70         $search_string=$insert;
71 }
72 my ($template, $loggedinuser, $cookie)
73     = get_template_and_user({template_name => "thesaurus_popup.tmpl",
74                              query => $input,
75                              type => "intranet",
76                              authnotrequired => 0,
77                              flagsrequired => {parameters => 1},
78                              debug => 1,
79                              });
80 # /search thesaurus terms starting by search_string
81 my @freelib;
82 my %stdlib;
83 my $select_list;
84 if ($search_string) {
85 #       my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'");
86         my $sti=$dbh->prepare("select id,freelib,father from bibliothesaurus where match (category,freelib) AGAINST (?) and category =?");
87         $sti->execute($search_string,$category);
88         while (my $line=$sti->fetchrow_hashref) {
89                 if ($nohierarchy) {
90                         $stdlib{$line->{'id'}} = "$line->{'freelib'}";
91                 } else {
92                         $stdlib{$line->{'id'}} = "$line->{'father'} $line->{'freelib'}";
93                 }
94                 push(@freelib,$line->{'id'});
95         }
96         $select_list= CGI::scrolling_list( -name=>'id',
97                         -values=> \@freelib,
98                         -default=> "",
99                         -size=>1,
100                         -multiple=>0,
101                         -labels=> \%stdlib
102                         );
103 }
104 my @x = SearchDeeper('',$category,$search_string);
105 #my @son;
106 #foreach (my $value @$x) {
107 #       warn \@$x[$value]->{'stdlib'};
108 #}
109 my $dig_list= CGI::scrolling_list( -name=>'search_string',
110                 -values=> \@x,
111                 -default=> "",
112                 -size=>1,
113                 -multiple=>0,
114                 );
115
116 $template->param(select_list => $select_list,
117                                                 search_string => $search_string,
118                                                 dig_list => $dig_list,
119                                                 result => $result,
120                                                 category => $category,
121                                                 index => $index,
122                                                 nohierarchy => $nohierarchy,
123                                                 );
124 output_html_with_http_headers $input, $cookie, $template->output;
125
126