catalog/catalog
diff -u -r1.16 -r1.17
--- checkout_payment_address.php 2004/03/18 10:09:08 1.16
+++ checkout_payment_address.php 2004/07/22 21:46:24 1.17
@@ -5,7 +5,7 @@
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
- Copyright (c) 2003 osCommerce
+ Copyright (c) 2004 osCommerce
Released under the GNU General Public License
*/
@@ -27,134 +27,147 @@
// needs to be included earlier to set the success message in the messageStack
require(DIR_WS_LANGUAGES . $osC_Session->value('language') . '/' . FILENAME_CHECKOUT_PAYMENT_ADDRESS);
- $error = false;
- $process = false;
if (isset($_POST['action']) && ($_POST['action'] == 'submit')) {
// process a new billing address
- if (tep_not_null($_POST['firstname']) && tep_not_null($_POST['lastname']) && tep_not_null($_POST['street_address'])) {
- $process = true;
-
- if (ACCOUNT_GENDER == 'true') $gender = tep_db_prepare_input($_POST['gender']);
- if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($_POST['company']);
- $firstname = tep_db_prepare_input($_POST['firstname']);
- $lastname = tep_db_prepare_input($_POST['lastname']);
- $street_address = tep_db_prepare_input($_POST['street_address']);
- if (ACCOUNT_SUBURB == 'true') $suburb = tep_db_prepare_input($_POST['suburb']);
- $postcode = tep_db_prepare_input($_POST['postcode']);
- $city = tep_db_prepare_input($_POST['city']);
- $country = tep_db_prepare_input($_POST['country']);
- if (ACCOUNT_STATE == 'true') {
- if (isset($_POST['zone_id'])) {
- $zone_id = tep_db_prepare_input($_POST['zone_id']);
- } else {
- $zone_id = false;
- }
- $state = tep_db_prepare_input($_POST['state']);
- }
-
- if (ACCOUNT_GENDER == 'true') {
- if ( ($gender != 'm') && ($gender != 'f') ) {
- $error = true;
-
+ if (($osC_Customer->hasDefaultAddress() === false) || (tep_not_null($_POST['firstname']) && tep_not_null($_POST['lastname']) && tep_not_null($_POST['street_address'])) ) {
+ if (ACCOUNT_GENDER > 0) {
+ if (!isset($_POST['gender']) || (($_POST['gender'] != 'm') && ($_POST['gender'] != 'f'))) {
$messageStack->add('checkout_address', ENTRY_GENDER_ERROR);
}
}
- if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
- $error = true;
-
+ if (!isset($_POST['firstname']) || (strlen(trim($_POST['firstname'])) < ACCOUNT_FIRST_NAME)) {
$messageStack->add('checkout_address', ENTRY_FIRST_NAME_ERROR);
}
-
- if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
- $error = true;
+ if (!isset($_POST['lastname']) || (strlen(trim($_POST['lastname'])) < ACCOUNT_LAST_NAME)) {
$messageStack->add('checkout_address', ENTRY_LAST_NAME_ERROR);
}
- if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
- $error = true;
+ if (ACCOUNT_COMPANY > 0) {
+ if (!isset($_POST['company']) || (strlen(trim($_POST['company'])) < ACCOUNT_COMPANY)) {
+ $messageStack->add('checkout_address', ENTRY_COMPANY_ERROR);
+ }
+ }
+ if (!isset($_POST['street_address']) || (strlen(trim($_POST['street_address'])) < ACCOUNT_STREET_ADDRESS)) {
$messageStack->add('checkout_address', ENTRY_STREET_ADDRESS_ERROR);
}
- if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
- $error = true;
+ if (ACCOUNT_SUBURB > 0) {
+ if (!isset($_POST['suburb']) || (strlen(trim($_POST['suburb'])) < ACCOUNT_SUBURB)) {
+ $messageStack->add('checkout_address', ENTRY_SUBURB_ERROR);
+ }
+ }
+ if (!isset($_POST['postcode']) || (strlen(trim($_POST['postcode'])) < ACCOUNT_POST_CODE)) {
$messageStack->add('checkout_address', ENTRY_POST_CODE_ERROR);
}
-
- if (strlen($city) < ENTRY_CITY_MIN_LENGTH) {
- $error = true;
+ if (!isset($_POST['city']) || (strlen(trim($_POST['city'])) < ACCOUNT_CITY)) {
$messageStack->add('checkout_address', ENTRY_CITY_ERROR);
}
- if (ACCOUNT_STATE == 'true') {
+ if (ACCOUNT_STATE > 0) {
$zone_id = 0;
- $check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "'");
- $check = tep_db_fetch_array($check_query);
- $entry_state_has_zones = ($check['total'] > 0);
- if ($entry_state_has_zones == true) {
- $zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and zone_code = '" . tep_db_input($state) . "'");
- if (tep_db_num_rows($zone_query) == 1) {
- $zone = tep_db_fetch_array($zone_query);
- $zone_id = $zone['zone_id'];
+
+ $Qcheck = $osC_Database->query('select zone_id from :table_zones where zone_country_id = :zone_country_id limit 1');
+ $Qcheck->bindRaw(':table_zones', TABLE_ZONES);
+ $Qcheck->bindValue(':zone_country_id', $_POST['country']);
+ $Qcheck->execute();
+
+ $entry_state_has_zones = ($Qcheck->numberOfRows() > 0);
+
+ $Qcheck->freeResult();
+
+ if ($entry_state_has_zones === true) {
+ $Qzone = $osC_Database->query('select zone_id from :table_zones where zone_country_id = :zone_country_id and zone_code like :zone_code');
+ $Qzone->bindRaw(':table_zones', TABLE_ZONES);
+ $Qzone->bindValue(':zone_country_id', $_POST['country']);
+ $Qzone->bindValue(':zone_code', trim($_POST['state']));
+ $Qzone->execute();
+
+ if ($Qzone->numberOfRows() === 1) {
+ $zone_id = $Qzone->valueInt('zone_id');
} else {
- $zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and zone_name like '" . tep_db_input($state) . "%'");
- if (tep_db_num_rows($zone_query) == 1) {
- $zone = tep_db_fetch_array($zone_query);
- $zone_id = $zone['zone_id'];
- } else {
- $error = true;
+ $Qzone = $osC_Database->query('select zone_id from :table_zones where zone_country_id = :zone_country_id and zone_name like :zone_name');
+ $Qzone->bindRaw(':table_zones', TABLE_ZONES);
+ $Qzone->bindValue(':zone_country_id', $_POST['country']);
+ $Qzone->bindValue(':zone_name', trim($_POST['state']) . '%');
+ $Qzone->execute();
+ if ($Qzone->numberOfRows() === 1) {
+ $zone_id = $Qzone->valueInt('zone_id');
+ } else {
$messageStack->add('checkout_address', ENTRY_STATE_ERROR_SELECT);
}
}
- } else {
- if (strlen($state) < ENTRY_STATE_MIN_LENGTH) {
- $error = true;
+ $Qzone->freeResult();
+ } else {
+ if (strlen(trim($_POST['state'])) < ACCOUNT_STATE) {
$messageStack->add('checkout_address', ENTRY_STATE_ERROR);
}
}
}
- if ( (is_numeric($country) == false) || ($country < 1) ) {
- $error = true;
-
+ if ( (is_numeric($_POST['country']) === false) || ($_POST['country'] < 1) ) {
$messageStack->add('checkout_address', ENTRY_COUNTRY_ERROR);
}
- if ($error == false) {
- $sql_data_array = array('customers_id' => $osC_Customer->id,
- 'entry_firstname' => $firstname,
- 'entry_lastname' => $lastname,
- 'entry_street_address' => $street_address,
- 'entry_postcode' => $postcode,
- 'entry_city' => $city,
- 'entry_country_id' => $country);
-
- if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender;
- if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company;
- if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb;
- if (ACCOUNT_STATE == 'true') {
- if ($zone_id > 0) {
- $sql_data_array['entry_zone_id'] = $zone_id;
- $sql_data_array['entry_state'] = '';
- } else {
- $sql_data_array['entry_zone_id'] = '0';
- $sql_data_array['entry_state'] = $state;
- }
+ if (ACCOUNT_TELEPHONE > 0) {
+ if (!isset($_POST['telephone']) || (strlen(trim($_POST['telephone'])) < ACCOUNT_TELEPHONE)) {
+ $messageStack->add('checkout_address', ENTRY_TELEPHONE_NUMBER_ERROR);
}
+ }
- tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
+ if (ACCOUNT_FAX > 0) {
+ if (!isset($_POST['fax']) || (strlen(trim($_POST['fax'])) < ACCOUNT_FAX)) {
+ $messageStack->add('checkout_address', ENTRY_FAX_NUMBER_ERROR);
+ }
+ }
- $osC_Session->set('billto', tep_db_insert_id());
+ if ($messageStack->size('checkout_address') === 0) {
+ $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->bindRaw(':table_address_book', TABLE_ADDRESS_BOOK);
+ $Qab->bindInt(':customers_id', $osC_Customer->id);
+ $Qab->bindValue(':entry_gender', (((ACCOUNT_GENDER > -1) && isset($_POST['gender']) && (($_POST['gender'] == 'm') || ($_POST['gender'] == 'f'))) ? $_POST['gender'] : ''));
+ $Qab->bindValue(':entry_company', ((ACCOUNT_COMPANY > -1) ? trim($_POST['company']) : ''));
+ $Qab->bindValue(':entry_firstname', trim($_POST['firstname']));
+ $Qab->bindValue(':entry_lastname', trim($_POST['lastname']));
+ $Qab->bindValue(':entry_street_address', trim($_POST['street_address']));
+ $Qab->bindValue(':entry_suburb', ((ACCOUNT_SUBURB > -1) ? trim($_POST['suburb']) : ''));
+ $Qab->bindValue(':entry_postcode', trim($_POST['postcode']));
+ $Qab->bindValue(':entry_city', trim($_POST['city']));
+ $Qab->bindValue(':entry_state', ((ACCOUNT_STATE > -1) ? (($zone_id > 0) ? '' : trim($_POST['state'])) : ''));
+ $Qab->bindInt(':entry_country_id', $_POST['country']);
+ $Qab->bindInt(':entry_zone_id', ((ACCOUNT_STATE > -1) ? (($zone_id > 0) ? $zone_id : 0) : ''));
+ $Qab->bindValue(':entry_telephone', ((ACCOUNT_TELEPHONE > -1) ? trim($_POST['telephone']) : ''));
+ $Qab->bindValue(':entry_fax', ((ACCOUNT_FAX > -1) ? trim($_POST['fax']) : ''));
+ $Qab->execute();
+
+ if ($Qab->affectedRows() === 1) {
+ $address_book_id = $osC_Database->nextID();
+
+ if ($osC_Customer->hasDefaultAddress() === false) {
+ $Qcustomer = $osC_Database->query('update :table_customers set customers_default_address_id = :customers_default_address_id where customers_id = :customers_id');
+ $Qcustomer->bindRaw(':table_customers', TABLE_CUSTOMERS);
+ $Qcustomer->bindInt(':customers_default_address_id', $address_book_id);
+ $Qcustomer->bindInt(':customers_id', $osC_Customer->id);
+ $Qcustomer->execute();
+
+ $osC_Customer->setCountryID($_POST['country']);
+ $osC_Customer->setZoneID($zone_id);
+ $osC_Customer->setDefaultAddressID($address_book_id);
+ }
- $osC_Session->remove('payment');
+ $osC_Session->set('billto', $address_book_id);
+ $osC_Session->remove('payment');
- tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
+ tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
+ } else {
+ $messageStack->add('checkout_address', 'Error inserting into address book table.');
+ }
}
// process the selected billing destination
} elseif (isset($_POST['address'])) {
@@ -292,7 +305,8 @@
<?php
}
- if ($process == false) {
+ if (!isset($_POST['action'])) {
+ if ($osC_Customer->hasDefaultAddress() === true) {
?>
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
@@ -325,6 +339,8 @@
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<?php
+ }
+
if ($addresses_count > 1) {
?>
<tr>
@@ -363,7 +379,7 @@
?>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
<td class="main" colspan="2"><b><?php echo $addresses['firstname'] . ' ' . $addresses['lastname']; ?></b></td>
- <td class="main" align="right"><?php echo tep_draw_radio_field('address', $addresses['address_book_id'], ($addresses['address_book_id'] == $osC_Session->value('billto'))); ?></td>
+ <td class="main" align="right"><?php echo osc_draw_radio_field('address', $addresses['address_book_id'], $osC_Session->value('billto')); ?></td>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
</tr>
<tr>
@@ -441,25 +457,13 @@
<tr>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
<td class="main"><?php echo '<b>' . TITLE_CONTINUE_CHECKOUT_PROCEDURE . '</b><br>' . TEXT_CONTINUE_CHECKOUT_PROCEDURE; ?></td>
- <td class="main" align="right"><?php echo tep_draw_hidden_field('action', 'submit') . tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
+ <td class="main" align="right"><?php echo osc_draw_hidden_field('action', 'submit') . tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
-<?php
- if ($process == true) {
-?>
- <tr>
- <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
- </tr>
- <tr>
- <td><?php echo '<a href="">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
- </tr>
-<?php
- }
-?>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>