BUG6067 When Add Duplicate changing framework would loose data
[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         for (@$results) {
142             my $authority = GetAuthority($_->{authid});
143                 if ($authority->field('200') and $authority->subfield('200','b')) {
144                     $_->{to_report} = $authority->subfield('200','b');
145             }
146         }
147
148         ($template, $loggedinuser, $cookie)
149             = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tmpl",
150                     query => $query,
151                     type => 'intranet',
152                     authnotrequired => 0,
153                     flagsrequired => {editcatalogue => '*'},
154                     debug => 1,
155                     });
156
157         # multi page display gestion
158         my $displaynext=0;
159         my $displayprev=$startfrom;
160         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
161             $displaynext = 1;
162         }
163
164         my @numbers = ();
165
166         if ($total>$resultsperpage) {
167             for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
168                 if ($i<16) {
169                     my $highlight=0;
170                     ($startfrom==($i-1)) && ($highlight=1);
171                     push @numbers, { number => $i,
172                         highlight => $highlight ,
173                         startfrom => ($i-1)};
174                 }
175             }
176         }
177
178         my $from = $startfrom*$resultsperpage+1;
179         my $to;
180
181         if($total < (($startfrom+1)*$resultsperpage)) {
182             $to = $total;
183         } else {
184             $to = (($startfrom+1)*$resultsperpage);
185         }
186         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";
187
188         $template->param(result => $results) if $results;
189         $template->param('index' => $query->param('index'));
190         $template->param(startfrom=> $startfrom,
191                                 displaynext=> $displaynext,
192                                 displayprev=> $displayprev,
193                                 resultsperpage => $resultsperpage,
194                                 startfromnext => $startfrom+1,
195                                 startfromprev => $startfrom-1,
196                                 total=>$total,
197                                 from=>$from,
198                                 to=>$to,
199                                 numbers=>\@numbers,
200                                 authtypecode =>$authtypecode,
201                                 resultstring =>$value[0],
202                                 pagination_bar => pagination_bar(
203                                     $link,
204                                     getnbpages($total, $resultsperpage),
205                                     $startfrom,
206                                     'startfrom'
207                                 ),
208                                 );
209     } else {
210         ($template, $loggedinuser, $cookie)
211             = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tmpl",
212                     query => $query,
213                     type => 'intranet',
214                     authnotrequired => 0,
215                     flagsrequired => {editcatalogue => '*'},
216                     debug => 1,
217                     });
218
219         $template->param(index => $index,
220                         resultstring => $resultstring
221                         );
222     }
223
224     $template->param(authtypesloop => \@authtypesloop);
225     $template->param(category => $category);
226
227     # Print the page
228     output_html_with_http_headers $query, $cookie, $template->output;
229 }
230
231 1;