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