Bug 17117: Patron personal details not displayed unless branch update request is...
[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
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.
12 #
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.
17 #
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>.
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 qw ( -utf8 );
29 use C4::Search;
30 use MARC::Record;
31 use C4::Koha;
32
33 ###TODO To rewrite in order to use SearchAuthorities
34
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
44
45
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');
51 }
52 </script>
53 ";
54 return ($function_name,$res);
55 }
56
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;
66
67     my $startfrom=$query->param('startfrom');
68     $startfrom=0 if(!defined $startfrom);
69     my ($template, $loggedinuser, $cookie);
70     my $resultsperpage;
71
72     if ($op eq "do_search") {
73         my @marclist = $query->multi_param('marclist');
74         my @and_or = $query->multi_param('and_or');
75         my @excluding = $query->multi_param('excluding');
76         my @operator = $query->multi_param('operator');
77         my @value = $query->multi_param('value');
78         my $orderby   = $query->param('orderby');
79
80         $resultsperpage= $query->param('resultsperpage');
81         $resultsperpage = 19 if(!defined $resultsperpage);
82
83         # builds tag and subfield arrays
84         my @tags;
85
86         my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
87                                             \@excluding, \@operator, \@value,
88                                             $startfrom*$resultsperpage, $resultsperpage,$authtypecode, $orderby);
89
90         # Getting the $b if it exists
91         for (@$results) {
92             my $authority = GetAuthority($_->{authid});
93                 if ($authority->field('200') and $authority->subfield('200','b')) {
94                     $_->{to_report} = $authority->subfield('200','b');
95             }
96         }
97
98         ($template, $loggedinuser, $cookie)
99             = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tt",
100                     query => $query,
101                     type => 'intranet',
102                     authnotrequired => 0,
103                     flagsrequired => {editcatalogue => '*'},
104                     debug => 1,
105                     });
106
107         # multi page display gestion
108         my $displaynext=0;
109         my $displayprev=$startfrom;
110         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
111             $displaynext = 1;
112         }
113
114         my @numbers = ();
115
116         if ($total>$resultsperpage) {
117             for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
118                 if ($i<16) {
119                     my $highlight=0;
120                     ($startfrom==($i-1)) && ($highlight=1);
121                     push @numbers, { number => $i,
122                         highlight => $highlight ,
123                         startfrom => ($i-1)};
124                 }
125             }
126         }
127
128         my $from = $startfrom*$resultsperpage+1;
129         my $to;
130
131         if($total < (($startfrom+1)*$resultsperpage)) {
132             $to = $total;
133         } else {
134             $to = (($startfrom+1)*$resultsperpage);
135         }
136         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";
137
138         $template->param(result => $results) if $results;
139         $template->param('index' => scalar $query->param('index'));
140         $template->param(startfrom=> $startfrom,
141                                 displaynext=> $displaynext,
142                                 displayprev=> $displayprev,
143                                 resultsperpage => $resultsperpage,
144                                 startfromnext => $startfrom+1,
145                                 startfromprev => $startfrom-1,
146                                 total=>$total,
147                                 from=>$from,
148                                 to=>$to,
149                                 numbers=>\@numbers,
150                                 authtypecode =>$authtypecode,
151                                 resultstring =>$value[0],
152                                 pagination_bar => pagination_bar(
153                                     $link,
154                                     getnbpages($total, $resultsperpage),
155                                     $startfrom,
156                                     'startfrom'
157                                 ),
158                                 );
159     } else {
160         ($template, $loggedinuser, $cookie)
161             = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tt",
162                     query => $query,
163                     type => 'intranet',
164                     authnotrequired => 0,
165                     flagsrequired => {editcatalogue => '*'},
166                     debug => 1,
167                     });
168
169         $template->param(index => $index,
170                         resultstring => $resultstring
171                         );
172     }
173
174     $template->param(category => $category);
175
176     # Print the page
177     output_html_with_http_headers $query, $cookie, $template->output;
178 }