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