Bug 17600: Standardize our EXPORT_OK
[srvgit] / cataloguing / value_builder / unimarc_field_210c.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 use Modern::Perl;
22 use C4::Auth qw( get_template_and_user );
23 use C4::Auth qw( get_template_and_user );
24 use C4::Context;
25 use C4::Output qw( pagination_bar output_html_with_http_headers );
26 use CGI qw ( -utf8 );
27 use C4::Search;
28 use C4::Koha qw( getnbpages );
29
30 ###TODO To rewrite in order to use SearchAuthorities
31
32 sub plugin_javascript {
33 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
34 my $function_name= $field_number;
35 #---- build editors list.
36 #---- the editor list is built from the "EDITORS" thesaurus
37 #---- this thesaurus category must be filled as follow :
38 #---- 200$a for isbn
39 #---- 200$b for editor
40 #---- 200$c (repeated) for collections
41
42
43 my $res  = "
44 <script>
45 function Clic$function_name(subfield_managed) {
46     defaultvalue=escape(document.getElementById(\"$field_number\").value);
47     newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_210c.pl&index=\"+subfield_managed,\"unimarc_225a\",'width=500,height=600,toolbar=false,scrollbars=yes');
48 }
49 </script>
50 ";
51 return ($function_name,$res);
52 }
53
54 sub plugin {
55 my ($input) = @_;
56     my $query=CGI->new;
57     my $op = $query->param('op');
58     my $authtypecode = $query->param('authtypecode');
59     my $index = $query->param('index');
60     my $category = $query->param('category');
61     my $resultstring = $query->param('result');
62     my $dbh = C4::Context->dbh;
63
64     my $startfrom = $query->param('startfrom') // 1; # Page number starting at 1
65     my ($template, $loggedinuser, $cookie);
66     my $resultsperpage = $query->param('resultsperpage') // 20; # TODO hardcoded
67     my $offset = ( $startfrom - 1 ) * $resultsperpage;
68
69     if ($op eq "do_search") {
70         my @marclist = $query->multi_param('marclist');
71         my @and_or = $query->multi_param('and_or');
72         my @excluding = $query->multi_param('excluding');
73         my @operator = $query->multi_param('operator');
74         my @value = $query->multi_param('value');
75         my $orderby   = $query->param('orderby');
76
77         # builds tag and subfield arrays
78         my @tags;
79
80         my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
81                                             \@excluding, \@operator, \@value,
82                                             $offset, $resultsperpage,$authtypecode, $orderby);
83
84         # Getting the $b if it exists
85         for (@$results) {
86             my $authority = GetAuthority($_->{authid});
87                 if ($authority->field('200') and $authority->subfield('200','b')) {
88                     $_->{to_report} = $authority->subfield('200','b');
89             }
90         }
91
92         ($template, $loggedinuser, $cookie)
93             = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tt",
94                     query => $query,
95                     type => 'intranet',
96                     flagsrequired => {editcatalogue => '*'},
97                     });
98
99         # Results displayed in current page
100         my $from = $offset + 1;
101         my $to = ( $offset + $resultsperpage > $total ) ? $total : $offset + $resultsperpage;
102
103         my $link="../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_210c.pl&amp;authtypecode=EDITORS&amp;".join("&amp;",map {"value=".$_} @value)."&amp;op=do_search&amp;type=intranet&amp;index=$index";
104
105         $template->param(result => $results) if $results;
106         $template->param('index' => scalar $query->param('index'));
107         $template->param(
108                                 total=>$total,
109                                 from=>$from,
110                                 to=>$to,
111                                 authtypecode =>$authtypecode,
112                                 resultstring =>$value[0],
113                                 pagination_bar => pagination_bar(
114                                     $link,
115                                     getnbpages($total, $resultsperpage),
116                                     $startfrom,
117                                     'startfrom'
118                                 ),
119                                 );
120     } else {
121         ($template, $loggedinuser, $cookie)
122             = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tt",
123                     query => $query,
124                     type => 'intranet',
125                     flagsrequired => {editcatalogue => '*'},
126                     });
127
128         $template->param(index => $index,
129                         resultstring => $resultstring
130                         );
131     }
132
133     $template->param(category => $category);
134
135     # Print the page
136     output_html_with_http_headers $query, $cookie, $template->output;
137 }