Bug 7180: (follow-up) update license version
[koha.git] / acqui / ajax-getauthvaluedropbox.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2012 BibLibre
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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;