Bug 12705 - News not possible for one sublanguage if two sublanguages are installed
[koha.git] / acqui / ajax-getauthvaluedropbox.pl
blob0a74ada47125abd67434c2223fa3f3971448da25
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2012 BibLibre
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.
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.
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>.
20 =head1 NAME
22 ajax-getauthvaluedropbox.pl - returns an authorised values dropbox
24 =head1 DESCRIPTION
26 this script returns an authorised values dropbox
28 =head1 CGI PARAMETERS
30 =over 4
32 =item name
34 The name of the dropbox.
36 =item category
38 The category of authorised values.
40 =item default
42 Default value for the dropbox.
44 =back
46 =cut
48 use Modern::Perl;
50 use CGI;
51 use C4::Koha;
52 use C4::Charset;
53 use C4::Auth qw/check_api_auth/;
55 my $query = CGI->new();
56 binmode STDOUT, ':encoding(UTF-8)';
58 my ($status, $cookie, $sessionID) = check_api_auth($query, { catalogue => '*'} );
59 unless ($status eq "ok") {
60 print $query->header(-type => 'text/plain', -status => '403 Forbidden');
61 print '<option></option>';
62 exit 0;
65 my $input = new CGI;
66 my $name = $input->param('name');
67 my $category = $input->param('category');
68 my $default = $input->param('default');
69 $default = C4::Charset::NormalizeString($default);
71 binmode STDOUT, ':encoding(UTF-8)';
72 print $input->header(-type => 'text/plain', -charset => 'UTF-8');
73 my $avs = C4::Koha::GetAuthvalueDropbox($category, $default);
74 my $html = qq|<select id="$name" name="$name">|;
75 for my $av ( @$avs ) {
76 if ( $av->{default} ) {
77 $html .= qq|<option value="$av->{value}" selected="selected">$av->{label}</option>|;
78 } else {
79 $html .= qq|<option value="$av->{value}">$av->{label}</option>|;
82 $html .= qq|</select>|;
84 print $html;