Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r6272]: trunk / web / Drivers / Horizon.php Maximize Restore History

Download this file

Horizon.php    1117 lines (1010 with data), 38.3 kB

   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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
<?php
/**
* Horizon ILS Driver
*
* PHP version 5
*
* Copyright (C) Villanova University 2007.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind
* @package ILS_Drivers
* @author Matt Mackey <vufind-tech@lists.sourceforge.net>
* @author Ray Cummins <vufind-tech@lists.sourceforge.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/building_an_ils_driver Wiki
*/
require_once 'Interface.php';
require_once 'sys/VuFindDate.php';
/**
* Horizon ILS Driver
*
* @category VuFind
* @package ILS_Drivers
* @author Matt Mackey <vufind-tech@lists.sourceforge.net>
* @author Ray Cummins <vufind-tech@lists.sourceforge.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/building_an_ils_driver Wiki
*/
class Horizon implements DriverInterface
{
private $_db;
protected $config;
protected $dateFormat;
/**
* Constructor
*
* @param string $configFile An alternative config file name
*
* @access public
*/
public function __construct($configFile = false)
{
if (!$configFile) {
$configFile = "Horizon.ini";
}
// Load Configuration for this Module
$this->config = parse_ini_file(
dirname(__FILE__) . '/../conf/' . $configFile, true
);
// Connect to database
$this->_db = mssql_pconnect(
$this->config['Catalog']['host'] . ':'
. $this->config['Catalog']['port'],
$this->config['Catalog']['username'],
$this->config['Catalog']['password']
);
// Select the databse
mssql_select_db($this->config['Catalog']['database']);
// Set up object for formatting dates and times:
$this->dateFormat = new VuFindDate();
}
/**
* Protected support method for building sql strings.
*
* @param array $sql An array of keyed sql data
*
* @return array An string query string
* @access protected
*/
protected function buildSqlFromArray($sql)
{
$modifier = isset($sql['modifier']) ? $sql['modifier'] . " " : "";
// Put String Together
$sqlString = "select ". $modifier . implode(", ", $sql['expressions']);
$sqlString .= " from " .implode(", ", $sql['from']);
$sqlString .= (!empty($sql['join']))
? " join " .implode(" join ", $sql['join']) : "";
$sqlString .= (!empty($sql['innerJoin']))
? " inner join " .implode(" inner join ", $sql['innerJoin']) : "";
$sqlString .= (!empty($sql['leftOuterJoin']))
? " left outer join "
. implode(" left outer join ", $sql['leftOuterJoin'])
: "";
$sqlString .= " where " .implode(" AND ", $sql['where']);
$sqlString .= (!empty($sql['order']))
? " ORDER BY " .implode(", ", $sql['order']) : "";
return $sqlString;
}
/**
* Protected support method determine availability, reserve and duedate values
* based on item status. Used by getHolding, getStatus and getStatuses.
*
* @param string $status Item status code
*
* @return array
*
*/
protected function parseStatus($status)
{
$statuses = isset($this->config['Statuses'][$item_status])
? $this->config['Statuses'][$item_status] : null;
// query the config file for the item status if there are
// config values, use the configuration otherwise execute the switch
if (!$statuses == null) {
// break out the values
$arrayValues = array_map('strtolower', explode(',', $statuses));
//set the variables based on what we find in the config file
if (in_array(strtolower('available:1'), $arrayValues)) {
$available = 1;
}
if (in_array(strtolower('available:0'), $arrayValues)) {
$available = 0;
}
if (in_array(strtolower('reserve:N'), $arrayValues)) {
$reserve = 'N';
}
if (in_array(strtolower('reserve:Y'), $arrayValues)) {
$reserve = 'Y';
}
if (in_array(strtolower('duedate:0'), $arrayValues)) {
$duedate = '';
}
} else {
switch ($status) {
case 'i': // checked in
$available = 1;
$reserve = 'N';
break;
case 'rb': // Reserve Bookroom
$available = 0;
$reserve = 'Y';
break;
case 'h': // being held
$available = 0;
$reserve = 'N';
break;
case 'l': // lost
$available = 0;
$reserve = 'N';
$duedate = ''; // No due date for lost items
break;
case 'm': // missing
$available = 0;
$reserve = 'N';
$duedate = ''; // No due date for missing items
break;
default:
$available = 0;
$reserve = 'N';
break;
}
}
$statusValues = array('available' => $available,
'reserve' => $reserve);
if (isset($duedate)) {
$statusValues += array('duedate' => $duedate);
}
return $statusValues;
}
/**
* Protected support method for getHolding.
*
* @param array $id A Bibliographic id
*
* @return array Keyed data for use in an sql query
* @access protected
*/
protected function getHoldingSQL($id)
{
// Query holding information based on id field defined in
// import/marc.properties
// Expressions
$sqlExpressions = array(
"i.item# as ITEM_ID",
"i.item_status as STATUS_CODE",
"ist.descr as STATUS",
"l.name as LOCATION",
"i.call_reconstructed as CALLNUMBER",
"i.ibarcode as ITEM_BARCODE",
"convert(varchar(10), " .
" dateadd(dd,i.due_date,'jan 1 1970'), " .
" 101) as DUEDATE",
"i.copy_reconstructed as NUMBER",
"convert(varchar(10), " .
" dateadd(dd,ch.cki_date,'jan 1 1970'), " .
" 101) as RETURNDATE",
"(select count(*)
from request r
where r.bib# = i.bib#
and r.reactivate_date = NULL) as REQUEST",
"i.notes as NOTES",
"ist.available_for_request IS_HOLDABLE",
);
// From
$sqlFrom = array("item i");
// inner Join
$sqlInnerJoin = array(
"item_status ist on i.item_status = ist.item_status",
"location l on i.location = l.location",
);
$sqlLeftOuterJoin = array(
"circ_history ch on ch.item# = i.item#"
);
// Where
$sqlWhere = array(
"i.bib# = " . addslashes($id),
"i.staff_only = 0"
);
$sqlArray = array(
'expressions' => $sqlExpressions,
'from' => $sqlFrom,
'innerJoin' => $sqlInnerJoin,
'leftOuterJoin' => $sqlLeftOuterJoin,
'where' => $sqlWhere
);
return $sqlArray;
}
/**
* Protected support method for getHolding.
*
* @param string $id Bib Id
* @param array $row SQL Row Data
* @param array $patron Patron Array
*
* @return array Keyed data
* @access protected
*/
protected function processHoldingRow($id, $row, $patron)
{
$duedate = $row['DUEDATE'];
$item_status = $row['STATUS_CODE']; //get the item status code
$statusValues = $this->parseStatus($item_status);
if (isset($statusValues['duedate'])) {
$duedate = $statusValues['duedate'];
}
$holding = array(
'id' => $id,
'availability' => $statusValues['available'],
'item_id' => $row['ITEM_ID'],
'status' => $row['STATUS'],
'location' => $row['LOCATION'],
'reserve' => $statusValues['reserve'],
'callnumber' => $row['CALLNUMBER'],
'duedate' => $duedate,
'returnDate' => $row['RETURNDATE'],
'barcode' => $row['ITEM_BARCODE'],
'requests_placed' => $row['REQUEST'],
'is_holdable' => $row['IS_HOLDABLE'],
);
// Only set the number key if there is actually volume data
if ($row['NUMBER'] != '') {
$holding += array('number' => $row['NUMBER']);
}
// Only set the notes key if there are actually notes to display
if ($row['NOTES'] != '') {
$holding += array('notes' => array($row['NOTES']));
}
return $holding;
}
/**
* Get Holding
*
* This is responsible for retrieving the holding information of a certain
* record.
*
* @param string $id The record id to retrieve the holdings for
* @param array $patron Patron data
*
* @return mixed On success, an associative array with the following keys:
* id, availability (boolean), status, location, reserve, callnumber, duedate,
* number, barcode; on failure, a PEAR_Error.
* @access public
*/
public function getHolding($id, $patron = false)
{
$sqlArray = $this->getHoldingSql($id);
$sql = $this->buildSqlFromArray($sqlArray);
try {
$holding = array();
$sqlStmt = mssql_query($sql);
while ($row = mssql_fetch_assoc($sqlStmt)) {
$holding[] = $this->processHoldingRow($id, $row, $patron);
}
return $holding;
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
}
/**
* Protected support method for getStatuses.
*
* @param string $id Bib Id
* @param array $row SQL Row Data
*
* @return array Keyed data
*/
protected function processStatusRow($id, $row)
{
$item_status = $row['STATUS_CODE']; //get the item status code
$statusValues = $this->parseStatus($item_status);
$status = array('id' => $id,
'availability' => $statusValues['available'],
'status' => $row['STATUS'],
'location' => $row['LOCATION'],
'reserve' => $statusValues['reserve'],
'callnumber' => $row['CALLNUMBER']);
return $status;
}
/**
* Get Status
*
* This is responsible for retrieving the status information of a specific
* record. It is a proxy to getStatuses.
*
* @param string $id The record id to retrieve the holdings for
*
* @return mixed On success, an associative array with the following keys:
* id, availability (boolean), status, location, reserve, callnumber; on
* failure, a PEAR_Error.
* @access public
*/
public function getStatus($id)
{
$idList = array($id);
$status = $this->getStatuses($idList);
return current($status);
}
/**
* Protected support method for getStatus.
*
* @param array $idList A list of Bibliographic id
*
* @return array Keyed data for use in an sql query
*/
protected function getStatusesSQL($idList)
{
// Query holding information based on id field defined in
// import/marc.properties
// Expressions
$sqlExpressions = array("i.bib# as ID",
"i.item_status as STATUS_CODE",
"ist.descr as STATUS",
"l.name as LOCATION",
"i.call_reconstructed as CALLNUMBER");
// From
$sqlFrom = array("item i");
// inner Join
$sqlInnerJoin = array("item_status ist on i.item_status = ist.item_status",
"location l on i.location = l.location");
$bibIDs = implode(',', $idList);
// Where
$sqlWhere = array("i.bib# in (" .$bibIDs . ")",
"i.staff_only = 0");
$sqlArray = array('expressions' => $sqlExpressions,
'from' => $sqlFrom,
'innerJoin' => $sqlInnerJoin,
'where' => $sqlWhere);
return $sqlArray;
}
/**
* Get Statuses
*
* This is responsible for retrieving the status information for a collection of
* records.
*
* @param array $idList The array of record ids to retrieve the status for
*
* @return mixed An array of getStatus() return values on success,
* a PEAR_Error object otherwise.
* @access public
*/
public function getStatuses($idList)
{
$sqlArray = $this->getStatusesSQL($idList);
$sql = $this->buildSqlFromArray($sqlArray);
try {
$status = array();
$sqlStmt = mssql_query($sql);
while ($row = mssql_fetch_assoc($sqlStmt)) {
$id = $row['ID'];
$status[$id][] = $this->processStatusRow($id, $row);
}
return $status;
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
}
/**
* Get Purchase History
*
* This is responsible for retrieving the acquisitions history data for the
* specific record (usually recently received issues of a serial).
*
* @param string $id The record id to retrieve the info for
*
* @return mixed An array with the acquisitions data on success, PEAR_Error
* on failure
* @access public
*/
public function getPurchaseHistory($id)
{
return array();
}
/**
* Patron Login
*
* This is responsible for authenticating a patron against the catalog.
*
* @param string $username The patron username
* @param string $password The patron password
*
* @return mixed Associative array of patron info on successful login,
* null on unsuccessful login, PEAR_Error on error.
* @access public
*/
public function patronLogin($username, $password)
{
$sql = "select name_reconstructed as FULLNAME, " .
"email_address as EMAIL from borrower " .
"left outer join borrower_address on " .
"borrower_address.borrower#=borrower.borrower# " .
"inner join borrower_barcode on " .
"borrower.borrower#=borrower_barcode.borrower# " .
"where borrower_barcode.bbarcode=\"" . addslashes($username) .
"\" and pin# = \"" . addslashes($password) . "\"";
try {
$user = array();
$sqlStmt = mssql_query($sql);
$row = mssql_fetch_assoc($sqlStmt);
if ($row) {
list($lastname,$firstname)=explode(', ', $row['FULLNAME']);
$user = array('id' => $username,
'firstname' => $firstname,
'lastname' => $lastname,
'cat_username' => $username,
'cat_password' => $password,
'email' => $row['EMAIL'],
'major' => null,
'college' => null);
return $user;
} else {
return null;
}
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
}
/**
* Protected support method for getMyHolds.
*
* @param array $patron Patron data for use in an sql query
*
* @return array Keyed data for use in an sql query
* @access protected
*/
protected function getHoldsSQL($patron)
{
// Expressions
$sqlExpressions = array(
"r.bib# as BIB_NUM",
"r.request# as REQNUM",
"r.item# as ITEM_ID",
"r.bib_queue_ord as POSITION",
"l.name as LOCATION",
"r.request_status as STATUS",
"case when r.request_status = 1 " .
"then 0 " .
"else 1 " .
"end as SORT",
"t.processed as TITLE",
"p.pubdate as PUBLICATION_YEAR",
"i.volume as VOLUME",
"convert(varchar(12),dateadd(dd, r.hold_exp_date, '1 jan 1970')) " .
"as HOLD_EXPIRE",
"convert(varchar(12),dateadd(dd, r.expire_date, '1 jan 1970')) " .
"as REQUEST_EXPIRE",
"convert(varchar(12),dateadd(dd, r.request_date, '1 jan 1970')) " .
"as CREATED"
);
// From
$sqlFrom = array("request r");
// Join
$sqlJoin = array(
"borrower_barcode bb on bb.borrower# = r.borrower#",
"location l on l.location = r.pickup_location",
"title t on t.bib# = r.bib#"
);
$sqlLeftOuterJoin = array(
"item i on i.item# = r.item#",
"pubdate_inverted p on p.bib# = r.bib#"
);
// Where
$sqlWhere = array(
"bb.bbarcode=\"" . addslashes($patron['id']) .
"\""
);
$sqlOrder = array(
"SORT",
"t.processed"
);
$sqlArray = array(
'expressions' => $sqlExpressions,
'from' => $sqlFrom,
'join' => $sqlJoin,
'leftOuterJoin' => $sqlLeftOuterJoin,
'where' => $sqlWhere,
'order' => $sqlOrder
);
return $sqlArray;
}
/**
* Protected support method for getMyHolds.
*
* @param array $row An sql row
*
* @return array Keyed data
* @access protected
*/
protected function processHoldsRow($row)
{
if ($row['STATUS'] != 6) {
$position = ($row['STATUS'] != 1) ? $row['POSITION'] : false;
$available = ($row['STATUS'] == 1) ? true : false;
$expire = false;
$create = false;
// Convert Horizon Format to display format
if (!empty($row['HOLD_EXPIRE'])) {
$expire = $this->dateFormat->convertToDisplayDate(
"M d Y", trim($row['HOLD_EXPIRE'])
);
if (PEAR::isError($expire)) {
return $expire;
}
} elseif (!empty($row['REQUEST_EXPIRE'])) {
// If there is no Hold Expiration date fall back to the
// Request Expiration date.
$expire = $this->dateFormat->convertToDisplayDate(
"M d Y", trim($row['REQUEST_EXPIRE'])
);
if (PEAR::isError($expire)) {
return $expire;
}
} elseif ($row['STATUS']==2) {
// Items that are 'In Transit' have no expiration date.
$expire = 'In Transit';
} else {
// Just in case we missed a possible scenario
$expire = false;
}
if (!empty($row['CREATED'])) {
$create = $this->dateFormat->convertToDisplayDate(
"M d Y", trim($row['CREATED'])
);
if (PEAR::isError($create)) {
return $create;
}
}
return array(
'id' => $row['BIB_NUM'],
'location' => $row['LOCATION'],
'reqnum' => $row['REQNUM'],
'expire' => $expire,
'create' => $create,
'position' => $position,
'available' => $available,
'item_id' => $row['ITEM_ID'],
'volume' => $row['VOLUME'],
'publication_year' => $row['PUBLICATION_YEAR'],
'title' => $row['TITLE']
);
}
return false;
}
/**
* Get Patron Holds
*
* This is responsible for retrieving all holds by a specific patron.
*
* @param array $patron The patron array from patronLogin
*
* @return mixed Array of the patron's holds on success, PEAR_Error
* otherwise.
* @access public
*/
public function getMyHolds($patron)
{
$sqlArray = $this->getHoldsSQL($patron);
$sql = $this->buildSqlFromArray($sqlArray);
try {
$sqlStmt = mssql_query($sql);
while ($row = mssql_fetch_assoc($sqlStmt)) {
$hold = $this->processHoldsRow($row);
if ($hold) {
$holdList[] = $hold;
}
}
return $holdList;
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
}
/**
* Get Patron Fines
*
* This is responsible for retrieving all fines by a specific patron.
*
* @param array $patron The patron array from patronLogin
*
* @return mixed Array of the patron's fines on success, PEAR_Error
* otherwise.
* @access public
*/
public function getMyFines($patron)
{
$sql = " select bu.amount as AMOUNT " .
" , coalesce( " .
" convert(varchar(10), " .
" dateadd(dd, i.last_cko_date, '01jan70'), " .
" 101), " .
" convert(varchar(10), " .
" dateadd(dd, bu2.date, '01jan70'), " .
" 101)) as CHECKOUT " .
" , bl.descr as FINE " .
" , ( select sum(b2.amount) " .
" from burb b2 " .
" where b2.reference# = bu.reference# " .
" group by b2.reference#) as BALANCE " .
" , convert(varchar(10), " .
" dateadd(dd, bu.date, '01jan70'), " .
" 101) as CREATEDATE " .
" , coalesce( " .
" convert(varchar(10), " .
" dateadd(dd, i.due_date, '01jan70'), " .
" 101), " .
" convert(varchar(10), " .
" dateadd(dd, bu3.date, '01jan70'), " .
" 101)) as DUEDATE " .
" , i2.bib# as ID " .
" , coalesce (t.processed, bu4.comment) as TITLE " .
" , case when bl.amount_type = 0 " .
" then 0 " .
" else 1 " .
" end as FEEBLOCK " .
" from burb bu " .
" join block bl " .
" on bl.block = bu.block " .
" join borrower_barcode bb " .
" on bb.borrower# = bu.borrower# " .
"left join item i " .
" on i.item# = bu.item# " .
" and i.borrower# = bu.borrower# " .
"left join item i2 " .
" on i2.item# = bu.item# " .
"left join burb bu2 " .
" on bu2.reference# = bu.reference# " .
" and bu2.block = 'infocko' " .
"left join burb bu3 " .
" on bu3.reference# = bu.reference# " .
" and bu3.block = 'infodue' " .
"left join title t " .
" on t.bib# = i2.bib# " .
"left join burb bu4 " .
" on bu4.reference# = bu.reference# " .
" and bu4.ord = 0 " .
" and bu4.block in ('l', 'LostPro','fine','he') " .
" where bb.bbarcode = \"" . addslashes($patron['id']) . "\" " .
" and bu.ord = 0 " .
" and bl.pac_display = 1 " .
" order by FEEBLOCK desc " .
" , bu.item# " .
" , TITLE " .
" , bu.block " .
" , bu.date";
try {
$sqlStmt = mssql_query($sql);
while ($row = mssql_fetch_assoc($sqlStmt)) {
$fineList[] = array('amount' => $row['AMOUNT'],
'checkout' => $row['CHECKOUT'],
'fine' => $row['FINE'],
'balance' => $row['BALANCE'],
'createdate' => $row['CREATEDATE'],
'duedate' => $row['DUEDATE'],
'id' => $row['ID'],
'title' => $row['TITLE']);
}
return $fineList;
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
}
/**
* Get Patron Profile
*
* This is responsible for retrieving the profile for a specific patron.
*
* @param array $patron The patron array
*
* @return mixed Array of the patron's profile data on success,
* PEAR_Error otherwise.
* @access public
*/
public function getMyProfile($patron)
{
$sql = "select name_reconstructed as FULLNAME, address1 as ADDRESS1, " .
"city_st.descr as ADDRESS2, postal_code as ZIP, phone_no as PHONE " .
"from borrower " .
"left outer join borrower_phone on " .
"borrower_phone.borrower#=borrower.borrower# " .
"inner join borrower_address on " .
"borrower_address.borrower#=borrower.borrower# " .
"inner join city_st on city_st.city_st=borrower_address.city_st " .
"inner join borrower_barcode on " .
"borrower_barcode.borrower#=borrower.borrower# " .
"where borrower_barcode.bbarcode=\"" . addslashes($patron['id']) . "\"";
try {
$sqlStmt = mssql_query($sql);
$row = mssql_fetch_assoc($sqlStmt);
if ($row) {
list($lastname,$firstname)=explode(', ', $row['FULLNAME']);
$profile= array('lastname' => $lastname,
'firstname' => $firstname,
'address1' => $row['ADDRESS1'],
'address2' => $row['ADDRESS2'],
'zip' => $row['ZIP'],
'phone' => $row['PHONE'],
'group' => null);
return $profile;
} else {
return null;
}
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
}
/**
* Protected support method for getMyTransactions.
*
* @param array $patron Patron data for use in an sql query
*
* @return array Keyed data for use in an sql query
* @access protected
*/
protected function getTransactionSQL($patron)
{
// Expressions
$sqlExpressions = array(
"convert(varchar(12), dateadd(dd, i.due_date, '01 jan 1970')) " .
"as DUEDATE",
"i.bib# as BIB_NUM",
"i.ibarcode as ITEM_BARCODE",
"i.n_renewals as RENEW",
"r.bib_queue_ord as REQUEST",
"i.volume as VOLUME",
"p.pubdate as PUBLICATION_YEAR",
"t.processed as TITLE",
"i.item# as ITEM_NUM",
);
// From
$sqlFrom = array("circ c");
// Join
$sqlJoin = array(
"item i on i.item#=c.item#",
"borrower b on b.borrower# = c.borrower#",
"borrower_barcode bb on bb.borrower# = c.borrower#",
"title t on t.bib# = i.bib#",
);
// Left Outer Join
$sqlLeftOuterJoin = array(
"request r on r.item#=c.item#",
"pubdate_inverted p on p.bib# = i.bib#"
);
// Where
$sqlWhere = array(
"bb.bbarcode=\"" . addslashes($patron['id']) . "\"");
// Order by
$sqlOrder = array(
"i.due_date",
"t.processed"
);
$sqlArray = array(
'expressions' => $sqlExpressions,
'from' => $sqlFrom,
'join' => $sqlJoin,
'leftOuterJoin' => $sqlLeftOuterJoin,
'where' => $sqlWhere,
'order' => $sqlOrder
);
return $sqlArray;
}
/**
* Protected support method for getMyTransactions.
*
* @param array $row An array of keyed data
*
* @return array Keyed data for display by template files
* @access protected
*/
protected function processTransactionsRow($row)
{
$dueStatus = false;
// Convert Horizon Format to display format
if (!empty($row['DUEDATE'])) {
$dueDate = $this->dateFormat->convertToDisplayDate(
"M d Y", trim($row['DUEDATE'])
);
if (PEAR::isError($dueDate)) {
return $dueDate;
} else {
$now = time();
$dueTimeStamp = $this->dateFormat->convertFromDisplayDate(
"U", $dueDate
);
if (!PEAR::isError($dueTimeStamp)
&& is_numeric($dueTimeStamp)
) {
if ($now > $dueTimeStamp) {
$dueStatus = "overdue";
} else if ($now > $dueTimeStamp-(1*24*60*60)) {
$dueStatus = "due";
}
}
}
}
return array(
'id' => $row['BIB_NUM'],
'item_id' => $row['ITEM_NUM'],
'duedate' => $dueDate,
'barcode' => $row['ITEM_BARCODE'],
'renew' => $row['RENEW'],
'request' => $row['REQUEST'],
'dueStatus' => $dueStatus,
'volume' => $row['VOLUME'],
'publication_year' => $row['PUBLICATION_YEAR'],
'title' => $row['TITLE']
);
}
/**
* Get Patron Transactions
*
* This is responsible for retrieving all transactions (i.e. checked out items)
* by a specific patron.
*
* @param array $patron The patron array from patronLogin
*
* @return mixed Array of the patron's transactions on success,
* PEAR_Error otherwise.
* @access public
*/
public function getMyTransactions($patron)
{
$transList = array();
$sqlArray = $this->getTransactionSQL($patron);
$sql = $this->buildSqlFromArray($sqlArray);
try {
$sqlStmt = mssql_query($sql);
while ($row = mssql_fetch_assoc($sqlStmt)) {
$transList[] = $this->processTransactionsRow($row);
}
return $transList;
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
}
/**
* Get Funds
*
* Return a list of funds which may be used to limit the getNewItems list.
*
* @return array An associative array with key = fund ID, value = fund name.
* @access public
*/
public function getFunds()
{
return array();
}
/**
* Get New Items
*
* Retrieve the IDs of items recently added to the catalog.
*
* The logic in this function follows the pattern used for the "New Additions"
* functionality of the Horizon staff client. New Additions was delivered with
* Horizon 7.4 and requires setup. Follow instructions in the "Circulation Setup
* Guide". The minimum setup is to set the "Track First Availability" flag for
* each appropriate item status.
*
* @param int $page Not implemented in this driver - Sybase does not have SQL
* query paging functionality.
* @param int $limit The maximum number of results to retrieve
* @param int $daysOld The maximum age of records to retrieve in days (max. 30)
* @param int $fundId Not implemented in this driver - The contributing library
* does not use acquisitions.
*
* @return array Associative array with 'count' and 'results' keys
* @access public
*/
public function getNewItems($page, $limit, $daysOld, $fundId = null)
{
// This functionality first appeared in Horizon 7.4 - check our version
$hzVersionRequired = "7.4.0.0";
if ($this->checkHzVersion($hzVersionRequired)) {
// Set the Sybase or MSSQL rowcount limit
$limitsql = "set rowcount {$limit}";
// This is the actual query for IDs.
$newsql = " select nb.bib# "
. " from new_bib nb "
. " join bib_control bc "
. " on bc.bib# = nb.bib# "
. " and bc.staff_only = 0 "
. " where nb.date > "
. " datediff(dd, '01JAN1970', getdate()) - {$daysOld} "
. "order by nb.date desc ";
try {
$results = array();
// Set the rowcount limit before executing the query for IDs
mssql_query($limitsql);
// Actual query for IDs
$sqlStmt = mssql_query($newsql);
while ($row = mssql_fetch_assoc($sqlStmt)) {
$results[] = $row['bib#'];
}
$retVal = array('count' => count($results), 'results' => array());
foreach ($results as $result) {
$retVal['results'][] = array('id' => $result);
}
return $retVal;
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
} else {
return array('count' => 0, 'results' => array());
}
}
/**
* Check Horizon Version
*
* Check the Horizon version found in the matham table to make sure it is at
* least the required version.
*
* @param string $hzVersionRequired Minimum version required
*
* @return boolean True or False the required version is the same or higher.
* @access protected
*/
protected function checkHzVersion($hzVersionRequired)
{
$checkHzVersionSQL = "select database_revision from matham";
$versionResult = mssql_query($checkHzVersionSQL);
while ($row = mssql_fetch_assoc($versionResult)) {
$hzVersionFound = $row['database_revision'];
}
/* The Horizon database version is made up of 4 numbers seperated by periods.
* Explode the string and check each segment against the required version.
*/
$foundVersionParts = explode('.', $hzVersionFound);
$requiredVersionParts = explode('.', $hzVersionRequired);
$versionOK = true;
for ($i = 0; $i < count($foundVersionParts); $i++) {
$required = intval($requiredVersionParts[$i]);
$found = intval($foundVersionParts[$i]);
if ($found > $required) {
// If found is greater than required stop checking
break;
} elseif ($found < $required) {
/* If found is less than required set $versionOK false
* and stop checking
*/
$versionOK = false;
break;
}
}
return $versionOK;
}
/**
* Get suppressed records.
*
* Get a list of Horizon bib numbers that have the staff-only flag set.
*
* @return array ID numbers of suppressed records in the system.
*/
public function getSuppressedRecords()
{
$list = array();
$sql = "select bc.bib#" .
" from bib_control bc" .
" where bc.staff_only = 1";
try {
$sqlStmt = mssql_query($sql);
while ($row = mssql_fetch_assoc($sqlStmt)) {
$list[] = $row['bib#'];
}
} catch (PDOException $e) {
return new PEAR_Error($e->getMessage());
}
return $list;
}
}
?>