Bug 11559: (QA followup) fix QA issues
[koha.git] / cataloguing / value_builder / unimarc_field_210c.pl
blobd775add86edae683511b68090fe570145bf357b9
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
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.
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.
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>.
21 use strict;
22 use warnings;
24 use C4::AuthoritiesMarc;
25 use C4::Auth;
26 use C4::Context;
27 use C4::Output;
28 use CGI qw ( -utf8 );
29 use C4::Search;
30 use MARC::Record;
31 use C4::Koha;
33 ###TODO To rewrite in order to use SearchAuthorities
35 sub plugin_javascript {
36 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
37 my $function_name= $field_number;
38 #---- build editors list.
39 #---- the editor list is built from the "EDITORS" thesaurus
40 #---- this thesaurus category must be filled as follow :
41 #---- 200$a for isbn
42 #---- 200$b for editor
43 #---- 200$c (repeated) for collections
46 my $res = "
47 <script type=\"text/javascript\">
48 function Clic$function_name(subfield_managed) {
49 defaultvalue=escape(document.getElementById(\"$field_number\").value);
50 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');
52 </script>
54 return ($function_name,$res);
57 sub plugin {
58 my ($input) = @_;
59 my $query=new CGI;
60 my $op = $query->param('op');
61 my $authtypecode = $query->param('authtypecode');
62 my $index = $query->param('index');
63 my $category = $query->param('category');
64 my $resultstring = $query->param('result');
65 my $dbh = C4::Context->dbh;
67 my $startfrom=$query->param('startfrom');
68 $startfrom=0 if(!defined $startfrom);
69 my ($template, $loggedinuser, $cookie);
70 my $resultsperpage;
72 my $authtypes = getauthtypes;
73 my @authtypesloop;
74 foreach my $thisauthtype (keys %$authtypes) {
75 my $selected;
76 if ($thisauthtype eq $authtypecode) {
77 $selected=1;
79 my %row =(value => $thisauthtype,
80 selected => $selected,
81 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
82 index => $index,
84 push @authtypesloop, \%row;
87 if ($op eq "do_search") {
88 my @marclist = $query->param('marclist');
89 my @and_or = $query->param('and_or');
90 my @excluding = $query->param('excluding');
91 my @operator = $query->param('operator');
92 my @value = $query->param('value');
93 my $orderby = $query->param('orderby');
95 $resultsperpage= $query->param('resultsperpage');
96 $resultsperpage = 19 if(!defined $resultsperpage);
98 # builds tag and subfield arrays
99 my @tags;
101 my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
102 \@excluding, \@operator, \@value,
103 $startfrom*$resultsperpage, $resultsperpage,$authtypecode, $orderby);
105 # Getting the $b if it exists
106 for (@$results) {
107 my $authority = GetAuthority($_->{authid});
108 if ($authority->field('200') and $authority->subfield('200','b')) {
109 $_->{to_report} = $authority->subfield('200','b');
113 ($template, $loggedinuser, $cookie)
114 = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tt",
115 query => $query,
116 type => 'intranet',
117 authnotrequired => 0,
118 flagsrequired => {editcatalogue => '*'},
119 debug => 1,
122 # multi page display gestion
123 my $displaynext=0;
124 my $displayprev=$startfrom;
125 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
126 $displaynext = 1;
129 my @numbers = ();
131 if ($total>$resultsperpage) {
132 for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
133 if ($i<16) {
134 my $highlight=0;
135 ($startfrom==($i-1)) && ($highlight=1);
136 push @numbers, { number => $i,
137 highlight => $highlight ,
138 startfrom => ($i-1)};
143 my $from = $startfrom*$resultsperpage+1;
144 my $to;
146 if($total < (($startfrom+1)*$resultsperpage)) {
147 $to = $total;
148 } else {
149 $to = (($startfrom+1)*$resultsperpage);
151 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";
153 $template->param(result => $results) if $results;
154 $template->param('index' => $query->param('index'));
155 $template->param(startfrom=> $startfrom,
156 displaynext=> $displaynext,
157 displayprev=> $displayprev,
158 resultsperpage => $resultsperpage,
159 startfromnext => $startfrom+1,
160 startfromprev => $startfrom-1,
161 total=>$total,
162 from=>$from,
163 to=>$to,
164 numbers=>\@numbers,
165 authtypecode =>$authtypecode,
166 resultstring =>$value[0],
167 pagination_bar => pagination_bar(
168 $link,
169 getnbpages($total, $resultsperpage),
170 $startfrom,
171 'startfrom'
174 } else {
175 ($template, $loggedinuser, $cookie)
176 = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tt",
177 query => $query,
178 type => 'intranet',
179 authnotrequired => 0,
180 flagsrequired => {editcatalogue => '*'},
181 debug => 1,
184 $template->param(index => $index,
185 resultstring => $resultstring
189 $template->param(authtypesloop => \@authtypesloop);
190 $template->param(category => $category);
192 # Print the page
193 output_html_with_http_headers $query, $cookie, $template->output;