From 1a03a8a38eb07b9bf55e3e2afeb4f2cb4e954f66 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Wed, 13 Apr 2011 17:21:47 +0100 Subject: [PATCH] Bug 6181: Remove CGI Scolling lists from C4::Budgets As noted on bug 766 more cases of usage of CGI::scrolling_list were imported into C4::Budgets Even if we were not trying to remove usage of this the C4 modules are not the place to generate markup Most of these routines are noise as they are not used in any current code but cause confusion and increase maintenance overhead. They are removed The sort dropboxes on order create are the only references in current templates to these routines they have been replaced by a select list generated by the markup. They can probably be removed too but their existence although the option that causes them to be displayed seems unlikely to be set. I've left them pending resolution of some of the inconsistencies and confusions surrounding Budgts Signed-off-by: Chris Cormack Signed-off-by: Paul Poulain Signed-off-by: Chris Cormack --- C4/Budgets.pm | 93 ++++--------------- acqui/addorderiso2709.pl | 12 +-- acqui/fetch_sort_dropbox.pl | 65 ------------- acqui/neworderempty.pl | 16 ++-- admin/aqbudgetperiods.pl | 2 - admin/aqbudgets.pl | 3 - admin/aqplan.pl | 2 - .../prog/en/modules/acqui/addorderiso2709.tt | 29 ++++-- .../prog/en/modules/acqui/neworderempty.tt | 24 ++++- 9 files changed, 75 insertions(+), 171 deletions(-) delete mode 100755 acqui/fetch_sort_dropbox.pl diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 98e5d632b7..888b4fde54 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -50,10 +50,7 @@ BEGIN { &AddBudgetPeriod &DelBudgetPeriod - &GetBudgetPeriodsDropbox - &GetBudgetSortDropbox &GetAuthvalueDropbox - &GetBudgetPermDropbox &ModBudgetPlan @@ -334,24 +331,6 @@ sub GetBudgetOrdered { return $sum; } -# ------------------------------------------------------------------- -sub GetBudgetPermDropbox { - my ($perm) = @_; - my %labels; - $labels{'0'} = 'None'; - $labels{'1'} = 'Owner'; - $labels{'2'} = 'Library'; - my $radio = CGI::scrolling_list( - -id => 'budget_permission', - -name => 'budget_permission', - -values => [ '0', '1', '2' ], - -default => $perm, - -labels => \%labels, - -size => 1, - ); - return $radio; -} - # ------------------------------------------------------------------- sub GetBudgetAuthCats { my ($budget_period_id) = shift; @@ -374,61 +353,27 @@ sub GetBudgetAuthCats { # ------------------------------------------------------------------- sub GetAuthvalueDropbox { - my ( $name, $authcat, $default ) = @_; - my @authorised_values; - my %authorised_lib; - my $value; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( - "SELECT authorised_value,lib - FROM authorised_values - WHERE category = ? - ORDER BY lib" - ); - $sth->execute( $authcat ); - - push @authorised_values, ''; - while (my ($value, $lib) = $sth->fetchrow_array) { - push @authorised_values, $value; - $authorised_lib{$value} = $lib; - } - - return 0 if keys(%authorised_lib) == 0; - - my $budget_authvalue_dropbox = CGI::scrolling_list( - -values => \@authorised_values, - -labels => \%authorised_lib, - -default => $default, - -override => 1, - -size => 1, - -multiple => 0, - -name => $name, - -id => $name, + my ( $authcat, $default ) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare( + 'SELECT authorised_value,lib FROM authorised_values + WHERE category = ? ORDER BY lib' ); + $sth->execute( $authcat ); + my $option_list = []; + my @authorised_values = ( q{} ); + while (my ($value, $lib) = $sth->fetchrow_array) { + push @{$option_list}, { + value => $value, + label => $lib, + default => ($default eq $value), + }; + } - return $budget_authvalue_dropbox -} - -# ------------------------------------------------------------------- -sub GetBudgetPeriodsDropbox { - my ($budget_period_id) = @_; - my %labels; - my @values; - my ($active, $periods) = GetBudgetPeriods(); - foreach my $r (@$periods) { - $labels{"$r->{budget_period_id}"} = $r->{budget_period_description}; - push @values, $r->{budget_period_id}; - } - - # if no buget_id is passed then its an add - my $budget_period_dropbox = CGI::scrolling_list( - -name => 'budget_period_id', - -values => \@values, - -default => $budget_period_id ? $budget_period_id : $active, - -size => 1, - -labels => \%labels, - ); - return $budget_period_dropbox; + if ( @{$option_list} ) { + return $option_list; + } + return; } # ------------------------------------------------------------------- diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index c46263a243..0b9d860f3f 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -281,12 +281,12 @@ $template->param( budget_loop => $budget_loop,); my $CGIsort1; if ($budget) { # its a mod .. if ( defined $budget->{'sort1_authcat'} ) { # with custom Asort* planning values - $CGIsort1 = GetAuthvalueDropbox( 'sort1', $budget->{'sort1_authcat'}, $data->{'sort1'} ); + $CGIsort1 = GetAuthvalueDropbox( $budget->{'sort1_authcat'}, $data->{'sort1'} ); } } elsif ( scalar(@$budgets) ) { - $CGIsort1 = GetAuthvalueDropbox( 'sort1', @$budgets[0]->{'sort1_authcat'}, '' ); + $CGIsort1 = GetAuthvalueDropbox( @$budgets[0]->{'sort1_authcat'}, '' ); } else { - $CGIsort1 = GetAuthvalueDropbox( 'sort1', '', '' ); + $CGIsort1 = GetAuthvalueDropbox( '', '' ); } # if CGIsort is successfully fetched, the use it @@ -300,12 +300,12 @@ if ($CGIsort1) { my $CGIsort2; if ($budget) { if ( defined $budget->{'sort2_authcat'} ) { - $CGIsort2 = GetAuthvalueDropbox( 'sort2', $budget->{'sort2_authcat'}, $data->{'sort2'} ); + $CGIsort2 = GetAuthvalueDropbox( $budget->{'sort2_authcat'}, $data->{'sort2'} ); } } elsif ( scalar(@$budgets) ) { - $CGIsort2 = GetAuthvalueDropbox( 'sort2', @$budgets[0]->{sort2_authcat}, '' ); + $CGIsort2 = GetAuthvalueDropbox( @$budgets[0]->{sort2_authcat}, '' ); } else { - $CGIsort2 = GetAuthvalueDropbox( 'sort2', '', '' ); + $CGIsort2 = GetAuthvalueDropbox( '', '' ); } if ($CGIsort2) { diff --git a/acqui/fetch_sort_dropbox.pl b/acqui/fetch_sort_dropbox.pl deleted file mode 100755 index 21d3c61743..0000000000 --- a/acqui/fetch_sort_dropbox.pl +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/perl - -# Copyright 2008-2009 BibLibre SARL -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -use strict; -#use warnings; FIXME - Bug 2505 -use CGI; -use C4::Context; -use C4::Output; -use C4::Auth; -use C4::Budgets; - -=head1 NAME - -fetch_sort_dropbox - -=cut - -my $input = new CGI; - -my $budget_id = $input->param('budget_id'); -my $sort_id = $input->param('sort'); - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { template_name => "acqui/ajax.tmpl", # FIXME: REMOVE TMPL DEP? - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => {editcatalogue => 'edit_catalogue'}, - debug => 0, - } -); - -my $sort_dropbox; -my $budget = GetBudget($budget_id); - -if ( $sort_id == 1 ) { - $sort_dropbox = GetAuthvalueDropbox( 'sort1', $budget->{'sort1_authcat'}, '' ); -} elsif ( $sort_id == 2 ) { - $sort_dropbox = GetAuthvalueDropbox( 'sort2', $budget->{'sort2_authcat'}, '' ); -} - -#strip off select tags ;/ -$sort_dropbox =~ s/^\//; -$sort_dropbox =~ s/\<\/select\>$//; -chomp $sort_dropbox; - -$template->param( return => $sort_dropbox ); -output_html_with_http_headers $input, $cookie, $template->output; -1; diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index c7d6083b79..e99eeb0d91 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -283,12 +283,12 @@ if ($close) { my $CGIsort1; if ($budget) { # its a mod .. if ( defined $budget->{'sort1_authcat'} ) { # with custom Asort* planning values - $CGIsort1 = GetAuthvalueDropbox( 'sort1', $budget->{'sort1_authcat'}, $data->{'sort1'} ); + $CGIsort1 = GetAuthvalueDropbox( $budget->{'sort1_authcat'}, $data->{'sort1'} ); } -} elsif(scalar(@$budgets)){ - $CGIsort1 = GetAuthvalueDropbox( 'sort1', @$budgets[0]->{'sort1_authcat'}, '' ); +} elsif(@{$budgets}){ + $CGIsort1 = GetAuthvalueDropbox( @$budgets[0]->{'sort1_authcat'}, '' ); }else{ - $CGIsort1 = GetAuthvalueDropbox( 'sort1','', '' ); + $CGIsort1 = GetAuthvalueDropbox( '', '' ); } # if CGIsort is successfully fetched, the use it @@ -302,12 +302,12 @@ if ($CGIsort1) { my $CGIsort2; if ($budget) { if ( defined $budget->{'sort2_authcat'} ) { - $CGIsort2 = GetAuthvalueDropbox( 'sort2', $budget->{'sort2_authcat'}, $data->{'sort2'} ); + $CGIsort2 = GetAuthvalueDropbox( $budget->{'sort2_authcat'}, $data->{'sort2'} ); } -} elsif(scalar(@$budgets)) { - $CGIsort2 = GetAuthvalueDropbox( 'sort2', @$budgets[0]->{sort2_authcat}, '' ); +} elsif(@{$budgets}) { + $CGIsort2 = GetAuthvalueDropbox( @$budgets[0]->{sort2_authcat}, '' ); }else{ - $CGIsort2 = GetAuthvalueDropbox( 'sort2','', '' ); + $CGIsort2 = GetAuthvalueDropbox( '', '' ); } if ($CGIsort2) { diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index 724c7e53bb..e74935e7f3 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -188,10 +188,8 @@ elsif ( $op eq 'delete_confirmed' ) { $budgetperiod->{budget_active} = 1; push( @period_loop, $budgetperiod ); } - my $budget_period_dropbox = GetBudgetPeriodsDropbox(); $template->param( - budget_period_dropbox => $budget_period_dropbox, period_loop => \@period_loop, pagination_bar => pagination_bar("aqbudgetperiods.pl",getnbpages(scalar(@$results),$pagesize),$page), ); diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 3ff1bd6d69..9c35079fbd 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -73,7 +73,6 @@ my $script_name = "/cgi-bin/koha/admin/aqbudgets.pl"; my $budget_hash = $input->Vars; my $budget_id = $$budget_hash{budget_id}; my $budget_permission = $input->param('budget_permission'); -my $budget_period_dropbox = $input->param('budget_period_dropbox'); my $filter_budgetbranch = $input->param('filter_budgetbranch'); #filtering non budget keys delete $$budget_hash{$_} foreach grep {/filter|^op$|show/} keys %$budget_hash; @@ -225,9 +224,7 @@ if ($op eq 'add_form') { } } my $branches = GetBranches(); - my $budget_period_dropbox = GetBudgetPeriodsDropbox($$period{budget_period_id} ); $template->param( - budget_period_dropbox => $budget_period_dropbox, budget_id => $budget_id, %$period, ); diff --git a/admin/aqplan.pl b/admin/aqplan.pl index 8b68d51460..81418ff358 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -74,14 +74,12 @@ my $budget_period_startdate = $period->{'budget_period_startdate'}; my $budget_period_enddate = $period->{'budget_period_enddate'}; my $budget_period_locked = $period->{'budget_period_locked'}; my $budget_period_description = $period->{'budget_period_description'}; -my $budget_period_dropbox = GetBudgetPeriodsDropbox($budget_period_id ); $template->param( budget_period_id => $budget_period_id, budget_period_locked => $budget_period_locked, budget_period_description => $budget_period_description, - budget_period_dropbox => $budget_period_dropbox, auth_cats_loop => $auth_cats_loop, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt index 04d0c58e12..dd864cfd28 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -184,21 +184,36 @@
  • The 2 following fields are available for your own usage. They can be useful for statistical purposes
    - [% IF ( CGIsort1 ) %] - [% CGIsort1 %] + [% IF CGIsort1 %] + [% ELSE %] - [% END %]
  • - [% IF ( CGIsort2 ) %] - [% CGIsort2 %] - [% ELSE %] - + [% IF CGIsort2 %] + + [% ELSE %] + + [% END %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index d6044fc81f..39e9ca26dc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -429,8 +429,16 @@ $(document).ready(function()
  • The 2 following fields are available for your own usage. They can be useful for statistical purposes
    - [% IF ( CGIsort1 ) %] - [% CGIsort1 %] + [% IF CGIsort1 %] + [% ELSE %] @@ -439,8 +447,16 @@ $(document).ready(function()
  • - [% IF ( CGIsort2 ) %] - [% CGIsort2 %] + [% IF CGIsort2 %] + [% ELSE %] [% END %] -- 2.39.5