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