Bug 24083: (follow-up) Include SelfCheckInModule
[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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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 =cut
41
42 use strict;
43 #use warnings; FIXME - Bug 2505
44 use C4::Auth;
45 use CGI qw ( -utf8 );
46 use C4::Context;
47
48 use C4::AuthoritiesMarc;
49 use C4::Output;
50
51 =head1 DESCRIPTION
52
53 plugin_parameters : other parameters added when the plugin is called by the dopop function
54
55 =cut
56
57 sub plugin_javascript {
58     my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
59     my $function_name = $field_number;
60     my $res = "
61     <script>
62     
63     
64         function Clic$function_name(index) {
65         /* find the 010a value and the 210c. it will be used in the popup to find possibles collections */
66             var isbn_found   = 0;
67             var editor_found = 0;
68             
69             var inputs = document.getElementsByTagName('input');
70             
71             for(var i=0 , len=inputs.length ; i \< len ; i++ ){
72                 if(inputs[i].id.match(/^tag_010_subfield_a_.*/)){
73                     isbn_found = inputs[i].value;
74                 }
75                 if(inputs[i].id.match(/^tag_210_subfield_c_.*/)){
76                     editor_found = inputs[i].value;
77                 }
78                 if(editor_found && isbn_found){
79                     break;
80                 }
81             }
82                     
83             defaultvalue = document.getElementById(\"$field_number\").value;
84             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');
85     
86         }
87     </script>
88 ";
89
90     return ( $function_name, $res );
91 }
92
93 sub plugin {
94     my ($input)      = @_;
95     my $index        = $input->param('index');
96     my $result       = $input->param('result');
97     my $editor_found = $input->param('editor_found');
98     my $AuthoritySeparator = C4::Context->preference("AuthoritySeparator");
99     
100     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
101         {
102             template_name =>
103               "cataloguing/value_builder/unimarc_field_225a.tt",
104             query           => $input,
105             type            => "intranet",
106             flagsrequired   => { editcatalogue => '*' },
107             debug           => 1,
108         }
109     );
110
111 # builds collection list : search isbn and editor, in parent, then load collections from bibliothesaurus table
112 # if there is an isbn, complete search
113     my @collections;
114     
115     my @value     = ($editor_found,"","");
116     my @tags      = ("mainentry","","");
117     my @and_or    = ('and','','');
118     my @operator  = ('is','','');
119     my @excluding = ('','','');
120     
121     
122     my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
123                                             \@excluding, \@operator, \@value,
124                                             0, 20,"EDITORS", "HeadingAsc");
125     foreach my $editor (@$results){
126         my $authority = GetAuthority($editor->{authid});
127         foreach my $col ($authority->subfield('200','c')){
128             push @collections, $col;
129         }
130             
131     } 
132     @collections = sort @collections;
133     # my @collections = ( "test" );
134     my $collection = {
135             values  => \@collections,
136             default => "$result",
137     };
138
139     $template->param(
140         index      => $index,
141         collection => $collection
142     );
143     output_html_with_http_headers $input, $cookie, $template->output;
144 }