add zipcode list
[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 if ($op eq "do_search") {
71     my $query = $input->param('q');
72
73     $resultsperpage= $input->param('resultsperpage');
74     $resultsperpage = 19 if(!defined $resultsperpage);
75
76     my ($error,$marcrecords) = SimpleSearch($query);
77     my $total = scalar @$marcrecords;
78
79     if (defined $error) {
80         $template->param(query_error => $error);
81         warn "error: ".$error;
82         output_html_with_http_headers $input, $cookie, $template->output;
83         exit;
84     }
85     my @results;
86     warn "total=".$total;
87     
88     for(my $i=0;$i<$total;$i++) {
89         my %resultsloop;
90         my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
91         my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
92
93         #build the hash for the template.
94         $resultsloop{highlight}       = ($i % 2)?(1):(0);
95         $resultsloop{title}           = $biblio->{'title'};
96         $resultsloop{subtitle}        = $biblio->{'subtitle'};
97         $resultsloop{biblionumber}    = $biblio->{'biblionumber'};
98         $resultsloop{author}          = $biblio->{'author'};
99         $resultsloop{publishercode}   = $biblio->{'publishercode'};
100         $resultsloop{publicationyear} = $biblio->{'publicationyear'};
101
102         push @results, \%resultsloop;
103     }
104     
105     ($template, $loggedinuser, $cookie)
106         = get_template_and_user({template_name => "serials/result.tmpl",
107                 query => $input,
108                 type => "intranet",
109                 authnotrequired => 0,
110                 flagsrequired => {serials => 1},
111                 flagsrequired => {catalogue => 1},
112                 debug => 1,
113                 });
114
115     # multi page display gestion
116     my $displaynext=0;
117     my $displayprev=$startfrom;
118     if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
119         $displaynext = 1;
120     }
121
122
123     my @numbers = ();
124
125     if ($total>$resultsperpage)
126     {
127         for (my $i=1; $i<$total/$resultsperpage+1; $i++)
128         {
129             if ($i<16)
130             {
131                 my $highlight=0;
132                 ($startfrom==($i-1)) && ($highlight=1);
133                 push @numbers, { number => $i,
134                     highlight => $highlight ,
135                     searchdata=> \@results,
136                     startfrom => ($i-1)};
137             }
138         }
139     }
140
141     my $from = $startfrom*$resultsperpage+1;
142     my $to;
143
144     if($total < (($startfrom+1)*$resultsperpage))
145     {
146         $to = $total;
147     } else {
148         $to = (($startfrom+1)*$resultsperpage);
149     }
150     $template->param(
151                             query => $query,
152                             resultsloop => \@results,
153                             startfrom=> $startfrom,
154                             displaynext=> $displaynext,
155                             displayprev=> $displayprev,
156                             resultsperpage => $resultsperpage,
157                             startfromnext => $startfrom+1,
158                             startfromprev => $startfrom-1,
159                             total=>$total,
160                             from=>$from,
161                             to=>$to,
162                             numbers=>\@numbers,
163                             );
164 } # end of if ($op eq "do_search")
165  else {
166     ($template, $loggedinuser, $cookie)
167         = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
168                 query => $input,
169                 type => "intranet",
170                 authnotrequired => 0,
171                 flagsrequired => {catalogue => 1, serials=>1},
172                 debug => 1,
173                 });
174
175     my  %itemtypes = GetItemTypes();
176     my @values = values %itemtypes;
177     my $CGIitemtype=CGI::scrolling_list(
178             -name     => 'value',
179             -values   => \@values,
180             -labels   => \%itemtypes,
181             -size     => 1,
182             -multiple => 0
183     );
184
185     $template->param(
186             CGIitemtype => $CGIitemtype,
187     );
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: