Bug 7180: Order from staged file improvements
[koha.git] / acqui / ajax-getauthvaluedropbox.pl
1 #!/usr/bin/perl
2
3 # Copyright 2012 BibLibre
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 =head1 NAME
21
22 ajax-getauthvaluedropbox.pl - returns an authorised values dropbox
23
24 =head1 DESCRIPTION
25
26 this script returns an authorised values dropbox
27
28 =head1 CGI PARAMETERS
29
30 =over 4
31
32 =item name
33
34 The name of the dropbox.
35
36 =item category
37
38 The category of authorised values.
39
40 =item default
41
42 Default value for the dropbox.
43
44 =back
45
46 =cut
47
48 use Modern::Perl;
49
50 use CGI;
51 use C4::Budgets;
52 use C4::Charset;
53
54 my $input = new CGI;
55 my $name = $input->param('name');
56 my $category = $input->param('category');
57 my $default = $input->param('default');
58 $default = C4::Charset::NormalizeString($default);
59
60 binmode STDOUT, ':encoding(UTF-8)';
61 print $input->header(-type => 'text/plain', -charset => 'UTF-8');
62 my $avs = GetAuthvalueDropbox($category, $default);
63 my $html = qq|<select id="$name", name="$name">|;
64 for my $av ( @$avs ) {
65     if ( $av->{default} ) {
66         $html .= qq|<option value="$av->{value}" selected="selected">$av->{label}</option>|;
67     } else {
68         $html .= qq|<option value="$av->{value}">$av->{label}</option>|;
69     }
70 }
71 $html .= qq|</select>|;
72
73 print $html;