View | Details | Raw Unified | Return to bug 7180
Collapse All | Expand All

(-)a/acqui/fetch_sort_dropbox.pl (-108 lines)
Lines 1-107 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2008-2009 BibLibre SARL
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
use strict;
21
use warnings;
22
use CGI;
23
use C4::Context;
24
use C4::Output;
25
use C4::Auth;
26
use C4::Budgets;
27
28
=head1 NAME
29
30
fetch_sort_dropbox.pl
31
32
=head1 DESCRIPTION
33
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.
37
38
=head1 CGI PARAMETERS
39
40
=over 4
41
42
=item budget_id
43
44
Budget identifier
45
46
=item sort
47
48
Sort number. 1 or 2 for the moment.
49
50
=back
51
52
=cut
53
54
my $input = new CGI;
55
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);
59
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,
67
    }
68
);
69
70
my $ret_html;
71
my $name = 'sort'.$sort_nb;
72
my $authcat_field = 'sort'.$sort_nb.'_authcat';
73
74
my $budget = GetBudget($budget_id);
75
76
if ( $budget && $budget->{$authcat_field} ) {
77
    # with custom  Asort* planning values
78
    my $dropbox_values = GetAuthvalueDropbox( $budget->{$authcat_field}, '' );
79
80
    my @authorised_values;
81
    my %authorised_lib;
82
    my $default_value;
83
84
    foreach ( @$dropbox_values) {
85
        push @authorised_values, $_->{value};
86
        $authorised_lib{$_->{value}} = $_->{label};
87
        $default_value = $_->{value} if $_->{'default'};
88
    }
89
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,
99
    );
100
101
} else {
102
    # free input
103
    $ret_html = '<input type="text" size="20" name="'.$name.'" id="'.$name.'" />';
104
}
105
106
$template->param( 'return' => $ret_html );
107
output_html_with_http_headers $input, $cookie, $template->output;
108
- 

Return to bug 7180