Adding ability to return biblio results from acquisition search that contain no items
[koha.git] / serials / subscription-bib-search.pl
1 #!/usr/bin/perl
2 # WARNING: 4-character tab stops here
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 with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21
22 =head1 NAME
23
24 subscription-bib-search.pl
25
26 =head1 DESCRIPTION
27
28 this script search among all existing subscriptions.
29
30 =head1 PARAMETERS
31
32 =over 4
33
34 =item op
35 op use to know the operation to do on this template.
36  * do_search : to search the subscription.
37
38 Note that if op = do_search there are some others params specific to the search :
39     marclist,and_or,excluding,operator,value
40
41 =item startfrom
42 to multipage gestion.
43
44
45 =back
46
47 =cut
48
49
50 use strict;
51 require Exporter;
52 use CGI;
53 use C4::Koha;
54 use C4::Auth;
55 use HTML::Template;
56 use C4::Context;
57 use C4::Output;
58 use C4::Interface::CGI::Output;
59 use C4::SearchMarc;
60
61 my $query=new CGI;
62 # my $type=$query->param('type');
63 my $op = $query->param('op');
64 my $dbh = C4::Context->dbh;
65
66 my $startfrom=$query->param('startfrom');
67 $startfrom=0 unless $startfrom;
68 my ($template, $loggedinuser, $cookie);
69 my $resultsperpage;
70
71 if ($op eq "do_search") {
72     my @marclist = $query->param('marclist');
73     my @and_or = $query->param('and_or');
74     my @excluding = $query->param('excluding');
75     my @operator = $query->param('operator');
76     my @value = $query->param('value');
77
78     $resultsperpage= $query->param('resultsperpage');
79     $resultsperpage = 19 if(!defined $resultsperpage);
80     my $orderby = $query->param('orderby');
81
82     # builds tag and subfield arrays
83     my @tags;
84
85     foreach my $marc (@marclist) {
86         if ($marc) {
87             my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,$marc);
88             if ($tag) {
89                 push @tags,$dbh->quote("$tag$subfield");
90             } else {
91                 push @tags, $dbh->quote(substr($marc,0,4));
92             }
93         } else {
94             push @tags, "";
95         }
96     }
97     my ($results,$total) = catalogsearch($dbh, \@tags,\@and_or,
98                                \@excluding, \@operator, \@value,
99                                $startfrom*$resultsperpage, $resultsperpage,$orderby);
100
101     ($template, $loggedinuser, $cookie)
102         = get_template_and_user({template_name => "serials/result.tmpl",
103                 query => $query,
104                 type => "intranet",
105                 authnotrequired => 0,
106                 flagsrequired => {borrowers => 1},
107                 flagsrequired => {catalogue => 1},
108                 debug => 1,
109                 });
110
111     # multi page display gestion
112     my $displaynext=0;
113     my $displayprev=$startfrom;
114     if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
115         $displaynext = 1;
116     }
117
118     my @field_data = ();
119
120
121     for(my $i = 0 ; $i <= $#marclist ; $i++)
122     {
123         push @field_data, { term => "marclist", val=>$marclist[$i] };
124         push @field_data, { term => "and_or", val=>$and_or[$i] };
125         push @field_data, { term => "excluding", val=>$excluding[$i] };
126         push @field_data, { term => "operator", val=>$operator[$i] };
127         push @field_data, { term => "value", val=>$value[$i] };
128     }
129
130     my @numbers = ();
131
132     if ($total>$resultsperpage)
133     {
134         for (my $i=1; $i<$total/$resultsperpage+1; $i++)
135         {
136             if ($i<16)
137             {
138                 my $highlight=0;
139                 ($startfrom==($i-1)) && ($highlight=1);
140                 push @numbers, { number => $i,
141                     highlight => $highlight ,
142                     searchdata=> \@field_data,
143                     startfrom => ($i-1)};
144             }
145         }
146     }
147
148     my $from = $startfrom*$resultsperpage+1;
149     my $to;
150
151     if($total < (($startfrom+1)*$resultsperpage))
152     {
153         $to = $total;
154     } else {
155         $to = (($startfrom+1)*$resultsperpage);
156     }
157     $template->param(result => $results,
158                             startfrom=> $startfrom,
159                             displaynext=> $displaynext,
160                             displayprev=> $displayprev,
161                             resultsperpage => $resultsperpage,
162                             startfromnext => $startfrom+1,
163                             startfromprev => $startfrom-1,
164                             searchdata=>\@field_data,
165                             total=>$total,
166                             from=>$from,
167                             to=>$to,
168                             numbers=>\@numbers,
169                             );
170 } else {
171     ($template, $loggedinuser, $cookie)
172         = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
173                 query => $query,
174                 type => "intranet",
175                 authnotrequired => 0,
176                 flagsrequired => {catalogue => 1},
177                 debug => 1,
178                 });
179
180     my  %itemtypes = GetItemTypes();
181     my @values = values %itemtypes;
182     my $CGIitemtype=CGI::scrolling_list(
183             -name     => 'value',
184             -values   => \@values,
185             -labels   => \%itemtypes,
186             -size     => 1,
187             -multiple => 0
188     );
189
190     $template->param(
191             CGIitemtype => $CGIitemtype,
192     );
193 }
194
195 # Print the page
196 output_html_with_http_headers $query, $cookie, $template->output;
197
198 # Local Variables:
199 # tab-width: 4
200 # End: