From 979940ecba10ad4c3525e5ba7cb757c64e220976 Mon Sep 17 00:00:00 2001 From: hdl Date: Tue, 12 Jul 2005 13:59:38 +0000 Subject: [PATCH] Modifying branch Selection : Now Superlibrarians are always able to see ALL branches budget, not simple librarians. --- C4/Acquisition.pm | 22 ++++++++-- admin/aqbookfund.pl | 40 ++++++++++++------- .../default/en/parameters/aqbookfund.tmpl | 6 +-- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 7a4098d6b7..54a29d636d 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -665,11 +665,25 @@ alphabetically by book fund name. =cut #' sub bookfunds { + my ($branch)=@_; my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("Select * from aqbookfund,aqbudget where aqbookfund.bookfundid - =aqbudget.bookfundid - group by aqbookfund.bookfundid order by bookfundname"); - $sth->execute; + my $strsth; + + if ($branch eq '') { + $strsth="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid + =aqbudget.bookfundid + group by aqbookfund.bookfundid order by bookfundname"; + } else { + $strsth="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid + =aqbudget.bookfundid and (aqbookfund.branchcode='' or aqbookfund.branchcode= ? ) + group by aqbookfund.bookfundid order by bookfundname"; + } + my $sth=$dbh->prepare($strsth); + if ($branch){ + $sth->execute($branch); + } else { + $sth->execute; + } my @results = (); while (my $data=$sth->fetchrow_hashref){ push(@results,$data); diff --git a/admin/aqbookfund.pl b/admin/aqbookfund.pl index b5d15f93f7..8e876c6bdc 100755 --- a/admin/aqbookfund.pl +++ b/admin/aqbookfund.pl @@ -49,12 +49,23 @@ use C4::Date; use HTML::Template; sub StringSearch { - my ($env,$searchstring,$type)=@_; + my ($env,$searchstring,%branches)=@_; my $dbh = C4::Context->dbh; $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where (bookfundname like ?) order by bookfundid"); + my $strsth= "select bookfundid,bookfundname,bookfundgroup,branchcode from aqbookfund where bookfundname like ? "; + if (%branches){ + $strsth.= "AND (aqbookfund.branchcode is null " ; + foreach my $branchcode (keys %branches){ + $strsth .= "or aqbookfund.branchcode = '".$branchcode."' "; + } + $strsth .= ") "; + } + $strsth.= "order by aqbookfund.bookfundid"; + warn "chaine de recherche : ".$strsth; + + my $sth=$dbh->prepare($strsth); $sth->execute("%$data[0]%"); my @results; while (my $data=$sth->fetchrow_hashref){ @@ -164,8 +175,8 @@ if ($op eq 'add_form') { my $sth=$dbh->prepare("delete from aqbookfund where bookfundid =?"); $sth->execute($bookfundid); $sth->finish; - my $sth=$dbh->prepare("replace aqbookfund (bookfundid,bookfundname) values (?,?)"); - $sth->execute($input->param('bookfundid'),$input->param('bookfundname')); + my $sth=$dbh->prepare("replace aqbookfund (bookfundid,bookfundname, branchcode) values (?,?,?)"); + $sth->execute($input->param('bookfundid'),$input->param('bookfundname'),$input->param('branchcode')); $sth->finish; print "Content-Type: text/html\n\n"; exit; @@ -200,23 +211,24 @@ if ($op eq 'add_form') { $template->param(searchfield => $searchfield); } my $env; - my ($count,$results)=StringSearch($env,$searchfield,'web'); + my ($count,$results)=StringSearch($env,$searchfield,%select_branches); my $toggle="white"; my @loop_data =(); - my $strsth2="Select aqbudgetid,startdate,enddate,budgetamount,aqbudget.branchcode from aqbudget where bookfundid = ? "; - if ($homebranch){ - $strsth2 .= "AND ((aqbudget.branchcode='') OR (aqbudget.branchcode= ".$dbh->quote($homebranch)."))" ; - } else { - $strsth2 .= "AND (aqbudget.branchcode='') " if ($flags>1); - } - $strsth2 .= "order by bookfundid"; - warn "".$strsth2; - my $sth2 = $dbh->prepare($strsth2); for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ my %row_data; $row_data{bookfundid} =$results->[$i]{'bookfundid'}; $row_data{bookfundname} = $results->[$i]{'bookfundname'}; + warn "".$results->[$i]{'bookfundid'}." ".$results->[$i]{'bookfundname'}." ".$results->[$i]{'branchcode'}; $row_data{branchname} = $select_branches{$results->[$i]{'branchcode'}}; + my $strsth2="Select aqbudgetid,startdate,enddate,budgetamount,aqbudget.branchcode from aqbudget where aqbudget.bookfundid = ?"; + if ($homebranch){ + $strsth2 .= " AND ((aqbudget.branchcode='') OR (aqbudget.branchcode= ".$dbh->quote($homebranch).")) " ; + } else { + $strsth2 .= " AND (aqbudget.branchcode='') " if ($flags>1); + } + $strsth2 .= " order by aqbudgetid"; + warn "".$strsth2; + my $sth2 = $dbh->prepare($strsth2); $sth2->execute($row_data{bookfundid}); my @budget_loop; while (my ($aqbudgetid,$startdate,$enddate,$budgetamount,$branchcode) = $sth2->fetchrow) { diff --git a/koha-tmpl/intranet-tmpl/default/en/parameters/aqbookfund.tmpl b/koha-tmpl/intranet-tmpl/default/en/parameters/aqbookfund.tmpl index c8384b7e97..5c02303ac1 100644 --- a/koha-tmpl/intranet-tmpl/default/en/parameters/aqbookfund.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/parameters/aqbookfund.tmpl @@ -20,11 +20,7 @@ - - - -   - + ?op=add_form&bookfundid= "> //images/fileopen.png" alt="Edit" title="Edit" width="32" hspace="0" vspace="0" border="0"> -- 2.39.2