bugfixes (various), handling utf-8 without guessencoding (as suggested by joshua...
[koha.git] / cataloguing / addbooks.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #
6 # Modified saas@users.sf.net 12:00 01 April 2001
7 # The biblioitemnumber was not correctly initialised
8 # The max(barcode) value was broken - koha 'barcode' is a string value!
9 # - If left blank, barcode value now defaults to max(biblionumber)
10
11 #
12 # TODO
13 #
14 # Add info on biblioitems and items already entered as you enter new ones
15 #
16 # Add info on biblioitems and items already entered as you enter new ones
17
18 # Copyright 2000-2002 Katipo Communications
19 #
20 # This file is part of Koha.
21 #
22 # Koha is free software; you can redistribute it and/or modify it under the
23 # terms of the GNU General Public License as published by the Free Software
24 # Foundation; either version 2 of the License, or (at your option) any later
25 # version.
26 #
27 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
28 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
29 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
30 #
31 # You should have received a copy of the GNU General Public License along with
32 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
33 # Suite 330, Boston, MA  02111-1307 USA
34
35 use strict;
36 use CGI;
37 use C4::Auth;
38 use C4::Biblio;
39 use C4::Breeding;
40 use C4::Output;
41
42 use C4::Koha;
43 use C4::Search;
44
45 my $input = new CGI;
46
47 my $success = $input->param('biblioitem');
48 my $query   = $input->param('q');
49 my @value = $input->param('value');
50
51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
52     {
53         template_name   => "cataloguing/addbooks.tmpl",
54         query           => $input,
55         type            => "intranet",
56         authnotrequired => 0,
57         flagsrequired   => { editcatalogue => 1 },
58         debug           => 1,
59     }
60 );
61
62 # get framework list
63 my $frameworks = getframeworks;
64 my @frameworkcodeloop;
65 foreach my $thisframeworkcode (keys %$frameworks) {
66         my %row =(value => $thisframeworkcode,
67                                 frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
68                         );
69         push @frameworkcodeloop, \%row;
70 }
71
72 # Searching the catalog.
73 if($query) {
74     # find results
75     my ($error, $marcresults) = SimpleSearch($query);
76
77     if (defined $error) {
78         $template->param(error => $error);
79         warn "error: ".$error;
80         output_html_with_http_headers $input, $cookie, $template->output;
81         exit;
82     }
83     # format output
84     my $total = scalar @$marcresults;
85     my @newresults = searchResults($query, $total, $total , 0, @$marcresults);
86     $template->param(
87         total => $total,
88         query => $query,
89         resultsloop => \@newresults,
90     );
91 }
92
93 # fill with books in breeding farm
94 my $toggle=0;
95 my ($title,$isbn);
96 # fill isbn or title, depending on what has been entered
97 #u must do check on isbn because u can find number in beginning of title
98 #check is on isbn legnth 13 for new isbn and 10 for old isbn
99 my $querylength=length($query);
100  if ($query =~ /\d/ and ($querylength eq 13 or $querylength eq 10))
101 {
102 $isbn=$query;
103 }
104 $title=$query unless $isbn;
105 my ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn ) if $query;
106 my @breeding_loop = ();
107 for ( my $i = 0 ; $i <= $#resultsbr ; $i++ ) {
108     my %row_data;
109     if ( $i % 2 ) {
110         $toggle = 0;
111     }
112     else {
113         $toggle = 1;
114     }
115     $row_data{toggle} = $toggle;
116     $row_data{id}     = $resultsbr[$i]->{'id'};
117     $row_data{isbn}   = $resultsbr[$i]->{'isbn'};
118     $row_data{file}   = $resultsbr[$i]->{'file'};
119     $row_data{title}  = $resultsbr[$i]->{'title'};
120     $row_data{author} = $resultsbr[$i]->{'author'};
121     push ( @breeding_loop, \%row_data );
122 }
123
124 $template->param( frameworkcodeloop => \@frameworkcodeloop,
125                   breeding_loop => \@breeding_loop,
126               );
127
128 output_html_with_http_headers $input, $cookie, $template->output;