forked from nathanejohnson/Sip2Wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sip2.class.php
1436 lines (1286 loc) · 50.6 KB
/
Sip2.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
//namespace tzeumer\Sip2Wrapper;
/**
* @package
* @author John Wohlers <[email protected]>
* @license http://opensource.org/licenses/gpl-3.0.html
* @copyright John Wohlers <[email protected]>
* @version $Id: sip2.class.php 28 2010-10-08 21:06:51Z cap60552 $
* @link http://php-sip2.googlecode.com/
*/
/**
* SIP2 Class
*
* This class provides a method of communicating with an Integrated
* Library System using 3M's SIP2 standard.
*
* PHP version 5
*
* Changelog:
*
* 2016-03-19
* - Added support for TLS connections
*
* 2012.02.05:
*
* - Fixed some underlying issues in the handling of CRC checking and Sequence number usage
* by adding public variables and making sure they are respected througout other in the class
*
* - Whitespace formatting cleanup and consistency (replace some tabs with spaces)
* Add docblock style commenting to all functions
*
* - Fleshed out usage example with checks
*
* 2010.10.08:
*
* - Fixed a potential endless loop condition if a socket lost connection in the middle of a transaction.
*
* 2008.04.11:
*
* - Encorported a bug fix submitted by Bob Wicksall
*
* TODO:
*
* - Clean up variable names, check for consistancy
* - Add better i18n support, including functions to handle the SIP2 language definitions
*
* Usage Example:
*
* ```php
* // include the class
* include('sip2.class.php');
*
* // create object
* $mysip = new sip2;
*
* // set host name
* $mysip->hostname = 'server.example.com';
* $mysip->port = 6002;
*
* // identify a patron
* $mysip->patron = '101010101';
* $mysip->patronpwd = '010101';
*
* // connect to SIP server
* $result = $mysip->connect();
*
* // check result
* if (!$result) {
* die('could not connect');
* }
*
* // generate login message
* $msg = $mysip->msgLogin('login', 'password');
*
* // get login response
* $login = $mysip->parseLoginResponse( $mysip->get_message($msg) );
*
* // check login response
* if ($login['fixed']['Ok'] != 1) {
* die('login failed');
* }
*
* // generate a self check message
* $msg = $mysip->msgSCStatus();
*
* // execute a self check
* $check = $mysip->parseACSStatusResponse( $mysip->get_message($msg) );
*
* // verify return
* if ($status['fixed']['Online'] != 'Y') {
* die('system not online');
* }
*
* // generate charged items request message
* $msg = $mysip->msgPatronInformation('charged');
*
* // parse the raw response into an array
* $charged = $mysip->parsePatronInfoResponse( $mysip->get_message($msg) );
* ```
*/
class Sip2
{
/**
* instance hostname
* @var string
*/
public $hostname;
/**
* port number
* @var int
*/
public $port = 6002;
/**
* language code (000 = default, 001 == english)
* @var string
*/
public $language = '000';
/**
* patron identifier (AA)
* @var string
*/
public $patron = '';
/**
* patron password (AD)
* @var string
*/
public $patronpwd = '';
/**
* terminal password (AC)
* @var string
*/
public $AC = '';
/**
* maximum number of resends allowed before we give up
* @var integer
*/
public $maxretry = 3;
/**
* field terminator
* @var string
*/
public $fldTerminator = '|';
/**
* message terminator
* @var string
*/
public $msgTerminator = "\r";
/**
* login encryption algorithm type (0 = plain text)
* @var integer
*/
public $UIDalgorithm = 0;
/**
* password encryption algorithm type (undocumented)
* @var integer
*/
public $PWDalgorithm = 0;
/**
* location code
* @var string
*/
public $scLocation = '';
/**
* toggle crc checking and appending
* @var boolean
*/
public $withCrc = true;
/**
* toggle the use of sequence numbers
* @var boolean
*/
public $withSeq = true;
/**
* debug logging toggle
* @var boolean
*/
public $debug = false;
/**
* Log of communication actions
* @var string
*/
public $log = '';
/**
* Last message sent to ACS
* @var string
*/
public $last_request = '';
/**
* Last response from ACS
* @var string
*/
public $last_response = '';
/**
* Last paresed response from ACS
* @var array
*/
public $last_response_parsed = '';
/**
* value for the AO field
* @var string
*/
public $AO = 'TUHH';
/**
* value for the AN field
* @var string
*/
public $AN = 'SIPCHK';
/**
* Socket: value until connection times out (no server response)
* @var integer
*/
public $socket_timeout = 5;
/**
* Socket: enable TLS (encrypted connection). Server has to support it.
* @var integer
*/
public $socket_tls_enable = false;
/**
* Socket: Set TLS options. Using most likely SIP-Server settings for example.
* Please refer to https://secure.php.net/manual/en/context.ssl.php
* @var array
*/
public $socket_tls_options = array(
//'peer_name' => 'YOUR TLS HOSTNAME', // since 5.6, If this value is not set, then the name is guessed based on the hostname used when opening the stream
'verify_peer' => true,
'verify_peer_name' => true, // since 5.6
'allow_self_signed' => true,
//'cafile' => 'path/to/cafile/cacert.pem',
//'capath' => 'path/to/ca_certificates/directory',
//'local_cert' => 'path/to/local_cert/cert_and_privateKey.pem',
//'local_pk' => 'path/to/local_certs_and_keys/',
//'passphrase' => 'My local_cert password',
//'CN_match' => $this->hostname, // until 5.6: use peer_name instead
//'verify_depth' => Defaults to no verification,
'ciphers' => 'HIGH:!SSLv2',
'capture_peer_cert' => true,
'capture_peer_cert_chain' => true,
//'SNI_enabled' => true, // since 5.3.2
//'SNI_server_name' => 'NAME', // until 5.6: use peer_name instead
'disable_compression' => true, // since 5.4.13
//'peer_fingerprint' => 'SOME_HASH_STRING or an ARRAY' // since 5.6
);
/**
* Socket: Error ID
* @var integer
*/
public $socket_error_id;
/**
* Socket: Error message
* @var integer
*/
public $socket_error_msg;
/**
* Socket protocol
* @var string
*/
private $socket_protocol = 'tcp';
/**
* raw socket connection
* @var object
*/
private $socket;
/**
* internal sequence number
* @var integer
*/
private $seq = -1;
/**
* internal retry counter
* @var integer
*/
private $retry = 0;
/**
* internal message build buffer
* @var string
*/
private $msgBuild = '';
/**
* internal message build toggle
* @var boolean
*/
private $noFixed = false;
/**
* Used protocol version (or extension)
* @var string
*/
public $version = 'Sip2';
/**
* Generate Patron Status (code 23) request messages in sip2 format
* @return string SIP2 request message
* @api
*/
function msgPatronStatusRequest()
{
/* Server Response: Patron Status Response message. */
$this->_newMessage('23');
$this->_addFixedOption($this->language, 3);
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AC',$this->AC);
$this->_addVarOption('AD',$this->patronpwd);
return $this->_returnMessage();
}
/**
* Generate Checkout (code 11) request messages in sip2 format
* @param string $item value for the variable length required AB field
* @param string $nbDateDue optional override for default due date (default '')
* @param string $scRenewal value for the renewal portion of the fixed length field (default N)
* @param string $itmProp value for the variable length optional CH field (default '')
* @param string $fee value for the variable length optional BO field (default N)
* @param string $noBlock value for the blocking portion of the fixed length field (default N)
* @param string $cancel value for the variable length optional BI field (default N)
* @return string SIP2 request message
* @api
*/
function msgCheckout($item, $nbDateDue ='', $scRenewal='N', $itmProp ='', $fee='N', $noBlock='N', $cancel='N')
{
/* Checkout an item (11) - untested */
$this->_newMessage('11');
$this->_addFixedOption($scRenewal, 1);
$this->_addFixedOption($noBlock, 1);
$this->_addFixedOption($this->_datestamp(), 18);
if ($nbDateDue != '') {
/* override defualt date due */
$this->_addFixedOption($this->_datestamp($nbDateDue), 18);
} else {
/* send a blank date due to allow ACS to use default date due computed for item */
$this->_addFixedOption('', 18);
}
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AB',$item);
$this->_addVarOption('AC',$this->AC);
$this->_addVarOption('CH',$itmProp, true);
$this->_addVarOption('AD',$this->patronpwd, true);
$this->_addVarOption('BO',$fee, true); /* Y or N */
$this->_addVarOption('BI',$cancel, true); /* Y or N */
return $this->_returnMessage();
}
/**
* Generate Checkin (code 09) request messages in sip2 format
* @param string $item value for the variable length required AB field
* @param string $itmReturnDate value for the return date portion of the fixed length field
* @param string $itmLocation value for the variable length required AP field (default '')
* @param string $itmProp value for the variable length optional CH field (default '')
* @param string $noBlock value for the blocking portion of the fixed length field (default N)
* @param string $cancel value for the variable length optional BI field (default N)
* @return string SIP2 request message
* @api
*/
function msgCheckin($item, $itmReturnDate, $itmLocation = '', $itmProp = '', $noBlock='N', $cancel = '')
{
/* Checkin an item (09) - untested */
if ($itmLocation == '') {
/* If no location is specified, assume the defualt location of the SC, behavior suggested by spec*/
$itmLocation = $this->scLocation;
}
$this->_newMessage('09');
$this->_addFixedOption($noBlock, 1);
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addFixedOption($this->_datestamp($itmReturnDate), 18);
$this->_addVarOption('AP',$itmLocation);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AB',$item);
$this->_addVarOption('AC',$this->AC);
$this->_addVarOption('CH',$itmProp, true);
$this->_addVarOption('BI',$cancel, true); /* Y or N */
return $this->_returnMessage();
}
/**
* Generate Block Patron (code 11) request messages in sip2 format
* @param string $message message value for the required variable length AL field
* @param string $retained value for the retained portion of the fixed length field (default N)
* @return string SIP2 request message
* @api
*/
function msgBlockPatron($message, $retained='N')
{
/* Blocks a patron, and responds with a patron status response (01) - untested */
$this->_newMessage('01');
$this->_addFixedOption($retained, 1); /* Y if card has been retained */
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AL',$message);
$this->_addVarOption('AA',$this->AA);
$this->_addVarOption('AC',$this->AC);
return $this->_returnMessage();
}
/**
* Generate SC Status (code 99) request messages in sip2 format
* @param int $status status code
* @param int $width message width (default 80)
* @param int $version prootocol version (default 2)
* @return string|false SIP2 request message or false on error
* @api
*/
function msgSCStatus($status = 0, $width = '080', $version = '2.00')
{
/* selfcheck status message, this should be sent immediatly after login - untested */
/* status codes, from the spec:
* 0 SC unit is OK
* 1 SC printer is out of paper
* 2 SC is about to shut down
*/
if ($version > 3) {
$version = '2.00';
}
if ($status < 0 || $status > 2) {
$this->_debugmsg( $this->version.": Invalid status passed to msgSCStatus" );
return false;
}
$this->_newMessage('99');
$this->_addFixedOption($status, 1);
$this->_addFixedOption($width, 3);
$this->_addFixedOption(sprintf("%03.2f",$version), 4);
return $this->_returnMessage();
}
/**
* Generate ACS Resend (code 97) request messages in sip2 format
* @return string SIP2 request message
* @api
*/
function msgRequestACSResend ()
{
/* Used to request a resend due to CRC mismatch - No sequence number is used */
$this->_newMessage('97');
return $this->_returnMessage(false);
}
/**
* Generate login (code 93) request messages in sip2 format
* @param string $sipLogin login value for the CN field
* @param string $sipPassword password value for the CO field
* @return string SIP2 request message
* @api
*/
function msgLogin($sipLogin, $sipPassword)
{
/* Login (93) - untested */
$this->_newMessage('93');
$this->_addFixedOption($this->UIDalgorithm, 1);
$this->_addFixedOption($this->PWDalgorithm, 1);
$this->_addVarOption('CN',$sipLogin);
$this->_addVarOption('CO',$sipPassword);
$this->_addVarOption('CP',$this->scLocation, true);
return $this->_returnMessage();
}
/**
* Generate Patron Information (code 63) request messages in sip2 format
* @param string $type type of information request (none, hold, overdue, charged, fine, recall, unavail)
* @param string $start value for BP field (default 1)
* @param string $end value for BQ field (default 5)
* @return string SIP2 request message
* @api
*/
function msgPatronInformation($type, $start = '1', $end = '5')
{
/*
* According to the specification:
* Only one category of items should be requested at a time, i.e. it would take 6 of these messages,
* each with a different position set to Y, to get all the detailed information about a patron's items.
*/
$summary['none'] = ' ';
$summary['hold'] = 'Y ';
$summary['overdue'] = ' Y ';
$summary['charged'] = ' Y ';
$summary['fine'] = ' Y ';
$summary['recall'] = ' Y ';
$summary['unavail'] = ' Y';
/* Request patron information */
$this->_newMessage('63');
$this->_addFixedOption($this->language, 3);
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addFixedOption(sprintf("%-10s",$summary[$type]), 10);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AC',$this->AC, true);
$this->_addVarOption('AD',$this->patronpwd, true);
$this->_addVarOption('BP',$start, true); /* old function version used padded 5 digits, not sure why */
$this->_addVarOption('BQ',$end, true); /* old function version used padded 5 digits, not sure why */
return $this->_returnMessage();
}
/**
* Generate End Patron Session (code 35) request messages in sip2 format
* @return string SIP2 request message
* @api
*/
function msgEndPatronSession()
{
/* End Patron Session, should be sent before switching to a new patron. (35) - untested */
$this->_newMessage('35');
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AC',$this->AC, true);
$this->_addVarOption('AD',$this->patronpwd, true);
return $this->_returnMessage();
}
/**
* Generate Fee Paid (code 37) request messages in sip2 format
* @param int $feeType value for the fee type portion of the fixed length field
* @param int $pmtType value for payment type portion of the fixed length field
* @param string $pmtAmount value for the payment amount variable length required BV field
* @param string $curType value for the currency type portion of the fixed field
* @param string $feeId value for the fee id variable length optional CG field
* @param string $transId value for the transaction id variable length optional BK field
* @return string|false SIP2 request message or false on error
* @api
*/
function msgFeePaid ($feeType, $pmtType, $pmtAmount, $curType = 'USD', $feeId = '', $transId = '')
{
/* Fee payment function (37) - untested */
/* Fee Types: */
/* 01 other/unknown */
/* 02 administrative */
/* 03 damage */
/* 04 overdue */
/* 05 processing */
/* 06 rental*/
/* 07 replacement */
/* 08 computer access charge */
/* 09 hold fee */
/* Value Payment Type */
/* 00 cash */
/* 01 VISA */
/* 02 credit card */
if (!is_numeric($feeType) || $feeType > 99 || $feeType < 1) {
/* not a valid fee type - exit */
$this->_debugmsg( $this->version.": (msgFeePaid) Invalid fee type: {$feeType}");
return false;
}
if (!is_numeric($pmtType) || $pmtType > 99 || $pmtType < 0) {
/* not a valid payment type - exit */
$this->_debugmsg( $this->version.": (msgFeePaid) Invalid payment type: {$pmtType}");
return false;
}
$this->_newMessage('37');
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addFixedOption(sprintf('%02d', $feeType), 2);
$this->_addFixedOption(sprintf('%02d', $pmtType), 2);
$this->_addFixedOption($curType, 3);
$this->_addVarOption('BV',$pmtAmount); /* due to currancy format localization, it is up to the programmer to properly format their payment amount */
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AC',$this->AC, true);
$this->_addVarOption('AD',$this->patronpwd, true);
$this->_addVarOption('CG',$feeId, true);
$this->_addVarOption('BK',$transId, true);
return $this->_returnMessage();
}
/**
* Generate Item Information (code 17) request messages in sip2 format
* @param string $item value for the variable length required AB field
* @return string SIP2 request message
* @api
*/
function msgItemInformation($item)
{
$this->_newMessage('17');
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AB',$item);
$this->_addVarOption('AC',$this->AC, true);
return $this->_returnMessage();
}
/**
* Generate Item Status (code 19) request messages in sip2 format
* @param string $item value for the variable length required AB field
* @param string $itmProp value for the variable length required CH field
* @return string SIP2 request message
* @api
*/
function msgItemStatus ($item, $itmProp = '')
{
/* Item status update function (19) - untested */
$this->_newMessage('19');
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AB',$item);
$this->_addVarOption('AC',$this->AC, true);
$this->_addVarOption('CH',$itmProp);
return $this->_returnMessage();
}
/**
* Generate Patron Enable (code 25) request messages in sip2 format
* @return string SIP2 request message
* @api
*/
function msgPatronEnable ()
{
/* Patron Enable function (25) - untested */
/* This message can be used by the SC to re-enable canceled patrons. It should only be used for system testing and validation. */
$this->_newMessage('25');
$this->_addFixedOption($this->_datestamp(), 18);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AC',$this->AC, true);
$this->_addVarOption('AD',$this->patronpwd, true);
return $this->_returnMessage();
}
/**
* Generate Hold (code 15) request messages in sip2 format
* @param string $mode value for the mode portion of the fixed length field
* @param string $expDate value for the optional variable length BW field
* @param string $holdtype value for the optional variable length BY field
* @param string $item value for the optional variable length AB field
* @param string $title value for the optional variable length AJ field
* @param string $fee value for the optional variable length BO field
* @param string $pkupLocation value for the optional variable length BS field
* @return string|false SIP2 request message or false on error
* @api
*/
function msgHold($mode, $expDate = '', $holdtype = '', $item = '', $title = '', $fee='N', $pkupLocation = '')
{
/* mode validity check */
/*
* - remove hold
* + place hold
* * modify hold
*/
if (strpos('-+*',$mode) === false) {
/* not a valid mode - exit */
$this->_debugmsg( $this->version.": Invalid hold mode: {$mode}");
return false;
}
if ($holdtype != '' && ($holdtype < 1 || $holdtype > 9)) {
/*
* Valid hold types range from 1 - 9
* 1 other
* 2 any copy of title
* 3 specific copy
* 4 any copy at a single branch or location
*/
$this->_debugmsg( $this->version.": Invalid hold type code: {$holdtype}");
return false;
}
$this->_newMessage('15');
$this->_addFixedOption($mode, 1);
$this->_addFixedOption($this->_datestamp(), 18);
if ($expDate != '') {
/* hold expiration date, due to the use of the datestamp function, we have to check here for empty value. when datestamp is passed an empty value it will generate a current datestamp */
$this->_addVarOption('BW', $this->_datestamp($expDate), true); /*spec says this is fixed field, but it behaves like a var field and is optional... */
}
$this->_addVarOption('BS',$pkupLocation, true);
$this->_addVarOption('BY',$holdtype, true);
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AD',$this->patronpwd, true);
$this->_addVarOption('AB',$item, true);
$this->_addVarOption('AJ',$title, true);
$this->_addVarOption('AC',$this->AC, true);
$this->_addVarOption('BO',$fee, true); /* Y when user has agreed to a fee notice */
return $this->_returnMessage();
}
/**
* Generate Renew (code 29) request messages in sip2 format
* @param string $item value for the variable length optional AB field
* @param string $title value for the variable length optional AJ field
* @param string $nbDateDue value for the due date portion of the fixed length field
* @param string $itmProp value for the variable length optional CH field
* @param string $fee value for the variable length optional BO field
* @param string $noBlock value for the blocking portion of the fixed length field
* @param string $thirdParty value for the party section of the fixed length field
* @return string SIP2 request message
* @api
*/
function msgRenew($item = '', $title = '', $nbDateDue = '', $itmProp = '', $fee= 'N', $noBlock = 'N', $thirdParty = 'N')
{
/* renew a single item (29) - untested */
$this->_newMessage('29');
$this->_addFixedOption($thirdParty, 1);
$this->_addFixedOption($noBlock, 1);
$this->_addFixedOption($this->_datestamp(), 18);
if ($nbDateDue != '') {
/* override default date due */
$this->_addFixedOption($this->_datestamp($nbDateDue), 18);
} else {
/* send a blank date due to allow ACS to use default date due computed for item */
$this->_addFixedOption('', 18);
}
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AD',$this->patronpwd, true);
$this->_addVarOption('AB',$item, true);
$this->_addVarOption('AJ',$title, true);
$this->_addVarOption('AC',$this->AC, true);
$this->_addVarOption('CH',$itmProp, true);
$this->_addVarOption('BO',$fee, true); /* Y or N */
return $this->_returnMessage();
}
/**
* Generate Renew All (code 65) request messages in sip2 format
* @param string $fee value for the optional variable length BO field
* @return string SIP2 request message
* @api
*/
function msgRenewAll($fee = 'N')
{
/* renew all items for a patron (65) - untested */
$this->_newMessage('65');
$this->_addVarOption('AO',$this->AO);
$this->_addVarOption('AA',$this->patron);
$this->_addVarOption('AD',$this->patronpwd, true);
$this->_addVarOption('AC',$this->AC, true);
$this->_addVarOption('BO',$fee, true); /* Y or N */
return $this->_returnMessage();
}
/**
* Parse the response returned from Patron Status request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parsePatronStatusResponse($response)
{
$result['fixed'] =
array(
'PatronStatus' => substr($response, 2, 14),
'Language' => substr($response, 16, 3),
'TransactionDate' => substr($response, 19, 18),
);
$result['variable'] = $this->_parsevariabledata($response, 37);
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from Checkout request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parseCheckoutResponse($response)
{
$result['fixed'] =
array(
'Ok' => substr($response,2,1),
'RenewalOk' => substr($response,3,1),
'Magnetic' => substr($response,4,1),
'Desensitize' => substr($response,5,1),
'TransactionDate' => substr($response,6,18),
);
$result['variable'] = $this->_parsevariabledata($response, 24);
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from Checkin request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parseCheckinResponse($response)
{
$result['fixed'] =
array(
'Ok' => substr($response,2,1),
'Resensitize' => substr($response,3,1),
'Magnetic' => substr($response,4,1),
'Alert' => substr($response,5,1),
'TransactionDate' => substr($response,6,18),
);
$result['variable'] = $this->_parsevariabledata($response, 24);
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from SC Status request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parseACSStatusResponse($response)
{
$result['fixed'] =
array(
'Online' => substr($response, 2, 1),
'Checkin' => substr($response, 3, 1), /* is Checkin by the SC allowed ?*/
'Checkout' => substr($response, 4, 1), /* is Checkout by the SC allowed ?*/
'Renewal' => substr($response, 5, 1), /* renewal allowed? */
'PatronUpdate' => substr($response, 6, 1), /* is patron status updating by the SC allowed ? (status update ok)*/
'Offline' => substr($response, 7, 1),
'Timeout' => substr($response, 8, 3),
'Retries' => substr($response, 11, 3),
'TransactionDate' => substr($response, 14, 18),
'Protocol' => substr($response, 32, 4),
);
$result['variable'] = $this->_parsevariabledata($response, 36);
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from login request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parseLoginResponse($response)
{
$result['fixed'] =
array(
'Ok' => substr($response, 2, 1),
);
$result['variable'] = array();
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from Patron Information request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parsePatronInfoResponse($response)
{
$result['fixed'] =
array(
'PatronStatus' => substr($response, 2, 14),
'Language' => substr($response, 16, 3),
'TransactionDate' => substr($response, 19, 18),
'HoldCount' => intval (substr($response, 37, 4)),
'OverdueCount' => intval (substr($response, 41, 4)),
'ChargedCount' => intval (substr($response, 45, 4)),
'FineCount' => intval (substr($response, 49, 4)),
'RecallCount' => intval (substr($response, 53, 4)),
'UnavailableCount' => intval (substr($response, 57, 4))
);
$result['variable'] = $this->_parsevariabledata($response, 61);
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from End Session request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parseEndSessionResponse($response)
{
/* Response example: 36Y20080228 145537AOWOHLERS|AAX00000000|AY9AZF474 */
$result['fixed'] =
array(
'EndSession' => substr($response, 2, 1),
'TransactionDate' => substr($response, 3, 18),
);
$result['variable'] = $this->_parsevariabledata($response, 21);
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from Fee Paid request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parseFeePaidResponse($response)
{
$result['fixed'] =
array(
'PaymentAccepted' => substr($response, 2, 1),
'TransactionDate' => substr($response, 3, 18),
);
$result['variable'] = $this->_parsevariabledata($response, 21);
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from Item Info request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parseItemInfoResponse($response)
{
$result['fixed'] =
array(
'CirculationStatus' => intval (substr($response, 2, 2)),
'SecurityMarker' => intval (substr($response, 4, 2)),
'FeeType' => intval (substr($response, 6, 2)),
'TransactionDate' => substr($response, 8, 18),
);
$result['variable'] = $this->_parsevariabledata($response, 26);
$this->last_response_parsed = $result;
return $result;
}
/**
* Parse the response returned from Item Status request messages
* @param string $response response string from the SIP2 backend
* @return array parsed SIP2 response message
* @api
*/
function parseItemStatusResponse($response)
{
$result['fixed'] =
array(
'PropertiesOk' => substr($response, 2, 1),
'TransactionDate' => substr($response, 3, 18),
);
$result['variable'] = $this->_parsevariabledata($response, 21);
$this->last_response_parsed = $result;