Bug 12792: C4::Reserves breaks my vim syntax color
[koha.git] / cataloguing / value_builder / unimarc_field_210c.pl
blob67f4ab6cfd3d6a72979820238776d2b91d0bb377
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 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.
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.
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.
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 =head1 FUNCTIONS
37 =head2 plugin_parameters
39 Other parameters added when the plugin is called by the dopop function
41 =cut
43 sub plugin_parameters {
44 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
45 return "";
48 =head2 plugin_javascript
50 The javascript function called when the user enters the subfield.
51 contain 3 javascript functions :
52 * one called when the field is entered (OnFocus). Named FocusXXX
53 * one called when the field is leaved (onBlur). Named BlurXXX
54 * one called when the ... link is clicked (<a href="javascript:function">) named ClicXXX
56 returns :
57 * XXX
58 * a variable containing the 3 scripts.
59 the 3 scripts are inserted after the <input> in the html code
61 =cut
63 sub plugin_javascript {
64 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
65 my $function_name= $field_number;
66 #---- build editors list.
67 #---- the editor list is built from the "EDITORS" thesaurus
68 #---- this thesaurus category must be filled as follow :
69 #---- 200$a for isbn
70 #---- 200$b for editor
71 #---- 200$c (repeated) for collections
74 my $res = "
75 <script type=\"text/javascript\">
76 function Focus$function_name(index) {
80 function Blur$function_name(subfield_managed) {
81 return 1;
84 function Clic$function_name(subfield_managed) {
85 defaultvalue=escape(document.getElementById(\"$field_number\").value);
86 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');
88 </script>
90 return ($function_name,$res);
93 =head2 plugin
95 The true value_builded. The screen that is open in the popup window.
97 =cut
99 sub plugin {
100 my ($input) = @_;
101 my $query=new CGI;
102 my $op = $query->param('op');
103 my $authtypecode = $query->param('authtypecode');
104 my $index = $query->param('index');
105 my $category = $query->param('category');
106 my $resultstring = $query->param('result');
107 my $dbh = C4::Context->dbh;
109 my $startfrom=$query->param('startfrom');
110 $startfrom=0 if(!defined $startfrom);
111 my ($template, $loggedinuser, $cookie);
112 my $resultsperpage;
114 my $authtypes = getauthtypes;
115 my @authtypesloop;
116 foreach my $thisauthtype (keys %$authtypes) {
117 my $selected;
118 if ($thisauthtype eq $authtypecode) {
119 $selected=1;
121 my %row =(value => $thisauthtype,
122 selected => $selected,
123 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
124 index => $index,
126 push @authtypesloop, \%row;
129 if ($op eq "do_search") {
130 my @marclist = $query->param('marclist');
131 my @and_or = $query->param('and_or');
132 my @excluding = $query->param('excluding');
133 my @operator = $query->param('operator');
134 my @value = $query->param('value');
135 my $orderby = $query->param('orderby');
137 $resultsperpage= $query->param('resultsperpage');
138 $resultsperpage = 19 if(!defined $resultsperpage);
140 # builds tag and subfield arrays
141 my @tags;
143 my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
144 \@excluding, \@operator, \@value,
145 $startfrom*$resultsperpage, $resultsperpage,$authtypecode, $orderby);
147 # Getting the $b if it exists
148 for (@$results) {
149 my $authority = GetAuthority($_->{authid});
150 if ($authority->field('200') and $authority->subfield('200','b')) {
151 $_->{to_report} = $authority->subfield('200','b');
155 ($template, $loggedinuser, $cookie)
156 = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tt",
157 query => $query,
158 type => 'intranet',
159 authnotrequired => 0,
160 flagsrequired => {editcatalogue => '*'},
161 debug => 1,
164 # multi page display gestion
165 my $displaynext=0;
166 my $displayprev=$startfrom;
167 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
168 $displaynext = 1;
171 my @numbers = ();
173 if ($total>$resultsperpage) {
174 for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
175 if ($i<16) {
176 my $highlight=0;
177 ($startfrom==($i-1)) && ($highlight=1);
178 push @numbers, { number => $i,
179 highlight => $highlight ,
180 startfrom => ($i-1)};
185 my $from = $startfrom*$resultsperpage+1;
186 my $to;
188 if($total < (($startfrom+1)*$resultsperpage)) {
189 $to = $total;
190 } else {
191 $to = (($startfrom+1)*$resultsperpage);
193 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";
195 $template->param(result => $results) if $results;
196 $template->param('index' => $query->param('index'));
197 $template->param(startfrom=> $startfrom,
198 displaynext=> $displaynext,
199 displayprev=> $displayprev,
200 resultsperpage => $resultsperpage,
201 startfromnext => $startfrom+1,
202 startfromprev => $startfrom-1,
203 total=>$total,
204 from=>$from,
205 to=>$to,
206 numbers=>\@numbers,
207 authtypecode =>$authtypecode,
208 resultstring =>$value[0],
209 pagination_bar => pagination_bar(
210 $link,
211 getnbpages($total, $resultsperpage),
212 $startfrom,
213 'startfrom'
216 } else {
217 ($template, $loggedinuser, $cookie)
218 = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tt",
219 query => $query,
220 type => 'intranet',
221 authnotrequired => 0,
222 flagsrequired => {editcatalogue => '*'},
223 debug => 1,
226 $template->param(index => $index,
227 resultstring => $resultstring
231 $template->param(authtypesloop => \@authtypesloop);
232 $template->param(category => $category);
234 # Print the page
235 output_html_with_http_headers $query, $cookie, $template->output;