removing warnings
[koha.git] / search.marc / 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 use strict;
22 require Exporter;
23 use CGI;
24 use C4::Auth;
25 use HTML::Template;
26 use C4::Context;
27 use C4::Search;
28 use C4::Auth;
29 use C4::Output;
30 use C4::Interface::CGI::Output;
31 use C4::Biblio;
32 use C4::SearchMarc;
33 use C4::Koha; # XXX subfield_is_koha_internal_p
34
35 my $query=new CGI;
36 my $type=$query->param('type');
37 my $op = $query->param('op');
38
39 my $dbh = C4::Context->dbh;
40
41 my $startfrom=$query->param('startfrom');
42 ($startfrom) || ($startfrom=0);
43 my ($template, $loggedinuser, $cookie);
44
45 if ($op eq "do_search") {
46         my @marclist = $query->param('marclist');
47         my @and_or = $query->param('and_or');
48         my @excluding = $query->param('excluding');
49         my @operator = $query->param('operator');
50         my @value = $query->param('value');
51         # builds tag and subfield arrays
52         my @tags;
53         my @subfields;
54         foreach my $marc (@marclist) {
55                 push @tags, substr($marc,0,3);
56                 push @subfields, substr($marc,3,1);
57         }
58         my @results = catalogsearch($dbh, \@tags, \@subfields, \@and_or,
59                                                                                         \@excluding, \@operator, \@value,
60                                                                                         $startfrom, 20);
61         ($template, $loggedinuser, $cookie)
62                 = get_template_and_user({template_name => "search.marc/result.tmpl",
63                                 query => $query,
64                                 type => $type,
65                                 authnotrequired => 0,
66                                 flagsrequired => {borrowers => 1},
67 #                               flagsrequired => {catalogue => 1},
68                                 debug => 1,
69                                 });
70         $template->param(result => \@results);
71
72 } else {
73         ($template, $loggedinuser, $cookie)
74                 = get_template_and_user({template_name => "search.marc/search.tmpl",
75                                 query => $query,
76                                 type => $type,
77                                 authnotrequired => 0,
78                                 flagsrequired => {catalogue => 1},
79                                 debug => 1,
80                                 });
81         #$template->param(loggedinuser => $loggedinuser);
82         my $tagslib;
83         if ($type eq "opac") {
84                 $tagslib = &MARCgettagslib($dbh,1);
85         } else {
86                 $tagslib = &MARCgettagslib($dbh,1);
87         }
88         my @marcarray;
89         push @marcarray,"";
90         my $widest_menu_item_width = 0;
91         for (my $pass = 1; $pass <= 2; $pass += 1) {
92                 for (my $tabloop = 0; $tabloop<=9;$tabloop++) {
93                         my $separator_inserted_p = 0; # FIXME... should not use!!
94                         foreach my $tag (sort(keys (%{$tagslib}))) {
95                                 foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
96                                         next if subfield_is_koha_internal_p($subfield);
97                                         next unless ($tagslib->{$tag}->{$subfield}->{tab} eq $tabloop);
98                                         my $menu_item = "$tag$subfield - $tagslib->{$tag}->{$subfield}->{lib}";
99                                         if ($pass == 1) {
100                                                 $widest_menu_item_width = length $menu_item
101                                                                 if $widest_menu_item_width < length $menu_item;
102                                         } else {
103                                                 if (!$separator_inserted_p) {
104                                                         my $w = int(($widest_menu_item_width - 3 + 0.5)/2);
105                                                         my $s = ('-' x ($w * 4/5));
106                                                         push @marcarray,  "$s $tabloop $s";
107                                                         $separator_inserted_p = 1;
108                                                 }
109                                                 push @marcarray, $menu_item;
110                                         }
111                                 }
112                         }
113                 }
114         }
115         my $marclist = CGI::scrolling_list(-name=>"marclist",
116                                         -values=> \@marcarray,
117                                         -size=>1,
118                                         -multiple=>0,
119                                         -onChange => "sql_update()",
120                                         );
121         $template->param("marclist" => $marclist);
122 }
123 # Print the page
124 output_html_with_http_headers $query, $cookie, $template->output;
125
126
127 # Local Variables:
128 # tab-width: 4
129 # End: