Follow-up fix for Bug 6753, Markup corrections and improvements for label export...
[koha.git] / cataloguing / value_builder / unimarc_field_225a.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
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 =head1 SYNOPSIS
22
23 This plugin is used to map isbn/editor with collection.
24 It need :
25   in thesaurus, a category named EDITORS
26   in this category, datas must be entered like following :
27   isbn separator editor separator collection.
28   for example :
29   2204 -- Cerf -- Cogitatio fidei
30   2204 -- Cerf -- Le Magistere de l'Eglise
31   2204 -- Cerf -- Lectio divina
32   2204 -- Cerf -- Lire la Bible
33   2204 -- Cerf -- Pour lire
34   2204 -- Cerf -- Sources chretiennes
35
36   when the user clic on ... on 225a line, the popup shows the list of collections from the selected editor
37   if the biblio has no isbn, then the search if done on editor only
38   If the biblio ha an isbn, the search is done on isbn and editor. It's faster.
39
40 =over 2
41
42 =cut
43
44 use strict;
45 #use warnings; FIXME - Bug 2505
46 use C4::Auth;
47 use CGI;
48 use C4::Context;
49
50 use C4::AuthoritiesMarc;
51 use C4::Output;
52
53 =head1
54
55 plugin_parameters : other parameters added when the plugin is called by the dopop function
56
57 =cut
58
59 sub plugin_parameters {
60     my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
61     return "";
62 }
63
64 sub plugin_javascript {
65     my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
66     my $function_name = $field_number;
67     my $res = "
68     <script type=\"text/javascript\">
69         function Focus$function_name(subfield_managed) {
70             return 1;
71         }
72     
73         function Blur$function_name(subfield_managed) {
74             return 1;
75         }
76     
77         function Clic$function_name(index) {
78         // find the 010a value and the 210c. it will be used in the popup to find possibles collections
79             var isbn_found   = 0;
80             var editor_found = 0;
81             
82             var inputs = document.getElementsByTagName('input');
83             
84             for(var i=0 , len=inputs.length ; i \< len ; i++ ){
85                 if(inputs[i].id.match(/^tag_010_subfield_a_.*/)){
86                     isbn_found = inputs[i].value;
87                 }
88                 if(inputs[i].id.match(/^tag_210_subfield_c_.*/)){
89                     editor_found = inputs[i].value;
90                 }
91                 if(editor_found && isbn_found){
92                     break;
93                 }
94             }
95                     
96             defaultvalue = document.getElementById(\"$field_number\").value;
97             window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_225a.pl&index=\"+index+\"&result=\"+defaultvalue+\"&editor_found=\"+editor_found,\"unimarc225a\",'width=500,height=400,toolbar=false,scrollbars=no');
98     
99         }
100     </script>
101 ";
102
103     return ( $function_name, $res );
104 }
105
106 sub plugin {
107     my ($input)      = @_;
108     my $index        = $input->param('index');
109     my $result       = $input->param('result');
110     my $editor_found = $input->param('editor_found');
111     my $authoritysep = C4::Context->preference("authoritysep");
112     
113     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
114         {
115             template_name =>
116               "cataloguing/value_builder/unimarc_field_225a.tmpl",
117             query           => $input,
118             type            => "intranet",
119             authnotrequired => 0,
120             flagsrequired   => { editcatalogue => '*' },
121             debug           => 1,
122         }
123     );
124
125 # builds collection list : search isbn and editor, in parent, then load collections from bibliothesaurus table
126 # if there is an isbn, complete search
127     my @collections;
128     
129     my @value     = ($editor_found,"","");
130     my @tags      = ("mainentry","","");
131     my @and_or    = ('and','','');
132     my @operator  = ('is','','');
133     my @excluding = ('','','');
134     
135     
136     my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
137                                             \@excluding, \@operator, \@value,
138                                             0, 20,"EDITORS", "HeadingAsc");
139     foreach my $editor (@$results){
140         my $authority = GetAuthority($editor->{authid});
141         foreach my $col ($authority->subfield('200','c')){
142             push @collections, $col;
143         }
144             
145     } 
146     @collections = sort @collections;
147     #   my @collections = ["test"];
148     my $collection = CGI::scrolling_list(
149         -name     => 'f1',
150         -values   => \@collections,
151         -default  => "$result",
152         -size     => 1,
153         -multiple => 0,
154     );
155     $template->param(
156         index      => $index,
157         collection => $collection
158     );
159     output_html_with_http_headers $input, $cookie, $template->output;
160 }
161
162 1;