function saveEntry($data, $id = '') { global $osC_Database, $osC_Customer; $updated_record = false; if (is_numeric($id)) { $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'); $Qab->bindInt(':address_book_id', $id); $Qab->bindInt(':customers_id', $osC_Customer->getID()); } else { $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)'); } $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); $Qab->bindInt(':customers_id', $osC_Customer->getID()); $Qab->bindValue(':entry_gender', ACCOUNT_GENDER > -1 && isset($data['gender']) && ($data['gender'] == 'm' || $data['gender'] == 'f') ? $data['gender'] : ''); $Qab->bindValue(':entry_company', ACCOUNT_COMPANY > -1 ? $data['company'] : ''); $Qab->bindValue(':entry_firstname', $data['firstname']); $Qab->bindValue(':entry_lastname', $data['lastname']); $Qab->bindValue(':entry_street_address', $data['street_address']); $Qab->bindValue(':entry_suburb', ACCOUNT_SUBURB > -1 ? $data['suburb'] : ''); $Qab->bindValue(':entry_postcode', ACCOUNT_POST_CODE > -1 ? $data['postcode'] : ''); $Qab->bindValue(':entry_city', $data['city']); $Qab->bindValue(':entry_state', ACCOUNT_STATE > -1 ? isset($data['zone_id']) && $data['zone_id'] > 0 ? '' : $data['state'] : ''); $Qab->bindInt(':entry_country_id', $data['country']); $Qab->bindInt(':entry_zone_id', ACCOUNT_STATE > -1 ? isset($data['zone_id']) && $data['zone_id'] > 0 ? $data['zone_id'] : 0 : ''); $Qab->bindValue(':entry_telephone', ACCOUNT_TELEPHONE > -1 ? $data['telephone'] : ''); $Qab->bindValue(':entry_fax', ACCOUNT_FAX > -1 ? $data['fax'] : ''); $Qab->execute(); if ($Qab->affectedRows() === 1) { $updated_record = true; } if (isset($data['primary']) && $data['primary'] === true) { if (is_numeric($id) === false) { $id = $osC_Database->nextID(); } if (osC_AddressBook::setPrimaryAddress($id)) { $osC_Customer->setCountryID($data['country']); $osC_Customer->setZoneID($data['zone_id'] > 0 ? (int) $data['zone_id'] : '0'); $osC_Customer->setDefaultAddressID($id); if ($updated_record === false) { $updated_record = true; } } } if ($updated_record === true) { return true; } return false; }
function createNewAddress($customers_id, $address) { global $osC_Database, $osC_Customer; $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)'); $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); $Qab->bindInt(':customers_id', $customers_id); $Qab->bindValue(':entry_gender', $address['gender']); $Qab->bindValue(':entry_company', $address['company']); $Qab->bindValue(':entry_firstname', $address['firstname']); $Qab->bindValue(':entry_lastname', $address['lastname']); $Qab->bindValue(':entry_street_address', $address['street_address']); $Qab->bindValue(':entry_suburb', $address['suburb']); $Qab->bindValue(':entry_postcode', $address['postcode']); $Qab->bindValue(':entry_city', $address['city']); $Qab->bindValue(':entry_state', $address['state']); $Qab->bindInt(':entry_country_id', $address['country_id']); $Qab->bindInt(':entry_zone_id', $address['zone_id']); $Qab->bindValue(':entry_telephone', $address['ship_to_this_address']); $Qab->bindValue(':entry_fax', $address['fax']); $Qab->execute(); if (!$osC_Database->isError()) { $address_book_id = $osC_Database->nextID(); $Qcheck = $osC_Database->query('select customers_default_address_id from :table_customers where customers_id = :customers_id'); $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS); $Qcheck->bindInt(':customers_id', $customers_id); $Qcheck->execute(); if ($Qcheck->valueInt('customers_default_address_id') == 0) { require_once 'includes/classes/address_book.php'; if (osC_AddressBook::setPrimaryAddress($address_book_id)) { $osC_Customer->setCountryID($address['country_id']); $osC_Customer->setZoneID($address['zone_id'] > 0 ? (int) $address['zone_id'] : '0'); $osC_Customer->setDefaultAddressID($address_book_id); $osC_Customer->synchronizeCustomerDataWithSession(); return true; } else { return false; } } return true; } return false; }