Displaying branchnames rather than branchcodes
[koha.git] / opac / opac-suggestions.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19
20 use CGI;
21 use C4::Auth;    # get_template_and_user
22 use C4::Branch;
23 use C4::Output;
24 use C4::Suggestions;
25
26 my $input           = new CGI;
27 my $title           = $input->param('title');
28 my $author          = $input->param('author');
29 my $note            = $input->param('note');
30 my $copyrightdate   = $input->param('copyrightdate');
31 my $publishercode   = $input->param('publishercode');
32 my $volumedesc      = $input->param('volumedesc');
33 my $publicationyear = $input->param('publicationyear');
34 my $place           = $input->param('place');
35 my $isbn            = $input->param('isbn');
36 my $status          = $input->param('status');
37 my $suggestedbyme   = (defined $input->param('suggestedbyme')? $input->param('suggestedbyme'):1);
38 my $op              = $input->param('op');
39 $op = 'else' unless $op;
40
41 my ( $template, $borrowernumber, $cookie );
42
43 my $dbh = C4::Context->dbh;
44
45 if ( C4::Context->preference("AnonSuggestions") ) {
46     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
47         {
48             template_name   => "opac-suggestions.tmpl",
49             query           => $input,
50             type            => "opac",
51             authnotrequired => 1,
52         }
53     );
54     if ( !$borrowernumber ) {
55         $borrowernumber = C4::Context->preference("AnonSuggestions");
56     }
57 }
58 else {
59     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
60         {
61             template_name   => "opac-suggestions.tmpl",
62             query           => $input,
63             type            => "opac",
64             authnotrequired => 0,
65         }
66     );
67 }
68
69 if ( $op eq "add_confirm" ) {
70     &NewSuggestion(
71         $borrowernumber, $title,         $author,     $publishercode,
72         $note,           $copyrightdate, $volumedesc, $publicationyear,
73         $place,          $isbn,          ''
74     );
75
76     # empty fields, to avoid filter in "SearchSuggestion"
77     $title           = '';
78     $author          = '';
79     $publishercode   = '';
80     $copyrightdate   = '';
81     $volumedesc      = '';
82     $publicationyear = '';
83     $place           = '';
84     $isbn            = '';
85     $op              = 'else';
86 }
87
88 if ( $op eq "delete_confirm" ) {
89     my @delete_field = $input->param("delete_field");
90     foreach my $delete_field (@delete_field) {
91         &DelSuggestion( $borrowernumber, $delete_field );
92     }
93     $op = 'else';
94 }
95
96 my $suggestions_loop =
97   &SearchSuggestion( $borrowernumber, $author, $title, $publishercode, $status,
98     $suggestedbyme );
99 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;  
100 $template->param(
101     suggestions_loop => $suggestions_loop,
102     title            => $title,
103     author           => $author,
104     publishercode    => $publishercode,
105     status           => $status,
106     suggestedbyme    => $suggestedbyme,
107     "op_$op"         => 1,
108         suggestionsview => 1
109 );
110
111 output_html_with_http_headers $input, $cookie, $template->output;