Bug 10218 - In OPAC XSLT search results, add class to 'online access'
[koha.git] / acqui / fetch_sort_dropbox.pl
blobce47fb792620a5023ebac82be139dd990eb6f03f
1 #!/usr/bin/perl
3 # Copyright 2008-2009 BibLibre SARL
5 # This file is part of Koha.
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.
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.
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.
20 use strict;
21 use warnings;
22 use CGI;
23 use C4::Context;
24 use C4::Output;
25 use C4::Auth;
26 use C4::Budgets;
28 =head1 NAME
30 fetch_sort_dropbox.pl
32 =head1 DESCRIPTION
34 This script fetches sort values for a given budget id. Currently it is used to dynamically fill
35 'Statistic 1' and 'Statistic 2' comboboxes in neworderempty page. Values retrieved depend on
36 categories of authorized values defined in funds configuration.
38 =head1 CGI PARAMETERS
40 =over 4
42 =item budget_id
44 Budget identifier
46 =item sort
48 Sort number. 1 or 2 for the moment.
50 =back
52 =cut
54 my $input = new CGI;
56 my $budget_id = $input->param('budget_id');
57 my $sort_nb = $input->param('sort');
58 die "sort parameter can only be 1 or 2" unless ($sort_nb == 1 || $sort_nb == 2);
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61 { template_name => "acqui/ajax.tmpl",
62 query => $input,
63 type => "intranet",
64 authnotrequired => 0,
65 flagsrequired => {acquisition => 'order_manage'},
66 debug => 0,
70 my $ret_html;
71 my $name = 'sort'.$sort_nb;
72 my $authcat_field = 'sort'.$sort_nb.'_authcat';
74 my $budget = GetBudget($budget_id);
76 if ( $budget && $budget->{$authcat_field} ) {
77 # with custom Asort* planning values
78 my $dropbox_values = GetAuthvalueDropbox( $budget->{$authcat_field}, '' );
80 my @authorised_values;
81 my %authorised_lib;
82 my $default_value;
84 foreach ( @$dropbox_values) {
85 push @authorised_values, $_->{value};
86 $authorised_lib{$_->{value}} = $_->{label};
87 $default_value = $_->{value} if $_->{'default'};
90 $ret_html = CGI::scrolling_list(
91 -values => \@authorised_values,
92 -labels => \%authorised_lib,
93 -default => $default_value,
94 -override => 1,
95 -size => 1,
96 -multiple => 0,
97 -name => $name,
98 -id => $name,
101 } else {
102 # free input
103 $ret_html = '<input type="text" size="20" name="'.$name.'" id="'.$name.'" />';
106 $template->param( 'return' => $ret_html );
107 output_html_with_http_headers $input, $cookie, $template->output;