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