Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 234 lines (197 sloc) 7.339 kb
a0b06fb @ctfliblime Prepare for perlbrew usage by changing all script magic to "#!/usr/bin/e...
ctfliblime authored
1 #!/usr/bin/env perl
247e04d templating serials & moving them to a serials directory, more self-expla...
tipaul authored
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
7e52a56 Clean up before final commits
tgarip1957 authored
21
fc1342f rel_3_0 moved to HEAD
tipaul authored
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;
c9f3ede @colinsc Enable warnings in serial scripts
colinsc authored
51 use warnings;
4bf76c2 bug 2615: remove unneeded 'require Exporter'
Galen Charlton authored
52
247e04d templating serials & moving them to a serials directory, more self-expla...
tipaul authored
53 use CGI;
54 use C4::Koha;
55 use C4::Auth;
3607caa @ctfliblime Add Koha.pm and include it universally
ctfliblime authored
56 use Koha;
247e04d templating serials & moving them to a serials directory, more self-expla...
tipaul authored
57 use C4::Context;
fc1342f rel_3_0 moved to HEAD
tipaul authored
58 use C4::Output;
59 use C4::Search;
7e52a56 Clean up before final commits
tgarip1957 authored
60 use C4::Biblio;
61
fc1342f rel_3_0 moved to HEAD
tipaul authored
62 my $input=new CGI;
63 # my $type=$query->param('type');
bfad238 @colinsc Ensure op is defined in serials scripts
colinsc authored
64 my $op = $input->param('op') || q{};
247e04d templating serials & moving them to a serials directory, more self-expla...
tipaul authored
65 my $dbh = C4::Context->dbh;
66
fc1342f rel_3_0 moved to HEAD
tipaul authored
67 my $startfrom=$input->param('startfrom');
68 $startfrom=0 unless $startfrom;
247e04d templating serials & moving them to a serials directory, more self-expla...
tipaul authored
69 my ($template, $loggedinuser, $cookie);
70 my $resultsperpage;
71
c6b086c 1409 empty search term in subscription search biblio
Paul POULAIN authored
72 my $query = $input->param('q');
73 # don't run the search if no search term !
74 if ($op eq "do_search" && $query) {
fc1342f rel_3_0 moved to HEAD
tipaul authored
75
f5674f9 @PaulPoulain reintroducing the limit on itemtype when searching a biblio in subscript...
PaulPoulain authored
76 # add the itemtype limit if applicable
77 my $itemtypelimit = $input->param('itemtypelimit');
d914fb6 @fredericd Bug 3351 - Limit Serials Search for Biblio to an item type
fredericd authored
78 if ( $itemtypelimit ) {
79 my $index = C4::Context->preference("item-level_itypes") ? 'itype' : 'itemtype';
80 $query .= " AND $index=$itemtypelimit";
81 }
c9f3ede @colinsc Enable warnings in serial scripts
colinsc authored
82
fc1342f rel_3_0 moved to HEAD
tipaul authored
83 $resultsperpage= $input->param('resultsperpage');
3442669 (bug #3355) add pagination in bib search for subscriptions
Nahuel ANGELINETTI authored
84 $resultsperpage = 20 if(!defined $resultsperpage);
fc1342f rel_3_0 moved to HEAD
tipaul authored
85
3442669 (bug #3355) add pagination in bib search for subscriptions
Nahuel ANGELINETTI authored
86 my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom*$resultsperpage, $resultsperpage);
fc1342f rel_3_0 moved to HEAD
tipaul authored
87 my $total = scalar @$marcrecords;
88
89 if (defined $error) {
90 $template->param(query_error => $error);
91 warn "error: ".$error;
92 output_html_with_http_headers $input, $cookie, $template->output;
93 exit;
94 }
95 my @results;
c9f3ede @colinsc Enable warnings in serial scripts
colinsc authored
96
fc1342f rel_3_0 moved to HEAD
tipaul authored
97 for(my $i=0;$i<$total;$i++) {
98 my %resultsloop;
d147d3e @pjones9 DE265: incomplete support for marcxml
pjones9 authored
99 my $marcrecord = MARC::File::XML::decode($marcrecords->[$i]);
a481fad Code cleaning :
tipaul authored
100 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
fc1342f rel_3_0 moved to HEAD
tipaul authored
101
102 #build the hash for the template.
103 $resultsloop{highlight} = ($i % 2)?(1):(0);
104 $resultsloop{title} = $biblio->{'title'};
105 $resultsloop{subtitle} = $biblio->{'subtitle'};
106 $resultsloop{biblionumber} = $biblio->{'biblionumber'};
107 $resultsloop{author} = $biblio->{'author'};
108 $resultsloop{publishercode} = $biblio->{'publishercode'};
109 $resultsloop{publicationyear} = $biblio->{'publicationyear'};
110
111 push @results, \%resultsloop;
112 }
c9f3ede @colinsc Enable warnings in serial scripts
colinsc authored
113
fc1342f rel_3_0 moved to HEAD
tipaul authored
114 ($template, $loggedinuser, $cookie)
115 = get_template_and_user({template_name => "serials/result.tmpl",
116 query => $input,
117 type => "intranet",
118 authnotrequired => 0,
119 flagsrequired => {serials => 1},
120 flagsrequired => {catalogue => 1},
121 debug => 1,
122 });
123
124 # multi page display gestion
125 my $displaynext=0;
126 my $displayprev=$startfrom;
3442669 (bug #3355) add pagination in bib search for subscriptions
Nahuel ANGELINETTI authored
127 if(($total_hits - (($startfrom+1)*($resultsperpage))) > 0 ){
fc1342f rel_3_0 moved to HEAD
tipaul authored
128 $displaynext = 1;
129 }
130
131
132 my @numbers = ();
133
3442669 (bug #3355) add pagination in bib search for subscriptions
Nahuel ANGELINETTI authored
134 if ($total_hits>$resultsperpage)
fc1342f rel_3_0 moved to HEAD
tipaul authored
135 {
136 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
137 {
138 if ($i<16)
139 {
140 my $highlight=0;
141 ($startfrom==($i-1)) && ($highlight=1);
142 push @numbers, { number => $i,
143 highlight => $highlight ,
144 searchdata=> \@results,
145 startfrom => ($i-1)};
146 }
147 }
148 }
c9f3ede @colinsc Enable warnings in serial scripts
colinsc authored
149
3442669 (bug #3355) add pagination in bib search for subscriptions
Nahuel ANGELINETTI authored
150 my $from = 0;
151 $from = $startfrom*$resultsperpage+1 if($total_hits > 0);
fc1342f rel_3_0 moved to HEAD
tipaul authored
152 my $to;
153
3442669 (bug #3355) add pagination in bib search for subscriptions
Nahuel ANGELINETTI authored
154 if($total_hits < (($startfrom+1)*$resultsperpage))
fc1342f rel_3_0 moved to HEAD
tipaul authored
155 {
156 $to = $total;
157 } else {
158 $to = (($startfrom+1)*$resultsperpage);
159 }
160 $template->param(
161 query => $query,
162 resultsloop => \@results,
163 startfrom=> $startfrom,
164 displaynext=> $displaynext,
165 displayprev=> $displayprev,
166 resultsperpage => $resultsperpage,
167 startfromnext => $startfrom+1,
168 startfromprev => $startfrom-1,
3442669 (bug #3355) add pagination in bib search for subscriptions
Nahuel ANGELINETTI authored
169 total=>$total_hits,
fc1342f rel_3_0 moved to HEAD
tipaul authored
170 from=>$from,
171 to=>$to,
172 numbers=>\@numbers,
173 );
c6b086c 1409 empty search term in subscription search biblio
Paul POULAIN authored
174 } # end of if ($op eq "do_search" & $query)
175 elsif ($op eq "do_search") {
176 ($template, $loggedinuser, $cookie)
177 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
178 query => $input,
179 type => "intranet",
180 authnotrequired => 0,
181 flagsrequired => {catalogue => 1, serials=>1},
182 debug => 1,
183 });
f5674f9 @PaulPoulain reintroducing the limit on itemtype when searching a biblio in subscript...
PaulPoulain authored
184 # load the itemtypes
185 my $itemtypes = GetItemTypes;
186 my @itemtypesloop;
187 my $selected=1;
188 my $cnt;
189 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
190 my %row =(
191 code => $thisitemtype,
192 selected => $selected,
193 description => $itemtypes->{$thisitemtype}->{'description'},
194 );
195 $selected = 0 if ($selected) ;
196 push @itemtypesloop, \%row;
197 }
198 $template->param(itemtypeloop => \@itemtypesloop);
c6b086c 1409 empty search term in subscription search biblio
Paul POULAIN authored
199 $template->param("no_query" => 1);
200 }
fc1342f rel_3_0 moved to HEAD
tipaul authored
201 else {
202 ($template, $loggedinuser, $cookie)
203 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
204 query => $input,
205 type => "intranet",
206 authnotrequired => 0,
207 flagsrequired => {catalogue => 1, serials=>1},
208 debug => 1,
209 });
f5674f9 @PaulPoulain reintroducing the limit on itemtype when searching a biblio in subscript...
PaulPoulain authored
210 # load the itemtypes
211 my $itemtypes = GetItemTypes;
212 my @itemtypesloop;
213 my $selected=1;
214 my $cnt;
215 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
216 my %row =(
217 code => $thisitemtype,
218 selected => $selected,
219 description => $itemtypes->{$thisitemtype}->{'description'},
220 );
221 $selected = 0 if ($selected) ;
222 push @itemtypesloop, \%row;
223 }
224 $template->param(itemtypeloop => \@itemtypesloop);
c6b086c 1409 empty search term in subscription search biblio
Paul POULAIN authored
225 $template->param("no_query" => 0);
247e04d templating serials & moving them to a serials directory, more self-expla...
tipaul authored
226 }
227
228 # Print the page
fc1342f rel_3_0 moved to HEAD
tipaul authored
229 output_html_with_http_headers $input, $cookie, $template->output;
247e04d templating serials & moving them to a serials directory, more self-expla...
tipaul authored
230
231 # Local Variables:
232 # tab-width: 4
233 # End:
Something went wrong with that request. Please try again.