Stores an associated borrowernumber now with issue data, if the system pref is set.
[koha.git] / C4 / Members.pm
index 9d4bec1..2a4f2fd 100644 (file)
@@ -19,6 +19,8 @@ package C4::Members;
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
+# $Id$
+
 use strict;
 require Exporter;
 use C4::Context;
@@ -28,7 +30,7 @@ use Digest::MD5 qw(md5_base64);
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
 
-$VERSION = 0.01;
+$VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
 
@@ -36,15 +38,18 @@ C4::Members - Perl Module containing convenience functions for member handling
 
 =head1 SYNOPSIS
 
+use C4::Members;
 
 =head1 DESCRIPTION
 
+This module contains routines for adding, modifying and deleting members/patrons/borrowers 
 
 =head1 FUNCTIONS
 
 =over 2
 
 =cut
+#'
 
 @ISA = qw(Exporter);
 @EXPORT = qw();
@@ -56,7 +61,7 @@ C4::Members - Perl Module containing convenience functions for member handling
        &getboracctrecord
        &borrowercategories &getborrowercategory
        &fixEthnicity
-       &ethnicitycategories
+       &ethnicitycategories get_institutions add_member_orgs
     );
 
 
@@ -598,7 +603,7 @@ sub NewBorrowerNumber {
   return($data->{'max(borrowernumber)'});
 }
 
-=item borrissues
+=head2 borrissues
 
   ($count, $issues) = &borrissues($borrowernumber);
 
@@ -628,7 +633,7 @@ sub borrissues {
   return(scalar(@result), \@result);
 }
 
-=item allissues
+=head2 allissues
 
   ($count, $issues) = &allissues($borrowernumber, $sortkey, $limit);
 
@@ -674,7 +679,7 @@ sub allissues {
   return($i,\@result);
 }
 
-=item getboracctrecord
+=head2 getboracctrecord
 
   ($count, $acctlines, $total) = &getboracctrecord($env, $borrowernumber);
 
@@ -786,6 +791,8 @@ check for title,firstname,surname,adress,zip code and city  from guarantor to
 guarantorchild
 
 =cut
+#'
+
 sub getguarantordata{
        my ($borrowerid)=@_;
        my $dbh = C4::Context->dbh;
@@ -799,6 +806,7 @@ sub getguarantordata{
 =head2 getdcity (OUEST-PROVENCE)
 recover cityid  with city_name condition
 =cut
+
 sub getidcity {
        my ($city_name)=@_;
        my $dbh = C4::Context->dbh;
@@ -880,7 +888,7 @@ sub borrowercategories {
        return(\@codes,\%labels);
 }
 
-=item getborrowercategory
+=head2 getborrowercategory
 
   $description = &getborrowercategory($categorycode);
 
@@ -947,6 +955,47 @@ sub fixEthnicity($) {
     my $data=$sth->fetchrow_hashref;
     $sth->finish;
     return $data->{'name'};
-}
+} # sub fixEthnicity
+
+=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;
+    }
+    $sth->finish();
+    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 $bornum (@$otherborrowers){
+       $sth->execute($borrowernumber,$bornum);
+       }
+    $sth->finish();
+    
+} # sub add_member_orgs
 1;