opac.css - button background fix for input.icon
[koha.git] / cataloguing / value_builder / unimarc_field_60X.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use C4::Auth;
23 use CGI;
24 use C4::Context;
25
26 use C4::Search;
27 use C4::Output;
28 use C4::Authorities;
29
30 sub plugin_javascript {
31     my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
32     my $function_name = $field_number;
33     my $res           = "
34         <script type=\"text/javascript\">
35             function Focus$function_name(subfield_managed) {
36                 return 1;
37             }
38
39             function Blur$function_name(subfield_managed) {
40                 return 1;
41             }
42
43             function Clic$function_name(index) {
44                 defaultvalue=document.getElementById(\"$field_number\").value;
45                 window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&index=$field_number&result=\"+defaultvalue,\"unimarc 600\",'width=700,height=300,toolbar=false,scrollbars=yes');
46
47             }
48         </script>
49     ";
50
51     return ( $function_name, $res );
52 }
53
54 sub plugin {
55     my ($input)       = @_;
56     my $dbh           = C4::Context->dbh;
57     my $index         = $input->param('index');
58     my $result        = $input->param('result');
59     my $search_string = $input->param('search_string');
60     my $op            = $input->param('op');
61     my $id            = $input->param('id');
62     my $insert        = $input->param('insert');
63     my %stdlib;
64     my $select_list;
65
66     if ( $op eq "add" ) {
67         newauthority( $dbh, 'NC', $insert, $insert, '', 1, '' );
68         $search_string = $insert;
69     }
70     if ( $op eq "select" ) {
71         my $sti =
72           $dbh->prepare("select stdlib from bibliothesaurus where id=?");
73         $sti->execute($id);
74         my ($freelib_text) = $sti->fetchrow_array;
75         $result = $freelib_text;
76     }
77     my $Rsearch_string = "$search_string%";
78     my $authoritysep   = C4::Context->preference('authoritysep');
79     my @splitted       = /$authoritysep/, $search_string;
80     my $level          = $#splitted + 1;
81     my $sti;
82     if ($search_string)
83     {    # if no search pattern, returns only the 50 1st top level values
84         $sti =
85           $dbh->prepare(
86 "select distinct freelib,father,level from bibliothesaurus where category='NC' and freelib like ? order by father,freelib"
87           );
88     }
89     else {
90         $sti =
91           $dbh->prepare(
92 "select distinct freelib,father,level from bibliothesaurus where category='NC' and level=0 and freelib like ? order by father,freelib limit 0,50"
93           );
94     }
95     $sti->execute($Rsearch_string);
96     my @results;
97     while ( my ( $freelib, $father, $level ) = $sti->fetchrow ) {
98         my %line;
99         if ($father) {
100             $line{value} = "$father $freelib";
101         }
102         else {
103             $line{value} = "$freelib";
104         }
105         $line{level}  = $level + 1;
106         $line{father} = $father;
107         push @results, \%line;
108     }
109     my @DeeperResults = SearchDeeper( 'NC', $search_string );
110     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
111         {
112             template_name => "cataloguing/value_builder/unimarc_field_60X.tmpl",
113             query         => $input,
114             type          => "intranet",
115             authnotrequired => 0,
116             flagsrequired   => { editcatalogue => 1 },
117             debug           => 1,
118         }
119     );
120
121 # builds collection list : search isbn and editor, in parent, then load collections from bibliothesaurus table
122     $template->param(
123         index         => $index,
124         result        => $result,
125         search_string => $search_string ? $search_string : $result,
126         results       => \@results,
127         deeper        => \@DeeperResults,
128     );
129     output_html_with_http_headers $input, $cookie, $template->output;
130 }
131
132 1;