Quick Search:

View

Revision:

Diff

Diff from 1422 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/address_book.php

Annotated File View

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
hpdl
829
18       $Qaddresses = $osC_Database->query('select ab.address_book_id, ab.entry_firstname as firstname, ab.entry_lastname as lastname, ab.entry_company as company, ab.entry_street_address as street_address, ab.entry_suburb as suburb, ab.entry_city as city, ab.entry_postcode as postcode, ab.entry_state as state, ab.entry_zone_id as zone_id, ab.entry_country_id as country_id, z.zone_code as zone_code, c.countries_name as country_title from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id), :table_countries c where ab.customers_id = :customers_id and ab.entry_country_id = c.countries_id order by ab.entry_firstname, ab.entry_lastname');
hpdl
175
19       $Qaddresses->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
hpdl
829
20       $Qaddresses->bindTable(':table_zones', TABLE_ZONES);
21       $Qaddresses->bindTable(':table_countries', TABLE_COUNTRIES);
hpdl
184
22       $Qaddresses->bindInt(':customers_id', $osC_Customer->getID());
hpdl
175
23       $Qaddresses->execute();
24
25       return $Qaddresses;
26     }
27
28     function &getEntry($id) {
29       global $osC_Database, $osC_Customer;
30
31       $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');
32       $Qentry->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
33       $Qentry->bindInt(':address_book_id', $id);
hpdl
184
34       $Qentry->bindInt(':customers_id', $osC_Customer->getID());
hpdl
175
35       $Qentry->execute();
36
37       return $Qentry;
38     }
39
40     function checkEntry($id) {
41       global $osC_Database, $osC_Customer;
42
43       $Qentry = $osC_Database->query('select address_book_id from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
44       $Qentry->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
45       $Qentry->bindInt(':address_book_id', $id);
hpdl
184
46       $Qentry->bindInt(':customers_id', $osC_Customer->getID());
hpdl
175
47       $Qentry->execute();
48
49       if ($Qentry->numberOfRows() === 1) {
50         return true;
51       }
52
53       return false;
54     }
55
56     function numberOfEntries() {
57       global $osC_Database, $osC_Customer;
hpdl
1422
58
hpdl
183
59       static $total_entries;
hpdl
175
60
hpdl
1422
61       if ( !is_numeric($total_entries) ) {
hpdl
175
62         $Qaddresses = $osC_Database->query('select count(*) as total from :table_address_book where customers_id = :customers_id');
63         $Qaddresses->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
hpdl
184
64         $Qaddresses->bindInt(':customers_id', $osC_Customer->getID());
hpdl
175
65         $Qaddresses->execute();
66
67         $total_entries = $Qaddresses->valueInt('total');
68       }
69
70       return $total_entries;
71     }
72
73     function saveEntry($data, $id = '') {
74       global $osC_Database, $osC_Customer;
75
76       $updated_record = false;
77
78       if (is_numeric($id)) {
79         $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');
80         $Qab->bindInt(':address_book_id', $id);
hpdl
184
81         $Qab->bindInt(':customers_id', $osC_Customer->getID());
hpdl
175
82       } else {
83         $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)');
84       }
85       $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
hpdl
184
86       $Qab->bindInt(':customers_id', $osC_Customer->getID());
hpdl
175
87       $Qab->bindValue(':entry_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : '');
88       $Qab->bindValue(':entry_company', (ACCOUNT_COMPANY > -1) ? $data['company'] : '');
89       $Qab->bindValue(':entry_firstname', $data['firstname']);
90       $Qab->bindValue(':entry_lastname', $data['lastname']);
91       $Qab->bindValue(':entry_street_address', $data['street_address']);
92       $Qab->bindValue(':entry_suburb', (ACCOUNT_SUBURB > -1) ? $data['suburb'] : '');
hpdl
778
93       $Qab->bindValue(':entry_postcode', (ACCOUNT_POST_CODE > -1) ? $data['postcode'] : '');
hpdl
175
94       $Qab->bindValue(':entry_city', $data['city']);
95       $Qab->bindValue(':entry_state', (ACCOUNT_STATE > -1) ? ((isset($data['zone_id']) && ($data['zone_id'] > 0)) ? '' : $data['state']) : '');
96       $Qab->bindInt(':entry_country_id', $data['country']);
97       $Qab->bindInt(':entry_zone_id', (ACCOUNT_STATE > -1) ? ((isset($data['zone_id']) && ($data['zone_id'] > 0)) ? $data['zone_id'] : 0) : '');
98       $Qab->bindValue(':entry_telephone', (ACCOUNT_TELEPHONE > -1) ? $data['telephone'] : '');
99       $Qab->bindValue(':entry_fax', (ACCOUNT_FAX > -1) ? $data['fax'] : '');
100       $Qab->execute();
101
102       if ($Qab->affectedRows() === 1) {
103         $updated_record = true;
104       }
105
106       if (isset($data['primary']) && ($data['primary'] === true)) {
107         if (is_numeric($id) === false) {
108           $id = $osC_Database->nextID();
109         }
110
111         if (osC_AddressBook::setPrimaryAddress($id)) {
112           $osC_Customer->setCountryID($data['country']);
113           $osC_Customer->setZoneID(($data['zone_id'] > 0) ? (int)$data['zone_id'] : '0');
114           $osC_Customer->setDefaultAddressID($id);
115
116           if ($updated_record === false) {
117             $updated_record = true;
118           }
119         }
120       }
121
122       if ($updated_record === true) {
123         return true;
124       }
125
126       return false;
127     }
128
129     function setPrimaryAddress($id) {
130       global $osC_Database, $osC_Customer;
131
132       if (is_numeric($id) && ($id > 0)) {
133         $Qupdate = $osC_Database->query('update :table_customers set customers_default_address_id = :customers_default_address_id where customers_id = :customers_id');
134         $Qupdate->bindTable(':table_customers', TABLE_CUSTOMERS);
135         $Qupdate->bindInt(':customers_default_address_id', $id);
hpdl
184
136         $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
hpdl
175
137         $Qupdate->execute();
138
139         if ($Qupdate->affectedRows() === 1) {
140           return true;
141         }
142       }
143
144       return false;
145     }
146
147     function deleteEntry($id) {
148       global $osC_Database, $osC_Customer;
149
150       $Qdelete = $osC_Database->query('delete from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
151       $Qdelete->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
152       $Qdelete->bindInt(':address_book_id', $id);
hpdl
184
153       $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
hpdl
175
154       $Qdelete->execute();
155
156       if ($Qdelete->affectedRows() === 1) {
157         return true;
158       }
159
160       return false;
161     }
162   }
163 ?>