Bug 12701 - OPAC reading history still accessible by URL if turned OFF
[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;
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 FUNCTIONS
36
37 =head2 plugin_parameters
38
39 Other parameters added when the plugin is called by the dopop function
40
41 =cut
42
43 sub plugin_parameters {
44 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
45 return "";
46 }
47
48 =head2 plugin_javascript
49
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
55
56 returns :
57 * XXX
58 * a variable containing the 3 scripts.
59 the 3 scripts are inserted after the <input> in the html code
60
61 =cut
62
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
72
73
74 my $res  = "
75 <script type=\"text/javascript\">
76 function Focus$function_name(index) {
77
78 }
79
80 function Blur$function_name(subfield_managed) {
81     return 1;
82 }
83
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');
87 }
88 </script>
89 ";
90 return ($function_name,$res);
91 }
92
93 =head2 plugin
94
95 The true value_builded. The screen that is open in the popup window.
96
97 =cut
98
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;
108
109     my $startfrom=$query->param('startfrom');
110     $startfrom=0 if(!defined $startfrom);
111     my ($template, $loggedinuser, $cookie);
112     my $resultsperpage;
113
114     my $authtypes = getauthtypes;
115     my @authtypesloop;
116     foreach my $thisauthtype (keys %$authtypes) {
117         my $selected;
118         if ($thisauthtype eq $authtypecode) {
119             $selected=1;
120         }
121         my %row =(value => $thisauthtype,
122                     selected => $selected,
123                     authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
124                 index => $index,
125                 );
126         push @authtypesloop, \%row;
127     }
128
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');
136
137         $resultsperpage= $query->param('resultsperpage');
138         $resultsperpage = 19 if(!defined $resultsperpage);
139
140         # builds tag and subfield arrays
141         my @tags;
142
143         my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
144                                             \@excluding, \@operator, \@value,
145                                             $startfrom*$resultsperpage, $resultsperpage,$authtypecode, $orderby);
146
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');
152             }
153         }
154
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,
162                     });
163
164         # multi page display gestion
165         my $displaynext=0;
166         my $displayprev=$startfrom;
167         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
168             $displaynext = 1;
169         }
170
171         my @numbers = ();
172
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)};
181                 }
182             }
183         }
184
185         my $from = $startfrom*$resultsperpage+1;
186         my $to;
187
188         if($total < (($startfrom+1)*$resultsperpage)) {
189             $to = $total;
190         } else {
191             $to = (($startfrom+1)*$resultsperpage);
192         }
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";
194
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'
214                                 ),
215                                 );
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,
224                     });
225
226         $template->param(index => $index,
227                         resultstring => $resultstring
228                         );
229     }
230
231     $template->param(authtypesloop => \@authtypesloop);
232     $template->param(category => $category);
233
234     # Print the page
235     output_html_with_http_headers $query, $cookie, $template->output;
236 }
237
238 1;