]> git.evergreen-ils.org Git - working/SIPServer.git/blob - ILS/Patron.pm
Patron Expiration in PA
[working/SIPServer.git] / ILS / Patron.pm
1 #
2 # Copyright (C) 2006-2008  Georgia Public Library Service
3
4 # Author: David J. Fiander
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of version 2 of the GNU General Public
8 # License as published by the Free Software Foundation.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public
16 # License along with this program; if not, write to the Free
17 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 # MA 02111-1307 USA
19 #
20 # ILS::Patron.pm
21
22 # A Class for hiding the ILS's concept of the patron from the OpenSIP
23 # system
24 #
25
26 package ILS::Patron;
27
28 use strict;
29 use warnings;
30 use Exporter;
31
32 use Sys::Syslog qw(syslog);
33 use Data::Dumper;
34
35 our (@ISA, @EXPORT_OK);
36
37 @ISA = qw(Exporter);
38
39 @EXPORT_OK = qw(invalid_patron);
40
41 our %patron_db = (
42                   djfiander => {
43                       name => "David J. Fiander",
44                       id => 'djfiander',
45                       password => '6789',
46                       ptype => 'A', # 'A'dult.  Whatever.
47                       birthdate => '19640925',
48                       address => '2 Meadowvale Dr. St Thomas, ON',
49                       home_phone => '(519) 555 1234',
50                       email_addr => 'djfiander@hotmail.com',
51                       home_library => 'Beacock',
52                       charge_ok => 1,
53                       renew_ok => 1,
54                       recall_ok => 0,
55                       hold_ok => 1,
56                       card_lost => 0,
57                       claims_returned => 0,
58                       fines => 100,
59                       fees => 0,
60                       recall_overdue => 0,
61                       items_billed => 0,
62                       screen_msg => '',
63                       print_line => '',
64                       items => [],
65                       hold_items => [],
66                       overdue_items => [],
67                       fine_items => ['Computer Time'],
68                       recall_items => [],
69                       unavail_holds => [],
70                       inet => 1,
71                       expire => '20501231',
72                   },
73                   miker => {
74                       name => "Mike Rylander",
75                       id => 'miker',
76                       password => '6789',
77                       ptype => 'A', # 'A'dult.  Whatever.
78                       birthdate => '19640925',
79                       address => 'Somewhere in Atlanta',
80                       home_phone => '(404) 555 1235',
81                       email_addr => 'mrylander@gmail.com',
82                       charge_ok => 1,
83                       renew_ok => 1,
84                       recall_ok => 0,
85                       hold_ok => 1,
86                       card_lost => 0,
87                       claims_returned => 0,
88                       fines => 0,
89                       fees => 0,
90                       recall_overdue => 0,
91                       items_billed => 0,
92                       screen_msg => '',
93                       print_line => '',
94                       items => [],
95                       hold_items => [],
96                       overdue_items => [],
97                       fine_items => [],
98                       recall_items => [],
99                       unavail_holds => [],
100                       inet => 0,
101                       expire => '20501120',
102                   },
103                   );
104
105 sub new {
106     my ($class, $patron_id) = @_;
107     my $type = ref($class) || $class;
108     my $self;
109
110     if (!exists($patron_db{$patron_id})) {
111         syslog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id);
112         return undef;
113     }
114
115     $self = $patron_db{$patron_id};
116
117     syslog("LOG_DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id,
118            $self->{id});
119
120     bless $self, $type;
121     return $self;
122 }
123
124 sub id {
125     my $self = shift;
126
127     return $self->{id};
128 }
129
130 sub name {
131     my $self = shift;
132
133     return $self->{name};
134 }
135
136 sub address {
137     my $self = shift;
138
139     return $self->{address};
140 }
141
142 sub email_addr {
143     my $self = shift;
144
145     return $self->{email_addr};
146 }
147
148 sub home_phone {
149     my $self = shift;
150
151     return $self->{home_phone};
152 }
153
154 sub sip_birthdate {
155     my $self = shift;
156
157     return $self->{birthdate};
158 }
159
160 sub sip_expire {
161     my $self = shift;
162
163     return $self->{expire};
164 }
165
166 sub ptype {
167     my $self = shift;
168
169     return $self->{ptype};
170 }
171
172 sub language {
173     my $self = shift;
174
175     return $self->{language} || '000'; # Unspecified
176 }
177
178 sub charge_ok {
179     my $self = shift;
180
181     return $self->{charge_ok};
182 }
183
184 sub renew_ok {
185     my $self = shift;
186
187     return $self->{renew_ok};
188 }
189
190 sub recall_ok {
191     my $self = shift;
192
193     return $self->{recall_ok};
194 }
195
196 sub hold_ok {
197     my $self = shift;
198
199     return $self->{hold_ok};
200 }
201
202 sub card_lost {
203     my $self = shift;
204
205     return $self->{card_lost};
206 }
207
208 sub recall_overdue {
209     my $self = shift;
210
211     return $self->{recall_overdue};
212 }
213
214 sub check_password {
215     my ($self, $pwd) = @_;
216
217     # If the patron doesn't have a password,
218     # then we don't need to check
219     return (!$self->{password} || ($pwd && ($self->{password} eq $pwd)));
220 }
221
222 sub currency {
223     my $self = shift;
224
225     return $self->{currency};
226 }
227
228 sub fee_amount {
229     my $self = shift;
230
231     return $self->{fee_amount} || undef;
232 }
233
234 sub screen_msg {
235     my $self = shift;
236
237     return $self->{screen_msg};
238 }
239
240 sub print_line {
241     my $self = shift;
242
243     return $self->{print_line};
244 }
245
246 sub too_many_charged {
247     my $self = shift;
248
249     return $self->{too_many_charged};
250 }
251
252 sub too_many_overdue {
253     my $self = shift;
254
255     return $self->{too_many_overdue};
256 }
257
258 sub too_many_renewal {
259     my $self = shift;
260
261     return $self->{too_many_renewal};
262 }
263
264 sub too_many_claim_return {
265     my $self = shift;
266
267     return $self->{too_many_claim_return};
268 }
269
270 sub too_many_lost {
271     my $self = shift;
272
273     return $self->{too_many_lost};
274 }
275
276 sub excessive_fines {
277     my $self = shift;
278
279     return $self->{excessive_fines};
280 }
281
282 sub excessive_fees {
283     my $self = shift;
284
285     return $self->{excessive_fees};
286 }
287
288 sub too_many_billed {
289     my $self = shift;
290
291     return $self->{too_many_billed};
292 }
293
294 #
295 # List of outstanding holds placed
296 #
297 sub hold_items {
298     my ($self, $start, $end) = @_;
299
300     $start = 1 if !defined($start);
301     $end = scalar @{$self->{hold_items}} if !defined($end);
302
303     return [@{$self->{hold_items}}[$start-1 .. $end-1]];
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     my $i;
313
314     for ($i = 0; $i < scalar @{$self->{hold_items}}; $i += 1) {
315         if ($self->{hold_items}[$i]->{item_id} eq $item_id) {
316             splice @{$self->{hold_items}}, $i, 1;
317             return 1;
318         }
319     }
320
321     return 0;
322 }
323
324 sub overdue_items {
325     my ($self, $start, $end) = @_;
326
327     $start = 1 if !defined($start);
328     $end = scalar @{$self->{overdue_items}} if !defined($end);
329
330     return [@{$self->{overdue_items}}[$start-1 .. $end-1]];
331 }
332
333 sub charged_items {
334     my ($self, $start, $end) = shift;
335
336     $start = 1 if !defined($start);
337     $end = scalar @{$self->{items}} if !defined($end);
338
339     syslog("LOG_DEBUG", "charged_items: start = %d, end = %d", $start, $end);
340     syslog("LOG_DEBUG", "charged_items: items = (%s)",
341            join(', ', @{$self->{items}}));
342
343         return [@{$self->{items}}[$start-1 .. $end-1]];
344 }
345
346 sub fine_items {
347     my ($self, $start, $end) = @_;
348
349     $start = 1 if !defined($start);
350     $end = scalar @{$self->{fine_items}} if !defined($end);
351
352     return [@{$self->{fine_items}}[$start-1 .. $end-1]];
353 }
354
355 sub recall_items {
356     my ($self, $start, $end) = @_;
357
358     $start = 1 if !defined($start);
359     $end = scalar @{$self->{recall_items}} if !defined($end);
360
361     return [@{$self->{recall_items}}[$start-1 .. $end-1]];
362 }
363
364 sub unavail_holds {
365     my ($self, $start, $end) = @_;
366
367     $start = 1 if !defined($start);
368     $end = scalar @{$self->{unavail_holds}} if !defined($end);
369
370     return [@{$self->{unavail_holds}}[$start-1 .. $end-1]];
371 }
372
373 sub block {
374     my ($self, $card_retained, $blocked_card_msg) = @_;
375
376     foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok') {
377         $self->{$field} = 0;
378     }
379
380     $self->{screen_msg} = $blocked_card_msg || "Card Blocked.  Please contact library staff";
381
382     return $self;
383 }
384
385 sub enable {
386     my $self = shift;
387
388     foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok') {
389         $self->{$field} = 1;
390     }
391
392     syslog("LOG_DEBUG", "Patron(%s)->enable: charge: %s, renew:%s, recall:%s, hold:%s",
393            $self->{id}, $self->{charge_ok}, $self->{renew_ok},
394            $self->{recall_ok}, $self->{hold_ok});
395
396     $self->{screen_msg} = "All privileges restored.";
397
398     return $self;
399 }
400
401
402 sub inet_privileges {
403     my $self = shift;
404
405     return $self->{inet} ? 'Y' : 'N';
406 }
407
408 # Extension requested by PINES. Report the home system for
409 # the patron in the 'AQ' field. This is normally the "permanent
410 # location" field for an ITEM, but it's not used in PATRON info.
411 # Apparently TLC systems do this.
412 sub home_library {
413     my $self = shift;
414
415     return $self->{home_library}
416 }
417
418 #
419 # Messages
420 #
421
422 sub invalid_patron {
423     return "Please contact library staff";
424 }
425
426 sub charge_denied {
427     return "Please contact library staff";
428 }
429
430 1;