numberingpattern was disimissed when editing a subscription
[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 C4::Context;
56 use C4::Output;
57 use C4::Search;
58 use C4::Biblio;
59
60 my $input=new CGI;
61 # my $type=$query->param('type');
62 my $op = $input->param('op');
63 my $dbh = C4::Context->dbh;
64
65 my $startfrom=$input->param('startfrom');
66 $startfrom=0 unless $startfrom;
67 my ($template, $loggedinuser, $cookie);
68 my $resultsperpage;
69
70 my $query = $input->param('q');
71 # don't run the search if no search term !
72 if ($op eq "do_search" && $query) {
73
74     $resultsperpage= $input->param('resultsperpage');
75     $resultsperpage = 19 if(!defined $resultsperpage);
76
77     my ($error,$marcrecords) = SimpleSearch($query);
78     my $total = scalar @$marcrecords;
79
80     if (defined $error) {
81         $template->param(query_error => $error);
82         warn "error: ".$error;
83         output_html_with_http_headers $input, $cookie, $template->output;
84         exit;
85     }
86     my @results;
87     warn "total=".$total;
88     
89     for(my $i=0;$i<$total;$i++) {
90         my %resultsloop;
91         my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
92         my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
93
94         #build the hash for the template.
95         $resultsloop{highlight}       = ($i % 2)?(1):(0);
96         $resultsloop{title}           = $biblio->{'title'};
97         $resultsloop{subtitle}        = $biblio->{'subtitle'};
98         $resultsloop{biblionumber}    = $biblio->{'biblionumber'};
99         $resultsloop{author}          = $biblio->{'author'};
100         $resultsloop{publishercode}   = $biblio->{'publishercode'};
101         $resultsloop{publicationyear} = $biblio->{'publicationyear'};
102
103         push @results, \%resultsloop;
104     }
105     
106     ($template, $loggedinuser, $cookie)
107         = get_template_and_user({template_name => "serials/result.tmpl",
108                 query => $input,
109                 type => "intranet",
110                 authnotrequired => 0,
111                 flagsrequired => {serials => 1},
112                 flagsrequired => {catalogue => 1},
113                 debug => 1,
114                 });
115
116     # multi page display gestion
117     my $displaynext=0;
118     my $displayprev=$startfrom;
119     if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
120         $displaynext = 1;
121     }
122
123
124     my @numbers = ();
125
126     if ($total>$resultsperpage)
127     {
128         for (my $i=1; $i<$total/$resultsperpage+1; $i++)
129         {
130             if ($i<16)
131             {
132                 my $highlight=0;
133                 ($startfrom==($i-1)) && ($highlight=1);
134                 push @numbers, { number => $i,
135                     highlight => $highlight ,
136                     searchdata=> \@results,
137                     startfrom => ($i-1)};
138             }
139         }
140     }
141
142     my $from = $startfrom*$resultsperpage+1;
143     my $to;
144
145     if($total < (($startfrom+1)*$resultsperpage))
146     {
147         $to = $total;
148     } else {
149         $to = (($startfrom+1)*$resultsperpage);
150     }
151     $template->param(
152                             query => $query,
153                             resultsloop => \@results,
154                             startfrom=> $startfrom,
155                             displaynext=> $displaynext,
156                             displayprev=> $displayprev,
157                             resultsperpage => $resultsperpage,
158                             startfromnext => $startfrom+1,
159                             startfromprev => $startfrom-1,
160                             total=>$total,
161                             from=>$from,
162                             to=>$to,
163                             numbers=>\@numbers,
164                             );
165 } # end of if ($op eq "do_search" & $query)
166  elsif ($op eq "do_search") {
167     ($template, $loggedinuser, $cookie)
168         = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
169                 query => $input,
170                 type => "intranet",
171                 authnotrequired => 0,
172                 flagsrequired => {catalogue => 1, serials=>1},
173                 debug => 1,
174                 });
175     $template->param("no_query" => 1);
176 }
177  else {
178     ($template, $loggedinuser, $cookie)
179         = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
180                 query => $input,
181                 type => "intranet",
182                 authnotrequired => 0,
183                 flagsrequired => {catalogue => 1, serials=>1},
184                 debug => 1,
185                 });
186
187     $template->param("no_query" => 0);
188 }
189
190 # Print the page
191 output_html_with_http_headers $input, $cookie, $template->output;
192
193 # Local Variables:
194 # tab-width: 4
195 # End: