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