use DateTime;
use DateTime::Format::DateParse;
use Koha::DateUtils;
+use Koha::Borrower::Debarments qw(IsDebarred);
use Text::Unaccent qw( unac_string );
use Koha::AuthUtils qw(hash_password);
&GetPendingIssues
&GetAllIssues
- &get_institutions
&getzipnamecity
&getidcity
&GetAge
&GetCities
- &GetRoadTypes
- &GetRoadTypeDetails
&GetSortDetails
&GetTitles
&IssueSlip
GetBorrowersWithEmail
+
+ HasOverdues
);
#Modify data
push @EXPORT, qw(
&AddMember
&AddMember_Opac
- &add_member_orgs
&MoveMemberToDeleted
&ExtendMemberSubscriptionTo
);
if ( C4::Context->preference("IndependentBranches") ) { # && !$showallbranches){
if ( my $userenv = C4::Context->userenv ) {
my $branch = $userenv->{'branch'};
- if ( ($userenv->{flags} % 2 !=1) && $branch ){
+ if ( !C4::Context->IsSuperLibrarian() && $branch ){
if (my $fr = ref $filter) {
if ( $fr eq "HASH" ) {
$filter->{branchcode} = $branch;
my $query;
my $sth;
if ($borrowernumber) {
- $sth = $dbh->prepare("SELECT borrowers.*,category_type,categories.description,reservefee,enrolmentperiod FROM borrowers LEFT JOIN categories ON borrowers.categorycode=categories.categorycode WHERE borrowernumber=?");
+ $sth = $dbh->prepare("
+ SELECT borrowers.*,
+ category_type,
+ categories.description,
+ categories.BlockExpiredPatronOpacActions,
+ reservefee,
+ enrolmentperiod
+ FROM borrowers
+ LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
+ WHERE borrowernumber = ?
+ ");
$sth->execute($borrowernumber);
}
elsif ($cardnumber) {
- $sth = $dbh->prepare("SELECT borrowers.*,category_type,categories.description,reservefee,enrolmentperiod FROM borrowers LEFT JOIN categories ON borrowers.categorycode=categories.categorycode WHERE cardnumber=?");
+ $sth = $dbh->prepare("
+ SELECT borrowers.*,
+ category_type,
+ categories.description,
+ categories.BlockExpiredPatronOpacActions,
+ reservefee,
+ enrolmentperiod
+ FROM borrowers
+ LEFT JOIN categories ON borrowers.categorycode = categories.categorycode
+ WHERE cardnumber = ?
+ ");
$sth->execute($cardnumber);
}
else {
$borrower->{'showname'} = $borrower->{'firstname'};
}
+ # Handle setting the true behavior for BlockExpiredPatronOpacActions
+ $borrower->{'BlockExpiredPatronOpacActions'} =
+ C4::Context->preference('BlockExpiredPatronOpacActions')
+ if ( $borrower->{'BlockExpiredPatronOpacActions'} == -1 );
+
+ $borrower->{'is_expired'} =
+ Date_to_Days( Today() ) >
+ Date_to_Days( split /-/, $borrower->{'dateexpiry'} );
+
return ($borrower); #, $flags, $accessflagshash);
}
my $borrowernumber = shift;
my $dbh = C4::Context->dbh;
- my $blockeddate = CheckBorrowerDebarred($borrowernumber);
+ my $blockeddate = Koha::Borrower::Debarments::IsDebarred($borrowernumber);
return ( 1, $blockeddate ) if $blockeddate;
}
sub checkcardnumber {
- my ($cardnumber,$borrowernumber) = @_;
+ my ( $cardnumber, $borrowernumber ) = @_;
+
# If cardnumber is null, we assume they're allowed.
- return 0 if !defined($cardnumber);
+ return 0 unless defined $cardnumber;
+
my $dbh = C4::Context->dbh;
my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
$query .= " AND borrowernumber <> ?" if ($borrowernumber);
- my $sth = $dbh->prepare($query);
- if ($borrowernumber) {
- $sth->execute($cardnumber,$borrowernumber);
- } else {
- $sth->execute($cardnumber);
- }
- if (my $data= $sth->fetchrow_hashref()){
- return 1;
- }
- else {
- return 0;
- }
-}
+ my $sth = $dbh->prepare($query);
+ $sth->execute(
+ $cardnumber,
+ ( $borrowernumber ? $borrowernumber : () )
+ );
+
+ return 1 if $sth->fetchrow_hashref;
+
+ my ( $min_length, $max_length ) = get_cardnumber_length();
+ return 2
+ if length $cardnumber > $max_length
+ or length $cardnumber < $min_length;
+
+ return 0;
+}
+
+=head2 get_cardnumber_length
+
+ my ($min, $max) = C4::Members::get_cardnumber_length()
+
+Returns the minimum and maximum length for patron cardnumbers as
+determined by the CardnumberLength system preference, the
+BorrowerMandatoryField system preference, and the width of the
+database column.
+
+=cut
+
+sub get_cardnumber_length {
+ my ( $min, $max ) = ( 0, 16 ); # borrowers.cardnumber is a nullable varchar(16)
+ $min = 1 if C4::Context->preference('BorrowerMandatoryField') =~ /cardnumber/;
+ if ( my $cardnumber_length = C4::Context->preference('CardnumberLength') ) {
+ # Is integer and length match
+ if ( $cardnumber_length =~ m|^\d+$| ) {
+ $min = $max = $cardnumber_length
+ if $cardnumber_length >= $min
+ and $cardnumber_length <= $max;
+ }
+ # Else assuming it is a range
+ elsif ( $cardnumber_length =~ m|(\d*),(\d*)| ) {
+ $min = $1 if $1 and $min < $1;
+ $max = $2 if $2 and $max > $2;
+ }
+ }
+ return ( $min, $max );
+}
=head2 getzipnamecity (OUEST-PROVENCE)
return $age;
} # sub get_age
-=head2 get_institutions
-
- $insitutions = get_institutions();
-
-Just returns a list of all the borrowers of type I, borrownumber and name
-
-=cut
-
-#'
-sub get_institutions {
- my $dbh = C4::Context->dbh();
- my $sth =
- $dbh->prepare(
-"SELECT borrowernumber,surname FROM borrowers WHERE categorycode=? ORDER BY surname"
- );
- $sth->execute('I');
- my %orgs;
- while ( my $data = $sth->fetchrow_hashref() ) {
- $orgs{ $data->{'borrowernumber'} } = $data;
- }
- return ( \%orgs );
-
-} # sub get_institutions
-
-=head2 add_member_orgs
-
- add_member_orgs($borrowernumber,$borrowernumbers);
-
-Takes a borrowernumber and a list of other borrowernumbers and inserts them into the borrowers_to_borrowers table
-
-=cut
-
-#'
-sub add_member_orgs {
- my ( $borrowernumber, $otherborrowers ) = @_;
- my $dbh = C4::Context->dbh();
- my $query =
- "INSERT INTO borrowers_to_borrowers (borrower1,borrower2) VALUES (?,?)";
- my $sth = $dbh->prepare($query);
- foreach my $otherborrowernumber (@$otherborrowers) {
- $sth->execute( $borrowernumber, $otherborrowernumber );
- }
-
-} # sub add_member_orgs
-
=head2 GetCities
$cityarrayref = GetCities();
return 0;
}
-=head2 GetRoadTypes (OUEST-PROVENCE)
-
- ($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes();
-
-Looks up the different road type . Returns two
-elements: a reference-to-array, which lists the id_roadtype
-codes, and a reference-to-hash, which maps the road type of the road .
-
-=cut
-
-sub GetRoadTypes {
- my $dbh = C4::Context->dbh;
- my $query = qq|
-SELECT roadtypeid,road_type
-FROM roadtype
-ORDER BY road_type|;
- my $sth = $dbh->prepare($query);
- $sth->execute();
- my %roadtype;
- my @id;
-
- # insert empty value to create a empty choice in cgi popup
-
- while ( my $data = $sth->fetchrow_hashref ) {
-
- push @id, $data->{'roadtypeid'};
- $roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'};
- }
-
-#test to know if the table contain some records if no the function return nothing
- my $id = @id;
- if ( $id eq 0 ) {
- return ();
- }
- else {
- unshift( @id, "" );
- return ( \@id, \%roadtype );
- }
-}
-
-
-
=head2 GetTitles (OUEST-PROVENCE)
($borrowertitle)= &GetTitles();
return $hidelostitems;
}
-=head2 GetRoadTypeDetails (OUEST-PROVENCE)
-
- ($roadtype) = &GetRoadTypeDetails($roadtypeid);
-
-Returns the description of roadtype
-C<&$roadtype>return description of road type
-C<&$roadtypeid>this is the value of roadtype s
-
-=cut
-
-sub GetRoadTypeDetails {
- my ($roadtypeid) = @_;
- my $dbh = C4::Context->dbh;
- my $query = qq|
-SELECT road_type
-FROM roadtype
-WHERE roadtypeid=?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($roadtypeid);
- my $roadtype = $sth->fetchrow;
- return ($roadtype);
-}
-
=head2 GetBorrowersToExpunge
$borrowers = &GetBorrowersToExpunge(
my $filterbranch = $params->{'branchcode'} ||
((C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags} % 2 !=1
+ && !C4::Context->IsSuperLibrarian()
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
my $filterbranch = shift ||
((C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags} % 2 !=1
+ && !C4::Context->IsSuperLibrarian()
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
my $filterbranch = shift ||
((C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags} % 2 !=1
+ && !C4::Context->IsSuperLibrarian()
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
return $results;
}
-=head2 DebarMember
-
-my $success = DebarMember( $borrowernumber, $todate );
-
-marks a Member as debarred, and therefore unable to checkout any more
-items.
-
-return :
-true on success, false on failure
-
-=cut
-
-sub DebarMember {
- my $borrowernumber = shift;
- my $todate = shift;
-
- return unless defined $borrowernumber;
- return unless $borrowernumber =~ /^\d+$/;
-
- return ModMember(
- borrowernumber => $borrowernumber,
- debarred => $todate
- );
-
-}
-
=head2 ModPrivacy
=over 4
'news' => [ map {
$_->{'timestamp'} = $_->{'newdate'};
{ opac_news => $_ }
- } @{ GetNewsToDisplay("slip") } ],
+ } @{ GetNewsToDisplay("slip",$branch) } ],
);
}
}
}
+sub HasOverdues {
+ my ( $borrowernumber ) = @_;
+
+ my $sql = "SELECT COUNT(*) FROM issues WHERE date_due < NOW() AND borrowernumber = ?";
+ my $sth = C4::Context->dbh->prepare( $sql );
+ $sth->execute( $borrowernumber );
+ my ( $count ) = $sth->fetchrow_array();
+
+ return $count;
+}
+
END { } # module clean-up code here (global destructor)
1;