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