hpdl
|
175
|
1
|
<?php
|
|
2
|
/*
|
|
3
|
$Id: address_book.php 166 2005-08-05 10:14:21 +0200 (Fr, 05 Aug 2005) hpdl $
|
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
|
8
|
Copyright (c) 2005 osCommerce
|
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
|
13
|
class osC_AddressBook {
|
|
14
|
|
|
15
|
function &getListing() {
|
|
16
|
global $osC_Database, $osC_Customer;
|
|
17
|
|
|
18
|
$Qaddresses = $osC_Database->query('select address_book_id, entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from :table_address_book where customers_id = :customers_id order by firstname, lastname');
|
|
19
|
$Qaddresses->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
|
20
|
$Qaddresses->bindInt(':customers_id', $osC_Customer->id);
|
|
21
|
$Qaddresses->execute();
|
|
22
|
|
|
23
|
return $Qaddresses;
|
|
24
|
}
|
|
25
|
|
|
26
|
function &getEntry($id) {
|
|
27
|
global $osC_Database, $osC_Customer;
|
|
28
|
|
|
29
|
$Qentry = $osC_Database->query('select entry_gender, entry_company, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_zone_id, entry_country_id, entry_telephone, entry_fax from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
|
|
30
|
$Qentry->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
|
31
|
$Qentry->bindInt(':address_book_id', $id);
|
|
32
|
$Qentry->bindInt(':customers_id', $osC_Customer->id);
|
|
33
|
$Qentry->execute();
|
|
34
|
|
|
35
|
return $Qentry;
|
|
36
|
}
|
|
37
|
|
|
38
|
function checkEntry($id) {
|
|
39
|
global $osC_Database, $osC_Customer;
|
|
40
|
|
|
41
|
$Qentry = $osC_Database->query('select address_book_id from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
|
|
42
|
$Qentry->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
|
43
|
$Qentry->bindInt(':address_book_id', $id);
|
|
44
|
$Qentry->bindInt(':customers_id', $osC_Customer->id);
|
|
45
|
$Qentry->execute();
|
|
46
|
|
|
47
|
if ($Qentry->numberOfRows() === 1) {
|
|
48
|
return true;
|
|
49
|
}
|
|
50
|
|
|
51
|
return false;
|
|
52
|
}
|
|
53
|
|
|
54
|
function numberOfEntries() {
|
|
55
|
global $osC_Database, $osC_Customer;
|
|
56
|
static $total_entries = 0;
|
|
57
|
|
|
58
|
if ($total_entries === 0) {
|
|
59
|
$Qaddresses = $osC_Database->query('select count(*) as total from :table_address_book where customers_id = :customers_id');
|
|
60
|
$Qaddresses->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
|
61
|
$Qaddresses->bindInt(':customers_id', $osC_Customer->id);
|
|
62
|
$Qaddresses->execute();
|
|
63
|
|
|
64
|
$total_entries = $Qaddresses->valueInt('total');
|
|
65
|
}
|
|
66
|
|
|
67
|
return $total_entries;
|
|
68
|
}
|
|
69
|
|
|
70
|
function saveEntry($data, $id = '') {
|
|
71
|
global $osC_Database, $osC_Customer;
|
|
72
|
|
|
73
|
$updated_record = false;
|
|
74
|
|
|
75
|
if (is_numeric($id)) {
|
|
76
|
$Qab = $osC_Database->query('update :table_address_book set customers_id = :customers_id, entry_gender = :entry_gender, entry_company = :entry_company, entry_firstname = :entry_firstname, entry_lastname = :entry_lastname, entry_street_address = :entry_street_address, entry_suburb = :entry_suburb, entry_postcode = :entry_postcode, entry_city = :entry_city, entry_state = :entry_state, entry_country_id = :entry_country_id, entry_zone_id = :entry_zone_id, entry_telephone = :entry_telephone, entry_fax = :entry_fax where address_book_id = :address_book_id and customers_id = :customers_id');
|
|
77
|
$Qab->bindInt(':address_book_id', $id);
|
|
78
|
$Qab->bindInt(':customers_id', $osC_Customer->id);
|
|
79
|
} else {
|
|
80
|
$Qab = $osC_Database->query('insert into :table_address_book (customers_id, entry_gender, entry_company, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_country_id, entry_zone_id, entry_telephone, entry_fax) values (:customers_id, :entry_gender, :entry_company, :entry_firstname, :entry_lastname, :entry_street_address, :entry_suburb, :entry_postcode, :entry_city, :entry_state, :entry_country_id, :entry_zone_id, :entry_telephone, :entry_fax)');
|
|
81
|
}
|
|
82
|
$Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
|
83
|
$Qab->bindInt(':customers_id', $osC_Customer->id);
|
|
84
|
$Qab->bindValue(':entry_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : '');
|
|
85
|
$Qab->bindValue(':entry_company', (ACCOUNT_COMPANY > -1) ? $data['company'] : '');
|
|
86
|
$Qab->bindValue(':entry_firstname', $data['firstname']);
|
|
87
|
$Qab->bindValue(':entry_lastname', $data['lastname']);
|
|
88
|
$Qab->bindValue(':entry_street_address', $data['street_address']);
|
|
89
|
$Qab->bindValue(':entry_suburb', (ACCOUNT_SUBURB > -1) ? $data['suburb'] : '');
|
|
90
|
$Qab->bindValue(':entry_postcode', $data['postcode']);
|
|
91
|
$Qab->bindValue(':entry_city', $data['city']);
|
|
92
|
$Qab->bindValue(':entry_state', (ACCOUNT_STATE > -1) ? ((isset($data['zone_id']) && ($data['zone_id'] > 0)) ? '' : $data['state']) : '');
|
|
93
|
$Qab->bindInt(':entry_country_id', $data['country']);
|
|
94
|
$Qab->bindInt(':entry_zone_id', (ACCOUNT_STATE > -1) ? ((isset($data['zone_id']) && ($data['zone_id'] > 0)) ? $data['zone_id'] : 0) : '');
|
|
95
|
$Qab->bindValue(':entry_telephone', (ACCOUNT_TELEPHONE > -1) ? $data['telephone'] : '');
|
|
96
|
$Qab->bindValue(':entry_fax', (ACCOUNT_FAX > -1) ? $data['fax'] : '');
|
|
97
|
$Qab->execute();
|
|
98
|
|
|
99
|
if ($Qab->affectedRows() === 1) {
|
|
100
|
$updated_record = true;
|
|
101
|
}
|
|
102
|
|
|
103
|
if (isset($data['primary']) && ($data['primary'] === true)) {
|
|
104
|
if (is_numeric($id) === false) {
|
|
105
|
$id = $osC_Database->nextID();
|
|
106
|
}
|
|
107
|
|
|
108
|
if (osC_AddressBook::setPrimaryAddress($id)) {
|
|
109
|
$osC_Customer->setCountryID($data['country']);
|
|
110
|
$osC_Customer->setZoneID(($data['zone_id'] > 0) ? (int)$data['zone_id'] : '0');
|
|
111
|
$osC_Customer->setDefaultAddressID($id);
|
|
112
|
|
|
113
|
if ($updated_record === false) {
|
|
114
|
$updated_record = true;
|
|
115
|
}
|
|
116
|
}
|
|
117
|
}
|
|
118
|
|
|
119
|
if ($updated_record === true) {
|
|
120
|
return true;
|
|
121
|
}
|
|
122
|
|
|
123
|
return false;
|
|
124
|
}
|
|
125
|
|
|
126
|
function setPrimaryAddress($id) {
|
|
127
|
global $osC_Database, $osC_Customer;
|
|
128
|
|
|
129
|
if (is_numeric($id) && ($id > 0)) {
|
|
130
|
$Qupdate = $osC_Database->query('update :table_customers set customers_default_address_id = :customers_default_address_id where customers_id = :customers_id');
|
|
131
|
$Qupdate->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
132
|
$Qupdate->bindInt(':customers_default_address_id', $id);
|
|
133
|
$Qupdate->bindInt(':customers_id', $osC_Customer->id);
|
|
134
|
$Qupdate->execute();
|
|
135
|
|
|
136
|
if ($Qupdate->affectedRows() === 1) {
|
|
137
|
return true;
|
|
138
|
}
|
|
139
|
}
|
|
140
|
|
|
141
|
return false;
|
|
142
|
}
|
|
143
|
|
|
144
|
function deleteEntry($id) {
|
|
145
|
global $osC_Database, $osC_Customer;
|
|
146
|
|
|
147
|
$Qdelete = $osC_Database->query('delete from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
|
|
148
|
$Qdelete->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
|
149
|
$Qdelete->bindInt(':address_book_id', $id);
|
|
150
|
$Qdelete->bindInt(':customers_id', $osC_Customer->id);
|
|
151
|
$Qdelete->execute();
|
|
152
|
|
|
153
|
if ($Qdelete->affectedRows() === 1) {
|
|
154
|
return true;
|
|
155
|
}
|
|
156
|
|
|
157
|
return false;
|
|
158
|
}
|
|
159
|
}
|
|
160
|
?>
|