followup - update SCO to recognize ITEMNOTSAMEBRANCH
[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 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.
12 #
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.
16 #
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.
20
21 #use strict;
22 #use warnings; FIXME - Bug 2505
23
24 use C4::AuthoritiesMarc;
25 use C4::Auth;
26 use C4::Context;
27 use C4::Output;
28 use CGI;
29 use C4::Search;
30 use MARC::Record;
31 use C4::Koha;
32
33 ###TODO To rewrite in order to use SearchAuthorities
34
35 =head1
36
37 plugin_parameters : other parameters added when the plugin is called by the dopop function
38
39 =cut
40 sub plugin_parameters {
41 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
42 return "";
43 }
44
45 =head1
46
47 plugin_javascript : the javascript function called when the user enters the subfield.
48 contain 3 javascript functions :
49 * one called when the field is entered (OnFocus). Named FocusXXX
50 * one called when the field is leaved (onBlur). Named BlurXXX
51 * one called when the ... link is clicked (<a href="javascript:function">) named ClicXXX
52
53 returns :
54 * XXX
55 * a variable containing the 3 scripts.
56 the 3 scripts are inserted after the <input> in the html code
57
58 =cut
59 sub plugin_javascript {
60 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
61 my $function_name= $field_number;
62 #---- build editors list.
63 #---- the editor list is built from the "EDITORS" thesaurus
64 #---- this thesaurus category must be filled as follow :
65 #---- 200$a for isbn
66 #---- 200$b for editor
67 #---- 200$c (repeated) for collections
68
69
70 my $res  = "
71 <script type=\"text/javascript\">
72 function Focus$function_name(index) {
73
74 }
75
76 function Blur$function_name(subfield_managed) {
77     return 1;
78 }
79
80 function Clic$function_name(subfield_managed) {
81     defaultvalue=escape(document.getElementById(\"$field_number\").value);
82     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');
83 }
84 </script>
85 ";
86 return ($function_name,$res);
87 }
88
89 =head1
90
91 plugin : the true value_builded. The screen that is open in the popup window.
92
93 =cut
94
95 sub plugin {
96 my ($input) = @_;
97     my $query=new CGI;
98     my $op = $query->param('op');
99     my $authtypecode = $query->param('authtypecode');
100     my $index = $query->param('index');
101     my $category = $query->param('category');
102     my $resultstring = $query->param('result');
103     my $dbh = C4::Context->dbh;
104     
105     my $startfrom=$query->param('startfrom');
106     $startfrom=0 if(!defined $startfrom);
107     my ($template, $loggedinuser, $cookie);
108     my $resultsperpage;
109     
110     my $authtypes = getauthtypes;
111     my @authtypesloop;
112     foreach my $thisauthtype (keys %$authtypes) {
113         my $selected = 1 if $thisauthtype eq $authtypecode;
114         my %row =(value => $thisauthtype,
115                     selected => $selected,
116                     authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
117                 index => $index,
118                 );
119         push @authtypesloop, \%row;
120     }
121
122     if ($op eq "do_search") {
123         my @marclist = $query->param('marclist');
124         my @and_or = $query->param('and_or');
125         my @excluding = $query->param('excluding');
126         my @operator = $query->param('operator');
127         my @value = $query->param('value');
128         my $orderby   = $query->param('orderby');
129         
130         $resultsperpage= $query->param('resultsperpage');
131         $resultsperpage = 19 if(!defined $resultsperpage);
132     
133         # builds tag and subfield arrays
134         my @tags;
135     
136         my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
137                                             \@excluding, \@operator, \@value,
138                                             $startfrom*$resultsperpage, $resultsperpage,$authtypecode, $orderby);
139
140         # Getting the $b if it exists
141         foreach my $_ (@$results) {
142                 if ($_->{reported_tag} =~ m/^\$b/) {
143                     $_->{to_report} = substr($_->{reported_tag}, 2);
144             }
145         }
146
147         ($template, $loggedinuser, $cookie)
148             = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tmpl",
149                     query => $query,
150                     type => 'intranet',
151                     authnotrequired => 0,
152                     flagsrequired => {editcatalogue => '*'},
153                     debug => 1,
154                     });
155     
156         # multi page display gestion
157         my $displaynext=0;
158         my $displayprev=$startfrom;
159         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
160             $displaynext = 1;
161         }
162     
163         my @numbers = ();
164     
165         if ($total>$resultsperpage) {
166             for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
167                 if ($i<16) {
168                     my $highlight=0;
169                     ($startfrom==($i-1)) && ($highlight=1);
170                     push @numbers, { number => $i,
171                         highlight => $highlight ,
172                         startfrom => ($i-1)};
173                 }
174             }
175         }
176     
177         my $from = $startfrom*$resultsperpage+1;
178         my $to;
179     
180         if($total < (($startfrom+1)*$resultsperpage)) {
181             $to = $total;
182         } else {
183             $to = (($startfrom+1)*$resultsperpage);
184         }
185         my $link="../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_210c.pl&amp;authtypecode=EDITORS&and_or=$and_or&amp;marclist=$marclist&amp;operator=$operator&amp;orderby=$orderby&amp;excluding=$excluding&amp;".join("&amp;",map {"value=".$_} @value)."&amp;op=do_search&amp;type=intranet&amp;index=$index";
186         warn "$link ,".getnbpages($total, $resultsperpage);
187         $template->param(result => $results) if $results;
188         $template->param('index' => $query->param('index'));
189         $template->param(startfrom=> $startfrom,
190                                 displaynext=> $displaynext,
191                                 displayprev=> $displayprev,
192                                 resultsperpage => $resultsperpage,
193                                 startfromnext => $startfrom+1,
194                                 startfromprev => $startfrom-1,
195                                 total=>$total,
196                                 from=>$from,
197                                 to=>$to,
198                                 numbers=>\@numbers,
199                                 authtypecode =>$authtypecode,
200                                 resultstring =>$value[0],
201                                 pagination_bar => pagination_bar(
202                                     $link,
203                                     getnbpages($total, $resultsperpage),
204                                     $startfrom,
205                                     'startfrom'
206                                 ),
207                                 );
208     } else {
209         ($template, $loggedinuser, $cookie)
210             = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tmpl",
211                     query => $query,
212                     type => 'intranet',
213                     authnotrequired => 0,
214                     flagsrequired => {editcatalogue => '*'},
215                     debug => 1,
216                     });
217     
218         $template->param(index => $index,
219                         resultstring => $resultstring
220                         );
221     }
222     
223     $template->param(authtypesloop => \@authtypesloop);
224     $template->param(category => $category);
225     
226     # Print the page
227     output_html_with_http_headers $query, $cookie, $template->output;
228 }
229
230 1;