Bug 27014: Enable C4::SIP::ILS::Patron::new to accept a hash
[koha.git] / C4 / SIP / ILS / Patron.pm
1 #
2 # ILS::Patron.pm
3
4 # A Class for hiding the ILS's concept of the patron from the OpenSIP
5 # system
6 #
7
8 package C4::SIP::ILS::Patron;
9
10 use strict;
11 use warnings;
12 use Exporter;
13 use Carp;
14
15 use C4::SIP::Sip qw(siplog);
16 use Data::Dumper;
17
18 use C4::SIP::Sip qw(add_field maybe_add);
19
20 use C4::Debug;
21 use C4::Context;
22 use C4::Koha;
23 use C4::Members;
24 use C4::Reserves;
25 use C4::Auth qw(checkpw);
26
27 use Koha::Items;
28 use Koha::Libraries;
29 use Koha::Patrons;
30
31 our $kp;    # koha patron
32
33 =head1 Methods
34
35 =cut
36
37 sub new {
38     my ($class, $patron_id) = @_;
39     my $type = ref($class) || $class;
40     my $self;
41
42     my $patron;
43     if ( ref $patron_id eq "HASH" ) {
44         if ( $patron_id->{borrowernumber} ) {
45             $patron = Koha::Patrons->find( $patron_id->{borrowernumber} );
46         } elsif ( $patron_id->{cardnumber} ) {
47             $patron = Koha::Patrons->find( { cardnumber => $patron_id->{cardnumber} } );
48         } elsif ( $patron_id->{userid} ) {
49             $patron = Koha::Patrons->find( { userid => $patron_id->{userid} } );
50         }
51     } else {
52         $patron = Koha::Patrons->find( { cardnumber => $patron_id } )
53             || Koha::Patrons->find( { userid => $patron_id } );
54     }
55
56     $debug and warn "new Patron: " . Dumper($patron->unblessed) if $patron;
57     unless ($patron) {
58         siplog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id);
59         return;
60     }
61     $kp = $patron->unblessed;
62     my $pw        = $kp->{password};
63     my $flags     = C4::Members::patronflags( $kp );
64     my $debarred  = $patron->is_debarred;
65     $debug and warn sprintf("Debarred = %s : ", ($debarred||'undef')); # Do we need more debug info here?
66     my ($day, $month, $year) = (localtime)[3,4,5];
67     my $today    = sprintf '%04d-%02d-%02d', $year+1900, $month+1, $day;
68     my $expired  = ($today gt $kp->{dateexpiry}) ? 1 : 0;
69     if ($expired) {
70         if ($kp->{opacnote} ) {
71             $kp->{opacnote} .= q{ };
72         }
73         $kp->{opacnote} .= 'PATRON EXPIRED';
74     }
75     my %ilspatron;
76     my $adr     = _get_address($kp);
77     my $dob     = $kp->{dateofbirth};
78     $dob and $dob =~ s/-//g;    # YYYYMMDD
79     my $dexpiry     = $kp->{dateexpiry};
80     $dexpiry and $dexpiry =~ s/-//g;    # YYYYMMDD
81
82     # Get fines and add fines for guarantees (depends on preference NoIssuesChargeGuarantees)
83     my $fines_amount = $flags->{CHARGES}->{amount}; #TODO Replace with $patron->account->non_issues_charges
84     $fines_amount = ($fines_amount and $fines_amount > 0) ? $fines_amount : 0;
85     if ( C4::Context->preference('NoIssuesChargeGuarantorsWithGuarantees') ) {
86         $fines_amount += $patron->relationships_debt({ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 1 });
87     } else {
88         my $guarantees_fines_amount = $flags->{CHARGES_GUARANTEES} ? $flags->{CHARGES_GUARANTEES}->{amount} : 0; #TODO: Replace with $patron->relationships_debt
89         $fines_amount += $guarantees_fines_amount;
90     }
91
92     my $fee_limit = _fee_limit();
93     my $fine_blocked = $fines_amount > $fee_limit;
94     my $circ_blocked =( C4::Context->preference('OverduesBlockCirc') ne "noblock" &&  defined $flags->{ODUES}->{itemlist} ) ? 1 : 0;
95     {
96     no warnings;    # any of these $kp->{fields} being concat'd could be undef
97     %ilspatron = (
98         name => $kp->{firstname} . " " . $kp->{surname},
99         id   => $kp->{cardnumber},    # to SIP, the id is the BARCODE, not userid
100         password        => $pw,
101         ptype           => $kp->{categorycode},     # 'A'dult.  Whatever.
102         dateexpiry      => $dexpiry,
103         dateexpiry_iso  => $kp->{dateexpiry},
104         birthdate       => $dob,
105         birthdate_iso   => $kp->{dateofbirth},
106         branchcode      => $kp->{branchcode},
107         library_name    => "",                      # only populated if needed, cached here
108         borrowernumber  => $kp->{borrowernumber},
109         address         => $adr,
110         home_phone      => $kp->{phone},
111         email_addr      => $kp->{email},
112         charge_ok       => ( !$debarred && !$expired && !$fine_blocked && !$circ_blocked),
113         renew_ok        => ( !$debarred && !$expired && !$fine_blocked),
114         recall_ok       => ( !$debarred && !$expired && !$fine_blocked),
115         hold_ok         => ( !$debarred && !$expired && !$fine_blocked),
116         card_lost       => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ),
117         claims_returned => 0,
118         fines           => $fines_amount,
119         fees            => 0,             # currently not distinct from fines
120         recall_overdue  => 0,
121         items_billed    => 0,
122         screen_msg      => 'Greetings from Koha. ' . $kp->{opacnote},
123         print_line      => '',
124         items           => [],
125         hold_items      => $flags->{WAITING}->{itemlist},
126         overdue_items   => $flags->{ODUES}->{itemlist},
127         too_many_overdue => $circ_blocked,
128         fine_items      => [],
129         recall_items    => [],
130         unavail_holds   => [],
131         inet            => ( !$debarred && !$expired ),
132         expired         => $expired,
133         fee_limit       => $fee_limit,
134         userid          => $kp->{userid},
135     );
136     }
137     $debug and warn "patron fines: $ilspatron{fines} ... amountoutstanding: $kp->{amountoutstanding} ... CHARGES->amount: $flags->{CHARGES}->{amount}";
138
139     if ( $patron->is_debarred and $patron->debarredcomment ) {
140         $ilspatron{screen_msg} .= " -- " . $patron->debarredcomment;
141     }
142     if ( $circ_blocked ) {
143         $ilspatron{screen_msg} .= " -- " . "Patron has overdues";
144     }
145     for (qw(EXPIRED CHARGES CREDITS GNA LOST NOTES)) {
146         ($flags->{$_}) or next;
147         if ($_ ne 'NOTES' and $flags->{$_}->{message}) {
148             $ilspatron{screen_msg} .= " -- " . $flags->{$_}->{message};  # show all but internal NOTES
149         }
150         if ($flags->{$_}->{noissues}) {
151             foreach my $toggle (qw(charge_ok renew_ok recall_ok hold_ok inet)) {
152                 $ilspatron{$toggle} = 0;    # if we get noissues, disable everything
153             }
154         }
155     }
156
157     # FIXME: populate fine_items recall_items
158     $ilspatron{unavail_holds} = _get_outstanding_holds($kp->{borrowernumber});
159
160     my $pending_checkouts = $patron->pending_checkouts;
161     my @barcodes;
162     while ( my $c = $pending_checkouts->next ) {
163         push @barcodes, { barcode => $c->item->barcode };
164     }
165     $ilspatron{items} = \@barcodes;
166
167     $self = \%ilspatron;
168     $debug and warn Dumper($self);
169     siplog("LOG_DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id,$self->{id});
170     bless $self, $type;
171     return $self;
172 }
173
174
175 # 0 means read-only
176 # 1 means read/write
177
178 my %fields = (
179     id                      => 0,
180     borrowernumber          => 0,
181     name                    => 0,
182     address                 => 0,
183     email_addr              => 0,
184     home_phone              => 0,
185     birthdate               => 0,
186     birthdate_iso           => 0,
187     dateexpiry              => 0,
188     dateexpiry_iso          => 0,
189     ptype                   => 0,
190     charge_ok               => 0,   # for patron_status[0] (inverted)
191     renew_ok                => 0,   # for patron_status[1] (inverted)
192     recall_ok               => 0,   # for patron_status[2] (inverted)
193     hold_ok                 => 0,   # for patron_status[3] (inverted)
194     card_lost               => 0,   # for patron_status[4]
195     recall_overdue          => 0,
196     currency                => 1,
197     fee_limit               => 0,
198     screen_msg              => 1,
199     print_line              => 1,
200     too_many_charged        => 0,   # for patron_status[5]
201     too_many_overdue        => 0,   # for patron_status[6]
202     too_many_renewal        => 0,   # for patron_status[7]
203     too_many_claim_return   => 0,   # for patron_status[8]
204     too_many_lost           => 0,   # for patron_status[9]
205 #   excessive_fines         => 0,   # for patron_status[10]
206 #   excessive_fees          => 0,   # for patron_status[11]
207     recall_overdue          => 0,   # for patron_status[12]
208     too_many_billed         => 0,   # for patron_status[13]
209     inet                    => 0,   # EnvisionWare extension
210 );
211
212 our $AUTOLOAD;
213
214 sub DESTROY {
215     # be cool.  needed for AUTOLOAD(?)
216 }
217
218 sub AUTOLOAD {
219     my $self = shift;
220     my $class = ref($self) or croak "$self is not an object";
221     my $name = $AUTOLOAD;
222
223     $name =~ s/.*://;
224
225     unless (exists $fields{$name}) {
226         croak "Cannot access '$name' field of class '$class'";
227     }
228
229     if (@_) {
230         $fields{$name} or croak "Field '$name' of class '$class' is READ ONLY.";
231         return $self->{$name} = shift;
232     } else {
233         return $self->{$name};
234     }
235 }
236
237 =head2 format
238
239 This method uses a template to build a string from a Koha::Patron object
240 If errors are encountered in processing template we log them and return nothing
241
242 =cut
243
244 sub format {
245     my ( $self, $template ) = @_;
246
247     if ($template) {
248         require Template;
249         require Koha::Patrons;
250
251         my $tt = Template->new();
252
253         my $patron = Koha::Patrons->find( $self->{borrowernumber} );
254
255         my $output;
256         eval {
257             $tt->process( \$template, { patron => $patron }, \$output );
258         };
259         if ( $@ ){
260             siplog("LOG_DEBUG", "Error processing template: $template");
261             return "";
262         }
263         return $output;
264     }
265 }
266
267 sub check_password {
268     my ( $self, $pwd ) = @_;
269
270     # you gotta give me something (at least ''), or no deal
271     return 0 unless defined $pwd;
272
273     # If the record has a NULL password, accept '' as match
274     return $pwd eq q{} unless $self->{password};
275
276     my $dbh = C4::Context->dbh;
277     my $ret = 0;
278     ($ret) = checkpw( $dbh, $self->{userid}, $pwd, undef, undef, 1 ); # dbh, userid, query, type, no_set_userenv
279     return $ret;
280 }
281
282 # A few special cases, not in AUTOLOADed %fields
283 sub fee_amount {
284     my $self = shift;
285     if ( $self->{fines} ) {
286         return $self->{fines};
287     }
288     return 0;
289 }
290
291 sub fines_amount {
292     my $self = shift;
293     return $self->fee_amount;
294 }
295
296 sub language {
297     my $self = shift;
298     return $self->{language} || '000'; # Unspecified
299 }
300
301 sub expired {
302     my $self = shift;
303     return $self->{expired};
304 }
305
306 #
307 # remove the hold on item item_id from my hold queue.
308 # return true if I was holding the item, false otherwise.
309
310 sub drop_hold {
311     my ($self, $item_id) = @_;
312     return if !$item_id;
313     my $result = 0;
314     foreach (qw(hold_items unavail_holds)) {
315         $self->{$_} or next;
316         for (my $i = 0; $i < scalar @{$self->{$_}}; $i++) {
317             my $held_item = $self->{$_}[$i]->{barcode} or next;
318             if ($held_item eq $item_id) {
319                 splice @{$self->{$_}}, $i, 1;
320                 $result++;
321             }
322         }
323     }
324     return $result;
325 }
326
327 # Accessor method for array_ref values, designed to get the "start" and "end" values
328 # from the SIP request.  Note those incoming values are 1-indexed, not 0-indexed.
329 #
330 sub x_items {
331     my $self      = shift;
332     my $array_var = shift or return;
333     my ($start, $end) = @_;
334
335     my $item_list = [];
336     if ($self->{$array_var}) {
337         if ($start && $start > 1) {
338             --$start;
339         }
340         else {
341             $start = 0;
342         }
343         if ( $end && $end < @{$self->{$array_var}} ) {
344         }
345         else {
346             $end = @{$self->{$array_var}};
347             --$end;
348         }
349         @{$item_list} = @{$self->{$array_var}}[ $start .. $end ];
350
351     }
352     return $item_list;
353 }
354
355 #
356 # List of outstanding holds placed
357 #
358 sub hold_items {
359     my $self = shift;
360     my $item_arr = $self->x_items('hold_items', @_);
361     foreach my $item (@{$item_arr}) {
362         my $item_obj = Koha::Items->find($item->{itemnumber});
363         $item->{barcode} = $item_obj ? $item_obj->barcode : undef;
364     }
365     return $item_arr;
366 }
367
368 sub overdue_items {
369     my $self = shift;
370     return $self->x_items('overdue_items', @_);
371 }
372 sub charged_items {
373     my $self = shift;
374     return $self->x_items('items', @_);
375 }
376 sub fine_items {
377     require Koha::Database;
378     require Template;
379
380     my $self = shift;
381     my $start = shift;
382     my $end = shift;
383     my $server = shift;
384
385     my @fees = Koha::Database->new()->schema()->resultset('Accountline')->search(
386         {
387             borrowernumber    => $self->{borrowernumber},
388             amountoutstanding => { '>' => '0' },
389         }
390     );
391
392     $start = $start ? $start - 1 : 0;
393     $end   = $end   ? $end - 1   : scalar @fees - 1;
394
395     my $av_field_template = $server ? $server->{account}->{av_field_template} : undef;
396     $av_field_template ||= "[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]";
397
398     my $tt = Template->new();
399
400     my @return_values;
401     for ( my $i = $start; $i <= $end; $i++ ) {
402         my $fee = $fees[$i];
403
404         next unless $fee;
405
406         my $output;
407         $tt->process( \$av_field_template, { accountline => $fee }, \$output );
408         push( @return_values, { barcode => $output } );
409     }
410
411     return \@return_values;
412 }
413 sub recall_items {
414     my $self = shift;
415     return $self->x_items('recall_items', @_);
416 }
417 sub unavail_holds {
418     my $self = shift;
419     return $self->x_items('unavail_holds', @_);
420 }
421
422 sub block {
423     my ($self, $card_retained, $blocked_card_msg) = @_;
424     foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok', 'inet') {
425         $self->{$field} = 0;
426     }
427     $self->{screen_msg} = "Block feature not implemented";  # $blocked_card_msg || "Card Blocked.  Please contact library staff";
428     # TODO: not really affecting patron record
429     return $self;
430 }
431
432 sub enable {
433     my $self = shift;
434     foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok', 'inet') {
435         $self->{$field} = 1;
436     }
437     siplog("LOG_DEBUG", "Patron(%s)->enable: charge: %s, renew:%s, recall:%s, hold:%s",
438        $self->{id}, $self->{charge_ok}, $self->{renew_ok},
439        $self->{recall_ok}, $self->{hold_ok});
440     $self->{screen_msg} = "Enable feature not implemented."; # "All privileges restored.";   # TODO: not really affecting patron record
441     return $self;
442 }
443
444 sub inet_privileges {
445     my $self = shift;
446     return $self->{inet} ? 'Y' : 'N';
447 }
448
449 sub _fee_limit {
450     return C4::Context->preference('noissuescharge') || 5;
451 }
452
453 sub excessive_fees {
454     my $self = shift;
455     return ($self->fee_amount and $self->fee_amount > $self->fee_limit);
456 }
457
458 sub excessive_fines {
459     my $self = shift;
460     return $self->excessive_fees;   # excessive_fines is the same thing as excessive_fees for Koha
461 }
462
463 sub holds_blocked_by_excessive_fees {
464     my $self = shift;
465     return ( $self->fee_amount
466           && $self->fee_amount > C4::Context->preference("maxoutstanding") );
467 }
468     
469 sub library_name {
470     my $self = shift;
471     unless ($self->{library_name}) {
472         my $library = Koha::Libraries->find( $self->{branchcode} );
473         $self->{library_name} = $library ? $library->branchname : '';
474     }
475     return $self->{library_name};
476 }
477 #
478 # Messages
479 #
480
481 sub invalid_patron {
482     my $self = shift;
483     return "Please contact library staff";
484 }
485
486 sub charge_denied {
487     my $self = shift;
488     return "Please contact library staff";
489 }
490
491 =head2 update_lastseen
492
493     $patron->update_lastseen();
494
495     Patron method to update lastseen field in borrower
496     to record that patron has been seen via sip connection
497
498 =cut
499
500 sub update_lastseen {
501     my $self = shift;
502     my $kohaobj = Koha::Patrons->find( $self->{borrowernumber} );
503     $kohaobj->track_login if $kohaobj; # track_login checks the pref
504 }
505
506 sub _get_address {
507     my $patron = shift;
508
509     my $address = $patron->{streetnumber} || q{};
510     for my $field (qw( roaddetails address address2 city state zipcode country))
511     {
512         next unless $patron->{$field};
513         if ($address) {
514             $address .= q{ };
515             $address .= $patron->{$field};
516         }
517         else {
518             $address .= $patron->{$field};
519         }
520     }
521     return $address;
522 }
523
524 sub _get_outstanding_holds {
525     my $borrowernumber = shift;
526
527     my $patron = Koha::Patrons->find( $borrowernumber );
528     my $holds = $patron->holds->search( { -or => [ { found => undef }, { found => { '!=' => 'W' } } ] } );
529     my @holds;
530     while ( my $hold = $holds->next ) {
531         my $item;
532         if ($hold->itemnumber) {
533             $item = $hold->item;
534         }
535         else {
536             # We need to return a barcode for the biblio so the client
537             # can request the biblio info
538             my $items = $hold->biblio->items;
539             $item = $items->count ? $items->next : undef;
540         }
541         my $unblessed_hold = $hold->unblessed;
542
543         $unblessed_hold->{barcode} = $item ? $item->barcode : undef;
544
545         push @holds, $unblessed_hold;
546     }
547     return \@holds;
548 }
549
550 =head2 build_patron_attributes_string
551
552 This method builds the part of the sip message for extended patron
553 attributes as defined in the sip config
554
555 =cut
556
557 sub build_patron_attributes_string {
558     my ( $self, $server ) = @_;
559
560     my $string = q{};
561     if ( $server->{account}->{patron_attribute} ) {
562         my @attributes_to_send =
563           ref $server->{account}->{patron_attribute} eq "ARRAY"
564           ? @{ $server->{account}->{patron_attribute} }
565           : ( $server->{account}->{patron_attribute} );
566
567         foreach my $a ( @attributes_to_send ) {
568             my @attributes = Koha::Patron::Attributes->search(
569                 {
570                     borrowernumber => $self->{borrowernumber},
571                     code           => $a->{code}
572                 }
573             );
574
575             foreach my $attribute ( @attributes ) {
576                 my $value = $attribute->attribute();
577                 $string .= add_field( $a->{field}, $value );
578             }
579         }
580     }
581
582     return $string;
583 }
584
585
586 =head2 build_custom_field_string
587
588 This method builds the part of the sip message for custom patron fields as defined in the sip config
589
590 =cut
591
592 sub build_custom_field_string {
593     my ( $self, $server ) = @_;
594
595     my $string = q{};
596
597     if ( $server->{account}->{custom_patron_field} ) {
598         my @custom_fields =
599             ref $server->{account}->{custom_patron_field} eq "ARRAY"
600             ? @{ $server->{account}->{custom_patron_field} }
601             : $server->{account}->{custom_patron_field};
602         foreach my $custom_field ( @custom_fields ) {
603             $string .= maybe_add( $custom_field->{field}, $self->format( $custom_field->{template} ) ) if defined $custom_field->{field};
604         }
605     }
606     return $string;
607 }
608
609 1;
610 __END__
611
612 =head1 EXAMPLES
613
614   our %patron_example = (
615           djfiander => {
616               name => "David J. Fiander",
617               id => 'djfiander',
618               password => '6789',
619               ptype => 'A', # 'A'dult.  Whatever.
620               birthdate => '19640925',
621               address => '2 Meadowvale Dr. St Thomas, ON',
622               home_phone => '(519) 555 1234',
623               email_addr => 'djfiander@hotmail.com',
624               charge_ok => 1,
625               renew_ok => 1,
626               recall_ok => 0,
627               hold_ok => 1,
628               card_lost => 0,
629               claims_returned => 0,
630               fines => 100,
631               fees => 0,
632               recall_overdue => 0,
633               items_billed => 0,
634               screen_msg => '',
635               print_line => '',
636               items => [],
637               hold_items => [],
638               overdue_items => [],
639               fine_items => ['Computer Time'],
640               recall_items => [],
641               unavail_holds => [],
642               inet => 1,
643           },
644   );
645
646  From borrowers table:
647 +---------------------+--------------+------+-----+---------+----------------+
648 | Field               | Type         | Null | Key | Default | Extra          |
649 +---------------------+--------------+------+-----+---------+----------------+
650 | borrowernumber      | int(11)      | NO   | PRI | NULL    | auto_increment |
651 | cardnumber          | varchar(16)  | YES  | UNI | NULL    |                |
652 | surname             | mediumtext   | NO   |     | NULL    |                |
653 | firstname           | text         | YES  |     | NULL    |                |
654 | title               | mediumtext   | YES  |     | NULL    |                |
655 | othernames          | mediumtext   | YES  |     | NULL    |                |
656 | initials            | text         | YES  |     | NULL    |                |
657 | streetnumber        | varchar(10)  | YES  |     | NULL    |                |
658 | streettype          | varchar(50)  | YES  |     | NULL    |                |
659 | address             | mediumtext   | NO   |     | NULL    |                |
660 | address2            | text         | YES  |     | NULL    |                |
661 | city                | mediumtext   | NO   |     | NULL    |                |
662 | state               | mediumtext   | YES  |     | NULL    |                |
663 | zipcode             | varchar(25)  | YES  |     | NULL    |                |
664 | country             | text         | YES  |     | NULL    |                |
665 | email               | mediumtext   | YES  |     | NULL    |                |
666 | phone               | text         | YES  |     | NULL    |                |
667 | mobile              | varchar(50)  | YES  |     | NULL    |                |
668 | fax                 | mediumtext   | YES  |     | NULL    |                |
669 | emailpro            | text         | YES  |     | NULL    |                |
670 | phonepro            | text         | YES  |     | NULL    |                |
671 | B_streetnumber      | varchar(10)  | YES  |     | NULL    |                |
672 | B_streettype        | varchar(50)  | YES  |     | NULL    |                |
673 | B_address           | varchar(100) | YES  |     | NULL    |                |
674 | B_address2          | text         | YES  |     | NULL    |                |
675 | B_city              | mediumtext   | YES  |     | NULL    |                |
676 | B_state             | mediumtext   | YES  |     | NULL    |                |
677 | B_zipcode           | varchar(25)  | YES  |     | NULL    |                |
678 | B_country           | text         | YES  |     | NULL    |                |
679 | B_email             | text         | YES  |     | NULL    |                |
680 | B_phone             | mediumtext   | YES  |     | NULL    |                |
681 | dateofbirth         | date         | YES  |     | NULL    |                |
682 | branchcode          | varchar(10)  | NO   | MUL |         |                |
683 | categorycode        | varchar(10)  | NO   | MUL |         |                |
684 | dateenrolled        | date         | YES  |     | NULL    |                |
685 | dateexpiry          | date         | YES  |     | NULL    |                |
686 | gonenoaddress       | tinyint(1)   | YES  |     | NULL    |                |
687 | lost                | tinyint(1)   | YES  |     | NULL    |                |
688 | debarred            | tinyint(1)   | YES  |     | NULL    |                |
689 | contactname         | mediumtext   | YES  |     | NULL    |                |
690 | contactfirstname    | text         | YES  |     | NULL    |                |
691 | contacttitle        | text         | YES  |     | NULL    |                |
692 | borrowernotes       | mediumtext   | YES  |     | NULL    |                |
693 | relationship        | varchar(100) | YES  |     | NULL    |                |
694 | ethnicity           | varchar(50)  | YES  |     | NULL    |                |
695 | ethnotes            | varchar(255) | YES  |     | NULL    |                |
696 | sex                 | varchar(1)   | YES  |     | NULL    |                |
697 | password            | varchar(30)  | YES  |     | NULL    |                |
698 | flags               | int(11)      | YES  |     | NULL    |                |
699 | userid              | varchar(30)  | YES  | MUL | NULL    |                |
700 | opacnote            | mediumtext   | YES  |     | NULL    |                |
701 | contactnote         | varchar(255) | YES  |     | NULL    |                |
702 | sort1               | varchar(80)  | YES  |     | NULL    |                |
703 | sort2               | varchar(80)  | YES  |     | NULL    |                |
704 | altcontactfirstname | varchar(255) | YES  |     | NULL    |                |
705 | altcontactsurname   | varchar(255) | YES  |     | NULL    |                |
706 | altcontactaddress1  | varchar(255) | YES  |     | NULL    |                |
707 | altcontactaddress2  | varchar(255) | YES  |     | NULL    |                |
708 | altcontactaddress3  | varchar(255) | YES  |     | NULL    |                |
709 | altcontactstate     | mediumtext   | YES  |     | NULL    |                |
710 | altcontactzipcode   | varchar(50)  | YES  |     | NULL    |                |
711 | altcontactcountry   | text         | YES  |     | NULL    |                |
712 | altcontactphone     | varchar(50)  | YES  |     | NULL    |                |
713 | smsalertnumber      | varchar(50)  | YES  |     | NULL    |                |
714 | privacy             | int(11)      | NO   |     | 1       |                |
715 +---------------------+--------------+------+-----+---------+----------------+
716
717
718  From C4::Members
719
720  $flags->{KEY}
721  {CHARGES}
722     {message}     Message showing patron's credit or debt
723     {noissues}    Set if patron owes >$5.00
724  {GNA}             Set if patron gone w/o address
725     {message}     "Borrower has no valid address"
726     {noissues}    Set.
727  {LOST}            Set if patron's card reported lost
728     {message}     Message to this effect
729     {noissues}    Set.
730  {DBARRED}         Set if patron is debarred
731     {message}     Message to this effect
732     {noissues}    Set.
733  {NOTES}           Set if patron has notes
734     {message}     Notes about patron
735  {ODUES}           Set if patron has overdue books
736     {message}     "Yes"
737     {itemlist}    ref-to-array: list of overdue books
738     {itemlisttext}    Text list of overdue items
739  {WAITING}         Set if there are items available that the patron reserved
740     {message}     Message to this effect
741     {itemlist}    ref-to-array: list of available items
742
743 =cut
744