+Returns the mimetype and binary image data of the image for the patron with the supplied cardnumber.
+
+=cut
+
+sub GetPatronImage {
+ my ($cardnumber) = @_;
+ warn "Cardnumber passed to GetPatronImage is $cardnumber" if $debug;
+ my $dbh = C4::Context->dbh;
+ my $query = 'SELECT mimetype, imagefile FROM patronimage WHERE cardnumber = ?';
+ my $sth = $dbh->prepare($query);
+ $sth->execute($cardnumber);
+ my $imagedata = $sth->fetchrow_hashref;
+ my $dberror = $sth->errstr;
+ warn "Database error!" if $sth->errstr;
+ $sth->finish;
+ return $imagedata, $dberror;
+}
+
+=head2 PutPatronImage
+
+ PutPatronImage($cardnumber, $mimetype, $imgfile);
+
+Stores patron binary image data and mimetype in database.
+NOTE: This function is good for updating images as well as inserting new images in the database.
+
+=cut
+
+sub PutPatronImage {
+ my ($cardnumber, $mimetype, $imgfile) = @_;
+ warn "Parameters passed in: Cardnumber=$cardnumber, Mimetype=$mimetype, " . ($imgfile ? "Imagefile" : "No Imagefile") if $debug;
+ my $dbh = C4::Context->dbh;
+ my $query = "INSERT INTO patronimage (cardnumber, mimetype, imagefile) VALUES (?,?,?) ON DUPLICATE KEY UPDATE imagefile = ?;";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($cardnumber,$mimetype,$imgfile,$imgfile);
+ warn "Error returned inserting $cardnumber.$mimetype." if $sth->errstr;
+ my $dberror = $sth->errstr;
+ $sth->finish;
+ return $dberror;
+}
+
+=head2 RmPatronImage
+
+ my ($dberror) = RmPatronImage($cardnumber);
+
+Removes the image for the patron with the supplied cardnumber.
+
+=cut
+
+sub RmPatronImage {
+ my ($cardnumber) = @_;
+ warn "Cardnumber passed to GetPatronImage is $cardnumber" if $debug;
+ my $dbh = C4::Context->dbh;
+ my $query = "DELETE FROM patronimage WHERE cardnumber = ?;";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($cardnumber);
+ my $dberror = $sth->errstr;
+ warn "Database error!" if $sth->errstr;
+ $sth->finish;
+ return $dberror;
+}