Plugin for field 124e
[koha.git] / C4 / Members.pm
index 053b0f1..560f1d4 100644 (file)
@@ -49,9 +49,51 @@ C4::Members - Perl Module containing convenience functions for member handling
 @EXPORT = qw();
 
 @EXPORT = qw(
-       &fixup_cardnumber &findguarantees &modmember &newmember &changepassword
+       &getmember &fixup_cardnumber &findguarantees &modmember &newmember &changepassword
     );
 
+       
+=item getmember
+
+  $borrower = &getmember($cardnumber, $borrowernumber);
+
+Looks up information about a patron (borrower) by either card number
+or borrower number. If $borrowernumber is specified, C<&borrdata>
+searches by borrower number; otherwise, it searches by card number.
+
+C<&getmember> returns a reference-to-hash whose keys are the fields of
+the C<borrowers> table in the Koha database.
+
+=cut
+#'
+sub getmember {
+  my ($cardnumber,$bornum)=@_;
+  $cardnumber = uc $cardnumber;
+  my $dbh = C4::Context->dbh;
+  my $sth;
+  if ($bornum eq ''){
+    $sth=$dbh->prepare("Select * from borrowers where cardnumber=?");
+    $sth->execute($cardnumber);
+  } else {
+    $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
+  $sth->execute($bornum);
+  }
+  my $data=$sth->fetchrow_hashref;
+  $sth->finish;
+  if ($data) {
+       return($data);
+       } else { # try with firstname
+               if ($cardnumber) {
+                       my $sth=$dbh->prepare("select * from borrowers where firstname=?");
+                       $sth->execute($cardnumber);
+                       my $data=$sth->fetchrow_hashref;
+                       $sth->finish;
+                       return($data);
+               }
+       }
+       return undef;
+}
+
 
 sub modmember {
        my (%data) = @_;
@@ -61,13 +103,13 @@ sub modmember {
        $data{'expiry'}=format_date_in_iso($data{'expiry'});
        my $query="update borrowers set title='$data{'title'}',expiry='$data{'expiry'}',
        cardnumber='$data{'cardnumber'}',sex='$data{'sex'}',ethnotes='$data{'ethnicnotes'}',
-       streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',firstname='$data{'firstname'}',
+       streetaddress='$data{'streetaddress'}',faxnumber='$data{'faxnumber'}',firstname='$data{'firstname'}',
        altnotes='$data{'altnotes'}',dateofbirth='$data{'dateofbirth'}',contactname='$data{'contactname'}',
        emailaddress='$data{'emailaddress'}',dateenrolled='$data{'joining'}',streetcity='$data{'streetcity'}',
        altrelationship='$data{'altrelationship'}',othernames='$data{'othernames'}',phoneday='$data{'phoneday'}',
        categorycode='$data{'categorycode'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}',
        borrowernotes='$data{'borrowernotes'}',altphone='$data{'altphone'}',surname='$data{'surname'}',
-       initials='$data{'initials'}',physstreet='$data{'streetaddress'}',ethnicity='$data{'ethnicity'}',
+       initials='$data{'initials'}',physstreet='$data{'physstreet'}',ethnicity='$data{'ethnicity'}',
        gonenoaddress='$data{'gna'}',lost='$data{'lost'}',debarred='$data{'debarred'}',
        textmessaging='$data{'textmessaging'}', branchcode = '$data{'branchcode'}',
        zipcode = '$data{'zipcode'}',homezipcode='$data{'homezipcode'}', sort1='$data{'sort1'}', sort2='$data{'sort2'}'
@@ -95,12 +137,12 @@ sub newmember {
        firstname,altnotes,dateofbirth,contactname,emailaddress,textmessaging,dateenrolled,streetcity,
        altrelationship,othernames,phoneday,categorycode,city,area,phone,borrowernotes,altphone,surname,
        initials,ethnicity,physstreet,branchcode,zipcode,homezipcode,sort1,sort2) values ('$data{'title'}','$data{'expiry'}','$data{'cardnumber'}',
-       '$data{'sex'}','$data{'ethnotes'}','$data{'address'}','$data{'faxnumber'}',
+       '$data{'sex'}','$data{'ethnotes'}','$data{'streetaddress'}','$data{'faxnumber'}',
        '$data{'firstname'}','$data{'altnotes'}','$data{'dateofbirth'}','$data{'contactname'}','$data{'emailaddress'}','$data{'textmessaging'}',
        '$data{'joining'}','$data{'streetcity'}','$data{'altrelationship'}','$data{'othernames'}',
        '$data{'phoneday'}','$data{'categorycode'}','$data{'city'}','$data{'area'}','$data{'phone'}',
        '$data{'borrowernotes'}','$data{'altphone'}','$data{'surname'}','$data{'initials'}',
-       '$data{'ethnicity'}','$data{'streetaddress'}','$data{'branchcode'}','$data{'zipcode'}','$data{'homezipcode'}','$data{'sort1'}','$data{'sort2'}')";
+       '$data{'ethnicity'}','$data{'physstreet'}','$data{'branchcode'}','$data{'zipcode'}','$data{'homezipcode'}','$data{'sort1'}','$data{'sort2'}')";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $sth->finish;