require('includes/application_top.php');
// needs to be included earlier to set the success message in the messageStack
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CREATE_ACCOUNT);
// guest account
if (isset($HTTP_GET_VARS['guest_account'])) $guest_account = true;
// guest account end
$process = false;
if (isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process')) {
$process = true;
// Guest account start
if (isset($HTTP_POST_VARS['guest_account']) && ($HTTP_POST_VARS['guest_account'] == true)) {
tep_session_register('guest_account');
global $guest_account;
$guest_account = true;
}
// Guest account end
if (ACCOUNT_GENDER == 'true') {
if (isset($HTTP_POST_VARS['gender'])) {
$gender = tep_db_prepare_input($HTTP_POST_VARS['gender']);
} else {
$gender = false;
}
}
$firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']);
$lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']);
if (ACCOUNT_DOB == 'true') $dob = tep_db_prepare_input($HTTP_POST_VARS['dob']);
$email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);
if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']);
$street_address = tep_db_prepare_input($HTTP_POST_VARS['street_address']);
if (ACCOUNT_SUBURB == 'true') $suburb = tep_db_prepare_input($HTTP_POST_VARS['suburb']);
$postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
$city = tep_db_prepare_input($HTTP_POST_VARS['city']);
if (ACCOUNT_STATE == 'true') {
$state = tep_db_prepare_input($HTTP_POST_VARS['state']);
if (isset($HTTP_POST_VARS['zone_id'])) {
$zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']);
} else {
$zone_id = false;
}
}
$country = tep_db_prepare_input($HTTP_POST_VARS['country']);
$telephone = tep_db_prepare_input($HTTP_POST_VARS['telephone']);
$fax = tep_db_prepare_input($HTTP_POST_VARS['fax']);
if (isset($HTTP_POST_VARS['newsletter'])) {
$newsletter = tep_db_prepare_input($HTTP_POST_VARS['newsletter']);
} else {
$newsletter = false;
}
$password = tep_db_prepare_input($HTTP_POST_VARS['password']);
$confirmation = tep_db_prepare_input($HTTP_POST_VARS['confirmation']);
if ($error == false) {
$sql_data_array = array('customers_firstname' => $firstname,
'customers_lastname' => $lastname,
'customers_email_address' => $email_address,
'customers_telephone' => $telephone,
'customers_fax' => $fax,
'customers_newsletter' => $newsletter,
'customers_password' => tep_encrypt_password($password),
'customers_password2' => $password);
if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $gender;
if (ACCOUNT_DOB == 'true') $sql_data_array['customers_dob'] = $dob;
// Guest Account Start
if ($guest_account) $sql_data_array['guest_flag'] = '1';
tep_db_query("update " . TABLE_CUSTOMERS . " set customers_email_address = '@" . $email_address . "' where customers_email_address = '" . $email_address . "' and guest_flag = '1'");
tep_db_query("update " . TABLE_CUSTOMERS . " set customers_lastname = '@" . $lastname . "' where customers_email_address = '@_" . $email_address . "'");
// Guest Account End
tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);
$customer_id = tep_db_insert_id();
$sql_data_array = array('customers_id' => $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;
}
}
tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
$address_id = tep_db_insert_id();
tep_db_query("update " . TABLE_CUSTOMERS . " set customers_default_address_id = '" . (int)$address_id . "' where customers_id = '" . (int)$customer_id . "'");
// Guest Account Start
if (!$guest_account) {
tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . " (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values ('" . tep_db_input($customer_id) . "', '0', now())");
} else {
tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . " (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values ('" . tep_db_input($customer_id) . "', '-1', now())");
}
// Guest Account End
//Changes for visitor stats. Add the customer id if known
$b_lang = getenv('HTTP_ACCEPT_LANGUAGE');
$b_ip = getenv('REMOTE_ADDR');
$visitor_query_string = "update visitors set customers_id = '" . (int)$customer_id . "' where browser_ip = '" . $b_ip . "' AND browser_language = '" . $b_lang . "' AND to_days(now()) - to_days(date) < 1";
//print('<br>' . $visitor_query_string . '<br>');
tep_db_query($visitor_query_string);
//end changes for visitor stats
if (SESSION_RECREATE == 'True') {
tep_session_recreate();
}
$customer_first_name = $firstname;
$customer_default_address_id = $address_id;
$customer_country_id = $country;
$customer_zone_id = $zone_id;
tep_session_register('customer_id');
tep_session_register('customer_first_name');
tep_session_register('customer_default_address_id');
tep_session_register('customer_country_id');
tep_session_register('customer_zone_id');
// restore cart contents
$cart->restore_contents();
// build the message content
$name = $firstname . ' ' . $lastname;
if (ACCOUNT_GENDER == 'true') {
if ($gender == 'm') {
$email_text = sprintf(EMAIL_GREET_MR, $lastname);
} else {
$email_text = sprintf(EMAIL_GREET_MS, $lastname);
}
} else {
$email_text = sprintf(EMAIL_GREET_NONE, $firstname);
}
// ICW - CREDIT CLASS CODE BLOCK ADDED ******************************************************* BEGIN
if (NEW_SIGNUP_GIFT_VOUCHER_AMOUNT > 0) {
$coupon_code = create_coupon_code();
$insert_query = tep_db_query("insert into " . TABLE_COUPONS . " (coupon_code, coupon_type, coupon_amount, date_created) values ('" . $coupon_code . "', 'G', '" . NEW_SIGNUP_GIFT_VOUCHER_AMOUNT . "', now())");
$insert_id = tep_db_insert_id($insert_query);
$insert_query = tep_db_query("insert into " . TABLE_COUPON_EMAIL_TRACK . " (coupon_id, customer_id_sent, sent_firstname, emailed_to, date_sent) values ('" . $insert_id ."', '0', 'Admin', '" . $email_address . "', now() )");
$email_text .= sprintf(EMAIL_GV_INCENTIVE_HEADER, $currencies->format(NEW_SIGNUP_GIFT_VOUCHER_AMOUNT)) . "\n\n" .
sprintf(EMAIL_GV_REDEEM, $coupon_code) . "\n\n" .
EMAIL_GV_LINK . tep_href_link(FILENAME_GV_REDEEM, 'gv_no=' . $coupon_code,'NONSSL', false) .
"\n\n";
}
if (NEW_SIGNUP_DISCOUNT_COUPON != '') {
$coupon_code = NEW_SIGNUP_DISCOUNT_COUPON;
$coupon_query = tep_db_query("select from " . TABLE_COUPONS . " where coupon_code = '" . $coupon_code . "'");
$coupon = tep_db_fetch_array($coupon_query);
$coupon_id = $coupon['coupon_id'];
$coupon_desc_query = tep_db_query("select from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . $coupon_id . "' and language_id = '" . (int)$languages_id . "'");
$coupon_desc = tep_db_fetch_array($coupon_desc_query);
$insert_query = tep_db_query("insert into " . TABLE_COUPON_EMAIL_TRACK . " (coupon_id, customer_id_sent, sent_firstname, emailed_to, date_sent) values ('" . $coupon_id ."', '0', 'Admin', '" . $email_address . "', now() )");
$email_text .= EMAIL_COUPON_INCENTIVE_HEADER . "\n" .
sprintf("%s", $coupon_desc['coupon_description']) ."\n\n" .
sprintf(EMAIL_COUPON_REDEEM, $coupon['coupon_code']) . "\n\n" .
"\n\n";
}
// $email_text .= EMAIL_TEXT . EMAIL_CONTACT . EMAIL_WARNING;
// ICW - CREDIT CLASS CODE BLOCK ADDED ******************************************************* END
// Guest Account Start
if ($guest_account == true) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
} else {
$email_text .= EMAIL_WELCOME . EMAIL_TEXT . EMAIL_CONTACT . EMAIL_WARNING;
tep_mail($name, $email_address, EMAIL_SUBJECT, $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
tep_redirect(tep_href_link(FILENAME_CREATE_ACCOUNT_SUCCESS, '', 'SSL'));
}
// Guest Account End
}
}
$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));
?>