Quick Search:

View

Revision:

Diff

Diff from 1498 to:

Annotations

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