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