Implementing Independancy Branches management :

- Trying to get a basket not owned by so of his own branch leads to mainpage.
- Lists onlys ths baskets owned by someon of user's brach.

Auth.pm now sends a cookie with userenv informations.
This commit is contained in:
hdl 2005-07-28 07:52:02 +00:00
parent 7bd7c514e4
commit 5d22c28ea2
4 changed files with 62 additions and 23 deletions

View File

@ -81,7 +81,7 @@ get all basket informations in aqbasket for a given basket
sub getbasket {
my ($basketno)=@_;
my $dbh=C4::Context->dbh;
my $sth=$dbh->prepare("select aqbasket.*,borrowers.firstname+' '+borrowers.surname as authorisedbyname from aqbasket left join borrowers on aqbasket.authorisedby=borrowers.borrowernumber where basketno=?");
my $sth=$dbh->prepare("select aqbasket.*,borrowers.firstname+' '+borrowers.surname as authorisedbyname, borrowers.branchcode as branch from aqbasket left join borrowers on aqbasket.authorisedby=borrowers.borrowernumber where basketno=?");
$sth->execute($basketno);
return($sth->fetchrow_hashref);
}
@ -391,14 +391,24 @@ Results are ordered from most to least recent.
sub getorders {
my ($supplierid)=@_;
my $dbh = C4::Context->dbh;
my $sth=$dbh->prepare("Select count(*),authorisedby,creationdate,aqbasket.basketno,
closedate,surname,firstname
from aqorders
left join aqbasket on aqbasket.basketno=aqorders.basketno
left join borrowers on aqbasket.authorisedby=borrowers.borrowernumber
where booksellerid=? and (quantity > quantityreceived or
quantityreceived is NULL) and datecancellationprinted is NULL
group by basketno order by aqbasket.basketno");
my $strsth ="Select count(*),authorisedby,creationdate,aqbasket.basketno,
closedate,surname,firstname
from aqorders
left join aqbasket on aqbasket.basketno=aqorders.basketno
left join borrowers on aqbasket.authorisedby=borrowers.borrowernumber
where booksellerid=? and (quantity > quantityreceived or
quantityreceived is NULL) and datecancellationprinted is NULL ";
if (C4::Context->preference("IndependantBranches")) {
my $userenv = C4::Context->userenv;
unless ($userenv->{flags} == 1){
$strsth .= " and (borrowers.branchcode = '".$userenv->{branch}."' or borrowers.branchcode ='')";
}
}
$strsth.=" group by basketno order by aqbasket.basketno";
warn "getorders :".$strsth;
my $sth=$dbh->prepare($strsth);
$sth->execute($supplierid);
my @results = ();
while (my $data=$sth->fetchrow_hashref){
@ -480,15 +490,24 @@ sub getallorders {
my ($supid)=@_;
my $dbh = C4::Context->dbh;
my @results = ();
my $sth=$dbh->prepare("Select * from aqorders,biblio,biblioitems,aqbasket where aqbasket.basketno=aqorders.basketno
and booksellerid=?
and (cancelledby is NULL or cancelledby = '')
my $strsth="Select * from aqorders,biblio,biblioitems,aqbasket ";
$strsth .= ",borrowers " if (C4::Context->preference("IndependantBranches"));
$strsth .=" where aqorders.basketno=aqbasket.basketno and aqbasket.booksellerid=aqbooksellers.id and biblio.biblionumber=aqorders.biblionumber ";
$strsth .= " and aqbasket.authorisedby=borrowers.borrowernumber" if (C4::Context->preference("IndependantBranches"));
$strsth.=" and booksellerid=? and (cancelledby is NULL or cancelledby = '')
and (quantityreceived < quantity or quantityreceived is NULL)
and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
aqorders.biblioitemnumber
group by aqorders.biblioitemnumber
aqorders.biblioitemnumber";
if (C4::Context->preference("IndependantBranches")) {
my $userenv = C4::Context->userenv;
unless ($userenv->{flags} == 1){
$strsth .= " and (borrowers.branchcode = '".$userenv->{branch}."' or borrowers.branchcode ='')";
}
}
$strsth .= "group by aqorders.biblioitemnumber
order by
biblio.title");
biblio.title";
my $sth=$dbh->prepare($strsth);
$sth->execute($supid);
while (my $data=$sth->fetchrow_hashref){
push(@results,$data);
@ -599,15 +618,23 @@ sub ordersearch {
sub histsearch {
my ($title,$author,$name,$from_placed_on,$to_placed_on)=@_;
my $dbh= C4::Context->dbh;
my $query = "select biblio.title,aqorders.basketno,name,aqbasket.creationdate,aqorders.datereceived, aqorders.quantity, aqorders.ecost from aqorders,aqbasket,aqbooksellers,biblio
where aqorders.basketno=aqbasket.basketno and aqbasket.booksellerid=aqbooksellers.id and
biblio.biblionumber=aqorders.biblionumber";
my $query = "select biblio.title,aqorders.basketno,name,aqbasket.creationdate,aqorders.datereceived, aqorders.quantity, aqorders.ecost from aqorders,aqbasket,aqbooksellers,biblio";
$query .= ",borrowers " if (C4::Context->preference("IndependantBranches"));
$query .=" where aqorders.basketno=aqbasket.basketno and aqbasket.booksellerid=aqbooksellers.id and biblio.biblionumber=aqorders.biblionumber ";
$query .= " and aqbasket.authorisedby=borrowers.borrowernumber" if (C4::Context->preference("IndependantBranches"));
$query .= " and biblio.title like ".$dbh->quote("%".$title."%") if $title;
$query .= " and biblio.author like ".$dbh->quote("%".$author."%") if $author;
$query .= " and name like ".$dbh->quote("%".$name."%") if $name;
$query .= " and creationdate >" .$dbh->quote($from_placed_on) if $from_placed_on;
$query .= " and creationdate<".$dbh->quote($to_placed_on) if $to_placed_on;
warn "C4:Acquisition : ".$query;
if (C4::Context->preference("IndependantBranches")) {
my $userenv = C4::Context->userenv;
unless ($userenv->{flags} == 1){
$query .= " and (borrowers.branchcode = '".$userenv->{branch}."' or borrowers.branchcode ='')";
}
}
# warn "C4:Acquisition : ".$query;
my $sth = $dbh->prepare($query);
$sth->execute;
my @order_loop;

View File

@ -494,8 +494,6 @@ sub checkpw {
}
}
if ($userid eq C4::Context->config('user') && $password eq C4::Context->config('pass')) {
# Koha superuser account
warn "setuserenv3";
return 2;
}
if ($userid eq 'demo' && $password eq 'demo' && C4::Context->config('demo')) {

View File

@ -60,7 +60,7 @@ my ($template, $loggedinuser, $cookie)
});
$template->param($count);
my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
$sthtemp->execute($borrowernumber);
$sthtemp->execute($loggedinuser);
my ($flags, $homebranch)=$sthtemp->fetchrow;
if ($count == 1){

View File

@ -35,7 +35,7 @@ use C4::Acquisition;
use C4::Date;
my $query =new CGI;
my $basketno = $query ->param('basket');
my $basketno = $query->param('basket');
my $booksellerid = $query->param('supplierid');
my $order = $query->param('order');
my ($template, $loggedinuser, $cookie)
@ -48,6 +48,7 @@ my ($template, $loggedinuser, $cookie)
});
my ($count,@results);
my $basket = getbasket($basketno);
# FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
# if no booksellerid in parameter, get it from basket
@ -56,6 +57,19 @@ $booksellerid = $basket->{booksellerid} unless $booksellerid;
my ($count2,@booksellers)=bookseller($booksellerid);
# get librarian branch...
if (C4::Context->preference("IndependantBranches")) {
my $userenv = C4::Context->userenv;
unless ($userenv->{flags} == 1){
my $validtest = ($basket->{creationdate} = "")
|| ($userenv->{branch} eq $basket->{branch})
|| ($userenv->{branch} = '')
|| ($basket->{branch} = '');
unless ($validtest) {
print $query->redirect("../mainpage.pl");
exit 1;
}
}
}
# if new basket, pre-fill infos
$basket->{creationdate} = "" unless ($basket->{creationdate});