X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Faqbudget.pl;h=33edc1cd760755cdfa9aa3451a9c91ce87cb19bf;hb=ac4c96f10fd1c68168ab199a39cbfc777c1f721d;hp=3a6c2f665c443c420f5ae71a15cb07b78dc4b0b6;hpb=100e6a9808ead4ee8d951da59ead1550e75bb4c3;p=koha.git diff --git a/admin/aqbudget.pl b/admin/aqbudget.pl index 3a6c2f665c..33edc1cd76 100755 --- a/admin/aqbudget.pl +++ b/admin/aqbudget.pl @@ -38,11 +38,11 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; +# use warnings; FIXME use CGI; use C4::Branch; # GetBranches use List::Util qw/min/; - -use C4::Date; +use C4::Dates qw/format_date format_date_in_iso/; use C4::Auth; use C4::Acquisition; use C4::Context; @@ -51,11 +51,11 @@ use C4::Koha; my $input = new CGI; my $script_name="/cgi-bin/koha/admin/aqbudget.pl"; -my $bookfundid=$input->param('bookfundid'); -my $aqbudgetid=$input->param('aqbudgetid'); -my $branchcodeid=$input->param('branchcode'); +my $bookfundid = $input->param('bookfundid'); +my $aqbudgetid = $input->param('aqbudgetid'); +my $branchcodeid = $input->param('branchcode'); +my $op = $input->param('op') || ''; my $pagesize = 20; -my $op = $input->param('op'); my ($template, $borrowernumber, $cookie) = get_template_and_user( @@ -70,7 +70,7 @@ my ($template, $borrowernumber, $cookie) $template->param( action => $script_name, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), script_name => $script_name, $op || 'else' => 1, ); @@ -84,8 +84,6 @@ my ($flags, $homebranch)=$sthtemp->fetchrow; # called by default. Used to create form to add or modify a record if ($op eq 'add_form') { my ($query, $dataaqbudget, $dataaqbookfund, $sth); - my $dbh = C4::Context->dbh; - #---- if primkey exists, it's a modify action, so read values to modify... if ($aqbudgetid) { $query = ' @@ -97,14 +95,14 @@ SELECT aqbudgetid, budgetamount, aqbudget.branchcode FROM aqbudget - INNER JOIN aqbookfund ON (aqbudget.bookfundid = aqbookfund.bookfundid AND - aqbudget.branchcode = aqbookfund.branchcode) - WHERE aqbudgetid = ? + INNER JOIN aqbookfund ON (aqbudget.bookfundid = aqbookfund.bookfundid) + WHERE aqbudgetid = ? AND + (aqbookfund.branchcode = aqbudget.branchcode OR + (aqbudget.branchcode IS NULL and aqbookfund.branchcode="")) '; $sth=$dbh->prepare($query); $sth->execute($aqbudgetid); $dataaqbudget=$sth->fetchrow_hashref; - $sth->finish; } $query = ' @@ -121,7 +119,6 @@ SELECT aqbookfund.branchcode, $branchcodeid ); $dataaqbookfund=$sth->fetchrow_hashref; - $sth->finish; if (defined $aqbudgetid) { $template->param( @@ -160,21 +157,19 @@ SELECT branchcode, $branch->{selected} = $dataaqbudget->{branchcode} eq $row->{branchcode} ? 1 : 0; } - push @branches, $branch; } - $sth->finish; $template->param( - dateformat => display_date_format(), + dateformat => C4::Dates->new()->visual(), aqbudgetid => $dataaqbudget->{'aqbudgetid'}, startdate => format_date($dataaqbudget->{'startdate'}), - enddate => format_date($dataaqbudget->{'enddate'}), + enddate => format_date($dataaqbudget->{'enddate'}), budgetamount => $dataaqbudget->{'budgetamount'}, branches => \@branches, ); - if (defined $dataaqbookfund->{branchcode}) { + if ( $dataaqbookfund->{branchcode}) { $template->param( disable_branchselection => 1, branch => $dataaqbookfund->{branchcode}, @@ -205,7 +200,6 @@ UPDATE aqbudget $input->param('branch') || '', $aqbudgetid, ); - $sth->finish; } else { $query = ' @@ -223,36 +217,31 @@ INSERT $input->param('budgetamount'), $input->param('branch') || '', ); - $sth->finish; } - $input->redirect("aqbudget.pl"); - + print $input->redirect("aqbudget.pl"); # FIXME: unnecessary redirect + exit; # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { - my $dbh = C4::Context->dbh; my $sth=$dbh->prepare("select aqbudgetid,bookfundid,startdate,enddate,budgetamount,branchcode from aqbudget where aqbudgetid=?"); $sth->execute($aqbudgetid); my $data=$sth->fetchrow_hashref; - $sth->finish; $template->param(bookfundid => $bookfundid); $template->param(aqbudgetid => $data->{'aqbudgetid'}); - $template->param(startdate => format_date($data->{'startdate'})); - $template->param(enddate => format_date($data->{'enddate'})); + $template->param(startdate => format_date($data->{'startdate'})); + $template->param(enddate => format_date($data->{'enddate'})); $template->param(budgetamount => $data->{'budgetamount'}); # END $OP eq DELETE_CONFIRM ################## DELETE_CONFIRMED ################################## # called by delete_confirm, used to effectively confirm deletion of data in DB } elsif ($op eq 'delete_confirmed') { - my $dbh = C4::Context->dbh; my $aqbudgetid=uc($input->param('aqbudgetid')); my $sth=$dbh->prepare("delete from aqbudget where aqbudgetid=?"); $sth->execute($aqbudgetid); - $sth->finish; - print $input->redirect("aqbookfund.pl"); - return; + print $input->redirect("aqbookfund.pl"); + exit; # END $OP eq DELETE_CONFIRMED ################## DEFAULT ################################## } else { # DEFAULT @@ -270,7 +259,6 @@ SELECT bookfundid, bookfundname while (my $row = $sth->fetchrow_hashref) { $bookfundname_of{ $row->{bookfundid} } = $row->{bookfundname}; } - $sth->finish; # filters my $branches = GetBranches(); @@ -285,7 +273,6 @@ SELECT bookfundid, bookfundname and $input->param('filter_branchcode') eq $branchcode) { $row->{selected} = 1; } - push @branchloop, $row; } @@ -301,10 +288,8 @@ SELECT bookfundid and $input->param('filter_bookfundid') eq $row->{bookfundid}) { $row->{selected} = 1; } - push @bookfundids_loop, $row; } - $sth->finish; $template->param( filter_bookfundids => \@bookfundids_loop, @@ -389,7 +374,6 @@ SELECT aqbudgetid, while (my $row = $sth->fetchrow_hashref){ push @results, $row; } - $sth->finish; # filter budgets depending on the pagination my $page = $input->param('page') || 1; @@ -402,20 +386,15 @@ SELECT aqbudgetid, scalar @results - 1, ); - my $toggle = 0; my @loop; foreach my $result (@results[$first .. $last]) { - push( - @loop, - { - %{$result}, - toggle => $toggle++%2, - bookfundname => $bookfundname_of{ $result->{'bookfundid'} }, - branchname => $branches->{ $result->{branchcode} }->{branchname}, - startdate => format_date($result->{startdate}), - enddate => format_date($result->{enddate}), - } - ); + push @loop, { + %{$result}, + bookfundname => $bookfundname_of{ $result->{'bookfundid'} }, + branchname => $branches->{ $result->{branchcode} }->{branchname}, + startdate => format_date($result->{startdate}), + enddate => format_date($result->{enddate}), + }; } $template->param( @@ -428,9 +407,5 @@ SELECT aqbudgetid, ) ); } #---- END $OP eq DEFAULT -$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), - intranetstylesheet => C4::Context->preference("intranetstylesheet"), - IntranetNav => C4::Context->preference("IntranetNav"), - ); output_html_with_http_headers $input, $cookie, $template->output;